static int/*bool*/ s_ParseHeader(const char* header, void* data, int server_error) { static const char kStateless[] = "TRY_STATELESS"; static const size_t klen = sizeof(kStateless) - 1; SServiceConnector* uuu = (SServiceConnector*) data; SERV_Update(uuu->iter, header, server_error); if (server_error) return 1/*parsed okay*/; while (header && *header) { if (strncasecmp(header, HTTP_CONNECTION_INFO, sizeof(HTTP_CONNECTION_INFO) - 1) == 0) { unsigned int i1, i2, i3, i4, ticket; unsigned char o1, o2, o3, o4; char ipaddr[40]; if (uuu->host) break/*failed - duplicate connection info*/; header += sizeof(HTTP_CONNECTION_INFO) - 1; while (*header && isspace((unsigned char)(*header))) header++; if (strncasecmp(header, kStateless, klen) == 0 && (!header[klen] || isspace((unsigned char) header[klen]))) { /* Special keyword for switching into stateless mode */ uuu->host = (unsigned int)(-1); #if defined(_DEBUG) && !defined(NDEBUG) if (uuu->net_info->debug_printout) { CORE_LOGF_X(2, eLOG_Note, ("[%s] Fallback to stateless", uuu->service)); } #endif /*_DEBUG && !NDEBUG*/ } else { int n; if (sscanf(header, "%u.%u.%u.%u %hu %x%n", &i1, &i2, &i3, &i4, &uuu->port, &ticket, &n) < 6 || (header[n] && !isspace((unsigned char) header[n]))) { break/*failed - unreadable connection info*/; } o1 = i1; o2 = i2; o3 = i3; o4 = i4; sprintf(ipaddr, "%u.%u.%u.%u", o1, o2, o3, o4); if (!(uuu->host = SOCK_gethostbyname(ipaddr)) || !uuu->port) break/*failed - bad host:port in connection info*/; uuu->ticket = SOCK_HostToNetLong(ticket); } } if ((header = strchr(header, '\n')) != 0) header++; } if (!header || !*header) return 1/*success*/; uuu->host = 0; return 0/*failure*/; }
static EHTTP_HeaderParse s_ParseHeader(const char* header, void* iter, int server_error) { struct SDISPD_Data* data = (struct SDISPD_Data*)((SERV_ITER) iter)->data; int code = 0/*success code if any*/; if (server_error) { if (server_error == 400 || server_error == 403) data->fail = 1/*true*/; } else if (sscanf(header, "%*s %d", &code) < 1) { data->eof = 1/*true*/; return eHTTP_HeaderError; } /* check for empty document */ if (!SERV_Update((SERV_ITER) iter, header, server_error) || code == 204) data->eof = 1/*true*/; return eHTTP_HeaderSuccess; }