aefe3da441da0a9f3ecfd38f5a6cab2926895018
[yaz-moved-to-github.git] / server / session.h
1 /*
2  * Copyright (C) 1995, Index Data I/S 
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: session.h,v $
7  * Revision 1.12  1997-09-01 08:53:01  adam
8  * New windows NT/95 port using MSV5.0. The test server 'ztest' was
9  * moved a separate directory. MSV5.0 project server.dsp created.
10  * As an option, the server can now operate as an NT service.
11  *
12  * Revision 1.11  1995/11/08 17:41:40  quinn
13  * Smallish.
14  *
15  * Revision 1.10  1995/08/29  11:18:01  quinn
16  * Added code to receive close
17  *
18  * Revision 1.9  1995/06/16  10:31:38  quinn
19  * Added session timeout.
20  *
21  * Revision 1.8  1995/05/17  08:42:28  quinn
22  * Transfer auth info to backend. Allow backend to reject init gracefully.
23  *
24  * Revision 1.7  1995/05/16  08:51:08  quinn
25  * License, documentation, and memory fixes
26  *
27  * Revision 1.6  1995/05/15  11:56:41  quinn
28  * Asynchronous facilities. Restructuring of seshigh code.
29  *
30  * Revision 1.5  1995/04/20  15:13:01  quinn
31  * Cosmetic
32  *
33  * Revision 1.4  1995/04/10  10:23:39  quinn
34  * Some work to add scan and other things.
35  *
36  * Revision 1.3  1995/03/30  09:09:27  quinn
37  * Added state-handle and some support for asynchronous activities.
38  *
39  * Revision 1.2  1995/03/27  08:34:29  quinn
40  * Added dynamic server functionality.
41  * Released bindings to session.c (is now redundant)
42  *
43  * Revision 1.1  1995/03/14  10:28:02  quinn
44  * More work on demo server.
45  *
46  *
47  */
48
49 #ifndef SESSION_H
50 #define SESSION_H
51
52 #include <comstack.h>
53 #include <odr.h>
54 #include <oid.h>
55 #include <proto.h>
56 #include <sys/types.h>
57 #include "eventl.h"
58
59 typedef struct request
60 {
61     int len_refid;          /* length of referenceid */
62     char *refid;            /* referenceid */
63     enum {
64         REQUEST_IDLE,    /* the request is just sitting in the queue */
65         REQUEST_PENDING  /* operation pending (b'end processing or network I/O*/
66         /* this list will have more elements when acc/res control is added */
67     } state;
68
69     Z_APDU *request;        /* Current request */
70     NMEM request_mem;    /* memory handle for request */
71
72     int size_response;     /* size of buffer */
73     int len_response;      /* length of encoded data */
74     char *response;        /* encoded data waiting for transmission */
75
76     struct request *next;
77     struct request_q *q; 
78 } request;
79
80 typedef struct request_q
81 {
82     request *head;
83     request *tail;
84     request *list;
85     int num;
86 } request_q;
87
88 /*
89  * association state.
90  */
91 typedef struct association
92 {
93     IOCHAN client_chan;           /* event-loop control */
94     COMSTACK client_link;         /* communication handle */
95     ODR decode;                   /* decoding stream */
96     ODR encode;                   /* encoding stream */
97     ODR print;                    /* printing stream (for -a) */
98     char *encode_buffer;          /* temporary buffer for encoded data */
99     int encoded_len;              /* length of encoded data */
100     char *input_buffer;           /* input buffer (allocated by comstack) */
101     int input_buffer_len;         /* length (size) of buffer */
102     int input_apdu_len;           /* length of current incoming APDU */
103     oid_proto proto;              /* protocol (PROTO_Z3950/PROTO_SR) */
104     void *backend;                /* backend handle */
105     request_q incoming;           /* Q of incoming PDUs */
106     request_q outgoing;           /* Q of outgoing data buffers (enc. PDUs) */
107     enum
108     {
109         ASSOC_NEW,                /* not initialized yet */
110         ASSOC_UP,                 /* normal operation */
111         ASSOC_DEAD                /* dead. Close if input arrives */
112     } state;
113
114     /* session parameters */
115     int preferredMessageSize;
116     int maximumRecordSize;
117     int version;                  /* highest version-bit set (2 or 3) */
118 } association;
119
120 association *create_association(IOCHAN channel, COMSTACK link);
121 void destroy_association(association *h);
122 void ir_session(IOCHAN h, int event);
123
124 void request_enq(request_q *q, request *r);
125 request *request_head(request_q *q);
126 request *request_deq(request_q *q);
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 #endif