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