OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I686LINUX / util / I686LINUX / include / pgsql / postgresql / internal / libpq / pqcomm.h
1 /*-------------------------------------------------------------------------
2  *
3  * pqcomm.h
4  *              Definitions common to frontends and backends.
5  *
6  * NOTE: for historical reasons, this does not correspond to pqcomm.c.
7  * pqcomm.c's routines are declared in libpq.h.
8  *
9  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
10  * Portions Copyright (c) 1994, Regents of the University of California
11  *
12  * $Id: pqcomm.h,v 1.93 2003/08/04 02:40:13 momjian Exp $
13  *
14  *-------------------------------------------------------------------------
15  */
16 #ifndef PQCOMM_H
17 #define PQCOMM_H
18
19 #ifdef WIN32
20 #include <winsock.h>
21 /* workaround for clashing defines of "ERROR" */
22 #ifdef ELOG_H
23 #undef ERROR
24 #define ERROR   PGERROR
25 #endif
26 #else                                                   /* not WIN32 */
27 #include <sys/socket.h>
28 #include <netdb.h>
29 #ifdef HAVE_SYS_UN_H
30 #include <sys/un.h>
31 #endif
32 #include <netinet/in.h>
33 #endif   /* not WIN32 */
34
35 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
36
37 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
38 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
39 #define ss_family __ss_family
40 #else
41 #error struct sockaddr_storage does not provide an ss_family member
42 #endif
43 #endif
44
45 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
46 #define ss_len __ss_len
47 #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
48 #endif
49
50 #else                                                   /* !HAVE_STRUCT_SOCKADDR_STORAGE */
51
52 /* Define a struct sockaddr_storage if we don't have one. */
53
54 struct sockaddr_storage
55 {
56         union
57         {
58                 struct sockaddr sa;             /* get the system-dependent fields */
59                 int64           ss_align;       /* ensures struct is properly aligned */
60                 char            ss_pad[128];    /* ensures struct has desired size */
61         }                       ss_stuff;
62 };
63
64 #define ss_family       ss_stuff.sa.sa_family
65 /* It should have an ss_len field if sockaddr has sa_len. */
66 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
67 #define ss_len          ss_stuff.sa.sa_len
68 #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
69 #endif
70 #endif   /* HAVE_STRUCT_SOCKADDR_STORAGE */
71
72 typedef struct
73 {
74         struct sockaddr_storage addr;
75         ACCEPT_TYPE_ARG3 salen;
76 } SockAddr;
77
78 /* Configure the UNIX socket location for the well known port. */
79
80 #define UNIXSOCK_PATH(path,port,defpath) \
81                 snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
82                                 ((defpath) && *(defpath) != '\0') ? (defpath) : \
83                                 DEFAULT_PGSOCKET_DIR, \
84                                 (port))
85
86 /*
87  * These manipulate the frontend/backend protocol version number.
88  *
89  * The major number should be incremented for incompatible changes.  The minor
90  * number should be incremented for compatible changes (eg. additional
91  * functionality).
92  *
93  * If a backend supports version m.n of the protocol it must actually support
94  * versions m.[0..n].  Backend support for version m-1 can be dropped after a
95  * `reasonable' length of time.
96  *
97  * A frontend isn't required to support anything other than the current
98  * version.
99  */
100
101 #define PG_PROTOCOL_MAJOR(v)    ((v) >> 16)
102 #define PG_PROTOCOL_MINOR(v)    ((v) & 0x0000ffff)
103 #define PG_PROTOCOL(m,n)        (((m) << 16) | (n))
104
105 /* The earliest and latest frontend/backend protocol version supported. */
106
107 #define PG_PROTOCOL_EARLIEST    PG_PROTOCOL(1,0)
108 #define PG_PROTOCOL_LATEST              PG_PROTOCOL(3,0)
109
110 typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
111
112 typedef ProtocolVersion MsgType;
113
114
115 /*
116  * Packet lengths are 4 bytes in network byte order.
117  *
118  * The initial length is omitted from the packet layouts appearing below.
119  */
120
121 typedef uint32 PacketLen;
122
123
124 /*
125  * Old-style startup packet layout with fixed-width fields.  This is used in
126  * protocol 1.0 and 2.0, but not in later versions.  Note that the fields
127  * in this layout are '\0' terminated only if there is room.
128  */
129
130 #define SM_DATABASE             64
131 #define SM_USER                 32
132 /* We append database name if db_user_namespace true. */
133 #define SM_DATABASE_USER (SM_DATABASE+SM_USER+1)                /* +1 for @ */
134 #define SM_OPTIONS              64
135 #define SM_UNUSED               64
136 #define SM_TTY                  64
137
138 typedef struct StartupPacket
139 {
140         ProtocolVersion protoVersion;           /* Protocol version */
141         char            database[SM_DATABASE];  /* Database name */
142         /* Db_user_namespace appends dbname */
143         char            user[SM_USER];  /* User name */
144         char            options[SM_OPTIONS];    /* Optional additional args */
145         char            unused[SM_UNUSED];              /* Unused */
146         char            tty[SM_TTY];    /* Tty for debug output */
147 } StartupPacket;
148
149 extern bool Db_user_namespace;
150
151 /*
152  * In protocol 3.0 and later, the startup packet length is not fixed, but
153  * we set an arbitrary limit on it anyway.      This is just to prevent simple
154  * denial-of-service attacks via sending enough data to run the server
155  * out of memory.
156  */
157 #define MAX_STARTUP_PACKET_LENGTH 10000
158
159
160 /* These are the authentication request codes sent by the backend. */
161
162 #define AUTH_REQ_OK                     0       /* User is authenticated  */
163 #define AUTH_REQ_KRB4           1       /* Kerberos V4 */
164 #define AUTH_REQ_KRB5           2       /* Kerberos V5 */
165 #define AUTH_REQ_PASSWORD       3       /* Password */
166 #define AUTH_REQ_CRYPT          4       /* crypt password */
167 #define AUTH_REQ_MD5            5       /* md5 password */
168 #define AUTH_REQ_SCM_CREDS      6       /* transfer SCM credentials */
169
170 typedef uint32 AuthRequest;
171
172
173 /*
174  * A client can also send a cancel-current-operation request to the postmaster.
175  * This is uglier than sending it directly to the client's backend, but it
176  * avoids depending on out-of-band communication facilities.
177  *
178  * The cancel request code must not match any protocol version number
179  * we're ever likely to use.  This random choice should do.
180  */
181 #define CANCEL_REQUEST_CODE PG_PROTOCOL(1234,5678)
182
183 typedef struct CancelRequestPacket
184 {
185         /* Note that each field is stored in network byte order! */
186         MsgType         cancelRequestCode;              /* code to identify a cancel
187                                                                                  * request */
188         uint32          backendPID;             /* PID of client's backend */
189         uint32          cancelAuthCode; /* secret key to authorize cancel */
190 } CancelRequestPacket;
191
192
193 /*
194  * A client can also start by sending a SSL negotiation request, to get a
195  * secure channel.
196  */
197 #define NEGOTIATE_SSL_CODE PG_PROTOCOL(1234,5679)
198
199 #endif   /* PQCOMM_H */