5 /************************************************************************
9 * Includes for the global database facility (gdb)
11 * Author: Noah Mendelsohn
12 * Copyright: 1986 MIT Project Athena
14 ************************************************************************/
17 * Note: following include may safely be done redundantly, so it doesn't
18 * matter if caller does it too. We need it for fd_set.
20 #include <sys/types.h>
32 #define max(a,b) ((a)>(b)?(a):(b))
36 #define min(a,b) ((a)<(b)?(a):(b))
43 #define howmany(x, y) (((x)+((y)-1))/(y))
46 #define FD_SETSIZE 256
49 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
50 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
51 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
52 #define FD_ZERO(p) bzero(p, sizeof(*(p)))
54 typedef struct fd_set {fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];} fd_set;
57 /* 32-bit type for consistency in data sent across the network */
66 /*----------------------------------------------------------*
70 * This macro is called with a string argument whenever a
71 * fatal error is encounterd. If you re-define this
72 * macro, you can control the disposition of fatal gdb
75 * The gdb library must be recompiled for the change to
76 * take effect. That will have to be fixed sometime.
78 *----------------------------------------------------------*/
80 #define GDB_GIVEUP(errormsg) g_givup(errormsg);
82 /*----------------------------------------------------------*
86 * Round a number up to the next specified boundary.
88 *----------------------------------------------------------*/
90 #define GDB_ROUNDUP(n,b) ((((n)+(b)-1)/(b))*(b))
92 extern int gdb_Options; /* Control optional features */
93 #define GDB_OPT_KEEPALIVE 1
94 extern int gdb_Debug; /* debugging flags are */
96 extern FILE *gdb_log; /* file descriptor for */
97 /* logging gdb output */
101 * connection failure indicator
103 * This variable is used to communicate between gdb_move_data and
104 * g_con_progress without passing an extra parameter through lots
105 * of procedure calls. When set to FALSE, it indicates that the
106 * connection currently being processed has encountered a fatal error
107 * and should be severed.
109 extern int gdb_conok;
110 /************************************************************************
112 * USER IDENTIFICATION
114 * gdb_init puts the user's i.d. and hostname as strings here.
116 ************************************************************************/
118 extern char *gdb_uname; /* user's string name */
119 extern char *gdb_host; /* name of local host */
124 /************************************************************************
129 * Declarations used to control the definition and use of 'types'
130 * as supported by the global database system. Most of the
131 * declarations for 'System Defined Types' will not be of concern
132 * to typical users, with the exception of the type names like
133 * INTEGER_T which are defined below.
135 * In this implementation, user defined types are added
136 * dynamically during execution by calling the appropriate
137 * functions. The define GDB_MAX_TYPES below sets the maximum
138 * total number of types, including both system and user defined,
139 * which the system can support for any one application. When
140 * GDB_MAX_TYPES is changed, the libary must be re-built. Space
141 * for a two dimensional array, with one word for each property
142 * of each possible type, is allocated statically in the library.
144 ************************************************************************/
148 * Maximum number of types we can support, including both system and
152 #define GDB_MAX_TYPES 50
154 typedef int FIELD_TYPE; /* data needed to repre- */
155 /* sent a system or user */
156 /* defined data type */
157 /* This is actualy just */
158 /* a row index in the type */
159 /* definition table */
161 /*----------------------------------------------------------
163 * System defined types
165 * WARNING: Any changes to these type definitions must be
166 * carefully matched with the initializations in the
167 * gdb_i_stype routine in gdb_stype.c. Mistakes in these
168 * tables may be VERY difficult to debug. Be careful!
170 *----------------------------------------------------------*/
173 * Primitive types for ingres data
176 #define INTEGER_T (0)
185 #define TUPLE_DESCRIPTOR_T (4)
187 #define TUPLE_DATA_T (6)
188 #define RELATION_T (7)
191 * Number of system defined types
193 * This will always be equal to one more than index of last system type
196 #define SYSTEM_TYPE_COUNT 8
198 /*----------------------------------------------------------
200 * Type descriptor tables
202 *----------------------------------------------------------*/
207 * Each entry in the type definition table is a union of this form,
208 * which allows us to store a choice of an integer, a function
209 * pointer, or a pointer to a character string.
212 union gdb_prop_union {
213 int i; /* when we want as an */
215 int (*f)(); /* as a function pointer */
216 char *cp; /* character pointer */
217 char *(*cpf)(); /* string function pointer */
220 #define TYPE_PROPERTY_COUNT 8 /* number of properties */
224 * Uses of the type properties. Each type has a set of properties.
225 * Some are integers, some are functions. The defines below descrive
226 * respectively the 0'th,1'st, 2'nd, etc. properties of EACH type.
228 * Note: TYPE_PROPERTY_COUNT (above) must be changed when new properties
229 * are added. For system defined types, bindings for the properties
230 * are done in gdb_i_stype in the gdb_stype.c source file.
233 #define LENGTH_PROPERTY 0 /* integer */
234 #define ALIGNMENT_PROPERTY 1 /* integer */
235 #define NULL_PROPERTY 2 /* function */
236 #define CODED_LENGTH_PROPERTY 3 /* function */
237 #define ENCODE_PROPERTY 4 /* string function */
238 #define DECODE_PROPERTY 5 /* string function */
239 #define FORMAT_PROPERTY 6 /* function */
240 #define NAME_PROPERTY 7 /* char pointer */
245 * Information to describe a single type
248 typedef union gdb_prop_union gdb_type_def[TYPE_PROPERTY_COUNT];
254 * This is the table where the actual definitions for the types are
258 extern gdb_type_def g_type_table[GDB_MAX_TYPES];
259 extern int gdb_n_types; /* number of entries in */
262 /*----------------------------------------------------------
264 * Macros for accessing properties
266 *----------------------------------------------------------*/
268 #define INT_PROPERTY(type, prop) (g_type_table[type][prop].i)
269 #define STR_PROPERTY(type, prop) (g_type_table[type][prop].cp)
270 #define FCN_PROPERTY(type, prop) (*g_type_table[type][prop].f)
273 /************************************************************************
277 * Stuff needed to declare and manage TUPLES, TUPLE_DESCRIPTORS
280 ************************************************************************/
282 /*----------------------------------------------------------
286 *----------------------------------------------------------*/
288 #define GDB_DESC_ID 0x54504400 /* "TPD" */
290 struct tupld_var { /* the variable length */
291 /* stuff in a tuple */
293 char *name; /* string name of field */
294 FIELD_TYPE type; /* type of this field */
295 int offset; /* byte offset of this field */
296 /* relative to first byte of */
297 /* data (not start of whole */
299 int length; /* Length of the actual data */
300 /* for this field. Note that */
301 /* alignment requirements of */
302 /* following field are NOT */
303 /* included in this length */
306 int32 id; /* this should say TPD\0 */
307 int ref_count; /* when this goes to zero, */
308 /* the descriptor may really */
310 int field_count; /* number of fields in */
312 int data_len; /* length of the data in */
313 /* the actual tuple */
314 int str_len; /* length of the strings */
315 /* stored off the end of */
317 struct tupld_var var[1]; /* one of these for each */
318 /* field, but the C compiler */
319 /* won't accept the[] decl, */
320 /* because it's afraid of */
321 /* uncertain length*/
324 typedef struct tupl_desc *TUPLE_DESCRIPTOR; /* use this to declare a */
325 /* tuple descriptor anchor */
327 #define gdb_descriptor_length(num_flds) (sizeof(struct tupl_desc) + ((num_flds)-1) * sizeof(struct tupld_var))
329 /*----------------------------------------------------------
333 * tuple_dat is allocated by the create_tuple routine.
335 * TUPLE may be used in user code to declare a handle
338 *----------------------------------------------------------*/
340 #define GDB_TUP_ID 0x54555000
342 typedef struct tuple_dat *TUPLE; /* handle on a tuple */
345 TUPLE next, prev; /* chain pointers when */
346 /* tuples are linked, as in */
347 /* a relation. Convention is*/
348 /* double linked, circular.*/
349 int32 id; /* should say TUP\0 */
350 TUPLE_DESCRIPTOR desc; /* pointer to the descriptor */
351 char data[1]; /* data goes here, word */
352 /* aligned. Should be [] */
353 /* if compiler would allow */
357 /*----------------------------------------------------------
361 * rel_dat is allocated by the create_relation
364 * RELATION may be used in user code to declare a handle
367 *----------------------------------------------------------*/
369 #define GDB_REL_ID 0x52454c00
372 TUPLE first, last; /* chain pointers to tuples */
373 /* note that first->prev and */
374 /* last->next are both == */
375 /* &rel-dat. Maintenance is */
376 /* simplified by keeping */
377 /* as the first fields in */
378 /* both rel_dat and tuple_dat*/
379 /* a minor non-portability */
380 int32 id; /* should contain REL\0 */
381 TUPLE_DESCRIPTOR desc; /* descriptor for the tuples */
382 /* in this relation. Should */
383 /* == that in each tuple */
387 typedef struct rel_dat *RELATION; /* handle on a relation */
389 /************************************************************************
391 * transport LAYER DECLARATIONS
393 * Declares the state maintenance structures for full duplex
394 * connections with asynchronous transmission capability. Most
395 * users need only know that the type CONNECTION is defined, and
396 * that it may be treated as a pointer for most purposes (i.e. it
397 * is compact, and copying it does not actually copy the connection
400 ************************************************************************/
402 #define GDB_PROTOCOL_VERSION 0x01 /* version of the gdb */
403 /* protocols that we're */
405 #define GDB_STREAM_BUFFER_SIZE 4096 /* amount to read in */
406 /* one chunk from tcp stream*/
407 #define GDB_PORT htons(9425) /* temporary until we use */
408 /* services properly */
409 #define GDB_BIND_RETRY_COUNT 5 /* number of times to */
410 /* retry a bind before */
411 /* giving up. Used when */
412 /* accepting connections */
413 #define GDB_BIND_RETRY_INTERVAL 10 /* Number of seconds to wait */
414 /* between attempts to bind */
415 /* the listening socket */
416 #define GDB_MAX_CONNECTIONS 40 /* maximum number of */
417 /* connections that */
418 /* any one process can */
419 /* control simultaneously */
421 * Circumvent bug in ACIS 4.2 socket support
424 #define GDB_MAX_SOCK_WRITE 2047 /* rt can't do socket */
425 /* writes longer than this */
428 #define GDB_MAX_SOCK_WRITE 0x00ffffff
431 /*----------------------------------------------------------
433 * Declarations for HALF_CONNECTIONS
435 * Each full duplex connection has associated with it
436 * two simplex half-connections, each of which
437 * has its own queue of pending operations. The
438 * following describes the state of a half-connection.
440 *----------------------------------------------------------*/
442 struct half_con_data {
444 * these two must be first to match position in OPERATION
446 struct oper_data *op_q_first; /* first item in q of pending*/
447 /* operations for this */
448 /* half-connection. (chained */
449 /* circularly to half con, */
451 struct oper_data *op_q_last; /* last item in q of pending*/
452 /* operations for this */
454 int status; /* values are of type */
455 /* OPSTATUS. tells whether */
456 /* transmit/receive is */
458 int32 flags; /* bit flags */
459 #define HCON_PROGRESS 0x00000001 /* used by selection */
460 /* routines to detect */
462 #define HCON_LISTEN 0x00000002 /* indicates that this is */
463 /* a special half connection */
464 /* used only for listenting */
465 /* to incoming connection */
467 #define HCON_UNUSED 0x00000004 /* on a one-way connection, */
468 /* this flag marks an unused */
470 #define HCON_PENDING_LISTEN 0x00000008 /* a queued op on this half */
471 /* connection is actually */
472 /* trying to listen */
473 #define HCON_BUSY 0x00000010 /* we are currently making */
474 /* progress on this half */
475 /* connection. Used to */
476 /* detect re-entrance of */
478 int fd; /* main half duplex file */
479 /* descriptor for this h_conn*/
480 int oob_fd; /* file descriptor for */
481 /* out of band signals*/
482 char *next_byte; /* next byte to send/recv */
483 int remaining; /* number of bytes remaining */
484 /* to send/receive */
485 char *stream_buffer; /* points to a buffer */
486 /* used to pre-read/write */
487 /* the stream to avoid */
488 /* window thrashing */
489 int stream_buffer_length; /* length of the stream */
491 char *stream_buffer_next; /* next byte to read in */
493 int stream_buffer_remaining; /* number of bytes currently */
494 /* in use in stream buffer*/
495 int *accepted_fdp; /* used only for listening */
496 /* connections. latest */
497 /* accepted fd is put where*/
499 int *accepted_len; /* ptr to length of 'from' */
504 typedef struct half_con_data *HALF_CONNECTION;
507 /*----------------------------------------------------------
509 * Declarations for CONNECTIONS
511 *----------------------------------------------------------*/
513 #define GDB_CON_ID 0x434f4e00 /*"CON"*/
516 int32 id; /* should contain CON\0 */
517 int status; /* See definitions below. */
518 /* Do not confuse with */
519 /* the status sub-fields of */
520 /* in and out half-cons. */
521 int version; /* the version of the */
522 /* protocol being observed */
523 /* on this connection */
524 int errno; /* the real errno gets */
525 /* copied here if it causes */
526 /* the connection to die */
527 int (*oob_fcn)(); /* pointer to function to */
528 /* call when something */
529 /* arrives on the out of */
531 struct half_con_data in, out; /* states of the inbound */
532 /* and outbound half */
536 typedef struct con_data *CONNECTION; /* the only externally */
537 /* visible handle on a */
541 * Definitions of status fields.
543 * WARNING: If you change any of the following, there are coordinated
544 * changes to be made in gdb_debug.c
547 #define CON_STOPPED 1 /* never started, terminated */
548 #define CON_UP 2 /* ready to use */
549 #define CON_STARTING 3 /* trying to start */
550 #define CON_STOPPING 4 /* trying to stop */
553 * The following are used as keywords when distinguishing input from output
556 #define CON_INPUT 1 /* this is an input half */
558 #define CON_OUTPUT 2 /* this is an output half */
562 /*----------------------------------------------------------
566 * This is the array of connection control data
567 * structures for gdb. Every connection has its
568 * structure stored here, but they are in no
569 * particular order. Because the connection data
570 * itself cannot be moved (due to possible dangling
571 * pointers), there may be some unused connections
572 * in the middle of this array. gdb_mcons is the
573 * 1 based number of the highest connection which is
574 * actually in use at this time. This is a considerable
575 * optimization for the typical case where very few
576 * are in use, and turnover is low.
578 * These are externs for globals defined in gdb_lib.h
579 * and included by gdb.c.
581 *----------------------------------------------------------*/
583 extern int gdb_mcons; /* one based number of the */
584 /* highest connection */
585 /* descriptor we're using */
588 extern int gdb_mfd; /* number of the highest */
589 /* file descriptor in use */
590 /* for a connection */
591 extern struct con_data gdb_cons[GDB_MAX_CONNECTIONS];
592 /* actual connection data */
595 extern fd_set gdb_crfds, gdb_cwfds, gdb_cefds; /* connection related file */
596 /* descriptor maps to be */
598 extern fd_set last_crfds, last_cwfds, last_cefds;/* these file desc. bit */
599 /* masks are set up */
600 /* for each select call */
601 /* to include the user */
602 /* supplied and the */
603 /* connection related */
606 /*----------------------------------------------------------
610 *----------------------------------------------------------*/
612 #define GDB_OP_ID 0x4f505200
615 struct oper_data *next, *prev; /* forward and back chain */
616 int32 id; /* should contain OPR\0 */
617 int tag; /* unique identifier for */
619 int status; /* current state of this */
622 #define OPF_MARKED_COMPLETE 0x00000001 /* operation was already */
623 /* complete when opsel was */
625 #define OPF_MARKED_CANCELLED 0x00000002 /* operation was already */
626 /* cancelled when opsel was */
628 int result; /* when the operation */
629 /* completes, this field is */
630 /* set to reflect its dispos-*/
631 /* ition. Contents of this */
632 /* field will depend on the */
633 /* operation being performed */
634 HALF_CONNECTION halfcon; /* the half connection on */
635 /* which this operation is */
637 /* May be meaningless if not */
639 char *arg; /* pointer to user data */
641 int (*init)(); /* pointer to routine to */
642 /* call to start this */
645 int (*cont)(); /* pointer to function to */
646 /* be called when this */
647 /* logical operation */
651 int (*cancel)(); /* this routine gets called */
652 /* to handle a cancel request*/
653 /* this field is normally */
654 /* set to NULL when the */
655 /* operation is queued and */
656 /* updated as required by */
657 /* the init and cont funcs. */
660 typedef struct oper_data OPERATION_DATA; /* an actual operation */
661 /* descritor, creator is */
662 /* responsible for making */
663 /* sure that memory is not */
664 /* freed while in use */
665 typedef OPERATION_DATA *OPERATION; /* a handle on an operation */
666 /* this is what most */
667 /* applications will use */
669 /*----------------------------------------------------------
671 * STATES OF AN OPERATION
673 * These represent the state of an asynchronous, queued
674 * operation. For convenience of the application programmer,
675 * some of these are folded together when queried through the
676 * operation_status routine. In particular, operation status
677 * returns only one of:
679 * OP_NOT_RUNNING, OP_RUNNING, OP_COMPLETE, or
682 * Any other status is reported as OP_RUNNING. This is
683 * done on the assumption that it makes correct coding
684 * of applications less error-prone, as there are fewer
685 * cases to check, and most of them would not be of
688 * Note that OP_CANCELLED may be generated by the system
689 * even when no explicit request for cancellation has been
690 * issued. For example, this may occur when a connection
691 * is severed unexpectedly.
693 * WARNING: If you change any of the following, be sure
694 * to make the equivalent changes to gdb_debug.c.
696 * We also define here certain standard values of OP_RESULT,
697 * since some return conventions presume that op_status
698 * and op_result values are orthogonal.
700 *----------------------------------------------------------*/
702 #define OP_SUCCESS 0 /* this value is actually */
703 /* used only in result */
704 /* fields, but it is */
705 /* sometimes convenient to */
706 /* have status and result */
707 /* have orthogonal values */
708 #define OP_NOT_STARTED 1 /* this operation has been */
709 /* initialized but is not on */
710 /* any connection's queue */
711 #define OP_QUEUED 2 /* this operation is on */
712 /* some connection's queue */
713 /* but it has not yet */
714 /* reached the head of the q */
715 #define OP_RUNNING 3 /* op is at head of q trying */
717 #define OP_COMPLETE 4 /* operation has run to */
718 /* completion. result field */
720 #define OP_CANCELLING 5 /* we are in the process of */
721 /* (trying to) cancel this */
723 #define OP_CANCELLED 6 /* operation was prematurely */
724 /* terminated. result field */
726 #define OP_MARKED 7 /* used by op_select_all */
727 #define OP_REQUEUED 8 /* returned by an init or */
728 /* continuation routine to */
729 /* indicate that the */
730 /* operation has requeued */
732 #define OP_PREEMPTED 9 /* returned by an init or */
733 /* continuation routine to */
734 /* indicate that the op has */
735 /* preempted itself by */
736 /* queueing a new operation */
737 /* ahead of itself */
739 /*----------------------------------------------------------
743 *----------------------------------------------------------*/
746 int count; /* number of operations */
748 OPERATION op[1]; /* really op[n], but */
749 /* structs must have a */
750 /* definite length */
753 typedef struct oper_list *LIST_OF_OPERATIONS; /* handle on a list */
755 #define size_of_list_of_operations(n) \
756 (sizeof(struct oper_list) + (n-1)*sizeof(OPERATION))
758 /*----------------------------------------------------------
762 * Pass this to select when doing a poll.
764 *----------------------------------------------------------*/
766 extern struct timeval gdb_notime;
769 /************************************************************************
771 * CHECKING ROUTINES IMPLEMENTED AS MACROS
773 ************************************************************************/
775 extern char g_errstr[150]; /* build emsgs here */
777 #define GDB_INIT_CHECK g_chk_init(); /* make sure gdb_init */
780 #define GDB_CHECK_CON(con, where) if ((con)->id != GDB_CON_ID) \
781 { (void) sprintf(g_errstr, "Invalid connection descriptor passed to \"%s\"\n", where); \
782 GDB_GIVEUP(g_errstr) }
785 #define GDB_CHECK_TUP(tup, where) if ((tup)->id != GDB_TUP_ID) \
786 { (void) sprintf(g_errstr, "Invalid tuple passed to \"%s\"\n", where); \
787 GDB_GIVEUP(g_errstr) }
790 #define GDB_CHECK_TPD(tpd, where) if ((tpd)->id != GDB_DESC_ID) \
791 { (void) sprintf(g_errstr, "Invalid tuple descriptor passed to \"%s\"\n", where); \
792 GDB_GIVEUP(g_errstr) }
795 #define GDB_CHECK_REL(rel, where) if ((rel)->id != GDB_REL_ID) \
796 { (void) sprintf(g_errstr, "Invalid relation passed to \"%s\"\n", where); \
797 GDB_GIVEUP(g_errstr) }
799 #define GDB_CHECK_OP(op, where) if ((op)->id != GDB_OP_ID) \
800 { (void) sprintf(g_errstr, "Invalid operation passed to \"%s\"\n", where); \
801 GDB_GIVEUP(g_errstr) }
803 #define GDB_CHECK_DB(db, where) if (db->id != GDB_DB_ID) \
804 { (void) sprintf(g_errstr, "Invalid database handle passed to \"%s\"\n", where); \
805 GDB_GIVEUP(g_errstr) }
810 /************************************************************************
812 * TRANSPORT ROUTINES IMPLEMENTED AS MACROS
814 ************************************************************************/
816 /*----------------------------------------------------------
820 * Returns the status of the indicated connection.
821 * Possible return values are:
823 * CON_STOPPED never started or terminated
824 * CON_UP currently usable
825 * CON_STARTING transient state on way up
826 * CON_STOPPING transient state on way down
828 *----------------------------------------------------------*/
830 #define connection_status(con) ((con)->status)
832 /*----------------------------------------------------------
836 * When a connection dies due to an error on a system
837 * call, the corresponding errno is recorded in the
838 * connection descriptor. This macro returns that value.
840 *----------------------------------------------------------*/
842 #define connection_errno(con) ((con)->errno)
846 /************************************************************************
848 * SERVER/CLIENT MANAGEMENT
850 * Definitions used in starting and maintaining communication
851 * between servers and clients (as opposed to peers.)
853 ************************************************************************/
855 #define GDB_MAX_SERVER_RETRIES 3 /* maximum number of times */
856 /* clients will accept */
857 /* forwarding requests from */
861 extern TUPLE_DESCRIPTOR gdb_tosrv; /* descriptor for request */
862 /* tuples sent to the */
863 /* server during negotiation*/
865 extern TUPLE_DESCRIPTOR gdb_fmsrv; /* descriptor for request */
866 /* tuples sent from the */
867 /* server during negotiation*/
869 #define GDB_MAX_SERVER_ID_SIZE 255 /* longest name of a server */
870 /* that we can handle */
871 #define GDB_MAX_SERVER_PARMS_SIZE 1023 /* longest parm string we */
872 /* can exchange between */
873 /* server and client*/
875 /*----------------------------------------------------------
877 * The following are values returned in the disposition
878 * field of the response tuple to indicate what the
879 * server has decided to do about the connection
882 *----------------------------------------------------------*/
884 #define GDB_ACCEPTED 1
885 #define GDB_REFUSED 2
886 #define GDB_FORWARDED 3
888 /*----------------------------------------------------------
890 * Global variables inherited by a child from a server
893 *----------------------------------------------------------*/
895 extern TUPLE gdb_client_tuple; /* request tuple sent from */
898 extern char gdb_sockaddr_of_client[100]; /* this should really be */
899 /* sockaddr_in, but I don't */
900 /* want everyone to have */
901 /* to include all those */
903 extern int gdb_socklen; /* length of above */
907 /************************************************************************
909 * DATABASE MANAGEMENT
911 * This layer of GDB provides access to the services of a relational
912 * database from anywhere in a GDB network.
914 ************************************************************************/
916 /*----------------------------------------------------------
920 * The name of the service, as found in /etc/services,
921 * for GDB database servers.
923 *----------------------------------------------------------*/
925 #define GDB_DB_SERVICE "#9420"
927 /*----------------------------------------------------------
931 * Describes a client's active connection to a database.
933 *----------------------------------------------------------*/
935 #define GDB_DB_ID 0x44420000 /* eye catcher */
938 int32 id; /* eye catcher */
939 CONNECTION connection; /* the GDB connection */
940 /* used to get at this */
942 int status; /* status of this */
943 /* database connection */
944 #define DB_OPEN 1 /* database opened */
946 #define DB_CLOSED 2 /* not open */
947 char *name; /* pointer to string name */
948 /* of the database, for */
950 char *server; /* pointer to the i.d. */
951 /* of the server, for */
955 typedef struct db_struct *DATABASE;
957 /*----------------------------------------------------------
959 * Return codes from DB operations
961 *----------------------------------------------------------*/
963 #define DB_NO_SUCH_OP 3
965 /*----------------------------------------------------------
967 * Parameters which limit sizes of things
969 *----------------------------------------------------------*/
971 #define GDB_MAX_QUERY_SIZE 2048 /* length of the longest */
972 /* substituted query */
973 /* string we can make */
974 #define GDB_MAX_QUERY_FIELDS 100 /* maximum number of fields */
975 /* we can retrieve in one */
977 #define GDB_SIZE_OF_INGRES_TEXT 2001 /* number of chars in */
978 /* largest ingres text */
980 #define GDB_MAX_RETRIEVED_TEXT_FIELDS 60 /* maximum number of text */
981 /* type fields we can */
982 /* retrieve in a single */
983 /* query. we hold this */
984 /* down because stack space */
985 /* is taken for max size of */
986 /* each during query. */
988 /*----------------------------------------------------------
990 * Return codes from database operations
992 *----------------------------------------------------------*/
994 #define DB_PARSE_FAIL (-3) /* couldn't parse */
995 /* the request string*/
998 /************************************************************************
1000 * DATABASE OPERATIONS IMPLEMENTED
1003 ************************************************************************/
1005 /*----------------------------------------------------------
1009 *----------------------------------------------------------*/
1011 #define DB_STATUS(dbhandle) ((dbhandle)->status)
1016 /************************************************************************
1020 * To allow dynamic manipulation of strings in gdb without
1021 * excessive memory re-allocation, we define a string as a
1022 * counted byte space. Though this space will frequently be used
1023 * to store a standard null terminated string, that is not
1026 * Current representation for a string is a pointer followed by
1027 * an integer length. A null pointer indicates a null string, in
1028 * which case the length is arbitrary. Any other pointer is to
1029 * memory which was allocated by db_alloc in which must be free'd
1030 * eventually with db_free.
1032 ************************************************************************/
1034 typedef struct str_dat {
1035 char *ptr; /* pointer to the data */
1036 int length; /* length of the allocated */
1037 /* memory (not necessarily */
1038 /* length of null-term'd */
1039 /* string stored there) */
1042 /*----------------------------------------------------------
1044 * Macros for manipulating strings. These return
1045 * the actual data from the string and the size of
1046 * the data space respectively. To get the length of
1047 * the null terminated string which might be stored
1048 * there, use strlen(STRING_DATA(string)).
1050 *----------------------------------------------------------*/
1053 #define STRING_DATA(str) ((str).ptr)
1054 #define MAX_STRING_SIZE(str) ((str).length)
1057 /************************************************************************
1061 * db_alloc and db_free are the externally visible names of
1062 * the memory allocation services. These actually call the
1063 * routines pointed to by the vectors gdb_amv and gdb_fmv, which
1064 * default to the supplied routines gdb_am and gdb_fm. Users
1065 * may supply their own memory allocation by storing over the
1066 * vectors. This may be done prior to calling gdb_init to
1067 * insure that all dynamic memory is controlled by the user.
1069 ************************************************************************/
1071 #define db_alloc (*gdb_amv)
1072 #define db_free (*gdb_fmv)
1074 extern char *gdb_am();
1075 extern int gdb_fm();
1077 extern char *((*gdb_amv)());
1078 extern int (*gdb_fmv)();
1081 /************************************************************************
1083 * STRUCTURED DATA ROUTINES IMPLEMENTED AS MACROS
1085 ************************************************************************/
1087 /*----------------------------------------------------------
1089 * ADD_TUPLE_TO_RELATION
1091 *----------------------------------------------------------*/
1093 #define ADD_TUPLE_TO_RELATION(relation, tuple) \
1095 (tuple)->prev = (relation)->last; \
1096 (tuple)->next = (TUPLE)(relation); \
1097 (relation)->last = tuple; \
1098 (tuple)->prev->next = tuple; \
1101 /*----------------------------------------------------------
1103 * ADD_TUPLE_AFTER_TUPLE
1105 *----------------------------------------------------------*/
1107 #define ADD_TUPLE_AFTER_TUPLE(relation, tuple, prev_tuple) \
1109 (tuple)->prev = (prev_tuple)->next->prev; \
1110 (tuple)->next = (prev_tuple)->next; \
1111 (tuple)->next->prev = tuple; \
1112 (prev_tuple)->next = tuple; \
1115 /*----------------------------------------------------------
1117 * REMOVE_TUPLE_FROM_RELATION
1119 *----------------------------------------------------------*/
1121 #define REMOVE_TUPLE_FROM_RELATION(relation, tuple) \
1123 (tuple)->prev->next = (tuple)->next; \
1124 (tuple)->next->prev = (tuple)->prev; \
1128 /*----------------------------------------------------------
1130 * DESCRIPTOR_FROM_TUPLE
1132 *----------------------------------------------------------*/
1134 #define DESCRIPTOR_FROM_TUPLE(tuple) ((tuple)->desc)
1136 /*----------------------------------------------------------
1138 * DESCRIPTOR_FROM_RELATION
1140 *----------------------------------------------------------*/
1142 #define DESCRIPTOR_FROM_RELATION(relation) ((relation)->desc)
1144 /*----------------------------------------------------------
1146 * REFERENCE_TUPLE_DESCRIPTOR
1148 * Bumps the reference count for a tuple descriptor.
1149 * Intended only for internal use of GDB.
1151 *----------------------------------------------------------*/
1153 #define REFERENCE_TUPLE_DESCRIPTOR(tpd) (++((tpd)->ref_count))
1155 /*----------------------------------------------------------
1157 * UNREFERENCE_TUPLE_DESCRIPTOR
1159 * Decrements the reference count for a tuple descriptor.
1160 * Intended only for internal use of GDB. Warning: it
1161 * is the user's responsibility to use delete_tuple_descriptor
1162 * instead of this macro in any situation in which the
1163 * reference count might go to zero.
1165 *----------------------------------------------------------*/
1167 #define UNREFERENCE_TUPLE_DESCRIPTOR(tpd) (--((tpd)->ref_count))
1169 /*----------------------------------------------------------
1173 *----------------------------------------------------------*/
1175 #define FIELD_FROM_TUPLE(tuple, field_index) \
1176 (((tuple)->data) + (((tuple)->desc)->var[field_index].offset))
1178 /*----------------------------------------------------------
1180 * FIELD_OFFSET_IN_TUPLE
1182 *----------------------------------------------------------*/
1184 #define FIELD_OFFSET_IN_TUPLE(tuple_descriptor, field_index) \
1185 ((tuple_descriptor)->var[field_index].offset)
1187 /*----------------------------------------------------------
1189 * FIELD_TYPE_IN_TUPLE
1191 *----------------------------------------------------------*/
1193 #define FIELD_TYPE_IN_TUPLE(tuple_descriptor, field_index) \
1194 ((tuple_descriptor)->var[field_index].type)
1196 /*----------------------------------------------------------
1198 * FIRST_TUPLE_IN_RELATION
1200 *----------------------------------------------------------*/
1202 #define FIRST_TUPLE_IN_RELATION(relation) \
1203 (((relation)->first) == (TUPLE)relation ? NULL : (relation)-> first)
1205 /*----------------------------------------------------------
1207 * NEXT_TUPLE_IN_RELATION
1209 *----------------------------------------------------------*/
1211 #define NEXT_TUPLE_IN_RELATION(relation, prev) \
1212 (((prev)->next) == (TUPLE)relation ? NULL : prev->next )
1214 /*----------------------------------------------------------
1216 * PREV_TUPLE_IN_RELATION
1218 *----------------------------------------------------------*/
1220 #define PREV_TUPLE_IN_RELATION(relation, next) \
1221 (((next)->prev) == (TUPLE) relation ? NULL : next->prev)
1226 /************************************************************************
1228 * TRANSPORT and OPERATION SERVICES IMPLEMENTED AS MACROS
1230 ************************************************************************/
1232 /*----------------------------------------------------------
1234 * OPERATION_FROM_DATA
1236 * Given OPERATION_DATA, return the corresponding handle
1237 * of type OPERATION. Currently, OPERATION is just
1238 * implemented as a pointer to OPERATION_DATA.
1240 *----------------------------------------------------------*/
1242 #define OPERATION_FROM_DATA(op_data) \
1243 ((OPERATION)&(op_data))
1245 /*----------------------------------------------------------
1249 * Return the tag for a given operation.
1251 *----------------------------------------------------------*/
1253 #define OP_TAG(operation) ((operation)->tag)
1255 /*----------------------------------------------------------
1259 * Return the status of a given operation. Note that
1260 * status describes an operations progress through
1261 * execution. It has the same values for all operations.
1262 * Result describes the final outcome of an operation.
1263 * It's values depend on the particular operation which
1266 *----------------------------------------------------------*/
1268 #define OP_STATUS(operation) ((operation)->status)
1270 /*----------------------------------------------------------
1274 * True iff the operation is either OP_COMPLETE or
1277 *----------------------------------------------------------*/
1279 #define OP_DONE(op) ((op)->status == OP_COMPLETE || (op)->status == OP_CANCELLED)
1281 /*----------------------------------------------------------
1285 * Return the result of a given operation. Note that
1286 * status describes an operations progress through
1287 * execution. It has the same values for all operations.
1288 * Result describes the final outcome of an operation.
1289 * It's values depend on the particular operation which
1290 * was attempted. The special result value -1 is used
1291 * to indicate an invalid value for result. Generally,
1292 * -1 is returned when result is accidently queried at
1293 * a time when OP_STATUS != OPERATION_COMPLETE.
1295 *----------------------------------------------------------*/
1297 #define OP_RESULT(operation) ((operation)->result)
1300 /************************************************************************
1302 * Debugging Interfaces
1304 ************************************************************************/
1306 /*----------------------------------------------------------
1308 * The following operation codes my be passed to
1309 * gdb_debug to set special debugging modes of operation.
1311 * Note that most of these are toggles
1313 *----------------------------------------------------------*/
1315 #define GDB_LOG 0x00000001 /* turn on tracing to */
1317 #define GDB_NOFORK 0x00000002 /* don't fork forking */
1321 /************************************************************************
1323 * Things which have to be at the end because they require
1324 * the various types to be defined first.
1326 ************************************************************************/
1329 #ifdef DUMB_7_CHAR_LOADER
1330 /*----------------------------------------------------------
1332 * Long Names for Routines
1334 * External names in Unix must generally be unique
1335 * within the first 7 characters or so, at least for
1336 * some versions of ld. To account for this without
1337 * making all our routine names terribly short and
1338 * cryptic, we use the following defines.
1340 *----------------------------------------------------------*/
1342 #define string_alloc gdb_sta
1343 #define string_free gdb_stf
1345 #define create_tuple_descriptor gdb_ctd
1346 #define delete_tuple_descriptor gdb_dtd
1347 #define field_index gdb_fi
1348 #define create_tuple gdb_ctup
1349 #define delete_tuple gdb_dtup
1350 #define initialize_tuple gdb_itup
1351 #define null_tuple_strings gdb_ntps
1353 #define create_relation gdb_crel
1354 #define delete_relation gdb_drel
1355 #define tuples_in_relation gdb_trel
1361 #define create_operation gdb_crop
1362 #define delete_operation gdb_dop
1363 #define initialize_operation gdb_inop
1364 #define reset_operation gdb_rsop
1365 #define cancel_operation gdb_cnop
1367 #define create_list_of_operations gdb_clop
1368 #define delete_list_of_operations gdb_dlop
1370 #define op_select gdb_opsel
1371 #define op_select_any gdb_opsel
1372 #define op_select_all gdb_aopsel
1373 #define con_select gdb_cnsel
1375 #define gdb_receive_data gdb_rcdat
1376 #define gdb_send_data gdb_sndat
1377 #define gdb_start_listening gdb_stl
1378 #define start_accepting_client gdb_stac
1381 #define gdb_listen gdb_lis
1384 * Connection management
1386 #define start_peer_connection gdb_spconn
1387 #define sever_connection gdb_svconn
1388 #define start_server_connection gdb_stsrv
1389 #define create_listening_connection gdb_clc
1390 #define start_replying_to_client gdb_strtc
1391 #define create_forking_server gdb_cfs
1395 * Asynchronous operations
1397 #define start_sending_object gdb_snobj
1398 #define start_receiving_object gdb_rcobj
1399 #define preempt_and_start_receiving_object gdb_prcobj
1401 #define queue_operation gdb_qop
1403 #define requeue_operation g_req_op
1405 #define complete_operation gdb_cmpo
1407 * Synchronous operations
1409 #define send_object gdb_sobj
1410 #define receive_object gdb_robj
1412 * Database operations
1414 #define access_db gdb_adb
1415 #define start_accessing_db gdb_sadb
1416 #define perform_db_operation gdb_pdbo
1417 #define db_query gdb_dbq
1418 #define start_performing_db_operation gdb_spdb
1419 #define start_db_query gdb_sdbq
1421 #define op_select_any op_select
1422 #endif /* DUMB_7_CHAR_LOADER */
1424 extern char *string_alloc();
1425 extern int string_free();
1426 extern TUPLE_DESCRIPTOR create_tuple_descriptor();
1427 extern int delete_tuple_descriptor();
1428 extern int field_index();
1429 extern TUPLE create_tuple();
1430 extern int delete_tuple();
1431 extern int initialize_tuple();
1432 extern int null_tuple_strings();
1433 extern RELATION create_relation();
1434 extern int delete_relation();
1435 extern OPERATION create_operation();
1436 extern LIST_OF_OPERATIONS create_list_of_operations();
1437 extern OPERATION g_op_newhead();
1438 extern CONNECTION start_peer_connection();
1439 extern CONNECTION sever_connection();
1440 extern CONNECTION start_server_connection();
1441 extern CONNECTION create_listening_connection();
1442 extern CONNECTION create_forking_server();
1443 extern int start_sending_object();
1444 extern int start_receiving_object();
1445 extern int preempt_and_start_receiving_object();
1446 extern int queue_operation();
1447 extern int requeue_operation();
1448 extern int complete_operation();
1449 extern int send_object();
1450 extern int receive_object();
1453 /*----------------------------------------------------------
1455 * Other routines requiring extern to avoid forward
1456 * reference to non integer type functions.
1458 *----------------------------------------------------------*/
1460 extern CONNECTION g_make_con();