From 331cea6299be141243e89e10755ec4adf5ef5d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Tue, 19 May 2015 18:51:14 +0000 Subject: Omegle: Fix receiving data without first letter; various cleanup; version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@13700 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Omegle/src/chat.cpp | 2 +- protocols/Omegle/src/client.h | 41 ++++---- protocols/Omegle/src/communication.cpp | 175 ++++++++++++++------------------- protocols/Omegle/src/messages.cpp | 16 +-- protocols/Omegle/src/proto.h | 2 - protocols/Omegle/src/version.h | 2 +- 6 files changed, 95 insertions(+), 143 deletions(-) (limited to 'protocols/Omegle/src') diff --git a/protocols/Omegle/src/chat.cpp b/protocols/Omegle/src/chat.cpp index 269c6d1731..f51104b1d9 100644 --- a/protocols/Omegle/src/chat.cpp +++ b/protocols/Omegle/src/chat.cpp @@ -47,7 +47,7 @@ void OmegleProto::UpdateChat(const TCHAR *name, const TCHAR *message, bool addto CallServiceSync(MS_GC_EVENT,0,reinterpret_cast(&gce)); } -int OmegleProto::OnChatEvent(WPARAM wParam,LPARAM lParam) +int OmegleProto::OnChatEvent(WPARAM, LPARAM lParam) { GCHOOK *hook = reinterpret_cast(lParam); diff --git a/protocols/Omegle/src/client.h b/protocols/Omegle/src/client.h index 1cf3f9b25b..d3a6bf6856 100644 --- a/protocols/Omegle/src/client.h +++ b/protocols/Omegle/src/client.h @@ -35,7 +35,7 @@ class Omegle_client public: // Client definition - Omegle_client( ) + Omegle_client() { nick_ = NULL; //msgid_ = 0; @@ -78,9 +78,9 @@ public: bool spy_mode_; // Data storage - void store_headers( http::response* resp, NETLIBHTTPHEADER* headers, int headers_count ); + void store_headers(http::response *resp, NETLIBHTTPHEADER *headers, int headers_count); - std::string get_server( bool not_last = false ); + std::string get_server(bool not_last = false); std::string get_language(); // Connection handling @@ -88,34 +88,31 @@ public: 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 ); + 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_--; } - void __inline reset_error( ) { error_count_ = 0; } + void __inline increment_error() { error_count_++; } + void __inline decrement_error() { if ( error_count_ > 0 ) error_count_--; } + void __inline reset_error() { error_count_ = 0; } - bool start( ); - bool stop( ); - bool events( ); + bool start(); + bool stop(); + bool events(); - bool typing_start( ); - bool typing_stop( ); - bool recaptcha( ); + bool typing_start(); + bool typing_stop(); + bool recaptcha(); - std::string get_page( int ); + std::string get_page(int); - bool send_message(const 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 ); + http::response flap(const int request_type, std::string *post_data = NULL, std::string *get_data = NULL); - int choose_method( int ); - std::string choose_proto( int ); - std::string choose_server( int, std::string* data = NULL, std::string* get_data = NULL ); - std::string choose_action( int, std::string* data = NULL, std::string* get_data = NULL ); - std::string choose_request_url( int, std::string* data = NULL, std::string* get_data = NULL ); + std::string choose_server(int); + std::string choose_action(int, std::string *get_data = NULL); - NETLIBHTTPHEADER* get_request_headers( int request_type, int* headers_count ); + NETLIBHTTPHEADER *get_request_headers(int request_type, int *headers_count); // Netlib handle diff --git a/protocols/Omegle/src/communication.cpp b/protocols/Omegle/src/communication.cpp index f6a027c5a4..a0e1d19c0c 100644 --- a/protocols/Omegle/src/communication.cpp +++ b/protocols/Omegle/src/communication.cpp @@ -21,25 +21,44 @@ along with this program. If not, see . #include "stdafx.h" -http::response Omegle_client::flap( const int request_type, std::string* request_data, std::string* get_data ) +http::response Omegle_client::flap(const int request_type, std::string *post_data, std::string *get_data) { - NETLIBHTTPREQUEST nlhr = {sizeof( NETLIBHTTPREQUEST )}; - nlhr.requestType = choose_method( request_type ); - std::string url = choose_request_url( request_type, request_data, get_data ); - nlhr.szUrl = (char*)url.c_str( ); - nlhr.flags = NLHRF_HTTP11 | NLHRF_NODUMP; - nlhr.headers = get_request_headers( request_type, &nlhr.headersCount ); - nlhr.timeout = 1000 * (( request_type == OMEGLE_REQUEST_EVENTS ) ? 60 : 15); - - if ( request_data != NULL ) - { - nlhr.pData = (char*)(*request_data).c_str(); - nlhr.dataLength = (int)request_data->length( ); + http::response resp; + + // Prepare the request + NETLIBHTTPREQUEST nlhr = { sizeof(NETLIBHTTPREQUEST) }; + + // Set request URL + std::string url = choose_server(request_type) + choose_action(request_type, get_data); + nlhr.szUrl = (char*)url.c_str(); + + // Set timeout (bigger for channel request) + nlhr.timeout = 1000 * ((request_type == OMEGLE_REQUEST_EVENTS) ? 65 : 20); + + // Set request type (GET/POST) and eventually also POST data + if (post_data != NULL) { + nlhr.requestType = REQUEST_POST; + nlhr.pData = (char*)(*post_data).c_str(); + nlhr.dataLength = (int)post_data->length(); + } + else { + nlhr.requestType = REQUEST_GET; } - parent->debugLogA("@@@@@ Sending request to '%s'", nlhr.szUrl); + // Set headers - it depends on requestType so it must be after setting that + nlhr.headers = get_request_headers(nlhr.requestType, &nlhr.headersCount); - switch ( request_type ) + // Set flags + nlhr.flags = NLHRF_HTTP11; + +#ifdef _DEBUG + nlhr.flags |= NLHRF_DUMPASTEXT; +#else + nlhr.flags |= NLHRF_NODUMP; +#endif + + // Set persistent connection (or not) + switch (request_type) { case OMEGLE_REQUEST_HOME: nlhr.nlc = NULL; @@ -57,10 +76,14 @@ http::response Omegle_client::flap( const int request_type, std::string* request break; } - NETLIBHTTPREQUEST* pnlhr = ( NETLIBHTTPREQUEST* )CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)handle_, (LPARAM)&nlhr ); + parent->debugLogA("@@@@@ Sending request to '%s'", nlhr.szUrl); - http::response resp; + // Send the request + NETLIBHTTPREQUEST *pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)handle_, (LPARAM)&nlhr); + mir_free(nlhr.headers); + + // Remember the persistent connection handle (or not) switch ( request_type ) { case OMEGLE_REQUEST_HOME: @@ -76,10 +99,11 @@ http::response Omegle_client::flap( const int request_type, std::string* request break; } - if ( pnlhr != NULL ) + // Check and copy response data + if (pnlhr != NULL) { parent->debugLogA("@@@@@ Got response with code %d", pnlhr->resultCode); - store_headers( &resp, pnlhr->headers, pnlhr->headersCount ); + store_headers(&resp, pnlhr->headers, pnlhr->headersCount); resp.code = pnlhr->resultCode; resp.data = pnlhr->pData ? pnlhr->pData : ""; @@ -89,8 +113,7 @@ http::response Omegle_client::flap( const int request_type, std::string* request } else { parent->debugLogA("!!!!! No response from server (time-out)"); resp.code = HTTP_CODE_FAKE_DISCONNECTED; - // Better to have something set explicitely as this value - // is compaired in all communication requests + // Better to have something set explicitely as this value is compaired in all communication requests } return resp; @@ -159,27 +182,7 @@ std::string Omegle_client::get_language() return language > 0 ? languages[language].id : "en"; } -int Omegle_client::choose_method( int request_type ) -{ - switch ( request_type ) - { - case OMEGLE_REQUEST_HOME: - case OMEGLE_REQUEST_COUNT: - return REQUEST_GET; - -/* case OMEGLE_REQUEST_START: - case OMEGLE_REQUEST_STOP: - case OMEGLE_REQUEST_SEND: - case OMEGLE_REQUEST_EVENTS: - case OMEGLE_REQUEST_TYPING_START: - case OMEGLE_REQUEST_TYPING_STOP: - case OMEGLE_REQUEST_RECAPTCHA: -*/ default: - return REQUEST_POST; - } -} - -std::string Omegle_client::choose_server( int request_type, std::string* data, std::string* get_data ) +std::string Omegle_client::choose_server(int request_type) { switch ( request_type ) { @@ -201,7 +204,7 @@ std::string Omegle_client::choose_server( int request_type, std::string* data, s } } -std::string Omegle_client::choose_action( int request_type, std::string* data, std::string* get_data ) +std::string Omegle_client::choose_action(int request_type, std::string* get_data) { switch ( request_type ) { @@ -244,62 +247,28 @@ std::string Omegle_client::choose_action( int request_type, std::string* data, s } } -std::string Omegle_client::choose_request_url( int request_type, std::string* data, std::string* get_data ) -{ - std::string url = ""; - url.append( choose_server( request_type, data, get_data )); - url.append( choose_action( request_type, data, get_data )); - return url; -} NETLIBHTTPHEADER* Omegle_client::get_request_headers( int request_type, int* headers_count ) { - switch ( request_type ) - { - case OMEGLE_REQUEST_START: - case OMEGLE_REQUEST_STOP: - case OMEGLE_REQUEST_SEND: - case OMEGLE_REQUEST_EVENTS: - case OMEGLE_REQUEST_TYPING_START: - case OMEGLE_REQUEST_TYPING_STOP: - case OMEGLE_REQUEST_RECAPTCHA: + if (request_type == REQUEST_POST) *headers_count = 4; - break; - - case OMEGLE_REQUEST_HOME: - case OMEGLE_REQUEST_COUNT: - default: + else *headers_count = 3; - break; - } - NETLIBHTTPHEADER* headers = ( NETLIBHTTPHEADER* )utils::mem::allocate( sizeof( NETLIBHTTPHEADER )*( *headers_count )); + NETLIBHTTPHEADER *headers = (NETLIBHTTPHEADER*)mir_calloc(sizeof(NETLIBHTTPHEADER)*(*headers_count)); - switch ( request_type ) - { - case OMEGLE_REQUEST_START: - case OMEGLE_REQUEST_STOP: - case OMEGLE_REQUEST_SEND: - case OMEGLE_REQUEST_EVENTS: - case OMEGLE_REQUEST_TYPING_START: - case OMEGLE_REQUEST_TYPING_STOP: - case OMEGLE_REQUEST_RECAPTCHA: + if (request_type == REQUEST_POST) { headers[3].szName = "Content-Type"; headers[3].szValue = "application/x-www-form-urlencoded; charset=utf-8"; - // intentionally no break; - - case OMEGLE_REQUEST_HOME: - case OMEGLE_REQUEST_COUNT: - default: - headers[2].szName = "User-Agent"; - headers[2].szValue = (char *)g_strUserAgent.c_str( ); - headers[1].szName = "Accept"; - headers[1].szValue = "*/*"; - headers[0].szName = "Accept-Language"; - headers[0].szValue = "en,en-US;q=0.9"; - break; } + headers[2].szName = "User-Agent"; + headers[2].szValue = (char *)g_strUserAgent.c_str(); + headers[1].szName = "Accept"; + headers[1].szValue = "*/*"; + headers[0].szName = "Accept-Language"; + headers[0].szValue = "en,en-US;q=0.9"; + return headers; } @@ -438,7 +407,7 @@ bool Omegle_client::start() } } -bool Omegle_client::stop( ) +bool Omegle_client::stop() { if ( parent->isOffline()) return true; @@ -473,7 +442,7 @@ bool Omegle_client::stop( ) }*/ } -bool Omegle_client::events( ) +bool Omegle_client::events() { handle_entry( "events" ); @@ -519,9 +488,9 @@ bool Omegle_client::events( ) mir_free(msg); }*/ - if ( (pos = resp.data.find( "[\"serverMessage\", \"" )) != std::string::npos ) { + if ( (pos = resp.data.find( "[\"serverMessage\"," )) != std::string::npos ) { // We got server message - pos += 19; + pos += 18; std::string message = utils::text::trim( resp.data.substr(pos, resp.data.find("\"]", pos) - pos)); TCHAR *tstr = Langpack_PcharToTchar(message.c_str()); @@ -545,7 +514,7 @@ bool Omegle_client::events( ) } if ( (pos = resp.data.find( "[\"commonLikes\"," )) != std::string::npos ) { - pos += 18; + pos += 17; std::string like = resp.data.substr(pos, resp.data.find("\"]", pos) - pos); utils::text::replace_all(&like, "\", \"", ", "); @@ -559,7 +528,7 @@ bool Omegle_client::events( ) } if ( (pos = resp.data.find( "[\"question\"," )) != std::string::npos ) { - pos += 14; + pos += 13; std::string question = utils::text::trim( utils::text::special_expressions_decode( @@ -604,7 +573,7 @@ bool Omegle_client::events( ) pos = 0; while ( (pos = resp.data.find( "[\"gotMessage\",", pos )) != std::string::npos ) { - pos += 16; + pos += 15; std::string message = utils::text::trim( utils::text::special_expressions_decode( @@ -622,7 +591,7 @@ bool Omegle_client::events( ) pos = 0; while ( (pos = resp.data.find( "[\"spyMessage\",", pos )) != std::string::npos ) { - pos += 16; + pos += 15; std::string message = resp.data.substr(pos, resp.data.find("\"]", pos) - pos); @@ -658,7 +627,7 @@ bool Omegle_client::events( ) } if ( (pos = resp.data.find( "[\"spyDisconnected\"," )) != std::string::npos ) { - pos += 21; + pos += 20; std::string stranger = utils::text::trim( utils::text::special_expressions_decode( @@ -694,7 +663,7 @@ bool Omegle_client::events( ) } if ( (pos = resp.data.find( "[\"error\"," )) != std::string::npos ) { - pos += 11; + pos += 10; std::string error = utils::text::trim( utils::text::special_expressions_decode( @@ -833,22 +802,22 @@ bool Omegle_client::recaptcha() } } -std::string Omegle_client::get_page( const int request_type ) +std::string Omegle_client::get_page(const int request_type) { - handle_entry( "get_page" ); + handle_entry("get_page"); - http::response resp = flap( OMEGLE_REQUEST_COUNT ); + http::response resp = flap(request_type); switch ( resp.code ) { case HTTP_CODE_OK: - handle_success( "get_page" ); + handle_success("get_page"); break; case HTTP_CODE_FAKE_ERROR: case HTTP_CODE_FAKE_DISCONNECTED: default: - handle_error( "get_page" ); + handle_error("get_page"); } return resp.data; diff --git a/protocols/Omegle/src/messages.cpp b/protocols/Omegle/src/messages.cpp index 893674de5b..5eea9b5893 100644 --- a/protocols/Omegle/src/messages.cpp +++ b/protocols/Omegle/src/messages.cpp @@ -68,24 +68,12 @@ void OmegleProto::SendTypingWorker(void *p) facy.typing_stop(); } -void OmegleProto::NewChatWorker(void*p) +void OmegleProto::NewChatWorker(void*) { NewChat(); } -void OmegleProto::StopChatWorker(void*p) +void OmegleProto::StopChatWorker(void*) { StopChat(); } - -int OmegleProto::SendMsg(MCONTACT hContact, int flags, const char *msg) -{ - // TODO: msg comes as Unicode (retyped wchar_t*), why should we convert it as ANSI to UTF-8? o_O -/* if ( flags & PREF_UNICODE ) - msg = mir_utf8encode(msg); - - facy.msgid_ = (facy.msgid_ % 1024)+1; - ForkThread( &OmegleProto::SendMsgWorker, this,new send_direct(hContact,msg,(HANDLE)facy.msgid_)); - return facy.msgid_;*/ - return 0; -} diff --git a/protocols/Omegle/src/proto.h b/protocols/Omegle/src/proto.h index 697bb4cd52..6af68ff566 100644 --- a/protocols/Omegle/src/proto.h +++ b/protocols/Omegle/src/proto.h @@ -47,8 +47,6 @@ public: virtual DWORD_PTR __cdecl GetCaps( int type, MCONTACT hContact = NULL ); - virtual int __cdecl SendMsg( MCONTACT hContact, int flags, const char* msg ); - virtual int __cdecl SetStatus( int iNewStatus ); virtual int __cdecl UserIsTyping( MCONTACT hContact, int type ); diff --git a/protocols/Omegle/src/version.h b/protocols/Omegle/src/version.h index 65f5ae1608..24b7c2d86c 100644 --- a/protocols/Omegle/src/version.h +++ b/protocols/Omegle/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 2 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include -- cgit v1.2.3