Reinsert initialiser for __UNUSED_loglevel
[yaz-moved-to-github.git] / src / session.h
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: session.h,v 1.10 2006-03-15 13:32:05 adam Exp $
6  */
7 /**
8  * \file session.h
9  * \brief Internal Header for GFS.
10  */
11 #ifndef SESSION_H
12 #define SESSION_H
13
14 #include <yaz/comstack.h>
15 #include <yaz/cql.h>
16 #include <yaz/odr.h>
17 #include <yaz/oid.h>
18 #include <yaz/proto.h>
19 #include <yaz/backend.h>
20 #include "eventl.h"
21
22 struct gfs_server {
23     statserv_options_block cb;
24     char *host;
25     int listen_ref;
26     cql_transform_t cql_transform;
27     void *server_node_ptr;
28     char *directory;
29     char *docpath;
30     char *stylesheet;
31     struct gfs_server *next;
32 };
33
34 struct gfs_listen {
35     char *id;
36     char *address;
37     struct gfs_listen *next;
38 };
39
40 typedef enum {
41     REQUEST_IDLE,    /* the request is just sitting in the queue */
42     REQUEST_PENDING  /* operation pending (b'end processing or network I/O*/
43     /* this list will have more elements when acc/res control is added */
44 } request_state;
45
46 typedef struct request
47 {
48     int len_refid;          /* length of referenceid */
49     char *refid;            /* referenceid */
50     request_state state;
51
52     Z_GDU *gdu_request;     /* Current request */
53     Z_APDU *apdu_request;   /* Current Z39.50 request */
54     NMEM request_mem;    /* memory handle for request */
55
56     int size_response;     /* size of buffer */
57     int len_response;      /* length of encoded data */
58     char *response;        /* encoded data waiting for transmission */
59
60     void *clientData;
61     struct request *next;
62     struct request_q *q; 
63 } request;
64
65 typedef struct request_q
66 {
67     request *head;
68     request *tail;
69     request *list;
70     int num;
71 } request_q;
72
73 /*
74  * association state.
75  */
76 typedef enum
77 {
78     ASSOC_NEW,                /* not initialized yet */
79     ASSOC_UP,                 /* normal operation */
80     ASSOC_DEAD                /* dead. Close if input arrives */
81 } association_state;
82
83 typedef struct association
84 {
85     IOCHAN client_chan;           /* event-loop control */
86     COMSTACK client_link;         /* communication handle */
87     ODR decode;                   /* decoding stream */
88     ODR encode;                   /* encoding stream */
89     ODR print;                    /* printing stream (for -a) */
90     char *encode_buffer;          /* temporary buffer for encoded data */
91     int encoded_len;              /* length of encoded data */
92     char *input_buffer;           /* input buffer (allocated by comstack) */
93     int input_buffer_len;         /* length (size) of buffer */
94     int input_apdu_len;           /* length of current incoming APDU */
95     oid_proto proto;              /* protocol (PROTO_Z3950/PROTO_SR) */
96     void *backend;                /* backend handle */
97     request_q incoming;           /* Q of incoming PDUs */
98     request_q outgoing;           /* Q of outgoing data buffers (enc. PDUs) */
99     association_state state;
100
101     /* session parameters */
102     int preferredMessageSize;
103     int maximumRecordSize;
104     int version;                  /* highest version-bit set (2 or 3) */
105
106     unsigned cs_get_mask;
107     unsigned cs_put_mask;
108     unsigned cs_accept_mask;
109
110     struct bend_initrequest *init;
111     statserv_options_block *last_control;
112     cql_transform_t cql_transform;
113     void *server_node_ptr;
114     const char *docpath;
115     const char *stylesheet;
116 } association;
117
118 association *create_association(IOCHAN channel, COMSTACK link,
119                                 const char *apdufile);
120 void destroy_association(association *h);
121 void ir_session(IOCHAN h, int event);
122
123 void request_enq(request_q *q, request *r);
124 request *request_head(request_q *q);
125 request *request_deq(request_q *q);
126 request *request_deq_x(request_q *q, request *r);
127 void request_initq(request_q *q);
128 void request_delq(request_q *q);
129 request *request_get(request_q *q);
130 void request_release(request *r);
131
132 int statserv_must_terminate(void);
133
134 int control_association(association *assoc, const char *host, int force);
135
136 #endif
137 /*
138  * Local variables:
139  * c-basic-offset: 4
140  * indent-tabs-mode: nil
141  * End:
142  * vim: shiftwidth=4 tabstop=8 expandtab
143  */
144