Eneboo - Documentación para desarrolladores
src/libpq/include/libpq/pqcomm.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * pqcomm.h
00004  *              Definitions common to frontends and backends.
00005  *
00006  * NOTE: for historical reasons, this does not correspond to pqcomm.c.
00007  * pqcomm.c's routines are declared in libpq.h.
00008  *
00009  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
00010  * Portions Copyright (c) 1994, Regents of the University of California
00011  *
00012  * $PostgreSQL: pgsql/src/include/libpq/pqcomm.h,v 1.98 2005/10/15 02:49:44 momjian Exp $
00013  *
00014  *-------------------------------------------------------------------------
00015  */
00016 #ifndef PQCOMM_H
00017 #define PQCOMM_H
00018 
00019 #ifdef WIN32
00020 #include <winsock.h>
00021 /* workaround for clashing defines of "ERROR" */
00022 #ifdef ELOG_H
00023 #undef ERROR
00024 #define ERROR   PGERROR
00025 #endif
00026 #else                                                   /* not WIN32 */
00027 #include <sys/socket.h>
00028 #include <netdb.h>
00029 #ifdef HAVE_SYS_UN_H
00030 #include <sys/un.h>
00031 #endif
00032 #include <netinet/in.h>
00033 #endif   /* not WIN32 */
00034 
00035 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
00036 
00037 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
00038 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
00039 #define ss_family __ss_family
00040 #else
00041 #error struct sockaddr_storage does not provide an ss_family member
00042 #endif
00043 #endif
00044 
00045 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
00046 #define ss_len __ss_len
00047 #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
00048 #endif
00049 #else                                                   /* !HAVE_STRUCT_SOCKADDR_STORAGE */
00050 
00051 /* Define a struct sockaddr_storage if we don't have one. */
00052 
00053 struct sockaddr_storage
00054 {
00055         union
00056         {
00057                 struct sockaddr sa;             /* get the system-dependent fields */
00058                 int64           ss_align;       /* ensures struct is properly aligned */
00059                 char            ss_pad[128];    /* ensures struct has desired size */
00060         }                       ss_stuff;
00061 };
00062 
00063 #define ss_family       ss_stuff.sa.sa_family
00064 /* It should have an ss_len field if sockaddr has sa_len. */
00065 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
00066 #define ss_len          ss_stuff.sa.sa_len
00067 #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
00068 #endif
00069 #endif   /* HAVE_STRUCT_SOCKADDR_STORAGE */
00070 
00071 typedef struct
00072 {
00073         struct sockaddr_storage addr;
00074         ACCEPT_TYPE_ARG3 salen;
00075 } SockAddr;
00076 
00077 /* Configure the UNIX socket location for the well known port. */
00078 
00079 #define UNIXSOCK_PATH(path,port,defpath) \
00080                 snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
00081                                 ((defpath) && *(defpath) != '\0') ? (defpath) : \
00082                                 DEFAULT_PGSOCKET_DIR, \
00083                                 (port))
00084 
00085 /*
00086  * These manipulate the frontend/backend protocol version number.
00087  *
00088  * The major number should be incremented for incompatible changes.  The minor
00089  * number should be incremented for compatible changes (eg. additional
00090  * functionality).
00091  *
00092  * If a backend supports version m.n of the protocol it must actually support
00093  * versions m.[0..n].  Backend support for version m-1 can be dropped after a
00094  * `reasonable' length of time.
00095  *
00096  * A frontend isn't required to support anything other than the current
00097  * version.
00098  */
00099 
00100 #define PG_PROTOCOL_MAJOR(v)    ((v) >> 16)
00101 #define PG_PROTOCOL_MINOR(v)    ((v) & 0x0000ffff)
00102 #define PG_PROTOCOL(m,n)        (((m) << 16) | (n))
00103 
00104 /* The earliest and latest frontend/backend protocol version supported. */
00105 
00106 #define PG_PROTOCOL_EARLIEST    PG_PROTOCOL(1,0)
00107 #define PG_PROTOCOL_LATEST              PG_PROTOCOL(3,0)
00108 
00109 typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
00110 
00111 typedef ProtocolVersion MsgType;
00112 
00113 
00114 /*
00115  * Packet lengths are 4 bytes in network byte order.
00116  *
00117  * The initial length is omitted from the packet layouts appearing below.
00118  */
00119 
00120 typedef uint32 PacketLen;
00121 
00122 
00123 /*
00124  * Old-style startup packet layout with fixed-width fields.  This is used in
00125  * protocol 1.0 and 2.0, but not in later versions.  Note that the fields
00126  * in this layout are '\0' terminated only if there is room.
00127  */
00128 
00129 #define SM_DATABASE             64
00130 #define SM_USER                 32
00131 /* We append database name if db_user_namespace true. */
00132 #define SM_DATABASE_USER (SM_DATABASE+SM_USER+1)                /* +1 for @ */
00133 #define SM_OPTIONS              64
00134 #define SM_UNUSED               64
00135 #define SM_TTY                  64
00136 
00137 typedef struct StartupPacket
00138 {
00139         ProtocolVersion protoVersion;           /* Protocol version */
00140         char            database[SM_DATABASE];  /* Database name */
00141         /* Db_user_namespace appends dbname */
00142         char            user[SM_USER];  /* User name */
00143         char            options[SM_OPTIONS];    /* Optional additional args */
00144         char            unused[SM_UNUSED];              /* Unused */
00145         char            tty[SM_TTY];    /* Tty for debug output */
00146 } StartupPacket;
00147 
00148 extern bool Db_user_namespace;
00149 
00150 /*
00151  * In protocol 3.0 and later, the startup packet length is not fixed, but
00152  * we set an arbitrary limit on it anyway.      This is just to prevent simple
00153  * denial-of-service attacks via sending enough data to run the server
00154  * out of memory.
00155  */
00156 #define MAX_STARTUP_PACKET_LENGTH 10000
00157 
00158 
00159 /* These are the authentication request codes sent by the backend. */
00160 
00161 #define AUTH_REQ_OK                     0       /* User is authenticated  */
00162 #define AUTH_REQ_KRB4           1       /* Kerberos V4. Not supported any more. */
00163 #define AUTH_REQ_KRB5           2       /* Kerberos V5 */
00164 #define AUTH_REQ_PASSWORD       3       /* Password */
00165 #define AUTH_REQ_CRYPT          4       /* crypt password */
00166 #define AUTH_REQ_MD5            5       /* md5 password */
00167 #define AUTH_REQ_SCM_CREDS      6       /* transfer SCM credentials */
00168 
00169 typedef uint32 AuthRequest;
00170 
00171 
00172 /*
00173  * A client can also send a cancel-current-operation request to the postmaster.
00174  * This is uglier than sending it directly to the client's backend, but it
00175  * avoids depending on out-of-band communication facilities.
00176  *
00177  * The cancel request code must not match any protocol version number
00178  * we're ever likely to use.  This random choice should do.
00179  */
00180 #define CANCEL_REQUEST_CODE PG_PROTOCOL(1234,5678)
00181 
00182 typedef struct CancelRequestPacket
00183 {
00184         /* Note that each field is stored in network byte order! */
00185         MsgType         cancelRequestCode;              /* code to identify a cancel request */
00186         uint32          backendPID;             /* PID of client's backend */
00187         uint32          cancelAuthCode; /* secret key to authorize cancel */
00188 } CancelRequestPacket;
00189 
00190 
00191 /*
00192  * A client can also start by sending a SSL negotiation request, to get a
00193  * secure channel.
00194  */
00195 #define NEGOTIATE_SSL_CODE PG_PROTOCOL(1234,5679)
00196 
00197 #endif   /* PQCOMM_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'