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