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