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