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_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
47 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
48 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
49 #define FD_ZERO(p) bzero(p, sizeof(*(p)))
54 /*----------------------------------------------------------*
58 * This macro is called with a string argument whenever a
59 * fatal error is encounterd. If you re-define this
60 * macro, you can control the disposition of fatal gdb
63 * The gdb library must be recompiled for the change to
64 * take effect. That will have to be fixed sometime.
66 *----------------------------------------------------------*/
68 #define GDB_GIVEUP(errormsg) g_givup(errormsg);
70 /*----------------------------------------------------------*
74 * Round a number up to the next specified boundary.
76 *----------------------------------------------------------*/
78 #define GDB_ROUNDUP(n,b) ((((n)+(b)-1)/(b))*(b))
80 extern int gdb_Debug; /* debugging flags are */
82 extern FILE *gdb_log; /* file descriptor for */
83 /* logging gdb output */
87 * connection failure indicator
89 * This variable is used to communicate between gdb_move_data and
90 * g_con_progress without passing an extra parameter through lots
91 * of procedure calls. When set to FALSE, it indicates that the
92 * connection currently being processed has encountered a fatal error
93 * and should be severed.
96 /************************************************************************
100 * gdb_init puts the user's i.d. and hostname as strings here.
102 ************************************************************************/
104 extern char *gdb_uname; /* user's string name */
105 extern char *gdb_host; /* name of local host */
110 /************************************************************************
115 * Declarations used to control the definition and use of 'types'
116 * as supported by the global database system. Most of the
117 * declarations for 'System Defined Types' will not be of concern
118 * to typical users, with the exception of the type names like
119 * INTEGER_T which are defined below.
121 * In this implementation, user defined types are added
122 * dynamically during execution by calling the appropriate
123 * functions. The define GDB_MAX_TYPES below sets the maximum
124 * total number of types, including both system and user defined,
125 * which the system can support for any one application. When
126 * GDB_MAX_TYPES is changed, the libary must be re-built. Space
127 * for a two dimensional array, with one word for each property
128 * of each possible type, is allocated statically in the library.
130 ************************************************************************/
134 * Maximum number of types we can support, including both system and
138 #define GDB_MAX_TYPES 50
140 typedef int FIELD_TYPE; /* data needed to repre- */
141 /* sent a system or user */
142 /* defined data type */
143 /* This is actualy just */
144 /* a row index in the type */
145 /* definition table */
147 /*----------------------------------------------------------
149 * System defined types
151 * WARNING: Any changes to these type definitions must be
152 * carefully matched with the initializations in the
153 * gdb_i_stype routine in gdb_stype.c. Mistakes in these
154 * tables may be VERY difficult to debug. Be careful!
156 *----------------------------------------------------------*/
159 * Primitive types for ingres data
162 #define INTEGER_T (0)
171 #define TUPLE_DESCRIPTOR_T (4)
173 #define TUPLE_DATA_T (6)
174 #define RELATION_T (7)
177 * Number of system defined types
179 * This will always be equal to one more than index of last system type
182 #define SYSTEM_TYPE_COUNT 8
184 /*----------------------------------------------------------
186 * Type descriptor tables
188 *----------------------------------------------------------*/
193 * Each entry in the type definition table is a union of this form,
194 * which allows us to store a choice of an integer, a function
195 * pointer, or a pointer to a character string.
198 union gdb_prop_union {
199 int i; /* when we want as an */
201 int (*f)(); /* as a function pointer */
202 char *cp; /* character pointer */
205 #define TYPE_PROPERTY_COUNT 8 /* number of properties */
209 * Uses of the type properties. Each type has a set of properties.
210 * Some are integers, some are functions. The defines below descrive
211 * respectively the 0'th,1'st, 2'nd, etc. properties of EACH type.
213 * Note: TYPE_PROPERTY_COUNT (above) must be changed when new properties
214 * are added. For system defined types, bindings for the properties
215 * are done in gdb_i_stype in the gdb_stype.c source file.
218 #define LENGTH_PROPERTY 0 /* integer */
219 #define ALIGNMENT_PROPERTY 1 /* integer */
220 #define NULL_PROPERTY 2 /* function */
221 #define CODED_LENGTH_PROPERTY 3 /* function */
222 #define ENCODE_PROPERTY 4 /* function */
223 #define DECODE_PROPERTY 5 /* function */
224 #define FORMAT_PROPERTY 6 /* function */
225 #define NAME_PROPERTY 7 /* char pointer */
230 * Information to describe a single type
233 typedef union gdb_prop_union gdb_type_def[TYPE_PROPERTY_COUNT];
239 * This is the table where the actual definitions for the types are
243 extern gdb_type_def g_type_table[GDB_MAX_TYPES];
244 extern int gdb_n_types; /* number of entries in */
247 /*----------------------------------------------------------
249 * Macros for accessing properties
251 *----------------------------------------------------------*/
253 #define INT_PROPERTY(type, prop) (g_type_table[type][prop].i)
254 #define STR_PROPERTY(type, prop) (g_type_table[type][prop].cp)
255 #define FCN_PROPERTY(type, prop) (*g_type_table[type][prop].f)
258 /************************************************************************
262 * Stuff needed to declare and manage TUPLES, TUPLE_DESCRIPTORS
265 ************************************************************************/
267 /*----------------------------------------------------------
271 *----------------------------------------------------------*/
273 #define GDB_DESC_ID 0x54504400 /* "TPD" */
275 struct tupld_var { /* the variable length */
276 /* stuff in a tuple */
278 char *name; /* string name of field */
279 FIELD_TYPE type; /* type of this field */
280 int offset; /* byte offset of this field */
281 /* relative to first byte of */
282 /* data (not start of whole */
284 int length; /* Length of the actual data */
285 /* for this field. Note that */
286 /* alignment requirements of */
287 /* following field are NOT */
288 /* included in this length */
291 long id; /* this should say TPD\0 */
292 int ref_count; /* when this goes to zero, */
293 /* the descriptor may really */
295 int field_count; /* number of fields in */
297 int data_len; /* length of the data in */
298 /* the actual tuple */
299 int str_len; /* length of the strings */
300 /* stored off the end of */
302 struct tupld_var var[1]; /* one of these for each */
303 /* field, but the C compiler */
304 /* won't accept the[] decl, */
305 /* because it's afraid of */
306 /* uncertain length*/
309 typedef struct tupl_desc *TUPLE_DESCRIPTOR; /* use this to declare a */
310 /* tuple descriptor anchor */
312 #define gdb_descriptor_length(num_flds) (sizeof(struct tupl_desc) + ((num_flds)-1) * sizeof(struct tupld_var))
314 /*----------------------------------------------------------
318 * tuple_dat is allocated by the create_tuple routine.
320 * TUPLE may be used in user code to declare a handle
323 *----------------------------------------------------------*/
325 #define GDB_TUP_ID 0x54555000
327 typedef struct tuple_dat *TUPLE; /* handle on a tuple */
330 TUPLE next, prev; /* chain pointers when */
331 /* tuples are linked, as in */
332 /* a relation. Convention is*/
333 /* double linked, circular.*/
334 long id; /* should say TUP\0 */
335 TUPLE_DESCRIPTOR desc; /* pointer to the descriptor */
336 char data[1]; /* data goes here, word */
337 /* aligned. Should be [] */
338 /* if compiler would allow */
342 /*----------------------------------------------------------
346 * rel_dat is allocated by the create_relation
349 * RELATION may be used in user code to declare a handle
352 *----------------------------------------------------------*/
354 #define GDB_REL_ID 0x52454c00
357 TUPLE first, last; /* chain pointers to tuples */
358 /* note that first->prev and */
359 /* last->next are both == */
360 /* &rel-dat. Maintenance is */
361 /* simplified by keeping */
362 /* as the first fields in */
363 /* both rel_dat and tuple_dat*/
364 /* a minor non-portability */
365 long id; /* should contain REL\0 */
366 TUPLE_DESCRIPTOR desc; /* descriptor for the tuples */
367 /* in this relation. Should */
368 /* == that in each tuple */
372 typedef struct rel_dat *RELATION; /* handle on a relation */
374 /************************************************************************
376 * transport LAYER DECLARATIONS
378 * Declares the state maintenance structures for full duplex
379 * connections with asynchronous transmission capability. Most
380 * users need only know that the type CONNECTION is defined, and
381 * that it may be treated as a pointer for most purposes (i.e. it
382 * is compact, and copying it does not actually copy the connection
385 ************************************************************************/
387 #define GDB_PROTOCOL_VERSION 0x01 /* version of the gdb */
388 /* protocols that we're */
390 #define GDB_STREAM_BUFFER_SIZE 4096 /* amount to read in */
391 /* one chunk from tcp stream*/
392 #define GDB_PORT htons(9425) /* temporary until we use */
393 /* services properly */
394 #define GDB_BIND_RETRY_COUNT 5 /* number of times to */
395 /* retry a bind before */
396 /* giving up. Used when */
397 /* accepting connections */
398 #define GDB_BIND_RETRY_INTERVAL 10 /* Number of seconds to wait */
399 /* between attempts to bind */
400 /* the listening socket */
401 #define GDB_MAX_CONNECTIONS 25 /* maximum number of */
402 /* connections that */
403 /* any one process can */
404 /* control simultaneously */
406 * Circumvent bug in ACIS 4.2 socket support
409 #define GDB_MAX_SOCK_WRITE 2047 /* rt can't do socket */
410 /* writes longer than this */
413 #define GDB_MAX_SOCK_WRITE 0x00ffffff
416 /*----------------------------------------------------------
418 * Declarations for HALF_CONNECTIONS
420 * Each full duplex connection has associated with it
421 * two simplex half-connections, each of which
422 * has its own queue of pending operations. The
423 * following describes the state of a half-connection.
425 *----------------------------------------------------------*/
427 struct half_con_data {
429 * these two must be first to match position in OPERATION
431 struct oper_data *op_q_first; /* first item in q of pending*/
432 /* operations for this */
433 /* half-connection. (chained */
434 /* circularly to half con, */
436 struct oper_data *op_q_last; /* last item in q of pending*/
437 /* operations for this */
439 int status; /* values are of type */
440 /* OPSTATUS. tells whether */
441 /* transmit/receive is */
443 long flags; /* bit flags */
444 #define HCON_PROGRESS 0x00000001 /* used by selection */
445 /* routines to detect */
447 #define HCON_LISTEN 0x00000002 /* indicates that this is */
448 /* a special half connection */
449 /* used only for listenting */
450 /* to incoming connection */
452 #define HCON_UNUSED 0x00000004 /* on a one-way connection, */
453 /* this flag marks an unused */
455 #define HCON_PENDING_LISTEN 0x00000008 /* a queued op on this half */
456 /* connection is actually */
457 /* trying to listen */
458 #define HCON_BUSY 0x00000010 /* we are currently making */
459 /* progress on this half */
460 /* connection. Used to */
461 /* detect re-entrance of */
463 int fd; /* main half duplex file */
464 /* descriptor for this h_conn*/
465 int oob_fd; /* file descriptor for */
466 /* out of band signals*/
467 char *next_byte; /* next byte to send/recv */
468 int remaining; /* number of bytes remaining */
469 /* to send/receive */
470 char *stream_buffer; /* points to a buffer */
471 /* used to pre-read/write */
472 /* the stream to avoid */
473 /* window thrashing */
474 int stream_buffer_length; /* length of the stream */
476 char *stream_buffer_next; /* next byte to read in */
478 int stream_buffer_remaining; /* number of bytes currently */
479 /* in use in stream buffer*/
480 int *accepted_fdp; /* used only for listening */
481 /* connections. latest */
482 /* accepted fd is put where*/
484 int *accepted_len; /* ptr to length of 'from' */
489 typedef struct half_con_data *HALF_CONNECTION;
492 /*----------------------------------------------------------
494 * Declarations for CONNECTIONS
496 *----------------------------------------------------------*/
498 #define GDB_CON_ID 0x434f4e00 /*"CON"*/
501 long id; /* should contain CON\0 */
502 int status; /* See definitions below. */
503 /* Do not confuse with */
504 /* the status sub-fields of */
505 /* in and out half-cons. */
506 int version; /* the version of the */
507 /* protocol being observed */
508 /* on this connection */
509 int errno; /* the real errno gets */
510 /* copied here if it causes */
511 /* the connection to die */
512 int (*oob_fcn)(); /* pointer to function to */
513 /* call when something */
514 /* arrives on the out of */
516 struct half_con_data in, out; /* states of the inbound */
517 /* and outbound half */
521 typedef struct con_data *CONNECTION; /* the only externally */
522 /* visible handle on a */
526 * Definitions of status fields.
528 * WARNING: If you change any of the following, there are coordinated
529 * changes to be made in gdb_debug.c
532 #define CON_STOPPED 1 /* never started, terminated */
533 #define CON_UP 2 /* ready to use */
534 #define CON_STARTING 3 /* trying to start */
535 #define CON_STOPPING 4 /* trying to stop */
538 * The following are used as keywords when distinguishing input from output
541 #define CON_INPUT 1 /* this is an input half */
543 #define CON_OUTPUT 2 /* this is an output half */
547 /*----------------------------------------------------------
551 * This is the array of connection control data
552 * structures for gdb. Every connection has its
553 * structure stored here, but they are in no
554 * particular order. Because the connection data
555 * itself cannot be moved (due to possible dangling
556 * pointers), there may be some unused connections
557 * in the middle of this array. gdb_mcons is the
558 * 1 based number of the highest connection which is
559 * actually in use at this time. This is a considerable
560 * optimization for the typical case where very few
561 * are in use, and turnover is low.
563 * These are externs for globals defined in gdb_lib.h
564 * and included by gdb.c.
566 *----------------------------------------------------------*/
568 extern int gdb_mcons; /* one based number of the */
569 /* highest connection */
570 /* descriptor we're using */
573 extern int gdb_mfd; /* number of the highest */
574 /* file descriptor in use */
575 /* for a connection */
576 extern struct con_data gdb_cons[GDB_MAX_CONNECTIONS];
577 /* actual connection data */
580 extern fd_set gdb_crfds, gdb_cwfds, gdb_cefds; /* connection related file */
581 /* descriptor maps to be */
583 extern fd_set last_crfds, last_cwfds, last_cefds;/* these file desc. bit */
584 /* masks are set up */
585 /* for each select call */
586 /* to include the user */
587 /* supplied and the */
588 /* connection related */
591 /*----------------------------------------------------------
595 *----------------------------------------------------------*/
597 #define GDB_OP_ID 0x4f505200
600 struct oper_data *next, *prev; /* forward and back chain */
601 long id; /* should contain OPR\0 */
602 int tag; /* unique identifier for */
604 int status; /* current state of this */
607 #define OPF_MARKED_COMPLETE 0x00000001 /* operation was already */
608 /* complete when opsel was */
610 #define OPF_MARKED_CANCELLED 0x00000002 /* operation was already */
611 /* cancelled when opsel was */
613 int result; /* when the operation */
614 /* completes, this field is */
615 /* set to reflect its dispos-*/
616 /* ition. Contents of this */
617 /* field will depend on the */
618 /* operation being performed */
619 HALF_CONNECTION halfcon; /* the half connection on */
620 /* which this operation is */
622 /* May be meaningless if not */
624 char *arg; /* pointer to user data */
626 int (*init)(); /* pointer to routine to */
627 /* call to start this */
630 int (*cont)(); /* pointer to function to */
631 /* be called when this */
632 /* logical operation */
636 int (*cancel)(); /* this routine gets called */
637 /* to handle a cancel request*/
638 /* this field is normally */
639 /* set to NULL when the */
640 /* operation is queued and */
641 /* updated as required by */
642 /* the init and cont funcs. */
645 typedef struct oper_data OPERATION_DATA; /* an actual operation */
646 /* descritor, creator is */
647 /* responsible for making */
648 /* sure that memory is not */
649 /* freed while in use */
650 typedef OPERATION_DATA *OPERATION; /* a handle on an operation */
651 /* this is what most */
652 /* applications will use */
654 /*----------------------------------------------------------
656 * STATES OF AN OPERATION
658 * These represent the state of an asynchronous, queued
659 * operation. For convenience of the application programmer,
660 * some of these are folded together when queried through the
661 * operation_status routine. In particular, operation status
662 * returns only one of:
664 * OP_NOT_RUNNING, OP_RUNNING, OP_COMPLETE, or
667 * Any other status is reported as OP_RUNNING. This is
668 * done on the assumption that it makes correct coding
669 * of applications less error-prone, as there are fewer
670 * cases to check, and most of them would not be of
673 * Note that OP_CANCELLED may be generated by the system
674 * even when no explicit request for cancellation has been
675 * issued. For example, this may occur when a connection
676 * is severed unexpectedly.
678 * WARNING: If you change any of the following, be sure
679 * to make the equivalent changes to gdb_debug.c.
681 * We also define here certain standard values of OP_RESULT,
682 * since some return conventions presume that op_status
683 * and op_result values are orthogonal.
685 *----------------------------------------------------------*/
687 #define OP_SUCCESS 0 /* this value is actually */
688 /* used only in result */
689 /* fields, but it is */
690 /* sometimes convenient to */
691 /* have status and result */
692 /* have orthogonal values */
693 #define OP_NOT_STARTED 1 /* this operation has been */
694 /* initialized but is not on */
695 /* any connection's queue */
696 #define OP_QUEUED 2 /* this operation is on */
697 /* some connection's queue */
698 /* but it has not yet */
699 /* reached the head of the q */
700 #define OP_RUNNING 3 /* op is at head of q trying */
702 #define OP_COMPLETE 4 /* operation has run to */
703 /* completion. result field */
705 #define OP_CANCELLING 5 /* we are in the process of */
706 /* (trying to) cancel this */
708 #define OP_CANCELLED 6 /* operation was prematurely */
709 /* terminated. result field */
711 #define OP_MARKED 7 /* used by op_select_all */
712 #define OP_REQUEUED 8 /* returned by an init or */
713 /* continuation routine to */
714 /* indicate that the */
715 /* operation has requeued */
717 #define OP_PREEMPTED 9 /* returned by an init or */
718 /* continuation routine to */
719 /* indicate that the op has */
720 /* preempted itself by */
721 /* queueing a new operation */
722 /* ahead of itself */
724 /*----------------------------------------------------------
728 *----------------------------------------------------------*/
731 int count; /* number of operations */
733 OPERATION op[1]; /* really op[n], but */
734 /* structs must have a */
735 /* definite length */
738 typedef struct oper_list *LIST_OF_OPERATIONS; /* handle on a list */
740 #define size_of_list_of_operations(n) \
741 (sizeof(struct oper_list) + (n-1)*sizeof(OPERATION))
743 /*----------------------------------------------------------
747 * Pass this to select when doing a poll.
749 *----------------------------------------------------------*/
751 extern struct timeval gdb_notime;
754 /************************************************************************
756 * CHECKING ROUTINES IMPLEMENTED AS MACROS
758 ************************************************************************/
760 extern char g_errstr[150]; /* build emsgs here */
762 #define GDB_INIT_CHECK g_chk_init(); /* make sure gdb_init */
765 #define GDB_CHECK_CON(con, where) if ((con)->id != GDB_CON_ID) \
766 { (void) sprintf(g_errstr, "Invalid connection descriptor passed to \"%s\"\n", where); \
767 GDB_GIVEUP(g_errstr) }
770 #define GDB_CHECK_TUP(tup, where) if ((tup)->id != GDB_TUP_ID) \
771 { (void) sprintf(g_errstr, "Invalid tuple passed to \"%s\"\n", where); \
772 GDB_GIVEUP(g_errstr) }
775 #define GDB_CHECK_TPD(tpd, where) if ((tpd)->id != GDB_DESC_ID) \
776 { (void) sprintf(g_errstr, "Invalid tuple descriptor passed to \"%s\"\n", where); \
777 GDB_GIVEUP(g_errstr) }
780 #define GDB_CHECK_REL(rel, where) if ((rel)->id != GDB_REL_ID) \
781 { (void) sprintf(g_errstr, "Invalid relation passed to \"%s\"\n", where); \
782 GDB_GIVEUP(g_errstr) }
784 #define GDB_CHECK_OP(op, where) if ((op)->id != GDB_OP_ID) \
785 { (void) sprintf(g_errstr, "Invalid operation passed to \"%s\"\n", where); \
786 GDB_GIVEUP(g_errstr) }
788 #define GDB_CHECK_DB(db, where) if (db->id != GDB_DB_ID) \
789 { (void) sprintf(g_errstr, "Invalid database handle passed to \"%s\"\n", where); \
790 GDB_GIVEUP(g_errstr) }
795 /************************************************************************
797 * TRANSPORT ROUTINES IMPLEMENTED AS MACROS
799 ************************************************************************/
801 /*----------------------------------------------------------
805 * Returns the status of the indicated connection.
806 * Possible return values are:
808 * CON_STOPPED never started or terminated
809 * CON_UP currently usable
810 * CON_STARTING transient state on way up
811 * CON_STOPPING transient state on way down
813 *----------------------------------------------------------*/
815 #define connection_status(con) ((con)->status)
817 /*----------------------------------------------------------
821 * When a connection dies due to an error on a system
822 * call, the corresponding errno is recorded in the
823 * connection descriptor. This macro returns that value.
825 *----------------------------------------------------------*/
827 #define connection_errno(con) ((con)->errno)
831 /************************************************************************
833 * SERVER/CLIENT MANAGEMENT
835 * Definitions used in starting and maintaining communication
836 * between servers and clients (as opposed to peers.)
838 ************************************************************************/
840 #define GDB_MAX_SERVER_RETRIES 3 /* maximum number of times */
841 /* clients will accept */
842 /* forwarding requests from */
846 extern TUPLE_DESCRIPTOR gdb_tosrv; /* descriptor for request */
847 /* tuples sent to the */
848 /* server during negotiation*/
850 extern TUPLE_DESCRIPTOR gdb_fmsrv; /* descriptor for request */
851 /* tuples sent from the */
852 /* server during negotiation*/
854 #define GDB_MAX_SERVER_ID_SIZE 255 /* longest name of a server */
855 /* that we can handle */
856 #define GDB_MAX_SERVER_PARMS_SIZE 1023 /* longest parm string we */
857 /* can exchange between */
858 /* server and client*/
860 /*----------------------------------------------------------
862 * The following are values returned in the disposition
863 * field of the response tuple to indicate what the
864 * server has decided to do about the connection
867 *----------------------------------------------------------*/
869 #define GDB_ACCEPTED 1
870 #define GDB_REFUSED 2
871 #define GDB_FORWARDED 3
873 /*----------------------------------------------------------
875 * Global variables inherited by a child from a server
878 *----------------------------------------------------------*/
880 extern TUPLE gdb_client_tuple; /* request tuple sent from */
883 extern char gdb_sockaddr_of_client[100]; /* this should really be */
884 /* sockaddr_in, but I don't */
885 /* want everyone to have */
886 /* to include all those */
888 extern int gdb_socklen; /* length of above */
892 /************************************************************************
894 * DATABASE MANAGEMENT
896 * This layer of GDB provides access to the services of a relational
897 * database from anywhere in a GDB network.
899 ************************************************************************/
901 /*----------------------------------------------------------
905 * The name of the service, as found in /etc/services,
906 * for GDB database servers.
908 *----------------------------------------------------------*/
910 #define GDB_DB_SERVICE "#9420"
912 /*----------------------------------------------------------
916 * Describes a client's active connection to a database.
918 *----------------------------------------------------------*/
920 #define GDB_DB_ID 0x44420000 /* eye catcher */
923 long id; /* eye catcher */
924 CONNECTION connection; /* the GDB connection */
925 /* used to get at this */
927 int status; /* status of this */
928 /* database connection */
929 #define DB_OPEN 1 /* database opened */
931 #define DB_CLOSED 2 /* not open */
932 char *name; /* pointer to string name */
933 /* of the database, for */
935 char *server; /* pointer to the i.d. */
936 /* of the server, for */
940 typedef struct db_struct *DATABASE;
942 /*----------------------------------------------------------
944 * Return codes from DB operations
946 *----------------------------------------------------------*/
948 #define DB_NO_SUCH_OP 3
950 /*----------------------------------------------------------
952 * Parameters which limit sizes of things
954 *----------------------------------------------------------*/
956 #define GDB_MAX_QUERY_SIZE 2048 /* length of the longest */
957 /* substituted query */
958 /* string we can make */
959 #define GDB_MAX_QUERY_FIELDS 100 /* maximum number of fields */
960 /* we can retrieve in one */
962 #define GDB_SIZE_OF_INGRES_TEXT 2001 /* number of chars in */
963 /* largest ingres text */
965 #define GDB_MAX_RETRIEVED_TEXT_FIELDS 60 /* maximum number of text */
966 /* type fields we can */
967 /* retrieve in a single */
968 /* query. we hold this */
969 /* down because stack space */
970 /* is taken for max size of */
971 /* each during query. */
973 /*----------------------------------------------------------
975 * Return codes from database operations
977 *----------------------------------------------------------*/
979 #define DB_PARSE_FAIL (-3) /* couldn't parse */
980 /* the request string*/
983 /************************************************************************
985 * DATABASE OPERATIONS IMPLEMENTED
988 ************************************************************************/
990 /*----------------------------------------------------------
994 *----------------------------------------------------------*/
996 #define DB_STATUS(dbhandle) ((dbhandle)->status)
1001 /************************************************************************
1005 * To allow dynamic manipulation of strings in gdb without
1006 * excessive memory re-allocation, we define a string as a
1007 * counted byte space. Though this space will frequently be used
1008 * to store a standard null terminated string, that is not
1011 * Current representation for a string is a pointer followed by
1012 * an integer length. A null pointer indicates a null string, in
1013 * which case the length is arbitrary. Any other pointer is to
1014 * memory which was allocated by db_alloc in which must be free'd
1015 * eventually with db_free.
1017 ************************************************************************/
1019 typedef struct str_dat {
1020 char *ptr; /* pointer to the data */
1021 int length; /* length of the allocated */
1022 /* memory (not necessarily */
1023 /* length of null-term'd */
1024 /* string stored there) */
1027 /*----------------------------------------------------------
1029 * Macros for manipulating strings. These return
1030 * the actual data from the string and the size of
1031 * the data space respectively. To get the length of
1032 * the null terminated string which might be stored
1033 * there, use strlen(STRING_DATA(string)).
1035 *----------------------------------------------------------*/
1038 #define STRING_DATA(str) ((str).ptr)
1039 #define MAX_STRING_SIZE(str) ((str).length)
1042 /************************************************************************
1046 * db_alloc and db_free are the externally visible names of
1047 * the memory allocation services. These actually call the
1048 * routines pointed to by the vectors gdb_amv and gdb_fmv, which
1049 * default to the supplied routines gdb_am and gdb_fm. Users
1050 * may supply their own memory allocation by storing over the
1051 * vectors. This may be done prior to calling gdb_init to
1052 * insure that all dynamic memory is controlled by the user.
1054 ************************************************************************/
1056 #define db_alloc (*gdb_amv)
1057 #define db_free (*gdb_fmv)
1059 extern char *gdb_am();
1060 extern int gdb_fm();
1062 extern char *((*gdb_amv)());
1063 extern int (*gdb_fmv)();
1066 /************************************************************************
1068 * STRUCTURED DATA ROUTINES IMPLEMENTED AS MACROS
1070 ************************************************************************/
1072 /*----------------------------------------------------------
1074 * ADD_TUPLE_TO_RELATION
1076 *----------------------------------------------------------*/
1078 #define ADD_TUPLE_TO_RELATION(relation, tuple) \
1080 (tuple)->prev = (relation)->last; \
1081 (tuple)->next = (TUPLE)(relation); \
1082 (relation)->last = tuple; \
1083 (tuple)->prev->next = tuple; \
1086 /*----------------------------------------------------------
1088 * ADD_TUPLE_AFTER_TUPLE
1090 *----------------------------------------------------------*/
1092 #define ADD_TUPLE_AFTER_TUPLE(relation, tuple, prev_tuple) \
1094 (tuple)->prev = (prev_tuple)->next->prev; \
1095 (tuple)->next = (prev_tuple)->next; \
1096 (tuple)->next->prev = tuple; \
1097 (prev_tuple)->next = tuple; \
1100 /*----------------------------------------------------------
1102 * REMOVE_TUPLE_FROM_RELATION
1104 *----------------------------------------------------------*/
1106 #define REMOVE_TUPLE_FROM_RELATION(relation, tuple) \
1108 (tuple)->prev->next = (tuple)->next; \
1109 (tuple)->next->prev = (tuple)->prev; \
1113 /*----------------------------------------------------------
1115 * DESCRIPTOR_FROM_TUPLE
1117 *----------------------------------------------------------*/
1119 #define DESCRIPTOR_FROM_TUPLE(tuple) ((tuple)->desc)
1121 /*----------------------------------------------------------
1123 * DESCRIPTOR_FROM_RELATION
1125 *----------------------------------------------------------*/
1127 #define DESCRIPTOR_FROM_RELATION(relation) ((relation)->desc)
1129 /*----------------------------------------------------------
1131 * REFERENCE_TUPLE_DESCRIPTOR
1133 * Bumps the reference count for a tuple descriptor.
1134 * Intended only for internal use of GDB.
1136 *----------------------------------------------------------*/
1138 #define REFERENCE_TUPLE_DESCRIPTOR(tpd) (++((tpd)->ref_count))
1140 /*----------------------------------------------------------
1142 * UNREFERENCE_TUPLE_DESCRIPTOR
1144 * Decrements the reference count for a tuple descriptor.
1145 * Intended only for internal use of GDB. Warning: it
1146 * is the user's responsibility to use delete_tuple_descriptor
1147 * instead of this macro in any situation in which the
1148 * reference count might go to zero.
1150 *----------------------------------------------------------*/
1152 #define UNREFERENCE_TUPLE_DESCRIPTOR(tpd) (--((tpd)->ref_count))
1154 /*----------------------------------------------------------
1158 *----------------------------------------------------------*/
1160 #define FIELD_FROM_TUPLE(tuple, field_index) \
1161 (((tuple)->data) + (((tuple)->desc)->var[field_index].offset))
1163 /*----------------------------------------------------------
1165 * FIELD_OFFSET_IN_TUPLE
1167 *----------------------------------------------------------*/
1169 #define FIELD_OFFSET_IN_TUPLE(tuple_descriptor, field_index) \
1170 ((tuple_descriptor)->var[field_index].offset)
1172 /*----------------------------------------------------------
1174 * FIELD_TYPE_IN_TUPLE
1176 *----------------------------------------------------------*/
1178 #define FIELD_TYPE_IN_TUPLE(tuple_descriptor, field_index) \
1179 ((tuple_descriptor)->var[field_index].type)
1181 /*----------------------------------------------------------
1183 * FIRST_TUPLE_IN_RELATION
1185 *----------------------------------------------------------*/
1187 #define FIRST_TUPLE_IN_RELATION(relation) \
1188 (((relation)->first) == (TUPLE)relation ? NULL : (relation)-> first)
1190 /*----------------------------------------------------------
1192 * NEXT_TUPLE_IN_RELATION
1194 *----------------------------------------------------------*/
1196 #define NEXT_TUPLE_IN_RELATION(relation, prev) \
1197 (((prev)->next) == (TUPLE)relation ? NULL : prev->next )
1199 /*----------------------------------------------------------
1201 * PREV_TUPLE_IN_RELATION
1203 *----------------------------------------------------------*/
1205 #define PREV_TUPLE_IN_RELATION(relation, next) \
1206 (((next)->prev) == (TUPLE) relation ? NULL : next->prev)
1211 /************************************************************************
1213 * TRANSPORT and OPERATION SERVICES IMPLEMENTED AS MACROS
1215 ************************************************************************/
1217 /*----------------------------------------------------------
1219 * OPERATION_FROM_DATA
1221 * Given OPERATION_DATA, return the corresponding handle
1222 * of type OPERATION. Currently, OPERATION is just
1223 * implemented as a pointer to OPERATION_DATA.
1225 *----------------------------------------------------------*/
1227 #define OPERATION_FROM_DATA(op_data) \
1228 ((OPERATION)&(op_data))
1230 /*----------------------------------------------------------
1234 * Return the tag for a given operation.
1236 *----------------------------------------------------------*/
1238 #define OP_TAG(operation) ((operation)->tag)
1240 /*----------------------------------------------------------
1244 * Return the status of a given operation. Note that
1245 * status describes an operations progress through
1246 * execution. It has the same values for all operations.
1247 * Result describes the final outcome of an operation.
1248 * It's values depend on the particular operation which
1251 *----------------------------------------------------------*/
1253 #define OP_STATUS(operation) ((operation)->status)
1255 /*----------------------------------------------------------
1259 * True iff the operation is either OP_COMPLETE or
1262 *----------------------------------------------------------*/
1264 #define OP_DONE(op) ((op)->status == OP_COMPLETE || (op)->status == OP_CANCELLED)
1266 /*----------------------------------------------------------
1270 * Return the result of a given operation. Note that
1271 * status describes an operations progress through
1272 * execution. It has the same values for all operations.
1273 * Result describes the final outcome of an operation.
1274 * It's values depend on the particular operation which
1275 * was attempted. The special result value -1 is used
1276 * to indicate an invalid value for result. Generally,
1277 * -1 is returned when result is accidently queried at
1278 * a time when OP_STATUS != OPERATION_COMPLETE.
1280 *----------------------------------------------------------*/
1282 #define OP_RESULT(operation) ((operation)->result)
1285 /************************************************************************
1287 * Debugging Interfaces
1289 ************************************************************************/
1291 /*----------------------------------------------------------
1293 * The following operation codes my be passed to
1294 * gdb_debug to set special debugging modes of operation.
1296 * Note that most of these are toggles
1298 *----------------------------------------------------------*/
1300 #define GDB_LOG 0x00000001 /* turn on tracing to */
1302 #define GDB_NOFORK 0x00000002 /* don't fork forking */
1306 /************************************************************************
1308 * Things which have to be at the end because they require
1309 * the various types to be defined first.
1311 ************************************************************************/
1314 #ifdef DUMB_7_CHAR_LOADER
1315 /*----------------------------------------------------------
1317 * Long Names for Routines
1319 * External names in Unix must generally be unique
1320 * within the first 7 characters or so, at least for
1321 * some versions of ld. To account for this without
1322 * making all our routine names terribly short and
1323 * cryptic, we use the following defines.
1325 *----------------------------------------------------------*/
1327 #define string_alloc gdb_sta
1328 #define string_free gdb_stf
1330 #define create_tuple_descriptor gdb_ctd
1331 #define delete_tuple_descriptor gdb_dtd
1332 #define field_index gdb_fi
1333 #define create_tuple gdb_ctup
1334 #define delete_tuple gdb_dtup
1335 #define initialize_tuple gdb_itup
1336 #define null_tuple_strings gdb_ntps
1338 #define create_relation gdb_crel
1339 #define delete_relation gdb_drel
1340 #define tuples_in_relation gdb_trel
1346 #define create_operation gdb_crop
1347 #define delete_operation gdb_dop
1348 #define initialize_operation gdb_inop
1349 #define reset_operation gdb_rsop
1350 #define cancel_operation gdb_cnop
1352 #define create_list_of_operations gdb_clop
1353 #define delete_list_of_operations gdb_dlop
1355 #define op_select gdb_opsel
1356 #define op_select_any gdb_opsel
1357 #define op_select_all gdb_aopsel
1358 #define con_select gdb_cnsel
1360 #define gdb_receive_data gdb_rcdat
1361 #define gdb_send_data gdb_sndat
1362 #define gdb_start_listening gdb_stl
1363 #define start_accepting_client gdb_stac
1366 #define gdb_listen gdb_lis
1369 * Connection management
1371 #define start_peer_connection gdb_spconn
1372 #define sever_connection gdb_svconn
1373 #define start_server_connection gdb_stsrv
1374 #define create_listening_connection gdb_clc
1375 #define start_replying_to_client gdb_strtc
1376 #define create_forking_server gdb_cfs
1380 * Asynchronous operations
1382 #define start_sending_object gdb_snobj
1383 #define start_receiving_object gdb_rcobj
1384 #define preempt_and_start_receiving_object gdb_prcobj
1386 #define queue_operation gdb_qop
1388 #define requeue_operation g_req_op
1390 #define complete_operation gdb_cmpo
1392 * Synchronous operations
1394 #define send_object gdb_sobj
1395 #define receive_object gdb_robj
1397 * Database operations
1399 #define access_db gdb_adb
1400 #define start_accessing_db gdb_sadb
1401 #define perform_db_operation gdb_pdbo
1402 #define db_query gdb_dbq
1403 #define start_performing_db_operation gdb_spdb
1404 #define start_db_query gdb_sdbq
1406 #define op_select_any op_select
1407 #endif /* DUMB_7_CHAR_LOADER */
1409 extern char *string_alloc();
1410 extern int string_free();
1411 extern TUPLE_DESCRIPTOR create_tuple_descriptor();
1412 extern int delete_tuple_descriptor();
1413 extern int field_index();
1414 extern TUPLE create_tuple();
1415 extern int delete_tuple();
1416 extern int initialize_tuple();
1417 extern int null_tuple_strings();
1418 extern RELATION create_relation();
1419 extern int delete_relation();
1420 extern OPERATION create_operation();
1421 extern LIST_OF_OPERATIONS create_list_of_operations();
1422 extern OPERATION g_op_newhead();
1423 extern CONNECTION start_peer_connection();
1424 extern CONNECTION sever_connection();
1425 extern CONNECTION start_server_connection();
1426 extern CONNECTION create_listening_connection();
1427 extern CONNECTION create_forking_server();
1428 extern int start_sending_object();
1429 extern int start_receiving_object();
1430 extern int preempt_and_start_receiving_object();
1431 extern int queue_operation();
1432 extern int requeue_operation();
1433 extern int complete_operation();
1434 extern int send_object();
1435 extern int receive_object();
1438 /*----------------------------------------------------------
1440 * Other routines requiring extern to avoid forward
1441 * reference to non integer type functions.
1443 *----------------------------------------------------------*/
1445 extern CONNECTION g_make_con();