示例#1
0
  void SIProfileFT::handleSIRequest( const JID& from, const std::string& id,
                                     const SIManager::SI& si )
  {
    if( si.profile() != XMLNS_SI_FT || !si.tag1() )
      return;

    if( m_handler )
    {
      long offset = 0;
      long length = -1;

      const Tag* t = si.tag1()->findChild( "desc" );
      const std::string& desc = t ? t->cdata() : EmptyString;

      if( ( t = si.tag1()->findChild( "range" ) ) )
      {
        if( t->hasAttribute( "offset" ) )
          offset = atol( t->findAttribute( "offset" ).c_str() );
        if( t->hasAttribute( "length" ) )
          length = atol( t->findAttribute( "length" ).c_str() );
      }

      const std::string& mt = si.mimetype();
      int types = 0;

      if( si.tag2() )
      {
        const DataForm df( si.tag2()->findChild( "x", XMLNS, XMLNS_X_DATA ) );
        const DataFormField* dff = df.field( "stream-method" );

        if( dff )
        {
          if( dff->value() == XMLNS_BYTESTREAMS )
            types |= FTTypeS5B;
          else if( dff->value() == XMLNS_IBB )
            types |= FTTypeIBB;
          else if( dff->value() == XMLNS_IQ_OOB )
            types |= FTTypeOOB;
        }
      }

      const std::string& sid = si.id();
      m_id2sid[sid] = id;
      m_handler->handleFTRequest( from, sid, si.tag1()->findAttribute( "name" ),
                                  atol( si.tag1()->findAttribute( "size" ).c_str() ),
                                        si.tag1()->findAttribute( "hash" ),
                                            si.tag1()->findAttribute( "date" ),
                                  mt.empty() ? "binary/octet-stream" : mt,
                                  desc, types, offset, length );
    }
  }
示例#2
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  DataForm *f;

  std::string title = "form test title";
  StringList instructions;
  instructions.push_back( "form test instructions" );
  instructions.push_back( "line 2" );
  instructions.push_back( "line 3" );
  // -------
  name = "form type, title, instructions";
  // using StringList instructions from previous test case
  // using std::string title from pre-previous test case
  f = new DataForm( TypeForm, instructions, title );
  if( f->instructions() != instructions )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  if( f->title() != title )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  if( f->type() != TypeForm )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;




  if( fail == 0 )
  {
    printf( "DataForm: OK\n" );
    return 0;
  }
  else
  {
    printf( "DataForm: %d test(s) failed\n", fail );
    return 1;
  }

}
示例#3
0
  void SIProfileFT::handleSIRequest( const JID& from, const JID& to, const std::string& id,
                                     const SIManager::SI& si )
  {
    if( si.profile() != XMLNS_SI_FT || !si.tag1() )
      return;

    if( m_handler )
    {
      const Tag* t = si.tag1()->findChild( "desc" );
      const std::string& desc = t ? t->cdata() : EmptyString;

      const std::string& mt = si.mimetype();
      int types = 0;

      if( si.tag2() )
      {
        const DataForm df( si.tag2()->findChild( "x", XMLNS, XMLNS_X_DATA ) );
        const DataFormField* dff = df.field( "stream-method" );

        if( dff )
        {
          const StringMultiMap& options = dff->options();
          StringMultiMap::const_iterator it = options.begin();
          for( ; it != options.end(); ++it )
          {
            if( (*it).second == XMLNS_BYTESTREAMS )
              types |= FTTypeS5B;
            else if( (*it).second == XMLNS_IBB )
              types |= FTTypeIBB;
            else if( (*it).second == XMLNS_IQ_OOB )
              types |= FTTypeOOB;
          }
        }
      }

      const std::string& sid = si.id();
      m_id2sid[sid] = id;
      m_handler->handleFTRequest( from, to, sid, si.tag1()->findAttribute( "name" ),
                                  atol( si.tag1()->findAttribute( "size" ).c_str() ),
                                        si.tag1()->findAttribute( "hash" ),
                                            si.tag1()->findAttribute( "date" ),
                                  mt.empty() ? "binary/octet-stream" : mt,
                                  desc, types );
    }
  }
 void Registration::createAccount( const DataForm& form )
 {
   const Tag *tmp = form.tag();
   if( tmp )
   {
     Tag *c = tmp->clone();
     m_parent->send( c );
   }
 }
示例#5
0
  void SIProfileFT::handleSIRequestResult( const JID& from, const JID& to, const std::string& sid,
                                           const SIManager::SI& si )
  {
    if( si.tag2() )
    {
      const DataForm df( si.tag2()->findChild( "x", XMLNS, XMLNS_X_DATA ) );
      const DataFormField* dff = df.field( "stream-method" );

      if( dff )
      {
        if( m_socks5Manager && dff->value() == XMLNS_BYTESTREAMS )
        {
          // check return value:
          m_socks5Manager->requestSOCKS5Bytestream( from, SOCKS5BytestreamManager::S5BTCP, sid, to );
        }
        else if( m_handler )
        {
          if( dff->value() == XMLNS_IBB )
          {
            InBandBytestream* ibb = new InBandBytestream( m_parent, m_parent->logInstance(),
                to ? to : m_parent->jid(), from, sid );

            m_handler->handleFTBytestream( ibb );
          }
          else if( dff->value() == XMLNS_IQ_OOB )
          {
            const std::string& url = m_handler->handleOOBRequestResult( from, to, sid );
            if( !url.empty() )
            {
              const std::string& id = m_parent->getID();
              IQ iq( IQ::Set, from, id );
              if( to )
                iq.setFrom( to );

              iq.addExtension( new OOB( url, EmptyString, true ) );
              m_parent->send( iq, this, OOBSent );
            }
          }
        }
      }
    }
  }
示例#6
0
// Authorize with OnSip PBX
// Pass unique contextId to be associated with this request,
// the Iq Result will have the same contextId
void OnSipXmppBase::Authorize(int contextId,IqHandler* iqHandler)
{
	Logger::log_debug("OnSipXmppBase::Authorize contextId %d iqh=%p",contextId, iqHandler );
	_checkThread.CheckSameThread();	// Verify we are single threaded for this object

	// Create DataForm
	DataForm* settings = new DataForm( gloox::TypeSubmit );
	// Add sip address field
	DataFormField* dff = new DataFormField( "sip-address", m_login.SIPAddress() );
	settings->addField(dff);
	// Add password field
	dff = new DataFormField( "password", m_login.m_password, EmptyString, DataFormField::TypeTextPrivate );
	settings->addField(dff);
	// Add command
	JID toJid( "commands.auth.xmpp.onsip.com" );
	IQ iq( IQ::Set, toJid, m_gloox->getID() );
	Adhoc::Command *cmd = new Adhoc::Command( "authorize-plain", EmptyString, Adhoc::Command::Executing, settings );
	iq.addExtension( cmd );

	Logger::log_debug("OnSipXmppBase::Authorize sending");
	_ASSERT( iqHandler != NULL );
	m_gloox->send( iq, iqHandler, contextId );
}
示例#7
0
文件: search.cpp 项目: soubok/libset
  void Search::search( const JID& directory, const DataForm& form, SearchHandler *sh )
  {
    if( !m_parent || !directory || !sh )
      return;

    const std::string& id = m_parent->getID();

    Tag *iq = new Tag( "iq" );
    iq->addAttribute( "id", id );
    iq->addAttribute( "type", "set" );
    iq->addAttribute( "to", directory.full() );
    Tag *q = new Tag( iq, "query" );
    q->addAttribute( "xmlns", XMLNS_SEARCH );
    q->addChild( form.tag() );

    m_track[id] = sh;
    m_parent->trackID( this, id, DoSearch );
    m_parent->send( iq );
  }
示例#8
0
文件: adhoc.cpp 项目: soubok/libset
  bool Adhoc::handleIqID( Stanza * stanza, int context )
  {
    if( context != ExecuteAdhocCommand || stanza->subtype() != StanzaIqResult )
      return false;

    AdhocTrackMap::iterator it = m_adhocTrackMap.begin();
    for( ; it != m_adhocTrackMap.end(); ++it )
    {
      if( (*it).second.context == context && (*it).second.remote == stanza->from() )
      {
        Tag *c = stanza->findChild( "command", "xmlns", XMLNS_ADHOC_COMMANDS );
        if( c )
        {
          const std::string& command = c->findAttribute( "node" );
          const std::string& id = c->findAttribute( "sessionid" );
          Tag *a = c->findChild( "actions" );
          int actions = ActionCancel;
          Adhoc::AdhocExecuteActions def = ActionCancel;
          if( a )
          {
            if( a->hasChild( "prev" ) )
              actions |= ActionPrevious;
            if( a->hasChild( "next" ) )
              actions |= ActionNext;
            if( a->hasChild( "complete" ) )
              actions |= ActionComplete;
            const std::string& d = a->findAttribute( "execute" );
            if( d == "next" )
              def = ActionNext;
            else if( d == "prev" )
              def = ActionPrevious;
            else if( d == "complete" )
              def = ActionComplete;
          }
          Tag *n = c->findChild( "note" );
          std::string note;
          AdhocNoteType type = AdhocNoteInfo;
          if( n )
          {
            note = n->cdata();
            if( n->hasAttribute( "type", "warn" ) )
              type = AdhocNoteWarn;
            else if( n->hasAttribute( "type", "error" ) )
              type = AdhocNoteError;
          }
          const std::string& s = c->findAttribute( "status" );
          AdhocCommandStatus status = AdhocCommandStatusUnknown;
          if( s == "executing" )
            status = AdhocCommandExecuting;
          else if( s == "completed" )
            status = AdhocCommandCompleted;
          else if( s == "canceled" )
            status = AdhocCommandCanceled;
          DataForm form;
          Tag *x = c->findChild( "x", "xmlns", XMLNS_X_DATA );
          if( x )
            form.parse( x );

          (*it).second.ah->handleAdhocExecutionResult( stanza->from(), command, status, id, form,
                                                       actions, def, note, type );
        }

        m_adhocTrackMap.erase( it );
        return true;
      }
    }

    return false;
  }
int main()
{
  ClientBase* cb = new ClientBase();
  PubSub::Manager* psm = new PubSub::Manager( cb );
  RH* rh = new RH();

  cb->setTest( SubscriptionDefault );
  psm->subscribe( jid, node, rh );

  cb->setTest( SubscriptionJID );
  psm->subscribe( jid, node, rh, jid2 );

  cb->setTest( SubscriptionSubType );
  psm->subscribe( jid, node, rh, jid2, PubSub::SubscriptionItems );

  cb->setTest( SubscriptionDepth );
  psm->subscribe( jid, node, rh, jid2, PubSub::SubscriptionItems, 0 );

  cb->setTest( UnsubscriptionDefault );
  psm->unsubscribe( jid, node, subid, rh );

  cb->setTest( UnsubscriptionJID );
  psm->unsubscribe( jid, node, subid, rh, jid2 );

  cb->setTest( GetSubscriptionOptions );
  psm->getSubscriptionOptions( jid, jid2, node, rh );

  DataForm* df = new DataForm( TypeSubmit );
  df->addField( DataFormField::TypeHidden, "FORM_TYPE",
      "http://jabber.org/protocol/pubsub#subscribe_options" );
  cb->setTest( SetSubscriptionOptions );
  psm->setSubscriptionOptions( jid, jid2, node, df, rh );

  cb->setTest( GetSubscriptionList );
  psm->getSubscriptions( jid, rh );

  cb->setTest( GetSubscriberList );
  psm->getSubscribers( jid, node, rh );

  PubSub::SubscriberList sl;
  sl.push_back( PubSub::Subscriber( jid2, PubSub::SubscriptionNone, "abc" ) );
  cb->setTest( SetSubscriberList );
  psm->setSubscribers( jid, node, sl, rh );

  cb->setTest( GetAffiliationList );
  psm->getAffiliations( jid, rh );

  cb->setTest( GetAffiliateList );
  psm->getAffiliates( jid, node, rh );

  PubSub::AffiliateList al;
  al.push_back( PubSub::Affiliate( jid2, PubSub::AffiliationOwner ) );
  cb->setTest( SetAffiliateList );
  psm->setAffiliates( jid, node, al, rh );

  cb->setTest( GetNodeConfig );
  psm->getNodeConfig( jid, node, rh );

  df = new DataForm( TypeSubmit );
  df->addField( DataFormField::TypeHidden, "FORM_TYPE",
      "http://jabber.org/protocol/pubsub#node_config" );
  df->addField( DataFormField::TypeNone, "pubsub#title", "Princely Musings (Atom)" );
  cb->setTest( SetNodeConfig );
  psm->setNodeConfig( jid, node, df, rh );

  cb->setTest( DefaultNodeConfig );
  psm->getDefaultNodeConfig( jid, PubSub::NodeLeaf, rh );


  delete rh;
  delete psm;




  if( cb->failed )
    printf( "PubSub::Manager: %d test(s) failed\n", cb->failed );
  else
    printf( "PubSub::Manager: OK\n" );

  delete cb;

}
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  DataForm *f;

  // -------
  name = "empty form";
  f = new DataForm();
  if( f->type() != DataForm::FormTypeInvalid )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "empty form tag";
  f = new DataForm();
  if( f->tag() )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "form title";
  std::string title = "form test title";
  f = new DataForm();
  f->setTitle( title );
  if( f->title() != title )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "form instructions";
  StringList instructions;
  instructions.push_back( "form test instructions" );
  instructions.push_back( "line 2" );
  instructions.push_back( "line 3" );
  f = new DataForm();
  f->setInstructions( instructions );
  if( f->instructions() != instructions )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "form type, title, instructions";
  // using StringList instructions from previous test case
  // using std::string title from pre-previous test case
  f = new DataForm( DataForm::FormTypeForm, instructions, title );
  if( f->instructions() != instructions )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  if( f->title() != title )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  if( f->type() != DataForm::FormTypeForm )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "parse empty Tag (ctor)";
  Tag *t = new Tag();
  f = new DataForm( t );
  delete t;
  if( f->type() != DataForm::FormTypeInvalid )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "parse() empty Tag";
  f = new DataForm();
  t = new Tag();
  f->parse( t );
  delete t;
  if( f->type() != DataForm::FormTypeInvalid )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "parse 0";
  f = new DataForm();
  f->parse( 0 );
  if( f->type() != DataForm::FormTypeInvalid )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;





  if( fail == 0 )
  {
    printf( "DataForm: all tests passed\n" );
    return 0;
  }
  else
  {
    printf( "DataForm: %d test(s) failed\n", fail );
    return 1;
  }

}