summaryrefslogtreecommitdiff
path: root/protocols/Omegle
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2015-10-20 09:37:26 +0000
committerRobert Pösel <robyer@seznam.cz>2015-10-20 09:37:26 +0000
commit1b270f957517df4def8cf85ee3dc75050cce3357 (patch)
tree1972b6e4270c798f1848f19e2a8574e0cc88f30c /protocols/Omegle
parentd3e496e29030a0ebe980dcd0326a1c3262d2db1e (diff)
Omegle: Adapt to use std_string_utils
git-svn-id: http://svn.miranda-ng.org/main/trunk@15575 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Omegle')
-rw-r--r--protocols/Omegle/omegle.vcxproj5
-rw-r--r--protocols/Omegle/src/communication.cpp10
-rw-r--r--protocols/Omegle/src/stdafx.h26
-rw-r--r--protocols/Omegle/src/utils.cpp173
-rw-r--r--protocols/Omegle/src/utils.h76
5 files changed, 34 insertions, 256 deletions
diff --git a/protocols/Omegle/omegle.vcxproj b/protocols/Omegle/omegle.vcxproj
index 8f89d2cb64..eb61116d9b 100644
--- a/protocols/Omegle/omegle.vcxproj
+++ b/protocols/Omegle/omegle.vcxproj
@@ -25,6 +25,11 @@
<ImportGroup Label="PropertySheets">
<Import Project="$(ProjectDir)..\..\build\vc.common\plugin.props" />
</ImportGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\utils\std_string_utils.cpp">
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ </ClCompile>
+ </ItemGroup>
<ItemDefinitionGroup>
<ClCompile>
<ExceptionHandling>Sync</ExceptionHandling>
diff --git a/protocols/Omegle/src/communication.cpp b/protocols/Omegle/src/communication.cpp
index a869a47391..428d4a8cc4 100644
--- a/protocols/Omegle/src/communication.cpp
+++ b/protocols/Omegle/src/communication.cpp
@@ -531,7 +531,7 @@ bool Omegle_client::events()
pos += 13;
std::string question = utils::text::trim(
- utils::text::special_expressions_decode(
+ utils::text::html_entities_decode(
utils::text::slashu_to_utf8(
resp.data.substr(pos, resp.data.find("\"]", pos) - pos) )) );
@@ -576,7 +576,7 @@ bool Omegle_client::events()
pos += 15;
std::string message = utils::text::trim(
- utils::text::special_expressions_decode(
+ utils::text::html_entities_decode(
utils::text::slashu_to_utf8(
resp.data.substr(pos, resp.data.find("\"]", pos) - pos) )) );
@@ -600,7 +600,7 @@ bool Omegle_client::events()
message = message.substr(stranger.length() + 4);
message = utils::text::trim(
- utils::text::special_expressions_decode(
+ utils::text::html_entities_decode(
utils::text::slashu_to_utf8( message )) );
stranger = Translate(stranger.c_str());
@@ -632,7 +632,7 @@ bool Omegle_client::events()
pos += 20;
std::string stranger = utils::text::trim(
- utils::text::special_expressions_decode(
+ utils::text::html_entities_decode(
utils::text::slashu_to_utf8(
resp.data.substr(pos, resp.data.find("\"]", pos) - pos) )) );
@@ -668,7 +668,7 @@ bool Omegle_client::events()
pos += 10;
std::string error = utils::text::trim(
- utils::text::special_expressions_decode(
+ utils::text::html_entities_decode(
utils::text::slashu_to_utf8(
resp.data.substr(pos, resp.data.find("\"]", pos) - pos) )) );
diff --git a/protocols/Omegle/src/stdafx.h b/protocols/Omegle/src/stdafx.h
index 58bd9ed275..69ea6c6e9c 100644
--- a/protocols/Omegle/src/stdafx.h
+++ b/protocols/Omegle/src/stdafx.h
@@ -64,8 +64,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class OmegleProto;
+#include "../../utils/std_string_utils.h"
+
#include "http.h"
-#include "utils.h"
#include "client.h"
#include "proto.h"
#include "db.h"
@@ -76,4 +77,25 @@ class OmegleProto;
extern HINSTANCE g_hInstance;
extern std::string g_strUserAgent;
-extern DWORD g_mirandaVersion; \ No newline at end of file
+extern DWORD g_mirandaVersion;
+
+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_;
+};
diff --git a/protocols/Omegle/src/utils.cpp b/protocols/Omegle/src/utils.cpp
deleted file mode 100644
index 0e5b4b2153..0000000000
--- a/protocols/Omegle/src/utils.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
-
-Omegle plugin for Miranda Instant Messenger
-_____________________________________________
-
-Copyright © 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
-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"
-
-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, const std::string &from, const std::string &to )
-{
- std::string::size_type position = 0;
-
- if ( ( position = data->find(from, position)) != std::string::npos )
- {
- data->replace( position, from.size(), to );
- position++;
- }
-}
-
-void utils::text::replace_all( std::string* data, const std::string &from, const std::string &to )
-{
- std::string::size_type position = 0;
-
- while ( ( position = data->find( from, position )) != std::string::npos )
- {
- data->replace( position, from.size(), to );
- position++;
- }
-}
-
-void utils::text::treplace_all(std::tstring* data, const std::tstring &from, const std::tstring &to)
-{
- std::tstring::size_type position = 0;
-
- while ((position = data->find(from, position)) != std::tstring::npos)
- {
- data->replace(position, from.size(), to);
- position++;
- }
-}
-
-
-std::string utils::text::special_expressions_decode( std::string data )
-{
- utils::text::replace_all( &data, "\\r", "\r" );
- utils::text::replace_all( &data, "\\n", "\n" );
- utils::text::replace_all( &data, "\\\"", "\"" );
- utils::text::replace_all( &data, "\\\\", "\\" );
-
- return data;
-}
-
-
-std::string utils::text::slashu_to_utf8(const std::string &data )
-{
- std::string new_string = "";
-
- for ( std::string::size_type i = 0; i < data.length( ); i++ )
- {
- if ( data.at(i) == '\\' && (i+1) < data.length( ) && data.at(i+1) == 'u' )
- {
- unsigned int udn = strtol( data.substr( i + 2, 4 ).c_str(), NULL, 16 );
-
- if ( udn >= 128 && udn <= 2047 )
- { // U+0080 .. U+07FF
- new_string += ( char )( 192 + ( udn / 64 ));
- new_string += ( char )( 128 + ( udn % 64 ));
- }
- else if ( udn >= 2048 && udn <= 65535 )
- { // U+0800 .. U+FFFF
- new_string += ( char )( 224 + ( udn / 4096 ));
- new_string += ( char )( 128 + ( ( udn / 64 ) % 64 ));
- new_string += ( char )( 128 + ( udn % 64 ));
- }
- else if ( udn <= 127 )
- { // U+0000 .. U+007F (should not appear)
- new_string += ( char )udn;
- }
-
- i += 5;
- continue;
- }
-
- new_string += data.at(i);
- }
-
- return new_string;
-}
-
-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);
- std::string::size_type end = data.find_last_not_of(spaces);
-
- return (end != std::string::npos) ? data.substr(begin, end + 1 - begin) : "";
-}
-
-void utils::text::explode(std::string str, std::string separator, std::vector<std::string>* results)
-{
- std::string::size_type pos;
- pos = str.find_first_of(separator);
- while (pos != std::string::npos) {
- if (pos > 0) {
- results->push_back(str.substr(0, pos));
- }
- str = str.substr(pos + 1);
- pos = str.find_first_of(separator);
- }
- if (str.length() > 0) {
- results->push_back(str);
- }
-}
-
-int utils::debug::log(const std::string &file_name, const std::string &text)
-{
- char szFile[MAX_PATH];
- GetModuleFileNameA(g_hInstance, szFile, _countof(szFile));
- std::string path = szFile;
- path = path.substr( 0, path.rfind( "\\" ));
- path = path.substr( 0, path.rfind( "\\" ) + 1 );
- path = path + file_name.c_str() + ".txt";
-
- SYSTEMTIME time;
- GetLocalTime( &time );
-
- std::ofstream out( path.c_str(), std::ios_base::out | std::ios_base::app | std::ios_base::ate );
- out << "[" << (time.wHour < 10 ? "0" : "") << time.wHour << ":" << (time.wMinute < 10 ? "0" : "") << time.wMinute << ":" << (time.wSecond < 10 ? "0" : "") << time.wSecond << "] " << text << std::endl;
- out.close( );
-
- return EXIT_SUCCESS;
-}
-
-void __fastcall utils::mem::detract(char** str )
-{
- utils::mem::detract( ( void** )str );
-}
-
-void __fastcall utils::mem::detract(void** p)
-{
- utils::mem::detract((void*)(*p));
-}
-
-void __fastcall utils::mem::detract(void* p)
-{
- mir_free(p);
-}
-
-void* __fastcall utils::mem::allocate(size_t size)
-{
- return mir_calloc(size);
-}
diff --git a/protocols/Omegle/src/utils.h b/protocols/Omegle/src/utils.h
deleted file mode 100644
index 578d2874a7..0000000000
--- a/protocols/Omegle/src/utils.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
-
-Omegle plugin for Miranda Instant Messenger
-_____________________________________________
-
-Copyright © 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
-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/>.
-
-*/
-
-#pragma once
-
-namespace utils
-{
- namespace url
- {
- std::string encode(const std::string &s);
- };
-
- namespace text
- {
- 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(const std::string &data );
- std::string trim(const std::string &data );
- void explode(std::string str, std::string separator, std::vector<std::string>* results);
- };
-
- namespace debug
- {
- int log(const std::string &file_name, const std::string &text);
- };
-
- namespace mem
- {
- void __fastcall detract(char** str );
- void __fastcall detract(void** p);
- void __fastcall detract(void* p);
- void* __fastcall allocate(size_t size);
- };
-};
-
-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_;
-};