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