1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-17 17:02:08 +03:00

Introduce macros for protocol characters.

This commit introduces descriptively-named macros for the
identifiers used in wire protocol messages.  These new macros are
placed in a new header file so that they can be easily used by
third-party code.

Author: Dave Cramer
Reviewed-by: Alvaro Herrera, Tatsuo Ishii, Peter Smith, Robert Haas, Tom Lane, Peter Eisentraut, Michael Paquier
Discussion: https://postgr.es/m/CADK3HHKbBmK-PKf1bPNFoMC%2BoBt%2BpD9PH8h5nvmBQskEHm-Ehw%40mail.gmail.com
This commit is contained in:
Nathan Bossart
2023-08-22 19:16:12 -07:00
parent 7114791158
commit f4b54e1ed9
25 changed files with 305 additions and 204 deletions

View File

@ -402,37 +402,37 @@ SocketBackend(StringInfo inBuf)
*/
switch (qtype)
{
case 'Q': /* simple query */
case PqMsg_Query:
maxmsglen = PQ_LARGE_MESSAGE_LIMIT;
doing_extended_query_message = false;
break;
case 'F': /* fastpath function call */
case PqMsg_FunctionCall:
maxmsglen = PQ_LARGE_MESSAGE_LIMIT;
doing_extended_query_message = false;
break;
case 'X': /* terminate */
case PqMsg_Terminate:
maxmsglen = PQ_SMALL_MESSAGE_LIMIT;
doing_extended_query_message = false;
ignore_till_sync = false;
break;
case 'B': /* bind */
case 'P': /* parse */
case PqMsg_Bind:
case PqMsg_Parse:
maxmsglen = PQ_LARGE_MESSAGE_LIMIT;
doing_extended_query_message = true;
break;
case 'C': /* close */
case 'D': /* describe */
case 'E': /* execute */
case 'H': /* flush */
case PqMsg_Close:
case PqMsg_Describe:
case PqMsg_Execute:
case PqMsg_Flush:
maxmsglen = PQ_SMALL_MESSAGE_LIMIT;
doing_extended_query_message = true;
break;
case 'S': /* sync */
case PqMsg_Sync:
maxmsglen = PQ_SMALL_MESSAGE_LIMIT;
/* stop any active skip-till-Sync */
ignore_till_sync = false;
@ -440,13 +440,13 @@ SocketBackend(StringInfo inBuf)
doing_extended_query_message = false;
break;
case 'd': /* copy data */
case PqMsg_CopyData:
maxmsglen = PQ_LARGE_MESSAGE_LIMIT;
doing_extended_query_message = false;
break;
case 'c': /* copy done */
case 'f': /* copy fail */
case PqMsg_CopyDone:
case PqMsg_CopyFail:
maxmsglen = PQ_SMALL_MESSAGE_LIMIT;
doing_extended_query_message = false;
break;
@ -1589,7 +1589,7 @@ exec_parse_message(const char *query_string, /* string to execute */
* Send ParseComplete.
*/
if (whereToSendOutput == DestRemote)
pq_putemptymessage('1');
pq_putemptymessage(PqMsg_ParseComplete);
/*
* Emit duration logging if appropriate.
@ -2047,7 +2047,7 @@ exec_bind_message(StringInfo input_message)
* Send BindComplete.
*/
if (whereToSendOutput == DestRemote)
pq_putemptymessage('2');
pq_putemptymessage(PqMsg_BindComplete);
/*
* Emit duration logging if appropriate.
@ -2290,7 +2290,7 @@ exec_execute_message(const char *portal_name, long max_rows)
{
/* Portal run not complete, so send PortalSuspended */
if (whereToSendOutput == DestRemote)
pq_putemptymessage('s');
pq_putemptymessage(PqMsg_PortalSuspended);
/*
* Set XACT_FLAGS_PIPELINING whenever we suspend an Execute message,
@ -2683,7 +2683,7 @@ exec_describe_statement_message(const char *stmt_name)
NULL);
}
else
pq_putemptymessage('n'); /* NoData */
pq_putemptymessage(PqMsg_NoData);
}
/*
@ -2736,7 +2736,7 @@ exec_describe_portal_message(const char *portal_name)
FetchPortalTargetList(portal),
portal->formats);
else
pq_putemptymessage('n'); /* NoData */
pq_putemptymessage(PqMsg_NoData);
}
@ -4239,7 +4239,7 @@ PostgresMain(const char *dbname, const char *username)
{
StringInfoData buf;
pq_beginmessage(&buf, 'K');
pq_beginmessage(&buf, PqMsg_BackendKeyData);
pq_sendint32(&buf, (int32) MyProcPid);
pq_sendint32(&buf, (int32) MyCancelKey);
pq_endmessage(&buf);
@ -4618,7 +4618,7 @@ PostgresMain(const char *dbname, const char *username)
switch (firstchar)
{
case 'Q': /* simple query */
case PqMsg_Query:
{
const char *query_string;
@ -4642,7 +4642,7 @@ PostgresMain(const char *dbname, const char *username)
}
break;
case 'P': /* parse */
case PqMsg_Parse:
{
const char *stmt_name;
const char *query_string;
@ -4672,7 +4672,7 @@ PostgresMain(const char *dbname, const char *username)
}
break;
case 'B': /* bind */
case PqMsg_Bind:
forbidden_in_wal_sender(firstchar);
/* Set statement_timestamp() */
@ -4687,7 +4687,7 @@ PostgresMain(const char *dbname, const char *username)
/* exec_bind_message does valgrind_report_error_query */
break;
case 'E': /* execute */
case PqMsg_Execute:
{
const char *portal_name;
int max_rows;
@ -4707,7 +4707,7 @@ PostgresMain(const char *dbname, const char *username)
}
break;
case 'F': /* fastpath function call */
case PqMsg_FunctionCall:
forbidden_in_wal_sender(firstchar);
/* Set statement_timestamp() */
@ -4742,7 +4742,7 @@ PostgresMain(const char *dbname, const char *username)
send_ready_for_query = true;
break;
case 'C': /* close */
case PqMsg_Close:
{
int close_type;
const char *close_target;
@ -4782,13 +4782,13 @@ PostgresMain(const char *dbname, const char *username)
}
if (whereToSendOutput == DestRemote)
pq_putemptymessage('3'); /* CloseComplete */
pq_putemptymessage(PqMsg_CloseComplete);
valgrind_report_error_query("CLOSE message");
}
break;
case 'D': /* describe */
case PqMsg_Describe:
{
int describe_type;
const char *describe_target;
@ -4822,13 +4822,13 @@ PostgresMain(const char *dbname, const char *username)
}
break;
case 'H': /* flush */
case PqMsg_Flush:
pq_getmsgend(&input_message);
if (whereToSendOutput == DestRemote)
pq_flush();
break;
case 'S': /* sync */
case PqMsg_Sync:
pq_getmsgend(&input_message);
finish_xact_command();
valgrind_report_error_query("SYNC message");
@ -4847,7 +4847,7 @@ PostgresMain(const char *dbname, const char *username)
/* FALLTHROUGH */
case 'X':
case PqMsg_Terminate:
/*
* Reset whereToSendOutput to prevent ereport from attempting
@ -4865,9 +4865,9 @@ PostgresMain(const char *dbname, const char *username)
*/
proc_exit(0);
case 'd': /* copy data */
case 'c': /* copy done */
case 'f': /* copy fail */
case PqMsg_CopyData:
case PqMsg_CopyDone:
case PqMsg_CopyFail:
/*
* Accept but ignore these messages, per protocol spec; we
@ -4897,7 +4897,7 @@ forbidden_in_wal_sender(char firstchar)
{
if (am_walsender)
{
if (firstchar == 'F')
if (firstchar == PqMsg_FunctionCall)
ereport(ERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("fastpath function calls not supported in a replication connection")));