splitting record specific definition out from pazpar2.h header to record.h header...
[pazpar2-moved-to-github.git] / src / pazpar2.h
1 /* $Id: pazpar2.h,v 1.29 2007-04-20 13:03:22 marc 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
26 #include <netdb.h>
27
28 #include <libxslt/xsltutils.h>
29 #include <libxslt/transform.h>
30
31 #include <yaz/comstack.h>
32 #include <yaz/pquery.h>
33 #include <yaz/ccl.h>
34 #include <yaz/yaz-ccl.h>
35
36 #include "termlists.h"
37 #include "relevance.h"
38 #include "reclists.h"
39 #include "eventl.h"
40 #include "config.h"
41
42 struct record;
43 struct client;
44
45 struct connection;
46
47 // Represents a host (irrespective of databases)
48 struct host {
49     char *hostport;
50     char *ipport;
51     struct connection *connections; // All connections to this
52     struct host *next;
53 };
54
55 // Represents a (virtual) database on a host
56 struct database {
57     struct host *host;
58     char *url;
59     char **databases;
60     int errors;
61     struct zr_explain *explain;
62     struct setting **settings;
63     struct database *next;
64     yaz_marc_t yaz_marc;
65     struct database_retrievalmap *map;
66 };
67
68 // Normalization filter. Turns incoming record into internal representation
69 // Simple sequence of stylesheets run in series.
70 struct database_retrievalmap {
71     xsltStylesheet *stylesheet;
72     struct database_retrievalmap *next;
73 };
74
75 struct database_criterion_value {
76     char *value;
77     struct database_criterion_value *next;
78 };
79
80 struct database_criterion {
81     char *name;
82     struct database_criterion_value *values;
83     struct database_criterion *next;
84 };
85
86 // Represents a physical, reusable  connection to a remote Z39.50 host
87 struct connection {
88     IOCHAN iochan;
89     COMSTACK link;
90     struct host *host;
91     struct client *client;
92     char *ibuf;
93     int ibufsize;
94     enum {
95         Conn_Connecting,
96         Conn_Open,
97         Conn_Waiting,
98     } state;
99     struct connection *next;
100 };
101
102 // Represents client state for a connection to one search target
103 struct client {
104     struct session_database *database;
105     struct connection *connection;
106     struct session *session;
107     char *pquery; // Current search
108     int hits;
109     int records;
110     int setno;
111     int requestid;                              // ID of current outstanding request
112     int diagnostic;
113     enum client_state
114     {
115         Client_Connecting,
116         Client_Connected,
117         Client_Idle,
118         Client_Initializing,
119         Client_Searching,
120         Client_Presenting,
121         Client_Error,
122         Client_Failed,
123         Client_Disconnected,
124         Client_Stopped
125     } state;
126     struct client *next;
127 };
128
129 #define SESSION_WATCH_RECORDS   0
130 #define SESSION_WATCH_MAX       0
131
132 #define SESSION_MAX_TERMLISTS 10
133
134 typedef void (*session_watchfun)(void *data);
135
136 struct named_termlist
137 {
138     char *name;
139     struct termlist *termlist;
140 };
141
142 // Represents a database as viewed from one session, possibly with settings overriden
143 // for that session (to support authorization/authentication)
144 struct session_database
145 {
146     struct database *database;
147     struct setting **settings;
148     struct session_database *next;
149 };
150
151 // End-user session
152 struct session {
153     struct session_database *databases;  // All databases, settings overriden
154     struct client *clients;              // Clients connected for current search
155     int requestid; 
156     NMEM session_nmem;  // Nmem for session-permanent storage
157     NMEM nmem;          // Nmem for each operation (i.e. search, result set, etc)
158     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
159     int num_termlists;
160     struct named_termlist termlists[SESSION_MAX_TERMLISTS];
161     struct relevance *relevance;
162     struct reclist *reclist;
163     struct {
164         void *data;
165         session_watchfun fun;
166     } watchlist[SESSION_WATCH_MAX + 1];
167     int expected_maxrecs;
168     int total_hits;
169     int total_records;
170     int total_merged;
171 };
172
173 struct statistics {
174     int num_clients;
175     int num_no_connection;
176     int num_connecting;
177     int num_initializing;
178     int num_searching;
179     int num_presenting;
180     int num_idle;
181     int num_failed;
182     int num_error;
183     int num_hits;
184     int num_records;
185 };
186
187 struct hitsbytarget {
188     char *id;
189     char *name;
190     int hits;
191     int diagnostic;
192     int records;
193     char* state;
194     int connected;
195 };
196
197 struct parameters {
198     char proxy_override[128];
199     char listener_override[128];
200     char zproxy_override[128];
201     char settings_path_override[128];
202     struct conf_server *server;
203     int dump_records;
204     int timeout;                /* operations timeout, in seconds */
205     char implementationId[128];
206     char implementationName[128];
207     char implementationVersion[128];
208     int target_timeout; // seconds
209     int session_timeout;
210     int toget;
211     int chunk;
212     ODR odr_out;
213     ODR odr_in;
214 };
215
216 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
217 int select_targets(struct session *se, struct database_criterion *crit);
218 struct session *new_session(NMEM nmem);
219 void destroy_session(struct session *s);
220 int load_targets(struct session *s, const char *fn);
221 void statistics(struct session *s, struct statistics *stat);
222 char *search(struct session *s, char *query, char *filter);
223 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
224         int *num, int *total, int *sumhits, NMEM nmem_show);
225 struct record_cluster *show_single(struct session *s, int id);
226 struct termlist_score **termlist(struct session *s, const char *name, int *num);
227 void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);
228 int session_active_clients(struct session *s);
229 void session_apply_setting(struct session *se, char *dbname, char *setting, char *value);
230 char *session_setting_oneval(struct session_database *db, int offset);
231
232 void start_http_listener(void);
233 void start_proxy(void);
234 void start_zproxy(void);
235
236 extern struct parameters global_parameters;
237 void pazpar2_add_channel(IOCHAN c);
238 void pazpar2_event_loop(void);
239
240
241
242 #endif
243
244 /*
245  * Local variables:
246  * c-basic-offset: 4
247  * indent-tabs-mode: nil
248  * End:
249  * vim: shiftwidth=4 tabstop=8 expandtab
250  */