void LoadNotificationSettings(POPUPTREEDATA *ptd, char* szModul) { if (ptd->typ == 1) { char setting[2 * MAXMODULELABELLENGTH]; char *szTmp = NULL; mir_snprintf(setting, "{%s/%s}enabled", ptd->notification.lpzGroup, ptd->notification.lpzName); ptd->enabled = (signed char)db_get_b(NULL, szModul, setting, TRUE); mir_snprintf(setting, "{%s/%s}Timeout", ptd->notification.lpzGroup, ptd->notification.lpzName); ptd->notification.iSeconds = (signed char)db_get_w(NULL, szModul, setting, ptd->notification.iSeconds); mir_snprintf(setting, "{%s/%s}TimeoutVal", ptd->notification.lpzGroup, ptd->notification.lpzName); ptd->timeoutValue = (signed char)db_get_w(NULL, szModul, setting, ptd->notification.iSeconds ? ptd->notification.iSeconds : 0); mir_snprintf(setting, "{%s/%s}disableWhen", ptd->notification.lpzGroup, ptd->notification.lpzName); ptd->disableWhen = db_get_b(NULL, szModul, setting, 0); mir_snprintf(setting, "{%s/%s}leftAction", ptd->notification.lpzGroup, ptd->notification.lpzName); szTmp = db_get_s(NULL, szModul, setting, ptd->notification.lpzLAction); mir_strncpy(ptd->leftAction, szTmp, sizeof(ptd->leftAction)); mir_free(szTmp); szTmp = NULL; mir_snprintf(setting, "{%s/%s}rightAction", ptd->notification.lpzGroup, ptd->notification.lpzName); szTmp = db_get_s(NULL, szModul, setting, ptd->notification.lpzRAction); mir_strncpy(ptd->rightAction, szTmp, sizeof(ptd->rightAction)); mir_free(szTmp); szTmp = NULL; } }
int FontService_RegisterFont(const char *pszDbModule, const char *pszDbName, const TCHAR *pszSection, const TCHAR *pszDescription, const TCHAR* pszBackgroundGroup, const TCHAR* pszBackgroundName, int position, BOOL bAllowEffects, LOGFONT *plfDefault, COLORREF clrDefault) { FontIDT fid; memset(&fid, 0, sizeof(fid)); fid.cbSize=sizeof(fid); mir_strncpy(fid.dbSettingsGroup,pszDbModule,sizeof(fid.dbSettingsGroup)); /* buffer safe */ mir_strncpy(fid.prefix,pszDbName,sizeof(fid.prefix)); /* buffer safe */ mir_tstrncpy(fid.group,pszSection,SIZEOF(fid.group)); /* buffer safe */ mir_tstrncpy(fid.name,pszDescription,SIZEOF(fid.name)); /* buffer safe */ mir_tstrncpy(fid.backgroundGroup, pszBackgroundGroup, SIZEOF(fid.backgroundGroup)); /* buffer safe */ mir_tstrncpy(fid.backgroundName, pszBackgroundName, SIZEOF(fid.backgroundName)); /* buffer safe */ fid.flags = FIDF_ALLOWREREGISTER; if(bAllowEffects) fid.flags|=FIDF_ALLOWEFFECTS; fid.order=position; if(plfDefault!=NULL) { fid.flags|=FIDF_DEFAULTVALID; fid.deffontsettings.colour=clrDefault; fid.deffontsettings.size=(char)plfDefault->lfHeight; if(plfDefault->lfItalic) fid.deffontsettings.style|=DBFONTF_ITALIC; if(plfDefault->lfWeight!=FW_NORMAL) fid.deffontsettings.style|=DBFONTF_BOLD; if(plfDefault->lfUnderline) fid.deffontsettings.style|=DBFONTF_UNDERLINE; if(plfDefault->lfStrikeOut) fid.deffontsettings.style|=DBFONTF_STRIKEOUT; fid.deffontsettings.charset=plfDefault->lfCharSet; mir_tstrncpy(fid.deffontsettings.szFace,plfDefault->lfFaceName,SIZEOF(fid.deffontsettings.szFace)); /* buffer safe */ } FontRegisterT(&fid); return 0; }
void ItemFound(HWND hwnd, HANDLE hContact,const char *module,const char *setting,const char* value,int type) { ItemInfo *ii = (ItemInfo*)mir_calloc(sizeof(ItemInfo)); int index; char text[256] = ""; int result = 0; char szValue[256]; char *name, *mode; if (!ii) return; if (type & FW_REPLACED) mode = Translate("Replaced with"); else if (type & FW_DELETED) mode = Translate("Deleted"); else mode = Translate("Found"); name = hContact?(char*)GetContactName(hContact,NULL,0):Translate("Settings"); switch (type & 0xFF) { case FW_MODULE: ii->type = FW_MODULE; mir_snprintf(text, SIZEOF(text), Translate("%s Module \"%s\" in contact \"%s\""), mode, module, name); break; case FW_SETTINGNAME: mir_strncpy(ii->setting,setting,256); ii->type = FW_SETTINGNAME; if (GetValue(hContact,module,setting, szValue, SIZEOF(szValue))) mir_snprintf(text, SIZEOF(text), Translate("%s Setting \"%s\" in module \"%s\" in contact \"%s\" - \"%s\""), mode, setting, module, name, szValue); else mir_snprintf(text, SIZEOF(text), Translate("%s Setting \"%s\" in module \"%s\" in contact \"%s\""), mode, setting, module, name); break; case FW_SETTINGVALUE: mir_strncpy(ii->setting,setting,256); ii->type = FW_SETTINGVALUE; mir_snprintf(text, SIZEOF(text), Translate("%s \"%s\" in Setting \"%s\" in module \"%s\" in contact \"%s\""), mode, value, setting, module, name); break; } index = SendMessage(hwnd,LB_ADDSTRING,0,(LPARAM)text); if (type & FW_DELETED) { SendMessage(hwnd,LB_SETITEMDATA,index,0); mir_free(ii); } else { ii->hContact= hContact; mir_strncpy(ii->module,module,256); SendMessage(hwnd,LB_SETITEMDATA,index,(LPARAM)ii); } }
static int IcqOpenFile(WPARAM wParam, LPARAM lParam) { TCHAR *pszFile = (TCHAR*)lParam; /* TCHAR is specified on AssocMgr_AddNewFileTypeT() */ FILE *fp; ICQFILEINFO info; char line[4096], *sep; UNREFERENCED_PARAMETER(wParam); /* send message: [ICQ Message User] UIN=1234567 add user: (all the .uin files I've seen only have UIN= in them) [ICQ User] UIN=1234567 Email= NickName= FirstName= LastName= */ if (pszFile == NULL) return 1; /* sanity check */ fp = _tfopen(pszFile, _T("rt")); if (fp == NULL) return 1; /* open failed */ info.type = 0; while (!feof(fp)) { if (fgets(line, sizeof(line), fp) == NULL) break; TrimString(line); if (IsEmpty(line)) continue; if (line[0] == '[') { memset(&info, 0, sizeof(info)); if (!mir_strcmpi(line, "[ICQ Message User]")) info.type = ICQFILE_MESSAGEUSER; else if (!mir_strcmpi(line, "[ICQ User]")) info.type = ICQFILE_ADDUSER; continue; } if (info.type == 0) continue; sep = strchr(line, '='); if (sep == NULL) { info.type = 0; break; } /* format error */ *(sep++) = '\0'; if (!mir_strcmp("UIN", line)) mir_strncpy(info.uin, sep, sizeof(info.uin)); /* buffer safe */ else if (!mir_strcmp("Email", line)) mir_strncpy(info.email, sep, sizeof(info.email)); /* buffer safe */ else if (!mir_strcmp("NickName", line)) mir_strncpy(info.nick, sep, sizeof(info.nick)); /* buffer safe */ else if (!mir_strcmp("FirstName", line)) mir_strncpy(info.firstName, sep, sizeof(info.firstName)); /* buffer safe */ else if (!mir_strcmp("LastName", line)) mir_strncpy(info.lastName, sep, sizeof(info.lastName)); /* buffer safe */ } fclose(fp); switch (info.type) { case ICQFILE_MESSAGEUSER: MessageIcqUser(&info); return 0; case ICQFILE_ADDUSER: AddIcqUser(&info); return 0; default: return 1; /* open failed */ } }
/** * name: DisplayNameToFileName * desc: convert contact's display name to valid filename * param: hContact - handle of contact to create the filename for * pszFileName - buffer, retrieving the converted filename * cchFileName - number of maximum characters the filename can be * return: nothing **/ static void DisplayNameToFileName(lpExImParam ExImContact, LPSTR pszFileName, WORD cchFileName) { LPCSTR disp = 0; LPSTR temp = 0; cchFileName--; pszFileName[0] = 0; switch (ExImContact->Typ) { case EXIM_ALL: case EXIM_GROUP: mir_strncpy(pszFileName, Translate("all Contacts"), cchFileName); return; case EXIM_CONTACT: if (ExImContact->hContact == NULL) { mir_strncpy(pszFileName, Translate("Owner"), cchFileName); return; } disp = temp = mir_t2a(pcli->pfnGetContactDisplayName(ExImContact->hContact, NULL)); break; case EXIM_SUBGROUP: temp = mir_t2a(ExImContact->ptszName); disp = temp; break; case EXIM_ACCOUNT: PROTOACCOUNT* acc = Proto_GetAccount(ExImContact->pszName); disp = temp = mir_t2a(acc->tszAccountName); break; } // replace unwanted characters while (*disp != 0 && cchFileName > 1) { switch (*disp) { case '?': case '*': case ':': case '\\': case '|': case '/': case '<': case '>': case '"': *(pszFileName++) = '_'; break; default: *(pszFileName++) = *disp; break; } disp++; cchFileName--; } mir_free(temp); pszFileName[0] = 0; }
int FontService_RegisterColor(const char *pszDbModule,const char *pszDbName,const TCHAR *pszSection,const TCHAR *pszDescription,COLORREF clrDefault) { ColourIDT cid; memset(&cid, 0, sizeof(cid)); cid.cbSize=sizeof(cid); cid.defcolour=clrDefault; mir_strncpy(cid.dbSettingsGroup,pszDbModule,sizeof(cid.dbSettingsGroup)); /* buffer safe */ mir_strncpy(cid.setting,pszDbName,sizeof(cid.setting)); /* buffer safe */ mir_tstrncpy(cid.group,pszSection,SIZEOF(cid.group)); /* buffer safe */ mir_tstrncpy(cid.name,pszDescription,SIZEOF(cid.name)); /* buffer safe */ ColourRegisterT(&cid); return 0; }
/** * name: DisplayNameToFileName * desc: convert contact's display name to valid filename * param: hContact - handle of contact to create the filename for * pszFileName - buffer, retrieving the converted filename * cchFileName - number of maximum characters the filename can be * return: nothing **/ static void DisplayNameToFileName(lpExImParam ExImContact, LPSTR pszFileName, WORD cchFileName) { LPCSTR disp = 0; LPSTR temp = 0; cchFileName--; ZeroMemory(pszFileName, cchFileName); switch (ExImContact->Typ) { case EXIM_ALL: case EXIM_GROUP: mir_strncpy(pszFileName, Translate("all Contacts"), cchFileName); return; case EXIM_CONTACT: if (ExImContact->hContact == NULL) { mir_strncpy(pszFileName, Translate("Owner"), cchFileName); return; } else { disp = (LPCSTR)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ExImContact->hContact, NULL); } break; case EXIM_SUBGROUP: temp = mir_t2a(ExImContact->ptszName); disp = temp; break; case EXIM_ACCOUNT: PROTOACCOUNT* acc = ProtoGetAccount(ExImContact->pszName); temp = mir_t2a(acc->tszAccountName); disp = temp; break; } // replace unwanted characters while (*disp != 0 && cchFileName > 1) { switch (*disp) { case '?': case '*': case ':': case '\\': case '|': case '/': case '<': case '>': case '"': *(pszFileName++) = '_'; break; default: *(pszFileName++) = *disp; break; } disp++; cchFileName--; } mir_free(temp); }
/** * name: DBWriteAnniversaries * class: CAnnivEditCtrl * desc: write all anniversaries to the database * param: hContact - the contact to write the anniversaries to * return: 0 on success 1 otherwise **/ INT_PTR CAnnivEditCtrl::DBWriteAnniversaries(MCONTACT hContact) { const LPCSTR szPrefix[] = { "Reminder", "Offset", "Desc", "Day", "Month", "Year", "Stamp", "Date" }; CHAR szSet0[MAXSETTING]; WORD i, ret, ofs, wIndex = 0; for (i = 0; i < _numDates; i++) { if ( _pDates[i] != NULL && !_pDates[i]->DBWriteAnniversaryDate(hContact, wIndex) && !_pDates[i]->DBWriteReminderOpts(hContact) ) { wIndex++; } } // delete reluctant items do { ofs = mir_snprintf(szSet0, _countof(szSet0), "Anniv%d", wIndex); ret = 1; for (i = 0; i < _countof(szPrefix); i++) { mir_strncpy(szSet0 + ofs, szPrefix[i], _countof(szSet0) - ofs); ret &= db_unset(hContact, USERINFO, szSet0); } } while (wIndex++ <= ANID_LAST && !ret); return 0; }
/** * Hotkeys initialiation */ void FacebookProto::InitHotkeys() { char text[200]; mir_strncpy(text, m_szModuleName, 100); char *tDest = text + mir_strlen(text); HOTKEYDESC hkd = { sizeof(hkd) }; hkd.pszName = text; hkd.pszService = text; hkd.ptszSection = m_tszUserName; hkd.dwFlags = HKD_TCHAR; mir_strcpy(tDest, "/VisitProfile"); hkd.ptszDescription = LPGENT("Visit profile"); Hotkey_Register(&hkd); mir_strcpy(tDest, "/VisitNotifications"); hkd.ptszDescription = LPGENT("Visit notifications"); Hotkey_Register(&hkd); mir_strcpy(tDest, "/Mind"); hkd.ptszDescription = LPGENT("Show 'Share status' window"); hkd.DefHotKey = HOTKEYCODE(HOTKEYF_ALT | HOTKEYF_EXT, 'F'); Hotkey_Register(&hkd); }
// do lastchecked(file(X)) returns amount of chars to add to str pointer int lastChecked(CMStringA &szNewStr, const char *str) { char *szPattern = "lastchecked(file("; size_t cbPattern = mir_strlen(szPattern); if (!strncmp(str, szPattern, cbPattern)) { int file; char tszFileName[MAX_PATH], temp[MAX_PATH], szSetting[20]; sscanf(&str[cbPattern], "%d", &file); mir_snprintf(szSetting, "fn%d", file); char *szVar = db_get_sa(NULL, MODNAME, szSetting); if (szVar == NULL) return 0; if (!strncmp("http://", szVar, 7) || !strncmp("https://", szVar, 8)) mir_snprintf(tszFileName, _countof(tszFileName), "%s\\plugins\\fn%d.html", getMimDir(temp), file); else mir_strncpy(tszFileName, szVar, _countof(tszFileName)); mir_free(szVar); HANDLE hFile = CreateFileA(tszFileName, 0, FILE_SHARE_READ, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) return 0; if (GetLastWriteTime(hFile, tszFileName)) { CloseHandle(hFile); szNewStr.Append(tszFileName); mir_snprintf(tszFileName, _countof(tszFileName), "%s%d))", szPattern, file); return (int)mir_strlen(tszFileName); } CloseHandle(hFile); } return 0; }
int readFileIntoArray(int fileNumber, char *FileContents[]) { char dbSetting[20], temp[MAX_STRING_LENGTH]; mir_snprintf(dbSetting, _countof(dbSetting), "fn%d", fileNumber); char *szVar = db_get_sa(NULL, MODNAME, dbSetting); if (szVar == NULL) return 0; char tszFileName[MAX_PATH]; if (!strncmp("http://", szVar, 7) || !strncmp("https://", szVar, 7)) mir_snprintf(tszFileName, _countof(tszFileName), "%s\\plugins\\fn%d.html", getMimDir(temp), fileNumber); else mir_strncpy(tszFileName, szVar, _countof(tszFileName)); mir_free(szVar); FILE* file = fopen(tszFileName, "r"); if (file == NULL) return 0; // read the file into the FileContents array // free this array before stringReplacer() returns int i; for (i = 0; fgets(temp, MAX_STRING_LENGTH - 1, file); i++) { if (temp[mir_strlen(temp) - 1] == '\n') temp[mir_strlen(temp) - 1] = '\0'; else temp[mir_strlen(temp)] = '\0'; FileContents[i] = (char*)malloc(mir_strlen(temp) + 1); if (FileContents[i] == NULL) break; mir_strcpy(FileContents[i], temp); } fclose(file); return i; }
Protocol::Protocol(const char *aName, const TCHAR *descr) { mir_strncpy(name, aName, _countof(name)); mir_tstrncpy(description, descr, _countof(description)); data_changed = true; // Load services int caps = CallProtoService(name, PS_GETCAPS, PFLAGNUM_1, 0); if (caps & PF1_IM) valid = true; else return; can_have_listening_to = (ProtoServiceExists(name, PS_SET_LISTENINGTO) != 0); PF3 = CallProtoService(name, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0); caps = CallProtoService(name, PS_GETCAPS, PFLAGNUM_4, 0); can_have_avatar = (caps & PF4_AVATARS) != 0; can_set_nick = ProtoServiceExists(name, PS_SETMYNICKNAME) != FALSE; // Initial value GetStatus(); GetStatusMsg(); GetNick(); GetAvatar(); }
// function to download webpage from the internet // szUrl = URL of the webpage to be retrieved // return value = 0 for success, 1 or HTTP error code for failure // global var used: szData, szInfo = containing the retrieved data int InternetDownloadFile (char *szUrl) { NETLIBHTTPREQUEST nlhr={0}; // initialize the netlib request nlhr.cbSize=sizeof(nlhr); nlhr.requestType=REQUEST_GET; nlhr.flags=NLHRF_DUMPASTEXT; nlhr.szUrl= szUrl; // change the header so the plugin is pretended to be IE 6 + WinXP nlhr.headersCount++; nlhr.headers=(NETLIBHTTPHEADER*)malloc(sizeof(NETLIBHTTPHEADER)*nlhr.headersCount); memcpy(nlhr.headers,nlhr.headers,sizeof(NETLIBHTTPHEADER)*nlhr.headersCount); nlhr.headers[nlhr.headersCount-1].szName="User-Agent"; nlhr.headers[nlhr.headersCount-1].szValue="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; // download the page NETLIBHTTPREQUEST *nlhrReply=(NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION,(WPARAM)hNetlibUser,(LPARAM)&nlhr); if (nlhrReply) { // return error code if the recieved code is neither 200 OK or 302 Moved if (nlhrReply->resultCode != 200 && nlhrReply->resultCode != 302) return nlhrReply->resultCode; // if the recieved code is 200 OK else if (nlhrReply->resultCode == 200) { // allocate memory and save the retrieved data szData = (char *)malloc(mir_strlen(nlhrReply->pData)+2); mir_strncpy(szData, nlhrReply->pData, mir_strlen(nlhrReply->pData)); } // if the recieved code is 302 Moved, Found, etc else if (nlhrReply->resultCode == 302) { // page moved int i; // get the url for the new location and save it to szInfo // look for the reply header "Location" for (i=0; i<nlhrReply->headersCount; i++) { if (!mir_strcmp(nlhrReply->headers[i].szName, "Location")) { szData = (char *)malloc(512); // add "Moved/Location:" in front of the new URL for identification mir_snprintf(szData, 512, "Moved/Location: %s\n", nlhrReply->headers[i].szValue); break; } } // log the new url into netlib log CallService(MS_NETLIB_LOG,(WPARAM)hNetlibUser,(LPARAM)szData); } } // if the data does not downloaded successfully (ie. disconnected), then return 1 as error code else return 1; // make a copy of the retrieved data, then free the memory of the http reply szInfo = szData; CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)nlhrReply); // the recieved data is empty, data was not recieved, so return an error code of 1 if (!mir_strcmp(szInfo, "")) return 1; return 0; }
INT_PTR NewsAggrGetName(WPARAM wParam, LPARAM lParam) { if(lParam) { mir_strncpy((char *)lParam, MODULE, wParam); return 0; } return 1; }
void ShowNotification(const char *caption, const char *message, int flags, MCONTACT hContact) { if (Miranda_Terminated()) return; if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) { POPUPDATA ppd = { 0 }; ppd.lchContact = hContact; mir_strncpy(ppd.lpzContactName, caption, MAX_CONTACTNAME); mir_strncpy(ppd.lpzText, message, MAX_SECONDLINE); if (!PUAddPopup(&ppd)) return; } ::MessageBoxA(NULL, message, caption, MB_OK | flags); }
INT_PTR CDropbox::ProtoGetName(WPARAM wParam, LPARAM lParam) { if (lParam) { mir_strncpy((char *)lParam, MODULE, wParam); return 0; } return 1; }
HANDLE RegisterNotification(POPUPNOTIFICATION *notification) { POPUPTREEDATA *ptd = (POPUPTREEDATA *)mir_alloc(sizeof(POPUPTREEDATA)); ptd->signature = PopupNotificationData_SIGNATURE; ptd->typ = 1; ptd->pszTreeRoot = mir_a2t(notification->lpzGroup); ptd->pszDescription = mir_a2t(notification->lpzName); ptd->notification = *notification; if (!ptd->notification.lpzLAction) ptd->notification.lpzLAction = POPUP_ACTION_NOTHING; if (!ptd->notification.lpzRAction) ptd->notification.lpzRAction = POPUP_ACTION_DISMISS; LoadNotificationSettings(ptd, "PopupNotifications"); // ugly hack to make reset always possible SaveNotificationSettings(ptd, "PopupNotifications"); FontID fontid = { 0 }; fontid.cbSize = sizeof(fontid); mir_snprintf(fontid.group, SIZEOF(fontid.group), PU_FNT_AND_COLOR"/%s", notification->lpzGroup); mir_strcpy(fontid.dbSettingsGroup, "PopupNotifications"); fontid.flags = FIDF_DEFAULTVALID; fontid.deffontsettings.charset = DEFAULT_CHARSET; fontid.deffontsettings.colour = ptd->notification.colorText; fontid.deffontsettings.size = -11; mir_strncpy(fontid.deffontsettings.szFace, "MS Shell Dlg", SIZEOF(fontid.deffontsettings.szFace)); fontid.deffontsettings.style = 0; mir_snprintf(fontid.name, SIZEOF(fontid.name), "%s (colors only)", notification->lpzName); mir_snprintf(fontid.prefix, SIZEOF(fontid.prefix), "{%s/%s}text", notification->lpzGroup, notification->lpzName); fontid.deffontsettings.style = 0; FontRegister(&fontid); ColourID colourid = { 0 }; colourid.cbSize = sizeof(colourid); mir_snprintf(colourid.group, SIZEOF(colourid.group), PU_FNT_AND_COLOR"/%s", notification->lpzGroup); mir_strcpy(colourid.dbSettingsGroup, "PopupNotifications"); mir_snprintf(colourid.name, SIZEOF(colourid.name), "%s (colors only)", notification->lpzName); mir_snprintf(colourid.setting, SIZEOF(colourid.setting), "{%s/%s}backColor", notification->lpzGroup, notification->lpzName); colourid.defcolour = ptd->notification.colorBack; ColourRegister(&colourid); char section[MAXMODULELABELLENGTH], setting[MAXMODULELABELLENGTH]; mir_snprintf(section, SIZEOF(section), "Popups/%s", notification->lpzGroup); mir_snprintf(setting, SIZEOF(setting), MODULNAME"_%s_%s", notification->lpzGroup, notification->lpzName); SKINICONDESC sid = { sizeof(sid) }; sid.pszSection = section; sid.cx = sid.cy = 16; sid.pszName = setting; sid.pszDescription = notification->lpzName; sid.hDefaultIcon = notification->lchIcon; Skin_AddIcon(&sid); gTreeData.insert(ptd); return (HANDLE)ptd; }
void LoadOptions() { options.default_policy = db_get_w(0, MODULENAME, "DefaultPolicy", OTRL_POLICY_OPPORTUNISTIC); // deal with changed flags in proto.h and new interpretation of 'manual' mode (see common.h) switch(options.default_policy) { case OTRL_POLICY_MANUAL: options.default_policy = OTRL_POLICY_MANUAL_MOD; break; case OTRL_POLICY_OPPORTUNISTIC: case OTRL_POLICY_MANUAL_MOD: case OTRL_POLICY_ALWAYS: case OTRL_POLICY_NEVER: break; default: options.default_policy = OTRL_POLICY_OPPORTUNISTIC; break; } options.err_method = (ErrorDisplay)db_get_w(0, MODULENAME, "ErrorDisplay", ED_POP); options.prefix_messages = (db_get_b(0, MODULENAME, "PrefixMessages", 0) == 1); options.msg_inline = (db_get_b(0, MODULENAME, "MsgInline", 0) == 1); options.msg_popup = (db_get_b(0, MODULENAME, "MsgPopup", 1) == 1); options.delete_history = (db_get_b(0, MODULENAME, "NoHistory", 0) == 1); options.delete_systeminfo = (db_get_b(0, MODULENAME, "NoSystemHistory", 0) == 1); options.autoshow_verify = (db_get_b(0, MODULENAME, "AutoShowVerify", 1) == 1); DBVARIANT dbv; if (!db_get_utf(0, MODULENAME, "Prefix", &dbv)) { mir_strncpy(options.prefix, dbv.pszVal, OPTIONS_PREFIXLEN); db_free(&dbv); } else mir_strncpy(options.prefix, OPTIONS_DEFAULT_PREFIX, OPTIONS_PREFIXLEN); options.end_offline = (db_get_b(0, MODULENAME, "EndOffline", 1) == 1); options.end_window_close = (db_get_b(0, MODULENAME, "EndWindowClose", 0) == 1); options.bHavePopups = 0 != ServiceExists(MS_POPUP_ADDPOPUPT) && ServiceExists(MS_POPUP_SHOWMESSAGE); options.bHaveSecureIM = 0 != ServiceExists("SecureIM/IsContactSecured"); options.bHaveButtonsBar = 0 != ServiceExists(MS_BB_ADDBUTTON); LoadFilenames(); }
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; }
int ParsePage(char *page, resultLink *prst) { char *str_head; char *str_tail; char name[64], title[64]; int num = 0; wchar_t str[64]; prst->next = NULL; if (strstr(page, "Unauthorized")) return -1; if (!(str_head = strstr(page, "<entry>"))) return 0; while (str_head = strstr(str_head, "<title>")) { prst = prst->next = (resultLink *)malloc(sizeof(resultLink)); str_head += 7; str_tail = strstr(str_head, "</title>"); *str_tail = '\0'; mir_strncpy(title, str_head, 41); if (mir_strlen(title) == 40) mir_strcat(title, "..."); *str_tail = ' '; str_head = strstr(str_head, "<name>") + 6; str_tail = strstr(str_head, "</name>"); *str_tail = '\0'; mir_strncpy(name, str_head, 11); mir_strcat(name, ": "); *str_tail = ' '; mir_strcpy(prst->content, name); mir_strcat(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; return num; }
// interface void LoadNotifications() { POPUPNOTIFICATION notification = { 0 }; notification.cbSize = sizeof(notification); notification.actionCount = 0; notification.lpActions = 0; mir_strncpy(notification.lpzGroup, "Misc", sizeof(notification.lpzName)); mir_strncpy(notification.lpzName, "Warning", sizeof(notification.lpzName)); notification.lchIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MB_WARN), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR | LR_SHARED); notification.colorBack = RGB(210, 210, 150); notification.colorText = RGB(0, 0, 0); notification.iSeconds = 10; g_hntfWarning = RegisterNotification(¬ification); mir_strncpy(notification.lpzGroup, "Misc", sizeof(notification.lpzName)); mir_strncpy(notification.lpzName, "Notification", sizeof(notification.lpzName)); notification.lchIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MB_INFO), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR | LR_SHARED); notification.colorBack = RGB(230, 230, 230); notification.colorText = RGB(0, 0, 0); notification.iSeconds = 7; g_hntfNotification = RegisterNotification(¬ification); mir_strncpy(notification.lpzGroup, "Misc", sizeof(notification.lpzName)); mir_strncpy(notification.lpzName, "Error", sizeof(notification.lpzName)); notification.lchIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_MB_STOP), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR | LR_SHARED); notification.colorBack = RGB(191, 0, 0); notification.colorText = RGB(255, 245, 225); notification.iSeconds = -1; g_hntfError = RegisterNotification(¬ification); }
// interface void LoadNotifications() { POPUPNOTIFICATION notification = { 0 }; notification.cbSize = sizeof(notification); notification.actionCount = 0; notification.lpActions = 0; mir_strncpy(notification.lpzGroup, "Misc", sizeof(notification.lpzName)); mir_strncpy(notification.lpzName, "Warning", sizeof(notification.lpzName)); notification.lchIcoLib = GetIconHandle(IDI_MB_WARN); notification.colorBack = RGB(210, 210, 150); notification.colorText = RGB(0, 0, 0); notification.iSeconds = 10; g_hntfWarning = RegisterNotification(¬ification); mir_strncpy(notification.lpzGroup, "Misc", sizeof(notification.lpzName)); mir_strncpy(notification.lpzName, "Notification", sizeof(notification.lpzName)); notification.lchIcoLib = GetIconHandle(IDI_MB_INFO); notification.colorBack = RGB(230, 230, 230); notification.colorText = RGB(0, 0, 0); notification.iSeconds = 7; g_hntfNotification = RegisterNotification(¬ification); mir_strncpy(notification.lpzGroup, "Misc", sizeof(notification.lpzName)); mir_strncpy(notification.lpzName, "Error", sizeof(notification.lpzName)); notification.lchIcoLib = GetIconHandle(IDI_MB_STOP); notification.colorBack = RGB(191, 0, 0); notification.colorText = RGB(255, 245, 225); notification.iSeconds = -1; g_hntfError = RegisterNotification(¬ification); }
int IsResidentSetting(const char *module, const char *setting) { if (!m_lResidentSettings.getCount()) return 0; if (m_lResidentModules.getIndex((char*)module) == -1) return 0; if (!setting) return 1; char str[2*FLD_SIZE]; mir_strncpy(str, module, _countof(str)-1); mir_strcat(str, "/"); mir_strncat(str, setting, _countof(str)); return m_lResidentSettings.getIndex(str) != -1; }
int enumResidentProc(const char *setting, DWORD, LPARAM) { m_lResidentSettings.insert(mir_strdup(setting)); char str[FLD_SIZE]; const char *end = strstr(setting, "/"); if (end && (end - setting) < _countof(str)) { mir_strncpy(str, setting, end - setting + 1); if (m_lResidentModules.getIndex(str) == -1) m_lResidentModules.insert(mir_strdup(str)); } return 0; }
/** * name: ParentItemName() * class: CPsTreeItem * desc: returns the unique name for the parent item * param: nothing * return: length of group name **/ LPSTR CPsTreeItem::ParentItemName() { // try to read the parent item from the database DBVARIANT dbv; if (!DB::Setting::GetAString(NULL, MODNAME, PropertyKey(SET_ITEM_GROUP), &dbv)) return dbv.pszVal; const CHAR* p = mir_strrchr(_pszName, '\\'); if (p) { int cchGroup = p - _pszName + 1; return mir_strncpy((LPSTR)mir_alloc(cchGroup), _pszName, cchGroup); } return NULL; }
int ModeChange(WPARAM, LPARAM lparam) { ACKDATA *ack = (ACKDATA *)lparam; if (ack->type != ACKTYPE_STATUS || ack->result != ACKRESULT_SUCCESS || ack->hContact != NULL) return 0; courProtoName = (char *)ack->szModule; if (!IsWatchedProtocol(courProtoName) && strncmp(courProtoName, "MetaContacts", 12)) return 0; DBWriteTimeTS(time(NULL), NULL); // isetting=CallProtoService(ack->szModule,PS_GETSTATUS,0,0); WORD isetting = (WORD)ack->lParam; if (isetting < ID_STATUS_OFFLINE) isetting = ID_STATUS_OFFLINE; if ((isetting > ID_STATUS_OFFLINE) && ((WORD)ack->hProcess <= ID_STATUS_OFFLINE)) { //we have just loged-in db_set_dw(NULL, "UserOnline", ack->szModule, GetTickCount()); if (!Miranda_Terminated() && IsWatchedProtocol(ack->szModule)) { logthread_info *info = (logthread_info *)mir_alloc(sizeof(logthread_info)); mir_strncpy(info->sProtoName, courProtoName, _countof(info->sProtoName)); info->hContact = 0; info->currStatus = 0; mir_forkthread(cleanThread, info); } } else if ((isetting == ID_STATUS_OFFLINE) && ((WORD)ack->hProcess > ID_STATUS_OFFLINE)) { //we have just loged-off if (IsWatchedProtocol(ack->szModule)) { char str[MAXMODULELABELLENGTH + 9]; time_t t; time(&t); mir_snprintf(str, "OffTime-%s", ack->szModule); db_set_dw(NULL, S_MOD, str, t); } } if (isetting == db_get_w(NULL, S_MOD, courProtoName, ID_STATUS_OFFLINE)) return 0; db_set_w(NULL, S_MOD, courProtoName, isetting); if (g_bFileActive) FileWrite(NULL); courProtoName = NULL; return 0; }
void import_ping_address(int index, PINGADDRESS &pa) { DBVARIANT dbv; char buf[256]; mir_snprintf(buf, "Address%d", index); if (!db_get_ts(0, "PingPlug", buf, &dbv)) { mir_tstrncpy(pa.pszName, dbv.ptszVal, _countof(pa.pszName)); db_free(&dbv); } else mir_tstrncpy(pa.pszName, TranslateT("Unknown Address"), _countof(pa.pszName)); mir_snprintf(buf, "Label%d", index); if (!db_get_ts(0, "PingPlug", buf, &dbv)) { mir_tstrncpy(pa.pszLabel, dbv.ptszVal, _countof(pa.pszLabel)); db_free(&dbv); } else mir_tstrncpy(pa.pszLabel, TranslateT("Unknown"), _countof(pa.pszLabel)); mir_snprintf(buf, "Port%d", index); pa.port = (int)db_get_dw(0, "PingPlug", buf, -1); mir_snprintf(buf, "Proto%d", index); if (!db_get_s(0, "PingPlug", buf, &dbv)) { mir_strncpy(pa.pszProto, dbv.pszVal, _countof(pa.pszProto)); db_free(&dbv); mir_snprintf(buf, "Status%d", index); pa.set_status = db_get_w(0, "PingPlug", buf, ID_STATUS_ONLINE); mir_snprintf(buf, "Status2%d", index); pa.get_status = db_get_w(0, "PingPlug", buf, ID_STATUS_OFFLINE); } else pa.pszProto[0] = '\0'; pa.responding = false; pa.round_trip_time = 0; pa.miss_count = 0; pa.index = index; pa.pszCommand[0] = '\0'; pa.pszParams[0] = '\0'; pa.item_id = 0; mir_snprintf(buf, "Enabled%d", index); if (db_get_b(0, "PingPlug", buf, 1) == 1) pa.status = PS_NOTRESPONDING; else pa.status = PS_DISABLED; }
INT_PTR ServiceGetTypeDescription(WPARAM wParam, LPARAM lParam) { /* shutdownType range check */ if (!wParam || (BYTE)wParam > SDSDT_MAX) return 0; /* select description */ TCHAR *pszDesc = (TCHAR*)((lParam&GSTDF_LONGDESC) ? apszLong : apszShort)[wParam - 1]; if (!(lParam&GSTDF_UNTRANSLATED)) pszDesc = TranslateTS(pszDesc); /* convert as needed */ if (!(lParam&GSTDF_UNICODE)) { static char szConvBuf[128]; char *buf = u2a(pszDesc); if (buf == NULL) return 0; mir_strncpy(szConvBuf, buf, sizeof(szConvBuf)); mir_free(buf); return (INT_PTR)szConvBuf; } return (INT_PTR)pszDesc; }
static HICON ExtractIconFromPath(const char *path, BOOL * needFree) { char *comma; char file[MAX_PATH],fileFull[MAX_PATH]; int n; HICON hIcon; mir_strncpy(file,path,sizeof(file)); comma=strrchr(file,','); if (comma == NULL) n=0; else {n=atoi(comma+1); *comma=0;} PathToAbsolute(file, fileFull); hIcon=NULL; ExtractIconExA(fileFull,n,NULL,&hIcon,1); if (needFree) *needFree=(hIcon != NULL); return hIcon; }
static INT_PTR GoToURLMsgCommand(WPARAM wParam, LPARAM lParam) { ptrA szMsg(db_get_sa(wParam, "CList", "StatusMsg")); char *szURL = StrFindURL(szMsg); if (szURL != NULL) { int i; for (i = 0; szURL[i] != ' ' && szURL[i] != '\n' && szURL[i] != '\r' && szURL[i] != '\t' && szURL[i] != '\0'; i++); char *szMsgURL = (char *)mir_alloc(i + 1); if (szMsgURL) { mir_strncpy(szMsgURL, szURL, i + 1); Utils_OpenUrl(szMsgURL); mir_free(szMsgURL); } } return 0; }