1 /*-------------------------------------------------------------------------
4 * Definitions common to frontends and backends.
6 * NOTE: for historical reasons, this does not correspond to pqcomm.c.
7 * pqcomm.c's routines are declared in libpq.h.
9 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
12 * $Id: pqcomm.h,v 1.70 2002/09/04 20:31:42 momjian Exp $
14 *-------------------------------------------------------------------------
19 #include <sys/types.h>
22 /* workaround for clashing defines of "ERROR" */
28 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #endif /* not WIN32 */
36 #ifndef HAVE_STRUCT_SOCKADDR_UN
39 short int sun_family; /* AF_UNIX */
40 char sun_path[108]; /* path name (gag) */
44 /* Define a generic socket address type. */
46 typedef union SockAddr
49 struct sockaddr_in in;
50 struct sockaddr_un un;
54 /* Configure the UNIX socket location for the well known port. */
56 #define UNIXSOCK_PATH(sun,port,defpath) \
57 snprintf((sun).sun_path, sizeof((sun).sun_path), "%s/.s.PGSQL.%d", \
58 ((defpath) && *(defpath) != '\0') ? (defpath) : \
59 DEFAULT_PGSOCKET_DIR, \
63 * We do this because sun_len is in BSD's struct, while others don't.
64 * We never actually set BSD's sun_len, and I can't think of a
65 * platform-safe way of doing it, but the code still works. bjm
68 #define UNIXSOCK_LEN(sun) \
71 #define UNIXSOCK_LEN(sun) \
72 (strlen((sun).sun_path) + offsetof(struct sockaddr_un, sun_path))
76 * These manipulate the frontend/backend protocol version number.
78 * The major number should be incremented for incompatible changes. The minor
79 * number should be incremented for compatible changes (eg. additional
82 * If a backend supports version m.n of the protocol it must actually support
83 * versions m.0..n]. Backend support for version m-1 can be dropped after a
84 * `reasonable' length of time.
86 * A frontend isn't required to support anything other than the current
90 #define PG_PROTOCOL_MAJOR(v) ((v) >> 16)
91 #define PG_PROTOCOL_MINOR(v) ((v) & 0x0000ffff)
92 #define PG_PROTOCOL(m,n) (((m) << 16) | (n))
94 /* The earliest and latest frontend/backend protocol version supported. */
96 #define PG_PROTOCOL_EARLIEST PG_PROTOCOL(1,0)
97 #define PG_PROTOCOL_LATEST PG_PROTOCOL(2,0)
100 * All packets sent to the postmaster start with the length. This is omitted
101 * from the different packet definitions specified below.
104 typedef uint32 PacketLen;
108 * Startup message parameters sizes. These must not be changed without changing
109 * the protocol version. These are all strings that are '\0' terminated only if
114 * FIXME: remove the fixed size limitations on the database name, user
115 * name, and options fields and use a variable length field instead. The
116 * actual limits on database & user name will then be NAMEDATALEN, which
117 * can be changed without changing the FE/BE protocol. -neilc,2002/08/27
120 #define SM_DATABASE 64
122 /* We append database name if db_user_namespace true. */
123 #define SM_DATABASE_USER (SM_DATABASE+SM_USER+1) /* +1 for @ */
124 #define SM_OPTIONS 64
128 typedef uint32 ProtocolVersion; /* Fe/Be protocol version number */
130 typedef ProtocolVersion MsgType;
133 typedef struct StartupPacket
135 ProtocolVersion protoVersion; /* Protocol version */
136 char database[SM_DATABASE]; /* Database name */
137 /* Db_user_namespace appends dbname */
138 char user[SM_USER]; /* User name */
139 char options[SM_OPTIONS]; /* Optional additional args */
140 char unused[SM_UNUSED]; /* Unused */
141 char tty[SM_TTY]; /* Tty for debug output */
144 extern bool Db_user_namespace;
146 /* These are the authentication requests sent by the backend. */
148 #define AUTH_REQ_OK 0 /* User is authenticated */
149 #define AUTH_REQ_KRB4 1 /* Kerberos V4 */
150 #define AUTH_REQ_KRB5 2 /* Kerberos V5 */
151 #define AUTH_REQ_PASSWORD 3 /* Password */
152 #define AUTH_REQ_CRYPT 4 /* crypt password */
153 #define AUTH_REQ_MD5 5 /* md5 password */
154 #define AUTH_REQ_SCM_CREDS 6 /* transfer SCM credentials */
156 typedef uint32 AuthRequest;
159 /* A client can also send a cancel-current-operation request to the postmaster.
160 * This is uglier than sending it directly to the client's backend, but it
161 * avoids depending on out-of-band communication facilities.
164 /* The cancel request code must not match any protocol version number
165 * we're ever likely to use. This random choice should do.
167 #define CANCEL_REQUEST_CODE PG_PROTOCOL(1234,5678)
169 typedef struct CancelRequestPacket
171 /* Note that each field is stored in network byte order! */
172 MsgType cancelRequestCode; /* code to identify a cancel
174 uint32 backendPID; /* PID of client's backend */
175 uint32 cancelAuthCode; /* secret key to authorize cancel */
176 } CancelRequestPacket;
180 * A client can also start by sending a SSL negotiation request, to get a
183 #define NEGOTIATE_SSL_CODE PG_PROTOCOL(1234,5679)
185 #endif /* PQCOMM_H */