};
struct PgStats {
- uint64 request_count;
- uint64 server_bytes;
- uint64 client_bytes;
+ uint64_t request_count;
+ uint64_t server_bytes;
+ uint64_t client_bytes;
usec_t query_time; /* total req time in us */
};
PgStats older_stats;
/* database info to be sent to client */
- uint8 welcome_msg[256];
+ uint8_t welcome_msg[256];
unsigned welcome_msg_len;
VarCache orig_vars;
unsigned db_paused:1;
/* key/val pairs (without user) for startup msg to be sent to server */
- uint8 startup_params[256];
+ uint8_t startup_params[256];
unsigned startup_params_len;
/* if not NULL, the user/psw is forced */
usec_t query_start; /* query start moment */
char salt[4];
- uint8 cancel_key[BACKENDKEY_LEN];
+ uint8_t cancel_key[BACKENDKEY_LEN];
PgUser * auth_user;
PgAddr remote_addr;
PgAddr local_addr;
typedef struct MBuf MBuf;
struct MBuf {
- const uint8 *data;
- const uint8 *end;
- const uint8 *pos;
+ const uint8_t *data;
+ const uint8_t *end;
+ const uint8_t *pos;
};
-static inline void mbuf_init(MBuf *buf, const uint8 *ptr, int len)
+static inline void mbuf_init(MBuf *buf, const uint8_t *ptr, int len)
{
if (len < 0)
fatal("fuckup");
buf->end = ptr + len;
}
-static inline uint8 mbuf_get_char(MBuf *buf)
+static inline uint8_t mbuf_get_char(MBuf *buf)
{
if (buf->pos + 1 > buf->end)
fatal("buffer overflow");
return val;
}
-static inline unsigned mbuf_get_uint32(MBuf *buf)
+static inline uint32_t mbuf_get_uint32(MBuf *buf)
{
- unsigned val;
+ uint32_t val;
if (buf->pos + 4 > buf->end)
fatal("buffer overflow");
val = *buf->pos++;
return val;
}
-static inline unsigned mbuf_get_uint64(MBuf *buf)
+static inline uint64_t mbuf_get_uint64(MBuf *buf)
{
- uint64 i1, i2;
+ uint64_t i1, i2;
i1 = mbuf_get_uint32(buf);
i2 = mbuf_get_uint32(buf);
return (i1 << 32) | i2;
}
-static inline const uint8 * mbuf_get_bytes(MBuf *buf, unsigned len)
+static inline const uint8_t * mbuf_get_bytes(MBuf *buf, unsigned len)
{
- const uint8 *res = buf->pos;
+ const uint8_t *res = buf->pos;
if (buf->pos + len > buf->end)
fatal("buffer overflow");
buf->pos += len;
static inline const char * mbuf_get_string(MBuf *buf)
{
const char *res = (const char *)buf->pos;
- const uint8 *nul = memchr(res, 0, mbuf_avail(buf));
+ const uint8_t *nul = memchr(res, 0, mbuf_avail(buf));
if (!nul)
return NULL;
buf->pos = nul + 1;
{
union
{
- uint32 md5_state32[4];
- uint8 md5_state8[16];
+ uint32_t md5_state32[4];
+ uint8_t md5_state8[16];
} md5_st;
#define md5_sta md5_st.md5_state32[0]
union
{
- uint64 md5_count64;
- uint8 md5_count8[8];
+ uint64_t md5_count64;
+ uint8_t md5_count8[8];
} md5_count;
#define md5_n md5_count.md5_count64
#define md5_n8 md5_count.md5_count8
- unsigned int md5_i;
- uint8 md5_buf[MD5_BUFLEN];
+ unsigned md5_i;
+ uint8_t md5_buf[MD5_BUFLEN];
} md5_ctxt;
extern void md5_init(md5_ctxt *);
-extern void md5_loop(md5_ctxt *, const uint8 *, unsigned int);
+extern void md5_loop(md5_ctxt *, const uint8_t *, unsigned int);
extern void md5_pad(md5_ctxt *);
-extern void md5_result(uint8 *, md5_ctxt *);
+extern void md5_result(uint8_t *, md5_ctxt *);
/* compatibility with OpenSSL */
#define MD5_CTX md5_ctxt
void launch_new_connection(PgPool *pool);
-bool use_client_socket(int fd, PgAddr *addr, const char *dbname, const char *username, uint64 ckey, int oldfd, int linkfd,
+bool use_client_socket(int fd, PgAddr *addr, const char *dbname, const char *username, uint64_t ckey, int oldfd, int linkfd,
const char *client_end, const char *std_string, const char *datestyle, const char *timezone);
-bool use_server_socket(int fd, PgAddr *addr, const char *dbname, const char *username, uint64 ckey, int oldfd, int linkfd,
+bool use_server_socket(int fd, PgAddr *addr, const char *dbname, const char *username, uint64_t ckey, int oldfd, int linkfd,
const char *client_end, const char *std_string, const char *datestyle, const char *timezone);
void pause_client(PgSocket *client);
typedef struct PktBuf PktBuf;
struct PktBuf {
- uint8 *buf;
+ uint8_t *buf;
int buf_len;
int write_pos;
int pktlen_pos;
* pktbuf creation
*/
PktBuf *pktbuf_dynamic(int start_len);
-void pktbuf_static(PktBuf *buf, uint8 *data, int len);
+void pktbuf_static(PktBuf *buf, uint8_t *data, int len);
/*
* sending
*/
void pktbuf_start_packet(PktBuf *buf, int type);
void pktbuf_put_char(PktBuf *buf, char val);
-void pktbuf_put_uint16(PktBuf *buf, uint16 val);
-void pktbuf_put_uint32(PktBuf *buf, uint32 val);
-void pktbuf_put_uint64(PktBuf *buf, uint64 val);
+void pktbuf_put_uint16(PktBuf *buf, uint16_t val);
+void pktbuf_put_uint32(PktBuf *buf, uint32_t val);
+void pktbuf_put_uint64(PktBuf *buf, uint64_t val);
void pktbuf_put_string(PktBuf *buf, const char *str);
void pktbuf_put_bytes(PktBuf *buf, const void *data, int len);
void pktbuf_finish_packet(PktBuf *buf);
*/
#define SEND_wrap(buflen, pktfn, res, sk, args...) do { \
- uint8 _data[buflen]; PktBuf _buf; \
+ uint8_t _data[buflen]; PktBuf _buf; \
pktbuf_static(&_buf, _data, sizeof(_data)); \
pktfn(&_buf, ## args); \
res = pktbuf_send_immidiate(&_buf, sk); \
unsigned is_unix:1; /* is it unix socket */
unsigned wait_send:1; /* debug var, otherwise useless */
- uint8 buf[0];
+ uint8_t buf[0];
};
#define sbuf_socket(sbuf) ((sbuf)->sock)
typedef enum { false=0, true=1 } bool;
-typedef uint8_t uint8;
-typedef uint16_t uint16;
-typedef uint32_t uint32;
-typedef uint64_t uint64;
-
/*
* PostgreSQL type OIDs for resultsets.
*/
#define isMD5(passwd) (memcmp(passwd, "md5", 3) == 0 \
&& strlen(passwd) == MD5_PASSWD_LEN)
bool pg_md5_encrypt(const char *part1, const char *part2, size_t p2len, char *dest);
-bool get_random_bytes(uint8 *dest, int len);
+bool get_random_bytes(uint8_t *dest, int len);
void socket_set_nonblocking(int fd, int val);
void tune_socket(int sock, bool is_unix);
bool admin_ready(PgSocket *admin, const char *desc)
{
PktBuf buf;
- uint8 tmp[512];
+ uint8_t tmp[512];
pktbuf_static(&buf, tmp, sizeof(tmp));
pktbuf_write_CommandComplete(&buf, desc);
pktbuf_write_ReadyForQuery(&buf);
int fd, const char *task,
const char *user, const char *db,
const char *addr, int port,
- uint64 ckey, int link,
+ uint64_t ckey, int link,
const char *client_enc,
const char *std_strings,
const char *datestyle,
struct cmsghdr *cmsg;
int res;
struct iovec iovec;
- uint8 pktbuf[1024];
- uint8 cntbuf[CMSG_SPACE(sizeof(int))];
+ uint8_t pktbuf[1024];
+ uint8_t cntbuf[CMSG_SPACE(sizeof(int))];
iovec.iov_base = pktbuf;
BUILD_DataRow(res, pktbuf, sizeof(pktbuf), "issssiqissss",
static bool send_client_authreq(PgSocket *client)
{
- uint8 saltlen = 0;
+ uint8_t saltlen = 0;
int res;
int auth = cf_auth_type;
- uint8 randbuf[2];
+ uint8_t randbuf[2];
if (auth == AUTH_CRYPT) {
saltlen = 2;
break;
case PKT_CANCEL:
if (mbuf_avail(&pkt->data) == BACKENDKEY_LEN) {
- const uint8 *key = mbuf_get_bytes(&pkt->data, BACKENDKEY_LEN);
+ const uint8_t *key = mbuf_get_bytes(&pkt->data, BACKENDKEY_LEN);
memcpy(client->cancel_key, key, BACKENDKEY_LEN);
accept_cancel_request(client);
} else
#define MD5_D0 0x10325476
/* Integer part of 4294967296 times abs(sin(i)), where i is in radians. */
-static const uint32 T[65] = {
+static const uint32_t T[65] = {
0,
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
};
-static const uint8 md5_paddat[MD5_BUFLEN] = {
+static const uint8_t md5_paddat[MD5_BUFLEN] = {
0x80, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
-static void md5_calc(uint8 *, md5_ctxt *);
+static void md5_calc(uint8_t *, md5_ctxt *);
void
md5_init(md5_ctxt * ctxt)
}
void
-md5_loop(md5_ctxt * ctxt, const uint8 *input, unsigned len)
+md5_loop(md5_ctxt * ctxt, const uint8_t *input, unsigned len)
{
unsigned int gap,
i;
md5_calc(ctxt->md5_buf, ctxt);
for (i = gap; i + MD5_BUFLEN <= len; i += MD5_BUFLEN)
- md5_calc((uint8 *) (input + i), ctxt);
+ md5_calc((uint8_t *) (input + i), ctxt);
ctxt->md5_i = len - i;
memmove(ctxt->md5_buf, input + i, ctxt->md5_i);
}
void
-md5_result(uint8 *digest, md5_ctxt * ctxt)
+md5_result(uint8_t *digest, md5_ctxt * ctxt)
{
/* 4 byte words */
#if BYTE_ORDER == LITTLE_ENDIAN
}
#if BYTE_ORDER == BIG_ENDIAN
-static uint32 X[16];
+static uint32_t X[16];
#endif
static void
-md5_calc(uint8 *b64, md5_ctxt * ctxt)
+md5_calc(uint8_t *b64, md5_ctxt * ctxt)
{
- uint32 A = ctxt->md5_sta;
- uint32 B = ctxt->md5_stb;
- uint32 C = ctxt->md5_stc;
- uint32 D = ctxt->md5_std;
+ uint32_t A = ctxt->md5_sta;
+ uint32_t B = ctxt->md5_stb;
+ uint32_t C = ctxt->md5_stc;
+ uint32_t D = ctxt->md5_std;
#if BYTE_ORDER == LITTLE_ENDIAN
- uint32 *X = (uint32 *) b64;
+ uint32_t *X = (uint32_t *) b64;
#endif
#if BYTE_ORDER == BIG_ENDIAN
/* 4 byte words */
/* what a brute force but fast! */
- uint8 *y = (uint8 *) X;
+ uint8_t *y = (uint8_t *) X;
y[0] = b64[3];
y[1] = b64[2];
{
PgPool *pool = server->pool;
PgSocket *client = server->link;
- static const uint8 pkt_term[] = {'X', 0,0,0,4};
+ static const uint8_t pkt_term[] = {'X', 0,0,0,4};
int send_term = 1;
if (cf_log_disconnections)
bool use_client_socket(int fd, PgAddr *addr,
const char *dbname, const char *username,
- uint64 ckey, int oldfd, int linkfd,
+ uint64_t ckey, int oldfd, int linkfd,
const char *client_enc, const char *std_string,
const char *datestyle, const char *timezone)
{
bool use_server_socket(int fd, PgAddr *addr,
const char *dbname, const char *username,
- uint64 ckey, int oldfd, int linkfd,
+ uint64_t ckey, int oldfd, int linkfd,
const char *client_enc, const char *std_string,
const char *datestyle, const char *timezone)
{
return buf;
}
-void pktbuf_static(PktBuf *buf, uint8 *data, int len)
+void pktbuf_static(PktBuf *buf, uint8_t *data, int len)
{
memset(buf, 0, sizeof(*buf));
buf->buf = data;
bool pktbuf_send_immidiate(PktBuf *buf, PgSocket *sk)
{
int fd = sbuf_socket(&sk->sbuf);
- uint8 *pos = buf->buf + buf->send_pos;
+ uint8_t *pos = buf->buf + buf->send_pos;
int amount = buf->write_pos - buf->send_pos;
int res;
buf->buf[buf->write_pos++] = val;
}
-void pktbuf_put_uint16(PktBuf *buf, uint16 val)
+void pktbuf_put_uint16(PktBuf *buf, uint16_t val)
{
make_room(buf, 4);
if (buf->failed)
buf->buf[buf->write_pos++] = val & 255;
}
-void pktbuf_put_uint32(PktBuf *buf, uint32 val)
+void pktbuf_put_uint32(PktBuf *buf, uint32_t val)
{
- uint8 *pos;
+ uint8_t *pos;
make_room(buf, 4);
if (buf->failed)
buf->write_pos += 4;
}
-void pktbuf_put_uint64(PktBuf *buf, uint64 val)
+void pktbuf_put_uint64(PktBuf *buf, uint64_t val)
{
pktbuf_put_uint32(buf, val >> 32);
- pktbuf_put_uint32(buf, (uint32)val);
+ pktbuf_put_uint32(buf, (uint32_t)val);
}
void pktbuf_put_bytes(PktBuf *buf, const void *data, int len)
void pktbuf_finish_packet(PktBuf *buf)
{
- uint8 *pos;
+ uint8_t *pos;
unsigned len;
if (buf->failed)
va_list ap;
int len;
const char *adesc = pktdesc;
- uint8 *bin;
+ uint8_t *bin;
pktbuf_start_packet(buf, type);
pktbuf_put_uint32(buf, va_arg(ap, int));
break;
case 'q':
- pktbuf_put_uint64(buf, va_arg(ap, uint64));
+ pktbuf_put_uint64(buf, va_arg(ap, uint64_t));
break;
case 's':
pktbuf_put_string(buf, va_arg(ap, char *));
break;
case 'b':
- bin = va_arg(ap, uint8 *);
+ bin = va_arg(ap, uint8_t *);
len = va_arg(ap, int);
pktbuf_put_bytes(buf, bin, len);
break;
sprintf(tmp, "%d", va_arg(ap, int));
val = tmp;
} else if (tupdesc[i] == 'q') {
- sprintf(tmp, "%llu", (unsigned long long)va_arg(ap, uint64));
+ sprintf(tmp, "%llu", (unsigned long long)va_arg(ap, uint64_t));
val = tmp;
} else if (tupdesc[i] == 's') {
val = va_arg(ap, char *);
bool send_pooler_error(PgSocket *client, bool send_ready, const char *msg)
{
- uint8 tmpbuf[512];
+ uint8_t tmpbuf[512];
PktBuf buf;
if (cf_log_pooler_errors)
bool welcome_client(PgSocket *client)
{
int res;
- uint8 buf[1024];
+ uint8_t buf[1024];
PktBuf msg;
PgPool *pool = client->pool;
return send_password(server, server->pool->user->passwd);
}
-static bool login_crypt_psw(PgSocket *server, const uint8 *salt)
+static bool login_crypt_psw(PgSocket *server, const uint8_t *salt)
{
char saltbuf[3];
const char *enc;
return send_password(server, enc);
}
-static bool login_md5_psw(PgSocket *server, const uint8 *salt)
+static bool login_md5_psw(PgSocket *server, const uint8_t *salt)
{
char txt[MD5_PASSWD_LEN + 1], *src;
PgUser *user = server->pool->user;
bool answer_authreq(PgSocket *server, PktHdr *pkt)
{
unsigned cmd;
- const uint8 *salt;
+ const uint8_t *salt;
bool res = false;
/* authreq body must contain 32bit cmd */
PgDatabase *db = server->pool->db;
const char *username = server->pool->user->name;
PktBuf pkt;
- uint8 buf[512];
+ uint8_t buf[512];
pktbuf_static(&pkt, buf, sizeof(buf));
pktbuf_write_StartupMessage(&pkt, username,
unsigned ncol, i, asked;
va_list ap;
int *int_p;
- uint64 *long_p;
+ uint64_t *long_p;
char **str_p;
asked = strlen(tupdesc);
*int_p = atoi(val);
break;
case 'q':
- long_p = va_arg(ap, uint64 *);
+ long_p = va_arg(ap, uint64_t *);
*long_p = atoll(val);
break;
case 's':
static bool sbuf_call_proto(SBuf *sbuf, int event)
{
MBuf mbuf;
- uint8 *pos = sbuf->buf + sbuf->pkt_pos;
+ uint8_t *pos = sbuf->buf + sbuf->pkt_pos;
int avail = sbuf->recv_pos - sbuf->pkt_pos;
bool res;
static bool sbuf_send_pending(SBuf *sbuf)
{
int res, avail;
- uint8 *pos;
+ uint8_t *pos;
AssertActive(sbuf);
Assert(sbuf->dst || !sbuf->send_remain);
static bool sbuf_actual_recv(SBuf *sbuf, int len)
{
int got;
- uint8 *pos;
+ uint8_t *pos;
AssertActive(sbuf);
Assert(len > 0);
static void calc_average(PgStats *avg, PgStats *cur, PgStats *old)
{
- uint64 qcount;
+ uint64_t qcount;
usec_t dur = get_cached_time() - old_stamp;
reset_stats(avg);
char *client_enc, *std_string, *datestyle, *timezone;
int oldfd, port, linkfd;
int got;
- uint64 ckey;
+ uint64_t ckey;
PgAddr addr;
memset(&addr, 0, sizeof(addr));
static void takeover_recv_cb(int sock, short flags, void *arg)
{
PgSocket *bouncer = arg;
- uint8 data_buf[2048];
- uint8 cnt_buf[128];
+ uint8_t data_buf[2048];
+ uint8_t cnt_buf[128];
struct msghdr msg;
struct iovec io;
int res;
* PostgreSQL MD5 hashing.
*/
-static void hash2hex(const uint8 *hash, char *dst)
+static void hash2hex(const uint8_t *hash, char *dst)
{
int i;
static const char hextbl [] = "0123456789abcdef";
char *dest)
{
MD5_CTX ctx;
- uint8 hash[MD5_DIGEST_LENGTH];
+ uint8_t hash[MD5_DIGEST_LENGTH];
MD5_Init(&ctx);
MD5_Update(&ctx, part1, strlen(part1));
}
/* wrapped for getting random bytes */
-bool get_random_bytes(uint8 *dest, int len)
+bool get_random_bytes(uint8_t *dest, int len)
{
int i;
for (i = 0; i < len; i++)
bool varcache_apply(PgSocket *server, PgSocket *client, bool *changes_p)
{
PktBuf pkt;
- uint8 buf[1024];
+ uint8_t buf[1024];
int changes = 0;
const char *cval, *sval;
const struct var_lookup *lk;
- uint8 *debug_sql;
+ uint8_t *debug_sql;
bool std_quote = is_std_quote(&server->vars);
pktbuf_static(&pkt, buf, sizeof(buf));