Wrap OPACXML in opacRecord as suggested by Larry Dixson.
[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.6 2005-03-01 20:37:01 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     struct gfs_server *next;
28 };
29
30 struct gfs_listen {
31     char *id;
32     char *address;
33     struct gfs_listen *next;
34 };
35
36 typedef enum {
37     REQUEST_IDLE,    /* the request is just sitting in the queue */
38     REQUEST_PENDING  /* operation pending (b'end processing or network I/O*/
39     /* this list will have more elements when acc/res control is added */
40 } request_state;
41
42 typedef struct request
43 {
44     int len_refid;          /* length of referenceid */
45     char *refid;            /* referenceid */
46     request_state state;
47
48     Z_GDU *gdu_request;     /* Current request */
49     Z_APDU *apdu_request;   /* Current Z39.50 request */
50     NMEM request_mem;    /* memory handle for request */
51
52     int size_response;     /* size of buffer */
53     int len_response;      /* length of encoded data */
54     char *response;        /* encoded data waiting for transmission */
55
56     void *clientData;
57     struct request *next;
58     struct request_q *q; 
59 } request;
60
61 typedef struct request_q
62 {
63     request *head;
64     request *tail;
65     request *list;
66     int num;
67 } request_q;
68
69 /*
70  * association state.
71  */
72 typedef enum
73 {
74     ASSOC_NEW,                /* not initialized yet */
75     ASSOC_UP,                 /* normal operation */
76     ASSOC_DEAD                /* dead. Close if input arrives */
77 } association_state;
78
79 typedef struct association
80 {
81     IOCHAN client_chan;           /* event-loop control */
82     COMSTACK client_link;         /* communication handle */
83     ODR decode;                   /* decoding stream */
84     ODR encode;                   /* encoding stream */
85     ODR print;                    /* printing stream (for -a) */
86     char *encode_buffer;          /* temporary buffer for encoded data */
87     int encoded_len;              /* length of encoded data */
88     char *input_buffer;           /* input buffer (allocated by comstack) */
89     int input_buffer_len;         /* length (size) of buffer */
90     int input_apdu_len;           /* length of current incoming APDU */
91     oid_proto proto;              /* protocol (PROTO_Z3950/PROTO_SR) */
92     void *backend;                /* backend handle */
93     request_q incoming;           /* Q of incoming PDUs */
94     request_q outgoing;           /* Q of outgoing data buffers (enc. PDUs) */
95     association_state state;
96
97     /* session parameters */
98     int preferredMessageSize;
99     int maximumRecordSize;
100     int version;                  /* highest version-bit set (2 or 3) */
101
102     unsigned cs_get_mask;
103     unsigned cs_put_mask;
104     unsigned cs_accept_mask;
105
106     struct bend_initrequest *init;
107     statserv_options_block *last_control;
108     cql_transform_t cql_transform;
109 } association;
110
111 association *create_association(IOCHAN channel, COMSTACK link,
112                                 const char *apdufile);
113 void destroy_association(association *h);
114 void ir_session(IOCHAN h, int event);
115
116 void request_enq(request_q *q, request *r);
117 request *request_head(request_q *q);
118 request *request_deq(request_q *q);
119 request *request_deq_x(request_q *q, request *r);
120 void request_initq(request_q *q);
121 void request_delq(request_q *q);
122 request *request_get(request_q *q);
123 void request_release(request *r);
124
125 int statserv_must_terminate(void);
126
127 int control_association(association *assoc, const char *host, int force);
128
129 #endif