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