39 #ifdef NCBI_CXX_TOOLKIT
49 #define NCBI_USE_ERRCODE_X Connect_Service
63 #define SERV_SERVICE_NAME_RECURSION_MAX 10
64 #define CONN_IMPLICIT_SERVER_TYPE DEF_CONN_REG_SECTION \
65 "_" REG_CONN_IMPLICIT_SERVER_TYPE
71 static char*
x_getenv(
const char* name)
73 char*
env = getenv(name);
79 # define x_getenv getenv
107 const char* service,
const char* svc,
108 int ismask,
int* isfast)
117 if (!svc || (!ismask && (!*svc || strpbrk(svc,
"?*[")))
120 if (!service ||
strcasecmp(service, svc) == 0)
123 (
"%s%s%s%s service name%s%s",
124 !svc || !*svc ?
"" :
"[",
126 !svc || !*svc ?
"" :
"] ",
127 !svc ?
"NULL" : !*svc ?
"Empty"
129 ?
"Invalid" :
"Too long",
130 *service ?
" for: " :
"", service));
133 if (!ismask && !*isfast) {
156 CORE_TRACEF((
"[%s] CONN_ServiceName(\"%s\"): \"%s\"",
162 (
"[%s] Maximal service name recursion"
163 " depth exceeded: %u", service,
depth));
166 svc = s, *isfast = 1;
176 int ismask,
int* isfast)
217 ? realloc((
void*) iter->
skip,
n *
sizeof(*temp))
218 :
malloc (
n *
sizeof(*temp)));
244 #define s_IsMapperConfigured(s, k) x_IsMapperConfigured(s, k, s_Fast)
256 unsigned int preferred_host,
257 unsigned short preferred_port,
273 #ifdef NCBI_CXX_TOOLKIT
298 iter->
port = preferred_port;
299 iter->
pref = (preference < 0.0
301 : 0.01 * (preference > 100.0
323 iter->
arglen = strlen(arg);
335 for (
i = 0;
i < n_skip; ++
i) {
369 #ifdef NCBI_CXX_TOOLKIT
370 do_linkerd = do_namerd =
440 && !do_linkerd && !do_namerd
448 (
"%s%s%s%s%sNo service mappers available",
449 &
"["[!*service], service,
450 &
"/"[!svc], svc ? svc :
"",
451 *service ?
"] " :
""));
469 while (n < iter->n_skip) {
477 memmove((
void*) ptr, (
void*)(ptr + 1),
478 (iter->
n_skip -
n) *
sizeof(*ptr));
487 #if defined(_DEBUG) && !defined(NDEBUG)
489 #define x_RETURN(retval) return x_Return((SSERV_Info*) info, infostr, retval)
500 free((
void*) infostr);
518 (
"[%s] NULL name @%p\n%s", iter->
name,
info,
519 infostr ? infostr :
"<NULL>"));
524 (
"[%s] %s name \"%s\" @%p\n%s", iter->
name,
525 *name ?
"Unexpected" :
"Empty", name,
526 info, infostr ? infostr :
"<NULL>"));
532 (
"[%s] Non-DNS server with empty %s @%p:\n%s",
534 :
info->host ?
"port" :
"host",
535 info, infostr ? infostr :
"<NULL>"));
540 (
"[%s] Interim DNS server w/o host @%p:\n%s",
541 iter->
name,
info, infostr ? infostr :
"<NULL>"));
551 (
"[%s] Expired entry (%u < %u) @%p:\n%s", iter->
name,
553 info, infostr ? infostr :
"<NULL>"));
560 (
"[%s] Excessive expiration (%u) @%p:\n%s", iter->
name,
562 info, infostr ? infostr :
"<NULL>"));
569 (
"[%s] Firewall DNS entry not allowed @%p:\n%s",
570 iter->
name,
info, infostr ? infostr :
"<NULL>"));
575 (
"[%s] Firewall entry with %s%s%s @%p:\n%s", iter->
name,
576 info->vhost ?
"vhost" :
"",
577 info->extra &&
info->vhost ?
" and " :
"",
578 info->extra ?
"extra" :
"",
579 info, infostr ? infostr :
"<NULL>"));
586 (
"[%s] DNS entry cannot be private @%p:\n%s",
587 iter->
name,
info, infostr ? infostr :
"<NULL>"));
592 (
"[%s] DNS entry cannot be stateful @%p:\n%s",
593 iter->
name,
info, infostr ? infostr :
"<NULL>"));
598 (
"[%s] DNS entry cannot be secure @%p:\n%s",
599 iter->
name,
info, infostr ? infostr :
"<NULL>"));
606 (
"[%s] DNS entry with MIME type @%p:\n%s", iter->
name,
607 info, infostr ? infostr :
"<NULL>"));
613 (
"[%s] HTTP entry cannot be stateful @%p:\n%s", iter->
name,
614 info, infostr ? infostr :
"<NULL>"));
621 (
"[%s] DNS entry unwarranted @%p:\n%s", iter->
name,
622 info, infostr ? infostr :
"<NULL>"));
631 (
"[%s] Mismatched type 0x%X vs 0x%X @%p:\n%s",
633 ?
info->u.firewall.type
635 info, infostr ? infostr :
"<NULL>"));
641 (
"[%s] Local/private entry for external @%p:\n%s",
642 iter->
name,
info, infostr ? infostr :
"<NULL>"));
648 (
"[%s] Private entry unwarranted @%p:\n%s", iter->
name,
649 info, infostr ? infostr :
"<NULL>"));
654 (
"[%s] Stateful entry in stateless search @%p:\n%s",
655 iter->
name,
info, infostr ? infostr :
"<NULL>"));
661 (
"[%s] Off entry not allowed @%p:\n%s", iter->
name,
662 info, infostr ? infostr :
"<NULL>"));
667 (
"[%s] Suppressed entry unwarranted @%p:\n%s",
668 iter->
name,
info, infostr ? infostr :
"<NULL>"));
673 (
"[%s] Down entry unwarranted @%p:\n%s", iter->
name,
674 info, infostr ? infostr :
"<NULL>"));
679 (
"[%s] Reserved entry unwarranted @%p:\n%s", iter->
name,
680 info, infostr ? infostr :
"<NULL>"));
687 (
"[%s] Standby entry unwarranted @%p:\n%s",
688 iter->
name,
info, infostr? infostr :
"<NULL>"));
699 (
"[%s] Entry is a duplicate of @%p and must be skipped"
700 " @%p:\n%s%s%s%s", iter->
name, skip,
info,
701 &
"\""[!*name], name, *name ?
"\" " :
"",
702 infostr ? infostr :
"<NULL>"));
708 iter->
name,
info, &
"\""[!*name], name,
709 *name ?
"\" " :
"", infostr ? infostr :
"<NULL>"));
759 unsigned int preferred_host,
760 unsigned short preferred_port,
773 preferred_host, preferred_port, preference,
774 net_info, skip, n_skip,
811 unsigned int preferred_host,
815 preferred_host, 0, 0.0,
824 unsigned int preferred_host,
830 preferred_host, 0, 0.0,
831 net_info, skip, n_skip,
839 unsigned int preferred_host,
840 unsigned short preferred_port,
850 service && (!*service || strpbrk(service,
"?*[")),
types,
851 preferred_host, preferred_port, preference,
852 net_info, skip, n_skip,
874 unsigned int preferred_host,
888 unsigned int preferred_host,
897 net_info, skip, n_skip,
905 unsigned int preferred_host,
906 unsigned short preferred_port,
918 preferred_host, preferred_port, preference,
919 net_info, skip, n_skip,
953 return name && *name ? name : iter->
name;
962 return iter->
op->
Feedback(iter, fine, time ? time : 1);
1016 static const char used_server_info[] =
"Used-Server-Info-";
1021 for (s =
text; (c = strchr(s,
'\n')) != 0; s = c + 1) {
1022 size_t len = (size_t)(c - s);
1031 if (q[
len - 1] ==
'\r')
1038 if (!
strncasecmp(p, used_server_info,
sizeof(used_server_info) - 1)
1039 &&
isdigit((
unsigned char) p[
sizeof(used_server_info) - 1])) {
1040 p +=
sizeof(used_server_info) - 1;
1041 if (sscanf(p,
"%u: %n", &d1, &d2) >= 1
1057 static const char kAcceptedServerTypes[] =
"Accepted-Server-Types:";
1058 static const char kClientRevision[] =
"Client-Revision: %u.%u\r\n";
1059 static const char kUsedServerInfo[] =
"Used-Server-Info: ";
1060 static const char kNcbiExternal[] =
NCBI_EXTERNAL ": Y\r\n";
1061 static const char kNcbiFWPorts[] =
"NCBI-Firewall-Ports: ";
1062 static const char kPreference[] =
"Preference: ";
1063 static const char kSkipInfo[] =
"Skip-Info-%u: ";
1064 static const char kAffinity[] =
"Affinity: ";
1070 buflen = (size_t) sprintf(
buffer, kClientRevision,
1082 if (!
BUF_Write(&
buf, kNcbiExternal,
sizeof(kNcbiExternal)-1)) {
1091 for (
t = 1;
t;
t <<= 1) {
1094 size_t namelen = strlen(name);
1097 if (buflen + namelen + (1 + 2) >
sizeof(
buffer))
1100 memcpy(
buffer + buflen, name, namelen);
1106 memcpy(
buffer + buflen,
"\r\n", 2);
1108 sizeof(kAcceptedServerTypes) - 1)
1121 && (!
BUF_Write(&
buf, kNcbiFWPorts,
sizeof(kNcbiFWPorts)-1) ||
1134 iter->
pref * 100.0, 2),
1136 if (!
BUF_Write(&
buf, kPreference,
sizeof(kPreference) - 1) ||
1144 if (!
BUF_Write(&
buf, kAffinity,
sizeof(kAffinity) - 1) ||
1160 size_t namelen = name && *name ? strlen(name) : 0;
1163 if (but_last && iter->
last == iter->
skip[
i]) {
1164 buflen =
sizeof(kUsedServerInfo) - 1;
1165 memcpy(
buffer, kUsedServerInfo, buflen);
1167 buflen = (size_t) sprintf(
buffer, kSkipInfo, (
unsigned)
i + 1);
1179 if (i < iter->n_skip) {
1186 if ((
str = (
char*)
malloc(buflen + 1)) != 0) {
1204 unsigned short port;
1243 + 2) + strlen(typ))) {
1264 # ifdef NCBI_OS_MSWIN
1265 # define putenv _putenv
1279 #define SERV_MERGE(a, b) a ## b
1281 #define SERV_GET_IMPLICIT_SERVER_TYPE(variant) \
1282 ESERV_Type SERV_MERGE(SERV_GetImplicitServerType, variant) \
1283 (const char* service) \
1289 if (!SERV_MERGE(ConnNetInfo_GetValue, variant) \
1290 (service, REG_CONN_IMPLICIT_SERVER_TYPE, val, sizeof(val), 0) \
1291 || !*val || !(end = SERV_ReadType(val, &type)) || *end) { \
1292 return SERV_GetImplicitServerTypeDefault(); \
1299 #define SERV_GET_IMPLICIT_SERVER_TYPE_PUBLIC_API
1301 #undef SERV_GET_IMPLICIT_SERVER_TYPE_PUBLIC_API
1308 #undef SERV_GET_IMPLICIT_SERVER_TYPE
1325 return info->host == host ? 1 : 0;
static unsigned char depth[2 *(256+1+29)+1]
int BUF_Write(BUF *pBuf, const void *data, size_t size)
size_t BUF_Read(BUF buf, void *data, size_t size)
void BUF_Destroy(BUF buf)
SSERV_InfoCPtr SERV_GetNextInfo(SERV_ITER iter)
Same as "SERV_GetNextInfoEx(., 0)" – i.e.
void SERV_Close(SERV_ITER iter)
Deallocate the iterator.
SSERV_Info * SERV_GetInfoEx(const char *service, TSERV_Type types, unsigned int preferred_host, const SConnNetInfo *net_info, SSERV_InfoCPtr skip[], size_t n_skip, HOST_INFO *host_info)
A "fast track" routine equivalent to creating of an iterator as with SERV_OpenEx(),...
SSERV_Info * SERV_GetInfoSimple(const char *service)
Equivalent to "SERV_GetInfo(., fSERV_Any, SERV_ANYHOST, ConnNetInfo_Crea...
int SERV_SetImplicitServerType(const char *service, ESERV_Type type)
Set a server type to use when a service mapper returns typeless entries for the given service name (t...
SSERV_FirewallInfo firewall
void SERV_Reset(SERV_ITER iter)
Reset the iterator to the state as if it has just been opened.
int SERV_Penalize(SERV_ITER iter, double fine)
Penalize the server returned last from SERV_GetNextInfo[Ex]().
unsigned short SERV_ServerPort(const char *name, unsigned int host)
Obtain a port number that corresponds to the named (standalone) service declared at the specified hos...
const char * SERV_TypeStr(ESERV_Type type)
SSERV_Info * SERV_GetInfo(const char *service, TSERV_Type types, unsigned int preferred_host, const SConnNetInfo *net_info)
Same as "SERV_GetInfoEx(., ., ., ., 0, 0, 0)" – i.e.
SERV_ITER SERV_OpenEx(const char *service, TSERV_Type types, unsigned int preferred_host, const SConnNetInfo *net_info, SSERV_InfoCPtr skip[], size_t n_skip)
Create an iterator for sequential server lookup.
SERV_ITER SERV_Open(const char *service, TSERV_Type types, unsigned int preferred_host, const SConnNetInfo *net_info)
Same as "SERV_OpenEx(., ., ., ., 0, 0)" – i.e.
char * SERV_WriteInfo(const SSERV_Info *info)
unsigned int TSERV_Type
Bitwise OR of ESERV_Type[Special].
unsigned short TSERV_TypeOnly
Server type only, w/o specials.
int SERV_Rerate(SERV_ITER iter, double rate)
Rerate the server returned last from SERV_GetNextInfo[Ex]().
SERV_ITER SERV_OpenSimple(const char *service)
Allocate an iterator and consult either local databases (if any present), or network database,...
#define SERV_CLIENT_REVISION_MAJOR
Revision 7.0.
#define SERV_CLIENT_REVISION_MINOR
#define SERV_LOCALHOST
Special values for the "preferred_host" parameter.
int SERV_EqualInfo(const SSERV_Info *info1, const SSERV_Info *info2)
SSERV_InfoCPtr SERV_GetNextInfoEx(SERV_ITER iter, HOST_INFO *host_info)
Get the next server meta-address, optionally accompanied by the host parameters made available by the...
@ fSERV_ReverseDns
LB-DNS translation.
@ fSERV_IncludeSuppressed
@ fSERV_All
Server type mask.
@ fSERV_Stateless
Stateless servers only.
@ fSERV_Promiscuous
Evrthng and the kitchen sink.
size_t SOCK_HostPortToString(unsigned int host, unsigned short port, char *buf, size_t bufsize)
Print numeric string "host:port" into a buffer provided, not to exceed 'bufsize' bytes (including the...
unsigned int SOCK_GetLocalHostAddress(ESwitch reget)
Get (and cache for faster follow-up retrievals) IPv4 address of local host.
#define REG_CONN_LBSMD_DISABLE
enum ENcbiSwitch ESwitch
Aux.
#define REG_CONN_LINKERD_ENABLE
#define REG_CONN_LBDNS_ENABLE
#define REG_CONN_LOCAL_ENABLE
#define NCBI_TIME_INFINITE
#define REG_CONN_NAMERD_ENABLE
#define REG_CONN_DISPD_DISABLE
SConnNetInfo * ConnNetInfo_Create(const char *service)
int ConnNetInfo_Boolean(const char *str)
#define REG_CONN_SERVICE_NAME
void ConnNetInfo_Destroy(SConnNetInfo *net_info)
@ eREG_Transient
only in-memory storage while program runs
@ eFWMode_Legacy
Relay, no firewall.
static void text(MDB_val *v)
const struct ncbi::grid::netcache::search::fields::KEY key
int NCBI_HasSpaces(const char *s, size_t n)
Return non-zero(true) if a block of memory based at "s" and of size "n" has any space characters (as ...
char * NCBI_simple_ftoa(char *s, double f, int p)
Locale-independent double-to-ASCII conversion of value "f" into a character buffer pointed to by "s",...
#define LBSM_DEFAULT_TIME
const char * ConnNetInfo_GetValueInternal(const char *service, const char *param, char *value, size_t value_size, const char *def_value)
void SERV_PrintFirewallPorts(char *buf, size_t bufsize, EFWMode mode)
const SSERV_VTable * SERV_DISPD_Open(SERV_ITER iter, const SConnNetInfo *net_info, SSERV_Info **info)
const SSERV_VTable * SERV_LBDNS_Open(SERV_ITER iter, SSERV_Info **info)
const SSERV_VTable * SERV_LBSMD_Open(SERV_ITER iter, SSERV_Info **info, HOST_INFO *host_info, int no_dispd_follows)
const SSERV_VTable * SERV_LINKERD_Open(SERV_ITER iter, const SConnNetInfo *net_info, SSERV_Info **info, int *do_namerd)
const SSERV_VTable * SERV_LOCAL_Open(SERV_ITER iter, SSERV_Info **info)
const SSERV_VTable * SERV_NAMERD_Open(SERV_ITER iter, const SConnNetInfo *net_info, SSERV_Info **info)
#define CORE_REG_GET(section, name, value, value_size, def_value)
#define CORE_DEBUG_ARG(arg)
#define CORE_REG_SET(section, name, value, storage)
#define CORE_LOGF_X(subcode, level, fmt_args)
#define CORE_TRACEF(fmt_args)
#define CORE_LOGF(level, fmt_args)
SSERV_Info * SERV_ReadInfoEx(const char *str, const char *name, int lazy)
SSERV_Info * SERV_CopyInfoEx(const SSERV_Info *orig, const char *name)
const char * SERV_NameOfInfo(const SSERV_Info *info)
static SERV_ITER s_Open(const char *service, int ismask, TSERV_Type types, unsigned int preferred_host, unsigned short preferred_port, double preference, const SConnNetInfo *net_info, SSERV_InfoCPtr skip[], size_t n_skip, int external, const char *arg, const char *val, SSERV_Info **info, HOST_INFO *host_info)
#define CONN_IMPLICIT_SERVER_TYPE
static void s_SkipSkip(SERV_ITER iter)
static int s_AddSkipInfo(SERV_ITER iter, const char *name, SSERV_InfoCPtr info)
#define SERV_GET_IMPLICIT_SERVER_TYPE(variant)
#define SERV_GET_IMPLICIT_SERVER_TYPE_PUBLIC_API
int SERV_IsMapperConfiguredInternal(const char *svc, const char *key)
#define SERV_SERVICE_NAME_RECURSION_MAX
SSERV_Info * SERV_GetInfoP(const char *service, TSERV_Type types, unsigned int preferred_host, unsigned short preferred_port, double preference, const SConnNetInfo *net_info, SSERV_InfoCPtr skip[], size_t n_skip, int external, const char *arg, const char *val, HOST_INFO *host_info)
char * SERV_ServiceName(const char *service)
static SERV_ITER x_Open(const char *service, int ismask, TSERV_Type types, unsigned int preferred_host, unsigned short preferred_port, double preference, const SConnNetInfo *net_info, SSERV_InfoCPtr skip[], size_t n_skip, int external, const char *arg, const char *val, SSERV_Info **info, HOST_INFO *host_info)
int SERV_Update(SERV_ITER iter, const char *text, int code)
const char * SERV_CurrentName(SERV_ITER iter)
static int x_tr(char *str, char a, char b, size_t len)
int SERV_PenalizeEx(SERV_ITER iter, double fine, TNCBI_Time time)
#define s_IsMapperConfigured(s, k)
static int x_Return(SSERV_Info *info, const char *infostr, int retval)
static int x_IsMapperConfigured(const char *svc, const char *key, int fast)
static char * s_ServiceName(const char *service, int ismask, int *isfast)
static SSERV_Info * s_GetNextInfo(SERV_ITER iter, HOST_INFO *host_info, int internal)
ESERV_Type SERV_GetImplicitServerTypeDefault(void)
char * SERV_Print(SERV_ITER iter, const SConnNetInfo *net_info, int but_last)
ESwitch SERV_DoFastOpens(ESwitch on)
SERV_ITER SERV_OpenP(const char *service, TSERV_Type types, unsigned int preferred_host, unsigned short preferred_port, double preference, const SConnNetInfo *net_info, SSERV_InfoCPtr skip[], size_t n_skip, int external, const char *arg, const char *val)
static int x_ConsistencyCheck(SERV_ITER iter, const SSERV_Info *info)
static char * x_ServiceName(unsigned int depth, const char *service, const char *svc, int ismask, int *isfast)
const char * SERV_MapperName(SERV_ITER iter)
#define SERV_IsReserved(i)
#define SERV_IfSuppressed(i)
#define SERV_IsStandby(i)
Int4 delta(size_t dimension_, const Int4 *score_)
static pcre_uint8 * buffer
static const char * str(char *buf, int n)
void(* Reset)(SERV_ITER iter)
SSERV_Info *(* GetNextInfo)(SERV_ITER iter, HOST_INFO *host_info)
void(* Close)(SERV_ITER iter)
int(* Update)(SERV_ITER iter, const char *text, int code)
int(* Feedback)(SERV_ITER iter, double rate, TNCBI_Time fine)
static const struct type types[]
voidp calloc(uInt items, uInt size)