6 /************************************************************************
10 * Includes for the global database facility (gdb)
12 * Author: Noah Mendelsohn
13 * Copyright: 1986 MIT Project Athena
15 ************************************************************************/
18 * Note: following include may safely be done redundantly, so it doesn't
19 * matter if caller does it too. We need it for fd_set.
21 #include <sys/types.h>
33 #define max(a,b) ((a)>(b)?(a):(b))
37 #define min(a,b) ((a)<(b)?(a):(b))
44 #define howmany(x, y) (((x)+((y)-1))/(y))
47 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
48 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
49 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
50 #define FD_ZERO(p) bzero(p, sizeof(*(p)))
55 /*----------------------------------------------------------*
59 * This macro is called with a string argument whenever a
60 * fatal error is encounterd. If you re-define this
61 * macro, you can control the disposition of fatal gdb
64 * The gdb library must be recompiled for the change to
65 * take effect. That will have to be fixed sometime.
67 *----------------------------------------------------------*/
69 #define GDB_GIVEUP(errormsg) g_givup(errormsg);
71 /*----------------------------------------------------------*
75 * Round a number up to the next specified boundary.
77 *----------------------------------------------------------*/
79 #define GDB_ROUNDUP(n,b) ((((n)+(b)-1)/(b))*(b))
81 extern int gdb_Debug; /* debugging flags are */
83 extern FILE *gdb_log; /* file descriptor for */
84 /* logging gdb output */
88 * connection failure indicator
90 * This variable is used to communicate between gdb_move_data and
91 * g_con_progress without passing an extra parameter through lots
92 * of procedure calls. When set to FALSE, it indicates that the
93 * connection currently being processed has encountered a fatal error
94 * and should be severed.
97 /************************************************************************
101 * gdb_init puts the user's i.d. and hostname as strings here.
103 ************************************************************************/
105 extern char *gdb_uname; /* user's string name */
106 extern char *gdb_host; /* name of local host */
111 /************************************************************************
116 * Declarations used to control the definition and use of 'types'
117 * as supported by the global database system. Most of the
118 * declarations for 'System Defined Types' will not be of concern
119 * to typical users, with the exception of the type names like
120 * INTEGER_T which are defined below.
122 * In this implementation, user defined types are added
123 * dynamically during execution by calling the appropriate
124 * functions. The define GDB_MAX_TYPES below sets the maximum
125 * total number of types, including both system and user defined,
126 * which the system can support for any one application. When
127 * GDB_MAX_TYPES is changed, the libary must be re-built. Space
128 * for a two dimensional array, with one word for each property
129 * of each possible type, is allocated statically in the library.
131 ************************************************************************/
135 * Maximum number of types we can support, including both system and
139 #define GDB_MAX_TYPES 50
141 typedef int FIELD_TYPE; /* data needed to repre- */
142 /* sent a system or user */
143 /* defined data type */
144 /* This is actualy just */
145 /* a row index in the type */
146 /* definition table */
148 /*----------------------------------------------------------
150 * System defined types
152 * WARNING: Any changes to these type definitions must be
153 * carefully matched with the initializations in the
154 * gdb_i_stype routine in gdb_stype.c. Mistakes in these
155 * tables may be VERY difficult to debug. Be careful!
157 *----------------------------------------------------------*/
160 * Primitive types for ingres data
163 #define INTEGER_T (0)
172 #define TUPLE_DESCRIPTOR_T (4)
174 #define TUPLE_DATA_T (6)
175 #define RELATION_T (7)
178 * Number of system defined types
180 * This will always be equal to one more than index of last system type
183 #define SYSTEM_TYPE_COUNT 8
185 /*----------------------------------------------------------
187 * Type descriptor tables
189 *----------------------------------------------------------*/
194 * Each entry in the type definition table is a union of this form,
195 * which allows us to store a choice of an integer, a function
196 * pointer, or a pointer to a character string.
199 union gdb_prop_union {
200 int i; /* when we want as an */
202 int (*f)(); /* as a function pointer */
203 char *cp; /* character pointer */
206 #define TYPE_PROPERTY_COUNT 8 /* number of properties */
210 * Uses of the type properties. Each type has a set of properties.
211 * Some are integers, some are functions. The defines below descrive
212 * respectively the 0'th,1'st, 2'nd, etc. properties of EACH type.
214 * Note: TYPE_PROPERTY_COUNT (above) must be changed when new properties
215 * are added. For system defined types, bindings for the properties
216 * are done in gdb_i_stype in the gdb_stype.c source file.
219 #define LENGTH_PROPERTY 0 /* integer */
220 #define ALIGNMENT_PROPERTY 1 /* integer */
221 #define NULL_PROPERTY 2 /* function */
222 #define CODED_LENGTH_PROPERTY 3 /* function */
223 #define ENCODE_PROPERTY 4 /* function */
224 #define DECODE_PROPERTY 5 /* function */
225 #define FORMAT_PROPERTY 6 /* function */
226 #define NAME_PROPERTY 7 /* char pointer */
231 * Information to describe a single type
234 typedef union gdb_prop_union gdb_type_def[TYPE_PROPERTY_COUNT];
240 * This is the table where the actual definitions for the types are
244 extern gdb_type_def g_type_table[GDB_MAX_TYPES];
245 extern int gdb_n_types; /* number of entries in */
248 /*----------------------------------------------------------
250 * Macros for accessing properties
252 *----------------------------------------------------------*/
254 #define INT_PROPERTY(type, prop) (g_type_table[type][prop].i)
255 #define STR_PROPERTY(type, prop) (g_type_table[type][prop].cp)
256 #define FCN_PROPERTY(type, prop) (*g_type_table[type][prop].f)
259 /************************************************************************
263 * Stuff needed to declare and manage TUPLES, TUPLE_DESCRIPTORS
266 ************************************************************************/
268 /*----------------------------------------------------------
272 *----------------------------------------------------------*/
274 #define GDB_DESC_ID 0x54504400 /* "TPD" */
276 struct tupld_var { /* the variable length */
277 /* stuff in a tuple */
279 char *name; /* string name of field */
280 FIELD_TYPE type; /* type of this field */
281 int offset; /* byte offset of this field */
282 /* relative to first byte of */
283 /* data (not start of whole */
285 int length; /* Length of the actual data */
286 /* for this field. Note that */
287 /* alignment requirements of */
288 /* following field are NOT */
289 /* included in this length */
292 long id; /* this should say TPD\0 */
293 int ref_count; /* when this goes to zero, */
294 /* the descriptor may really */
296 int field_count; /* number of fields in */
298 int data_len; /* length of the data in */
299 /* the actual tuple */
300 int str_len; /* length of the strings */
301 /* stored off the end of */
303 struct tupld_var var[1]; /* one of these for each */
304 /* field, but the C compiler */
305 /* won't accept the[] decl, */
306 /* because it's afraid of */
307 /* uncertain length*/
310 typedef struct tupl_desc *TUPLE_DESCRIPTOR; /* use this to declare a */
311 /* tuple descriptor anchor */
313 #define gdb_descriptor_length(num_flds) (sizeof(struct tupl_desc) + ((num_flds)-1) * sizeof(struct tupld_var))
315 /*----------------------------------------------------------
319 * tuple_dat is allocated by the create_tuple routine.
321 * TUPLE may be used in user code to declare a handle
324 *----------------------------------------------------------*/
326 #define GDB_TUP_ID 0x54555000
328 typedef struct tuple_dat *TUPLE; /* handle on a tuple */
331 TUPLE next, prev; /* chain pointers when */
332 /* tuples are linked, as in */
333 /* a relation. Convention is*/
334 /* double linked, circular.*/
335 long id; /* should say TUP\0 */
336 TUPLE_DESCRIPTOR desc; /* pointer to the descriptor */
337 char data[1]; /* data goes here, word */
338 /* aligned. Should be [] */
339 /* if compiler would allow */
343 /*----------------------------------------------------------
347 * rel_dat is allocated by the create_relation
350 * RELATION may be used in user code to declare a handle
353 *----------------------------------------------------------*/
355 #define GDB_REL_ID 0x52454c00
358 TUPLE first, last; /* chain pointers to tuples */
359 /* note that first->prev and */
360 /* last->next are both == */
361 /* &rel-dat. Maintenance is */
362 /* simplified by keeping */
363 /* as the first fields in */
364 /* both rel_dat and tuple_dat*/
365 /* a minor non-portability */
366 long id; /* should contain REL\0 */
367 TUPLE_DESCRIPTOR desc; /* descriptor for the tuples */
368 /* in this relation. Should */
369 /* == that in each tuple */
373 typedef struct rel_dat *RELATION; /* handle on a relation */
375 /************************************************************************
377 * transport LAYER DECLARATIONS
379 * Declares the state maintenance structures for full duplex
380 * connections with asynchronous transmission capability. Most
381 * users need only know that the type CONNECTION is defined, and
382 * that it may be treated as a pointer for most purposes (i.e. it
383 * is compact, and copying it does not actually copy the connection
386 ************************************************************************/
388 #define GDB_PROTOCOL_VERSION 0x01 /* version of the gdb */
389 /* protocols that we're */
391 #define GDB_STREAM_BUFFER_SIZE 4096 /* amount to read in */
392 /* one chunk from tcp stream*/
393 #define GDB_PORT htons(9425) /* temporary until we use */
394 /* services properly */
395 #define GDB_BIND_RETRY_COUNT 5 /* number of times to */
396 /* retry a bind before */
397 /* giving up. Used when */
398 /* accepting connections */
399 #define GDB_BIND_RETRY_INTERVAL 10 /* Number of seconds to wait */
400 /* between attempts to bind */
401 /* the listening socket */
402 #define GDB_MAX_CONNECTIONS 25 /* maximum number of */
403 /* connections that */
404 /* any one process can */
405 /* control simultaneously */
407 * Circumvent bug in ACIS 4.2 socket support
410 #define GDB_MAX_SOCK_WRITE 2047 /* rt can't do socket */
411 /* writes longer than this */
414 #define GDB_MAX_SOCK_WRITE 0x00ffffff
417 /*----------------------------------------------------------
419 * Declarations for HALF_CONNECTIONS
421 * Each full duplex connection has associated with it
422 * two simplex half-connections, each of which
423 * has its own queue of pending operations. The
424 * following describes the state of a half-connection.
426 *----------------------------------------------------------*/
428 struct half_con_data {
430 * these two must be first to match position in OPERATION
432 struct oper_data *op_q_first; /* first item in q of pending*/
433 /* operations for this */
434 /* half-connection. (chained */
435 /* circularly to half con, */
437 struct oper_data *op_q_last; /* last item in q of pending*/
438 /* operations for this */
440 int status; /* values are of type */
441 /* OPSTATUS. tells whether */
442 /* transmit/receive is */
444 long flags; /* bit flags */
445 #define HCON_PROGRESS 0x00000001 /* used by selection */
446 /* routines to detect */
448 #define HCON_LISTEN 0x00000002 /* indicates that this is */
449 /* a special half connection */
450 /* used only for listenting */
451 /* to incoming connection */
453 #define HCON_UNUSED 0x00000004 /* on a one-way connection, */
454 /* this flag marks an unused */
456 #define HCON_PENDING_LISTEN 0x00000008 /* a queued op on this half */
457 /* connection is actually */
458 /* trying to listen */
459 #define HCON_BUSY 0x00000010 /* we are currently making */
460 /* progress on this half */
461 /* connection. Used to */
462 /* detect re-entrance of */
464 int fd; /* main half duplex file */
465 /* descriptor for this h_conn*/
466 int oob_fd; /* file descriptor for */
467 /* out of band signals*/
468 char *next_byte; /* next byte to send/recv */
469 int remaining; /* number of bytes remaining */
470 /* to send/receive */
471 char *stream_buffer; /* points to a buffer */
472 /* used to pre-read/write */
473 /* the stream to avoid */
474 /* window thrashing */
475 int stream_buffer_length; /* length of the stream */
477 char *stream_buffer_next; /* next byte to read in */
479 int stream_buffer_remaining; /* number of bytes currently */
480 /* in use in stream buffer*/
481 int *accepted_fdp; /* used only for listening */
482 /* connections. latest */
483 /* accepted fd is put where*/
485 int *accepted_len; /* ptr to length of 'from' */
490 typedef struct half_con_data *HALF_CONNECTION;
493 /*----------------------------------------------------------
495 * Declarations for CONNECTIONS
497 *----------------------------------------------------------*/
499 #define GDB_CON_ID 0x434f4e00 /*"CON"*/
502 long id; /* should contain CON\0 */
503 int status; /* See definitions below. */
504 /* Do not confuse with */
505 /* the status sub-fields of */
506 /* in and out half-cons. */
507 int version; /* the version of the */
508 /* protocol being observed */
509 /* on this connection */
510 int errno; /* the real errno gets */
511 /* copied here if it causes */
512 /* the connection to die */
513 int (*oob_fcn)(); /* pointer to function to */
514 /* call when something */
515 /* arrives on the out of */
517 struct half_con_data in, out; /* states of the inbound */
518 /* and outbound half */
522 typedef struct con_data *CONNECTION; /* the only externally */
523 /* visible handle on a */
527 * Definitions of status fields.
529 * WARNING: If you change any of the following, there are coordinated
530 * changes to be made in gdb_debug.c
533 #define CON_STOPPED 1 /* never started, terminated */
534 #define CON_UP 2 /* ready to use */
535 #define CON_STARTING 3 /* trying to start */
536 #define CON_STOPPING 4 /* trying to stop */
539 * The following are used as keywords when distinguishing input from output
542 #define CON_INPUT 1 /* this is an input half */
544 #define CON_OUTPUT 2 /* this is an output half */
548 /*----------------------------------------------------------
552 * This is the array of connection control data
553 * structures for gdb. Every connection has its
554 * structure stored here, but they are in no
555 * particular order. Because the connection data
556 * itself cannot be moved (due to possible dangling
557 * pointers), there may be some unused connections
558 * in the middle of this array. gdb_mcons is the
559 * 1 based number of the highest connection which is
560 * actually in use at this time. This is a considerable
561 * optimization for the typical case where very few
562 * are in use, and turnover is low.
564 * These are externs for globals defined in gdb_lib.h
565 * and included by gdb.c.
567 *----------------------------------------------------------*/
569 extern int gdb_mcons; /* one based number of the */
570 /* highest connection */
571 /* descriptor we're using */
574 extern int gdb_mfd; /* number of the highest */
575 /* file descriptor in use */
576 /* for a connection */
577 extern struct con_data gdb_cons[GDB_MAX_CONNECTIONS];
578 /* actual connection data */
581 extern fd_set gdb_crfds, gdb_cwfds, gdb_cefds; /* connection related file */
582 /* descriptor maps to be */
584 fd_set last_crfds, last_cwfds, last_cefds; /* these file desc. bit */
585 /* masks are set up */
586 /* for each select call */
587 /* to include the user */
588 /* supplied and the */
589 /* connection related */
592 /*----------------------------------------------------------
596 *----------------------------------------------------------*/
598 #define GDB_OP_ID 0x4f505200
601 struct oper_data *next, *prev; /* forward and back chain */
602 long id; /* should contain OPR\0 */
603 int tag; /* unique identifier for */
605 int status; /* current state of this */
608 #define OPF_MARKED_COMPLETE 0x00000001 /* operation was already */
609 /* complete when opsel was */
611 #define OPF_MARKED_CANCELLED 0x00000002 /* operation was already */
612 /* cancelled when opsel was */
614 int result; /* when the operation */
615 /* completes, this field is */
616 /* set to reflect its dispos-*/
617 /* ition. Contents of this */
618 /* field will depend on the */
619 /* operation being performed */
620 HALF_CONNECTION halfcon; /* the half connection on */
621 /* which this operation is */
623 /* May be meaningless if not */
625 char *arg; /* pointer to user data */
627 int (*init)(); /* pointer to routine to */
628 /* call to start this */
631 int (*cont)(); /* pointer to function to */
632 /* be called when this */
633 /* logical operation */
637 int (*cancel)(); /* this routine gets called */
638 /* to handle a cancel request*/
639 /* this field is normally */
640 /* set to NULL when the */
641 /* operation is queued and */
642 /* updated as required by */
643 /* the init and cont funcs. */
646 typedef struct oper_data OPERATION_DATA; /* an actual operation */
647 /* descritor, creator is */
648 /* responsible for making */
649 /* sure that memory is not */
650 /* freed while in use */
651 typedef OPERATION_DATA *OPERATION; /* a handle on an operation */
652 /* this is what most */
653 /* applications will use */
655 /*----------------------------------------------------------
657 * STATES OF AN OPERATION
659 * These represent the state of an asynchronous, queued
660 * operation. For convenience of the application programmer,
661 * some of these are folded together when queried through the
662 * operation_status routine. In particular, operation status
663 * returns only one of:
665 * OP_NOT_RUNNING, OP_RUNNING, OP_COMPLETE, or
668 * Any other status is reported as OP_RUNNING. This is
669 * done on the assumption that it makes correct coding
670 * of applications less error-prone, as there are fewer
671 * cases to check, and most of them would not be of
674 * Note that OP_CANCELLED may be generated by the system
675 * even when no explicit request for cancellation has been
676 * issued. For example, this may occur when a connection
677 * is severed unexpectedly.
679 * WARNING: If you change any of the following, be sure
680 * to make the equivalent changes to gdb_debug.c.
682 * We also define here certain standard values of OP_RESULT,
683 * since some return conventions presume that op_status
684 * and op_result values are orthogonal.
686 *----------------------------------------------------------*/
688 #define OP_SUCCESS 0 /* this value is actually */
689 /* used only in result */
690 /* fields, but it is */
691 /* sometimes convenient to */
692 /* have status and result */
693 /* have orthogonal values */
694 #define OP_NOT_STARTED 1 /* this operation has been */
695 /* initialized but is not on */
696 /* any connection's queue */
697 #define OP_QUEUED 2 /* this operation is on */
698 /* some connection's queue */
699 /* but it has not yet */
700 /* reached the head of the q */
701 #define OP_RUNNING 3 /* op is at head of q trying */
703 #define OP_COMPLETE 4 /* operation has run to */
704 /* completion. result field */
706 #define OP_CANCELLING 5 /* we are in the process of */
707 /* (trying to) cancel this */
709 #define OP_CANCELLED 6 /* operation was prematurely */
710 /* terminated. result field */
712 #define OP_MARKED 7 /* used by op_select_all */
713 #define OP_REQUEUED 8 /* returned by an init or */
714 /* continuation routine to */
715 /* indicate that the */
716 /* operation has requeued */
718 #define OP_PREEMPTED 9 /* returned by an init or */
719 /* continuation routine to */
720 /* indicate that the op has */
721 /* preempted itself by */
722 /* queueing a new operation */
723 /* ahead of itself */
725 /*----------------------------------------------------------
729 *----------------------------------------------------------*/
732 int count; /* number of operations */
734 OPERATION op[1]; /* really op[n], but */
735 /* structs must have a */
736 /* definite length */
739 typedef struct oper_list *LIST_OF_OPERATIONS; /* handle on a list */
741 #define size_of_list_of_operations(n) \
742 (sizeof(struct oper_list) + (n-1)*sizeof(OPERATION))
744 /*----------------------------------------------------------
748 * Pass this to select when doing a poll.
750 *----------------------------------------------------------*/
752 extern struct timeval gdb_notime;
755 /************************************************************************
757 * CHECKING ROUTINES IMPLEMENTED AS MACROS
759 ************************************************************************/
761 extern char g_errstr[150]; /* build emsgs here */
763 #define GDB_INIT_CHECK g_chk_init(); /* make sure gdb_init */
766 #define GDB_CHECK_CON(con, where) if ((con)->id != GDB_CON_ID) \
767 { (void) sprintf(g_errstr, "Invalid connection descriptor passed to \"%s\"\n", where); \
768 GDB_GIVEUP(g_errstr) }
771 #define GDB_CHECK_TUP(tup, where) if ((tup)->id != GDB_TUP_ID) \
772 { (void) sprintf(g_errstr, "Invalid tuple passed to \"%s\"\n", where); \
773 GDB_GIVEUP(g_errstr) }
776 #define GDB_CHECK_TPD(tpd, where) if ((tpd)->id != GDB_DESC_ID) \
777 { (void) sprintf(g_errstr, "Invalid tuple descriptor passed to \"%s\"\n", where); \
778 GDB_GIVEUP(g_errstr) }
781 #define GDB_CHECK_REL(rel, where) if ((rel)->id != GDB_REL_ID) \
782 { (void) sprintf(g_errstr, "Invalid relation passed to \"%s\"\n", where); \
783 GDB_GIVEUP(g_errstr) }
785 #define GDB_CHECK_OP(op, where) if ((op)->id != GDB_OP_ID) \
786 { (void) sprintf(g_errstr, "Invalid operation passed to \"%s\"\n", where); \
787 GDB_GIVEUP(g_errstr) }
789 #define GDB_CHECK_DB(db, where) if (db->id != GDB_DB_ID) \
790 { (void) sprintf(g_errstr, "Invalid database handle passed to \"%s\"\n", where); \
791 GDB_GIVEUP(g_errstr) }
796 /************************************************************************
798 * TRANSPORT ROUTINES IMPLEMENTED AS MACROS
800 ************************************************************************/
802 /*----------------------------------------------------------
806 * Returns the status of the indicated connection.
807 * Possible return values are:
809 * CON_STOPPED never started or terminated
810 * CON_UP currently usable
811 * CON_STARTING transient state on way up
812 * CON_STOPPING transient state on way down
814 *----------------------------------------------------------*/
816 #define connection_status(con) ((con)->status)
818 /*----------------------------------------------------------
822 * When a connection dies due to an error on a system
823 * call, the corresponding errno is recorded in the
824 * connection descriptor. This macro returns that value.
826 *----------------------------------------------------------*/
828 #define connection_errno(con) ((con)->errno)
832 /************************************************************************
834 * SERVER/CLIENT MANAGEMENT
836 * Definitions used in starting and maintaining communication
837 * between servers and clients (as opposed to peers.)
839 ************************************************************************/
841 #define GDB_MAX_SERVER_RETRIES 3 /* maximum number of times */
842 /* clients will accept */
843 /* forwarding requests from */
847 extern TUPLE_DESCRIPTOR gdb_tosrv; /* descriptor for request */
848 /* tuples sent to the */
849 /* server during negotiation*/
851 extern TUPLE_DESCRIPTOR gdb_fmsrv; /* descriptor for request */
852 /* tuples sent from the */
853 /* server during negotiation*/
855 #define GDB_MAX_SERVER_ID_SIZE 255 /* longest name of a server */
856 /* that we can handle */
857 #define GDB_MAX_SERVER_PARMS_SIZE 1023 /* longest parm string we */
858 /* can exchange between */
859 /* server and client*/
861 /*----------------------------------------------------------
863 * The following are values returned in the disposition
864 * field of the response tuple to indicate what the
865 * server has decided to do about the connection
868 *----------------------------------------------------------*/
870 #define GDB_ACCEPTED 1
871 #define GDB_REFUSED 2
872 #define GDB_FORWARDED 3
874 /*----------------------------------------------------------
876 * Global variables inherited by a child from a server
879 *----------------------------------------------------------*/
881 extern TUPLE gdb_client_tuple; /* request tuple sent from */
884 extern char gdb_sockaddr_of_client[100]; /* this should really be */
885 /* sockaddr_in, but I don't */
886 /* want everyone to have */
887 /* to include all those */
889 extern int gdb_socklen; /* length of above */
893 /************************************************************************
895 * DATABASE MANAGEMENT
897 * This layer of GDB provides access to the services of a relational
898 * database from anywhere in a GDB network.
900 ************************************************************************/
902 /*----------------------------------------------------------
906 * The name of the service, as found in /etc/services,
907 * for GDB database servers.
909 *----------------------------------------------------------*/
911 #define GDB_DB_SERVICE "#9420"
913 /*----------------------------------------------------------
917 * Describes a client's active connection to a database.
919 *----------------------------------------------------------*/
921 #define GDB_DB_ID 0x44420000 /* eye catcher */
924 long id; /* eye catcher */
925 CONNECTION connection; /* the GDB connection */
926 /* used to get at this */
928 int status; /* status of this */
929 /* database connection */
930 #define DB_OPEN 1 /* database opened */
932 #define DB_CLOSED 2 /* not open */
933 char *name; /* pointer to string name */
934 /* of the database, for */
936 char *server; /* pointer to the i.d. */
937 /* of the server, for */
941 typedef struct db_struct *DATABASE;
943 /*----------------------------------------------------------
945 * Return codes from DB operations
947 *----------------------------------------------------------*/
949 #define DB_NO_SUCH_OP 3
951 /*----------------------------------------------------------
953 * Parameters which limit sizes of things
955 *----------------------------------------------------------*/
957 #define GDB_MAX_QUERY_SIZE 2048 /* length of the longest */
958 /* substituted query */
959 /* string we can make */
960 #define GDB_MAX_QUERY_FIELDS 100 /* maximum number of fields */
961 /* we can retrieve in one */
963 #define GDB_SIZE_OF_INGRES_TEXT 2001 /* number of chars in */
964 /* largest ingres text */
966 #define GDB_MAX_RETRIEVED_TEXT_FIELDS 60 /* maximum number of text */
967 /* type fields we can */
968 /* retrieve in a single */
969 /* query. we hold this */
970 /* down because stack space */
971 /* is taken for max size of */
972 /* each during query. */
974 /*----------------------------------------------------------
976 * Return codes from database operations
978 *----------------------------------------------------------*/
980 #define DB_PARSE_FAIL (-3) /* couldn't parse */
981 /* the request string*/
984 /************************************************************************
986 * DATABASE OPERATIONS IMPLEMENTED
989 ************************************************************************/
991 /*----------------------------------------------------------
995 *----------------------------------------------------------*/
997 #define DB_STATUS(dbhandle) ((dbhandle)->status)
1002 /************************************************************************
1006 * To allow dynamic manipulation of strings in gdb without
1007 * excessive memory re-allocation, we define a string as a
1008 * counted byte space. Though this space will frequently be used
1009 * to store a standard null terminated string, that is not
1012 * Current representation for a string is a pointer followed by
1013 * an integer length. A null pointer indicates a null string, in
1014 * which case the length is arbitrary. Any other pointer is to
1015 * memory which was allocated by db_alloc in which must be free'd
1016 * eventually with db_free.
1018 ************************************************************************/
1020 typedef struct str_dat {
1021 char *ptr; /* pointer to the data */
1022 int length; /* length of the allocated */
1023 /* memory (not necessarily */
1024 /* length of null-term'd */
1025 /* string stored there) */
1028 /*----------------------------------------------------------
1030 * Macros for manipulating strings. These return
1031 * the actual data from the string and the size of
1032 * the data space respectively. To get the length of
1033 * the null terminated string which might be stored
1034 * there, use strlen(STRING_DATA(string)).
1036 *----------------------------------------------------------*/
1039 #define STRING_DATA(str) ((str).ptr)
1040 #define MAX_STRING_SIZE(str) ((str).length)
1043 /************************************************************************
1047 * db_alloc and db_free are the externally visible names of
1048 * the memory allocation services. These actually call the
1049 * routines pointed to by the vectors gdb_amv and gdb_fmv, which
1050 * default to the supplied routines gdb_am and gdb_fm. Users
1051 * may supply their own memory allocation by storing over the
1052 * vectors. This may be done prior to calling gdb_init to
1053 * insure that all dynamic memory is controlled by the user.
1055 ************************************************************************/
1057 #define db_alloc (*gdb_amv)
1058 #define db_free (*gdb_fmv)
1060 extern char *gdb_am();
1061 extern int gdb_fm();
1063 extern char *((*gdb_amv)());
1064 extern int (*gdb_fmv)();
1067 /************************************************************************
1069 * STRUCTURED DATA ROUTINES IMPLEMENTED AS MACROS
1071 ************************************************************************/
1073 /*----------------------------------------------------------
1075 * ADD_TUPLE_TO_RELATION
1077 *----------------------------------------------------------*/
1079 #define ADD_TUPLE_TO_RELATION(relation, tuple) \
1081 (tuple)->prev = (relation)->last; \
1082 (tuple)->next = (TUPLE)(relation); \
1083 (relation)->last = tuple; \
1084 (tuple)->prev->next = tuple; \
1087 /*----------------------------------------------------------
1089 * ADD_TUPLE_AFTER_TUPLE
1091 *----------------------------------------------------------*/
1093 #define ADD_TUPLE_AFTER_TUPLE(relation, tuple, prev_tuple) \
1095 (tuple)->prev = (prev_tuple)->next->prev; \
1096 (tuple)->next = (prev_tuple)->next; \
1097 (tuple)->next->prev = tuple; \
1098 (prev_tuple)->next = tuple; \
1101 /*----------------------------------------------------------
1103 * REMOVE_TUPLE_FROM_RELATION
1105 *----------------------------------------------------------*/
1107 #define REMOVE_TUPLE_FROM_RELATION(relation, tuple) \
1109 (tuple)->prev->next = (tuple)->next; \
1110 (tuple)->next->prev = (tuple)->prev; \
1114 /*----------------------------------------------------------
1116 * DESCRIPTOR_FROM_TUPLE
1118 *----------------------------------------------------------*/
1120 #define DESCRIPTOR_FROM_TUPLE(tuple) ((tuple)->desc)
1122 /*----------------------------------------------------------
1124 * DESCRIPTOR_FROM_RELATION
1126 *----------------------------------------------------------*/
1128 #define DESCRIPTOR_FROM_RELATION(relation) ((relation)->desc)
1130 /*----------------------------------------------------------
1132 * REFERENCE_TUPLE_DESCRIPTOR
1134 * Bumps the reference count for a tuple descriptor.
1135 * Intended only for internal use of GDB.
1137 *----------------------------------------------------------*/
1139 #define REFERENCE_TUPLE_DESCRIPTOR(tpd) (++((tpd)->ref_count))
1141 /*----------------------------------------------------------
1143 * UNREFERENCE_TUPLE_DESCRIPTOR
1145 * Decrements the reference count for a tuple descriptor.
1146 * Intended only for internal use of GDB. Warning: it
1147 * is the user's responsibility to use delete_tuple_descriptor
1148 * instead of this macro in any situation in which the
1149 * reference count might go to zero.
1151 *----------------------------------------------------------*/
1153 #define UNREFERENCE_TUPLE_DESCRIPTOR(tpd) (--((tpd)->ref_count))
1155 /*----------------------------------------------------------
1159 *----------------------------------------------------------*/
1161 #define FIELD_FROM_TUPLE(tuple, field_index) \
1162 (((tuple)->data) + (((tuple)->desc)->var[field_index].offset))
1164 /*----------------------------------------------------------
1166 * FIELD_OFFSET_IN_TUPLE
1168 *----------------------------------------------------------*/
1170 #define FIELD_OFFSET_IN_TUPLE(tuple_descriptor, field_index) \
1171 ((tuple_descriptor)->var[field_index].offset)
1173 /*----------------------------------------------------------
1175 * FIELD_TYPE_IN_TUPLE
1177 *----------------------------------------------------------*/
1179 #define FIELD_TYPE_IN_TUPLE(tuple_descriptor, field_index) \
1180 ((tuple_descriptor)->var[field_index].type)
1182 /*----------------------------------------------------------
1184 * FIRST_TUPLE_IN_RELATION
1186 *----------------------------------------------------------*/
1188 #define FIRST_TUPLE_IN_RELATION(relation) \
1189 (((relation)->first) == (TUPLE)relation ? NULL : (relation)-> first)
1191 /*----------------------------------------------------------
1193 * NEXT_TUPLE_IN_RELATION
1195 *----------------------------------------------------------*/
1197 #define NEXT_TUPLE_IN_RELATION(relation, prev) \
1198 (((prev)->next) == (TUPLE)relation ? NULL : prev->next )
1200 /*----------------------------------------------------------
1202 * PREV_TUPLE_IN_RELATION
1204 *----------------------------------------------------------*/
1206 #define PREV_TUPLE_IN_RELATION(relation, next) \
1207 (((next)->prev) == (TUPLE) relation ? NULL : next->prev)
1212 /************************************************************************
1214 * TRANSPORT and OPERATION SERVICES IMPLEMENTED AS MACROS
1216 ************************************************************************/
1218 /*----------------------------------------------------------
1220 * OPERATION_FROM_DATA
1222 * Given OPERATION_DATA, return the corresponding handle
1223 * of type OPERATION. Currently, OPERATION is just
1224 * implemented as a pointer to OPERATION_DATA.
1226 *----------------------------------------------------------*/
1228 #define OPERATION_FROM_DATA(op_data) \
1229 ((OPERATION)&(op_data))
1231 /*----------------------------------------------------------
1235 * Return the tag for a given operation.
1237 *----------------------------------------------------------*/
1239 #define OP_TAG(operation) ((operation)->tag)
1241 /*----------------------------------------------------------
1245 * Return the status of a given operation. Note that
1246 * status describes an operations progress through
1247 * execution. It has the same values for all operations.
1248 * Result describes the final outcome of an operation.
1249 * It's values depend on the particular operation which
1252 *----------------------------------------------------------*/
1254 #define OP_STATUS(operation) ((operation)->status)
1256 /*----------------------------------------------------------
1260 * True iff the operation is either OP_COMPLETE or
1263 *----------------------------------------------------------*/
1265 #define OP_DONE(op) ((op)->status == OP_COMPLETE || (op)->status == OP_CANCELLED)
1267 /*----------------------------------------------------------
1271 * Return the result of a given operation. Note that
1272 * status describes an operations progress through
1273 * execution. It has the same values for all operations.
1274 * Result describes the final outcome of an operation.
1275 * It's values depend on the particular operation which
1276 * was attempted. The special result value -1 is used
1277 * to indicate an invalid value for result. Generally,
1278 * -1 is returned when result is accidently queried at
1279 * a time when OP_STATUS != OPERATION_COMPLETE.
1281 *----------------------------------------------------------*/
1283 #define OP_RESULT(operation) ((operation)->result)
1286 /************************************************************************
1288 * Debugging Interfaces
1290 ************************************************************************/
1292 /*----------------------------------------------------------
1294 * The following operation codes my be passed to
1295 * gdb_debug to set special debugging modes of operation.
1297 * Note that most of these are toggles
1299 *----------------------------------------------------------*/
1301 #define GDB_LOG 0x00000001 /* turn on tracing to */
1303 #define GDB_NOFORK 0x00000002 /* don't fork forking */
1307 /************************************************************************
1309 * Things which have to be at the end because they require
1310 * the various types to be defined first.
1312 ************************************************************************/
1315 #ifdef DUMB_7_CHAR_LOADER
1316 /*----------------------------------------------------------
1318 * Long Names for Routines
1320 * External names in Unix must generally be unique
1321 * within the first 7 characters or so, at least for
1322 * some versions of ld. To account for this without
1323 * making all our routine names terribly short and
1324 * cryptic, we use the following defines.
1326 *----------------------------------------------------------*/
1328 #define string_alloc gdb_sta
1329 #define string_free gdb_stf
1331 #define create_tuple_descriptor gdb_ctd
1332 #define delete_tuple_descriptor gdb_dtd
1333 #define field_index gdb_fi
1334 #define create_tuple gdb_ctup
1335 #define delete_tuple gdb_dtup
1336 #define initialize_tuple gdb_itup
1337 #define null_tuple_strings gdb_ntps
1339 #define create_relation gdb_crel
1340 #define delete_relation gdb_drel
1341 #define tuples_in_relation gdb_trel
1347 #define create_operation gdb_crop
1348 #define delete_operation gdb_dop
1349 #define initialize_operation gdb_inop
1350 #define reset_operation gdb_rsop
1351 #define cancel_operation gdb_cnop
1353 #define create_list_of_operations gdb_clop
1354 #define delete_list_of_operations gdb_dlop
1356 #define op_select gdb_opsel
1357 #define op_select_any gdb_opsel
1358 #define op_select_all gdb_aopsel
1359 #define con_select gdb_cnsel
1361 #define gdb_receive_data gdb_rcdat
1362 #define gdb_send_data gdb_sndat
1363 #define gdb_start_listening gdb_stl
1364 #define start_accepting_client gdb_stac
1367 #define gdb_listen gdb_lis
1370 * Connection management
1372 #define start_peer_connection gdb_spconn
1373 #define sever_connection gdb_svconn
1374 #define start_server_connection gdb_stsrv
1375 #define create_listening_connection gdb_clc
1376 #define start_replying_to_client gdb_strtc
1377 #define create_forking_server gdb_cfs
1381 * Asynchronous operations
1383 #define start_sending_object gdb_snobj
1384 #define start_receiving_object gdb_rcobj
1385 #define preempt_and_start_receiving_object gdb_prcobj
1387 #define queue_operation gdb_qop
1389 #define requeue_operation g_req_op
1391 #define complete_operation gdb_cmpo
1393 * Synchronous operations
1395 #define send_object gdb_sobj
1396 #define receive_object gdb_robj
1398 * Database operations
1400 #define access_db gdb_adb
1401 #define start_accessing_db gdb_sadb
1402 #define perform_db_operation gdb_pdbo
1403 #define db_query gdb_dbq
1404 #define start_performing_db_operation gdb_spdb
1405 #define start_db_query gdb_sdbq
1407 #define op_select_any op_select
1408 #endif DUMB_7_CHAR_LOADER
1410 extern char *string_alloc();
1411 extern int string_free();
1412 extern TUPLE_DESCRIPTOR create_tuple_descriptor();
1413 extern int delete_tuple_descriptor();
1414 extern int field_index();
1415 extern TUPLE create_tuple();
1416 extern int delete_tuple();
1417 extern int initialize_tuple();
1418 extern int null_tuple_strings();
1419 extern RELATION create_relation();
1420 extern int delete_relation();
1421 extern OPERATION create_operation();
1422 extern LIST_OF_OPERATIONS create_list_of_operations();
1423 extern OPERATION g_op_newhead();
1424 extern CONNECTION start_peer_connection();
1425 extern CONNECTION sever_connection();
1426 extern CONNECTION start_server_connection();
1427 extern CONNECTION create_listening_connection();
1428 extern CONNECTION create_forking_server();
1429 extern int start_sending_object();
1430 extern int start_receiving_object();
1431 extern int preempt_and_start_receiving_object();
1432 extern int queue_operation();
1433 extern int requeue_operation();
1434 extern int complete_operation();
1435 extern int send_object();
1436 extern int receive_object();
1439 /*----------------------------------------------------------
1441 * Other routines requiring extern to avoid forward
1442 * reference to non integer type functions.
1444 *----------------------------------------------------------*/
1446 extern CONNECTION g_make_con();