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