pazpar2  1.14.1
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

◆ MAX

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

Definition at line 83 of file session.c.

◆ MAX_CHUNK

#define MAX_CHUNK   15

Definition at line 81 of file session.c.

◆ MAX_XSLT_ARGS

#define MAX_XSLT_ARGS   16

Definition at line 321 of file session.c.

◆ USE_TIMING

#define USE_TIMING   0

Definition at line 61 of file session.c.

Function Documentation

◆ add_facet()

void add_facet ( struct session s,
const char *  type,
const char *  value,
int  count,
struct client cl 
)

◆ check_limit_local()

static int check_limit_local ( struct client cl,
struct record record,
int  record_no 
)
static

◆ check_record_filter()

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 PZ_RECORDFILTER, session_setting_oneval(), and conf_metadata::type.

Referenced by ingest_sub_record().

◆ cmp_ht()

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().

◆ cmp_ht_approx()

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().

◆ find_session_database()

static struct session_database* find_session_database ( struct session se,
const char *  id 
)
static

◆ get_hitsbytarget()

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().

◆ get_mergekey()

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

◆ get_mergekey_from_doc()

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(), name, and record_metadata_attr::value.

Referenced by get_mergekey().

◆ hitsbytarget_nb()

static struct hitsbytarget* hitsbytarget_nb ( struct session se,
int *  count,
NMEM  nmem 
)
static

◆ ingest_record()

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(), conf_service::nmem, normalize_record(), and session::service.

Referenced by client_record_ingest().

◆ ingest_sub_record()

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

◆ ingest_to_cluster()

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, global_parameters, conf_metadata::icurule, database::id, data_types::max, MAX, conf_metadata::merge, conf_service::metadata, record::metadata, record_cluster::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, conf_service::sortkeys, record_cluster::sortkeys, conf_metadata::termlist, data_types::text, session::total_merged, session::total_records, conf_metadata::type, and conf_sortkey::type.

Referenced by ingest_sub_record().

◆ ingest_xml_record()

int ingest_xml_record ( struct client cl,
xmlDoc *  xdoc,
int  record_no,
NMEM  nmem,
int  cached_copy 
)

◆ insert_settings_parameters()

static void insert_settings_parameters ( struct session_database sdb,
struct conf_service service,
char **  parms,
NMEM  nmem 
)
static

◆ insert_settings_values()

static void insert_settings_values ( struct session_database sdb,
xmlDoc *  doc,
xmlNode *  root,
struct conf_service service 
)
static

◆ load_session_database()

static struct session_database* load_session_database ( struct session se,
const char *  id 
)
static

◆ log_xml_doc()

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().

◆ match_metadata_local()

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

◆ mergekey_norm_wr()

static void mergekey_norm_wr ( pp2_charset_fact_t  charsets,
WRBUF  norm_wr,
const char *  value 
)
static

◆ normalize_record()

static xmlDoc* normalize_record ( struct session se,
struct session_database sdb,
struct conf_service service,
const char *  rec,
NMEM  nmem 
)
static

◆ perform_termlist()

void perform_termlist ( struct http_channel c,
struct session se,
const char *  name,
int  num,
int  version 
)

◆ prepare_map()

static int prepare_map ( struct session se,
struct session_database sdb 
)
static

◆ record_metadata_init()

static struct record_metadata* record_metadata_init ( NMEM  nmem,
const char *  value,
const char *  norm,
enum conf_metadata_type  type,
struct _xmlAttr *  attr 
)
static

◆ record_to_xml()

static xmlDoc* record_to_xml ( struct session se,
struct session_database sdb,
const char *  rec 
)
static

◆ run_icu()

static int run_icu ( struct session s,
const char *  icu_chain_id,
const char *  value,
WRBUF  norm_wr,
WRBUF  disp_wr 
)
static

◆ select_targets()

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().

◆ select_targets_callback()

static void select_targets_callback ( struct session se,
struct session_database db 
)
static

◆ session_active_clients()

int session_active_clients ( struct session s)

◆ session_add_id_facet()

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

◆ session_alert_watch()

void session_alert_watch ( struct session s,
int  what 
)

◆ session_apply_setting()

void session_apply_setting ( struct session se,
const char *  dbname,
const char *  name,
const char *  value 
)

◆ session_check_cluster_limit()

int session_check_cluster_limit ( struct session se,
struct record_cluster rec 
)

◆ session_clear_set()

static void session_clear_set ( struct session se,
struct reclist_sortparms sp 
)
static

◆ session_create()

struct session* session_create ( NMEM  nmem,
struct conf_service service,
unsigned  session_id 
)

◆ session_database_destroy()

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().

◆ session_destroy()

void session_destroy ( struct session se)

◆ session_enter()

static void session_enter ( struct session s,
const char *  caller 
)
static

◆ session_fetch_more()

int session_fetch_more ( struct session se)

◆ session_get_memory_status()

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 session_status().

◆ session_init_databases()

void session_init_databases ( struct session se)

◆ session_init_databases_fun()

static void session_init_databases_fun ( void *  context,
struct database db 
)
static

◆ session_is_preferred_clients_ready()

int session_is_preferred_clients_ready ( struct session s)

◆ session_leave()

static void session_leave ( struct session s,
const char *  caller 
)
static

◆ session_log()

void session_log ( struct session s,
int  level,
const char *  fmt,
  ... 
)

◆ session_lookup_id_facet()

const char* session_lookup_id_facet ( struct session s,
struct client cl,
const char *  type,
const char *  term 
)

◆ session_normalize_facet()

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().

◆ session_remove_cached_clients()

static void session_remove_cached_clients ( struct session se)
static

◆ session_reset_active_clients()

static void session_reset_active_clients ( struct session se,
struct client_list new_list 
)
static

◆ session_search()

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 
)

◆ session_set_watch()

int session_set_watch ( struct session s,
int  what,
session_watchfun  fun,
void *  data,
struct http_channel chan 
)

◆ session_setting_oneval()

const char* session_setting_oneval ( struct session_database db,
int  offset 
)

◆ session_settings_dump()

void session_settings_dump ( struct session se,
struct session_database db,
WRBUF  w 
)

◆ session_sort()

void session_sort ( struct session se,
struct reclist_sortparms sp,
const char *  mergekey,
const char *  rank 
)

◆ session_stop()

void session_stop ( struct session se)

Definition at line 791 of file session.c.

Referenced by cmd_stop().

◆ session_use()

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().

◆ session_watch_cancel()

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().

◆ sessions_get_count()

int sessions_get_count ( void  )

Definition at line 116 of file session.c.

References session_use().

Referenced by cmd_info().

◆ show_range_start()

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 
)

◆ show_range_stop()

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().

◆ show_single_start()

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

◆ show_single_stop()

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().

◆ statistics()

void statistics ( struct session se,
struct statistics stat 
)

◆ targets_termlist_nb()

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

Variable Documentation

◆ g_session_mutex

YAZ_MUTEX g_session_mutex = 0
static

Definition at line 99 of file session.c.

Referenced by session_use().

◆ global_parameters

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

Definition at line 1 of file session.c.

Referenced by cmd_exit(), http_serialize_response(), ingest_to_cluster(), ingest_xml_record(), make_sessionid(), record_to_xml(), and sc_main().

◆ no_sessions

int no_sessions = 0
static

Definition at line 100 of file session.c.

Referenced by session_use().