More work on settings system.. still not functional.
[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 conf_queryprofile *qprofile;
74     struct conf_retrievalprofile *rprofile;
75     struct database *next;
76 };
77
78 struct database_criterion_value {
79     char *value;
80     struct database_criterion_value *next;
81 };
82
83 struct database_criterion {
84     char *name;
85     struct database_criterion_value *values;
86     struct database_criterion *next;
87 };
88
89 // Represents a physical, reusable  connection to a remote Z39.50 host
90 struct connection {
91     IOCHAN iochan;
92     COMSTACK link;
93     struct host *host;
94     struct client *client;
95     char *ibuf;
96     int ibufsize;
97     enum {
98         Conn_Connecting,
99         Conn_Open,
100         Conn_Waiting,
101     } state;
102     struct connection *next;
103 };
104
105 // Represents client state for a connection to one search target
106 struct client {
107     struct database *database;
108     struct connection *connection;
109     struct session *session;
110     int hits;
111     int records;
112     int setno;
113     int requestid;                              // ID of current outstanding request
114     int diagnostic;
115     enum client_state
116     {
117         Client_Connecting,
118         Client_Connected,
119         Client_Idle,
120         Client_Initializing,
121         Client_Searching,
122         Client_Presenting,
123         Client_Error,
124         Client_Failed,
125         Client_Disconnected,
126         Client_Stopped
127     } state;
128     struct client *next;
129 };
130
131 #define SESSION_WATCH_RECORDS   0
132 #define SESSION_WATCH_MAX       0
133
134 #define SESSION_MAX_TERMLISTS 10
135
136 typedef void (*session_watchfun)(void *data);
137
138 struct named_termlist
139 {
140     char *name;
141     struct termlist *termlist;
142 };
143
144 // End-user session
145 struct session {
146     struct client *clients;
147     int requestid; 
148     char query[1024];
149     NMEM nmem;          // Nmem for each operation (i.e. search)
150     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
151     int num_termlists;
152     struct named_termlist termlists[SESSION_MAX_TERMLISTS];
153     struct relevance *relevance;
154     struct reclist *reclist;
155     struct {
156         void *data;
157         session_watchfun fun;
158     } watchlist[SESSION_WATCH_MAX + 1];
159     int expected_maxrecs;
160     int total_hits;
161     int total_records;
162     int total_merged;
163 };
164
165 struct statistics {
166     int num_clients;
167     int num_no_connection;
168     int num_connecting;
169     int num_initializing;
170     int num_searching;
171     int num_presenting;
172     int num_idle;
173     int num_failed;
174     int num_error;
175     int num_hits;
176     int num_records;
177 };
178
179 struct hitsbytarget {
180     char *id;
181     char *name;
182     int hits;
183     int diagnostic;
184     int records;
185     char* state;
186     int connected;
187 };
188
189 struct parameters {
190     char proxy_override[128];
191     char listener_override[128];
192     char zproxy_override[128];
193     char settings_path[128];
194     struct conf_server *server;
195     int dump_records;
196     int timeout;                /* operations timeout, in seconds */
197     char implementationId[128];
198     char implementationName[128];
199     char implementationVersion[128];
200     int target_timeout; // seconds
201     int session_timeout;
202     int toget;
203     int chunk;
204     CCL_bibset ccl_filter;
205     yaz_marc_t yaz_marc;
206     ODR odr_out;
207     ODR odr_in;
208 };
209
210 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
211 int select_targets(struct session *se, struct database_criterion *crit);
212 struct session *new_session();
213 void destroy_session(struct session *s);
214 int load_targets(struct session *s, const char *fn);
215 void statistics(struct session *s, struct statistics *stat);
216 char *search(struct session *s, char *query, char *filter);
217 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
218         int *num, int *total, int *sumhits, NMEM nmem_show);
219 struct record_cluster *show_single(struct session *s, int id);
220 struct termlist_score **termlist(struct session *s, const char *name, int *num);
221 void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);
222 int session_active_clients(struct session *s);
223
224 #endif
225
226 /*
227  * Local variables:
228  * c-basic-offset: 4
229  * indent-tabs-mode: nil
230  * End:
231  * vim: shiftwidth=4 tabstop=8 expandtab
232  */