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