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