pazpar2  1.13.0
session.h
Go to the documentation of this file.
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_SESSION_H
21 #define PAZPAR2_SESSION_H
22 
23 #include <yaz/comstack.h>
24 #include <yaz/pquery.h>
25 #include <yaz/ccl.h>
26 #include <yaz/yaz-ccl.h>
27 
28 #include "facet_limit.h"
29 #include "relevance.h"
30 #include "reclists.h"
31 
32 struct record;
33 struct client;
34 
35 
38 
52 
54 };
55 
56 // Represents a database as viewed from one session, possibly with settings overriden
57 // for that session
59 {
60  struct database *database;
62  struct setting **settings;
65 };
66 
67 #define SESSION_WATCH_SHOW 0
68 #define SESSION_WATCH_RECORD 1
69 #define SESSION_WATCH_SHOW_PREF 2
70 #define SESSION_WATCH_TERMLIST 3
71 #define SESSION_WATCH_BYTARGET 4
72 #define SESSION_WATCH_MAX 4
73 
74 typedef void (*session_watchfun)(void *data);
75 
77 {
78  char *name;
79  struct termlist *termlist;
81 };
82 
84  void *data;
87 };
88 
89 struct client_list;
90 
91 // End-user session
92 struct session {
93  struct conf_service *service; /* service in use for this session */
94  struct session_database *databases; // All databases, settings overriden
95  struct client_list *clients_active; // Clients connected for current search
96  struct client_list *clients_cached; // Clients in cache
97  NMEM session_nmem; // Nmem for session-permanent storage
98  NMEM nmem; // Nmem for each operation (i.e. search, result set, etc)
101  struct reclist *reclist;
102  char *mergekey;
103  char *rank;
104  struct session_watchentry watchlist[SESSION_WATCH_MAX + 1];
110  YAZ_MUTEX session_mutex;
111  unsigned session_id;
118 };
119 
120 struct statistics {
125  int num_idle;
128  Odr_int num_hits;
130 };
131 
132 struct hitsbytarget {
133  const char *id;
134  const char *name;
135  Odr_int hits;
136  Odr_int approximation;
138  const char *message;
139  const char *addinfo;
140  int records;
141  int filtered;
142  const char *state;
146  const char *query_type;
147  const char *query_data;
148 };
149 
150 struct hitsbytarget *get_hitsbytarget(struct session *s, int *count, NMEM nmem);
151 struct session *session_create(NMEM nmem, struct conf_service *service,
152  unsigned session_id);
153 void session_destroy(struct session *s);
154 void session_init_databases(struct session *s);
155 void statistics(struct session *s, struct statistics *stat);
156 
157 int sessions_get_count(void);
158 
159 void session_sort(struct session *se, struct reclist_sortparms *sp,
160  const char *mergekey, const char *rank);
161 
162 enum pazpar2_error_code session_search(struct session *s, const char *query,
163  const char *startrecs,
164  const char *maxrecs,
165  const char *filter, const char *limit,
166  const char **addinfo,
167  const char **addinfo2,
168  struct reclist_sortparms *sort_parm,
169  const char *mergekey,
170  const char *rank);
171 struct record_cluster **show_range_start(struct session *s,
172  struct reclist_sortparms *sp,
173  int start,
174  int *num, int *total,
175  Odr_int *sumhits,
176  Odr_int *approximation,
177  void (*ready)(void *data),
178  struct http_channel *chan);
179 int session_fetch_more(struct session *s);
180 void show_range_stop(struct session *s, struct record_cluster **recs);
181 
182 struct record_cluster *show_single_start(struct session *s, const char *id,
183  struct record_cluster **prev_r,
184  struct record_cluster **next_r);
185 void show_single_stop(struct session *s, struct record_cluster *rec);
186 int session_set_watch(struct session *s, int what, session_watchfun fun, void *data, struct http_channel *c);
187 int session_active_clients(struct session *s);
189 void session_apply_setting(struct session *se, const char *dbname,
190  const char *setting, const char *value);
191 const char *session_setting_oneval(struct session_database *db, int offset);
192 void session_stop(struct session *se);
193 
194 int ingest_record(struct client *cl, const char *rec, int record_no, NMEM nmem);
195 int ingest_xml_record(struct client *cl, xmlDoc *xdoc,
196  int record_no, NMEM nmem, int cached_copy);
197 void session_alert_watch(struct session *s, int what);
198 void add_facet(struct session *s, const char *type, const char *value, int count, struct client *cl);
199 
200 int session_check_cluster_limit(struct session *se, struct record_cluster *rec);
201 
202 void perform_termlist(struct http_channel *c, struct session *se, const char *name, int num, int version);
203 
204 const char *session_lookup_id_facet(struct session *s, struct client *cl,
205  const char *type, const char *term);
206 
207 void session_log(struct session *s, int level, const char *fmt, ...)
208 #ifdef __GNUC__
209  __attribute__ ((format (printf, 3, 4)))
210 #endif
211  ;
212 #endif
213 
214 /*
215  * Local variables:
216  * c-basic-offset: 4
217  * c-file-style: "Stroustrup"
218  * indent-tabs-mode: nil
219  * End:
220  * vim: shiftwidth=4 tabstop=8 expandtab
221  */
222 
struct client_list * clients_active
Definition: session.h:95
struct facet_id * facet_id_list
Definition: session.h:117
int connected
Definition: session.h:143
int force_position
Definition: session.h:115
struct named_termlist * next
Definition: session.h:80
Definition: record.h:60
Odr_int num_hits
Definition: session.h:128
int session_fetch_more(struct session *s)
Definition: session.c:1384
void session_sort(struct session *se, struct reclist_sortparms *sp, const char *mergekey, const char *rank)
Definition: session.c:685
const char * name
Definition: session.h:134
const char * query_type
Definition: session.h:146
int num_connecting
Definition: session.h:123
int num_failed
Definition: session.h:126
struct conf_service * service
Definition: session.h:93
const char * id
Definition: session.h:133
struct record_cluster ** show_range_start(struct session *s, struct reclist_sortparms *sp, int start, int *num, int *total, Odr_int *sumhits, Odr_int *approximation, void(*ready)(void *data), struct http_channel *chan)
Definition: session.c:1432
void session_destroy(struct session *s)
Definition: session.c:1053
pazpar2_error_code
Definition: session.h:36
NMEM session_nmem
Definition: session.h:97
#define SESSION_WATCH_MAX
Definition: session.h:72
int sessions_get_count(void)
Definition: session.c:116
int records
Definition: session.h:140
void(* fun)(struct http_channel *c)
struct hitsbytarget * get_hitsbytarget(struct session *s, int *count, NMEM nmem)
Definition: session.c:1184
void show_range_stop(struct session *s, struct record_cluster **recs)
Definition: session.c:1543
void add_facet(struct session *s, const char *type, const char *value, int count, struct client *cl)
Definition: session.c:254
struct record_cluster * show_single_start(struct session *s, const char *id, struct record_cluster **prev_r, struct record_cluster **next_r)
Definition: session.c:1351
char * name
int clients_starting
Definition: session.h:114
int session_is_preferred_clients_ready(struct session *s)
Definition: session.c:649
char * mergekey
Definition: session.h:102
void session_alert_watch(struct session *s, int what)
Definition: session.c:521
int num_working
Definition: session.h:124
int num_error
Definition: session.h:127
int num_clients
Definition: session.h:121
Represents client state for a connection to one search target.
Definition: client.c:99
void session_stop(struct session *se)
Definition: session.c:791
void session_apply_setting(struct session *se, const char *dbname, const char *setting, const char *value)
Definition: session.c:1018
int total_records
Definition: session.h:105
struct session_database * next
Definition: session.h:64
struct reclist * reclist
Definition: session.h:101
session_watchfun fun
Definition: session.h:86
void session_init_databases(struct session *s)
Definition: session.c:987
int total_merged
Definition: session.h:106
const char * message
Definition: session.h:138
int num_idle
Definition: session.h:125
struct database * database
Definition: session.h:60
const char * session_setting_oneval(struct session_database *db, int offset)
Definition: session.c:433
int session_check_cluster_limit(struct session *se, struct record_cluster *rec)
Definition: session.c:2035
int num_records
Definition: session.h:129
Odr_int approximation
Definition: session.h:136
struct client_list * clients_cached
Definition: session.h:96
NMEM nmem
Definition: session.h:98
struct reclist_sortparms * sorted_results
Definition: session.h:116
enum pazpar2_error_code session_search(struct session *s, const char *query, const char *startrecs, const char *maxrecs, const char *filter, const char *limit, const char **addinfo, const char **addinfo2, struct reclist_sortparms *sort_parm, const char *mergekey, const char *rank)
Definition: session.c:818
char * suggestions_xml
Definition: session.h:145
struct session * session_create(NMEM nmem, struct conf_service *service, unsigned session_id)
Definition: session.c:1093
const char * session_lookup_id_facet(struct session *s, struct client *cl, const char *type, const char *term)
Definition: session.c:234
http_channel_observer_t obs
Definition: session.h:85
normalize_record_t map
Definition: session.h:63
char * settings_xml
Definition: session.h:144
Odr_int hits
Definition: session.h:135
struct setting ** settings
Definition: session.h:62
int number_of_warnings_unknown_metadata
Definition: session.h:108
int session_active_clients(struct session *s)
Definition: session.c:637
unsigned session_id
Definition: session.h:111
char * name
Definition: session.h:78
const char * query_data
Definition: session.h:147
void show_single_stop(struct session *s, struct record_cluster *rec)
Definition: session.c:1378
YAZ_MUTEX session_mutex
Definition: session.h:110
void session_log(struct session *s, int level, const char *fmt,...)
Definition: session.c:2509
int num_no_connection
Definition: session.h:122
facet_limits_t facet_limits
Definition: session.h:113
int session_set_watch(struct session *s, int what, session_watchfun fun, void *data, struct http_channel *c)
Definition: session.c:500
normalize_cache_t normalize_cache
Definition: session.h:109
struct session_database * databases
Definition: session.h:94
void(* session_watchfun)(void *data)
Definition: session.h:74
int diagnostic
Definition: session.h:137
const char * addinfo
Definition: session.h:139
int filtered
Definition: session.h:141
char * rank
Definition: session.h:103
int settings_modified
Definition: session.h:112
struct relevance * relevance
Definition: session.h:100
int ingest_xml_record(struct client *cl, xmlDoc *xdoc, int record_no, NMEM nmem, int cached_copy)
Definition: session.c:1886
void perform_termlist(struct http_channel *c, struct session *se, const char *name, int num, int version)
Definition: session.c:1259
struct named_termlist * termlists
Definition: session.h:99
int ingest_record(struct client *cl, const char *rec, int record_no, NMEM nmem)
ingest XML record
Definition: session.c:1874
const char * state
Definition: session.h:142
struct termlist * termlist
Definition: session.h:79
int number_of_warnings_unknown_elements
Definition: session.h:107
void statistics(struct session *s, struct statistics *stat)
Definition: session.c:1548
int num_settings
Definition: session.h:61