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