Added XSLT support. Configuration file (e.g. etc/pazpar2.cfg) must now be specified
[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 "eventl.h"
19 #include "config.h"
20
21 struct client;
22
23 struct record {
24     struct client *client;
25     int target_offset;
26     char *merge_key;
27     char *title;
28     int relevance;
29     int *term_frequency_vec;
30     struct record *next_cluster;
31 };
32
33 struct connection;
34
35 // Represents a host (irrespective of databases)
36 struct host {
37     char *hostport;
38     char *ipport;
39     struct connection *connections; // All connections to this
40     struct host *next;
41 };
42
43 // Represents a (virtual) database on a host
44 struct database {
45     struct host *host;
46     char *url;
47     char **databases;
48     int errors;
49     struct conf_queryprofile *qprofile;
50     struct conf_retrievalprofile *rprofile;
51     struct database *next;
52 };
53
54
55 // Represents a physical, reusable  connection to a remote Z39.50 host
56 struct connection {
57     IOCHAN iochan;
58     COMSTACK link;
59     struct host *host;
60     struct client *client;
61     char *ibuf;
62     int ibufsize;
63     enum {
64         Conn_Connecting,
65         Conn_Open,
66         Conn_Waiting,
67     } state;
68     struct connection *next;
69 };
70
71 // Represents client state for a connection to one search target
72 struct client {
73     struct database *database;
74     struct connection *connection;
75     struct session *session;
76     int hits;
77     int records;
78     int setno;
79     int requestid;                              // ID of current outstanding request
80     int diagnostic;
81     enum client_state
82     {
83         Client_Connecting,
84         Client_Connected,
85         Client_Idle,
86         Client_Initializing,
87         Client_Searching,
88         Client_Presenting,
89         Client_Error,
90         Client_Failed,
91         Client_Disconnected,
92         Client_Stopped
93     } state;
94     struct client *next;
95 };
96
97 #define SESSION_WATCH_RECORDS   0
98 #define SESSION_WATCH_MAX       0
99
100 #define SESSION_MAX_TERMLISTS 10
101
102 typedef void (*session_watchfun)(void *data);
103
104 struct named_termlist
105 {
106     char *name;
107     struct termlist *termlist;
108 };
109
110 // End-user session
111 struct session {
112     struct client *clients;
113     int requestid; 
114     char query[1024];
115     NMEM nmem;          // Nmem for each operation (i.e. search)
116     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
117     int num_termlists;
118     struct named_termlist termlists[SESSION_MAX_TERMLISTS];
119     struct relevance *relevance;
120     struct reclist *reclist;
121     struct {
122         void *data;
123         session_watchfun fun;
124     } watchlist[SESSION_WATCH_MAX + 1];
125     int expected_maxrecs;
126     int total_hits;
127     int total_records;
128 };
129
130 struct statistics {
131     int num_clients;
132     int num_no_connection;
133     int num_connecting;
134     int num_initializing;
135     int num_searching;
136     int num_presenting;
137     int num_idle;
138     int num_failed;
139     int num_error;
140     int num_hits;
141     int num_records;
142 };
143
144 struct hitsbytarget {
145     char id[256];
146     int hits;
147     int diagnostic;
148     int records;
149     char* state;
150     int connected;
151 };
152
153 struct parameters {
154     int dump_records;
155     int timeout;                /* operations timeout, in seconds */
156     char implementationId[128];
157     char implementationName[128];
158     char implementationVersion[128];
159     int target_timeout; // seconds
160     int session_timeout;
161     int toget;
162     int chunk;
163     CCL_bibset ccl_filter;
164     yaz_marc_t yaz_marc;
165     ODR odr_out;
166     ODR odr_in;
167 };
168
169 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
170 int select_targets(struct session *se);
171 struct session *new_session();
172 void destroy_session(struct session *s);
173 int load_targets(struct session *s, const char *fn);
174 void statistics(struct session *s, struct statistics *stat);
175 char *search(struct session *s, char *query);
176 struct record **show(struct session *s, int start, int *num, int *total, int *sumhits, NMEM nmem_show);
177 struct termlist_score **termlist(struct session *s, const char *name, int *num);
178 void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);
179
180 #endif
181
182 /*
183  * Local variables:
184  * c-basic-offset: 4
185  * indent-tabs-mode: nil
186  * End:
187  * vim: shiftwidth=4 tabstop=8 expandtab
188  */