$(E) " CHECK" $(srcs)
$(Q) sparse $(SPARCE_FLAGS) $(srcs)
+pgbouncer.pg:
+ $(CC) -pg $(DEFS) -g -O2 $(CPPFLAGS) $(LDFLAGS) -o $@ $(srcs) $(LIBS)
+
+pg: pgbouncer.pg
+
dbname = val;
else if (strcmp(key, "user") == 0)
username = val;
- else if (varcache_set(&client->vars, key, val, true))
+ else if (varcache_set(&client->vars, key, val))
slog_debug(client, "got var: %s=%s", key, val);
else {
disconnect_client(client, true, "Unknown startup parameter");
client->tmp_sk_oldfd = oldfd;
client->tmp_sk_linkfd = linkfd;
- varcache_set(&client->vars, "client_encoding", client_enc, true);
- varcache_set(&client->vars, "standard_conforming_strings", std_string, true);
- varcache_set(&client->vars, "datestyle", datestyle, true);
- varcache_set(&client->vars, "timezone", timezone, true);
+ varcache_set(&client->vars, "client_encoding", client_enc);
+ varcache_set(&client->vars, "standard_conforming_strings", std_string);
+ varcache_set(&client->vars, "datestyle", datestyle);
+ varcache_set(&client->vars, "timezone", timezone);
return true;
}
server->tmp_sk_oldfd = oldfd;
server->tmp_sk_linkfd = linkfd;
- varcache_set(&server->vars, "client_encoding", client_enc, true);
- varcache_set(&server->vars, "standard_conforming_strings", std_string, true);
- varcache_set(&server->vars, "datestyle", datestyle, true);
- varcache_set(&server->vars, "timezone", timezone, true);
+ varcache_set(&server->vars, "client_encoding", client_enc);
+ varcache_set(&server->vars, "standard_conforming_strings", std_string);
+ varcache_set(&server->vars, "datestyle", datestyle);
+ varcache_set(&server->vars, "timezone", timezone);
return true;
}
return false;
}
- slog_debug(server, "S: param: %s = %s", key, val);
- if (varcache_set(&pool->orig_vars, key, val, true)) {
- slog_debug(server, "interesting var: %s=%s", key, val);
- varcache_set(&server->vars, key, val, true);
+ 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_debug(server, "uninteresting var: %s=%s", key, val);
+ slog_noise(server, "uninteresting var: %s=%s", key, val);
pktbuf_write_ParameterStatus(&msg, key, val);
pool->welcome_msg_len += pktbuf_written(&msg);
}
if (!pool->welcome_msg_ready)
return false;
- varcache_print(&client->vars, "welcome/client");
- varcache_print(&client->pool->orig_vars, "welcome/pool");
-
pktbuf_static(&msg, buf, sizeof(buf));
pktbuf_put_bytes(&msg, pool->welcome_msg, pool->welcome_msg_len);
}
slog_debug(server, "S: param: %s = %s", key, val);
- varcache_set(&server->vars, key, val, true);
+ varcache_set(&server->vars, key, val);
if (client) {
slog_debug(client, "setting client var: %s='%s'", key, val);
- varcache_set(&client->vars, key, val, true);
+ varcache_set(&client->vars, key, val);
}
return;
};
static const struct var_lookup lookup [] = {
-{"client_encoding", offsetof(VarCache, client_encoding), VAR_ENCODING_LEN },
-{"datestyle", offsetof(VarCache, datestyle), VAR_DATESTYLE_LEN },
-{"timezone", offsetof(VarCache, timezone), VAR_TIMEZONE_LEN },
-{"standard_conforming_strings", offsetof(VarCache, std_strings), VAR_STDSTR_LEN },
-{NULL},
+ {"client_encoding", offsetof(VarCache, client_encoding), VAR_ENCODING_LEN },
+ {"datestyle", offsetof(VarCache, datestyle), VAR_DATESTYLE_LEN },
+ {"timezone", offsetof(VarCache, timezone), VAR_TIMEZONE_LEN },
+ {"standard_conforming_strings", offsetof(VarCache, std_strings), VAR_STDSTR_LEN },
+ {NULL},
};
-static char *get_value(VarCache *cache, const struct var_lookup *lk)
+static inline char *get_value(VarCache *cache, const struct var_lookup *lk)
{
return (char *)(cache) + lk->offset;
}
-bool varcache_set(VarCache *cache,
- const char *key, const char *value,
- bool overwrite)
+bool varcache_set(VarCache *cache, const char *key, const char *value)
{
int vlen;
char *pos;
if (strcasecmp(lk->name, key) != 0)
continue;
- pos = get_value(cache, lk);
-
- if (!overwrite && *pos)
- break;
+ vlen = strlen(value);
+ if (vlen >= lk->len) {
+ log_warning("varcache_set overflow: %s", key);
+ return false;
+ }
- vlen = strlcpy(pos, value, lk->len);
- if (vlen >= lk->len)
- log_warning("varcache_set(%s) overflow", key);
- else
- log_debug("varcache_set: %s=%s", key, pos);
+ pos = get_value(cache, lk);
+ memcpy(pos, value, vlen + 1);
return true;
}
return false;
for (lk = lookup; lk->name; lk++) {
srcval = get_value(src, lk);
dstval = get_value(&dst->vars, lk);
- if (*dstval)
- continue;
-
- /* empty val, copy */
- slog_debug(dst, "varcache_fill_unset: %s = %s", lk->name, srcval);
- strlcpy(dstval, srcval, lk->len);
+ if (!*dstval)
+ strlcpy(dstval, srcval, lk->len);
}
}
val = get_value(vars, lk);
if (*val)
pktbuf_write_ParameterStatus(pkt, lk->name, val);
- else
- log_error("varcache_add_params: empty param: %s", lk->name);
- }
-}
-
-void varcache_print(VarCache *vars, const char *desc)
-{
- char *val;
- const struct var_lookup *lk;
- for (lk = lookup; lk->name; lk++) {
- val = get_value(vars, lk);
- log_debug("%s: %s='%s'", desc, lk->name, val);
}
}
-
char std_strings[VAR_STDSTR_LEN];
};
-bool varcache_set(VarCache *cache, const char *key, const char *value, bool overwrite);
+bool varcache_set(VarCache *cache, const char *key, const char *value);
bool varcache_apply(PgSocket *server, PgSocket *client, bool *changes_p);
void varcache_fill_unset(VarCache *src, PgSocket *dst);
void varcache_clean(VarCache *cache);
void varcache_add_params(PktBuf *pkt, VarCache *vars);
-void varcache_print(VarCache *vars, const char *desc);