Refactor stuff from logic.c: connection stuff in connection.[ch],
[pazpar2-moved-to-github.git] / src / pazpar2.h
1 /* $Id: pazpar2.h,v 1.34 2007-04-23 21:05:23 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 struct connection;
47
48 // Represents a (virtual) database on a host
49 struct database {
50     struct host *host;
51     char *url;
52     char **databases;
53     int errors;
54     struct zr_explain *explain;
55     struct setting **settings;
56     struct database *next;
57 };
58
59 struct database_criterion_value {
60     char *value;
61     struct database_criterion_value *next;
62 };
63
64 struct database_criterion {
65     char *name;
66     struct database_criterion_value *values;
67     struct database_criterion *next;
68 };
69
70 // Normalization filter. Turns incoming record into internal representation
71 // Simple sequence of stylesheets run in series.
72 struct database_retrievalmap {
73     xsltStylesheet *stylesheet;
74     struct database_retrievalmap *next;
75 };
76
77 // Represents a database as viewed from one session, possibly with settings overriden
78 // for that session
79 struct session_database
80 {
81     struct database *database;
82     struct setting **settings;
83     yaz_marc_t yaz_marc;
84     struct database_retrievalmap *map;
85     struct session_database *next;
86 };
87
88 #define SESSION_WATCH_RECORDS   0
89 #define SESSION_WATCH_MAX       0
90
91 #define SESSION_MAX_TERMLISTS 10
92
93 typedef void (*session_watchfun)(void *data);
94
95 struct named_termlist
96 {
97     char *name;
98     struct termlist *termlist;
99 };
100
101 // End-user session
102 struct session {
103     struct session_database *databases;  // All databases, settings overriden
104     struct client *clients;              // Clients connected for current search
105     int requestid; 
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 {
114         void *data;
115         session_watchfun fun;
116     } watchlist[SESSION_WATCH_MAX + 1];
117     int expected_maxrecs;
118     int total_hits;
119     int total_records;
120     int total_merged;
121 };
122
123 struct statistics {
124     int num_clients;
125     int num_no_connection;
126     int num_connecting;
127     int num_initializing;
128     int num_searching;
129     int num_presenting;
130     int num_idle;
131     int num_failed;
132     int num_error;
133     int num_hits;
134     int num_records;
135 };
136
137 struct hitsbytarget {
138     char *id;
139     char *name;
140     int hits;
141     int diagnostic;
142     int records;
143     const char *state;
144     int connected;
145 };
146
147 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
148 int select_targets(struct session *se, struct database_criterion *crit);
149 struct session *new_session(NMEM nmem);
150 void destroy_session(struct session *s);
151 int load_targets(struct session *s, const char *fn);
152 void statistics(struct session *s, struct statistics *stat);
153 char *search(struct session *s, char *query, char *filter);
154 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
155         int *num, int *total, int *sumhits, NMEM nmem_show);
156 struct record_cluster *show_single(struct session *s, int id);
157 struct termlist_score **termlist(struct session *s, const char *name, int *num);
158 void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);
159 int session_active_clients(struct session *s);
160 void session_apply_setting(struct session *se, char *dbname, char *setting, char *value);
161 char *session_setting_oneval(struct session_database *db, int offset);
162
163 void start_http_listener(void);
164 void start_proxy(void);
165 void start_zproxy(void);
166
167 void pazpar2_add_channel(IOCHAN c);
168 void pazpar2_event_loop(void);
169
170 int host_getaddrinfo(struct host *host);
171
172 xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec);
173 void connection_destroy(struct connection *co);
174
175 struct record *ingest_record(struct client *cl, Z_External *rec,
176                              int record_no);
177 void session_alert_watch(struct session *s, int what);
178 void connection_release(struct connection *co);
179 void pull_terms(NMEM nmem, struct ccl_rpn_node *n, char **termlist, int *num);
180
181 #endif
182
183 /*
184  * Local variables:
185  * c-basic-offset: 4
186  * indent-tabs-mode: nil
187  * End:
188  * vim: shiftwidth=4 tabstop=8 expandtab
189  */