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