Added typecasts to make C++ happy.
[yaz-moved-to-github.git] / server / session.h
1 /*
2  * Copyright (C) 1995-1999, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: session.h,v $
7  * Revision 1.25  2001-07-19 19:51:42  adam
8  * Added typecasts to make C++ happy.
9  *
10  * Revision 1.24  2000/11/23 10:58:32  adam
11  * SSL comstack support. Separate POSIX thread support library.
12  *
13  * Revision 1.23  2000/04/05 07:39:55  adam
14  * Added shared library support (libtool).
15  *
16  * Revision 1.22  2000/03/20 19:06:25  adam
17  * Added Segment request for fronend server. Work on admin for client.
18  *
19  * Revision 1.21  1999/11/30 13:47:12  adam
20  * Improved installation. Moved header files to include/yaz.
21  *
22  * Revision 1.20  1999/10/11 10:01:24  adam
23  * Implemented bend_sort_rr handler for frontend server.
24  *
25  * Revision 1.19  1999/04/20 09:56:48  adam
26  * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
27  * Modified all encoders/decoders to reflect this change.
28  *
29  * Revision 1.18  1998/08/03 10:23:57  adam
30  * Fixed bug regarding Options for Sort.
31  *
32  * Revision 1.17  1998/07/20 12:38:43  adam
33  * Implemented delete result set service to server API.
34  *
35  * Revision 1.16  1998/03/31 11:07:45  adam
36  * Furhter work on UNIverse resource report.
37  * Added Extended Services handling in frontend server.
38  *
39  * Revision 1.15  1998/02/11 11:53:36  adam
40  * Changed code so that it compiles as C++.
41  *
42  * Revision 1.14  1998/02/10 11:03:57  adam
43  * Added support for extended handlers in backend server interface.
44  *
45  * Revision 1.13  1998/01/29 13:30:23  adam
46  * Better event handle system for NT/Unix.
47  *
48  * Revision 1.12  1997/09/01 08:53:01  adam
49  * New windows NT/95 port using MSV5.0. The test server 'ztest' was
50  * moved a separate directory. MSV5.0 project server.dsp created.
51  * As an option, the server can now operate as an NT service.
52  *
53  * Revision 1.11  1995/11/08 17:41:40  quinn
54  * Smallish.
55  *
56  * Revision 1.10  1995/08/29  11:18:01  quinn
57  * Added code to receive close
58  *
59  * Revision 1.9  1995/06/16  10:31:38  quinn
60  * Added session timeout.
61  *
62  * Revision 1.8  1995/05/17  08:42:28  quinn
63  * Transfer auth info to backend. Allow backend to reject init gracefully.
64  *
65  * Revision 1.7  1995/05/16  08:51:08  quinn
66  * License, documentation, and memory fixes
67  *
68  * Revision 1.6  1995/05/15  11:56:41  quinn
69  * Asynchronous facilities. Restructuring of seshigh code.
70  *
71  * Revision 1.5  1995/04/20  15:13:01  quinn
72  * Cosmetic
73  *
74  * Revision 1.4  1995/04/10  10:23:39  quinn
75  * Some work to add scan and other things.
76  *
77  * Revision 1.3  1995/03/30  09:09:27  quinn
78  * Added state-handle and some support for asynchronous activities.
79  *
80  * Revision 1.2  1995/03/27  08:34:29  quinn
81  * Added dynamic server functionality.
82  * Released bindings to session.c (is now redundant)
83  *
84  * Revision 1.1  1995/03/14  10:28:02  quinn
85  * More work on demo server.
86  *
87  *
88  */
89
90 #ifndef SESSION_H
91 #define SESSION_H
92
93 #include <sys/types.h>
94 #include <yaz/comstack.h>
95 #include <yaz/odr.h>
96 #include <yaz/oid.h>
97 #include <yaz/proto.h>
98 #include "eventl.h"
99
100 typedef enum {
101         REQUEST_IDLE,    /* the request is just sitting in the queue */
102         REQUEST_PENDING  /* operation pending (b'end processing or network I/O*/
103         /* this list will have more elements when acc/res control is added */
104 } request_state;
105
106 typedef struct request
107 {
108     int len_refid;          /* length of referenceid */
109     char *refid;            /* referenceid */
110     request_state state;
111
112     Z_APDU *apdu_request;   /* Current request */
113     NMEM request_mem;    /* memory handle for request */
114
115     int size_response;     /* size of buffer */
116     int len_response;      /* length of encoded data */
117     char *response;        /* encoded data waiting for transmission */
118
119     void *clientData;
120     struct request *next;
121     struct request_q *q; 
122 } request;
123
124 typedef struct request_q
125 {
126     request *head;
127     request *tail;
128     request *list;
129     int num;
130 } request_q;
131
132 /*
133  * association state.
134  */
135 typedef enum
136 {
137     ASSOC_NEW,                /* not initialized yet */
138     ASSOC_UP,                 /* normal operation */
139     ASSOC_DEAD                /* dead. Close if input arrives */
140 } association_state;
141
142 typedef struct association
143 {
144     IOCHAN client_chan;           /* event-loop control */
145     COMSTACK client_link;         /* communication handle */
146     ODR decode;                   /* decoding stream */
147     ODR encode;                   /* encoding stream */
148     ODR print;                    /* printing stream (for -a) */
149     char *encode_buffer;          /* temporary buffer for encoded data */
150     int encoded_len;              /* length of encoded data */
151     char *input_buffer;           /* input buffer (allocated by comstack) */
152     int input_buffer_len;         /* length (size) of buffer */
153     int input_apdu_len;           /* length of current incoming APDU */
154     oid_proto proto;              /* protocol (PROTO_Z3950/PROTO_SR) */
155     void *backend;                /* backend handle */
156     request_q incoming;           /* Q of incoming PDUs */
157     request_q outgoing;           /* Q of outgoing data buffers (enc. PDUs) */
158     association_state state;
159
160     /* session parameters */
161     int preferredMessageSize;
162     int maximumRecordSize;
163     int version;                  /* highest version-bit set (2 or 3) */
164
165     unsigned cs_get_mask;
166     unsigned cs_put_mask;
167     unsigned cs_accept_mask;
168
169     struct bend_initrequest *init;
170 #if 0
171     int (*bend_sort) ();
172     int (*bend_search) ();
173     int (*bend_present) ();
174     int (*bend_esrequest) ();
175     int (*bend_delete) ();
176     int (*bend_scan) ();
177     int (*bend_segment) ();
178 #endif
179 } association;
180
181 association *create_association(IOCHAN channel, COMSTACK link);
182 void destroy_association(association *h);
183 void ir_session(IOCHAN h, int event);
184
185 void request_enq(request_q *q, request *r);
186 request *request_head(request_q *q);
187 request *request_deq(request_q *q);
188 request *request_deq_x(request_q *q, request *r);
189 void request_initq(request_q *q);
190 void request_delq(request_q *q);
191 request *request_get(request_q *q);
192 void request_release(request *r);
193
194 #endif