pazpar2  1.6.30
session.h
Go to the documentation of this file.
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_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 "termlists.h"
30 #include "reclists.h"
31 #include "http.h"
32 
33 struct record;
34 struct client;
35 
36 
39 
53 
55 };
56 
57 // Represents a database
58 struct database {
59  char *id;
61  struct setting **settings;
62  struct database *next;
63 };
64 
65 
66 // Represents a database as viewed from one session, possibly with settings overriden
67 // for that session
69 {
70  struct database *database;
72  struct setting **settings;
75 };
76 
77 #define SESSION_WATCH_SHOW 0
78 #define SESSION_WATCH_RECORD 1
79 #define SESSION_WATCH_SHOW_PREF 2
80 #define SESSION_WATCH_TERMLIST 3
81 #define SESSION_WATCH_BYTARGET 4
82 #define SESSION_WATCH_MAX 4
83 
84 #define SESSION_MAX_TERMLISTS 10
85 
86 typedef void (*session_watchfun)(void *data);
87 
89 {
90  char *name;
91  struct termlist *termlist;
92 };
93 
95  void *data;
98 };
99 
100 struct client_list;
101 
102 // End-user session
103 struct session {
104  struct conf_service *service; /* service in use for this session */
105  struct session_database *databases; // All databases, settings overriden
106  struct client_list *clients_active; // Clients connected for current search
107  struct client_list *clients_cached; // Clients in cache
108  NMEM session_nmem; // Nmem for session-permanent storage
109  NMEM nmem; // Nmem for each operation (i.e. search, result set, etc)
113  struct reclist *reclist;
120  YAZ_MUTEX session_mutex;
121  unsigned session_id;
125 };
126 
127 struct statistics {
132  int num_idle;
135  Odr_int num_hits;
137 };
138 
139 struct hitsbytarget {
140  const char *id;
141  const char *name;
142  Odr_int hits;
143  Odr_int approximation;
145  const char *message;
146  const char *addinfo;
147  int records;
148  int filtered;
149  const char *state;
153 };
154 
155 struct hitsbytarget *get_hitsbytarget(struct session *s, int *count, NMEM nmem);
156 struct session *new_session(NMEM nmem, struct conf_service *service,
157  unsigned session_id);
158 void session_destroy(struct session *s);
159 void session_init_databases(struct session *s);
160 void statistics(struct session *s, struct statistics *stat);
161 
162 void session_sort(struct session *se, struct reclist_sortparms *sp);
163 
164 enum pazpar2_error_code session_search(struct session *s, const char *query,
165  const char *startrecs,
166  const char *maxrecs,
167  const char *filter, const char *limit,
168  const char **addinfo,
169  struct reclist_sortparms *sort_parm);
170 struct record_cluster **show_range_start(struct session *s,
171  struct reclist_sortparms *sp,
172  int start,
173  int *num, int *total,
174  Odr_int *sumhits,
175  Odr_int *approximation,
176  void (*ready)(void *data),
177  struct http_channel *chan);
178 int session_fetch_more(struct session *s);
179 void show_range_stop(struct session *s, struct record_cluster **recs);
180 
181 struct record_cluster *show_single_start(struct session *s, const char *id,
182  struct record_cluster **prev_r,
183  struct record_cluster **next_r);
184 void show_single_stop(struct session *s, struct record_cluster *rec);
185 int session_set_watch(struct session *s, int what, session_watchfun fun, void *data, struct http_channel *c);
186 int session_active_clients(struct session *s);
188 void session_apply_setting(struct session *se, char *dbname, char *setting, char *value);
189 const char *session_setting_oneval(struct session_database *db, int offset);
190 
191 int ingest_record(struct client *cl, const char *rec, int record_no, NMEM nmem);
192 void session_alert_watch(struct session *s, int what);
193 void add_facet(struct session *s, const char *type, const char *value, int count);
194 
195 int session_check_cluster_limit(struct session *se, struct record_cluster *rec);
196 
197 void perform_termlist(struct http_channel *c, struct session *se, const char *name, int num, int version);
198 void session_log(struct session *s, int level, const char *fmt, ...)
199 #ifdef __GNUC__
200  __attribute__ ((format (printf, 3, 4)))
201 #endif
202  ;
203 #endif
204 
205 /*
206  * Local variables:
207  * c-basic-offset: 4
208  * c-file-style: "Stroustrup"
209  * indent-tabs-mode: nil
210  * End:
211  * vim: shiftwidth=4 tabstop=8 expandtab
212  */
213