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