int OpenDDS::DCPS::ThreadPerConnectionSendTask::add_request(SendStrategyOpType op,
                                                        TransportQueueElement* element)
{
  DBG_ENTRY("ThreadPerConnectionSendTask","add");

  ACE_Auto_Ptr<SendRequest> req (new SendRequest);
  req->op_ = op;
  req->element_ = element;

  int result = -1;
  { // guard scope
    GuardType guard(this->lock_);

    if (this->shutdown_initiated_)
      return -1;

    result = this->queue_.put (req.get());
    if (result == 0)
      {
  this->work_available_.signal();
  req.release ();
      }
    else
      ACE_ERROR((LM_ERROR, "(%P|%t)ERROR: ThreadPerConnectionSendTask::add %p\n", "put"));
  }

  return result;
}
Esempio n. 2
0
TAO::PG_Group_List_Store::PG_Group_List_Store (
  Storable_Factory & storable_factory)
  : next_group_id_ (0)
  , storable_factory_ (storable_factory)
  , loaded_from_stream_ (false)
  , last_changed_ (0)
  , stale_ (false)
{
  // Create a temporary stream simply to check if a readable
  // version already exists.
  bool stream_exists = false;
  {
    ACE_Auto_Ptr<TAO::Storable_Base> stream (
      this->create_stream ("r"));

    if (stream->exists ())
      stream_exists = true;
  }

  if (stream_exists)
    {
      File_Guard fg(*this, SFG::CREATE_WITH_FILE);
    }
  else
    {
      File_Guard fg(*this, SFG::CREATE_WITHOUT_FILE);
      this->write (fg.peer ());
    }
}
Esempio n. 3
0
::Test::arr_bds_str_slice *
A_i::arr_method_s (::Test::A::FailOn where,
                   const ::Test::arr_bds_str,
                   ::Test::arr_bds_str_out arg2,
                   ::Test::arr_bds_str arg3)
{
  arg2 = ::Test::arr_bds_str_alloc ();

  ::Test::arr_bds_str_slice *res =
    ::Test::arr_bds_str_alloc ();
  ACE_Auto_Ptr< ::Test::arr_bds_str_slice > safe (res);

  switch (where)
    {
    case ::Test::A::ARG1:
      // must be never reached.
      break;
    case ::Test::A::ARG2:
      {
        ::Test::arr_bds_str_slice *& arg2_slice = arg2;
        arg2_slice[0] = CORBA::string_dup (::Test::FailStr);
      }
      break;
    case ::Test::A::ARG3:
      arg3[0] = CORBA::string_dup (::Test::FailStr);
      break;
    case ::Test::A::RETN:
      res[0] = CORBA::string_dup (::Test::FailStr);
      break;
    }

  safe.release ();
  return res;
}
Esempio n. 4
0
Savable::Savable (TAO::Storable_Factory & storable_factory)
  : storable_factory_(storable_factory)
  , loaded_from_stream_ (false)
{

  for (int index = 0; index < 2; ++index)
    {
      this->i_[index] = 0;
      this->ui_[index] = 0;
      this->bytes_size_[index] = 0;
      this->bytes_[index] = new char [this->bytes_size_max];
      for (int i = 0; i < this->bytes_size_max; ++i)
        {
          this->bytes_[index][i] = ACE_CHAR_MAX;
        }
    }

  ACE_Auto_Ptr<TAO::Storable_Base>
    stream (storable_factory_.create_stream("test.dat", "r"));
  if (stream->exists ())
    {
      Savable_File_Guard fg(*this, SFG::CREATE_WITH_FILE);
    }
  else
    {
      Savable_File_Guard fg(*this, SFG::CREATE_WITHOUT_FILE);
      this->write (fg.peer ());
    }
}
Esempio n. 5
0
bool
TAO::PG_Group_List_Store::list_obsolete ()
{
  // TODO: Upate if obsolete flag is set based on CORBA call.
  ACE_Auto_Ptr<TAO::Storable_Base> stream (this->create_stream ("r"));
  if (!stream->exists ())
    throw CORBA::INTERNAL ();
  if (stream->open () != 0)
    throw CORBA::INTERNAL ();
  return this->is_obsolete (stream->last_changed ());
}
TAO::PG_Object_Group_Storable::~PG_Object_Group_Storable (void)
{
  if (destroyed_)
    {
      ACE_Auto_Ptr<TAO::Storable_Base> stream (
        this->create_stream ("r"));

      if (stream->exists ())
        {
          stream->remove ();
        }

    }

}
Esempio n. 7
0
int
HTTP_Server::init (int argc, ACE_TCHAR *argv[])
  // Document this function
{
  // Ignore signals generated when a connection is broken unexpectedly.
  ACE_Sig_Action sig ((ACE_SignalHandler) SIG_IGN, SIGPIPE);
  ACE_UNUSED_ARG (sig);

  // Parse arguments which sets the initial state.
  this->parse_args (argc, argv);

  //If the IO strategy is synchronous (SYNCH case), then choose a handler
  //factory based on the desired caching scheme
  HTTP_Handler_Factory *f = 0;

  if (this->strategy_ != (JAWS::JAWS_POOL | JAWS::JAWS_ASYNCH))
    {
      if (this->caching_)
        {
          ACE_NEW_RETURN (f, Synch_HTTP_Handler_Factory (), -1);
        }
      else
        {
          ACE_NEW_RETURN (f, No_Cache_Synch_HTTP_Handler_Factory (), -1);
        }
    }

  //NOTE: At this point f better not be a NULL pointer,
  //so please do not change the ACE_NEW_RETURN macros unless
  //you know what you are doing
  ACE_Auto_Ptr<HTTP_Handler_Factory> factory (f);

  // Choose what concurrency strategy to run.
  switch (this->strategy_)
    {
    case (JAWS::JAWS_POOL | JAWS::JAWS_ASYNCH) :
      return this->asynch_thread_pool ();

    case (JAWS::JAWS_PER_REQUEST | JAWS::JAWS_SYNCH) :
      return this->thread_per_request (*factory.get ());

    case (JAWS::JAWS_POOL | JAWS::JAWS_SYNCH) :
    default:
      return this->synch_thread_pool (*factory.get ());
    }

  ACE_NOTREACHED (return 0);
}
TAO::PG_Object_Group_Storable::PG_Object_Group_Storable (
  CORBA::ORB_ptr orb,
  PortableGroup::FactoryRegistry_ptr factory_registry,
  TAO::PG_Object_Group_Manipulator & manipulator,
  CORBA::Object_ptr empty_group,
  const PortableGroup::TagGroupTaggedComponent & tagged_component,
  const char * type_id,
  const PortableGroup::Criteria & the_criteria,
  const TAO::PG_Property_Set_var & type_properties,
  TAO::Storable_Factory & storable_factory)
  : PG_Object_Group(orb,
                    factory_registry,
                    manipulator,
                    empty_group,
                    tagged_component,
                    type_id,
                    the_criteria,
                    type_properties)
  , group_previously_stored_(false)
  , group_id_previously_stored_(0)
  , storable_factory_ (storable_factory)
  , last_changed_ (0)
  , loaded_from_stream_ (false)
  , destroyed_ (false)
  , write_occurred_ (false)
{
  // Create a temporary stream simply to check if a readable
  // version already exists.
  bool stream_exists = false;
  {
    ACE_Auto_Ptr<TAO::Storable_Base> stream (
      this->create_stream ("r"));

    if (stream->exists ())
      stream_exists = true;
  }

  if (stream_exists)
    {
      Object_Group_File_Guard fg (*this, SFG::CREATE_WITH_FILE);
    }
  else
    {
      Object_Group_File_Guard fg (*this, SFG::CREATE_WITHOUT_FILE);
      this->write (fg.peer ());
    }
}
Esempio n. 9
0
    bool
    STD_PC_Intf::prepare_PC (const char *file)
    {
      DANCE_TRACE("STD_PC_Intf::prepare_PC");

      ACE_Auto_Ptr<XML_Helper> helper (new XML_Helper);

      if (!helper->is_initialized ())
        return false;

      // parse the .pcd (PackageConfigurationDescription) file
      xercesc::DOMDocument *dom =
        helper->create_dom (file);

      if (!dom)
        return false;


      PackageConfiguration pc =
        packageConfiguration (dom);


      Deployment::PackageConfiguration idl_pc;


      STD_PCD_Handler pcd_handler (helper.get ());

      pcd_handler.package_config (pc,
                                  idl_pc);


      Deployment::PackageConfiguration *p_idl_pc =
        new Deployment::PackageConfiguration (idl_pc);

      // let ACE_Auto_Ptr take over
      this->idl_pc_.reset (p_idl_pc);

      if (this->idl_pc_.get ())
        return true;

      return false;
    }
Esempio n. 10
0
void
TAO_Leader_Follower::resume_events ()
{
  // not need to obtain the lock, only called when holding the lock
  while (!this->deferred_event_set_.is_empty ())
    {
      ACE_Auto_Ptr<Deferred_Event> event (this->deferred_event_set_.pop_front ());
      // Send a notification to the reactor to cause the awakening of a new
      // follower, if there is one already available.
      ACE_Reactor *reactor = this->orb_core_->reactor ();
      int const retval = reactor->notify (event->handler (), ACE_Event_Handler::READ_MASK);
      if (TAO_debug_level > 2)
        {
          // @@todo: need to think about what is the action that
          // we can take when we get here with an error?!
          TAOLIB_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - TAO_Leader_Follower::resume_events, ")
                      ACE_TEXT ("an event handler[%d] has been resumed, ")
                      ACE_TEXT ("notified the reactor, retval=%d.\n"),
                      event->handler ()->get_handle (), retval));
        }
    }
}
Esempio n. 11
0
TAO::PG_Object_Group_Storable::PG_Object_Group_Storable (
  PortableGroup::ObjectGroupId group_id,
  CORBA::ORB_ptr orb,
  PortableGroup::FactoryRegistry_ptr factory_registry,
  TAO::PG_Object_Group_Manipulator & manipulator,
  TAO::Storable_Factory & storable_factory)
  : PG_Object_Group(orb,
                    factory_registry,
                    manipulator)
  , group_previously_stored_(true)
  , group_id_previously_stored_(group_id)
  , storable_factory_ (storable_factory)
  , last_changed_ (0)
  , loaded_from_stream_ (false)
  , destroyed_ (false)
  , write_occurred_ (false)
{
  // Create a temporary stream to simply to check if a readable
  // version already exists.
  bool stream_exists = false;
  {
    ACE_Auto_Ptr<TAO::Storable_Base> stream (
      this->create_stream ("r"));

    if (stream->exists ())
      stream_exists = true;
  }

  if (stream_exists)
    {
      Object_Group_File_Guard fg (*this, SFG::ACCESSOR);
    }
  else
    {
      throw CORBA::INTERNAL ();
    }
}
Esempio n. 12
0
int
ACE_Service_Gestalt::initialize (const ACE_Service_Type_Factory *stf,
                                 const ACE_TCHAR *parameters)
{
  ACE_TRACE ("ACE_Service_Gestalt::initialize");

#ifndef ACE_NLOGGING
  if (ACE::debug ())
    ACELIB_DEBUG ((LM_DEBUG,
                ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@, name=%s")
                ACE_TEXT (" - looking up in the repo\n"),
                this->repo_,
                stf->name ()));
#endif

  ACE_Service_Type *srp = 0;
  int const retv = this->repo_->find (stf->name (),
                                      (const ACE_Service_Type **) &srp);

  // If there is an active service already, remove it first
  // before it can be re-installed.
  if (retv >= 0)
    {
#ifndef ACE_NLOGGING
      if (ACE::debug ())
        ACELIB_DEBUG ((LM_WARNING,
                    ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@,")
                    ACE_TEXT (" name=%s - removing a pre-existing namesake.\n"),
                    this->repo_,
                    stf->name ()));
#endif
      this->repo_->remove (stf->name ());
    }

  // If there is an inactive service by that name it may have been
  // either inactivated, or just a forward declaration for a service,
  // that is in the process of being initialized. If it is the latter,
  // then we have detected an attempt to initialize the same dynamic
  // service while still processing previous attempt. This can lock up
  // the process, because the ACE_DLL_Manager::open () is not
  // re-entrant - it uses a Singleton lock to serialize concurent
  // invocations. This use case must be handled here, because if the
  // DLL_Manager was re-entrant we would have entered an infinite
  // recursion here.
  if (retv == -2 && srp->type () == 0)
    ACELIB_ERROR_RETURN ((LM_WARNING,
                       ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@,")
                       ACE_TEXT (" name=%s - forward-declared; ")
                       ACE_TEXT (" recursive initialization requests are")
                       ACE_TEXT (" ignored.\n"),
                       this->repo_,
                       stf->name ()),
                      -1);

  // Reserve a spot for the dynamic service by inserting an incomplete
  // service declaration, i.e. one that can not produce a service
  // object if asked (a forward declaration).  This declaration
  // ensures maintaining the proper partial ordering of the services
  // with respect to their finalization. For example, dependent static
  // services must be registered *after* the dynamic service that
  // loads them, so that their finalization is complete *before*
  // finalizing the dynamic service.
  ACE_Service_Type_Dynamic_Guard dummy (*this->repo_,
                                        stf->name ());

  // make_service_type() is doing the dynamic loading and also runs
  // any static initializers
  ACE_Auto_Ptr<ACE_Service_Type> tmp (stf->make_service_type (this));

  if (tmp.get () != 0 &&
      this->initialize_i (tmp.get (), parameters) == 0)
    {
      // All good. Tthe ACE_Service_Type instance is now owned by the
      // repository and we should make sure it is not destroyed upon
      // exit from this method.
      tmp.release ();
      return 0;
    }

  return -1;
}
Esempio n. 13
0
int WorldSocket::ProcessIncoming(WorldPacket* new_pct)
{
    ACE_ASSERT (new_pct);

    // manage memory ;)
    ACE_Auto_Ptr<WorldPacket> aptr (new_pct);

    const ACE_UINT16 opcode = new_pct->GetOpcode();

    if (closing_)
        return -1;

    // Dump received packet.
    if (sPacketLog->CanLogPacket())
        sPacketLog->LogPacket(*new_pct, CLIENT_TO_SERVER);

    try
    {
        switch (opcode)
        {
            case CMSG_PING:
                return HandlePing (*new_pct);
            case CMSG_AUTH_SESSION:
                if (m_Session)
                {
                    sLog->outError("WorldSocket::ProcessIncoming: Player send CMSG_AUTH_SESSION again");
                    return -1;
                }

                sScriptMgr->OnPacketReceive(this, WorldPacket(*new_pct));

                return HandleAuthSession(*new_pct);

            case CMSG_KEEP_ALIVE:
                sLog->outStaticDebug ("CMSG_KEEP_ALIVE, size: " UI64FMTD, uint64(new_pct->size()));
                sScriptMgr->OnPacketReceive(this, WorldPacket(*new_pct));
                return 0;
            default:
            {
                ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);

                if (m_Session != NULL)
                {
                    // Our Idle timer will reset on any non PING opcodes.
                    // Catches people idling on the login screen and any lingering ingame connections.
                    m_Session->ResetTimeOutTime();

                    // OK, give the packet to WorldSession
                    aptr.release();
                    // WARNINIG here we call it with locks held.
                    // Its possible to cause deadlock if QueuePacket calls back
                    m_Session->QueuePacket (new_pct);
                    return 0;
                }
                else
                {
                    sLog->outError("WorldSocket::ProcessIncoming: Client not authed opcode = %u", uint32(opcode));
                    return -1;
                }
            }
        }
    }
    catch (ByteBufferException &)
    {
        sLog->outError("WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i. Disconnected client.",
                opcode, GetRemoteAddress().c_str(), m_Session?m_Session->GetAccountId():-1);
        if (sLog->IsOutDebug())
        {
            sLog->outDebug(LOG_FILTER_NETWORKIO, "Dumping error causing packet:");
            new_pct->hexlike();
        }

        return -1;
    }

    ACE_NOTREACHED (return 0);
}
Esempio n. 14
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      // Initialize the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
      CORBA::ORB_var s_orb;

      // Find the Naming Service.
      CORBA::Object_var obj = orb->resolve_initial_references ("NameService");
      CosNaming::NamingContextExt_var root_context =
        CosNaming::NamingContextExt::_narrow (obj.in ());

      obj = root_context->resolve_str ("CosEventService");

      // Downcast the object reference to an EventChannel reference.
      CosEventChannelAdmin::EventChannel_var ec =
        CosEventChannelAdmin::EventChannel::_narrow (obj.in ());
      if (CORBA::is_nil (ec.in ()))
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("Could not narrow the EventChannel.\n")));
          return 1;
        }
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Found the EventChannel.\n")));

      bool consumer = false;
      bool supplier = false;
      bool hang = false;
      for (int i=1; i < argc; ++i)
        {
          if (0 == ACE_OS::strcasecmp (argv[i], ACE_TEXT ("-consumer")))
            consumer = true;
          else if (0 == ACE_OS::strcasecmp (argv[i], ACE_TEXT ("-supplier")))
            supplier = true;
          else if (0 == ACE_OS::strcasecmp (argv[i], ACE_TEXT ("-hang")))
            hang = true;
        }

      TestEventConsumer_i servant (orb.in (), hang);

      if (consumer)
        {
          // Register it with the RootPOA.
          obj = orb->resolve_initial_references ("RootPOA");
          PortableServer::POA_var poa =
            PortableServer::POA::_narrow (obj.in ());
          PortableServer::ObjectId_var oid = poa->activate_object (&servant);
          CORBA::Object_var consumer_obj = poa->id_to_reference (oid.in ());
          CosEventComm::PushConsumer_var consumer =
            CosEventComm::PushConsumer::_narrow (consumer_obj.in ());

          // Get a ConsumerAdmin object from the EventChannel.
          CosEventChannelAdmin::ConsumerAdmin_var consumerAdmin =
            ec->for_consumers ();

          // Get a ProxyPushSupplier from the ConsumerAdmin.
          CosEventChannelAdmin::ProxyPushSupplier_var supplier =
            consumerAdmin->obtain_push_supplier ();

          // Connect to the ProxyPushSupplier, passing our PushConsumer object
          // reference to it.
          supplier->connect_push_consumer (consumer.in ());
          ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Consumer connected\n")));

          // Activate the POA via its POAManager.
          PortableServer::POAManager_var poa_manager = poa->the_POAManager ();
          poa_manager->activate ();
          servant.activate ();
        }

      ACE_Auto_Ptr<SupplierTask> pST;
      if (supplier)
        {
          // The supplier will use its own ORB.
          CORBA::String_var ec_str = orb->object_to_string (ec.in ());

          int no_args = 0;
          ACE_TCHAR **no_argv = 0;
          s_orb = CORBA::ORB_init (no_args, no_argv,
                                   "Supplier_pure_client_ORB");

          CORBA::Object_var s_ec_obj = s_orb->string_to_object (ec_str.in ());

          CosEventChannelAdmin::EventChannel_var s_ec =
            CosEventChannelAdmin::EventChannel::_narrow (s_ec_obj.in ());

          // Get a SupplierAdmin object from the EventChannel.
          CosEventChannelAdmin::SupplierAdmin_var supplierAdmin =
            s_ec->for_suppliers ();

          // Get a ProxyPushConsumer from the SupplierAdmin.
          CosEventChannelAdmin::ProxyPushConsumer_var consumer =
            supplierAdmin->obtain_push_consumer ();

          // Connect to the ProxyPushConsumer as a PushSupplier
          // (passing a nil PushSupplier object reference to it because
          // we don't care to be notified about disconnects).
          consumer->connect_push_supplier
            (CosEventComm::PushSupplier::_nil ());

          SupplierTask *tmp = 0;
          ACE_NEW_RETURN (tmp, SupplierTask (consumer.in (), s_orb.in ()), -1);
          pST.reset (tmp);
          pST->activate ();
        }

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Ready to receive events...\n")));

      // Enter the ORB event loop.
      orb->run ();

      ACE_Thread_Manager::instance ()->wait ();

      if (!CORBA::is_nil (s_orb.in ()))
        {
          s_orb->destroy ();
        }

      orb->destroy ();
      return 0;
    }
  catch (CORBA::Exception &ex)
    {
      ex._tao_print_exception (
        ACE_TEXT (
          "TimeoutTest: Caught CORBA::Exception:"));
    }

  return 1;
}
Esempio n. 15
0
int PoolSocket::ProcessIncoming (WorldPacket* new_pct)
{
    ACE_ASSERT (new_pct);

    // manage memory ;)
    ACE_Auto_Ptr<WorldPacket> aptr (new_pct);

    const ACE_UINT16 opcode = new_pct->GetOpcode();

    if (closing_)
        return -1;

    // Dump received packet.
    if (sPacketLog->CanLogPacket())
        sPacketLog->LogPacket(*new_pct, CLIENT_TO_SERVER);

    try
    {
        switch (opcode)
        {
            case CMSG_PING:
                return HandlePing (*new_pct);
            case LOGON_AUTH_MASTER:
                if (m_Session)
                {
                    sLog->outError ("PoolSocket::ProcessIncoming: Player send CMSG_AUTH_SESSION again");
                    return -1;
                }
                return HandleAuthSession (*new_pct);
            case CMSG_KEEP_ALIVE:
                sLog->outStaticDebug ("CMSG_KEEP_ALIVE, size: " UI64FMTD, uint64(new_pct->size()));
                return 0;
            default:
            {
                ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);

                if (m_Session != NULL)
                {
                    // OK, give the packet to WorldSession
                    aptr.release();
                    // WARNINIG here we call it with locks held.
                    // Its possible to cause deadlock if QueuePacket calls back
                    m_Session->QueueServerPacket (new_pct);
                    return 0;
                }
                else
                {
                    new_pct->Initialize(SMSG_AUTH_RESPONSE, 1);
                    *new_pct << uint8(AUTH_REJECT);
                    SendPacket(*new_pct);

                    sLog->outError ("PoolSocket::ProcessIncoming: Client not authed opcode = %u => rejected", uint32(opcode));
                    return -1;
                }
            }
        }
    }
    catch (ByteBufferException &)
    {
        sLog->outError("PoolSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i. Disconnected client.",
                opcode, GetRemoteAddress().c_str(), m_Session?m_Session->GetServerId():-1);
        if (sLog->IsOutDebug())
        {
            sLog->outDebug(LOG_FILTER_NETWORKIO, "Dumping error causing packet:");
            new_pct->hexlike();
        }

        return -1;
    }

    ACE_NOTREACHED (return 0);
}
Esempio n. 16
0
int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
{
    ACE_ASSERT (new_pct);

    // manage memory ;)
    ACE_Auto_Ptr<WorldPacket> aptr (new_pct);

    const ACE_UINT16 opcode = new_pct->GetOpcode ();

    if (opcode >= NUM_MSG_TYPES)
    {
        sLog.outError( "SESSION: received non-existed opcode 0x%.4X", opcode);
        return -1;
    }

    if (closing_)
        return -1;

    // Dump received packet.
    sLog.outWorldPacketDump(uint32(get_handle()), new_pct->GetOpcode(), LookupOpcodeName(new_pct->GetOpcode()), new_pct, true);

    try
    {
        switch(opcode)
        {
            case CMSG_PING:
                return HandlePing (*new_pct);
            case CMSG_AUTH_SESSION:
                if (m_Session)
                {
                    sLog.outError ("WorldSocket::ProcessIncoming: Player send CMSG_AUTH_SESSION again");
                    return -1;
                }

                return HandleAuthSession (*new_pct);
            case CMSG_KEEP_ALIVE:
                DEBUG_LOG ("CMSG_KEEP_ALIVE ,size: %d", new_pct->size ());

                return 0;
            default:
            {
                ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);

                if (m_Session != NULL)
                {
                    // OK ,give the packet to WorldSession
                    aptr.release ();
                    // WARNINIG here we call it with locks held.
                    // Its possible to cause deadlock if QueuePacket calls back
                    m_Session->QueuePacket (new_pct);
                    return 0;
                }
                else
                {
                    sLog.outError ("WorldSocket::ProcessIncoming: Client not authed opcode = %u", uint32(opcode));
                    return -1;
                }
            }
        }
    }
    catch (ByteBufferException &)
    {
        sLog.outError("WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i. Disconnected client.",
                opcode, GetRemoteAddress().c_str(), m_Session?m_Session->GetAccountId():-1);
        if(sLog.IsOutDebug())
        {
            sLog.outDebug("Dumping error-causing packet:");
            new_pct->hexlike();
        }

        return -1;
    }

    ACE_NOTREACHED (return 0);
}
Esempio n. 17
0
int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
{
    ACE_ASSERT (new_pct);

    // manage memory ;)
    ACE_Auto_Ptr<WorldPacket> aptr (new_pct);

    const ACE_UINT16 opcode = new_pct->GetOpcode ();

    if (closing_)
        return -1;

    // Dump received packet.
    if (sWorldLog.LogWorld ())
    {
        sWorldLog.Log ("CLIENT:\nSOCKET: %u\nLENGTH: %u\nOPCODE: %s (0x%.4X)\nDATA:\n",
                     (uint32) get_handle (),
                     new_pct->size (),
                     LookupOpcodeName (new_pct->GetOpcode ()),
                     new_pct->GetOpcode ());

        uint32 p = 0;
        while (p < new_pct->size ())
        {
            for (uint32 j = 0; j < 16 && p < new_pct->size (); j++)
                sWorldLog.Log ("%.2X ", (*new_pct)[p++]);
            sWorldLog.Log ("\n");
        }
        sWorldLog.Log ("\n\n");
    }

    // like one switch ;)
    if (opcode == CMSG_PING)
    {
        return HandlePing (*new_pct);
    }
    else if (opcode == CMSG_AUTH_SESSION)
    {
        if (m_Session)
        {
            sLog.outError ("WorldSocket::ProcessIncoming: Player send CMSG_AUTH_SESSION again");
            return -1;
        }

        return HandleAuthSession (*new_pct);
    }
    else if (opcode == CMSG_KEEP_ALIVE)
    {
        DEBUG_LOG ("CMSG_KEEP_ALIVE ,size: %d", new_pct->size ());

        return 0;
    }
    else
    {
        ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);

        if (m_Session != NULL)
        {
            // OK ,give the packet to WorldSession
            aptr.release ();
            // WARNINIG here we call it with locks held.
            // Its possible to cause deadlock if QueuePacket calls back
            m_Session->QueuePacket (new_pct);
            return 0;
        }
        else
        {
            sLog.outError ("WorldSocket::ProcessIncoming: Client not authed opcode = ", opcode);
            return -1;
        }
    }

    ACE_NOTREACHED (return 0);
}
Esempio n. 18
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  ACE_Auto_Ptr<std::ofstream> fout;
  std::ostream* sout = &std::cout;

  if (!parse_args (argc, argv))
    {
      return 1;
    }

  ACE::INet::URL_INetAuthBase::add_authenticator ("my_auth",
                                                  new My_Authenticator);

  std::cout << "Starting..." << std::endl;

  if (!url.empty ())
    {
      if (!outfile.empty ())
        {
          fout.reset (new std::ofstream (outfile.c_str (), std::ios_base::binary|std::ios_base::out));

          if (!*fout)
            {
              std::cerr << "Failed to open output file : " << outfile.c_str () << std::endl;
              return 1;
            }

          sout = fout.get ();
        }

      ACE::FTP::URL ftp_url;

      std::cout << "Parsing url [" << url.c_str () << "]" << std::endl;

      if (!ftp_url.parse (url))
        {
          std::cerr << "Failed parsing url [" << url << "]" << std::endl;
          std::cerr << "\tresult = " << ftp_url.to_string ().c_str ();
          return 1;
        }

      std::cout << "Opening url..." << std::endl;
      My_FTP_RequestHandler my_rh;
      if (do_active)  my_rh.use_active_mode ();
      ACE::INet::URLStream urlin = ftp_url.open (my_rh);
      if (urlin)
        {
          std::cout << "Saving to: ";
          if (!outfile.empty ())
            std::cout << '\'' << outfile.c_str () << '\'' << std::endl;
          else
            std::cout << "(stdout)" << std::endl;

          (*sout) << urlin->rdbuf ();
          sout->flush ();
        }
    }
  else
    {
      std::cerr << "ERROR: No URL specified!" << std::endl;
      usage ();
      return 1;
    }

  std::cout << "Done" << std::endl;

  return 0;
}
Esempio n. 19
0
int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
{
    ACE_ASSERT (new_pct);

    // manage memory ;)
    ACE_Auto_Ptr<WorldPacket> aptr (new_pct);

    const ACE_UINT16 opcode = new_pct->GetOpcode();

    if (closing_)
        return -1;

    // Dump received packet.
    if (sWorldLog.LogWorld())
    {
        sWorldLog.outTimestampLog ("CLIENT:\nSOCKET: %u\nLENGTH: %u\nOPCODE: %s (0x%.4X)\nDATA:\n",
                                   (uint32) get_handle(),
                                   new_pct->size(),
                                   LookupOpcodeName (new_pct->GetOpcode()),
                                   new_pct->GetOpcode());

        uint32 p = 0;
        while (p < new_pct->size())
        {
            for (uint32 j = 0; j < 16 && p < new_pct->size(); j++)
                sWorldLog.outLog ("%.2X ", (*new_pct)[p++]);

            sWorldLog.outLog ("\n");
        }
        sWorldLog.outLog ("\n");
    }

    try
    {
        switch(opcode)
        {
        case CMSG_PING:
            return HandlePing (*new_pct);
        case CMSG_AUTH_SESSION:
            if (m_Session)
            {
                sLog.outError ("WorldSocket::ProcessIncoming: Player send CMSG_AUTH_SESSION again");
                return -1;
            }

            return HandleAuthSession (*new_pct);
        case CMSG_KEEP_ALIVE:
            DEBUG_LOG ("CMSG_KEEP_ALIVE ,size: %d", new_pct->size());

            return 0;
        default:
        {
            ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);

            if (m_Session != NULL)
            {
                // Our Idle timer will reset on any non PING opcodes.
                // Catches people idling on the login screen and any lingering ingame connections.
                m_Session->ResetTimeOutTime();

                // OK ,give the packet to WorldSession
                aptr.release();
                // WARNINIG here we call it with locks held.
                // Its possible to cause deadlock if QueuePacket calls back
                m_Session->QueuePacket (new_pct);
                return 0;
            }
            else
            {
                sLog.outError ("WorldSocket::ProcessIncoming: Client not authed opcode = %u", uint32(opcode));
                return -1;
            }
        }
        }
    }
    catch(ByteBufferException &)
    {
        sLog.outError("WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i. Disconnected client.",
                      opcode, GetRemoteAddress().c_str(), m_Session?m_Session->GetAccountId():-1);
        if (sLog.IsOutDebug())
        {
            sLog.outDebug("Dumping error causing packet:");
            new_pct->hexlike();
        }

        return -1;
    }

    ACE_NOTREACHED (return 0);
}
Esempio n. 20
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  ACE_Auto_Ptr<std::ofstream> fout;
  std::ostream* sout = &std::cout;

  if (!parse_args (argc, argv))
    {
      return 1;
    }

#if defined (ACE_HAS_SSL) && ACE_HAS_SSL == 1
  ACE::HTTPS::Context::set_default_ssl_mode (ssl_mode);
  ACE::HTTPS::Context::set_default_verify_mode (verify_peer);
  ACE::HTTPS::Context::instance ().use_default_ca ();
  if (!private_key.empty ())
    {
      if (certificate.empty ())
        {
          std::cerr << "ERROR: private key file [" << private_key << "] requires certificate file to be specified." << std::endl;
          return 1;
        }
      if (!ACE::HTTPS::Context::instance ().set_key_files (private_key.c_str (), certificate.c_str ()))
        {
          std::cerr << "ERROR: failed to set private key [" << private_key << "]." << std::endl;
          return 1;
        }
    }
  if (!ca_location.empty ())
    {
      INET_DEBUG (6, (LM_INFO, DLINFO ACE_TEXT ("loading trusted CA [%C]\n"), ca_location.c_str ()));
      if (!ACE::HTTPS::Context::instance ().load_trusted_ca (ca_location.c_str ()))
        {
          std::cerr << "ERROR: failed to load trusted CA from [" << ca_location << "]." << std::endl;
          return 1;
        }
      INET_DEBUG (6, (LM_INFO, DLINFO ACE_TEXT ("loaded [%d] trusted CA\n"), ACE::HTTPS::Context::instance ().has_trusted_ca ()));
    }
  if (ignore_verify)
    ACE::INet::SSL_CallbackManager::instance ()->set_certificate_callback (new ACE::INet::SSL_CertificateAcceptor);
#endif

  std::cout << "Starting..." << std::endl;

  if (!url.empty ())
    {
      if (!outfile.empty ())
        {
          fout.reset (new std::ofstream (outfile.c_str (), std::ios_base::binary|std::ios_base::out));

          if (!*fout)
            {
              std::cerr << "Failed to open output file : " << outfile.c_str () << std::endl;
              return 1;
            }

          sout = fout.get ();
        }

      std::cout << "Parsing url [" << url.c_str () << "]" << std::endl;

      ACE_Auto_Ptr<ACE::INet::URL_Base> url_safe (ACE::INet::URL_Base::create_from_string (url));

      if (url_safe.get () == 0 || url != url_safe->to_string ())
        {
          std::cerr << "Failed parsing url [" << url << "]" << std::endl;
          std::cerr << "\tresult = " << (url_safe.get () == 0 ? "(null)" : url_safe->to_string ().c_str ()) << std::endl;
          return 1;
        }

      ACE::HTTP::URL& http_url = *dynamic_cast<ACE::HTTP::URL*> (url_safe.get ());

      if (!proxy_hostname.empty ())
        {
          std::cout << "Setting proxy: " << proxy_hostname.c_str () << ':' << proxy_port << std::endl;
          http_url.set_proxy (proxy_hostname, proxy_port);
        }

      std::cout << "Opening url...";
      My_HTTP_RequestHandler my_rh;
      ACE::INet::URLStream urlin = http_url.open (my_rh);
      if (urlin)
        {
          std::cout << "Received response "
                    << (int)my_rh.response ().get_status ().get_status ()
                    << " "
                    << my_rh.response ().get_status ().get_reason ().c_str ()
                    << std::endl;
          if (my_rh.response ().get_status ().is_ok ())
            {
              std::cout << "Length: ";
              if (my_rh.response ().get_content_length () != ACE::HTTP::Response::UNKNOWN_CONTENT_LENGTH)
                std::cout << my_rh.response ().get_content_length () << " [";
              else
                std::cout << "(unknown) [";
              if (my_rh.response ().get_content_type () != ACE::HTTP::Response::UNKNOWN_CONTENT_TYPE)
                std::cout << my_rh.response ().get_content_type ().c_str ();
              else
                std::cout << "(unknown)";
              std::cout  << "]" << std::endl;
            }

          std::cout << "Saving to: ";
          if (!outfile.empty ())
            std::cout << '\'' << outfile.c_str () << '\'' << std::endl;
          else
            std::cout << "(stdout)" << std::endl;

          (*sout) << urlin->rdbuf ();
          sout->flush ();
        }
    }
  else
    {
      std::cerr << "ERROR: No URL specified!" << std::endl;
      usage ();
      return 1;
    }

  std::cout << "Done" << std::endl;

  return 0;
}