diff options
author | Robert Pösel <robyer@seznam.cz> | 2014-12-20 03:22:13 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2014-12-20 03:22:13 +0000 |
commit | 1705273c443d069c82fac78ad34d909513af519b (patch) | |
tree | 0ca1a5a0aa1977ca69afd09371985032da06b45e /protocols/Omegle | |
parent | 1f70e7a998a41fa0c85b129eb4584d44c166036c (diff) |
Omegle: Various fixes and code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@11541 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Omegle')
-rw-r--r-- | protocols/Omegle/src/chat.cpp | 29 | ||||
-rw-r--r-- | protocols/Omegle/src/client.h | 12 | ||||
-rw-r--r-- | protocols/Omegle/src/communication.cpp | 14 | ||||
-rw-r--r-- | protocols/Omegle/src/connection.cpp | 2 | ||||
-rw-r--r-- | protocols/Omegle/src/dialogs.cpp | 11 | ||||
-rw-r--r-- | protocols/Omegle/src/proto.cpp | 5 | ||||
-rw-r--r-- | protocols/Omegle/src/theme.cpp | 22 | ||||
-rw-r--r-- | protocols/Omegle/src/utils.cpp | 12 | ||||
-rw-r--r-- | protocols/Omegle/src/utils.h | 12 |
9 files changed, 40 insertions, 79 deletions
diff --git a/protocols/Omegle/src/chat.cpp b/protocols/Omegle/src/chat.cpp index cf98c66a32..fcc7706690 100644 --- a/protocols/Omegle/src/chat.cpp +++ b/protocols/Omegle/src/chat.cpp @@ -37,7 +37,7 @@ void OmegleProto::UpdateChat(const TCHAR *name, const TCHAR *message, bool addto name = TranslateT("Server");
gce.bIsMe = false;
}
- else gce.bIsMe = !_tcscmp(name, this->facy.nick_);
+ else gce.bIsMe = !mir_tstrcmp(name, this->facy.nick_);
if (addtolog)
gce.dwFlags |= GCEF_ADDTOLOG;
@@ -83,7 +83,7 @@ int OmegleProto::OnChatEvent(WPARAM wParam,LPARAM lParam) if (!stricmp(command.c_str(), "new"))
{
facy.spy_mode_ = false;
- facy.question_ = "";
+ facy.question_.clear();
ForkThread(&OmegleProto::NewChatWorker, NULL);
break;
@@ -96,7 +96,7 @@ int OmegleProto::OnChatEvent(WPARAM wParam,LPARAM lParam) else if (!stricmp(command.c_str(), "spy"))
{
facy.spy_mode_ = true;
- facy.question_ = "";
+ facy.question_.clear();
ForkThread(&OmegleProto::NewChatWorker, NULL);
break;
@@ -117,13 +117,13 @@ int OmegleProto::OnChatEvent(WPARAM wParam,LPARAM lParam) }
} else {
// Save actual question as last question
- if (strlen(params.c_str()) >= OMEGLE_QUESTION_MIN_LENGTH)
+ if (params.length() >= OMEGLE_QUESTION_MIN_LENGTH)
{
setU8String( OMEGLE_KEY_LAST_QUESTION, params.c_str());
}
}
- if (strlen(params.c_str()) < OMEGLE_QUESTION_MIN_LENGTH)
+ if (params.length() < OMEGLE_QUESTION_MIN_LENGTH)
{
UpdateChat(NULL, TranslateT("Your question is too short."), false);
break;
@@ -184,7 +184,7 @@ int OmegleProto::OnChatEvent(WPARAM wParam,LPARAM lParam) case GC_USER_LEAVE:
case GC_SESSION_TERMINATE:
- mir_free( facy.nick_ );
+ facy.nick_ = NULL;
ForkThread(&OmegleProto::StopChatWorker, NULL);
break;
}
@@ -234,7 +234,7 @@ void OmegleProto::AddChatContact(const TCHAR *name) if (name == NULL)
gce.bIsMe = false;
else
- gce.bIsMe = !_tcscmp(name, this->facy.nick_);
+ gce.bIsMe = mir_tstrcmp(name, this->facy.nick_);
if (gce.bIsMe)
gce.ptszStatus = _T("Admin");
@@ -255,7 +255,7 @@ void OmegleProto::DeleteChatContact(const TCHAR *name) if (name == NULL)
gce.bIsMe = false;
else
- gce.bIsMe = !_tcscmp(name, this->facy.nick_);
+ gce.bIsMe = mir_tstrcmp(name, this->facy.nick_);
CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
}
@@ -326,20 +326,13 @@ void OmegleProto::SetChatStatus(int status) if(status == ID_STATUS_ONLINE)
{
- // Free previously loaded name
- mir_free(facy.nick_);
-
// Load actual name from database
- DBVARIANT dbv;
- if ( !db_get_ts(NULL, m_szModuleName, OMEGLE_KEY_NAME, &dbv))
- {
- facy.nick_ = mir_tstrdup(dbv.ptszVal);
- db_free(&dbv);
- } else {
+ facy.nick_ = db_get_tsa(NULL, m_szModuleName, OMEGLE_KEY_NAME);
+ if (facy.nick_ == NULL) {
facy.nick_ = mir_tstrdup(TranslateT("You"));
db_set_ts(NULL, m_szModuleName, OMEGLE_KEY_NAME, facy.nick_);
}
-
+
// Add self contact
AddChatContact(facy.nick_);
diff --git a/protocols/Omegle/src/client.h b/protocols/Omegle/src/client.h index a6e28c5a2c..8506c14556 100644 --- a/protocols/Omegle/src/client.h +++ b/protocols/Omegle/src/client.h @@ -37,7 +37,6 @@ public: // Client definition
Omegle_client( )
{
- chat_id_ = server_ = question_ = "";
nick_ = NULL;
//msgid_ = 0;
send_message_lock_ = NULL;
@@ -63,7 +62,7 @@ public: std::string chat_id_;
std::string server_;
std::string question_;
- TCHAR *nick_;
+ ptrT nick_;
HANDLE send_message_lock_;
//int msgid_;
@@ -75,7 +74,6 @@ public: bool spy_mode_;
// Data storage
- std::map< std::string, std::string > headers;
void store_headers( http::response* resp, NETLIBHTTPHEADER* headers, int headers_count );
std::string get_server( bool not_last = false );
@@ -84,9 +82,9 @@ public: // Connection handling
unsigned int error_count_;
- bool handle_entry( std::string method );
- bool handle_success( std::string method );
- bool handle_error( std::string method, bool force_disconnect = false );
+ bool handle_entry(const std::string &method);
+ bool handle_success(const std::string &method);
+ bool handle_error(const std::string &method, bool force_disconnect = false );
void __inline increment_error( ) { error_count_++; }
void __inline decrement_error( ) { if ( error_count_ > 0 ) error_count_--; }
@@ -102,7 +100,7 @@ public: std::string get_page( int );
- bool send_message( std::string message_text );
+ bool send_message(const std::string &message_text );
// HTTP communication
http::response flap( const int request_type, std::string* request_data = NULL, std::string* get_data = NULL );
diff --git a/protocols/Omegle/src/communication.cpp b/protocols/Omegle/src/communication.cpp index 377a9e6e53..fb2641a88b 100644 --- a/protocols/Omegle/src/communication.cpp +++ b/protocols/Omegle/src/communication.cpp @@ -96,20 +96,20 @@ http::response Omegle_client::flap( const int request_type, std::string* request return resp;
}
-bool Omegle_client::handle_entry( std::string method )
+bool Omegle_client::handle_entry(const std::string &method )
{
parent->debugLogA(" >> Entering %s()", method.c_str());
return true;
}
-bool Omegle_client::handle_success( std::string method )
+bool Omegle_client::handle_success(const std::string &method )
{
parent->debugLogA(" << Quitting %s()", method.c_str());
reset_error();
return true;
}
-bool Omegle_client::handle_error( std::string method, bool force_disconnect )
+bool Omegle_client::handle_error(const std::string &method, bool force_disconnect )
{
bool result;
increment_error();
@@ -138,7 +138,7 @@ std::string Omegle_client::get_server( bool not_last ) {
BYTE q = not_last ? 1 : 0;
- BYTE server = db_get_b(NULL, parent->m_szModuleName, OMEGLE_KEY_SERVER, 0);
+ int server = db_get_b(NULL, parent->m_szModuleName, OMEGLE_KEY_SERVER, 0);
if (server < 0 || server >= (SIZEOF(servers)-q))
server = 0;
@@ -152,7 +152,7 @@ std::string Omegle_client::get_server( bool not_last ) std::string Omegle_client::get_language()
{
- BYTE language = db_get_b(NULL, parent->m_szModuleName, OMEGLE_KEY_LANGUAGE, 0);
+ int language = db_get_b(NULL, parent->m_szModuleName, OMEGLE_KEY_LANGUAGE, 0);
if (language < 0 || language >= (SIZEOF(languages)))
language = 0;
@@ -304,7 +304,7 @@ NETLIBHTTPHEADER* Omegle_client::get_request_headers( int request_type, int* hea void Omegle_client::store_headers( http::response* resp, NETLIBHTTPHEADER* headers, int headersCount )
{
- for ( int i = 0; i < headersCount; i++ )
+ for ( size_t i = 0; i < headersCount; i++ )
{
std::string header_name = headers[i].szName;
std::string header_value = headers[i].szValue;
@@ -740,7 +740,7 @@ bool Omegle_client::events( ) }
}
-bool Omegle_client::send_message( std::string message_text )
+bool Omegle_client::send_message(const std::string &message_text )
{
handle_entry( "send_message" );
diff --git a/protocols/Omegle/src/connection.cpp b/protocols/Omegle/src/connection.cpp index 46625c6eea..4037abadb1 100644 --- a/protocols/Omegle/src/connection.cpp +++ b/protocols/Omegle/src/connection.cpp @@ -100,7 +100,7 @@ void OmegleProto::StopChat(bool disconnect) }
facy.state_ = STATE_INACTIVE;
- facy.chat_id_ = "";
+ facy.chat_id_.clear();
}
void OmegleProto::NewChat()
diff --git a/protocols/Omegle/src/dialogs.cpp b/protocols/Omegle/src/dialogs.cpp index 01dbe75516..5678d6c50b 100644 --- a/protocols/Omegle/src/dialogs.cpp +++ b/protocols/Omegle/src/dialogs.cpp @@ -38,12 +38,9 @@ static BOOL StoreDBCheckState(OmegleProto* ppro, HWND hwnd, int idCtrl, const ch static void LoadDBText(OmegleProto* ppro, HWND hwnd, int idCtrl, const char* szSetting)
{
- DBVARIANT dbv;
- if ( !db_get_ts(NULL, ppro->m_szModuleName, szSetting, &dbv))
- {
- SetDlgItemText(hwnd, idCtrl, dbv.ptszVal);
- db_free(&dbv);
- }
+ ptrT tstr( db_get_tsa(NULL, ppro->m_szModuleName, szSetting));
+ if (tstr)
+ SetDlgItemText(hwnd, idCtrl, tstr);
}
static void StoreDBText(OmegleProto* ppro, HWND hwnd, int idCtrl, const char* szSetting)
@@ -51,7 +48,7 @@ static void StoreDBText(OmegleProto* ppro, HWND hwnd, int idCtrl, const char* sz TCHAR tstr[250+1];
GetDlgItemText(hwnd, idCtrl, tstr, SIZEOF(tstr));
- if ( _tcsclen( tstr ) > 0 ) {
+ if (tstr[0] != '\0') {
db_set_ts(NULL, ppro->m_szModuleName, szSetting, tstr);
} else {
db_unset(NULL, ppro->m_szModuleName, szSetting);
diff --git a/protocols/Omegle/src/proto.cpp b/protocols/Omegle/src/proto.cpp index e8cc0c4d42..bc785a9c44 100644 --- a/protocols/Omegle/src/proto.cpp +++ b/protocols/Omegle/src/proto.cpp @@ -46,9 +46,6 @@ OmegleProto::OmegleProto(const char* proto_name, const TCHAR* username) : NETLIBUSER nlu = {sizeof(nlu)};
nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
nlu.szSettingsModule = m_szModuleName;
- char module[512];
- mir_snprintf(module,SIZEOF(module),"%sAv",m_szModuleName);
- nlu.szSettingsModule = module;
mir_sntprintf(descr,SIZEOF(descr),TranslateT("%s server connection"),m_tszUserName);
nlu.ptszDescriptiveName = descr;
m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER,0,(LPARAM)&nlu);
@@ -76,8 +73,6 @@ OmegleProto::~OmegleProto( ) CloseHandle( this->facy.send_message_lock_ );
CloseHandle( this->events_loop_lock_ );
CloseHandle( this->facy.connection_lock_ );
-
- mir_free( this->facy.nick_ );
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Omegle/src/theme.cpp b/protocols/Omegle/src/theme.cpp index c9b41d93ec..bfc7389230 100644 --- a/protocols/Omegle/src/theme.cpp +++ b/protocols/Omegle/src/theme.cpp @@ -45,25 +45,3 @@ HANDLE GetIconHandle(const char* name) }
return 0;
}
-
-// Helper functions
-static OmegleProto * GetInstanceByHContact(MCONTACT hContact)
-{
- char *proto = GetContactProto(hContact);
- if (!proto)
- return 0;
-
- 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 (__cdecl OmegleProto::*Fcn)(WPARAM,LPARAM)>
-INT_PTR GlobalService(WPARAM wParam,LPARAM lParam)
-{
- OmegleProto *proto = GetInstanceByHContact(reinterpret_cast<HANDLE>(wParam));
- return proto ? (proto->*Fcn)(wParam,lParam) : 0;
-}
-
diff --git a/protocols/Omegle/src/utils.cpp b/protocols/Omegle/src/utils.cpp index bc7bac240a..09ced8f1db 100644 --- a/protocols/Omegle/src/utils.cpp +++ b/protocols/Omegle/src/utils.cpp @@ -27,7 +27,7 @@ std::string utils::url::encode(const std::string &s) return (char*)ptrA( mir_urlEncode( s.c_str()));
}
-void utils::text::replace_first( std::string* data, std::string from, std::string to )
+void utils::text::replace_first( std::string* data, const std::string &from, const std::string &to )
{
std::string::size_type position = 0;
@@ -38,7 +38,7 @@ void utils::text::replace_first( std::string* data, std::string from, std::strin }
}
-void utils::text::replace_all( std::string* data, std::string from, std::string to )
+void utils::text::replace_all( std::string* data, const std::string &from, const std::string &to )
{
std::string::size_type position = 0;
@@ -49,7 +49,7 @@ void utils::text::replace_all( std::string* data, std::string from, std::string }
}
-void utils::text::treplace_all(std::tstring* data, std::tstring from, std::tstring to)
+void utils::text::treplace_all(std::tstring* data, const std::tstring &from, const std::tstring &to)
{
std::tstring::size_type position = 0;
@@ -72,7 +72,7 @@ std::string utils::text::special_expressions_decode( std::string data ) }
-std::string utils::text::slashu_to_utf8( std::string data )
+std::string utils::text::slashu_to_utf8(const std::string &data )
{
std::string new_string = "";
@@ -108,7 +108,7 @@ std::string utils::text::slashu_to_utf8( std::string data ) return new_string;
}
-std::string utils::text::trim( std::string data )
+std::string utils::text::trim(const std::string &data )
{
std::string spaces = " \t\r\n";
std::string::size_type begin = data.find_first_not_of( spaces );
@@ -117,7 +117,7 @@ std::string utils::text::trim( std::string data ) return (begin != std::string::npos) ? data.substr( begin, end - begin ) : "";
}
-int utils::debug::log(std::string file_name, std::string text)
+int utils::debug::log(const std::string &file_name, const std::string &text)
{
char szFile[MAX_PATH];
GetModuleFileNameA(g_hInstance, szFile, SIZEOF(szFile));
diff --git a/protocols/Omegle/src/utils.h b/protocols/Omegle/src/utils.h index dc22deffbb..420f736ff8 100644 --- a/protocols/Omegle/src/utils.h +++ b/protocols/Omegle/src/utils.h @@ -31,17 +31,17 @@ namespace utils namespace text
{
- void replace_first( std::string* data, std::string from, std::string to );
- void replace_all( std::string* data, std::string from, std::string to );
- void treplace_all(std::tstring* data, std::tstring from, std::tstring to);
+ void replace_first( std::string* data, const std::string &from, const std::string &to );
+ void replace_all( std::string* data, const std::string &from, const std::string &to );
+ void treplace_all(std::tstring* data, const std::tstring &from, const std::tstring &to);
std::string special_expressions_decode( std::string data );
- std::string slashu_to_utf8( std::string data );
- std::string trim( std::string data );
+ std::string slashu_to_utf8(const std::string &data );
+ std::string trim(const std::string &data );
};
namespace debug
{
- int log(std::string file_name, std::string text);
+ int log(const std::string &file_name, const std::string &text);
};
namespace mem
|