43 #define NCBI_USE_ERRCODE_X Connect_Util
46 #define CONN_NET_INFO_MAGIC 0x600DCAFE
48 #define SizeOf(arr) (sizeof(arr) / sizeof((arr)[0]))
51 static const char kDigits[] =
"0123456789";
66 static char*
x_getenv(
const char* name)
68 char*
env = getenv(name);
74 # define x_getenv getenv
81 size_t dstlen = dst && *dst ? strlen(dst) : 0;
82 size_t srclen = src && *src ? strlen(src) : 0;
83 if (dstlen && dst[dstlen - 1] ==
'\n') {
84 if (--dstlen && dst[dstlen - 1] ==
'\r')
88 if (!
isspace((
unsigned char)(*src)))
94 if (!
isspace((
unsigned char) src[srclen - 1]))
98 if (dstlen | srclen) {
101 len = (dstlen ? dstlen + 2 : 0) + (srclen ? srclen + 2 : 0) + 1;
102 if (!(temp = (
char*)(dst ? realloc(dst,
len) :
malloc (
len))))
107 memcpy(temp,
"\r\n", 3);
111 memcpy(temp, src, srclen);
113 memcpy(temp,
"\r\n", 3);
121 static const char*
x_strncpy0(
char* dst,
const char* src,
size_t dst_size)
123 size_t src_len = strlen(src);
124 const char* retval = dst;
126 if (src_len >= dst_size) {
127 src_len = dst_size - 1;
139 const char* end =
str +
len;
141 unsigned char c = (
unsigned char)(*
str);
172 static const char*
x_GetValue(
const char* svc,
size_t svclen,
173 const char* param,
char*
value,
174 size_t value_size,
const char* def_value,
177 const char*
val, *rv;
182 assert(!svclen || (svclen == strlen(svc)));
187 parlen = strlen(param) + 1;
190 size_t len = svclen + 1 + parlen;
204 s = (
char*) memcpy(
buf, svc, svclen) + svclen;
217 memcpy(s, param, parlen);
222 || (memcmp(
buf,
tmp, svclen) != 0
233 memcpy(
buf, svc, svclen);
234 buf[svclen++] =
'\0';
251 }
else if (strncompar !=
strncmp) {
252 if (parlen >
sizeof(
buf))
258 memcpy(s, param, parlen);
287 while (*ptr &&
isspace((
unsigned char)(*ptr)))
294 if (
len > 1 && (*ptr ==
'"' || *ptr ==
'\'') && ptr[
len - 1] == *ptr)
302 static const char*
s_GetValue(
const char* svc,
size_t svclen,
303 const char* param,
char*
value,
304 size_t value_size,
const char* def_value,
308 value_size, def_value,
generic,strncompar);
316 CORE_TRACEF((
"ConnNetInfo(%s%.*s%s%s=\"%s\"): %s%s%s", &
"\""[!svclen],
317 (
int) svclen, svc, svclen ?
"\", " :
"", param,
value,
318 &
"\""[!retval], retval ? retval :
"NULL",
326 char*
value,
size_t value_size,
327 const char* def_value)
329 int service_only = 0;
331 && !strpbrk(service,
"?*[")));
335 return s_GetValue(service, service && *service ? strlen(service) : 0,
336 param,
value, value_size, def_value,
343 char*
value,
size_t value_size,
344 const char* def_value)
347 int service_only = 1;
349 && !strpbrk(service,
"?*["));
354 param,
value, value_size, def_value,
362 char*
value,
size_t value_size,
363 const char* def_value)
369 if (!
value || !value_size)
376 if (!*service || strpbrk(service,
"?*["))
381 verify((svclen = strlen(service)) != 0);
387 param,
value, value_size, def_value,
390 free((
void*) service);
407 if (c ==
'Y' || c ==
'T')
409 if (c ==
'N' || c ==
'F')
435 #if defined(_DEBUG) && !defined(NDEBUG)
437 (
"Unrecognized boolean value %s%s%s treated as FALSE",
484 if (sscanf(ptr,
"%hu%n", &port, &
n) < 1 || port < 2)
489 if (!*(ptr += strspn(ptr,
" \t")))
520 if (*
val ==
'"' || *
val ==
'\'') {
527 ((
char*)
val)[
len] =
'\0';
533 x_info->
user[0] =
'\0';
534 x_info->
pass[0] =
'\0';
535 x_info->
host[0] =
'\0';
537 x_info->
path[0] =
'\0';
540 if (parsed && (!x_info->
scheme
544 || (x_info->
path[0] ==
'/' && !x_info->
path[1]))) {
545 memcpy(
info->http_proxy_user, x_info->
user, strlen(x_info->
user) + 1);
546 memcpy(
info->http_proxy_pass, x_info->
pass, strlen(x_info->
pass) + 1);
547 memcpy(
info->http_proxy_host, x_info->
host, strlen(x_info->
host) + 1);
548 info->http_proxy_port = x_info->
port;
549 info->http_proxy_only = 1;
551 strlen(
info->http_proxy_host)));
556 (
"ConnNetInfo(%s%s%s$%s): Unrecognized HTTP proxy"
557 " specification \"%s\"", &
"\""[!*
info->svc],
559 parsed =
info->http_proxy_leak ? -1 : 0;
571 if (
info->http_proxy_skip)
583 assert(!referer || *referer);
602 if (
info->http_user_header) {
603 free((
void*)
info->http_user_header);
604 info->http_user_header = 0;
606 if (
info->http_referer) {
608 info->http_referer = 0;
639 #define REG_VALUE(name, value, def_value) \
642 if (!s_GetValue(service, len, \
643 name, value, sizeof(value), def_value, \
644 &generic, strncmp)) \
655 len = service && *service ? strlen(service) : 0;
657 && !strpbrk(service,
"?*[")));
665 info->http_referer = 0;
666 info->http_user_header = 0;
669 memcpy((
char*)
info->svc, service ? service :
"",
len + 1);
672 info->client_host[0] =
'\0';
706 info->http_version = *
str && atoi(
str) == 1 ? 1 : 0;
735 info->http_proxy_only = 0;
747 (
"[ConnNetInfo_Create%s%s%s] Invalid host specification"
748 " \"%s\"", *
info->svc ?
"(\"" :
"",
756 if (*
str && (
val = (
long) strtoul(
str, &e, 10)) > 0 && !errno
757 && !*e &&
val < (1 << 16)) {
758 info->port = (
unsigned short)
val;
766 info->http_proxy_host[0] =
'\0';
767 info->http_proxy_port = 0;
768 info->http_proxy_user[0] =
'\0';
769 info->http_proxy_pass[0] =
'\0';
783 info->tmo.sec = (
unsigned int) dbl;
784 info->tmo.usec = (
unsigned int)((dbl -
info->tmo.sec) * 1.0e6);
785 if (dbl && !(
info->tmo.sec |
info->tmo.usec))
801 info->credentials = 0;
822 strlen(
info->http_proxy_host))){
824 (
"[ConnNetInfo_Create%s%s%s] Invalid HTTP proxy"
825 " host specification \"%s\"",
827 *
info->svc ?
"\")" :
"",
info->http_proxy_host));
828 if (!
info->http_proxy_leak)
830 info->http_proxy_host[0] =
'\0';
832 if (
info->http_proxy_host[0]) {
835 if (*
str && (
val = (
long) strtoul(
str, &e, 10)) > 0
836 && !errno && !*e &&
val < (1 << 16)) {
837 info->http_proxy_port = (
unsigned short)
val;
839 info->http_proxy_port = 0;
860 const char* x_service;
863 if (service && *service && !strpbrk(service,
"?*[")) {
873 free((
void*) x_service);
879 const char* user_header)
884 if (
info->http_user_header) {
885 free((
void*)
info->http_user_header);
886 info->http_user_header = 0;
893 const char* user_header)
902 const char* newval,
size_t newvallen)
905 while (oldvallen > 0) {
907 if (!
isspace((
unsigned char)(*oldval)))
910 }
while (--oldvallen > 0);
911 if (oldvallen < newvallen)
914 && (oldvallen == newvallen
915 ||
isspace((
unsigned char) oldval[newvallen]))) {
920 if (
isspace((
unsigned char)(*oldval)))
923 }
while (--oldvallen > 0);
937 const char* user_header,
951 if (!user_header || !(newhdrlen = strlen(user_header)))
954 if (!(hdr = (
char*)
info->http_user_header) || !(hdrlen = strlen(hdr))) {
957 if (!hdr && !(hdr =
strdup(
"")))
965 if (!(newhdr = (
char*)
malloc(newhdrlen + 1))) {
969 memcpy(newhdr, user_header, newhdrlen + 1);
973 char* eol = strchr(
newline,
'\n');
974 char* eot = strchr(
newline,
':');
983 newlinelen = (size_t)
985 if (!eot || eot >=
newline + newlinelen) {
990 if (eot >
newline && eot[-1] ==
'\r')
993 eot = newhdr + newhdrlen;
995 if (!(newtaglen = (
size_t)(eot -
newline)))
999 newtagval =
newline + newtaglen;
1001 assert(*newtagval ==
':');
1002 while (++newtagval <
newline + newlinelen) {
1003 if (!
isspace((
unsigned char)(*newtagval)))
1008 newlen = newtagval <
newline + newlinelen ? newlinelen : 0;
1012 if (!(newlen = newlinelen - (
size_t)(newtagval -
newline)))
1020 if (newlen && eol) {
1021 if (eol[-1] ==
'\r')
1030 for (line = hdr; *line; line += linelen) {
1035 eol = strchr(line,
'\n');
1036 eot = strchr(line,
':');
1038 linelen = (size_t)(eol ? eol - line + 1 : hdr + hdrlen - line);
1039 if (!eot || eot >= line + linelen)
1042 taglen = (size_t)(eot - line);
1045 assert(0 < taglen && taglen <= linelen);
1049 off = !eol ? 0 : eol[-1] !=
'\r' ? 1 : 2;
1051 assert(line[taglen] ==
':');
1054 newtagval, newlen)) {
1057 line += linelen - off;
1062 len = linelen - off;
1066 off = (size_t)(line - hdr);
1070 if (!(temp = (
char*) realloc(hdr, hdrlen +
len + 1))) {
1080 memcpy(line + 1, newtagval, newlen - 1);
1085 }
else if (
len > newlen) {
1088 memmove(line + newlen, line +
len, hdrlen - off + 1);
1093 memcpy(line,
newline, newlen);
1099 memmove(line, line + linelen, hdrlen - off + 1);
1107 off = (size_t)(
newline - newhdr);
1108 newhdrlen -= newlinelen;
1120 info->http_user_header = hdr;
1154 const char *user, *pass, *host, *path, *args;
1155 size_t userlen, passlen, hostlen, pathlen, argslen;
1170 s = (
const char*) memchr(url,
':',
len);
1172 if (!
isdigit((
unsigned char) s[1]) || s[1] ==
'0')
1174 len = (size_t)(s - url);
1176 if (
len >=
sizeof(
info->host))
1182 port = strtol(++s, &p, 10);
1183 if (errno || s == p || *p)
1185 if (!port || port ^ (port & 0xFFFF))
1187 info->port = (
unsigned short) port;
1197 if ((s = strstr(url,
"//")) != 0) {
1203 len = (size_t)(s++ - url);
1209 hostlen = strcspn(host,
"/?#");
1212 path = host + hostlen;
1216 user = pass = host = (scheme ==
eURL_File ?
"" : 0);
1217 userlen = passlen = 0;
1219 if (!(s = (
const char*)
memrchr(host,
'@', hostlen))) {
1221 userlen = passlen = 0;
1224 userlen = (size_t)(s - user);
1226 hostlen = (size_t)(path - s);
1229 if (!(s = (
const char*) memchr(user,
':', userlen))) {
1233 userlen = (size_t)(s++ - user);
1235 passlen = (size_t)(host - s);
1240 if ((s = (
const char*) memchr(host,
':', hostlen)) != 0) {
1241 hostlen = (size_t)(s - host);
1242 if (!hostlen || !
isdigit((
unsigned char)s[1]) || s[1]==
'0')
1245 port = strtol(++s, &p, 10);
1246 if (errno || s == p || p != path)
1248 if (!port || port ^ (port & 0xFFFF))
1253 if (userlen >=
sizeof(
info->user) ||
1254 passlen >=
sizeof(
info->pass) ||
1255 hostlen >=
sizeof(
info->host)) {
1261 s = (
const char*) strchr(url,
':');
1262 if (s && s != url &&
1270 && *++s !=
'0' && (hostlen = strspn(s,
kDigits))
1271 && memchr(
"/?#", s[hostlen], 4)
1272 && (errno = 0, (port = strtol(s, &p, 10)) != 0) && !errno
1273 && p == s + hostlen && !(port ^ (port & 0xFFFF))
1286 userlen = passlen = 0;
1288 assert(!hostlen || host);
1289 if (hostlen && hostlen == strlen(
info->host)
1295 ? strcspn(path,
"?#") : strlen(path));
1296 args = path + pathlen;
1298 if ((!pathlen && !*args) || (pathlen && *path ==
'/')) {
1309 ? strcspn(
info->path,
"?#") : strlen(
info->path));
1317 len = (size_t)(++p -
info->path);
1319 if (
len + pathlen >=
sizeof(
info->path))
1326 argslen = strlen(args);
1329 else if (!(frag = strchr(args + 1,
'#')))
1330 frag = args + argslen;
1331 assert(!*frag || *frag ==
'#');
1337 if ((
size_t)(p -
info->path)
1338 + pathlen + argslen >=
sizeof(
info->path)) {
1342 }
else if ((frag = strchr(
info->path,
'#')) != 0) {
1345 if ((
size_t)(p -
info->path)
1346 + pathlen + argslen +
len >=
sizeof(
info->path)) {
1351 if ((
size_t)(p -
info->path)
1352 + pathlen + argslen >=
sizeof(
info->path)) {
1357 memcpy(p + pathlen, args, argslen);
1358 p[pathlen + argslen +
len] =
'\0';
1360 && (args = strchr(
info->path,
'#'))) {
1362 memmove(p + pathlen, args, strlen(args) + 1);
1366 memcpy(p, path, pathlen);
1367 if (user && (*user || host)) {
1369 memcpy(
info->user, user, userlen);
1370 info->user[userlen] =
'\0';
1371 memcpy(
info->pass, pass, passlen);
1372 info->pass[passlen] =
'\0';
1375 info->port = (
unsigned short)(port < 0 ? 0 : port);
1378 memcpy(
info->host, host, hostlen);
1379 info->host[hostlen] =
'\0';
1381 info->scheme = scheme;
1390 size_t n = strcspn(
str, sep);
1395 sep += (size_t)(strchr(sep,
str[
n++]) - sep) + 1;
1406 size_t plen, x_alen;
1415 info->path[0] =
'\0';
1421 x_args =
info->path + strcspn(
info->path, sep);
1425 info->path[0] =
'\0';
1426 else if (x_args !=
info->path)
1431 x_alen = strlen(x_args);
1432 if ((frag = (
const char*) memchr(path,
'#', plen)) != 0 && !frag[1])
1434 if (plen + x_alen >=
sizeof(
info->path))
1438 memcpy(
info->path, path, plen);
1445 size_t plen, x_alen;
1453 if (!path || !*path)
1459 x_args =
info->path + strcspn(
info->path, sep);
1460 x_alen = strlen(x_args);
1462 if (*path ==
'?' || *path ==
'#') {
1463 x_path = (
char*) memchr (
info->path,
1464 *path, (
size_t)(x_args -
info->path));
1467 if (*path ==
'#' && !path[1])
1469 }
else if (*path !=
'/') {
1471 '/', (
size_t)(x_args -
info->path));
1473 x_path =
info->path;
1477 x_path =
info->path + strcspn(
info->path,
"?#");
1478 if (x_path !=
info->path && x_path[-1] ==
'/')
1481 if ((
size_t)(x_path -
info->path) + plen + x_alen >=
sizeof(
info->path))
1484 memmove(x_path + plen, x_args, x_alen + 1);
1485 memcpy(x_path, path, plen);
1492 size_t alen, x_flen, room;
1499 alen = args ? strlen(args) : 0;
1501 x_args =
info->path + strcspn(
info->path,
"?#");
1507 if (*x_args ==
'?') {
1508 x_frag = (x_args + 1) + strcspn(x_args + 1,
"#");
1512 memmove(x_args, x_frag, strlen(x_frag) + 1);
1517 if (!(frag = (
const char*) memchr(args,
'#', alen))) {
1519 x_frag = x_args + strcspn(x_args,
"#");
1520 x_flen = strlen(x_frag);
1527 room = !(*args ==
'#') + alen;
1528 if ((
size_t)(x_args -
info->path) + room + x_flen >=
sizeof(
info->path))
1532 memmove(x_args + room, x_frag, x_flen + 1);
1533 if (!(*args ==
'#'))
1535 memcpy(x_args, args, alen);
1537 x_args[alen] =
'\0';
1556 flen = frag ? strlen(frag += !(*frag !=
'#')) : 0;
1558 x_frag =
info->path + strcspn(
info->path,
"#");
1564 if ((
size_t)(x_frag -
info->path) + flen >=
sizeof(
info->path))
1568 memcpy(x_frag, frag, flen);
1580 args =
info->path + strcspn(
info->path,
"?#");
1591 size_t alen, vlen, x_alen, x_flen, room;
1592 char* x_args, *x_frag;
1596 if (!arg || !(alen = strcspn(arg,
"#")))
1598 vlen =
val ? 1 + strcspn(
val,
"#") : 0;
1600 x_args =
info->path + strcspn(
info->path,
"?#");
1601 x_alen = strlen(x_args);
1603 if (*x_args ==
'?') {
1604 x_frag = (x_args + 1) + strcspn(x_args + 1,
"#");
1605 x_flen = x_alen - (size_t)(x_frag - x_args);
1612 room = (x_alen == 1 ? 0 : x_alen) + 1 + (alen + vlen);
1613 if ((
size_t)(x_args -
info->path) + room + x_flen >=
sizeof(
info->path))
1616 assert(!x_flen || *x_frag ==
'#');
1618 memmove(x_args + room, x_frag, x_flen + 1);
1625 memcpy(x_args, arg, alen);
1629 memcpy(x_args,
val, vlen);
1650 size_t alen, vlen, x_alen, room;
1651 char* x_args, *xx_args;
1655 if (!arg || !(alen = strcspn(arg,
"#")))
1657 vlen =
val ? 1 + strcspn(
val,
"#") : 0;
1659 x_args =
info->path + strcspn(
info->path,
"?#");
1660 x_alen = strlen(x_args);
1663 if (*xx_args ==
'?' && (!xx_args[1] || xx_args[1] ==
'#')) {
1669 room += alen + vlen;
1670 if ((
size_t)(x_args -
info->path) + room + x_alen >=
sizeof(
info->path))
1674 if (*xx_args ==
'?')
1676 memmove(xx_args + room, xx_args, x_alen + 1);
1679 memcpy(x_args, arg, alen);
1683 memcpy(x_args,
val, vlen);
1704 size_t alen, x_alen;
1709 if (!arg || !(alen = strcspn(arg,
"=&#")))
1713 x_args =
info->path + strcspn(
info->path,
"?#");
1714 for (x_a = x_args; *x_a && *x_a !=
'#'; x_a += x_alen) {
1715 if (x_a == x_args || *x_a ==
'&')
1717 x_alen = strcspn(x_a,
"&#");
1718 if (x_alen < alen ||
strncasecmp(x_a, arg, alen) != 0 ||
1720 x_a[alen] !=
'=' && x_a[alen] !=
'&' && x_a[alen] !=
'#')) {
1723 if (x_a[x_alen] ==
'&')
1727 memmove(x_a, x_a + x_alen, strlen(x_a + x_alen) + 1);
1747 while (*args && *args !=
'#') {
1748 size_t alen = strcspn(args,
"&#");
1751 if (args[alen] ==
'&')
1799 return !strchr(addr,
' ')
1801 || ((c = strchr(addr,
'.')) != 0 && c[1] &&
1802 (c = strchr(c + 2,
'.')) != 0 && c[1]));
1809 const char* c = client_host;
1815 strncpy0(addr, client_host,
sizeof(addr) - 1);
1820 || !(
ip = (*c && !local_host
1824 || !(s = (
char*)
malloc(strlen(client_host) + strlen(addr) + 3))) {
1828 sprintf(s,
"%s(%s)", client_host, addr);
1829 if (client_host != c)
1830 free((
void*) client_host);
1831 for (client_host = s; *s; ++s) {
1840 const char* service)
1842 static const char kService[] =
"service";
1843 static const char kAddress[] =
"address";
1844 static const char kPlatform[] =
"platform";
1854 sprintf(ua,
"User-Agent: %.80s", s);
1863 local_host = !
info->client_host[0];
1872 if (s !=
info->client_host)
1898 svclen = strlen(
info->svc);
1933 memcpy((
char*) x_info->
svc,
info->svc, svclen + 1);
1947 if (
info->http_user_header && *
info->http_user_header
1951 if (
info->http_referer && *
info->http_referer
1965 sprintf(
buf,
"0x%08lX (INVALID != 0x%08lX)",
1973 sprintf(
buf,
"(#%u)", num);
2001 sprintf(
buf,
"%hu", port);
2010 switch (req_method) {
2012 return v1 ?
"ANY/1.1" :
"ANY";
2014 return v1 ?
"GET/1.1" :
"GET";
2016 return v1 ?
"POST/1.1" :
"POST";
2018 return v1 ?
"HEAD/1.1" :
"HEAD";
2020 return v1 ?
"CONNECT/1.1" :
"CONNECT";
2057 unsigned int who, what;
2060 who = cred->
type / 100;
2061 what = cred->
type % 100;
2066 return "(GNUTLS X.509 Cert Cred)";
2068 sprintf(
buf,
"(GNUTLS/%u)", what);
2074 return "(MBEDTLS X.509 Cert & PK)";
2076 sprintf(
buf,
"(MBEDTLS/%u)", what);
2082 sprintf(
buf,
"(TLS 0x%08X/%u)", cred->
type, what);
2088 const char*
str,
int quote)
2090 sprintf(s + strlen(s),
"%-16.16s: %s%s%s\n", name,
2091 str && quote ?
"\"" :
"",
2093 str && quote ?
"\"" :
"");
2107 static void s_SaveBool(
char* s,
const char* name,
unsigned int bbb)
2114 sprintf(s + strlen(s),
"%-16.16s: %lu\n", name, lll);
2118 const char* uh,
size_t uhlen)
2121 s += sprintf(s,
"%-16.16s: ", name);
2126 memcpy(s,
"NULL\n", 6);
2139 "ConnNetInfo_Log: NULL", 0, 0);
2143 uhlen =
info->http_user_header ? strlen(
info->http_user_header) : 0;
2145 len =
sizeof(*info) + 1024
2147 + (
info->http_referer ? strlen(
info->http_referer) : 0)
2148 + strlen(
info->svc);
2153 "ConnNetInfo_Log: Cannot allocate memory");
2157 strcpy(s,
"ConnNetInfo_Log\n"
2158 "#################### [BEGIN] SConnNetInfo:\n");
2165 if (*
info->client_host)
2171 | (
info->http_version
2178 #if defined(_DEBUG) && !defined(NDEBUG)
2198 #if defined(_DEBUG) && !defined(NDEBUG)
2202 ?
"(set)" :
"\"\""));
2204 if (*
info->http_proxy_pass) {
2206 ?
"(set)" :
"(ignored)"));
2213 if (
info->timeout) {
2225 :
info->debug_printout
2228 :
info->debug_printout
2235 if (
info->credentials)
2238 "#################### [_END_] SConnNetInfo\n");
2241 LOG_Write(lg,
NCBI_C_ERRCODE_X, 12, sev, 0, 0, 0, 0, s, 0, 0);
2268 schlen = strlen(scheme);
2270 len = schlen + 4 + strlen(path);
2272 len += strlen(
info->host) + 7;
2276 strlwr((
char*) memcpy(url, scheme, schlen + 1));
2278 len += sprintf(url +
len,
2279 &
"://%s"[schlen ? 0 : path ? 1 : 3],
info->host);
2280 if (
info->port || !path)
2281 len += sprintf(url +
len,
":%hu",
info->port);
2283 "%s%s", &
"/"[!(path && *path !=
'/')], path ? path :
"");
2296 info->tmo = *timeout;
2329 unsigned short port,
2333 size_t content_length,
2336 const char* user_hdr,
2341 static const char kHttp[][12] = {
" HTTP/1.0\r\n",
2355 unsigned short x_port;
2357 size_t user_hdr_len = user_hdr && *user_hdr ? strlen(user_hdr) : 0;
2361 args_len = strcspn(path,
"?#");
2369 if (!sock || !host || !*host || !path_len || args_len < path_len) {
2382 args = &path[path_len] + !(path[path_len] !=
'?');
2385 while (user_hdr_len) {
2386 if (!
isspace((
unsigned char) user_hdr[0]))
2391 while (user_hdr_len) {
2392 if (!
isspace((
unsigned char) user_hdr[user_hdr_len - 1]))
2398 x_c_l = content_length && content_length != (size_t)(-1L) ? 1 : 0;
2404 sprintf(temp,
":%hu", port);
2408 (
"[URL_Connect; http%s://%s%s%s%.*s] "
2409 " Content-Length (%lu) is ignored with request method %s",
2411 &
"/"[path_len && *path ==
'/'], (
int) path_len, path,
2412 (
unsigned long) content_length,
2414 content_length = (size_t)(-1L);
2418 x_c_l = content_length
2427 sprintf(temp,
":%hu", port);
2431 (
"[URL_Connect; http%s://%s%s%s%.*s] "
2432 " Unsupported request method %s",
2434 &
"/"[path_len && *path ==
'/'], (
int) path_len, path,
2444 args_len = args ? strcspn(args,
"#") : 0;
2463 sprintf(temp,
"Content-Length: %lu\r\n",
2464 (
unsigned long) content_length))) ||
2475 && content_length && content_length != (
size_t)(-1L)
2477 int x_errno = errno;
2479 sprintf(temp,
":%hu", port);
2483 (
"[URL_Connect; http%s://%s%s%s%.*s%s%.*s] "
2484 " Cannot build HTTP header",
2486 &
"/"[path_len && *path ==
'/'], (
int)path_len, path,
2487 &
"?"[!args_len], (
int) args_len, args));
2494 int x_errno = errno;
2496 sprintf(temp,
":%hu", port);
2500 (
"[URL_Connect; http%s://%s%s%s%.*s%s%.*s] "
2501 " Cannot maintain HTTP header (%lu byte%s)",
2503 &
"/"[path_len && *path ==
'/'], (
int)path_len, path,
2504 &
"?"[!args_len], (
int) args_len, args,
2505 (
unsigned long) hdr_len, &
"s"[hdr_len == 1]));
2515 init.size = hdr_len;
2537 sprintf(timeout,
"[%u.%06u]",
2538 o_timeout->
usec / 1000000 + o_timeout->
sec,
2539 o_timeout->
usec % 1000000);
2543 sprintf(temp,
":%hu", port);
2547 (
"[URL_Connect; http%s://%s%s%s%.*s%s%.*s] "
2548 " Failed to %s: %s%s",
2550 &
"/"[path_len && *path ==
'/'], (
int) path_len, path,
2551 &
"?"[!args_len], (
int) args_len, args,
2552 s ?
"use connection" :
"connect",
2562 unsigned short port,
2566 size_t content_length,
2569 const char* user_hdr,
2573 static const char kHost[] =
"Host: ";
2574 const char* x_hdr = user_hdr;
2575 static void* s_Once = 0;
2581 " *DEPRECATED*!!! DON'T USE IT!! Update your code please!");
2585 "[URL_Connect] Unsupported version of HTTP protocol");
2591 while (x_hdr && *x_hdr) {
2592 if (x_hdr != user_hdr)
2598 x_hdr = strchr(x_hdr,
'\n');
2601 size_t x_len = host && *host ? strlen(host) : 0;
2602 char* x_host = x_len ? (
char*)
malloc(x_len +
sizeof(
kHost)+6) : 0;
2605 memcpy(x_host +
sizeof(
kHost) - 1, host, x_len);
2606 x_len +=
sizeof(
kHost) - 1;
2608 sprintf(x_host + x_len,
":%hu", port);
2610 x_host[x_len] =
'\0';
2621 if (args && encode_args && (x_add = strcspn(args,
"#")) > 0) {
2623 size_t size = 3 * x_add;
2624 size_t rd_len, wr_len;
2627 (
"[URL_Connect] Out of memory (%lu)",
2628 (
unsigned long)(
size + 1)));
2629 if (x_hdr != user_hdr)
2630 free((
void*) x_hdr);
2636 x_args[wr_len] =
'\0';
2643 req_method, content_length,
2644 o_timeout, rw_timeout,
2650 if (x_hdr != user_hdr)
2651 free((
void*) x_hdr);
2673 const void* pattern,
2674 size_t pattern_size,
2676 size_t* n_discarded)
2690 if (!pattern_size) {
2692 buf_size =
sizeof(x_buf);
2694 buf_size = pattern ? pattern_size << 1 : pattern_size;
2697 if (buf_size <=
sizeof(x_buf) && pattern) {
2698 buf_size =
sizeof(x_buf);
2700 }
else if (!(
buf = (
char*)
malloc(buf_size)))
2708 status = io_func(stream, xx_buf, buf_size, &n_read,
eIO_Read);
2709 assert(buf_size && n_read <= buf_size);
2716 if (xx_buf ==
buf) {
2726 *n_discarded += n_read;
2727 if (!(buf_size -= n_read)) {
2734 buf_size =
sizeof(x_buf);
2755 size_t x_read, n_stored;
2757 assert(n_read <= pattern_size && n_read < buf_size);
2758 status = io_func(stream,
buf + n_read, buf_size - n_read,
2760 assert(x_read <= buf_size - n_read);
2766 n_stored = n_read + x_read;
2768 if (n_stored > pattern_size) {
2771 const char*
b =
buf;
2772 for (n_check = n_stored - pattern_size; n_check; --n_check) {
2773 if (*
b++ != *((
const char*)pattern))
2777 if (memcmp(
b, (
const char*)pattern + 1, pattern_size) == 0)
2782 size_t x_discarded = (size_t)(
b -
buf) + pattern_size;
2784 x_discarded - n_read)) {
2788 *n_discarded += x_discarded - n_read;
2790 status = io_func(stream,
buf + x_discarded,
2800 *n_discarded += x_read;
2801 if (discard && !
BUF_Write(discard,
buf + n_read, x_read)) {
2809 if (n_stored > pattern_size) {
2810 n_read = pattern_size;
2845 const void* pattern,
2846 size_t pattern_size,
2848 size_t* n_discarded)
2851 (
conn,
s_CONN_IO, pattern, pattern_size, discard, n_discarded);
2876 const void* pattern,
2877 size_t pattern_size,
2879 size_t* n_discarded)
2882 (sock,
s_SOCK_IO, pattern, pattern_size, discard, n_discarded);
2911 const void* pattern,
2912 size_t pattern_size,
2914 size_t* n_discarded)
2932 unsigned int rc = (
unsigned int)(ch -
'0');
2935 rc = (
unsigned int)((ch |
' ') -
'a');
2936 return rc <= 5 ? (
int)(rc + 10) : -1;
2943 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
2944 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
2945 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
2946 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
2947 "+",
"!",
"%22",
"%23",
"$",
"%25",
"%26",
"'",
2948 "(",
")",
"*",
"%2B",
",",
"-",
".",
"%2F",
2949 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
2950 "8",
"9",
"%3A",
"%3B",
"%3C",
"%3D",
"%3E",
"%3F",
2951 "%40",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
2952 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
2953 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
2954 "X",
"Y",
"Z",
"%5B",
"%5C",
"%5D",
"%5E",
"_",
2955 "%60",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
2956 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
2957 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
2958 "x",
"y",
"z",
"%7B",
"%7C",
"%7D",
"%7E",
"%7F",
2959 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
2960 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
2961 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
2962 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
2963 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
2964 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
2965 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
2966 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
2967 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
2968 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
2969 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
2970 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
2971 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
2972 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
2973 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
2974 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
2977 #define VALID_URL_SYMBOL(ch) (s_EncodeTable[(unsigned char)ch][0] != '%')
2981 (
const void* src_buf,
2986 size_t* dst_written,
2987 const char* allow_symbols)
2989 const char* src = (
char*
const) src_buf;
2990 char* dst = (
char*) dst_buf;
2994 if (!src_size || !dst_size)
2999 for ( ; *src_read != src_size && *dst_written != dst_size;
3000 ++(*src_read), ++(*dst_written), ++src, ++dst) {
3006 if (*src_read + 2 < src_size) {
3010 *dst = (char)((i1 << 4) + i2);
3015 }
else if (src != src_buf) {
3019 if (!allow_symbols || *allow_symbols)
3020 return *dst_written ? 1 : 0;
3024 || (allow_symbols && (!*allow_symbols
3025 || strchr(allow_symbols, *src)))) {
3028 return *dst_written ? 1 : 0;
3032 assert(src == (
const char*) src_buf + *src_read );
3033 assert(dst == (
char*) dst_buf + *dst_written);
3034 assert(*src_read && *dst_written);
3040 (
const void* src_buf,
3045 size_t* dst_written)
3048 (src_buf, src_size, src_read, dst_buf, dst_size, dst_written, 0);
3053 (
const void* src_buf,
3058 size_t* dst_written,
3059 const char* allow_symbols)
3061 const char* src = (
const char*) src_buf;
3062 char* dst = (
char*) dst_buf;
3066 if (!src_size || !dst_size || !dst || !src)
3069 for ( ; *src_read != src_size && *dst_written != dst_size;
3070 ++(*src_read), ++(*dst_written), ++src, ++dst) {
3071 const char* subst = allow_symbols ? strchr(allow_symbols, *src) : 0;
3077 if (*subst !=
'%') {
3079 }
else if (*dst_written < dst_size - 2) {
3081 *(++dst) = *(++subst);
3082 *(++dst) = *(++subst);
3087 assert(src == (
const char*) src_buf + *src_read );
3088 assert(dst == (
char*) dst_buf + *dst_written);
3093 (
const void* src_buf,
3098 size_t* dst_written)
3101 (src_buf, src_size, src_read, dst_buf, dst_size, dst_written, 0);
3147 const char* x_type, *x_subtype, *x_encoding;
3169 if ( *x_encoding ) {
3171 + strlen(x_encoding) + 4 <
sizeof(x_buf));
3172 sprintf(x_buf,
"%s%s/%s-%s\r\n",
3176 + 3 <
sizeof(x_buf));
3177 sprintf(x_buf,
"%s%s/%s\r\n",
kContentType, x_type, x_subtype);
3179 len = strlen(x_buf);
3220 if ((sscanf(x_buf,
" content-type: %s ", x_type) != 1 &&
3221 sscanf(x_buf,
" %s ", x_type) != 1)
3222 || !(x_subtype = strchr(x_type,
'/'))) {
3226 *x_subtype++ =
'\0';
3227 x_size = strlen(x_subtype);
3240 char* x_encoding = x_subtype +
x_size -
len;
3241 if (x_encoding[-1] ==
'-'
3247 x_encoding[-1] =
'\0';
3313 memcpy(
buf,
"0", 2);
3323 for (p = (
unsigned short)(m + 1);
mask; ++p,
mask >>= 1) {
3326 size_t k = (size_t) sprintf(port, &
" %hu"[!
len], p);
3328 memcpy(
buf +
len, port, k);
3333 m = (
unsigned short)(m + (
sizeof(
s_FWPorts[0]) << 3));
static const char * kContentType
static CS_CONNECTION * conn
static void DLIST_NAME() init(DLIST_LIST_TYPE *list)
std::ofstream out("events_result.xml")
main entry point for tests
int BUF_Write(BUF *pBuf, const void *data, size_t size)
struct SNcbiBuf * BUF
handle of a buffer
int BUF_Pushback(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)
void BUF_Destroy(BUF buf)
EIO_Status CONN_Read(CONN conn, void *buf, size_t size, size_t *n_read, EIO_ReadMethod how)
const STimeout g_NcbiDefConnTimeout
DEF_CONN_TIMEOUT as STimeout.
EIO_Status CONN_Pushback(CONN conn, const void *data, size_t size)
Push "size" bytes from the buffer "data" back into connection.
EIO_Status SOCK_SetTimeout(SOCK sock, EIO_Event event, const STimeout *timeout)
Specify timeout for the connection I/O (see SOCK_[Read|Write|Close]()).
void SOCK_DisableOSSendDelay(SOCK sock, int on_off)
Control OS-defined send strategy by disabling/enabling the TCP Nagle algorithm (which is on by defaul...
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".
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_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_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.
unsigned int SOCK_GetLocalHostAddress(ESwitch reget)
Get (and cache for faster follow-up retrievals) IPv4 address of local host.
const char * SOCK_gethostbyaddr(unsigned int addr, char *name, size_t namelen)
Same as SOCK_gethostbyaddrEx(,,<current API data logging>)
int SOCK_isip(const char *host)
Equivalent of SOCK_isip(host, 0)
unsigned int TSOCK_Flags
bitwise "OR" of ESOCK_Flags
@ fSOCK_Secure
subsumes CloseOnExec regardless of Keep
#define LOG_WRITE(lg, code, subcode, level, message)
Auxiliary plain macros to write message (maybe, with raw data) to the log.
ELOG_Level
Log severity level.
#define REG_CONN_HTTP_VERSION
#define DEF_CONN_HTTP_PROXY_SKIP
char http_proxy_host[255+1]
int ConnNetInfo_ExtendUserHeader(SConnNetInfo *info, const char *header)
int ConnNetInfo_AddPath(SConnNetInfo *info, const char *path)
int ConnNetInfo_SetupStandardArgs(SConnNetInfo *info, const char *service)
#define UTIL_PrintableString(d, s, b, f)
Same as UTIL_PrintableStringEx(..., 0) – i.e.
char http_proxy_user[63+1]
unsigned short http_proxy_port
#define DEF_CONN_HTTP_PROXY_HOST
#define REG_CONN_HTTP_PROXY_PORT
int ConnNetInfo_SetTimeout(SConnNetInfo *info, const STimeout *timeout)
int ConnNetInfo_OverrideUserHeader(SConnNetInfo *info, const char *header)
void ConnNetInfo_DeleteAllArgs(SConnNetInfo *info, const char *args)
int ConnNetInfo_ParseURL(SConnNetInfo *info, const char *url)
char * MIME_ComposeContentTypeEx(EMIME_Type type, EMIME_SubType subtype, EMIME_Encoding encoding, char *buf, size_t bufsize)
int ConnNetInfo_SetArgs(SConnNetInfo *info, const char *args)
int ConnNetInfo_AppendUserHeader(SConnNetInfo *info, const char *user_header)
SConnNetInfo * ConnNetInfo_Clone(const SConnNetInfo *info)
int ConnNetInfo_AppendArg(SConnNetInfo *info, const char *arg, const char *val)
#define REG_CONN_HTTP_PROXY_USER
#define REG_CONN_DEBUG_PRINTOUT
#define REG_CONN_HTTP_USER_HEADER
const char * ConnNetInfo_GetValue(const char *service, const char *param, char *value, size_t value_size, const char *def_value)
#define DEF_CONN_LB_DISABLE
#define DEF_CONN_HTTP_PUSH_AUTH
#define REG_CONN_STATELESS
EIO_Status CONN_StripToPattern(CONN conn, const void *pattern, size_t pattern_size, BUF *discard, size_t *n_discarded)
Discard all input data before (and including) the first occurrence of a "pattern".
#define REG_CONN_HTTP_PUSH_AUTH
unsigned int usec
microseconds (modulo 1,000,000)
#define REG_CONN_LB_DISABLE
int URL_Decode(const void *src_buf, size_t src_size, size_t *src_read, void *dst_buf, size_t dst_size, size_t *dst_written)
#define CONN_CONTENT_TYPE_LEN
char http_proxy_pass[63+1]
#define DEF_CONN_FIREWALL
const char * ConnNetInfo_GetArgs(const SConnNetInfo *info)
int ConnNetInfo_PreOverrideArg(SConnNetInfo *info, const char *arg, const char *val)
#define DEF_CONN_REQ_METHOD
#define REG_CONN_FIREWALL
#define REG_CONN_HTTP_PROXY_LEAK
SOCK URL_Connect(const char *host, unsigned short port, const char *path, const char *args, EReqMethod req_method, size_t content_length, const STimeout *o_timeout, const STimeout *rw_timeout, const char *user_hdr, int encode_args, TSOCK_Flags flags)
#define DEF_CONN_HTTP_PROXY_LEAK
#define DEF_CONN_STATELESS
#define DEF_CONN_HTTP_PROXY_PASS
char * ConnNetInfo_URL(const SConnNetInfo *info)
#define DEF_CONN_DEBUG_PRINTOUT
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).
int ConnNetInfo_PostOverrideArg(SConnNetInfo *info, const char *arg, const char *val)
void LOG_Write(LOG lg, int code, int subcode, ELOG_Level level, const char *module, const char *func, const char *file, int line, const char *message, const void *raw_data, size_t raw_size)
Upon having filled SLOG_Message data from parameters, write a message (perhaps with raw data attached...
int ConnNetInfo_SetUserHeader(SConnNetInfo *info, const char *user_header)
int MIME_ParseContentTypeEx(const char *str, EMIME_Type *type, EMIME_SubType *subtype, EMIME_Encoding *encoding)
void ConnNetInfo_DeleteUserHeader(SConnNetInfo *info, const char *header)
#define DEF_CONN_HTTP_PROXY_USER
#define REG_CONN_HTTP_REFERER
void URL_EncodeEx(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)
#define DEF_CONN_HTTP_REFERER
#define REG_CONN_EXTERNAL
void ConnNetInfo_Log(const SConnNetInfo *info, ELOG_Level sev, LOG lg)
#define REG_CONN_REQ_METHOD
const char * http_user_header
size_t UTIL_PrintableStringSize(const char *data, size_t size)
Calculate size of buffer needed to store printable representation of the block of data of the specifi...
#define DEF_CONN_REG_SECTION
int ConnNetInfo_DeleteArg(SConnNetInfo *info, const char *arg)
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_hdr, NCBI_CRED cred, TSOCK_Flags flags, SOCK *sock)
#define REG_CONN_HTTP_PROXY_SKIP
char * UTIL_NcbiLocalHostName(char *hostname)
Cut off well-known NCBI domain suffix out of the passed "hostname".
EIO_Status SOCK_StripToPattern(SOCK sock, const void *pattern, size_t pattern_size, BUF *discard, size_t *n_discarded)
SConnNetInfo * ConnNetInfo_Create(const char *service)
#define REG_CONN_HTTP_PROXY_HOST
int ConnNetInfo_PrependArg(SConnNetInfo *info, const char *arg, const char *val)
#define DEF_CONN_HTTP_USER_HEADER
EIO_Event
I/O event (or direction).
#define DEF_CONN_HTTP_VERSION
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 DEF_CONN_HTTP_PROXY_PORT
int ConnNetInfo_Boolean(const char *str)
#define DEF_CONN_EXTERNAL
const char * CORE_GetPlatform(void)
Return NCBI platrofm ID (if known).
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)
int ConnNetInfo_SetPath(SConnNetInfo *info, const char *path)
const char * http_referer
void ConnNetInfo_Destroy(SConnNetInfo *info)
int ConnNetInfo_SetFrag(SConnNetInfo *info, const char *frag)
uint64_t TNCBI_BigCount
Big unsigned integer for file size and position.
EIO_Status BUF_StripToPattern(BUF buffer, const void *pattern, size_t pattern_size, BUF *discard, size_t *n_discarded)
#define REG_CONN_HTTP_PROXY_PASS
@ 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
@ eFWMode_Legacy
Relay, no firewall.
@ eFWMode_Firewall
Regular firewall ports only, no fallback.
@ eFWMode_Adaptive
Regular firewall ports first, then fallback.
@ eFWMode_Fallback
Fallback ports only (w/o trying any regular)
@ eIO_ReadPlain
read readily available data only, wait if none
@ eIO_ReadWrite
eIO_Read | eIO_Write (also, eCONN_OnFlush)
unsigned int
A callback function used to compare two keys in a database.
if(yy_accept[yy_current_state])
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)
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 ...
double NCBI_simple_atof(const char *s, char **t)
Locale-independent ASCII-to-double conversion of string "s".
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,...
static void x_DestroyNetInfo(SConnNetInfo *info, unsigned int magic)
static void s_SaveKeyval(char *s, const char *name, const char *str)
static const char * x_BadMagic(unsigned int magic, char buf[])
static int x_PrependArg(SConnNetInfo *info, const char *arg, const char *val)
static void s_SaveString(char *s, const char *name, const char *str)
static int x_SetArgs(SConnNetInfo *info, const char *args)
static EIO_Status s_CONN_IO(void *stream, void *buf, size_t size, size_t *n_read, EIO_Event what)
static const char * x_ReqMethod(TReqMethod req_method, char buf[])
static int x_mkenv(char *str, size_t len)
SConnNetInfo * ConnNetInfo_CloneInternal(const SConnNetInfo *info)
#define REG_VALUE(name, value, def_value)
const char * ConnNetInfo_GetValueService(const char *service, const char *param, char *value, size_t value_size, const char *def_value)
static const char s_EncodeTable[256][4]
#define CONN_NET_INFO_MAGIC
static const char * kMIME_Encoding[eENCOD_Unknown+1]
static int x_TagValueMatches(const char *oldval, size_t oldvallen, const char *newval, size_t newvallen)
static void s_SaveStringQuot(char *s, const char *name, const char *str, int quote)
static void x_Trim(char *str)
const char * ConnNetInfo_GetValueInternal(const char *service, const char *param, char *value, size_t value_size, const char *def_value)
static TNCBI_BigCount s_FWPorts[1024/sizeof(TNCBI_BigCount)]
static EIO_Status s_SOCK_IO(void *stream, void *buf, size_t size, size_t *n_read, EIO_Event what)
static const char * x_ClientAddress(const char *client_host, int local_host)
static const char * x_SepAndLen(const char *str, const char *sep, size_t *len)
static void x_DeleteAllArgs(SConnNetInfo *info, const char *args)
static const char * x_strncpy0(char *dst, const char *src, size_t dst_size)
EIO_Status(* FDoIO)(void *stream, void *buf, size_t size, size_t *n_read, EIO_Event what)
static const char * x_Firewall(unsigned int firewall)
static EIO_Status x_URLConnectErrorReturn(SOCK sock, EIO_Status status)
void SERV_PrintFirewallPorts(char *buf, size_t bufsize, EFWMode mode)
static int x_SetupSystemHttpProxy(SConnNetInfo *info)
static void s_SaveULong(char *s, const char *name, unsigned long lll)
static const char * s_GetValue(const char *svc, size_t svclen, const char *param, char *value, size_t value_size, const char *def_value, int *generic, FStrNCmp strncompar)
static int s_InfoIsValid(const SConnNetInfo *info)
static int x_SetupHttpProxy(SConnNetInfo *info, const char *env)
static const char * x_Num(unsigned int num, char buf[])
void SERV_InitFirewallPorts(void)
static void s_SaveUserHeader(char *s, const char *name, const char *uh, size_t uhlen)
int SERV_IsFirewallPort(unsigned short port)
static EFWMode x_ParseFirewall(const char *str, int generic)
#define VALID_URL_SYMBOL(ch)
static const char * x_GetValue(const char *svc, size_t svclen, const char *param, char *value, size_t value_size, const char *def_value, int *generic, FStrNCmp strncompar)
static int s_HexChar(char ch)
static EURLScheme x_ParseScheme(const char *str, size_t len)
static const char * kMIME_Type[eMIME_T_Unknown+1]
static int x_DeleteArg(SConnNetInfo *info, const char *arg)
SConnNetInfo * ConnNetInfo_CreateInternal(const char *service)
static const char * x_GetReferer(char *str, size_t size)
static const char * x_Port(unsigned short port, char buf[])
int SERV_AddFirewallPort(unsigned short port)
static const char * x_Scheme(EURLScheme scheme, char buf[])
static const char * x_CredInfo(NCBI_CRED cred, char buf[])
static int x_StrcatCRLF(char **dstp, const char *src)
int(* FStrNCmp)(const char *s1, const char *s2, size_t n)
static int x_IsSufficientAddress(const char *addr)
static EIO_Status s_StripToPattern(void *stream, FDoIO io_func, const void *pattern, size_t pattern_size, BUF *discard, size_t *n_discarded)
static int s_ModifyUserHeader(SConnNetInfo *info, const char *user_header, enum EUserHeaderOp op)
static const char kDigits[]
static EIO_Status s_BUF_IO(void *stream, void *buf, size_t size, size_t *n_read, EIO_Event what)
static void s_SaveBool(char *s, const char *name, unsigned int bbb)
static const char * kMIME_SubType[eMIME_Unknown+1]
static int x_AppendArg(SConnNetInfo *info, const char *arg, const char *val)
static size_t x_size(const char *dst, size_t len, const char *ptr)
#define CORE_Once(once)
Return non-zero (true) if "*once" had a value of NULL, and set the value to non-NULL regardless (best...
FNcbiGetReferer g_CORE_GetReferer
#define CORE_REG_GET(section, name, value, value_size, def_value)
#define NCBI_C_ERRCODE_X
Return currently set default error code.
#define CORE_LOGF_X(subcode, level, fmt_args)
#define CORE_LOGF_ERRNO_X(subcode, level, error, fmt_args)
#define CORE_TRACEF(fmt_args)
#define CORE_LOG_X(subcode, level, message)
#define CORE_LOG(level, message)
char * SERV_ServiceName(const char *service)
EIO_Status SOCK_CreateOnTopInternal(const void *handle, size_t handle_size, SOCK *sock, const SSOCK_Init *init, TSOCK_Flags flags)
EIO_Status SOCK_CreateInternal(const char *host, unsigned short port, const STimeout *timeout, SOCK *sock, const SSOCK_Init *init, TSOCK_Flags flags)
static pcre_uint8 * buffer
static const char * str(char *buf, int n)