// mapped to: void funcs::free_function1(int i); (there are overloaded methods) ulxr::MethodResponse UlxrIdlTestFuncs_funcs__free_function1_ovr0 (const ulxr::MethodCall &calldata) { try { int p0 = (int) ulxr::Integer(calldata.getParam(0)).getInteger(); funcs::free_function1(p0); return ulxr::MethodResponse (ulxr::Void()); } catch(std::exception &ex) { ulxr::CppString s = ULXR_PCHAR("C++ exception caught when invoking 'void funcs::free_function1(int i);'\n "); s += ULXR_GET_STRING(ex.what()); return ulxr::MethodResponse(ulxr::ApplicationError, s); } catch(...) { ulxr::CppString s = ULXR_PCHAR("Unknown exception caught when invoking 'void funcs::free_function1(int i);'"); return ulxr::MethodResponse(ulxr::ApplicationError, s); } }
TcpIpConnection::getHostAdress(const CppString &dom) { unsigned start = 0; if (dom.substr(start, 5) == ULXR_PCHAR("http:")) start += 5; if (dom.substr(start, 2) == ULXR_PCHAR("//")) start += 2; std::size_t slash = dom.find (ULXR_PCHAR("/"), start); if (slash != CppString::npos) pimpl->serverdomain = dom.substr(start, slash-1); else pimpl->serverdomain = dom; #ifndef ULXR_OMIT_REENTRANT_PROTECTOR Mutex::Locker lock(gethostbynameMutex); #endif return gethostbyname(getLatin1(pimpl->serverdomain).c_str() ); }
// mapped to: std::string * inline_func::free_function2(long int * i, float f); (there are overloaded methods) ulxr::MethodResponse UlxrIdlTestFuncs_inline_func__free_function2 (const ulxr::MethodCall &calldata) { try { long int p0 = (long int) ulxr::Integer(calldata.getParam(0)).getInteger(); float p1 = (float) ulxr::Double(calldata.getParam(1)).getDouble(); std::string retval = *inline_func::free_function2(&p0, p1); return ulxr::MethodResponse (ulxr::RpcString (ULXR_GET_STRING(retval))); } catch(std::exception &ex) { ulxr::CppString s = ULXR_PCHAR("C++ exception caught when invoking 'std::string * inline_func::free_function2(long int * i, float f);'\n "); s += ULXR_GET_STRING(ex.what()); return ulxr::MethodResponse(ulxr::ApplicationError, s); } catch(...) { ulxr::CppString s = ULXR_PCHAR("Unknown exception caught when invoking 'std::string * inline_func::free_function2(long int * i, float f);'"); return ulxr::MethodResponse(ulxr::ApplicationError, s); } }
ULXR_API_IMPL0 TcpIpConnection::TcpIpConnection(bool I_am_server, long adr, unsigned prt) : Connection() , pimpl(new PImpl) { ULXR_TRACE(ULXR_PCHAR("TcpIpConnection(bool, long, uint)") << adr << ULXR_PCHAR(" ") << pimpl->port); init(prt); pimpl->hostdata.sin_addr.s_addr = htonl(adr); if (I_am_server) { pimpl->server_data = new ServerSocketData(socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)); if (getServerHandle() < 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not create socket: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); #ifdef ULXR_REUSE_SOCKET int sockOpt = 1; if (::setsockopt(getServerHandle(), SOL_SOCKET, SO_REUSEADDR, (const char*)&sockOpt, sizeof(sockOpt)) < 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not set reuse flag for socket: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); #endif int iOptVal = getTimeout() * 1000; int iOptLen = sizeof(int); ::setsockopt(getServerHandle(), SOL_SOCKET, SO_RCVTIMEO, (char*)&iOptVal, iOptLen); ::setsockopt(getServerHandle(), SOL_SOCKET, SO_SNDTIMEO, (char*)&iOptVal, iOptLen); if((::bind(getServerHandle(), (sockaddr*) &pimpl->hostdata, sizeof(pimpl->hostdata))) < 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not bind adress: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); ::listen(getServerHandle(), 5); } }
ULXR_API_IMPL0 TcpIpConnection::~TcpIpConnection() { ULXR_TRACE(ULXR_PCHAR("~TcpIpConnection")); try { decrementServerRef(); } catch(...) { // forget exception? } delete pimpl; pimpl = 0; }
ULXR_API_IMPL(void) FileResource::clear() { ULXR_TRACE(ULXR_PCHAR("FileResource::clear ") << filename); CachedResource::clear(); opened = false; #ifdef __unix__ if (0 == ulxr_access(getLatin1(getFilename()).c_str(), F_OK)) #else if (0 == ulxr_access(getLatin1(getFilename()).c_str(), 0)) #endif if (0 != ulxr_remove(getLatin1(getFilename()).c_str())) error = true; }
void TcpIpConnection::decrementServerRef(bool in_shutdown) { ULXR_TRACE(ULXR_PCHAR("decrementServerRef")); if (pimpl->server_data != 0 && pimpl->server_data->decRef() <= 0) { ULXR_TRACE(ULXR_PCHAR("delete serverdata ") << std::hex << (void*)pimpl->server_data << std::dec); if(in_shutdown) { ULXR_TRACE(ULXR_PCHAR("shutdown server_data")); if (pimpl->server_data->isOpen()) #ifdef __WIN32__ pimpl->server_data->shutdown(SD_BOTH); #else pimpl->server_data->shutdown(SHUT_RD); #endif } delete pimpl->server_data; pimpl->server_data = 0; } }
ULXR_API_IMPL(void) TcpIpConnection::asciiToInAddr(const char *address, struct in_addr &saddr) { memset (&saddr, 0, sizeof(in_addr)); struct hostent *host; /* First try it as aaa.bbb.ccc.ddd. */ saddr.s_addr = inet_addr(address); if ((int)saddr.s_addr == -1) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not perform inet_addr(): ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); #ifndef ULXR_OMIT_REENTRANT_PROTECTOR Mutex::Locker lock(gethostbynameMutex); #endif host = gethostbyname(address); if (host == 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not perform gethostbyname(): ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); memmove((void*)&saddr, host->h_addr_list, sizeof(in_addr)); }
void Requester::send_call (const MethodCall &calldata, const CppString &rpc_root) { ULXR_TRACE(ULXR_PCHAR("send_call ") << calldata.getMethodName()); if (!protocol->isOpen() ) protocol->open(); else protocol->resetConnection(); #ifdef ULXR_ENFORCE_NON_PERSISTENT protocol->setPersistent(false); #endif protocol->sendRpcCall(calldata, rpc_root, wbxml_mode); }
ULXR_API_IMPL(void) HttpClient::msgPUT(const Cpp8BitString &msg, const CppString &type, const CppString &resource) { ULXR_TRACE(ULXR_PCHAR("msgPUT")); if (!protocol->isOpen() ) protocol->open(); sendAuthentication(); protocol->sendRequestHeader(ULXR_PCHAR("PUT"), resource, type, msg.length()); #ifdef ULXR_USE_WXSTRING protocol->writeBody(msg.data(), msg.length()); #else protocol->writeBody(msg.data(), msg.length()); #endif BodyProcessor bp; receiveResponse(bp); if (getHttpStatus() != 200) throw ConnectionException(TransportError, getHttpPhrase(), getHttpStatus()); if (!protocol->isPersistent() ) protocol->close(); }
ULXR_API_IMPL(void) HttpClient::fileGET(const CppString &filename, const CppString &resource) { ULXR_TRACE(ULXR_PCHAR("fileGET")); if (!protocol->isOpen() ) protocol->open(); std::ofstream ofs (getLatin1(filename).c_str(), std::ios::out | std::ios::binary); if (!ofs.good() ) throw Exception(SystemError, ulxr_i18n(ULXR_PCHAR("Cannot create file: "))+filename); sendAuthentication(); protocol->sendRequestHeader(ULXR_PCHAR("GET"), resource, ULXR_PCHAR(""), 0); FileProcessor fp(ofs, filename); receiveResponse(fp); if (getHttpStatus() != 200) throw ConnectionException(TransportError, getHttpPhrase(), getHttpStatus()); if (!protocol->isPersistent() ) protocol->close(); }
void testPattern(const char *pattern, unsigned len) { ULXR_COUT << ULXR_PCHAR("====================================================\n"); unsigned cnt = 0; for (unsigned i = 0; i < len; ++i) { ULXR_COUT << ulxr::HtmlFormHandler::makeHexNumber(pattern[i]) << ULXR_PCHAR(" "); if (++cnt > 16) { ULXR_COUT << std::endl; cnt = 0; } } ULXR_COUT << std::endl << ULXR_PCHAR("-----------------------------------------------------\n"); ulxr::ValueParserWb parser; bool done = false; ULXR_COUT << ULXR_PCHAR("Parser start\n"); if (!parser.parse(pattern, len, done)) { ULXR_COUT << ULXR_PCHAR("Parser error\n"); std::cerr << ulxr::getLatin1(parser.getErrorString(parser.getErrorCode())).c_str() << " at line " << parser.getCurrentLineNumber() << std::endl; } ULXR_COUT << ULXR_PCHAR("Parser finish\n"); ulxr::Value val = parser.getValue(); ULXR_COUT << val.getSignature(true) << std::endl; ULXR_COUT << val.getXml(0) << std::endl; if (val.isString() ) { ulxr::RpcString str= val; ULXR_COUT << ULXR_PCHAR("EinRpcString: ") << str.getString() << std::endl; return; } ULXR_COUT << ULXR_PCHAR("----------------------------------------------------\n"); ULXR_COUT << ulxr::binaryDebugOutput(val.getWbXml()); ULXR_COUT << ULXR_PCHAR("====================================================\n"); }
void testRespPattern(const char *pattern, unsigned len) { ULXR_COUT << ULXR_PCHAR("====================================================\n"); unsigned cnt = 0; for (unsigned i = 0; i < len; ++i) { ULXR_COUT << ulxr::HtmlFormHandler::makeHexNumber(pattern[i]) << ULXR_PCHAR(" "); if (++cnt > 16) { ULXR_COUT << std::endl; cnt = 0; } } ULXR_COUT << std::endl << ULXR_PCHAR("-----------------------------------------------------\n"); ulxr::MethodResponseParserWb parser; bool done= false; if (!parser.parse(pattern, len, done)) { ULXR_COUT << ULXR_PCHAR("Parser error\n"); std::cerr << ulxr::getLatin1(parser.getErrorString(parser.getErrorCode())).c_str() << " at line " << parser.getCurrentLineNumber() << std::endl; } ulxr::Value val= parser.getValue(); ULXR_COUT << ULXR_PCHAR("!Value...\n"); ULXR_COUT << val.getSignature(true) << std::endl; ULXR_COUT << ULXR_PCHAR("----------------------------------------------------\n"); ULXR_COUT << val.getXml(0) << std::endl; ULXR_COUT << ULXR_PCHAR("Response...\n"); ULXR_COUT << parser.getMethodResponse().getSignature(true) << std::endl; ULXR_COUT << parser.getMethodResponse().getXml(0) << std::endl; ULXR_COUT << ULXR_PCHAR("----------------------------------------------------\n"); ULXR_COUT << ulxr::binaryDebugOutput(parser.getMethodResponse().getWbXml()); ULXR_COUT << ULXR_PCHAR("====================================================\n"); }
ULXR_API_IMPL(void) TcpIpConnection::open() { ULXR_TRACE(ULXR_PCHAR("open")); if (isOpen() ) throw RuntimeException(ApplicationError, ulxr_i18n(ULXR_PCHAR("Attempt to open an already open connection"))); if (pimpl->server_data != 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Connection is NOT prepared for client mode")), 500); // resetConnection(); setHandle(socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)); if (getHandle() < 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not create socket: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); int iOptVal = getTimeout() * 1000; int iOptLen = sizeof(int); ::setsockopt(getHandle(), SOL_SOCKET, SO_RCVTIMEO, (char*)&iOptVal, iOptLen); ::setsockopt(getHandle(), SOL_SOCKET, SO_SNDTIMEO, (char*)&iOptVal, iOptLen); doTcpNoDelay(); if(connect(getHandle(), (struct sockaddr *)&pimpl->hostdata, sizeof(pimpl->hostdata)) < 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not connect: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); ULXR_TRACE(ULXR_PCHAR("/open.peername")); #ifdef ULXR_ENABLE_GET_PEERNAME pimpl->remotedata_len = sizeof(pimpl->remotedata); if(getpeername(getHandle(), (struct sockaddr *)&pimpl->remotedata, &pimpl->remotedata_len)<0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not get peer data: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); #ifdef __BORLANDC__ pimpl->remote_name = ULXR_PCHAR("<remote-host>"); // FIXME, not working host = 0; host; #else else {
static ulxr::MethodResponse ServerChat(ulxr::MethodCall methodcall) { ulxr::MethodResponse response; std::string strServerUrl = "api.opensubtitles.org"; std::string method = methodcall.getMethodName(); try { std::unique_ptr<ulxr::TcpIpConnection> connection(new ulxr::TcpIpConnection(false, ULXR_PCHAR(strServerUrl), 80)); ulxr::HttpProtocol protocol(connection.get()); ulxr::Requester client(&protocol); response = client.call(methodcall, ULXR_PCHAR("/xml-rpc")); CLog::Log(LOGDEBUG, "%s - finished - %s", __PRETTY_FUNCTION__, method.c_str()); } catch(...) { std::string method = methodcall.getMethodName(); CLog::Log(LOGDEBUG, "%s - crashed with %s", __PRETTY_FUNCTION__, method.c_str()); } return response; }
bool COpenSubtitlesSearch::Download(const CFileItem *subItem,std::vector<std::string> &items) { ulxr::MethodCall methodcall(ULXR_PCHAR("DownloadSubtitles")); ulxr::Array subtitleIDlist; ulxr::RpcString ID = subItem->GetProperty("IDSubtitleFile").asString(); subtitleIDlist.addItem(ID); ulxr::RpcString token = m_strToken; methodcall.addParam(token); methodcall.addParam(subtitleIDlist); ulxr::MethodResponse response = ServerChat(methodcall); ulxr::Struct cap = response.getResult(); if (response.isOK() && cap.hasMember(ULXR_PCHAR("status"))) { ulxr::RpcString status = cap.getMember(ULXR_PCHAR("status")); CLog::Log(LOGDEBUG, "%s - response - %s", __PRETTY_FUNCTION__, status.getString().c_str()); if (status.getString() == "200 OK") { if (cap.hasMember(ULXR_PCHAR("data"))) { ulxr::Array subs = cap.getMember(ULXR_PCHAR("data")); for (unsigned i = 0; i < subs.size(); ++i) { ulxr::Struct entry = subs.getItem(i); ulxr::RpcString data = entry.getMember(ULXR_PCHAR("data")); std::string zipdata = data.getString(); std::string zipdata64Decoded = Base64::Decode(zipdata); std::string zipdata64DecodedInflated; CSubtitleUtilities::gzipInflate(zipdata64Decoded,zipdata64DecodedInflated); XFILE::CFile file; std::string destination = StringUtils::Format("special://temp/%s.%s", StringUtils::CreateUUID().c_str(), subItem->GetProperty("SubFormat").asString().c_str() ); file.OpenForWrite(destination); file.Write(zipdata64DecodedInflated.c_str(), zipdata64DecodedInflated.size()); items.push_back(destination); } CLog::Log(LOGDEBUG, "%s - OpenSubitles subfile downloaded", __PRETTY_FUNCTION__); return true; } } } return false; }
ULXR_API_IMPL0 TcpIpConnection::TcpIpConnection(bool I_am_server, const CppString &dom, unsigned prt) : Connection() , pimpl(new PImpl) { ULXR_TRACE(ULXR_PCHAR("TcpIpConnection(bool, string, uint)") << dom << ULXR_PCHAR(" ") << pimpl->port); init(prt); pimpl->remote_name = dom; struct hostent *hp = getHostAdress(dom); if (hp == 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Host adress not found: ")) + pimpl->serverdomain, 500); memcpy(&(pimpl->hostdata.sin_addr), hp->h_addr_list[0], hp->h_length); if (I_am_server) { pimpl->server_data = new ServerSocketData(socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)); if (getServerHandle() < 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not create socket: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); #ifdef ULXR_REUSE_SOCKET int sockOpt = 1; if (::setsockopt(getServerHandle(), SOL_SOCKET, SO_REUSEADDR, (const char*)&sockOpt, sizeof(sockOpt)) < 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not set reuse flag for socket: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); #endif int iOptVal = getTimeout() * 1000; int iOptLen = sizeof(int); ::setsockopt(getServerHandle(), SOL_SOCKET, SO_RCVTIMEO, (char*)&iOptVal, iOptLen); ::setsockopt(getServerHandle(), SOL_SOCKET, SO_SNDTIMEO, (char*)&iOptVal, iOptLen); if((::bind(getServerHandle(), (sockaddr*) &pimpl->hostdata, sizeof(pimpl->hostdata))) < 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not bind adress: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); listen(getServerHandle(), 5); } }
void testCallPattern(const char *pattern, unsigned len) { ULXR_COUT << ULXR_PCHAR("====================================================\n"); unsigned cnt = 0; for (unsigned i2 = 0; i2 < len; ++i2) { ULXR_COUT << ulxr::HtmlFormHandler::makeHexNumber(pattern[i2]) << ULXR_PCHAR(" "); if (++cnt > 16) { ULXR_COUT << std::endl; cnt = 0; } } ULXR_COUT << std::endl << ULXR_PCHAR("-----------------------------------------------------\n"); ulxr::MethodCallParserWb parser; bool done= false; if (!parser.parse(pattern, len, done)) { ULXR_COUT << ULXR_PCHAR("Parser error\n"); std::cerr << ulxr::getLatin1(parser.getErrorString(parser.getErrorCode())).c_str() << " at line " << parser.getCurrentLineNumber() << std::endl; } ULXR_COUT << parser.getMethodCall().getSignature(true) << std::endl; ULXR_COUT << ULXR_PCHAR("----------------------------------------------------\n"); ULXR_COUT << parser.getMethodCall().getXml(0) << std::endl; ULXR_COUT << parser.getMethodName() << std::endl; ULXR_COUT << parser.numParams() << std::endl; for (unsigned i1 = 0; i1 < parser.numParams(); ++i1) ULXR_COUT << parser.getParam(i1).getSignature(true) << std::endl; ULXR_COUT << ULXR_PCHAR("----------------------------------------------------\n"); ULXR_COUT << ulxr::binaryDebugOutput(parser.getMethodCall().getWbXml()); ULXR_COUT << ULXR_PCHAR("====================================================\n"); }
ULXR_API_IMPL0 ValueParser::~ValueParser() { ULXR_TRACE(ULXR_PCHAR("ValueParser::~ValueParser()")); #ifdef DEBUG if (states.size() != 1) std::cerr << ulxr_i18n("########## abnormal program behaviour: states.size() != 1: ") << states.size() << std::endl; if (getTopValueState()->getParserState() != eNone) std::cerr << ulxr_i18n("########## abnormal program behaviour: getTopState()->getState() != eNone: ") << getTopValueState()->getParserState() << std::endl; #endif while (states.size() != 0) { if (getTopValueState()->canDelete()) delete getTopValueState()->getValue(); delete getTopValueState(); states.pop(); } }
ULXR_API_IMPL(Connection *) TcpIpConnection::detach() { ULXR_TRACE(ULXR_PCHAR("detach")); TcpIpConnection *clone = makeClone();; clone->pimpl->server_data = 0; clone->setServerData(getServerData()); if (getServerData() != 0) getServerData()->incRef(); ULXR_TRACE(ULXR_PCHAR("detach getHandle() ") << getHandle()); ULXR_TRACE(ULXR_PCHAR("detach clone->getHandle() ") << clone->getHandle()); cut(); ULXR_TRACE(ULXR_PCHAR("detach getHandle() ") << getHandle()); ULXR_TRACE(ULXR_PCHAR("detach clone->getHandle() ") << clone->getHandle()); ULXR_TRACE(ULXR_PCHAR("/detach")); return clone; }
ULXR_API_IMPL(CppString) MethodCall::getXml(int indent) const { CppString ind = getXmlIndent(indent); CppString ind1 = getXmlIndent(indent+1); CppString ind2 = getXmlIndent(indent+2); CppString s = ULXR_PCHAR("<?xml version=\"1.0\" encoding=\"GB2312\" standalone=\"yes\"?>") + getXmlLinefeed(); s += ind + ULXR_PCHAR("<request command =\"") + methodname + ULXR_PCHAR("\">") +getXmlLinefeed(); s += ind1 + ULXR_PCHAR("<parameters>") + getXmlLinefeed(); for (std::vector<Value>::const_iterator it = params.begin(); it != params.end(); ++it) { //s += ind2 + ULXR_PCHAR("<param>") + getXmlLinefeed(); s += (*it).getXml(indent+3) + getXmlLinefeed(); //s += ind2 + ULXR_PCHAR("</param>") + getXmlLinefeed(); } s += ind1 + ULXR_PCHAR("</parameters>") + getXmlLinefeed(); s += ind + ULXR_PCHAR("</request>"); return s; }
Requester::call (const MethodCall& calldata, const CppString &rpc_root) { ULXR_TRACE(ULXR_PCHAR("call")); send_call (calldata, rpc_root); return waitForResponse(); }
Requester::waitForResponse(Protocol *protocol, bool wbxml_mode) { ULXR_TRACE(ULXR_PCHAR("waitForResponse(Protocol, wbxml)")); char buffer[ULXR_RECV_BUFFER_SIZE]; char *buff_ptr; std::auto_ptr<XmlParserBase> parser; MethodResponseParserBase *rpb = 0; if (wbxml_mode) { ULXR_TRACE(ULXR_PCHAR("waitForResponse in WBXML")); MethodResponseParserWb *rp = new MethodResponseParserWb(); rpb = rp; #ifdef _MSC_VER std::auto_ptr<XmlParserBase> temp(rp); parser = temp; #else parser.reset(rp); #endif } else { ULXR_TRACE(ULXR_PCHAR("waitForResponse in XML")); MethodResponseParser *rp = new MethodResponseParser(); rpb = rp; #ifdef _MSC_VER std::auto_ptr<XmlParserBase> temp(rp); parser = temp; #else parser.reset(rp); #endif } bool done = false; long readed; while (!done && protocol->hasBytesToRead() && ((readed = protocol->readRaw(buffer, sizeof(buffer))) > 0) ) { buff_ptr = buffer; while (readed > 0) { Protocol::State state = protocol->connectionMachine(buff_ptr, readed); if (state == Protocol::ConnError) { done = true; throw ConnectionException(TransportError, ulxr_i18n(ULXR_PCHAR("network problem occured")), 400); } else if (state == Protocol::ConnSwitchToBody) { #ifdef ULXR_SHOW_READ Cpp8BitString super_data (buff_ptr, readed); while ((readed = protocol->readRaw(buffer, sizeof(buffer))) > 0) super_data.append(buffer, readed); ULXR_DOUT_READ(ULXR_PCHAR("superdata 3 start:\n")); if (wbxml_mode) { ULXR_DOUT_READ(binaryDebugOutput(super_data)); } else { ULXR_DOUT_READ(ULXR_GET_STRING(super_data)); } ULXR_DOUT_READ(ULXR_PCHAR("superdata 3 end:\n") ); #endif if (!protocol->hasBytesToRead()) { throw ConnectionException(NotConformingError, ulxr_i18n(ULXR_PCHAR("Content-Length of message not available")), 411); } CppString s; if (!protocol->responseStatus(s)) throw ConnectionException(TransportError, s, 500); } else if (state == Protocol::ConnBody) { ULXR_DOUT_XML(ULXR_GET_STRING(std::string(buff_ptr, readed))); if (!parser->parse(buff_ptr, readed, false)) { throw XmlException(parser->mapToFaultCode(parser->getErrorCode()), ulxr_i18n(ULXR_PCHAR("Problem while parsing xml response")), parser->getCurrentLineNumber(), ULXR_GET_STRING(parser->getErrorString(parser->getErrorCode()))); } readed = 0; } } if (!protocol->hasBytesToRead()) // || parser->isComplete()) done = true; } if (protocol->isOpen() && !protocol->isPersistent() ) protocol->close(); return rpb->getMethodResponse(); }
ULXR_API_IMPL0 HttpClient::HttpClient (HttpProtocol* prot) { ULXR_TRACE(ULXR_PCHAR("HttpClient(HttpProtocol*)")); protocol = prot; protocol->setChunkedTransfer(false); }
ULXR_API_IMPL(void) HttpClient::sendAuthentication() { ULXR_TRACE(ULXR_PCHAR("sendAuthentication")); if (http_user.length() != 0 && http_pass.length() != 0) protocol->setMessageAuthentication(http_user, http_pass); }
virtual void process(const char *buffer, unsigned len) { target.write(buffer, len); if (!target.good() ) throw Exception(SystemError, ulxr_i18n(ULXR_PCHAR("Cannot write to file: "))+name); }
int main(int argc, char ** argv) { ulxr::intializeLog4J(argv[0]); ulxr::TcpIpConnection conn (false, ULXR_PCHAR("localhost"), 32001); ulxr::HttpProtocol http (&conn, ULXR_PCHAR("123"), 123); const char *http_msg = "HTTP/1.1 100 Continue\r\n" "Connection: Close\r\n" "Content-Type: xyz/abc\r\n" "\r\n" "HTTP/1.1 200 OK\r\n" "Connection: Close\r\n" "Content-Length: 42\r\n" "Content-Type: text/xml; encoding=UTF-8;\r\n" "\r\n" "12345678901234567890\r\n" "abcasdf8901234567890\r\n"; const char *http_msg2 = "HTTP/1.1 200 OK\r\n" "Connection : Close\r\n" "Host : me.at.home\r\n" "Content-Length : 44\r\n" "Content-Type : text/xml;\r\n" " encoding=UTF-8;\r\n" "\r\n" "kasdklfjasldkjfaksjf\r\n" "abcasdf8901234567890\r\n" "-->ready"; const char *http_msg3 = "HTTP/1.1 200 OK\r\n" "Connection : Close\r\n" "Host : me.at.home\r\n" "Transfer-Encoding : chunked\r\n" "Content-Length : 16\r\n" "Content-Type : text/xml;\r\n" " encoding=UTF-8;\r\n" "\r\n" "5\r\n" "kas\r\n\r\n" "8\r\n" "abc123\r\n\r\n" "3 ; more info\r\n" "k\r\n\r\n" "0\r\n" "footer1: text1\r\n" "footer2: text2\r\n" "\r\n"; const char *http_msg4 = "HTTP/1.1 200 OK\r\n" "Connection : Close\r\n" "Host : me.at.home\r\n" "Transfer-Encoding : chunked\r\n" "Content-Type : text/xml;\r\n" " encoding=UTF-8;\r\n" "\r\n" "5\r\n" "kas\r\n\r\n" "8\r\n" "abc123\r\n\r\n" "3 ; more info\r\n" "k\r\n\r\n" "0\r\n" "footer1: text1\r\n" "footer2: text2\r\n" "\r\n"; int success = 0; try { { char *buff = (char*)http_msg; long buff_len = strlen(buff); http.resetConnection(); http.connectionMachine(buff, buff_len); ULXR_COUT << ULXR_PCHAR("len: ") << buff_len << std::endl; ULXR_COUT << ULXR_PCHAR("body:\n") << buff << std::endl; if (http.getHttpProperty(ULXR_PCHAR("Content-Type")) != ULXR_PCHAR("text/xml; encoding=UTF-8;")) NoSuccess; ulxr::CppString head_version; unsigned head_status = 500; ulxr::CppString head_phrase; http.splitHeaderLine(head_version, head_status, head_phrase); ULXR_COUT << ULXR_PCHAR("content-type: ") << http.getHttpProperty(ULXR_PCHAR("Content-Type")) << std::endl; ULXR_COUT << ULXR_PCHAR("head_phrase: ") << head_phrase << std::endl; ULXR_COUT << ULXR_PCHAR("head_status: ") << head_status << std::endl; if (head_status != 200) NoSuccess; if (head_phrase != ULXR_PCHAR("OK")) NoSuccess; if (buff_len != 44) NoSuccess; } { char *buff = (char*)http_msg2; long buff_len = strlen(buff); http.resetConnection(); http.connectionMachine(buff, buff_len); ULXR_COUT << ULXR_PCHAR("len2: ") << buff_len << std::endl; ULXR_COUT << ULXR_PCHAR("body2:\n") << buff << std::endl; } { char *buff_start = strdup(http_msg3); const int buff_len = strlen(buff_start); http.resetConnection(); if (!http.hasBytesToRead()) NoSuccess; long ptr = 0; std::string body; while (ptr < buff_len) { const int bl = 1; long len = bl; char *buff = buff_start + ptr; ulxr::HttpProtocol::State st = http.connectionMachine(buff, len); if (ulxr::HttpProtocol::ConnBody == st) body.append(buff, len); else if (ulxr::HttpProtocol::ConnSwitchToBody == st) { if (!http.hasBytesToRead()) NoSuccess; } ptr += bl; } free(buff_start); std::string b = "kas\r\n" "abc123\r\n" "k\r\n"; if (b != body) NoSuccess; if (http.hasBytesToRead()) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer1")) != ULXR_PCHAR("text1")) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer2")) != ULXR_PCHAR("text2")) NoSuccess; } { char *buff_start = strdup(http_msg3); const int buff_len = strlen(buff_start); // a multiple of 2 if (buff_len % 2 != 0) NoSuccess; http.resetConnection(); long ptr = 0; std::string body; while (ptr < buff_len) { const int bl = 2; long len = bl; char *buff = buff_start + ptr; if (ulxr::HttpProtocol::ConnBody == http.connectionMachine(buff, len)) body.append(buff, len); ptr += bl; } free(buff_start); std::string b = "kas\r\n" "abc123\r\n" "k\r\n"; if (b != body) NoSuccess; if (http.hasBytesToRead()) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer2")) != ULXR_PCHAR("text2")) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer1")) != ULXR_PCHAR("text1")) NoSuccess; } { char *buff_start = strdup(http_msg3); const int buff_len = strlen(buff_start); if (buff_len % 3 != 0) NoSuccess; http.resetConnection(); long ptr = 0; std::string body; while (ptr < buff_len) { const int bl = 3; long len = bl; char *buff = buff_start + ptr; if (ulxr::HttpProtocol::ConnBody == http.connectionMachine(buff, len)) body.append(buff, len); ptr += bl; } free(buff_start); std::string b = "kas\r\n" "abc123\r\n" "k\r\n"; if (b != body) NoSuccess; if (http.hasBytesToRead()) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer1")) != ULXR_PCHAR("text1")) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer2")) != ULXR_PCHAR("text2")) NoSuccess; } { char *buff_start = strdup(http_msg3); const int buff_len = strlen(buff_start); if (buff_len % 4 != 0) NoSuccess; http.resetConnection(); long ptr = 0; std::string body; while (ptr < buff_len) { const int bl = 4; long len = bl; char *buff = buff_start + ptr; if (ulxr::HttpProtocol::ConnBody == http.connectionMachine(buff, len)) body.append(buff, len); ptr += bl; } free(buff_start); std::string b = "kas\r\n" "abc123\r\n" "k\r\n"; if (b != body) NoSuccess; if (http.hasBytesToRead()) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer1")) != ULXR_PCHAR("text1")) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer2")) != ULXR_PCHAR("text2")) NoSuccess; } { char *buff_start = strdup(http_msg4); const int buff_len = strlen(buff_start); // a multiple of 3 if (buff_len % 3 != 0) NoSuccess; http.resetConnection(); long ptr = 0; std::string body; while (ptr < buff_len) { const int bl = 3; long len = bl; char *buff = buff_start + ptr; if (ulxr::HttpProtocol::ConnBody == http.connectionMachine(buff, len)) body.append(buff, len); ptr += bl; } free(buff_start); std::string b = "kas\r\n" "abc123\r\n" "k\r\n"; if (b != body) NoSuccess; if (http.hasBytesToRead()) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer1")) != ULXR_PCHAR("text1")) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer2")) != ULXR_PCHAR("text2")) NoSuccess; } { char *buff_start = strdup(http_msg4); const int buff_len = strlen(buff_start); http.resetConnection(); std::string body; long len = buff_len; char *buff = buff_start; if (ulxr::HttpProtocol::ConnBody == http.connectionMachine(buff, len)) body.append(buff, len); free(buff_start); std::string b = "kas\r\n" "abc123\r\n" "k\r\n"; if (b != body) NoSuccess; if (http.hasBytesToRead()) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer1")) != ULXR_PCHAR("text1")) NoSuccess; if (http.getHttpProperty(ULXR_PCHAR("footer2")) != ULXR_PCHAR("text2")) NoSuccess; } } catch(...) { NoSuccess; } if (success == 0) ULXR_COUT << ULXR_PCHAR("\nsuccess\n"); else ULXR_COUT << ULXR_PCHAR("\nfailed\n"); return success; }
ULXR_API_IMPL(void) TcpIpConnection::init(unsigned prt) { ULXR_TRACE(ULXR_PCHAR("init")); #if defined(__WIN32__) && !defined (ULXR_NO_WSA_STARTUP) WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD( 2, 0 ); if (WSAStartup( wVersionRequested, &wsaData) != 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not initialize Windows sockets: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); #endif pimpl->server_data = 0; setTcpNoDelay(false); pimpl->serverdomain = ULXR_PCHAR(""); pimpl->remote_name = ULXR_PCHAR(""); setTimeout(10); pimpl->port = prt; pimpl->hostdata_len = sizeof(pimpl->hostdata); pimpl->remotedata_len = sizeof(pimpl->remotedata); memset(&pimpl->hostdata, 0, sizeof(pimpl->hostdata)); memset(&pimpl->remotedata, 0, sizeof(pimpl->remotedata)); pimpl->hostdata.sin_port = htons(pimpl->port); pimpl->hostdata.sin_family = AF_INET; char buffer [1000]; memset(buffer, 0, sizeof(buffer)); int ret = gethostname(buffer, sizeof(buffer)-1); if (ret != 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not get host name: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); pimpl->host_name = ULXR_GET_STRING(buffer); #if defined(__SUN__) long status = sysinfo(SI_SRPC_DOMAIN ,buffer, sizeof(buffer)-1); if (status == -1) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not get domain name: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); if (buffer[0] != 0) { pimpl->host_name += ULXR_PCHAR("."); pimpl->host_name += ULXR_GET_STRING(buffer); } #elif defined(__unix__) || defined(__CYGWIN__) ret = getdomainname(buffer, sizeof(buffer)-1); if (ret != 0) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not get domain name: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); if (buffer[0] != 0) { pimpl->host_name += ULXR_PCHAR("."); pimpl->host_name += ULXR_GET_STRING(buffer); } #elif _WIN32 #ifndef ULXR_OMIT_REENTRANT_PROTECTOR Mutex::Locker lock(gethostbynameMutex); #endif struct hostent *hostEntPtr = gethostbyname(getLatin1(pimpl->host_name).c_str()); if (!hostEntPtr) throw ConnectionException(SystemError, ulxr_i18n(ULXR_PCHAR("Could not get host+domain name: ")) + ULXR_GET_STRING(getErrorString(getLastError())), 500); pimpl->host_name = ULXR_GET_STRING(hostEntPtr->h_name); #else # pragma message ("don't know how to determine the domain name") #endif }
ULXR_API_IMPL(MethodResponse) Requester::waitForResponse() { ULXR_TRACE(ULXR_PCHAR("waitForResponse")); return waitForResponse(protocol, wbxml_mode); }
void UlxrIdlTestServer::setupServerMethods() { // mapped to: void first_url4(); (there are overloaded methods) method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::first_url4_ovr4), ulxr::Void::getValueName(), ULXR_CALLTO_UlxrIdlTest_first_url4_ovr4, ulxr::Signature(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'void UlxrIdlTest::first_url4()'."))); // TODO adjust comment // mapped to: std::string * first_url4(int i); (there are overloaded methods) method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::first_url4_ovr3), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_first_url4_ovr3, ulxr::Signature() << ulxr::Integer::getValueName(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'std::string * UlxrIdlTest::first_url4(int i)'."))); // TODO adjust comment // mapped to: std::string * first_url4(long int li); (there are overloaded methods) method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::first_url4_ovr2), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_first_url4_ovr2, ulxr::Signature() << ulxr::Integer::getValueName(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'std::string * UlxrIdlTest::first_url4(long int li)'."))); // TODO adjust comment // mapped to: const char * first_url4(float li); (there are overloaded methods) method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::first_url4_ovr1), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_first_url4_ovr1, ulxr::Signature() << ulxr::Double::getValueName(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'const char * UlxrIdlTest::first_url4(float li)'."))); // TODO adjust comment // mapped to: wchar_t * const first_url4(double li); (there are overloaded methods) method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::first_url4_ovr0), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_first_url4_ovr0, ulxr::Signature() << ulxr::Double::getValueName(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'wchar_t * const UlxrIdlTest::first_url4(double li)'."))); // TODO adjust comment // mapped to: std::string constTest() const; method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::constTest), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_constTest, ulxr::Signature(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'std::string UlxrIdlTest::constTest() const'."))); // TODO adjust comment // mapped to: std::string & constRefTest() const; method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::constRefTest), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_constRefTest, ulxr::Signature(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'std::string & UlxrIdlTest::constRefTest() const'."))); // TODO adjust comment // mapped to: long int * firstViewConst() const; method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::firstViewConst), ulxr::Integer::getValueName(), ULXR_CALLTO_UlxrIdlTest_firstViewConst, ulxr::Signature(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'long int * UlxrIdlTest::firstViewConst() const'."))); // TODO adjust comment // mapped to: std::string * firstView(); method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::firstView), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_firstView, ulxr::Signature(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'std::string * UlxrIdlTest::firstView()'."))); // TODO adjust comment // mapped to: std::wstring * nextView1(int i, long int * l, std::string & s, const bool * b, char c) const; method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::nextView1), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_nextView1, ulxr::Signature() << ulxr::Integer::getValueName() << ulxr::Integer::getValueName() << ulxr::RpcString::getValueName() << ulxr::Boolean::getValueName() << ulxr::Integer::getValueName(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'std::wstring * UlxrIdlTest::nextView1(int i, long int * l, std::string & s, const bool * b, char c) const'."))); // TODO adjust comment // mapped to: std::basic_string<char> * nextView2(int i, long int l, std::string & s, bool * const b, char c) const; method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::nextView2), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_nextView2, ulxr::Signature() << ulxr::Integer::getValueName() << ulxr::Integer::getValueName() << ulxr::RpcString::getValueName() << ulxr::Boolean::getValueName() << ulxr::Integer::getValueName(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'std::basic_string<char> * UlxrIdlTest::nextView2(int i, long int l, std::string & s, bool * const b, char c) const'."))); // TODO adjust comment // mapped to: void getNumObjects(std::string s); method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::getNumObjects), ulxr::Void::getValueName(), ULXR_CALLTO_UlxrIdlTest_getNumObjects, ulxr::Signature() << ulxr::RpcString::getValueName(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'void UlxrIdlTest::getNumObjects(std::string s)'."))); // TODO adjust comment // mapped to: const std::basic_string<wchar_t> * getObject(const std::string & s); method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::getObject), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_getObject, ulxr::Signature() << ulxr::RpcString::getValueName(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'const std::basic_string<wchar_t> * UlxrIdlTest::getObject(const std::string & s)'."))); // TODO adjust comment // mapped to: int getNumPages(const std::wstring & s); method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::getNumPages), ulxr::Integer::getValueName(), ULXR_CALLTO_UlxrIdlTest_getNumPages, ulxr::Signature() << ulxr::RpcString::getValueName(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'int UlxrIdlTest::getNumPages(const std::wstring & s)'."))); // TODO adjust comment // mapped to: const std::string * last_url4(); (there are overloaded methods) method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::last_url4_ovr0), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_last_url4_ovr0, ulxr::Signature(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'const std::string * UlxrIdlTest::last_url4()'."))); // TODO adjust comment // mapped to: std::string * last_url4(int i); (there are overloaded methods) method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::last_url4_ovr1), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_last_url4_ovr1, ulxr::Signature() << ulxr::Integer::getValueName(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'std::string * UlxrIdlTest::last_url4(int i)'."))); // TODO adjust comment // mapped to: std::string * last_url4(long int li); (there are overloaded methods) method_adder.addMethod(ulxr::make_method(*this, &UlxrIdlTestServer::last_url4_ovr2), ulxr::RpcString::getValueName(), ULXR_CALLTO_UlxrIdlTest_last_url4_ovr2, ulxr::Signature() << ulxr::Integer::getValueName(), ulxr_i18n(ULXR_PCHAR("Some descriptive comment about 'std::string * UlxrIdlTest::last_url4(long int li)'."))); // TODO adjust comment }