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