removed Z39.50 Proxy functionality from parameters global overrides and moved into...
[pazpar2-moved-to-github.git] / src / pazpar2.h
1 /* $Id: pazpar2.h,v 1.37 2007-06-06 11:49:48 marc 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     pp2_charset_t pct;
80     struct database *database;
81     struct setting **settings;
82     yaz_marc_t yaz_marc;
83     struct database_retrievalmap *map;
84     struct session_database *next;
85 };
86
87 #define SESSION_WATCH_RECORDS   0
88 #define SESSION_WATCH_MAX       0
89
90 #define SESSION_MAX_TERMLISTS 10
91
92 typedef void (*session_watchfun)(void *data);
93
94 struct named_termlist
95 {
96     char *name;
97     struct termlist *termlist;
98 };
99
100 // End-user session
101 struct session {
102     struct session_database *databases;  // All databases, settings overriden
103     struct client *clients;              // Clients connected for current search
104     int requestid; 
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 {
113         void *data;
114         session_watchfun fun;
115     } watchlist[SESSION_WATCH_MAX + 1];
116     int expected_maxrecs;
117     int total_hits;
118     int total_records;
119     int total_merged;
120 };
121
122 struct statistics {
123     int num_clients;
124     int num_no_connection;
125     int num_connecting;
126     int num_initializing;
127     int num_searching;
128     int num_presenting;
129     int num_idle;
130     int num_failed;
131     int num_error;
132     int num_hits;
133     int num_records;
134 };
135
136 struct hitsbytarget {
137     char *id;
138     char *name;
139     int hits;
140     int diagnostic;
141     int records;
142     const char *state;
143     int connected;
144 };
145
146 struct hitsbytarget *hitsbytarget(struct session *s, int *count);
147 int select_targets(struct session *se, struct database_criterion *crit);
148 struct session *new_session(NMEM nmem);
149 void destroy_session(struct session *s);
150 int load_targets(struct session *s, const char *fn);
151 void statistics(struct session *s, struct statistics *stat);
152 char *search(struct session *s, char *query, char *filter);
153 struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, int start,
154         int *num, int *total, int *sumhits, NMEM nmem_show);
155 struct record_cluster *show_single(struct session *s, int id);
156 struct termlist_score **termlist(struct session *s, const char *name, int *num);
157 void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);
158 int session_active_clients(struct session *s);
159 void session_apply_setting(struct session *se, char *dbname, char *setting, char *value);
160 char *session_setting_oneval(struct session_database *db, int offset);
161
162 void start_http_listener(void);
163 void start_proxy(void);
164 //void start_zproxy(void);
165
166 void pazpar2_add_channel(IOCHAN c);
167 void pazpar2_event_loop(void);
168
169 int host_getaddrinfo(struct host *host);
170
171 xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec);
172
173 struct record *ingest_record(struct client *cl, Z_External *rec,
174                              int record_no);
175 void session_alert_watch(struct session *s, int what);
176 void pull_terms(NMEM nmem, struct ccl_rpn_node *n, char **termlist, int *num);
177
178 #endif
179
180 /*
181  * Local variables:
182  * c-basic-offset: 4
183  * indent-tabs-mode: nil
184  * End:
185  * vim: shiftwidth=4 tabstop=8 expandtab
186  */