NCBI C++ ToolKit
Classes | Macros | Typedefs | Enumerations | Functions | Variables
ncbi_namerd.c File Reference
#include "ncbi_ansi_ext.h"
#include "ncbi_comm.h"
#include "ncbi_lb.h"
#include "ncbi_linkerd.h"
#include "ncbi_namerd.h"
#include "ncbi_once.h"
#include "ncbi_priv.h"
#include "parson.h"
#include <connect/ncbi_buffer.h>
#include <connect/ncbi_connutil.h>
#include <connect/ncbi_http_connector.h>
#include <connect/ncbi_memory_connector.h>
#include <connect/ncbi_server_info.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <time.h>
+ Include dependency graph for ncbi_namerd.c:

Go to the source code of this file.

Go to the SVN repository for this file.

Classes

struct  SNAMERD_Data
 

Macros

#define FMT_SIZE_T   "%zu"
 
#define FMT_TIME_T   "%lu"
 
#define NCBI_USE_ERRCODE_X   Connect_NamerdLinkerd
 
#define DEBUG_PARAM(x)   , x
 
#define DEF_NAMERD_REG_SECTION   "_NAMERD"
 
#define REG_NAMERD_API_SCHEME   "SCHEME"
 
#define DEF_NAMERD_API_SCHEME   "http"
 
#define REG_NAMERD_API_REQ_METHOD   REG_CONN_REQ_METHOD
 
#define DEF_NAMERD_API_REQ_METHOD   "GET"
 
#define REG_NAMERD_API_HTTP_VERSION   REG_CONN_HTTP_VERSION
 
#define DEF_NAMERD_API_HTTP_VERSION   0
 
#define REG_NAMERD_API_HOST   REG_CONN_HOST
 
#define DEF_NAMERD_API_HOST   "namerd-api.linkerd.ncbi.nlm.nih.gov"
 
#define REG_NAMERD_API_PORT   REG_CONN_PORT
 
#define DEF_NAMERD_API_PORT   0/*unsupported*/
 
#define REG_NAMERD_API_PATH   REG_CONN_PATH
 
#define DEF_NAMERD_API_PATH   "/api/1/resolve"
 
#define REG_NAMERD_API_ENV   "ENV" /*deprecated*/
 
#define REG_NAMERD_API_NAMESPACE   "NAMESPACE"
 
#define DEF_NAMERD_API_NAMESPACE   "default"
 
#define REG_NAMERD_API_LOCATION   "LOCATION"
 
#define REG_NAMERD_API_ROLE   "ROLE"
 
#define REG_NAMERD_API_PROTOCOL   "PROTOCOL"
 
#define REG_NAMERD_API_ARGS   REG_CONN_ARGS
 
#define DEF_NAMERD_API_ARGS   "path=/service/"
 
#define REG_NAMERD_PROXY_HOST   REG_CONN_HTTP_PROXY_HOST
 
#define DEF_NAMERD_PROXY_HOST   "linkerd"
 
#define REG_NAMERD_PROXY_PORT   REG_CONN_HTTP_PROXY_PORT
 
#define DEF_NAMERD_PROXY_PORT   "4140"
 
#define REG_NAMERD_DTAB   "DTAB"
 
#define DEF_NAMERD_DTAB   ""
 
#define NAMERD_DTAB_ARG   "dtab"
 
#define NAMERD_LOCAL_BONUS   1.2
 
#define DTAB_HTTP_HEADER_TAG   "DTab-Local:"
 

Typedefs

typedef CONNECTOR(* FCreateConnector) (SERV_ITER iter)
 
typedef void *(* FSvcCpy) (void *dst, const void *src, size_t n)
 

Enumerations

enum  ENAMERD_Subcodes {
  eNSub_Message = 0 , eNSub_Alloc = 1 , eNSub_BadData = 2 , eNSub_TooLong = 3 ,
  eNSub_Connect = 4 , eNSub_Json = 5
}
 

Functions

static SSERV_Infos_GetNextInfo (SERV_ITER, HOST_INFO *)
 
static void s_Reset (SERV_ITER)
 
static void s_Close (SERV_ITER)
 
static CONNECTOR s_CreateConnectorHttp (SERV_ITER iter)
 
static CONNECTOR s_CreateConnectorMemory (SERV_ITER iter)
 
static void s_RemoveServerInfo (struct SNAMERD_Data *data, size_t n, int del, const char *name)
 
static void s_ProcessForStandby (struct SNAMERD_Data *data, const char *name)
 
static int s_AddServerInfo (struct SNAMERD_Data *data, SSERV_Info *info, const char *name)
 
static TNCBI_Time x_ParseExpires (const char *expires, time_t utc, const char *name, size_t i)
 
static const char * s_ReadFullResponse (CONN conn, const char *name)
 
static int s_ParseResponse (SERV_ITER iter, CONN conn)
 
static int s_Resolve (SERV_ITER iter)
 
static int s_IsUpdateNeeded (struct SNAMERD_Data *data, TNCBI_Time now, const char *name)
 
static SLB_Candidates_GetCandidate (void *user_data, size_t n)
 
static int x_UpdateDtabInArgs (SConnNetInfo *net_info, const char *dtab, const char *name)
 
static char * x_GetDtabFromHeader (const char *header, const char *name)
 
static const char * x_ReadLine (const char *path, char *line, size_t size)
 
static void * x_memlwrcpy (void *dst, const void *src, size_t n)
 
static char * x_Namespace (char *nspc, size_t size, const char *name)
 
static int x_SetupConnectionParams (const SERV_ITER iter)
 
const SSERV_VTableSERV_NAMERD_Open (SERV_ITER iter, const SConnNetInfo *net_info, SSERV_Info **info)
 
int SERV_NAMERD_SetConnectorSource (const char *mock_body)
 

Variables

static const SSERV_VTable kNamerdOp
 
static const char * s_mock_body = 0
 
static FCreateConnector s_CreateConnector = s_CreateConnectorHttp
 

Macro Definition Documentation

◆ DEBUG_PARAM

#define DEBUG_PARAM (   x)    , x

Definition at line 68 of file ncbi_namerd.c.

◆ DEF_NAMERD_API_ARGS

#define DEF_NAMERD_API_ARGS   "path=/service/"

Definition at line 121 of file ncbi_namerd.c.

◆ DEF_NAMERD_API_HOST

#define DEF_NAMERD_API_HOST   "namerd-api.linkerd.ncbi.nlm.nih.gov"

Definition at line 102 of file ncbi_namerd.c.

◆ DEF_NAMERD_API_HTTP_VERSION

#define DEF_NAMERD_API_HTTP_VERSION   0

Definition at line 99 of file ncbi_namerd.c.

◆ DEF_NAMERD_API_NAMESPACE

#define DEF_NAMERD_API_NAMESPACE   "default"

Definition at line 115 of file ncbi_namerd.c.

◆ DEF_NAMERD_API_PATH

#define DEF_NAMERD_API_PATH   "/api/1/resolve"

Definition at line 108 of file ncbi_namerd.c.

◆ DEF_NAMERD_API_PORT

#define DEF_NAMERD_API_PORT   0/*unsupported*/

Definition at line 105 of file ncbi_namerd.c.

◆ DEF_NAMERD_API_REQ_METHOD

#define DEF_NAMERD_API_REQ_METHOD   "GET"

Definition at line 96 of file ncbi_namerd.c.

◆ DEF_NAMERD_API_SCHEME

#define DEF_NAMERD_API_SCHEME   "http"

Definition at line 93 of file ncbi_namerd.c.

◆ DEF_NAMERD_DTAB

#define DEF_NAMERD_DTAB   ""

Definition at line 136 of file ncbi_namerd.c.

◆ DEF_NAMERD_PROXY_HOST

#define DEF_NAMERD_PROXY_HOST   "linkerd"

Definition at line 126 of file ncbi_namerd.c.

◆ DEF_NAMERD_PROXY_PORT

#define DEF_NAMERD_PROXY_PORT   "4140"

Definition at line 133 of file ncbi_namerd.c.

◆ DEF_NAMERD_REG_SECTION

#define DEF_NAMERD_REG_SECTION   "_NAMERD"

Definition at line 90 of file ncbi_namerd.c.

◆ DTAB_HTTP_HEADER_TAG

#define DTAB_HTTP_HEADER_TAG   "DTab-Local:"

Definition at line 145 of file ncbi_namerd.c.

◆ FMT_SIZE_T

#define FMT_SIZE_T   "%zu"

Definition at line 59 of file ncbi_namerd.c.

◆ FMT_TIME_T

#define FMT_TIME_T   "%lu"

Definition at line 60 of file ncbi_namerd.c.

◆ NAMERD_DTAB_ARG

#define NAMERD_DTAB_ARG   "dtab"

Definition at line 138 of file ncbi_namerd.c.

◆ NAMERD_LOCAL_BONUS

#define NAMERD_LOCAL_BONUS   1.2

Definition at line 142 of file ncbi_namerd.c.

◆ NCBI_USE_ERRCODE_X

#define NCBI_USE_ERRCODE_X   Connect_NamerdLinkerd

Definition at line 64 of file ncbi_namerd.c.

◆ REG_NAMERD_API_ARGS

#define REG_NAMERD_API_ARGS   REG_CONN_ARGS

Definition at line 120 of file ncbi_namerd.c.

◆ REG_NAMERD_API_ENV

#define REG_NAMERD_API_ENV   "ENV" /*deprecated*/

Definition at line 113 of file ncbi_namerd.c.

◆ REG_NAMERD_API_HOST

#define REG_NAMERD_API_HOST   REG_CONN_HOST

Definition at line 101 of file ncbi_namerd.c.

◆ REG_NAMERD_API_HTTP_VERSION

#define REG_NAMERD_API_HTTP_VERSION   REG_CONN_HTTP_VERSION

Definition at line 98 of file ncbi_namerd.c.

◆ REG_NAMERD_API_LOCATION

#define REG_NAMERD_API_LOCATION   "LOCATION"

Definition at line 116 of file ncbi_namerd.c.

◆ REG_NAMERD_API_NAMESPACE

#define REG_NAMERD_API_NAMESPACE   "NAMESPACE"

Definition at line 114 of file ncbi_namerd.c.

◆ REG_NAMERD_API_PATH

#define REG_NAMERD_API_PATH   REG_CONN_PATH

Definition at line 107 of file ncbi_namerd.c.

◆ REG_NAMERD_API_PORT

#define REG_NAMERD_API_PORT   REG_CONN_PORT

Definition at line 104 of file ncbi_namerd.c.

◆ REG_NAMERD_API_PROTOCOL

#define REG_NAMERD_API_PROTOCOL   "PROTOCOL"

Definition at line 118 of file ncbi_namerd.c.

◆ REG_NAMERD_API_REQ_METHOD

#define REG_NAMERD_API_REQ_METHOD   REG_CONN_REQ_METHOD

Definition at line 95 of file ncbi_namerd.c.

◆ REG_NAMERD_API_ROLE

#define REG_NAMERD_API_ROLE   "ROLE"

Definition at line 117 of file ncbi_namerd.c.

◆ REG_NAMERD_API_SCHEME

#define REG_NAMERD_API_SCHEME   "SCHEME"

Definition at line 92 of file ncbi_namerd.c.

◆ REG_NAMERD_DTAB

#define REG_NAMERD_DTAB   "DTAB"

Definition at line 135 of file ncbi_namerd.c.

◆ REG_NAMERD_PROXY_HOST

#define REG_NAMERD_PROXY_HOST   REG_CONN_HTTP_PROXY_HOST

Definition at line 123 of file ncbi_namerd.c.

◆ REG_NAMERD_PROXY_PORT

#define REG_NAMERD_PROXY_PORT   REG_CONN_HTTP_PROXY_PORT

Definition at line 132 of file ncbi_namerd.c.

Typedef Documentation

◆ FCreateConnector

typedef CONNECTOR(* FCreateConnector) (SERV_ITER iter)

Definition at line 186 of file ncbi_namerd.c.

◆ FSvcCpy

typedef void*(* FSvcCpy) (void *dst, const void *src, size_t n)

Definition at line 1217 of file ncbi_namerd.c.

Enumeration Type Documentation

◆ ENAMERD_Subcodes

Enumerator
eNSub_Message 

not an error

eNSub_Alloc 

memory allocation failed

eNSub_BadData 

bad data was provided

eNSub_TooLong 

data was too long to fit in a buffer

eNSub_Connect 

problem in connect library

eNSub_Json 

a JSON parsing failure

Definition at line 75 of file ncbi_namerd.c.

Function Documentation

◆ s_AddServerInfo()

static int s_AddServerInfo ( struct SNAMERD_Data data,
SSERV_Info info,
const char *  name 
)
static

◆ s_Close()

static void s_Close ( SERV_ITER  iter)
static

◆ s_CreateConnectorHttp()

static CONNECTOR s_CreateConnectorHttp ( SERV_ITER  iter)
static

◆ s_CreateConnectorMemory()

static CONNECTOR s_CreateConnectorMemory ( SERV_ITER  iter)
static

◆ s_GetCandidate()

static SLB_Candidate* s_GetCandidate ( void *  user_data,
size_t  n 
)
static

Definition at line 880 of file ncbi_namerd.c.

References SNAMERD_Data::cand, n, and SNAMERD_Data::n_cand.

Referenced by s_GetNextInfo().

◆ s_GetNextInfo()

static SSERV_Info * s_GetNextInfo ( SERV_ITER  iter,
HOST_INFO host_info 
)
static

◆ s_IsUpdateNeeded()

static int s_IsUpdateNeeded ( struct SNAMERD_Data data,
TNCBI_Time  now,
const char *  name 
)
static

◆ s_ParseResponse()

static int s_ParseResponse ( SERV_ITER  iter,
CONN  conn 
)
static

◆ s_ProcessForStandby()

static void s_ProcessForStandby ( struct SNAMERD_Data data,
const char *  name 
)
static

◆ s_ReadFullResponse()

static const char* s_ReadFullResponse ( CONN  conn,
const char *  name 
)
static

◆ s_RemoveServerInfo()

static void s_RemoveServerInfo ( struct SNAMERD_Data data,
size_t  n,
int  del,
const char *  name 
)
static

◆ s_Reset()

static void s_Reset ( SERV_ITER  iter)
static

◆ s_Resolve()

static int s_Resolve ( SERV_ITER  iter)
static

◆ SERV_NAMERD_Open()

const SSERV_VTable* SERV_NAMERD_Open ( SERV_ITER  iter,
const SConnNetInfo net_info,
SSERV_Info **  info 
)

◆ SERV_NAMERD_SetConnectorSource()

int SERV_NAMERD_SetConnectorSource ( const char *  mock_body)

◆ x_GetDtabFromHeader()

static char* x_GetDtabFromHeader ( const char *  header,
const char *  name 
)
static

Definition at line 1041 of file ncbi_namerd.c.

References CORE_TRACEF, DTAB_HTTP_HEADER_TAG, isspace(), strncasecmp, and strndup.

Referenced by x_SetupConnectionParams().

◆ x_memlwrcpy()

static void* x_memlwrcpy ( void *  dst,
const void *  src,
size_t  n 
)
static

Definition at line 1099 of file ncbi_namerd.c.

References n, and tolower().

Referenced by x_Namespace(), and x_SetupConnectionParams().

◆ x_Namespace()

static char* x_Namespace ( char *  nspc,
size_t  size,
const char *  name 
)
static

◆ x_ParseExpires()

static TNCBI_Time x_ParseExpires ( const char *  expires,
time_t  utc,
const char *  name,
size_t  i 
)
static

◆ x_ReadLine()

static const char* x_ReadLine ( const char *  path,
char *  line,
size_t  size 
)
static

Definition at line 1081 of file ncbi_namerd.c.

References fp, len, and ncbi::grid::netcache::search::fields::size.

Referenced by x_Namespace().

◆ x_SetupConnectionParams()

static int x_SetupConnectionParams ( const SERV_ITER  iter)
static

Definition at line 1221 of file ncbi_namerd.c.

References SSERV_IterTag::arg, SSERV_IterTag::arglen, buf, CONN_PATH_LEN, ConnNetInfo_AddPath(), ConnNetInfo_GetValueService(), ConnNetInfo_OverrideUserHeader(), ConnNetInfo_PreOverrideArg(), ConnNetInfo_SetPath(), CORE_LOGF_ERRNO_X, CORE_LOGF_X, SSERV_IterTag::data, DEBUG_PARAM, DEF_NAMERD_API_ARGS, DEF_NAMERD_API_HOST, DEF_NAMERD_API_HTTP_VERSION, DEF_NAMERD_API_PATH, DEF_NAMERD_API_PORT, DEF_NAMERD_API_REQ_METHOD, DEF_NAMERD_API_SCHEME, DEF_NAMERD_DTAB, DEF_NAMERD_PROXY_HOST, DEF_NAMERD_PROXY_PORT, DEF_NAMERD_REG_SECTION, DTAB_HTTP_HEADER_TAG, eLOG_Critical, eLOG_Error, eNSub_Alloc, eNSub_BadData, eNSub_TooLong, eReqMethod_Any, eReqMethod_Get, eReqMethod_Post, eURL_Http, eURL_Https, eURL_Unspec, SSERV_IterTag::exact, fProxy_Http, free(), SConnNetInfo::host, SConnNetInfo::http_proxy_host, SConnNetInfo::http_proxy_mask, SConnNetInfo::http_proxy_port, SConnNetInfo::http_user_header, SConnNetInfo::http_version, len, n, SSERV_IterTag::name, NCBI_HasSpaces(), SNAMERD_Data::net_info, SConnNetInfo::port, REG_NAMERD_API_ARGS, REG_NAMERD_API_HOST, REG_NAMERD_API_HTTP_VERSION, REG_NAMERD_API_PATH, REG_NAMERD_API_PORT, REG_NAMERD_API_REQ_METHOD, REG_NAMERD_API_SCHEME, REG_NAMERD_DTAB, REG_NAMERD_PROXY_HOST, REG_NAMERD_PROXY_PORT, SConnNetInfo::req_method, SConnNetInfo::scheme, strcasecmp, strupr, SSERV_IterTag::val, SSERV_IterTag::vallen, x_GetDtabFromHeader(), x_memlwrcpy(), x_Namespace(), and x_UpdateDtabInArgs().

Referenced by SERV_NAMERD_Open().

◆ x_UpdateDtabInArgs()

static int x_UpdateDtabInArgs ( SConnNetInfo net_info,
const char *  dtab,
const char *  name 
)
static

Variable Documentation

◆ kNamerdOp

const SSERV_VTable kNamerdOp
static
Initial value:
= {
s_GetNextInfo, 0, 0, s_Reset, s_Close, "NAMERD"
}
static void s_Close(SERV_ITER)
Definition: ncbi_namerd.c:952
static void s_Reset(SERV_ITER)
Definition: ncbi_namerd.c:926
static SSERV_Info * s_GetNextInfo(SERV_ITER, HOST_INFO *)
Definition: ncbi_namerd.c:887

Definition at line 156 of file ncbi_namerd.c.

Referenced by SERV_NAMERD_Open().

◆ s_CreateConnector

FCreateConnector s_CreateConnector = s_CreateConnectorHttp
static

Definition at line 187 of file ncbi_namerd.c.

Referenced by s_Resolve(), and SERV_NAMERD_SetConnectorSource().

◆ s_mock_body

const char* s_mock_body = 0
static

Definition at line 178 of file ncbi_namerd.c.

Referenced by s_CreateConnectorMemory(), and SERV_NAMERD_SetConnectorSource().

Modified on Mon Mar 04 05:11:10 2024 by modify_doxy.py rev. 669887