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