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