diff options
Diffstat (limited to 'plugins/GmailNotifier/src/check.cpp')
-rw-r--r-- | plugins/GmailNotifier/src/check.cpp | 132 |
1 files changed, 68 insertions, 64 deletions
diff --git a/plugins/GmailNotifier/src/check.cpp b/plugins/GmailNotifier/src/check.cpp index dafed2dcc8..b3821cb7cf 100644 --- a/plugins/GmailNotifier/src/check.cpp +++ b/plugins/GmailNotifier/src/check.cpp @@ -9,12 +9,12 @@ void CheckMailInbox(Account *curAcc) HINTERNET hHTTPRequest; // internet request hadle
DBVARIANT dbv;
- static TCHAR *contentType = _T("Content-Type: application/x-www-form-urlencoded");
- TCHAR requestBuffer[256] = _T("continue=https%3A%2F%2Fmail.google.com%2Fa%2F");
- TCHAR fileBuffer[_MAX_DOWN_BUFFER] = _T("");
- TCHAR *tail;
- TCHAR str[64];
- TCHAR temp[_MAX_DOWN_BUFFER] = _T("");
+ static char *contentType = "Content-Type: application/x-www-form-urlencoded";
+ char requestBuffer[256] = "continue=https%3A%2F%2Fmail.google.com%2Fa%2F";
+ char fileBuffer[_MAX_DOWN_BUFFER] = "";
+ char *tail;
+ char str[64];
+ char temp[_MAX_DOWN_BUFFER] = "";
unsigned long bufferLength;
if (curAcc->IsChecking)
@@ -22,30 +22,30 @@ void CheckMailInbox(Account *curAcc) curAcc->IsChecking = TRUE;
- if (!db_get_ts(curAcc->hContact, "CList", "MyHandle", &dbv)) {
- lstrcpy(curAcc->results.content, dbv.ptszVal);
+ if (!db_get_s(curAcc->hContact, "CList", "MyHandle", &dbv)) {
+ lstrcpyA(curAcc->results.content, dbv.pszVal);
db_free(&dbv);
}
- else lstrcpy(curAcc->results.content, curAcc->name);
+ else lstrcpyA(curAcc->results.content, curAcc->name);
- tail = _tcsstr(curAcc->results.content, _T(" ["));
+ tail = strstr(curAcc->results.content, " [");
if (tail) *tail = '\0';
- lstrcat(curAcc->results.content, _T(" ["));
+ lstrcatA(curAcc->results.content, " [");
- lstrcpy(str, curAcc->results.content);
- lstrcat(str, TranslateT("Checking..."));
- lstrcat(str, _T("]"));
+ lstrcpyA(str, curAcc->results.content);
+ lstrcatA(str, Translate("Checking..."));
+ lstrcatA(str, "]");
- db_set_ts(curAcc->hContact, "CList", "MyHandle", str);
- hHTTPOpen = InternetOpen(_T(""), INTERNET_OPEN_TYPE_PRECONFIG, _T(""), _T(""), 0);
+ db_set_s(curAcc->hContact, "CList", "MyHandle", str);
+ hHTTPOpen = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, "", "", 0);
if (!hHTTPOpen) {
- lstrcat(curAcc->results.content, TranslateT("Can't open Internet!"));
+ lstrcatA(curAcc->results.content, Translate("Can't open Internet!"));
goto error_handle;
}
if (curAcc->hosted[0]) {
- hHTTPConnection = InternetConnect(hHTTPOpen,
- _T("www.google.com"),
+ hHTTPConnection = InternetConnectA(hHTTPOpen,
+ "www.google.com",
INTERNET_DEFAULT_HTTPS_PORT,
NULL,
NULL,
@@ -54,22 +54,22 @@ void CheckMailInbox(Account *curAcc) 0);
if (!hHTTPConnection) {
- lstrcat(curAcc->results.content, TranslateT("Can't reach server!"));
+ lstrcatA(curAcc->results.content, Translate("Can't reach server!"));
goto error_handle;
}
- lstrcpy(str, _T("/a/"));
- lstrcat(str, curAcc->hosted);
- lstrcat(str, _T("/LoginAction"));
- hHTTPRequest = HttpOpenRequest(hHTTPConnection, _T("POST"), str, HTTP_VERSION, NULL, NULL, INTERNET_FLAG_SECURE, 0);
- lstrcat(requestBuffer, curAcc->hosted);
- lstrcat(requestBuffer, _T("%2Ffeed%2Fatom&service=mail&userName="));
- lstrcat(requestBuffer, curAcc->name);
- tail = _tcschr(requestBuffer, '@');
+ lstrcpyA(str, "/a/");
+ lstrcatA(str, curAcc->hosted);
+ lstrcatA(str, "/LoginAction");
+ hHTTPRequest = HttpOpenRequestA(hHTTPConnection, "POST", str, HTTP_VERSIONA, NULL, NULL, INTERNET_FLAG_SECURE, 0);
+ lstrcatA(requestBuffer, curAcc->hosted);
+ lstrcatA(requestBuffer, "%2Ffeed%2Fatom&service=mail&userName=");
+ lstrcatA(requestBuffer, curAcc->name);
+ tail = strchr(requestBuffer, '@');
*tail = '\0';
- lstrcat(requestBuffer, _T("&password="));
- lstrcat(requestBuffer, curAcc->pass);
- if (!HttpSendRequest(hHTTPRequest, contentType, (int)_tcslen(contentType) + 1, requestBuffer, (int)_tcslen(requestBuffer) + 1)) {
- lstrcpy(curAcc->results.content, TranslateT("Can't send account data!"));
+ lstrcatA(requestBuffer, "&password=");
+ lstrcatA(requestBuffer, curAcc->pass);
+ if (!HttpSendRequestA(hHTTPRequest, contentType, (int)strlen(contentType) + 1, requestBuffer, (int)strlen(requestBuffer) + 1)) {
+ lstrcpyA(curAcc->results.content, Translate("Can't send account data!"));
goto error_handle;
}
@@ -77,42 +77,42 @@ void CheckMailInbox(Account *curAcc) InternetCloseHandle(hHTTPRequest);
}
- hHTTPConnection = InternetConnect(hHTTPOpen, _T("mail.google.com"), INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
+ hHTTPConnection = InternetConnectA(hHTTPOpen, "mail.google.com", INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if (!hHTTPConnection) {
- lstrcat(curAcc->results.content, TranslateT("Can't reach server!"));
+ lstrcatA(curAcc->results.content, Translate("Can't reach server!"));
goto error_handle;
}
if (curAcc->hosted[0]) {
- lstrcpy(str, _T("/a/"));
- lstrcat(str, curAcc->hosted);
- lstrcat(str, _T("/feed/atom"));
+ lstrcpyA(str, "/a/");
+ lstrcatA(str, curAcc->hosted);
+ lstrcatA(str, "/feed/atom");
}
- else lstrcpy(str, _T("/mail/feed/atom"));
+ else lstrcpyA(str, "/mail/feed/atom");
- hHTTPRequest = HttpOpenRequest(hHTTPConnection, _T("GET"), str, NULL, NULL, NULL, INTERNET_FLAG_SECURE | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0);
- InternetSetOption(hHTTPRequest, INTERNET_OPTION_USERNAME, curAcc->name, (int)_tcslen(curAcc->name) + 1);
- InternetSetOption(hHTTPRequest, INTERNET_OPTION_PASSWORD, curAcc->pass, (int)_tcslen(curAcc->pass) + 1);
+ hHTTPRequest = HttpOpenRequest(hHTTPConnection, _T("GET"), _A2T(str), NULL, NULL, NULL, INTERNET_FLAG_SECURE | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0);
+ InternetSetOption(hHTTPRequest, INTERNET_OPTION_USERNAME, _A2T(curAcc->name), (int)strlen(curAcc->name) + 1);
+ InternetSetOption(hHTTPRequest, INTERNET_OPTION_PASSWORD, _A2T(curAcc->pass), (int)strlen(curAcc->pass) + 1);
if (!HttpSendRequest(hHTTPRequest, NULL, 0, NULL, 0)) {
- lstrcat(curAcc->results.content, TranslateT("Can't get RSS feed!"));
+ lstrcatA(curAcc->results.content, Translate("Can't get RSS feed!"));
goto error_handle;
}
while (InternetReadFile(hHTTPRequest, temp, _MAX_DOWN_BUFFER, &bufferLength) && bufferLength > 0) {
temp[bufferLength] = '\0';
- lstrcat(fileBuffer, temp);
+ lstrcatA(fileBuffer, temp);
}
fileBuffer[_MAX_DOWN_BUFFER - 1] = '\0';
curAcc->results_num = ParsePage(fileBuffer, &curAcc->results);
if (curAcc->results_num == -1) {
- lstrcat(curAcc->results.content, TranslateT("Wrong name or password!"));
+ lstrcatA(curAcc->results.content, Translate("Wrong name or password!"));
goto error_handle;
}
InternetCloseHandle(hHTTPOpen);
InternetCloseHandle(hHTTPConnection);
InternetCloseHandle(hHTTPRequest);
- lstrcat(curAcc->results.content, _itot(curAcc->results_num, str, 10));
- lstrcat(curAcc->results.content, _T("]"));
+ lstrcatA(curAcc->results.content, _itoa(curAcc->results_num, str, 10));
+ lstrcatA(curAcc->results.content, "]");
curAcc->IsChecking = FALSE;
return;
@@ -123,14 +123,14 @@ error_handle: InternetCloseHandle(hHTTPConnection);
InternetCloseHandle(hHTTPRequest);
- lstrcat(curAcc->results.content, _T("]"));
+ lstrcatA(curAcc->results.content, "]");
curAcc->IsChecking = FALSE;
}
void __cdecl Check_ThreadFunc(void *lpParam)
{
- InternetSetCookie(_T("https://mail.google.com/mail/"), _T("GX"), _T(""));
+ InternetSetCookieA("https://mail.google.com/mail/", "GX", "");
if (lpParam) {
CheckMailInbox((Account *)lpParam);
NotifyUser((Account *)lpParam);
@@ -143,37 +143,41 @@ void __cdecl Check_ThreadFunc(void *lpParam) }
}
-int ParsePage(TCHAR *page, resultLink *prst)
+int ParsePage(char *page, resultLink *prst)
{
- TCHAR *str_head, *str_tail;
- TCHAR name[64], title[64];
+ char *str_head;
+ char *str_tail;
+ char name[64], title[64];
int num = 0;
+ wchar_t str[64];
prst->next = NULL;
- if (_tcsstr(page, _T("Unauthorized")))
+ if (strstr(page, "Unauthorized"))
return -1;
- if (!(str_head = _tcsstr(page, _T("<entry>"))))
+ if (!(str_head = strstr(page, "<entry>")))
return 0;
- while (str_head = _tcsstr(str_head, _T("<title>"))) {
+ while (str_head = strstr(str_head, "<title>")) {
prst = prst->next = (resultLink *)malloc(sizeof(resultLink));
str_head += 7;
- str_tail = _tcsstr(str_head, _T("</title>"));
+ str_tail = strstr(str_head, "</title>");
*str_tail = '\0';
- lstrcpyn(title, str_head, 41);
- if (lstrlen(title) == 40)
- lstrcat(title, _T("..."));
+ lstrcpynA(title, str_head, 41);
+ if (lstrlenA(title) == 40)
+ lstrcatA(title, "...");
*str_tail = ' ';
- str_head = _tcsstr(str_head, _T("<name>")) + 6;
- str_tail = _tcsstr(str_head, _T("</name>"));
+ str_head = strstr(str_head, "<name>") + 6;
+ str_tail = strstr(str_head, "</name>");
*str_tail = '\0';
- lstrcpyn(name, str_head, 11);
- lstrcat(name, _T(": "));
+ lstrcpynA(name, str_head, 11);
+ lstrcatA(name, ": ");
*str_tail = ' ';
- lstrcpy(prst->content, name);
- lstrcat(prst->content, title);
+ lstrcpyA(prst->content, name);
+ lstrcatA(prst->content, title);
+ MultiByteToWideChar(CP_UTF8, 0, prst->content, -1, str, 64);
+ WideCharToMultiByte(CP_ACP, 0, str, -1, prst->content, 64, NULL, NULL);
num++;
}
prst->next = NULL;
|