GPLv2. Added appendix with full license. Added refernece to that from
[pazpar2-moved-to-github.git] / src / pazpar2.h
1 /* $Id: pazpar2.h,v 1.21 2007-04-10 08:48:56 adam 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 *name;
91     char **databases;
92     int errors;
93     struct zr_explain *explain;
94     struct setting **settings;
95     struct database *next;
96     CCL_bibset ccl_map;
97     yaz_marc_t yaz_marc;
98     struct database_retrievalmap *map;
99 };
100
101 // Normalization filter chain. Turns incoming record into internal representation
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 database *database;
137     struct connection *connection;
138     struct session *session;
139     int hits;
140     int records;
141     int setno;
142     int requestid;                              // ID of current outstanding request
143     int diagnostic;
144     enum client_state
145     {
146         Client_Connecting,
147         Client_Connected,
148         Client_Idle,
149         Client_Initializing,
150         Client_Searching,
151         Client_Presenting,
152         Client_Error,
153         Client_Failed,
154         Client_Disconnected,
155         Client_Stopped
156     } state;
157     struct client *next;
158 };
159
160 #define SESSION_WATCH_RECORDS   0
161 #define SESSION_WATCH_MAX       0
162
163 #define SESSION_MAX_TERMLISTS 10
164
165 typedef void (*session_watchfun)(void *data);
166
167 struct named_termlist
168 {
169     char *name;
170     struct termlist *termlist;
171 };
172
173 // Represents a database as viewed from one session, possibly with settings overriden
174 // for that session (to support authorization/authentication)
175 struct session_database
176 {
177     struct database *database;
178     struct setting *settings;
179     struct session_database *next;
180 };
181
182 // End-user session
183 struct session {
184     struct client *clients;
185     int requestid; 
186     char query[1024];
187     NMEM session_nmem;  // Nmem for session-permanent storage
188     NMEM nmem;          // Nmem for each operation (i.e. search, result set, etc)
189     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
190     int num_termlists;
191     struct named_termlist termlists[SESSION_MAX_TERMLISTS];
192     struct relevance *relevance;
193     struct reclist *reclist;
194     struct {
195         void *data;
196         session_watchfun fun;
197     } watchlist[SESSION_WATCH_MAX + 1];
198     int expected_maxrecs;
199     int total_hits;
200     int total_records;
201     int total_merged;
202 };
203
204 struct statistics {
205     int num_clients;
206     int num_no_connection;
207     int num_connecting;
208     int num_initializing;
209     int num_searching;
210     int num_presenting;
211     int num_idle;
212     int num_failed;
213     int num_error;
214     int num_hits;
215     int num_records;
216 };
217
218 struct hitsbytarget {
219     char *id;
220     char *name;
221     int hits;
222     int diagnostic;
223     int records;
224     char* state;
225     int connected;
226 };
227
228 struct parameters {
229     char proxy_override[128];
230     char listener_override[128];
231     char zproxy_override[128];
232     char settings_path_override[128];
233     struct conf_server *server;
234     int dump_records;
235     int timeout;                /* operations timeout, in seconds */
236     char implementationId[128];
237     char implementationName[128];
238     char implementationVersion[128];
239     int target_timeout; // seconds
240     int session_timeout;
241     int toget;
242     int chunk;
243     ODR odr_out;
244     ODR odr_in;
245 };
246
247 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
248 int select_targets(struct session *se, struct database_criterion *crit);
249 struct session *new_session(NMEM nmem);
250 void destroy_session(struct session *s);
251 int load_targets(struct session *s, const char *fn);
252 void statistics(struct session *s, struct statistics *stat);
253 char *search(struct session *s, char *query, char *filter);
254 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
255         int *num, int *total, int *sumhits, NMEM nmem_show);
256 struct record_cluster *show_single(struct session *s, int id);
257 struct termlist_score **termlist(struct session *s, const char *name, int *num);
258 void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);
259 int session_active_clients(struct session *s);
260
261 #endif
262
263 /*
264  * Local variables:
265  * c-basic-offset: 4
266  * indent-tabs-mode: nil
267  * End:
268  * vim: shiftwidth=4 tabstop=8 expandtab
269  */