コード例 #1
0
ファイル: XmppGSUpdate.cpp プロジェクト: asdfjkl697/projects
XmppGSUpdate::XmppGSUpdate( const Tag* tag )
	:StanzaExtension(ExtIotUpdate), m_state(defUPState_Unknown)
{
	if( !tag || tag->name() != "gsiot" || tag->xmlns() != XMLNS_GSIOT_UPDATE )
		return;

	Tag *tmgr = tag->findChild("update");

	if( tmgr )
	{
		if( tmgr->findChild("state") )
		{
			std::string strState = tmgr->findChild("state")->cdata();
			g_toLowerCase( strState );
			if( strState == "check" )
			{
				m_state = defUPState_check;
			}
			else if( strState == "update" )
			{
				m_state = defUPState_update;
			}
			else if( strState == "forceupdate" )
			{
				m_state = defUPState_forceupdate;
			}
		}
	}
}
コード例 #2
0
ファイル: GSIOTInfo.cpp プロジェクト: asdfjkl697/package
GSIOTInfo::GSIOTInfo( const Tag* tag )
	:StanzaExtension( ExtIot ), m_isInputDevice(false)
{
	if( !tag || tag->name() != "gsiot" || tag->xmlns() != XMLNS_GSIOT )
       return;

	Tag *d = tag->findChild("device");
	if(d)
	{
		Tag *ttypelist = d->findChild("typelist");
		if( ttypelist )
		{
			const TagList& l = ttypelist->children();
			TagList::const_iterator it = l.begin();
			for( ; it != l.end(); ++it )
			{
				if((*it)->name() != "type")
					continue;

				m_getForType.insert( (IOTDeviceType)atoi( (*it)->cdata().c_str() ) );
			}
		}
	}

	//const TagList& l = tag->children();
	//TagList::const_iterator it = l.begin();
	//for( ; it != l.end(); ++it )
	//{
	//	if((*it)->name() == "device"){
	//		this->m_deviceList.push_back(new GSIOTDevice(*it));
	//	}
	//}
}
コード例 #3
0
  void ClientBase::send( IQ& iq, IqHandler* ih, int ctx )
  {
    const PrivateXML::Query* q = iq.findExtension<PrivateXML::Query>( ExtPrivateXML );
    if( !q )
      return;

    Tag* tag = q->tag();
    switch( m_test )
    {
      case 1:
      {
        if( iq.subtype() == IQ::Set
            && tag && *(tag->findChild( "foo", "xmlns", "test" )) == *t1 )
        {
          IQ re( IQ::Result, iq.from(), iq.id() );
          re.addExtension( new PrivateXML::Query() );
          ih->handleIqID( re, ctx );
        }
        break;
      }
      case 2:
      {
        if( iq.subtype() == IQ::Get
            && tag && tag->hasChild( "foo", "xmlns", "test" ) )
        {
          IQ re( IQ::Result, iq.from(), iq.id() );
          re.addExtension( new PrivateXML::Query( t1->clone() ) );
          ih->handleIqID( re, ctx );
        }
        break;
      }
    }
    delete tag;
  }
コード例 #4
0
ファイル: simanager_test.cpp プロジェクト: junction/jn-tapi
 void ClientBase::send( IQ& iq, IqHandler*, int )
 {
   Tag* tag = iq.tag();
   switch( m_test )
   {
     case 1:
     {
       Tag* si = tag->findChild( "si", "xmlns", XMLNS_SI );
       if( tag->findAttribute( "to" ) == to.full() && si && *(si->findChild( "file" )) == *t1
           && *(si->findChild( "feature" )) == *t2 && si->findAttribute( "mime-type" ) == "binary/octet-stream"
           && si->findAttribute( "profile" ) == g_profile )
         m_ok = true;
       break;
     }
   }
   delete tag;
 }
コード例 #5
0
ファイル: adhoctag.cpp プロジェクト: bochi/spectrum-gw
const std::string AdhocTag::getValue(const std::string &var) {
    if (xdata == NULL)
        return "";
    Tag *v = xdata->findChildWithAttrib("var", var);
    if (!v)
        return "";
    Tag *value =v->findChild("value");
    if (!value)
        return "";
    return value->cdata();
}
コード例 #6
0
 virtual void handleMessage( const Message& msg, MessageSession * /*session*/ )
 {
     Tag* m = msg.tag();
     Tag *x = m->findChild( "xtls", "xmlns", "test:xtls" );
     if( x )
     {
         printf( "decrypting: %d\n", x->cdata().length() );
         m_tls->decrypt( Base64::decode64( x->cdata() ) );
         xtlsSend();
     }
     delete m;
 }
コード例 #7
0
ファイル: adhoctag.cpp プロジェクト: bochi/spectrum-gw
AdhocTag::AdhocTag(const IQ &stanza) : Tag("command") {
    m_from = stanza.from().full();
    m_id = stanza.id();
    xdata = NULL;
    Tag *iq = stanza.tag();
    Tag *command = iq->findChild("command");
    if (command) {
        const Tag::AttributeList & attributes = command->attributes();
        for (Tag::AttributeList::const_iterator it = attributes.begin(); it != attributes.end(); it++) {
            addAttribute(std::string((*it)->name()), std::string((*it)->value()));
        }
        Tag *x = command->findChildWithAttrib("xmlns","jabber:x:data");
        if (x) {
            xdata = x->clone();
            addChild(xdata);
        }
    }
    delete iq;
}
コード例 #8
0
ファイル: client.cpp プロジェクト: wuyingfengsui/V6Chat
  void Client::processResourceBind( Stanza *stanza )
  {
    switch( stanza->subtype() )
    {
      case StanzaIqResult:
      {
        Tag *bind = stanza->findChild( "bind" );
        Tag *jid = bind->findChild( "jid" );
        m_jid.setJID( jid->cdata() );
        m_resourceBound = true;

        if( m_streamFeatures & StreamFeatureSession )
          createSession();
        else
          connected();
        break;
      }
      case StanzaIqError:
      {
        Tag *error = stanza->findChild( "error" );
        if( stanza->hasChild( "error", "type", "modify" )
            && error->hasChild( "bad-request", "xmlns", XMLNS_XMPP_STANZAS ) )
        {
          notifyOnResourceBindError( RbErrorBadRequest );
        }
        else if( stanza->hasChild( "error", "type", "cancel" ) )
        {
          if( error->hasChild( "not-allowed", "xmlns", XMLNS_XMPP_STANZAS ) )
            notifyOnResourceBindError( RbErrorNotAllowed );
          else if( error->hasChild( "conflict", "xmlns", XMLNS_XMPP_STANZAS ) )
            notifyOnResourceBindError( RbErrorConflict );
          else
            notifyOnResourceBindError( RbErrorUnknownError );
        }
        else
          notifyOnResourceBindError( RbErrorUnknownError );
        break;
      }
      default:
        break;
    }
  }
コード例 #9
0
ファイル: vcardupdate_test.cpp プロジェクト: soubok/libset
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;
  VCardUpdate *d;
  Tag *x = new Tag( "x" );
  x->addAttribute( "xmlns", XMLNS_X_VCARD_UPDATE );
  new Tag( x, "photo", "invalidhash" );

  // -------
  name = "parsing 0 tag";
  d = new VCardUpdate( 0 );
  if( d->tag() != 0 )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "filled object/getters";
  d = new VCardUpdate( "invalidhash" );
  if( d->hash() != "invalidhash" )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "filled object/tag()";
  d = new VCardUpdate( "invalidhash" );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_X_VCARD_UPDATE )
       || !t->hasChild( "photo" ) || t->findChild( "photo" )->cdata() != "invalidhash" )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;

  // -------
  name = "from Tag/getters";
  d = new VCardUpdate( x );
  if( d->hash() != "invalidhash" )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "from Tag/tag()";
  d = new VCardUpdate( x );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_X_VCARD_UPDATE )
       || !t->hasChild( "photo" ) || t->findChild( "photo" )->cdata() != "invalidhash" )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;




  delete x;
  x = 0;


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

}
コード例 #10
0
ファイル: XmppGSPlayback.cpp プロジェクト: asdfjkl697/package
XmppGSPlayback::XmppGSPlayback( const Tag* tag )
	:StanzaExtension(ExtIotPlayback), m_camera_id(0), m_startdt(0), m_enddt(0), m_state(defPBState_Unknown), m_sound(-1)
{
	if( !tag || tag->name() != "gsiot" || tag->xmlns() != XMLNS_GSIOT_PLAYBACK )
		return;

	Tag *tmgr = tag->findChild("playback");

	if( tmgr )
	{
		Tag *tcamera = tmgr->findChild("device");
		if( tcamera )
		{
			if( tcamera->hasAttribute("id") )
			{
				m_camera_id = atoi( tcamera->findAttribute("id").c_str() );
			}
		}

		if( tmgr->findChild("startdate") )
		{
			m_startdt = atoi( tmgr->findChild("startdate")->cdata().c_str() );
		}

		if( tmgr->findChild("enddate") )
		{
			m_enddt = atoi( tmgr->findChild("enddate")->cdata().c_str() );
		}

		if( tmgr->findChild("url") )
		{
			m_url = tmgr->findChild("url")->cdata();
		}

		//#ifdef _DEBUG
#if 0
		std::string useUrl_lastback;
		if( IsRUNCODEEnable( defCodeIndex_TEST_Debug_TempCode ) )
		{
			if( !g_IsRTMFP_url( m_url ) ) useUrl_lastback = m_url;

			//m_url = "rtmfp://192.168.0.76:1985/p2p";
			m_url = "rtmfp://p2p.gsss.cn:1985/p2p";
			//m_url = "rtmfp://unknownp2p.gsss.cn:1985/p2p";

			GUID guid;
			::CoCreateGuid( &guid );
			m_url += "/";
			m_url += g_BufferToString( (unsigned char*)&guid, sizeof( guid ), false, false );
		}
#endif

		if( IsRUNCODEEnable( defCodeIndex_RTMFP_DelFromUrlStreamID ) && g_IsRTMFP_url( m_url ) )
		{
			std::vector<std::string> useUrl_unit_vec;
			split( m_url, useUrl_unit_vec, "/" );

			const int unitsize = useUrl_unit_vec.size();
			// 偶数个表示最后一个为streamid,去掉
			if( 0 == (unitsize%2) )
			{
				g_replace_all_distinct( m_url, std::string( "/" )+useUrl_unit_vec[unitsize-1], "" );
			}
		}

		Tag *tchildlist_url_backup = tmgr->findChild("url_backup");
		if( tchildlist_url_backup )
		{
			const TagList& l = tchildlist_url_backup->children();
			TagList::const_iterator it = l.begin();
			for( ; it != l.end(); ++it )
			{
				Tag *tChild = (*it);
				if( tChild->name() == "url" )
				{
					m_url_backup.push_back( tChild->cdata() );
				}
			}
		}
		//if( !useUrl_lastback.empty() ) m_url_backup.push_back( useUrl_lastback );

		if( tmgr->findChild("key") )
		{
			m_key = tmgr->findChild("key")->cdata();
		}

		if( tmgr->findChild("state") )
		{
			std::string strState = tmgr->findChild("state")->cdata();
			g_toLowerCase( strState );
			if( strState == "start" )
			{
				m_state = defPBState_Start;
			}
			else if( strState == "stop" )
			{
				m_state = defPBState_Stop;
			}
			else if( strState == "set" )
			{
				m_state = defPBState_Set;
			}
			else if( strState == "get" )
			{
				m_state = defPBState_Get;
			}
			else if( strState == "pause" )
			{
				m_state = defPBState_Pause;
			}
			else if( strState == "resume" )
			{
				m_state = defPBState_Resume;
			}
			else if( strState == "normalplay" )
			{
				m_state = defPBState_NormalPlay;
			}
			else if( strState == "fastplay" )
			{
				m_state = defPBState_FastPlay;
			}
			else if( strState == "fastplaythrow" )
			{
				m_state = defPBState_FastPlayThrow;
			}
			else if( strState == "fastplay1" )
			{
				m_state = defPBState_FastPlay1;
			}
			else if( strState == "fastplay2" )
			{
				m_state = defPBState_FastPlay2;
			}
			else if( strState == "slowplay" )
			{
				m_state = defPBState_SlowPlay;
			}
			else if( strState == "slowplay1" )
			{
				m_state = defPBState_SlowPlay1;
			}
			else if( strState == "slowplay2" )
			{
				m_state = defPBState_SlowPlay2;
			}
			else if( strState == "stopall" )
			{
				m_state = defPBState_StopAll;
			}
		}

		if( tmgr->findChild("sound") )
		{
			m_sound = atoi( tmgr->findChild("sound")->cdata().c_str() );
		}
		else
		{
			m_sound = -1; // 无效值
		}
	}
}
コード例 #11
0
ファイル: tag_test.cpp プロジェクト: jvalvert/societas
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t = new Tag( "toe" ); t->addAttribute( "foo", "bar" );
  Tag *u = new Tag( t, "uni" ); u->addAttribute( "u3", "3u" );
  Tag *v = new Tag( t, "vie" ); v->addAttribute( "v3", "3v" );
  Tag *v2 = new Tag( t, "vie" ); v->addAttribute( "v32", "3v2" );
  Tag *w = new Tag( u, "who" ); w->addAttribute( "w3", "3w" );
  Tag *x = new Tag( v, "xep" ); x->addAttribute( "x3", "3x" );
  Tag *y = new Tag( u, "yps" ); y->addAttribute( "y3", "3y" );
  Tag *z = new Tag( w, "zoo" ); z->addAttribute( "z3", "3z" );
  Tag *c = 0;
  Tag *d = 0;

  // -------
  name = "simple ctor";
  if( t->name() != "toe" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "cdata ctor";
  c = new Tag( "cod", "foobar" );
  if( c->name() != "cod" || c->cdata() != "foobar" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete c;
  c = 0;

  //-------
  name = "clone test 1";
  c = z->clone();
  if( *z != *c )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete c;
  c = 0;

  //-------
  name = "clone test 2";
  c = t->clone();
  if( *t != *c )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete c;
  c = 0;

  //-------
  name = "operator== test 1";
  c = new Tag( "name" );
  if( *t == *c )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete c;
  c = 0;

  //-------
  name = "operator== test 2";
  c = new Tag( "test" );
  c->addAttribute( "me", "help" );
  c->addChild( new Tag( "yes" ) );
  if( *t == *c )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete c;
  c = 0;

  //-------
  name = "operator== test 3";
  c = new Tag( "hello" );
  c->addAttribute( "test", "bacd" );
  c->addChild( new Tag( "hello" ) );
  d = new Tag( "hello" );
  d->addAttribute( "test", "bacd" );
  d->addChild( new Tag( "helloo" ) );
  if( *d == *c )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete c;
  delete d;
  c = 0;
  d = 0;

  //-------
  name = "operator!= test 1";
  c = new Tag( "hello" );
  c->addAttribute( "test", "bacd" );
  c->addChild( new Tag( "hello" ) );
  d = new Tag( "hello" );
  d->addAttribute( "test", "bacd" );
  d->addChild( new Tag( "hello" ) );
  if( *d != *c )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete c;
  delete d;
  c = 0;
  d = 0;

  //-------
  name = "findChildren test";
  TagList l = t->findChildren( "vie" );
  TagList::const_iterator it = l.begin();
  if( l.size() != 2 || (*it) != v || *(++it) != v2 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete c;
  c = 0;

  //-------
  name = "util::escape";
  if ( util::escape( "&<>'\"" ) != "&amp;&lt;&gt;&apos;&quot;" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  //-------
  name = "xml() 1";
  if( t->xml() != "<toe foo='bar'><uni u3='3u'><who w3='3w'><zoo z3='3z'/></who><yps y3='3y'/>"
                    "</uni><vie v3='3v' v32='3v2'><xep x3='3x'/></vie><vie/></toe>" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
  }

  //-------
  name = "xml() 2";
  t->addAttribute( "test", "bacd" );
  if( t->xml() != "<toe foo='bar' test='bacd'><uni u3='3u'><who w3='3w'><zoo z3='3z'/></who><yps y3='3y'/>"
                    "</uni><vie v3='3v' v32='3v2'><xep x3='3x'/></vie><vie/></toe>" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
  }

  //-------
  name = "hasChild 1";
  if( !t->hasChild( "uni" ) || !t->hasChild( "vie" ) || !u->hasChild( "who" ) || !w->hasChild( "zoo" )
      || !u->hasChild( "yps" ) )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
  }

  //-------
  name = "hasAttribute 1";
  if( !t->hasAttribute( "test" ) || !t->hasAttribute( "test", "bacd" )
      || !t->hasAttribute( "foo" ) || !t->hasAttribute( "foo", "bar" ) )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
  }

  //-------
  name = "findAttribute 1";
  if( t->findAttribute( "test" ) != "bacd" || t->findAttribute( "foo" ) != "bar" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
  }

  //-------
  name = "findChild 1";
  c = t->findChild( "uni" );
  if( c != u )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
  }

  //-------
  name = "findChild 2";
  c = t->findChild( "uni", "u3" );
  if( c != u )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
  }

  //-------
  name = "findChild 3";
  c = t->findChild( "uni", "u3", "3u" );
  if( c != u )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
  }

  //-------
  name = "findChildWithAttrib 1";
  c = t->findChildWithAttrib( "u3" );
  if( c != u )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
  }

  //-------
  name = "findChildWithAttrib 2";
  c = t->findChildWithAttrib( "u3", "3u" );
  if( c != u )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
  }

  //-------
  name = "attribute order";
  c = new Tag( "abc" );
  c->addAttribute( "abc", "def" );
  c->addAttribute( "xyz", "123" );
  d = c->clone();
  if( *c != *d )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), d->xml().c_str() );
  }
  delete c;
  c = 0;
  delete d;
  d = 0;

  //-------
  name = "mixed content 1";
  c = new Tag( "abc" );
  c->addCData( "cdata1" );
  new Tag( c, "fgh" );
  c->addCData( "cdata2" );
  new Tag( c, "xyz" );
  c->addCData( "cdata3" );
  if( c->xml() != "<abc>cdata1<fgh/>cdata2<xyz/>cdata3</abc>" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), c->xml().c_str() );
  }
  delete c;
  c = 0;

  //-------
  name = "operator bool()";
  Tag tag1( "" );
  if( tag1 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), tag1.xml().c_str() );
  }

  //-------
  name = "bool operator!()";
  Tag tag2( "abc" );
  if( !tag2 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), d->xml().c_str() );
  }

  //-------
  {
    name = "simple xmlns";
    Tag t( "abc" );
    t.setXmlns( "foo" );
    if( t.xml() != "<abc xmlns='foo'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() );
    }
  }

  //-------
  {
    name = "deep xmlns";
    Tag t( "abc" );
    Tag* f = new Tag( &t, "def" );
    f = new Tag( f, "ghi" );
    t.setXmlns( "foo" );
    if( t.xml() != "<abc xmlns='foo'><def><ghi/></def></abc>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() );
    }
  }

  //-------
  {
    name = "simple nested xmlns 2";
    Tag t( "abc" );
    t.setXmlns( "foo" );
    Tag* d = new Tag( &t, "def" );
    d->setXmlns( "foobar", "xyz" );
    d->setPrefix( "xyz" );
    if( t.xml() != "<abc xmlns='foo'><xyz:def xmlns:xyz='foobar'/></abc>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() );
    }
  }

  //-------
  {
    name = "attribute with xmlns";
    Tag t( "abc" );
    t.setXmlns( "foo", "xyz" );
    Tag::Attribute* a = new Tag::Attribute( "foo", "bar", "foo" );
    a->setPrefix( "xyz" );
    t.addAttribute( a );
    if( t.xml() != "<abc xmlns:xyz='foo' xyz:foo='bar'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() );
    }
  }

  //-------
  {
    name = "escape attribute value";
    Tag t( "foo", "abc", "&amp;" );
    if( t.xml() != "<foo abc='&amp;amp;'/>" )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() );
    }
  }

  //-------
  {
    name = "remove child 1";
    Tag t( "foo" );
    t.addChild( new Tag( "test", "xmlns", "foo" ) );
    t.addChild( new Tag( "abc", "xmlns", "foobar" ) );
    t.addAttribute( "attr1", "value1" );
    t.addAttribute( "attr2", "value2" );
    t.removeChild( "test" );
    if( t.hasChild( "test" ) )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() );
    }

    name = "remove child 2";
    t.removeChild( "abc", "foobar" );
    if( t.hasChild( "abc", "xmlns", "foobar" ) )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() );
    }

    name = "remove attrib 1";
    t.removeAttribute( "attr1" );
    if( t.hasAttribute( "attr1", "value1") )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() );
    }

    name = "remove attrib 2";
    t.removeAttribute( "attr2", "value2" );
    if( t.hasAttribute( "attr2", "value2") )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t.xml().c_str() );
    }
  }

  //-------
  {
    name = "invalid chars 1";
    Tag t( "foo" );
    bool check = t.addAttribute( "nul", std::string( 1, 0x00 ) );
    if( check || t.hasAttribute( "nul" ) )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed:%s\n", name.c_str(), t.xml().c_str() );
    }
  }

  //-------
  {
    name = "invalid chars 2";
    for( int i = 0; i <= 0xff; ++i )
    {
      Tag::Attribute a( "test", std::string( 1, i ) );

      if( ( i < 0x09 || i == 0x0b || i == 0x0c
          || ( i > 0x0d && i < 0x20 ) || i == 0xc0
          || i == 0xc1 || i >= 0xf5 ) && a )
      {
        ++fail;
        fprintf( stderr, "test '%s' (branch 1) failed (i == %02X)\n", name.c_str(), i );
      }
      else if( ( i == 0x09 || i == 0x0a || i == 0x0d
                 || ( i >= 0x20 && i < 0xc0 )
                 || ( i > 0xc1 && i < 0xf5 ) ) && !a )
      {
        ++fail;
        fprintf( stderr, "test '%s' (branch 2) failed (i == %02X)\n", name.c_str(), i );
      }
//       printf( "i: 0x%02X, a: %d, value: %s\n", i, (bool)a, std::string( 1, i ).c_str() );
    }
  }




  delete t;
  t = 0;




















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

}
コード例 #12
0
ファイル: XmppGSTalk.cpp プロジェクト: asdfjkl697/package
XmppGSTalk::XmppGSTalk( const Tag* tag )
	:StanzaExtension(ExtIotTalk), m_cmd(defTalkCmd_Unknown), m_result(true)
{
	if( !tag || tag->name() != "gstalk" || tag->xmlns() != XMLNS_GSIOT_TALK )
		return;

	Tag *tmgr = tag->findChild("gstalk");

	if( tmgr )
	{
		if( tmgr->findChild("command") )
		{
			m_strSrcCmd = tmgr->findChild("command")->cdata();
			std::string strcmd = m_strSrcCmd;
			g_toLowerCase( strcmd );
			if( strcmd == "request" )
			{
				m_cmd = defTalkCmd_request;
			}
			else if( strcmd == "accept" )
			{
				m_cmd = defTalkCmd_accept;
			}
			else if( strcmd == "reject" )
			{
				m_cmd = defTalkCmd_reject;
			}
			else if( strcmd == "session" )
			{
				m_cmd = defTalkCmd_session;
			}
			else if( strcmd == "adddev" )
			{
				m_cmd = defTalkCmd_adddev;
			}
			else if( strcmd == "removedev" )
			{
				m_cmd = defTalkCmd_removedev;
			}
			else if( strcmd == "keepalive" )
			{
				m_cmd = defTalkCmd_keepalive;
			}
			else if( strcmd == "quit" )
			{
				m_cmd = defTalkCmd_quit;
			}
			else if( strcmd == "forcequit" )
			{
				m_cmd = defTalkCmd_forcequit;
			}
			else
			{
				m_cmd = defTalkCmd_Unknown;
			}
		}

		if( tmgr->findChild("url") )
		{
			m_url = tmgr->findChild("url")->cdata();
		}

		Tag *tdevicelist = tmgr->findChild("devicelist");
		if( tdevicelist )
		{
			const TagList& l = tdevicelist->children();
			TagList::const_iterator it = l.begin();
			for( ; it != l.end(); ++it )
			{
				Tag *tDev = (*it);
				if( tDev->name() == "device" )
				{
					if( tDev->hasAttribute("type") && tDev->hasAttribute("id") )
					{
						IOTDeviceType dev_type = (IOTDeviceType)atoi( tDev->findAttribute("type").c_str() );
						int dev_id = atoi( tDev->findAttribute("id").c_str() );

						m_vecdev.push_back( GSIOTDeviceKey(dev_type,dev_id) );
					}
				}
			}
		}
	}
}
コード例 #13
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  DataFormField *f;

  // -------
  name = "empty field";
  f = new DataFormField();
  if( f->type() != DataFormField::TypeTextSingle )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "TypeBoolean field";
  f = new DataFormField( DataFormField::TypeBoolean );
  if( f->type() != DataFormField::TypeBoolean )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "2nd ctor";
  f = new DataFormField( "fieldName", "fieldValue", "fieldLabel", DataFormField::TypeBoolean );
  if( f->type() != DataFormField::TypeBoolean || f->name() != "fieldName" ||
      f->value() != "fieldValue" || f->label() != "fieldLabel" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "parse 0";
  f = new DataFormField( 0 );
  if( f->type() != DataFormField::TypeInvalid )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;
  Tag*t;

  // -------
  name = "set name";
  f = new DataFormField();
  f->setName( name );
  if( f->name() != name )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "set required";
  f = new DataFormField();
  bool req = true;
  f->setRequired( req );
  if( f->required() != req )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "set label";
  f = new DataFormField();
  f->setLabel( name );
  if( f->label() != name )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "set value";
  f = new DataFormField();
  f->setValue( name );
  if( f->value() != name )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "set values";
  f = new DataFormField();
  StringList val;
  val.push_back( "val 1" );
  val.push_back( "val 2" );
  val.push_back( "val 3" );
  f->setValues( val );
  if( f->values() != val )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "set values";
  f = new DataFormField();
  StringMultiMap opt;
  opt.insert( std::make_pair( "lock", "1" ) );
  opt.insert( std::make_pair( "stock", "1" ) );
  opt.insert( std::make_pair( "smoking barrel", "2" ) );
  f->setOptions( opt );
  if( f->options() != opt )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;
  f = 0;

  // -------
  name = "parse Tag 1";
  t = new Tag( "field");
  t->addAttribute( "type", "fixed" );
  new Tag( t, "value", "abc" );
  f = new DataFormField( t );
  Tag *ft = f->tag();
  if( *ft != *t )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
    printf( "f->tag(): %s\n", f->tag()->xml().c_str() );
    printf( "       t: %s\n", t->xml().c_str() );
  }
  delete f;
  delete t;
  delete ft;
  f = 0;

  // -------
  t = new Tag( "field");
  t->addAttribute( "type", "list-multi" );
  t->addAttribute( "label", "blabla label" );
  t->addAttribute( "var", "features" );
  Tag *o = new Tag( t, "option" );
  o->addAttribute( "label", "lock" );
  new Tag( o, "value", "lock" );
  o = new Tag( t, "option" );
  o->addAttribute( "label", "stock" );
  new Tag( o, "value", "stock" );
  o = new Tag( t, "option" );
  o->addAttribute( "label", "smoking barrel" );
  new Tag( o, "value", "smoking barrel" );
  new Tag( t, "value", "lock" );
  new Tag( t, "value", "stock" );
  f = new DataFormField( t );
  Tag *r = f->tag();
  name = "parse Tag 2.1";
  if( r->name() != "field" || !r->hasAttribute( "type", "list-multi" ) )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
    printf( "f->tag(): %s\n", f->tag()->xml().c_str() );
    printf( "       t: %s\n", t->xml().c_str() );
  }

  name = "parse Tag 2.2";
  if( !r->hasAttribute( "label", "blabla label" ) || !r->hasAttribute( "var", "features" ) )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
    printf( "f->tag(): %s\n", f->tag()->xml().c_str() );
    printf( "       t: %s\n", t->xml().c_str() );
  }

  name = "parse Tag 2.3";
  if( !r->hasChild( "option" ) || !r->findChild( "option" )->hasAttribute( "label", "lock" ) )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
    printf( "f->tag(): %s\n", f->tag()->xml().c_str() );
    printf( "       t: %s\n", t->xml().c_str() );
  }

  name = "parse Tag 2.4";
  if( !r->hasChild( "option", "label", "stock" ) )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
    printf( "f->tag(): %s\n", f->tag()->xml().c_str() );
    printf( "       t: %s\n", t->xml().c_str() );
  }

  name = "parse Tag 2.5";
  if( !r->hasChild( "option", "label", "smoking barrel" ) )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
    printf( "f->tag(): %s\n", f->tag()->xml().c_str() );
    printf( "       t: %s\n", t->xml().c_str() );
  }

  name = "parse Tag 2.6";
  if( !r->findChild( "option" )->findChild( "value" ) )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
    printf( "f->tag(): %s\n", f->tag()->xml().c_str() );
    printf( "       t: %s\n", t->xml().c_str() );
  }

  name = "parse Tag 2.7";
  if( r->findChild( "option" )->findChild( "value" )->cdata() != "lock" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
    printf( "f->tag(): %s\n", f->tag()->xml().c_str() );
    printf( "       t: %s\n", t->xml().c_str() );
  }

  name = "parse Tag 2.8";
  TagList l = r->children();
  TagList::const_iterator it = l.begin();
  for( ; it != l.end(); ++it )
  {
    if( (*it)->name() == "option" && ( !(*it)->hasChildWithCData( "value", "lock" ) &&
          !(*it)->hasChildWithCData( "value", "stock" ) &&
          !(*it)->hasChildWithCData( "value", "smoking barrel" ) ) )
    {
      ++fail;
      fprintf( stderr, "test '%s' failed\n", name.c_str() );
      printf( "f->tag(): %s\n", f->tag()->xml().c_str() );
      printf( "       t: %s\n", t->xml().c_str() );
    }
  }

  name = "parse Tag 2.9";
  if( !r->hasChildWithCData( "value", "lock" ) || !r->hasChildWithCData( "value", "stock" ) )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
    printf( "f->tag(): %s\n", f->tag()->xml().c_str() );
    printf( "       t: %s\n", t->xml().c_str() );
  }
  delete f;
  delete t;
  delete r;
  f = 0;



  // -------
  name = "boolean duplicate <value/>";
  f = new DataFormField( DataFormField::TypeBoolean );
  f->setName( "name" );
  f->setValue( "1" );
  f->setLabel( "label" );
  t = f->tag();
  if( t->children().size() != 1 || t->xml() != "<field type='boolean' var='name' "
                                               "label='label'><value>1</value></field>" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), t->xml().c_str() );
  }
  delete f;
  delete t;
  f = 0;
  t = 0;









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

}
コード例 #14
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;
  }
コード例 #15
0
  bool Registration::handleIqID( Stanza *stanza, int context )
  {
    if( stanza->subtype() != StanzaIqResult )
      return false;

    if( !m_registrationHandler )
      return false;

    switch( context )
    {
      case FETCH_REGISTRATION_FIELDS:
      {
        Tag *q = stanza->findChild( "query" );

        if( q->hasChild( "registered" ) )
        {
          m_registrationHandler->handleAlreadyRegistered();
          break;
        }

        if( q->hasChild( "x", "xmlns", XMLNS_X_DATA ) )
        {
          DataForm form( q->findChild( "x", "xmlns", XMLNS_X_DATA ) );
          m_registrationHandler->handleDataForm( form );
        }

        if( q->hasChild( "x", "xmlns", XMLNS_X_OOB ) )
        {
          Tag *x = q->findChild( "x", "xmlns", XMLNS_X_OOB );
          std::string url;
          if( x->hasChild( "url" ) )
            url = x->findChild( "url" )->cdata();

          std::string desc;
          if( x->hasChild( "url" ) )
            url = x->findChild( "url" )->cdata();

          m_registrationHandler->handleOOB( url, desc );
        }

        int fields = 0;
        std::string instructions;

        if( q->hasChild( "username" ) )
          fields |= FIELD_USERNAME;
        if( q->hasChild( "nick" ) )
          fields |= FIELD_NICK;
        if( q->hasChild( "password" ) )
          fields |= FIELD_PASSWORD;
        if( q->hasChild( "name" ) )
          fields |= FIELD_NAME;
        if( q->hasChild( "first" ) )
          fields |= FIELD_FIRST;
        if( q->hasChild( "last" ) )
            fields |= FIELD_LAST;
        if( q->hasChild( "email" ) )
          fields |= FIELD_EMAIL;
        if( q->hasChild( "address" ) )
          fields |= FIELD_ADDRESS;
        if( q->hasChild( "city" ) )
          fields |= FIELD_CITY;
        if( q->hasChild( "state" ) )
          fields |= FIELD_STATE;
        if( q->hasChild( "zip" ) )
          fields |= FIELD_ZIP;
        if( q->hasChild( "phone" ) )
          fields |= FIELD_PHONE;
        if( q->hasChild( "url" ) )
          fields |= FIELD_URL;
        if( q->hasChild( "date" ) )
          fields |= FIELD_DATE;
        if( q->hasChild( "misc" ) )
          fields |= FIELD_MISC;
        if( q->hasChild( "text" ) )
          fields |= FIELD_TEXT;
        if( q->hasChild( "instructions" ) )
          instructions = q->findChild( "instructions" )->cdata();

        m_registrationHandler->handleRegistrationFields( fields, instructions );
        break;
      }

      case CREATE_ACCOUNT:
        m_registrationHandler->handleRegistrationResult( RegistrationHandler::REGISTRATION_SUCCESS );
        break;

      case CHANGE_PASSWORD:
        m_registrationHandler->handleRegistrationResult( RegistrationHandler::REGISTRATION_SUCCESS );
        break;

      case REMOVE_ACCOUNT:
        m_registrationHandler->handleRegistrationResult( RegistrationHandler::REGISTRATION_SUCCESS );
        break;
    }
    return false;
  }
コード例 #16
0
	void whistleVcardHandler::handleIqID( const IQ& iq, int context )
	{
		switch( iq.subtype() )
		{
		case IQ::Result:
			{
				switch( context )
				{
				case VCardHandler::FetchVCard:
					{
						json::jobject jobj;
						json::jobject status = json::jobject();
						if (iq.findExtension( ExtVCard ))
						{
							boost::shared_ptr<gloox::Tag> ptag(iq.findExtension( ExtVCard )->tag());
							for (TagList::const_iterator cit = ptag->children().begin(); cit != ptag->children().end(); ++cit) {
								Tag* ptag = *cit;
								if (ptag->name() == s_VcardPrivacy)
								{
									jobj[ptag->name()] = json::jobject(ptag->cdata());
								}
								else if (ptag->name() == s_VcardStatus)
								{
									//获取vcard协议改变 新的解析iq
									Tag* presource = ptag->findChild("resource");
									Tag* pshow = ptag->findChild("show");
									if ( presource && pshow)
									{
										json::jobject itemdata;
										itemdata["resource"] = presource->cdata();
										itemdata["show"] = pshow->cdata();
										status.arr_push(itemdata);
									}
								}
								else
								{
									jobj[ptag->name()] = ptag->cdata();
								}
							}
							jobj[s_VcardJid] = iq.from().bare();

							gwhistleVcard::instance().handleVCard(iq.from(), jobj, status, waitCallback_);
						}
						break;
					}
				case VCardHandler::StoreVCard:
					gwhistleVcard::instance().handleVCardResult(VCardHandler::StoreVCard, iq.from());
					break;
				}
			}
			break;
		case IQ::Error:
			{
				switch( context )
				{
				case VCardHandler::FetchVCard:
					if (!waitCallback_.empty())
					{
						waitCallback_();
					}
					else
					{
						gwhistleVcard::instance().updatedVcard(iq.from());
					}
					break;
				case VCardHandler::StoreVCard:
					gwhistleVcard::instance().handleVCardResult( (VCardHandler::VCardContext)context,
						iq.from(),
						iq.error() ? iq.error()->error()
						: StanzaErrorUndefined );
					break;
				}
			}
		default:
			break;
		}
	}
コード例 #17
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;
  OOB *d;

  // -------
  name = "parsing 0 tag";
  d = new OOB( 0 );
  if( d->tag() != 0 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------------------
  // jabber:x:oob tests
  // -------------------
  Tag *x = new Tag( "x" );
  x->addAttribute( "xmlns", XMLNS_X_OOB );
  new Tag( x, "url", "invalidurl" );
  new Tag( x, "desc", "description" );


  // -------
  name = "filled object/getters";
  d = new OOB( "invalidurl", "description", false );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "filled object/tag()";
  d = new OOB( "invalidurl", "description", false );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_X_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;

  // -------
  name = "from Tag/getters";
  d = new OOB( x );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "from Tag/tag()";
  d = new OOB( x );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_X_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;


  // -------------------
  // jabber:iq:oob tests
  // -------------------

  delete x;
  x  = 0;
  x = new Tag( "query" );
  x->addAttribute( "xmlns", XMLNS_IQ_OOB );
  new Tag( x, "url", "invalidurl" );
  new Tag( x, "desc", "description" );


  // -------
  name = "filled object/getters";
  d = new OOB( "invalidurl", "description", true );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "filled object/tag()";
  d = new OOB( "invalidurl", "description", true );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_IQ_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;

  // -------
  name = "from Tag/getters";
  d = new OOB( x );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "from Tag/tag()";
  d = new OOB( x );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_IQ_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;


  delete x;
  x = 0;


  StanzaExtensionFactory sef;

  // -------
  name = "OOB/SEFactory test";
  OOB* oob = new OOB( 0 ); // deleted by StanzaExtensionFactory sef;
  sef.registerExtension( oob );
  Tag* f = new Tag( "iq" );
  Tag* b = new Tag( f, "query", "xmlns", XMLNS_IQ_OOB );
  new Tag( b, "url", "url" );
  new Tag( b, "desc", "desc" );
  IQ iq( IQ::Set, JID(), "" );
  sef.addExtensions( iq, f );
  const OOB* se = iq.findExtension<OOB>( ExtOOB );
  if( se == 0 || se->url() != "url" || se->desc() != "desc" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }
  delete f;


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

}
コード例 #18
0
ファイル: oob_test.cpp プロジェクト: soubok/libset
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  Tag *t;
  OOB *d;

  // -------
  name = "parsing 0 tag";
  d = new OOB( 0 );
  if( d->tag() != 0 )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------------------
  // jabber:x:oob tests
  // -------------------
  Tag *x = new Tag( "x" );
  x->addAttribute( "xmlns", XMLNS_X_OOB );
  new Tag( x, "url", "invalidurl" );
  new Tag( x, "desc", "description" );


  // -------
  name = "filled object/getters";
  d = new OOB( "invalidurl", "description", false );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "filled object/tag()";
  d = new OOB( "invalidurl", "description", false );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_X_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;

  // -------
  name = "from Tag/getters";
  d = new OOB( x );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "from Tag/tag()";
  d = new OOB( x );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_X_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;


  // -------------------
  // jabber:iq:oob tests
  // -------------------

  delete x;
  x  = 0;
  x = new Tag( "query" );
  x->addAttribute( "xmlns", XMLNS_IQ_OOB );
  new Tag( x, "url", "invalidurl" );
  new Tag( x, "desc", "description" );


  // -------
  name = "filled object/getters";
  d = new OOB( "invalidurl", "description", true );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "filled object/tag()";
  d = new OOB( "invalidurl", "description", true );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_IQ_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;

  // -------
  name = "from Tag/getters";
  d = new OOB( x );
  if( d->url() != "invalidurl" || d->desc() != "description" )
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  d = 0;

  // -------
  name = "from Tag/tag()";
  d = new OOB( x );
  t = d->tag();
  if( !t || !t->hasAttribute( "xmlns", XMLNS_IQ_OOB )
       || !t->hasChild( "url" ) || t->findChild( "url" )->cdata() != "invalidurl"
       || !t->hasChild( "desc" ) || t->findChild( "desc" )->cdata() != "description")
  {
    ++fail;
    printf( "test '%s' failed\n", name.c_str() );
  }
  delete d;
  delete t;
  d = 0;
  t = 0;



  delete x;
  x = 0;

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

}
コード例 #19
0
  bool SOCKS5BytestreamManager::handleIqID( Stanza *stanza, int context )
  {
    StringMap::iterator it = m_trackMap.find( stanza->id() );
    if( it == m_trackMap.end() )
      return false;

    switch( context )
    {
      case S5BOpenStream:
      {
        switch( stanza->subtype() )
        {
          case StanzaIqResult:
          {
            Tag* q = stanza->findChild( "query", "xmlns", XMLNS_BYTESTREAMS );
            if( !q || !m_socks5BytestreamHandler )
              return false;

            Tag* s = q->findChild( "streamhost-used" );
            if( !s || !s->hasAttribute( "jid" ) )
              return false;

            const std::string & proxy = s->findAttribute( "jid" );
            const StreamHost* sh = findProxy( stanza->from(), proxy, (*it).second );
            if( sh )
            {
              SOCKS5Bytestream* s5b = 0;
              bool selfProxy = ( proxy == m_parent->jid().full() && m_server );
              if( selfProxy )
              {
                SHA sha;
                sha.feed( (*it).second );
                sha.feed( m_parent->jid().full() );
                sha.feed( stanza->from().full() );
                s5b = new SOCKS5Bytestream( this, m_server->getConnection( sha.hex() ),
                                            m_parent->logInstance(),
                                            m_parent->jid(), stanza->from(),
                                            (*it).second );
              }
              else
              {
                s5b = new SOCKS5Bytestream( this, m_parent->connectionImpl()->newInstance(),
                                            m_parent->logInstance(),
                                            m_parent->jid(), stanza->from(),
                                            (*it).second );
                StreamHostList shl;
                shl.push_back( *sh );
                s5b->setStreamHosts( shl );
              }
              m_s5bMap[(*it).second] = s5b;
              m_socks5BytestreamHandler->handleOutgoingSOCKS5Bytestream( s5b );
              if( selfProxy )
                s5b->activate();
            }
            break;
          }
          case StanzaIqError:
            m_socks5BytestreamHandler->handleSOCKS5BytestreamError( stanza, (*it).second );
            break;
          default:
            break;
        }
        break;
      }
      case S5BActivateStream:
      {
        switch( stanza->subtype() )
        {
          case StanzaIqResult:
          {
            S5BMap::const_iterator it5 = m_s5bMap.find( (*it).second );
            if( it5 != m_s5bMap.end() )
              (*it5).second->activate();
            break;
          }
          case StanzaIqError:
            m_socks5BytestreamHandler->handleSOCKS5BytestreamError( stanza, (*it).second );
            break;
          default:
            break;
        }
        break;
      }
      default:
        break;
    }
    m_trackMap.erase( it );

    return false;
  }
コード例 #20
0
ファイル: registerhandler.cpp プロジェクト: bochi/spectrum-gw
bool GlooxRegisterHandler::handleIq(const Tag *iqTag) {
	Log("GlooxRegisterHandler", iqTag->findAttribute("from") << ": iq:register received (" << iqTag->findAttribute("type") << ")");

	JID from(iqTag->findAttribute("from"));

	if (CONFIG().protocol == "irc") {
		sendError(400, "bad-request", iqTag);
		return false;
	}
	
	AbstractUser *user = Transport::instance()->userManager()->getUserByJID(from.bare());
	if (!Transport::instance()->getConfiguration().enable_public_registration) {
		std::list<std::string> const &x = Transport::instance()->getConfiguration().allowedServers;
		if (std::find(x.begin(), x.end(), from.server()) == x.end()) {
			Log("GlooxRegisterHandler", "This user has no permissions to register an account");
			sendError(400, "bad-request", iqTag);
			return false;
		}
	}

	const char *_language = user ? user->getLang() : Transport::instance()->getConfiguration().language.c_str();

	// send registration form
	if (iqTag->findAttribute("type") == "get") {
		Tag *reply = new Tag( "iq" );
		reply->addAttribute( "id", iqTag->findAttribute("id") );
		reply->addAttribute( "type", "result" );
		reply->addAttribute( "to", iqTag->findAttribute("from") );
		reply->addAttribute( "from", Transport::instance()->jid() );
		Tag *query = new Tag( "query" );
		query->addAttribute( "xmlns", "jabber:iq:register" );
		UserRow res = Transport::instance()->sql()->getUserByJid(from.bare());

		std::string instructions = CONFIG().reg_instructions.empty() ? PROTOCOL()->text("instructions") : CONFIG().reg_instructions;
		std::string usernameField = CONFIG().reg_username_field.empty() ? PROTOCOL()->text("username") : CONFIG().reg_username_field;

		if (res.id == -1) {
			Log("GlooxRegisterHandler", "* sending registration form; user is not registered");
			query->addChild( new Tag("instructions", tr(_language, instructions)) );
			query->addChild( new Tag("username") );
			if (CONFIG().protocol != "twitter" && CONFIG().protocol != "bonjour")
				query->addChild( new Tag("password") );
		}
		else {
			Log("GlooxRegisterHandler", "* sending registration form; user is registered");
			query->addChild( new Tag("instructions", tr(_language, instructions)) );
			query->addChild( new Tag("registered") );
			query->addChild( new Tag("username", res.uin));
			if (CONFIG().protocol != "twitter" && CONFIG().protocol != "bonjour")
				query->addChild( new Tag("password"));
		}

		Tag *x = new Tag("x");
		x->addAttribute("xmlns", "jabber:x:data");
		x->addAttribute("type", "form");
		x->addChild( new Tag("title", tr(_language, _("Registration"))));
		x->addChild( new Tag("instructions", tr(_language, instructions)) );

		Tag *field = new Tag("field");
		field->addAttribute("type", "hidden");
		field->addAttribute("var", "FORM_TYPE");
		field->addChild( new Tag("value", "jabber:iq:register") );
		x->addChild(field);

		field = new Tag("field");
		field->addAttribute("type", "text-single");
		field->addAttribute("var", "username");
		field->addAttribute("label", tr(_language, usernameField));
		field->addChild( new Tag("required") );
		if (res.id!=-1)
			field->addChild( new Tag("value", res.uin) );
		x->addChild(field);

		if (CONFIG().protocol != "twitter" && CONFIG().protocol != "bonjour") {
			field = new Tag("field");
			field->addAttribute("type", "text-private");
			field->addAttribute("var", "password");
			field->addAttribute("label", tr(_language, _("Password")));
			x->addChild(field);
		}

		field = new Tag("field");
		field->addAttribute("type", "list-single");
		field->addAttribute("var", "language");
		field->addAttribute("label", tr(_language, _("Language")));
		if (res.id!=-1)
			field->addChild( new Tag("value", res.language) );
		else
			field->addChild( new Tag("value", Transport::instance()->getConfiguration().language) );
		x->addChild(field);

		std::map <std::string, std::string> languages = localization.getLanguages();
		for (std::map <std::string, std::string>::iterator it = languages.begin(); it != languages.end(); it++) {
			Tag *option = new Tag("option");
			option->addAttribute("label", (*it).second);
			option->addChild( new Tag("value", (*it).first) );
			field->addChild(option);
		}

		field = new Tag("field");
		field->addAttribute("type", "text-single");
		field->addAttribute("var", "encoding");
		field->addAttribute("label", tr(_language, _("Encoding")));
		if (res.id!=-1)
			field->addChild( new Tag("value", res.encoding) );
		else
			field->addChild( new Tag("value", Transport::instance()->getConfiguration().encoding) );
		x->addChild(field);

		if (res.id != -1) {
			field = new Tag("field");
			field->addAttribute("type", "boolean");
			field->addAttribute("var", "unregister");
			field->addAttribute("label", tr(_language, _("Remove your registration")));
			field->addChild( new Tag("value", "0") );
			x->addChild(field);
		}

		query->addChild(x);
		reply->addChild(query);
		Transport::instance()->send( reply );
		return true;
	}
	else if (iqTag->findAttribute("type") == "set") {
		bool remove = false;
		Tag *query;
		Tag *usernametag;
		Tag *passwordtag;
		Tag *languagetag;
		Tag *encodingtag;
		std::string username("");
		std::string password("");
		std::string language("");
		std::string encoding("");

		UserRow res = Transport::instance()->sql()->getUserByJid(from.bare());
		
		query = iqTag->findChild( "query" );
		if (!query) return true;

		Tag *xdata = query->findChild("x", "xmlns", "jabber:x:data");
		if (xdata) {
			if (query->hasChild( "remove" ))
				remove = true;
			for (std::list<Tag*>::const_iterator it = xdata->children().begin(); it != xdata->children().end(); ++it) {
				std::string key = (*it)->findAttribute("var");
				if (key.empty()) continue;

				Tag *v = (*it)->findChild("value");
				if (!v) continue;

				if (key == "username")
					username = v->cdata();
				else if (key == "password")
					password = v->cdata();
				else if (key == "language")
					language = v->cdata();
				else if (key == "encoding")
					encoding = v->cdata();
				else if (key == "unregister")
					remove = atoi(v->cdata().c_str());
			}
		}
		else {
			if (query->hasChild( "remove" ))
				remove = true;
			else {
				usernametag = query->findChild("username");
				passwordtag = query->findChild("password");
				languagetag = query->findChild("language");
				encodingtag = query->findChild("encoding");

				if (languagetag)
					language = languagetag->cdata();
				else
					language = Transport::instance()->getConfiguration().language;

				if (encodingtag)
					encoding = encodingtag->cdata();
				else
					encoding = Transport::instance()->getConfiguration().encoding;

				if (usernametag==NULL || (passwordtag==NULL && CONFIG().protocol != "twitter" && CONFIG().protocol != "bonjour")) {
					sendError(406, "not-acceptable", iqTag);
					return false;
				}
				else {
					username = usernametag->cdata();
					if (passwordtag)
						password = passwordtag->cdata();
					if (username.empty() || (password.empty() && CONFIG().protocol != "twitter" && CONFIG().protocol != "bonjour")) {
						sendError(406, "not-acceptable", iqTag);
						return false;
					}
				}
			}
		}

		if (Transport::instance()->getConfiguration().protocol == "xmpp") {
			// User tries to register himself.
			if ((JID(username).bare() == from.bare())) {
				sendError(406, "not-acceptable", iqTag);
				return false;
			}

			// User tries to register someone who's already registered.
			UserRow user_row = Transport::instance()->sql()->getUserByJid(JID(username).bare());
			if (user_row.id != -1) {
				sendError(406, "not-acceptable", iqTag);
				return false;
			}
		}

		if (remove) {
			unregisterUser(from.bare());

			Tag *reply = new Tag("iq");
			reply->addAttribute( "type", "result" );
			reply->addAttribute( "from", Transport::instance()->jid() );
			reply->addAttribute( "to", iqTag->findAttribute("from") );
			reply->addAttribute( "id", iqTag->findAttribute("id") );
			Transport::instance()->send( reply );

			return true;
		}

		// Register or change password

		std::string jid = from.bare();

		if (username.empty() || (password.empty() && CONFIG().protocol != "twitter" && CONFIG().protocol != "bonjour") || localization.getLanguages().find(language) == localization.getLanguages().end()) {
			sendError(406, "not-acceptable", iqTag);
			return false;
		}

		Transport::instance()->protocol()->prepareUsername(username);

		std::string newUsername(username);
		if (!CONFIG().username_mask.empty()) {
			newUsername = CONFIG().username_mask;
			replace(newUsername, "$username", username.c_str());
		}

		if (!Transport::instance()->protocol()->isValidUsername(newUsername)) {
			Log("GlooxRegisterHandler", "This is not valid username: "******"bad-request", iqTag);
			return false;
		}

#if GLIB_CHECK_VERSION(2,14,0)
		if (!CONFIG().reg_allowed_usernames.empty() &&
			!g_regex_match_simple(CONFIG().reg_allowed_usernames.c_str(), newUsername.c_str(),(GRegexCompileFlags) (G_REGEX_CASELESS | G_REGEX_EXTENDED), (GRegexMatchFlags) 0)) {
			Log("GlooxRegisterHandler", "This is not valid username: "******"bad-request", iqTag);
			return false;
		}
#endif
		if (res.id == -1) {
			res.jid = from.bare();
			res.uin = username;
			res.password = password;
			res.language = language;
			res.encoding = encoding;
			res.vip = 0;

			registerUser(res);
		}
		else {
			// change passwordhttp://soumar.jabbim.cz/phpmyadmin/index.php
			Log("GlooxRegisterHandler", "changing user password: "******", " << username);
			res.jid = from.bare();
			res.password = password;
			res.language = language;
			res.encoding = encoding;
			Transport::instance()->sql()->updateUser(res);
		}

		Tag *reply = new Tag( "iq" );
		reply->addAttribute( "id", iqTag->findAttribute("id") );
		reply->addAttribute( "type", "result" );
		reply->addAttribute( "to", iqTag->findAttribute("from") );
		reply->addAttribute( "from", Transport::instance()->jid() );
		Transport::instance()->send( reply );

		return true;
	}
	return false;
}
コード例 #21
0
ファイル: iodata.cpp プロジェクト: OSUser/avbot
  IOData::IOData( const Tag* tag )
    : AdhocPlugin( ExtIOData ),
      m_in( 0 ), m_out( 0 ), m_error( 0 ),
      m_type( TypeInvalid )
  {
    if( !tag || !( tag->name() == "iodata" && tag->hasAttribute( XMLNS, XMLNS_IODATA ) ) )
      return;

    m_status.elapsed = -1;
    m_status.remaining = -1;
    m_status.percentage = -1;

    m_type = ioType( tag->findAttribute( "type" ) );
    Tag* m = 0;
    switch( m_type )
    {
      case TypeInput:
        m = tag->findChild( "in" );
        if( m )
          m_in = m->clone();
        break;
      case TypeIoSchemataResult:
        m = tag->findChild( "desc" );
        if( m )
          m_desc = m->cdata();

        m = tag->findChild( "out" );
        if( m )
          m_out = m->clone();

        m = tag->findChild( "in" );
        if( m )
          m_in = m->clone();
        break;
      case TypeOutput:
        m = tag->findChild( "out" );
        if( m )
          m_out = m->clone();
        break;
      case TypeError:
        m = tag->findChild( "error" );
        if( m )
          m_error = m->clone();
        break;
      case TypeStatus:
        m = tag->findChild( "status" );
        if( m )
        {
          Tag* t = m->findChild( "elapsed" );
          if( t )
            m_status.elapsed = atoi( t->cdata().c_str() );

          t = m->findChild( "remaining" );
          if( t )
            m_status.remaining = atoi( t->cdata().c_str() );

          t = m->findChild( "percentage" );
          if( t )
            m_status.percentage = atoi( t->cdata().c_str() );

          t = m->findChild( "information" );
          if( t )
            m_status.info = t->cdata();
        }
        break;
      case TypeIoSchemataGet:
      case TypeGetStatus:
      case TypeGetOutput:
      default:
        break;
    }

  }
コード例 #22
0
ファイル: XmppGSEvent.cpp プロジェクト: asdfjkl697/projects
XmppGSEvent::XmppGSEvent( const Tag* tag )
	:StanzaExtension(ExtIotEvent), m_method(defCfgOprt_Unknown), m_pDevice(NULL), m_runstate(1)
{
	if( !tag || tag->name() != "gsiot" || tag->xmlns() != XMLNS_GSIOT_EVENT )
		return;

	//GSIOTClient::XmppPrint( tag, "recv", stanza, false ); //jyc20170227 debug
	//XmppGSEvent::PrintTag( tag , ExtIotEvent);

	Tag *tmgr = tag->findChild("event");

	if( tmgr )
	{
		Tag *tDevice = tmgr->findChild("device");
		if( tDevice )
		{
			m_pDevice = new GSIOTDevice(tDevice);
		}
		else
		{
			LOGMSG( "not found device tag" );
			return;
		}

		this->UntagEditAttr( tmgr );

		if(tmgr->hasAttribute("method"))
		{
			m_srcmethod = tmgr->findAttribute("method");
			std::string method = m_srcmethod;
			g_toLowerCase( method );
			if( method == "add" )
			{
				m_method = defCfgOprt_Add;
			}
			else if( method == "edit" )
			{
				m_method = defCfgOprt_Modify;
			}
			else if( method == "delete" )
			{
				m_method = defCfgOprt_Delete;
			}
		}

		Tag *tdo = tmgr->findChild("do");  //jyc20170223 trans  "edit trigger"
		if( tdo )
		{
			const TagList& l = tdo->children();
			TagList::const_iterator it = l.begin();
			for( ; it != l.end(); ++it )
			{
				ControlEvent *pNew = NULL;

				if((*it)->name() == "smsthing")
				{
					pNew = new AutoSendSMSEvent(*it);
				}
				else if((*it)->name() == "mailthing")
				{
					//...
				}
				else if((*it)->name() == "messagething")
				{
					pNew = new AutoNoticeEvent(*it);
				}
				else if((*it)->name() == "devicething")
				{
					pNew = new AutoControlEvent(*it);
				}
				else if((*it)->name() == "callthing")
				{
					//...
				}
				else if((*it)->name() == "eventthing")
				{
					pNew = new AutoEventthing(*it);
				}

				if( pNew )
				{
					if( m_pDevice )
					{
						pNew->SetDeviceType( m_pDevice->getType() );
						pNew->SetDeviceID( m_pDevice->getId() );
					}

					m_Events.push_back( pNew );
				}
			}
		}

		Tag *tState = tmgr->findChild("state");
		if( tState )
		{
			m_runstate = atoi( tState->cdata().c_str() );
		} 
	}
}
コード例 #23
0
ファイル: search.cpp プロジェクト: soubok/libset
  bool Search::handleIqID( Stanza *stanza, int context )
  {
    TrackMap::iterator it = m_track.find( stanza->id() );
    if( it != m_track.end() )
    {
      switch( stanza->subtype() )
      {
        case StanzaIqResult:
          switch( context )
          {
            case FetchSearchFields:
            {
              Tag *q = stanza->findChild( "query" );
              if( q && q->hasAttribute( "xmlns", XMLNS_SEARCH ) )
              {
                Tag *x = q->findChild( "x", "xmlns", XMLNS_X_DATA );
                if( x )
                {
                  DataForm *df = new DataForm( x );
                  (*it).second->handleSearchFields( stanza->from(), df );
                }
                else
                {
                  int fields = 0;
                  std::string instructions;

                  if( q->hasChild( "first" ) )
                    fields |= SearchFieldFirst;
                  if( q->hasChild( "last" ) )
                    fields |= SearchFieldLast;
                  if( q->hasChild( "nick" ) )
                    fields |= SearchFieldNick;
                  if( q->hasChild( "email" ) )
                    fields |= SearchFieldEmail;
                  if( q->hasChild( "instructions" ) )
                    instructions = q->findChild( "instructions" )->cdata();

                  (*it).second->handleSearchFields( stanza->from(), fields, instructions );
                }
              }
              break;
            }
            case DoSearch:
            {
              Tag *q = stanza->findChild( "query" );
              if( q && q->hasAttribute( "xmlns", XMLNS_SEARCH ) )
              {
                Tag *x = q->findChild( "x", "xmlns", XMLNS_X_DATA );
                if( x )
                {
                  DataForm *df = new DataForm( x );
                  (*it).second->handleSearchResult( stanza->from(), df );
                }
                else
                {
                  SearchResultList e;
                  SearchFieldStruct s;
                  const Tag::TagList &l = q->children();
                  Tag::TagList::const_iterator itl = l.begin();
                  for( ; itl != l.end(); ++itl )
                  {
                    if( (*itl)->name() == "item" )
                    {
                      s.jid.setJID( (*itl)->findAttribute( "jid" ) );
                      Tag *t = 0;
                      if( ( t = (*itl)->findChild( "first" ) ) != 0 )
                        s.first = t->cdata();
                      if( ( t = (*itl)->findChild( "last" ) ) != 0 )
                        s.last = t->cdata();
                      if( ( t = (*itl)->findChild( "nick" ) ) != 0 )
                        s.nick = t->cdata();
                      if( ( t = (*itl)->findChild( "email" ) ) != 0 )
                        s.email = t->cdata();
                      e.push_back( s );
                    }
                  }

                  (*it).second->handleSearchResult( stanza->from(), e );
                }
              }
              break;
            }
          }
          break;
        case StanzaIqError:
          (*it).second->handleSearchError( stanza->from(), stanza );
          break;

        default:
          break;
      }

      m_track.erase( it );
    }

    return false;
  }