New host list manager: database_hosts_t
[pazpar2-moved-to-github.git] / src / pazpar2_config.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_CONFIG_H
21 #define PAZPAR2_CONFIG_H
22
23 #include "normalize_cache.h"
24
25 #include <yaz/nmem.h>
26 #include <yaz/mutex.h>
27 #include "charsets.h"
28 #include "http.h"
29 #include "database.h"
30
31 enum conf_metadata_type {
32     Metadata_type_generic,    // Generic text field
33     Metadata_type_number,     // A number
34     Metadata_type_year,        // A number
35     Metadata_type_date        // A number
36 };
37
38 enum conf_metadata_merge {
39     Metadata_merge_no,        // Don't merge
40     Metadata_merge_unique,    // Include unique elements in merged block
41     Metadata_merge_longest,   // Include the longest (strlen) value
42     Metadata_merge_range,     // Store value as a range of lowest-highest
43     Metadata_merge_all        // Just include all elements found
44 };
45
46 enum conf_sortkey_type {
47     Metadata_sortkey_relevance,
48     Metadata_sortkey_numeric,       // Standard numerical sorting
49     Metadata_sortkey_skiparticle,   // Skip leading article when sorting
50     Metadata_sortkey_string         // Flat string
51 };
52
53 // This controls the ability to insert 'static' values from settings into retrieval recs
54 enum conf_setting_type {
55     Metadata_setting_no,
56     Metadata_setting_postproc,      // Insert setting value into normalized record
57     Metadata_setting_parameter      // Expose value to normalization stylesheets
58 };
59
60 enum conf_metadata_mergekey {
61     Metadata_mergekey_no,
62     Metadata_mergekey_optional,
63     Metadata_mergekey_required
64 };
65
66 // Describes known metadata elements and how they are to be manipulated
67 // An array of these structure provides a 'map' against which
68 // discovered metadata elements are matched. It also governs storage,
69 // to minimize number of cycles needed at various tages of processing
70 struct conf_metadata 
71 {
72     char *name;  // The field name. Output by normalization stylesheet
73     int brief;   // Is this element to be returned in the brief format?
74     int termlist;// Is this field to be treated as a termlist for browsing?
75     int rank;    // Rank factor. 0 means don't use this field for ranking, 
76                  // 1 is default
77                  // values >1  give additional significance to a field
78     int sortkey_offset; // -1 if it's not a sortkey, otherwise index
79                         // into service/record_cluster->sortkey array
80     enum conf_metadata_type type;
81     enum conf_metadata_merge merge;
82     enum conf_setting_type setting; // Value is to be taken from session/db settings?
83     enum conf_metadata_mergekey mergekey;
84 };
85
86
87
88 // Controls sorting
89 struct conf_sortkey
90 {
91     char *name;
92     enum conf_sortkey_type type;
93 };
94
95 struct conf_server;
96
97 // It is conceivable that there will eventually be several 'services'
98 // offered from one server, with separate configuration -- possibly
99 // more than one services associated with the same port. For now,
100 // however, only a single service is possible.
101 struct conf_service
102 {
103     YAZ_MUTEX mutex;
104     int num_metadata;
105     struct conf_metadata *metadata;
106     int num_sortkeys;
107     struct conf_sortkey *sortkeys;
108     struct setting_dictionary *dictionary;
109     struct conf_service *next;
110     char *id;
111     char *settings;
112     NMEM nmem;
113     int session_timeout;
114     int z3950_session_timeout;
115     int z3950_operation_timeout;
116
117     int ref_count;
118     /* duplicated from conf_server */
119     pp2_charset_t relevance_pct;
120     pp2_charset_t sort_pct;
121     pp2_charset_t mergekey_pct;
122
123     struct database *databases;
124     struct conf_targetprofiles *targetprofiles;
125     struct conf_server *server;
126 };
127
128 int conf_service_metadata_field_id(struct conf_service *service, const char * name);
129
130 int conf_service_sortkey_field_id(struct conf_service *service, const char * name);
131
132 struct conf_server
133 {
134     char *host;
135     int port;
136     char *proxy_host;
137     int proxy_port;
138     char *myurl;
139     char *server_settings;
140     char *server_id;
141
142     pp2_charset_t relevance_pct;
143     pp2_charset_t sort_pct;
144     pp2_charset_t mergekey_pct;
145     struct conf_service *service;
146     struct conf_server *next;
147     struct conf_config *config;
148     http_server_t http_server;
149     iochan_man_t iochan_man;
150     database_hosts_t database_hosts;
151 };
152
153 struct conf_targetprofiles
154 {
155     enum {
156         Targetprofiles_local
157     } type;
158     char *src;
159 };
160
161 struct conf_config *config_create(const char *fname, int verbose);
162 void config_destroy(struct conf_config *config);
163 void config_process_events(struct conf_config *config);
164
165 struct conf_service *locate_service(struct conf_server *server,
166                                     const char *service_id);
167
168 struct conf_service *service_create(struct conf_server *server,
169                                     xmlNode *node);
170 void service_incref(struct conf_service *service);
171 void service_destroy(struct conf_service *service);
172
173 int config_start_listeners(struct conf_config *conf,
174                            const char *listener_override);
175
176 void config_stop_listeners(struct conf_config *conf);
177
178 WRBUF conf_get_fname(struct conf_service *service, const char *fname);
179
180 #endif
181
182 /*
183  * Local variables:
184  * c-basic-offset: 4
185  * c-file-style: "Stroustrup"
186  * indent-tabs-mode: nil
187  * End:
188  * vim: shiftwidth=4 tabstop=8 expandtab
189  */
190