Esempio n. 1
0
void IRCProtocol::makePurpleUsernameRoom(User *user, const JID &to, std::string &name) {
    std::string username = to.username();
    // "#pidgin%[email protected]/HanzZ" -> "HanzZ"
    if (!to.resource().empty() && to.resource() != "bot") {
        username = to.resource();
    }
    // "hanzz%[email protected]/bot" -> "hanzz"
    else if (to.resource() == "bot") {
        size_t pos = username.find("%");
        if (pos != std::string::npos)
            username.erase((int) pos, username.length() - (int) pos);
    }
    // "#pidgin%[email protected]" -> #pidgin
    else {
        size_t pos = username.find("%");
        if (pos != std::string::npos)
            username.erase((int) pos, username.length() - (int) pos);
    }
    std::for_each( username.begin(), username.end(), replaceJidCharacters() );
    name.assign(username);
}
void jConference::handleDiscoInfo(const JID &from, const Disco::Info &info, int /*context*/)
{
	QString bare = utils::fromStd(from.bare());
	QString resource = utils::fromStd(from.resource());
	if(Room *room = m_rooms.value(bare))
	{
		QHash<QString,MucContact> &contacts = room->contacts_list;
		if(!contacts.contains(resource))
			return;
		jBuddy::ResourceInfo &resource_info = contacts[resource].m_info;
		jClientIdentification::instance().newInfo(info, &resource_info);
	}
}
Esempio n. 3
0
int main( int /*argc*/, char** /*argv*/ )
{
  int fail = 0;
  std::string name;
  JID j;

  // -------
  name = "bare JID ctor";
  j = JID( "*****@*****.**" );
  if( j.bare() != "*****@*****.**" || j.username() != "abc" || j.server() != "server.dom" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "full JID ctor";
  j = JID( "[email protected]/res" );
  if( j.full() != "[email protected]/res" || j.username() != "abc" || j.server() != "server.dom"
      || j.resource() != "res" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "server + resource ctor";
  j = JID( "server.dom/res" );
  if( j.full() != "server.dom/res" || j.server() != "server.dom" || j.resource() != "res" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "server ctor";
  j = JID( "server.dom" );
  if( j.full() != "server.dom" || j.server() != "server.dom" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "prepped node";
  j = JID( "*****@*****.**" );
  if( j.bare() != "*****@*****.**" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "prepped dom";
  j = JID( "*****@*****.**" );
  if( j.bare() != "*****@*****.**" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "resource getter";
  j = JID( "[email protected]/rEsOurCe" );
  if( j.resource() != "rEsOurCe" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "node getter";
  j = JID( "[email protected]/rEsOurCe" );
  if( j.username() != "abc" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "server getter";
  j = JID( "[email protected]/rEsOurCe" );
  if( j.server() != "server.dom" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "bare JID getter";
  j = JID( "[email protected]/rEsOurCe" );
  JID t1( "[email protected]/rEsOurCe");
  if( j.bareJID() != t1.bareJID() )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "clear jid";
  j = JID( "[email protected]/rEsOurCe" );
  j.setJID( "" );
  if( j || !j.username().empty()
        || !j.server().empty()
        || !j.serverRaw().empty()
        || !j.resource().empty()
        || !j.bare().empty()
        || !j.full().empty() )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "operator bool() 1";
  JID jid1( "[email protected]/rEsOurCe" );
  if( !jid1 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "operator bool() 2";
  JID jid2( "" );
  if( jid2 )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "JID\20Escaping";
  const std::string e = JID::escapeNode( "1 2\"3&4'5/6:7<8>9@10\\" );
  if( e != "1\\202\\223\\264\\275\\2f6\\3a7\\3c8\\3e9\\4010\\5c" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }

  // -------
  name = "JID\20Unescaping";
  const std::string f = JID::unescapeNode( "1\\202\\223\\264\\275\\2f6\\3a7\\3c8\\3e9\\4010\\5c" );
  if( f != "1 2\"3&4'5/6:7<8>9@10\\" )
  {
    ++fail;
    fprintf( stderr, "test '%s' failed\n", name.c_str() );
  }










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

}