summaryrefslogtreecommitdiff
path: root/protocols/Twitter/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-03-31 16:42:07 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-03-31 16:42:07 +0000
commitd3a10049eee36dc0c451cbed542314a94f62ab3c (patch)
tree546ce7b3a217740e352cb74882ffee4afa0f1f93 /protocols/Twitter/src
parentbebfb51465b364d5673a3f555655213dbff0b2c6 (diff)
Twitter:
- unused module removed; - copyright update; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@12575 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Twitter/src')
-rw-r--r--protocols/Twitter/src/StringUtil.cpp65
-rw-r--r--protocols/Twitter/src/chat.cpp78
-rw-r--r--protocols/Twitter/src/connection.cpp392
-rw-r--r--protocols/Twitter/src/contacts.cpp113
-rw-r--r--protocols/Twitter/src/http.cpp3
-rw-r--r--protocols/Twitter/src/http.h2
-rw-r--r--protocols/Twitter/src/main.cpp17
-rw-r--r--protocols/Twitter/src/oauth.cpp247
-rw-r--r--protocols/Twitter/src/proto.cpp212
-rw-r--r--protocols/Twitter/src/proto.h33
-rw-r--r--protocols/Twitter/src/stdafx.cpp1
-rw-r--r--protocols/Twitter/src/stubs.cpp129
-rw-r--r--protocols/Twitter/src/theme.cpp39
-rw-r--r--protocols/Twitter/src/theme.h1
-rw-r--r--protocols/Twitter/src/twitter.cpp376
-rw-r--r--protocols/Twitter/src/twitter.h1
-rw-r--r--protocols/Twitter/src/ui.cpp13
-rw-r--r--protocols/Twitter/src/ui.h1
-rw-r--r--protocols/Twitter/src/utility.cpp113
-rw-r--r--protocols/Twitter/src/utility.h35
-rw-r--r--protocols/Twitter/src/version.h4
21 files changed, 774 insertions, 1101 deletions
diff --git a/protocols/Twitter/src/StringUtil.cpp b/protocols/Twitter/src/StringUtil.cpp
index a395b67fa7..61cb9adbd2 100644
--- a/protocols/Twitter/src/StringUtil.cpp
+++ b/protocols/Twitter/src/StringUtil.cpp
@@ -29,27 +29,18 @@ void Split(const tstring& str, std::vector<tstring>& out, TCHAR sep, bool includ
unsigned start = 0;
unsigned end = 0;
- while(true)
- {
- if(end == str.size() || str[end] == sep)
- {
- if(end > start || includeEmpty)
- {
+ while (true) {
+ if (end == str.size() || str[end] == sep) {
+ if (end > start || includeEmpty)
out.push_back(str.substr(start, end - start));
- }
- if(end == str.size())
- {
+ if (end == str.size())
break;
- }
++end;
start = end;
}
- else
- {
- ++end;
- }
+ else ++end;
}
}
@@ -60,38 +51,25 @@ tstring GetWord(const tstring& str, unsigned index, bool getRest)
unsigned count = 0;
- while(true)
- {
- if(end == str.size() || str[end] == _T(' '))
- {
- if(end > start)
- {
- if(count == index)
- {
- if(getRest)
- {
+ while (true) {
+ if (end == str.size() || str[end] == _T(' ')) {
+ if (end > start) {
+ if (count == index) {
+ if (getRest)
return str.substr(start);
- }
- else
- {
- return str.substr(start, end - start);
- }
+
+ return str.substr(start, end - start);
}
++count;
}
- if(end == str.size())
- {
+ if (end == str.size())
break;
- }
++end;
start = end;
}
- else
- {
- ++end;
- }
+ else ++end;
}
return _T("");
}
@@ -100,12 +78,11 @@ tstring GetWord(const tstring& str, unsigned index, bool getRest)
// within the string with "to". returns the pointer to the string which is kinda silly IMO
std::string& replaceAll(std::string& context, const std::string& from, const std::string& to)
{
- size_t lookHere = 0;
- size_t foundHere;
- while((foundHere = context.find(from, lookHere)) != std::string::npos)
- {
- context.replace(foundHere, from.size(), to);
- lookHere = foundHere + to.size();
- }
- return context;
+ size_t lookHere = 0;
+ size_t foundHere;
+ while ((foundHere = context.find(from, lookHere)) != std::string::npos) {
+ context.replace(foundHere, from.size(), to);
+ lookHere = foundHere + to.size();
+ }
+ return context;
}
diff --git a/protocols/Twitter/src/chat.cpp b/protocols/Twitter/src/chat.cpp
index e94bdc40e3..30e357a7bc 100644
--- a/protocols/Twitter/src/chat.cpp
+++ b/protocols/Twitter/src/chat.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -35,68 +36,67 @@ void TwitterProto::UpdateChat(const twitter_user &update)
replaceAll(chatText, "%", "%%");
- gce.ptszText = mir_a2t_cp(chatText.c_str(),CP_UTF8);
+ gce.ptszText = mir_a2t_cp(chatText.c_str(), CP_UTF8);
//gce.ptszText = mir_a2t_cp(update.status.text.c_str(),CP_UTF8);
- gce.time = static_cast<DWORD>(update.status.time);
+ gce.time = static_cast<DWORD>(update.status.time);
DBVARIANT nick;
MCONTACT hContact = UsernameToHContact(update.username.c_str());
- if(hContact && !db_get_s(hContact,"CList","MyHandle",&nick))
- {
+ if (hContact && !db_get_s(hContact, "CList", "MyHandle", &nick)) {
gce.ptszNick = mir_a2t(nick.pszVal);
db_free(&nick);
}
else
gce.ptszNick = mir_a2t(update.username.c_str());
- CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
mir_free(const_cast<TCHAR*>(gce.ptszNick));
mir_free(const_cast<TCHAR*>(gce.ptszUID));
mir_free(const_cast<TCHAR*>(gce.ptszText));
}
-int TwitterProto::OnChatOutgoing(WPARAM wParam,LPARAM lParam)
+int TwitterProto::OnChatOutgoing(WPARAM wParam, LPARAM lParam)
{
GCHOOK *hook = reinterpret_cast<GCHOOK*>(lParam);
- if ( strcmp(hook->pDest->pszModule, m_szModuleName))
+ if (strcmp(hook->pDest->pszModule, m_szModuleName))
return 0;
- switch(hook->pDest->iType) {
+ switch (hook->pDest->iType) {
case GC_USER_MESSAGE:
- debugLog( _T("**Chat - Outgoing message: %s"), hook->ptszText);
+ debugLog(_T("**Chat - Outgoing message: %s"), hook->ptszText);
{
- ptrA text( mir_utf8encodeT(hook->ptszText));
+ ptrA text(mir_utf8encodeT(hook->ptszText));
std::string tweet(text);
replaceAll(tweet, "%%", "%"); // the chat plugin will turn "%" into "%%", so we have to change it back :/
- char *varTweet = mir_strdup( tweet.c_str());
+ char *varTweet = mir_strdup(tweet.c_str());
ForkThread(&TwitterProto::SendTweetWorker, varTweet);
}
break;
case GC_USER_PRIVMESS:
- {
- ptrA text( mir_t2a(hook->ptszUID));
- CallService(MS_MSG_SENDMESSAGE, WPARAM(UsernameToHContact(text)), 0);
- }
- break;
+ {
+ ptrA text(mir_t2a(hook->ptszUID));
+ CallService(MS_MSG_SENDMESSAGE, WPARAM(UsernameToHContact(text)), 0);
+ }
+ break;
}
return 0;
}
// TODO: remove nick?
-void TwitterProto::AddChatContact(const char *name,const char *nick)
+void TwitterProto::AddChatContact(const char *name, const char *nick)
{
GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_JOIN };
GCEVENT gce = { sizeof(gce), &gcd };
gce.time = DWORD(time(0));
- gce.ptszNick = mir_a2t(nick ? nick:name);
+ gce.ptszNick = mir_a2t(nick ? nick : name);
gce.ptszUID = mir_a2t(name);
gce.ptszStatus = _T("Normal");
- CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
mir_free(const_cast<TCHAR*>(gce.ptszNick));
mir_free(const_cast<TCHAR*>(gce.ptszUID));
@@ -109,12 +109,12 @@ void TwitterProto::DeleteChatContact(const char *name)
gce.time = DWORD(time(0));
gce.ptszNick = mir_a2t(name);
gce.ptszUID = gce.ptszNick;
- CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
mir_free(const_cast<TCHAR*>(gce.ptszNick));
}
-INT_PTR TwitterProto::OnJoinChat(WPARAM,LPARAM suppress)
+INT_PTR TwitterProto::OnJoinChat(WPARAM, LPARAM suppress)
{
// ***** Create the group chat session
GCSESSION gcw = { sizeof(gcw) };
@@ -124,35 +124,35 @@ INT_PTR TwitterProto::OnJoinChat(WPARAM,LPARAM suppress)
gcw.ptszID = m_tszUserName;
CallServiceSync(MS_GC_NEWSESSION, 0, (LPARAM)&gcw);
- if(m_iStatus != ID_STATUS_ONLINE)
+ if (m_iStatus != ID_STATUS_ONLINE)
return 0;
// ***** Create a group
GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_ADDGROUP };
GCEVENT gce = { sizeof(gce), &gcd };
gce.ptszStatus = _T("Normal");
- CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
// ***** Hook events
HookProtoEvent(ME_GC_EVENT, &TwitterProto::OnChatOutgoing);
// Note: Initialization will finish up in SetChatStatus, called separately
- if(!suppress)
+ if (!suppress)
SetChatStatus(m_iStatus);
in_chat_ = true;
return 0;
}
-INT_PTR TwitterProto::OnLeaveChat(WPARAM,LPARAM)
+INT_PTR TwitterProto::OnLeaveChat(WPARAM, LPARAM)
{
in_chat_ = false;
GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_CONTROL };
GCEVENT gce = { sizeof(gce), &gcd };
- CallServiceSync(MS_GC_EVENT,SESSION_OFFLINE, reinterpret_cast<LPARAM>(&gce));
- CallServiceSync(MS_GC_EVENT,SESSION_TERMINATE,reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, SESSION_OFFLINE, reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, SESSION_TERMINATE, reinterpret_cast<LPARAM>(&gce));
return 0;
}
@@ -161,20 +161,18 @@ void TwitterProto::SetChatStatus(int status)
GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_CONTROL };
GCEVENT gce = { sizeof(gce), &gcd };
- if(status == ID_STATUS_ONLINE)
- {
+ if (status == ID_STATUS_ONLINE) {
// Add all friends to contact list
- for(MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- if( isChatRoom(hContact))
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ if (isChatRoom(hContact))
continue;
- DBVARIANT uid,nick;
- if(db_get_s(hContact,m_szModuleName,TWITTER_KEY_UN,&uid))
+ DBVARIANT uid, nick;
+ if (db_get_s(hContact, m_szModuleName, TWITTER_KEY_UN, &uid))
continue;
- if(!db_get_s(hContact,"CList","MyHandle",&nick))
- {
- AddChatContact(uid.pszVal,nick.pszVal);
+ if (!db_get_s(hContact, "CList", "MyHandle", &nick)) {
+ AddChatContact(uid.pszVal, nick.pszVal);
db_free(&nick);
}
else
@@ -185,9 +183,9 @@ void TwitterProto::SetChatStatus(int status)
// For some reason, I have to send an INITDONE message, even if I'm not actually
// initializing the room...
- CallServiceSync(MS_GC_EVENT,SESSION_INITDONE,reinterpret_cast<LPARAM>(&gce));
- CallServiceSync(MS_GC_EVENT,SESSION_ONLINE, reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, SESSION_INITDONE, reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, reinterpret_cast<LPARAM>(&gce));
}
else
- CallServiceSync(MS_GC_EVENT,SESSION_OFFLINE,reinterpret_cast<LPARAM>(&gce));
-} \ No newline at end of file
+ CallServiceSync(MS_GC_EVENT, SESSION_OFFLINE, reinterpret_cast<LPARAM>(&gce));
+}
diff --git a/protocols/Twitter/src/connection.cpp b/protocols/Twitter/src/connection.cpp
index a0b990dfc1..2db1d892b9 100644
--- a/protocols/Twitter/src/connection.cpp
+++ b/protocols/Twitter/src/connection.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -25,23 +26,23 @@ void CALLBACK TwitterProto::APC_callback(ULONG_PTR p)
}
template<typename T>
-inline static T db_pod_get(MCONTACT hContact,const char *module,const char *setting,T errorValue)
+inline static T db_pod_get(MCONTACT hContact, const char *module, const char *setting, T errorValue)
{
DBVARIANT dbv;
- if(db_get(hContact, module, setting, &dbv))
+ if (db_get(hContact, module, setting, &dbv))
return errorValue;
// TODO: remove this, it's just a temporary workaround
- if(dbv.type == DBVT_DWORD)
+ if (dbv.type == DBVT_DWORD)
return dbv.dVal;
- if(dbv.cpbVal != sizeof(T))
+ if (dbv.cpbVal != sizeof(T))
return errorValue;
return *reinterpret_cast<T*>(dbv.pbVal);
}
template<typename T>
-inline static INT_PTR db_pod_set(MCONTACT hContact,const char *module,const char *setting,T val)
+inline static INT_PTR db_pod_set(MCONTACT hContact, const char *module, const char *setting, T val)
{
return db_set_blob(hContact, module, setting, &val, sizeof(T));
}
@@ -49,29 +50,27 @@ inline static INT_PTR db_pod_set(MCONTACT hContact,const char *module,const char
void TwitterProto::SignOn(void*)
{
debugLogA("***** Beginning SignOn process");
- WaitForSingleObject(&signon_lock_,INFINITE);
+ mir_cslock lck(signon_lock_);
// Kill the old thread if it's still around
// this doesn't seem to work.. should we wait infinitely?
- if(hMsgLoop_)
- {
+ if (hMsgLoop_) {
debugLogA("***** Requesting MessageLoop to exit");
- QueueUserAPC(APC_callback,hMsgLoop_,(ULONG_PTR)this);
+ QueueUserAPC(APC_callback, hMsgLoop_, (ULONG_PTR)this);
debugLogA("***** Waiting for old MessageLoop to exit");
//WaitForSingleObject(hMsgLoop_,INFINITE);
- WaitForSingleObject(hMsgLoop_,180000);
+ WaitForSingleObject(hMsgLoop_, 180000);
CloseHandle(hMsgLoop_);
}
- if(NegotiateConnection()) // Could this be? The legendary Go Time??
+ if (NegotiateConnection()) // Could this be? The legendary Go Time??
{
- if(!in_chat_ && db_get_b(0,m_szModuleName,TWITTER_KEY_CHATFEED,0))
- OnJoinChat(0,true);
-
+ if (!in_chat_ && db_get_b(0, m_szModuleName, TWITTER_KEY_CHATFEED, 0))
+ OnJoinChat(0, true);
+
SetAllContactStatuses(ID_STATUS_ONLINE);
hMsgLoop_ = ForkThreadEx(&TwitterProto::MessageLoop, NULL, 0);
}
- ReleaseMutex(signon_lock_);
debugLogA("***** SignOn complete");
}
@@ -85,50 +84,50 @@ bool TwitterProto::NegotiateConnection()
DBVARIANT dbv;
wstring oauthToken;
- wstring oauthTokenSecret;
+ wstring oauthTokenSecret;
wstring oauthAccessToken;
wstring oauthAccessTokenSecret;
string screenName;
- INT_PTR dbTOK = db_get_ws(0,m_szModuleName,TWITTER_KEY_OAUTH_TOK,&dbv);
+ INT_PTR dbTOK = db_get_ws(0, m_szModuleName, TWITTER_KEY_OAUTH_TOK, &dbv);
if (!dbTOK) {
oauthToken = dbv.pwszVal;
db_free(&dbv);
//debugLogW("**NegotiateConnection - we have an oauthToken already in the db - %s", oauthToken);
}
-
- INT_PTR dbTOKSec = db_get_ws(0,m_szModuleName,TWITTER_KEY_OAUTH_TOK_SECRET,&dbv);
+
+ INT_PTR dbTOKSec = db_get_ws(0, m_szModuleName, TWITTER_KEY_OAUTH_TOK_SECRET, &dbv);
if (!dbTOKSec) {
oauthTokenSecret = dbv.pwszVal;
db_free(&dbv);
//debugLogW("**NegotiateConnection - we have an oauthTokenSecret already in the db - %s", oauthTokenSecret);
}
- INT_PTR dbName = db_get_s(0,m_szModuleName,TWITTER_KEY_NICK,&dbv);
+ INT_PTR dbName = db_get_s(0, m_szModuleName, TWITTER_KEY_NICK, &dbv);
if (!dbName) {
screenName = dbv.pszVal;
db_free(&dbv);
//debugLogW("**NegotiateConnection - we have a username already in the db - %s", screenName);
}
else {
- dbName = db_get_s(0,m_szModuleName,TWITTER_KEY_UN,&dbv);
+ dbName = db_get_s(0, m_szModuleName, TWITTER_KEY_UN, &dbv);
if (!dbName) {
screenName = dbv.pszVal;
- db_set_s(0,m_szModuleName,TWITTER_KEY_NICK,dbv.pszVal);
+ db_set_s(0, m_szModuleName, TWITTER_KEY_NICK, dbv.pszVal);
db_free(&dbv);
//debugLogW("**NegotiateConnection - we have a username already in the db - %s", screenName);
}
}
- // twitter changed the base URL in v1.1 of the API, I don't think users will need to modify it, so
+ // twitter changed the base URL in v1.1 of the API, I don't think users will need to modify it, so
// i'll be forcing it to the new API URL here. After a while I can get rid of this as users will
// have either had this run at least once, or have reset their miranda profile. 14/10/2012
- if(db_get_b(0,m_szModuleName,"UpgradeBaseURL",1)) {
- db_set_s(0,m_szModuleName,TWITTER_KEY_BASEURL,"https://api.twitter.com/");
- db_set_b(0,m_szModuleName,"UpgradeBaseURL",0);
+ if (db_get_b(0, m_szModuleName, "UpgradeBaseURL", 1)) {
+ db_set_s(0, m_szModuleName, TWITTER_KEY_BASEURL, "https://api.twitter.com/");
+ db_set_b(0, m_szModuleName, "UpgradeBaseURL", 0);
}
- if((oauthToken.size() <= 1) || (oauthTokenSecret.size() <= 1)) {
+ if ((oauthToken.size() <= 1) || (oauthTokenSecret.size() <= 1)) {
// first, reset all the keys so we can start fresh
resetOAuthKeys();
debugLogA("**NegotiateConnection - Reset OAuth Keys");
@@ -163,46 +162,46 @@ bool TwitterProto::NegotiateConnection()
}
//write those bitches to the db foe latta
- db_set_ws(0,m_szModuleName,TWITTER_KEY_OAUTH_TOK,oauthToken.c_str());
- db_set_ws(0,m_szModuleName,TWITTER_KEY_OAUTH_TOK_SECRET,oauthTokenSecret.c_str());
-
+ db_set_ws(0, m_szModuleName, TWITTER_KEY_OAUTH_TOK, oauthToken.c_str());
+ db_set_ws(0, m_szModuleName, TWITTER_KEY_OAUTH_TOK_SECRET, oauthTokenSecret.c_str());
+
// this looks like bad code.. can someone clean this up please? or confirm that it's ok
wchar_t buf[1024] = {};
mir_snwprintf(buf, SIZEOF(buf), AuthorizeUrl.c_str(), oauthToken.c_str());
- debugLogW( _T("**NegotiateConnection - Launching %s"), buf);
+ debugLogW(_T("**NegotiateConnection - Launching %s"), buf);
ShellExecute(NULL, L"open", buf, NULL, NULL, SW_SHOWNORMAL);
-
+
ShowPinDialog();
}
- if (!db_get_ts(NULL,m_szModuleName,TWITTER_KEY_GROUP,&dbv)) {
- CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)dbv.ptszVal );
- db_free(&dbv);
+ if (!db_get_ts(NULL, m_szModuleName, TWITTER_KEY_GROUP, &dbv)) {
+ CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)dbv.ptszVal);
+ db_free(&dbv);
}
bool realAccessTok = false;
bool realAccessTokSecret = false;
// remember, dbTOK is 0 (false) if the db setting has returned something
- dbTOK = db_get_ws(0,m_szModuleName,TWITTER_KEY_OAUTH_ACCESS_TOK,&dbv);
- if (!dbTOK) {
+ dbTOK = db_get_ws(0, m_szModuleName, TWITTER_KEY_OAUTH_ACCESS_TOK, &dbv);
+ if (!dbTOK) {
oauthAccessToken = dbv.pwszVal;
db_free(&dbv);
// this bit is saying "if we have found the db key, but it contains no data, then set dbTOK to 1"
- if (oauthAccessToken.size() > 1) {
- realAccessTok = true;
+ if (oauthAccessToken.size() > 1) {
+ realAccessTok = true;
//debugLogW("**NegotiateConnection - we have an oauthAccessToken already in the db - %s", oauthAccessToken);
}
else { debugLogA("**NegotiateConnection - oauthAccesToken too small? this is.. weird."); }
}
- dbTOKSec = db_get_ws(0,m_szModuleName,TWITTER_KEY_OAUTH_ACCESS_TOK_SECRET,&dbv);
- if (!dbTOKSec) {
+ dbTOKSec = db_get_ws(0, m_szModuleName, TWITTER_KEY_OAUTH_ACCESS_TOK_SECRET, &dbv);
+ if (!dbTOKSec) {
oauthAccessTokenSecret = dbv.pwszVal;
db_free(&dbv);
- if (oauthAccessTokenSecret.size() > 1) {
- realAccessTokSecret = true;
+ if (oauthAccessTokenSecret.size() > 1) {
+ realAccessTokSecret = true;
//debugLogW("**NegotiateConnection - we have an oauthAccessTokenSecret already in the db - %s", oauthAccessTokenSecret);
}
else { debugLogA("**NegotiateConnection - oauthAccessTokenSecret too small? weird"); }
@@ -211,7 +210,7 @@ bool TwitterProto::NegotiateConnection()
if (!realAccessTok || !realAccessTokSecret) { // if we don't have one of these beasties then lets go get 'em!
wstring pin;
debugLogA("**NegotiateConnection - either the accessToken or accessTokenSecret was not there..");
- if (!db_get_ws(0,m_szModuleName,TWITTER_KEY_OAUTH_PIN,&dbv)) {
+ if (!db_get_ws(0, m_szModuleName, TWITTER_KEY_OAUTH_PIN, &dbv)) {
pin = dbv.pwszVal;
//debugLogW("**NegotiateConnection - we have an pin already in the db - %s", pin);
db_free(&dbv);
@@ -221,12 +220,12 @@ bool TwitterProto::NegotiateConnection()
debugLogA("**NegotiateConnection - We don't have a PIN? this doesn't make sense. Resetting OAuth keys and setting offline.");
resetOAuthKeys();
- ProtoBroadcastAck(0,ACKTYPE_STATUS,ACKRESULT_FAILED,(HANDLE)old_status,m_iStatus);
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_FAILED, (HANDLE)old_status, m_iStatus);
// Set to offline
old_status = m_iStatus;
m_iDesiredStatus = m_iStatus = ID_STATUS_OFFLINE;
- ProtoBroadcastAck(0,ACKTYPE_STATUS,ACKRESULT_SUCCESS,(HANDLE)old_status,m_iStatus);
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
return false;
}
@@ -248,12 +247,12 @@ bool TwitterProto::NegotiateConnection()
resetOAuthKeys();
- ProtoBroadcastAck(0,ACKTYPE_STATUS,ACKRESULT_FAILED,(HANDLE)old_status,m_iStatus);
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_FAILED, (HANDLE)old_status, m_iStatus);
// Set to offline
old_status = m_iStatus;
m_iDesiredStatus = m_iStatus = ID_STATUS_OFFLINE;
- ProtoBroadcastAck(0,ACKTYPE_STATUS,ACKRESULT_SUCCESS,(HANDLE)old_status,m_iStatus);
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
return false;
}
@@ -262,7 +261,7 @@ bool TwitterProto::NegotiateConnection()
wstring rdata_WSTR2 = UTF8ToWide(accessResp.data);
//debugLogW("**NegotiateConnection - accessToken STring is %s", rdata_WSTR2);
-
+
OAuthParameters accessTokenParameters = twit_.ParseQueryString(rdata_WSTR2);
oauthAccessToken = accessTokenParameters[L"oauth_token"];
@@ -273,29 +272,28 @@ bool TwitterProto::NegotiateConnection()
screenName = WideToUTF8(accessTokenParameters[L"screen_name"]);
debugLogA("**NegotiateConnection - screen name is %s", screenName.c_str());
-
+
//save em
- db_set_ws(0,m_szModuleName,TWITTER_KEY_OAUTH_ACCESS_TOK,oauthAccessToken.c_str());
- db_set_ws(0,m_szModuleName,TWITTER_KEY_OAUTH_ACCESS_TOK_SECRET,oauthAccessTokenSecret.c_str());
- db_set_s(0,m_szModuleName,TWITTER_KEY_NICK,screenName.c_str());
- db_set_s(0,m_szModuleName,TWITTER_KEY_UN,screenName.c_str());
+ db_set_ws(0, m_szModuleName, TWITTER_KEY_OAUTH_ACCESS_TOK, oauthAccessToken.c_str());
+ db_set_ws(0, m_szModuleName, TWITTER_KEY_OAUTH_ACCESS_TOK_SECRET, oauthAccessTokenSecret.c_str());
+ db_set_s(0, m_szModuleName, TWITTER_KEY_NICK, screenName.c_str());
+ db_set_s(0, m_szModuleName, TWITTER_KEY_UN, screenName.c_str());
}
}
-/* if( !db_get_s(0,m_szModuleName,TWITTER_KEY_PASS,&dbv)) {
- CallService(MS_DB_CRYPT_DECODESTRING,strlen(dbv.pszVal)+1,
+ /* if( !db_get_s(0,m_szModuleName,TWITTER_KEY_PASS,&dbv)) {
+ CallService(MS_DB_CRYPT_DECODESTRING,strlen(dbv.pszVal)+1,
reinterpret_cast<LPARAM>(dbv.pszVal));
- pass = dbv.pszVal;
- db_free(&dbv);
- }
- else {
- ShowPopup(TranslateT("Please enter a password."));
- return false;
- }*/
+ pass = dbv.pszVal;
+ db_free(&dbv);
+ }
+ else {
+ ShowPopup(TranslateT("Please enter a password."));
+ return false;
+ }*/
- if( !db_get_s(0,m_szModuleName,TWITTER_KEY_BASEURL,&dbv))
- {
- ScopedLock s(twitter_lock_);
+ if (!db_get_s(0, m_szModuleName, TWITTER_KEY_BASEURL, &dbv)) {
+ mir_cslock s(twitter_lock_);
twit_.set_base_url(dbv.pszVal);
db_free(&dbv);
}
@@ -308,30 +306,30 @@ bool TwitterProto::NegotiateConnection()
}
bool success;
- {
- ScopedLock s(twitter_lock_);
+ {
+ mir_cslock s(twitter_lock_);
success = twit_.set_credentials(screenName, ConsumerKey, ConsumerSecret, oauthAccessToken, oauthAccessTokenSecret, L"", true);
}
- if(!success) {
+ if (!success) {
//ShowPopup(TranslateT("Something went wrong with authorization, OAuth keys have been reset. Please try to reconnect. If problems persist, please se your doctor"));
debugLogA("**NegotiateConnection - Verifying credentials failed! No internet maybe?");
//resetOAuthKeys();
- ProtoBroadcastAck(0,ACKTYPE_STATUS,ACKRESULT_FAILED,(HANDLE)old_status,m_iStatus);
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_FAILED, (HANDLE)old_status, m_iStatus);
// Set to offline
old_status = m_iStatus;
m_iDesiredStatus = m_iStatus = ID_STATUS_OFFLINE;
- ProtoBroadcastAck(0,ACKTYPE_STATUS,ACKRESULT_SUCCESS,(HANDLE)old_status,m_iStatus);
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
return false;
}
else {
m_iStatus = m_iDesiredStatus;
- ProtoBroadcastAck(0,ACKTYPE_STATUS,ACKRESULT_SUCCESS,(HANDLE)old_status,m_iStatus);
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
return true;
}
}
@@ -341,45 +339,44 @@ void TwitterProto::MessageLoop(void*)
{
debugLogA("***** Entering Twitter::MessageLoop");
- since_id_ = db_pod_get<twitter_id>(0,m_szModuleName,TWITTER_KEY_SINCEID,0);
- dm_since_id_ = db_pod_get<twitter_id>(0,m_szModuleName,TWITTER_KEY_DMSINCEID,0);
+ since_id_ = db_pod_get<twitter_id>(0, m_szModuleName, TWITTER_KEY_SINCEID, 0);
+ dm_since_id_ = db_pod_get<twitter_id>(0, m_szModuleName, TWITTER_KEY_DMSINCEID, 0);
- bool new_account = db_get_b(0,m_szModuleName,TWITTER_KEY_NEW,1) != 0;
- bool popups = db_get_b(0,m_szModuleName,TWITTER_KEY_POPUP_SIGNON,1) != 0;
+ bool new_account = db_get_b(0, m_szModuleName, TWITTER_KEY_NEW, 1) != 0;
+ bool popups = db_get_b(0, m_szModuleName, TWITTER_KEY_POPUP_SIGNON, 1) != 0;
// if this isn't set, it will automatically not turn a tweet into a msg. probably should make the default that it does turn a tweet into a message
- bool tweetToMsg = db_get_b(0,m_szModuleName,TWITTER_KEY_TWEET_TO_MSG,0) != 0;
+ bool tweetToMsg = db_get_b(0, m_szModuleName, TWITTER_KEY_TWEET_TO_MSG, 0) != 0;
- int poll_rate = db_get_dw(0,m_szModuleName,TWITTER_KEY_POLLRATE,80);
+ int poll_rate = db_get_dw(0, m_szModuleName, TWITTER_KEY_POLLRATE, 80);
- for(unsigned int i=0;;i++)
- {
+ for (unsigned int i = 0;; i++) {
- if(m_iStatus != ID_STATUS_ONLINE)
+ if (m_iStatus != ID_STATUS_ONLINE)
break;
-// if(i%10 == 0)
-// UpdateFriends();
+ // if(i%10 == 0)
+ // UpdateFriends();
- if(m_iStatus != ID_STATUS_ONLINE)
+ if (m_iStatus != ID_STATUS_ONLINE)
break;
- UpdateStatuses(new_account,popups, tweetToMsg);
+ UpdateStatuses(new_account, popups, tweetToMsg);
- if(m_iStatus != ID_STATUS_ONLINE)
+ if (m_iStatus != ID_STATUS_ONLINE)
break;
-
- if(i%10 == 0)
+
+ if (i % 10 == 0)
UpdateMessages(new_account);
- if(new_account) // Not anymore!
+ if (new_account) // Not anymore!
{
new_account = false;
- db_set_b(0,m_szModuleName,TWITTER_KEY_NEW,0);
+ db_set_b(0, m_szModuleName, TWITTER_KEY_NEW, 0);
}
- if(m_iStatus != ID_STATUS_ONLINE)
+ if (m_iStatus != ID_STATUS_ONLINE)
break;
debugLogA("***** TwitterProto::MessageLoop going to sleep...");
- if(SleepEx(poll_rate*1000,true) == WAIT_IO_COMPLETION)
+ if (SleepEx(poll_rate * 1000, true) == WAIT_IO_COMPLETION)
break;
debugLogA("***** TwitterProto::MessageLoop waking up...");
@@ -387,15 +384,15 @@ void TwitterProto::MessageLoop(void*)
}
{
- ScopedLock s(twitter_lock_);
- twit_.set_credentials("",L"",L"",L"",L"",L"", false);
+ mir_cslock s(twitter_lock_);
+ twit_.set_credentials("", L"", L"", L"", L"", L"", false);
}
debugLogA("***** Exiting TwitterProto::MessageLoop");
}
struct update_avatar
{
- update_avatar(MCONTACT hContact,const std::string &url) : hContact(hContact),url(url) {}
+ update_avatar(MCONTACT hContact, const std::string &url) : hContact(hContact), url(url) {}
MCONTACT hContact;
std::string url;
};
@@ -403,22 +400,22 @@ struct update_avatar
/* void *p should always be a struct of type update_avatar */
void TwitterProto::UpdateAvatarWorker(void *p)
{
- if(p == 0)
+ if (p == 0)
return;
- std::auto_ptr<update_avatar> data( static_cast<update_avatar*>(p));
- DBVARIANT dbv = {0};
+ std::auto_ptr<update_avatar> data(static_cast<update_avatar*>(p));
+ DBVARIANT dbv = { 0 };
// db_get_s returns 0 when it suceeds, so if this suceeds it will return 0, or false.
// therefore if it returns 1, or true, we want to return as there is no such user.
// as a side effect, dbv now has the username in it i think
- if(db_get_ts(data->hContact,m_szModuleName,TWITTER_KEY_UN,&dbv))
+ if (db_get_ts(data->hContact, m_szModuleName, TWITTER_KEY_UN, &dbv))
return;
std::string ext = data->url.substr(data->url.rfind('.')); // finds the filetype of the avatar
std::tstring filename = GetAvatarFolder() + _T('\\') + dbv.ptszVal + (TCHAR*)_A2T(ext.c_str()); // local filename and path
db_free(&dbv);
- PROTO_AVATAR_INFORMATIONT ai = {sizeof(ai)};
+ PROTO_AVATAR_INFORMATIONT ai = { sizeof(ai) };
ai.hContact = data->hContact;
ai.format = ProtoGetAvatarFormat(filename.c_str());
@@ -426,11 +423,12 @@ void TwitterProto::UpdateAvatarWorker(void *p)
debugLogA("***** Update avatar: Terminated for this contact, extension format unknown for %s", data->url.c_str());
return; // lets just ignore unknown formats... if not it crashes miranda. should probably speak to borkra about this.
}
-
- _tcsncpy(ai.filename,filename.c_str(),MAX_PATH); // puts the local file name in the avatar struct, to a max of 260 chars (as of now)
+
+ _tcsncpy(ai.filename, filename.c_str(), MAX_PATH); // puts the local file name in the avatar struct, to a max of 260 chars (as of now)
debugLogA("***** Updating avatar: %s", data->url.c_str());
- WaitForSingleObjectEx(avatar_lock_,INFINITE,true);
+ mir_cslock lck(avatar_lock_);
+
if (CallService(MS_SYSTEM_TERMINATED, 0, 0)) // if miranda is shutting down...
{
debugLogA("***** Terminating avatar update early: %s", data->url.c_str());
@@ -442,32 +440,27 @@ void TwitterProto::UpdateAvatarWorker(void *p)
ProtoBroadcastAck(data->hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &ai, 0);
}
else ProtoBroadcastAck(data->hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, &ai, 0);
-
- ReleaseMutex(avatar_lock_);
+
debugLogA("***** Done avatar: %s", data->url.c_str());
}
-void TwitterProto::UpdateAvatar(MCONTACT hContact,const std::string &url,bool force)
+void TwitterProto::UpdateAvatar(MCONTACT hContact, const std::string &url, bool force)
{
- DBVARIANT dbv = {0};
+ DBVARIANT dbv = { 0 };
- if( !force && (!db_get_s(hContact,m_szModuleName,TWITTER_KEY_AV_URL,&dbv) && url == dbv.pszVal))
- {
+ if (!force && (!db_get_s(hContact, m_szModuleName, TWITTER_KEY_AV_URL, &dbv) && url == dbv.pszVal)) {
debugLogA("***** Avatar already up-to-date: %s", url.c_str());
}
- else
- {
+ else {
// TODO: more defaults (configurable?)
- if(url == "http://static.twitter.com/images/default_profile_normal.png")
- {
- PROTO_AVATAR_INFORMATIONT ai = {sizeof(ai),hContact};
-
- db_set_s(hContact,m_szModuleName,TWITTER_KEY_AV_URL,url.c_str());
- ProtoBroadcastAck(hContact,ACKTYPE_AVATAR,ACKRESULT_SUCCESS,&ai,0);
+ if (url == "http://static.twitter.com/images/default_profile_normal.png") {
+ PROTO_AVATAR_INFORMATIONT ai = { sizeof(ai), hContact };
+
+ db_set_s(hContact, m_szModuleName, TWITTER_KEY_AV_URL, url.c_str());
+ ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &ai, 0);
}
- else
- {
- ForkThread(&TwitterProto::UpdateAvatarWorker, new update_avatar(hContact,url));
+ else {
+ ForkThread(&TwitterProto::UpdateAvatarWorker, new update_avatar(hContact, url));
}
}
@@ -476,24 +469,24 @@ void TwitterProto::UpdateAvatar(MCONTACT hContact,const std::string &url,bool fo
void TwitterProto::UpdateFriends()
{
- try
- {
- ScopedLock s(twitter_lock_);
- std::vector<twitter_user> friends = twit_.get_friends();
- s.Unlock();
- for(std::vector<twitter_user>::iterator i=friends.begin(); i!=friends.end(); ++i)
+ try {
+ std::vector<twitter_user> friends;
{
- if(i->username == twit_.get_username())
+ mir_cslock s(twitter_lock_);
+ friends = twit_.get_friends();
+ }
+
+ for (std::vector<twitter_user>::iterator i = friends.begin(); i != friends.end(); ++i) {
+ if (i->username == twit_.get_username())
continue;
- MCONTACT hContact = AddToClientList(i->username.c_str(),i->status.text.c_str());
- UpdateAvatar(hContact,i->profile_image_url);
+ MCONTACT hContact = AddToClientList(i->username.c_str(), i->status.text.c_str());
+ UpdateAvatar(hContact, i->profile_image_url);
}
- disconnectionCount = 0;
+ disconnectionCount = 0;
debugLogA("***** Friends list updated");
}
- catch(const bad_response &)
- {
+ catch (const bad_response &) {
++disconnectionCount;
debugLogA("***** UpdateFriends - Bad response from server, this has happened %d time(s)", disconnectionCount);
if (disconnectionCount > 2) {
@@ -501,69 +494,61 @@ void TwitterProto::UpdateFriends()
SetStatus(ID_STATUS_OFFLINE);
}
}
- catch(const std::exception &e)
- {
- ShowPopup( (std::string("While updating friends list, an error occurred: ")+e.what()).c_str());
+ catch (const std::exception &e) {
+ ShowPopup((std::string("While updating friends list, an error occurred: ") + e.what()).c_str());
debugLogA("***** Error updating friends list: %s", e.what());
}
-
}
-
LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch (message)
- {
+ std::string *url;
+
+ switch (message) {
case WM_COMMAND:
- {
// Get the plugin data (we need the Popup service to do it)
- std::string *url = (std::string *)PUGetPluginData(hwnd);
+ url = (std::string *)PUGetPluginData(hwnd);
if (url != NULL) {
//std::string url = profile_base_url("https://twitter.com/") + http::url_encode(dbv.pszVal);
CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, reinterpret_cast<LPARAM>(url->c_str()));
}
// Intentionally no break here
- }
+
case WM_CONTEXTMENU:
- {
// After a click, destroy popup
PUDeletePopup(hwnd);
return TRUE;
- }
+
case UM_FREEPLUGINDATA:
- {
// After close, free
- std::string *url = (std::string *)PUGetPluginData(hwnd);
+ url = (std::string *)PUGetPluginData(hwnd);
delete url;
return FALSE;
}
- }
return DefWindowProc(hwnd, message, wParam, lParam);
};
-void TwitterProto::ShowContactPopup(MCONTACT hContact,const std::string &text,const std::string *url)
+void TwitterProto::ShowContactPopup(MCONTACT hContact, const std::string &text, const std::string *url)
{
- if(!ServiceExists(MS_POPUP_ADDPOPUPT) || db_get_b(0,m_szModuleName,TWITTER_KEY_POPUP_SHOW,0) == 0)
- {
+ if (!ServiceExists(MS_POPUP_ADDPOPUPT) || db_get_b(0, m_szModuleName, TWITTER_KEY_POPUP_SHOW, 0) == 0) {
return;
}
POPUPDATAT popup = {};
popup.lchContact = hContact;
- popup.iSeconds = db_get_dw(0,m_szModuleName,TWITTER_KEY_POPUP_TIMEOUT,0);
-
- popup.colorBack = db_get_dw(0,m_szModuleName,TWITTER_KEY_POPUP_COLBACK,0);
- if(popup.colorBack == 0xFFFFFFFF)
+ popup.iSeconds = db_get_dw(0, m_szModuleName, TWITTER_KEY_POPUP_TIMEOUT, 0);
+
+ popup.colorBack = db_get_dw(0, m_szModuleName, TWITTER_KEY_POPUP_COLBACK, 0);
+ if (popup.colorBack == 0xFFFFFFFF)
popup.colorBack = GetSysColor(COLOR_WINDOW);
- popup.colorText = db_get_dw(0,m_szModuleName,TWITTER_KEY_POPUP_COLTEXT,0);
- if(popup.colorBack == 0xFFFFFFFF)
+ popup.colorText = db_get_dw(0, m_szModuleName, TWITTER_KEY_POPUP_COLTEXT, 0);
+ if (popup.colorBack == 0xFFFFFFFF)
popup.colorBack = GetSysColor(COLOR_WINDOWTEXT);
DBVARIANT dbv;
- if( !db_get_ts(hContact,"CList","MyHandle",&dbv) || !db_get_ts(hContact,m_szModuleName,TWITTER_KEY_UN,&dbv))
- {
- _tcsncpy(popup.lptzContactName,dbv.ptszVal,MAX_CONTACTNAME);
+ if (!db_get_ts(hContact, "CList", "MyHandle", &dbv) || !db_get_ts(hContact, m_szModuleName, TWITTER_KEY_UN, &dbv)) {
+ _tcsncpy(popup.lptzContactName, dbv.ptszVal, MAX_CONTACTNAME);
db_free(&dbv);
}
@@ -572,38 +557,38 @@ void TwitterProto::ShowContactPopup(MCONTACT hContact,const std::string &text,co
popup.PluginData = (void *)url;
}
- mbcs_to_tcs(CP_UTF8,text.c_str(),popup.lptzText,MAX_SECONDLINE);
+ mbcs_to_tcs(CP_UTF8, text.c_str(), popup.lptzText, MAX_SECONDLINE);
PUAddPopupT(&popup);
}
void TwitterProto::UpdateStatuses(bool pre_read, bool popups, bool tweetToMsg)
{
- try
- {
- ScopedLock s(twitter_lock_);
- twitter::status_list updates = twit_.get_statuses(200,since_id_);
- s.Unlock();
- if(!updates.empty()) {
- since_id_ = std::max(since_id_, updates[0].status.id);
+ try {
+ twitter::status_list updates;
+ {
+ mir_cslock s(twitter_lock_);
+ updates = twit_.get_statuses(200, since_id_);
}
- for(twitter::status_list::reverse_iterator i=updates.rbegin(); i!=updates.rend(); ++i)
- {
+ if (!updates.empty())
+ since_id_ = std::max(since_id_, updates[0].status.id);
- if(!pre_read && in_chat_)
+ for (twitter::status_list::reverse_iterator i = updates.rbegin(); i != updates.rend(); ++i) {
+
+ if (!pre_read && in_chat_)
UpdateChat(*i);
- if(i->username == twit_.get_username())
+ if (i->username == twit_.get_username())
continue;
- MCONTACT hContact = AddToClientList(i->username.c_str(),"");
- UpdateAvatar(hContact,i->profile_image_url); // as UpdateFriends() doesn't work at the moment, i'm going to update the avatars here
+ MCONTACT hContact = AddToClientList(i->username.c_str(), "");
+ UpdateAvatar(hContact, i->profile_image_url); // as UpdateFriends() doesn't work at the moment, i'm going to update the avatars here
// i think we maybe should just do that DBEF_READ line instead of stopping ALL this code. have to test.
if (tweetToMsg) {
- DBEVENTINFO dbei = {sizeof(dbei)};
+ DBEVENTINFO dbei = { sizeof(dbei) };
dbei.pBlob = (BYTE*)(i->status.text.c_str());
- dbei.cbBlob = (int)i->status.text.size()+1;
+ dbei.cbBlob = (int)i->status.text.size() + 1;
dbei.eventType = TWITTER_DB_EVENT_TYPE_TWEET;
dbei.flags = DBEF_UTF | DBEF_READ;
dbei.timestamp = static_cast<DWORD>(i->status.time);
@@ -611,7 +596,7 @@ void TwitterProto::UpdateStatuses(bool pre_read, bool popups, bool tweetToMsg)
db_event_add(hContact, &dbei);
}
- db_set_utf(hContact,"CList","StatusMsg",i->status.text.c_str());
+ db_set_utf(hContact, "CList", "StatusMsg", i->status.text.c_str());
if (!pre_read && popups) {
std::stringstream url;
@@ -620,12 +605,11 @@ void TwitterProto::UpdateStatuses(bool pre_read, bool popups, bool tweetToMsg)
}
}
- db_pod_set(0,m_szModuleName,TWITTER_KEY_SINCEID,since_id_);
+ db_pod_set(0, m_szModuleName, TWITTER_KEY_SINCEID, since_id_);
disconnectionCount = 0;
debugLogA("***** Status messages updated");
}
- catch(const bad_response &)
- {
+ catch (const bad_response &) {
++disconnectionCount;
debugLogA("***** UpdateStatuses - Bad response from server, this has happened %d time(s)", disconnectionCount);
if (disconnectionCount > 2) {
@@ -633,44 +617,42 @@ void TwitterProto::UpdateStatuses(bool pre_read, bool popups, bool tweetToMsg)
SetStatus(ID_STATUS_OFFLINE);
}
}
- catch(const std::exception &e)
- {
- ShowPopup( (std::string("While updating status messages, an error occurred: ")
- +e.what()).c_str());
+ catch (const std::exception &e) {
+ ShowPopup((std::string("While updating status messages, an error occurred: ")
+ + e.what()).c_str());
debugLogA("***** Error updating status messages: %s", e.what());
}
}
void TwitterProto::UpdateMessages(bool pre_read)
{
- try
- {
- ScopedLock s(twitter_lock_);
- twitter::status_list messages = twit_.get_direct(dm_since_id_);
- s.Unlock();
+ try {
+ twitter::status_list messages;
+ {
+ mir_cslock s(twitter_lock_);
+ messages = twit_.get_direct(dm_since_id_);
+ }
- if(messages.size())
+ if (messages.size())
dm_since_id_ = std::max(dm_since_id_, messages[0].status.id);
- for(twitter::status_list::reverse_iterator i=messages.rbegin(); i!=messages.rend(); ++i)
- {
- MCONTACT hContact = AddToClientList(i->username.c_str(),"");
+ for (twitter::status_list::reverse_iterator i = messages.rbegin(); i != messages.rend(); ++i) {
+ MCONTACT hContact = AddToClientList(i->username.c_str(), "");
PROTORECVEVENT recv = { 0 };
recv.flags = PREF_UTF;
- if(pre_read)
+ if (pre_read)
recv.flags |= PREF_CREATEREAD;
recv.szMessage = const_cast<char*>(i->status.text.c_str());
recv.timestamp = static_cast<DWORD>(i->status.time);
ProtoChainRecvMsg(hContact, &recv);
}
- db_pod_set(0,m_szModuleName,TWITTER_KEY_DMSINCEID,dm_since_id_);
+ db_pod_set(0, m_szModuleName, TWITTER_KEY_DMSINCEID, dm_since_id_);
disconnectionCount = 0;
debugLogA("***** Direct messages updated");
}
- catch(const bad_response &)
- {
+ catch (const bad_response &) {
++disconnectionCount;
debugLogA("***** UpdateMessages - Bad response from server, this has happened %d time(s)", disconnectionCount);
if (disconnectionCount > 2) {
@@ -678,17 +660,17 @@ void TwitterProto::UpdateMessages(bool pre_read)
SetStatus(ID_STATUS_OFFLINE);
}
}
- catch(const std::exception &e)
- {
- ShowPopup( (std::string("While updating direct messages, an error occurred: ")+e.what()).c_str());
+ catch (const std::exception &e) {
+ ShowPopup((std::string("While updating direct messages, an error occurred: ") + e.what()).c_str());
debugLogA("***** Error updating direct messages: %s", e.what());
}
}
-void TwitterProto::resetOAuthKeys() {
- db_unset(0,m_szModuleName,TWITTER_KEY_OAUTH_ACCESS_TOK);
- db_unset(0,m_szModuleName,TWITTER_KEY_OAUTH_ACCESS_TOK_SECRET);
- db_unset(0,m_szModuleName,TWITTER_KEY_OAUTH_TOK);
- db_unset(0,m_szModuleName,TWITTER_KEY_OAUTH_TOK_SECRET);
- db_unset(0,m_szModuleName,TWITTER_KEY_OAUTH_PIN);
+void TwitterProto::resetOAuthKeys()
+{
+ db_unset(0, m_szModuleName, TWITTER_KEY_OAUTH_ACCESS_TOK);
+ db_unset(0, m_szModuleName, TWITTER_KEY_OAUTH_ACCESS_TOK_SECRET);
+ db_unset(0, m_szModuleName, TWITTER_KEY_OAUTH_TOK);
+ db_unset(0, m_szModuleName, TWITTER_KEY_OAUTH_TOK_SECRET);
+ db_unset(0, m_szModuleName, TWITTER_KEY_OAUTH_PIN);
}
diff --git a/protocols/Twitter/src/contacts.cpp b/protocols/Twitter/src/contacts.cpp
index bf482bbe9d..ffbabc4503 100644
--- a/protocols/Twitter/src/contacts.cpp
+++ b/protocols/Twitter/src/contacts.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -21,35 +22,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
void TwitterProto::AddToListWorker(void *p)
{
// TODO: what happens if there is an error?
- if(p == 0)
+ if (p == 0)
return;
char *name = static_cast<char*>(p);
- try
- {
- ScopedLock s(twitter_lock_);
- twitter_user user = twit_.add_friend(name);
- s.Unlock();
+ try {
+ twitter_user user;
+ {
+ mir_cslock s(twitter_lock_);
+ user = twit_.add_friend(name);
+ }
MCONTACT hContact = UsernameToHContact(name);
- UpdateAvatar(hContact,user.profile_image_url);
+ UpdateAvatar(hContact, user.profile_image_url);
}
- catch(const std::exception &e)
- {
+ catch (const std::exception &e) {
ShowPopup((std::string("While adding a friend, an error occurred: ") + e.what()).c_str());
debugLogA("***** Error adding friend: %s", e.what());
}
mir_free(name);
}
-MCONTACT TwitterProto::AddToList(int flags,PROTOSEARCHRESULT *result)
+MCONTACT TwitterProto::AddToList(int flags, PROTOSEARCHRESULT *result)
{
- if(m_iStatus != ID_STATUS_ONLINE)
+ if (m_iStatus != ID_STATUS_ONLINE)
return 0;
ForkThread(&TwitterProto::AddToListWorker, mir_utf8encodeT(result->nick));
- return AddToClientList( _T2A(result->nick),"");
+ return AddToClientList(_T2A(result->nick), "");
}
// *************************
@@ -57,36 +58,28 @@ MCONTACT TwitterProto::AddToList(int flags,PROTOSEARCHRESULT *result)
void TwitterProto::UpdateInfoWorker(void *hContact)
{
twitter_user user;
- std::string username;
- DBVARIANT dbv;
- if (!db_get_s((MCONTACT)hContact, m_szModuleName, TWITTER_KEY_UN, &dbv))
- {
- username = dbv.pszVal;
- db_free(&dbv);
- }
- else
+ ptrA username(db_get_sa((MCONTACT)hContact, m_szModuleName, TWITTER_KEY_UN));
+ if (username == NULL)
return;
- {
- ScopedLock s(twitter_lock_);
- twit_.get_info(username,&user);
+ { mir_cslock s(twitter_lock_);
+ twit_.get_info(std::string(username), &user);
}
UpdateAvatar((MCONTACT)hContact, user.profile_image_url, true);
ProtoBroadcastAck((MCONTACT)hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, 0, 0);
}
-int TwitterProto::GetInfo(MCONTACT hContact,int info_type)
+int TwitterProto::GetInfo(MCONTACT hContact, int info_type)
{
- if(m_iStatus != ID_STATUS_ONLINE)
+ if (m_iStatus != ID_STATUS_ONLINE)
return 1;
- if(!IsMyContact(hContact)) // Do nothing for chat rooms
+ if (!IsMyContact(hContact)) // Do nothing for chat rooms
return 1;
- if(info_type == 0) // From clicking "Update" in the Userinfo dialog
- {
+ if (info_type == 0) { // From clicking "Update" in the Userinfo dialog
ForkThread(&TwitterProto::UpdateInfoWorker, (void*)hContact);
return 0;
}
@@ -98,7 +91,7 @@ int TwitterProto::GetInfo(MCONTACT hContact,int info_type)
struct search_query
{
- search_query(const std::tstring &_query,bool _by_email) : query(_query),by_email(_by_email)
+ search_query(const std::tstring &_query, bool _by_email) : query(_query), by_email(_by_email)
{}
std::tstring query;
bool by_email;
@@ -116,7 +109,7 @@ void TwitterProto::DoSearch(void *p)
try {
char *p = mir_utf8encodeT(query->query.c_str());
- ScopedLock s(twitter_lock_);
+ mir_cslock s(twitter_lock_);
if (query->by_email)
found = twit_.get_info_by_email(p, &info);
else
@@ -148,13 +141,13 @@ void TwitterProto::DoSearch(void *p)
HANDLE TwitterProto::SearchBasic(const TCHAR *username)
{
- ForkThread(&TwitterProto::DoSearch, new search_query(username,false));
+ ForkThread(&TwitterProto::DoSearch, new search_query(username, false));
return (HANDLE)1;
}
HANDLE TwitterProto::SearchByEmail(const TCHAR *email)
{
- ForkThread(&TwitterProto::DoSearch, new search_query(email,true));
+ ForkThread(&TwitterProto::DoSearch, new search_query(email, true));
return (HANDLE)1;
}
@@ -162,7 +155,7 @@ HANDLE TwitterProto::SearchByEmail(const TCHAR *email)
void TwitterProto::GetAwayMsgWorker(void *hContact)
{
- if(hContact == 0)
+ if (hContact == 0)
return;
DBVARIANT dbv;
@@ -192,7 +185,7 @@ int TwitterProto::OnContactDeleted(WPARAM hContact, LPARAM lParam)
if (in_chat_)
DeleteChatContact(dbv.pszVal);
- ScopedLock s(twitter_lock_);
+ mir_cslock s(twitter_lock_);
twit_.remove_friend(dbv.pszVal); // Be careful about this until Miranda is fixed
db_free(&dbv);
}
@@ -201,11 +194,11 @@ int TwitterProto::OnContactDeleted(WPARAM hContact, LPARAM lParam)
// *************************
-bool TwitterProto::IsMyContact(MCONTACT hContact,bool include_chat)
+bool TwitterProto::IsMyContact(MCONTACT hContact, bool include_chat)
{
char *proto = GetContactProto(hContact);
- if(proto && strcmp(m_szModuleName,proto) == 0) {
- if(include_chat)
+ if (proto && strcmp(m_szModuleName, proto) == 0) {
+ if (include_chat)
return true;
return !isChatRoom(hContact);
}
@@ -214,16 +207,13 @@ bool TwitterProto::IsMyContact(MCONTACT hContact,bool include_chat)
MCONTACT TwitterProto::UsernameToHContact(const char *name)
{
- for(MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
- {
- if( db_get_b(hContact, m_szModuleName, "ChatRoom", 0))
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0))
continue;
DBVARIANT dbv;
- if( !db_get_s(hContact,m_szModuleName,TWITTER_KEY_UN,&dbv))
- {
- if(strcmp(name,dbv.pszVal) == 0)
- {
+ if (!db_get_s(hContact, m_szModuleName, TWITTER_KEY_UN, &dbv)) {
+ if (strcmp(name, dbv.pszVal) == 0) {
db_free(&dbv);
return hContact;
}
@@ -239,35 +229,32 @@ MCONTACT TwitterProto::AddToClientList(const char *name, const char *status)
{
// First, check if this contact exists
MCONTACT hContact = UsernameToHContact(name);
- if(hContact)
+ if (hContact)
return hContact;
- if(in_chat_)
+ if (in_chat_)
AddChatContact(name);
// If not, make a new contact!
hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
- if(hContact)
- {
- if(CallService(MS_PROTO_ADDTOCONTACT,hContact,(LPARAM)m_szModuleName) == 0)
- {
- db_set_s(hContact,m_szModuleName,TWITTER_KEY_UN,name);
- db_set_w(hContact,m_szModuleName,"Status",ID_STATUS_ONLINE);
- db_set_utf(hContact,"CList","StatusMsg",status);
+ if (hContact) {
+ if (CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)m_szModuleName) == 0) {
+ db_set_s(hContact, m_szModuleName, TWITTER_KEY_UN, name);
+ db_set_w(hContact, m_szModuleName, "Status", ID_STATUS_ONLINE);
+ db_set_utf(hContact, "CList", "StatusMsg", status);
- std::string url = profile_base_url(twit_.get_base_url())+http::url_encode(name);
- db_set_s(hContact,m_szModuleName,"Homepage",url.c_str());
+ std::string url = profile_base_url(twit_.get_base_url()) + http::url_encode(name);
+ db_set_s(hContact, m_szModuleName, "Homepage", url.c_str());
DBVARIANT dbv;
- if(!db_get_ts(NULL,m_szModuleName,TWITTER_KEY_GROUP,&dbv))
- {
- db_set_ts(hContact,"CList","Group",dbv.ptszVal);
+ if (!db_get_ts(NULL, m_szModuleName, TWITTER_KEY_GROUP, &dbv)) {
+ db_set_ts(hContact, "CList", "Group", dbv.ptszVal);
db_free(&dbv);
}
return hContact;
}
- CallService(MS_DB_CONTACT_DELETE,hContact,0);
+ CallService(MS_DB_CONTACT_DELETE, hContact, 0);
}
return 0;
@@ -275,9 +262,9 @@ MCONTACT TwitterProto::AddToClientList(const char *name, const char *status)
void TwitterProto::SetAllContactStatuses(int status)
{
- for(MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
- if( !db_get_b(hContact, m_szModuleName, "ChatRoom", 0))
- db_set_w(hContact,m_szModuleName,"Status",status);
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ if (!db_get_b(hContact, m_szModuleName, "ChatRoom", 0))
+ db_set_w(hContact, m_szModuleName, "Status", status);
SetChatStatus(status);
-} \ No newline at end of file
+}
diff --git a/protocols/Twitter/src/http.cpp b/protocols/Twitter/src/http.cpp
index 2c07b80902..1eb5b03746 100644
--- a/protocols/Twitter/src/http.cpp
+++ b/protocols/Twitter/src/http.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -20,5 +21,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
std::string http::url_encode(const std::string &s)
{
- return (char*)ptrA( mir_urlEncode( s.c_str()));
+ return (char*)ptrA(mir_urlEncode(s.c_str()));
}
diff --git a/protocols/Twitter/src/http.h b/protocols/Twitter/src/http.h
index 65ef5af407..cfbda8f7cd 100644
--- a/protocols/Twitter/src/http.h
+++ b/protocols/Twitter/src/http.h
@@ -1,4 +1,6 @@
/*
+
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
diff --git a/protocols/Twitter/src/main.cpp b/protocols/Twitter/src/main.cpp
index e4edf0beaa..53081ab253 100644
--- a/protocols/Twitter/src/main.cpp
+++ b/protocols/Twitter/src/main.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -26,7 +27,7 @@ CLIST_INTERFACE* pcli;
HINSTANCE g_hInstance;
int hLangpack = 0;
-PLUGININFOEX pluginInfo={
+PLUGININFOEX pluginInfo = {
sizeof(PLUGININFOEX),
__PLUGIN_NAME,
PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
@@ -50,7 +51,7 @@ static int compare_protos(const TwitterProto *p1, const TwitterProto *p2)
OBJLIST<TwitterProto> g_Instances(1, compare_protos);
-DWORD WINAPI DllMain(HINSTANCE hInstance,DWORD,LPVOID)
+DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
{
g_hInstance = hInstance;
return TRUE;
@@ -64,14 +65,14 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD miranda
/////////////////////////////////////////////////////////////////////////////////////////
// Interface information
-extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_PROTOCOL, MIID_LAST};
+extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST };
/////////////////////////////////////////////////////////////////////////////////////////
// Load
-static PROTO_INTERFACE* protoInit(const char *proto_name,const TCHAR *username )
+static PROTO_INTERFACE* protoInit(const char *proto_name, const TCHAR *username)
{
- TwitterProto *proto = new TwitterProto(proto_name,username);
+ TwitterProto *proto = new TwitterProto(proto_name, username);
g_Instances.insert(proto);
return proto;
}
@@ -89,12 +90,12 @@ extern "C" int __declspec(dllexport) Load(void)
mir_getLP(&pluginInfo);
mir_getCLI();
- PROTOCOLDESCRIPTOR pd = {sizeof(pd)};
+ PROTOCOLDESCRIPTOR pd = { sizeof(pd) };
pd.szName = "Twitter";
pd.type = PROTOTYPE_PROTOCOL;
pd.fnInit = protoInit;
pd.fnUninit = protoUninit;
- CallService(MS_PROTO_REGISTERMODULE,0,reinterpret_cast<LPARAM>(&pd));
+ CallService(MS_PROTO_REGISTERMODULE, 0, reinterpret_cast<LPARAM>(&pd));
InitIcons();
InitContactMenus();
@@ -108,7 +109,7 @@ extern "C" int __declspec(dllexport) Load(void)
extern "C" int __declspec(dllexport) Unload(void)
{
UninitContactMenus();
- for(size_t i=1; i<SIZEOF(g_hEvents); i++)
+ for (size_t i = 1; i < SIZEOF(g_hEvents); i++)
UnhookEvent(g_hEvents[i]);
return 0;
diff --git a/protocols/Twitter/src/oauth.cpp b/protocols/Twitter/src/oauth.cpp
index 82e409e5ac..8458004e42 100644
--- a/protocols/Twitter/src/oauth.cpp
+++ b/protocols/Twitter/src/oauth.cpp
@@ -1,21 +1,35 @@
-/* aww whatup? this is all the oauth functions, at the moment
- * they're all part of the twitter class.. i think this is the
- * best way?
- */
+/*
+Copyright © 2012-15 Miranda NG team
+Copyright © 2009 Jim Porter
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#include "stdafx.h"
#include "twitter.h"
#include "utility.h"
-OAuthParameters mir_twitter::BuildSignedOAuthParameters( const OAuthParameters& requestParameters,
- const std::wstring& url,
- const std::wstring& httpMethod,
- const OAuthParameters *postData,
- const std::wstring& consumerKey,
- const std::wstring& consumerSecret,
- const std::wstring& requestToken = L"",
- const std::wstring& requestTokenSecret = L"",
- const std::wstring& pin = L"" )
+OAuthParameters mir_twitter::BuildSignedOAuthParameters(
+ const OAuthParameters& requestParameters,
+ const std::wstring& url,
+ const std::wstring& httpMethod,
+ const OAuthParameters *postData,
+ const std::wstring& consumerKey,
+ const std::wstring& consumerSecret,
+ const std::wstring& requestToken = L"",
+ const std::wstring& requestTokenSecret = L"",
+ const std::wstring& pin = L"")
{
wstring timestamp = OAuthCreateTimestamp();
wstring nonce = OAuthCreateNonce();
@@ -30,14 +44,12 @@ OAuthParameters mir_twitter::BuildSignedOAuthParameters( const OAuthParameters&
oauthParameters[L"oauth_consumer_key"] = consumerKey;
// add the request token if found
- if (!requestToken.empty())
- {
+ if (!requestToken.empty()) {
oauthParameters[L"oauth_token"] = requestToken; /*debugLogW("requestToken not empty: %s", requestToken);*/
}
// add the authorization pin if found
- if (!pin.empty())
- {
+ if (!pin.empty()) {
oauthParameters[L"oauth_verifier"] = pin;
}
@@ -45,7 +57,7 @@ OAuthParameters mir_twitter::BuildSignedOAuthParameters( const OAuthParameters&
// this will be used to create the parameter signature
OAuthParameters allParameters = requestParameters;
- if(Compare(httpMethod, L"POST", false) && postData) {
+ if (Compare(httpMethod, L"POST", false) && postData) {
//debugLogA("in post section of buildOAuthParams");
allParameters.insert(postData->begin(), postData->end());
}
@@ -69,7 +81,7 @@ OAuthParameters mir_twitter::BuildSignedOAuthParameters( const OAuthParameters&
return oauthParameters;
}
-wstring mir_twitter::UrlGetQuery( const wstring& url )
+wstring mir_twitter::UrlGetQuery(const wstring& url)
{
wstring query;
/*
@@ -85,21 +97,19 @@ wstring mir_twitter::UrlGetQuery( const wstring& url )
if(crackUrlOk)
{*/
- map<wstring, wstring> brokenURL = CrackURL(url);
+ map<wstring, wstring> brokenURL = CrackURL(url);
- query = brokenURL[L"extraInfo"];
- //debugLogW("inside crack, url is %s", url);
- wstring::size_type q = query.find_first_of(L'?');
- if(q != wstring::npos)
- {
- query = query.substr(q + 1);
- }
+ query = brokenURL[L"extraInfo"];
+ //debugLogW("inside crack, url is %s", url);
+ wstring::size_type q = query.find_first_of(L'?');
+ if (q != wstring::npos) {
+ query = query.substr(q + 1);
+ }
- wstring::size_type h = query.find_first_of(L'#');
- if(h != wstring::npos)
- {
- query = query.substr(0, h);
- }
+ wstring::size_type h = query.find_first_of(L'#');
+ if (h != wstring::npos) {
+ query = query.substr(0, h);
+ }
//}
return query;
}
@@ -109,52 +119,50 @@ wstring mir_twitter::UrlGetQuery( const wstring& url )
// consumerKey and consumerSecret - must be provided for every call, they identify the application
// oauthToken and oauthTokenSecret - need to be provided for every call, except for the first token request before authorizing
// pin - only used during authorization, when the user enters the PIN they received from the twitter website
-wstring mir_twitter::OAuthWebRequestSubmit(
- const wstring& url,
- const wstring& httpMethod,
+wstring mir_twitter::OAuthWebRequestSubmit(
+ const wstring& url,
+ const wstring& httpMethod,
const OAuthParameters *postData,
- const wstring& consumerKey,
- const wstring& consumerSecret,
- const wstring& oauthToken,
- const wstring& oauthTokenSecret,
- const wstring& pin
- )
+ const wstring& consumerKey,
+ const wstring& consumerSecret,
+ const wstring& oauthToken,
+ const wstring& oauthTokenSecret,
+ const wstring& pin
+ )
{
//debugLogW("URL is %s", url);
- wstring query = UrlGetQuery(url);
+ wstring query = UrlGetQuery(url);
//debugLogW("query is %s", query);
- OAuthParameters originalParameters = ParseQueryString(query);
-
- OAuthParameters oauthSignedParameters = BuildSignedOAuthParameters(
- originalParameters,
- url,
- httpMethod, postData,
- consumerKey, consumerSecret,
- oauthToken, oauthTokenSecret,
- pin );
- return OAuthWebRequestSubmit(oauthSignedParameters, url);
+ OAuthParameters originalParameters = ParseQueryString(query);
+
+ OAuthParameters oauthSignedParameters = BuildSignedOAuthParameters(
+ originalParameters,
+ url,
+ httpMethod, postData,
+ consumerKey, consumerSecret,
+ oauthToken, oauthTokenSecret,
+ pin);
+ return OAuthWebRequestSubmit(oauthSignedParameters, url);
}
-wstring mir_twitter::OAuthWebRequestSubmit(
- const OAuthParameters& parameters,
- const wstring& url
- )
+wstring mir_twitter::OAuthWebRequestSubmit(
+ const OAuthParameters& parameters,
+ const wstring& url
+ )
{
//debugLogW("OAuthWebRequestSubmit(%s)", url);
//wstring oauthHeader = L"Authorization: OAuth ";
wstring oauthHeader = L"OAuth ";
- for(OAuthParameters::const_iterator it = parameters.begin();
- it != parameters.end();
- ++it)
- {
+ for (OAuthParameters::const_iterator it = parameters.begin();
+ it != parameters.end();
+ ++it) {
//debugLogW("%s = ", it->first);
//debugLogW("%s", it->second);
//debugLogA("---------");
- if(it != parameters.begin())
- {
+ if (it != parameters.begin()) {
oauthHeader += L",";
}
@@ -169,31 +177,29 @@ wstring mir_twitter::OAuthWebRequestSubmit(
}
// parameters must already be URL encoded before calling BuildQueryString
-std::wstring mir_twitter::BuildQueryString( const OAuthParameters &parameters )
+std::wstring mir_twitter::BuildQueryString(const OAuthParameters &parameters)
{
wstring query;
//debugLogA("do we ever get here?");
- for(OAuthParameters::const_iterator it = parameters.begin();
- it != parameters.end();
- ++it)
- {
+ for (OAuthParameters::const_iterator it = parameters.begin();
+ it != parameters.end();
+ ++it) {
//debugLogA("aww como ONNNNNN");
//debugLogA("%s = %s", it->first.c_str(), it->second.c_str());
//debugLogW("in buildqueryString bit, first is %s", it->first);
- if(it != parameters.begin())
- {
+ if (it != parameters.begin()) {
query += L"&";
}
wstring pair;
pair += it->first + L"=" + it->second + L"";
query += pair;
- }
+ }
return query;
}
-wstring mir_twitter::OAuthConcatenateRequestElements( const wstring& httpMethod, wstring url, const wstring& parameters )
+wstring mir_twitter::OAuthConcatenateRequestElements(const wstring& httpMethod, wstring url, const wstring& parameters)
{
wstring escapedUrl = UrlEncode(url);
//debugLogW("before OAUTHConcat, params are %s", parameters);
@@ -213,7 +219,8 @@ wstring mir_twitter::OAuthConcatenateRequestElements( const wstring& httpMethod,
* "https://twitter.com:989/blah.htm?boom" will give:
* https, twitter.com, 989, blah.htm?boom, ?boom, 1
*/
-map<wstring, wstring> mir_twitter::CrackURL(wstring url) {
+map<wstring, wstring> mir_twitter::CrackURL(wstring url)
+{
wstring scheme1, domain1, port1, path1, extraInfo, explicitPort;
vector<wstring> urlToks, urlToks2, extraInfoToks;
@@ -256,7 +263,7 @@ map<wstring, wstring> mir_twitter::CrackURL(wstring url) {
path1 += urlToks2[i];
}
//debugLogW("**CRACK - path is %s", path1);
-
+
wstring::size_type foundHash = path1.find(L"#");
wstring::size_type foundQ = path1.find(L"?");
@@ -293,113 +300,81 @@ map<wstring, wstring> mir_twitter::CrackURL(wstring url) {
return result;
}
-wstring mir_twitter::OAuthNormalizeUrl( const wstring& url )
+wstring mir_twitter::OAuthNormalizeUrl(const wstring& url)
{
- /*wchar_t scheme[1024*4] = {};
- wchar_t host[1024*4] = {};
- wchar_t path[1024*4] = {};
-
- URL_COMPONENTS components = { sizeof(URL_COMPONENTS) };
-
- components.lpszScheme = scheme;
- components.dwSchemeLength = SIZEOF(scheme);
-
- components.lpszHostName = host;
- components.dwHostNameLength = SIZEOF(host);
-
- components.lpszUrlPath = path;
- components.dwUrlPathLength = SIZEOF(path);
-
- BOOL crackUrlOk = InternetCrackUrl(url.c_str(), url.size(), 0, &components);*/
-
wstring normalUrl = url;
map<wstring, wstring> brokenURL = CrackURL(url);
- /*_ASSERTE(crackUrlOk);
- if(crackUrlOk)
- {*/
- wchar_t port[10] = {};
+ wchar_t port[10] = {};
- // The port number must only be included if it is non-standard
- if(Compare(brokenURL[L"scheme"], L"http", false) && !(Compare(brokenURL[L"port"], L"80", false)) ||
- (Compare(brokenURL[L"scheme"], L"https", false) && !(Compare(brokenURL[L"port"], L"443", false))))
- {
- mir_snwprintf(port, SIZEOF(port), L":%s", brokenURL[L"port"]);
- }
+ // The port number must only be included if it is non-standard
+ if (Compare(brokenURL[L"scheme"], L"http", false) && !(Compare(brokenURL[L"port"], L"80", false)) ||
+ (Compare(brokenURL[L"scheme"], L"https", false) && !(Compare(brokenURL[L"port"], L"443", false))))
+ {
+ mir_snwprintf(port, SIZEOF(port), L":%s", brokenURL[L"port"]);
+ }
- // InternetCrackUrl includes ? and # elements in the path,
- // which we need to strip off
- wstring pathOnly = brokenURL[L"path"];
- wstring::size_type q = pathOnly.find_first_of(L"#?");
- if(q != wstring::npos)
- {
- pathOnly = pathOnly.substr(0, q);
- }
+ // InternetCrackUrl includes ? and # elements in the path,
+ // which we need to strip off
+ wstring pathOnly = brokenURL[L"path"];
+ wstring::size_type q = pathOnly.find_first_of(L"#?");
+ if (q != wstring::npos)
+ pathOnly = pathOnly.substr(0, q);
- normalUrl = brokenURL[L"scheme"] + L"://" + brokenURL[L"domain"] + port + L"/" + pathOnly;
- //debugLogW("**OAuthNOrmailseURL - normalUrl is %s", normalUrl);
- //}
- return normalUrl;
+ return brokenURL[L"scheme"] + L"://" + brokenURL[L"domain"] + port + L"/" + pathOnly;
}
-wstring mir_twitter::OAuthNormalizeRequestParameters( const OAuthParameters& requestParameters )
+wstring mir_twitter::OAuthNormalizeRequestParameters(const OAuthParameters& requestParameters)
{
list<wstring> sorted;
- for(OAuthParameters::const_iterator it = requestParameters.begin();
- it != requestParameters.end();
- ++it)
- {
+ for (OAuthParameters::const_iterator it = requestParameters.begin();
+ it != requestParameters.end();
+ ++it) {
wstring param = it->first + L"=" + it->second;
sorted.push_back(param);
}
sorted.sort();
wstring params;
- for(list<wstring>::iterator it = sorted.begin(); it != sorted.end(); ++it)
- {
- if(params.size() > 0)
- {
+ for (list<wstring>::iterator it = sorted.begin(); it != sorted.end(); ++it) {
+ if (params.size() > 0)
params += L"&";
- }
+
params += *it;
}
return params;
}
-OAuthParameters mir_twitter::ParseQueryString( const wstring& url )
+OAuthParameters mir_twitter::ParseQueryString(const wstring& url)
{
OAuthParameters ret;
vector<wstring> queryParams;
Split(url, queryParams, L'&', false);
- for(size_t i = 0; i < queryParams.size(); ++i)
- {
+ for (size_t i = 0; i < queryParams.size(); ++i) {
vector<wstring> paramElements;
Split(queryParams[i], paramElements, L'=', true);
_ASSERTE(paramElements.size() == 2);
- if(paramElements.size() == 2)
- {
+ if (paramElements.size() == 2)
ret[paramElements[0]] = paramElements[1];
- }
}
return ret;
}
-wstring mir_twitter::OAuthCreateNonce()
+wstring mir_twitter::OAuthCreateNonce()
{
wchar_t ALPHANUMERIC[] = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
wstring nonce;
- for(int i = 0; i <= 16; ++i)
- {
+ for (int i = 0; i <= 16; ++i)
nonce += ALPHANUMERIC[rand() % (SIZEOF(ALPHANUMERIC) - 1)]; // don't count null terminator in array
- }
+
return nonce;
}
-wstring mir_twitter::OAuthCreateTimestamp()
+wstring mir_twitter::OAuthCreateTimestamp()
{
__time64_t utcNow;
__time64_t ret = _time64(&utcNow);
@@ -411,7 +386,7 @@ wstring mir_twitter::OAuthCreateTimestamp()
return buf;
}
-wstring mir_twitter::OAuthCreateSignature( const wstring& signatureBase, const wstring& consumerSecret, const wstring& requestTokenSecret )
+wstring mir_twitter::OAuthCreateSignature(const wstring& signatureBase, const wstring& consumerSecret, const wstring& requestTokenSecret)
{
// URL encode key elements
wstring escapedConsumerSecret = UrlEncode(consumerSecret);
@@ -423,6 +398,6 @@ wstring mir_twitter::OAuthCreateSignature( const wstring& signatureBase, const w
BYTE digest[MIR_SHA1_HASH_SIZE];
string data = WideToUTF8(signatureBase);
mir_hmac_sha1(digest, (PBYTE)keyBytes.c_str(), keyBytes.size(), (PBYTE)data.c_str(), data.size());
- ptrA encoded( mir_base64_encode(digest, sizeof(digest)));
+ ptrA encoded(mir_base64_encode(digest, sizeof(digest)));
return UrlEncode((TCHAR*)_A2T(encoded));
}
diff --git a/protocols/Twitter/src/proto.cpp b/protocols/Twitter/src/proto.cpp
index 9472b02e8b..20cfcc14c5 100644
--- a/protocols/Twitter/src/proto.cpp
+++ b/protocols/Twitter/src/proto.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -25,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
static volatile LONG g_msgid = 1;
-TwitterProto::TwitterProto(const char *proto_name,const TCHAR *username) :
+TwitterProto::TwitterProto(const char *proto_name, const TCHAR *username) :
PROTO<TwitterProto>(proto_name, username)
{
CreateProtoService(PS_CREATEACCMGRUI, &TwitterProto::SvcCreateAccMgrUI);
@@ -38,25 +39,21 @@ TwitterProto::TwitterProto(const char *proto_name,const TCHAR *username) :
CreateProtoService(PS_GETMYAVATAR, &TwitterProto::GetAvatar);
CreateProtoService(PS_SETMYAVATAR, &TwitterProto::SetAvatar);
- HookProtoEvent(ME_DB_CONTACT_DELETED, &TwitterProto::OnContactDeleted);
+ HookProtoEvent(ME_OPT_INITIALISE, &TwitterProto::OnOptionsInit);
+ HookProtoEvent(ME_DB_CONTACT_DELETED, &TwitterProto::OnContactDeleted);
HookProtoEvent(ME_CLIST_PREBUILDSTATUSMENU, &TwitterProto::OnBuildStatusMenu);
- HookProtoEvent(ME_OPT_INITIALISE, &TwitterProto::OnOptionsInit);
// Initialize hotkeys
char text[512];
- mir_snprintf(text,SIZEOF(text),"%s/Tweet",m_szModuleName);
+ mir_snprintf(text, SIZEOF(text), "%s/Tweet", m_szModuleName);
- HOTKEYDESC hkd = {sizeof(hkd)};
+ HOTKEYDESC hkd = { sizeof(hkd) };
hkd.pszName = text;
hkd.pszService = text;
hkd.pszSection = m_szModuleName; // Section title; TODO: use username?
hkd.pszDescription = "Send Tweet";
Hotkey_Register(&hkd);
- signon_lock_ = CreateMutex(0,false,0);
- avatar_lock_ = CreateMutex(0,false,0);
- twitter_lock_ = CreateMutex(0,false,0);
-
// set Tokens and stuff
//mirandas keys
@@ -70,22 +67,17 @@ TwitterProto::~TwitterProto()
{
twit_.Disconnect();
- if(m_hNetlibUser)
+ if (m_hNetlibUser)
Netlib_CloseHandle(m_hNetlibUser);
- if(hAvatarNetlib_)
+ if (hAvatarNetlib_)
Netlib_CloseHandle(hAvatarNetlib_);
-
- CloseHandle(twitter_lock_);
- CloseHandle(avatar_lock_);
- CloseHandle(signon_lock_);
}
// *************************
DWORD_PTR TwitterProto::GetCaps(int type, MCONTACT)
{
- switch(type)
- {
+ switch (type) {
case PFLAGNUM_1:
return PF1_IM | PF1_MODEMSGRECV | PF1_BASICSEARCH | PF1_SEARCHBYEMAIL |
PF1_SERVERCLIST | PF1_CHANGEINFO;
@@ -100,14 +92,14 @@ DWORD_PTR TwitterProto::GetCaps(int type, MCONTACT)
case PFLAG_UNIQUEIDTEXT:
return (DWORD_PTR) "Username";
case PFLAG_UNIQUEIDSETTING:
- return (DWORD_PTR) TWITTER_KEY_UN;
+ return (DWORD_PTR)TWITTER_KEY_UN;
}
return 0;
}
// *************************
-int TwitterProto::RecvMsg(MCONTACT hContact,PROTORECVEVENT *pre)
+int TwitterProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre)
{
Proto_RecvMessage(hContact, pre);
return 0;
@@ -119,7 +111,7 @@ struct send_direct
{
__inline send_direct(MCONTACT _hContact, const std::string &_msg, int _msgid) :
hContact(_hContact), msg(_msg), msgid(_msgid)
- {}
+ {}
MCONTACT hContact;
std::string msg;
@@ -128,35 +120,34 @@ struct send_direct
void TwitterProto::SendSuccess(void *p)
{
- if(p == 0)
+ if (p == 0)
return;
send_direct *data = static_cast<send_direct*>(p);
DBVARIANT dbv;
- if( !db_get_s(data->hContact,m_szModuleName,TWITTER_KEY_UN,&dbv))
- {
- ScopedLock s(twitter_lock_);
- twit_.send_direct(dbv.pszVal,data->msg);
+ if (!db_get_s(data->hContact, m_szModuleName, TWITTER_KEY_UN, &dbv)) {
+ mir_cslock s(twitter_lock_);
+ twit_.send_direct(dbv.pszVal, data->msg);
- ProtoBroadcastAck(data->hContact,ACKTYPE_MESSAGE,ACKRESULT_SUCCESS,(HANDLE)data->msgid,0);
+ ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)data->msgid, 0);
db_free(&dbv);
}
delete data;
}
-int TwitterProto::SendMsg(MCONTACT hContact,int flags,const char *msg)
+int TwitterProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
{
- if(m_iStatus != ID_STATUS_ONLINE)
+ if (m_iStatus != ID_STATUS_ONLINE)
return 0;
- TCHAR* tszMsg;
- if ( flags & PREF_UTF )
- tszMsg = mir_utf8decodeT( msg );
- else if ( flags & PREF_UNICODE )
- tszMsg = mir_u2t(( wchar_t* )&msg[ strlen( msg )+1 ] );
+ TCHAR *tszMsg;
+ if (flags & PREF_UTF)
+ tszMsg = mir_utf8decodeT(msg);
+ else if (flags & PREF_UNICODE)
+ tszMsg = mir_u2t((wchar_t*)&msg[strlen(msg) + 1]);
else
- tszMsg = mir_a2t( msg );
+ tszMsg = mir_a2t(msg);
int seq = InterlockedIncrement(&g_msgid);
ForkThread(&TwitterProto::SendSuccess, new send_direct(hContact, msg, seq));
@@ -168,18 +159,17 @@ int TwitterProto::SendMsg(MCONTACT hContact,int flags,const char *msg)
int TwitterProto::SetStatus(int new_status)
{
int old_status = m_iStatus;
- if(new_status == m_iStatus)
+ if (new_status == m_iStatus)
return 0;
m_iDesiredStatus = new_status;
// 40072 - 40080 are the "online" statuses, basically every status except offline. see statusmodes.h
- if(new_status >= 40072 && new_status <= 40080)
- {
+ if (new_status >= 40072 && new_status <= 40080) {
m_iDesiredStatus = ID_STATUS_ONLINE; //i think i have to set this so it forces the twitter proto to be online (and not away, DND, etc)
// if we're already connecting and they want to go online, BAIL! we're already trying to connect you dumbass
- if(old_status == ID_STATUS_CONNECTING)
+ if (old_status == ID_STATUS_CONNECTING)
return 0;
// if we're already connected, and we change to another connected status, don't try and reconnect!
@@ -189,17 +179,16 @@ int TwitterProto::SetStatus(int new_status)
// i think here we tell the proto interface struct that we're connecting, just so it knows
m_iStatus = ID_STATUS_CONNECTING;
// ok.. here i think we're telling the core that this protocol something.. but why?
- ProtoBroadcastAck(0,ACKTYPE_STATUS,ACKRESULT_SUCCESS,(HANDLE)old_status,m_iStatus);
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
- ForkThread(&TwitterProto::SignOn,this);
+ ForkThread(&TwitterProto::SignOn, this);
}
- else if(new_status == ID_STATUS_OFFLINE)
- {
+ else if (new_status == ID_STATUS_OFFLINE) {
twit_.Disconnect();
m_iStatus = m_iDesiredStatus;
SetAllContactStatuses(ID_STATUS_OFFLINE);
- ProtoBroadcastAck(0,ACKTYPE_STATUS,ACKRESULT_SUCCESS,(HANDLE)old_status,m_iStatus);
+ ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
}
return 0;
@@ -207,13 +196,12 @@ int TwitterProto::SetStatus(int new_status)
// *************************
-int TwitterProto::OnEvent(PROTOEVENTTYPE event,WPARAM wParam,LPARAM lParam)
+int TwitterProto::OnEvent(PROTOEVENTTYPE event, WPARAM wParam, LPARAM lParam)
{
- switch(event)
- {
- case EV_PROTO_ONLOAD: return OnModulesLoaded(wParam,lParam);
- case EV_PROTO_ONEXIT: return OnPreShutdown (wParam,lParam);
- case EV_PROTO_ONOPTIONS: return OnOptionsInit (wParam,lParam);
+ switch (event) {
+ case EV_PROTO_ONLOAD: return OnModulesLoaded(wParam, lParam);
+ case EV_PROTO_ONEXIT: return OnPreShutdown(wParam, lParam);
+ case EV_PROTO_ONOPTIONS: return OnOptionsInit(wParam, lParam);
}
return 1;
@@ -221,18 +209,18 @@ int TwitterProto::OnEvent(PROTOEVENTTYPE event,WPARAM wParam,LPARAM lParam)
// *************************
-INT_PTR TwitterProto::SvcCreateAccMgrUI(WPARAM,LPARAM lParam)
+INT_PTR TwitterProto::SvcCreateAccMgrUI(WPARAM, LPARAM lParam)
{
- return (INT_PTR)CreateDialogParam(g_hInstance,MAKEINTRESOURCE(IDD_TWITTERACCOUNT),(HWND)lParam, first_run_dialog, (LPARAM)this );
+ return (INT_PTR)CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_TWITTERACCOUNT), (HWND)lParam, first_run_dialog, (LPARAM)this);
}
-INT_PTR TwitterProto::GetName(WPARAM wParam,LPARAM lParam)
+INT_PTR TwitterProto::GetName(WPARAM wParam, LPARAM lParam)
{
mir_strncpy(reinterpret_cast<char*>(lParam), m_szModuleName, (int)wParam);
return 0;
}
-INT_PTR TwitterProto::GetStatus(WPARAM,LPARAM)
+INT_PTR TwitterProto::GetStatus(WPARAM, LPARAM)
{
return m_iStatus;
}
@@ -240,16 +228,15 @@ INT_PTR TwitterProto::GetStatus(WPARAM,LPARAM)
INT_PTR TwitterProto::ReplyToTweet(WPARAM hContact, LPARAM)
{
// TODO: support replying to tweets instead of just users
- HWND hDlg = CreateDialogParam(g_hInstance,MAKEINTRESOURCE(IDD_TWEET),0,tweet_proc,reinterpret_cast<LPARAM>(this));
+ HWND hDlg = CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_TWEET), 0, tweet_proc, reinterpret_cast<LPARAM>(this));
DBVARIANT dbv;
- if(!db_get_s(hContact,m_szModuleName,TWITTER_KEY_UN,&dbv))
- {
- SendMessage(hDlg,WM_SETREPLY,reinterpret_cast<WPARAM>(dbv.pszVal),0);
+ if (!db_get_s(hContact, m_szModuleName, TWITTER_KEY_UN, &dbv)) {
+ SendMessage(hDlg, WM_SETREPLY, reinterpret_cast<WPARAM>(dbv.pszVal), 0);
db_free(&dbv);
}
- ShowWindow(hDlg,SW_SHOW);
+ ShowWindow(hDlg, SW_SHOW);
return 0;
}
@@ -258,12 +245,11 @@ INT_PTR TwitterProto::VisitHomepage(WPARAM hContact, LPARAM)
{
DBVARIANT dbv;
// TODO: remove this
- if( !db_get_s(hContact,m_szModuleName,TWITTER_KEY_UN,&dbv))
- {
+ if (!db_get_s(hContact, m_szModuleName, TWITTER_KEY_UN, &dbv)) {
std::string url = profile_base_url("https://twitter.com/") + http::url_encode(dbv.pszVal);
- db_set_s(hContact,m_szModuleName,"Homepage",url.c_str());
+ db_set_s(hContact, m_szModuleName, "Homepage", url.c_str());
- CallService(MS_UTILS_OPENURL,OUF_NEWWINDOW,reinterpret_cast<LPARAM>(url.c_str()));
+ CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, reinterpret_cast<LPARAM>(url.c_str()));
db_free(&dbv);
}
@@ -272,15 +258,15 @@ INT_PTR TwitterProto::VisitHomepage(WPARAM hContact, LPARAM)
// *************************
-int TwitterProto::OnBuildStatusMenu(WPARAM,LPARAM)
+int TwitterProto::OnBuildStatusMenu(WPARAM, LPARAM)
{
HGENMENU hRoot = pcli->pfnGetProtocolMenu(m_szModuleName);
if (hRoot == NULL)
return 0;
char text[200];
- strcpy(text,m_szModuleName);
- char *tDest = text+strlen(text);
+ strcpy(text, m_szModuleName);
+ char *tDest = text + strlen(text);
CLISTMENUITEM mi = { sizeof(mi) };
mi.pszService = text;
@@ -294,7 +280,7 @@ int TwitterProto::OnBuildStatusMenu(WPARAM,LPARAM)
// TODO: Disable this menu item when offline
// "Send Tweet..."
CreateProtoService("/Tweet", &TwitterProto::OnTweet);
- strcpy(tDest,"/Tweet");
+ strcpy(tDest, "/Tweet");
mi.ptszName = LPGENT("Send Tweet...");
mi.popupPosition = 200001;
mi.icolibItem = GetIconHandle("tweet");
@@ -302,62 +288,62 @@ int TwitterProto::OnBuildStatusMenu(WPARAM,LPARAM)
return 0;
}
-int TwitterProto::OnOptionsInit(WPARAM wParam,LPARAM)
+int TwitterProto::OnOptionsInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { sizeof(odp) };
- odp.position = 271828;
- odp.hInstance = g_hInstance;
- odp.ptszGroup = LPGENT("Network");
- odp.ptszTitle = m_tszUserName;
+ odp.position = 271828;
+ odp.hInstance = g_hInstance;
+ odp.ptszGroup = LPGENT("Network");
+ odp.ptszTitle = m_tszUserName;
odp.dwInitParam = LPARAM(this);
- odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR;
+ odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR;
- odp.ptszTab = LPGENT("Basic");
+ odp.ptszTab = LPGENT("Basic");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
- odp.pfnDlgProc = options_proc;
+ odp.pfnDlgProc = options_proc;
Options_AddPage(wParam, &odp);
if (ServiceExists(MS_POPUP_ADDPOPUPT)) {
- odp.ptszTab = LPGENT("Popups");
+ odp.ptszTab = LPGENT("Popups");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_POPUPS);
- odp.pfnDlgProc = popup_options_proc;
+ odp.pfnDlgProc = popup_options_proc;
Options_AddPage(wParam, &odp);
}
return 0;
}
-INT_PTR TwitterProto::OnTweet(WPARAM,LPARAM)
+INT_PTR TwitterProto::OnTweet(WPARAM, LPARAM)
{
- if(m_iStatus != ID_STATUS_ONLINE)
+ if (m_iStatus != ID_STATUS_ONLINE)
return 1;
- HWND hDlg = CreateDialogParam(g_hInstance,MAKEINTRESOURCE(IDD_TWEET), 0,tweet_proc,reinterpret_cast<LPARAM>(this));
- ShowWindow(hDlg,SW_SHOW);
+ HWND hDlg = CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_TWEET), 0, tweet_proc, reinterpret_cast<LPARAM>(this));
+ ShowWindow(hDlg, SW_SHOW);
return 0;
}
-int TwitterProto::OnModulesLoaded(WPARAM,LPARAM)
+int TwitterProto::OnModulesLoaded(WPARAM, LPARAM)
{
TCHAR descr[512];
- NETLIBUSER nlu = {sizeof(nlu)};
+ NETLIBUSER nlu = { sizeof(nlu) };
nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_TCHAR;
nlu.szSettingsModule = m_szModuleName;
// Create standard network connection
- mir_sntprintf(descr,SIZEOF(descr),TranslateT("%s server connection"),m_tszUserName);
+ mir_sntprintf(descr, SIZEOF(descr), TranslateT("%s server connection"), m_tszUserName);
nlu.ptszDescriptiveName = descr;
- m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER,0,(LPARAM)&nlu);
- if(m_hNetlibUser == 0)
+ m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
+ if (m_hNetlibUser == 0)
MessageBox(0, TranslateT("Unable to get Netlib connection for Twitter"), TranslateT("Twitter"), 0);
// Create avatar network connection (TODO: probably remove this)
char module[512];
- mir_snprintf(module,SIZEOF(module),"%sAv",m_szModuleName);
+ mir_snprintf(module, SIZEOF(module), "%sAv", m_szModuleName);
nlu.szSettingsModule = module;
- mir_sntprintf(descr,SIZEOF(descr),TranslateT("%s avatar connection"),m_tszUserName);
+ mir_sntprintf(descr, SIZEOF(descr), TranslateT("%s avatar connection"), m_tszUserName);
nlu.ptszDescriptiveName = descr;
- hAvatarNetlib_ = (HANDLE)CallService(MS_NETLIB_REGISTERUSER,0,(LPARAM)&nlu);
- if(hAvatarNetlib_ == 0)
+ hAvatarNetlib_ = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu);
+ if (hAvatarNetlib_ == 0)
MessageBox(0, TranslateT("Unable to get avatar Netlib connection for Twitter"), TranslateT("Twitter"), 0);
twit_.set_handle(this, m_hNetlibUser);
@@ -366,20 +352,20 @@ int TwitterProto::OnModulesLoaded(WPARAM,LPARAM)
gcr.pszModule = m_szModuleName;
gcr.ptszDispName = m_tszUserName;
gcr.iMaxText = 159;
- CallService(MS_GC_REGISTER,0,reinterpret_cast<LPARAM>(&gcr));
+ CallService(MS_GC_REGISTER, 0, reinterpret_cast<LPARAM>(&gcr));
DBEVENTTYPEDESCR evt = { sizeof(evt) };
evt.eventType = TWITTER_DB_EVENT_TYPE_TWEET;
evt.module = m_szModuleName;
evt.descr = "Tweet";
evt.flags = DETF_HISTORY | DETF_MSGWINDOW;
- CallService(MS_DB_EVENT_REGISTERTYPE,0,reinterpret_cast<LPARAM>(&evt));
+ CallService(MS_DB_EVENT_REGISTERTYPE, 0, reinterpret_cast<LPARAM>(&evt));
SetAllContactStatuses(ID_STATUS_OFFLINE); // In case we crashed last time
return 0;
}
-int TwitterProto::OnPreShutdown(WPARAM,LPARAM)
+int TwitterProto::OnPreShutdown(WPARAM, LPARAM)
{
Netlib_Shutdown(m_hNetlibUser);
Netlib_Shutdown(hAvatarNetlib_);
@@ -388,7 +374,7 @@ int TwitterProto::OnPreShutdown(WPARAM,LPARAM)
int TwitterProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM)
{
- if(IsMyContact(hContact))
+ if (IsMyContact(hContact))
ShowContactMenus(true);
return 0;
@@ -396,8 +382,8 @@ int TwitterProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM)
int TwitterProto::ShowPinDialog()
{
- HWND hDlg = (HWND)DialogBoxParam(g_hInstance,MAKEINTRESOURCE(IDD_TWITTERPIN),0,pin_proc,reinterpret_cast<LPARAM>(this));
- ShowWindow(hDlg,SW_SHOW);
+ HWND hDlg = (HWND)DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_TWITTERPIN), 0, pin_proc, reinterpret_cast<LPARAM>(this));
+ ShowWindow(hDlg, SW_SHOW);
return 0;
}
@@ -413,10 +399,10 @@ void TwitterProto::ShowPopup(const wchar_t *text, int Error)
popup.colorText = 0x00FFFFFF;
}
- if(ServiceExists(MS_POPUP_ADDPOPUPT))
+ if (ServiceExists(MS_POPUP_ADDPOPUPT))
PUAddPopupT(&popup);
else
- MessageBox(0,popup.lptzText,popup.lptzContactName,0);
+ MessageBox(0, popup.lptzText, popup.lptzContactName, 0);
}
void TwitterProto::ShowPopup(const char *text, int Error)
@@ -430,10 +416,10 @@ void TwitterProto::ShowPopup(const char *text, int Error)
popup.colorText = 0x00FFFFFF;
}
- if(ServiceExists(MS_POPUP_ADDPOPUPT))
+ if (ServiceExists(MS_POPUP_ADDPOPUPT))
PUAddPopupT(&popup);
else
- MessageBox(0,popup.lptzText,popup.lptzContactName,0);
+ MessageBox(0, popup.lptzText, popup.lptzContactName, 0);
}
// TODO: the more I think about it, the more I think all twit.* methods should
@@ -446,12 +432,12 @@ void TwitterProto::SendTweetWorker(void *p)
char *text = static_cast<char*>(p);
if (strlen(text) > 140) { // looks like the chat max outgoing msg thing doesn't work, so i'll do it here.
TCHAR errorPopup[280];
- mir_sntprintf(errorPopup,SIZEOF(errorPopup), _T("Don't be crazy! Everyone knows the max tweet size is 140, and you're trying to fit %d chars in there?"), strlen(text));
+ mir_sntprintf(errorPopup, SIZEOF(errorPopup), _T("Don't be crazy! Everyone knows the max tweet size is 140, and you're trying to fit %d chars in there?"), strlen(text));
ShowPopup(errorPopup, 1);
return;
}
- ScopedLock s(twitter_lock_);
+ mir_cslock s(twitter_lock_);
twit_.set_status(text);
mir_free(text);
@@ -459,19 +445,17 @@ void TwitterProto::SendTweetWorker(void *p)
void TwitterProto::UpdateSettings()
{
- if(db_get_b(0,m_szModuleName,TWITTER_KEY_CHATFEED,0))
- {
- if(!in_chat_)
- OnJoinChat(0,0);
+ if (db_get_b(0, m_szModuleName, TWITTER_KEY_CHATFEED, 0)) {
+ if (!in_chat_)
+ OnJoinChat(0, 0);
}
- else
- {
- if(in_chat_)
- OnLeaveChat(0,0);
+ else {
+ if (in_chat_)
+ OnLeaveChat(0, 0);
- for(MCONTACT hContact = db_find_first(m_szModuleName); hContact; ) {
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact;) {
MCONTACT hNext = db_find_next(hContact, m_szModuleName);
- if(isChatRoom(hContact))
+ if (isChatRoom(hContact))
CallService(MS_DB_CONTACT_DELETE, WPARAM(hContact), 0);
hContact = hNext;
}
@@ -481,16 +465,16 @@ void TwitterProto::UpdateSettings()
std::tstring TwitterProto::GetAvatarFolder()
{
TCHAR path[MAX_PATH];
- mir_sntprintf(path, SIZEOF(path), _T("%s\\%s"), VARST( _T("%miranda_avatarcache%")), m_tszUserName);
+ mir_sntprintf(path, SIZEOF(path), _T("%s\\%s"), VARST(_T("%miranda_avatarcache%")), m_tszUserName);
return path;
}
-INT_PTR TwitterProto::GetAvatar(WPARAM,LPARAM)
+INT_PTR TwitterProto::GetAvatar(WPARAM, LPARAM)
{
return 0;
}
-INT_PTR TwitterProto::SetAvatar(WPARAM,LPARAM)
+INT_PTR TwitterProto::SetAvatar(WPARAM, LPARAM)
{
return 0;
}
diff --git a/protocols/Twitter/src/proto.h b/protocols/Twitter/src/proto.h
index f5b658aebb..fc78347aa9 100644
--- a/protocols/Twitter/src/proto.h
+++ b/protocols/Twitter/src/proto.h
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -33,45 +34,19 @@ public:
//PROTO_INTERFACE
virtual MCONTACT __cdecl AddToList(int,PROTOSEARCHRESULT *);
- virtual MCONTACT __cdecl AddToListByEvent(int,int,MEVENT);
-
- virtual int __cdecl Authorize(MEVENT);
- virtual int __cdecl AuthDeny(MEVENT,const TCHAR *);
- virtual int __cdecl AuthRecv(MCONTACT, PROTORECVEVENT *);
- virtual int __cdecl AuthRequest(MCONTACT, const TCHAR *);
-
- virtual HANDLE __cdecl FileAllow(MCONTACT, HANDLE, const TCHAR *);
- virtual int __cdecl FileCancel(MCONTACT, HANDLE);
- virtual int __cdecl FileDeny(MCONTACT, HANDLE, const TCHAR *);
- virtual int __cdecl FileResume(HANDLE, int *, const TCHAR **);
virtual DWORD_PTR __cdecl GetCaps(int, MCONTACT = 0);
virtual int __cdecl GetInfo(MCONTACT, int);
virtual HANDLE __cdecl SearchBasic(const TCHAR *);
virtual HANDLE __cdecl SearchByEmail(const TCHAR *);
- virtual HANDLE __cdecl SearchByName(const TCHAR *,const TCHAR *,const TCHAR *);
- virtual HWND __cdecl SearchAdvanced(HWND);
- virtual HWND __cdecl CreateExtendedSearchUI(HWND);
- virtual int __cdecl RecvContacts(MCONTACT, PROTORECVEVENT *);
- virtual int __cdecl RecvFile(MCONTACT, PROTORECVFILET *);
virtual int __cdecl RecvMsg(MCONTACT, PROTORECVEVENT *);
- virtual int __cdecl RecvUrl(MCONTACT, PROTORECVEVENT *);
-
- virtual int __cdecl SendContacts(MCONTACT, int, int, MCONTACT*);
- virtual HANDLE __cdecl SendFile(MCONTACT, const TCHAR *, TCHAR **);
virtual int __cdecl SendMsg(MCONTACT, int, const char *);
- virtual int __cdecl SendUrl(MCONTACT, int, const char *);
- virtual int __cdecl SetApparentMode(MCONTACT, int);
virtual int __cdecl SetStatus(int);
virtual HANDLE __cdecl GetAwayMsg(MCONTACT);
- virtual int __cdecl RecvAwayMsg(MCONTACT, int, PROTORECVEVENT *);
- virtual int __cdecl SetAwayMsg(int,const TCHAR *);
-
- virtual int __cdecl UserIsTyping(MCONTACT, int);
virtual int __cdecl OnEvent(PROTOEVENTTYPE,WPARAM,LPARAM);
@@ -140,9 +115,9 @@ private:
std::tstring GetAvatarFolder();
- HANDLE signon_lock_;
- HANDLE avatar_lock_;
- HANDLE twitter_lock_;
+ mir_cs signon_lock_;
+ mir_cs avatar_lock_;
+ mir_cs twitter_lock_;
HANDLE hAvatarNetlib_;
HANDLE hMsgLoop_;
diff --git a/protocols/Twitter/src/stdafx.cpp b/protocols/Twitter/src/stdafx.cpp
index 058bd215c8..fd705e1c02 100644
--- a/protocols/Twitter/src/stdafx.cpp
+++ b/protocols/Twitter/src/stdafx.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
diff --git a/protocols/Twitter/src/stubs.cpp b/protocols/Twitter/src/stubs.cpp
deleted file mode 100644
index 38f7b93288..0000000000
--- a/protocols/Twitter/src/stubs.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
-Copyright © 2009 Jim Porter
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "stdafx.h"
-#include "proto.h"
-
-MCONTACT TwitterProto::AddToListByEvent(int flags,int iContact,MEVENT hDbEvent)
-{
- return NULL;
-}
-
-int TwitterProto::Authorize(MEVENT hDbEvent)
-{
- return 1;
-}
-
-int TwitterProto::AuthDeny(MEVENT hDbEvent,const TCHAR *reason)
-{
- return 1;
-}
-
-int TwitterProto::AuthRecv(MCONTACT hContact,PROTORECVEVENT *)
-{
- return 1;
-}
-
-int TwitterProto::AuthRequest(MCONTACT hContact,const TCHAR *message)
-{
- return 1;
-}
-
-HANDLE TwitterProto::FileAllow(MCONTACT hContact,HANDLE hTransfer,const TCHAR *path)
-{
- return NULL;
-}
-
-int TwitterProto::FileCancel(MCONTACT hContact,HANDLE hTransfer)
-{
- return 1;
-}
-
-int TwitterProto::FileDeny(MCONTACT hContact,HANDLE hTransfer,const TCHAR *reason)
-{
- return 1;
-}
-
-int TwitterProto::FileResume(HANDLE hTransfer,int *action,const TCHAR **filename)
-{
- return 1;
-}
-
-HANDLE TwitterProto::SearchByName(const TCHAR *nick,const TCHAR *first_name, const TCHAR *last_name)
-{
- return NULL;
-}
-
-HWND TwitterProto::SearchAdvanced(HWND owner)
-{
- return NULL;
-}
-
-HWND TwitterProto::CreateExtendedSearchUI(HWND owner)
-{
- return NULL;
-}
-
-int TwitterProto::RecvContacts(MCONTACT hContact,PROTORECVEVENT *)
-{
- return 1;
-}
-
-int TwitterProto::RecvFile(MCONTACT hContact,PROTORECVFILET *)
-{
- return 1;
-}
-
-int TwitterProto::RecvUrl(MCONTACT hContact,PROTORECVEVENT *)
-{
- return 1;
-}
-
-int TwitterProto::SendContacts(MCONTACT hContact, int flags, int nContacts, MCONTACT *hContactsList)
-{
- return 1;
-}
-
-HANDLE TwitterProto::SendFile(MCONTACT hContact,const TCHAR *desc, TCHAR **files)
-{
- return NULL;
-}
-
-int TwitterProto::SendUrl(MCONTACT hContact,int flags,const char *url)
-{
- return 1;
-}
-
-int TwitterProto::SetApparentMode(MCONTACT hContact,int mode)
-{
- return 1;
-}
-
-int TwitterProto::RecvAwayMsg(MCONTACT hContact,int mode,PROTORECVEVENT *evt)
-{
- return 1;
-}
-
-int TwitterProto::SetAwayMsg(int status,const TCHAR *msg)
-{
- return 1;
-}
-
-int TwitterProto::UserIsTyping(MCONTACT hContact,int type)
-{
- return 1;
-}
diff --git a/protocols/Twitter/src/theme.cpp b/protocols/Twitter/src/theme.cpp
index 5e7235f7c2..8a0d3960cc 100644
--- a/protocols/Twitter/src/theme.cpp
+++ b/protocols/Twitter/src/theme.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -36,13 +37,13 @@ static HANDLE hIconLibItem[SIZEOF(icons)];
void InitIcons(void)
{
Icon_Register(g_hInstance, "Protocols/Twitter", icons, SIZEOF(icons), "Twitter");
- icons[ SIZEOF(icons)-1 ].hIcolib = LoadSkinnedIconHandle(SKINICON_EVENT_URL);
+ icons[SIZEOF(icons) - 1].hIcolib = LoadSkinnedIconHandle(SKINICON_EVENT_URL);
}
HANDLE GetIconHandle(const char* name)
{
- for(size_t i=0; i<SIZEOF(icons); i++)
- if(strcmp(icons[i].szName, name) == 0)
+ for (size_t i = 0; i < SIZEOF(icons); i++)
+ if (strcmp(icons[i].szName, name) == 0)
return hIconLibItem[i];
return 0;
@@ -56,46 +57,46 @@ static HANDLE g_hMenuEvts[3];
static TwitterProto * GetInstanceByHContact(MCONTACT hContact)
{
char *proto = GetContactProto(hContact);
- if(!proto)
+ if (!proto)
return 0;
- for(int i=0; i<g_Instances.getCount(); i++)
- if(!strcmp(proto,g_Instances[i].m_szModuleName))
+ for (int i = 0; i < g_Instances.getCount(); i++)
+ if (!strcmp(proto, g_Instances[i].m_szModuleName))
return &g_Instances[i];
return 0;
}
-template<INT_PTR (__cdecl TwitterProto::*Fcn)(WPARAM,LPARAM)>
-INT_PTR GlobalService(WPARAM wParam,LPARAM lParam)
+template<INT_PTR(__cdecl TwitterProto::*Fcn)(WPARAM, LPARAM)>
+INT_PTR GlobalService(WPARAM wParam, LPARAM lParam)
{
TwitterProto *proto = GetInstanceByHContact(MCONTACT(wParam));
- return proto ? (proto->*Fcn)(wParam,lParam) : 0;
+ return proto ? (proto->*Fcn)(wParam, lParam) : 0;
}
-static int PrebuildContactMenu(WPARAM wParam,LPARAM lParam)
+static int PrebuildContactMenu(WPARAM wParam, LPARAM lParam)
{
ShowContactMenus(false);
TwitterProto *proto = GetInstanceByHContact(MCONTACT(wParam));
- return proto ? proto->OnPrebuildContactMenu(wParam,lParam) : 0;
+ return proto ? proto->OnPrebuildContactMenu(wParam, lParam) : 0;
}
void InitContactMenus()
{
- g_hMenuEvts[0] = HookEvent(ME_CLIST_PREBUILDCONTACTMENU,PrebuildContactMenu);
+ g_hMenuEvts[0] = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, PrebuildContactMenu);
- CLISTMENUITEM mi = {sizeof(mi)};
+ CLISTMENUITEM mi = { sizeof(mi) };
mi.flags = CMIF_NOTOFFLINE | CMIF_TCHAR;
- mi.position=-2000006000;
+ mi.position = -2000006000;
mi.icolibItem = GetIconHandle("reply");
mi.ptszName = LPGENT("Reply...");
mi.pszService = "Twitter/ReplyToTweet";
g_hMenuEvts[1] = CreateServiceFunction(mi.pszService, GlobalService<&TwitterProto::ReplyToTweet>);
g_hMenuItems[0] = Menu_AddContactMenuItem(&mi);
- mi.position=-2000006000;
+ mi.position = -2000006000;
mi.icolibItem = GetIconHandle("homepage");
mi.ptszName = LPGENT("Visit Homepage");
mi.pszService = "Twitter/VisitHomepage";
@@ -105,16 +106,16 @@ void InitContactMenus()
void UninitContactMenus()
{
- for(size_t i=0; i<SIZEOF(g_hMenuItems); i++)
+ for (size_t i = 0; i < SIZEOF(g_hMenuItems); i++)
CallService(MO_REMOVEMENUITEM, (WPARAM)g_hMenuItems[i], 0);
UnhookEvent(g_hMenuEvts[0]);
- for(size_t i=1; i<SIZEOF(g_hMenuEvts); i++)
+ for (size_t i = 1; i < SIZEOF(g_hMenuEvts); i++)
DestroyServiceFunction(g_hMenuEvts[i]);
}
void ShowContactMenus(bool show)
{
- for(size_t i=0; i<SIZEOF(g_hMenuItems); i++)
+ for (size_t i = 0; i < SIZEOF(g_hMenuItems); i++)
Menu_ShowItem(g_hMenuItems[i], show);
-} \ No newline at end of file
+}
diff --git a/protocols/Twitter/src/theme.h b/protocols/Twitter/src/theme.h
index e74f5da2e3..96492938f9 100644
--- a/protocols/Twitter/src/theme.h
+++ b/protocols/Twitter/src/theme.h
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
diff --git a/protocols/Twitter/src/twitter.cpp b/protocols/Twitter/src/twitter.cpp
index 504ec20206..1a762ec08d 100644
--- a/protocols/Twitter/src/twitter.cpp
+++ b/protocols/Twitter/src/twitter.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -21,53 +22,48 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "tinyjson.hpp"
#include <boost/lexical_cast.hpp>
-//#include "boost/spirit/include/classic_core.hpp"
-//#include "boost/spirit/include/classic_loops.hpp"
-
typedef json::grammar<char> js;
// utility functions
template <typename T>
-static T cast_and_decode(boost::any &a,bool allow_null)
+static T cast_and_decode(boost::any &a, bool allow_null)
{
- if(allow_null && a.type() == typeid(void))
+ if (allow_null && a.type() == typeid(void))
return T();
return boost::any_cast<T>(a);
}
template <>
-static std::string cast_and_decode<std::string>(boost::any &a,bool allow_null)
+static std::string cast_and_decode<std::string>(boost::any &a, bool allow_null)
{
- if(allow_null && a.type() == typeid(void))
+ if (allow_null && a.type() == typeid(void))
return std::string();
std::string s = boost::any_cast<std::string>(a);
// Twitter *only* encodes < and >, so decode them
size_t off;
- while( (off = s.find("&lt;")) != std::string::npos)
- s.replace(off,4,"<");
- while( (off = s.find("&gt;")) != std::string::npos)
- s.replace(off,4,">");
+ while ((off = s.find("&lt;")) != std::string::npos)
+ s.replace(off, 4, "<");
+ while ((off = s.find("&gt;")) != std::string::npos)
+ s.replace(off, 4, ">");
return s;
}
template <typename T>
-static T retrieve(const js::object &o,const std::string &key,bool allow_null = false)
+static T retrieve(const js::object &o, const std::string &key, bool allow_null = false)
{
using boost::any_cast;
js::object::const_iterator i = o.find(key);
- if(i == o.end())
- throw std::exception( ("unable to retrieve key '"+key+"'").c_str());
- try
- {
- return cast_and_decode<T>(*i->second,allow_null);
+ if (i == o.end())
+ throw std::exception(("unable to retrieve key '" + key + "'").c_str());
+ try {
+ return cast_and_decode<T>(*i->second, allow_null);
}
- catch(const boost::bad_any_cast &)
- {
- throw std::exception( ("unable to cast key '"+key+"' to target type").c_str());
+ catch (const boost::bad_any_cast &) {
+ throw std::exception(("unable to cast key '" + key + "' to target type").c_str());
}
}
@@ -76,27 +72,29 @@ static T retrieve(const js::object &o,const std::string &key,bool allow_null = f
twitter::twitter() : base_url_("https://api.twitter.com/")
{}
-bool twitter::set_credentials(const std::string &username, const std::wstring &consumerKey, const std::wstring &consumerSecret,
+bool twitter::set_credentials(const std::string &username, const std::wstring &consumerKey, const std::wstring &consumerSecret,
const std::wstring &oauthAccessToken, const std::wstring &oauthAccessTokenSecret, const std::wstring &pin, bool test)
{
- username_ = username;
- consumerKey_ = consumerKey;
- consumerSecret_ = consumerSecret;
- oauthAccessToken_ = oauthAccessToken;
+ username_ = username;
+ consumerKey_ = consumerKey;
+ consumerSecret_ = consumerSecret;
+ oauthAccessToken_ = oauthAccessToken;
oauthAccessTokenSecret_ = oauthAccessTokenSecret;
pin_ = pin;
- if(test)
- return slurp(base_url_+"1.1/account/verify_credentials.json",http::get).code == 200;
+ if (test)
+ return slurp(base_url_ + "1.1/account/verify_credentials.json", http::get).code == 200;
else
return true;
}
-http::response twitter::request_token() {
- return slurp("https://api.twitter.com/oauth/request_token",http::get);
+http::response twitter::request_token()
+{
+ return slurp("https://api.twitter.com/oauth/request_token", http::get);
}
-http::response twitter::request_access_tokens() {
+http::response twitter::request_access_tokens()
+{
return slurp("https://api.twitter.com/oauth/access_token", http::get);
}
@@ -123,38 +121,38 @@ const std::string & twitter::get_base_url() const
js::array masterIDs; // the list that contains all the users that the user follows
std::vector<twitter_user> friends;
-
+
while (friendCursor != 0) {
- http::response resp = slurp(base_url_ + "/1.1/followers/ids.json?cursor=" + friendCursor + "&screen_name=" + username_,http::get);
- if(resp.code != 200)
- throw bad_response();
-
- const js::variant var = json::parse( resp.data.begin(),resp.data.end() ); // pull the data out of the http response
- if(var->type() == typeid(js::object)) // make sure the parsed data is of type js::object (??)
- {
- const js::object &friendIDs = boost::any_cast<js::object>(*var); // cast the object into the type we can use
- if(friendIDs.find("error") != friendIDs.end()) // don't really know why error should be at the end here?
- throw std::exception("error while parsing friendIDs object from ids.json");
-
- // ok need to find out how to convert all the IDs into an array. dunno if i can magically make it happen, or
- // if i will have to parse it myself and add them one by one :(
- IDs = retrieve<js::array>(friendIDs,"ids");
- for(js::array::const_iterator i=IDs.begin(); i!=IDs.end(); ++i) {
- //debugLogA("friends ID: " + i);
- // add array to master array
- js::object one = boost::any_cast<js::object>(**i);
- masterIDs.push_back(one); // i don't understand this. how do we push into the array? should i just use C++ arrays (list?) and bail on boost?
- }
+ http::response resp = slurp(base_url_ + "/1.1/followers/ids.json?cursor=" + friendCursor + "&screen_name=" + username_,http::get);
+ if(resp.code != 200)
+ throw bad_response();
- // now we need to pick out the cursor stuff, and keep punching IDs into the array
- }
- else {
- throw std::exception("in buildFriendList(), return type is not js::object");
- }
+ const js::variant var = json::parse( resp.data.begin(),resp.data.end() ); // pull the data out of the http response
+ if(var->type() == typeid(js::object)) // make sure the parsed data is of type js::object (??)
+ {
+ const js::object &friendIDs = boost::any_cast<js::object>(*var); // cast the object into the type we can use
+ if(friendIDs.find("error") != friendIDs.end()) // don't really know why error should be at the end here?
+ throw std::exception("error while parsing friendIDs object from ids.json");
+
+ // ok need to find out how to convert all the IDs into an array. dunno if i can magically make it happen, or
+ // if i will have to parse it myself and add them one by one :(
+ IDs = retrieve<js::array>(friendIDs,"ids");
+ for(js::array::const_iterator i=IDs.begin(); i!=IDs.end(); ++i) {
+ //debugLogA("friends ID: " + i);
+ // add array to master array
+ js::object one = boost::any_cast<js::object>(**i);
+ masterIDs.push_back(one); // i don't understand this. how do we push into the array? should i just use C++ arrays (list?) and bail on boost?
+ }
+
+ // now we need to pick out the cursor stuff, and keep punching IDs into the array
+ }
+ else {
+ throw std::exception("in buildFriendList(), return type is not js::object");
+ }
}
-}*/
+ }*/
std::vector<twitter_user> twitter::get_friends()
@@ -163,36 +161,33 @@ std::vector<twitter_user> twitter::get_friends()
//js::array friendArray = buildFriendList();
std::vector<twitter_user> friends;
- http::response resp = slurp(base_url_+"1.1/statuses/friends.json",http::get);
+ http::response resp = slurp(base_url_ + "1.1/statuses/friends.json", http::get);
- if(resp.code != 200)
+ if (resp.code != 200)
throw bad_response();
- const js::variant var = json::parse( resp.data.begin(),resp.data.end());
- if(var->type() != typeid(js::array))
+ const js::variant var = json::parse(resp.data.begin(), resp.data.end());
+ if (var->type() != typeid(js::array))
throw std::exception("unable to parse response");
const js::array &list = boost::any_cast<js::array>(*var);
- for(js::array::const_iterator i=list.begin(); i!=list.end(); ++i)
- {
- if((*i)->type() == typeid(js::object))
- {
+ for (js::array::const_iterator i = list.begin(); i != list.end(); ++i) {
+ if ((*i)->type() == typeid(js::object)) {
const js::object &one = boost::any_cast<js::object>(**i);
twitter_user user;
- user.username = retrieve<std::string>(one,"screen_name");
- user.real_name = retrieve<std::string>(one,"name",true);
- user.profile_image_url = retrieve<std::string>(one,"profile_image_url",true);
+ user.username = retrieve<std::string>(one, "screen_name");
+ user.real_name = retrieve<std::string>(one, "name", true);
+ user.profile_image_url = retrieve<std::string>(one, "profile_image_url", true);
- if(one.find("status") != one.end())
- {
- js::object &status = retrieve<js::object>(one,"status");
- user.status.text = retrieve<std::string>(status,"text");
+ if (one.find("status") != one.end()) {
+ js::object &status = retrieve<js::object>(one, "status");
+ user.status.text = retrieve<std::string>(status, "text");
- user.status.id = retrieve<long long>(status,"id");
+ user.status.id = retrieve<long long>(status, "id");
- std::string timestr = retrieve<std::string>(status,"created_at");
- user.status.time = parse_time(timestr);
+ std::string timestr = retrieve<std::string>(status, "created_at");
+ user.status.time = parse_time(timestr);
}
friends.push_back(user);
@@ -202,27 +197,26 @@ std::vector<twitter_user> twitter::get_friends()
return friends;
}
-bool twitter::get_info(const std::string &name,twitter_user *info)
+bool twitter::get_info(const std::string &name, twitter_user *info)
{
- if(!info)
+ if (!info)
return false;
- std::string url = base_url_+"1.1/users/show/"+http::url_encode(name)+".json";
+ std::string url = base_url_ + "1.1/users/show/" + http::url_encode(name) + ".json";
- http::response resp = slurp(url,http::get);
- if(resp.code != 200)
+ http::response resp = slurp(url, http::get);
+ if (resp.code != 200)
throw bad_response();
- const js::variant var = json::parse( resp.data.begin(),resp.data.end());
- if(var->type() == typeid(js::object))
- {
+ const js::variant var = json::parse(resp.data.begin(), resp.data.end());
+ if (var->type() == typeid(js::object)) {
const js::object &user_info = boost::any_cast<js::object>(*var);
- if(user_info.find("error") != user_info.end())
+ if (user_info.find("error") != user_info.end())
return false;
- info->username = retrieve<std::string>(user_info,"screen_name");
- info->real_name = retrieve<std::string>(user_info,"name",true);
- info->profile_image_url = retrieve<std::string>(user_info,"profile_image_url",true);
+ info->username = retrieve<std::string>(user_info, "screen_name");
+ info->real_name = retrieve<std::string>(user_info, "name", true);
+ info->profile_image_url = retrieve<std::string>(user_info, "profile_image_url", true);
return true;
}
@@ -230,27 +224,26 @@ bool twitter::get_info(const std::string &name,twitter_user *info)
return false;
}
-bool twitter::get_info_by_email(const std::string &email,twitter_user *info)
+bool twitter::get_info_by_email(const std::string &email, twitter_user *info)
{
- if(!info)
+ if (!info)
return false;
- std::string url = base_url_+"1.1/users/show.json?email="+http::url_encode(email);
+ std::string url = base_url_ + "1.1/users/show.json?email=" + http::url_encode(email);
- http::response resp = slurp(url,http::get);
- if(resp.code != 200)
+ http::response resp = slurp(url, http::get);
+ if (resp.code != 200)
throw bad_response();
- js::variant var = json::parse( resp.data.begin(),resp.data.end());
- if(var->type() == typeid(js::object))
- {
+ js::variant var = json::parse(resp.data.begin(), resp.data.end());
+ if (var->type() == typeid(js::object)) {
const js::object &user_info = boost::any_cast<js::object>(*var);
- if(user_info.find("error") != user_info.end())
+ if (user_info.find("error") != user_info.end())
return false;
- info->username = retrieve<std::string>(user_info,"screen_name");
- info->real_name = retrieve<std::string>(user_info,"name",true);
- info->profile_image_url = retrieve<std::string>(user_info,"profile_image_url",true);
+ info->username = retrieve<std::string>(user_info, "screen_name");
+ info->real_name = retrieve<std::string>(user_info, "name", true);
+ info->profile_image_url = retrieve<std::string>(user_info, "profile_image_url", true);
return true;
}
@@ -260,27 +253,26 @@ bool twitter::get_info_by_email(const std::string &email,twitter_user *info)
twitter_user twitter::add_friend(const std::string &name)
{
- std::string url = base_url_+"1.1/friendships/create/"+http::url_encode(name)+".json";
+ std::string url = base_url_ + "1.1/friendships/create/" + http::url_encode(name) + ".json";
twitter_user ret;
- http::response resp = slurp(url,http::post);
- if(resp.code != 200)
+ http::response resp = slurp(url, http::post);
+ if (resp.code != 200)
throw bad_response();
- js::variant var = json::parse( resp.data.begin(),resp.data.end());
- if(var->type() != typeid(js::object))
+ js::variant var = json::parse(resp.data.begin(), resp.data.end());
+ if (var->type() != typeid(js::object))
throw std::exception("unable to parse response");
const js::object &user_info = boost::any_cast<js::object>(*var);
- ret.username = retrieve<std::string>(user_info,"screen_name");
- ret.real_name = retrieve<std::string>(user_info,"name",true);
- ret.profile_image_url = retrieve<std::string>(user_info,"profile_image_url",true);
+ ret.username = retrieve<std::string>(user_info, "screen_name");
+ ret.real_name = retrieve<std::string>(user_info, "name", true);
+ ret.profile_image_url = retrieve<std::string>(user_info, "profile_image_url", true);
- if(user_info.find("status") != user_info.end())
- {
+ if (user_info.find("status") != user_info.end()) {
// TODO: fill in more fields
- const js::object &status = retrieve<js::object>(user_info,"status");
- ret.status.text = retrieve<std::string>(status,"text");
+ const js::object &status = retrieve<js::object>(user_info, "status");
+ ret.status.text = retrieve<std::string>(status, "text");
}
return ret;
@@ -288,106 +280,94 @@ twitter_user twitter::add_friend(const std::string &name)
void twitter::remove_friend(const std::string &name)
{
- std::string url = base_url_+"1.1/friendships/destroy/"+http::url_encode(name)+".json";
+ std::string url = base_url_ + "1.1/friendships/destroy/" + http::url_encode(name) + ".json";
- slurp(url,http::post);
+ slurp(url, http::post);
}
void twitter::set_status(const std::string &text)
{
- if(text.size())
- {
-/* slurp(base_url_+"statuses/update.json",http::post,
- "status="+http::url_encode(text)+
- "&source=mirandang");*/
-
- //MessageBox(NULL, UTF8ToWide(text).c_str(), NULL, MB_OK);
+ if (text.size()) {
std::wstring wTweet = UTF8ToWide(text);
OAuthParameters postParams;
postParams[L"status"] = UrlEncode(wTweet);
- slurp(base_url_+"1.1/statuses/update.json",http::post, postParams);
+ slurp(base_url_ + "1.1/statuses/update.json", http::post, postParams);
}
}
-void twitter::send_direct(const std::string &name,const std::string &text)
+void twitter::send_direct(const std::string &name, const std::string &text)
{
std::wstring temp = UTF8ToWide(text);
OAuthParameters postParams;
postParams[L"text"] = UrlEncode(temp);
postParams[L"screen_name"] = UTF8ToWide(name);
- slurp(base_url_+"1.1/direct_messages/new.json", http::post, postParams);
+ slurp(base_url_ + "1.1/direct_messages/new.json", http::post, postParams);
}
-std::vector<twitter_user> twitter::get_statuses(int count,twitter_id id)
+std::vector<twitter_user> twitter::get_statuses(int count, twitter_id id)
{
using boost::lexical_cast;
std::vector<twitter_user> statuses;
- std::string url = base_url_+"1.1/statuses/home_timeline.json?count="+
+ std::string url = base_url_ + "1.1/statuses/home_timeline.json?count=" +
lexical_cast<std::string>(count);
- if(id != 0)
- url += "&since_id="+boost::lexical_cast<std::string>(id);
+ if (id != 0)
+ url += "&since_id=" + boost::lexical_cast<std::string>(id);
- http::response resp = slurp(url,http::get);
- if(resp.code != 200)
+ http::response resp = slurp(url, http::get);
+ if (resp.code != 200)
throw bad_response();
- js::variant var = json::parse( resp.data.begin(),resp.data.end());
- if(var->type() != typeid(js::array))
+ js::variant var = json::parse(resp.data.begin(), resp.data.end());
+ if (var->type() != typeid(js::array))
throw std::exception("unable to parse response");
const js::array &list = boost::any_cast<js::array>(*var);
- for(js::array::const_iterator i=list.begin(); i!=list.end(); ++i)
- {
- if((*i)->type() == typeid(js::object))
- {
- const js::object &one = boost::any_cast<js::object>(**i);
- const js::object &user = retrieve<js::object>(one,"user");
+ for (js::array::const_iterator i = list.begin(); i != list.end(); ++i) {
+ if ((*i)->type() == typeid(js::object)) {
+ const js::object &one = boost::any_cast<js::object>(**i);
+ const js::object &user = retrieve<js::object>(one, "user");
twitter_user u;
- u.username = retrieve<std::string>(user,"screen_name");
- u.profile_image_url = retrieve<std::string>(user,"profile_image_url");
+ u.username = retrieve<std::string>(user, "screen_name");
+ u.profile_image_url = retrieve<std::string>(user, "profile_image_url");
// the tweet will be truncated unless we take action. i hate you twitter API
- if(one.find("retweeted_status") != one.end())
- {
+ if (one.find("retweeted_status") != one.end()) {
//MessageBox(NULL, L"retweeted: TRUE", L"long tweets", MB_OK);
// here we grab the "retweeted_status" um.. section? it's in here that all the info we need is
// at this point the user will get no tweets and an error popup if the tweet happens to be exactly 140 chars, start with
// "RT @", end in " ...", and notactually be a real retweet. it's possible but unlikely, wish i knew how to get
// the retweet_count variable to work :(
- const js::object &Retweet = retrieve<js::object>(one,"retweeted_status");
- const js::object &RTUser = retrieve<js::object>(Retweet,"user");
+ const js::object &Retweet = retrieve<js::object>(one, "retweeted_status");
+ const js::object &RTUser = retrieve<js::object>(Retweet, "user");
- std::string retweeteesName = retrieve<std::string>(RTUser,"screen_name"); // the user that is being retweeted
- std::string retweetText = retrieve<std::string>(Retweet,"text"); // their tweet in all it's untruncated glory
+ std::string retweeteesName = retrieve<std::string>(RTUser, "screen_name"); // the user that is being retweeted
+ std::string retweetText = retrieve<std::string>(Retweet, "text"); // their tweet in all it's untruncated glory
// fix "&amp;" in the tweets :(
- for(size_t pos = 0;(pos = retweetText.find("&amp;", pos)) != std::string::npos;pos++)
- {
+ for (size_t pos = 0; (pos = retweetText.find("&amp;", pos)) != std::string::npos; pos++) {
retweetText.replace(pos, 5, "&");
}
u.status.text = "RT @" + retweeteesName + " " + retweetText; // mash it together in some format people will understand
}
- else
- {
+ else {
// if it's not truncated, then the twitter API returns the native RT correctly anyway,
- std::string rawText = retrieve<std::string>(one,"text");
+ std::string rawText = retrieve<std::string>(one, "text");
// ok here i'm trying some way to fix all the "&amp;" things that are showing up
// i dunno why it's happening, so i'll just find and replace each occurance :/
- for(size_t pos = 0;(pos = rawText.find("&amp;", pos)) != std::string::npos;pos++)
- {
+ for (size_t pos = 0; (pos = rawText.find("&amp;", pos)) != std::string::npos; pos++) {
rawText.replace(pos, 5, "&");
}
u.status.text = rawText;
}
- u.status.id = retrieve<long long>(one,"id");
- std::string timestr = retrieve<std::string>(one,"created_at");
- u.status.time = parse_time(timestr);
+ u.status.id = retrieve<long long>(one, "id");
+ std::string timestr = retrieve<std::string>(one, "created_at");
+ u.status.time = parse_time(timestr);
statuses.push_back(u);
}
@@ -401,38 +381,35 @@ std::vector<twitter_user> twitter::get_direct(twitter_id id)
{
std::vector<twitter_user> messages;
- std::string url = base_url_+"1.1/direct_messages.json";
- if(id != 0)
- url += "?since_id="+boost::lexical_cast<std::string>(id);
+ std::string url = base_url_ + "1.1/direct_messages.json";
+ if (id != 0)
+ url += "?since_id=" + boost::lexical_cast<std::string>(id);
- http::response resp = slurp(url,http::get);
- if(resp.code != 200)
+ http::response resp = slurp(url, http::get);
+ if (resp.code != 200)
throw bad_response();
- js::variant var = json::parse( resp.data.begin(),resp.data.end());
- if(var->type() != typeid(js::array))
+ js::variant var = json::parse(resp.data.begin(), resp.data.end());
+ if (var->type() != typeid(js::array))
throw std::exception("unable to parse response");
const js::array &list = boost::any_cast<js::array>(*var);
- for(js::array::const_iterator i=list.begin(); i!=list.end(); ++i)
- {
- if((*i)->type() == typeid(js::object))
- {
+ for (js::array::const_iterator i = list.begin(); i != list.end(); ++i) {
+ if ((*i)->type() == typeid(js::object)) {
const js::object &one = boost::any_cast<js::object>(**i);
twitter_user u;
- u.username = retrieve<std::string>(one,"sender_screen_name");
+ u.username = retrieve<std::string>(one, "sender_screen_name");
- u.status.text = retrieve<std::string>(one,"text");
- u.status.id = retrieve<long long>(one,"id");
- std::string timestr = retrieve<std::string>(one,"created_at");
- u.status.time = parse_time(timestr);
+ u.status.text = retrieve<std::string>(one, "text");
+ u.status.id = retrieve<long long>(one, "id");
+ std::string timestr = retrieve<std::string>(one, "created_at");
+ u.status.time = parse_time(timestr);
messages.push_back(u);
}
}
-
return messages;
}
@@ -441,27 +418,24 @@ string twitter::urlencode(const string &c)
string escaped;
size_t max = c.length();
- for(int i=0; i<max; i++)
- {
- if ( (48 <= c[i] && c[i] <= 57) ||//0-9
+ for (int i = 0; i < max; i++) {
+ if ((48 <= c[i] && c[i] <= 57) ||//0-9
(65 <= c[i] && c[i] <= 90) ||//ABC...XYZ
(97 <= c[i] && c[i] <= 122) || //abc...xyz
- (c[i]=='~' || c[i]=='-' || c[i]=='_' || c[i]=='.')
- )
- {
- escaped.append( &c[i], 1);
+ (c[i] == '~' || c[i] == '-' || c[i] == '_' || c[i] == '.')
+ ) {
+ escaped.append(&c[i], 1);
}
- else
- {
+ else {
escaped.append("%");
- escaped.append( char2hex(c[i]));//converts char 255 to string "FF"
+ escaped.append(char2hex(c[i]));//converts char 255 to string "FF"
}
}
return escaped;
}
-wstring twitter::UrlEncode( const wstring& url )
+wstring twitter::UrlEncode(const wstring& url)
{
// multiple encodings r sux
return UTF8ToWide(urlencode(WideToUTF8(url)));
@@ -481,18 +455,18 @@ wstring twitter::UrlEncode( const wstring& url )
//
// unreserved = ALPHA, DIGIT, '-', '.', '_', '~'
-string twitter::char2hex( char dec )
+string twitter::char2hex(char dec)
{
- char dig1 = (dec&0xF0)>>4;
- char dig2 = (dec&0x0F);
- if ( 0<= dig1 && dig1<= 9) dig1+=48; //0,48 in ascii
- if (10<= dig1 && dig1<=15) dig1+=65-10; //A,65 in ascii
- if ( 0<= dig2 && dig2<= 9) dig2+=48;
- if (10<= dig2 && dig2<=15) dig2+=65-10;
+ char dig1 = (dec & 0xF0) >> 4;
+ char dig2 = (dec & 0x0F);
+ if (0 <= dig1 && dig1 <= 9) dig1 += 48; //0,48 in ascii
+ if (10 <= dig1 && dig1 <= 15) dig1 += 65 - 10; //A,65 in ascii
+ if (0 <= dig2 && dig2 <= 9) dig2 += 48;
+ if (10 <= dig2 && dig2 <= 15) dig2 += 65 - 10;
string r;
- r.append( &dig1, 1);
- r.append( &dig2, 1);
+ r.append(&dig1, 1);
+ r.append(&dig2, 1);
return r;
}
@@ -506,13 +480,12 @@ time_t timegm(struct tm *t)
return mktime(t);
}
-static char *month_names[] = { "Jan","Feb","Mar","Apr","May","Jun",
- "Jul","Aug","Sep","Oct","Nov","Dec" };
+static char *month_names[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
int parse_month(const char *m)
{
- for(int i=0; i<12; i++)
- if(strcmp(month_names[i],m) == 0)
+ for (int i = 0; i < 12; i++)
+ if (strcmp(month_names[i], m) == 0)
return i;
return -1;
@@ -521,18 +494,15 @@ int parse_month(const char *m)
time_t parse_time(const std::string &s)
{
struct tm t;
- char day[4],month[4];
+ char day[4], month[4];
char plus;
int zone;
- if(sscanf(s.c_str(),"%3s %3s %d %d:%d:%d %c%d %d",
- day,month,&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec,
- &plus,&zone,&t.tm_year) == 9)
- {
+ if (sscanf(s.c_str(), "%3s %3s %d %d:%d:%d %c%d %d", day, month, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec, &plus, &zone, &t.tm_year) == 9) {
t.tm_year -= 1900;
t.tm_mon = parse_month(month);
- if(t.tm_mon == -1)
+ if (t.tm_mon == -1)
return 0;
return timegm(&t);
}
return 0;
-} \ No newline at end of file
+}
diff --git a/protocols/Twitter/src/twitter.h b/protocols/Twitter/src/twitter.h
index 96aee77cdc..e8ced8ca85 100644
--- a/protocols/Twitter/src/twitter.h
+++ b/protocols/Twitter/src/twitter.h
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
diff --git a/protocols/Twitter/src/ui.cpp b/protocols/Twitter/src/ui.cpp
index 5b0d962583..c9b78db00f 100644
--- a/protocols/Twitter/src/ui.cpp
+++ b/protocols/Twitter/src/ui.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -303,17 +304,17 @@ namespace popup_options
TCHAR *name;
TCHAR *text;
} const quotes[] = {
- {
- _T("Dorothy Parker"), _T("If, with the literate, I am\n")
+ {
+ _T("Dorothy Parker"), _T("If, with the literate, I am\n")
_T("Impelled to try an epigram,\n")
_T("I never seek to take the credit;\n")
_T("We all assume that Oscar said it.") },
- { _T("Steve Ballmer"), _T("I have never, honestly, thrown a chair in my life.") },
- { _T("James Joyce"), _T("I think I would know Nora's fart anywhere. I think ")
+ { _T("Steve Ballmer"), _T("I have never, honestly, thrown a chair in my life.") },
+ { _T("James Joyce"), _T("I think I would know Nora's fart anywhere. I think ")
_T("I could pick hers out in a roomful of farting women.") },
- { _T("Brooke Shields"), _T("Smoking kills. If you're killed, you've lost a very ")
+ { _T("Brooke Shields"), _T("Smoking kills. If you're killed, you've lost a very ")
_T("important part of your life.") },
- { _T("Yogi Berra"), _T("Always go to other peoples' funerals, otherwise ")
+ { _T("Yogi Berra"), _T("Always go to other peoples' funerals, otherwise ")
_T("they won't go to yours.") },
};
diff --git a/protocols/Twitter/src/ui.h b/protocols/Twitter/src/ui.h
index f5520bba40..dac5aa72c8 100644
--- a/protocols/Twitter/src/ui.h
+++ b/protocols/Twitter/src/ui.h
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
diff --git a/protocols/Twitter/src/utility.cpp b/protocols/Twitter/src/utility.cpp
index d7ed48d108..46e3c07d60 100644
--- a/protocols/Twitter/src/utility.cpp
+++ b/protocols/Twitter/src/utility.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -22,72 +23,47 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
std::string b64encode(const std::string &s)
{
- return std::string( ptrA( mir_base64_encode((BYTE*)s.c_str(), (unsigned)s.length())));
+ return std::string(ptrA(mir_base64_encode((BYTE*)s.c_str(), (unsigned)s.length())));
}
http::response mir_twitter::slurp(const std::string &url, http::method meth, OAuthParameters postParams)
{
- NETLIBHTTPREQUEST req = {sizeof(req)};
- req.requestType = (meth == http::get) ? REQUEST_GET:REQUEST_POST;
+ NETLIBHTTPREQUEST req = { sizeof(req) };
+ req.requestType = (meth == http::get) ? REQUEST_GET : REQUEST_POST;
req.szUrl = const_cast<char*>(url.c_str());
- //std::wstring url_WSTR(url.length(),L' ');
- //std::copy(url.begin(), url.end(), url_WSTR.begin());
std::wstring url_WSTR = UTF8ToWide(url);
std::string pdata_STR;
std::wstring pdata_WSTR;
-
std::wstring auth;
+
if (meth == http::get) {
- if (url_WSTR.size()>0) { ppro_->debugLogW(L"**SLURP::GET - we have a URL: %s", url_WSTR); }
- if (consumerKey_.size()>0) { ppro_->debugLogA("**SLURP::GET - we have a consumerKey"); }
- if (consumerSecret_.size()>0) { ppro_->debugLogA("**SLURP::GET - we have a consumerSecret"); }
- if (oauthAccessToken_.size()>0) { ppro_->debugLogA("**SLURP::GET - we have a oauthAccessToken"); }
- if (oauthAccessTokenSecret_.size()>0) { ppro_->debugLogA("**SLURP::GET - we have a oauthAccessTokenSecret"); }
- if (pin_.size()>0) { ppro_->debugLogA("**SLURP::GET - we have a pin"); }
- //debugLogW("consumerSEcret is %s", consumerSecret_);
- //debugLogW("oauthAccessTok is %s", oauthAccessToken_);
- //debugLogW("oautAccessTokSEc is %s", oauthAccessTokenSecret_);
- //debugLogW("pin is %s", pin_);
-
- auth = OAuthWebRequestSubmit(url_WSTR, L"GET", NULL, consumerKey_, consumerSecret_,
+ if (url_WSTR.size() > 0) { ppro_->debugLogW(L"**SLURP::GET - we have a URL: %s", url_WSTR); }
+ if (consumerKey_.size() > 0) { ppro_->debugLogA("**SLURP::GET - we have a consumerKey"); }
+ if (consumerSecret_.size() > 0) { ppro_->debugLogA("**SLURP::GET - we have a consumerSecret"); }
+ if (oauthAccessToken_.size() > 0) { ppro_->debugLogA("**SLURP::GET - we have a oauthAccessToken"); }
+ if (oauthAccessTokenSecret_.size() > 0) { ppro_->debugLogA("**SLURP::GET - we have a oauthAccessTokenSecret"); }
+ if (pin_.size() > 0) { ppro_->debugLogA("**SLURP::GET - we have a pin"); }
+
+ auth = OAuthWebRequestSubmit(url_WSTR, L"GET", NULL, consumerKey_, consumerSecret_,
oauthAccessToken_, oauthAccessTokenSecret_, pin_);
}
else if (meth == http::post) {
-
- //OAuthParameters postParams;
- if (url_WSTR.size()>0) { ppro_->debugLogW(L"**SLURP::POST - we have a URL: %s", url_WSTR); }
- if (consumerKey_.size()>0) { ppro_->debugLogA("**SLURP::POST - we have a consumerKey"); }
- if (consumerSecret_.size()>0) { ppro_->debugLogA("**SLURP::POST - we have a consumerSecret"); }
- if (oauthAccessToken_.size()>0) { ppro_->debugLogA("**SLURP::POST - we have a oauthAccessToken"); }
- if (oauthAccessTokenSecret_.size()>0) { ppro_->debugLogA("**SLURP::POST - we have a oauthAccessTokenSecret"); }
- if (pin_.size()>0) { ppro_->debugLogA("**SLURP::POST - we have a pin"); }
-
- //debugLogW("consumerKey is %s", consumerKey_);
- //debugLogW("consumerSEcret is %s", consumerSecret_);
- //debugLogW("oauthAccessTok is %s", oauthAccessToken_);
- //debugLogW("oautAccessTokSEc is %s", oauthAccessTokenSecret_);
-
- //std::wstring pdata_WSTR(post_data.length(),L' ');
- //std::copy(post_data.begin(), post_data.end(), pdata_WSTR.begin());
-
- //postParams[L"status"] = UrlEncode(pdata_WSTR);
- //postParams[L"source"] = L"mirandang";
+ // OAuthParameters postParams;
+ if (url_WSTR.size() > 0) { ppro_->debugLogW(L"**SLURP::POST - we have a URL: %s", url_WSTR); }
+ if (consumerKey_.size() > 0) { ppro_->debugLogA("**SLURP::POST - we have a consumerKey"); }
+ if (consumerSecret_.size() > 0) { ppro_->debugLogA("**SLURP::POST - we have a consumerSecret"); }
+ if (oauthAccessToken_.size() > 0) { ppro_->debugLogA("**SLURP::POST - we have a oauthAccessToken"); }
+ if (oauthAccessTokenSecret_.size() > 0) { ppro_->debugLogA("**SLURP::POST - we have a oauthAccessTokenSecret"); }
+ if (pin_.size() > 0) { ppro_->debugLogA("**SLURP::POST - we have a pin"); }
pdata_WSTR = BuildQueryString(postParams);
- ppro_->debugLogW(L"**SLURP::POST - post data is: %s", pdata_WSTR);
+ ppro_->debugLogW(L"**SLURP::POST - post data is: %s", pdata_WSTR);
- auth = OAuthWebRequestSubmit(url_WSTR, L"POST", &postParams, consumerKey_, consumerSecret_,
- oauthAccessToken_, oauthAccessTokenSecret_);
- //debugLogW("**SLURP::POST auth is %s", auth);
+ auth = OAuthWebRequestSubmit(url_WSTR, L"POST", &postParams, consumerKey_, consumerSecret_, oauthAccessToken_, oauthAccessTokenSecret_);
}
- else {
- ppro_->debugLogA("**SLURP - There is something really wrong.. the http method was neither get or post.. WHY??");
- }
-
- //std::string auth_STR(auth.length(), ' ');
- //std::copy(auth.begin(), auth.end(), auth_STR.begin());
+ else ppro_->debugLogA("**SLURP - There is something really wrong.. the http method was neither get or post.. WHY??");
std::string auth_STR = WideToUTF8(auth);
@@ -98,16 +74,12 @@ http::response mir_twitter::slurp(const std::string &url, http::method meth, OAu
req.headers = hdr;
req.headersCount = 1;
- if(meth == http::post)
- {
+ if (meth == http::post) {
hdr[1].szName = "Content-Type";
hdr[1].szValue = "application/x-www-form-urlencoded";
- hdr[2].szName = "Cache-Control";
+ hdr[2].szName = "Cache-Control";
hdr[2].szValue = "no-cache";
- //char *pdata_STR = new char[pdata_WSTR.length() + 1];
- //sprintf(pdata_STR,"%ls",pdata_WSTR.c_str());
-
pdata_STR = WideToUTF8(pdata_WSTR);
req.headersCount = 3;
@@ -123,26 +95,25 @@ http::response mir_twitter::slurp(const std::string &url, http::method meth, OAu
NETLIBHTTPREQUEST *resp = reinterpret_cast<NETLIBHTTPREQUEST*>(CallService(MS_NETLIB_HTTPTRANSACTION,
reinterpret_cast<WPARAM>(handle_), reinterpret_cast<LPARAM>(&req)));
ppro_->debugLogA("**SLURP - HTTPTRANSACTION complete.");
- if(resp)
- {
+ if (resp) {
ppro_->debugLogA("**SLURP - the server has responded!");
httpPOST_ = resp->nlc;
resp_data.code = resp->resultCode;
- resp_data.data = resp->pData ? resp->pData:"";
+ resp_data.data = resp->pData ? resp->pData : "";
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)resp);
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp);
}
- else {
- httpPOST_ = NULL;
- ppro_->debugLogA("SLURP - there was no response!");
+ else {
+ httpPOST_ = NULL;
+ ppro_->debugLogA("SLURP - there was no response!");
}
return resp_data;
}
-bool save_url(HANDLE hNetlib,const std::string &url,const std::tstring &filename)
+bool save_url(HANDLE hNetlib, const std::string &url, const std::tstring &filename)
{
- NETLIBHTTPREQUEST req = {sizeof(req)};
+ NETLIBHTTPREQUEST req = { sizeof(req) };
req.requestType = REQUEST_GET;
req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT;
req.szUrl = const_cast<char*>(url.c_str());
@@ -150,25 +121,23 @@ bool save_url(HANDLE hNetlib,const std::string &url,const std::tstring &filename
NETLIBHTTPREQUEST *resp = reinterpret_cast<NETLIBHTTPREQUEST*>(CallService(MS_NETLIB_HTTPTRANSACTION,
reinterpret_cast<WPARAM>(hNetlib), reinterpret_cast<LPARAM>(&req)));
- if (resp)
- {
+ if (resp) {
bool success = (resp->resultCode == 200);
- if (success)
- {
+ if (success) {
// Create folder if necessary
- std::tstring dir = filename.substr(0,filename.rfind('\\'));
- if( _taccess(dir.c_str(),0))
+ std::tstring dir = filename.substr(0, filename.rfind('\\'));
+ if (_taccess(dir.c_str(), 0))
CreateDirectoryTreeT(dir.c_str());
// Write to file
FILE *f = _tfopen(filename.c_str(), _T("wb"));
- fwrite(resp->pData,1,resp->dataLength,f);
+ fwrite(resp->pData, 1, resp->dataLength, f);
fclose(f);
}
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)resp);
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp);
return success;
}
- else
- return false;
+
+ return false;
}
diff --git a/protocols/Twitter/src/utility.h b/protocols/Twitter/src/utility.h
index a74ec25c36..017fd2e9be 100644
--- a/protocols/Twitter/src/utility.h
+++ b/protocols/Twitter/src/utility.h
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -86,40 +87,14 @@ protected:
PROTO_INTERFACE *ppro_;
};
-inline void mbcs_to_tcs(UINT code_page,const char *mbstr,TCHAR *tstr,int tlen)
+inline void mbcs_to_tcs(UINT code_page, const char *mbstr, TCHAR *tstr, int tlen)
{
-
- MultiByteToWideChar(code_page,0,mbstr,-1,tstr,tlen);
-
+ MultiByteToWideChar(code_page, 0, mbstr, -1, tstr, tlen);
}
-inline void wcs_to_tcs(UINT code_page,const wchar_t *wstr,TCHAR *tstr,int tlen)
+inline void wcs_to_tcs(UINT code_page, const wchar_t *wstr, TCHAR *tstr, int tlen)
{
-
- wcsncpy(tstr,wstr,tlen);
-
+ wcsncpy(tstr, wstr, tlen);
}
-class ScopedLock
-{
-public:
- ScopedLock(HANDLE h) : handle_(h)
- {
- WaitForSingleObject(handle_,INFINITE);
- }
- ~ScopedLock()
- {
- if(handle_)
- ReleaseMutex(handle_);
- }
-
- void Unlock()
- {
- ReleaseMutex(handle_);
- handle_ = 0;
- }
-private:
- HANDLE handle_;
-};
-
bool save_url(HANDLE hNetlib,const std::string &url,const std::tstring &filename); \ No newline at end of file
diff --git a/protocols/Twitter/src/version.h b/protocols/Twitter/src/version.h
index 75ab96c9e1..b4ea3e65fb 100644
--- a/protocols/Twitter/src/version.h
+++ b/protocols/Twitter/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 1
-#define __MINOR_VERSION 1
+#define __MINOR_VERSION 2
#define __RELEASE_NUM 0
-#define __BUILD_NUM 3
+#define __BUILD_NUM 1
#include <stdver.h>