pazpar2  1.14.1
Data Structures | Macros | Functions | Variables
client.c File Reference

Z39.50 client. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <assert.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/diagbib1.h>
#include <yaz/snprintf.h>
#include <yaz/rpn2cql.h>
#include <yaz/rpn2solr.h>
#include <yaz/gettimeofday.h>
#include "ppmutex.h"
#include "session.h"
#include "parameters.h"
#include "client.h"
#include "connection.h"
#include "settings.h"
#include "relevance.h"
#include "incref.h"

Go to the source code of this file.

Data Structures

struct  client
 Represents client state for a connection to one search target. More...
 
struct  suggestions
 
struct  show_raw
 

Macros

#define USE_TIMING   0
 
#define XDOC_CACHE_SIZE   100
 

Functions

static int client_use (int delta)
 
int clients_get_count (void)
 
const char * client_get_state_str (struct client *cl)
 
enum client_state client_get_state (struct client *cl)
 
void client_set_state_nb (struct client *cl, enum client_state st)
 
void client_set_state (struct client *cl, enum client_state st)
 
static void client_init_xdoc (struct client *cl)
 
static void client_destroy_xdoc (struct client *cl)
 
xmlDoc * client_get_xdoc (struct client *cl, int record_no)
 
void client_store_xdoc (struct client *cl, int record_no, xmlDoc *xdoc)
 
static void client_show_raw_error (struct client *cl, const char *addinfo)
 
struct connectionclient_get_connection (struct client *cl)
 
struct session_databaseclient_get_database (struct client *cl)
 
struct sessionclient_get_session (struct client *cl)
 
static void client_send_raw_present (struct client *cl)
 
static int nativesyntax_to_type (const char *s, char *type, ZOOM_record rec)
 
static void client_show_immediate (ZOOM_resultset resultset, struct session_database *sdb, int position, void *data, void(*error_handler)(void *data, const char *addinfo), void(*record_handler)(void *data, const char *buf, size_t sz), int binary, const char *nativesyntax)
 
int client_show_raw_begin (struct client *cl, int position, const char *syntax, const char *esn, void *data, void(*error_handler)(void *data, const char *addinfo), void(*record_handler)(void *data, const char *buf, size_t sz), int binary, const char *nativesyntax)
 
static void client_show_raw_delete (struct show_raw *r)
 
void client_show_raw_remove (struct client *cl, void *data)
 
static void client_show_raw_dequeue (struct client *cl)
 
static void client_report_facets (struct client *cl, ZOOM_resultset rs)
 
static void ingest_raw_record (struct client *cl, ZOOM_record rec)
 
struct suggestionsclient_suggestions_create (const char *suggestions_string)
 
static void client_suggestions_destroy (struct client *cl)
 
void client_search_response (struct client *cl)
 
void client_got_records (struct client *cl)
 
static void client_record_ingest (struct client *cl)
 
void client_record_response (struct client *cl, int *got_records)
 
int client_reingest (struct client *cl)
 
static void client_set_facets_request (struct client *cl, ZOOM_connection link)
 
int client_has_facet (struct client *cl, const char *name)
 
static const char * get_strategy_plus_sort (struct client *l, const char *field)
 
void client_update_show_stat (struct client *cl, int cmd)
 
int client_fetch_more (struct client *cl)
 
int client_parse_init (struct client *cl, int same_search)
 
int client_parse_range (struct client *cl, const char *startrecs, const char *maxrecs)
 
const char * client_get_query (struct client *cl, const char **type, NMEM nmem)
 
int client_start_search (struct client *cl)
 
struct clientclient_create (const char *id)
 
void client_lock (struct client *c)
 
void client_unlock (struct client *c)
 
void client_incref (struct client *c)
 
int client_destroy (struct client *c)
 
void client_set_connection (struct client *cl, struct connection *con)
 
void client_disconnect (struct client *cl)
 
void client_mark_dead (struct client *cl)
 
void client_stop (struct client *cl)
 
static CCL_bibset prepare_cclmap (struct client *cl, CCL_bibset base_bibset)
 
static char * make_cqlquery (struct client *cl, Z_RPNQuery *zquery)
 
static char * make_solrquery (struct client *cl, Z_RPNQuery *zquery)
 
const char * client_get_facet_limit_local (struct client *cl, struct session_database *sdb, int *l, NMEM nmem, int *num, char ***values)
 
static void ccl_quote_map_term (CCL_bibset ccl_map, WRBUF w, const char *term)
 
static int apply_limit (struct client *cl, facet_limits_t facet_limits, WRBUF w_pqf, CCL_bibset ccl_map, struct conf_service *service)
 
int client_parse_query (struct client *cl, const char *query, facet_limits_t facet_limits, const char **error_msg)
 
int client_parse_sort (struct client *cl, struct reclist_sortparms *sp, int *has_sortmap)
 
void client_set_session (struct client *cl, struct session *se)
 
int client_is_active (struct client *cl)
 
int client_is_active_preferred (struct client *cl)
 
Odr_int client_get_hits (struct client *cl)
 
Odr_int client_get_approximation (struct client *cl)
 
int client_get_num_records (struct client *cl, int *filtered, int *ingest, int *failed)
 
void client_set_diagnostic (struct client *cl, int diagnostic, const char *message, const char *addinfo)
 
int client_get_diagnostic (struct client *cl, const char **message, const char **addinfo)
 
const char * client_get_suggestions_xml (struct client *cl, WRBUF wrbuf)
 
void client_set_database (struct client *cl, struct session_database *db)
 
const char * client_get_id (struct client *cl)
 
int client_get_maxrecs (struct client *cl)
 
void client_set_preferred (struct client *cl, int v)
 

Variables

static YAZ_MUTEX g_mutex = 0
 
static int no_clients = 0
 
static const char * client_states []
 

Detailed Description

Z39.50 client.

Definition in file client.c.

Macro Definition Documentation

◆ USE_TIMING

#define USE_TIMING   0

Definition at line 60 of file client.c.

◆ XDOC_CACHE_SIZE

#define XDOC_CACHE_SIZE   100

Definition at line 74 of file client.c.

Function Documentation

◆ apply_limit()

static int apply_limit ( struct client cl,
facet_limits_t  facet_limits,
WRBUF  w_pqf,
CCL_bibset  ccl_map,
struct conf_service service 
)
static

◆ ccl_quote_map_term()

static void ccl_quote_map_term ( CCL_bibset  ccl_map,
WRBUF  w,
const char *  term 
)
static

Definition at line 1331 of file client.c.

Referenced by apply_limit().

◆ client_create()

struct client* client_create ( const char *  id)

◆ client_destroy()

int client_destroy ( struct client c)

◆ client_destroy_xdoc()

static void client_destroy_xdoc ( struct client cl)
static

Definition at line 209 of file client.c.

References client::xdoc, and XDOC_CACHE_SIZE.

Referenced by client_destroy(), and client_start_search().

◆ client_disconnect()

void client_disconnect ( struct client cl)

◆ client_fetch_more()

int client_fetch_more ( struct client cl)

◆ client_get_approximation()

Odr_int client_get_approximation ( struct client cl)

Definition at line 1751 of file client.c.

References client_get_id(), client::filtered, client::hits, and client::record_offset.

Referenced by hitsbytarget_nb(), and show_range_start().

◆ client_get_connection()

struct connection* client_get_connection ( struct client cl)

◆ client_get_database()

struct session_database* client_get_database ( struct client cl)

◆ client_get_diagnostic()

int client_get_diagnostic ( struct client cl,
const char **  message,
const char **  addinfo 
)

Definition at line 1789 of file client.c.

References client::addinfo, client::diagnostic, and client::message.

Referenced by hitsbytarget_nb().

◆ client_get_facet_limit_local()

const char* client_get_facet_limit_local ( struct client cl,
struct session_database sdb,
int *  l,
NMEM  nmem,
int *  num,
char ***  values 
)

◆ client_get_hits()

Odr_int client_get_hits ( struct client cl)

◆ client_get_id()

const char* client_get_id ( struct client cl)

◆ client_get_maxrecs()

int client_get_maxrecs ( struct client cl)

Definition at line 1838 of file client.c.

References client::maxrecs.

Referenced by ingest_to_cluster().

◆ client_get_num_records()

int client_get_num_records ( struct client cl,
int *  filtered,
int *  ingest,
int *  failed 
)

◆ client_get_query()

const char* client_get_query ( struct client cl,
const char **  type,
NMEM  nmem 
)

Definition at line 894 of file client.c.

References client::cqlquery, and client::pquery.

Referenced by hitsbytarget_nb().

◆ client_get_session()

struct session* client_get_session ( struct client cl)

◆ client_get_state()

enum client_state client_get_state ( struct client cl)

Definition at line 161 of file client.c.

References client_states, and client::state.

Referenced by session_fetch_more(), session_sort(), and statistics().

◆ client_get_state_str()

const char* client_get_state_str ( struct client cl)

Definition at line 161 of file client.c.

Referenced by hitsbytarget_nb(), and session_fetch_more().

◆ client_get_suggestions_xml()

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

Definition at line 1799 of file client.c.

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

Referenced by hitsbytarget_nb().

◆ client_get_xdoc()

xmlDoc* client_get_xdoc ( struct client cl,
int  record_no 
)

Definition at line 220 of file client.c.

References client::xdoc, and XDOC_CACHE_SIZE.

Referenced by client_record_ingest().

◆ client_got_records()

void client_got_records ( struct client cl)

◆ client_has_facet()

int client_has_facet ( struct client cl,
const char *  name 
)

◆ client_incref()

void client_incref ( struct client c)

Definition at line 1101 of file client.c.

References client_get_id(), client::mutex, pazpar2_incref(), and client::ref_count.

Referenced by client_set_connection().

◆ client_init_xdoc()

static void client_init_xdoc ( struct client cl)
static

Definition at line 200 of file client.c.

References client::xdoc, and XDOC_CACHE_SIZE.

Referenced by client_create(), and client_start_search().

◆ client_is_active()

int client_is_active ( struct client cl)

◆ client_is_active_preferred()

int client_is_active_preferred ( struct client cl)

◆ client_lock()

void client_lock ( struct client c)

◆ client_mark_dead()

void client_mark_dead ( struct client cl)

Definition at line 1170 of file client.c.

References client::connection, and connection_mark_dead().

Referenced by session_remove_cached_clients().

◆ client_parse_init()

int client_parse_init ( struct client cl,
int  same_search 
)

Definition at line 867 of file client.c.

References client::same_search.

Referenced by session_sort().

◆ client_parse_query()

int client_parse_query ( struct client cl,
const char *  query,
facet_limits_t  facet_limits,
const char **  error_msg 
)

◆ client_parse_range()

int client_parse_range ( struct client cl,
const char *  startrecs,
const char *  maxrecs 
)

Definition at line 876 of file client.c.

References client::maxrecs, client::same_search, and client::startrecs.

◆ client_parse_sort()

int client_parse_sort ( struct client cl,
struct reclist_sortparms sp,
int *  has_sortmap 
)

◆ client_record_ingest()

static void client_record_ingest ( struct client cl)
static

◆ client_record_response()

void client_record_response ( struct client cl,
int *  got_records 
)

◆ client_reingest()

int client_reingest ( struct client cl)

◆ client_report_facets()

static void client_report_facets ( struct client cl,
ZOOM_resultset  rs 
)
static

◆ client_search_response()

void client_search_response ( struct client cl)

◆ client_send_raw_present()

static void client_send_raw_present ( struct client cl)
static

◆ client_set_connection()

void client_set_connection ( struct client cl,
struct connection con 
)

◆ client_set_database()

void client_set_database ( struct client cl,
struct session_database db 
)

Definition at line 1828 of file client.c.

References client::database.

Referenced by select_targets_callback(), and session_remove_cached_clients().

◆ client_set_diagnostic()

void client_set_diagnostic ( struct client cl,
int  diagnostic,
const char *  message,
const char *  addinfo 
)

Definition at line 1777 of file client.c.

References client::addinfo, client::diagnostic, and client::message.

Referenced by connection_connect(), non_block_events(), and prepare_cclmap().

◆ client_set_facets_request()

static void client_set_facets_request ( struct client cl,
ZOOM_connection  link 
)
static

◆ client_set_preferred()

void client_set_preferred ( struct client cl,
int  v 
)

Definition at line 1843 of file client.c.

References client::preferred.

◆ client_set_session()

void client_set_session ( struct client cl,
struct session se 
)

◆ client_set_state()

void client_set_state ( struct client cl,
enum client_state  st 
)

◆ client_set_state_nb()

void client_set_state_nb ( struct client cl,
enum client_state  st 
)

Definition at line 171 of file client.c.

References client::state.

Referenced by connection_connect(), and prepare_cclmap().

◆ client_show_immediate()

static void client_show_immediate ( ZOOM_resultset  resultset,
struct session_database sdb,
int  position,
void *  data,
void(*)(void *data, const char *addinfo)  error_handler,
void(*)(void *data, const char *buf, size_t sz)  record_handler,
int  binary,
const char *  nativesyntax 
)
static

Definition at line 264 of file client.c.

References nativesyntax_to_type().

Referenced by client_show_raw_begin().

◆ client_show_raw_begin()

int client_show_raw_begin ( struct client cl,
int  position,
const char *  syntax,
const char *  esn,
void *  data,
void(*)(void *data, const char *addinfo)  error_handler,
void(*)(void *data, const char *buf, size_t sz)  record_handler,
int  binary,
const char *  nativesyntax 
)

◆ client_show_raw_delete()

static void client_show_raw_delete ( struct show_raw r)
static

Definition at line 373 of file client.c.

References show_raw::esn, show_raw::nativesyntax, and show_raw::syntax.

Referenced by client_show_raw_dequeue(), and client_show_raw_remove().

◆ client_show_raw_dequeue()

static void client_show_raw_dequeue ( struct client cl)
static

Definition at line 394 of file client.c.

References client_show_raw_delete(), show_raw::next, and client::show_raw.

Referenced by client_show_raw_error(), and ingest_raw_record().

◆ client_show_raw_error()

static void client_show_raw_error ( struct client cl,
const char *  addinfo 
)
static

◆ client_show_raw_remove()

void client_show_raw_remove ( struct client cl,
void *  data 
)

Definition at line 381 of file client.c.

References client_show_raw_delete(), show_raw::data, show_raw::next, and client::show_raw.

◆ client_start_search()

int client_start_search ( struct client cl)

◆ client_stop()

void client_stop ( struct client cl)

◆ client_store_xdoc()

void client_store_xdoc ( struct client cl,
int  record_no,
xmlDoc *  xdoc 
)

Definition at line 228 of file client.c.

References client::xdoc, and XDOC_CACHE_SIZE.

Referenced by ingest_record().

◆ client_suggestions_create()

struct suggestions * client_suggestions_create ( const char *  suggestions_string)

◆ client_suggestions_destroy()

static void client_suggestions_destroy ( struct client cl)
static

Definition at line 1884 of file client.c.

References suggestions::nmem, and client::suggestions.

Referenced by client_search_response().

◆ client_unlock()

void client_unlock ( struct client c)

◆ client_update_show_stat()

void client_update_show_stat ( struct client cl,
int  cmd 
)

Definition at line 814 of file client.c.

References client::show_stat_no.

Referenced by show_range_start().

◆ client_use()

static int client_use ( int  delta)
static

Definition at line 79 of file client.c.

References g_mutex, and no_clients.

Referenced by client_create(), client_destroy(), and clients_get_count().

◆ clients_get_count()

int clients_get_count ( void  )

Definition at line 93 of file client.c.

References client_use().

Referenced by cmd_info().

◆ get_strategy_plus_sort()

static const char* get_strategy_plus_sort ( struct client l,
const char *  field 
)
static

◆ ingest_raw_record()

static void ingest_raw_record ( struct client cl,
ZOOM_record  rec 
)
static

◆ make_cqlquery()

static char* make_cqlquery ( struct client cl,
Z_RPNQuery *  zquery 
)
static

Definition at line 1247 of file client.c.

Referenced by client_parse_query().

◆ make_solrquery()

static char* make_solrquery ( struct client cl,
Z_RPNQuery *  zquery 
)
static

Definition at line 1269 of file client.c.

Referenced by client_parse_query().

◆ nativesyntax_to_type()

static int nativesyntax_to_type ( const char *  s,
char *  type,
ZOOM_record  rec 
)
static

Definition at line 446 of file client.c.

Referenced by client_record_ingest(), client_show_immediate(), and ingest_raw_record().

◆ prepare_cclmap()

static CCL_bibset prepare_cclmap ( struct client cl,
CCL_bibset  base_bibset 
)
static

Variable Documentation

◆ client_states

const char* client_states[]
static
Initial value:
= {
"Client_Connecting",
"Client_Idle",
"Client_Working",
"Client_Error",
"Client_Failed",
"Client_Disconnected"
}

Definition at line 152 of file client.c.

Referenced by client_get_state().

◆ g_mutex

YAZ_MUTEX g_mutex = 0
static

Definition at line 76 of file client.c.

Referenced by client_use().

◆ no_clients

int no_clients = 0
static

Definition at line 77 of file client.c.

Referenced by client_use().