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