summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/FacebookRM/src/utils.cpp6
-rw-r--r--protocols/GTalkExt/src/handlers.cpp7
-rw-r--r--protocols/GTalkExt/src/inbox.cpp98
-rw-r--r--protocols/Omegle/src/utils.cpp7
-rw-r--r--protocols/Twitter/src/http.cpp6
5 files changed, 25 insertions, 99 deletions
diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp
index 7b9f9c578e..77772175d9 100644
--- a/protocols/FacebookRM/src/utils.cpp
+++ b/protocols/FacebookRM/src/utils.cpp
@@ -24,11 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
std::string utils::url::encode(const std::string &s)
{
- char *encoded = reinterpret_cast<char*>(CallService(MS_NETLIB_URLENCODE, 0, reinterpret_cast<LPARAM>(s.c_str())));
- std::string ret = encoded;
- HeapFree(GetProcessHeap(), 0, encoded);
-
- return ret;
+ return mir_ptr<char>( mir_urlEncode( s.c_str()));
}
std::string utils::url::decode(std::string data)
diff --git a/protocols/GTalkExt/src/handlers.cpp b/protocols/GTalkExt/src/handlers.cpp
index 6ca82693f0..e72a940d3e 100644
--- a/protocols/GTalkExt/src/handlers.cpp
+++ b/protocols/GTalkExt/src/handlers.cpp
@@ -173,11 +173,10 @@ BOOL InternalListHandler(IJabberInterface *ji, HXML node, LPCTSTR jid, LPCTSTR m
if (ReadCheckbox(0, IDC_STANDARDVIEW, settings))
FormatMessageUrl(MESSAGE_URL_FORMAT_STANDARD, (LPTSTR)url, mailboxUrl, tid);
+ else if (ReadCheckbox(0, IDC_HTMLVIEW, settings))
+ FormatMessageUrl(MESSAGE_URL_FORMAT_HTML, (LPTSTR)url, mailboxUrl, tid);
else
- if (ReadCheckbox(0, IDC_HTMLVIEW, settings))
- FormatMessageUrl(MESSAGE_URL_FORMAT_HTML, (LPTSTR)url, mailboxUrl, tid);
- else
- MakeUrlHex((LPTSTR)url, tid);
+ MakeUrlHex((LPTSTR)url, tid);
CloseNotifications(acc, url, jid, i);
UnreadThreadNotification(acc, jid, url, xi.getAttrValue(node, ATTRNAME_TOTAL_MATCHED), &mtn);
diff --git a/protocols/GTalkExt/src/inbox.cpp b/protocols/GTalkExt/src/inbox.cpp
index cff579bb4c..3e0bd96932 100644
--- a/protocols/GTalkExt/src/inbox.cpp
+++ b/protocols/GTalkExt/src/inbox.cpp
@@ -64,26 +64,6 @@ const DWORD SIZE_OF_JABBER_OPTIONS = 243 * sizeof(DWORD);
#define NLH_INVALID 0
#define NLH_USER 'USER'
-char to_hex(char code) {
- static char hex[] = "0123456789abcdef";
- return hex[code & 15];
-}
-
-char *url_encode(char *str) {
- char *pstr = str, *buf = (char*)malloc(strlen(str) * 3 + 1), *pbuf = buf;
- while (*pstr) {
- if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == ',' || *pstr == '~')
- *pbuf++ = *pstr;
- else if (*pstr == ' ')
- *pbuf++ = '+';
- else
- *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15);
- pstr++;
- }
- *pbuf = '\0';
- return buf;
-}
-
LPSTR HttpPost(HANDLE hUser, LPSTR reqUrl, LPSTR reqParams)
{
NETLIBHTTPREQUEST nlhr = {0};
@@ -100,7 +80,7 @@ LPSTR HttpPost(HANDLE hUser, LPSTR reqUrl, LPSTR reqParams)
if (!pResp) return NULL;
__try {
if (HTTP_OK == pResp->resultCode)
- return _strdup(pResp->pData);
+ return mir_strdup(pResp->pData);
else
return NULL;
}
@@ -111,26 +91,10 @@ LPSTR HttpPost(HANDLE hUser, LPSTR reqUrl, LPSTR reqParams)
LPSTR MakeRequest(HANDLE hUser, LPSTR reqUrl, LPSTR reqParamsFormat, LPSTR p1, LPSTR p2)
{
- LPSTR encodedP1 = url_encode(p1);
- __try {
- LPSTR encodedP2 = url_encode(p2);
- __try {
- LPSTR reqParams = (LPSTR)malloc(lstrlenA(reqParamsFormat) + 1 + lstrlenA(encodedP1) + lstrlenA(encodedP2));
- __try {
- sprintf(reqParams, reqParamsFormat, encodedP1, encodedP2);
- return HttpPost(hUser, reqUrl, reqParams);
- }
- __finally {
- free(reqParams);
- }
- }
- __finally {
- free(encodedP2);
- }
- }
- __finally {
- free(encodedP1);
- }
+ mir_ptr<char> encodedP1( mir_urlEncode(p1)), encodedP2( mir_urlEncode(p2));
+ LPSTR reqParams = (LPSTR)alloca(lstrlenA(reqParamsFormat) + 1 + lstrlenA(encodedP1) + lstrlenA(encodedP2));
+ sprintf(reqParams, reqParamsFormat, encodedP1, encodedP2);
+ return HttpPost(hUser, reqUrl, reqParams);
}
LPSTR FindSid(LPSTR resp, LPSTR *LSID)
@@ -155,50 +119,26 @@ LPSTR FindSid(LPSTR resp, LPSTR *LSID)
void DoOpenUrl(LPSTR tokenResp, LPSTR url)
{
- LPSTR encodedUrl = url_encode(url);
- __try {
- LPSTR encodedToken = url_encode(tokenResp);
- __try {
- LPSTR composedUrl = (LPSTR)malloc(lstrlenA(TOKEN_AUTH_URL) + 1 + lstrlenA(encodedToken) + lstrlenA(encodedUrl));
- __try {
- sprintf(composedUrl, TOKEN_AUTH_URL, encodedToken, encodedUrl);
- ShellExecuteA(0, NULL, composedUrl, NULL, NULL, SW_SHOW);
- }
- __finally {
- free(composedUrl);
- }
- }
- __finally {
- free(encodedToken);
- }
- }
- __finally {
- free(encodedUrl);
- }
+ mir_ptr<char> encodedUrl( mir_urlEncode(url)), encodedToken( mir_urlEncode(tokenResp));
+ LPSTR composedUrl = (LPSTR)alloca(lstrlenA(TOKEN_AUTH_URL) + 1 + lstrlenA(encodedToken) + lstrlenA(encodedUrl));
+ sprintf(composedUrl, TOKEN_AUTH_URL, encodedToken, encodedUrl);
+ CallService(MS_UTILS_OPENURL, 0, (LPARAM)composedUrl);
}
BOOL AuthAndOpen(HANDLE hUser, LPSTR url, LPSTR mailbox, LPSTR pwd)
{
- LPSTR authResp = MakeRequest(hUser, AUTH_REQUEST_URL, AUTH_REQUEST_PARAMS, mailbox, pwd);
- if (!authResp) return FALSE;
+ mir_ptr<char> authResp( MakeRequest(hUser, AUTH_REQUEST_URL, AUTH_REQUEST_PARAMS, mailbox, pwd));
+ if (!authResp)
+ return FALSE;
- __try {
- LPSTR LSID;
- LPSTR SID = FindSid(authResp, &LSID);
- LPSTR tokenResp = MakeRequest(hUser, ISSUE_TOKEN_REQUEST_URL, ISSUE_TOKEN_REQUEST_PARAMS, SID, LSID);
- if (!tokenResp) return FALSE;
+ LPSTR LSID;
+ LPSTR SID = FindSid(authResp, &LSID);
+ mir_ptr<char> tokenResp( MakeRequest(hUser, ISSUE_TOKEN_REQUEST_URL, ISSUE_TOKEN_REQUEST_PARAMS, SID, LSID));
+ if (!tokenResp)
+ return FALSE;
- __try {
- DoOpenUrl(tokenResp, url);
- return TRUE;
- }
- __finally {
- free(tokenResp);
- }
- }
- __finally {
- free(authResp);
- }
+ DoOpenUrl(tokenResp, url);
+ return TRUE;
}
struct OPEN_URL_HEADER {
diff --git a/protocols/Omegle/src/utils.cpp b/protocols/Omegle/src/utils.cpp
index f524dcfba1..09b6eed036 100644
--- a/protocols/Omegle/src/utils.cpp
+++ b/protocols/Omegle/src/utils.cpp
@@ -24,12 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
std::string utils::url::encode(const std::string &s)
{
- char *encoded = reinterpret_cast<char*>(CallService( MS_NETLIB_URLENCODE,
- 0,reinterpret_cast<LPARAM>(s.c_str())));
- std::string ret = encoded;
- HeapFree(GetProcessHeap(),0,encoded);
-
- return ret;
+ return mir_ptr<char>( mir_urlEncode( s.c_str()));
}
void utils::text::replace_first( std::string* data, std::string from, std::string to )
diff --git a/protocols/Twitter/src/http.cpp b/protocols/Twitter/src/http.cpp
index f953ec1973..912219dfaf 100644
--- a/protocols/Twitter/src/http.cpp
+++ b/protocols/Twitter/src/http.cpp
@@ -23,9 +23,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
std::string http::url_encode(const std::string &s)
{
- char *encoded = reinterpret_cast<char*>(CallService( MS_NETLIB_URLENCODE,0,reinterpret_cast<LPARAM>(s.c_str())));
- std::string ret = encoded;
- HeapFree(GetProcessHeap(),0,encoded);
-
- return ret;
+ return mir_ptr<char>( mir_urlEncode( s.c_str()));
}