Only warn about unexpected elements once per session.
[pazpar2-moved-to-github.git] / src / pazpar2.h
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2008 Index Data
3
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #ifndef PAZPAR2_H
21 #define PAZPAR2_H
22
23
24 #include <libxslt/xsltutils.h>
25 #include <libxslt/transform.h>
26
27 #include <yaz/comstack.h>
28 #include <yaz/pquery.h>
29 #include <yaz/ccl.h>
30 #include <yaz/yaz-ccl.h>
31
32 #include "termlists.h"
33 #include "relevance.h"
34 #include "reclists.h"
35 #include "eventl.h"
36 #include "pazpar2_config.h"
37 #include "parameters.h"
38 #include "http.h"
39
40 struct record;
41 struct client;
42
43
44 enum pazpar2_error_code {
45     PAZPAR2_NO_ERROR = 0,
46
47     PAZPAR2_NO_SESSION,
48     PAZPAR2_MISSING_PARAMETER,
49     PAZPAR2_MALFORMED_PARAMETER_VALUE,
50     PAZPAR2_MALFORMED_PARAMETER_ENCODING,
51     PAZPAR2_MALFORMED_SETTING,
52     PAZPAR2_HITCOUNTS_FAILED,
53     PAZPAR2_RECORD_MISSING,
54     PAZPAR2_NO_TARGETS,
55     PAZPAR2_CONFIG_TARGET,
56     PAZPAR2_RECORD_FAIL,
57     PAZPAR2_NOT_IMPLEMENTED,
58
59     PAZPAR2_LAST_ERROR
60 };
61
62 // Represents a (virtual) database on a host
63 struct database {
64     struct host *host;
65     char *url;
66     char **databases;
67     int errors;
68     struct zr_explain *explain;
69     struct setting **settings;
70     struct database *next;
71 };
72
73 struct database_criterion_value {
74     char *value;
75     struct database_criterion_value *next;
76 };
77
78 struct database_criterion {
79     char *name;
80     struct database_criterion_value *values;
81     struct database_criterion *next;
82 };
83
84 // Normalization filter. Turns incoming record into internal representation
85 // Simple sequence of stylesheets run in series.
86 struct database_retrievalmap {
87     xsltStylesheet *stylesheet;
88     struct database_retrievalmap *next;
89 };
90
91 // Represents a database as viewed from one session, possibly with settings overriden
92 // for that session
93 struct session_database
94 {
95     struct database *database;
96     struct setting **settings;
97     yaz_marc_t yaz_marc;
98     struct database_retrievalmap *map;
99     struct session_database *next;
100 };
101
102
103
104 #define SESSION_WATCH_SHOW      0
105 #define SESSION_WATCH_RECORD    1
106 #define SESSION_WATCH_MAX       1
107
108 #define SESSION_MAX_TERMLISTS 10
109
110 typedef void (*session_watchfun)(void *data);
111
112 struct named_termlist
113 {
114     char *name;
115     struct termlist *termlist;
116 };
117
118 struct session_watchentry {
119     void *data;
120     http_channel_observer_t obs;
121     session_watchfun fun;
122 };
123
124 // End-user session
125 struct session {
126     struct session_database *databases;  // All databases, settings overriden
127     struct client *clients;              // Clients connected for current search
128     int requestid; 
129     NMEM session_nmem;  // Nmem for session-permanent storage
130     NMEM nmem;          // Nmem for each operation (i.e. search, result set, etc)
131     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
132     int num_termlists;
133     struct named_termlist termlists[SESSION_MAX_TERMLISTS];
134     struct relevance *relevance;
135     struct reclist *reclist;
136     struct session_watchentry watchlist[SESSION_WATCH_MAX + 1];
137     int expected_maxrecs;
138     int total_hits;
139     int total_records;
140     int total_merged;
141     int number_of_warnings_unknown_elements;
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;
160     const char *name;
161     int hits;
162     int diagnostic;
163     int records;
164     const char *state;
165     int connected;
166 };
167
168 struct hitsbytarget *hitsbytarget(struct session *s, int *count, NMEM nmem);
169 int select_targets(struct session *se, struct database_criterion *crit);
170 struct session *new_session(NMEM nmem);
171 void destroy_session(struct session *s);
172 void session_init_databases(struct session *s);
173 int load_targets(struct session *s, const char *fn);
174 void statistics(struct session *s, struct statistics *stat);
175 enum pazpar2_error_code search(struct session *s, char *query, 
176                                char *filter, const char **addinfo);
177 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
178         int *num, int *total, int *sumhits, NMEM nmem_show);
179 struct record_cluster *show_single(struct session *s, const char *id);
180 struct termlist_score **termlist(struct session *s, const char *name, int *num);
181 int session_set_watch(struct session *s, int what, session_watchfun fun, void *data, struct http_channel *c);
182 int session_active_clients(struct session *s);
183 void session_apply_setting(struct session *se, char *dbname, char *setting, char *value);
184 const char *session_setting_oneval(struct session_database *db, int offset);
185
186 int start_http_listener(void);
187 void start_proxy(void);
188
189 void pazpar2_add_channel(IOCHAN c);
190 void pazpar2_event_loop(void);
191
192 int host_getaddrinfo(struct host *host);
193
194 xmlDoc *normalize_record(struct session_database *sdb, struct session *se,
195         Z_External *rec);
196 xmlDoc *record_to_xml(struct session_database *sdb, Z_External *rec);
197
198 struct record *ingest_record(struct client *cl, Z_External *rec,
199                              int record_no);
200 void session_alert_watch(struct session *s, int what);
201 void pull_terms(NMEM nmem, struct ccl_rpn_node *n, char **termlist, int *num);
202
203 #endif
204
205 /*
206  * Local variables:
207  * c-basic-offset: 4
208  * indent-tabs-mode: nil
209  * End:
210  * vim: shiftwidth=4 tabstop=8 expandtab
211  */