Removed query from session structure. It is no longer needed, since a pquery
[pazpar2-moved-to-github.git] / src / pazpar2.h
1 /* $Id: pazpar2.h,v 1.27 2007-04-20 04:08:14 quinn Exp $
2    Copyright (c) 2006-2007, Index Data.
3
4 This file is part of Pazpar2.
5
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #ifndef PAZPAR2_H
23 #define PAZPAR2_H
24
25 struct record;
26
27 #include <netdb.h>
28
29 #include <libxslt/xsltutils.h>
30 #include <libxslt/transform.h>
31
32 #include <yaz/comstack.h>
33 #include <yaz/pquery.h>
34 #include <yaz/ccl.h>
35 #include <yaz/yaz-ccl.h>
36
37 #include "termlists.h"
38 #include "relevance.h"
39 #include "reclists.h"
40 #include "eventl.h"
41 #include "config.h"
42
43 struct client;
44
45 union data_types {
46     char *text;
47     struct {
48         int min;
49         int max;
50     } number;
51 };
52
53 struct record_metadata {
54     union data_types data;
55     struct record_metadata *next; // next item of this name
56 };
57
58 struct record {
59     struct client *client;
60     struct record_metadata **metadata; // Array mirrors list of metadata fields in config
61     union data_types **sortkeys;       // Array mirrors list of sortkey fields in config
62     struct record *next;  // Next in cluster of merged records
63 };
64
65 struct record_cluster
66 {
67     struct record_metadata **metadata; // Array mirrors list of metadata fields in config
68     union data_types **sortkeys;
69     char *merge_key;
70     int relevance;
71     int *term_frequency_vec;
72     int recid; // Set-specific ID for this record
73     struct record *records;
74 };
75
76 struct connection;
77
78 // Represents a host (irrespective of databases)
79 struct host {
80     char *hostport;
81     char *ipport;
82     struct connection *connections; // All connections to this
83     struct host *next;
84 };
85
86 // Represents a (virtual) database on a host
87 struct database {
88     struct host *host;
89     char *url;
90     char **databases;
91     int errors;
92     struct zr_explain *explain;
93     struct setting **settings;
94     struct database *next;
95     CCL_bibset ccl_map;
96     yaz_marc_t yaz_marc;
97     struct database_retrievalmap *map;
98 };
99
100 // Normalization filter. Turns incoming record into internal representation
101 // Simple sequence of stylesheets run in series.
102 struct database_retrievalmap {
103     xsltStylesheet *stylesheet;
104     struct database_retrievalmap *next;
105 };
106
107 struct database_criterion_value {
108     char *value;
109     struct database_criterion_value *next;
110 };
111
112 struct database_criterion {
113     char *name;
114     struct database_criterion_value *values;
115     struct database_criterion *next;
116 };
117
118 // Represents a physical, reusable  connection to a remote Z39.50 host
119 struct connection {
120     IOCHAN iochan;
121     COMSTACK link;
122     struct host *host;
123     struct client *client;
124     char *ibuf;
125     int ibufsize;
126     enum {
127         Conn_Connecting,
128         Conn_Open,
129         Conn_Waiting,
130     } state;
131     struct connection *next;
132 };
133
134 // Represents client state for a connection to one search target
135 struct client {
136     struct session_database *database;
137     struct connection *connection;
138     struct session *session;
139     char *pquery; // Current search
140     int hits;
141     int records;
142     int setno;
143     int requestid;                              // ID of current outstanding request
144     int diagnostic;
145     enum client_state
146     {
147         Client_Connecting,
148         Client_Connected,
149         Client_Idle,
150         Client_Initializing,
151         Client_Searching,
152         Client_Presenting,
153         Client_Error,
154         Client_Failed,
155         Client_Disconnected,
156         Client_Stopped
157     } state;
158     struct client *next;
159 };
160
161 #define SESSION_WATCH_RECORDS   0
162 #define SESSION_WATCH_MAX       0
163
164 #define SESSION_MAX_TERMLISTS 10
165
166 typedef void (*session_watchfun)(void *data);
167
168 struct named_termlist
169 {
170     char *name;
171     struct termlist *termlist;
172 };
173
174 // Represents a database as viewed from one session, possibly with settings overriden
175 // for that session (to support authorization/authentication)
176 struct session_database
177 {
178     struct database *database;
179     struct setting **settings;
180     struct session_database *next;
181 };
182
183 // End-user session
184 struct session {
185     struct session_database *databases;  // All databases, settings overriden
186     struct client *clients;              // Clients connected for current search
187     int requestid; 
188     NMEM session_nmem;  // Nmem for session-permanent storage
189     NMEM nmem;          // Nmem for each operation (i.e. search, result set, etc)
190     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
191     int num_termlists;
192     struct named_termlist termlists[SESSION_MAX_TERMLISTS];
193     struct relevance *relevance;
194     struct reclist *reclist;
195     struct {
196         void *data;
197         session_watchfun fun;
198     } watchlist[SESSION_WATCH_MAX + 1];
199     int expected_maxrecs;
200     int total_hits;
201     int total_records;
202     int total_merged;
203 };
204
205 struct statistics {
206     int num_clients;
207     int num_no_connection;
208     int num_connecting;
209     int num_initializing;
210     int num_searching;
211     int num_presenting;
212     int num_idle;
213     int num_failed;
214     int num_error;
215     int num_hits;
216     int num_records;
217 };
218
219 struct hitsbytarget {
220     char *id;
221     char *name;
222     int hits;
223     int diagnostic;
224     int records;
225     char* state;
226     int connected;
227 };
228
229 struct parameters {
230     char proxy_override[128];
231     char listener_override[128];
232     char zproxy_override[128];
233     char settings_path_override[128];
234     struct conf_server *server;
235     int dump_records;
236     int timeout;                /* operations timeout, in seconds */
237     char implementationId[128];
238     char implementationName[128];
239     char implementationVersion[128];
240     int target_timeout; // seconds
241     int session_timeout;
242     int toget;
243     int chunk;
244     ODR odr_out;
245     ODR odr_in;
246 };
247
248 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
249 int select_targets(struct session *se, struct database_criterion *crit);
250 struct session *new_session(NMEM nmem);
251 void destroy_session(struct session *s);
252 int load_targets(struct session *s, const char *fn);
253 void statistics(struct session *s, struct statistics *stat);
254 char *search(struct session *s, char *query, char *filter);
255 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
256         int *num, int *total, int *sumhits, NMEM nmem_show);
257 struct record_cluster *show_single(struct session *s, int id);
258 struct termlist_score **termlist(struct session *s, const char *name, int *num);
259 void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);
260 int session_active_clients(struct session *s);
261 void session_apply_setting(struct session *se, char *dbname, char *setting, char *value);
262 char *session_setting_oneval(struct session_database *db, int offset);
263
264 void start_http_listener(void);
265 void start_proxy(void);
266 void start_zproxy(void);
267
268 extern struct parameters global_parameters;
269 void pazpar2_add_channel(IOCHAN c);
270 void pazpar2_event_loop(void);
271 #endif
272
273 /*
274  * Local variables:
275  * c-basic-offset: 4
276  * indent-tabs-mode: nil
277  * End:
278  * vim: shiftwidth=4 tabstop=8 expandtab
279  */