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