]> andersk Git - moira.git/blame - include/gdb.h
added U_COMMENT & U_SIGNATURE
[moira.git] / include / gdb.h
CommitLineData
5580185e 1/*
5580185e 2 * $Header$
3 */
4
939744d7 5/************************************************************************
6 *
7 * gdb.h
8 *
9 * Includes for the global database facility (gdb)
10 *
11 * Author: Noah Mendelsohn
12 * Copyright: 1986 MIT Project Athena
13 *
14 ************************************************************************/
5580185e 15
16/*
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.
19 */
20#include <sys/types.h>
21#include <sys/time.h>
22
23#ifndef TRUE
24#define TRUE 1
25#endif
26
27#ifndef FALSE
28#define FALSE 0
29#endif
30
31#ifndef max
32#define max(a,b) ((a)>(b)?(a):(b))
33#endif
34
35#ifndef min
36#define min(a,b) ((a)<(b)?(a):(b))
37#endif
38
39#ifndef NFDBITS
40#define NFDBITS 32
41#endif
42#ifndef howmany
43#define howmany(x, y) (((x)+((y)-1))/(y))
44#endif
3bed758d 45#ifndef FD_SETSIZE
46#define FD_SETSIZE 256
47#endif
5580185e 48#ifndef FD_SET
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)))
3bed758d 53typedef long fd_mask;
54typedef struct fd_set {fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];} fd_set;
5580185e 55#endif
56
57
58
939744d7 59 /*----------------------------------------------------------*
60 *
61 * GDB_GIVEUP
62 *
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
66 * errors.
67 *
68 * The gdb library must be recompiled for the change to
69 * take effect. That will have to be fixed sometime.
70 *
71 *----------------------------------------------------------*/
5580185e 72
73#define GDB_GIVEUP(errormsg) g_givup(errormsg);
74
939744d7 75 /*----------------------------------------------------------*
76 *
77 * GDB_ROUNDUP
78 *
79 * Round a number up to the next specified boundary.
80 *
81 *----------------------------------------------------------*/
5580185e 82
83#define GDB_ROUNDUP(n,b) ((((n)+(b)-1)/(b))*(b))
84
85extern int gdb_Debug; /* debugging flags are */
86 /* stored here */
87extern FILE *gdb_log; /* file descriptor for */
88 /* logging gdb output */
89
90
91/*
92 * connection failure indicator
93 *
94 * This variable is used to communicate between gdb_move_data and
95 * g_con_progress without passing an extra parameter through lots
96 * of procedure calls. When set to FALSE, it indicates that the
97 * connection currently being processed has encountered a fatal error
98 * and should be severed.
99 */
100extern int gdb_conok;
939744d7 101/************************************************************************
102 *
103 * USER IDENTIFICATION
104 *
105 * gdb_init puts the user's i.d. and hostname as strings here.
106 *
107 ************************************************************************/
5580185e 108
109extern char *gdb_uname; /* user's string name */
110extern char *gdb_host; /* name of local host */
111 /* goes here */
112
113
114\f
939744d7 115/************************************************************************
116 *
117 *
118 * TYPE MANAGEMENT
119 *
120 * Declarations used to control the definition and use of 'types'
121 * as supported by the global database system. Most of the
122 * declarations for 'System Defined Types' will not be of concern
123 * to typical users, with the exception of the type names like
124 * INTEGER_T which are defined below.
125 *
126 * In this implementation, user defined types are added
127 * dynamically during execution by calling the appropriate
128 * functions. The define GDB_MAX_TYPES below sets the maximum
129 * total number of types, including both system and user defined,
130 * which the system can support for any one application. When
131 * GDB_MAX_TYPES is changed, the libary must be re-built. Space
132 * for a two dimensional array, with one word for each property
133 * of each possible type, is allocated statically in the library.
134 *
135 ************************************************************************/
5580185e 136
137
138/*
139 * Maximum number of types we can support, including both system and
140 * user defined.
141 */
142
143#define GDB_MAX_TYPES 50
144
145typedef int FIELD_TYPE; /* data needed to repre- */
146 /* sent a system or user */
147 /* defined data type */
148 /* This is actualy just */
149 /* a row index in the type */
150 /* definition table */
151
939744d7 152 /*----------------------------------------------------------
153 *
154 * System defined types
155 *
156 * WARNING: Any changes to these type definitions must be
157 * carefully matched with the initializations in the
158 * gdb_i_stype routine in gdb_stype.c. Mistakes in these
159 * tables may be VERY difficult to debug. Be careful!
160 *
161 *----------------------------------------------------------*/
5580185e 162
163/*
164 * Primitive types for ingres data
165 */
166
167#define INTEGER_T (0)
168#define STRING_T (1)
169#define REAL_T (2)
170#define DATE_T (3)
171
172/*
173 * Structured types
174 */
175
176#define TUPLE_DESCRIPTOR_T (4)
177#define TUPLE_T (5)
178#define TUPLE_DATA_T (6)
179#define RELATION_T (7)
180
181/*
182 * Number of system defined types
183 *
184 * This will always be equal to one more than index of last system type
185 */
186
187#define SYSTEM_TYPE_COUNT 8
188
939744d7 189 /*----------------------------------------------------------
190 *
191 * Type descriptor tables
192 *
193 *----------------------------------------------------------*/
5580185e 194
195/*
196 * gdb_prop_union
197 *
198 * Each entry in the type definition table is a union of this form,
199 * which allows us to store a choice of an integer, a function
200 * pointer, or a pointer to a character string.
201 */
202
203union gdb_prop_union {
204 int i; /* when we want as an */
205 /* integer */
206 int (*f)(); /* as a function pointer */
207 char *cp; /* character pointer */
208};
209
210#define TYPE_PROPERTY_COUNT 8 /* number of properties */
211 /* for each type*/
212
213/*
214 * Uses of the type properties. Each type has a set of properties.
215 * Some are integers, some are functions. The defines below descrive
216 * respectively the 0'th,1'st, 2'nd, etc. properties of EACH type.
217 *
218 * Note: TYPE_PROPERTY_COUNT (above) must be changed when new properties
219 * are added. For system defined types, bindings for the properties
220 * are done in gdb_i_stype in the gdb_stype.c source file.
221 */
222
223#define LENGTH_PROPERTY 0 /* integer */
224#define ALIGNMENT_PROPERTY 1 /* integer */
225#define NULL_PROPERTY 2 /* function */
226#define CODED_LENGTH_PROPERTY 3 /* function */
227#define ENCODE_PROPERTY 4 /* function */
228#define DECODE_PROPERTY 5 /* function */
229#define FORMAT_PROPERTY 6 /* function */
230#define NAME_PROPERTY 7 /* char pointer */
231
232/*
233 * gdb_type_def
234 *
235 * Information to describe a single type
236 */
237
238typedef union gdb_prop_union gdb_type_def[TYPE_PROPERTY_COUNT];
239
240
241/*
242 * g_type_table
243 *
244 * This is the table where the actual definitions for the types are
245 * kept.
246 */
247
248extern gdb_type_def g_type_table[GDB_MAX_TYPES];
249extern int gdb_n_types; /* number of entries in */
250 /* table */
251
939744d7 252 /*----------------------------------------------------------
253 *
254 * Macros for accessing properties
255 *
256 *----------------------------------------------------------*/
5580185e 257
258#define INT_PROPERTY(type, prop) (g_type_table[type][prop].i)
259#define STR_PROPERTY(type, prop) (g_type_table[type][prop].cp)
260#define FCN_PROPERTY(type, prop) (*g_type_table[type][prop].f)
261
262\f
939744d7 263/************************************************************************
264 *
265 * STRUCTURED DATA
266 *
267 * Stuff needed to declare and manage TUPLES, TUPLE_DESCRIPTORS
268 * and RELATIONS.
269 *
270 ************************************************************************/
271
272 /*----------------------------------------------------------
273 *
274 * TUPLE_DESCRIPTOR
275 *
276 *----------------------------------------------------------*/
5580185e 277
278#define GDB_DESC_ID 0x54504400 /* "TPD" */
279
280struct tupld_var { /* the variable length */
281 /* stuff in a tuple */
282 /* descriptor*/
283 char *name; /* string name of field */
284 FIELD_TYPE type; /* type of this field */
285 int offset; /* byte offset of this field */
286 /* relative to first byte of */
287 /* data (not start of whole */
288 /* tuple) */
289 int length; /* Length of the actual data */
290 /* for this field. Note that */
291 /* alignment requirements of */
292 /* following field are NOT */
293 /* included in this length */
294};
295struct tupl_desc {
296 long id; /* this should say TPD\0 */
297 int ref_count; /* when this goes to zero, */
298 /* the descriptor may really */
299 /* be reclaimed */
300 int field_count; /* number of fields in */
301 /* the tuple*/
302 int data_len; /* length of the data in */
303 /* the actual tuple */
304 int str_len; /* length of the strings */
305 /* stored off the end of */
306 /* this descriptor*/
307 struct tupld_var var[1]; /* one of these for each */
308 /* field, but the C compiler */
309 /* won't accept the[] decl, */
310 /* because it's afraid of */
311 /* uncertain length*/
312};
313
314typedef struct tupl_desc *TUPLE_DESCRIPTOR; /* use this to declare a */
315 /* tuple descriptor anchor */
316
317#define gdb_descriptor_length(num_flds) (sizeof(struct tupl_desc) + ((num_flds)-1) * sizeof(struct tupld_var))
318
939744d7 319 /*----------------------------------------------------------
320 *
321 * TUPLE
322 *
323 * tuple_dat is allocated by the create_tuple routine.
324 *
325 * TUPLE may be used in user code to declare a handle
326 * on a tuple.
327 *
328 *----------------------------------------------------------*/
5580185e 329
330#define GDB_TUP_ID 0x54555000
331
332typedef struct tuple_dat *TUPLE; /* handle on a tuple */
333
334struct tuple_dat {
335 TUPLE next, prev; /* chain pointers when */
336 /* tuples are linked, as in */
337 /* a relation. Convention is*/
338 /* double linked, circular.*/
339 long id; /* should say TUP\0 */
340 TUPLE_DESCRIPTOR desc; /* pointer to the descriptor */
341 char data[1]; /* data goes here, word */
342 /* aligned. Should be [] */
343 /* if compiler would allow */
344};
345
346
939744d7 347 /*----------------------------------------------------------
348 *
349 * RELATION
350 *
351 * rel_dat is allocated by the create_relation
352 * routine.
353 *
354 * RELATION may be used in user code to declare a handle
355 * on a relation.
356 *
357 *----------------------------------------------------------*/
5580185e 358
359#define GDB_REL_ID 0x52454c00
360
361struct rel_dat {
362 TUPLE first, last; /* chain pointers to tuples */
363 /* note that first->prev and */
364 /* last->next are both == */
365 /* &rel-dat. Maintenance is */
366 /* simplified by keeping */
367 /* as the first fields in */
368 /* both rel_dat and tuple_dat*/
369 /* a minor non-portability */
370 long id; /* should contain REL\0 */
371 TUPLE_DESCRIPTOR desc; /* descriptor for the tuples */
372 /* in this relation. Should */
373 /* == that in each tuple */
374
375};
376
377typedef struct rel_dat *RELATION; /* handle on a relation */
378\f
939744d7 379/************************************************************************
380 *
381 * transport LAYER DECLARATIONS
382 *
383 * Declares the state maintenance structures for full duplex
384 * connections with asynchronous transmission capability. Most
385 * users need only know that the type CONNECTION is defined, and
386 * that it may be treated as a pointer for most purposes (i.e. it
387 * is compact, and copying it does not actually copy the connection
388 * state.)
389 *
390 ************************************************************************/
5580185e 391
392#define GDB_PROTOCOL_VERSION 0x01 /* version of the gdb */
393 /* protocols that we're */
394 /* observing */
395#define GDB_STREAM_BUFFER_SIZE 4096 /* amount to read in */
396 /* one chunk from tcp stream*/
397#define GDB_PORT htons(9425) /* temporary until we use */
398 /* services properly */
399#define GDB_BIND_RETRY_COUNT 5 /* number of times to */
400 /* retry a bind before */
401 /* giving up. Used when */
402 /* accepting connections */
403#define GDB_BIND_RETRY_INTERVAL 10 /* Number of seconds to wait */
404 /* between attempts to bind */
405 /* the listening socket */
406#define GDB_MAX_CONNECTIONS 25 /* maximum number of */
407 /* connections that */
408 /* any one process can */
409 /* control simultaneously */
410/*
411 * Circumvent bug in ACIS 4.2 socket support
412 */
413#ifdef ibm032
414#define GDB_MAX_SOCK_WRITE 2047 /* rt can't do socket */
415 /* writes longer than this */
416 /* gives errno 40*/
417#else
418#define GDB_MAX_SOCK_WRITE 0x00ffffff
419#endif
420
939744d7 421 /*----------------------------------------------------------
422 *
423 * Declarations for HALF_CONNECTIONS
424 *
425 * Each full duplex connection has associated with it
426 * two simplex half-connections, each of which
427 * has its own queue of pending operations. The
428 * following describes the state of a half-connection.
429 *
430 *----------------------------------------------------------*/
5580185e 431
432struct half_con_data {
433 /*
434 * these two must be first to match position in OPERATION
435 */
436 struct oper_data *op_q_first; /* first item in q of pending*/
437 /* operations for this */
438 /* half-connection. (chained */
439 /* circularly to half con, */
440 /* NOT the con. */
441 struct oper_data *op_q_last; /* last item in q of pending*/
442 /* operations for this */
443 /* half-connection*/
444 int status; /* values are of type */
445 /* OPSTATUS. tells whether */
446 /* transmit/receive is */
447 /* pending.*/
448 long flags; /* bit flags */
449#define HCON_PROGRESS 0x00000001 /* used by selection */
450 /* routines to detect */
451 /* progress */
452#define HCON_LISTEN 0x00000002 /* indicates that this is */
453 /* a special half connection */
454 /* used only for listenting */
455 /* to incoming connection */
456 /* requests */
457#define HCON_UNUSED 0x00000004 /* on a one-way connection, */
458 /* this flag marks an unused */
459 /* half */
460#define HCON_PENDING_LISTEN 0x00000008 /* a queued op on this half */
461 /* connection is actually */
462 /* trying to listen */
463#define HCON_BUSY 0x00000010 /* we are currently making */
464 /* progress on this half */
465 /* connection. Used to */
466 /* detect re-entrance of */
467 /* hcon_progress */
468 int fd; /* main half duplex file */
469 /* descriptor for this h_conn*/
470 int oob_fd; /* file descriptor for */
471 /* out of band signals*/
472 char *next_byte; /* next byte to send/recv */
473 int remaining; /* number of bytes remaining */
474 /* to send/receive */
475 char *stream_buffer; /* points to a buffer */
476 /* used to pre-read/write */
477 /* the stream to avoid */
478 /* window thrashing */
479 int stream_buffer_length; /* length of the stream */
480 /* buffer */
481 char *stream_buffer_next; /* next byte to read in */
482 /* stream buffer */
483 int stream_buffer_remaining; /* number of bytes currently */
484 /* in use in stream buffer*/
485 int *accepted_fdp; /* used only for listening */
486 /* connections. latest */
487 /* accepted fd is put where*/
488 /* this points */
489 int *accepted_len; /* ptr to length of 'from' */
490 /* data on accept */
491
492};
493
494typedef struct half_con_data *HALF_CONNECTION;
495
496
939744d7 497 /*----------------------------------------------------------
498 *
499 * Declarations for CONNECTIONS
500 *
501 *----------------------------------------------------------*/
5580185e 502
503#define GDB_CON_ID 0x434f4e00 /*"CON"*/
504
505struct con_data {
506 long id; /* should contain CON\0 */
507 int status; /* See definitions below. */
508 /* Do not confuse with */
509 /* the status sub-fields of */
510 /* in and out half-cons. */
511 int version; /* the version of the */
512 /* protocol being observed */
513 /* on this connection */
514 int errno; /* the real errno gets */
515 /* copied here if it causes */
516 /* the connection to die */
517 int (*oob_fcn)(); /* pointer to function to */
518 /* call when something */
519 /* arrives on the out of */
520 /* band channel */
521 struct half_con_data in, out; /* states of the inbound */
522 /* and outbound half */
523 /* sessions.*/
524};
525
526typedef struct con_data *CONNECTION; /* the only externally */
527 /* visible handle on a */
528 /* connection*/
529
530/*
531 * Definitions of status fields.
532 *
533 * WARNING: If you change any of the following, there are coordinated
534 * changes to be made in gdb_debug.c
535 */
536
537#define CON_STOPPED 1 /* never started, terminated */
538#define CON_UP 2 /* ready to use */
539#define CON_STARTING 3 /* trying to start */
540#define CON_STOPPING 4 /* trying to stop */
541
542/*
543 * The following are used as keywords when distinguishing input from output
544 * half connections.
545 */
546#define CON_INPUT 1 /* this is an input half */
547 /* session*/
548#define CON_OUTPUT 2 /* this is an output half */
549 /* session*/
550
551
939744d7 552 /*----------------------------------------------------------
553 *
554 * gdb_cons
555 *
556 * This is the array of connection control data
557 * structures for gdb. Every connection has its
558 * structure stored here, but they are in no
559 * particular order. Because the connection data
560 * itself cannot be moved (due to possible dangling
561 * pointers), there may be some unused connections
562 * in the middle of this array. gdb_mcons is the
563 * 1 based number of the highest connection which is
564 * actually in use at this time. This is a considerable
565 * optimization for the typical case where very few
566 * are in use, and turnover is low.
567 *
568 * These are externs for globals defined in gdb_lib.h
569 * and included by gdb.c.
570 *
571 *----------------------------------------------------------*/
5580185e 572
573extern int gdb_mcons; /* one based number of the */
574 /* highest connection */
575 /* descriptor we're using */
576 /* at the moment */
577
578extern int gdb_mfd; /* number of the highest */
579 /* file descriptor in use */
580 /* for a connection */
581extern struct con_data gdb_cons[GDB_MAX_CONNECTIONS];
582 /* actual connection data */
583 /* is stored here */
584
585extern fd_set gdb_crfds, gdb_cwfds, gdb_cefds; /* connection related file */
586 /* descriptor maps to be */
587 /* used in select */
121a6479 588extern fd_set last_crfds, last_cwfds, last_cefds;/* these file desc. bit */
5580185e 589 /* masks are set up */
590 /* for each select call */
591 /* to include the user */
592 /* supplied and the */
593 /* connection related */
594 /* fd's */
595
939744d7 596 /*----------------------------------------------------------
597 *
598 * OPERATIONS
599 *
600 *----------------------------------------------------------*/
5580185e 601
602#define GDB_OP_ID 0x4f505200
603
604struct oper_data {
605 struct oper_data *next, *prev; /* forward and back chain */
606 long id; /* should contain OPR\0 */
607 int tag; /* unique identifier for */
608 /* this operation */
609 int status; /* current state of this */
610 /* oaperation*/
611 int flags;
612#define OPF_MARKED_COMPLETE 0x00000001 /* operation was already */
613 /* complete when opsel was */
614 /* called*/
615#define OPF_MARKED_CANCELLED 0x00000002 /* operation was already */
616 /* cancelled when opsel was */
617 /* called*/
618 int result; /* when the operation */
619 /* completes, this field is */
620 /* set to reflect its dispos-*/
621 /* ition. Contents of this */
622 /* field will depend on the */
623 /* operation being performed */
624 HALF_CONNECTION halfcon; /* the half connection on */
625 /* which this operation is */
626 /* queued */
627 /* May be meaningless if not */
628 /* queued..*/
629 char *arg; /* pointer to user data */
630 union fcn {
631 int (*init)(); /* pointer to routine to */
632 /* call to start this */
633
634 /* operation*/
635 int (*cont)(); /* pointer to function to */
636 /* be called when this */
637 /* logical operation */
638 /* continues*/
639 } fcn;
640
641 int (*cancel)(); /* this routine gets called */
642 /* to handle a cancel request*/
643 /* this field is normally */
644 /* set to NULL when the */
645 /* operation is queued and */
646 /* updated as required by */
647 /* the init and cont funcs. */
648};
649
650typedef struct oper_data OPERATION_DATA; /* an actual operation */
651 /* descritor, creator is */
652 /* responsible for making */
653 /* sure that memory is not */
654 /* freed while in use */
655typedef OPERATION_DATA *OPERATION; /* a handle on an operation */
656 /* this is what most */
657 /* applications will use */
658
939744d7 659 /*----------------------------------------------------------
660 *
661 * STATES OF AN OPERATION
662 *
663 * These represent the state of an asynchronous, queued
664 * operation. For convenience of the application programmer,
665 * some of these are folded together when queried through the
666 * operation_status routine. In particular, operation status
667 * returns only one of:
668 *
669 * OP_NOT_RUNNING, OP_RUNNING, OP_COMPLETE, or
670 * OP_CANCELLED.
671 *
672 * Any other status is reported as OP_RUNNING. This is
673 * done on the assumption that it makes correct coding
674 * of applications less error-prone, as there are fewer
675 * cases to check, and most of them would not be of
676 * interest anyway.
677 *
678 * Note that OP_CANCELLED may be generated by the system
679 * even when no explicit request for cancellation has been
680 * issued. For example, this may occur when a connection
681 * is severed unexpectedly.
682 *
683 * WARNING: If you change any of the following, be sure
684 * to make the equivalent changes to gdb_debug.c.
685 *
686 * We also define here certain standard values of OP_RESULT,
687 * since some return conventions presume that op_status
688 * and op_result values are orthogonal.
689 *
690 *----------------------------------------------------------*/
5580185e 691
692#define OP_SUCCESS 0 /* this value is actually */
693 /* used only in result */
694 /* fields, but it is */
695 /* sometimes convenient to */
696 /* have status and result */
697 /* have orthogonal values */
698#define OP_NOT_STARTED 1 /* this operation has been */
699 /* initialized but is not on */
700 /* any connection's queue */
701#define OP_QUEUED 2 /* this operation is on */
702 /* some connection's queue */
703 /* but it has not yet */
704 /* reached the head of the q */
705#define OP_RUNNING 3 /* op is at head of q trying */
706 /* to progress */
707#define OP_COMPLETE 4 /* operation has run to */
708 /* completion. result field */
709 /* is now valid */
710#define OP_CANCELLING 5 /* we are in the process of */
711 /* (trying to) cancel this */
712 /* operation */
713#define OP_CANCELLED 6 /* operation was prematurely */
714 /* terminated. result field */
715 /* is NOT valid. */
716#define OP_MARKED 7 /* used by op_select_all */
717#define OP_REQUEUED 8 /* returned by an init or */
718 /* continuation routine to */
719 /* indicate that the */
720 /* operation has requeued */
721 /* itself */
722#define OP_PREEMPTED 9 /* returned by an init or */
723 /* continuation routine to */
724 /* indicate that the op has */
725 /* preempted itself by */
726 /* queueing a new operation */
727 /* ahead of itself */
728
939744d7 729 /*----------------------------------------------------------
730 *
731 * LIST_OF_OPERATIONS
732 *
733 *----------------------------------------------------------*/
5580185e 734
735struct oper_list {
736 int count; /* number of operations */
737 /* in the list */
738 OPERATION op[1]; /* really op[n], but */
739 /* structs must have a */
740 /* definite length */
741};
742
743typedef struct oper_list *LIST_OF_OPERATIONS; /* handle on a list */
744
745#define size_of_list_of_operations(n) \
746 (sizeof(struct oper_list) + (n-1)*sizeof(OPERATION))
747
939744d7 748 /*----------------------------------------------------------
749 *
750 * gdb_notime
751 *
752 * Pass this to select when doing a poll.
753 *
754 *----------------------------------------------------------*/
5580185e 755
756extern struct timeval gdb_notime;
757
758\f
939744d7 759/************************************************************************
760 *
761 * CHECKING ROUTINES IMPLEMENTED AS MACROS
762 *
763 ************************************************************************/
5580185e 764
765extern char g_errstr[150]; /* build emsgs here */
766
767#define GDB_INIT_CHECK g_chk_init(); /* make sure gdb_init */
768 /* was called */
769
770#define GDB_CHECK_CON(con, where) if ((con)->id != GDB_CON_ID) \
771 { (void) sprintf(g_errstr, "Invalid connection descriptor passed to \"%s\"\n", where); \
772 GDB_GIVEUP(g_errstr) }
773
774
775#define GDB_CHECK_TUP(tup, where) if ((tup)->id != GDB_TUP_ID) \
776 { (void) sprintf(g_errstr, "Invalid tuple passed to \"%s\"\n", where); \
777 GDB_GIVEUP(g_errstr) }
778
779
780#define GDB_CHECK_TPD(tpd, where) if ((tpd)->id != GDB_DESC_ID) \
781 { (void) sprintf(g_errstr, "Invalid tuple descriptor passed to \"%s\"\n", where); \
782 GDB_GIVEUP(g_errstr) }
783
784
785#define GDB_CHECK_REL(rel, where) if ((rel)->id != GDB_REL_ID) \
786 { (void) sprintf(g_errstr, "Invalid relation passed to \"%s\"\n", where); \
787 GDB_GIVEUP(g_errstr) }
788
789#define GDB_CHECK_OP(op, where) if ((op)->id != GDB_OP_ID) \
790 { (void) sprintf(g_errstr, "Invalid operation passed to \"%s\"\n", where); \
791 GDB_GIVEUP(g_errstr) }
792
793#define GDB_CHECK_DB(db, where) if (db->id != GDB_DB_ID) \
794 { (void) sprintf(g_errstr, "Invalid database handle passed to \"%s\"\n", where); \
795 GDB_GIVEUP(g_errstr) }
796
797
798
799\f
939744d7 800/************************************************************************
801 *
802 * TRANSPORT ROUTINES IMPLEMENTED AS MACROS
803 *
804 ************************************************************************/
805
806 /*----------------------------------------------------------
807 *
808 * connection_status
809 *
810 * Returns the status of the indicated connection.
811 * Possible return values are:
812 *
813 * CON_STOPPED never started or terminated
814 * CON_UP currently usable
815 * CON_STARTING transient state on way up
816 * CON_STOPPING transient state on way down
817 *
818 *----------------------------------------------------------*/
5580185e 819
820#define connection_status(con) ((con)->status)
821
939744d7 822 /*----------------------------------------------------------
823 *
824 * connection_errno
825 *
826 * When a connection dies due to an error on a system
827 * call, the corresponding errno is recorded in the
828 * connection descriptor. This macro returns that value.
829 *
830 *----------------------------------------------------------*/
5580185e 831
832#define connection_errno(con) ((con)->errno)
833
834
835\f
939744d7 836/************************************************************************
837 *
838 * SERVER/CLIENT MANAGEMENT
839 *
840 * Definitions used in starting and maintaining communication
841 * between servers and clients (as opposed to peers.)
842 *
843 ************************************************************************/
5580185e 844
845#define GDB_MAX_SERVER_RETRIES 3 /* maximum number of times */
846 /* clients will accept */
847 /* forwarding requests from */
848 /* a given server */
849
850
851extern TUPLE_DESCRIPTOR gdb_tosrv; /* descriptor for request */
852 /* tuples sent to the */
853 /* server during negotiation*/
854
855extern TUPLE_DESCRIPTOR gdb_fmsrv; /* descriptor for request */
856 /* tuples sent from the */
857 /* server during negotiation*/
858
859#define GDB_MAX_SERVER_ID_SIZE 255 /* longest name of a server */
860 /* that we can handle */
861#define GDB_MAX_SERVER_PARMS_SIZE 1023 /* longest parm string we */
862 /* can exchange between */
863 /* server and client*/
864
939744d7 865 /*----------------------------------------------------------
866 *
867 * The following are values returned in the disposition
868 * field of the response tuple to indicate what the
869 * server has decided to do about the connection
870 * request.
871 *
872 *----------------------------------------------------------*/
5580185e 873
874#define GDB_ACCEPTED 1
875#define GDB_REFUSED 2
876#define GDB_FORWARDED 3
877
939744d7 878 /*----------------------------------------------------------
879 *
880 * Global variables inherited by a child from a server
881 * parent.
882 *
883 *----------------------------------------------------------*/
5580185e 884
885extern TUPLE gdb_client_tuple; /* request tuple sent from */
886 /* the client */
887
888extern char gdb_sockaddr_of_client[100]; /* this should really be */
889 /* sockaddr_in, but I don't */
890 /* want everyone to have */
891 /* to include all those */
892 /* big .h files */
893extern int gdb_socklen; /* length of above */
894
895
896\f
939744d7 897/************************************************************************
898 *
899 * DATABASE MANAGEMENT
900 *
901 * This layer of GDB provides access to the services of a relational
902 * database from anywhere in a GDB network.
903 *
904 ************************************************************************/
905
906 /*----------------------------------------------------------
907 *
908 * GDB_DB_SERVICE
909 *
910 * The name of the service, as found in /etc/services,
911 * for GDB database servers.
912 *
913 *----------------------------------------------------------*/
5580185e 914
915#define GDB_DB_SERVICE "#9420"
916
939744d7 917 /*----------------------------------------------------------
918 *
919 * DATABASE
920 *
921 * Describes a client's active connection to a database.
922 *
923 *----------------------------------------------------------*/
5580185e 924
925#define GDB_DB_ID 0x44420000 /* eye catcher */
926
927struct db_struct {
928 long id; /* eye catcher */
929 CONNECTION connection; /* the GDB connection */
930 /* used to get at this */
931 /* database */
932 int status; /* status of this */
933 /* database connection */
934#define DB_OPEN 1 /* database opened */
935 /* successfully */
936#define DB_CLOSED 2 /* not open */
937 char *name; /* pointer to string name */
938 /* of the database, for */
939 /* debugging */
940 char *server; /* pointer to the i.d. */
941 /* of the server, for */
942 /* debugging */
943};
944
945typedef struct db_struct *DATABASE;
946
939744d7 947 /*----------------------------------------------------------
948 *
949 * Return codes from DB operations
950 *
951 *----------------------------------------------------------*/
5580185e 952
953#define DB_NO_SUCH_OP 3
954
939744d7 955 /*----------------------------------------------------------
956 *
957 * Parameters which limit sizes of things
958 *
959 *----------------------------------------------------------*/
5580185e 960
961#define GDB_MAX_QUERY_SIZE 2048 /* length of the longest */
962 /* substituted query */
963 /* string we can make */
964#define GDB_MAX_QUERY_FIELDS 100 /* maximum number of fields */
965 /* we can retrieve in one */
966 /* query */
967#define GDB_SIZE_OF_INGRES_TEXT 2001 /* number of chars in */
968 /* largest ingres text */
969 /* field */
970#define GDB_MAX_RETRIEVED_TEXT_FIELDS 60 /* maximum number of text */
971 /* type fields we can */
972 /* retrieve in a single */
973 /* query. we hold this */
974 /* down because stack space */
975 /* is taken for max size of */
976 /* each during query. */
977
939744d7 978 /*----------------------------------------------------------
979 *
980 * Return codes from database operations
981 *
982 *----------------------------------------------------------*/
5580185e 983
984#define DB_PARSE_FAIL (-3) /* couldn't parse */
985 /* the request string*/
986
987\f
939744d7 988/************************************************************************
989 *
990 * DATABASE OPERATIONS IMPLEMENTED
991 * AS MACROS
992 *
993 ************************************************************************/
994
995 /*----------------------------------------------------------
996 *
997 * DB_STATUS
998 *
999 *----------------------------------------------------------*/
5580185e 1000
1001#define DB_STATUS(dbhandle) ((dbhandle)->status)
1002
1003
1004
1005\f
939744d7 1006/************************************************************************
1007 *
1008 * STRING MANAGEMENT
1009 *
1010 * To allow dynamic manipulation of strings in gdb without
1011 * excessive memory re-allocation, we define a string as a
1012 * counted byte space. Though this space will frequently be used
1013 * to store a standard null terminated string, that is not
1014 * required.
1015 *
1016 * Current representation for a string is a pointer followed by
1017 * an integer length. A null pointer indicates a null string, in
1018 * which case the length is arbitrary. Any other pointer is to
1019 * memory which was allocated by db_alloc in which must be free'd
1020 * eventually with db_free.
1021 *
1022 ************************************************************************/
5580185e 1023
1024typedef struct str_dat {
1025 char *ptr; /* pointer to the data */
1026 int length; /* length of the allocated */
1027 /* memory (not necessarily */
1028 /* length of null-term'd */
1029 /* string stored there) */
1030} STRING;
1031
939744d7 1032 /*----------------------------------------------------------
1033 *
1034 * Macros for manipulating strings. These return
1035 * the actual data from the string and the size of
1036 * the data space respectively. To get the length of
1037 * the null terminated string which might be stored
1038 * there, use strlen(STRING_DATA(string)).
1039 *
1040 *----------------------------------------------------------*/
5580185e 1041
1042
1043#define STRING_DATA(str) ((str).ptr)
1044#define MAX_STRING_SIZE(str) ((str).length)
1045
1046
939744d7 1047/************************************************************************
1048 *
1049 * MEMORY ALLOCATION
1050 *
1051 * db_alloc and db_free are the externally visible names of
1052 * the memory allocation services. These actually call the
1053 * routines pointed to by the vectors gdb_amv and gdb_fmv, which
1054 * default to the supplied routines gdb_am and gdb_fm. Users
1055 * may supply their own memory allocation by storing over the
1056 * vectors. This may be done prior to calling gdb_init to
1057 * insure that all dynamic memory is controlled by the user.
1058 *
1059 ************************************************************************/
5580185e 1060
1061#define db_alloc (*gdb_amv)
1062#define db_free (*gdb_fmv)
1063
1064extern char *gdb_am();
1065extern int gdb_fm();
1066
1067extern char *((*gdb_amv)());
1068extern int (*gdb_fmv)();
1069
1070\f
939744d7 1071/************************************************************************
1072 *
1073 * STRUCTURED DATA ROUTINES IMPLEMENTED AS MACROS
1074 *
1075 ************************************************************************/
1076
1077 /*----------------------------------------------------------
1078 *
1079 * ADD_TUPLE_TO_RELATION
1080 *
1081 *----------------------------------------------------------*/
5580185e 1082
1083#define ADD_TUPLE_TO_RELATION(relation, tuple) \
1084 { \
1085 (tuple)->prev = (relation)->last; \
1086 (tuple)->next = (TUPLE)(relation); \
1087 (relation)->last = tuple; \
1088 (tuple)->prev->next = tuple; \
1089 }
1090
939744d7 1091 /*----------------------------------------------------------
1092 *
1093 * ADD_TUPLE_AFTER_TUPLE
1094 *
1095 *----------------------------------------------------------*/
5580185e 1096
1097#define ADD_TUPLE_AFTER_TUPLE(relation, tuple, prev_tuple) \
1098 { \
1099 (tuple)->prev = (prev_tuple)->next->prev; \
1100 (tuple)->next = (prev_tuple)->next; \
1101 (tuple)->next->prev = tuple; \
1102 (prev_tuple)->next = tuple; \
1103 }
1104
939744d7 1105 /*----------------------------------------------------------
1106 *
1107 * REMOVE_TUPLE_FROM_RELATION
1108 *
1109 *----------------------------------------------------------*/
5580185e 1110
1111#define REMOVE_TUPLE_FROM_RELATION(relation, tuple) \
1112 { \
1113 (tuple)->prev->next = (tuple)->next; \
1114 (tuple)->next->prev = (tuple)->prev; \
1115 }
1116
1117
939744d7 1118 /*----------------------------------------------------------
1119 *
1120 * DESCRIPTOR_FROM_TUPLE
1121 *
1122 *----------------------------------------------------------*/
5580185e 1123
1124#define DESCRIPTOR_FROM_TUPLE(tuple) ((tuple)->desc)
1125
939744d7 1126 /*----------------------------------------------------------
1127 *
1128 * DESCRIPTOR_FROM_RELATION
1129 *
1130 *----------------------------------------------------------*/
5580185e 1131
1132#define DESCRIPTOR_FROM_RELATION(relation) ((relation)->desc)
1133
939744d7 1134 /*----------------------------------------------------------
1135 *
1136 * REFERENCE_TUPLE_DESCRIPTOR
1137 *
1138 * Bumps the reference count for a tuple descriptor.
1139 * Intended only for internal use of GDB.
1140 *
1141 *----------------------------------------------------------*/
5580185e 1142
1143#define REFERENCE_TUPLE_DESCRIPTOR(tpd) (++((tpd)->ref_count))
1144
939744d7 1145 /*----------------------------------------------------------
1146 *
1147 * UNREFERENCE_TUPLE_DESCRIPTOR
1148 *
1149 * Decrements the reference count for a tuple descriptor.
1150 * Intended only for internal use of GDB. Warning: it
1151 * is the user's responsibility to use delete_tuple_descriptor
1152 * instead of this macro in any situation in which the
1153 * reference count might go to zero.
1154 *
1155 *----------------------------------------------------------*/
5580185e 1156
1157#define UNREFERENCE_TUPLE_DESCRIPTOR(tpd) (--((tpd)->ref_count))
1158
939744d7 1159 /*----------------------------------------------------------
1160 *
1161 * FIELD_FROM_TUPLE
1162 *
1163 *----------------------------------------------------------*/
5580185e 1164
1165#define FIELD_FROM_TUPLE(tuple, field_index) \
1166 (((tuple)->data) + (((tuple)->desc)->var[field_index].offset))
1167
939744d7 1168 /*----------------------------------------------------------
1169 *
1170 * FIELD_OFFSET_IN_TUPLE
1171 *
1172 *----------------------------------------------------------*/
5580185e 1173
1174#define FIELD_OFFSET_IN_TUPLE(tuple_descriptor, field_index) \
1175 ((tuple_descriptor)->var[field_index].offset)
1176
939744d7 1177 /*----------------------------------------------------------
1178 *
1179 * FIELD_TYPE_IN_TUPLE
1180 *
1181 *----------------------------------------------------------*/
5580185e 1182
1183#define FIELD_TYPE_IN_TUPLE(tuple_descriptor, field_index) \
1184 ((tuple_descriptor)->var[field_index].type)
1185
939744d7 1186 /*----------------------------------------------------------
1187 *
1188 * FIRST_TUPLE_IN_RELATION
1189 *
1190 *----------------------------------------------------------*/
5580185e 1191
1192#define FIRST_TUPLE_IN_RELATION(relation) \
1193 (((relation)->first) == (TUPLE)relation ? NULL : (relation)-> first)
1194
939744d7 1195 /*----------------------------------------------------------
1196 *
1197 * NEXT_TUPLE_IN_RELATION
1198 *
1199 *----------------------------------------------------------*/
5580185e 1200
1201#define NEXT_TUPLE_IN_RELATION(relation, prev) \
1202 (((prev)->next) == (TUPLE)relation ? NULL : prev->next )
1203
939744d7 1204 /*----------------------------------------------------------
1205 *
1206 * PREV_TUPLE_IN_RELATION
1207 *
1208 *----------------------------------------------------------*/
5580185e 1209
1210#define PREV_TUPLE_IN_RELATION(relation, next) \
1211 (((next)->prev) == (TUPLE) relation ? NULL : next->prev)
1212
1213
1214
1215\f
939744d7 1216/************************************************************************
1217 *
1218 * TRANSPORT and OPERATION SERVICES IMPLEMENTED AS MACROS
1219 *
1220 ************************************************************************/
1221
1222 /*----------------------------------------------------------
1223 *
1224 * OPERATION_FROM_DATA
1225 *
1226 * Given OPERATION_DATA, return the corresponding handle
1227 * of type OPERATION. Currently, OPERATION is just
1228 * implemented as a pointer to OPERATION_DATA.
1229 *
1230 *----------------------------------------------------------*/
5580185e 1231
1232#define OPERATION_FROM_DATA(op_data) \
1233 ((OPERATION)&(op_data))
1234
939744d7 1235 /*----------------------------------------------------------
1236 *
1237 * OP_TAG
1238 *
1239 * Return the tag for a given operation.
1240 *
1241 *----------------------------------------------------------*/
5580185e 1242
1243#define OP_TAG(operation) ((operation)->tag)
1244
939744d7 1245 /*----------------------------------------------------------
1246 *
1247 * OP_STATUS
1248 *
1249 * Return the status of a given operation. Note that
1250 * status describes an operations progress through
1251 * execution. It has the same values for all operations.
1252 * Result describes the final outcome of an operation.
1253 * It's values depend on the particular operation which
1254 * was attempted.
1255 *
1256 *----------------------------------------------------------*/
5580185e 1257
1258#define OP_STATUS(operation) ((operation)->status)
1259
939744d7 1260 /*----------------------------------------------------------
1261 *
1262 * OP_DONE
1263 *
1264 * True iff the operation is either OP_COMPLETE or
1265 * OP_CANCELLED.
1266 *
1267 *----------------------------------------------------------*/
5580185e 1268
1269#define OP_DONE(op) ((op)->status == OP_COMPLETE || (op)->status == OP_CANCELLED)
1270
939744d7 1271 /*----------------------------------------------------------
1272 *
1273 * OP_RESULT
1274 *
1275 * Return the result of a given operation. Note that
1276 * status describes an operations progress through
1277 * execution. It has the same values for all operations.
1278 * Result describes the final outcome of an operation.
1279 * It's values depend on the particular operation which
1280 * was attempted. The special result value -1 is used
1281 * to indicate an invalid value for result. Generally,
1282 * -1 is returned when result is accidently queried at
1283 * a time when OP_STATUS != OPERATION_COMPLETE.
1284 *
1285 *----------------------------------------------------------*/
5580185e 1286
1287#define OP_RESULT(operation) ((operation)->result)
1288
1289\f
939744d7 1290/************************************************************************
1291 *
1292 * Debugging Interfaces
1293 *
1294 ************************************************************************/
1295
1296 /*----------------------------------------------------------
1297 *
1298 * The following operation codes my be passed to
1299 * gdb_debug to set special debugging modes of operation.
1300 *
1301 * Note that most of these are toggles
1302 *
1303 *----------------------------------------------------------*/
5580185e 1304
1305#define GDB_LOG 0x00000001 /* turn on tracing to */
1306 /* log file */
1307#define GDB_NOFORK 0x00000002 /* don't fork forking */
1308 /* servers */
1309
1310\f
939744d7 1311/************************************************************************
1312 *
1313 * Things which have to be at the end because they require
1314 * the various types to be defined first.
1315 *
1316 ************************************************************************/
5580185e 1317
1318
1319#ifdef DUMB_7_CHAR_LOADER
939744d7 1320 /*----------------------------------------------------------
1321 *
1322 * Long Names for Routines
1323 *
1324 * External names in Unix must generally be unique
1325 * within the first 7 characters or so, at least for
1326 * some versions of ld. To account for this without
1327 * making all our routine names terribly short and
1328 * cryptic, we use the following defines.
1329 *
1330 *----------------------------------------------------------*/
5580185e 1331
1332#define string_alloc gdb_sta
1333#define string_free gdb_stf
1334
1335#define create_tuple_descriptor gdb_ctd
1336#define delete_tuple_descriptor gdb_dtd
1337#define field_index gdb_fi
1338#define create_tuple gdb_ctup
1339#define delete_tuple gdb_dtup
1340#define initialize_tuple gdb_itup
1341#define null_tuple_strings gdb_ntps
1342
1343#define create_relation gdb_crel
1344#define delete_relation gdb_drel
1345#define tuples_in_relation gdb_trel
1346
1347
1348/*
1349 * Transport layer
1350 */
1351#define create_operation gdb_crop
1352#define delete_operation gdb_dop
1353#define initialize_operation gdb_inop
1354#define reset_operation gdb_rsop
1355#define cancel_operation gdb_cnop
1356
1357#define create_list_of_operations gdb_clop
1358#define delete_list_of_operations gdb_dlop
1359
1360#define op_select gdb_opsel
1361#define op_select_any gdb_opsel
1362#define op_select_all gdb_aopsel
1363#define con_select gdb_cnsel
1364
1365#define gdb_receive_data gdb_rcdat
1366#define gdb_send_data gdb_sndat
1367#define gdb_start_listening gdb_stl
1368#define start_accepting_client gdb_stac
1369
1370
1371#define gdb_listen gdb_lis
1372
1373/*
1374 * Connection management
1375 */
1376#define start_peer_connection gdb_spconn
1377#define sever_connection gdb_svconn
1378#define start_server_connection gdb_stsrv
1379#define create_listening_connection gdb_clc
1380#define start_replying_to_client gdb_strtc
1381#define create_forking_server gdb_cfs
1382
1383
1384/*
1385 * Asynchronous operations
1386 */
1387#define start_sending_object gdb_snobj
1388#define start_receiving_object gdb_rcobj
1389#define preempt_and_start_receiving_object gdb_prcobj
1390
1391#define queue_operation gdb_qop
1392
1393#define requeue_operation g_req_op
1394
1395#define complete_operation gdb_cmpo
1396/*
1397 * Synchronous operations
1398 */
1399#define send_object gdb_sobj
1400#define receive_object gdb_robj
1401/*
1402 * Database operations
1403 */
1404#define access_db gdb_adb
1405#define start_accessing_db gdb_sadb
1406#define perform_db_operation gdb_pdbo
1407#define db_query gdb_dbq
1408#define start_performing_db_operation gdb_spdb
1409#define start_db_query gdb_sdbq
1410#else
1411#define op_select_any op_select
b42dcf6c 1412#endif /* DUMB_7_CHAR_LOADER */
5580185e 1413
1414extern char *string_alloc();
1415extern int string_free();
1416extern TUPLE_DESCRIPTOR create_tuple_descriptor();
1417extern int delete_tuple_descriptor();
1418extern int field_index();
1419extern TUPLE create_tuple();
1420extern int delete_tuple();
1421extern int initialize_tuple();
1422extern int null_tuple_strings();
1423extern RELATION create_relation();
1424extern int delete_relation();
1425extern OPERATION create_operation();
1426extern LIST_OF_OPERATIONS create_list_of_operations();
1427extern OPERATION g_op_newhead();
1428extern CONNECTION start_peer_connection();
1429extern CONNECTION sever_connection();
1430extern CONNECTION start_server_connection();
1431extern CONNECTION create_listening_connection();
1432extern CONNECTION create_forking_server();
1433extern int start_sending_object();
1434extern int start_receiving_object();
1435extern int preempt_and_start_receiving_object();
1436extern int queue_operation();
1437extern int requeue_operation();
1438extern int complete_operation();
1439extern int send_object();
1440extern int receive_object();
1441
1442
939744d7 1443 /*----------------------------------------------------------
1444 *
1445 * Other routines requiring extern to avoid forward
1446 * reference to non integer type functions.
1447 *
1448 *----------------------------------------------------------*/
5580185e 1449
1450extern CONNECTION g_make_con();
This page took 0.264661 seconds and 5 git commands to generate.