6e8f8b0180644e9fea8619451127f3ce335834d2
[yaz-moved-to-github.git] / server / session.h
1 /*
2  * Copyright (C) 1995-2003, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Id: session.h,v 1.27 2003-01-06 08:20:28 adam Exp $
7  */
8
9 #ifndef SESSION_H
10 #define SESSION_H
11
12 #include <sys/types.h>
13 #include <yaz/comstack.h>
14 #include <yaz/odr.h>
15 #include <yaz/oid.h>
16 #include <yaz/proto.h>
17 #include "eventl.h"
18
19 typedef enum {
20         REQUEST_IDLE,    /* the request is just sitting in the queue */
21         REQUEST_PENDING  /* operation pending (b'end processing or network I/O*/
22         /* this list will have more elements when acc/res control is added */
23 } request_state;
24
25 typedef struct request
26 {
27     int len_refid;          /* length of referenceid */
28     char *refid;            /* referenceid */
29     request_state state;
30
31     Z_APDU *apdu_request;   /* Current request */
32     NMEM request_mem;    /* memory handle for request */
33
34     int size_response;     /* size of buffer */
35     int len_response;      /* length of encoded data */
36     char *response;        /* encoded data waiting for transmission */
37
38     void *clientData;
39     struct request *next;
40     struct request_q *q; 
41 } request;
42
43 typedef struct request_q
44 {
45     request *head;
46     request *tail;
47     request *list;
48     int num;
49 } request_q;
50
51 /*
52  * association state.
53  */
54 typedef enum
55 {
56     ASSOC_NEW,                /* not initialized yet */
57     ASSOC_UP,                 /* normal operation */
58     ASSOC_DEAD                /* dead. Close if input arrives */
59 } association_state;
60
61 typedef struct association
62 {
63     IOCHAN client_chan;           /* event-loop control */
64     COMSTACK client_link;         /* communication handle */
65     ODR decode;                   /* decoding stream */
66     ODR encode;                   /* encoding stream */
67     ODR print;                    /* printing stream (for -a) */
68     char *encode_buffer;          /* temporary buffer for encoded data */
69     int encoded_len;              /* length of encoded data */
70     char *input_buffer;           /* input buffer (allocated by comstack) */
71     int input_buffer_len;         /* length (size) of buffer */
72     int input_apdu_len;           /* length of current incoming APDU */
73     oid_proto proto;              /* protocol (PROTO_Z3950/PROTO_SR) */
74     void *backend;                /* backend handle */
75     request_q incoming;           /* Q of incoming PDUs */
76     request_q outgoing;           /* Q of outgoing data buffers (enc. PDUs) */
77     association_state state;
78
79     /* session parameters */
80     int preferredMessageSize;
81     int maximumRecordSize;
82     int version;                  /* highest version-bit set (2 or 3) */
83
84     unsigned cs_get_mask;
85     unsigned cs_put_mask;
86     unsigned cs_accept_mask;
87
88     struct bend_initrequest *init;
89 #if 0
90     int (*bend_sort) ();
91     int (*bend_search) ();
92     int (*bend_present) ();
93     int (*bend_esrequest) ();
94     int (*bend_delete) ();
95     int (*bend_scan) ();
96     int (*bend_segment) ();
97 #endif
98 } association;
99
100 association *create_association(IOCHAN channel, COMSTACK link);
101 void destroy_association(association *h);
102 void ir_session(IOCHAN h, int event);
103
104 void request_enq(request_q *q, request *r);
105 request *request_head(request_q *q);
106 request *request_deq(request_q *q);
107 request *request_deq_x(request_q *q, request *r);
108 void request_initq(request_q *q);
109 void request_delq(request_q *q);
110 request *request_get(request_q *q);
111 void request_release(request *r);
112
113 int statserv_must_terminate(void);
114
115 #endif