1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pqcomm.h--
|
1997-09-07 07:04:48 +02:00
|
|
|
* Parameters for the communication module
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
1997-09-08 23:56:23 +02:00
|
|
|
* $Id: pqcomm.h,v 1.14 1997/09/08 21:52:38 momjian Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
1997-09-07 07:04:48 +02:00
|
|
|
* Some of this should move to libpq.h
|
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>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* startup msg parameters: path length, argument string length
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#define PATH_SIZE 64
|
|
|
|
#define ARGV_SIZE 64
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/* The various kinds of startup messages are for the various kinds of
|
1996-10-11 11:12:18 +02:00
|
|
|
user authentication systems. In the beginning, there was only
|
|
|
|
STARTUP_MSG and all connections were unauthenticated. Now, there are
|
1997-09-07 07:04:48 +02:00
|
|
|
several choices of authentication method (the client picks one, but
|
1996-10-11 11:12:18 +02:00
|
|
|
the server needn't necessarily accept it). So now, the STARTUP_MSG
|
|
|
|
message means to start either an unauthenticated or a host-based
|
1997-09-07 07:04:48 +02:00
|
|
|
authenticated connection, depending on what the server prefers. This
|
1996-10-11 11:12:18 +02:00
|
|
|
is possible because the protocol between server and client is the same
|
|
|
|
in both cases (basically, no negotiation is required at all).
|
|
|
|
*/
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef enum _MsgType
|
|
|
|
{
|
|
|
|
ACK_MSG = 0, /* acknowledge a message */
|
|
|
|
ERROR_MSG = 1, /* error response to client from server */
|
|
|
|
RESET_MSG = 2, /* client must reset connection */
|
|
|
|
PRINT_MSG = 3, /* tuples for client from server */
|
|
|
|
NET_ERROR = 4, /* error in net system call */
|
|
|
|
FUNCTION_MSG = 5, /* fastpath call (unused) */
|
|
|
|
QUERY_MSG = 6, /* client query to server */
|
|
|
|
STARTUP_MSG = 7, /* initialize a connection with a backend */
|
|
|
|
DUPLICATE_MSG = 8, /* duplicate msg arrived (errors msg only) */
|
|
|
|
INVALID_MSG = 9, /* for some control functions */
|
|
|
|
STARTUP_KRB4_MSG = 10, /* krb4 session follows startup packet */
|
|
|
|
STARTUP_KRB5_MSG = 11, /* krb5 session follows startup packet */
|
|
|
|
STARTUP_HBA_MSG = 12, /* use host-based authentication */
|
|
|
|
STARTUP_UNAUTH_MSG = 13, /* use unauthenticated connection */
|
|
|
|
STARTUP_PASSWORD_MSG = 14 /* use plaintext password authentication */
|
|
|
|
/* insert new values here -- DO NOT REORDER OR DELETE ENTRIES */
|
|
|
|
/* also change LAST_AUTHENTICATION_TYPE below and add to the */
|
|
|
|
/* authentication_type_name[] array in pqcomm.c */
|
1996-07-09 08:22:35 +02:00
|
|
|
} MsgType;
|
|
|
|
|
1997-03-12 22:23:16 +01:00
|
|
|
#define LAST_AUTHENTICATION_TYPE 14
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
typedef char *Addr;
|
|
|
|
typedef int PacketLen; /* packet length */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct StartupInfo
|
|
|
|
{
|
|
|
|
/* PacketHdr hdr; */
|
1997-09-08 04:41:22 +02:00
|
|
|
char database[PATH_SIZE]; /* database name */
|
|
|
|
char user[NAMEDATALEN]; /* user name */
|
|
|
|
char options[ARGV_SIZE]; /* possible additional args */
|
|
|
|
char execFile[ARGV_SIZE]; /* possible backend to use */
|
|
|
|
char tty[PATH_SIZE]; /* possible tty for debug output */
|
1997-09-08 23:56:23 +02:00
|
|
|
} StartupInfo;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* amount of available data in a packet buffer */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define MESSAGE_SIZE sizeof(StartupInfo) + 5 /* why 5? BJM 2/11/97 */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* I/O can be blocking or non-blocking */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define BLOCKING (FALSE)
|
1996-07-09 08:22:35 +02:00
|
|
|
#define NON_BLOCKING (TRUE)
|
|
|
|
|
|
|
|
/* a PacketBuf gets shipped from client to server so be careful
|
1997-09-07 07:04:48 +02:00
|
|
|
of differences in representation.
|
1996-07-09 08:22:35 +02:00
|
|
|
Be sure to use htonl() and ntohl() on the len and msgtype fields! */
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct PacketBuf
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int len;
|
|
|
|
MsgType msgtype;
|
|
|
|
char data[MESSAGE_SIZE];
|
1997-09-08 23:56:23 +02:00
|
|
|
} PacketBuf;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* update the conversion routines
|
1996-07-09 08:22:35 +02:00
|
|
|
StartupInfo2PacketBuf() and PacketBuf2StartupInfo() (decl. below)
|
|
|
|
if StartupInfo or PacketBuf structs ever change */
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* socket descriptor port
|
|
|
|
* we need addresses of both sides to do authentication calls
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef struct Port
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int sock; /* file descriptor */
|
|
|
|
int mask; /* select mask */
|
|
|
|
int nBytes; /* nBytes read in so far */
|
1997-09-07 07:04:48 +02:00
|
|
|
struct sockaddr_in laddr; /* local addr (us) */
|
|
|
|
struct sockaddr_in raddr; /* remote addr (them) */
|
|
|
|
|
|
|
|
/*
|
1997-09-08 04:41:22 +02:00
|
|
|
* PacketBufId id;
|
1997-09-08 22:59:27 +02:00
|
|
|
*//* id of packet buf currently in use */
|
1997-09-08 04:41:22 +02:00
|
|
|
PacketBuf buf; /* stream implementation (curr pack buf) */
|
1997-09-08 23:56:23 +02:00
|
|
|
} Port;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* invalid socket descriptor */
|
|
|
|
#define INVALID_SOCK (-1)
|
|
|
|
|
|
|
|
#define INVALID_ID (-1)
|
1997-09-07 07:04:48 +02:00
|
|
|
#define MAX_CONNECTIONS 10
|
|
|
|
#define N_PACK_BUFS 20
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* no multi-packet messages yet */
|
1997-09-07 07:04:48 +02:00
|
|
|
#define MAX_PACKET_BACKLOG 1
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define DEFAULT_STRING ""
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern FILE *Pfout,
|
|
|
|
*Pfin;
|
|
|
|
extern int PQAsyncNotifyWaiting;
|
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
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
|
|
|
* prototypes for functions in pqpacket.c
|
|
|
|
*/
|
1997-09-08 23:56:23 +02:00
|
|
|
extern int PacketReceive(Port *port, PacketBuf *buf, char nonBlocking);
|
1997-09-07 07:04:48 +02:00
|
|
|
extern int
|
1997-09-08 23:56:23 +02:00
|
|
|
PacketSend(Port *port, PacketBuf *buf,
|
1997-09-07 07:04:48 +02:00
|
|
|
PacketLen len, char nonBlocking);
|
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/* extern PacketBuf* StartupInfo2PacketBuf(StartupInfo*); */
|
|
|
|
/* extern StartupInfo* PacketBuf2StartupInfo(PacketBuf*); */
|
1997-09-08 04:41:22 +02:00
|
|
|
extern char *name_of_authentication_type(int type);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif /* PQCOMM_H */
|