]> granicus.if.org Git - pgbouncer/commitdiff
Make sure server->vars is always initialized.
authorMarko Kreen <markokr@gmail.com>
Thu, 18 Oct 2007 12:18:27 +0000 (12:18 +0000)
committerMarko Kreen <markokr@gmail.com>
Thu, 18 Oct 2007 12:18:27 +0000 (12:18 +0000)
src/proto.c
src/proto.h
src/server.c

index b7c7a61df12dc62f05dc78de34bc8516f396387f..6a8106caed33971f7bafa384363b8de6fb65893b 100644 (file)
@@ -145,43 +145,25 @@ void log_server_error(const char *note, PktHdr *pkt)
  */
 
 /* add another server parameter packet to cache */
-bool add_welcome_parameter(PgSocket *server, PktHdr *pkt)
+void add_welcome_parameter(PgPool *pool, const char *key, const char *val)
 {
-       PgPool *pool = server->pool;
        PktBuf msg;
-       const char *key, *val;
 
        if (pool->welcome_msg_ready)
-               return true;
-
-       /* incomplete startup msg from server? */
-       if (incomplete_pkt(pkt))
-               return false;
+               return;
 
        pktbuf_static(&msg, pool->welcome_msg + pool->welcome_msg_len,
                      sizeof(pool->welcome_msg) - pool->welcome_msg_len);
 
+       /* first packet must be AuthOk */
        if (pool->welcome_msg_len == 0)
                pktbuf_write_AuthenticationOk(&msg);
 
-       key = mbuf_get_string(&pkt->data);
-       val = mbuf_get_string(&pkt->data);
-       if (!key || !val) {
-               disconnect_server(server, true, "broken ParameterStatus packet");
-               return false;
-       }
-
-       slog_noise(server, "S: param: %s = %s", key, val);
-       if (varcache_set(&pool->orig_vars, key, val)) {
-               slog_noise(server, "interesting var: %s=%s", key, val);
-               varcache_set(&server->vars, key, val);
-       } else {
-               slog_noise(server, "uninteresting var: %s=%s", key, val);
+       /* if not stored in ->orig_vars, write full packet */
+       if (!varcache_set(&pool->orig_vars, key, val)) {
                pktbuf_write_ParameterStatus(&msg, key, val);
                pool->welcome_msg_len += pktbuf_written(&msg);
        }
-
-       return true;
 }
 
 /* all parameters processed */
index c4eb5d2e70dc14eba941ad26041c3a1699085c1a..a19a5e23ebc2104e2af734fc44653efb3c7f00d1 100644 (file)
@@ -37,7 +37,7 @@ bool get_header(MBuf *data, PktHdr *pkt);
 bool send_pooler_error(PgSocket *client, bool send_ready, const char *msg);
 void log_server_error(const char *note, PktHdr *pkt);
 
-bool add_welcome_parameter(PgSocket *server, PktHdr *pkt);
+void add_welcome_parameter(PgPool *pool, const char *key, const char *val);
 void finish_welcome_msg(PgSocket *server);
 bool welcome_client(PgSocket *client);
 
index cb2a1c25de2421ad19b1c33d579071ce81f6b3f3..b06d3e0666e2f6ab63d633f0d042b80357fc3818 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "bouncer.h"
 
-static bool load_parameter(PgSocket *server, PktHdr *pkt)
+static bool load_parameter(PgSocket *server, PktHdr *pkt, bool startup)
 {
        const char *key, *val;
        PgSocket *client = server->link;
@@ -49,6 +49,9 @@ static bool load_parameter(PgSocket *server, PktHdr *pkt)
                varcache_set(&client->vars, key, val);
        }
 
+       if (startup)
+               add_welcome_parameter(server->pool, key, val);
+
        return true;
 }
 
@@ -84,7 +87,7 @@ static bool handle_server_startup(PgSocket *server, PktHdr *pkt)
                break;
 
        case 'S':               /* ParameterStatus */
-               res = add_welcome_parameter(server, pkt);
+               res = load_parameter(server, pkt, true);
                break;
 
        case 'Z':               /* ReadyForQuery */
@@ -158,7 +161,7 @@ static bool handle_server_work(PgSocket *server, PktHdr *pkt)
                break;
 
        case 'S':               /* ParameterStatus */
-               if (!load_parameter(server, pkt))
+               if (!load_parameter(server, pkt, false))
                        return false;
                break;