HANDLE CSametimeProto::AcceptFileTransfer(MCONTACT hContact, HANDLE hFt, char* save_path) { mwFileTransfer* ft = (mwFileTransfer*)hFt; CSametimeProto* proto = getProtoFromMwFileTransfer(ft); debugLog(_T("CSametimeProto::AcceptFileTransfer() start")); FileTransferClientData* ftcd = new FileTransferClientData; memset((void*)ftcd, 0, sizeof(FileTransferClientData)); ftcd->ft = ft; ftcd->sending = false; ftcd->hFt = hFt; if (save_path) // save path ftcd->save_path = _strdup(save_path); else ftcd->save_path = 0; mwFileTransfer_setClientData(ft, (gpointer)ftcd, 0); char fp[MAX_PATH]; char* fn = strrchr((char*)mwFileTransfer_getFileName(ft), '\\'); if (fn) fn++; if (ftcd->save_path) mir_strcpy(fp, ftcd->save_path); else fp[0] = 0; if (fn) mir_strcat(fp, fn); else mir_strcat(fp, mwFileTransfer_getFileName(ft)); ftcd->hFile = CreateFileA(fp, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0); if (ftcd->hFile == INVALID_HANDLE_VALUE) { debugLog(_T("CSametimeProto::AcceptFileTransfer() INVALID_HANDLE_VALUE")); mwFileTransfer_close(ft, mwFileTransfer_ERROR); return 0; } ftcd->hContact = hContact; mwFileTransfer_setClientData(ft, (gpointer)ftcd, 0); mwFileTransfer_accept(ft); return hFt; }
void HexToBin(char *inData, ULONG &size, LPBYTE &outData) { char buffer[32] = {0}; mir_strcpy(buffer, "0x"); strncpy(buffer + 2, inData, HEX_SIZE); sscanf(buffer, "%x", &size); outData = (unsigned char*)new char[size*2]; UINT i; //size = i; char *tmp = inData + HEX_SIZE; buffer[4] = '\0'; //mark the end of the string for (i = 0; i < size; i++) { strncpy(buffer + 2, &tmp[i * 2], 2); sscanf(buffer, "%hhx", &outData[i]); } i = size; }
static void DeleteRegTreeBackup(const char *pszSubKey,const char *pszDbPrefix) { char **ppszSettings; int nSettingsCount,i; char *pszPrefixWithSubKey=(char*)mir_alloc(mir_strlen(pszDbPrefix)+mir_strlen(pszSubKey)+2); if (pszPrefixWithSubKey==NULL) return; mir_strcat(mir_strcat(mir_strcpy(pszPrefixWithSubKey,pszDbPrefix),pszSubKey),"\\"); /* buffer safe */ if (pszPrefixWithSubKey!=NULL) { if (EnumDbPrefixSettings("AssocMgr",pszPrefixWithSubKey,&ppszSettings,&nSettingsCount)) { for(i=0;i<nSettingsCount;++i) { db_unset(NULL,"AssocMgr",ppszSettings[i]); mir_free(ppszSettings[i]); } mir_free(ppszSettings); } mir_free(pszPrefixWithSubKey); } }
bool TiXmlDocument::GetAsCharBuffer(char* buffer, size_t bufferSize) { #ifdef TIXML_USE_STL std::string data = GetAsString(); #else TIXML_OSTREAM data; FormattedStreamOut(&data, 0); #endif if (bufferSize < data.length()) { return false; } else { mir_strcpy(buffer, data.c_str()); return true; } }
char* Utils::makeSafeString(TCHAR *input, char *output) { char *buff = mir_t2a(input); size_t length = mir_strlen(buff); for (UINT i = 0; i < length; i++) { for (int j = 0; from_chars[j] != 0; j++) { if (buff[i] == from_chars[j]) { buff[i] = to_chars[j]; break; } } } mir_strcpy(output, buff); FREE(buff); return output; }
static INT_PTR CALLBACK WarnIniChangeDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { static warnSettingChangeInfo_t *warnInfo; switch(message) { case WM_INITDIALOG: { char szSettingName[256]; const TCHAR *pszSecurityInfo; warnInfo = (warnSettingChangeInfo_t*)lParam; TranslateDialogDefault(hwndDlg); SetDlgItemText(hwndDlg, IDC_ININAME, warnInfo->szIniPath); mir_strcpy(szSettingName, warnInfo->szSection); mir_strcat(szSettingName, " / "); mir_strcat(szSettingName, warnInfo->szName); SetDlgItemTextA(hwndDlg, IDC_SETTINGNAME, szSettingName); SetDlgItemTextA(hwndDlg, IDC_NEWVALUE, warnInfo->szValue); if (IsInSpaceSeparatedList(warnInfo->szSection, warnInfo->szSafeSections)) pszSecurityInfo = LPGENT("This change is known to be safe."); else if (IsInSpaceSeparatedList(warnInfo->szSection, warnInfo->szUnsafeSections)) pszSecurityInfo = LPGENT("This change is known to be potentially hazardous."); else pszSecurityInfo = LPGENT("This change is not known to be safe."); SetDlgItemText(hwndDlg, IDC_SECURITYINFO, TranslateTS(pszSecurityInfo)); } return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: warnInfo->cancel = 1; // fall through case IDYES: case IDNO: warnInfo->warnNoMore = IsDlgButtonChecked(hwndDlg, IDC_WARNNOMORE); EndDialog(hwndDlg, LOWORD(wParam)); break; } break; } return FALSE; }
INT_PTR ReportMyAvatarChanged(WPARAM wParam, LPARAM) { const char *proto = (const char*)wParam; if (proto == NULL) return -1; for (int i = 0; i < g_MyAvatars.getCount(); i++) { if (g_MyAvatars[i].dwFlags & AVS_IGNORENOTIFY) continue; if (!mir_strcmp(g_MyAvatars[i].szProtoname, proto)) { LPVOID lpParam = (void *)malloc(mir_strlen(g_MyAvatars[i].szProtoname) + 2); mir_strcpy((char *)lpParam, g_MyAvatars[i].szProtoname); mir_forkthread(ReloadMyAvatar, lpParam); return 0; } } return -2; }
static void SetAvatar(TlenProtocol *proto, MCONTACT hContact, TLEN_LIST_ITEM *item, char *data, int len, DWORD format) { TCHAR filename[MAX_PATH]; char md5[33]; mir_md5_state_t ctx; DWORD digest[4]; if (format == PA_FORMAT_UNKNOWN && len > 4) format = ProtoGetBufferFormat(data); mir_md5_init( &ctx ); mir_md5_append( &ctx, ( BYTE* )data, len); mir_md5_finish( &ctx, ( BYTE* )digest ); sprintf( md5, "%08x%08x%08x%08x", (int)htonl(digest[0]), (int)htonl(digest[1]), (int)htonl(digest[2]), (int)htonl(digest[3])); //!!!!!!!!!!!!!! if (item != NULL) { char *hash = item->avatarHash; item->avatarFormat = format; item->avatarHash = mir_strdup(md5); mir_free(hash); } else { proto->threadData->avatarFormat = format; mir_strcpy(proto->threadData->avatarHash, md5); } TlenGetAvatarFileName(proto, item, filename, _countof(filename)-1); DeleteFile(filename); FILE *out = _tfopen(filename, TEXT("wb") ); if (out != NULL) { fwrite(data, len, 1, out); fclose(out); db_set_ts(hContact, "ContactPhoto", "File", filename ); db_set_s(hContact, proto->m_szModuleName, "AvatarHash", md5); db_set_dw(hContact, proto->m_szModuleName, "AvatarFormat", format); } else { TCHAR buffer[128]; mir_sntprintf(buffer, _countof(buffer), TranslateT("Cannot save new avatar file \"%s\" Error:\n\t%s (Error: %d)"), filename, _tcserror(errno), errno); PUShowMessageT(buffer, SM_WARNING); proto->debugLog(buffer); return; } ProtoBroadcastAck( proto->m_szModuleName, hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL , 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; }
static char *StatusModeToDbSetting(int status, const char *suffix) { char *prefix; static char str[64]; switch (status) { case ID_STATUS_AWAY: prefix = "Away"; break; case ID_STATUS_NA: prefix = "Na"; break; case ID_STATUS_DND: prefix = "Dnd"; break; case ID_STATUS_OCCUPIED: prefix = "Occupied"; break; case ID_STATUS_FREECHAT: prefix = "FreeChat"; break; case ID_STATUS_ONLINE: prefix = "On"; break; case ID_STATUS_OFFLINE: prefix = "Off"; break; case ID_STATUS_INVISIBLE: prefix = "Inv"; break; case ID_STATUS_ONTHEPHONE: prefix = "Otp"; break; case ID_STATUS_OUTTOLUNCH: prefix = "Otl"; break; case ID_STATUS_IDLE: prefix = "Idl"; break; default: return NULL; } mir_strcpy(str, prefix); mir_strcat(str, suffix); return str; }
void ICQTransfer::resume(int action, const char *newName) { switch (action) { case FILERESUME_OVERWRITE: T("[ ] overwrite existing file\n"); fileProgress = 0; break; case FILERESUME_RESUME: T("[ ] file resume\n"); break; case FILERESUME_RENAME: T("[ ] rename file\n"); delete [] fileName; fileName = new char[mir_strlen(newName) + 1]; mir_strcpy(fileName, newName); files[current] = fileName; openFile(); fileProgress = 0; break; case FILERESUME_SKIP: T("[ ] skip file\n"); fileProgress = fileSize; break; } totalProgress += fileProgress; sendPacket0x03(); ack(ACKRESULT_NEXTFILE); if (fileProgress) ack(ACKRESULT_DATA); }
static INT_PTR icqSendFile(WPARAM wParam, LPARAM lParam) { CCSDATA *ccs = (CCSDATA *)lParam; char **files = (char **)ccs->lParam; //HANDLE hFile; ICQUser *u; T("[ ] send file\n"); u = icq.getUserByContact(ccs->hContact); if (u == NULL || u->statusVal == ID_STATUS_OFFLINE || icq.statusVal <= ID_STATUS_OFFLINE) return 0; unsigned long filesCount, directoriesCount, filesSize = 0; char filename[MAX_PATH], format[32]; WIN32_FIND_DATA findData; for (filesCount = 0, directoriesCount = 0; files[filesCount]; filesCount++) { FindClose(FindFirstFile(files[filesCount], &findData)); if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) directoriesCount++; else filesSize += findData.nFileSizeLow; } filesCount -= directoriesCount; if (directoriesCount) { sprintf(format, "%s, %s", filesCount == 1 ? Translate("%d file") : Translate("%d files"), directoriesCount == 1 ? Translate("%d directory") : Translate("%d directories")); sprintf(filename, format, filesCount, directoriesCount); } else { if (filesCount == 1) { char *p = strrchr(files[0], '\\'); mir_strcpy(filename, p ? p + 1 : files[0]); } else sprintf(filename, filesCount == 1 ? Translate("%d file") : Translate("%d files"), filesCount); } return (INT_PTR)icq.sendFile(u, (char*)ccs->wParam, filename, filesSize, files); }
static INT_PTR nGetShare(WPARAM /*wParam*/, LPARAM lParam) { if (!lParam) return 1001; CLFileShareListAccess clCritSection; STFileShareInfo * pclShare = (STFileShareInfo*)lParam; CLFileShareNode * pclCur = pclFirstNode; while (pclCur) { if (mir_strcmp(pclCur->st.pszSrvPath, pclShare->pszSrvPath) == 0) { if (pclShare->dwMaxRealPath <= mir_strlen(pclCur->st.pszRealPath) + 1) return 1003; mir_strcpy(pclShare->pszRealPath, pclCur->st.pszRealPath); pclShare->dwAllowedIP = pclCur->st.dwAllowedIP; pclShare->dwAllowedMask = pclCur->st.dwAllowedMask; pclShare->nMaxDownloads = pclCur->st.nMaxDownloads; pclShare->dwOptions = pclCur->st.dwOptions; return 0; } pclCur = pclCur->pclNext; } return 1002; }
void CSendHost_Imgur::SendThread(void* obj) { CSendHost_Imgur* self = (CSendHost_Imgur*)obj; /// send DATA and wait for m_nlreply NETLIBHTTPREQUEST* reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)g_hNetlibUser, (LPARAM)&self->m_nlhr); self->HTTPFormDestroy(&self->m_nlhr); if (reply) { if (reply->dataLength) { char buf[128]; if (GetJSONBool(reply->pData, reply->dataLength, "success")) { GetJSONString(reply->pData, reply->dataLength, "data[link]", buf, sizeof(buf)); mir_free(self->m_URL), self->m_URL = mir_strdup(buf); char* ext = strrchr(self->m_URL, '.'); if (ext) { size_t thumblen = mir_strlen(self->m_URL) + 2; mir_free(self->m_URLthumb), self->m_URLthumb = (char*)mir_alloc(thumblen); thumblen = ext - self->m_URL; memcpy(self->m_URLthumb, self->m_URL, thumblen); self->m_URLthumb[thumblen] = 'm'; // 320x320, see http://api.imgur.com/models/image mir_strcpy(self->m_URLthumb + thumblen + 1, self->m_URL + thumblen); } CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); self->svcSendMsgExit(self->m_URL); return; } else self->Error(SS_ERR_RESPONSE, self->m_pszSendTyp, GetJSONInteger(reply->pData, reply->dataLength, "status", 0)); } else self->Error(SS_ERR_RESPONSE, self->m_pszSendTyp, reply->resultCode); CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); } else self->Error(SS_ERR_NORESPONSE, self->m_pszSendTyp, self->m_nlhr.resultCode); self->Exit(ACKRESULT_FAILED); }
int AlarmWinModulesLoaded(WPARAM, LPARAM) { title_font_id.cbSize = sizeof(FontIDT); mir_tstrcpy(title_font_id.group, LPGENT("Alarms")); mir_tstrcpy(title_font_id.name, LPGENT("Title")); mir_strcpy(title_font_id.dbSettingsGroup, MODULE); mir_strcpy(title_font_id.prefix, "FontTitle"); mir_tstrcpy(title_font_id.backgroundGroup,LPGENT("Alarms")); mir_tstrcpy(title_font_id.backgroundName,LPGENT("Background")); title_font_id.flags = 0; title_font_id.order = 0; FontRegisterT(&title_font_id); window_font_id.cbSize = sizeof(FontIDT); mir_tstrcpy(window_font_id.group, LPGENT("Alarms")); mir_tstrcpy(window_font_id.name, LPGENT("Window")); mir_strcpy(window_font_id.dbSettingsGroup, MODULE); mir_strcpy(window_font_id.prefix, "FontWindow"); mir_tstrcpy(window_font_id.backgroundGroup,LPGENT("Alarms")); mir_tstrcpy(window_font_id.backgroundName,LPGENT("Background")); window_font_id.flags = 0; window_font_id.order = 1; FontRegisterT(&window_font_id); bk_colour_id.cbSize = sizeof(ColourIDT); mir_strcpy(bk_colour_id.dbSettingsGroup, MODULE); mir_tstrcpy(bk_colour_id.group, LPGENT("Alarms")); mir_tstrcpy(bk_colour_id.name, LPGENT("Background")); mir_strcpy(bk_colour_id.setting, "BkColour"); bk_colour_id.defcolour = GetSysColor(COLOR_3DFACE); bk_colour_id.flags = 0; bk_colour_id.order = 0; ColourRegisterT(&bk_colour_id); ReloadFonts(0, 0); HookEvent(ME_FONT_RELOAD, ReloadFonts); return 0; }
void stripHTML(char* str) { char *p, *q; for ( p=q=str; *p!='\0'; p++,q++ ) { if ( *p == '<' ) { if ( !strnicmp( p, "<p>", 3 )) { mir_strcpy(q, "\r\n\r\n"); q += 3; p += 2; } else if ( !strnicmp( p, "</p>", 4 )) { mir_strcpy(q, "\r\n\r\n"); q += 3; p += 3; } else if ( !strnicmp( p, "<br>", 4 )) { mir_strcpy(q, "\r\n"); ++q; p += 3; } else if ( !strnicmp( p, "<br />", 6 )) { mir_strcpy(q, "\r\n"); ++q; p += 5; } else if ( !strnicmp( p, "<hr>", 4 )) { mir_strcpy(q, "\r\n"); ++q; p += 3; } else if ( !strnicmp( p, "<hr />", 6 )) { mir_strcpy(q, "\r\n"); ++q; p += 5; } else { char *l = strchr(p, '>'); if (l) { p = l; --q; } else *q = *p; } } else *q = *p; } *q = '\0'; }
void TlenProtocol::initMenuItems() { char text[MAX_PATH]; strncpy_s(text, m_szModuleName, _TRUNCATE); char *pSvcName = text + mir_strlen(text); CMenuItem mi; mi.root = hMenuRoot = Menu_CreateRoot(MO_MAIN, m_tszUserName, -1999901009, GetIconHandle(IDI_TLEN)); mi.pszService = text; hMenuChats = NULL; // "Multi-User Conference" mir_strcpy(pSvcName, "/MainMenuMUC"); CreateProtoService(pSvcName, &TlenProtocol::MUCMenuHandleMUC); mi.name.a = LPGEN("Multi-User Conference"); mi.position = 2000050002; mi.hIcolibItem = GetIconHandle(IDI_MUC); mi.pszService = text; hMenuMUC = Menu_AddMainMenuItem(&mi); mir_strcpy(pSvcName, "/MainMenuInbox"); CreateProtoService(pSvcName, &TlenProtocol::MenuHandleInbox); mi.name.a = LPGEN("Tlen Mail"); mi.position = 2000050003; mi.hIcolibItem = GetIconHandle(IDI_MAIL); mi.pszService = text; hMenuInbox = Menu_AddMainMenuItem(&mi); // contact menu items mi.root = NULL; // "Send picture" mi.pszService = "/SendPicture"; CreateProtoService(mi.pszService, &TlenProtocol::ContactMenuHandleSendPicture); mi.name.a = LPGEN("Send picture"); mi.position = -2000019030; mi.hIcolibItem = GetIconHandle(IDI_IMAGE); hMenuPicture = Menu_AddContactMenuItem(&mi, m_szModuleName); // "Invite to MUC" mi.pszService = "/ContactMenuMUC"; CreateProtoService(mi.pszService, &TlenProtocol::MUCContactMenuHandleMUC); mi.name.a = LPGEN("Multi-User Conference"); mi.position = -2000019020; mi.hIcolibItem = GetIconHandle(IDI_MUC); hMenuContactMUC = Menu_AddContactMenuItem(&mi, m_szModuleName); // "Invite to voice chat" mi.pszService = "/ContactMenuVoice"; CreateProtoService(mi.pszService, &TlenProtocol::VoiceContactMenuHandleVoice); mi.name.a = LPGEN("Voice Chat"); mi.position = -2000019010; mi.hIcolibItem = GetIconHandle(IDI_VOICE); hMenuContactVoice = Menu_AddContactMenuItem(&mi, m_szModuleName); // "Request authorization" mi.pszService = "/RequestAuth"; CreateProtoService(mi.pszService, &TlenProtocol::ContactMenuHandleRequestAuth); mi.name.a = LPGEN("Request authorization"); mi.position = -2000001001; mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_REQUEST); hMenuContactRequestAuth = Menu_AddContactMenuItem(&mi, m_szModuleName); // "Grant authorization" mi.pszService = "/GrantAuth"; CreateProtoService(mi.pszService, &TlenProtocol::ContactMenuHandleGrantAuth); mi.name.a = LPGEN("Grant authorization"); mi.position = -2000001000; mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_GRANT); hMenuContactGrantAuth = Menu_AddContactMenuItem(&mi, m_szModuleName); }
INT_PTR CALLBACK DlgProcUrlRecv(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { struct UrlRcvData *dat = (struct UrlRcvData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_URL); Button_SetIcon_IcoLib(hwndDlg, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list")); Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details")); Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, LPGEN("View user's history")); Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, LPGEN("User menu")); dat = (struct UrlRcvData*)mir_alloc(sizeof(struct UrlRcvData)); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); dat->hContact = ((CLISTEVENT*)lParam)->hContact; dat->hDbEvent = ((CLISTEVENT*)lParam)->hDbEvent; WindowList_Add(hUrlWindowList, hwndDlg, dat->hContact); { DBEVENTINFO dbei = { sizeof(dbei) }; dbei.cbBlob = db_event_getBlobSize(dat->hDbEvent); dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); db_event_get(dat->hDbEvent, &dbei); SetDlgItemTextA(hwndDlg, IDC_URL, (char*)dbei.pBlob); SetDlgItemTextA(hwndDlg, IDC_MSG, (char*)dbei.pBlob+mir_strlen((char*)dbei.pBlob)+1); mir_free(dbei.pBlob); db_event_markRead(dat->hContact, dat->hDbEvent); TCHAR *contactName = pcli->pfnGetContactDisplayName(dat->hContact, 0), msg[128]; mir_sntprintf(msg, _countof(msg), TranslateT("URL from %s"), contactName); SetWindowText(hwndDlg, msg); SetDlgItemText(hwndDlg, IDC_FROM, contactName); SendDlgItemMessage(hwndDlg, IDOK, BUTTONSETARROW, 1, 0); TCHAR str[128]; TimeZone_PrintTimeStamp(NULL, dbei.timestamp, _T("t d"), str, _countof(str), 0); SetDlgItemText(hwndDlg, IDC_DATE, str); } // From message dlg if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0)) ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE); SendMessage(hwndDlg, DM_UPDATETITLE, 0, 0); // From message dlg end Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, "SRUrl", "recv"); return TRUE; case WM_MEASUREITEM: return Menu_MeasureItem((LPMEASUREITEMSTRUCT)lParam); case WM_DRAWITEM: { LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL)) { char *szProto = GetContactProto(dat->hContact); if (szProto) { HICON hIcon = (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL|PLIF_SMALL, 0); if (hIcon) { DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL); DestroyIcon(hIcon); } } } } return Menu_DrawItem((LPDRAWITEMSTRUCT)lParam); case DM_UPDATETITLE: sttUpdateTitle(hwndDlg, dat->hContact); break; case WM_COMMAND: if (!dat) break; if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) break; switch(LOWORD(wParam)) { case IDOK: { RECT rc; char url[256]; HMENU hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXT)); HMENU hSubMenu = GetSubMenu(hMenu, 6); TranslateMenu(hSubMenu); GetWindowRect((HWND)lParam, &rc); GetDlgItemTextA(hwndDlg, IDC_URL, url, _countof(url)); switch(TrackPopupMenu(hSubMenu, TPM_RETURNCMD, rc.left, rc.bottom, 0, hwndDlg, NULL)) { case IDM_OPENNEW: Utils_OpenUrl(url); break; case IDM_OPENEXISTING: Utils_OpenUrl(url); break; case IDM_COPYLINK: { if ( !OpenClipboard(hwndDlg)) break; EmptyClipboard(); HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, mir_strlen(url)+1); mir_strcpy((char*)GlobalLock(hData), url); GlobalUnlock(hData); SetClipboardData(CF_TEXT, hData); CloseClipboard(); break; } } DestroyMenu(hMenu); } return TRUE; case IDC_USERMENU: { RECT rc; HMENU hMenu = Menu_BuildContactMenu(dat->hContact); GetWindowRect(GetDlgItem(hwndDlg, IDC_USERMENU), &rc); TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); DestroyMenu(hMenu); } break; case IDC_HISTORY: CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)dat->hContact, 0); break; case IDC_DETAILS: CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)dat->hContact, 0); break; case IDC_ADD: { ADDCONTACTSTRUCT acs = {0}; acs.hContact = dat->hContact; acs.handleType = HANDLE_CONTACT; CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs); } if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0)) { ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), FALSE); } break; case IDC_REPLY: CallService(MS_MSG_SENDMESSAGE, (WPARAM)dat->hContact, 0); //fall through case IDCANCEL: DestroyWindow(hwndDlg); return TRUE; } break; case WM_DESTROY: Window_FreeIcon_IcoLib(hwndDlg); Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD); Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS); Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY); Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU); WindowList_Remove(hUrlWindowList, hwndDlg); mir_free(dat); Utils_SaveWindowPosition(hwndDlg, NULL, "SRUrl", "recv"); break; } return FALSE; }
INT_PTR CALLBACK DlgProcUrlSend(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { struct UrlSendData* dat = (struct UrlSendData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_URL); Button_SetIcon_IcoLib(hwndDlg, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list")); Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details")); Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, LPGEN("View user's history")); Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, LPGEN("User menu")); SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_LIMITTEXT, 450, 0); dat = (struct UrlSendData*)mir_alloc(sizeof(struct UrlSendData)); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); dat->hContact = lParam; dat->hAckEvent = NULL; dat->hSendId = NULL; dat->sendBuffer = NULL; WindowList_Add(hUrlWindowList, hwndDlg, dat->hContact); { TCHAR *str = pcli->pfnGetContactDisplayName(dat->hContact, 0); SetDlgItemText(hwndDlg, IDC_NAME, str); } GetOpenBrowserUrls(hwndDlg, GetDlgItem(hwndDlg, IDC_URLS)); SendDlgItemMessage(hwndDlg, IDC_URLS, CB_SETCURSEL, 0, 0); if (SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETCOUNT, 0, 0))SendMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_URLS, CBN_SELCHANGE), 0); EnableWindow(GetDlgItem(hwndDlg, IDOK), (SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETCURSEL, 0, 0) == CB_ERR)?FALSE:TRUE); Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, "SRUrl", "send"); mir_subclassWindow( GetDlgItem(hwndDlg, IDC_MESSAGE), SendEditSubclassProc); mir_subclassWindow( GetWindow(GetDlgItem(hwndDlg, IDC_URLS), GW_CHILD), SendEditSubclassProc); // From message dlg if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0)) ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE); SendMessage(hwndDlg, DM_UPDATETITLE, 0, 0); // From message dlg end return TRUE; case WM_DDE_DATA: case WM_DDE_ACK: return DdeMessage(hwndDlg, msg, wParam, lParam); case WM_TIMER: if (wParam == 0) { //ICQ sendurl timed out KillTimer(hwndDlg, 0); MessageBox(hwndDlg, TranslateT("Send timed out"), _T(""), MB_OK); EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_URLS), TRUE); SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETREADONLY, FALSE, 0); } break; case WM_MEASUREITEM: return Menu_MeasureItem((LPMEASUREITEMSTRUCT)lParam); case WM_DRAWITEM: { LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL)) { char *szProto = GetContactProto(dat->hContact); if (szProto) { HICON hIcon = (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL|PLIF_SMALL, 0); if (hIcon) { DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL); DestroyIcon(hIcon); } } } } return Menu_DrawItem((LPDRAWITEMSTRUCT)lParam); case DM_UPDATETITLE: sttUpdateTitle(hwndDlg, dat->hContact); break; case WM_COMMAND: if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) break; switch (LOWORD(wParam)) { case IDOK: { char *body, *url; int bodySize, urlSize; urlSize = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_URLS))+1; url = (char*)mir_alloc(urlSize); GetDlgItemTextA(hwndDlg, IDC_URLS, url, urlSize); if (url[0] == 0) { mir_free(url); break; } bodySize = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_MESSAGE))+1; body = (char*)mir_alloc(bodySize); GetDlgItemTextA(hwndDlg, IDC_MESSAGE, body, bodySize); dat->sendBuffer = (char*)mir_realloc(dat->sendBuffer, mir_strlen(url)+mir_strlen(body)+2); mir_strcpy(dat->sendBuffer, url); mir_strcpy(dat->sendBuffer+mir_strlen(url)+1, body); dat->hAckEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_EVENTSENT); dat->hSendId = (HANDLE)CallContactService(dat->hContact, PSS_URL, 0, (LPARAM)dat->sendBuffer); mir_free(url); mir_free(body); //create a timeout timer SetTimer(hwndDlg, 0, TIMEOUT_URLSEND, NULL); EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_URLS), FALSE); SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETREADONLY, TRUE, 0); return TRUE; } case IDCANCEL: DestroyWindow(hwndDlg); return TRUE; case IDC_URLS: if (HIWORD(wParam) == CBN_SELCHANGE) { int i, urlSize; char *title; i = SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETCURSEL, 0, 0); title = (char*)SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETITEMDATA, (WPARAM)i, 0); SetDlgItemTextA(hwndDlg, IDC_MESSAGE, title); urlSize = SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETLBTEXTLEN, (WPARAM)i, 0); EnableWindow(GetDlgItem(hwndDlg, IDOK), (urlSize>0)); } else if (HIWORD(wParam) == CBN_EDITCHANGE) { int urlSize = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_URLS)); EnableWindow(GetDlgItem(hwndDlg, IDOK), (urlSize>0)); } break; case IDC_USERMENU: { RECT rc; HMENU hMenu = Menu_BuildContactMenu(dat->hContact); GetWindowRect(GetDlgItem(hwndDlg, IDC_USERMENU), &rc); TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); DestroyMenu(hMenu); } break; case IDC_HISTORY: CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)dat->hContact, 0); break; case IDC_DETAILS: CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)dat->hContact, 0); break; case IDC_ADD: ADDCONTACTSTRUCT acs = {0}; acs.hContact = dat->hContact; acs.handleType = HANDLE_CONTACT; acs.szProto = 0; CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs); if ( !db_get_b(dat->hContact, "CList", "NotOnList", 0)) ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), FALSE); } break; case HM_EVENTSENT: { ACKDATA *ack = (ACKDATA*)lParam; if (ack->hProcess != dat->hSendId) break; if (ack->hContact != dat->hContact) break; if (ack->type != ACKTYPE_URL || ack->result != ACKRESULT_SUCCESS) break; DBEVENTINFO dbei = { 0 }; dbei.cbSize = sizeof(dbei); dbei.eventType = EVENTTYPE_URL; dbei.flags = DBEF_SENT; dbei.szModule = GetContactProto(dat->hContact); dbei.timestamp = time(NULL); dbei.cbBlob = (DWORD)(mir_strlen(dat->sendBuffer)+mir_strlen(dat->sendBuffer+mir_strlen(dat->sendBuffer)+1)+2); dbei.pBlob = (PBYTE)dat->sendBuffer; db_event_add(dat->hContact, &dbei); KillTimer(hwndDlg, 0); DestroyWindow(hwndDlg); } break; case WM_DESTROY: Window_FreeIcon_IcoLib(hwndDlg); Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD); Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS); Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY); Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU); WindowList_Remove(hUrlWindowList, hwndDlg); if (dat->hAckEvent) UnhookEvent(dat->hAckEvent); if (dat->sendBuffer != NULL) mir_free(dat->sendBuffer); mir_free(dat); Utils_SaveWindowPosition(hwndDlg, NULL, "SRUrl", "send"); for (int i = SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETCOUNT, 0, 0)-1;i>=0;i--) mir_free((char*)SendDlgItemMessage(hwndDlg, IDC_URLS, CB_GETITEMDATA, i, 0)); break; } return FALSE; }
static INT_PTR CALLBACK YahooUserInfoDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: // lParam is hContact TranslateDialogDefault(hwndDlg); //SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_LoadIcon(SKINICON_OTHER_USERDETAILS)); break; case WM_NOTIFY: if (((LPNMHDR)lParam)->idFrom == 0) { switch (((LPNMHDR)lParam)->code) { case PSN_PARAMCHANGED: SetWindowLongPtr(hwndDlg, GWLP_USERDATA, ((PSHNOTIFY*)lParam)->lParam); break; case PSN_INFOCHANGED: { CYahooProto* ppro = (CYahooProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); if (!ppro) break; char* szProto; MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; if (hContact == NULL) { szProto = ppro->m_szModuleName; } else { szProto = GetContactProto(hContact); } if (!szProto) break; if (hContact) { DBVARIANT dbv; char z[128]; if (ppro->getString(hContact, YAHOO_LOGINID, &dbv) == 0) { mir_strcpy(z, dbv.pszVal); db_free(&dbv); } else { mir_strcpy(z, "???"); } SetDlgItemTextA(hwndDlg, IDC_SEARCH_ID, z); if (ppro->getString(hContact, "Transport", &dbv) == 0) { mir_strcpy(z, dbv.pszVal); db_free(&dbv); } else { mir_strcpy(z, "Yahoo"); } SetDlgItemTextA(hwndDlg, IDC_SEARCH_PROTOCOL, z); if (ppro->getString(hContact, "MirVer", &dbv) == 0) { mir_strcpy(z, dbv.pszVal); db_free(&dbv); } else { mir_strcpy(z, "???"); } SetDlgItemTextA(hwndDlg, IDC_NFO_CLIENT, z); } else { } } break; } } break; case WM_CLOSE: DestroyWindow(hwndDlg); break; case WM_DESTROY: break; } return FALSE; }
bool InternetDownloadFile(const char *szUrl, char* szDest, HANDLE &hHttpDwnl) { int result = 0xBADBAD; char *szRedirUrl = NULL; NETLIBHTTPREQUEST nlhr = {0}; // initialize the netlib request nlhr.cbSize = sizeof(nlhr); nlhr.requestType = REQUEST_GET; nlhr.flags = NLHRF_NODUMP | NLHRF_HTTP11 | NLHRF_PERSISTENT | NLHRF_REDIRECT; nlhr.szUrl = (char*)szUrl; nlhr.nlc = hHttpDwnl; // change the header so the plugin is pretended to be IE 6 + WinXP nlhr.headersCount = 2; nlhr.headers=(NETLIBHTTPHEADER*)alloca(sizeof(NETLIBHTTPHEADER)*nlhr.headersCount); nlhr.headers[0].szName = "User-Agent"; nlhr.headers[0].szValue = NETLIB_USER_AGENT; nlhr.headers[1].szName = "Connection"; nlhr.headers[1].szValue = "close"; while (result == 0xBADBAD) { // download the page NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser,(LPARAM)&nlhr); if (nlhrReply) { hHttpDwnl = nlhrReply->nlc; // if the recieved code is 200 OK if (nlhrReply->resultCode == 200) { char *delim = strrchr(szDest, '\\'); if (delim) *delim = '\0'; CreateDirectoryTree(szDest); if (delim) *delim = '\\'; int res = -1; int fh = _open(szDest, _O_BINARY | _O_WRONLY | _O_CREAT, _S_IREAD | _S_IWRITE); if (fh != -1) { res = _write(fh, nlhrReply->pData, nlhrReply->dataLength); _close(fh); } if (res < 0) remove(szDest); else result = 0; } // if the recieved code is 302 Moved, Found, etc // workaround for url forwarding else if (nlhrReply->resultCode == 302 || nlhrReply->resultCode == 301 || nlhrReply->resultCode == 307) { // page moved // get the url for the new location and save it to szInfo // look for the reply header "Location" for (int i=0; i<nlhrReply->headersCount; i++) { if (!mir_strcmp(nlhrReply->headers[i].szName, "Location")) { size_t rlen = 0; if (nlhrReply->headers[i].szValue[0] == '/') { const char* szPath; const char* szPref = strstr(szUrl, "://"); szPref = szPref ? szPref + 3 : szUrl; szPath = strchr(szPref, '/'); rlen = szPath != NULL ? szPath - szUrl : mir_strlen(szUrl); } szRedirUrl = (char*)mir_realloc(szRedirUrl, rlen + mir_strlen(nlhrReply->headers[i].szValue)*3 + 1); strncpy(szRedirUrl, szUrl, rlen); mir_strcpy(szRedirUrl+rlen, nlhrReply->headers[i].szValue); nlhr.szUrl = szRedirUrl; break; } } } else result = 1; } else { hHttpDwnl = NULL; result = 1; } CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT,0,(LPARAM)nlhrReply); } mir_free(szRedirUrl); return result == 0; }
int CDb3Mmap::GetContactSettingWorker(MCONTACT contactID, LPCSTR szModule, LPCSTR szSetting, DBVARIANT *dbv, int isStatic) { if (szSetting == NULL || szModule == NULL) return 1; // the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name int settingNameLen = (int)mir_strlen(szSetting); int moduleNameLen = (int)mir_strlen(szModule); if (settingNameLen > 0xFE) { #ifdef _DEBUG OutputDebugStringA("GetContactSettingWorker() got a > 255 setting name length. \n"); #endif return 1; } if (moduleNameLen > 0xFE) { #ifdef _DEBUG OutputDebugStringA("GetContactSettingWorker() got a > 255 module name length. \n"); #endif return 1; } mir_cslock lck(m_csDbAccess); LBL_Seek: char *szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen); log3("get [%08p] %s (%p)", hContact, szCachedSettingName, szCachedSettingName); DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 0); if (pCachedValue != NULL) { if (pCachedValue->type == DBVT_ASCIIZ || pCachedValue->type == DBVT_UTF8) { int cbOrigLen = dbv->cchVal; char *cbOrigPtr = dbv->pszVal; memcpy(dbv, pCachedValue, sizeof(DBVARIANT)); if (isStatic) { int cbLen = 0; if (pCachedValue->pszVal != NULL) cbLen = (int)mir_strlen(pCachedValue->pszVal); cbOrigLen--; dbv->pszVal = cbOrigPtr; if (cbLen < cbOrigLen) cbOrigLen = cbLen; memcpy(dbv->pszVal, pCachedValue->pszVal, cbOrigLen); dbv->pszVal[cbOrigLen] = 0; dbv->cchVal = cbLen; } else { dbv->pszVal = (char*)mir_alloc(mir_strlen(pCachedValue->pszVal) + 1); mir_strcpy(dbv->pszVal, pCachedValue->pszVal); } } else memcpy(dbv, pCachedValue, sizeof(DBVARIANT)); log2("get cached %s (%p)", printVariant(dbv), pCachedValue); return (pCachedValue->type == DBVT_DELETED) ? 1 : 0; } // never look db for the resident variable if (szCachedSettingName[-1] != 0) return 1; DBCachedContact *cc; DWORD ofsContact = GetContactOffset(contactID, &cc); DWORD ofsModuleName = GetModuleNameOfs(szModule); DBContact dbc = *(DBContact*)DBRead(ofsContact, NULL); if (dbc.signature != DBCONTACT_SIGNATURE) return 1; DWORD ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(&dbc, ofsModuleName); if (ofsSettingsGroup) { int bytesRemaining; unsigned varLen; DWORD ofsBlobPtr = ofsSettingsGroup + offsetof(DBContactSettings, blob); PBYTE pBlob = DBRead(ofsBlobPtr, &bytesRemaining); while (pBlob[0]) { NeedBytes(1 + settingNameLen); if (pBlob[0] == settingNameLen && !memcmp(pBlob + 1, szSetting, settingNameLen)) { MoveAlong(1 + settingNameLen); NeedBytes(5); if (isStatic && (pBlob[0] & DBVTF_VARIABLELENGTH) && VLT(dbv->type) != VLT(pBlob[0])) return 1; BYTE iType = dbv->type = pBlob[0]; switch (iType) { case DBVT_DELETED: /* this setting is deleted */ dbv->type = DBVT_DELETED; return 2; case DBVT_BYTE: dbv->bVal = pBlob[1]; break; case DBVT_WORD: memmove(&(dbv->wVal), (PWORD)(pBlob + 1), 2); break; case DBVT_DWORD: memmove(&(dbv->dVal), (PDWORD)(pBlob + 1), 4); break; case DBVT_UTF8: case DBVT_ASCIIZ: varLen = *(PWORD)(pBlob + 1); NeedBytes(int(3 + varLen)); if (isStatic) { dbv->cchVal--; if (varLen < dbv->cchVal) dbv->cchVal = varLen; memmove(dbv->pszVal, pBlob + 3, dbv->cchVal); // decode dbv->pszVal[dbv->cchVal] = 0; dbv->cchVal = varLen; } else { dbv->pszVal = (char*)mir_alloc(1 + varLen); memmove(dbv->pszVal, pBlob + 3, varLen); dbv->pszVal[varLen] = 0; } break; case DBVT_BLOB: varLen = *(PWORD)(pBlob + 1); NeedBytes(int(3 + varLen)); if (isStatic) { if (varLen < dbv->cpbVal) dbv->cpbVal = varLen; memmove(dbv->pbVal, pBlob + 3, dbv->cpbVal); } else { dbv->pbVal = (BYTE *)mir_alloc(varLen); memmove(dbv->pbVal, pBlob + 3, varLen); } dbv->cpbVal = varLen; break; case DBVT_ENCRYPTED: if (m_crypto == NULL) return 1; else { varLen = *(PWORD)(pBlob + 1); NeedBytes(int(3 + varLen)); size_t realLen; ptrA decoded(m_crypto->decodeString(pBlob + 3, varLen, &realLen)); if (decoded == NULL) return 1; varLen = (WORD)realLen; dbv->type = DBVT_UTF8; if (isStatic) { dbv->cchVal--; if (varLen < dbv->cchVal) dbv->cchVal = varLen; memmove(dbv->pszVal, decoded, dbv->cchVal); dbv->pszVal[dbv->cchVal] = 0; dbv->cchVal = varLen; } else { dbv->pszVal = (char*)mir_alloc(1 + varLen); memmove(dbv->pszVal, decoded, varLen); dbv->pszVal[varLen] = 0; } } break; } /**** add to cache **********************/ if (iType != DBVT_BLOB && iType != DBVT_ENCRYPTED) { DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 1); if (pCachedValue != NULL) { m_cache->SetCachedVariant(dbv, pCachedValue); log3("set cached [%08p] %s (%p)", hContact, szCachedSettingName, pCachedValue); } } return 0; } NeedBytes(1); MoveAlong(pBlob[0] + 1); NeedBytes(3); MoveAlong(1 + GetSettingValueLength(pBlob)); NeedBytes(1); } } // try to get the missing mc setting from the active sub if (cc && cc->IsMeta() && ValidLookupName(szModule, szSetting)) { if (contactID = db_mc_getDefault(contactID)) { if (szModule = GetContactProto(contactID)) { moduleNameLen = (int)mir_strlen(szModule); goto LBL_Seek; } } } logg(); return 1; }
STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws) { if (dbcws == NULL || dbcws->szSetting == NULL || dbcws->szModule == NULL || m_bReadOnly) return 1; // the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name int settingNameLen = (int)mir_strlen(dbcws->szSetting); int moduleNameLen = (int)mir_strlen(dbcws->szModule); if (settingNameLen > 0xFE) { #ifdef _DEBUG OutputDebugStringA("WriteContactSetting() got a > 255 setting name length. \n"); #endif return 1; } if (moduleNameLen > 0xFE) { #ifdef _DEBUG OutputDebugStringA("WriteContactSetting() got a > 255 module name length. \n"); #endif return 1; } // used for notifications DBCONTACTWRITESETTING dbcwNotif = *dbcws; if (dbcwNotif.value.type == DBVT_WCHAR) { if (dbcwNotif.value.pszVal != NULL) { char* val = mir_utf8encodeW(dbcwNotif.value.pwszVal); if (val == NULL) return 1; dbcwNotif.value.pszVal = (char*)alloca(mir_strlen(val) + 1); mir_strcpy(dbcwNotif.value.pszVal, val); mir_free(val); dbcwNotif.value.type = DBVT_UTF8; } else return 1; } if (dbcwNotif.szModule == NULL || dbcwNotif.szSetting == NULL) return 1; DBCONTACTWRITESETTING dbcwWork = dbcwNotif; mir_ptr<BYTE> pEncoded(NULL); bool bIsEncrypted = false; switch (dbcwWork.value.type) { case DBVT_BYTE: case DBVT_WORD: case DBVT_DWORD: break; case DBVT_ASCIIZ: case DBVT_UTF8: bIsEncrypted = m_bEncrypted || IsSettingEncrypted(dbcws->szModule, dbcws->szSetting); LBL_WriteString: if (dbcwWork.value.pszVal == NULL) return 1; dbcwWork.value.cchVal = (WORD)mir_strlen(dbcwWork.value.pszVal); if (bIsEncrypted) { size_t len; BYTE *pResult = m_crypto->encodeString(dbcwWork.value.pszVal, &len); if (pResult != NULL) { pEncoded = dbcwWork.value.pbVal = pResult; dbcwWork.value.cpbVal = (WORD)len; dbcwWork.value.type = DBVT_ENCRYPTED; } } break; case DBVT_UNENCRYPTED: dbcwNotif.value.type = dbcwWork.value.type = DBVT_UTF8; goto LBL_WriteString; case DBVT_BLOB: case DBVT_ENCRYPTED: if (dbcwWork.value.pbVal == NULL) return 1; break; default: return 1; } mir_cslockfull lck(m_csDbAccess); DWORD ofsBlobPtr, ofsContact = GetContactOffset(contactID); if (ofsContact == 0) { _ASSERT(false); // contact doesn't exist? return 2; } char *szCachedSettingName = m_cache->GetCachedSetting(dbcwWork.szModule, dbcwWork.szSetting, moduleNameLen, settingNameLen); log3("set [%08p] %s (%p)", hContact, szCachedSettingName, szCachedSettingName); // we don't cache blobs and passwords if (dbcwWork.value.type != DBVT_BLOB && dbcwWork.value.type != DBVT_ENCRYPTED && !bIsEncrypted) { DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 1); if (pCachedValue != NULL) { bool bIsIdentical = false; if (pCachedValue->type == dbcwWork.value.type) { switch (dbcwWork.value.type) { case DBVT_BYTE: bIsIdentical = pCachedValue->bVal == dbcwWork.value.bVal; break; case DBVT_WORD: bIsIdentical = pCachedValue->wVal == dbcwWork.value.wVal; break; case DBVT_DWORD: bIsIdentical = pCachedValue->dVal == dbcwWork.value.dVal; break; case DBVT_UTF8: case DBVT_ASCIIZ: bIsIdentical = mir_strcmp(pCachedValue->pszVal, dbcwWork.value.pszVal) == 0; break; } if (bIsIdentical) return 0; } m_cache->SetCachedVariant(&dbcwWork.value, pCachedValue); } if (szCachedSettingName[-1] != 0) { lck.unlock(); log2(" set resident as %s (%p)", printVariant(&dbcwWork.value), pCachedValue); NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)&dbcwWork); return 0; } } else m_cache->GetCachedValuePtr(contactID, szCachedSettingName, -1); log1(" write database as %s", printVariant(&dbcwWork.value)); DWORD ofsModuleName = GetModuleNameOfs(dbcwWork.szModule); DBContact dbc = *(DBContact*)DBRead(ofsContact, NULL); if (dbc.signature != DBCONTACT_SIGNATURE) return 1; // make sure the module group exists PBYTE pBlob; int bytesRequired, bytesRemaining; DBContactSettings dbcs; DWORD ofsSettingsGroup = GetSettingsGroupOfsByModuleNameOfs(&dbc, ofsModuleName); if (ofsSettingsGroup == 0) { //module group didn't exist - make it switch (dbcwWork.value.type) { case DBVT_ASCIIZ: case DBVT_UTF8: bytesRequired = dbcwWork.value.cchVal + 2; break; case DBVT_BLOB: case DBVT_ENCRYPTED: bytesRequired = dbcwWork.value.cpbVal + 2; break; default: bytesRequired = dbcwWork.value.type; } bytesRequired += 2 + settingNameLen; bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY - (bytesRequired % DB_SETTINGS_RESIZE_GRANULARITY)) % DB_SETTINGS_RESIZE_GRANULARITY; ofsSettingsGroup = CreateNewSpace(bytesRequired + offsetof(DBContactSettings, blob)); dbcs.signature = DBCONTACTSETTINGS_SIGNATURE; dbcs.ofsNext = dbc.ofsFirstSettings; dbcs.ofsModuleName = ofsModuleName; dbcs.cbBlob = bytesRequired; dbcs.blob[0] = 0; dbc.ofsFirstSettings = ofsSettingsGroup; DBWrite(ofsContact, &dbc, sizeof(DBContact)); DBWrite(ofsSettingsGroup, &dbcs, sizeof(DBContactSettings)); ofsBlobPtr = ofsSettingsGroup + offsetof(DBContactSettings, blob); pBlob = (PBYTE)DBRead(ofsBlobPtr, &bytesRemaining); } else { dbcs = *(DBContactSettings*)DBRead(ofsSettingsGroup, &bytesRemaining); // find if the setting exists ofsBlobPtr = ofsSettingsGroup + offsetof(DBContactSettings, blob); pBlob = (PBYTE)DBRead(ofsBlobPtr, &bytesRemaining); while (pBlob[0]) { NeedBytes(settingNameLen + 1); if (pBlob[0] == settingNameLen && !memcmp(pBlob + 1, dbcwWork.szSetting, settingNameLen)) break; NeedBytes(1); MoveAlong(pBlob[0] + 1); NeedBytes(3); MoveAlong(1 + GetSettingValueLength(pBlob)); NeedBytes(1); } // setting already existed, and up to end of name is in cache if (pBlob[0]) { MoveAlong(1 + settingNameLen); // if different type or variable length and length is different NeedBytes(3); if (pBlob[0] != dbcwWork.value.type || ((pBlob[0] == DBVT_ASCIIZ || pBlob[0] == DBVT_UTF8) && *(PWORD)(pBlob + 1) != dbcwWork.value.cchVal) || ((pBlob[0] == DBVT_BLOB || pBlob[0] == DBVT_ENCRYPTED) && *(PWORD)(pBlob + 1) != dbcwWork.value.cpbVal)) { // bin it NeedBytes(3); int nameLen = 1 + settingNameLen; int valLen = 1 + GetSettingValueLength(pBlob); DWORD ofsSettingToCut = ofsBlobPtr - nameLen; MoveAlong(valLen); NeedBytes(1); while (pBlob[0]) { MoveAlong(pBlob[0] + 1); NeedBytes(3); MoveAlong(1 + GetSettingValueLength(pBlob)); NeedBytes(1); } DBMoveChunk(ofsSettingToCut, ofsSettingToCut + nameLen + valLen, ofsBlobPtr + 1 - ofsSettingToCut); ofsBlobPtr -= nameLen + valLen; pBlob = (PBYTE)DBRead(ofsBlobPtr, &bytesRemaining); } else { // replace existing setting at pBlob MoveAlong(1); // skip data type switch (dbcwWork.value.type) { case DBVT_BYTE: DBWrite(ofsBlobPtr, &dbcwWork.value.bVal, 1); break; case DBVT_WORD: DBWrite(ofsBlobPtr, &dbcwWork.value.wVal, 2); break; case DBVT_DWORD: DBWrite(ofsBlobPtr, &dbcwWork.value.dVal, 4); break; case DBVT_BLOB: DBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal); break; case DBVT_ENCRYPTED: DBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal); break; case DBVT_UTF8: case DBVT_ASCIIZ: DBWrite(ofsBlobPtr + 2, dbcwWork.value.pszVal, dbcwWork.value.cchVal); break; } // quit DBFlush(1); lck.unlock(); // notify NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)&dbcwNotif); return 0; } } } // cannot do a simple replace, add setting to end of list // pBlob already points to end of list // see if it fits switch (dbcwWork.value.type) { case DBVT_ASCIIZ: case DBVT_UTF8: bytesRequired = dbcwWork.value.cchVal + 2; break; case DBVT_BLOB: case DBVT_ENCRYPTED: bytesRequired = dbcwWork.value.cpbVal + 2; break; default: bytesRequired = dbcwWork.value.type; } bytesRequired += 2 + settingNameLen; bytesRequired += ofsBlobPtr + 1 - (ofsSettingsGroup + offsetof(DBContactSettings, blob)); if ((DWORD)bytesRequired > dbcs.cbBlob) { // doesn't fit: move entire group DBContactSettings *dbcsPrev; DWORD ofsDbcsPrev, ofsNew; InvalidateSettingsGroupOfsCacheEntry(ofsSettingsGroup); bytesRequired += (DB_SETTINGS_RESIZE_GRANULARITY - (bytesRequired % DB_SETTINGS_RESIZE_GRANULARITY)) % DB_SETTINGS_RESIZE_GRANULARITY; // find previous group to change its offset ofsDbcsPrev = dbc.ofsFirstSettings; if (ofsDbcsPrev == ofsSettingsGroup) ofsDbcsPrev = 0; else { dbcsPrev = (DBContactSettings*)DBRead(ofsDbcsPrev, NULL); while (dbcsPrev->ofsNext != ofsSettingsGroup) { if (dbcsPrev->ofsNext == 0) DatabaseCorruption(NULL); ofsDbcsPrev = dbcsPrev->ofsNext; dbcsPrev = (DBContactSettings*)DBRead(ofsDbcsPrev, NULL); } } // create the new one ofsNew = ReallocSpace(ofsSettingsGroup, dbcs.cbBlob + offsetof(DBContactSettings, blob), bytesRequired + offsetof(DBContactSettings, blob)); dbcs.cbBlob = bytesRequired; DBWrite(ofsNew, &dbcs, offsetof(DBContactSettings, blob)); if (ofsDbcsPrev == 0) { dbc.ofsFirstSettings = ofsNew; DBWrite(ofsContact, &dbc, sizeof(DBContact)); } else { dbcsPrev = (DBContactSettings*)DBRead(ofsDbcsPrev, NULL); dbcsPrev->ofsNext = ofsNew; DBWrite(ofsDbcsPrev, dbcsPrev, offsetof(DBContactSettings, blob)); } ofsBlobPtr += ofsNew - ofsSettingsGroup; ofsSettingsGroup = ofsNew; pBlob = (PBYTE)DBRead(ofsBlobPtr, &bytesRemaining); } // we now have a place to put it and enough space: make it DBWrite(ofsBlobPtr, &settingNameLen, 1); DBWrite(ofsBlobPtr + 1, (PVOID)dbcwWork.szSetting, settingNameLen); MoveAlong(1 + settingNameLen); DBWrite(ofsBlobPtr, &dbcwWork.value.type, 1); MoveAlong(1); switch (dbcwWork.value.type) { case DBVT_BYTE: DBWrite(ofsBlobPtr, &dbcwWork.value.bVal, 1); MoveAlong(1); break; case DBVT_WORD: DBWrite(ofsBlobPtr, &dbcwWork.value.wVal, 2); MoveAlong(2); break; case DBVT_DWORD: DBWrite(ofsBlobPtr, &dbcwWork.value.dVal, 4); MoveAlong(4); break; case DBVT_BLOB: DBWrite(ofsBlobPtr, &dbcwWork.value.cpbVal, 2); DBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal); MoveAlong(2 + dbcwWork.value.cpbVal); break; case DBVT_ENCRYPTED: DBWrite(ofsBlobPtr, &dbcwWork.value.cpbVal, 2); DBWrite(ofsBlobPtr + 2, dbcwWork.value.pbVal, dbcwWork.value.cpbVal); MoveAlong(2 + dbcwWork.value.cpbVal); break; case DBVT_UTF8: case DBVT_ASCIIZ: DBWrite(ofsBlobPtr, &dbcwWork.value.cchVal, 2); DBWrite(ofsBlobPtr + 2, dbcwWork.value.pszVal, dbcwWork.value.cchVal); MoveAlong(2 + dbcwWork.value.cchVal); break; } BYTE zero = 0; DBWrite(ofsBlobPtr, &zero, 1); // quit DBFlush(1); lck.unlock(); // notify NotifyEventHooks(hSettingChangeEvent, contactID, (LPARAM)&dbcwNotif); return 0; }
void CSend::svcSendMsgExit(const char* szMessage) { if (m_bSilent) { Exit(ACKRESULT_SUCCESS); return; } if (!m_hContact) { if (!m_pszFileDesc) m_pszFileDesc = mir_a2t(szMessage); Exit(CSEND_DIALOG); return; } if (m_ChatRoom) { TCHAR* tmp = mir_a2t(szMessage); if (m_pszFileDesc) { mir_tstradd(tmp, _T("\r\n")); mir_tstradd(tmp, m_pszFileDesc); } GC_INFO gci = { 0 }; int res = GC_RESULT_NOSESSION; int cnt = (int)CallService(MS_GC_GETSESSIONCOUNT, 0, (LPARAM)m_pszProto); //loop on all gc session to get the right (save) ptszID for the chatroom from m_hContact gci.pszModule = m_pszProto; for (int i = 0; i < cnt; i++) { gci.iItem = i; gci.Flags = GCF_BYINDEX | GCF_HCONTACT | GCF_ID; CallService(MS_GC_GETINFO, 0, (LPARAM)&gci); if (gci.hContact == m_hContact) { GCDEST gcd = { m_pszProto, gci.pszID, GC_EVENT_SENDMESSAGE }; GCEVENT gce = { sizeof(gce), &gcd }; gce.bIsMe = TRUE; gce.dwFlags = GCEF_ADDTOLOG; gce.ptszText = tmp; gce.time = time(NULL); //* returns 0 on success or error code on failure res = 200 + (int)CallService(MS_GC_EVENT, 0, (LPARAM)&gce); break; } } Exit(res); return; } else { mir_freeAndNil(m_szEventMsg); m_cbEventMsg = (DWORD)mir_strlen(szMessage) + 1; m_szEventMsg = (char*)mir_realloc(m_szEventMsg, (sizeof(char) * m_cbEventMsg)); memset(m_szEventMsg, 0, (sizeof(char) * m_cbEventMsg)); mir_strcpy(m_szEventMsg, szMessage); if (m_pszFileDesc && m_pszFileDesc[0] != NULL) { char *temp = mir_t2a(m_pszFileDesc); mir_stradd(m_szEventMsg, "\r\n"); mir_stradd(m_szEventMsg, temp); m_cbEventMsg = (DWORD)mir_strlen(m_szEventMsg) + 1; mir_free(temp); } //create a HookEventObj on ME_PROTO_ACK if (!m_hOnSend) { m_hOnSend = HookEventObj(ME_PROTO_ACK, OnSend, this); } //start PSS_MESSAGE service m_hSend = (HANDLE)CallContactService(m_hContact, PSS_MESSAGE, NULL, ptrA(mir_utf8encode(m_szEventMsg))); // check we actually got an ft handle back from the protocol if (!m_hSend) { Unhook(); Error(SS_ERR_INIT, m_pszSendTyp); Exit(ACKRESULT_FAILED); return; } } }
INT_PTR CALLBACK ChangeInfoDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { ChangeInfoData* dat = (ChangeInfoData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); dat = new ChangeInfoData(); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); dat->hwndDlg = hwndDlg; dat->ppro = (CIcqProto*)lParam; dat->hwndList = GetDlgItem(hwndDlg, IDC_LIST); ListView_SetExtendedListViewStyle(dat->hwndList, LVS_EX_FULLROWSELECT); dat->iEditItem = -1; { dat->hListFont = (HFONT)SendMessage(dat->hwndList, WM_GETFONT, 0, 0); LOGFONT lf; GetObject(dat->hListFont, sizeof(lf), &lf); lf.lfHeight -= 5; HFONT hFont = CreateFontIndirect(&lf); SendMessage(dat->hwndList, WM_SETFONT, (WPARAM)hFont, 0); // Prepare ListView Columns RECT rc; GetClientRect(dat->hwndList, &rc); rc.right -= GetSystemMetrics(SM_CXVSCROLL); LV_COLUMN lvc = { 0 }; lvc.mask = LVCF_WIDTH; lvc.cx = rc.right / 3; ListView_InsertColumn(dat->hwndList, 0, &lvc); lvc.cx = rc.right - lvc.cx; ListView_InsertColumn(dat->hwndList, 1, &lvc); // Prepare Setting Items LV_ITEM lvi = { 0 }; lvi.mask = LVIF_PARAM | LVIF_TEXT; for (lvi.iItem = 0; lvi.iItem < settingCount; lvi.iItem++) { TCHAR text[MAX_PATH]; lvi.lParam = lvi.iItem; lvi.pszText = text; utf8_to_tchar_static(setting[lvi.iItem].szDescription, text, _countof(text)); ListView_InsertItem(dat->hwndList, &lvi); } } SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); return TRUE; case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case 0: switch (((LPNMHDR)lParam)->code) { case PSN_PARAMCHANGED: dat->ppro = (CIcqProto*)((PSHNOTIFY*)lParam)->lParam; dat->LoadSettingsFromDb(0); { char *pwd = dat->ppro->GetUserPassword(TRUE); mir_strcpy(dat->Password, (pwd) ? pwd : ""); /// FIXME } break; case PSN_INFOCHANGED: dat->LoadSettingsFromDb(1); break; case PSN_KILLACTIVE: dat->EndStringEdit(1); dat->EndListEdit(1); break; case PSN_APPLY: if (dat->ChangesMade()) { if (MessageBox(hwndDlg, TranslateT("You've made some changes to your ICQ details but it has not been saved to the server. Are you sure you want to close this dialog?"), TranslateT("Change ICQ Details"), MB_YESNOCANCEL) != IDYES) { SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); return TRUE; } } } break; case IDC_LIST: switch (((LPNMHDR)lParam)->code) { case LVN_GETDISPINFO: if (dat->iEditItem != -1) { if (dat->editTopIndex != ListView_GetTopIndex(dat->hwndList)) { dat->EndStringEdit(1); dat->EndListEdit(1); } } break; case NM_CUSTOMDRAW: { LPNMLVCUSTOMDRAW cd = (LPNMLVCUSTOMDRAW)lParam; switch (cd->nmcd.dwDrawStage) { case CDDS_PREPAINT: SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW); return TRUE; case CDDS_ITEMPREPAINT: if (dat->iEditItem != -1) { if (dat->editTopIndex != ListView_GetTopIndex(dat->hwndList)) { dat->EndStringEdit(1); dat->EndListEdit(1); } } { RECT rcItem; ListView_GetItemRect(dat->hwndList, cd->nmcd.dwItemSpec, &rcItem, LVIR_BOUNDS); if (GetWindowLongPtr(dat->hwndList, GWL_STYLE) & WS_DISABLED) { // Disabled List SetTextColor(cd->nmcd.hdc, cd->clrText); FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_3DFACE)); } else if ((cd->nmcd.uItemState & CDIS_SELECTED || dat->iEditItem == (int)cd->nmcd.dwItemSpec) && setting[cd->nmcd.lItemlParam].displayType != LI_DIVIDER) { // Selected item SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_HIGHLIGHT)); } else { // Unselected item SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_WINDOWTEXT)); FillRect(cd->nmcd.hdc, &rcItem, GetSysColorBrush(COLOR_WINDOW)); } HFONT hoFont = (HFONT)SelectObject(cd->nmcd.hdc, dat->hListFont); if (setting[cd->nmcd.lItemlParam].displayType == LI_DIVIDER) { RECT rcLine; SIZE textSize; char str[MAX_PATH]; char *szText = ICQTranslateUtfStatic(setting[cd->nmcd.lItemlParam].szDescription, str, MAX_PATH); SetTextColor(cd->nmcd.hdc, GetSysColor(COLOR_3DSHADOW)); DrawTextUtf(cd->nmcd.hdc, szText, &rcItem, DT_CENTER | DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER, &textSize); rcLine.top = (rcItem.top + rcItem.bottom) / 2 - 1; rcLine.bottom = rcLine.top + 2; rcLine.left = rcItem.left + 3; rcLine.right = (rcItem.left + rcItem.right - textSize.cx) / 2 - 3; DrawEdge(cd->nmcd.hdc, &rcLine, BDR_SUNKENOUTER, BF_RECT); rcLine.left = (rcItem.left + rcItem.right + textSize.cx) / 2 + 3; rcLine.right = rcItem.right - 3; DrawEdge(cd->nmcd.hdc, &rcLine, BDR_SUNKENOUTER, BF_RECT); } else { RECT rcItemDescr, rcItemValue; char str[MAX_PATH]; ListView_GetSubItemRect(dat->hwndList, cd->nmcd.dwItemSpec, 0, LVIR_BOUNDS, &rcItemDescr); ListView_GetSubItemRect(dat->hwndList, cd->nmcd.dwItemSpec, 1, LVIR_BOUNDS, &rcItemValue); rcItemDescr.right = rcItemValue.left; rcItemDescr.left += 2; DrawTextUtf(cd->nmcd.hdc, ICQTranslateUtfStatic(setting[cd->nmcd.lItemlParam].szDescription, str, MAX_PATH), &rcItemDescr, DT_END_ELLIPSIS | DT_LEFT | DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER, NULL); dat->PaintItemSetting(cd->nmcd.hdc, &rcItemValue, cd->nmcd.lItemlParam, cd->nmcd.uItemState); } SelectObject(cd->nmcd.hdc, hoFont); SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); return TRUE; } } } break; case NM_CLICK: { LPNMLISTVIEW nm = (LPNMLISTVIEW)lParam; LV_ITEM lvi; RECT rc; dat->EndStringEdit(1); dat->EndListEdit(1); if (nm->iSubItem != 1) break; lvi.mask = LVIF_PARAM | LVIF_STATE; lvi.stateMask = 0xFFFFFFFF; lvi.iItem = nm->iItem; lvi.iSubItem = nm->iSubItem; ListView_GetItem(dat->hwndList, &lvi); if (!(lvi.state & LVIS_SELECTED)) break; ListView_EnsureVisible(dat->hwndList, lvi.iItem, FALSE); ListView_GetSubItemRect(dat->hwndList, lvi.iItem, lvi.iSubItem, LVIR_BOUNDS, &rc); dat->editTopIndex = ListView_GetTopIndex(dat->hwndList); switch (setting[lvi.lParam].displayType & LIM_TYPE) { case LI_STRING: case LI_LONGSTRING: case LI_NUMBER: dat->BeginStringEdit(nm->iItem, &rc, lvi.lParam, 0); break; case LI_LIST: dat->BeginListEdit(nm->iItem, &rc, lvi.lParam, 0); break; } } break; case LVN_KEYDOWN: { LPNMLVKEYDOWN nm = (LPNMLVKEYDOWN)lParam; LV_ITEM lvi; RECT rc; dat->EndStringEdit(1); dat->EndListEdit(1); if (nm->wVKey == VK_SPACE || nm->wVKey == VK_RETURN || nm->wVKey == VK_F2) nm->wVKey = 0; if (nm->wVKey && (nm->wVKey<'0' || (nm->wVKey>'9' && nm->wVKey<'A') || (nm->wVKey>'Z' && nm->wVKey < VK_NUMPAD0) || nm->wVKey >= VK_F1)) break; lvi.mask = LVIF_PARAM | LVIF_STATE; lvi.stateMask = 0xFFFFFFFF; lvi.iItem = ListView_GetNextItem(dat->hwndList, -1, LVNI_ALL | LVNI_SELECTED); if (lvi.iItem == -1) break; lvi.iSubItem = 1; ListView_GetItem(dat->hwndList, &lvi); ListView_EnsureVisible(dat->hwndList, lvi.iItem, FALSE); ListView_GetSubItemRect(dat->hwndList, lvi.iItem, lvi.iSubItem, LVIR_BOUNDS, &rc); dat->editTopIndex = ListView_GetTopIndex(dat->hwndList); switch (setting[lvi.lParam].displayType & LIM_TYPE) { case LI_STRING: case LI_LONGSTRING: case LI_NUMBER: dat->BeginStringEdit(lvi.iItem, &rc, lvi.lParam, nm->wVKey); break; case LI_LIST: dat->BeginListEdit(lvi.iItem, &rc, lvi.lParam, nm->wVKey); break; } SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); } return TRUE; case NM_KILLFOCUS: if (!IsStringEditWindow(GetFocus())) dat->EndStringEdit(1); if (!IsListEditWindow(GetFocus())) dat->EndListEdit(1); } } break; case WM_KILLFOCUS: dat->EndStringEdit(1); dat->EndListEdit(1); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: SendMessage(GetParent(hwndDlg), msg, wParam, lParam); break; case IDC_SAVE: if (!dat->SaveSettingsToDb(hwndDlg)) break; EnableDlgItem(hwndDlg, IDC_SAVE, FALSE); EnableDlgItem(hwndDlg, IDC_LIST, FALSE); SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload in progress...")); EnableDlgItem(hwndDlg, IDC_UPLOADING, TRUE); ShowDlgItem(hwndDlg, IDC_UPLOADING, SW_SHOW); dat->hAckHook = HookEventMessage(ME_PROTO_ACK, hwndDlg, DM_PROTOACK); if (!dat->UploadSettings()) { EnableDlgItem(hwndDlg, IDC_SAVE, TRUE); EnableDlgItem(hwndDlg, IDC_LIST, TRUE); ShowDlgItem(hwndDlg, IDC_UPLOADING, SW_HIDE); UnhookEvent(dat->hAckHook); dat->hAckHook = NULL; } } break; case WM_SIZE: if (IsIconic(hwndDlg)) break; Utils_ResizeDialog(hwndDlg, hInst, MAKEINTRESOURCEA(IDD_INFO_CHANGEINFO), ChangeInfoDlg_Resize); { RECT rc; // update listview column widths GetClientRect(dat->hwndList, &rc); rc.right -= GetSystemMetrics(SM_CXVSCROLL); ListView_SetColumnWidth(dat->hwndList, 0, rc.right / 3); ListView_SetColumnWidth(dat->hwndList, 1, rc.right - rc.right / 3); } break; case DM_PROTOACK: { ACKDATA *ack = (ACKDATA*)lParam; int i, done; if (ack->type != ACKTYPE_SETINFO) break; if (ack->result == ACKRESULT_SUCCESS) { for (i = 0; i < _countof(dat->hUpload); i++) if (dat->hUpload[i] && ack->hProcess == dat->hUpload[i]) break; if (i == _countof(dat->hUpload)) break; dat->hUpload[i] = NULL; for (done = 0, i = 0; i < _countof(dat->hUpload); i++) done += dat->hUpload[i] == NULL; TCHAR buf[MAX_PATH]; mir_sntprintf(buf, TranslateT("Upload in progress...%d%%"), 100 * done / (_countof(dat->hUpload))); SetDlgItemText(hwndDlg, IDC_UPLOADING, buf); if (done < _countof(dat->hUpload)) break; dat->ClearChangeFlags(); UnhookEvent(dat->hAckHook); dat->hAckHook = NULL; EnableDlgItem(hwndDlg, IDC_LIST, TRUE); EnableDlgItem(hwndDlg, IDC_UPLOADING, FALSE); SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload complete")); SendMessage(GetParent(hwndDlg), PSM_FORCECHANGED, 0, 0); } else if (ack->result == ACKRESULT_FAILED) { UnhookEvent(dat->hAckHook); dat->hAckHook = NULL; EnableDlgItem(hwndDlg, IDC_LIST, TRUE); EnableDlgItem(hwndDlg, IDC_UPLOADING, FALSE); SetDlgItemText(hwndDlg, IDC_UPLOADING, TranslateT("Upload FAILED")); SendMessage(GetParent(hwndDlg), PSM_FORCECHANGED, 0, 0); EnableDlgItem(hwndDlg, IDC_SAVE, TRUE); } } break; case WM_DESTROY: if (dat->hAckHook) { UnhookEvent(dat->hAckHook); dat->hAckHook = NULL; } DeleteObject((HFONT)SendMessage(dat->hwndList, WM_GETFONT, 0, 0)); dat->FreeStoredDbSettings(); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); delete dat; break; } return FALSE; }
void TlenProtocol::initMenuItems() { char text[MAX_PATH]; strncpy_s(text, m_szModuleName, _TRUNCATE); char *pSvcName = text + mir_strlen(text); CMenuItem mi; mi.root = hMenuRoot = Menu_CreateRoot(MO_MAIN, m_tszUserName, -1999901009, GetIconHandle(IDI_TLEN)); mi.pszService = text; hMenuChats = NULL; // "Multi-User Conference" SET_UID(mi,0x4984828, 0x2066, 0x43da, 0x87, 0x9e, 0x71, 0x23, 0xc6, 0xe2, 0x46, 0xd5); mir_strcpy(pSvcName, "/MainMenuMUC"); CreateProtoService(pSvcName, &TlenProtocol::MUCMenuHandleMUC); mi.name.a = LPGEN("Multi-User Conference"); mi.position = 2000050002; mi.hIcolibItem = GetIconHandle(IDI_MUC); mi.pszService = text; hMenuMUC = Menu_AddMainMenuItem(&mi); SET_UID(mi, 0x594133f1, 0xc5b1, 0x4825, 0xa3, 0x8d, 0x33, 0x0, 0x33, 0x74, 0x3a, 0x29); mir_strcpy(pSvcName, "/MainMenuInbox"); CreateProtoService(pSvcName, &TlenProtocol::MenuHandleInbox); mi.name.a = LPGEN("Tlen Mail"); mi.position = 2000050003; mi.hIcolibItem = GetIconHandle(IDI_MAIL); mi.pszService = text; hMenuInbox = Menu_AddMainMenuItem(&mi); // contact menu items mi.root = NULL; // "Send picture" SET_UID(mi, 0x12c66fb1, 0x6e57, 0x4acd, 0x90, 0x16, 0xc, 0x83, 0xae, 0x16, 0xe3, 0x12); mi.pszService = "/SendPicture"; CreateProtoService(mi.pszService, &TlenProtocol::ContactMenuHandleSendPicture); mi.name.a = LPGEN("Send picture"); mi.position = -2000019030; mi.hIcolibItem = GetIconHandle(IDI_IMAGE); hMenuPicture = Menu_AddContactMenuItem(&mi, m_szModuleName); // "Invite to MUC" SET_UID(mi, 0x4728c863, 0xe95f, 0x4203, 0x9b, 0xe8, 0x1, 0xbf, 0x5e, 0x57, 0x88, 0x43); mi.pszService = "/ContactMenuMUC"; CreateProtoService(mi.pszService, &TlenProtocol::MUCContactMenuHandleMUC); mi.name.a = LPGEN("Multi-User Conference"); mi.position = -2000019020; mi.hIcolibItem = GetIconHandle(IDI_MUC); hMenuContactMUC = Menu_AddContactMenuItem(&mi, m_szModuleName); // "Invite to voice chat" SET_UID(mi, 0x53f919b6, 0x313c, 0x4ed4, 0x96, 0xbc, 0xf6, 0xa2, 0x67, 0x10, 0x7b, 0xa2); mi.pszService = "/ContactMenuVoice"; CreateProtoService(mi.pszService, &TlenProtocol::VoiceContactMenuHandleVoice); mi.name.a = LPGEN("Voice Chat"); mi.position = -2000019010; mi.hIcolibItem = GetIconHandle(IDI_VOICE); hMenuContactVoice = Menu_AddContactMenuItem(&mi, m_szModuleName); // "Request authorization" SET_UID(mi, 0x36375a1f, 0xc142, 0x4d6e, 0xa6, 0x57, 0xe4, 0x76, 0x5d, 0xbc, 0x59, 0x8e); mi.pszService = "/RequestAuth"; CreateProtoService(mi.pszService, &TlenProtocol::ContactMenuHandleRequestAuth); mi.name.a = LPGEN("Request authorization"); mi.position = -2000001001; mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_REQUEST); hMenuContactRequestAuth = Menu_AddContactMenuItem(&mi, m_szModuleName); // "Grant authorization" SET_UID(mi, 0x4c90452a, 0x869a, 0x4a81, 0xaf, 0xa8, 0x28, 0x34, 0xaf, 0x2b, 0x6b, 0x30); mi.pszService = "/GrantAuth"; CreateProtoService(mi.pszService, &TlenProtocol::ContactMenuHandleGrantAuth); mi.name.a = LPGEN("Grant authorization"); mi.position = -2000001000; mi.hIcolibItem = Skin_GetIconHandle(SKINICON_AUTH_GRANT); hMenuContactGrantAuth = Menu_AddContactMenuItem(&mi, m_szModuleName); }
// request avatar data from server int CIcqProto::GetAvatarData(MCONTACT hContact, DWORD dwUin, const char *szUid, const BYTE *hash, size_t hashlen, const TCHAR *file) { uid_str szUidData; char *pszUid = NULL; if (!dwUin && szUid) { // create a copy in local writable buffer mir_strcpy(szUidData, szUid); pszUid = szUidData; } mir_cslockfull alck(m_avatarsMutex); if (m_avatarsConnection && m_avatarsConnection->isReady()) { // check if we are ready // check if requests for this user are not blocked for (int i = 0; i < m_arAvatars.getCount();) { avatars_request *ar = m_arAvatars[i]; if (ar->hContact == hContact && ar->type == ART_BLOCK) { // found a block item if (GetTickCount() > ar->timeOut) { // remove timeouted block m_arAvatars.remove(i); delete ar; continue; } debugLogA("Avatars: Requests for %s avatar are blocked.", strUID(dwUin, pszUid)); return 0; } i++; } mir_cslock l(m_avatarsConnection->getLock()); alck.unlock(); DWORD dwCookie = m_avatarsConnection->sendGetAvatarRequest(hContact, dwUin, pszUid, hash, hashlen, file); if (dwCookie) // return now if the request was sent successfully return dwCookie; alck.lock(); } // we failed to send request, or avatar thread not ready // check if any request for this user is not already in the queue for (int i = 0; i < m_arAvatars.getCount();) { avatars_request *ar = m_arAvatars[i]; if (ar->hContact == hContact) { // we found it, return error if (ar->type == ART_BLOCK && GetTickCount() > ar->timeOut) { // remove timeouted block m_arAvatars.remove(i); delete ar; continue; } alck.unlock(); debugLogA("Avatars: Ignoring duplicate get %s avatar request.", strUID(dwUin, pszUid)); // make sure avatar connection is in progress requestAvatarConnection(); return 0; } i++; } // add request to queue, processed after successful login avatars_request *ar = new avatars_request(ART_GET); // get avatar ar->hContact = hContact; ar->dwUin = dwUin; if (!dwUin) mir_strcpy(ar->szUid, szUid); ar->hash = (BYTE*)SAFE_MALLOC(hashlen); if (!ar->hash) { // alloc failed delete ar; return 0; } memcpy(ar->hash, hash, hashlen); // copy the data ar->hashlen = hashlen; ar->szFile = null_strdup(file); // duplicate the string m_arAvatars.insert(ar); alck.unlock(); debugLogA("Avatars: Request to get %s image added to queue.", strUID(dwUin, pszUid)); // make sure avatar connection is in progress requestAvatarConnection(); return -1; // we added to queue }
void StreamInEvents(HWND hwndDlg, MEVENT hDbEventFirst, int count, int fAppend) { SrmmWindowData *dat = (SrmmWindowData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); CHARRANGE oldSel, sel; BOOL bottomScroll = TRUE; POINT scrollPos; HWND hwndLog = GetDlgItem(hwndDlg, IDC_LOG); SendMessage(hwndLog, WM_SETREDRAW, FALSE, 0); SendMessage(hwndLog, EM_EXGETSEL, 0, (LPARAM)& oldSel); LogStreamData streamData = { 0 }; streamData.hContact = dat->hContact; streamData.hDbEvent = hDbEventFirst; streamData.dlgDat = dat; streamData.eventsToInsert = count; streamData.isEmpty = !fAppend || GetWindowTextLength(hwndLog) == 0; EDITSTREAM stream = { 0 }; stream.pfnCallback = LogStreamInEvents; stream.dwCookie = (DWORD_PTR)&streamData; if (!streamData.isEmpty) { bottomScroll = (GetFocus() != hwndLog); if (bottomScroll && (GetWindowLongPtr(hwndLog, GWL_STYLE) & WS_VSCROLL)) { SCROLLINFO si = { 0 }; si.cbSize = sizeof(si); si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS; GetScrollInfo(hwndLog, SB_VERT, &si); bottomScroll = (si.nPos + (int)si.nPage) >= si.nMax; } if (!bottomScroll) SendMessage(hwndLog, EM_GETSCROLLPOS, 0, (LPARAM)&scrollPos); } if (fAppend) { sel.cpMin = sel.cpMax = -1; SendMessage(hwndLog, EM_EXSETSEL, 0, (LPARAM)& sel); } mir_strcpy(szSep2, fAppend ? "\\par\\sl0" : "\\sl1000"); mir_strcpy(szSep2_RTL, fAppend ? "\\rtlpar\\rtlmark\\par\\sl1000" : "\\sl1000"); SendMessage(hwndLog, EM_STREAMIN, fAppend ? SFF_SELECTION | SF_RTF : SF_RTF, (LPARAM)& stream); if (bottomScroll) { sel.cpMin = sel.cpMax = -1; SendMessage(hwndLog, EM_EXSETSEL, 0, (LPARAM)&sel); if (GetWindowLongPtr(hwndLog, GWL_STYLE) & WS_VSCROLL) { SendMessage(hwndDlg, DM_SCROLLLOGTOBOTTOM, 0, 0); PostMessage(hwndDlg, DM_SCROLLLOGTOBOTTOM, 0, 0); } } else { SendMessage(hwndLog, EM_EXSETSEL, 0, (LPARAM)&oldSel); SendMessage(hwndLog, EM_SETSCROLLPOS, 0, (LPARAM)&scrollPos); } SendMessage(hwndLog, WM_SETREDRAW, TRUE, 0); if (bottomScroll) RedrawWindow(hwndLog, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); dat->hDbEventLast = streamData.hDbEventLast; }
static void InitFonts() { font_id_firstline.cbSize = sizeof(FontIDT); font_id_firstline.flags = FIDF_ALLOWEFFECTS; mir_tstrcpy(font_id_firstline.group, LPGENT("Popups")); mir_tstrcpy(font_id_firstline.name, LPGENT("First line")); mir_strcpy(font_id_firstline.dbSettingsGroup, MODULE); mir_strcpy(font_id_firstline.prefix, "FontFirst"); mir_tstrcpy(font_id_firstline.backgroundGroup, _T("Popups")); mir_tstrcpy(font_id_firstline.backgroundName, _T("Background")); font_id_firstline.order = 0; FontRegisterT(&font_id_firstline); font_id_secondline.cbSize = sizeof(FontIDT); font_id_secondline.flags = FIDF_ALLOWEFFECTS; mir_tstrcpy(font_id_secondline.group, LPGENT("Popups")); mir_tstrcpy(font_id_secondline.name, LPGENT("Second line")); mir_strcpy(font_id_secondline.dbSettingsGroup, MODULE); mir_strcpy(font_id_secondline.prefix, "FontSecond"); mir_tstrcpy(font_id_secondline.backgroundGroup, _T("Popups")); mir_tstrcpy(font_id_secondline.backgroundName, _T("Background")); font_id_secondline.order = 1; FontRegisterT(&font_id_secondline); font_id_time.cbSize = sizeof(FontIDT); font_id_time.flags = FIDF_ALLOWEFFECTS; mir_tstrcpy(font_id_time.group, LPGENT("Popups")); mir_tstrcpy(font_id_time.name, LPGENT("Time")); mir_strcpy(font_id_time.dbSettingsGroup, MODULE); mir_strcpy(font_id_time.prefix, "FontTime"); mir_tstrcpy(font_id_time.backgroundGroup, _T("Popups")); mir_tstrcpy(font_id_time.backgroundName, _T("Background")); font_id_time.order = 2; FontRegisterT(&font_id_time); colour_id_bg.cbSize = sizeof(ColourIDT); mir_tstrcpy(colour_id_bg.group, LPGENT("Popups")); mir_tstrcpy(colour_id_bg.name, LPGENT("Background")); mir_strcpy(colour_id_bg.dbSettingsGroup, MODULE); mir_strcpy(colour_id_bg.setting, "ColourBg"); colour_id_bg.defcolour = GetSysColor(COLOR_3DSHADOW); colour_id_bg.order = 0; ColourRegisterT(&colour_id_bg); colour_id_border.cbSize = sizeof(ColourIDT); mir_tstrcpy(colour_id_border.group, LPGENT("Popups")); mir_tstrcpy(colour_id_border.name, LPGENT("Border")); mir_strcpy(colour_id_border.dbSettingsGroup, MODULE); mir_strcpy(colour_id_border.setting, "ColourBorder"); colour_id_border.defcolour = RGB(0, 0, 0); colour_id_border.order = 1; ColourRegisterT(&colour_id_border); colour_id_sidebar.cbSize = sizeof(ColourIDT); mir_tstrcpy(colour_id_sidebar.group, LPGENT("Popups")); mir_tstrcpy(colour_id_sidebar.name, LPGENT("Sidebar")); mir_strcpy(colour_id_sidebar.dbSettingsGroup, MODULE); mir_strcpy(colour_id_sidebar.setting, "ColourSidebar"); colour_id_sidebar.defcolour = RGB(128, 128, 128); colour_id_sidebar.order = 2; ColourRegisterT(&colour_id_sidebar); colour_id_titleunderline.cbSize = sizeof(ColourIDT); mir_tstrcpy(colour_id_titleunderline.group, LPGENT("Popups")); mir_tstrcpy(colour_id_titleunderline.name, LPGENT("Title underline")); mir_strcpy(colour_id_titleunderline.dbSettingsGroup, MODULE); mir_strcpy(colour_id_titleunderline.setting, "ColourTitleUnderline"); colour_id_titleunderline.defcolour = GetSysColor(COLOR_3DSHADOW); colour_id_titleunderline.order = 3; ColourRegisterT(&colour_id_titleunderline); ReloadFont(0, 0); }
static INT_PTR CALLBACK DlgProcOptNet(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { CSametimeProto* proto = (CSametimeProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); proto = (CSametimeProto*)lParam; WORD client_ver = proto->GetClientVersion(); if (client_ver) { TCHAR verbuf[100]; mir_sntprintf(verbuf, _countof(verbuf), TranslateT("Client protocol version: %03d.%03d"), (client_ver & 0xFF00) >> 8, client_ver & 0xFF); SetDlgItemText(hwndDlg, IDC_ST_CLIENTVER, verbuf); } WORD server_ver = proto->GetServerVersion(); if (server_ver) { TCHAR verbuf[100]; mir_sntprintf(verbuf, _countof(verbuf), TranslateT("Server protocol version: %03d.%03d"), (server_ver & 0xFF00) >> 8, server_ver & 0xFF); SetDlgItemText(hwndDlg, IDC_ST_SERVERVER, verbuf); } TCHAR *s = mir_utf8decodeT(proto->options.server_name); SetDlgItemText(hwndDlg, IDC_ED_SNAME, s); mir_free(s); s = mir_utf8decodeT(proto->options.id); SetDlgItemText(hwndDlg, IDC_ED_NAME, s); mir_free(s); s = mir_utf8decodeT(proto->options.pword); SetDlgItemText(hwndDlg, IDC_ED_PWORD, s); mir_free(s); SetDlgItemInt(hwndDlg, IDC_ED_PORT, proto->options.port, FALSE); CheckDlgButton(hwndDlg, IDC_CHK_GETSERVERCONTACTS, proto->options.get_server_contacts ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_CHK_ADDCONTACTS, proto->options.add_contacts ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_CHK_IDLEAWAY, proto->options.idle_as_away ? BST_CHECKED : BST_UNCHECKED); SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_RESETCONTENT, 0, 0); int pos = 0; bool found = false; for (int i = 0; i < NUM_IDS; i++) { pos = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_ADDSTRING, -1, (LPARAM)client_names[i]); SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_SETITEMDATA, pos, client_ids[i]); if (client_ids[i] == proto->options.client_id) { found = true; SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_SETCURSEL, pos, 0); SetDlgItemInt(hwndDlg, IDC_ED_CLIENTID, client_ids[i], FALSE); if (i != sizeof(client_ids) / sizeof(int)-1) { HWND hw = GetDlgItem(hwndDlg, IDC_ED_CLIENTID); EnableWindow(hw, false); } } } if (!found) { SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_SETCURSEL, pos, 0); // pos is last item, i.e. custom SetDlgItemInt(hwndDlg, IDC_ED_CLIENTID, proto->options.client_id, FALSE); } SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_RESETCONTENT, 0, 0); pos = 0; for (int i = 0; i < NUM_CVS; i++) { pos = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_ADDSTRING, -1, (LPARAM)CV_names[i]); SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_SETITEMDATA, pos, i); if (CV_major[i] == proto->options.client_versionMajor && CV_minor[i] == proto->options.client_versionMinor) { found = true; SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_SETCURSEL, pos, 0); } } if (!ServiceExists(MS_POPUP_ADDPOPUPT)) { HWND hw = GetDlgItem(hwndDlg, IDC_RAD_ERRPOP); EnableWindow(hw, FALSE); } if (!ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) { HWND hw = GetDlgItem(hwndDlg, IDC_RAD_ERRBAL); EnableWindow(hw, FALSE); } switch (proto->options.err_method) { case ED_POP: CheckDlgButton(hwndDlg, IDC_RAD_ERRPOP, BST_CHECKED); break; case ED_MB: CheckDlgButton(hwndDlg, IDC_RAD_ERRMB, BST_CHECKED); break; case ED_BAL: CheckDlgButton(hwndDlg, IDC_RAD_ERRBAL, BST_CHECKED); break; } if (proto->options.encrypt_session) CheckDlgButton(hwndDlg, IDC_RAD_ENC, BST_CHECKED); else CheckDlgButton(hwndDlg, IDC_RAD_NOENC, BST_CHECKED); return FALSE; } case WM_COMMAND: if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); if (HIWORD(wParam) == CBN_SELCHANGE) { switch (LOWORD(wParam)) { case IDC_CMB_CLIENT: { int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_GETCURSEL, 0, 0); int id = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_GETITEMDATA, sel, 0); bool custom = (id == client_ids[sizeof(client_ids) / sizeof(int)-1]); if (!custom) SetDlgItemInt(hwndDlg, IDC_ED_CLIENTID, id, FALSE); else SetDlgItemInt(hwndDlg, IDC_ED_CLIENTID, DEFAULT_ID, FALSE); HWND hw = GetDlgItem(hwndDlg, IDC_ED_CLIENTID); EnableWindow(hw, custom); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); return TRUE; } case IDC_CMB_CLIENTVN: { SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); return TRUE; } } } if (HIWORD(wParam) == BN_CLICKED) { switch (LOWORD(wParam)) { case IDC_BTN_UPLOADCONTACTS: { EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UPLOADCONTACTS), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_IMPORTCONTACTS), FALSE); proto->ExportContactsToServer(); SendMessage(hwndDlg, WMU_STORECOMPLETE, 0, 0); } return TRUE; case IDC_BTN_IMPORTCONTACTS: { TCHAR import_filename[MAX_PATH]; import_filename[0] = 0; OPENFILENAME ofn = { 0 }; ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = import_filename; ofn.hwndOwner = hwndDlg; ofn.Flags = CC_FULLOPEN; ofn.nMaxFile = MAX_PATH; ofn.lpstrFilter = _T("All\0*.*\0"); ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = NULL; ofn.Flags = OFN_PATHMUSTEXIST; if (GetOpenFileName(&ofn) == TRUE) { HWND hBut = GetDlgItem(hwndDlg, IDC_BTN_UPLOADCONTACTS); EnableWindow(hBut, FALSE); hBut = GetDlgItem(hwndDlg, IDC_BTN_IMPORTCONTACTS); EnableWindow(hBut, FALSE); proto->ImportContactsFromFile(ofn.lpstrFile); SendMessage(hwndDlg, WMU_STORECOMPLETE, 0, 0); } } return TRUE; case IDC_CHK_GETSERVERCONTACTS: case IDC_CHK_ENCMESSAGES: case IDC_RAD_ERRMB: case IDC_RAD_ERRBAL: case IDC_RAD_ERRPOP: case IDC_CHK_USERCP: case IDC_CHK_ADDCONTACTS: case IDC_CHK_IDLEAWAY: case IDC_RAD_ENC: case IDC_RAD_NOENC: SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); return TRUE; case IDC_RAD_ANSI: case IDC_RAD_UTF8: case IDC_RAD_OEM: case IDC_RAD_UTF7: case IDC_RAD_USERCP: HWND hw = GetDlgItem(hwndDlg, IDC_CHK_USERCP); EnableWindow(hw, BST_UNCHECKED == IsDlgButtonChecked(hwndDlg, IDC_RAD_USERCP)); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); return TRUE; } } break; case WMU_STORECOMPLETE: EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UPLOADCONTACTS), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_IMPORTCONTACTS), TRUE); return TRUE; case WM_NOTIFY: if (((LPNMHDR)lParam)->code == PSN_APPLY) { TCHAR ws[2048]; GetDlgItemText(hwndDlg, IDC_ED_SNAME, ws, LSTRINGLEN); mir_strcpy(proto->options.server_name, T2Utf(ws)); GetDlgItemText(hwndDlg, IDC_ED_NAME, ws, LSTRINGLEN); mir_strcpy(proto->options.id, T2Utf(ws)); GetDlgItemText(hwndDlg, IDC_ED_PWORD, ws, LSTRINGLEN); mir_strcpy(proto->options.pword, T2Utf(ws)); BOOL translated; int port = GetDlgItemInt(hwndDlg, IDC_ED_PORT, &translated, FALSE); if (translated) proto->options.port = port; proto->options.get_server_contacts = (IsDlgButtonChecked(hwndDlg, IDC_CHK_GETSERVERCONTACTS) != FALSE); int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_GETCURSEL, 0, 0); int id = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_GETITEMDATA, sel, 0); if (id == client_ids[sizeof(client_ids) / sizeof(int)-1]) { BOOL trans; id = GetDlgItemInt(hwndDlg, IDC_ED_CLIENTID, &trans, FALSE); if (trans) proto->options.client_id = id; } else proto->options.client_id = id; sel = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_GETCURSEL, 0, 0); int CVpos = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_GETITEMDATA, sel, 0); proto->options.client_versionMajor = CV_major[CVpos]; proto->options.client_versionMinor = CV_minor[CVpos]; if (IsDlgButtonChecked(hwndDlg, IDC_RAD_ERRMB)) proto->options.err_method = ED_MB; else if (IsDlgButtonChecked(hwndDlg, IDC_RAD_ERRBAL)) proto->options.err_method = ED_BAL; else if (IsDlgButtonChecked(hwndDlg, IDC_RAD_ERRPOP)) proto->options.err_method = ED_POP; proto->options.add_contacts = (IsDlgButtonChecked(hwndDlg, IDC_CHK_ADDCONTACTS) != FALSE); proto->options.encrypt_session = (IsDlgButtonChecked(hwndDlg, IDC_RAD_ENC) != FALSE); proto->options.idle_as_away = (IsDlgButtonChecked(hwndDlg, IDC_CHK_IDLEAWAY) != FALSE); proto->SaveOptions(); return TRUE; } break; case WM_DESTROY: break; } return FALSE; }