pazpar2  1.6.30
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/timing.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

Macros

#define USE_TIMING   1
#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_count (void)
int session_count_total (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 void session_normalize_facet (struct session *s, const char *type, const char *value, WRBUF display_wrbuf, WRBUF facet_wrbuf)
void add_facet (struct session *s, const char *type, const char *value, int count)
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, 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)
static void session_sort_unlocked (struct session *se, struct reclist_sortparms *sp)
void session_sort (struct session *se, struct reclist_sortparms *sp)
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, struct reclist_sortparms *sp)
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, char *id)
static struct session_databasefind_session_database (struct session *se, char *id)
void session_apply_setting (struct session *se, char *dbname, char *setting, char *value)
void session_destroy (struct session *se)
size_t session_get_memory_status (struct session *session)
struct sessionnew_session (NMEM nmem, struct conf_service *service, unsigned session_id)
const char * client_get_suggestions_xml (struct client *cl, WRBUF wrbuf)
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, enum conf_metadata_type type, struct _xmlAttr *attr)
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, struct client *cl, int record_no, struct conf_service *service, NMEM nmem)
static int check_record_filter (xmlNode *root, struct session_database *sdb)
 see if metadata for pz:recordfilter exists
static int ingest_to_cluster (struct client *cl, xmlDoc *xdoc, xmlNode *root, int record_no, const char *mergekey_norm)
int ingest_record (struct client *cl, const char *rec, int record_no, NMEM nmem)
 ingest XML record
static int match_metadata_local (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
static int no_session_total = 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 82 of file session.c.

Referenced by ingest_to_cluster().

#define MAX_CHUNK   15

Definition at line 80 of file session.c.

#define MAX_XSLT_ARGS   16

Definition at line 273 of file session.c.

Referenced by insert_settings_parameters(), and normalize_record().

#define USE_TIMING   1

Definition at line 60 of file session.c.

Function Documentation

void add_facet ( struct session s,
const char *  type,
const char *  value,
int  count 
)
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 1580 of file session.c.

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

Referenced by ingest_record().

const char* client_get_suggestions_xml ( struct client cl,
WRBUF  wrbuf 
)

Definition at line 1633 of file client.c.

References suggestions::num, suggestions::passthrough, and client::suggestions.

Referenced by hitsbytarget_nb().

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

Definition at line 1042 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 1050 of file session.c.

References hitsbytarget::approximation.

Referenced by targets_termlist_nb().

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

Definition at line 1032 of file session.c.

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

Referenced by bytarget_response().

static const char* get_mergekey ( xmlDoc *  doc,
struct client cl,
int  record_no,
struct conf_service service,
NMEM  nmem 
)
static
static int get_mergekey_from_doc ( xmlDoc *  doc,
xmlNode *  root,
const char *  name,
struct conf_service service,
WRBUF  norm_wr 
)
static
static struct hitsbytarget* hitsbytarget_nb ( struct session se,
int *  count,
NMEM  nmem 
)
staticread
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 1647 of file session.c.

References check_record_filter(), client_get_database(), client_get_session(), session_database::database, get_mergekey(), database::id, ingest_to_cluster(), normalize_record(), session::relevance, session::service, session_enter(), session_leave(), and session_log().

Referenced by client_record_ingest().

static int ingest_to_cluster ( struct client cl,
xmlDoc *  xdoc,
xmlNode *  root,
int  record_no,
const char *  mergekey_norm 
)
static

Definition at line 1829 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, 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_sortkey_skiparticle, Metadata_type_year, data_types::min, conf_metadata::name, record_metadata::next, session::nmem, 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, record_cluster::recid, session::reclist, reclist_insert(), record_create(), record_metadata_init(), session::relevance, relevance_countwords(), relevance_donerecord(), relevance_newrec(), session::service, session_log(), session_setting_oneval(), 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 ingest_record().

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,
struct conf_service service 
)
static
static struct session_database* load_session_database ( struct session se,
char *  id 
)
staticread
static void log_xml_doc ( xmlDoc *  doc)
static

Definition at line 133 of file session.c.

Referenced by normalize_record(), and record_to_xml().

static int match_metadata_local ( struct conf_metadata ser_md,
struct record_metadata rec_md0,
char **  values,
int  num_v 
)
static
struct session* new_session ( NMEM  nmem,
struct conf_service service,
unsigned  session_id 
)
read
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,
enum conf_metadata_type  type,
struct _xmlAttr *  attr 
)
staticread
static xmlDoc* record_to_xml ( struct session se,
struct session_database sdb,
const char *  rec 
)
static
static int select_targets ( struct session se,
const char *  filter 
)
static

Definition at line 595 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)
void session_alert_watch ( struct session s,
int  what 
)
void session_apply_setting ( struct session se,
char *  dbname,
char *  setting,
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
int session_count_total ( void  )

Definition at line 122 of file session.c.

References g_session_mutex, and no_session_total.

static void session_database_destroy ( struct session_database sdb)
static

Definition at line 846 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 938 of file session.c.

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

Referenced by 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,
  ... 
)
static void session_normalize_facet ( struct session s,
const char *  type,
const char *  value,
WRBUF  display_wrbuf,
WRBUF  facet_wrbuf 
)
static
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,
struct reclist_sortparms sp 
)
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 
)

Definition at line 720 of file session.c.

References session_sort_unlocked().

Referenced by cmd_show().

static void session_sort_unlocked ( struct session se,
struct reclist_sortparms sp 
)
static
static int session_use ( int  delta)
static

Definition at line 102 of file session.c.

References g_session_mutex, no_session_total, and no_sessions.

Referenced by new_session(), session_destroy(), and sessions_count().

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

Definition at line 452 of file session.c.

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

Referenced by session_set_watch().

int sessions_count ( void  )

Definition at line 117 of file session.c.

References session_use().

Referenced by cmd_server_status().

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 
)
read
void show_range_stop ( struct session se,
struct record_cluster **  recs 
)

Definition at line 1367 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 
)
read
void show_single_stop ( struct session se,
struct record_cluster rec 
)

Definition at line 1227 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 98 of file session.c.

Referenced by session_count_total(), and session_use().

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

Definition at line 85 of file session.c.

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

int no_session_total = 0
static

Definition at line 100 of file session.c.

Referenced by session_count_total(), and session_use().

int no_sessions = 0
static

Definition at line 99 of file session.c.

Referenced by session_use().