int luaM_toansi(lua_State *L) { const char* value = luaL_checkstring(L, 1); int codepage = luaL_optinteger(L, 2, Langpack_GetDefaultCodePage()); ptrA string(mir_strdup(value)); lua_pushstring(L, mir_utf8decodecp(string, codepage, NULL)); return 1; }
// This function adds a new job to the list of messages to send unattended // used by the send later feature and multisend // // @param szSetting is either the name of the database key for a send later // job OR the utf-8 encoded message for a multisend job prefixed with // a 'M+timestamp'. Send later job ids start with "S". // // @param lParam: a contact handle for which the job should be scheduled // @return 0 on failure, 1 otherwise // int CSendLater::addJob(const char *szSetting, LPARAM lParam) { MCONTACT hContact = lParam; DBVARIANT dbv = {0}; char *szOrig_Utf = 0; if (!m_fAvail || !szSetting || !strcmp(szSetting, "count") || lstrlenA(szSetting) < 8) return 0; if (szSetting[0] != 'S' && szSetting[0] != 'M') return 0; // check for possible dupes for (int i=0; i < m_sendLaterJobList.getCount(); i++) { CSendLaterJob *p = m_sendLaterJobList[i]; if (p->hContact == hContact && !strcmp(p->szId, szSetting)) return 0; } if (szSetting[0] == 'S') { if (0 == db_get_s(hContact, "SendLater", szSetting, &dbv)) szOrig_Utf = dbv.pszVal; else return 0; } else if (szSetting[0] == 'M') { char *szSep = strchr(const_cast<char *>(szSetting), '|'); if (!szSep) return 0; *szSep = 0; szOrig_Utf = szSep + 1; } else return 0; CSendLaterJob *job = new CSendLaterJob; strncpy(job->szId, szSetting, 20); job->szId[19] = 0; job->hContact = hContact; job->created = atol(&szSetting[1]); int iLen = lstrlenA(szOrig_Utf); job->sendBuffer = reinterpret_cast<char *>(mir_alloc(iLen + 1)); strncpy(job->sendBuffer, szOrig_Utf, iLen); job->sendBuffer[iLen] = 0; // construct conventional send buffer wchar_t *szWchar = 0; char *szAnsi = mir_utf8decodecp(szOrig_Utf, CP_ACP, &szWchar); iLen = lstrlenA(szAnsi); UINT required = iLen + 1; if (szWchar) required += ((lstrlenW(szWchar) + 1) * sizeof(wchar_t)); job->pBuf = (PBYTE)mir_calloc(required); strncpy((char *)job->pBuf, szAnsi, iLen); job->pBuf[iLen] = 0; if (szWchar) wcsncpy((wchar_t *)&job->pBuf[iLen + 1], szWchar, lstrlenW(szWchar)); if (szSetting[0] == 'S') db_free(&dbv); mir_free(szWchar); job->readFlags(); m_sendLaterJobList.insert(job); qMgrUpdate(); return 1; }