40 #include <connect/ncbi_base64.h>
46 #define NCBI_USE_ERRCODE_X Connect_HTTP
49 #define HTTP_SOAK_READ_SIZE 16384
178 "HTTP_UNSAFE_REDIRECTS",
205 static const char kAuthTagTemplate[] =
"Proxy-Authorization: Basic ";
207 size_t taglen, userlen, passlen,
len,
n;
208 const char *
tag, *user, *pass;
214 tag = kAuthTagTemplate + 6;
215 taglen =
sizeof(kAuthTagTemplate) - 7;
226 tag = kAuthTagTemplate;
227 taglen =
sizeof(kAuthTagTemplate) - 1;
248 userlen = strlen(user);
249 passlen = strlen(pass);
250 s =
buf +
sizeof(
buf) - passlen;
251 if (passlen > 2 && pass[0] ==
'[' && pass[passlen - 1] ==
']') {
253 &&
len == passlen - 2) {
260 memcpy(--s, user, userlen);
263 memcpy(s + userlen, pass, passlen);
264 len = userlen + passlen;
268 userlen = (size_t)(s -
buf);
270 userlen -= taglen + 1;
273 if (
len !=
n ||
buf[taglen + passlen])
289 return scheme1 == scheme2 ? 1 : 0;
296 unsigned int ip1, ip2;
308 return *buf1 &&
strcasecmp(buf1, buf2) == 0 ? 1 : 0;
389 && (!same_port || !same_host ||
395 net_info->
host) != 0))) {
412 return port1 == port2
422 unsigned short port_to,
424 const char* host_from,
425 unsigned short port_from)
428 unsigned int ip1, ip2;
438 strncpy0(buf1, host_from,
sizeof(buf1) - 1);
443 if (ip1 && ip1 == ip2)
446 strncpy0(buf2, host_to,
sizeof(buf2) - 1);
516 }
else if (uuu->
vhost
558 ?
"[HTTP%s%s] Too many failed attempts (%hu), giving up" :
"";
559 }
else if (retry && retry->
mode) {
563 switch (retry->
mode) {
572 else if (!retry->
data || *retry->
data ==
'?')
585 reason =
"Prohibited";
593 reason =
"Spurious tunnel";
597 reason =
"Unknown failure of";
604 (
"[HTTP%s%s] %s %s%s to %s%s%s",
612 ?
"redirect" :
"submission",
613 retry->
data ?
"\"" :
"<",
615 retry->
data ?
"\"" :
">"));
618 (
"[HTTP%s%s] %s \"%s\"",
622 ?
"Finishing submission with" :
"Redirecting to",
635 strcspn(retry->
data,
" \t")) != 0) {
644 reason =
"not allowed with CONNECT";
648 reason =
"not implemented";
652 reason =
"cannot be done at this point";
661 reason =
"prohibited";
669 reason =
"unknown failure";
676 (
"[HTTP%s%s] %s %s %c%s%c",
680 ?
"Authorization" :
"Proxy authorization",
684 ")]"[!retry->
data]));
687 (
"[HTTP%s%s] Authorizing%s",
697 (
"[HTTP%s%s] Unknown retry mode #%u",
699 url ? url :
"", (
unsigned int) retry->
mode));
711 ?
"[HTTP%s%s] Retry attempts (%hu) exhausted, giving up" :
"";
730 static char*
x_HostPort(
size_t reserve,
const char* host,
unsigned short xport)
732 size_t hostlen = strlen(host), portlen;
733 char* hostport, port[16];
739 portlen = (size_t) sprintf(port,
":%hu", xport) + 1;
740 hostport = (
char*)
malloc(reserve + hostlen + portlen);
742 memcpy(hostport + reserve, host, hostlen);
744 memcpy(hostport + hostlen, port, portlen);
753 unsigned short port = net_info->
port;
762 char* c = strchr(v,
':');
763 size_t s = c ? (size_t)(c - v) : strlen(v);
781 size_t len = strlen(
id);
797 size_t len = strlen(
id);
842 (
"[HTTP%s%s] Connector is no longer usable",
873 uuu->
reused = sock ? 1 : 0;
886 net_info->
user[0] =
'\0';
887 net_info->
pass[0] =
'\0';
888 if (net_info->
port == 0)
900 int reset_user_header;
901 char* http_user_header;
926 (uuu->
net_info,
"Transfer-Encoding: chunked")) {
973 if ((temp = (
char*) strchr(path,
'?')) != 0)
976 if (args && (!*args || *args ==
'#'))
1006 size_t args_len = strcspn(args,
"#");
1007 size_t size = args_len * 3;
1008 size_t rd_len, wr_len;
1010 if (!(temp = (
char*)
malloc(
size + strlen(args+args_len) +1))){
1014 (
"[HTTP%s%s] Out of memory encoding"
1015 " URL arguments (%lu bytes)",
1018 (
unsigned long)(
size + strlen
1019 (args + args_len) +1)));
1026 assert(rd_len == args_len);
1028 strcpy(temp + wr_len, args + args_len);
1042 (uuu->
net_info,
"User-Agent: NCBIHttpConnector"
1052 "Connection: keep-alive");
1054 reset_user_header = 1;
1056 reset_user_header = 0;
1070 memset(&extra, 0,
sizeof(extra));
1072 extra.host = uuu->
vhost;
1086 extrap,
flags, &sock);
1090 if (reset_user_header) {
1125 if (status == eIO_Closed)
1200 status =
ctx.status;
1221 #if !defined(NCBI_OS_MSWIN) && !defined(NCBI_OS_CYGWIN)
1233 || (timeout && !(timeout->
sec | timeout->
usec)))) {
1240 sprintf(what,
"write request body at offset %lu",
1241 (
unsigned long) off);
1243 strcpy(what,
"write request body");
1246 strcpy(what,
"finalize request body");
1248 strcpy(what,
"finalize request");
1253 (
"[HTTP%s%s] Cannot %s (%s)",
1272 const char* e = (
const char*) memchr(param,
'=', paramlen);
1274 if (!e || e == param)
1276 if ((
len = (
size_t)(++e - param)) >= paramlen)
1279 if (strcspn(param,
" \t") <
len)
1281 if (*e ==
'\'' || *e ==
'"') {
1285 if (!(e = (
const char*) memchr(e + 1, *e, --
len)))
1289 e += strcspn(e,
" \t");
1290 if (e != param + paramlen && e + strspn(e,
" \t") != param + paramlen)
1302 size_t word = strcspn(
text,
" \t");
1306 const char* param =
text + word;
1307 for (param += strspn(param,
" \t"); param <
text +
len;
1308 param += strspn(param,
", \t")) {
1309 size_t paramlen = (size_t)(
text +
len - param);
1310 const char* c = (
const char*) memchr(param,
',', paramlen);
1312 paramlen = (size_t)(c - param);
1315 if (paramlen > 6 &&
strncasecmp(param,
"realm=", 6) == 0)
1317 param += c ? ++paramlen : paramlen;
1366 if (!
first && (
str[0] !=
'\r' ||
str[1] !=
'\n')) {
1388 sprintf(errbuf,
"Partial read %lu out of %lu",
1390 (
unsigned long)
size);
1401 (
"[HTTP%s%s] Cannot read chunk size: %s%.*s%s",
1405 !
str ? (
int) strlen(err) : (
int)(
size - (
first ? 2 : 4)),
1440 if (status == eIO_Closed) {
1443 (
"[HTTP%s%s] Cannot read chunk tail",
1485 (
"[HTTP%s%s] Cannot allocate response chunk"
1489 (
unsigned long)
size, &
"s"[
size == 1]));
1509 (
"[HTTP%s%s] Cannot collect response body",
1517 if (status == eIO_Closed)
1542 "HTTP_ERROR_HEADER_ONLY",
1556 eHTTP_NcbiMsg = 1 << 0,
1557 eHTTP_NcbiSid = 1 << 1,
1558 eHTTP_Location = 1 << 2,
1559 eHTTP_Connection = 1 << 3,
1560 eHTTP_Authenticate = 1 << 4,
1561 eHTTP_ContentLength = 1 << 5,
1562 eHTTP_TransferEncoding = 1 << 6
1564 typedef unsigned short THTTP_Tags;
1565 char* url = 0, *hdr, *s;
1574 memset(retry, 0,
sizeof(*retry));
1587 (
"[HTTP%s%s] Cannot allocate header"
1591 (
unsigned long)
size));
1598 if (memcmp(&hdr[
size - 4],
"\r\n\r\n", 4) == 0) {
1616 else if (tmo->
sec | tmo->
usec)
1625 (
"[HTTP%s%s] Cannot %s header (%s)",
1647 if (sscanf(hdr,
"HTTP/%*d.%*d %d ", &http_code) != 1 || !http_code)
1649 uuu->
http_code = (
unsigned short) http_code;
1650 if (http_code < 200 || 299 < http_code) {
1651 if (http_code == 304)
1653 else if (http_code == 301 || http_code == 302 || http_code == 307)
1655 else if (http_code == 303)
1657 else if (http_code == 401)
1659 else if (http_code == 407)
1661 else if (http_code <= 0 ||
1662 http_code == 400 || http_code == 403 ||
1663 http_code == 404 || http_code == 405 ||
1664 http_code == 406 || http_code == 410) {
1674 const char* header_header;
1675 if (!http_code || http_code == 304)
1676 header_header =
"HTTP header";
1678 header_header =
"HTTP header (fatal)";
1680 header_header =
"HTTP header (error)";
1682 header_header =
"HTTP header (redirect)";
1684 header_header =
"HTTP header (see other)";
1686 header_header =
"HTTP header (authentication)";
1687 else if (retry->
mode)
1688 header_header = 0,
assert(0);
1690 header_header =
"HTTP header (retriable server error)";
1696 url ? url :
"", header_header));
1707 sprintf(
text,
"%d", http_code);
1709 strcpy(
text,
"occurred");
1711 (
"[HTTP%s%s] Fatal error %s",
1713 url ? url :
"",
text));
1730 (
"[HTTP%s%s] HTTP header (parse error)",
1745 (eHTTP_NcbiMsg | eHTTP_Connection
1751 tags |= eHTTP_ContentLength | eHTTP_TransferEncoding;
1755 for (s = strchr(hdr,
'\n'); s && *s; s = strchr(s + 1,
'\n')) {
1756 if (tags & eHTTP_NcbiMsg) {
1759 if (
strncasecmp(s, kNcbiMsgTag,
sizeof(kNcbiMsgTag) - 1) == 0) {
1760 char*
msg = s +
sizeof(kNcbiMsgTag) - 1, *e;
1761 while (*
msg &&
isspace((
unsigned char)(*msg)))
1763 if (!(e = strchr(
msg,
'\r')) && !(e = strchr(
msg,
'\n')))
1766 if (!
isspace((
unsigned char) e[-1]))
1768 }
while (--e >
msg);
1769 n = (size_t)(e -
msg);
1781 (
"[NCBI-MESSAGE] %s",
msg));
1785 tags &= (THTTP_Tags)(~eHTTP_NcbiMsg);
1789 if (tags & eHTTP_NcbiSid) {
1792 if (
strncasecmp(s, kNcbiSidTag,
sizeof(kNcbiSidTag) - 1) == 0) {
1793 char* sid = s +
sizeof(kNcbiSidTag) - 1, *e;
1794 while (*sid &&
isspace((
unsigned char)(*sid)))
1796 if (!(e = strchr(sid,
'\r')) && !(e = strchr(sid,
'\n')))
1799 if (!
isspace((
unsigned char) e[-1]))
1801 }
while (--e > sid);
1802 n = (size_t)(e - sid);
1809 tags &= (THTTP_Tags)(~eHTTP_NcbiSid);
1813 if (tags & eHTTP_Location) {
1815 static const char kLocationTag[] =
"\nLocation:";
1817 if (
strncasecmp(s, kLocationTag,
sizeof(kLocationTag) - 1) == 0) {
1818 char* loc = s +
sizeof(kLocationTag) - 1, *e;
1819 while (*loc &&
isspace((
unsigned char)(*loc)))
1821 if (!(e = strchr(loc,
'\r')) && !(e = strchr(loc,
'\n')))
1824 if (!
isspace((
unsigned char) e[-1]))
1826 }
while (--e > loc);
1827 n = (size_t)(e - loc);
1833 tags &= (THTTP_Tags)(~eHTTP_Location);
1837 if (tags & eHTTP_Connection) {
1839 static const char kConnectionTag[] =
"\nConnection:";
1840 if (
strncasecmp(s, kConnectionTag,
sizeof(kConnectionTag)-1) == 0){
1841 char* con = s +
sizeof(kConnectionTag) - 1, *e;
1842 while (*con &&
isspace((
unsigned char)(*con)))
1844 if (!(e = strchr(con,
'\r')) && !(e = strchr(con,
'\n')))
1847 if (!
isspace((
unsigned char) e[-1]))
1849 }
while (--e > con);
1850 while ((
n = (
size_t)(e - con)) > 0) {
1851 const char* c = (
const char*) memchr(con,
',',
n);
1855 if (!
isspace((
unsigned char) c[-1]))
1857 }
while (--c > con);
1858 m = (size_t)(c - con);
1861 if (m == 5 &&
strncasecmp(con,
"close", 5) == 0) {
1865 if (m == 10 &&
strncasecmp(con,
"keep-alive", 10) == 0) {
1872 while (con < e &&
isspace((
unsigned char)(*con)))
1875 tags &= (THTTP_Tags)(~eHTTP_Connection);
1879 if (tags & eHTTP_Authenticate) {
1881 static const char kAuthenticateTag[] =
"-Authenticate:";
1889 kAuthenticateTag,
sizeof(kAuthenticateTag)-1)==0) {
1890 char* txt = s +
n +
sizeof(kAuthenticateTag) - 1, *e;
1891 while (*txt &&
isspace((
unsigned char)(*txt)))
1893 if (!(e = strchr(txt,
'\r')) && !(e = strchr(txt,
'\n')))
1896 if (!
isspace((
unsigned char) e[-1]))
1898 }
while (--e > txt);
1899 n = (size_t)(e - txt);
1905 tags &= (THTTP_Tags)(~eHTTP_Authenticate);
1909 if (tags & eHTTP_ContentLength) {
1911 static const char kContentLenTag[] =
"\nContent-Length:";
1912 if (
strncasecmp(s, kContentLenTag,
sizeof(kContentLenTag)-1) == 0){
1916 const char*
len = s +
sizeof(kContentLenTag) - 1, *e;
1918 while (*
len &&
isspace((
unsigned char)(*len)))
1920 if (!(e = strchr(
len,
'\r')) && !(e = strchr(
len,
'\n')))
1923 if (!
isspace((
unsigned char) e[-1]))
1925 }
while (--e >
len);
1933 tags &= (THTTP_Tags)(~eHTTP_ContentLength);
1937 if (tags & eHTTP_TransferEncoding) {
1938 static const char kTransferEncodingTag[] =
"\nTransfer-Encoding:";
1940 sizeof(kTransferEncodingTag)-1) == 0) {
1941 const char* te = s +
sizeof(kTransferEncodingTag) - 1, *e;
1942 while (*te &&
isspace((
unsigned char)(*te)))
1944 if (!(e = strchr(te,
'\r')) && !(e = strchr(te,
'\n')))
1947 if (!
isspace((
unsigned char) e[-1]))
1950 n = (size_t)(e - te);
1952 && (
isspace((
unsigned char) e[-8])
1953 || e[-8] ==
':' || e[-8] ==
',')) {
1957 tags &= (THTTP_Tags)
1958 (~(eHTTP_ContentLength | eHTTP_TransferEncoding));
1963 (
"[HTTP%s%s] Chunked transfer encoding"
1989 (
"[HTTP%s%s] Cannot save HTTP header",
2002 if (!http_code || http_code == 304) {
2028 const char* err = status != eIO_Closed ?
IO_StatusStr(status) : 0;
2036 (
"[HTTP%s%s] Server error message incomplete (%s)",
2038 url ? url :
"", err));
2042 (
"[HTTP%s%s] No error message received from server"
2047 err ? err :
"", &
")"[!err]));
2048 }
else if ((s = (
char*)
malloc(
size)) != 0) {
2052 (
"[HTTP%s%s] Cannot extract server error message"
2053 " from buffer entirely (%lu/%lu)",
2056 (
unsigned long)
n, (
unsigned long)
size));
2060 (
"[HTTP%s%s] Server error message%s%s%s",
2064 err ? err :
"", &
")"[!err]));
2069 (
"[HTTP%s%s] Cannot allocate server error message"
2073 (
unsigned long)
size, &
"s"[
size == 1]));
2150 || (timeout && !(timeout->
sec | timeout->
usec)))) {
2158 adjust =
s_Adjust(uuu, &retry, status, extract);
2162 if (adjust != eIO_Closed)
2188 size_t size,
size_t* n_read)
2206 }
else if (status != eIO_Closed)
2210 return status ? status : eIO_Closed;
2220 status = eIO_Closed;
2224 size_t n_peeked, n_decoded;
2226 size_t peek_size =
size > remain ? (size_t)(remain + 1) :
size;
2227 void* peek_buf =
malloc(peek_size *= 3);
2236 assert(n_peeked == n_decoded);
2243 if (status == eIO_Closed)
2252 (
"[HTTP%s%s] Cannot URL-decode data: %s",
2268 if (status == eIO_Closed) {
2276 const char* how = 0;
2278 if (status == eIO_Closed) {
2280 how =
"Premature EOM in";
2289 assert(*n_read >= excess);
2290 *n_read -= (size_t) excess;
2294 how =
"Got too much";
2300 (
"[HTTP%s%s] %s data (received "
2304 url ? url :
"", how,
2351 if (status == eIO_Closed)
2559 (
"[HTTP%s%s] Illegal write (%lu byte%s) with %s",
2562 (
unsigned long)
size, &
"s"[
size == 1],
2591 size += (size_t)
n + 2;
2602 size_t dst_size = 3 *
size;
2603 void* dst =
malloc(dst_size);
2666 assert(n_read && !*n_read);
2668 status =
s_Read(uuu, (
char*)
buf + x_read,
size - x_read, n_read);
2746 const char* vhost = 0, *s;
2756 vhost = s + 6 - !!
first;
2757 vhost = vhost + strspn(vhost,
"\t ");
2758 vhost =
strndup(vhost, strcspn(vhost,
":\r\n"));
2761 && (s[4 -
first] ==
'-' || s[4 - !!
first] ==
':')) {
2772 }
else if (!*has_sid
2777 if (!(s = strchr(++s,
'\n')))
2785 sprintf(
buf,
"User-Agent: %.80s", s);
2790 if (has_ref <= 0 && *s) {
2791 size_t len = strlen(s);
2792 if ((ref = (
char*) realloc((
char*) s, 10 +
len)) != 0) {
2794 memcpy(ref,
"Referer: ", 9);
2812 const char* user_header,
2849 if (user_header && *user_header
2863 xxx->
path[0] =
'\0';
2920 const char* user_header,
2967 const char* user_header,
2983 parse_header, user_data, adjust,
cleanup);
2990 const void* init_data,
2996 unsigned short http_code;
3005 user_data, adjust, &uuu);
3035 switch (http_code) {
static void cleanup(void)
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
static void fatal(const char *msg,...)
static const char * str(char *buf, int n)
int BUF_Write(BUF *pBuf, const void *data, size_t size)
int BUF_Prepend(BUF *pBuf, const void *data, size_t size)
int BUF_AppendEx(BUF *pBuf, void *base, size_t alloc_size, void *data, size_t size)
size_t BUF_Read(BUF buf, void *data, size_t size)
int BUF_Splice(BUF *dst, BUF src)
size_t BUF_Peek(BUF buf, void *data, size_t size)
size_t BUF_PeekAtCB(BUF buf, size_t pos, size_t(*callback)(void *cbdata, const void *buf, size_t size), void *cbdata, size_t size)
void BUF_Destroy(BUF buf)
void(* FHTTP_NcbiMessageHook)(const char *message)
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...
unsigned int THTTP_Flags
Bitwise OR of EHTTP_Flag.
int(* FHTTP_Adjust)(SConnNetInfo *net_info, void *user_data, unsigned int failure_count)
#define CONN_SET_DEFAULT_TIMEOUT(meta, timeout)
void(* FHTTP_Cleanup)(void *user_data)
CONNECTOR next
linked list
CONNECTOR HTTP_CreateConnector(const SConnNetInfo *net_info, const char *user_header, THTTP_Flags flags)
Same as HTTP_CreateConnector(net_info, flags, 0, 0, 0, 0) with the passed "user_header" overriding th...
void HTTP_SetNcbiMessageHook(FHTTP_NcbiMessageHook hook)
Set a message hook procedure for messages originating from NCBI via HTTP.
FDestroy destroy
destroys handle, can be NULL
EHTTP_HeaderParse
The extended version HTTP_CreateConnectorEx() is able to track the HTTP response chain and also chang...
void * handle
data handle of the connector
SMetaConnector * meta
back link to original meta
EHTTP_HeaderParse(* FHTTP_ParseHeader)(const char *http_header, void *user_data, int server_error)
EIO_Status HTTP_CreateTunnelEx(const SConnNetInfo *net_info, THTTP_Flags flags, const void *init_data, size_t init_size, void *user_data, FHTTP_Adjust adjust, SOCK *sock)
Create a tunnel to "net_info->host:net_info->port" via an HTTP proxy server located at "net_info->htt...
const STimeout g_NcbiDefConnTimeout
DEF_CONN_TIMEOUT as STimeout.
@ fHTTP_DropUnread
Each microsession drops unread data.
@ fHTTP_AdjustOnRedirect
Call adjust routine for redirects, too.
@ fHTTP_NoUpread
Do not use SOCK_SetReadOnWrite()
@ fHTTP_NoAutoRetry
No auto-retries allowed.
@ fHTTP_AutoReconnect
See HTTP_CreateConnectorEx()
@ fHTTP_KeepHeader
Keep HTTP header (see limitations)
@ fHTTP_NoAutomagicSID
Do not add NCBI SID automagically.
@ fHTTP_SuppressMessages
Most annoying ones reduced to traces.
@ fHTTP_UnsafeRedirects
Any redirect will be honored.
@ fHTTP_Flushable
Connector will really flush on Flush()
@ fHTTP_PushAuth
HTTP/1.1 pushes out auth if present.
@ fHTTP_WriteThru
HTTP/1.1 writes through (chunked)
@ eHTTP_HeaderSuccess
Parse succeeded, retain server status.
@ eHTTP_HeaderError
Parse failed, treat as a server error.
@ eHTTP_HeaderContinue
Parse succeeded, continue with body.
@ eHTTP_HeaderComplete
Parse succeeded, no more processing.
@ fHCC_UrlEncodeOutput
Obsolete, may not work, do not use!
@ fHCC_UrlDecodeInput
Obsolete, may not work, do not use!
@ fHCC_UrlEncodeArgs
NB: Error-prone semantics, do not use!
int SOCK_isipEx(const char *host, int fullquad)
Check whether the given string represents a valid IPv4 address.
int SOCK_IsSecure(SOCK sock)
Check whether a socket is using SSL (Secure Socket Layer).
EIO_Status SOCK_SetTimeout(SOCK sock, EIO_Event event, const STimeout *timeout)
Specify timeout for the connection I/O (see SOCK_[Read|Write|Close]()).
EIO_Status SOCK_Close(SOCK sock)
Close the SOCK handle, and destroy all relevant internal data.
EIO_Status SOCK_Read(SOCK sock, void *buf, size_t size, size_t *n_read, EIO_ReadMethod how)
Read/peek up to "size" bytes from "sock" to a buffer pointed to by "buf".
EIO_Status SOCK_Status(SOCK sock, EIO_Event direction)
Return low-level socket I/O status of *last* socket operation.
unsigned int SOCK_gethostbyname(const char *hostname)
Same as SOCK_gethostbynameEx(,<current API data logging>)
EIO_Status SOCK_Pushback(SOCK sock, const void *data, size_t size)
Push the specified data back to the socket's input queue (in the socket's internal read buffer).
EIO_Status SOCK_Wait(SOCK sock, EIO_Event event, const STimeout *timeout)
Block on the socket until either the specified "event" is available or "timeout" expires (if "timeout...
EIO_Status SOCK_Abort(SOCK sock)
If there is outstanding connection or output data pending, cancel it.
EIO_Status SOCK_Write(SOCK sock, const void *data, size_t size, size_t *n_written, EIO_WriteMethod how)
Write "size" bytes of "data" to "sock".
const STimeout * SOCK_GetTimeout(SOCK sock, EIO_Event event)
Get the connection's i/o timeout (or NULL, if the timeout is infinite).
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_KeepAlive
keep socket alive (if supported by OS)
@ fSOCK_Secure
subsumes CloseOnExec regardless of Keep
ELOG_Level
Log severity level.
char http_proxy_host[255+1]
int ConnNetInfo_ExtendUserHeader(SConnNetInfo *net_info, const char *header)
EIO_Status URL_ConnectEx(const char *host, unsigned short port, const char *path, const char *args, TReqMethod req_method, size_t content_length, const STimeout *o_timeout, const STimeout *rw_timeout, const char *user_header, SURLExtra *extra, TSOCK_Flags flags, SOCK *sock)
char http_proxy_user[63+1]
unsigned short http_proxy_port
#define NCBI_BIGCOUNT_FORMAT_SPEC_HEX
int ConnNetInfo_OverrideUserHeader(SConnNetInfo *net_info, const char *header)
int ConnNetInfo_PreOverrideUserHeader(SConnNetInfo *net_info, const char *header)
int ConnNetInfo_ParseURL(SConnNetInfo *net_info, const char *url)
int ConnNetInfo_SetArgs(SConnNetInfo *net_info, const char *args)
int ConnNetInfo_AppendUserHeader(SConnNetInfo *net_info, const char *header)
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).
unsigned int usec
microseconds (modulo 1,000,000)
char http_proxy_pass[63+1]
const char * ConnNetInfo_GetArgs(const SConnNetInfo *net_info)
char * ConnNetInfo_URL(const SConnNetInfo *net_info)
const char * IO_StatusStr(EIO_Status status)
Get the text form of an enum status value.
const char * CORE_GetAppName(void)
Obtain current application name (toolkit dependent).
EIO_ReadMethod
I/O read method.
int ConnNetInfo_SetUserHeader(SConnNetInfo *net_info, const char *header)
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
char * CORE_GetNcbiRequestID(ENcbiRequestID reqid)
Obtain current NCBI request ID (if known, per thread).
#define ConnNetInfo_PostOverrideUserHeader
EIO_Status SOCK_StripToPattern(SOCK sock, const void *pattern, size_t pattern_size, BUF *discard, size_t *n_discarded)
EIO_Event
I/O event (or direction).
void URL_Encode(const void *src_buf, size_t src_size, size_t *src_read, void *dst_buf, size_t dst_size, size_t *dst_written)
#define NCBI_BIGCOUNT_FORMAT_SPEC
int ConnNetInfo_Boolean(const char *str)
EBDebugPrintout debug_printout
int URL_DecodeEx(const void *src_buf, size_t src_size, size_t *src_read, void *dst_buf, size_t dst_size, size_t *dst_written, const char *allow_symbols)
const char * http_referer
void ConnNetInfo_Destroy(SConnNetInfo *net_info)
int ConnNetInfo_SetFrag(SConnNetInfo *net_info, const char *frag)
uint64_t TNCBI_BigCount
Big unsigned integer for file size and position.
@ eIO_Timeout
timeout expired before any I/O succeeded
@ 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)
@ eIO_InvalidArg
bad argument / parameter value(s) supplied
@ fProxy_Http
$http_proxy used
@ fProxy_Https
$https_proxy used
@ eIO_ReadPlain
read readily available data only, wait if none
@ eIO_ReadPeek
do eIO_ReadPlain but leave data in input queue
@ eIO_ReadPersist
read exactly as much as requested, w/waits
@ eIO_WritePlain
write as much as possible, report back how much
@ eIO_Close
also serves as an error indicator in SOCK_Poll
@ eNcbiRequestID_SID
NCBI Session ID.
@ eNcbiRequestID_HitID
NCBI Hit ID.
if(yy_accept[yy_current_state])
static void text(MDB_val *v)
const struct ncbi::grid::netcache::search::fields::SIZE size
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 HTTP_NCBI_MESSAGE
SConnNetInfo * ConnNetInfo_CloneInternal(const SConnNetInfo *info)
const char * ConnNetInfo_GetValueInternal(const char *service, const char *param, char *value, size_t value_size, const char *def_value)
SConnNetInfo * ConnNetInfo_CreateInternal(const char *service)
static int x_IsValidChallenge(const char *text, size_t len)
static EIO_Status x_ReadChunkTail(SHttpConnector *uuu)
static EHTTP_Redirect x_Redirect(SHttpConnector *uuu, const SRetry *retry)
static int x_SamePort(unsigned short port1, EBURLScheme scheme1, unsigned short port2, EBURLScheme scheme2)
static const char kHttpHostTag[]
static int x_UnsafeRedirectOK(SHttpConnector *uuu)
static EIO_Status s_Connect(SHttpConnector *uuu, const STimeout *timeout, EExtractMode extract)
static int x_Pushback(SOCK sock, BUF buf)
static const char * x_SetHttpHostTag(SConnNetInfo *net_info)
static EIO_Status s_Adjust(SHttpConnector *uuu, const SRetry *retry, EIO_Status status, EExtractMode extract)
static void s_DestroyHttpConnector(SHttpConnector *uuu)
static char * s_VT_Descr(CONNECTOR connector)
static EIO_Status s_Read(SHttpConnector *uuu, void *buf, size_t size, size_t *n_read)
static EIO_Status s_VT_Write(CONNECTOR connector, const void *buf, size_t size, size_t *n_written, const STimeout *timeout)
@ eRetry_ProxyAuthenticate
static EIO_Status s_VT_Read(CONNECTOR connector, void *buf, size_t size, size_t *n_read, const STimeout *timeout)
static char * x_HostPort(size_t reserve, const char *host, unsigned short xport)
static const char * s_VT_GetType(CONNECTOR connector)
static EIO_Status s_ReadData(SHttpConnector *uuu, void *buf, size_t size, size_t *n_read, EIO_ReadMethod how)
static int x_IsValidParam(const char *param, size_t paramlen)
static EIO_Status s_ReadHeader(SHttpConnector *uuu, SRetry *retry, EExtractMode extract)
static int x_SameProxyHost(const char *host1, const char *host2)
static int x_RedirectOK(EBURLScheme scheme_to, const char *host_to, unsigned short port_to, EBURLScheme scheme_from, const char *host_from, unsigned short port_from)
static int x_SameScheme(EBURLScheme scheme1, EBURLScheme scheme2)
static EIO_Status s_VT_Close(CONNECTOR connector, const STimeout *timeout)
static int s_TunnelAdjust(SConnNetInfo *net_info, void *data, unsigned int arg)
static int s_CallAdjust(SHttpConnector *uuu, unsigned int arg)
static EIO_Status s_VT_Flush(CONNECTOR connector, const STimeout *timeout)
static int x_ErrorHeaderOnly(SHttpConnector *uuu)
static EIO_Status s_VT_Open(CONNECTOR connector, const STimeout *timeout)
static EIO_Status s_ConnectAndSend(SHttpConnector *uuu, const STimeout *timeout, EExtractMode extract)
#define HTTP_SOAK_READ_SIZE
static CONNECTOR s_CreateConnector(const SConnNetInfo *net_info, const char *user_header, THTTP_Flags flags, FHTTP_ParseHeader parse_header, void *user_data, FHTTP_Adjust adjust, FHTTP_Cleanup cleanup)
static void x_SetRequestIDs(SConnNetInfo *net_info)
static size_t x_PushbackBuf(void *data, const void *buf, size_t size)
static int x_IsWriteThru(const SHttpConnector *uuu)
static void s_OpenHttpConnector(SHttpConnector *uuu, const STimeout *timeout)
static EIO_Status s_Disconnect(SHttpConnector *uuu, const STimeout *timeout, EExtractMode extract)
static EIO_Status x_ReadChunkHead(SHttpConnector *uuu, int first)
static const char * x_FixupUserHeader(SConnNetInfo *net_info, int has_ref, int *has_sid)
static int s_MessageIssued
static FHTTP_NcbiMessageHook s_MessageHook
static size_t x_WriteBuf(void *data, const void *buf, size_t size)
static void s_Setup(CONNECTOR connector)
static void s_DropConnection(SHttpConnector *uuu, enum EConnState state)
static EIO_Status s_CreateHttpConnector(const SConnNetInfo *net_info, const char *user_header, int tunnel, THTTP_Flags flags, void *user_data, FHTTP_Adjust adjust, SHttpConnector **http)
static unsigned short x_PortForScheme(unsigned port, EBURLScheme scheme)
static int x_SameOrDefPort(unsigned short port1, EBURLScheme scheme1, unsigned short port2, EBURLScheme scheme2)
static EIO_Status s_VT_Status(CONNECTOR connector, EIO_Event dir)
static EIO_Status s_VT_Wait(CONNECTOR connector, EIO_Event event, const STimeout *timeout)
static EIO_Status s_PreRead(SHttpConnector *uuu, const STimeout *timeout, EExtractMode extract)
static void x_Close(SHttpConnector *uuu)
static EHTTP_Auth x_Authenticate(SHttpConnector *uuu, ERetry auth, int retry)
static void s_Destroy(CONNECTOR connector)
static const STimeout kZeroTimeout
#define CORE_DATAF_X(subcode, level, data, size, fmt_args)
#define CORE_LOGF_X(subcode, level, fmt_args)
#define CORE_LOGF_ERRNO_X(subcode, level, error, fmt_args)
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
const STimeout * o_timeout
unsigned char minor_fault
unsigned short major_fault
FHTTP_ParseHeader parse_header
const STimeout * w_timeout