ULXR_API_IMPL(void) HttpClient::filePUT(const CppString &filename,
                                     const CppString &type,
                                     const CppString &resource)
{
  ULXR_TRACE(ULXR_PCHAR("filePUT"));

  if (!protocol->isOpen() )
    protocol->open();

  FILE *ifs = fopen (getLatin1(filename).c_str(), "rb");
  if (ifs == 0)
    throw Exception(SystemError,
                    ulxr_i18n(ULXR_PCHAR("Cannot open file: "))+filename);

  struct stat statbuf;
  if (0 != stat (getLatin1(filename).c_str(), &statbuf) )
    throw Exception(SystemError,
                    ulxr_i18n(ULXR_PCHAR("Could not get information about file: "))+filename);

  sendAuthentication();
  protocol->sendRequestHeader(ULXR_PCHAR("PUT"), resource, type, statbuf.st_size);

  char buffer [ULXR_SEND_BUFFER_SIZE];
  long readed;
  try {
    while (!feof(ifs))
    {
      readed = fread(buffer, 1, sizeof(buffer), ifs);
      if (readed < 0)
        throw Exception(SystemError,
                        ulxr_i18n(ULXR_PCHAR("Could not read from file: "))+filename);
      protocol->writeBody(buffer, readed);
    }
  }
  catch (...)
  {
    fclose(ifs);
    throw;
  }

//  bool eof_reached = feof(ifs);
  fclose(ifs);

  BodyProcessor bp;
  receiveResponse(bp);

  if (getHttpStatus() != 200)
    throw ConnectionException(TransportError,
                              getHttpPhrase(), getHttpStatus());

  if (!protocol->isPersistent() )
    protocol->close();
}
ULXR_API_IMPL(void) HttpClient::receiveResponse(BodyProcessor &proc)
{
  ULXR_TRACE(ULXR_PCHAR("receiveResponse"));
  protocol->resetConnection();

  char buffer[ULXR_RECV_BUFFER_SIZE];
  char *buff_ptr;

  bool done = false;
  long readed;
  while (!done && ((readed = protocol->readRaw(buffer, sizeof(buffer))) > 0) )
  {
    buff_ptr = buffer;

    if (!protocol->hasBytesToRead())
      done = true;

    while (readed > 0)
    {
      Protocol::State state = protocol->connectionMachine(buff_ptr, readed);
      if (state == Protocol::ConnError)
        throw ConnectionException(TransportError,
                                  ulxr_i18n(ULXR_PCHAR("network problem occured")), 500);

      // switch to appropriate method when header is completely read
      else if (   state == Protocol::ConnSwitchToBody
               || state == Protocol::ConnBody)
      {
        interpreteHttpHeader();
        proc.process(buff_ptr, readed);
        readed = 0;
      }
    }
  }
}
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
  {
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);
  }
}
Beispiel #5
0
ULXR_API_IMPL(Value) MethodCall::getParam(unsigned ind) const
{
  if (ind < params.size() )
    return params[ind];

  throw ParameterException(InvalidMethodParameterError,
                           ulxr_i18n(ULXR_PCHAR("Not enough actual parameters for call to method: ")
                               +getSignature()));
}
ULXR_API_IMPL(void) TcpIpConnection::setProxy(const CppString &dom, unsigned port)
{
  ULXR_TRACE(ULXR_PCHAR("setProxy ") << dom << ULXR_PCHAR(" ") << port);
  struct hostent *hp = getHostAdress(dom);
  if (hp == 0)
    throw ConnectionException(SystemError,
                              ulxr_i18n(ULXR_PCHAR("Host adress for proxy not found: ")) + dom, 500);
  memcpy(&(pimpl->hostdata.sin_addr), hp->h_addr_list[0], hp->h_length);
  pimpl->hostdata.sin_port = htons(port);
}
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_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));
}
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(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();
}
Beispiel #11
0
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();
}
 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);
 }
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
}
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(bool) ValueParser::testEndElement(const XML_Char *name)
{
  ULXR_TRACE(ULXR_PCHAR("ValueParser::testEndElement(const XML_Char*)"));

  if (states.size() <= 1)
    throw RuntimeException(ApplicationError, ulxr_i18n(ULXR_PCHAR("abnormal program behaviour: ValueParser::testEndElement() had no states left")));

  std::auto_ptr<ValueState> curr(getTopValueState());
  states.pop();
/*
  ULXR_DOUT (ULXR_GET_STRING(name)
             << ULXR_PCHAR(" = cur-val: ")
             << std::hex << (void*) curr->getValue()
             << ULXR_PCHAR(" state: ")
             << std::hex << (void*) curr->getParserState()
             << ULXR_PCHAR(" prev state: ")
             << std::hex << (void*) curr->getPrevParserState()
             << std::dec);
*/
  states.top()->setPrevParserState(curr->getParserState());
  switch(curr->getParserState() )
  {
    case eBoolean:
      assertEndElement(name, "boolean");
      getTopValueState()->takeValue(new Value(Boolean(curr->getCharData())) );
    break;

    case eInt:
      assertEndElement(name, "int");
      getTopValueState()->takeValue(new Value(Integer(curr->getCharData())) );
    break;

    case eI4:
      assertEndElement(name, "i4");
      getTopValueState()->takeValue(new Value(Integer(curr->getCharData())) );
    break;

    case eDouble:
      assertEndElement(name, "double");
      getTopValueState()->takeValue(new Value(Double(curr->getCharData())) );
    break;

    case eString:
      assertEndElement(name, "string");
      getTopValueState()->takeValue(new Value(RpcString(curr->getCharData())) );
    break;

    case eBase64:
    {
      assertEndElement(name, "base64");
      Base64 b64;
      b64.setBase64(curr->getCharData()); // move raw data!
      getTopValueState()->takeValue(new Value(b64));
    }
    break;

    case eDate:
      assertEndElement(name , "dateTime.iso8601");
      getTopValueState()->takeValue(new Value(DateTime(curr->getCharData())) );
    break;

    case eMember:
      assertEndElement(name, "member");
      getTopValueState()->takeValue (curr->getValue());
    break;

    case eName:
      assertEndElement(name, "name");
      getTopValueState()->takeName((curr->getCharData()) );
    break;

    case eValue:
      assertEndElement(name, "value");
      if (curr->getValue() == 0)     // special case
      {
        if(curr->getPrevParserState() == eArray)            // not empty Array
           getTopValueState()->takeValue (new Value(Array()));

        else if (curr->getPrevParserState() == eStruct)     // not empty Struct
           getTopValueState()->takeValue (new Value(Struct()));

        else                                                // no type tag defaults to string
          getTopValueState()->takeValue (new Value(RpcString(curr->getCharData())));
      }
      else
        getTopValueState()->takeValue (curr->getValue());
    break;

    case eStruct:
      assertEndElement(name, "struct");
      getTopValueState()->takeValue (curr->getValue());
    break;

    case eArray:
      assertEndElement(name, "array");
      getTopValueState()->takeValue (curr->getValue());
    break;

    case eData:
      assertEndElement(name, "data");
      getTopValueState()->takeValue (curr->getValue());
    break;

    default:
      states.push(curr.release());
      return false;
  }

  return true;
}