Added retrieval handling support in Generic Frontend Server to support
[yaz-moved-to-github.git] / src / session.h
1 /*
2  * Copyright (C) 1995-2006, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: session.h,v 1.11 2006-05-07 14:48:25 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 <yaz/retrieval.h>
21 #include "eventl.h"
22
23 struct gfs_server {
24     statserv_options_block cb;
25     char *host;
26     int listen_ref;
27     cql_transform_t cql_transform;
28     void *server_node_ptr;
29     char *directory;
30     char *docpath;
31     char *stylesheet;
32     yaz_retrieval_t retrieval;
33     struct gfs_server *next;
34 };
35
36 struct gfs_listen {
37     char *id;
38     char *address;
39     struct gfs_listen *next;
40 };
41
42 typedef enum {
43     REQUEST_IDLE,    /* the request is just sitting in the queue */
44     REQUEST_PENDING  /* operation pending (b'end processing or network I/O*/
45     /* this list will have more elements when acc/res control is added */
46 } request_state;
47
48 typedef struct request
49 {
50     int len_refid;          /* length of referenceid */
51     char *refid;            /* referenceid */
52     request_state state;
53
54     Z_GDU *gdu_request;     /* Current request */
55     Z_APDU *apdu_request;   /* Current Z39.50 request */
56     NMEM request_mem;    /* memory handle for request */
57
58     int size_response;     /* size of buffer */
59     int len_response;      /* length of encoded data */
60     char *response;        /* encoded data waiting for transmission */
61
62     void *clientData;
63     struct request *next;
64     struct request_q *q; 
65 } request;
66
67 typedef struct request_q
68 {
69     request *head;
70     request *tail;
71     request *list;
72     int num;
73 } request_q;
74
75 /*
76  * association state.
77  */
78 typedef enum
79 {
80     ASSOC_NEW,                /* not initialized yet */
81     ASSOC_UP,                 /* normal operation */
82     ASSOC_DEAD                /* dead. Close if input arrives */
83 } association_state;
84
85 typedef struct association
86 {
87     IOCHAN client_chan;           /* event-loop control */
88     COMSTACK client_link;         /* communication handle */
89     ODR decode;                   /* decoding stream */
90     ODR encode;                   /* encoding stream */
91     ODR print;                    /* printing stream (for -a) */
92     char *encode_buffer;          /* temporary buffer for encoded data */
93     int encoded_len;              /* length of encoded data */
94     char *input_buffer;           /* input buffer (allocated by comstack) */
95     int input_buffer_len;         /* length (size) of buffer */
96     int input_apdu_len;           /* length of current incoming APDU */
97     oid_proto proto;              /* protocol (PROTO_Z3950/PROTO_SR) */
98     void *backend;                /* backend handle */
99     request_q incoming;           /* Q of incoming PDUs */
100     request_q outgoing;           /* Q of outgoing data buffers (enc. PDUs) */
101     association_state state;
102
103     /* session parameters */
104     int preferredMessageSize;
105     int maximumRecordSize;
106     int version;                  /* highest version-bit set (2 or 3) */
107
108     unsigned cs_get_mask;
109     unsigned cs_put_mask;
110     unsigned cs_accept_mask;
111
112     struct bend_initrequest *init;
113     statserv_options_block *last_control;
114
115     struct gfs_server *server;
116 } association;
117
118 association *create_association(IOCHAN channel, COMSTACK link,
119                                 const char *apdufile);
120 void destroy_association(association *h);
121 void ir_session(IOCHAN h, int event);
122
123 void request_enq(request_q *q, request *r);
124 request *request_head(request_q *q);
125 request *request_deq(request_q *q);
126 request *request_deq_x(request_q *q, request *r);
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 int statserv_must_terminate(void);
133
134 int control_association(association *assoc, const char *host, int force);
135
136 #endif
137 /*
138  * Local variables:
139  * c-basic-offset: 4
140  * indent-tabs-mode: nil
141  * End:
142  * vim: shiftwidth=4 tabstop=8 expandtab
143  */
144