bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result) { debugLogA("CVkProto::RunCaptchaForm: reading picture from %s", szUrl); result.Empty(); CAPTCHA_FORM_PARAMS param = { 0 }; if (getBool("UseCaptchaAssistant", false)) { CMStringA szCaptchaAssistant(FORMAT, "http://ca.tiflohelp.ru/?link=%s", ptrA(ExpUrlEncode(szUrl))); Utils_OpenUrl(szCaptchaAssistant); } else { NETLIBHTTPREQUEST req = { sizeof(req) }; req.requestType = REQUEST_GET; req.szUrl = (LPSTR)szUrl; req.flags = VK_NODUMPHEADERS; NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req); if (reply == NULL) return false; if (reply->resultCode != 200) { debugLogA("CVkProto::RunCaptchaForm: failed with code %d", reply->resultCode); return false; } IMGSRVC_MEMIO memio = { 0 }; memio.iLen = reply->dataLength; memio.pBuf = reply->pData; memio.fif = FIF_UNKNOWN; /* detect */ param.bmp = (HBITMAP)CallService(MS_IMG_LOADFROMMEM, (WPARAM)&memio); BITMAP bmp = { 0 }; GetObject(param.bmp, sizeof(bmp), &bmp); param.w = bmp.bmWidth; param.h = bmp.bmHeight; } CVkCaptchaForm dlg(this, ¶m); if (!dlg.DoModal()) return false; debugLogA("CVkProto::RunCaptchaForm: user entered text %s", param.Result); result = param.Result; return true; }
bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result) { debugLogA("CVkProto::RunCaptchaForm: reading picture from %s", szUrl); result.Empty(); NETLIBHTTPREQUEST req = { sizeof(req) }; req.requestType = REQUEST_GET; req.szUrl = (LPSTR)szUrl; req.flags = VK_NODUMPHEADERS; NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req); if (reply == NULL) return false; if (reply->resultCode != 200) { debugLogA("CVkProto::RunCaptchaForm: failed with code %d", reply->resultCode); return false; } CAPTCHA_FORM_PARAMS param = { 0 }; IMGSRVC_MEMIO memio = { 0 }; memio.iLen = reply->dataLength; memio.pBuf = reply->pData; memio.fif = FIF_UNKNOWN; /* detect */ param.bmp = (HBITMAP)CallService(MS_IMG_LOADFROMMEM, (WPARAM)&memio); BITMAP bmp = {0}; GetObject(param.bmp, sizeof(bmp), &bmp); param.w = bmp.bmWidth; param.h = bmp.bmHeight; int res = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CAPTCHAFORM), NULL, CaptchaFormDlgProc, (LPARAM)¶m); if (res == 0) return false; debugLogA("CVkProto::RunCaptchaForm: user entered text %s", param.Result); result = param.Result; return true; }
int stringReplacer(const char *oldString, CMStringA &szNewString, MCONTACT hContact) { char var_file[8]; int tempInt; int startLine = 0, endLine = 0, startChar = 0, endChar = 0, wholeLine = -1, linesInFile; int positionInOldString = 0; char *fileContents[MAXLINES] = { NULL }, tempString[MAX_STRING_LENGTH]; // setup the variable names szNewString.Empty(); strncpy(var_file, "file(", sizeof(var_file)); while ((positionInOldString < (int)mir_strlen(oldString)) && (oldString[positionInOldString] != '\0')) { // load the file... must be first if (!strncmp(&oldString[positionInOldString], var_file, mir_strlen(var_file))) { positionInOldString += (int)mir_strlen(var_file); // check if its a number tempInt = getNumber(&oldString[positionInOldString]); if (tempInt == -1) { // not a number so check vars.. // there are none yet return ERROR_NO_FILE; } // read the file linesInFile = readFileIntoArray(tempInt, fileContents); if (linesInFile == 0) return ERROR_NO_FILE; positionInOldString += (int)mir_strlen(_itoa(tempInt, tempString, 10)) + 1; // +1 for the closing ) // wholeline() if (!strncmp(&oldString[positionInOldString], "wholeline(line(", mir_strlen("wholeline(line("))) { positionInOldString += (int)mir_strlen("wholeline(line("); tempInt = findLine(fileContents, oldString, linesInFile, startLine, &positionInOldString); if (tempInt == -1 || !fileContents[tempInt]) return ERROR_NO_LINE_AFTER_VAR_F; wholeLine = tempInt; positionInOldString += 3; // add 2 for the )) for wholeline(line()) } if (!strncmp(&oldString[positionInOldString], "start(", mir_strlen("start("))) { positionInOldString += (int)mir_strlen("start(line("); tempInt = findLine(fileContents, oldString, linesInFile, startLine, &positionInOldString); if (tempInt == -1 || !fileContents[tempInt]) return ERROR_NO_LINE_AFTER_VAR_F; else { positionInOldString += 2; startLine = tempInt; if (!endChar) endChar = (int)mir_strlen(fileContents[startLine]); tempInt = findChar(fileContents, oldString, linesInFile, startLine, &positionInOldString, startChar, 0); if (tempInt == -1) return ERROR_NO_LINE_AFTER_VAR_F; startChar = tempInt; } positionInOldString += 2; // add 2 for the )) for start(line()) } if (!strncmp(&oldString[positionInOldString], "end(", mir_strlen("end("))) { positionInOldString += (int)mir_strlen("end(line("); tempInt = findLine(fileContents, oldString, linesInFile, startLine, &positionInOldString); if (tempInt == -1 || !fileContents[tempInt]) return ERROR_NO_LINE_AFTER_VAR_F; positionInOldString += 2; endLine = tempInt; tempInt = findChar(fileContents, oldString, linesInFile, startLine, &positionInOldString, startChar, 1); if (tempInt == -1) return ERROR_NO_LINE_AFTER_VAR_F; endChar = tempInt; positionInOldString += 2; // add 2 for the )) for end(line()) } // check for both start() and end() otherwise, only copying 1 line if (!strstr(oldString, "start(")) startLine = endLine; if (!strstr(oldString, "end(")) endLine = startLine; // after all the options copy the line across and add 2 to positionInOldString for the file(print(....)) if (wholeLine >= 0) szNewString.Append(fileContents[wholeLine]); else { // only copying from 1 line if (startLine == endLine) szNewString.Append(&fileContents[startLine][startChar], endChar - startChar); else { // copy the whole first line from startChar szNewString.Append(&fileContents[startLine][startChar]); // copy the middle lines across for (int i = (startLine + 1); i < endLine; i++) szNewString.Append(fileContents[i]); // copy the last line untill endChar szNewString.Append(fileContents[endLine], endChar); } } } // filename() else if (!strncmp(&oldString[positionInOldString], "filename(", mir_strlen("filename("))) { positionInOldString += (int)mir_strlen("filename("); tempInt = getNumber(&oldString[positionInOldString]); if (tempInt == -1) { return ERROR_NO_FILE; } else { mir_snprintf(tempString, _countof(tempString), "fn%d", tempInt); if (db_get_static(NULL, MODNAME, tempString, tempString, _countof(tempString))) szNewString.Append(tempString); else return ERROR_NO_FILE; positionInOldString += (int)mir_strlen(_itoa(tempInt, tempString, 10)) + 1; } } // lastchecked(file(X)) else if (!strncmp(&oldString[positionInOldString], "lastchecked(file(", mir_strlen("lastchecked(file("))) { positionInOldString += lastChecked(szNewString, &oldString[positionInOldString]); } else { szNewString.Append(&oldString[positionInOldString], 1); positionInOldString++; } } // free the file strings for (tempInt = 0; (fileContents[tempInt] != NULL) && (tempInt < MAXLINES); tempInt++) free(fileContents[tempInt]); // check for load("A","B") checkStringForLoad(hContact, szNewString); // and loadN(...) checkStringForLoadN(szNewString); // check for compare("A","B","X","Y") checkStringForcompare(szNewString); // check for save("A","B") checkStringForSave(hContact, szNewString); // and saveN(...) checkStringForSaveN(szNewString); return 1; }
INT_PTR ImportContacts(WPARAM, LPARAM) { MCONTACT hContact; char name[256] = "", program[256] = "", programparam[256] = "", group[256] = "", line[2001] = ""; int icon = 40072, usetimer = 0, minutes = 1, timer = 0; char fn[MAX_PATH]; int i, j, contactDone = 0; if (!Openfile(fn, 1)) return 1; FILE *file = fopen(fn, "r"); if (!file) return 1; CMStringA tooltip; while (fgets(line, 2000, file)) { if (!mir_strcmp(line, "\r\n\0")) continue; if (!mir_strcmp(line, "[Non-IM Contact]\r\n")) contactDone = 0; else if (!strncmp(line, "Name=", mir_strlen("Name="))) { i = (int)mir_strlen("Name="); j = 0; while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') { name[j] = line[i++]; name[++j] = '\0'; } contactDone = 1; } else if (!strncmp(line, "ProgramString=", mir_strlen("ProgramString="))) { i = (int)mir_strlen("ProgramString="); j = 0; while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') { program[j] = line[i++]; program[++j] = '\0'; } } else if (!strncmp(line, "ProgramParamString=", mir_strlen("ProgramParamString="))) { i = (int)mir_strlen("ProgramParamString="); j = 0; while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') { programparam[j] = line[i++]; programparam[++j] = '\0'; } } else if (!strncmp(line, "Group=", mir_strlen("Group="))) { i = (int)mir_strlen("Group="); j = 0; while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') { group[j] = line[i++]; group[++j] = '\0'; } } else if (!strncmp(line, "ToolTip=", mir_strlen("ToolTip="))) { i = (int)mir_strlen("ToolTip="); tooltip = &line[i]; fgets(line, 2000, file); while (!strstr(line, "</tooltip>\r\n")) { tooltip.Append(line); fgets(line, 2000, file); } // the line that has the </tooltip> tooltip.Append(line); } else if (!strncmp(line, "Icon=", mir_strlen("Icon="))) { i = (int)mir_strlen("Icon="); sscanf(&line[i], "%d", &icon); } else if (!strncmp(line, "UseTimer=", mir_strlen("UseTimer="))) { i = (int)mir_strlen("UseTimer="); sscanf(&line[i], "%d", &usetimer); } else if (!strncmp(line, "Timer=", mir_strlen("Timer="))) { i = (int)mir_strlen("Timer="); sscanf(&line[i], "%d", &timer); } else if (!strncmp(line, "Minutes=", mir_strlen("Minutes="))) { i = (int)mir_strlen("Minutes="); sscanf(&line[i], "%d", &minutes); } else if (contactDone && !mir_strcmp(line, "[/Non-IM Contact]\r\n")) { if (!name) continue; size_t size = mir_strlen(name) + mir_strlen("Do you want to import this Non-IM Contact?\r\n\r\nName: \r\n") + 1; char *msg = (char*)malloc(size); mir_snprintf(msg, size, "Do you want to import this Non-IM Contact?\r\n\r\nName: %s\r\n", name); if (program[0] != '\0') { msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(program) + mir_strlen("Program: \r\n") + 1); mir_strcat(msg, "Program: "); mir_strcat(msg, program); mir_strcat(msg, "\r\n"); } if (programparam[0] != '\0') { msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(programparam) + mir_strlen("Program Parameters: \r\n") + 1); mir_strcat(msg, "Program Parameters: "); mir_strcat(msg, programparam); mir_strcat(msg, "\r\n"); } if (tooltip) { msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(tooltip) + mir_strlen("ToolTip: \r\n") + 1); mir_strcat(msg, "ToolTip: "); mir_strcat(msg, tooltip); mir_strcat(msg, "\r\n"); } if (group[0] != '\0') { msg = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(group) + mir_strlen("Group: \r\n") + 1); mir_strcat(msg, "Group: "); mir_strcat(msg, group); mir_strcat(msg, "\r\n"); } if (icon) { char tmp[64]; if (icon == ID_STATUS_ONLINE) mir_snprintf(tmp, "Icon: Online\r\n"); else if (icon == ID_STATUS_AWAY) mir_snprintf(tmp, "Icon: Away\r\n"); else if (icon == ID_STATUS_NA) mir_snprintf(tmp, "Icon: NA\r\n"); else if (icon == ID_STATUS_DND) mir_snprintf(tmp, "Icon: DND\r\n"); else if (icon == ID_STATUS_OCCUPIED) mir_snprintf(tmp, "Icon: Occupied\r\n"); else if (icon == ID_STATUS_FREECHAT) mir_snprintf(tmp, "Icon: Free For Chat\r\n"); else if (icon == ID_STATUS_INVISIBLE) mir_snprintf(tmp, "Icon: Invisible\r\n"); else if (icon == ID_STATUS_ONTHEPHONE) mir_snprintf(tmp, "Icon: On The Phone\r\n"); else if (icon == ID_STATUS_OUTTOLUNCH) mir_snprintf(tmp, "Icon: Out To Lunch\r\n"); else { free(msg); continue; } char *msgtemp = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(tmp) + 1); if (msgtemp) { msg = msgtemp; mir_strcat(msg, tmp); } } if (usetimer && timer) { char tmp[64], tmp2[8]; if (minutes) mir_strcpy(tmp2, "Minutes"); else mir_strcpy(tmp2, "Seconds"); mir_snprintf(tmp, "UseTimer: Yes\r\nTimer: %d %s", timer, tmp2); char *msgtemp = (char*)realloc(msg, mir_strlen(msg) + mir_strlen(tmp) + 1); if (msgtemp) { msg = msgtemp; mir_strcat(msg, tmp); } } if (MessageBoxA(0, msg, modFullname, MB_YESNO) == IDYES) { if (!(hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0))) { msg("contact did get created", ""); continue; } Proto_AddToContact(hContact, MODNAME); CallService(MS_IGNORE_IGNORE, hContact, IGNOREEVENT_USERONLINE); db_set_s(hContact, MODNAME, "Nick", Translate("New Non-IM Contact")); db_set_s(hContact, MODNAME, "Name", name); db_set_s(hContact, MODNAME, "ProgramString", program); // copy the ProgramParamString db_set_s(hContact, MODNAME, "ProgramParamString", programparam); // copy the group db_set_s(hContact, "CList", "Group", group); // copy the ToolTip db_set_s(hContact, MODNAME, "ToolTip", tooltip); // timer db_set_b(hContact, MODNAME, "UseTimer", (BYTE)usetimer); db_set_b(hContact, MODNAME, "Minutes", (BYTE)minutes); db_set_w(hContact, MODNAME, "Timer", (WORD)timer); //icon db_set_w(hContact, MODNAME, "Icon", (WORD)icon); replaceAllStrings(hContact); } free(msg); contactDone = 0; name[0] = '\0'; program[0] = '\0'; programparam[0] = '\0'; group[0] = '\0'; line[0] = '\0'; tooltip.Empty(); icon = 40072; usetimer = 0; minutes = 1; timer = 0; } } fclose(file); return 1; }
TemplateMap* TemplateMap::loadTemplateFile(const char *id, const char *filename, bool onlyInfo) { char lastTemplate[1024], tmp2[1024]; unsigned int i = 0; if (filename == NULL || mir_strlen(filename) == 0) return NULL; FILE *fh = fopen(filename, "rt"); if (fh == NULL) return NULL; TemplateMap *tmap; if (!onlyInfo) tmap = TemplateMap::add(id, filename); else tmap = new TemplateMap(id); char store[4096]; bool wasTemplate = false; CMStringA templateText; while (fgets(store, sizeof(store), fh) != NULL) { if (sscanf(store, "%s", tmp2) == EOF) continue; //template start bool bFound = false; for (unsigned i = 0; i < _countof(templateNames); i++) { if (!strncmp(store, templateNames[i].tokenString, templateNames[i].tokenLen)) { bFound = true; break; } } if (bFound) { if (wasTemplate) tmap->addTemplate(lastTemplate, templateText); templateText.Empty(); wasTemplate = true; sscanf(store, "<!--%[^-]", lastTemplate); } else if (wasTemplate) templateText.Append(store); } if (wasTemplate) tmap->addTemplate(lastTemplate, templateText); templateText.Empty(); fclose(fh); static const char *groupTemplates[] = { "MessageInGroupStart", "MessageInGroupInner", "hMessageInGroupStart", "hMessageInGroupInner", "MessageOutGroupStart", "MessageOutGroupInner", "hMessageOutGroupStart", "hMessageOutGroupInner" }; tmap->grouping = true; for (i = 0; i < _countof(groupTemplates); i++) { if (tmap->getTemplate(groupTemplates[i]) == NULL) { tmap->grouping = false; break; } } static const char *rtlTemplates[] = { "MessageInRTL", "MessageOutRTL" }; //"HTMLStartRTL", tmap->rtl = true; for (i = 0; i < _countof(rtlTemplates); i++) { if (tmap->getTemplate(rtlTemplates[i]) == NULL) { tmap->rtl = false; break; } } return tmap; }