Changeset - b85749ab7b4f
[Not reviewed]
0 1 0
Sarang Bharadwaj - 13 years ago 2012-07-25 14:12:15
sarang.bh@gmail.com
Changed from convertToChars to Swift::Hexify::hexify to convert SHA1 digest to string of chars
1 file changed with 14 insertions and 11 deletions:
0 comments (0 inline, 0 general)
backends/twitter/TwitterPlugin.cpp
Show inline comments
 
@@ -7,30 +7,32 @@
 
#include "Requests/PINExchangeProcess.h"
 
#include "Requests/OAuthFlow.h"
 
#include "Requests/CreateFriendRequest.h"
 
#include "Requests/DestroyFriendRequest.h"
 
#include "Requests/RetweetRequest.h"
 
#include "Requests/ProfileImageRequest.h"
 
#include "Swiften/StringCodecs/Hexify.h"
 

	
 
DEFINE_LOGGER(logger, "Twitter Backend");
 

	
 
TwitterPlugin *np = NULL;
 
Swift::SimpleEventLoop *loop_; // Event Loop
 

	
 
#define abs(x) ((x)<0?-(x):(x))
 
#define SHA(x) (convertToChars(Swift::byteArrayToString(Swift::SHA1::getHash(Swift::createByteArray((x))))))
 

	
 
static std::string convertToChars(std::string s)
 
{
 
	std::string ret = "";
 
	std::string tab[] = {"0","1","2","3","4","5","6","7",
 
						 "8","9","A","B","C","D","E","F"};
 
	for(int i = 0 ; i < s.size() ; i++)
 
		ret = tab[s[i]>>4&15] + tab[s[i]&15] + ret;
 
	return ret;
 
}
 
//#define SHA(x) (convertToChars(Swift::byteArrayToString(Swift::SHA1::getHash(Swift::createByteArray((x))))))
 
#define SHA(x) (Swift::Hexify::hexify(Swift::SHA1::getHash(Swift::createByteArray((x)))))
 

	
 
//static std::string convertToChars(std::string s)
 
//{
 
//	std::string ret = "";
 
//	std::string tab[] = {"0","1","2","3","4","5","6","7",
 
//						 "8","9","A","B","C","D","E","F"};
 
//	for(int i = 0 ; i < s.size() ; i++)
 
//		ret = tab[s[i]>>4&15] + tab[s[i]&15] + ret;
 
//	return ret;
 
//}
 

	
 
//Compares two +ve intergers 'a' and 'b' represented as strings 
 
static int cmp(std::string a, std::string b)
 
{
 
	int diff = abs((int)a.size() - (int)b.size());
 
	if(a.size() < b.size()) a = std::string(diff,'0') + a;
 
@@ -543,12 +545,13 @@ void TwitterPlugin::populateRoster(std::string &user, std::vector<User> &friends
 
			userdb[user].buddies.insert(friends[i].getScreenName());
 
			userdb[user].buddiesInfo[friends[i].getScreenName()] = friends[i];
 
			userdb[user].buddiesImgs[friends[i].getScreenName()] = friendAvatars[i];
 
			
 
			if(userdb[user].twitterMode == MULTIPLECONTACT) {
 
				std::string lastTweet = friends[i].getLastStatus().getTweet();
 
				//LOG4CXX_INFO(logger, user << " - " << SHA(friendAvatars[i]))
 
				handleBuddyChanged(user, friends[i].getScreenName(), friends[i].getUserName(), std::vector<std::string>(), 
 
								   pbnetwork::STATUS_ONLINE, lastTweet, SHA(friendAvatars[i]));
 
			}
 
			else if(userdb[user].twitterMode == CHATROOM)
 
				handleParticipantChanged(user, friends[i].getScreenName(), adminChatRoom, 0, pbnetwork::STATUS_ONLINE);
 
			
0 comments (0 inline, 0 general)