static const char* s_AdjustNetParams(const char* service, 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, char* dynamic_header/*freed!*/) { const char *retval = 0; net_info->req_method = req_method; if (cgi_path) strncpy0(net_info->path, cgi_path, sizeof(net_info->path) - 1); if (args) strncpy0(net_info->args, args, sizeof(net_info->args) - 1); ConnNetInfo_DeleteAllArgs(net_info, cgi_args); if (ConnNetInfo_PrependArg(net_info, cgi_args, 0)) { size_t sh_len = static_header ? strlen(static_header) : 0; size_t dh_len = dynamic_header ? strlen(dynamic_header) : 0; char c_t[MAX_CONTENT_TYPE_LEN]; size_t ct_len, len; if (s_IsContentTypeDefined(service, net_info, mime_t, mime_s, mime_e) || !MIME_ComposeContentTypeEx(mime_t, mime_s, mime_e, c_t, sizeof(c_t))) { c_t[0] = '\0'; ct_len = 0; } else ct_len = strlen(c_t); if ((len = sh_len + dh_len + ct_len) != 0) { char* temp = (char*) malloc(len + 1/*EOL*/); if (temp) { strcpy(temp, static_header ? static_header : ""); strcpy(temp + sh_len, dynamic_header ? dynamic_header : ""); strcpy(temp + sh_len + dh_len, c_t); retval = temp; } } else retval = ""; } if (dynamic_header) free(dynamic_header); return retval; }
static void TEST_MIME(void) { /* MIME API */ EMIME_Type type; EMIME_SubType subtype; EMIME_Encoding encoding; char str[MAX_CONTENT_TYPE_LEN]; int i,j,k; CORE_LOG(eLOG_Note, "MIME test started"); *str = '\0'; for (k = 0, type = (EMIME_Type) k; k <= (int) eMIME_T_Unknown; k++, type = (EMIME_Type) k) { for (i = 0, subtype = (EMIME_SubType) i; i <= (int) eMIME_Unknown; i++, subtype = (EMIME_SubType) i) { for (j = 0, encoding = (EMIME_Encoding) j; j < (int) eENCOD_Unknown; j++, encoding = (EMIME_Encoding) j) { assert(!s_Try_MIME(str, type, subtype, encoding)); MIME_ComposeContentTypeEx(type, subtype, encoding, str, sizeof(str)); assert(s_Try_MIME(str, type, subtype, encoding)); } } } assert(s_Try_MIME("content-type: x-ncbi-data/x-asn-binary ", eMIME_T_NcbiData, eMIME_AsnBinary, eENCOD_None)); assert(s_Try_MIME("content-type: application/x-www-form-urlencoded ", eMIME_T_Application, eMIME_WwwForm, eENCOD_Url)); assert(s_Try_MIME("content-TYPE: \t x-ncbi-data/x-asn-text-urlencoded\r", eMIME_T_NcbiData, eMIME_AsnText, eENCOD_Url)); assert(s_Try_MIME("x-ncbi-data/x-eeee", eMIME_T_NcbiData, eMIME_Unknown, eENCOD_None)); assert(s_Try_MIME("x-ncbi-data/plain-", eMIME_T_NcbiData, eMIME_Unknown, eENCOD_None)); assert(!s_Try_MIME("content-TYPE : x-ncbi-data/x-unknown\r", eMIME_T_NcbiData, eMIME_Unknown, eENCOD_None)); assert(s_Try_MIME("text/html", eMIME_T_Text, eMIME_Html, eENCOD_None)); assert(s_Try_MIME("application/xml+soap", eMIME_T_Application, eMIME_XmlSoap, eENCOD_None)); assert(!s_Try_MIME("", eMIME_T_NcbiData, eMIME_Unknown, eENCOD_Unknown)); assert(!s_Try_MIME(0, eMIME_T_NcbiData, eMIME_Unknown, eENCOD_Unknown)); CORE_LOG(eLOG_Note, "MIME test completed"); }
void CSoapHttpClient::Invoke(CSoapMessage& response, const CSoapMessage& request, CConstRef<CSoapFault>* fault /*=0*/, const string& soap_action /*= kEmptyStr*/) const { response.Reset(); vector< TTypeInfoGetter >::const_iterator types_in; for (types_in = m_Types.begin(); types_in != m_Types.end(); ++types_in) { response.RegisterObjectType(*types_in); } char content_type[MAX_CONTENT_TYPE_LEN + 1]; // SOAPAction: // http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528 // "An HTTP client MUST use this header field when issuing a SOAP HTTP Request" CConn_HttpStream http(m_ServerUrl, 0, "SOAPAction: \"" + soap_action + "\"\r\n" + string(MIME_ComposeContentTypeEx(eMIME_T_Text, eMIME_Xml, eENCOD_None, content_type, sizeof(content_type) - 1)), x_ParseHttpHeader); auto_ptr<CObjectOStream> os(CObjectOStream::Open(eSerial_Xml, http)); auto_ptr<CObjectIStream> is(CObjectIStream::Open(eSerial_Xml, http)); // allow unknown data is->SetSkipUnknownMembers(eSerialSkipUnknown_Yes); // allow missing mandatory data is->SetVerifyData(eSerialVerifyData_No); if (m_OmitScopePrefixes) { dynamic_cast<CObjectOStreamXml*>(os.get())->SetEnforcedStdXml(true); dynamic_cast<CObjectIStreamXml*>(is.get())->SetEnforcedStdXml(true); } *os << request; dynamic_cast<CObjectIStreamXml*>(is.get())->FindFileHeader(false); *is >> response; if (fault) { *fault = SOAP_GetKnownObject<CSoapFault>(response); } }
/* Set HTTP user header */ static void x_SetupUserHeader ( SConnNetInfo* net_info, const char* appName, EMIME_Type type, EMIME_SubType subtype, EMIME_Encoding encoding ) { const char* userAgentName = NULL; char user_header [MAX_CONTENT_TYPE_LEN + 80]; /* content-type if specified */ if (type < eMIME_T_Unknown) { VERIFY( MIME_ComposeContentTypeEx (type, subtype, encoding, user_header, MAX_CONTENT_TYPE_LEN) ); ConnNetInfo_OverrideUserHeader (net_info, user_header); } /* allow the user to specify a prog. name, otherwise get it from elsewhere */ if (StringHasNoText (appName)) { const char* progName = GetProgramName(); if (StringHasNoText (progName)) { char path [PATH_MAX]; Nlm_ProgramPath (path, sizeof (path)); userAgentName = StringRChr (path, DIRDELIMCHR); if (userAgentName) ++userAgentName; } else userAgentName = progName; } else userAgentName = appName; if (StringDoesHaveText (userAgentName)) { sprintf (user_header, "User-Agent: %.80s\r\n", userAgentName); ConnNetInfo_ExtendUserHeader (net_info, user_header); } }
char* SERV_WriteInfo(const SSERV_Info* info) { char c_t[MAX_CONTENT_TYPE_LEN]; const SSERV_Attr* attr; size_t reserve; char* str; if (!(attr = s_GetAttrByType(info->type))) return 0; if (info->type != fSERV_Dns && MIME_ComposeContentTypeEx(info->mime_t, info->mime_s, info->mime_e, c_t, sizeof(c_t))) { char* p; assert(c_t[strlen(c_t) - 2] == '\r' && c_t[strlen(c_t) - 1] == '\n'); c_t[strlen(c_t) - 2] = 0; p = strchr(c_t, ' '); assert(p); p++; memmove(c_t, p, strlen(p) + 1); } else *c_t = 0; reserve = attr->tag_len+1 + MAX_IP_ADDR_LEN + 1+5/*port*/ + 1+10/*flag*/ + 1+9/*coef*/ + 3+strlen(c_t)/*cont.type*/ + 1+5/*locl*/ + 1+5/*priv*/ + 1+7/*quorum*/ + 1+14/*rate*/ + 1+5/*sful*/ + 1+12/*time*/ + 1/*EOL*/; /* write server-specific info */ if ((str = attr->vtable.Write(reserve, &info->u)) != 0) { char* s = str; size_t n; memcpy(s, attr->tag, attr->tag_len); s += attr->tag_len; *s++ = ' '; s += SOCK_HostPortToString(info->host, info->port, s, reserve); if ((n = strlen(str + reserve)) != 0) { *s++ = ' '; memmove(s, str + reserve, n + 1); s = str + strlen(str); } assert(info->flag < (int)(sizeof(k_FlagTag)/sizeof(k_FlagTag[0]))); if (k_FlagTag[info->flag] && *k_FlagTag[info->flag]) s += sprintf(s, " %s", k_FlagTag[info->flag]); s += sprintf(s, " B=%.2f", info->coef); if (*c_t) s += sprintf(s, " C=%s", c_t); s += sprintf(s, " L=%s", info->locl & 0x0F ? "yes" : "no"); if (info->type != fSERV_Dns && (info->locl & 0xF0)) s += sprintf(s, " P=yes"); if (info->host && info->quorum) { if (info->quorum == (unsigned short)(-1)) s += sprintf(s, " Q=yes"); else s += sprintf(s, " Q=%hu", info->quorum); } s += sprintf(s," R=%.*f", fabs(info->rate) < 0.01 ? 3 : 2, info->rate); if (!(info->type & fSERV_Http) && info->type != fSERV_Dns) s += sprintf(s, " S=%s", info->sful ? "yes" : "no"); s += sprintf(s, " T=%lu", (unsigned long)info->time); } return str; }
/*ARGSUSED*/ static int/*bool*/ s_IsContentTypeDefined(const char* service, const SConnNetInfo* net_info, EMIME_Type mime_t, EMIME_SubType mime_s, EMIME_Encoding mime_e) { const char* s; assert(net_info); for (s = net_info->http_user_header; s; s = strchr(s, '\n')) { if (s != net_info->http_user_header) s++; if (!*s) break; if (strncasecmp(s, "content-type: ", 14) == 0) { #if defined(_DEBUG) && !defined(NDEBUG) EMIME_Type m_t; EMIME_SubType m_s; EMIME_Encoding m_e; char c_t[MAX_CONTENT_TYPE_LEN]; if (net_info->debug_printout && mime_t != eMIME_T_Undefined && mime_t != eMIME_T_Unknown && (!MIME_ParseContentTypeEx(s, &m_t, &m_s, &m_e) || mime_t != m_t || (mime_s != eMIME_Undefined && mime_s != eMIME_Unknown && m_s != eMIME_Unknown && mime_s != m_s) || (mime_e != eENCOD_None && m_e != eENCOD_None && mime_e != m_e))) { const char* c; size_t len; char* t; for (s += 15; *s; s++) { if (!isspace((unsigned char)(*s))) break; } if (!(c = strchr(s, '\n'))) c = s + strlen(s); if (c > s && c[-1] == '\r') c--; len = (size_t)(c - s); if ((t = (char*) malloc(len + 1)) != 0) { memcpy(t, s, len); t[len] = '\0'; } if (!MIME_ComposeContentTypeEx(mime_t, mime_s, mime_e, c_t, sizeof(c_t))) { *c_t = '\0'; } CORE_LOGF_X(3, eLOG_Warning, ("[%s] Content-Type mismatch: " "%s%s%s%s%s%s%s", service, t && *t ? "specified=<" : "", t && *t ? t : "", t && *t ? ">" : "", t && *t && *c_t ? ", " : "", *c_t ? "configured=<" : "", *c_t ? c_t : "", *c_t ? ">" : "")); if (t) free(t); } #endif return 1/*true*/; } } return 0/*false*/; }