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