mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +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:
@@ -3591,7 +3591,9 @@ keep_going: /* We will come back to here until there is
|
||||
* Anything else probably means it's not Postgres on the other
|
||||
* end at all.
|
||||
*/
|
||||
if (!(beresp == 'R' || beresp == 'v' || beresp == 'E'))
|
||||
if (beresp != PqMsg_AuthenticationRequest &&
|
||||
beresp != PqMsg_ErrorResponse &&
|
||||
beresp != PqMsg_NegotiateProtocolVersion)
|
||||
{
|
||||
libpq_append_conn_error(conn, "expected authentication request from server, but received %c",
|
||||
beresp);
|
||||
@@ -3618,19 +3620,22 @@ keep_going: /* We will come back to here until there is
|
||||
* version 14, the server also used the old protocol for
|
||||
* errors that happened before processing the startup packet.)
|
||||
*/
|
||||
if (beresp == 'R' && (msgLength < 8 || msgLength > 2000))
|
||||
if (beresp == PqMsg_AuthenticationRequest &&
|
||||
(msgLength < 8 || msgLength > 2000))
|
||||
{
|
||||
libpq_append_conn_error(conn, "received invalid authentication request");
|
||||
goto error_return;
|
||||
}
|
||||
if (beresp == 'v' && (msgLength < 8 || msgLength > 2000))
|
||||
if (beresp == PqMsg_NegotiateProtocolVersion &&
|
||||
(msgLength < 8 || msgLength > 2000))
|
||||
{
|
||||
libpq_append_conn_error(conn, "received invalid protocol negotiation message");
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
#define MAX_ERRLEN 30000
|
||||
if (beresp == 'E' && (msgLength < 8 || msgLength > MAX_ERRLEN))
|
||||
if (beresp == PqMsg_ErrorResponse &&
|
||||
(msgLength < 8 || msgLength > MAX_ERRLEN))
|
||||
{
|
||||
/* Handle error from a pre-3.0 server */
|
||||
conn->inCursor = conn->inStart + 1; /* reread data */
|
||||
@@ -3693,7 +3698,7 @@ keep_going: /* We will come back to here until there is
|
||||
}
|
||||
|
||||
/* Handle errors. */
|
||||
if (beresp == 'E')
|
||||
if (beresp == PqMsg_ErrorResponse)
|
||||
{
|
||||
if (pqGetErrorNotice3(conn, true))
|
||||
{
|
||||
@@ -3770,7 +3775,7 @@ keep_going: /* We will come back to here until there is
|
||||
|
||||
goto error_return;
|
||||
}
|
||||
else if (beresp == 'v')
|
||||
else if (beresp == PqMsg_NegotiateProtocolVersion)
|
||||
{
|
||||
if (pqGetNegotiateProtocolVersion3(conn))
|
||||
{
|
||||
@@ -4540,7 +4545,7 @@ sendTerminateConn(PGconn *conn)
|
||||
* Try to send "close connection" message to backend. Ignore any
|
||||
* error.
|
||||
*/
|
||||
pqPutMsgStart('X', conn);
|
||||
pqPutMsgStart(PqMsg_Terminate, conn);
|
||||
pqPutMsgEnd(conn);
|
||||
(void) pqFlush(conn);
|
||||
}
|
||||
|
Reference in New Issue
Block a user