Moved CCL Map, record syntax, charset normalization, record syntax normalization...
[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 // End-user session
153 struct session {
154     struct client *clients;
155     int requestid; 
156     char query[1024];
157     NMEM nmem;          // Nmem for each operation (i.e. search)
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();
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
230 #endif
231
232 /*
233  * Local variables:
234  * c-basic-offset: 4
235  * indent-tabs-mode: nil
236  * End:
237  * vim: shiftwidth=4 tabstop=8 expandtab
238  */