summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r--protocols/FacebookRM/src/client.h8
-rw-r--r--protocols/FacebookRM/src/common.h1
-rw-r--r--protocols/FacebookRM/src/communication.cpp4
-rw-r--r--protocols/FacebookRM/src/connection.cpp6
-rw-r--r--protocols/FacebookRM/src/main.cpp2
-rw-r--r--protocols/FacebookRM/src/proto.cpp3
-rw-r--r--protocols/FacebookRM/src/utils.cpp13
-rw-r--r--protocols/FacebookRM/src/utils.h4
-rw-r--r--protocols/FacebookRM/src/version.h2
9 files changed, 31 insertions, 12 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index 6022cd5dca..55b06a24be 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -3,7 +3,7 @@
Facebook plugin for Miranda Instant Messenger
_____________________________________________
-Copyright © 2009-11 Michal Zelinka, 2011-15 Robert Pösel
+Copyright � 2009-11 Michal Zelinka, 2011-15 Robert P�sel
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
@@ -37,7 +37,7 @@ public:
facebook_client()
{
- msgid_ = error_count_ = last_feeds_update_ = last_notification_time_ = 0;
+ msgid_ = error_count_ = last_feeds_update_ = last_notification_time_ = random_ = 0;
https_ = is_typing_ = false;
@@ -53,6 +53,10 @@ public:
HANDLE hFcbCon;
HANDLE fcb_conn_lock_;
+ // Random generator value for this client
+
+ unsigned int random_;
+
// Parent handle
FacebookProto* parent;
diff --git a/protocols/FacebookRM/src/common.h b/protocols/FacebookRM/src/common.h
index 318f5ddd7b..7b459c9b3a 100644
--- a/protocols/FacebookRM/src/common.h
+++ b/protocols/FacebookRM/src/common.h
@@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define _WIN32_WINNT 0x0500
#define _WIN32_WINDOWS 0x0500
+#define _CRT_RAND_S
#include <sstream>
#include <fstream>
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index cfcbdfbff6..d0cee49e4b 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -541,7 +541,7 @@ std::string facebook_client::choose_action(RequestType request_type, std::string
action += "&seq=" + (this->chat_sequence_num_.empty() ? "0" : this->chat_sequence_num_);
action += "&partition=" + (this->chat_channel_partition_.empty() ? "0" : this->chat_channel_partition_);
action += "&clientid=" + this->chat_clientid_;
- action += "&cb=" + utils::text::rand_string(4, "0123456789abcdefghijklmnopqrstuvwxyz");
+ action += "&cb=" + utils::text::rand_string(4, "0123456789abcdefghijklmnopqrstuvwxyz", &this->random_);
int idleSeconds = parent->IdleSeconds();
action += "&idle=" + utils::conversion::to_string(&idleSeconds, UTILS_CONV_UNSIGNED_NUMBER);
@@ -1253,7 +1253,7 @@ bool facebook_client::channel()
case HTTP_CODE_GATEWAY_TIMEOUT:
// Maybe we have same clientid as other connected client, try to generate different one
- this->chat_clientid_ = utils::text::rand_string(8, "0123456789abcdef");
+ this->chat_clientid_ = utils::text::rand_string(8, "0123456789abcdef", &this->random_);
// Intentionally fall to handle_error() below
case HTTP_CODE_FAKE_DISCONNECTED:
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp
index 42f1526e38..8eaec5044a 100644
--- a/protocols/FacebookRM/src/connection.cpp
+++ b/protocols/FacebookRM/src/connection.cpp
@@ -54,6 +54,10 @@ void FacebookProto::ChangeStatus(void*)
ToggleStatusMenuItems(false);
delSetting(FACEBOOK_KEY_LOGON_TS);
+ facy.chat_traceid_.clear();
+ facy.chat_sticky_num_.clear();
+ facy.chat_sticky_pool_.clear();
+
facy.clear_cookies();
facy.clear_notifications();
facy.clear_chatrooms();
@@ -186,7 +190,7 @@ bool FacebookProto::NegotiateConnection()
facy.https_ = getByte(FACEBOOK_KEY_FORCE_HTTPS, DEFAULT_FORCE_HTTPS) != 0;
// Generate random clientid for this connection
- facy.chat_clientid_ = utils::text::rand_string(8, "0123456789abcdef");
+ facy.chat_clientid_ = utils::text::rand_string(8, "0123456789abcdef", &facy.random_);
// Create default group for new contacts
if (m_tszDefaultGroup)
diff --git a/protocols/FacebookRM/src/main.cpp b/protocols/FacebookRM/src/main.cpp
index 0de3b6f195..242a1c944c 100644
--- a/protocols/FacebookRM/src/main.cpp
+++ b/protocols/FacebookRM/src/main.cpp
@@ -115,7 +115,7 @@ extern "C" int __declspec(dllexport) Load(void)
agent << __VERSION_STRING_DOTS;
g_strUserAgent = agent.str();
- // Initialize random generator
+ // Initialize random generator (used only as fallback in utils)
srand(::time(NULL));
return 0;
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index cdfd1cdeca..d91d3e9494 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -38,6 +38,9 @@ FacebookProto::FacebookProto(const char* proto_name, const TCHAR* username) :
facy.notifications_lock_ = CreateMutex(NULL, FALSE, NULL);
facy.cookies_lock_ = CreateMutex(NULL, FALSE, NULL);
+ // Initialize random seed for this client
+ facy.random_ = ::time(NULL) + PtrToUint(&facy);
+
m_hMenuRoot = m_hMenuServicesRoot = m_hStatusMind = NULL;
m_invisible = false;
diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp
index 8c388f738c..f277103203 100644
--- a/protocols/FacebookRM/src/utils.cpp
+++ b/protocols/FacebookRM/src/utils.cpp
@@ -456,19 +456,26 @@ std::string utils::text::source_get_form_data(std::string* data)
return values;
}
-std::string utils::text::rand_string(int len, const char *chars)
+std::string utils::text::rand_string(int len, const char *chars, unsigned int *number)
{
std::stringstream out;
int strLen = (int)strlen(chars);
for (int i = 0; i < len; ++i) {
- out << chars[utils::number::random(0, strLen)];
+ out << chars[utils::number::random(0, strLen, number)];
}
return out.str();
}
-int utils::number::random(int min, int max)
+int utils::number::random(int min, int max, unsigned int *number)
{
+ if (number != NULL) {
+ errno_t err = rand_s(number);
+ if (!err)
+ return (*number % (max - min)) + min;
+ }
+
+ // If called didn't specified "number" or there was error, fallback to rand()
return (rand() % (max - min)) + min;
}
diff --git a/protocols/FacebookRM/src/utils.h b/protocols/FacebookRM/src/utils.h
index 3768cc9415..af9cf3ceed 100644
--- a/protocols/FacebookRM/src/utils.h
+++ b/protocols/FacebookRM/src/utils.h
@@ -48,7 +48,7 @@ namespace utils
namespace number
{
- int random(int min, int max);
+ int random(int min, int max, unsigned int *value = NULL);
};
namespace text
@@ -64,7 +64,7 @@ namespace utils
std::string source_get_value(std::string* data, unsigned int argument_count, ...);
std::string source_get_value2(std::string* data, const char *term, const char *endings, bool wholeString = false);
std::string source_get_form_data(std::string* data);
- std::string rand_string(int len, const char *chars = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz");
+ std::string rand_string(int len, const char *chars = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz", unsigned int *number = NULL);
void explode(std::string str, const std::string &separator, std::vector<std::string>* results);
void append_ordinal(unsigned long value, std::string* data);
};
diff --git a/protocols/FacebookRM/src/version.h b/protocols/FacebookRM/src/version.h
index f4c9d6f9df..e7d50238ad 100644
--- a/protocols/FacebookRM/src/version.h
+++ b/protocols/FacebookRM/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 2
#define __RELEASE_NUM 10
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>