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