#include "postgres.h"
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "libpq/libpq.h"
#include "libpq/pqformat.h"
#include "mb/pg_wchar.h"
Go to the source code of this file.
void pq_beginmessage | ( | StringInfo | buf, | |
char | msgtype | |||
) |
Definition at line 87 of file pqformat.c.
References StringInfoData::cursor, and initStringInfo().
Referenced by exec_describe_statement_message(), IdentifySystem(), NotifyMyFrontEnd(), perform_base_backup(), PostgresMain(), printtup(), printtup_20(), printtup_internal_20(), ReadyForQuery(), ReceiveCopyBegin(), ReportGUCOption(), send_message_to_frontend(), sendAuthRequest(), SendBackupHeader(), SendCopyBegin(), SendFunctionResult(), SendRowDescriptionMessage(), SendTimeLineHistory(), SendXlogRecPtrResult(), and StartReplication().
{ initStringInfo(buf); /* * We stash the message type into the buffer's cursor field, expecting * that the pq_sendXXX routines won't touch it. We could alternatively * make it the first byte of the buffer contents, but this seems easier. */ buf->cursor = msgtype; }
void pq_begintypsend | ( | StringInfo | buf | ) |
Definition at line 358 of file pqformat.c.
References appendStringInfoCharMacro, and initStringInfo().
Referenced by abstimesend(), array_send(), boolsend(), box_send(), cash_send(), charsend(), cidsend(), circle_send(), complex_send(), cstring_send(), date_send(), enum_send(), float4send(), float8send(), hstore_send(), int2send(), int4send(), int8send(), interval_send(), json_send(), lseg_send(), macaddr_send(), namesend(), network_send(), numeric_send(), oidsend(), path_send(), point_send(), poly_send(), range_send(), record_send(), reltimesend(), textsend(), tidsend(), time_send(), timestamp_send(), timestamptz_send(), timetz_send(), tintervalsend(), tsquerysend(), tsvectorsend(), txid_snapshot_send(), unknownsend(), uuid_send(), varbit_send(), void_send(), xidsend(), and xml_send().
{ initStringInfo(buf); /* Reserve four bytes for the bytea length word */ appendStringInfoCharMacro(buf, '\0'); appendStringInfoCharMacro(buf, '\0'); appendStringInfoCharMacro(buf, '\0'); appendStringInfoCharMacro(buf, '\0'); }
void pq_copymsgbytes | ( | StringInfo | msg, | |
char * | buf, | |||
int | datalen | |||
) |
Definition at line 569 of file pqformat.c.
References StringInfoData::cursor, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, and StringInfoData::len.
Referenced by bit_recv(), bytearecv(), CopyGetData(), pq_getmsgint(), pq_getmsgint64(), and varbit_recv().
void pq_endmessage | ( | StringInfo | buf | ) |
Definition at line 343 of file pqformat.c.
References StringInfoData::cursor, StringInfoData::data, StringInfoData::len, pfree(), and pq_putmessage().
Referenced by exec_describe_statement_message(), IdentifySystem(), NotifyMyFrontEnd(), perform_base_backup(), PostgresMain(), printtup(), printtup_20(), printtup_internal_20(), ReadyForQuery(), ReceiveCopyBegin(), ReportGUCOption(), send_message_to_frontend(), sendAuthRequest(), SendBackupHeader(), SendCopyBegin(), SendFunctionResult(), SendRowDescriptionMessage(), SendTimeLineHistory(), SendXlogRecPtrResult(), and StartReplication().
bytea* pq_endtypsend | ( | StringInfo | buf | ) |
Definition at line 378 of file pqformat.c.
References Assert, StringInfoData::data, StringInfoData::len, SET_VARSIZE, and VARHDRSZ.
Referenced by abstimesend(), array_send(), boolsend(), box_send(), cash_send(), charsend(), cidsend(), circle_send(), complex_send(), cstring_send(), date_send(), enum_send(), float4send(), float8send(), hstore_send(), int2send(), int4send(), int8send(), interval_send(), json_send(), lseg_send(), macaddr_send(), namesend(), network_send(), numeric_send(), oidsend(), path_send(), point_send(), poly_send(), range_send(), record_send(), reltimesend(), textsend(), tidsend(), time_send(), timestamp_send(), timestamptz_send(), timetz_send(), tintervalsend(), tsquerysend(), tsvectorsend(), txid_snapshot_send(), unknownsend(), uuid_send(), varbit_send(), void_send(), xidsend(), and xml_send().
int pq_getmsgbyte | ( | StringInfo | msg | ) |
Definition at line 431 of file pqformat.c.
References StringInfoData::cursor, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, and StringInfoData::len.
Referenced by boolrecv(), charrecv(), macaddr_recv(), network_recv(), path_recv(), PostgresMain(), ProcessStandbyMessage(), ProcessStandbyReplyMessage(), range_recv(), and XLogWalRcvProcessMsg().
const char* pq_getmsgbytes | ( | StringInfo | msg, | |
int | datalen | |||
) |
Definition at line 549 of file pqformat.c.
References StringInfoData::cursor, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, and StringInfoData::len.
Referenced by exec_bind_message(), parse_fcall_arguments(), parse_fcall_arguments_20(), range_recv(), uuid_recv(), and xml_recv().
void pq_getmsgend | ( | StringInfo | msg | ) |
Definition at line 647 of file pqformat.c.
References StringInfoData::cursor, ereport, errcode(), errmsg(), ERROR, and StringInfoData::len.
Referenced by exec_bind_message(), HandleFunctionRequest(), PostgresMain(), and range_recv().
float4 pq_getmsgfloat4 | ( | StringInfo | msg | ) |
Definition at line 510 of file pqformat.c.
References i, pq_getmsgint(), and swap.
Referenced by float4recv().
float8 pq_getmsgfloat8 | ( | StringInfo | msg | ) |
Definition at line 529 of file pqformat.c.
References i, pq_getmsgint64(), and swap.
Referenced by box_recv(), circle_recv(), complex_recv(), float8recv(), interval_recv(), lseg_recv(), path_recv(), point_recv(), poly_recv(), time_recv(), timestamp_recv(), timestamptz_recv(), and timetz_recv().
{ union { float8 f; int64 i; } swap; swap.i = pq_getmsgint64(msg); return swap.f; }
unsigned int pq_getmsgint | ( | StringInfo | msg, | |
int | b | |||
) |
Definition at line 447 of file pqformat.c.
References elog, ERROR, and pq_copymsgbytes().
Referenced by abstimerecv(), array_recv(), bit_recv(), cidrecv(), date_recv(), exec_bind_message(), HandleFunctionRequest(), hstore_recv(), int2recv(), int4recv(), interval_recv(), numeric_recv(), oidrecv(), parse_fcall_arguments(), parse_fcall_arguments_20(), path_recv(), poly_recv(), PostgresMain(), pq_getmsgfloat4(), ProcessStandbyHSFeedbackMessage(), range_recv(), ReadArrayBinary(), record_recv(), reltimerecv(), tidrecv(), timetz_recv(), tintervalrecv(), tsqueryrecv(), tsvectorrecv(), txid_snapshot_recv(), varbit_recv(), and xidrecv().
{ unsigned int result; unsigned char n8; uint16 n16; uint32 n32; switch (b) { case 1: pq_copymsgbytes(msg, (char *) &n8, 1); result = n8; break; case 2: pq_copymsgbytes(msg, (char *) &n16, 2); result = ntohs(n16); break; case 4: pq_copymsgbytes(msg, (char *) &n32, 4); result = ntohl(n32); break; default: elog(ERROR, "unsupported integer size %d", b); result = 0; /* keep compiler quiet */ break; } return result; }
int64 pq_getmsgint64 | ( | StringInfo | msg | ) |
Definition at line 485 of file pqformat.c.
References pq_copymsgbytes().
Referenced by cash_recv(), int8recv(), interval_recv(), pq_getmsgfloat8(), ProcessStandbyHSFeedbackMessage(), ProcessStandbyReplyMessage(), time_recv(), timestamp_recv(), timestamptz_recv(), timetz_recv(), txid_snapshot_recv(), and XLogWalRcvProcessMsg().
{ int64 result; uint32 h32; uint32 l32; pq_copymsgbytes(msg, (char *) &h32, 4); pq_copymsgbytes(msg, (char *) &l32, 4); h32 = ntohl(h32); l32 = ntohl(l32); result = h32; result <<= 32; result |= l32; return result; }
const char* pq_getmsgstring | ( | StringInfo | msg | ) |
Definition at line 620 of file pqformat.c.
References StringInfoData::cursor, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, StringInfoData::len, and pg_client_to_server().
Referenced by CopyGetData(), exec_bind_message(), HandleFunctionRequest(), PostgresMain(), tsqueryrecv(), and tsvectorrecv().
{ char *str; int slen; str = &msg->data[msg->cursor]; /* * It's safe to use strlen() here because a StringInfo is guaranteed to * have a trailing null byte. But check we found a null inside the * message. */ slen = strlen(str); if (msg->cursor + slen >= msg->len) ereport(ERROR, (errcode(ERRCODE_PROTOCOL_VIOLATION), errmsg("invalid string in message"))); msg->cursor += slen + 1; return pg_client_to_server(str, slen); }
char* pq_getmsgtext | ( | StringInfo | msg, | |
int | rawbytes, | |||
int * | nbytes | |||
) |
Definition at line 587 of file pqformat.c.
References StringInfoData::cursor, StringInfoData::data, ereport, errcode(), errmsg(), ERROR, StringInfoData::len, palloc(), and pg_client_to_server().
Referenced by bpcharrecv(), cstring_recv(), enum_recv(), hstore_recv(), json_recv(), namerecv(), textrecv(), unknownrecv(), and varcharrecv().
{ char *str; char *p; if (rawbytes < 0 || rawbytes > (msg->len - msg->cursor)) ereport(ERROR, (errcode(ERRCODE_PROTOCOL_VIOLATION), errmsg("insufficient data left in message"))); str = &msg->data[msg->cursor]; msg->cursor += rawbytes; p = pg_client_to_server(str, rawbytes); if (p != str) /* actual conversion has been done? */ *nbytes = strlen(p); else { p = (char *) palloc(rawbytes + 1); memcpy(p, str, rawbytes); p[rawbytes] = '\0'; *nbytes = rawbytes; } return p; }
void pq_putemptymessage | ( | char | msgtype | ) |
Definition at line 420 of file pqformat.c.
References NULL, and pq_putmessage().
Referenced by exec_bind_message(), exec_describe_portal_message(), exec_describe_statement_message(), exec_execute_message(), exec_parse_message(), NullCommand(), perform_base_backup(), PostgresMain(), ReadyForQuery(), ReceiveCopyBegin(), SendCopyBegin(), and SendCopyEnd().
{ (void) pq_putmessage(msgtype, NULL, 0); }
void pq_puttextmessage | ( | char | msgtype, | |
const char * | str | |||
) |
Definition at line 399 of file pqformat.c.
References pfree(), pg_server_to_client(), and pq_putmessage().
Referenced by printtup_startup(), SendBackupHeader(), SendXlogRecPtrResult(), and StartReplication().
{ int slen = strlen(str); char *p; p = pg_server_to_client(str, slen); if (p != str) /* actual conversion has been done? */ { (void) pq_putmessage(msgtype, p, strlen(p) + 1); pfree(p); return; } (void) pq_putmessage(msgtype, str, slen + 1); }
void pq_send_ascii_string | ( | StringInfo | buf, | |
const char * | str | |||
) |
Definition at line 217 of file pqformat.c.
References appendStringInfoChar(), appendStringInfoCharMacro, and IS_HIGHBIT_SET.
Referenced by err_sendstring().
{ while (*str) { char ch = *str++; if (IS_HIGHBIT_SET(ch)) ch = '?'; appendStringInfoCharMacro(buf, ch); } appendStringInfoChar(buf, '\0'); }
void pq_sendbyte | ( | StringInfo | buf, | |
int | byt | |||
) |
Definition at line 104 of file pqformat.c.
References appendStringInfoCharMacro.
Referenced by boolsend(), charsend(), macaddr_send(), network_send(), path_send(), perform_base_backup(), range_send(), ReadyForQuery(), ReceiveCopyBegin(), send_message_to_frontend(), SendCopyBegin(), SendFunctionResult(), StartReplication(), tsvectorsend(), WalSndKeepalive(), XLogSend(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
{ appendStringInfoCharMacro(buf, byt); }
void pq_sendbytes | ( | StringInfo | buf, | |
const char * | data, | |||
int | datalen | |||
) |
Definition at line 114 of file pqformat.c.
References appendBinaryStringInfo().
Referenced by array_send(), IdentifySystem(), printtup(), printtup_internal_20(), range_send(), record_send(), send_int8_string(), sendAuthRequest(), SendBackupHeader(), SendFunctionResult(), SendTimeLineHistory(), SendXlogRecPtrResult(), StartReplication(), uuid_send(), and varbit_send().
{ appendBinaryStringInfo(buf, data, datalen); }
void pq_sendcountedtext | ( | StringInfo | buf, | |
const char * | str, | |||
int | slen, | |||
bool | countincludesself | |||
) |
Definition at line 130 of file pqformat.c.
References appendBinaryStringInfo(), pfree(), pg_server_to_client(), and pq_sendint().
Referenced by printtup(), printtup_20(), and SendFunctionResult().
{ int extra = countincludesself ? 4 : 0; char *p; p = pg_server_to_client(str, slen); if (p != str) /* actual conversion has been done? */ { slen = strlen(p); pq_sendint(buf, slen + extra, 4); appendBinaryStringInfo(buf, p, slen); pfree(p); } else { pq_sendint(buf, slen + extra, 4); appendBinaryStringInfo(buf, str, slen); } }
void pq_sendfloat4 | ( | StringInfo | buf, | |
float4 | f | |||
) |
Definition at line 297 of file pqformat.c.
References appendBinaryStringInfo(), i, and swap.
Referenced by float4send().
void pq_sendfloat8 | ( | StringInfo | buf, | |
float8 | f | |||
) |
Definition at line 323 of file pqformat.c.
References i, pq_sendint64(), and swap.
Referenced by box_send(), circle_send(), complex_send(), float8send(), interval_send(), lseg_send(), path_send(), point_send(), poly_send(), time_send(), timestamp_send(), timestamptz_send(), and timetz_send().
{ union { float8 f; int64 i; } swap; swap.f = f; pq_sendint64(buf, swap.i); }
void pq_sendint | ( | StringInfo | buf, | |
int | i, | |||
int | b | |||
) |
Definition at line 235 of file pqformat.c.
References appendBinaryStringInfo(), elog, and ERROR.
Referenced by abstimesend(), array_send(), cidsend(), date_send(), exec_describe_statement_message(), hstore_send(), IdentifySystem(), int2send(), int4send(), interval_send(), NotifyMyFrontEnd(), numeric_send(), oidsend(), path_send(), perform_base_backup(), poly_send(), PostgresMain(), pq_sendcountedtext(), printtup(), printtup_20(), printtup_internal_20(), range_send(), ReceiveCopyBegin(), record_send(), reltimesend(), send_int8_string(), sendAuthRequest(), SendBackupHeader(), SendCopyBegin(), SendFunctionResult(), SendRowDescriptionMessage(), SendTimeLineHistory(), SendXlogRecPtrResult(), StartReplication(), tidsend(), timetz_send(), tintervalsend(), tsquerysend(), tsvectorsend(), txid_snapshot_send(), varbit_send(), xidsend(), and XLogWalRcvSendHSFeedback().
{ unsigned char n8; uint16 n16; uint32 n32; switch (b) { case 1: n8 = (unsigned char) i; appendBinaryStringInfo(buf, (char *) &n8, 1); break; case 2: n16 = htons((uint16) i); appendBinaryStringInfo(buf, (char *) &n16, 2); break; case 4: n32 = htonl((uint32) i); appendBinaryStringInfo(buf, (char *) &n32, 4); break; default: elog(ERROR, "unsupported integer size %d", b); break; } }
void pq_sendint64 | ( | StringInfo | buf, | |
int64 | i | |||
) |
Definition at line 270 of file pqformat.c.
References appendBinaryStringInfo().
Referenced by cash_send(), int8send(), interval_send(), pq_sendfloat8(), time_send(), timestamp_send(), timestamptz_send(), timetz_send(), txid_snapshot_send(), WalSndKeepalive(), XLogSend(), XLogWalRcvSendHSFeedback(), and XLogWalRcvSendReply().
{ uint32 n32; /* High order half first, since we're doing MSB-first */ n32 = (uint32) (i >> 32); n32 = htonl(n32); appendBinaryStringInfo(buf, (char *) &n32, 4); /* Now the low order half */ n32 = (uint32) i; n32 = htonl(n32); appendBinaryStringInfo(buf, (char *) &n32, 4); }
void pq_sendstring | ( | StringInfo | buf, | |
const char * | str | |||
) |
Definition at line 185 of file pqformat.c.
References appendBinaryStringInfo(), pfree(), and pg_server_to_client().
Referenced by err_sendstring(), IdentifySystem(), NotifyMyFrontEnd(), ReportGUCOption(), SendBackupHeader(), SendRowDescriptionMessage(), SendTimeLineHistory(), SendXlogRecPtrResult(), StartReplication(), and tsquerysend().
{ int slen = strlen(str); char *p; p = pg_server_to_client(str, slen); if (p != str) /* actual conversion has been done? */ { slen = strlen(p); appendBinaryStringInfo(buf, p, slen + 1); pfree(p); } else appendBinaryStringInfo(buf, str, slen + 1); }
void pq_sendtext | ( | StringInfo | buf, | |
const char * | str, | |||
int | slen | |||
) |
Definition at line 162 of file pqformat.c.
References appendBinaryStringInfo(), pfree(), and pg_server_to_client().
Referenced by cstring_send(), enum_send(), hstore_send(), json_send(), namesend(), textsend(), tsvectorsend(), unknownsend(), and xml_send().
{ char *p; p = pg_server_to_client(str, slen); if (p != str) /* actual conversion has been done? */ { slen = strlen(p); appendBinaryStringInfo(buf, p, slen); pfree(p); } else appendBinaryStringInfo(buf, str, slen); }