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