Extended command 'record' so that XML representation of original record
[pazpar2-moved-to-github.git] / src / pazpar2.h
1 /* $Id: pazpar2.h,v 1.41 2007-06-15 06:45:39 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
43 struct record;
44 struct client;
45
46
47 enum pazpar2_error_code {
48     PAZPAR2_NO_ERROR = 0,
49
50     PAZPAR2_NO_SESSION,
51     PAZPAR2_MISSING_PARAMETER,
52     PAZPAR2_MALFORMED_PARAMETER_VALUE,
53     PAZPAR2_MALFORMED_PARAMETER_ENCODING,
54     PAZPAR2_MALFORMED_SETTING,
55     PAZPAR2_HITCOUNTS_FAILED,
56     PAZPAR2_RECORD_MISSING,
57     PAZPAR2_NO_TARGETS,
58     PAZPAR2_CONFIG_TARGET,
59     PAZPAR2_RECORD_FAIL,
60     PAZPAR2_NOT_IMPLEMENTED,
61
62     PAZPAR2_LAST_ERROR
63 };
64
65 // Represents a (virtual) database on a host
66 struct database {
67     struct host *host;
68     char *url;
69     char **databases;
70     int errors;
71     struct zr_explain *explain;
72     struct setting **settings;
73     struct database *next;
74 };
75
76 struct database_criterion_value {
77     char *value;
78     struct database_criterion_value *next;
79 };
80
81 struct database_criterion {
82     char *name;
83     struct database_criterion_value *values;
84     struct database_criterion *next;
85 };
86
87 // Normalization filter. Turns incoming record into internal representation
88 // Simple sequence of stylesheets run in series.
89 struct database_retrievalmap {
90     xsltStylesheet *stylesheet;
91     struct database_retrievalmap *next;
92 };
93
94 // Represents a database as viewed from one session, possibly with settings overriden
95 // for that session
96 struct session_database
97 {
98     pp2_charset_t pct;
99     struct database *database;
100     struct setting **settings;
101     yaz_marc_t yaz_marc;
102     struct database_retrievalmap *map;
103     struct session_database *next;
104 };
105
106 #define SESSION_WATCH_RECORDS   0
107 #define SESSION_WATCH_MAX       0
108
109 #define SESSION_MAX_TERMLISTS 10
110
111 typedef void (*session_watchfun)(void *data);
112
113 struct named_termlist
114 {
115     char *name;
116     struct termlist *termlist;
117 };
118
119 // End-user session
120 struct session {
121     struct session_database *databases;  // All databases, settings overriden
122     struct client *clients;              // Clients connected for current search
123     int requestid; 
124     NMEM session_nmem;  // Nmem for session-permanent storage
125     NMEM nmem;          // Nmem for each operation (i.e. search, result set, etc)
126     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
127     int num_termlists;
128     struct named_termlist termlists[SESSION_MAX_TERMLISTS];
129     struct relevance *relevance;
130     struct reclist *reclist;
131     struct {
132         void *data;
133         session_watchfun fun;
134     } watchlist[SESSION_WATCH_MAX + 1];
135     int expected_maxrecs;
136     int total_hits;
137     int total_records;
138     int total_merged;
139 };
140
141 struct statistics {
142     int num_clients;
143     int num_no_connection;
144     int num_connecting;
145     int num_initializing;
146     int num_searching;
147     int num_presenting;
148     int num_idle;
149     int num_failed;
150     int num_error;
151     int num_hits;
152     int num_records;
153 };
154
155 struct hitsbytarget {
156     char *id;
157     char *name;
158     int hits;
159     int diagnostic;
160     int records;
161     const char *state;
162     int connected;
163 };
164
165 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
166 int select_targets(struct session *se, struct database_criterion *crit);
167 struct session *new_session(NMEM nmem);
168 void destroy_session(struct session *s);
169 int load_targets(struct session *s, const char *fn);
170 void statistics(struct session *s, struct statistics *stat);
171 enum pazpar2_error_code search(struct session *s, char *query, 
172                                char *filter, const char **addinfo);
173 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
174         int *num, int *total, int *sumhits, NMEM nmem_show);
175 struct record_cluster *show_single(struct session *s, int id);
176 struct termlist_score **termlist(struct session *s, const char *name, int *num);
177 void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);
178 int session_active_clients(struct session *s);
179 void session_apply_setting(struct session *se, char *dbname, char *setting, char *value);
180 char *session_setting_oneval(struct session_database *db, int offset);
181
182 void start_http_listener(void);
183 void start_proxy(void);
184 //void start_zproxy(void);
185
186 void pazpar2_add_channel(IOCHAN c);
187 void pazpar2_event_loop(void);
188
189 int host_getaddrinfo(struct host *host);
190
191 xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec);
192 xmlDoc *record_to_xml(struct session_database *sdb, Z_External *rec);
193
194 struct record *ingest_record(struct client *cl, Z_External *rec,
195                              int record_no);
196 void session_alert_watch(struct session *s, int what);
197 void pull_terms(NMEM nmem, struct ccl_rpn_node *n, char **termlist, int *num);
198
199 int pazpar2_process(int debug,
200                     void (*work)(void *data), void *data,
201                     const char *pidfile, const char *uid);
202
203
204 #endif
205
206 /*
207  * Local variables:
208  * c-basic-offset: 4
209  * indent-tabs-mode: nil
210  * End:
211  * vim: shiftwidth=4 tabstop=8 expandtab
212  */