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;
59 /*----------------------------------------------------------*
63 * This macro is called with a string argument whenever a
64 * fatal error is encounterd. If you re-define this
65 * macro, you can control the disposition of fatal gdb
68 * The gdb library must be recompiled for the change to
69 * take effect. That will have to be fixed sometime.
71 *----------------------------------------------------------*/
73 #define GDB_GIVEUP(errormsg) g_givup(errormsg);
75 /*----------------------------------------------------------*
79 * Round a number up to the next specified boundary.
81 *----------------------------------------------------------*/
83 #define GDB_ROUNDUP(n,b) ((((n)+(b)-1)/(b))*(b))
85 extern int gdb_Options; /* Control optional features */
86 #define GDB_OPT_KEEPALIVE 1
87 extern int gdb_Debug; /* debugging flags are */
89 extern FILE *gdb_log; /* file descriptor for */
90 /* logging gdb output */
94 * connection failure indicator
96 * This variable is used to communicate between gdb_move_data and
97 * g_con_progress without passing an extra parameter through lots
98 * of procedure calls. When set to FALSE, it indicates that the
99 * connection currently being processed has encountered a fatal error
100 * and should be severed.
102 extern int gdb_conok;
103 /************************************************************************
105 * USER IDENTIFICATION
107 * gdb_init puts the user's i.d. and hostname as strings here.
109 ************************************************************************/
111 extern char *gdb_uname; /* user's string name */
112 extern char *gdb_host; /* name of local host */
117 /************************************************************************
122 * Declarations used to control the definition and use of 'types'
123 * as supported by the global database system. Most of the
124 * declarations for 'System Defined Types' will not be of concern
125 * to typical users, with the exception of the type names like
126 * INTEGER_T which are defined below.
128 * In this implementation, user defined types are added
129 * dynamically during execution by calling the appropriate
130 * functions. The define GDB_MAX_TYPES below sets the maximum
131 * total number of types, including both system and user defined,
132 * which the system can support for any one application. When
133 * GDB_MAX_TYPES is changed, the libary must be re-built. Space
134 * for a two dimensional array, with one word for each property
135 * of each possible type, is allocated statically in the library.
137 ************************************************************************/
141 * Maximum number of types we can support, including both system and
145 #define GDB_MAX_TYPES 50
147 typedef int FIELD_TYPE; /* data needed to repre- */
148 /* sent a system or user */
149 /* defined data type */
150 /* This is actualy just */
151 /* a row index in the type */
152 /* definition table */
154 /*----------------------------------------------------------
156 * System defined types
158 * WARNING: Any changes to these type definitions must be
159 * carefully matched with the initializations in the
160 * gdb_i_stype routine in gdb_stype.c. Mistakes in these
161 * tables may be VERY difficult to debug. Be careful!
163 *----------------------------------------------------------*/
166 * Primitive types for ingres data
169 #define INTEGER_T (0)
178 #define TUPLE_DESCRIPTOR_T (4)
180 #define TUPLE_DATA_T (6)
181 #define RELATION_T (7)
184 * Number of system defined types
186 * This will always be equal to one more than index of last system type
189 #define SYSTEM_TYPE_COUNT 8
191 /*----------------------------------------------------------
193 * Type descriptor tables
195 *----------------------------------------------------------*/
200 * Each entry in the type definition table is a union of this form,
201 * which allows us to store a choice of an integer, a function
202 * pointer, or a pointer to a character string.
205 union gdb_prop_union {
206 int i; /* when we want as an */
208 int (*f)(); /* as a function pointer */
209 char *cp; /* character pointer */
212 #define TYPE_PROPERTY_COUNT 8 /* number of properties */
216 * Uses of the type properties. Each type has a set of properties.
217 * Some are integers, some are functions. The defines below descrive
218 * respectively the 0'th,1'st, 2'nd, etc. properties of EACH type.
220 * Note: TYPE_PROPERTY_COUNT (above) must be changed when new properties
221 * are added. For system defined types, bindings for the properties
222 * are done in gdb_i_stype in the gdb_stype.c source file.
225 #define LENGTH_PROPERTY 0 /* integer */
226 #define ALIGNMENT_PROPERTY 1 /* integer */
227 #define NULL_PROPERTY 2 /* function */
228 #define CODED_LENGTH_PROPERTY 3 /* function */
229 #define ENCODE_PROPERTY 4 /* function */
230 #define DECODE_PROPERTY 5 /* function */
231 #define FORMAT_PROPERTY 6 /* function */
232 #define NAME_PROPERTY 7 /* char pointer */
237 * Information to describe a single type
240 typedef union gdb_prop_union gdb_type_def[TYPE_PROPERTY_COUNT];
246 * This is the table where the actual definitions for the types are
250 extern gdb_type_def g_type_table[GDB_MAX_TYPES];
251 extern int gdb_n_types; /* number of entries in */
254 /*----------------------------------------------------------
256 * Macros for accessing properties
258 *----------------------------------------------------------*/
260 #define INT_PROPERTY(type, prop) (g_type_table[type][prop].i)
261 #define STR_PROPERTY(type, prop) (g_type_table[type][prop].cp)
262 #define FCN_PROPERTY(type, prop) (*g_type_table[type][prop].f)
265 /************************************************************************
269 * Stuff needed to declare and manage TUPLES, TUPLE_DESCRIPTORS
272 ************************************************************************/
274 /*----------------------------------------------------------
278 *----------------------------------------------------------*/
280 #define GDB_DESC_ID 0x54504400 /* "TPD" */
282 struct tupld_var { /* the variable length */
283 /* stuff in a tuple */
285 char *name; /* string name of field */
286 FIELD_TYPE type; /* type of this field */
287 int offset; /* byte offset of this field */
288 /* relative to first byte of */
289 /* data (not start of whole */
291 int length; /* Length of the actual data */
292 /* for this field. Note that */
293 /* alignment requirements of */
294 /* following field are NOT */
295 /* included in this length */
298 long id; /* this should say TPD\0 */
299 int ref_count; /* when this goes to zero, */
300 /* the descriptor may really */
302 int field_count; /* number of fields in */
304 int data_len; /* length of the data in */
305 /* the actual tuple */
306 int str_len; /* length of the strings */
307 /* stored off the end of */
309 struct tupld_var var[1]; /* one of these for each */
310 /* field, but the C compiler */
311 /* won't accept the[] decl, */
312 /* because it's afraid of */
313 /* uncertain length*/
316 typedef struct tupl_desc *TUPLE_DESCRIPTOR; /* use this to declare a */
317 /* tuple descriptor anchor */
319 #define gdb_descriptor_length(num_flds) (sizeof(struct tupl_desc) + ((num_flds)-1) * sizeof(struct tupld_var))
321 /*----------------------------------------------------------
325 * tuple_dat is allocated by the create_tuple routine.
327 * TUPLE may be used in user code to declare a handle
330 *----------------------------------------------------------*/
332 #define GDB_TUP_ID 0x54555000
334 typedef struct tuple_dat *TUPLE; /* handle on a tuple */
337 TUPLE next, prev; /* chain pointers when */
338 /* tuples are linked, as in */
339 /* a relation. Convention is*/
340 /* double linked, circular.*/
341 long id; /* should say TUP\0 */
342 TUPLE_DESCRIPTOR desc; /* pointer to the descriptor */
343 char data[1]; /* data goes here, word */
344 /* aligned. Should be [] */
345 /* if compiler would allow */
349 /*----------------------------------------------------------
353 * rel_dat is allocated by the create_relation
356 * RELATION may be used in user code to declare a handle
359 *----------------------------------------------------------*/
361 #define GDB_REL_ID 0x52454c00
364 TUPLE first, last; /* chain pointers to tuples */
365 /* note that first->prev and */
366 /* last->next are both == */
367 /* &rel-dat. Maintenance is */
368 /* simplified by keeping */
369 /* as the first fields in */
370 /* both rel_dat and tuple_dat*/
371 /* a minor non-portability */
372 long id; /* should contain REL\0 */
373 TUPLE_DESCRIPTOR desc; /* descriptor for the tuples */
374 /* in this relation. Should */
375 /* == that in each tuple */
379 typedef struct rel_dat *RELATION; /* handle on a relation */
381 /************************************************************************
383 * transport LAYER DECLARATIONS
385 * Declares the state maintenance structures for full duplex
386 * connections with asynchronous transmission capability. Most
387 * users need only know that the type CONNECTION is defined, and
388 * that it may be treated as a pointer for most purposes (i.e. it
389 * is compact, and copying it does not actually copy the connection
392 ************************************************************************/
394 #define GDB_PROTOCOL_VERSION 0x01 /* version of the gdb */
395 /* protocols that we're */
397 #define GDB_STREAM_BUFFER_SIZE 4096 /* amount to read in */
398 /* one chunk from tcp stream*/
399 #define GDB_PORT htons(9425) /* temporary until we use */
400 /* services properly */
401 #define GDB_BIND_RETRY_COUNT 5 /* number of times to */
402 /* retry a bind before */
403 /* giving up. Used when */
404 /* accepting connections */
405 #define GDB_BIND_RETRY_INTERVAL 10 /* Number of seconds to wait */
406 /* between attempts to bind */
407 /* the listening socket */
408 #define GDB_MAX_CONNECTIONS 25 /* maximum number of */
409 /* connections that */
410 /* any one process can */
411 /* control simultaneously */
413 * Circumvent bug in ACIS 4.2 socket support
416 #define GDB_MAX_SOCK_WRITE 2047 /* rt can't do socket */
417 /* writes longer than this */
420 #define GDB_MAX_SOCK_WRITE 0x00ffffff
423 /*----------------------------------------------------------
425 * Declarations for HALF_CONNECTIONS
427 * Each full duplex connection has associated with it
428 * two simplex half-connections, each of which
429 * has its own queue of pending operations. The
430 * following describes the state of a half-connection.
432 *----------------------------------------------------------*/
434 struct half_con_data {
436 * these two must be first to match position in OPERATION
438 struct oper_data *op_q_first; /* first item in q of pending*/
439 /* operations for this */
440 /* half-connection. (chained */
441 /* circularly to half con, */
443 struct oper_data *op_q_last; /* last item in q of pending*/
444 /* operations for this */
446 int status; /* values are of type */
447 /* OPSTATUS. tells whether */
448 /* transmit/receive is */
450 long flags; /* bit flags */
451 #define HCON_PROGRESS 0x00000001 /* used by selection */
452 /* routines to detect */
454 #define HCON_LISTEN 0x00000002 /* indicates that this is */
455 /* a special half connection */
456 /* used only for listenting */
457 /* to incoming connection */
459 #define HCON_UNUSED 0x00000004 /* on a one-way connection, */
460 /* this flag marks an unused */
462 #define HCON_PENDING_LISTEN 0x00000008 /* a queued op on this half */
463 /* connection is actually */
464 /* trying to listen */
465 #define HCON_BUSY 0x00000010 /* we are currently making */
466 /* progress on this half */
467 /* connection. Used to */
468 /* detect re-entrance of */
470 int fd; /* main half duplex file */
471 /* descriptor for this h_conn*/
472 int oob_fd; /* file descriptor for */
473 /* out of band signals*/
474 char *next_byte; /* next byte to send/recv */
475 int remaining; /* number of bytes remaining */
476 /* to send/receive */
477 char *stream_buffer; /* points to a buffer */
478 /* used to pre-read/write */
479 /* the stream to avoid */
480 /* window thrashing */
481 int stream_buffer_length; /* length of the stream */
483 char *stream_buffer_next; /* next byte to read in */
485 int stream_buffer_remaining; /* number of bytes currently */
486 /* in use in stream buffer*/
487 int *accepted_fdp; /* used only for listening */
488 /* connections. latest */
489 /* accepted fd is put where*/
491 int *accepted_len; /* ptr to length of 'from' */
496 typedef struct half_con_data *HALF_CONNECTION;
499 /*----------------------------------------------------------
501 * Declarations for CONNECTIONS
503 *----------------------------------------------------------*/
505 #define GDB_CON_ID 0x434f4e00 /*"CON"*/
508 long id; /* should contain CON\0 */
509 int status; /* See definitions below. */
510 /* Do not confuse with */
511 /* the status sub-fields of */
512 /* in and out half-cons. */
513 int version; /* the version of the */
514 /* protocol being observed */
515 /* on this connection */
516 int errno; /* the real errno gets */
517 /* copied here if it causes */
518 /* the connection to die */
519 int (*oob_fcn)(); /* pointer to function to */
520 /* call when something */
521 /* arrives on the out of */
523 struct half_con_data in, out; /* states of the inbound */
524 /* and outbound half */
528 typedef struct con_data *CONNECTION; /* the only externally */
529 /* visible handle on a */
533 * Definitions of status fields.
535 * WARNING: If you change any of the following, there are coordinated
536 * changes to be made in gdb_debug.c
539 #define CON_STOPPED 1 /* never started, terminated */
540 #define CON_UP 2 /* ready to use */
541 #define CON_STARTING 3 /* trying to start */
542 #define CON_STOPPING 4 /* trying to stop */
545 * The following are used as keywords when distinguishing input from output
548 #define CON_INPUT 1 /* this is an input half */
550 #define CON_OUTPUT 2 /* this is an output half */
554 /*----------------------------------------------------------
558 * This is the array of connection control data
559 * structures for gdb. Every connection has its
560 * structure stored here, but they are in no
561 * particular order. Because the connection data
562 * itself cannot be moved (due to possible dangling
563 * pointers), there may be some unused connections
564 * in the middle of this array. gdb_mcons is the
565 * 1 based number of the highest connection which is
566 * actually in use at this time. This is a considerable
567 * optimization for the typical case where very few
568 * are in use, and turnover is low.
570 * These are externs for globals defined in gdb_lib.h
571 * and included by gdb.c.
573 *----------------------------------------------------------*/
575 extern int gdb_mcons; /* one based number of the */
576 /* highest connection */
577 /* descriptor we're using */
580 extern int gdb_mfd; /* number of the highest */
581 /* file descriptor in use */
582 /* for a connection */
583 extern struct con_data gdb_cons[GDB_MAX_CONNECTIONS];
584 /* actual connection data */
587 extern fd_set gdb_crfds, gdb_cwfds, gdb_cefds; /* connection related file */
588 /* descriptor maps to be */
590 extern fd_set last_crfds, last_cwfds, last_cefds;/* these file desc. bit */
591 /* masks are set up */
592 /* for each select call */
593 /* to include the user */
594 /* supplied and the */
595 /* connection related */
598 /*----------------------------------------------------------
602 *----------------------------------------------------------*/
604 #define GDB_OP_ID 0x4f505200
607 struct oper_data *next, *prev; /* forward and back chain */
608 long id; /* should contain OPR\0 */
609 int tag; /* unique identifier for */
611 int status; /* current state of this */
614 #define OPF_MARKED_COMPLETE 0x00000001 /* operation was already */
615 /* complete when opsel was */
617 #define OPF_MARKED_CANCELLED 0x00000002 /* operation was already */
618 /* cancelled when opsel was */
620 int result; /* when the operation */
621 /* completes, this field is */
622 /* set to reflect its dispos-*/
623 /* ition. Contents of this */
624 /* field will depend on the */
625 /* operation being performed */
626 HALF_CONNECTION halfcon; /* the half connection on */
627 /* which this operation is */
629 /* May be meaningless if not */
631 char *arg; /* pointer to user data */
633 int (*init)(); /* pointer to routine to */
634 /* call to start this */
637 int (*cont)(); /* pointer to function to */
638 /* be called when this */
639 /* logical operation */
643 int (*cancel)(); /* this routine gets called */
644 /* to handle a cancel request*/
645 /* this field is normally */
646 /* set to NULL when the */
647 /* operation is queued and */
648 /* updated as required by */
649 /* the init and cont funcs. */
652 typedef struct oper_data OPERATION_DATA; /* an actual operation */
653 /* descritor, creator is */
654 /* responsible for making */
655 /* sure that memory is not */
656 /* freed while in use */
657 typedef OPERATION_DATA *OPERATION; /* a handle on an operation */
658 /* this is what most */
659 /* applications will use */
661 /*----------------------------------------------------------
663 * STATES OF AN OPERATION
665 * These represent the state of an asynchronous, queued
666 * operation. For convenience of the application programmer,
667 * some of these are folded together when queried through the
668 * operation_status routine. In particular, operation status
669 * returns only one of:
671 * OP_NOT_RUNNING, OP_RUNNING, OP_COMPLETE, or
674 * Any other status is reported as OP_RUNNING. This is
675 * done on the assumption that it makes correct coding
676 * of applications less error-prone, as there are fewer
677 * cases to check, and most of them would not be of
680 * Note that OP_CANCELLED may be generated by the system
681 * even when no explicit request for cancellation has been
682 * issued. For example, this may occur when a connection
683 * is severed unexpectedly.
685 * WARNING: If you change any of the following, be sure
686 * to make the equivalent changes to gdb_debug.c.
688 * We also define here certain standard values of OP_RESULT,
689 * since some return conventions presume that op_status
690 * and op_result values are orthogonal.
692 *----------------------------------------------------------*/
694 #define OP_SUCCESS 0 /* this value is actually */
695 /* used only in result */
696 /* fields, but it is */
697 /* sometimes convenient to */
698 /* have status and result */
699 /* have orthogonal values */
700 #define OP_NOT_STARTED 1 /* this operation has been */
701 /* initialized but is not on */
702 /* any connection's queue */
703 #define OP_QUEUED 2 /* this operation is on */
704 /* some connection's queue */
705 /* but it has not yet */
706 /* reached the head of the q */
707 #define OP_RUNNING 3 /* op is at head of q trying */
709 #define OP_COMPLETE 4 /* operation has run to */
710 /* completion. result field */
712 #define OP_CANCELLING 5 /* we are in the process of */
713 /* (trying to) cancel this */
715 #define OP_CANCELLED 6 /* operation was prematurely */
716 /* terminated. result field */
718 #define OP_MARKED 7 /* used by op_select_all */
719 #define OP_REQUEUED 8 /* returned by an init or */
720 /* continuation routine to */
721 /* indicate that the */
722 /* operation has requeued */
724 #define OP_PREEMPTED 9 /* returned by an init or */
725 /* continuation routine to */
726 /* indicate that the op has */
727 /* preempted itself by */
728 /* queueing a new operation */
729 /* ahead of itself */
731 /*----------------------------------------------------------
735 *----------------------------------------------------------*/
738 int count; /* number of operations */
740 OPERATION op[1]; /* really op[n], but */
741 /* structs must have a */
742 /* definite length */
745 typedef struct oper_list *LIST_OF_OPERATIONS; /* handle on a list */
747 #define size_of_list_of_operations(n) \
748 (sizeof(struct oper_list) + (n-1)*sizeof(OPERATION))
750 /*----------------------------------------------------------
754 * Pass this to select when doing a poll.
756 *----------------------------------------------------------*/
758 extern struct timeval gdb_notime;
761 /************************************************************************
763 * CHECKING ROUTINES IMPLEMENTED AS MACROS
765 ************************************************************************/
767 extern char g_errstr[150]; /* build emsgs here */
769 #define GDB_INIT_CHECK g_chk_init(); /* make sure gdb_init */
772 #define GDB_CHECK_CON(con, where) if ((con)->id != GDB_CON_ID) \
773 { (void) sprintf(g_errstr, "Invalid connection descriptor passed to \"%s\"\n", where); \
774 GDB_GIVEUP(g_errstr) }
777 #define GDB_CHECK_TUP(tup, where) if ((tup)->id != GDB_TUP_ID) \
778 { (void) sprintf(g_errstr, "Invalid tuple passed to \"%s\"\n", where); \
779 GDB_GIVEUP(g_errstr) }
782 #define GDB_CHECK_TPD(tpd, where) if ((tpd)->id != GDB_DESC_ID) \
783 { (void) sprintf(g_errstr, "Invalid tuple descriptor passed to \"%s\"\n", where); \
784 GDB_GIVEUP(g_errstr) }
787 #define GDB_CHECK_REL(rel, where) if ((rel)->id != GDB_REL_ID) \
788 { (void) sprintf(g_errstr, "Invalid relation passed to \"%s\"\n", where); \
789 GDB_GIVEUP(g_errstr) }
791 #define GDB_CHECK_OP(op, where) if ((op)->id != GDB_OP_ID) \
792 { (void) sprintf(g_errstr, "Invalid operation passed to \"%s\"\n", where); \
793 GDB_GIVEUP(g_errstr) }
795 #define GDB_CHECK_DB(db, where) if (db->id != GDB_DB_ID) \
796 { (void) sprintf(g_errstr, "Invalid database handle passed to \"%s\"\n", where); \
797 GDB_GIVEUP(g_errstr) }
802 /************************************************************************
804 * TRANSPORT ROUTINES IMPLEMENTED AS MACROS
806 ************************************************************************/
808 /*----------------------------------------------------------
812 * Returns the status of the indicated connection.
813 * Possible return values are:
815 * CON_STOPPED never started or terminated
816 * CON_UP currently usable
817 * CON_STARTING transient state on way up
818 * CON_STOPPING transient state on way down
820 *----------------------------------------------------------*/
822 #define connection_status(con) ((con)->status)
824 /*----------------------------------------------------------
828 * When a connection dies due to an error on a system
829 * call, the corresponding errno is recorded in the
830 * connection descriptor. This macro returns that value.
832 *----------------------------------------------------------*/
834 #define connection_errno(con) ((con)->errno)
838 /************************************************************************
840 * SERVER/CLIENT MANAGEMENT
842 * Definitions used in starting and maintaining communication
843 * between servers and clients (as opposed to peers.)
845 ************************************************************************/
847 #define GDB_MAX_SERVER_RETRIES 3 /* maximum number of times */
848 /* clients will accept */
849 /* forwarding requests from */
853 extern TUPLE_DESCRIPTOR gdb_tosrv; /* descriptor for request */
854 /* tuples sent to the */
855 /* server during negotiation*/
857 extern TUPLE_DESCRIPTOR gdb_fmsrv; /* descriptor for request */
858 /* tuples sent from the */
859 /* server during negotiation*/
861 #define GDB_MAX_SERVER_ID_SIZE 255 /* longest name of a server */
862 /* that we can handle */
863 #define GDB_MAX_SERVER_PARMS_SIZE 1023 /* longest parm string we */
864 /* can exchange between */
865 /* server and client*/
867 /*----------------------------------------------------------
869 * The following are values returned in the disposition
870 * field of the response tuple to indicate what the
871 * server has decided to do about the connection
874 *----------------------------------------------------------*/
876 #define GDB_ACCEPTED 1
877 #define GDB_REFUSED 2
878 #define GDB_FORWARDED 3
880 /*----------------------------------------------------------
882 * Global variables inherited by a child from a server
885 *----------------------------------------------------------*/
887 extern TUPLE gdb_client_tuple; /* request tuple sent from */
890 extern char gdb_sockaddr_of_client[100]; /* this should really be */
891 /* sockaddr_in, but I don't */
892 /* want everyone to have */
893 /* to include all those */
895 extern int gdb_socklen; /* length of above */
899 /************************************************************************
901 * DATABASE MANAGEMENT
903 * This layer of GDB provides access to the services of a relational
904 * database from anywhere in a GDB network.
906 ************************************************************************/
908 /*----------------------------------------------------------
912 * The name of the service, as found in /etc/services,
913 * for GDB database servers.
915 *----------------------------------------------------------*/
917 #define GDB_DB_SERVICE "#9420"
919 /*----------------------------------------------------------
923 * Describes a client's active connection to a database.
925 *----------------------------------------------------------*/
927 #define GDB_DB_ID 0x44420000 /* eye catcher */
930 long id; /* eye catcher */
931 CONNECTION connection; /* the GDB connection */
932 /* used to get at this */
934 int status; /* status of this */
935 /* database connection */
936 #define DB_OPEN 1 /* database opened */
938 #define DB_CLOSED 2 /* not open */
939 char *name; /* pointer to string name */
940 /* of the database, for */
942 char *server; /* pointer to the i.d. */
943 /* of the server, for */
947 typedef struct db_struct *DATABASE;
949 /*----------------------------------------------------------
951 * Return codes from DB operations
953 *----------------------------------------------------------*/
955 #define DB_NO_SUCH_OP 3
957 /*----------------------------------------------------------
959 * Parameters which limit sizes of things
961 *----------------------------------------------------------*/
963 #define GDB_MAX_QUERY_SIZE 2048 /* length of the longest */
964 /* substituted query */
965 /* string we can make */
966 #define GDB_MAX_QUERY_FIELDS 100 /* maximum number of fields */
967 /* we can retrieve in one */
969 #define GDB_SIZE_OF_INGRES_TEXT 2001 /* number of chars in */
970 /* largest ingres text */
972 #define GDB_MAX_RETRIEVED_TEXT_FIELDS 60 /* maximum number of text */
973 /* type fields we can */
974 /* retrieve in a single */
975 /* query. we hold this */
976 /* down because stack space */
977 /* is taken for max size of */
978 /* each during query. */
980 /*----------------------------------------------------------
982 * Return codes from database operations
984 *----------------------------------------------------------*/
986 #define DB_PARSE_FAIL (-3) /* couldn't parse */
987 /* the request string*/
990 /************************************************************************
992 * DATABASE OPERATIONS IMPLEMENTED
995 ************************************************************************/
997 /*----------------------------------------------------------
1001 *----------------------------------------------------------*/
1003 #define DB_STATUS(dbhandle) ((dbhandle)->status)
1008 /************************************************************************
1012 * To allow dynamic manipulation of strings in gdb without
1013 * excessive memory re-allocation, we define a string as a
1014 * counted byte space. Though this space will frequently be used
1015 * to store a standard null terminated string, that is not
1018 * Current representation for a string is a pointer followed by
1019 * an integer length. A null pointer indicates a null string, in
1020 * which case the length is arbitrary. Any other pointer is to
1021 * memory which was allocated by db_alloc in which must be free'd
1022 * eventually with db_free.
1024 ************************************************************************/
1026 typedef struct str_dat {
1027 char *ptr; /* pointer to the data */
1028 int length; /* length of the allocated */
1029 /* memory (not necessarily */
1030 /* length of null-term'd */
1031 /* string stored there) */
1034 /*----------------------------------------------------------
1036 * Macros for manipulating strings. These return
1037 * the actual data from the string and the size of
1038 * the data space respectively. To get the length of
1039 * the null terminated string which might be stored
1040 * there, use strlen(STRING_DATA(string)).
1042 *----------------------------------------------------------*/
1045 #define STRING_DATA(str) ((str).ptr)
1046 #define MAX_STRING_SIZE(str) ((str).length)
1049 /************************************************************************
1053 * db_alloc and db_free are the externally visible names of
1054 * the memory allocation services. These actually call the
1055 * routines pointed to by the vectors gdb_amv and gdb_fmv, which
1056 * default to the supplied routines gdb_am and gdb_fm. Users
1057 * may supply their own memory allocation by storing over the
1058 * vectors. This may be done prior to calling gdb_init to
1059 * insure that all dynamic memory is controlled by the user.
1061 ************************************************************************/
1063 #define db_alloc (*gdb_amv)
1064 #define db_free (*gdb_fmv)
1066 extern char *gdb_am();
1067 extern int gdb_fm();
1069 extern char *((*gdb_amv)());
1070 extern int (*gdb_fmv)();
1073 /************************************************************************
1075 * STRUCTURED DATA ROUTINES IMPLEMENTED AS MACROS
1077 ************************************************************************/
1079 /*----------------------------------------------------------
1081 * ADD_TUPLE_TO_RELATION
1083 *----------------------------------------------------------*/
1085 #define ADD_TUPLE_TO_RELATION(relation, tuple) \
1087 (tuple)->prev = (relation)->last; \
1088 (tuple)->next = (TUPLE)(relation); \
1089 (relation)->last = tuple; \
1090 (tuple)->prev->next = tuple; \
1093 /*----------------------------------------------------------
1095 * ADD_TUPLE_AFTER_TUPLE
1097 *----------------------------------------------------------*/
1099 #define ADD_TUPLE_AFTER_TUPLE(relation, tuple, prev_tuple) \
1101 (tuple)->prev = (prev_tuple)->next->prev; \
1102 (tuple)->next = (prev_tuple)->next; \
1103 (tuple)->next->prev = tuple; \
1104 (prev_tuple)->next = tuple; \
1107 /*----------------------------------------------------------
1109 * REMOVE_TUPLE_FROM_RELATION
1111 *----------------------------------------------------------*/
1113 #define REMOVE_TUPLE_FROM_RELATION(relation, tuple) \
1115 (tuple)->prev->next = (tuple)->next; \
1116 (tuple)->next->prev = (tuple)->prev; \
1120 /*----------------------------------------------------------
1122 * DESCRIPTOR_FROM_TUPLE
1124 *----------------------------------------------------------*/
1126 #define DESCRIPTOR_FROM_TUPLE(tuple) ((tuple)->desc)
1128 /*----------------------------------------------------------
1130 * DESCRIPTOR_FROM_RELATION
1132 *----------------------------------------------------------*/
1134 #define DESCRIPTOR_FROM_RELATION(relation) ((relation)->desc)
1136 /*----------------------------------------------------------
1138 * REFERENCE_TUPLE_DESCRIPTOR
1140 * Bumps the reference count for a tuple descriptor.
1141 * Intended only for internal use of GDB.
1143 *----------------------------------------------------------*/
1145 #define REFERENCE_TUPLE_DESCRIPTOR(tpd) (++((tpd)->ref_count))
1147 /*----------------------------------------------------------
1149 * UNREFERENCE_TUPLE_DESCRIPTOR
1151 * Decrements the reference count for a tuple descriptor.
1152 * Intended only for internal use of GDB. Warning: it
1153 * is the user's responsibility to use delete_tuple_descriptor
1154 * instead of this macro in any situation in which the
1155 * reference count might go to zero.
1157 *----------------------------------------------------------*/
1159 #define UNREFERENCE_TUPLE_DESCRIPTOR(tpd) (--((tpd)->ref_count))
1161 /*----------------------------------------------------------
1165 *----------------------------------------------------------*/
1167 #define FIELD_FROM_TUPLE(tuple, field_index) \
1168 (((tuple)->data) + (((tuple)->desc)->var[field_index].offset))
1170 /*----------------------------------------------------------
1172 * FIELD_OFFSET_IN_TUPLE
1174 *----------------------------------------------------------*/
1176 #define FIELD_OFFSET_IN_TUPLE(tuple_descriptor, field_index) \
1177 ((tuple_descriptor)->var[field_index].offset)
1179 /*----------------------------------------------------------
1181 * FIELD_TYPE_IN_TUPLE
1183 *----------------------------------------------------------*/
1185 #define FIELD_TYPE_IN_TUPLE(tuple_descriptor, field_index) \
1186 ((tuple_descriptor)->var[field_index].type)
1188 /*----------------------------------------------------------
1190 * FIRST_TUPLE_IN_RELATION
1192 *----------------------------------------------------------*/
1194 #define FIRST_TUPLE_IN_RELATION(relation) \
1195 (((relation)->first) == (TUPLE)relation ? NULL : (relation)-> first)
1197 /*----------------------------------------------------------
1199 * NEXT_TUPLE_IN_RELATION
1201 *----------------------------------------------------------*/
1203 #define NEXT_TUPLE_IN_RELATION(relation, prev) \
1204 (((prev)->next) == (TUPLE)relation ? NULL : prev->next )
1206 /*----------------------------------------------------------
1208 * PREV_TUPLE_IN_RELATION
1210 *----------------------------------------------------------*/
1212 #define PREV_TUPLE_IN_RELATION(relation, next) \
1213 (((next)->prev) == (TUPLE) relation ? NULL : next->prev)
1218 /************************************************************************
1220 * TRANSPORT and OPERATION SERVICES IMPLEMENTED AS MACROS
1222 ************************************************************************/
1224 /*----------------------------------------------------------
1226 * OPERATION_FROM_DATA
1228 * Given OPERATION_DATA, return the corresponding handle
1229 * of type OPERATION. Currently, OPERATION is just
1230 * implemented as a pointer to OPERATION_DATA.
1232 *----------------------------------------------------------*/
1234 #define OPERATION_FROM_DATA(op_data) \
1235 ((OPERATION)&(op_data))
1237 /*----------------------------------------------------------
1241 * Return the tag for a given operation.
1243 *----------------------------------------------------------*/
1245 #define OP_TAG(operation) ((operation)->tag)
1247 /*----------------------------------------------------------
1251 * Return the status of a given operation. Note that
1252 * status describes an operations progress through
1253 * execution. It has the same values for all operations.
1254 * Result describes the final outcome of an operation.
1255 * It's values depend on the particular operation which
1258 *----------------------------------------------------------*/
1260 #define OP_STATUS(operation) ((operation)->status)
1262 /*----------------------------------------------------------
1266 * True iff the operation is either OP_COMPLETE or
1269 *----------------------------------------------------------*/
1271 #define OP_DONE(op) ((op)->status == OP_COMPLETE || (op)->status == OP_CANCELLED)
1273 /*----------------------------------------------------------
1277 * Return the result of a given operation. Note that
1278 * status describes an operations progress through
1279 * execution. It has the same values for all operations.
1280 * Result describes the final outcome of an operation.
1281 * It's values depend on the particular operation which
1282 * was attempted. The special result value -1 is used
1283 * to indicate an invalid value for result. Generally,
1284 * -1 is returned when result is accidently queried at
1285 * a time when OP_STATUS != OPERATION_COMPLETE.
1287 *----------------------------------------------------------*/
1289 #define OP_RESULT(operation) ((operation)->result)
1292 /************************************************************************
1294 * Debugging Interfaces
1296 ************************************************************************/
1298 /*----------------------------------------------------------
1300 * The following operation codes my be passed to
1301 * gdb_debug to set special debugging modes of operation.
1303 * Note that most of these are toggles
1305 *----------------------------------------------------------*/
1307 #define GDB_LOG 0x00000001 /* turn on tracing to */
1309 #define GDB_NOFORK 0x00000002 /* don't fork forking */
1313 /************************************************************************
1315 * Things which have to be at the end because they require
1316 * the various types to be defined first.
1318 ************************************************************************/
1321 #ifdef DUMB_7_CHAR_LOADER
1322 /*----------------------------------------------------------
1324 * Long Names for Routines
1326 * External names in Unix must generally be unique
1327 * within the first 7 characters or so, at least for
1328 * some versions of ld. To account for this without
1329 * making all our routine names terribly short and
1330 * cryptic, we use the following defines.
1332 *----------------------------------------------------------*/
1334 #define string_alloc gdb_sta
1335 #define string_free gdb_stf
1337 #define create_tuple_descriptor gdb_ctd
1338 #define delete_tuple_descriptor gdb_dtd
1339 #define field_index gdb_fi
1340 #define create_tuple gdb_ctup
1341 #define delete_tuple gdb_dtup
1342 #define initialize_tuple gdb_itup
1343 #define null_tuple_strings gdb_ntps
1345 #define create_relation gdb_crel
1346 #define delete_relation gdb_drel
1347 #define tuples_in_relation gdb_trel
1353 #define create_operation gdb_crop
1354 #define delete_operation gdb_dop
1355 #define initialize_operation gdb_inop
1356 #define reset_operation gdb_rsop
1357 #define cancel_operation gdb_cnop
1359 #define create_list_of_operations gdb_clop
1360 #define delete_list_of_operations gdb_dlop
1362 #define op_select gdb_opsel
1363 #define op_select_any gdb_opsel
1364 #define op_select_all gdb_aopsel
1365 #define con_select gdb_cnsel
1367 #define gdb_receive_data gdb_rcdat
1368 #define gdb_send_data gdb_sndat
1369 #define gdb_start_listening gdb_stl
1370 #define start_accepting_client gdb_stac
1373 #define gdb_listen gdb_lis
1376 * Connection management
1378 #define start_peer_connection gdb_spconn
1379 #define sever_connection gdb_svconn
1380 #define start_server_connection gdb_stsrv
1381 #define create_listening_connection gdb_clc
1382 #define start_replying_to_client gdb_strtc
1383 #define create_forking_server gdb_cfs
1387 * Asynchronous operations
1389 #define start_sending_object gdb_snobj
1390 #define start_receiving_object gdb_rcobj
1391 #define preempt_and_start_receiving_object gdb_prcobj
1393 #define queue_operation gdb_qop
1395 #define requeue_operation g_req_op
1397 #define complete_operation gdb_cmpo
1399 * Synchronous operations
1401 #define send_object gdb_sobj
1402 #define receive_object gdb_robj
1404 * Database operations
1406 #define access_db gdb_adb
1407 #define start_accessing_db gdb_sadb
1408 #define perform_db_operation gdb_pdbo
1409 #define db_query gdb_dbq
1410 #define start_performing_db_operation gdb_spdb
1411 #define start_db_query gdb_sdbq
1413 #define op_select_any op_select
1414 #endif /* DUMB_7_CHAR_LOADER */
1416 extern char *string_alloc();
1417 extern int string_free();
1418 extern TUPLE_DESCRIPTOR create_tuple_descriptor();
1419 extern int delete_tuple_descriptor();
1420 extern int field_index();
1421 extern TUPLE create_tuple();
1422 extern int delete_tuple();
1423 extern int initialize_tuple();
1424 extern int null_tuple_strings();
1425 extern RELATION create_relation();
1426 extern int delete_relation();
1427 extern OPERATION create_operation();
1428 extern LIST_OF_OPERATIONS create_list_of_operations();
1429 extern OPERATION g_op_newhead();
1430 extern CONNECTION start_peer_connection();
1431 extern CONNECTION sever_connection();
1432 extern CONNECTION start_server_connection();
1433 extern CONNECTION create_listening_connection();
1434 extern CONNECTION create_forking_server();
1435 extern int start_sending_object();
1436 extern int start_receiving_object();
1437 extern int preempt_and_start_receiving_object();
1438 extern int queue_operation();
1439 extern int requeue_operation();
1440 extern int complete_operation();
1441 extern int send_object();
1442 extern int receive_object();
1445 /*----------------------------------------------------------
1447 * Other routines requiring extern to avoid forward
1448 * reference to non integer type functions.
1450 *----------------------------------------------------------*/
1452 extern CONNECTION g_make_con();