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