void MakeHotkey(lua_State *L, HOTKEYDESC &hk) { hk.cbSize = sizeof(HOTKEYDESC); lua_getfield(L, -1, "Flags"); hk.dwFlags = lua_tointeger(L, -1); lua_pop(L, 1); if (!(hk.dwFlags & HKD_TCHAR)) hk.dwFlags |= HKD_TCHAR; lua_getfield(L, -1, "Name"); hk.pszName = mir_utf8decodeA(luaL_checkstring(L, -1)); lua_pop(L, 1); lua_getfield(L, -1, "Description"); hk.ptszDescription = mir_utf8decodeT((char*)lua_tostring(L, -1)); lua_pop(L, 1); lua_getfield(L, -1, "Section"); hk.ptszSection = mir_utf8decodeT(luaL_optstring(L, -1, MODULE)); lua_pop(L, 1); lua_getfield(L, -1, "Hotkey"); hk.DefHotKey = lua_tointeger(L, -1); lua_pop(L, 1); lua_getfield(L, -1, "Service"); hk.pszService = mir_utf8decodeA(luaL_checkstring(L, -1)); lua_pop(L, 1); lua_getfield(L, -1, "lParam"); hk.lParam = (LPARAM)lua_touserdata(L, -1); lua_pop(L, 1); }
static TTBButton* MakeTBButton(lua_State *L) { TTBButton *tbb = (TTBButton*)mir_calloc(sizeof(TTBButton)); tbb->dwFlags = TTBBF_ISLBUTTON; lua_getfield(L, -1, "Name"); tbb->name = mir_utf8decodeA(luaL_checkstring(L, -1)); lua_pop(L, 1); lua_getfield(L, -1, "Service"); tbb->pszService = (char*)lua_tostring(L, -1); lua_pop(L, 1); lua_getfield(L, -1, "Flags"); tbb->dwFlags = lua_tointeger(L, -1); lua_pop(L, 1); // up state lua_getfield(L, -1, "IconUp"); tbb->hIconHandleUp = (HANDLE)lua_touserdata(L, -1); lua_pop(L, 1); lua_getfield(L, -1, "TooltipUp"); tbb->pszTooltipUp = mir_utf8decodeA(lua_tostring(L, -1)); lua_pop(L, 1); lua_getfield(L, -1, "wParamUp"); tbb->wParamUp = luaM_towparam(L, -1); lua_pop(L, 1); lua_getfield(L, -1, "lParamUp"); tbb->lParamUp = luaM_tolparam(L, -1); lua_pop(L, 1); // dn state lua_getfield(L, -1, "IconDown"); tbb->hIconHandleDn = (HANDLE)lua_touserdata(L, -1); lua_pop(L, 1); lua_getfield(L, -1, "TooltipDown"); tbb->pszTooltipDn = mir_utf8decodeA(lua_tostring(L, -1)); lua_pop(L, 1); lua_getfield(L, -1, "wParamDown"); tbb->wParamDown = luaM_towparam(L, -1); lua_pop(L, 1); lua_getfield(L, -1, "lParamDown"); tbb->lParamDown = luaM_tolparam(L, -1); lua_pop(L, 1); return tbb; }
INT_PTR CAimProto::GetMyAwayMsg(WPARAM wParam, LPARAM lParam) { char** msgptr = get_status_msg_loc(wParam ? wParam : m_iStatus); if (msgptr == NULL) return 0; return (lParam & SGMA_UNICODE) ? (INT_PTR)mir_utf8decodeW(*msgptr) : (INT_PTR)mir_utf8decodeA(*msgptr); }
static int icolib_AddIcon(lua_State *L) { const char *name = luaL_checkstring(L, 1); ptrT description(mir_utf8decodeT(luaL_checkstring(L, 2))); ptrT section(mir_utf8decodeT(luaL_optstring(L, 3, MODULE))); ptrT filePath(mir_utf8decodeT(lua_tostring(L, 4))); if (filePath == NULL) { filePath = (TCHAR*)mir_calloc(MAX_PATH + 1); GetModuleFileName(g_hInstance, filePath, MAX_PATH); } SKINICONDESC si = { 0 }; si.flags = SIDF_ALL_TCHAR; si.pszName = mir_utf8decodeA(name); si.description.t = description; si.section.t = section; si.defaultFile.t = filePath; si.hDefaultIcon = GetIcon(IDI_SCRIPT); HANDLE res = IcoLib_AddIcon(&si, g_mLua->GetHLangpack()); lua_pushlightuserdata(L, res); return 1; }
INT_PTR __cdecl CYahooProto::GetMyAwayMsg(WPARAM wParam, LPARAM lParam) { if (!m_bLoggedIn || ! m_startMsg) return 0; if (lParam & SGMA_UNICODE) { return (INT_PTR) mir_utf8decodeW(m_startMsg); } else { return (INT_PTR) mir_utf8decodeA(m_startMsg); } }
static int lua_GetProto(lua_State *L) { const char *name = luaL_checkstring(L, 1); PROTOCOLDESCRIPTOR* pd = ::Proto_IsProtocolLoaded(ptrA(mir_utf8decodeA(name))); if (pd) lua_pushlightuserdata(L, pd); else lua_pushnil(L); return 1; }
static int lua_GetAccount(lua_State *L) { ptrA moduleName(mir_utf8decodeA(luaL_checkstring(L, 1))); PROTOACCOUNT* pa = ::Proto_GetAccount(moduleName); if (pa) lua_pushlightuserdata(L, pa); else lua_pushnil(L); return 1; }
static int lua_GetProto(lua_State *L) { ptrA name(mir_utf8decodeA(luaL_checkstring(L, 1))); PROTOCOLDESCRIPTOR* pd = ::Proto_IsProtocolLoaded(name); if (pd) MapToTable(L, pd); else lua_pushnil(L); return 1; }
static int lua_AddSound(lua_State *L) { ptrA name(mir_utf8decodeA(luaL_checkstring(L, 1))); ptrW description(mir_utf8decodeW(luaL_checkstring(L, 2))); ptrW section(mir_utf8decodeW(luaL_optstring(L, 3, MODULENAME))); ptrW filePath(mir_utf8decodeW(lua_tostring(L, 4))); int res = 1; CMPluginBase *pPlugin = CMLuaEnvironment::GetEnvironment(L); if (pPlugin != nullptr) res = pPlugin->addSound(name, section, description, filePath); lua_pushboolean(L, res == 0); return 1; }
// TODO: the more I think about it, the more I think all twit.* methods should // be in MessageLoop void TwitterProto::SendTweetWorker(void *p) { if (p == 0) return; char *text = static_cast<char*>(p); if (mir_strlen(mir_utf8decodeA(text)) > 140) { // looks like the chat max outgoing msg thing doesn't work, so i'll do it here. TCHAR errorPopup[280]; mir_sntprintf(errorPopup, TranslateT("Don't be crazy! Everyone knows the max tweet size is 140, and you're trying to fit %d chars in there?"), mir_strlen(text)); ShowPopup(errorPopup, 1); return; } mir_cslock s(twitter_lock_); twit_.set_status(text); mir_free(text); }
static int lua_AddSound(lua_State *L) { ptrA name(mir_utf8decodeA(luaL_checkstring(L, 1))); ptrT description(mir_utf8decodeT(luaL_checkstring(L, 2))); ptrT section(mir_utf8decodeT(luaL_optstring(L, 3, MODULE))); ptrT filePath(mir_utf8decodeT(lua_tostring(L, 4))); SKINSOUNDDESCEX ssd = { sizeof(SKINSOUNDDESCEX) }; ssd.pszName = name; ssd.dwFlags = SSDF_TCHAR; ssd.ptszDescription = description; ssd.ptszSection = section; ssd.ptszDefaultFile = filePath; INT_PTR res = ::CallService("Skin/Sounds/AddNew", hLangpack, (LPARAM)&ssd); lua_pushboolean(L, res == 0); return 1; }
int GetValueA(MCONTACT hContact, const char *module, const char *setting, char *value, int length) { DBVARIANT dbv = { 0 }; if (!module || !setting || !value) return 0; if (length >= 10 && !db_get_s(hContact, module, setting, &dbv, 0)) { switch (dbv.type) { case DBVT_ASCIIZ: mir_strncpy(value, dbv.pszVal, length); break; case DBVT_DWORD: case DBVT_WORD: case DBVT_BYTE: _ultoa(getNumericValue(&dbv), value, 10); break; case DBVT_WCHAR: mir_strncpy(value, ptrA(mir_u2a(dbv.pwszVal)), length); break; case DBVT_UTF8: mir_strncpy(value, ptrA(mir_utf8decodeA(dbv.pszVal)), length); break; case DBVT_DELETED: value[0] = 0; return 0; } int type = dbv.type; db_free(&dbv); return type; } value[0] = 0; return 0; }
http::response facebook_client::flap(RequestType request_type, std::string* request_data, std::string* request_get_data, int method) { NETLIBHTTPREQUEST nlhr = {sizeof(NETLIBHTTPREQUEST)}; nlhr.requestType = !method ? choose_method(request_type) : method; std::string url = choose_proto(request_type); url.append(choose_server(request_type, request_data, request_get_data)); url.append(choose_action(request_type, request_data, request_get_data)); nlhr.szUrl = (char*)url.c_str(); nlhr.flags = NLHRF_HTTP11 | choose_security_level(request_type); nlhr.headers = get_request_headers(nlhr.requestType, &nlhr.headersCount); #ifdef _DEBUG nlhr.flags |= NLHRF_DUMPASTEXT; #else nlhr.flags |= NLHRF_NODUMP; #endif switch (request_type) { case REQUEST_MESSAGES_RECEIVE: nlhr.timeout = 1000 * 65; break; default: nlhr.timeout = 1000 * 20; break; } if (request_data != NULL) { nlhr.pData = (char*)(*request_data).c_str(); nlhr.dataLength = (int)request_data->length(); } parent->debugLogA("@@@@@ Sending request to '%s'", nlhr.szUrl); switch (request_type) { case REQUEST_LOGIN: nlhr.nlc = NULL; break; case REQUEST_MESSAGES_RECEIVE: nlhr.nlc = hMsgCon; nlhr.flags |= NLHRF_PERSISTENT; break; default: WaitForSingleObject(fcb_conn_lock_, INFINITE); nlhr.nlc = hFcbCon; nlhr.flags |= NLHRF_PERSISTENT; break; } NETLIBHTTPREQUEST* pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)handle_, (LPARAM)&nlhr); mir_free(nlhr.headers[3].szValue); mir_free(nlhr.headers); http::response resp; switch (request_type) { case REQUEST_LOGIN: case REQUEST_SETUP_MACHINE: break; case REQUEST_MESSAGES_RECEIVE: hMsgCon = pnlhr ? pnlhr->nlc : NULL; break; default: ReleaseMutex(fcb_conn_lock_); hFcbCon = pnlhr ? pnlhr->nlc : NULL; break; } if (pnlhr != NULL) { parent->debugLogA("@@@@@ Got response with code %d", pnlhr->resultCode); store_headers(&resp, pnlhr->headers, pnlhr->headersCount); resp.code = pnlhr->resultCode; resp.data = pnlhr->pData ? pnlhr->pData : ""; CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)pnlhr); } 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 } // Get Facebook's error message if (resp.code == HTTP_CODE_OK) { std::string::size_type pos = resp.data.find("\"error\":"); if (pos != std::string::npos) { pos += 8; int error_num = atoi(resp.data.substr(pos, resp.data.find(",", pos) - pos).c_str()); if (error_num != 0) { std::string error = ""; pos = resp.data.find("\"errorDescription\":\"", pos); if (pos != std::string::npos) { pos += 20; error = resp.data.substr(pos, resp.data.find("\"", pos) - pos); error = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(error))); error = ptrA( mir_utf8decodeA(error.c_str())); } std::string title = ""; pos = resp.data.find("\"errorSummary\":\"", pos); if (pos != std::string::npos) { pos += 16; title = resp.data.substr(pos, resp.data.find("\"", pos) - pos); title = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(title))); title = ptrA( mir_utf8decodeA(title.c_str())); } bool silent = resp.data.find("\"silentError\":1") != std::string::npos; resp.error_number = error_num; resp.error_text = error; resp.error_title = title; resp.code = HTTP_CODE_FAKE_ERROR; parent->debugLogA(" ! ! Received Facebook error: %d -- %s", error_num, error.c_str()); if (notify_errors(request_type) && !silent) client_notify(_A2T(error.c_str())); } } } return resp; }
INT_PTR CSkypeProto::GetEventText(WPARAM, LPARAM lParam) { DBEVENTGETTEXT *pEvent = (DBEVENTGETTEXT *)lParam; CMStringA szText; BOOL bUseBB = db_get_b(NULL, pEvent->dbei->szModule, "UseBBCodes", 1); switch (pEvent->dbei->eventType) { case SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE: { JSONNode jMsg = JSONNode::parse((char*)pEvent->dbei->pBlob); if (jMsg) { JSONNode &jOriginalMsg = jMsg["original_message"]; szText.AppendFormat(bUseBB ? Translate("[b]Original message:[/b]\n%s\n") : Translate("Original message:\n%s\n"), mir_utf8decodeA(jOriginalMsg["text"].as_string().c_str())); JSONNode &jEdits = jMsg["edits"]; for (auto it = jEdits.begin(); it != jEdits.end(); ++it) { const JSONNode &jEdit = *it; time_t time = jEdit["time"].as_int(); char szTime[MAX_PATH]; strftime(szTime, sizeof(szTime), "%X %x", localtime(&time)); szText.AppendFormat(bUseBB ? Translate("[b]Edited at %s:[/b]\n%s\n") : Translate("Edited at %s:\n%s\n"), szTime, mir_utf8decodeA(jEdit["text"].as_string().c_str())); } } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_CALL_INFO: { HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("partlist")); if (xml != NULL) { ptrA type(mir_t2a(xmlGetAttrValue(xml, _T("type")))); bool bType = (!mir_strcmpi(type, "started")) ? 1 : 0; time_t callDuration = 0; for (int i = 0; i < xmlGetChildCount(xml); i++) { HXML xmlPart = xmlGetNthChild(xml, _T("part"), i); if (xmlPart != NULL) { HXML xmlDuration = xmlGetChildByPath(xmlPart, _T("duration"), 0); if (xmlDuration != NULL) { callDuration = _ttol(xmlGetText(xmlDuration)); xmlDestroyNode(xmlDuration); xmlDestroyNode(xmlPart); break; } xmlDestroyNode(xmlPart); } } if (bType) { szText = Translate("Call"); } else { if (callDuration == 0) { szText = Translate("Call missed"); } else { char szTime[100]; strftime(szTime, sizeof(szTime), "%X", gmtime(&callDuration)); szText.Format(Translate("Call ended (%s)"), szTime); } } xmlDestroyNode(xml); } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO: { HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("files")); if (xml != NULL) { for (int i = 0; i < xmlGetChildCount(xml); i++) { LONGLONG fileSize = 0; HXML xmlNode = xmlGetNthChild(xml, _T("file"), i); if (xmlNode != NULL) { fileSize = _ttol(xmlGetAttrValue(xmlNode, _T("size"))); char *fileName = _T2A(xmlGetText(xmlNode)); if (fileName != NULL) { szText.AppendFormat(Translate("File transfer:\n\tFile name: %s \n\tSize: %lld bytes \n"), fileName, fileSize); } xmlDestroyNode(xmlNode); } } xmlDestroyNode(xml); } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_MOJI: case SKYPE_DB_EVENT_TYPE_URIOBJ: { HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("URIObject")); if (xml != NULL) { szText.Append(_T2A(xmlGetText(xml))); HXML xmlA = xmlGetChildByPath(xml, _T("a"), 0); if (xmlA != NULL) { szText += _T2A(xmlGetAttrValue(xmlA, _T("href"))); xmlDestroyNode(xmlA); } xmlDestroyNode(xml); } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_INCOMING_CALL: { szText = Translate("Incoming call"); break; } case SKYPE_DB_EVENT_TYPE_UNKNOWN: { szText.Format(Translate("Unknown event, please send this text for developer: \"%s\""), mir_utf8decodeA((char*)pEvent->dbei->pBlob)); break; } default: { szText = ptrA(mir_utf8decodeA((char*)pEvent->dbei->pBlob)); } } switch(pEvent->datatype) { case DBVT_TCHAR: { return (INT_PTR)mir_a2t(szText); } case DBVT_ASCIIZ: { return (INT_PTR)szText.Detach(); } case DBVT_UTF8: { return (INT_PTR)mir_utf8encode(szText); } default: { return NULL; } } }