UString USOAPEncoder::encodeMethod(URPCMethod& method, const UString& nsName) // namespace qualified element information { U_TRACE(0, "USOAPEncoder::encodeMethod(%p,%V)", &method, nsName.rep) method.encode(); // Encode the method by virtual method... if (method.hasFailed()) U_RETURN_STRING(encodedValue); uint32_t num_arg = arg.size(); if (num_arg > 1) encodedValue = arg.join(0, 0); else if (num_arg == 1) encodedValue = arg[0]; else encodedValue.setEmpty(); UString methodName = method.getMethodName(), headerContents = method.getHeaderContent(); if (bIsResponse) (void) methodName.append(U_CONSTANT_TO_PARAM("Response")); buffer.setBuffer(400U + (nsName.size() * 4) + (methodName.size() * 2) + encodedValue.size() + headerContents.size()); buffer.snprintf("<?xml version='1.0' ?>" "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" "<env:Header>%v</env:Header>" "<env:Body>" "<%v:%v env:encodingStyle=\"http://www.w3.org/2003/05/soap-encoding\" xmlns:%v=\"%v\">%v</%v:%v>" "</env:Body>" "</env:Envelope>", headerContents.rep, nsName.rep, methodName.rep, nsName.rep, nsName.rep, encodedValue.rep, nsName.rep, methodName.rep); U_RETURN_STRING(buffer); }
UString USOAPEncoder::encodeMethod(URPCMethod& method, const UString& nsName) // namespace qualified element information { U_TRACE(0, "USOAPEncoder::encodeMethod(%p,%.*S)", &method, U_STRING_TO_TRACE(nsName)) method.encode(); // Encode the method by virtual method... if (method.hasFailed()) U_RETURN_STRING(encodedValue); uint32_t num_arg = arg.size(); if (num_arg > 1) encodedValue = arg.join(0, 0); else if (num_arg == 1) encodedValue = arg[0]; else encodedValue.setEmpty(); UString methodName = method.getMethodName(), headerContents = method.getHeaderContent(); if (bIsResponse) (void) methodName.append(U_CONSTANT_TO_PARAM("Response")); uint32_t sz_nsName = nsName.size(), sz_methodName = methodName.size(), sz_encodedValue = encodedValue.size(), sz_headerContents = headerContents.size(); const char* ptr_nsName = nsName.data(); const char* ptr_methodName = methodName.data(); const char* ptr_encodedValue = encodedValue.data(); const char* ptr_headerContents = headerContents.data(); buffer.setBuffer(400U + (sz_nsName * 4) + (sz_methodName * 2) + sz_encodedValue + sz_headerContents); buffer.snprintf("<?xml version='1.0' ?>" "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" "<env:Header>%.*s</env:Header>" "<env:Body>" "<%.*s:%.*s env:encodingStyle=\"http://www.w3.org/2003/05/soap-encoding\" xmlns:%.*s=\"%.*s\">%.*s</%.*s:%.*s>" "</env:Body>" "</env:Envelope>", sz_headerContents, ptr_headerContents, sz_nsName, ptr_nsName, sz_methodName, ptr_methodName, sz_nsName, ptr_nsName, sz_nsName, ptr_nsName, sz_encodedValue, ptr_encodedValue, sz_nsName, ptr_nsName, sz_methodName, ptr_methodName); U_RETURN_STRING(buffer); }
UString UDES3::signData(const char* fmt, ...) { U_TRACE(0, "UDES3::signData(%S)", fmt) uint32_t sz1; UString buffer1(U_CAPACITY), buffer2(U_CAPACITY), signed_data(U_CAPACITY); va_list argp; va_start(argp, fmt); buffer1.vsnprintf(fmt, argp); va_end(argp); sz1 = buffer1.size(); if (sz1 <= 512) encode((const unsigned char*)buffer1.data(), sz1, buffer2); else { UString data = UStringExt::compress(buffer1.data(), sz1); uint32_t sz2 = data.size(); if (sz2 < (sz1 - (sz1 / 4))) encode((const unsigned char*) data.data(), sz2, buffer2); else encode((const unsigned char*)buffer1.data(), sz1, buffer2); } UBase64::encode(buffer2, signed_data); U_RETURN_STRING(signed_data); }
UString UXML2Document::getElementData(uint32_t pos, const char* tag, uint32_t tag_len) { U_TRACE(0, "UXML2Document::getElementData(%u,%.*S,%u)", pos, tag_len, tag, tag_len) UString element; uint32_t end = getElement(element, pos, tag, tag_len); if (element && end != U_NOT_FOUND) { uint32_t n = tag_len + 2; // <...> UString _data = UStringExt::trim(element.substr(n, element.size() - (n * 2) - 1)); // </..> U_RETURN_STRING(_data); } U_RETURN_STRING(element); }
UString USOAPParser::processMessage(const UString& msg, URPCObject& object, bool& bContainsFault) { U_TRACE(0, "USOAPParser::processMessage(%V,%p,%p,%b)", msg.rep, &object, &bContainsFault) U_INTERNAL_ASSERT(msg) UString retval; clearData(); if (U_STRING_FIND(msg, 0, "http://schemas.xmlsoap.org/soap/envelope/") != U_NOT_FOUND) { zero(); bContainsFault = true; (void) retval.assign(U_CONSTANT_TO_PARAM("<?xml version=\"1.0\" ?>" "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">" "<env:Header>" "<env:Upgrade>" "<env:SupportedEnvelope qname=\"ns1:Envelope\" xmlns:ns1=\"http://www.w3.org/2003/05/soap-envelope\"/>" "</env:Upgrade>" "</env:Header>" "<env:Body>" "<env:Fault>" "<faultcode>env:VersionMismatch</faultcode>" "<faultstring>Version Mismatch</faultstring>" "</env:Fault>" "</env:Body>" "</env:Envelope>")); } else if (parse(msg)) { U_ASSERT_EQUALS(envelope.methodName.equal(U_CONSTANT_TO_PARAM("Fault")), false) retval = object.processMessage(envelope, bContainsFault); } else { int line = ::XML_GetCurrentLineNumber(m_parser), coln = ::XML_GetCurrentColumnNumber(m_parser); object.setFailed(); URPCMethod::pFault->getFaultReason() = UXMLParser::getErrorMessage(); U_INTERNAL_DUMP("UXMLParser: %V (%d,%d) ", URPCMethod::pFault->getFaultReason().rep, line, coln) URPCMethod::pFault->setDetail("The fault occurred near position (line: %d col: %d) within the message", line, coln); bContainsFault = true; retval = URPCMethod::encoder->encodeFault(URPCMethod::pFault); } U_RETURN_STRING(retval); }
UString Url::getService() const { U_TRACE(0, "Url::getService()") UString srv; if (service_end > 0) srv = url.substr(0U, (uint32_t)service_end); U_RETURN_STRING(srv); }
UString getTimeStampToken(const UString& data, const UString& url) { U_TRACE(5, "Application::getTimeStampToken(%.*S,%.*S)", U_STRING_TO_TRACE(data), U_STRING_TO_TRACE(url)) UString token; # ifdef HAVE_SSL_TS token = UTimeStamp::getTimeStampToken(U_HASH_SHA1, data, url); # endif U_RETURN_STRING(token); }
UString UOptions::operator[](uint32_t i) { U_TRACE(0, "UOptions::operator[](%u)", i) U_CHECK_MEMORY U_INTERNAL_ASSERT_MINOR(i,length) UString str(item[i].value); U_RETURN_STRING(str); }
UString UMagic::getType(const char* buffer, uint32_t buffer_len) { U_TRACE(1, "UMagic::getType(%.*S,%u)", buffer_len, buffer, buffer_len) U_INTERNAL_ASSERT_POINTER(magic) UString str; const char* result = (const char*) U_SYSCALL(magic_buffer, "%p,%p,%u", magic, buffer, buffer_len); if (result) (void) str.assign(result); else (void) str.assign(U_CONSTANT_TO_PARAM("application/octet-stream")); U_RETURN_STRING(str); }
UString UOptions::operator[](char c) { U_TRACE(0, "UOptions::operator[](%C)", c) uint32_t i; for (i = 0; i < length; ++i) { if (item[i].short_opt == c) break; } UString str = operator[](i); U_RETURN_STRING(str); }
UString UOptions::operator[](const UString& long_opt) { U_TRACE(0, "UOptions::operator[](%V)", long_opt.rep) uint32_t i; for (i = 0; i < length; ++i) { if (long_opt.equal(item[i].long_opt)) break; } UString str = operator[](i); U_RETURN_STRING(str); }
UString UDES3::getSignedData(const char* ptr, uint32_t len) { U_TRACE(0, "UDES3::getSignedData(%.*S,%u)", len, ptr, len) UString buffer(U_CAPACITY), output(U_CAPACITY); if (UBase64::decode(ptr, len, buffer)) { UDES3::decode(buffer, output); if (UStringExt::isCompress(output)) output = UStringExt::decompress(output); } U_RETURN_STRING(output); }
UString URPCEncoder::encodeMethod(URPCMethod& method, const UString& nsName) // namespace qualified element information { U_TRACE(0, "URPCEncoder::encodeMethod(%p,%.*S)", &method, U_STRING_TO_TRACE(nsName)) encodedValue.setEmpty(); method.encode(); // Encode the method by virtual method... if (method.hasFailed() == false && bIsResponse == false) { UStringExt::buildTokenVector(method.getMethodName().data(), arg, encodedValue); } U_RETURN_STRING(encodedValue); }
UString USOAPParser::getFaultResponse() { U_TRACE_NO_PARAM(0, "USOAPParser::getFaultResponse()") U_INTERNAL_ASSERT_POINTER(method) URPCFault fault; UString retval(U_CAPACITY); fault.setFaultCode(); fault.getFaultReason() = (*envelope.arg)[0]; if (envelope.arg->size() > 1) fault.getDetail() = (*envelope.arg)[1]; fault.encode(retval); (void) retval.shrink(); U_RETURN_STRING(retval); }
UString UPKCS10::getSubject(X509_REQ* _request) { U_TRACE(1, "UPKCS10::getSubject(%p)", _request) U_INTERNAL_ASSERT_POINTER(_request) X509_NAME* name = X509_REQ_get_subject_name(_request); unsigned len = U_SYSCALL(i2d_X509_NAME, "%p,%p", name, 0); UString subject(len); char* ptr = subject.data(); (void) U_SYSCALL(X509_NAME_oneline, "%p,%p,%d", name, ptr, subject.capacity()); len = u__strlen(ptr, __PRETTY_FUNCTION__); subject.size_adjust(len); U_RETURN_STRING(subject); }
UString getOptionValue(const char* param, const char* tag) { U_TRACE(5, "Application::getOptionValue(%S,%S)", param, tag) UString result; if (param && *param) result = param; else { UString tmp(100U); U_INTERNAL_DUMP("xades_c = %b", xades_c) tmp.snprintf(U_CONSTANT_TO_PARAM("XAdES-%s.%s"), (xades_c ? "C" : "BES"), tag); result = cfg[tmp]; } U_RETURN_STRING(result); }
UString URPCFault::getFaultCode() { U_TRACE_NO_PARAM(0, "URPCFault::getFaultCode()") UString retval; /* SOAP: * ---------------------------------------------------------------------------------------------------- * VersionMismatch: The faulting node found an invalid element information item instead of the expected * Envelope element information item. The namespace, local name or both did not match * the Envelope element information item required by this recommendation. * * MustUnderstand: An immediate child element information item of the SOAP Header element information * item targeted at the faulting node that was not understood by the faulting node * contained a SOAP mustUnderstand attribute information item with a value of "true". * * DataEncodingUnknown: A SOAP header block or SOAP body child element information item targeted at the * faulting SOAP node is scoped with a data encoding that the faulting node does not support. * * Sender: The message was incorrectly formed or did not contain the appropriate information in order to * succeed. For example, the message could lack the proper authentication or payment information. * It is generally an indication that the message is not to be resent without change. * * Receiver: The message could not be processed for reasons attributable to the processing of the message * rather than to the contents of the message itself. For example, processing could include * communicating with an upstream SOAP node, which did not respond. The message could succeed * if resent at a later point in time * ---------------------------------------------------------------------------------------------------- */ switch (faultCode) { case Sender: (void) retval.assign(U_CONSTANT_TO_PARAM("Client")); break; case Receiver: (void) retval.assign(U_CONSTANT_TO_PARAM("Server")); break; case MustUnderstand: (void) retval.assign(U_CONSTANT_TO_PARAM("MustUnderstand")); break; case VersionMismatch: (void) retval.assign(U_CONSTANT_TO_PARAM("VersionMismatch")); break; case DataEncodingUnknown: (void) retval.assign(U_CONSTANT_TO_PARAM("DataEncodingUnknown")); break; } U_RETURN_STRING(retval); }
UString URPCObject::processMessage(URPCEnvelope& envelope, bool& bContainsFault) { U_TRACE(0, "URPCObject::processMessage(%p,%p)", &envelope, &bContainsFault) U_INTERNAL_ASSERT_POINTER(URPCMethod::encoder) UString retval; // Iterate over the list of methods URPCMethod* method = find(envelope.getMethodName()); if (method == 0) { // Return object not found error. This would be a Client fault setFailed(); URPCMethod::pFault->setFaultReason(U_CONSTANT_TO_PARAM("The requested method does not exist on this server")); bContainsFault = true; retval = URPCMethod::encoder->encodeFault(URPCMethod::pFault); } else { UString ns = envelope.getNsName(); U_INTERNAL_DUMP("envelope.nsName = %V", ns.rep) // check the name of namespace qualified element information (gSOAP) if (ns.empty()) ns = method->getNamespaces(); if (ns.empty()) ns = *UString::str_ns; bContainsFault = (method->execute(envelope) == false); retval = URPCMethod::encoder->encodeMethodResponse(*method, ns); } U_RETURN_STRING(retval); }
UString UHttpClient_Base::getBasicAuthorizationHeader() { U_TRACE_NO_PARAM(0, "UHttpClient_Base::getBasicAuthorizationHeader()") UString headerValue(300U), tmp(100U), data(100U); // --------------------------------------------------------------------------------------------------------------------------- // According to RFC 2617 HTTP Authentication: Basic and Digest Access Authentication // --------------------------------------------------------------------------------------------------------------------------- // For "Basic" authentication, the user and password are concatentated with a colon separator before being encoded in base64. // According to RFC 2068 (HTTP/1.1) the Username and Password are defined as TEXT productions and are therefore supposed to be // encoded in ISO-8859-1 before being Base64-encoded // --------------------------------------------------------------------------------------------------------------------------- tmp.snprintf(U_CONSTANT_TO_PARAM("%v:%v"), user.rep, password.rep); UBase64::encode(tmp, data); // Authorization: Basic cy5jYXNhenphOnN0ZWZhbm8x headerValue.snprintf(U_CONSTANT_TO_PARAM("Basic %v"), data.rep); U_RETURN_STRING(headerValue); }