1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pqcomm.h--
|
1998-02-26 05:46:47 +01:00
|
|
|
* Definitions common to frontends and backends.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1998-03-02 06:42:15 +01:00
|
|
|
* $Id: pqcomm.h,v 1.24 1998/03/02 05:42:15 scrappy Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef PQCOMM_H
|
1997-09-07 07:04:48 +02:00
|
|
|
#define PQCOMM_H
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1996-10-23 09:42:13 +02:00
|
|
|
#include <stdio.h>
|
1996-07-09 08:22:35 +02:00
|
|
|
#include <sys/types.h>
|
1998-01-26 02:42:53 +01:00
|
|
|
#include <sys/socket.h>
|
1997-11-07 21:52:15 +01:00
|
|
|
#include <sys/un.h>
|
1998-01-26 02:42:53 +01:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include "c.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Define a generic socket address type. */
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
typedef union SockAddr
|
|
|
|
{
|
|
|
|
struct sockaddr sa;
|
|
|
|
struct sockaddr_in in;
|
|
|
|
struct sockaddr_un un;
|
1998-01-26 02:42:53 +01:00
|
|
|
} SockAddr;
|
|
|
|
|
|
|
|
|
|
|
|
/* Configure the UNIX socket address for the well known port. */
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
#define UNIXSOCK_PATH(sun,port) \
|
1998-03-02 06:42:15 +01:00
|
|
|
(sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)), \
|
|
|
|
strlen((sun).sun_path)+ offsetof(struct sockaddr_un, sun_path))
|
|
|
|
|
1998-01-27 16:35:30 +01:00
|
|
|
/*
|
1998-01-28 03:29:40 +01:00
|
|
|
* We do this because sun_len is in BSD's struct, while others don't.
|
|
|
|
* We never actually set BSD's sun_len, and I can't think of a
|
1998-01-27 16:35:30 +01:00
|
|
|
* platform-safe way of doing it, but the code still works. bjm
|
|
|
|
*/
|
1998-01-26 02:42:53 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These manipulate the frontend/backend protocol version number.
|
|
|
|
*
|
|
|
|
* The major number should be incremented for incompatible changes. The minor
|
|
|
|
* number should be incremented for compatible changes (eg. additional
|
|
|
|
* functionality).
|
|
|
|
*
|
|
|
|
* If a backend supports version m.n of the protocol it must actually support
|
|
|
|
* versions m.0..n]. Backend support for version m-1 can be dropped after a
|
|
|
|
* `reasonable' length of time.
|
|
|
|
*
|
|
|
|
* A frontend isn't required to support anything other than the current
|
|
|
|
* version.
|
|
|
|
*/
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
#define PG_PROTOCOL_MAJOR(v) ((v) >> 16)
|
|
|
|
#define PG_PROTOCOL_MINOR(v) ((v) & 0x0000ffff)
|
|
|
|
#define PG_PROTOCOL(m,n) (((m) << 16) | (n))
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-01-26 02:42:53 +01:00
|
|
|
/* The earliest and latest frontend/backend protocol version supported. */
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
#define PG_PROTOCOL_EARLIEST PG_PROTOCOL(0,0)
|
|
|
|
#define PG_PROTOCOL_LATEST PG_PROTOCOL(1,0)
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/*
|
1998-01-26 02:42:53 +01:00
|
|
|
* All packets sent to the postmaster start with the length. This is omitted
|
|
|
|
* from the different packet definitions specified below.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
|
1998-01-26 02:42:53 +01:00
|
|
|
typedef uint32 PacketLen;
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
1998-01-26 02:42:53 +01:00
|
|
|
* Startup message parameters sizes. These must not be changed without changing
|
|
|
|
* the protcol version. These are all strings that are '\0' terminated only if
|
|
|
|
* there is room.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-01-26 02:42:53 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
#define SM_DATABASE 64
|
|
|
|
#define SM_USER 32
|
|
|
|
#define SM_OPTIONS 64
|
|
|
|
#define SM_UNUSED 64
|
|
|
|
#define SM_TTY 64
|
1998-01-26 02:42:53 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
typedef uint32 ProtocolVersion; /* Fe/Be protocol version nr. */
|
1998-01-26 02:42:53 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
typedef struct StartupPacket
|
|
|
|
{
|
|
|
|
ProtocolVersion protoVersion; /* Protocol version */
|
1998-01-26 02:42:53 +01:00
|
|
|
char database[SM_DATABASE]; /* Database name */
|
1998-02-26 05:46:47 +01:00
|
|
|
char user[SM_USER]; /* User name */
|
1998-01-26 02:42:53 +01:00
|
|
|
char options[SM_OPTIONS]; /* Optional additional args */
|
1998-02-26 05:46:47 +01:00
|
|
|
char unused[SM_UNUSED]; /* Unused */
|
|
|
|
char tty[SM_TTY]; /* Tty for debug output */
|
1998-01-26 02:42:53 +01:00
|
|
|
} StartupPacket;
|
|
|
|
|
|
|
|
|
|
|
|
/* These are the authentication requests sent by the backend. */
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
#define AUTH_REQ_OK 0 /* User is authenticated */
|
|
|
|
#define AUTH_REQ_KRB4 1 /* Kerberos V4 */
|
|
|
|
#define AUTH_REQ_KRB5 2 /* Kerberos V5 */
|
|
|
|
#define AUTH_REQ_PASSWORD 3 /* Password */
|
|
|
|
#define AUTH_REQ_CRYPT 4 /* Encrypted password */
|
1998-01-26 02:42:53 +01:00
|
|
|
|
|
|
|
typedef uint32 AuthRequest;
|
|
|
|
|
|
|
|
|
|
|
|
/* This next section is to maintain compatibility with protocol v0.0. */
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
#define STARTUP_MSG 7 /* Initialise a connection */
|
|
|
|
#define STARTUP_KRB4_MSG 10 /* krb4 session follows */
|
|
|
|
#define STARTUP_KRB5_MSG 11 /* krb5 session follows */
|
|
|
|
#define STARTUP_PASSWORD_MSG 14 /* Password follows */
|
1998-01-26 02:42:53 +01:00
|
|
|
|
|
|
|
typedef ProtocolVersion MsgType;
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-03-16 19:51:29 +01:00
|
|
|
/* in pqcompriv.c */
|
1997-09-08 04:41:22 +02:00
|
|
|
int pqGetShort(int *, FILE *);
|
|
|
|
int pqGetLong(int *, FILE *);
|
|
|
|
int pqGetNBytes(char *, size_t, FILE *);
|
|
|
|
int pqGetString(char *, size_t, FILE *);
|
|
|
|
int pqGetByte(FILE *);
|
|
|
|
|
|
|
|
int pqPutShort(int, FILE *);
|
|
|
|
int pqPutLong(int, FILE *);
|
|
|
|
int pqPutNBytes(const char *, size_t, FILE *);
|
|
|
|
int pqPutString(const char *, FILE *);
|
|
|
|
int pqPutByte(int, FILE *);
|
1997-03-20 19:23:33 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif /* PQCOMM_H */
|