Implemented session timeout; ping command
[pazpar2-moved-to-github.git] / pazpar2.h
1 #ifndef PAZPAR2_H
2 #define PAZPAR2_H
3
4 struct record;
5
6 #include <netdb.h>
7
8 #include <yaz/comstack.h>
9 #include <yaz/pquery.h>
10 #include <yaz/ccl.h>
11 #include <yaz/yaz-ccl.h>
12 #include "termlists.h"
13 #include "relevance.h"
14 #include "eventl.h"
15
16 #define MAX_DATABASES 512
17
18 struct record {
19     struct client *client;
20     int target_offset;
21     char *buf;
22     char *merge_key;
23     char *title;
24     int relevance;
25     int *term_frequency_vec;
26     struct record *next_cluster;
27 };
28
29 struct connection;
30
31 // Represents a host (irrespective of databases)
32 struct host {
33     char *hostport;
34     char *ipport;
35     struct connection *connections; // All connections to this
36     struct host *next;
37 };
38
39 // Represents a (virtual) database on a host
40 struct database {
41     struct host *host;
42     char *url;
43     char databases[MAX_DATABASES][128];
44     int errors;
45     struct database *next;
46 };
47
48 struct client;
49
50 // Represents a physical, reusable  connection to a remote Z39.50 host
51 struct connection {
52     IOCHAN iochan;
53     COMSTACK link;
54     struct host *host;
55     struct client *client;
56     char *ibuf;
57     int ibufsize;
58     enum {
59         Conn_Connecting,
60         Conn_Open,
61         Conn_Waiting,
62     } state;
63     struct connection *next;
64 };
65
66 // Represents client state for a connection to one search target
67 struct client {
68     struct database *database;
69     struct connection *connection;
70     struct session *session;
71     int hits;
72     int records;
73     int setno;
74     int requestid;                              // ID of current outstanding request
75     int diagnostic;
76     enum client_state
77     {
78         Client_Connecting,
79         Client_Connected,
80         Client_Idle,
81         Client_Initializing,
82         Client_Searching,
83         Client_Presenting,
84         Client_Error,
85         Client_Failed,
86         Client_Disconnected,
87         Client_Stopped
88     } state;
89     struct client *next;
90 };
91
92 // End-user session
93 struct session {
94     struct client *clients;
95     int requestid; 
96     char query[1024];
97     NMEM nmem;          // Nmem for each operation (i.e. search)
98     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
99     struct termlist *termlist;
100     struct relevance *relevance;
101     struct reclist *reclist;
102     int total_hits;
103     int total_records;
104 };
105
106 struct statistics {
107     int num_clients;
108     int num_no_connection;
109     int num_connecting;
110     int num_initializing;
111     int num_searching;
112     int num_presenting;
113     int num_idle;
114     int num_failed;
115     int num_error;
116     int num_hits;
117     int num_records;
118 };
119
120 struct hitsbytarget {
121     char id[256];
122     int hits;
123     int diagnostic;
124     int records;
125     char* state;
126     int connected;
127 };
128
129 struct parameters {
130     int timeout;                /* operations timeout, in seconds */
131     char implementationId[128];
132     char implementationName[128];
133     char implementationVersion[128];
134     int target_timeout; // seconds
135     int session_timeout;
136     int toget;
137     int chunk;
138     CCL_bibset ccl_filter;
139     yaz_marc_t yaz_marc;
140     ODR odr_out;
141     ODR odr_in;
142 };
143
144 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
145 int select_targets(struct session *se);
146 struct session *new_session();
147 void destroy_session(struct session *s);
148 int load_targets(struct session *s, const char *fn);
149 void statistics(struct session *s, struct statistics *stat);
150 char *search(struct session *s, char *query);
151 struct record **show(struct session *s, int start, int *num, int *total, int *sumhits);
152 struct termlist_score **termlist(struct session *s, int *num);
153
154 #endif
155
156 /*
157  * Local variables:
158  * c-basic-offset: 4
159  * indent-tabs-mode: nil
160  * End:
161  * vim: shiftwidth=4 tabstop=8 expandtab
162  */