void jAccount::s_saveVCard(VCard *vcard) { QString hex = ""; const VCard::Photo &photo = vcard->photo(); if(!photo.binval.empty()) { QByteArray data(photo.binval.c_str(),photo.binval.length()); SHA sha; sha.feed(photo.binval); sha.finalize(); hex = jProtocol::fromStd(sha.hex()); } m_jabber_protocol->updateAvatarPresence(hex); m_jabber_protocol->storeVCard(vcard); }
int main( int /*argc*/, char** /*argv*/ ) { int fail = 0; std::string name; SHA sha; // ------- name = "empty string"; sha.feed( "" ); sha.finalize(); if( sha.hex() != "da39a3ee5e6b4b0d3255bfef95601890afd80709" ) { ++fail; fprintf( stderr, "test '%s' failed\n", name.c_str() ); } sha.reset(); // ------- name = "The quick brown fox jumps over the lazy dog"; sha.feed( name ); sha.finalize(); if( sha.hex() != "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() ); } sha.reset(); // ------- name = "The quick brown fox jumps over the lazy cog"; sha.feed( name ); sha.finalize(); if( sha.hex() != "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() ); } sha.reset(); // ------- name = "two-step"; sha.feed( "The quick brown fox " ); sha.feed( "jumps over the lazy dog" ); sha.finalize(); if( sha.hex() != "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() ); } sha.reset(); // ------- name = "54byte string"; sha.feed( std::string( 54, 'x' ) ); sha.finalize(); if( sha.hex() != "31045e7bb077ff8d188a776b196b980388735dbb" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() ); } sha.reset(); // ------- name = "55byte string"; sha.feed( std::string( 55, 'x' ) ); sha.finalize(); if( sha.hex() != "cef734ba81a024479e09eb5a75b6ddae62e6abf1" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() ); } sha.reset(); // ------- name = "56byte string"; sha.feed( std::string( 56, 'x' ) ); sha.finalize(); if( sha.hex() != "901305367c259952f4e7af8323f480d59f81335b" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() ); } sha.reset(); // ------- name = "57byte string"; sha.feed( std::string( 57, 'x' ) ); sha.finalize(); if( sha.hex() != "025ecbd5d70f8fb3c5457cd96bab13fda305dc59" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() ); } sha.reset(); // ------- name = "many-step"; sha.feed( "The" ); sha.feed( " quick bro" ); sha.feed( "" ); sha.feed( "wn fox " ); sha.feed( "jumps over the lazy dog" ); sha.finalize(); if( sha.hex() != "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" ) { ++fail; fprintf( stderr, "test '%s' failed: %s\n", name.c_str(), sha.hex().c_str() ); } sha.reset(); if( fail == 0 ) { printf( "SHA: OK\n" ); return 0; } else { fprintf( stderr, "SHA: %d test(s) failed\n", fail ); return 1; } }
bool NonSaslAuth::handleIqID( Stanza *stanza, int context ) { switch( stanza->subtype() ) { case StanzaIqError: { m_parent->setAuthed( false ); m_parent->disconnect( ConnAuthenticationFailed ); Tag *t = stanza->findChild( "error" ); if( t ) { if( t->hasChild( "conflict" ) || t->hasAttribute( "code", "409" ) ) m_parent->setAuthFailure( NonSaslConflict ); else if( t->hasChild( "not-acceptable" ) || t->hasAttribute( "code", "406" ) ) m_parent->setAuthFailure( NonSaslNotAcceptable ); else if( t->hasChild( "not-authorized" ) || t->hasAttribute( "code", "401" ) ) m_parent->setAuthFailure( NonSaslNotAuthorized ); } break; } case StanzaIqResult: switch( context ) { case TRACK_REQUEST_AUTH_FIELDS: { const std::string& id = m_parent->getID(); Tag *iq = new Tag( "iq" ); iq->addAttribute( "id", id ); iq->addAttribute( "type", "set" ); Tag *query = new Tag( iq, "query" ); query->addAttribute( "xmlns", XMLNS_AUTH ); new Tag( query, "username", m_parent->jid().username() ); new Tag( query, "resource", m_parent->jid().resource() ); Tag *q = stanza->findChild( "query" ); if( ( q->hasChild( "digest" ) ) && !m_sid.empty() ) { SHA sha; sha.feed( m_sid ); sha.feed( m_parent->password() ); sha.finalize(); new Tag( query, "digest", sha.hex() ); } else { new Tag( query, "password", m_parent->password() ); } m_parent->trackID( this, id, TRACK_SEND_AUTH ); m_parent->send( iq ); break; } case TRACK_SEND_AUTH: m_parent->setAuthed( true ); m_parent->connected(); break; } break; default: break; } return false; }