Highly experimental boss-worker socket handler
[pazpar2-moved-to-github.git] / src / pazpar2.h
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2010 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     PAZPAR2_NO_SERVICE,
52
53     PAZPAR2_LAST_ERROR
54 };
55
56 struct host;
57 // Represents a (virtual) database on a host
58 struct database {
59     struct host *host;
60     char *url;
61     char **databases;
62     int errors;
63     struct zr_explain *explain;
64     int num_settings;
65     struct setting **settings;
66     struct database *next;
67 };
68
69
70 // Represents a database as viewed from one session, possibly with settings overriden
71 // for that session
72 struct session_database
73 {
74     struct database *database;
75     int num_settings;
76     struct setting **settings;
77     normalize_record_t map;
78     struct session_database *next;
79 };
80
81 #define SESSION_WATCH_SHOW      0
82 #define SESSION_WATCH_RECORD    1
83 #define SESSION_WATCH_MAX       1
84
85 #define SESSION_MAX_TERMLISTS 10
86
87 typedef void (*session_watchfun)(void *data);
88
89 struct named_termlist
90 {
91     char *name;
92     struct termlist *termlist;
93 };
94
95 struct session_watchentry {
96     void *data;
97     http_channel_observer_t obs;
98     session_watchfun fun;
99 };
100
101 // End-user session
102 struct session {
103     struct conf_service *service; /* service in use for this session */
104     struct session_database *databases;  // All databases, settings overriden
105     struct client *clients;              // Clients connected for current search
106     NMEM session_nmem;  // Nmem for session-permanent storage
107     NMEM nmem;          // Nmem for each operation (i.e. search, result set, etc)
108     WRBUF wrbuf;        // Wrbuf for scratch(i.e. search)
109     int num_termlists;
110     struct named_termlist termlists[SESSION_MAX_TERMLISTS];
111     struct relevance *relevance;
112     struct reclist *reclist;
113     struct session_watchentry watchlist[SESSION_WATCH_MAX + 1];
114     Odr_int total_hits;
115     int total_records;
116     int total_merged;
117     int number_of_warnings_unknown_elements;
118     int number_of_warnings_unknown_metadata;
119     normalize_cache_t normalize_cache;
120 };
121
122 struct statistics {
123     int num_clients;
124     int num_no_connection;
125     int num_connecting;
126     int num_working;
127     int num_idle;
128     int num_failed;
129     int num_error;
130     Odr_int num_hits;
131     int num_records;
132 };
133
134 struct hitsbytarget {
135     char *id;
136     const char *name;
137     Odr_int hits;
138     int diagnostic;
139     int records;
140     const char *state;
141     int connected;
142     WRBUF settings_xml;
143 };
144
145 struct hitsbytarget *hitsbytarget(struct session *s, int *count, NMEM nmem);
146 struct session *new_session(NMEM nmem, struct conf_service *service);
147 void destroy_session(struct session *s);
148 void session_init_databases(struct session *s);
149 int load_targets(struct session *s, const char *fn);
150 void statistics(struct session *s, struct statistics *stat);
151 enum pazpar2_error_code search(struct session *s, const char *query,
152                                const char *startrecs, const char *maxrecs,
153                                const char *filter, const char **addinfo);
154 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
155         int *num, int *total, Odr_int *sumhits, NMEM nmem_show);
156 struct record_cluster *show_single(struct session *s, const char *id,
157                                    struct record_cluster **prev_r,
158                                    struct record_cluster **next_r);
159 struct termlist_score **termlist(struct session *s, const char *name, int *num);
160 int session_set_watch(struct session *s, int what, session_watchfun fun, void *data, struct http_channel *c);
161 int session_active_clients(struct session *s);
162 void session_apply_setting(struct session *se, char *dbname, char *setting, char *value);
163 const char *session_setting_oneval(struct session_database *db, int offset);
164
165 void pazpar2_add_channel(IOCHAN c);
166 void pazpar2_event_loop(void);
167
168 int host_getaddrinfo(struct host *host);
169
170 struct record *ingest_record(struct client *cl, const char *rec,
171                              int record_no);
172 void session_alert_watch(struct session *s, int what);
173 void pull_terms(NMEM nmem, struct ccl_rpn_node *n, char **termlist, int *num);
174
175 #endif
176
177 /*
178  * Local variables:
179  * c-basic-offset: 4
180  * c-file-style: "Stroustrup"
181  * indent-tabs-mode: nil
182  * End:
183  * vim: shiftwidth=4 tabstop=8 expandtab
184  */
185