pazpar2  1.13.0
Data Structures | Macros | Functions | Variables
session.c File Reference

high-level logic; mostly user sessions and settings More...

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <assert.h>
#include <math.h>
#include <yaz/marcdisp.h>
#include <yaz/comstack.h>
#include <yaz/tcpip.h>
#include <yaz/proto.h>
#include <yaz/readconf.h>
#include <yaz/pquery.h>
#include <yaz/otherinfo.h>
#include <yaz/yaz-util.h>
#include <yaz/nmem.h>
#include <yaz/query-charset.h>
#include <yaz/querytowrbuf.h>
#include <yaz/oid_db.h>
#include <yaz/snprintf.h>
#include <yaz/xml_get.h>
#include "ppmutex.h"
#include "parameters.h"
#include "session.h"
#include "eventl.h"
#include "http.h"
#include "termlists.h"
#include "reclists.h"
#include "relevance.h"
#include "database.h"
#include "client.h"
#include "settings.h"
#include "normalize7bit.h"
#include <libxml/tree.h>

Go to the source code of this file.

Data Structures

struct  client_list
 
struct  facet_id
 

Macros

#define USE_TIMING   0
 
#define MAX_CHUNK   15
 
#define MAX(a, b)   ((a)>(b)?(a):(b))
 
#define MAX_XSLT_ARGS   16
 

Functions

static int session_use (int delta)
 
int sessions_get_count (void)
 
static void log_xml_doc (xmlDoc *doc)
 
static void session_enter (struct session *s, const char *caller)
 
static void session_leave (struct session *s, const char *caller)
 
static int run_icu (struct session *s, const char *icu_chain_id, const char *value, WRBUF norm_wr, WRBUF disp_wr)
 
static void session_normalize_facet (struct session *s, const char *type, const char *value, WRBUF display_wrbuf, WRBUF facet_wrbuf)
 
static void session_add_id_facet (struct session *s, struct client *cl, const char *type, const char *id, size_t id_len, const char *term)
 
const char * session_lookup_id_facet (struct session *s, struct client *cl, const char *type, const char *term)
 
void add_facet (struct session *s, const char *type, const char *value, int count, struct client *cl)
 
static xmlDoc * record_to_xml (struct session *se, struct session_database *sdb, const char *rec)
 
static void insert_settings_parameters (struct session_database *sdb, struct conf_service *service, char **parms, NMEM nmem)
 
static void insert_settings_values (struct session_database *sdb, xmlDoc *doc, xmlNode *root, struct conf_service *service)
 
static xmlDoc * normalize_record (struct session *se, struct session_database *sdb, struct conf_service *service, const char *rec, NMEM nmem)
 
void session_settings_dump (struct session *se, struct session_database *db, WRBUF w)
 
const char * session_setting_oneval (struct session_database *db, int offset)
 
static int prepare_map (struct session *se, struct session_database *sdb)
 
static void session_watch_cancel (void *data, struct http_channel *c, void *data2)
 
int session_set_watch (struct session *s, int what, session_watchfun fun, void *data, struct http_channel *chan)
 
void session_alert_watch (struct session *s, int what)
 
static void select_targets_callback (struct session *se, struct session_database *db)
 
static void session_reset_active_clients (struct session *se, struct client_list *new_list)
 
static void session_remove_cached_clients (struct session *se)
 
static int select_targets (struct session *se, const char *filter)
 
int session_active_clients (struct session *s)
 
int session_is_preferred_clients_ready (struct session *s)
 
static void session_clear_set (struct session *se, struct reclist_sortparms *sp)
 
void session_sort (struct session *se, struct reclist_sortparms *sp, const char *mergekey, const char *rank)
 
void session_stop (struct session *se)
 
enum pazpar2_error_code session_search (struct session *se, const char *query, const char *startrecs, const char *maxrecs, const char *filter, const char *limit, const char **addinfo, const char **addinfo2, struct reclist_sortparms *sp, const char *mergekey, const char *rank)
 
static void session_init_databases_fun (void *context, struct database *db)
 
static void session_database_destroy (struct session_database *sdb)
 
void session_init_databases (struct session *se)
 
static struct session_databaseload_session_database (struct session *se, const char *id)
 
static struct session_databasefind_session_database (struct session *se, const char *id)
 
void session_apply_setting (struct session *se, const char *dbname, const char *name, const char *value)
 
void session_destroy (struct session *se)
 
size_t session_get_memory_status (struct session *session)
 
struct sessionsession_create (NMEM nmem, struct conf_service *service, unsigned session_id)
 
static struct hitsbytargethitsbytarget_nb (struct session *se, int *count, NMEM nmem)
 
struct hitsbytargetget_hitsbytarget (struct session *se, int *count, NMEM nmem)
 
static int cmp_ht (const void *p1, const void *p2)
 
static int cmp_ht_approx (const void *p1, const void *p2)
 
static int targets_termlist_nb (WRBUF wrbuf, struct session *se, int num, NMEM nmem, int version)
 
void perform_termlist (struct http_channel *c, struct session *se, const char *name, int num, int version)
 
struct record_clustershow_single_start (struct session *se, const char *id, struct record_cluster **prev_r, struct record_cluster **next_r)
 
void show_single_stop (struct session *se, struct record_cluster *rec)
 
int session_fetch_more (struct session *se)
 
struct record_cluster ** show_range_start (struct session *se, struct reclist_sortparms *sp, int start, int *num, int *total, Odr_int *sumhits, Odr_int *approx_hits, void(*show_records_ready)(void *data), struct http_channel *chan)
 
void show_range_stop (struct session *se, struct record_cluster **recs)
 
void statistics (struct session *se, struct statistics *stat)
 
static struct record_metadatarecord_metadata_init (NMEM nmem, const char *value, const char *norm, enum conf_metadata_type type, struct _xmlAttr *attr)
 
static void mergekey_norm_wr (pp2_charset_fact_t charsets, WRBUF norm_wr, const char *value)
 
static int get_mergekey_from_doc (xmlDoc *doc, xmlNode *root, const char *name, struct conf_service *service, WRBUF norm_wr)
 
static const char * get_mergekey (xmlDoc *doc, xmlNode *root, struct client *cl, int record_no, struct conf_service *service, NMEM nmem, const char *session_mergekey)
 
static int check_record_filter (xmlNode *root, struct session_database *sdb)
 see if metadata for pz:recordfilter exists More...
 
static int ingest_to_cluster (struct client *cl, WRBUF wrbuf_disp, WRBUF wrbuf_norm, xmlDoc *xdoc, xmlNode *root, int record_no, struct record_metadata_attr *mergekey)
 
static int ingest_sub_record (struct client *cl, xmlDoc *xdoc, xmlNode *root, int record_no, NMEM nmem, struct session_database *sdb, struct record_metadata_attr *mergekeys)
 
int ingest_record (struct client *cl, const char *rec, int record_no, NMEM nmem)
 ingest XML record More...
 
int ingest_xml_record (struct client *cl, xmlDoc *xdoc, int record_no, NMEM nmem, int cached_copy)
 
static int match_metadata_local (struct conf_service *service, struct conf_metadata *ser_md, struct record_metadata *rec_md0, char **values, int num_v)
 
int session_check_cluster_limit (struct session *se, struct record_cluster *rec)
 
static int check_limit_local (struct client *cl, struct record *record, int record_no)
 
void session_log (struct session *s, int level, const char *fmt,...)
 

Variables

struct parameters global_parameters
 
static YAZ_MUTEX g_session_mutex = 0
 
static int no_sessions = 0
 

Detailed Description

high-level logic; mostly user sessions and settings

Definition in file session.c.

Macro Definition Documentation

#define MAX (   a,
 
)    ((a)>(b)?(a):(b))

Definition at line 83 of file session.c.

Referenced by ingest_to_cluster().

#define MAX_CHUNK   15

Definition at line 81 of file session.c.

#define MAX_XSLT_ARGS   16

Definition at line 321 of file session.c.

Referenced by insert_settings_parameters(), and normalize_record().

#define USE_TIMING   0

Definition at line 61 of file session.c.

Function Documentation

void add_facet ( struct session s,
const char *  type,
const char *  value,
int  count,
struct client cl 
)
static int check_limit_local ( struct client cl,
struct record record,
int  record_no 
)
static
static int check_record_filter ( xmlNode *  root,
struct session_database sdb 
)
static

see if metadata for pz:recordfilter exists

Parameters
rootxml root element of normalized record
sdbsession database for client
Return values
0if there is no metadata for pz:recordfilter
1if there is metadata for pz:recordfilter

If there is no pz:recordfilter defined, this function returns 1 as well.

Definition at line 1779 of file session.c.

References ingest_to_cluster(), conf_metadata::mergekey, PZ_RECORDFILTER, session_setting_oneval(), and conf_metadata::type.

Referenced by ingest_sub_record().

static int cmp_ht ( const void *  p1,
const void *  p2 
)
static

Definition at line 1194 of file session.c.

References hitsbytarget::hits.

Referenced by targets_termlist_nb().

static int cmp_ht_approx ( const void *  p1,
const void *  p2 
)
static

Definition at line 1202 of file session.c.

References hitsbytarget::approximation.

Referenced by targets_termlist_nb().

static struct session_database* find_session_database ( struct session se,
const char *  id 
)
static
struct hitsbytarget* get_hitsbytarget ( struct session se,
int *  count,
NMEM  nmem 
)

Definition at line 1184 of file session.c.

References hitsbytarget_nb(), session_enter(), and session_leave().

Referenced by bytarget_response().

static const char* get_mergekey ( xmlDoc *  doc,
xmlNode *  root,
struct client cl,
int  record_no,
struct conf_service service,
NMEM  nmem,
const char *  session_mergekey 
)
static
static int get_mergekey_from_doc ( xmlDoc *  doc,
xmlNode *  root,
const char *  name,
struct conf_service service,
WRBUF  norm_wr 
)
static

Definition at line 1672 of file session.c.

References conf_service::charsets, mergekey_norm_wr(), and record_metadata_attr::value.

Referenced by get_mergekey().

static struct hitsbytarget* hitsbytarget_nb ( struct session se,
int *  count,
NMEM  nmem 
)
static
int ingest_record ( struct client cl,
const char *  rec,
int  record_no,
NMEM  nmem 
)

ingest XML record

Parameters
clclient holds the result set for record
recrecord buffer (0 terminated)
record_norecord position (1, 2, ..)
nmemworking NMEM
Return values
0OK
-1failure
-2Filtered

Definition at line 1874 of file session.c.

References client_get_database(), client_get_session(), client_store_xdoc(), ingest_xml_record(), normalize_record(), and session::service.

Referenced by client_record_ingest().

static int ingest_sub_record ( struct client cl,
xmlDoc *  xdoc,
xmlNode *  root,
int  record_no,
NMEM  nmem,
struct session_database sdb,
struct record_metadata_attr mergekeys 
)
static
static int ingest_to_cluster ( struct client cl,
WRBUF  wrbuf_disp,
WRBUF  wrbuf_norm,
xmlDoc *  xdoc,
xmlNode *  root,
int  record_no,
struct record_metadata_attr mergekey 
)
static

Definition at line 2141 of file session.c.

References add_facet(), conf_service::charsets, check_limit_local(), client_get_database(), client_get_hits(), client_get_maxrecs(), client_get_session(), client_has_facet(), conf_service_metadata_field_id(), record_metadata::data, session_database::database, data_types::disp, parameters::dump_records, conf_metadata::icurule, database::id, data_types::max, MAX, conf_metadata::merge, record::metadata, record_cluster::metadata, conf_service::metadata, Metadata_merge_all, Metadata_merge_first, Metadata_merge_longest, Metadata_merge_range, Metadata_merge_unique, Metadata_type_generic, Metadata_type_skiparticle, Metadata_type_year, data_types::min, conf_metadata::name, record_metadata::next, session::nmem, data_types::norm, conf_service::num_metadata, conf_service::num_sortkeys, data_types::number, session::number_of_warnings_unknown_elements, session::number_of_warnings_unknown_metadata, pp2_charset_token_create(), pp2_charset_token_destroy(), pp2_charset_token_first(), pp2_charset_token_next(), pp2_get_sort(), PZ_TERMLIST_TERM_FACTOR, conf_metadata::rank, session::rank, record_cluster::recid, session::reclist, reclist_insert(), record_create(), record_metadata_init(), session::relevance, relevance_countwords(), relevance_donerecord(), relevance_snippet(), run_icu(), session::service, session_log(), session_setting_oneval(), data_types::snippet, data_types::sort, conf_metadata::sortkey_offset, record_cluster::sortkeys, conf_service::sortkeys, conf_metadata::termlist, data_types::text, session::total_merged, session::total_records, conf_metadata::type, and conf_sortkey::type.

Referenced by check_record_filter(), and ingest_sub_record().

int ingest_xml_record ( struct client cl,
xmlDoc *  xdoc,
int  record_no,
NMEM  nmem,
int  cached_copy 
)
static void insert_settings_parameters ( struct session_database sdb,
struct conf_service service,
char **  parms,
NMEM  nmem 
)
static
static void insert_settings_values ( struct session_database sdb,
xmlDoc *  doc,
xmlNode *  root,
struct conf_service service 
)
static
static struct session_database* load_session_database ( struct session se,
const char *  id 
)
static
static void log_xml_doc ( xmlDoc *  doc)
static

Definition at line 121 of file session.c.

Referenced by ingest_xml_record(), and record_to_xml().

static int match_metadata_local ( struct conf_service service,
struct conf_metadata ser_md,
struct record_metadata rec_md0,
char **  values,
int  num_v 
)
static
static void mergekey_norm_wr ( pp2_charset_fact_t  charsets,
WRBUF  norm_wr,
const char *  value 
)
static
static xmlDoc* normalize_record ( struct session se,
struct session_database sdb,
struct conf_service service,
const char *  rec,
NMEM  nmem 
)
static
void perform_termlist ( struct http_channel c,
struct session se,
const char *  name,
int  num,
int  version 
)
static int prepare_map ( struct session se,
struct session_database sdb 
)
static
static struct record_metadata* record_metadata_init ( NMEM  nmem,
const char *  value,
const char *  norm,
enum conf_metadata_type  type,
struct _xmlAttr *  attr 
)
static
static xmlDoc* record_to_xml ( struct session se,
struct session_database sdb,
const char *  rec 
)
static
static int run_icu ( struct session s,
const char *  icu_chain_id,
const char *  value,
WRBUF  norm_wr,
WRBUF  disp_wr 
)
static
static int select_targets ( struct session se,
const char *  filter 
)
static

Definition at line 632 of file session.c.

References select_targets_callback(), and session_grep_databases().

Referenced by session_search().

static void select_targets_callback ( struct session se,
struct session_database db 
)
static
int session_active_clients ( struct session s)
static void session_add_id_facet ( struct session s,
struct client cl,
const char *  type,
const char *  id,
size_t  id_len,
const char *  term 
)
static
void session_alert_watch ( struct session s,
int  what 
)
void session_apply_setting ( struct session se,
const char *  dbname,
const char *  name,
const char *  value 
)
int session_check_cluster_limit ( struct session se,
struct record_cluster rec 
)
static void session_clear_set ( struct session se,
struct reclist_sortparms sp 
)
static
struct session* session_create ( NMEM  nmem,
struct conf_service service,
unsigned  session_id 
)
static void session_database_destroy ( struct session_database sdb)
static

Definition at line 980 of file session.c.

References session_database::map.

Referenced by session_destroy().

void session_destroy ( struct session se)
static void session_enter ( struct session s,
const char *  caller 
)
static
int session_fetch_more ( struct session se)
size_t session_get_memory_status ( struct session session)

Definition at line 1082 of file session.c.

References session::nmem, session_enter(), and session_leave().

Referenced by cmd_termlist(), and session_status().

void session_init_databases ( struct session se)
static void session_init_databases_fun ( void *  context,
struct database db 
)
static
int session_is_preferred_clients_ready ( struct session s)
static void session_leave ( struct session s,
const char *  caller 
)
static
void session_log ( struct session s,
int  level,
const char *  fmt,
  ... 
)
const char* session_lookup_id_facet ( struct session s,
struct client cl,
const char *  type,
const char *  term 
)
static void session_normalize_facet ( struct session s,
const char *  type,
const char *  value,
WRBUF  display_wrbuf,
WRBUF  facet_wrbuf 
)
static

Definition at line 189 of file session.c.

References conf_service::metadata, conf_service::num_metadata, run_icu(), and session::service.

Referenced by add_facet().

static void session_remove_cached_clients ( struct session se)
static
static void session_reset_active_clients ( struct session se,
struct client_list new_list 
)
static
enum pazpar2_error_code session_search ( struct session se,
const char *  query,
const char *  startrecs,
const char *  maxrecs,
const char *  filter,
const char *  limit,
const char **  addinfo,
const char **  addinfo2,
struct reclist_sortparms sp,
const char *  mergekey,
const char *  rank 
)
int session_set_watch ( struct session s,
int  what,
session_watchfun  fun,
void *  data,
struct http_channel chan 
)
const char* session_setting_oneval ( struct session_database db,
int  offset 
)
void session_settings_dump ( struct session se,
struct session_database db,
WRBUF  w 
)
void session_sort ( struct session se,
struct reclist_sortparms sp,
const char *  mergekey,
const char *  rank 
)
void session_stop ( struct session se)
static int session_use ( int  delta)
static

Definition at line 102 of file session.c.

References g_session_mutex, and no_sessions.

Referenced by session_create(), session_destroy(), and sessions_get_count().

static void session_watch_cancel ( void *  data,
struct http_channel c,
void *  data2 
)
static

Definition at line 489 of file session.c.

References session_watchentry::data, session_watchentry::fun, and session_watchentry::obs.

Referenced by session_set_watch().

int sessions_get_count ( void  )

Definition at line 116 of file session.c.

References session_use().

Referenced by cmd_info().

struct record_cluster** show_range_start ( struct session se,
struct reclist_sortparms sp,
int  start,
int *  num,
int *  total,
Odr_int *  sumhits,
Odr_int *  approx_hits,
void(*)(void *data)  show_records_ready,
struct http_channel chan 
)
void show_range_stop ( struct session se,
struct record_cluster **  recs 
)

Definition at line 1543 of file session.c.

References session_leave().

Referenced by show_range_start(), and show_records().

struct record_cluster* show_single_start ( struct session se,
const char *  id,
struct record_cluster **  prev_r,
struct record_cluster **  next_r 
)
void show_single_stop ( struct session se,
struct record_cluster rec 
)

Definition at line 1378 of file session.c.

References session_leave().

Referenced by show_record().

void statistics ( struct session se,
struct statistics stat 
)
static int targets_termlist_nb ( WRBUF  wrbuf,
struct session se,
int  num,
NMEM  nmem,
int  version 
)
static

Variable Documentation

YAZ_MUTEX g_session_mutex = 0
static

Definition at line 99 of file session.c.

Referenced by session_use().

struct parameters global_parameters
Initial value:
=
{
0,
0,
0,
}

Definition at line 86 of file session.c.

Referenced by cmd_exit(), http_serialize_response(), make_sessionid(), and sc_main().

int no_sessions = 0
static

Definition at line 100 of file session.c.

Referenced by session_use().