Beispiel #1
0
Identifier::Identifier (const char *s)
  : pv_string (0),
    escaped_ (false)
{
  bool shift = false;

  if (*s == '_')
    {
      // Only one leading underscore is allowed.
      if (s[1] == '_')
        {
          idl_global->err ()->error0 (UTL_Error::EIDL_UNDERSCORE);
        }

      shift = true;
      this->escaped_ = true;
      ACE_CString str (s);
      const char *c_prefix = "_cxx_";

      if (str.find ("_tc_") == 0
          || str.find ("_tao_") == 0)
        {
          shift = false;
        }
      else if (str.find (c_prefix) == 0)
        {
          str = str.substr (ACE_OS::strlen (c_prefix));
          const char *eh_suffix = "_excep";
          ACE_CString::size_type pos =
            str.length () - ACE_OS::strlen (eh_suffix);

          // If we have an AMI exception holder suffix, strip it off.
          if (str.find (eh_suffix) == pos)
            {
              str = str.substr (0, pos);
            }

          TAO_IDL_CPP_Keyword_Table cpp_key_tbl;
          unsigned int len =
            static_cast<unsigned int> (str.length ());
          const TAO_IDL_CPP_Keyword_Entry *entry =
            cpp_key_tbl.lookup (str.c_str (), len);

          if (entry != 0)
            {
              shift = false;
            }
        }
    }

  if (shift)
    {
      this->pv_string = ACE::strnew (s + 1);
    }
  else
    {
      this->pv_string = ACE::strnew (s);
    }
}
Beispiel #2
0
bool Request::read(std::istream& str)
{
    ACE_CString cmd (4, '\0');
    ACE_CString args (128, '\0');

    int ch =  str.peek ();
    if (ch == eof_)
    {
        str.get (); // skip to eof
        return false;
    }
    // skip whitespace
    while (ACE_OS::ace_isspace (str.peek ()))
    {
        str.get ();
    }
    // get method
    ch = str.get ();
    while (!ACE_OS::ace_isspace (ch) && ch != eof_ && cmd.length () < MAX_CMD_LENGTH)
    {
        cmd += ch;
        ch = str.get ();
    }
    if (!ACE_OS::ace_isspace (ch))
        return false; // invalid FTP command string
    if (ch != '\r' && ch != '\n')
    {
        // skip whitespace
        while (ACE_OS::ace_isspace (str.peek ()))
        {
            str.get ();
        }
        // get arguments
        ch = str.get ();
        while (ch != eof_ && ch != '\r' && ch != '\n' && args.length () < MAX_ARG_LENGTH)
        {
            args += ch;
            ch = str.get ();
        }
        if (ch != eof_ && ch != '\r' && ch != '\n')
        {
            return false; // args too long
        }
    }
    if (ch == '\r')
    {
        str.get ();
    }
    this->command (cmd);
    this->args_ = args;
    return true;
}
void
TAO_Notify_StructuredProxyPushConsumer::load_attrs (const TAO_Notify::NVPList& attrs)
{
  SuperClass::load_attrs(attrs);
  ACE_CString ior;
  if (attrs.load("PeerIOR", ior))
  {
    CORBA::ORB_var orb = TAO_Notify_PROPERTIES::instance()->orb();
    try
    {
      CosNotifyComm::StructuredPushSupplier_var ps = CosNotifyComm::StructuredPushSupplier::_nil();
      if ( ior.length() > 0 )
      {
        CORBA::Object_var obj = orb->string_to_object(ior.c_str());
        ps = CosNotifyComm::StructuredPushSupplier::_unchecked_narrow(obj.in());
      }
      // minor hack: suppress generating subscription updates during reload.
      bool save_updates = this->updates_off_;
      this->updates_off_ = true;
      this->connect_structured_push_supplier(ps.in());
      this->updates_off_ = save_updates;
    }
    catch (const CORBA::Exception&)
    {
      // if we can't reconnect to peer, tough...
    }
  }
}
Beispiel #4
0
Boolean
StreamSize::write_string(const ACE_CString &x) {
    // @@ Leave this method in here, not the `.i' file so that we don't
    //    have to unnecessarily pull in the `ace/SString.h' header.
    return this->write_string(static_cast<ULong> (x.length()),
            x.c_str());
}
Beispiel #5
0
Server_Info_Ptr
Locator_Repository::get_active_server (const ACE_CString& name, int pid)
{
  sync_load ();
  ACE_CString key;
  Server_Info_Ptr si;
  if (name.length() == 0)
    {
      return si;
    }
  Server_Info::fqname_to_key (name.c_str(), key);
  servers ().find (key, si);
  if (si.null())
    {
      if (this->opts_.debug() > 5)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%P|%t) get_active_server could not find %C\n"),
                          name.c_str()));
        }
      si = find_by_poa (key);
      if (si.null())
        {
          if (name.find ("JACORB:") == ACE_CString::npos)
            {
              ACE_CString jo_key ("JACORB:");
              ACE_CString::size_type pos = name.find (':');
              if (pos == ACE_CString::npos)
                {
                  jo_key += name;
                }
              else
                {
                  jo_key += name.substring (0, pos);
                  jo_key += '/';
                  jo_key += name.substring (pos+1);
                }
              return this->get_active_server (jo_key, pid);
            }
          else
            {
              return si;
            }
        }
    }

  if (pid != 0 && si->pid != 0 && si->pid != pid)
    {
      if (this->opts_.debug() > 5)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("(%P|%t) get_active_server could not")
                          ACE_TEXT (" find %C, %d != %d\n"),
                          name.c_str(), pid, si->pid));
        }
      si.reset ();
    }
  return si;
}
Beispiel #6
0
int testConstIterator()
{
  const ACE_CString s1 ("Hello, World");

  // Use the advance () method to count number of characters.
  size_t count = 0;
  for (ACE_CString::CONST_ITERATOR iter (s1); !iter.done (); iter.advance ())
    ++ count;

  if (count != s1.length ())
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("advance () failed")),
                       1);

  // Use the prefix operator to count number of characters.
  count = 0;
  for (ACE_CString::CONST_ITERATOR iter (s1); !iter.done (); ++ iter)
    ++ count;

  if (count != s1.length ())
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("++ operator failed")),
                       1);

  count = 0;

  for (ACE_CString::const_iterator iter = s1.begin (), iter_end = s1.end ();
       iter != iter_end; iter ++)
  {
    ++ count;
  }

  if (count != s1.length ())
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("end () failed")),
                       1);

  ACE_CString::const_iterator iter1 (s1);

  if (*iter1 != s1[0])
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("dereference operator failed")),
                       1);

  return 0;
}
  void cleanup(PersistenceUpdater::ALLOCATOR* allocator)
  {
    if (name.length() > 0)
    {
      char* strMemory = const_cast<char*>(name.fast_rep());
      name.fast_clear();
      allocator->free(strMemory);
    }
    if (dataType.length() > 0)
    {
      char* strMemory = const_cast<char*>(dataType.fast_rep());
      dataType.fast_clear();
      allocator->free(strMemory);
    }

    allocator->free(topicQos.second.second);
  }
Beispiel #8
0
bool BACIValue::fromString(const ACE_CString value, bool specifyType)
{

  ACE_CString strType;
  ACE_CString strContent;
  const char *szType;
  const char *szContent;
  unsigned long ulBound = 0;

  if (specifyType)
    {
      ACE_CString::size_type nPos0 = value.find('<');
      ACE_CString::size_type nPos1 = value.find(':');
      ACE_CString::size_type nPos2 = value.find('>');

      if((nPos1 != ACE_CString::npos) && (nPos1 < (nPos2-1)))
		ulBound = atoi(value.substr(nPos1+1, nPos2-nPos1-1).c_str());
      else
		nPos1 = nPos2;

      strType = value.substr(nPos0+1, nPos1-nPos0-1);
      strContent = value.substr(nPos2+1);
      szType = strType.c_str();
      szContent = strContent.c_str();

    }
  else
    {
      strType = typeName[type_m];
      strContent = value;
      szType = strType.c_str();
      szContent = strContent.c_str();
    }

/// User defined

  // special threathment for string (no conversion needed)
  if(strType.compare(BACIValue::typeName[type_string]) == 0)
    {
      if ((ulBound != 0) && (strContent.length() > ulBound))
	return false;
      if(!setType(type_string, ulBound))
	return 0;
      return stringValue(szContent);
    }

   PROCESS_INLINE_TYPE(double, BACIdouble)
   PROCESS_INLINE_TYPE(float, BACIfloat)
   PROCESS_INLINE_TYPE(long, BACIlong)
   PROCESS_INLINE_TYPE(longLong, BACIlongLong)
   PROCESS_INLINE_TYPE(uLongLong, BACIuLongLong)
//TBDeleted   PROCESS_INLINE_TYPE(pattern, BACIpattern)

  return false;

}
ssize_t
ACE::HTBP::Inside_Squid_Filter::recv_data_header (ACE::HTBP::Channel *ch)
{
  if (this->http_code() != 200 && this->http_code() != 0)
    {
      if (ACE::debug())
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT("HTBP::Inside_Squid_Filter::recv_data_header, ")
                    ACE_TEXT("non-OK result code %d recvd\n"),
                    this->http_code()));

      errno = ch->consume_error () ? EINVAL : EWOULDBLOCK;
      return 0;
    }
  char *header_end = this->header_complete(ch);
  if (header_end == 0)
    {
      if (ch->state() != ACE::HTBP::Channel::Closed)
        {
          ch->state (ACE::HTBP::Channel::Header_Pending);
          errno = EWOULDBLOCK;
        }
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT("HTBP::Inside_Squid_Filter::")
                         ACE_TEXT("recv_data_header, ")
                         ACE_TEXT("header not complete\n")),
                        0);
    }
  char *start = ch->leftovers().rd_ptr();
  ACE_CString token = "Content-Length: ";
  char *tpos = ACE_OS::strstr(start,token.c_str());
  char *nl = ACE_OS::strchr (start,'\n');
  if (tpos != 0)
    {
      tpos += token.length();
      *nl = 0;
      ch->data_len (ACE_OS::strtol(tpos,0,10));
      start = nl+1;
    }

  ch->leftovers().rd_ptr(header_end);
  if (this->http_code() != 200)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("HTBP::Inside_Squid_Filter::recv_data_header, ")
                  ACE_TEXT("non-OK result code %d recvd\n"),
                  this->http_code()));

      errno = ch->consume_error () ? EINVAL : EWOULDBLOCK;
      return 0;
    }

  ch->state(ACE::HTBP::Channel::Data_Queued);
  return 1;
}
Beispiel #10
0
int
Locator_Repository::setup_multicast (ACE_Reactor* reactor, const char* ior)
{
  ACE_ASSERT (reactor != 0);
#if defined (ACE_HAS_IP_MULTICAST)

  TAO_ORB_Core* core = TAO_ORB_Core_instance ();
  // See if the -ORBMulticastDiscoveryEndpoint option was specified.
  ACE_CString mde (core->orb_params ()->mcast_discovery_endpoint ());

  if (mde.length () != 0)
    {
      if (this->ior_multicast_.init (ior,
                                     mde.c_str (), TAO_SERVICEID_IMPLREPOSERVICE) == -1)
        {
          return -1;
        }
    }
  else
    {
      // Port can be specified as param, env var, or default
      CORBA::UShort port =
        core->orb_params ()->service_port (TAO::MCAST_IMPLREPOSERVICE);
      if (port == 0)
        {
          // Check environment var. for multicast port.
          const char* port_number = ACE_OS::getenv ("ImplRepoServicePort");

          if (port_number != 0)
            port = static_cast<CORBA::UShort> (ACE_OS::atoi (port_number));
        }
      if (port == 0)
        port = TAO_DEFAULT_IMPLREPO_SERVER_REQUEST_PORT;

      if (this->ior_multicast_.init (ior, port,
                                     ACE_DEFAULT_MULTICAST_ADDR, TAO_SERVICEID_IMPLREPOSERVICE) == -1)
        {
          return -1;
        }
    }

  // Register event handler for the ior multicast.
  if (reactor->register_handler (&this->ior_multicast_,
                                 ACE_Event_Handler::READ_MASK) == -1)
    {
      if (this->opts_.debug() > 0)
        ORBSVCS_DEBUG ((LM_DEBUG, "ImR: cannot register Event handler\n"));
      return -1;
    }
#else /* ACE_HAS_IP_MULTICAST*/
  ACE_UNUSED_ARG (reactor);
  ACE_UNUSED_ARG (ior);
#endif /* ACE_HAS_IP_MULTICAST*/
  return 0;
}
Beispiel #11
0
    bool GetCmd(const ACE_CString& input, ACE_CString& cmd)
    {
        size_t nEndCommand = 0;
        while(nEndCommand < input.length() && 
            input[nEndCommand] != ' ' 
            && input[nEndCommand] != '\r' && 
            input[nEndCommand] != '\n')nEndCommand++;

        if(nEndCommand)
            cmd = input.substr(0,nEndCommand);
        return nEndCommand>0;
    }
    int SSL_CallbackManager::passwd_callback (char* buf, int size, int /*rwflag*/, void* user_data)
      {
        if (user_data == 0)
          return 0;

        SSL_CallbackManager* cbmngr = reinterpret_cast<SSL_CallbackManager*> (user_data);

        ACE_CString pwd;
        cbmngr->passwd_callback (pwd);
        if (!pwd.empty ())
          {
            ACE_OS::strncpy (buf, pwd.c_str (), size);
            buf[size - 1] = '\0';
            if (size > ACE_Utils::truncate_cast<int> (pwd.length ()))
              size = ACE_Utils::truncate_cast<int> (pwd.length ());

            return size;
          }
        else
          return 0;
      }
Beispiel #13
0
    bool GetCmdLine(const ACE_CString& input, ACE_CString& cmd, ACE_CString& remain_input)
    {
        if(input.find('\n') != ACE_TString::npos)
        {
            size_t pos = input.find('\n');
            cmd = input.substr(0, pos+1);
            size_t len = input.length();
            remain_input = input.substr(pos+1, len-pos+1);

            return true;
        }
        return false;
    }
  void cleanup(PersistenceUpdater::ALLOCATOR* allocator)
  {
    if (callback.length() > 0)
    {
      char* strMemory = const_cast<char*>(callback.fast_rep());
      callback.fast_clear();
      allocator->free(strMemory);
    }

    allocator->free(pubsubQos.second.second);
    allocator->free(drdwQos.second.second);
    allocator->free(transportInterfaceInfo.second);
    allocator->free(contentSubscriptionProfile.exprParams.second);
  }
Beispiel #15
0
void
ImR_DSI_ResponseHandler::send_ior (const char *pior)
{
  ACE_CString ior = pior;

  // Check that the returned ior is the expected partial ior with
  // missing ObjectKey.
  if (ior.find ("corbaloc:") == 0 && ior[ior.length () -1] == '/')
    {
      ior += this->key_str_.in();

      CORBA::Object_var forward_obj = this->orb_->string_to_object (ior.c_str ());

      if (!CORBA::is_nil (forward_obj.in ()))
        {
          this->resp_->invoke_location_forward(forward_obj.in(), false);
          delete this;
          return;
        }
      else
        {
          if (ImR_Locator_i::debug () > 1)
            {
              ORBSVCS_ERROR ((LM_ERROR,
                          ACE_TEXT ("(%P|%t) ImR_DSI_ResponseHandler::send_ior (): Forward_to ")
                          ACE_TEXT ("reference is nil for key <%C> server_name <%C>\n"),
                          key_str_.in (), server_name_.in ()));
            }
        }
    }
  else
    {
      if (ImR_Locator_i::debug () > 1)
        {
          ORBSVCS_ERROR ((LM_ERROR,
                      ACE_TEXT ("(%P|%t) ImR_DSI_ResponseHandler::send_ior (): Invalid corbaloc ior for key <%C> server_name <%C> IOR <%C>\n"),
                      key_str_.in (), server_name_.in (), pior));
        }
    }

  this->invoke_excep_i (new CORBA::OBJECT_NOT_EXIST
                        (CORBA::SystemException::_tao_minor_code
                         ( TAO_IMPLREPO_MINOR_CODE, 0),
                         CORBA::COMPLETED_NO));
}
Beispiel #16
0
bool
FE_Utils::is_include_file_found (ACE_CString & inc_file,
                                 UTL_String * idl_file_name)
{
  char abspath[MAXPATHLEN] = "";
  char *full_path = 0;

  // If the include path has literal "s (because of an include
  // of a Windows path with spaces), we must remove them here.
  const char *tmp_inc_file = inc_file.c_str ();

  if (tmp_inc_file
      && FE_Utils::hasspace (tmp_inc_file)
      && tmp_inc_file[0] == '\"')
    {
      inc_file =
        inc_file.substr (1, inc_file.length () - 2);
    }

  inc_file += ACE_DIRECTORY_SEPARATOR_STR_A;
  inc_file += idl_file_name->get_string ();
  full_path =
    ACE_OS::realpath (inc_file.c_str (), abspath);

  if (full_path != 0)
    {
      FILE *test = ACE_OS::fopen (abspath, "r");

      if (test == 0)
        {
          return false;
        }
      else
        {
          // Overwrite inc_file with abspath since the later
          // is normalized to the native OS representation.
          inc_file = abspath;
          ACE_OS::fclose (test);
          return true;
        }
    }

  return false;
}
ssize_t
ACE::HTBP::Inside_Squid_Filter::send_data_header (ssize_t data_len,
                                                ACE::HTBP::Channel *ch)
{
  char *buffer = new char[BUFSIZ];
  ACE_Auto_Array_Ptr<char> guard (buffer);
  ssize_t result = -1;
  if (this->make_request_header (ch,"POST ",buffer,BUFSIZ) != -1)
    {
      ACE_CString header (buffer);
      header += "Content-Type: application/octet-stream\nContent-Length: ";
      char datalenstr[20];
      ACE_OS::itoa (data_len,datalenstr,10);
      header += datalenstr;
      header += "\n\n";
      result = ch->ace_stream().send(header.c_str(),header.length());
    }
  ch->state(result == -1 ? ACE::HTBP::Channel::Closed :
            ACE::HTBP::Channel::Header_Sent);
  this->reset_http_code();
  return 1;
}
Beispiel #18
0
    bool
    ClientRequestHandler::parse_address (const ACE_CString& str, ACE_INET_Addr& addr)
      {
        static const int eof_ = std::char_traits<char>::eof ();

        ACE::IOS::CString_OStream sos_host;
        u_short port_hi = 0, port_lo = 0;

        ACE::IOS::CString_IStream sis (str);
        sis.ignore (str.length (), '(');
        int ch = sis.get ();
        if (ACE_OS::ace_isdigit (ch))
          {
            for (int i=0; i<4 ;++i)
              {
                if (ch == ',')
                  {
                    sos_host.put ('.');
                    ch = sis.get ();
                  }
                while (ch != eof_ && ACE_OS::ace_isdigit (ch))
                  {
                    sos_host.put (ch);
                    ch = sis.get ();
                  }
              }
            if (ch == ',')
              {
                sis >> port_hi;
                ch = sis.get ();
                if (ch == ',')
                  {
                    sis >> port_lo;

                    u_short port = port_hi*256 + port_lo;
                    addr.set (port, sos_host.str ().c_str ());
                    return true;
                  }
              }
int
ACE::HTBP::Inside_Squid_Filter::recv_ack (ACE::HTBP::Channel *ch)
{

  char *header_end = this->header_complete(ch);
  if (header_end == 0)
    {
      if (ch->state() != ACE::HTBP::Channel::Closed)
        errno = EWOULDBLOCK;
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT("HTBP::Inside_Squid_Filter::")
                         ACE_TEXT("recv_ack, ")
                         ACE_TEXT("header not complete\n")),0);
    }
  if (this->http_code() == 200)
    {
      ch->leftovers().length(0);
      ch->state(ACE::HTBP::Channel::Ready);
      return 1;
    }

  char *start = ch->leftovers().rd_ptr();
  ACE_CString token = "Content-Length: ";
  char *tpos = ACE_OS::strstr(start,token.c_str());
  char *nl = ACE_OS::strchr (start,'\n');
  if (tpos != 0)
    {
      tpos += token.length();
      *nl = 0;
      ch->data_len (ACE_OS::strtol(tpos,0,10));
      start = nl+1;
    }

  ch->leftovers().rd_ptr(header_end);
  errno = ch->consume_error () ? EINVAL : EWOULDBLOCK;
  return 0;
}
void
TAO_Notify_StructuredProxyPushSupplier::load_attrs (const TAO_Notify::NVPList& attrs)
{
    SuperClass::load_attrs(attrs);
    ACE_CString ior;
    if (attrs.load("PeerIOR", ior))
    {
        CORBA::ORB_var orb = TAO_Notify_PROPERTIES::instance()->orb();
        try
        {
            CosNotifyComm::StructuredPushConsumer_var pc = CosNotifyComm::StructuredPushConsumer::_nil();
            if (ior.length() > 0)
            {
                CORBA::Object_var obj = orb->string_to_object(ior.c_str());
                pc = CosNotifyComm::StructuredPushConsumer::_unchecked_narrow(obj.in());
            }
            this->connect_structured_push_consumer(pc.in());
        }
        catch (const CORBA::Exception&)
        {
            // if we can't connect... tough
        }
    }
}
Beispiel #21
0
UTL_ScopedName *
ast_visitor_reifying::template_module_rel_name (AST_Decl *d)
{
  AST_Decl *tmp = d;
  ACE_CString name (d->full_name ());

  while (tmp != 0)
    {
      if (AST_Template_Module::narrow_from_decl (tmp) != 0)
        {
          ACE_CString head (tmp->local_name ()->get_string ());

          ACE_CString::size_type start = name.find (head) + 2;

          ACE_CString tail (name.substr (start + head.length ()));

          return FE_Utils::string_to_scoped_name (tail.c_str ());
        }

      tmp = ScopeAsDecl (tmp->defined_in ());
    }

  return 0;
}
Beispiel #22
0
void
CORBA::ServerRequest::gateway_exception_reply (ACE_CString &raw_exception)
{
  // This defaults to 1, but just to be safe...
  this->orb_server_request_.argument_flag (true);

  // This reply path handles only user exceptions.
  this->orb_server_request_.reply_status (GIOP::USER_EXCEPTION);

  this->orb_server_request_.init_reply ();

  // We know nothing about this exception, so we marshal it as a block
  // of bytes. The outgoing stream's byte order has already been matched
  // to the original source of the reply.
  this->orb_server_request_.outgoing ()->write_octet_array (
      reinterpret_cast<const CORBA::Octet *> (raw_exception.fast_rep ()),
      static_cast<CORBA::ULong> (raw_exception.length () + ACE_CDR::MAX_ALIGNMENT)
    );

  // This will prevent the marshaling of any parameters into this reply.
  this->sent_gateway_exception_ = true;

  this->orb_server_request_.tao_send_reply ();
}
int
ACE::HTBP::Inside_Squid_Filter::send_ack (ACE::HTBP::Channel *ch)
{
  char *buffer = new char[BUFSIZ];
  ACE_Auto_Array_Ptr<char> guard (buffer);
  ssize_t result = -1;
  if (ch->state() == ACE::HTBP::Channel::Ack_Sent)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT("HTBP::Inside Filter::send_ack: ")
                         ACE_TEXT("state is already ACK_SENT\n")),
                        1);
    }
  if (this->make_request_header (ch,"GET ",buffer,BUFSIZ) != -1)
    {
      ACE_CString header (buffer);
      header += "\n";
      result = ch->ace_stream().send(header.c_str(),header.length());
    }
  ch->state(result == -1 ?
            ACE::HTBP::Channel::Closed : ACE::HTBP::Channel::Ack_Sent);
  this->reset_http_code();
  return 1;
}
UTL_ScopedName *
be_visitor_xplicit_pre_proc::xplicit_iface_rel_name (AST_Decl *d)
{
  AST_Decl *tmp = d;
  ACE_CString name (d->full_name ());

  while (tmp != 0)
    {
      if (be_home::narrow_from_decl (tmp) != 0)
        {
          ACE_CString head (tmp->local_name ()->get_string ());

          ACE_CString::size_type start = name.find (head) + 2;

          ACE_CString tail (name.substr (start + head.length ()));

          return FE_Utils::string_to_scoped_name (tail.c_str ());
        }

      tmp = ScopeAsDecl (tmp->defined_in ());
    }

  return 0;
}
Beispiel #25
0
void
Locator_XMLHandler::startElement (const ACEXML_Char*,
                                  const ACEXML_Char*,
                                  const ACEXML_Char* qName,
                                  ACEXML_Attributes* attrs)
{
  if (ACE_OS::strcasecmp (qName, SERVER_INFO_TAG) == 0)
    {
      ACE_NEW (this->si_, Server_Info);
      this->env_vars_.clear ();

      // if attrs exists and if the previously required 9 fields
      const size_t previous_size = 9;
      if (attrs != 0 && attrs->getLength () >= previous_size)
        {
          size_t index = 0;
          this->si_->server_id = ACE_TEXT_ALWAYS_CHAR (attrs->getValue (index++));
          this->si_->poa_name = ACE_TEXT_ALWAYS_CHAR (attrs->getValue (index++));
          this->si_->activator = ACE_TEXT_ALWAYS_CHAR (attrs->getValue (index++));
          this->si_->cmdline = ACE_TEXT_ALWAYS_CHAR (attrs->getValue (index++));
          this->si_->dir = ACE_TEXT_ALWAYS_CHAR (attrs->getValue (index++));
          this->si_->activation_mode_ =
            ImR_Utils::stringToActivationMode (ACE_TEXT_ALWAYS_CHAR (attrs->getValue (index++)));
          this->si_->start_limit_ = ACE_OS::atoi (attrs->getValue (index++));
          this->si_->partial_ior = ACE_TEXT_ALWAYS_CHAR (attrs->getValue (index++));
          this->si_->ior = ACE_TEXT_ALWAYS_CHAR (attrs->getValue (index++));

          if (attrs->getLength () >= index)
            {
              this->server_started_ =
                (ACE_OS::atoi (attrs->getValue (index++)) != 0);
            }
          if (attrs->getLength () >= index)
            {
              this->si_->is_jacorb =
                (ACE_OS::atoi (attrs->getValue (index++)) != 0);
            }

          for ( ; index < attrs->getLength(); ++index)
            {
              ACE_TString name (attrs->getLocalName (index));
              ACE_CString value (ACE_TEXT_ALWAYS_CHAR (attrs->getValue (index)));
              if (name == KEYNAME_TAG)
                {
                  this->si_->key_name_ = value;
                }
              else if (name == ALTKEY_TAG)
                {
                  if (value.length() > 0 &&
                      this->repo_.servers ().find (value, this->si_->alt_info_) != 0)
                    {
                      Server_Info *base_si = 0;
                      ACE_NEW (base_si, Server_Info);
                      base_si->key_name_ = value;
                      this->si_->alt_info_.reset (base_si);
                      this->repo_.servers ().bind (value, this->si_->alt_info_);
                    }
                }
              else if (name == PID_TAG)
                {
                  this->si_->pid =
                    ACE_OS::atoi (attrs->getValue (index++));
                }
              else
                {
                  const ACE_CString name_cstr (ACE_TEXT_ALWAYS_CHAR (name.c_str ()));
                  this->extra_params_.push_back (std::make_pair (name_cstr, value));
                }
            }
        }
    }
  else if (ACE_OS::strcasecmp (qName, ACTIVATOR_INFO_TAG) == 0)
  {
    if (attrs != 0 && attrs->getLength () >= 3)
      {
        size_t index = 0;
        const ACE_CString aname =
          ACE_TEXT_ALWAYS_CHAR(attrs->getValue (index++));
        const ACE_TString token_str = attrs->getValue (index++);
        long token = ACE_OS::atoi (token_str.c_str ());
        const ACE_CString ior =
          ACE_TEXT_ALWAYS_CHAR(attrs->getValue (index++));
        NameValues extra_params;
        for ( ; index < attrs->getLength(); ++index)
          {
            ACE_CString name (ACE_TEXT_ALWAYS_CHAR (attrs->getLocalName(index)));
            ACE_CString value (ACE_TEXT_ALWAYS_CHAR (attrs->getValue(index)));
            extra_params.push_back (std::make_pair (name, value));
          }
        this->repo_.load_activator (aname, token, ior, extra_params);
      }
  }
  else if (ACE_OS::strcasecmp (qName, ENVIRONMENT_TAG) == 0)
    {
      if (attrs != 0 && attrs->getLength () == 2)
        {
          EnvVar ev;
          ev.name = attrs->getValue ((size_t)0);
          ev.value = attrs->getValue ((size_t)1);
          this->env_vars_.push_back (ev);
        }
    }
  else if (ACE_OS::strcasecmp (qName, PEER_TAG) == 0)
    {
      if (attrs != 0)
        {
          ACE_CString peer (ACE_TEXT_ALWAYS_CHAR (attrs->getValue((size_t)0)));
          this->peer_list_.push_back (peer);
        }
    }
}
int
be_visitor_ami_pre_proc::visit_interface (be_interface *node)
{
  // We check for an imported node after generating the reply handler.
  if (node->is_local () || node->is_abstract ())
    {
      return 0;
    }

  // The following 3 IF blocks are checks for CCM-related nodes, which
  // we want to skip until we get AMI integrated with CIAO.

  // Skip the *EventConsumer added for each eventtype.
  if (node->is_event_consumer ())
    {
      return 0;
    }

  // Check for home equivalent interface. The lookup will find the
  // home itself, which was declared first.
  Identifier *node_lname = node->AST_Decl::local_name ();
  AST_Decl *first_stored =
    node->defined_in ()->lookup_by_name_local (node_lname, false);

  if (0 != first_stored && first_stored->node_type () == AST_Decl::NT_home)
    {
      return 0;
    }

  ACE_CString lname (node_lname->get_string ());

  // Skip the *Explict and *Implicit interfaces added for a home.
  if (lname.substr (lname.length () - 6) == "plicit")
    {
      UTL_Scope *s = node->defined_in ();
      Identifier local_id (lname.substr (0, lname.length () - 8).c_str ());
      AST_Decl *d = s->lookup_by_name_local (&local_id, false);
      local_id.destroy ();

      if (0 != d)
        {
          return 0;
        }
    }

  AST_Module *module =
    AST_Module::narrow_from_scope (node->defined_in ());

  if (!module)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_ami_pre_proc::"
                         "visit_interface - "
                         "module is null\n"),
                        -1);
    }

  be_interface *reply_handler = this->create_reply_handler (node);

  if (reply_handler)
    {
      reply_handler->set_defined_in (node->defined_in ());

      // Insert the ami handler after the node, the
      // exception holder will be placed between these two later.
      module->be_add_interface (reply_handler, node);

      // Remember from whom we were cloned
      reply_handler->original_interface (node);

      // If this was created for an imported node, it will be wrong
      // unless we set it.
      reply_handler->set_imported (node->imported ());
    }
  else
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_ami_pre_proc::"
                         "visit_interface - "
                         "creating the reply handler failed\n"),
                        -1);
    }

  if (this->visit_scope (node) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_ami_pre_proc::"
                         "visit_interface - "
                         "visit scope failed\n"),
                        -1);
    }

  return 0;
}
Beispiel #27
0
// Install ior multicast handler.
int
TAO_IFR_Server::init_multicast_server (void)
{
#if defined (ACE_HAS_IP_MULTICAST)
  // Get reactor instance from TAO.
  ACE_Reactor *reactor = this->orb_->orb_core ()->reactor ();

  // See if the -ORBMulticastDiscoveryEndpoint option was specified.
  ACE_CString mde (
      TAO_ORB_Core_instance ()->orb_params ()->mcast_discovery_endpoint ()
    );

  // First, see if the user has given us a multicast port number
  // on the command-line;
  u_short port =
    TAO_ORB_Core_instance ()->orb_params ()->service_port (
                                                 TAO::MCAST_INTERFACEREPOSERVICE
                                               );

  if (port == 0)
    {
      // Check environment var. for multicast port.
      const char *port_number =
        ACE_OS::getenv ("InterfaceRepoServicePort");

      if (port_number != 0)
        port = static_cast<u_short> (ACE_OS::atoi (port_number));
    }

  // Port wasn't specified on the command-line or in environment -
  // use the default.
  if (port == 0)
    port = TAO_DEFAULT_INTERFACEREPO_SERVER_REQUEST_PORT;

  // Instantiate a handler which will handle client requests for
  // the IFR ior, received on the multicast port.
  ACE_NEW_THROW_EX (this->ior_multicast_,
                    TAO_IOR_Multicast (),
                    CORBA::NO_MEMORY ());

  if (mde.length () != 0)
    {
      if (this->ior_multicast_->init (this->ifr_ior_.in (),
                                      mde.c_str (),
                                      TAO_SERVICEID_INTERFACEREPOSERVICE)
           == -1)
        {
          ORBSVCS_ERROR_RETURN ((
              LM_ERROR,
              ACE_TEXT ("Interface Repository: cannot initialize ")
              ACE_TEXT ("multicast event handler\n")
            ),
            -1
          );
        }
    }
  else
    {
      if (this->ior_multicast_->init (this->ifr_ior_.in (),
                                      port,
                                      ACE_DEFAULT_MULTICAST_ADDR,
                                      TAO_SERVICEID_INTERFACEREPOSERVICE)
           == -1)
        {
          ORBSVCS_ERROR_RETURN ((
              LM_ERROR,
              ACE_TEXT ("Interface Repository: cannot initialize ")
              ACE_TEXT ("multicast event handler\n")
            ),
            -1
          );
        }
    }

  // Register event handler for the ior multicast.
  if (reactor->register_handler (this->ior_multicast_,
                                 ACE_Event_Handler::READ_MASK)
       == -1)
    {
      ORBSVCS_ERROR_RETURN ((
          LM_ERROR,
          ACE_TEXT ("Interface Repository: cannot register ")
          ACE_TEXT ("multicast event handler\n")
        ),
        -1
      );
    }

#endif /* ACE_HAS_IP_MULTICAST */

  return 0;
}
Beispiel #28
0
int
TAO_Naming_Server::init_new_naming (CORBA::ORB_ptr orb,
                                    PortableServer::POA_ptr poa,
                                    const ACE_TCHAR *persistence_location,
                                    void *base_addr,
                                    size_t context_size,
                                    int enable_multicast,
                                    int use_storable_context,
                                    int round_trip_timeout,
                                    int use_round_trip_timeout)
{
  try
    {
#if defined (CORBA_E_MICRO)
      ACE_UNUSED_ARG (persistence_location);
      ACE_UNUSED_ARG (base_addr);
      ACE_UNUSED_ARG (use_storable_context);
#else
      if (use_storable_context)
        {
          // In lieu of a fully implemented service configurator version
          // of this Reader and Writer, let's just take something off the
          // command line for now.
          TAO::Storable_Factory* pf = 0;
          ACE_CString directory (ACE_TEXT_ALWAYS_CHAR (persistence_location));
          ACE_NEW_RETURN (pf, TAO::Storable_FlatFileFactory (directory), -1);
          auto_ptr<TAO::Storable_Factory> persFactory(pf);

          // Use an auto_ptr to ensure that we clean up the factory in the case
          // of a failure in creating and registering the Activator.
          TAO_Storable_Naming_Context_Factory* cf =
            this->storable_naming_context_factory (context_size);
          // Make sure we got a factory
          if (cf == 0) return -1;
          auto_ptr<TAO_Storable_Naming_Context_Factory> contextFactory (cf);

          // This instance will either get deleted after recreate all or,
          // in the case of a servant activator's use, on destruction of the
          // activator.

          // Was a location specified?
          if (persistence_location == 0)
            {
              // No, assign the default location "NameService"
              persistence_location = ACE_TEXT ("NameService");
            }

          // Now make sure this directory exists
          if (ACE_OS::access (persistence_location, W_OK|X_OK))
            {
              ORBSVCS_ERROR_RETURN ((LM_ERROR, "Invalid persistence directory\n"), -1);
            }

#if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
          if (this->use_servant_activator_)
            {
              ACE_NEW_THROW_EX (this->servant_activator_,
                                TAO_Storable_Naming_Context_Activator (orb,
                                                                       persFactory.get(),
                                                                       contextFactory.get (),
                                                                       persistence_location),
                                CORBA::NO_MEMORY ());
              this->ns_poa_->set_servant_manager(this->servant_activator_);
            }
#endif /* TAO_HAS_MINIMUM_POA */
          try {  // The following might throw an exception.
            this->naming_context_ =
              TAO_Storable_Naming_Context::recreate_all (orb,
              poa,
              TAO_ROOT_NAMING_CONTEXT,
              context_size,
              0,
              contextFactory.get (),
              persFactory.get (),
              use_redundancy_);
          }
          catch (const CORBA::Exception& ex)
          {
            // The activator already took over the factories so we need to release the auto_ptr
            if (this->use_servant_activator_)
            {
              // The context factory is now owned by the activator
              // so we should release it
              contextFactory.release ();
              // If using a servant activator, the activator now owns the
              // factory, so we should release it
              persFactory.release ();
            }
            // Print out the exception and return failure
            ex._tao_print_exception (
              "TAO_Naming_Server::init_new_naming");
            return -1;
          }

        // Kind of a duplicate of the above here, but we must also release the
        // factory autoptrs in the good case as well.
        if (this->use_servant_activator_)
            {
              // The context factory is now owned by the activator
              // so we should release it
              contextFactory.release ();
              // If using a servant activator, the activator now owns the
              // factory, so we should release it
              persFactory.release ();
            }

      }
      else if (persistence_location != 0)
        //
        // Initialize Persistent Naming Service.
        //
        {

          // Create Naming Context Implementation Factory to be used for the creation of
          // naming contexts by the TAO_Persistent_Context_Index
          TAO_Persistent_Naming_Context_Factory *naming_context_factory =
            this->persistent_naming_context_factory ();
          // Make sure we got a factory.
          if (naming_context_factory == 0) return -1;

          // Allocate and initialize Persistent Context Index.
          ACE_NEW_RETURN (this->context_index_,
                          TAO_Persistent_Context_Index (orb, poa, naming_context_factory),
                          -1);

          if (this->context_index_->open (persistence_location,
                                          base_addr) == -1
              || this->context_index_->init (context_size) == -1)
            {
              if (TAO_debug_level >0)
                ORBSVCS_DEBUG ((LM_DEBUG,
                            "TAO_Naming_Server: context_index initialization failed\n"));
              return -1;
            }

          // Set the root Naming Context reference.
          this->naming_context_ =
            this->context_index_->root_context ();
        }
      else
#endif /* CORBA_E_MICRO */
        {
          //
          // Initialize Transient Naming Service.
          //
          this->naming_context_ =
            TAO_Transient_Naming_Context::make_new_context (poa,
                                                            TAO_ROOT_NAMING_CONTEXT,
                                                            context_size);

        }

#if !defined (CORBA_E_MICRO)
      // Register with the ORB's resolve_initial_references()
      // mechanism.  Primarily useful for dynamically loaded Name
      // Services.
      orb->register_initial_reference ("NameService",
                                       this->naming_context_.in ());
#endif /* CORBA_E_MICRO */

      // Set the ior of the root Naming Context.
      this->naming_service_ior_=
        orb->object_to_string (this->naming_context_.in ());

      CORBA::Object_var table_object =
        orb->resolve_initial_references ("IORTable");

      IORTable::Table_var adapter =
        IORTable::Table::_narrow (table_object.in ());
      if (CORBA::is_nil (adapter.in ()))
        {
          ORBSVCS_ERROR ((LM_ERROR, "Nil IORTable\n"));
        }
      else
        {
          CORBA::String_var ior =
            orb->object_to_string (this->naming_context_.in ());
          adapter->bind ("NameService", ior.in ());
        }

#if defined (ACE_HAS_IP_MULTICAST)
      if (enable_multicast)
        {
          // @@ Marina: is there anyway to implement this stuff
          // without using ORB_Core_instance()? For example can you
          // pass the ORB as an argument?

          //
          // Install ior multicast handler.
          //
          // Get reactor instance from TAO.
          ACE_Reactor *reactor = orb->orb_core()->reactor ();

          // See if the -ORBMulticastDiscoveryEndpoint option was specified.
          ACE_CString mde (orb->orb_core ()->orb_params ()->mcast_discovery_endpoint ());

          // First, see if the user has given us a multicast port number
          // on the command-line;
          u_short port =
            orb->orb_core ()->orb_params ()->service_port (TAO::MCAST_NAMESERVICE);

          if (port == 0)
            {
              // Check environment var. for multicast port.
              const char *port_number =
                ACE_OS::getenv ("NameServicePort");

              if (port_number != 0)
                port = static_cast<u_short> (ACE_OS::atoi (port_number));
            }

          // Port wasn't specified on the command-line or in environment -
          // use the default.
          if (port == 0)
            port = TAO_DEFAULT_NAME_SERVER_REQUEST_PORT;

          // Instantiate a handler which will handle client requests for
          // the root Naming Context ior, received on the multicast port.
          ACE_NEW_RETURN (this->ior_multicast_,
                          TAO_IOR_Multicast (),
                          -1);

          if (mde.length () != 0)
            {
              if (this->ior_multicast_->init (this->naming_service_ior_.in (),
                                              mde.c_str (),
                                              TAO_SERVICEID_NAMESERVICE) == -1)
                return -1;
            }
          else
            {
              if (this->ior_multicast_->init (this->naming_service_ior_.in (),
                                              port,
#if defined (ACE_HAS_IPV6)
                                              ACE_DEFAULT_MULTICASTV6_ADDR,
#else
                                              ACE_DEFAULT_MULTICAST_ADDR,
#endif /* ACE_HAS_IPV6 */
                                              TAO_SERVICEID_NAMESERVICE) == -1)
                return -1;
            }

          // Register event handler for the ior multicast.
          if (reactor->register_handler (this->ior_multicast_,
                                         ACE_Event_Handler::READ_MASK) == -1)
            {
              if (TAO_debug_level > 0)
                ORBSVCS_DEBUG ((LM_DEBUG,
                            "TAO_Naming_Server: cannot register Event handler\n"));
              return -1;
            }

          if (TAO_debug_level > 0)
            ORBSVCS_DEBUG ((LM_DEBUG,
                        "TAO_Naming_Server: The multicast server setup is done.\n"));
        }
#else
  ACE_UNUSED_ARG (enable_multicast);
#endif /* ACE_HAS_IP_MULTICAST */

#if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
      if (use_round_trip_timeout == 1)
      {
        TimeBase::TimeT roundTripTimeoutVal = round_trip_timeout;
        CORBA::Any anyObjectVal;
        anyObjectVal <<= roundTripTimeoutVal;
        CORBA::PolicyList polList (1);
        polList.length (1);
        polList[0] = orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
                                         anyObjectVal);

        // set a timeout on the orb
        //
        CORBA::Object_var orbPolicyManagerObj =
          orb->resolve_initial_references ("ORBPolicyManager");

        CORBA::PolicyManager_var orbPolicyManager =
          CORBA::PolicyManager::_narrow (orbPolicyManagerObj.in ());
        orbPolicyManager->set_policy_overrides (polList, CORBA::SET_OVERRIDE);

        polList[0]->destroy ();
        polList[0] = CORBA::Policy::_nil ();
      }
#else
  ACE_UNUSED_ARG (use_round_trip_timeout);
  ACE_UNUSED_ARG (round_trip_timeout);
#endif /* TAO_HAS_CORBA_MESSAGING */
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "TAO_Naming_Server::init_new_naming");
      return -1;
    }

  return 0;
}
Beispiel #29
0
/*the repo function
  talk to the repo.jg.org at a regular interval, 1 minute,
  and send acknowledgement to repo.jg.org
 */
static ACE_THR_FUNC_RETURN
fetch_step2(void *){
  ACE_INET_Addr addr(repo_port, repo_host.c_str());
  ACE_SOCK_Connector con;
  ACE_SOCK_Stream stream;
  do{
  if(con.connect(stream, addr) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t:%l) %p\n",
                       "connection failed"),
                      0);
  }
  else
    ACE_DEBUG ((LM_DEBUG,
                "(%P|%t:%l) connected to %s at port %d\n",
                addr.get_host_name (),
                addr.get_port_number ()));
  ACE_CString hb = ACE_CString("^^hb->");
  hb+=id+"$$";
  ACE_DEBUG((LM_INFO,
	     "%l: %s\n", hb.c_str()));
  
  stream.send(hb.c_str(),hb.length());
  stream.close_writer();
  ACE_DEBUG((LM_INFO,
	     "%l\n"));
  
  char* buf = new char[128];
  ACE_CString str;
  do{
    int bytes = stream.recv(buf,128);
    if(bytes == -1 || bytes == 0){
      break;
    }
    for(int i=0; i< bytes; i++){
      str += buf[i];
    }
  }while(true);
  delete[] buf;
  stream.close();

  ACE_CString acks = ACE_CString("^^");
  int p1=2;
  int p2= str.find("->",p1);
  int p3 = str.find("->",p2);
  int p4 = str.find("||",p3);
  node *head=NULL, *tail=NULL;
  while(p1 != -1 && p2 != -1 && p3 != -1){
    ACE_CString* pqr = new ACE_CString(str.substr(p1, p2 - p1));
    ACE_CString* v2 = new ACE_CString(str.substr(p2, p3 - p2));
    ACE_CString txn_id = str.substr(p3, p4 - p3);
    acks+="ack->"+txn_id+"||";
    node* n = new node(pqr, v2);
    if(head == NULL){
      head = n;
      tail = n;
    }else{
      tail->next = n;
      tail = n;
    }
  }
  acks+="$$";
  //  delete str;
  
  if(con.connect(stream, addr) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t:%l) %p\n",
                       "connection failed"),
                      0);
  }
  else
    ACE_DEBUG ((LM_DEBUG,
                "(%P|%t:%l) connected to %s at port %d\n",
                addr.get_host_name (),
                addr.get_port_number ()));
  //send out the acks
  ACE_DEBUG((LM_INFO,
	     "(%P|%t:%l) %s\n",acks.c_str()));
  stream.send(acks.c_str(),acks.length());
  stream.close();
  node* tmp=head;
  //    ACE_SOCK_Connector connector;
  ACE_INET_Addr _9907addr(9907,"localhost");
  //ACE_SOCK_Stream stream;
  if(con.connect(stream, _9907addr) == -1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "(%P|%t:%l) %p\n",
		      "connection failed"),0);
  }else
    ACE_DEBUG ((LM_DEBUG,
		"(%P|%t) connected to %s at port %d\n",
		_9907addr.get_host_name (),
		_9907addr.get_port_number ()));

  ACE_CString reply = ACE_CString("^^");
  while(tmp!=NULL){
    bn* pqr = from_hex(tmp->pqr);
    bn* v2 = from_hex(tmp->v2);
    bn* prv = from_hex(&pr);
    bn* res = npmod(v2,prv,pqr);
    ACE_CString* resStr = res->to_hex();
    /*send the output to localhost:9907*/
    reply += tmp->pqr->c_str();
    reply += "->" + *resStr + "||";
    ACE_DEBUG((LM_DEBUG,
	       "(%P|%t) %s\n",reply.c_str()));
    delete pqr;
    delete v2;
    delete prv;
    delete res;
    delete resStr;
    tmp = tmp->next;
  }
  reply += "$$";
  stream.send(reply.c_str(),reply.length());
  stream.close();
  reclaim_node(head);
  /*sleep for 1 second, for the next poll;*/
  ACE_OS::sleep(1000);
  }while(true);
  //  delete str;
}
Beispiel #30
0
/*the accept function*/
static ACE_THR_FUNC_RETURN accept_step1(void *arg)
{
  /*ACE_INET_Addr addr;*/
  ACE_SOCK_Stream stream;
  ACE_HANDLE handle = (ACE_HANDLE)(intptr_t) arg;
  stream.set_handle(handle);
  if(stream.disable(ACE_NONBLOCK) == -1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "%p\n","get_remote_addr"),0);
  }
  /*
  ACE_DEBUG ((LM_INFO,
              "(%P|%t) client %s connected from %d\n",
              addr.get_host_name (),
              addr.get_port_number ()));
  */
  char* buf = new char[128];
  ACE_CString* str = new ACE_CString();
  do{
    int bytes= stream.recv(buf,128);
    ACE_DEBUG((LM_INFO,
	       "(%P|%t:%l) bytes = %d\n",bytes));
    if(bytes == -1|| bytes == 0){
      break;
    }
    for(int i=0 ;i < bytes; i++){
      *str += buf[i];
    }
  }while(true);
  delete[] buf;
  
  //the input format is '^^pqr->v1$$';
  int pos = str->find("->");
  int tail = str->find("$$");
  ACE_CString* pqr = new ACE_CString(str->substr(2,pos-2));
  ACE_CString* pv1 = new ACE_CString(str->substr(pos+2, tail - pos - 2));
  ACE_DEBUG((LM_INFO,
	     "(%P|%t:%l) pqr: %s\n pv1:%s\n",pqr->c_str(),pv1->c_str()));
	     
  bn* _pqr = from_hex(pqr);
  bn* _v1 = from_hex(pv1);
  bn* _pr = from_hex(&pr);
  bn* _r = npmod( _v1, _pr, _pqr);

  ACE_CString* result = _r->to_hex();
  ACE_DEBUG((LM_INFO,
	     "(%P|%t:%l)pqr:%s step1:%s ", pqr->c_str(), result->c_str()));
  ACE_CString reply = ACE_CString("ack");
  stream.send(reply.c_str() , reply.length());
  stream.close();
  /*send the step1 result to hub:10007
  */
  ACE_SOCK_Connector connector;
  ACE_INET_Addr hub_addr(port,hub.c_str());
  ACE_DEBUG((LM_DEBUG,
	     "(%P|%t:%l) port:%d host:%s\n", port, hub.c_str()));
  if(connector.connect(stream, hub_addr) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t) %p\n",
                       "connection failed"),
                      0);
  }
  else
    ACE_DEBUG ((LM_DEBUG,
                "(%P|%t) connected to %s at port %d\n",
                hub_addr.get_host_name (),
                hub_addr.get_port_number ()));

  /*
   * message layout:
^^pqr->digest->senderid$$
  */
  
  ACE_CString input = ACE_CString("^^");
  input += *pqr;
  input += "->";
  input += *result;
  input += "->";
  input += id ;
  input += "$$";
  ACE_DEBUG((LM_INFO,
	     "(%P|%t:%l) input of step1:%s\n", input.c_str()));
  
  if(stream.send(input.c_str(),input.length()) != input.length()){
    ACE_ERROR((LM_ERROR,
	       "%p\n","send"));
  }
  stream.close();
  delete str;
  delete pqr;
  delete pv1;
  delete _pqr;
  delete _v1;
  delete _pr;
  delete _r;
  delete result;
  return 0;
}