43 #define NCBI_USE_ERRCODE_X Connect_Service
106 (
"[%s] Service not found", uuu->
name));
138 int user_callback_enabled)
140 static const char kStateless[] =
"TRY_STATELESS";
141 static const size_t kSLen =
sizeof(kStateless) - 1;
150 if (server_error || !header_parse)
157 if (user_callback_enabled && !uuu->
warned)
160 while (header && *header) {
163 if (user_callback_enabled || uuu->
host)
166 while (*header &&
isspace((
unsigned char)(*header)))
169 (!header[kSLen] ||
isspace((
unsigned char) header[kSLen]))) {
171 uuu->
host = (
unsigned int)(-1);
172 #if defined(_DEBUG) && !defined(NDEBUG)
175 (
"[%s] Fallback to stateless", uuu->
name));
179 unsigned int i1, i2, i3, i4, tkt,
n, m;
180 unsigned char o1, o2, o3, o4;
183 if (sscanf(header,
"%u.%u.%u.%u%n", &i1, &i2, &i3, &i4, &
n) < 4
184 || sscanf(header +
n,
"%hu%x%n", &uuu->
port, &tkt, &m) < 2
185 || (header[m +=
n] && !(header[m] ==
'$') &&
186 !
isspace((
unsigned char)((header + m)
187 [header[m] ==
'$'])))) {
190 o1 = (
unsigned char) i1;
191 o2 = (
unsigned char) i2;
192 o3 = (
unsigned char) i3;
193 o4 = (
unsigned char) i4;
194 sprintf(ipaddr,
"%u.%u.%u.%u", o1, o2, o3, o4);
201 if (header[m] ==
'$')
205 if ((header = strchr(header,
'\n')) != 0)
209 if (header && *header)
211 else if (!header_parse)
261 &&
isspace((
unsigned char) s[kCTLen])) {
262 #if defined(_DEBUG) && !defined(NDEBUG)
280 for (s += kCTLen + 1; *s; ++s) {
281 if (!
isspace((
unsigned char)(*s)))
284 if (!(c = strchr(s,
'\n')))
286 if (c > s && c[-1] ==
'\r')
288 len = (size_t)(c - s);
298 (
"[%s] Content-Type mismatch: "
299 "%s%s%s%s%s%s%s", service,
300 t && *
t ?
"specified=<" :
"",
303 t && *
t && *c_t ?
", " :
"",
304 *c_t ?
"configured=<" :
"",
322 const char* cgi_path,
323 const char* cgi_args,
325 const char* static_header,
329 const char* extend_header)
331 const char *retval = 0;
341 size_t sh_len = static_header ? strlen(static_header) : 0;
342 size_t eh_len = extend_header ? strlen(extend_header) : 0;
353 if ((
len += sh_len + eh_len) != 0) {
358 memcpy(temp, static_header, sh_len);
362 memcpy(temp, extend_header, eh_len);
373 if (retval && *retval)
374 free((
void*) retval);
412 static char*
x_HostPort(
const char* host,
unsigned short aport)
414 char* hostport, port[16];
415 size_t hostlen = strlen(host);
416 size_t portlen = (size_t) sprintf(port,
":%hu", aport) + 1;
417 hostport = (
char*)
malloc(hostlen + portlen);
419 memcpy(hostport, host, hostlen);
420 memcpy(hostport + hostlen, port, portlen);
433 const char* hostport,
495 net_info->
user[0] =
'\0';
496 net_info->
pass[0] =
'\0';
497 net_info->
path[0] =
'\0';
562 sizeof(net_info->
host) - (
size_t)(2*ipv6),
565 *net_info->
host =
'\0';
569 *net_info->
host =
'[';
573 }
else if (
info->host) {
577 *net_info->
host =
'\0';
607 const char* user_header;
614 if (
n == (
unsigned int)(-1))
627 switch (
info->type) {
629 user_header =
"Connection-Mode: STATELESS\r\n";
635 user_header,
info->mime_t,
642 user_header =
"Client-Mode: STATELESS_ONLY\r\n";
652 user_header,
info->mime_t,
658 user_header =
"Client-Mode: STATELESS_ONLY\r\n";
662 user_header,
info->mime_t,
707 assert(mapper && *mapper);
716 net_info->
scheme = scheme;
718 }
else if ((
str =
strdup(mapper)) != 0) {
719 const char* args = strchr(net_info->
path,
'?');
721 const char* name = iter->
name;
730 if (!(referer = (
char*) realloc(
str,
731 3 + 1 + 1 + (
len << 1) +
732 strlen(host) + (args && args[1]
734 : 9 + strlen(name))))){
739 str += sprintf(
str,
"://%s/", host);
745 strcpy(strcpy(
str,
"?service=") + 9, name);
772 const char* user_header;
790 switch (
info->type) {
798 ?
"Connection-Mode: STATELESS\r\n"
800 :
"Connection-Mode: STATEFUL\r\n";
805 0, user_header,
info->mime_t,
818 user_header =
"Client-Mode: STATELESS_ONLY\r\n";
823 0, user_header,
info->mime_t,
838 user_header =
"Client-Mode: STATELESS_ONLY\r\n";
841 0, user_header,
info->mime_t,
860 ?
info->u.firewall.type
872 mime_t =
info->mime_t;
873 mime_s =
info->mime_s;
874 mime_e =
info->mime_e;
884 ?
"Client-Mode: STATELESS_ONLY\r\n"
885 :
"Client-Mode: STATEFUL_CAPABLE\r\n");
888 0, user_header, mime_t,
894 if ((iter_header =
SERV_Print(iter, net_info, but_last)) != 0) {
896 if ((uh_len = strlen(user_header)) > 0) {
898 size_t ih_len = strlen(iter_header);
899 if ((ih = (
char*) realloc(iter_header, ++uh_len + ih_len)) != 0) {
900 memcpy(ih + ih_len, user_header, uh_len);
903 free((
void*) user_header);
905 user_header = iter_header;
906 }
else if (!*user_header)
920 (net_info,
"User-Agent: NCBIServiceConnector/"
960 aux_status != eIO_Closed &&
961 *status < aux_status) {
962 *status = aux_status;
973 (
"[%s] Unable to create auxiliary HTTP %s%s%s",
974 uuu->
name, c ?
"connection" :
"connector",
978 if (uuu->
host == (
unsigned int)(-1)) {
984 return s_Open(uuu, timeout,
info, net_info, status);
995 (
"[%s] Firewall port :%hu is not in the fallback set",
1011 else if (!net_info->
scheme)
1138 c =
s_Open(uuu, timeout,
info, net_info, &status);
1153 memset(&uuu->
meta, 0,
sizeof(uuu->
meta));
1157 status = meta_status;
1164 c->
next = meta->list;
1169 else if (!uuu->
descr) {
1183 size_t nlen = strlen(uuu->
name);
1184 size_t tlen = strlen(
type);
1185 char* temp = (
char*)
malloc(nlen + tlen + 2);
1187 memcpy(temp, uuu->
name, nlen);
1189 memcpy(temp + nlen,
type, tlen);
1190 temp[nlen + tlen] =
'\0';
1197 s_Close(connector, timeout, 0);
1211 (
"[%s] %s connection failure (%s) usually"
1212 " indicates possible firewall configuration"
1213 " problem(s); please consult <%s>", uuu->
name,
1218 s_Close(connector, timeout, 0);
1223 (
"[%s] Too many failed attempts (%hu), giving up",
1240 return s_Close(connector, timeout, 1);
1311 x_net_info = (net_info
1322 memcpy((
char*) xxx->
name, name,
len);
1343 memcpy(&xxx->
extra, extra,
sizeof(xxx->
extra));
static const char * kContentType
static void cleanup(void)
static CS_CONNECTION * conn
static void DLIST_NAME() init(DLIST_LIST_TYPE *list)
static const char * str(char *buf, int n)
static const struct type types[]
CONNECTOR SERVICE_CreateConnectorEx(const char *name, TSERV_Type types, const SConnNetInfo *net_info, const SSERVICE_Extra *extra)
EIO_Status HTTP_CreateTunnel(const SConnNetInfo *net_info, THTTP_Flags flags, SOCK *sock)
Same as HTTP_CreateTunnelEx(net_info, flags, 0, 0, 0, 0, sock)
FSetupVTable setup
init meta, may not be NULL
#define CONN_SET_METHOD(meta, method, function, connector)
CONNECTOR HTTP_CreateConnectorEx(const SConnNetInfo *net_info, THTTP_Flags flags, FHTTP_ParseHeader parse_header, void *user_data, FHTTP_Adjust adjust, FHTTP_Cleanup cleanup)
Create new CONNECTOR structure to hit the specified URL using HTTP with either POST / GET (or ANY) me...
FConnectorGetType get_type
unsigned int THTTP_Flags
Bitwise OR of EHTTP_Flag.
EIO_Status CONN_Flush(CONN conn)
Explicitly flush connection from any pending data written by CONN_Write().
#define CONN_SET_DEFAULT_TIMEOUT(meta, timeout)
CONNECTOR next
linked list
FHTTP_ParseHeader parse_header
EIO_Status CONN_SetTimeout(CONN conn, EIO_Event event, const STimeout *timeout)
Specify timeout for the connection I/O, including "Connect" (aka "Open") and "Close".
EIO_Status CONN_Create(CONNECTOR connector, CONN *conn)
Same as CONN_CreateEx() called with 0 in the "flags" parameter.
FDestroy destroy
destroys handle, can be NULL
FSERVICE_GetNextInfo get_next_info
EIO_Status METACONN_Remove(SMetaConnector *meta, CONNECTOR connector)
Delete given "connector" all its descendants (all connectors if "connector" is NULL) from the connect...
EHTTP_HeaderParse
The extended version HTTP_CreateConnectorEx() is able to track the HTTP response chain and also chang...
EIO_Status METACONN_Insert(SMetaConnector *meta, CONNECTOR connector)
Insert a connector in the beginning of the connection's list of connectors.
void * handle
data handle of the connector
SMetaConnector * meta
back link to original meta
EIO_Status CONN_Close(CONN conn)
Close the connection and destroy all relevant internal data.
CONNECTOR SOCK_CreateConnectorOnTopEx(SOCK sock, unsigned short own_sock, const char *hostport)
@ fHTTP_AdjustOnRedirect
Call adjust routine for redirects, too.
@ fHTTP_NoAutoRetry
No auto-retries allowed.
@ fHTTP_AutoReconnect
See HTTP_CreateConnectorEx()
@ fHTTP_Flushable
Connector will really flush on Flush()
@ eHTTP_HeaderSuccess
Parse succeeded, retain server status.
@ eHTTP_HeaderError
Parse failed, treat as a server error.
#define SERV_HTTP_PATH(ui)
#define SERV_HTTP_ARGS(ui)
SSERV_InfoCPtr SERV_GetNextInfo(SERV_ITER iter)
Same as "SERV_GetNextInfoEx(., 0)" – i.e.
void SERV_Close(SERV_ITER iter)
Deallocate the iterator.
void SERV_Reset(SERV_ITER iter)
Reset the iterator to the state as if it has just been opened.
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.
unsigned int TSERV_Type
Bitwise OR of ESERV_Type[Special].
unsigned short TSERV_TypeOnly
Server type only, w/o specials.
#define SERV_LOCALHOST
Special values for the "preferred_host" parameter.
#define SERV_NCBID_ARGS(ui)
@ fSERV_Stateless
Stateless servers only.
@ fSERV_DelayOpen
Don't open service until use.
unsigned int SOCK_HostToNetLong(unsigned int value)
See man for the BSDisms, htonl() and htons().
EIO_Status SOCK_Close(SOCK sock)
Close the SOCK handle, and destroy all relevant internal data.
int SOCK_gethostname(char *name, size_t namelen)
Same as SOCK_gethostnameEx(,,<current API data logging>)
unsigned int SOCK_gethostbyname(const char *hostname)
Same as SOCK_gethostbynameEx(,<current API data logging>)
EIO_Status SOCK_Abort(SOCK sock)
If there is outstanding connection or output data pending, cancel it.
int SOCK_ntoa(unsigned int addr, char *buf, size_t bufsize)
Convert IP address to a string in dotted notation.
const char * SOCK_gethostbyaddr(unsigned int addr, char *name, size_t namelen)
Same as SOCK_gethostbyaddrEx(,,<current API data logging>)
unsigned int TSOCK_Flags
bitwise "OR" of ESOCK_Flags
@ fSOCK_Secure
subsumes CloseOnExec regardless of Keep
char http_proxy_host[255+1]
int ConnNetInfo_ExtendUserHeader(SConnNetInfo *net_info, const char *header)
int ConnNetInfo_SetupStandardArgs(SConnNetInfo *net_info, const char *service)
char http_proxy_user[63+1]
unsigned short http_proxy_port
int ConnNetInfo_OverrideUserHeader(SConnNetInfo *net_info, const char *header)
char * MIME_ComposeContentTypeEx(EMIME_Type type, EMIME_SubType subtype, EMIME_Encoding encoding, char *buf, size_t bufsize)
int ConnNetInfo_SetArgs(SConnNetInfo *net_info, const char *args)
SConnNetInfo * ConnNetInfo_Clone(const SConnNetInfo *net_info)
LOG CORE_GetLOG(void)
Get the log handle that is to be used by the core internals (CORE LOG).
#define CONN_CONTENT_TYPE_LEN
char http_proxy_pass[63+1]
const char * ConnNetInfo_GetArgs(const SConnNetInfo *net_info)
int ConnNetInfo_PreOverrideArg(SConnNetInfo *net_info, const char *arg, const char *val)
char * ConnNetInfo_URL(const SConnNetInfo *net_info)
const char * IO_StatusStr(EIO_Status status)
Get the text form of an enum status value.
int ConnNetInfo_SetUserHeader(SConnNetInfo *net_info, const char *header)
int MIME_ParseContentTypeEx(const char *str, EMIME_Type *type, EMIME_SubType *subtype, EMIME_Encoding *encoding)
void ConnNetInfo_DeleteUserHeader(SConnNetInfo *net_info, const char *header)
void ConnNetInfo_Log(const SConnNetInfo *net_info, ELOG_Level sev, LOG log)
const char * http_user_header
EBProxyType http_proxy_mask
EIO_Event
I/O event (or direction).
EBDebugPrintout debug_printout
int ConnNetInfo_SetPath(SConnNetInfo *net_info, const char *path)
const char * http_referer
void ConnNetInfo_Destroy(SConnNetInfo *net_info)
@ eIO_NotSupported
operation is not supported or is not available
@ eIO_Success
everything is fine, no error occurred
@ eIO_Unknown
unknown I/O error (likely fatal but can retry)
@ fProxy_Http
$http_proxy used
@ eFWMode_Adaptive
Regular firewall ports first, then fallback.
@ eFWMode_Fallback
Fallback ports only (w/o trying any regular)
@ eIO_ReadWrite
eIO_Read | eIO_Write (also, eCONN_OnFlush)
@ eIO_Open
also serves as no-event indicator in SOCK_Poll
@ eIO_Close
also serves as an error indicator in SOCK_Poll
unsigned int
A callback function used to compare two keys in a database.
for(len=0;yy_str[len];++len)
if(yy_accept[yy_current_state])
static const CS_INT unused
const struct ncbi::grid::netcache::search::fields::SIZE size
int strncmp(const char *str1, const char *str2, size_t count)
int strcmp(const char *str1, const char *str2)
char * strncpy0(char *s1, const char *s2, size_t n)
Copy not more than "n" characters from string "s2" into "s1", and return the result,...
#define NCBI_DISP_VERSION
#define HTTP_CONNECTION_INFO
int SERV_IsFirewallPort(unsigned short port)
SConnNetInfo * ConnNetInfo_CreateInternal(const char *service)
char * NcbiAddrToString(char *buf, size_t bufsize, const TNCBI_IPv6Addr *addr)
Convert an IPv6 address into either a full-quad text IPv4 (for IPv4-mapped IPv6 addresses) or a hex c...
int NcbiIsIPv4(const TNCBI_IPv6Addr *addr)
Return non-zero(true) if the address is a true IPv4 address (a mapped IPv4 address); return zero(fals...
#define CORE_LOGF_X(subcode, level, fmt_args)
const char * SERV_HostOfInfo(const SSERV_Info *info)
char * SERV_ServiceName(const char *service)
int SERV_Update(SERV_ITER iter, const char *text, int code)
char * SERV_Print(SERV_ITER iter, const SConnNetInfo *net_info, int but_last)
const char * SERV_MapperName(SERV_ITER iter)
static EIO_Status s_Close(CONNECTOR connector, const STimeout *timeout, int cleanup)
static void s_CloseDispatcher(SServiceConnector *uuu)
static const char kHttpHostTag[]
static EHTTP_HeaderParse s_ParseHeaderUCB(const char *header, void *data, int server_error)
static void s_Cleanup(SServiceConnector *uuu)
static const char * s_AdjustNetParams(const char *service, const char *svcname, SConnNetInfo *net_info, EReqMethod req_method, const char *cgi_path, const char *cgi_args, const char *args, const char *static_header, EMIME_Type mime_t, EMIME_SubType mime_s, EMIME_Encoding mime_e, const char *extend_header)
static SSERV_InfoCPtr s_GetNextInfo(SServiceConnector *uuu, int http)
static char * s_VT_Descr(CONNECTOR connector)
static EIO_Status s_VT_Status(CONNECTOR connector, EIO_Event direction)
static int s_IsContentTypeDefined(const char *service, const SConnNetInfo *net_info, EMIME_Type mime_t, EMIME_SubType mime_s, EMIME_Encoding mime_e)
static void x_SetDefaultReferer(SConnNetInfo *net_info, SERV_ITER iter)
static int s_Adjust(SConnNetInfo *net_info, void *data, unsigned int n)
static const char * s_VT_GetType(CONNECTOR connector)
static void s_Reset(SMetaConnector *meta, CONNECTOR connector)
static int x_SetHostPort(SConnNetInfo *net_info, const SSERV_Info *info)
static EIO_Status s_VT_Close(CONNECTOR connector, const STimeout *timeout)
static EIO_Status s_VT_Open(CONNECTOR connector, const STimeout *timeout)
struct SServiceConnectorTag SServiceConnector
static CONNECTOR s_SocketConnectorBuilder(SConnNetInfo *net_info, const char *hostport, EIO_Status *status, const void *data, size_t size, TSOCK_Flags flags)
static EHTTP_HeaderParse s_ParseHeader(const char *header, void *user_data, int server_error, int user_callback_enabled)
static void s_Setup(CONNECTOR connector)
static EHTTP_HeaderParse s_ParseHeaderNoUCB(const char *header, void *data, int server_error)
static char * x_HostPort(const char *host, unsigned short aport)
static CONNECTOR s_Open(SServiceConnector *uuu, const STimeout *timeout, SSERV_InfoCPtr info, SConnNetInfo *net_info, EIO_Status *status)
static int s_OpenDispatcher(SServiceConnector *uuu)
static void s_Destroy(CONNECTOR connector)
static void x_DestroyConnector(CONNECTOR c)
EIO_Status SOCK_CreateOnTopInternal(const void *handle, size_t handle_size, SOCK *sock, const SSOCK_Init *init, TSOCK_Flags flags)
const char g_kNcbiSockNameAbbr[]
EIO_Status SOCK_CreateInternal(const char *host, unsigned short port, const STimeout *timeout, SOCK *sock, const SSOCK_Init *init, TSOCK_Flags flags)
const SConnNetInfo * net_info
voidp calloc(uInt items, uInt size)