INT_PTR CDropbox::ProtoSendFile(void *obj, WPARAM, LPARAM lParam) { CDropbox *instance = (CDropbox*)obj; if (!instance->HasAccessToken()) return ACKRESULT_FAILED; CCSDATA *pccsd = (CCSDATA*)lParam; FileTransferParam *ftp = new FileTransferParam(); ftp->pfts.flags |= PFTS_SENDING; ftp->pfts.hContact = pccsd->hContact; ftp->hContact = (instance->hTransferContact) ? instance->hTransferContact : pccsd->hContact; instance->hTransferContact = 0; wchar_t **paths = (wchar_t**)pccsd->lParam; for (int i = 0; paths[i]; i++) { if (PathIsDirectory(paths[i])) ftp->totalFolders++; else ftp->pfts.totalFiles++; } ftp->pwszFolders = (wchar_t**)mir_alloc(sizeof(wchar_t*) * (ftp->totalFolders + 1)); ftp->pwszFolders[ftp->totalFolders] = NULL; ftp->pfts.pwszFiles = (wchar_t**)mir_alloc(sizeof(wchar_t*) * (ftp->pfts.totalFiles + 1)); ftp->pfts.pwszFiles[ftp->pfts.totalFiles] = NULL; for (int i = 0, j = 0, k = 0; paths[i]; i++) { if (PathIsDirectory(paths[i])) { if (!ftp->relativePathStart) { wchar_t *rootFolder = paths[j]; wchar_t *relativePath = wcsrchr(rootFolder, '\\') + 1; ftp->relativePathStart = relativePath - rootFolder; } ftp->pwszFolders[j] = mir_wstrdup(&paths[i][ftp->relativePathStart]); j++; } else { if (!ftp->pfts.wszWorkingDir) { wchar_t *path = paths[j]; int length = wcsrchr(path, '\\') - path; ftp->pfts.wszWorkingDir = (wchar_t*)mir_alloc(sizeof(wchar_t) * (length + 1)); lstrcpyn(ftp->pfts.wszWorkingDir, paths[j], length + 1); ftp->pfts.wszWorkingDir[length] = '\0'; } ftp->pfts.pwszFiles[k] = mir_wstrdup(paths[i]); FILE *file = _wfopen(paths[i], L"rb"); if (file != NULL) { fseek(file, 0, SEEK_END); ftp->pfts.totalBytes += ftell(file); fseek(file, 0, SEEK_SET); fclose(file); } k++; } } ULONG fileId = InterlockedIncrement(&instance->hFileProcess); ftp->hProcess = (HANDLE)fileId; mir_forkthreadowner(CDropbox::SendFilesAndReportAsync, obj, ftp, 0); return fileId; }
bool ipcGetSortedContacts(THeaderIPC *ipch, int *pSlot, bool bGroupMode) { DBVARIANT dbv; int n, rc; bool Result = false; // hide offliners? bool bHideOffline = db_get_b(0, "CList", "HideOffline", 0) == 1; // do they wanna hide the offline people anyway? if (db_get_b(0, SHLExt_Name, SHLExt_ShowNoOffline, 0) == 1) // hide offline people bHideOffline = true; // get the number of contacts int dwContacts = (int)CallService(MS_DB_CONTACT_GETCOUNT, 0, 0); if (dwContacts == 0) return false; // get the contacts in the array to be sorted by status, trim out anyone // who doesn't wanna be seen. TSlotInfo *pContacts = (TSlotInfo*)mir_alloc((dwContacts + 2) * sizeof(TSlotInfo)); int i = 0; int dwOnline = 0; for (MCONTACT hContact = db_find_first(); hContact != 0; hContact = db_find_next(hContact)) { if (i >= dwContacts) break; // do they have a running protocol? char *szProto = GetContactProto(hContact); if (szProto != NULL) { // does it support file sends? DWORD dwCaps = ProtoCallService(szProto, PS_GETCAPS, PFLAGNUM_1, 0); if ((dwCaps & PF1_FILESEND) == 0) continue; int dwStatus = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE); if (dwStatus != ID_STATUS_OFFLINE) dwOnline++; else if (bHideOffline) continue; // is HIT on? if (BST_UNCHECKED == db_get_b(0, SHLExt_Name, SHLExt_UseHITContacts, BST_UNCHECKED)) { // don't show people who are "Hidden" "NotOnList" or Ignored if (db_get_b(hContact, "CList", "Hidden", 0) == 1 || db_get_b(hContact, "CList", "NotOnList", 0) == 1 || CallService(MS_IGNORE_ISIGNORED, hContact, IGNOREEVENT_MESSAGE | IGNOREEVENT_URL | IGNOREEVENT_FILE) != 0) continue; } // is HIT2 off? if (BST_UNCHECKED == db_get_b(0, SHLExt_Name, SHLExt_UseHIT2Contacts, BST_UNCHECKED)) if (db_get_w(hContact, szProto, "ApparentMode", 0) == ID_STATUS_OFFLINE) continue; // store pContacts[i].hContact = hContact; pContacts[i].dwStatus = dwStatus; pContacts[i].hProto = murmur_hash(szProto); i++; } } // if no one is online and the CList isn't showing offliners, quit if (dwOnline == 0 && bHideOffline) { mir_free(pContacts); return false; } dwContacts = i; qsort(pContacts, dwContacts, sizeof(TSlotInfo), SortContact); // create an IPC slot for each contact and store display name, etc for (i=0; i < dwContacts; i++) { char *szContact = (char*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)pContacts[i].hContact, 0); if (szContact != NULL) { n = 0; rc = 1; if (bGroupMode) { rc = db_get_s(pContacts[i].hContact, "CList", "Group", &dbv); if (!rc) n = lstrlenA(dbv.pszVal) + 1; } int cch = lstrlenA(szContact) + 1; TSlotIPC *pct = ipcAlloc(ipch, cch + 1 + n); if (pct == NULL) { db_free(&dbv); break; } // lie about the actual size of the TSlotIPC pct->cbStrSection = cch; LPSTR szSlot = LPSTR(pct) + sizeof(TSlotIPC); lstrcpyA(szSlot, szContact); pct->fType = REQUEST_CONTACTS; pct->hContact = pContacts[i].hContact; pct->Status = pContacts[i].dwStatus; pct->hProto = pContacts[i].hProto; pct->MRU = db_get_b(pct->hContact, SHLExt_Name, SHLExt_MRU, 0); if (ipch->ContactsBegin == NULL) ipch->ContactsBegin = pct; szSlot += cch + 1; if (rc == 0) { pct->hGroup = murmur_hash(dbv.pszVal); lstrcpyA(szSlot, dbv.pszVal); db_free(&dbv); } else { pct->hGroup = 0; *szSlot = 0; } pSlot[0]++; } } mir_free(pContacts); return true; }
//////////////////////////////////////////////////////////////////////////////// // Info Page : Proc // lParam: 0 if current user (account owner) details, hContact if on list user details static INT_PTR CALLBACK gg_detailsdlgproc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { struct GGDETAILSDLGDATA *dat = (struct GGDETAILSDLGDATA *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch(msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); dat = (struct GGDETAILSDLGDATA *)mir_alloc(sizeof(struct GGDETAILSDLGDATA)); dat->hContact = lParam; dat->disableUpdate = FALSE; dat->updating = FALSE; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); // Add genders if (!dat->hContact) { SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)_T("")); // 0 SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)TranslateT("Female")); // 1 SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)TranslateT("Male")); // 2 } break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case 0: switch (((LPNMHDR)lParam)->code) { case PSN_PARAMCHANGED: dat->gg = (GGPROTO *)((LPPSHNOTIFY)lParam)->lParam; break; case PSN_INFOCHANGED: { MCONTACT hContact = (MCONTACT)((LPPSHNOTIFY)lParam)->lParam; GGPROTO *gg = dat->gg; if (!dat) break; // Show updated message if (dat->updating) { MessageBox(NULL, TranslateT("Your details has been uploaded to the public directory."), gg->m_tszUserName, MB_OK | MB_ICONINFORMATION); dat->updating = FALSE; break; } char *szProto = (hContact == NULL) ? gg->m_szModuleName : GetContactProto(hContact); if (szProto == NULL) break; // Disable when updating dat->disableUpdate = TRUE; SetValue(hwndDlg, IDC_UIN, hContact, szProto, GG_KEY_UIN, 0, hContact != NULL); SetValue(hwndDlg, IDC_REALIP, hContact, szProto, GG_KEY_CLIENTIP, SVS_IP, hContact != NULL); SetValue(hwndDlg, IDC_PORT, hContact, szProto, GG_KEY_CLIENTPORT, SVS_ZEROISUNSPEC, hContact != NULL); SetValue(hwndDlg, IDC_VERSION, hContact, szProto, GG_KEY_CLIENTVERSION, SVS_GGVERSION, hContact != NULL); SetValue(hwndDlg, IDC_FIRSTNAME, hContact, szProto, GG_KEY_PD_FIRSTNAME, SVS_NORMAL, hContact != NULL); SetValue(hwndDlg, IDC_LASTNAME, hContact, szProto, GG_KEY_PD_LASTNAME, SVS_NORMAL, hContact != NULL); SetValue(hwndDlg, IDC_NICKNAME, hContact, szProto, GG_KEY_PD_NICKNAME, SVS_NORMAL, hContact != NULL); SetValue(hwndDlg, IDC_BIRTHYEAR, hContact, szProto, GG_KEY_PD_BIRTHYEAR, SVS_ZEROISUNSPEC, hContact != NULL); SetValue(hwndDlg, IDC_CITY, hContact, szProto, GG_KEY_PD_CITY, SVS_NORMAL, hContact != NULL); SetValue(hwndDlg, IDC_FAMILYNAME, hContact, szProto, GG_KEY_PD_FAMILYNAME, SVS_NORMAL, hContact != NULL); SetValue(hwndDlg, IDC_CITYORIGIN, hContact, szProto, GG_KEY_PD_FAMILYCITY , SVS_NORMAL, hContact != NULL); if (hContact) { SetValue(hwndDlg, IDC_GENDER, hContact, szProto, GG_KEY_PD_GANDER, SVS_GENDER, hContact != NULL); SetValue(hwndDlg, IDC_STATUSDESCR, hContact, "CList", GG_KEY_STATUSDESCR, SVS_NORMAL, hContact != NULL); } else switch((char)db_get_b(hContact, gg->m_szModuleName, GG_KEY_PD_GANDER, (BYTE)'?')) { case 'F': SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 1, 0); break; case 'M': SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 2, 0); break; default: SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_SETCURSEL, 0, 0); } // Disable when updating dat->disableUpdate = FALSE; break; } } break; } break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: SendMessage(GetParent(hwndDlg),msg,wParam,lParam); break; case IDC_NICKNAME: case IDC_FIRSTNAME: case IDC_LASTNAME: case IDC_FAMILYNAME: case IDC_CITY: case IDC_CITYORIGIN: case IDC_BIRTHYEAR: if (HIWORD(wParam) == EN_CHANGE) { if (!dat || dat->hContact || dat->disableUpdate) break; EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), TRUE); break; } case IDC_GENDER: if (HIWORD(wParam) == CBN_SELCHANGE) { if (!dat || dat->hContact || dat->disableUpdate) break; EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), TRUE); break; } case IDC_SAVE: // Save current user data if (HIWORD(wParam) == BN_CLICKED) { if (!dat || dat->hContact || dat->disableUpdate) break; { TCHAR text[256]; GGPROTO *gg = dat->gg; if (!gg->isonline()) { MessageBox(NULL, TranslateT("You have to be logged in before you can change your details."), gg->m_tszUserName, MB_OK | MB_ICONSTOP); break; } EnableWindow(GetDlgItem(hwndDlg, IDC_SAVE), FALSE); gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_WRITE); GetDlgItemText(hwndDlg, IDC_FIRSTNAME, text, _countof(text)); if (mir_tstrlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, T2Utf(text)); GetDlgItemText(hwndDlg, IDC_LASTNAME, text, _countof(text)); if (mir_tstrlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, T2Utf(text)); GetDlgItemText(hwndDlg, IDC_NICKNAME, text, _countof(text)); if (mir_tstrlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, T2Utf(text)); GetDlgItemText(hwndDlg, IDC_CITY, text, _countof(text)); if (mir_tstrlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_CITY, T2Utf(text)); // Gadu-Gadu Female <-> Male switch(SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_GETCURSEL, 0, 0)) { case 1: gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_FEMALE); break; case 2: gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_SET_MALE); break; default: gg_pubdir50_add(req, GG_PUBDIR50_GENDER, ""); } GetDlgItemText(hwndDlg, IDC_BIRTHYEAR, text, _countof(text)); if (mir_tstrlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, T2Utf(text)); GetDlgItemText(hwndDlg, IDC_FAMILYNAME, text, _countof(text)); if (mir_tstrlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_FAMILYNAME, T2Utf(text)); GetDlgItemText(hwndDlg, IDC_CITYORIGIN, text, _countof(text)); if (mir_tstrlen(text)) gg_pubdir50_add(req, GG_PUBDIR50_FAMILYCITY, T2Utf(text)); // Run update gg_pubdir50_seq_set(req, GG_SEQ_CHINFO); gg->gg_EnterCriticalSection(&gg->sess_mutex, "gg_detailsdlgproc", 35, "sess_mutex", 1); gg_pubdir50(gg->sess, req); gg->gg_LeaveCriticalSection(&gg->sess_mutex, "gg_genoptsdlgproc", 35, 1, "sess_mutex", 1); dat->updating = TRUE; gg_pubdir50_free(req); } break; } } break; case WM_DESTROY: if (dat) mir_free(dat); break; } return FALSE; }
void CJabberProto::SearchReturnResults(HANDLE id, void * pvUsersInfo, U_TCHAR_MAP * pmAllFields) { LIST<TCHAR> ListOfNonEmptyFields(20,(LIST<TCHAR>::FTSortFunc)TCharKeyCmp); LIST<TCHAR> ListOfFields(20); LIST<void>* plUsersInfo = (LIST<void>*)pvUsersInfo; int i, nUsersFound = plUsersInfo->getCount(); // lets fill the ListOfNonEmptyFields but in users order for (i=0; i < nUsersFound; i++) { U_TCHAR_MAP* pmUserData = (U_TCHAR_MAP*)plUsersInfo->operator [](i); int nUserFields = pmUserData->getCount(); for (int j=0; j < nUserFields; j++) { TCHAR *var = pmUserData->getKeyName(j); if (var && ListOfNonEmptyFields.getIndex(var) < 0) ListOfNonEmptyFields.insert(var); } } // now fill the ListOfFields but order is from pmAllFields int nAllCount = pmAllFields->getCount(); for (i=0; i < nAllCount; i++) { TCHAR * var=pmAllFields->getUnOrderedKeyName(i); if (var && ListOfNonEmptyFields.getIndex(var) < 0) continue; ListOfFields.insert(var); } // now lets transfer field names int nFieldCount = ListOfFields.getCount(); JABBER_CUSTOMSEARCHRESULTS Results={0}; Results.nSize=sizeof(Results); Results.pszFields=(TCHAR**)mir_alloc(sizeof(TCHAR*)*nFieldCount); Results.nFieldCount=nFieldCount; /* Sending Columns Titles */ for (i=0; i < nFieldCount; i++) { TCHAR *var = ListOfFields[i]; if (var) Results.pszFields[i] = pmAllFields->operator [](var); } Results.jsr.hdr.cbSize = 0; // sending column names ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SEARCHRESULT, id, (LPARAM) &Results); /* Sending Users Data */ Results.jsr.hdr.cbSize = sizeof(Results.jsr); // sending user data for (i=0; i < nUsersFound; i++) { TCHAR buff[200]=_T(""); Results.jsr.jid[0]=0; U_TCHAR_MAP * pmUserData = (U_TCHAR_MAP *) plUsersInfo->operator [](i); for (int j=0; j < nFieldCount; j++) { TCHAR* var = ListOfFields[j]; TCHAR* value = pmUserData->operator [](var); Results.pszFields[j] = value ? value : (TCHAR *)_T(" "); if (!_tcsicmp(var,_T("jid")) && value) _tcsncpy(Results.jsr.jid, value, SIZEOF(Results.jsr.jid)); } { TCHAR * nickfields[]={ _T("nick"), _T("nickname"), _T("fullname"), _T("name"), _T("given"), _T("first"), _T("jid"), NULL }; TCHAR * nick=NULL; int k=0; while (nickfields[k] && !nick) nick=pmUserData->operator [](nickfields[k++]); if (_tcsicmp(nick, Results.jsr.jid)) mir_sntprintf(buff, SIZEOF(buff), _T("%s (%s)"), nick, Results.jsr.jid); else _tcsncpy(buff, nick, SIZEOF(buff)); Results.jsr.hdr.nick = nick ? buff : NULL; Results.jsr.hdr.flags = PSR_TCHAR; } ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SEARCHRESULT, id, (LPARAM) &Results); Results.jsr.hdr.nick=NULL; } mir_free(Results.pszFields); }
static int InputMenuPopup(WPARAM, LPARAM lParam) { HMENU hSubMenu = NULL; int i = 0; MessageWindowPopupData * mwpd = (MessageWindowPopupData *)lParam; if (mwpd->uFlags == MSG_WINDOWPOPUP_LOG || !g_bQuickMenu || !QuickList->realCount) return 0; if (mwpd->uType == MSG_WINDOWPOPUP_SHOWING) { hSubMenu = CreatePopupMenu(); InsertMenu((HMENU)mwpd->hMenu, 6, MF_STRING | MF_POPUP | MF_BYPOSITION, (UINT_PTR)hSubMenu, TranslateT("Quick Messages")); InsertMenu((HMENU)mwpd->hMenu, 7, MF_SEPARATOR | MF_BYPOSITION, 0, 0); qsort(QuickList->items, QuickList->realCount, sizeof(QuickData *), sstQuickSortButtons); for (i = 0; i < QuickList->realCount; i++) { QuickData* qd = (QuickData *)QuickList->items[i]; if (qd->fEntryType&QMF_EX_SEPARATOR) AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL); else AppendMenu(hSubMenu, MF_STRING, qd->dwPos + 254, qd->ptszValueName); } } else if (mwpd->uType == MSG_WINDOWPOPUP_SELECTED&&mwpd->selection >= 254) { for (i = 0; i < QuickList->realCount; i++) { QuickData* qd = (QuickData *)QuickList->items[i]; if ((qd->dwPos + 254) == mwpd->selection) { CHARRANGE cr; UINT textlenght = 0; TCHAR* pszText = NULL; TCHAR* ptszQValue = NULL; TCHAR* pszCBText = NULL; BOOL bIsService = 0; if (IsClipboardFormatAvailable(CF_TEXT)) { if (OpenClipboard(mwpd->hwnd)) { HANDLE hData = NULL; TCHAR* chBuffer = NULL; int textLength = 0; hData = GetClipboardData(CF_UNICODETEXT); chBuffer = (TCHAR*)GlobalLock(hData); textLength = (int)mir_tstrlen(chBuffer); pszCBText = mir_tstrdup(chBuffer); GlobalUnlock(hData); CloseClipboard(); } } SendMessage(mwpd->hwnd, EM_EXGETSEL, 0, (LPARAM)&cr); textlenght = cr.cpMax - cr.cpMin; if (textlenght) { pszText = (TCHAR *)mir_alloc((textlenght + 10)*sizeof(TCHAR)); memset(pszText, 0, ((textlenght + 10) * sizeof(TCHAR))); SendMessage(mwpd->hwnd, EM_GETSELTEXT, 0, (LPARAM)pszText); } if (qd->ptszValue) { ptszQValue = ParseString(mwpd->hContact, qd->ptszValue, pszText ? pszText : _T(""), pszCBText ? pszCBText : _T(""), (int)mir_tstrlen(qd->ptszValue), textlenght, pszCBText ? (int)mir_tstrlen(pszCBText) : 0); if ((bIsService = qd->bIsService) && ptszQValue) CallService(mir_u2a(ptszQValue), (WPARAM)mwpd->hContact, 0); } if (ptszQValue) SendMessage(mwpd->hwnd, EM_REPLACESEL, TRUE, (LPARAM)ptszQValue); if (pszText) mir_free(pszText); if (ptszQValue) free(ptszQValue); if (pszCBText) mir_free(pszCBText); break; } } return 1; } return 0; }
INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { struct FileDlgData *dat; dat=(struct FileDlgData*)GetWindowLongPtr(hwndDlg,GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: { TCHAR *contactName; TCHAR szPath[450]; CLISTEVENT* cle = (CLISTEVENT*)lParam; TranslateDialogDefault(hwndDlg); dat=(struct FileDlgData*)mir_calloc(sizeof(struct FileDlgData)); SetWindowLongPtr(hwndDlg,GWLP_USERDATA,(LONG_PTR)dat); dat->hContact = cle->hContact; dat->hDbEvent = cle->hDbEvent; dat->hPreshutdownEvent = HookEventMessage(ME_SYSTEM_PRESHUTDOWN,hwndDlg,M_PRESHUTDOWN); dat->dwTicks = GetTickCount(); EnumChildWindows(hwndDlg,ClipSiblingsChildEnumProc,0); Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_FILE); 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")); contactName = cli.pfnGetContactDisplayName( dat->hContact, 0 ); SetDlgItemText(hwndDlg,IDC_FROM,contactName); GetContactReceivedFilesDir(dat->hContact,szPath,SIZEOF(szPath),TRUE); SetDlgItemText(hwndDlg,IDC_FILEDIR,szPath); { int i; char idstr[32]; DBVARIANT dbv; if (shAutoComplete) shAutoComplete(GetWindow(GetDlgItem(hwndDlg,IDC_FILEDIR),GW_CHILD),1); for(i=0;i<MAX_MRU_DIRS;i++) { mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d",i); if(DBGetContactSettingTString(NULL,"SRFile",idstr,&dbv)) break; SendDlgItemMessage(hwndDlg,IDC_FILEDIR,CB_ADDSTRING,0,(LPARAM)dbv.ptszVal); DBFreeVariant(&dbv); } } CallService(MS_DB_EVENT_MARKREAD,(WPARAM)dat->hContact,(LPARAM)dat->hDbEvent); { DBEVENTINFO dbei={0}; TCHAR datetimestr[64]; char buf[540]; dbei.cbSize=sizeof(dbei); dbei.cbBlob=CallService(MS_DB_EVENT_GETBLOBSIZE,(WPARAM)dat->hDbEvent,0); dbei.pBlob=(PBYTE)mir_alloc(dbei.cbBlob); CallService(MS_DB_EVENT_GET,(WPARAM)dat->hDbEvent,(LPARAM)&dbei); dat->fs = cle->lParam ? (HANDLE)cle->lParam : (HANDLE)*(PDWORD)dbei.pBlob; lstrcpynA(buf, (char*)dbei.pBlob+4, min(dbei.cbBlob+1,SIZEOF(buf))); TCHAR* ptszFileName = DbGetEventStringT( &dbei, buf ); SetDlgItemText(hwndDlg,IDC_FILENAMES,ptszFileName); mir_free(ptszFileName); lstrcpynA(buf, (char*)dbei.pBlob+4+strlen((char*)dbei.pBlob+4)+1, min((int)(dbei.cbBlob-4-strlen((char*)dbei.pBlob+4)),SIZEOF(buf))); TCHAR* ptszDescription = DbGetEventStringT( &dbei, buf ); SetDlgItemText(hwndDlg,IDC_MSG,ptszDescription); mir_free(ptszDescription); mir_free(dbei.pBlob); tmi.printTimeStamp(NULL, dbei.timestamp, _T("t d"), datetimestr, SIZEOF(datetimestr), 0); SetDlgItemText(hwndDlg, IDC_DATE, datetimestr); } { char* szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)dat->hContact, 0); if (szProto) { CONTACTINFO ci; int hasName = 0; char buf[128]; ZeroMemory(&ci,sizeof(ci)); ci.cbSize = sizeof(ci); ci.hContact = dat->hContact; ci.szProto = szProto; ci.dwFlag = CNF_UNIQUEID; if (!CallService(MS_CONTACT_GETCONTACTINFO,0,(LPARAM)&ci)) { switch(ci.type) { case CNFT_ASCIIZ: hasName = 1; mir_snprintf(buf, SIZEOF(buf), "%s", ci.pszVal); mir_free(ci.pszVal); break; case CNFT_DWORD: hasName = 1; mir_snprintf(buf, SIZEOF(buf),"%u",ci.dVal); break; } } if (hasName) SetDlgItemTextA(hwndDlg, IDC_NAME, buf ); else SetDlgItemText(hwndDlg, IDC_NAME, contactName); } } if(DBGetContactSettingByte(dat->hContact,"CList","NotOnList",0)) { RECT rcBtn1,rcBtn2,rcDateCtrl; GetWindowRect(GetDlgItem(hwndDlg,IDC_ADD),&rcBtn1); GetWindowRect(GetDlgItem(hwndDlg,IDC_USERMENU),&rcBtn2); GetWindowRect(GetDlgItem(hwndDlg,IDC_DATE),&rcDateCtrl); SetWindowPos(GetDlgItem(hwndDlg,IDC_DATE),0,0,0,rcDateCtrl.right-rcDateCtrl.left-(rcBtn2.left-rcBtn1.left),rcDateCtrl.bottom-rcDateCtrl.top,SWP_NOZORDER|SWP_NOMOVE); } else if(DBGetContactSettingByte(NULL,"SRFile","AutoAccept",0)) { //don't check auto-min here to fix BUG#647620 PostMessage(hwndDlg,WM_COMMAND,MAKEWPARAM(IDOK,BN_CLICKED),(LPARAM)GetDlgItem(hwndDlg,IDOK)); } if(!DBGetContactSettingByte(dat->hContact,"CList","NotOnList",0)) ShowWindow(GetDlgItem(hwndDlg, IDC_ADD),SW_HIDE); return TRUE; } case WM_MEASUREITEM: return CallService(MS_CLIST_MENUMEASUREITEM,wParam,lParam); case WM_DRAWITEM: { LPDRAWITEMSTRUCT dis=(LPDRAWITEMSTRUCT)lParam; if(dis->hwndItem==GetDlgItem(hwndDlg, IDC_PROTOCOL)) { char *szProto; szProto=(char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)dat->hContact,0); if (szProto) { HICON 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 CallService(MS_CLIST_MENUDRAWITEM,wParam,lParam); case WM_COMMAND: if ( CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam),MPCF_CONTACTMENU), (LPARAM)dat->hContact )) break; switch ( LOWORD( wParam )) { case IDC_FILEDIRBROWSE: { TCHAR szDirName[MAX_PATH],szExistingDirName[MAX_PATH]; GetDlgItemText(hwndDlg,IDC_FILEDIR,szDirName,SIZEOF(szDirName)); GetLowestExistingDirName(szDirName,szExistingDirName,SIZEOF(szExistingDirName)); if(BrowseForFolder(hwndDlg,szExistingDirName)) SetDlgItemText(hwndDlg,IDC_FILEDIR,szExistingDirName); } break; case IDOK: { //most recently used directories TCHAR szRecvDir[MAX_PATH],szDefaultRecvDir[MAX_PATH]; GetDlgItemText(hwndDlg,IDC_FILEDIR,szRecvDir,SIZEOF(szRecvDir)); RemoveInvalidPathChars(szRecvDir); GetContactReceivedFilesDir(NULL,szDefaultRecvDir,SIZEOF(szDefaultRecvDir),TRUE); if(_tcsnicmp(szRecvDir,szDefaultRecvDir,lstrlen(szDefaultRecvDir))) { char idstr[32]; int i; DBVARIANT dbv; for(i=MAX_MRU_DIRS-2;i>=0;i--) { mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d",i); if(DBGetContactSettingTString(NULL,"SRFile",idstr,&dbv)) continue; mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d",i+1); DBWriteContactSettingTString(NULL,"SRFile",idstr,dbv.ptszVal); DBFreeVariant(&dbv); } DBWriteContactSettingTString(NULL,"SRFile",idstr,szRecvDir); } } EnableWindow(GetDlgItem(hwndDlg,IDC_FILENAMES),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_MSG),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_FILEDIR),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_FILEDIRBROWSE),FALSE); GetDlgItemText(hwndDlg,IDC_FILEDIR,dat->szSavePath,SIZEOF(dat->szSavePath)); GetDlgItemText(hwndDlg,IDC_FILE,dat->szFilenames,SIZEOF(dat->szFilenames)); GetDlgItemText(hwndDlg,IDC_MSG,dat->szMsg,SIZEOF(dat->szMsg)); dat->hwndTransfer = FtMgr_AddTransfer(dat); SetWindowLongPtr( hwndDlg, GWLP_USERDATA, 0); //check for auto-minimize here to fix BUG#647620 if(DBGetContactSettingByte(NULL,"SRFile","AutoAccept",0) && DBGetContactSettingByte(NULL,"SRFile","AutoMin",0)) { ShowWindow(hwndDlg,SW_HIDE); ShowWindow(hwndDlg,SW_SHOWMINNOACTIVE); } DestroyWindow(hwndDlg); break; case IDCANCEL: if (dat->fs) CallContactService(dat->hContact,PSS_FILEDENYT,(WPARAM)dat->fs,(LPARAM)TranslateT("Cancelled")); dat->fs=NULL; /* the protocol will free the handle */ DestroyWindow(hwndDlg); break; case IDC_ADD: { ADDCONTACTSTRUCT acs={0}; acs.handle=dat->hContact; acs.handleType=HANDLE_CONTACT; acs.szProto=""; CallService(MS_ADDCONTACT_SHOW,(WPARAM)hwndDlg,(LPARAM)&acs); if(!DBGetContactSettingByte(dat->hContact,"CList","NotOnList",0)) ShowWindow(GetDlgItem(hwndDlg,IDC_ADD), SW_HIDE); } break; case IDC_USERMENU: { RECT rc; HMENU hMenu=(HMENU)CallService(MS_CLIST_MENUBUILDCONTACT,(WPARAM)dat->hContact,0); GetWindowRect((HWND)lParam,&rc); TrackPopupMenu(hMenu,0,rc.left,rc.bottom,0,hwndDlg,NULL); DestroyMenu(hMenu); } break; case IDC_DETAILS: CallService(MS_USERINFO_SHOWDIALOG,(WPARAM)dat->hContact,0); break; case IDC_HISTORY: CallService(MS_HISTORY_SHOWCONTACTHISTORY,(WPARAM)dat->hContact,0); break; } 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); if ( dat ) FreeFileDlgData( dat ); 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 CallService(MS_CLIST_MENUMEASUREITEM, wParam, 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 CallService(MS_CLIST_MENUDRAWITEM, wParam, 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, lstrlenA(url)+lstrlenA(body)+2); lstrcpyA(dat->sendBuffer, url); lstrcpyA(dat->sendBuffer+lstrlenA(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 = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); 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 = { sizeof(dbei) }; dbei.eventType = EVENTTYPE_URL; dbei.flags = DBEF_SENT; dbei.szModule = GetContactProto(dat->hContact); dbei.timestamp = time(NULL); dbei.cbBlob = (DWORD)(strlen(dat->sendBuffer)+strlen(dat->sendBuffer+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 ReadAwayMsgDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { AwayMsgDlgData *dat = (AwayMsgDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch(message) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); dat = (AwayMsgDlgData*)mir_alloc(sizeof(AwayMsgDlgData)); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); dat->hContact = (HANDLE)lParam; dat->hAwayMsgEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_AWAYMSG); dat->hSeq = (HANDLE)CallContactService(dat->hContact, PSS_GETAWAYMSG, 0, 0); WindowList_Add(hWindowList, hwndDlg, dat->hContact); { TCHAR str[256], format[128]; TCHAR* contactName = cli.pfnGetContactDisplayName(dat->hContact, 0); char* szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)dat->hContact, 0); WORD dwStatus = DBGetContactSettingWord(dat->hContact, szProto, "Status", ID_STATUS_OFFLINE); TCHAR* status = cli.pfnGetStatusModeDescription(dwStatus, 0); GetWindowText(hwndDlg, format, SIZEOF(format)); mir_sntprintf(str, SIZEOF(str), format, status, contactName); SetWindowText(hwndDlg, str); GetDlgItemText(hwndDlg, IDC_RETRIEVING, format, SIZEOF(format)); mir_sntprintf(str, SIZEOF(str), format, status); SetDlgItemText(hwndDlg, IDC_RETRIEVING, str); Window_SetProtoIcon_IcoLib(hwndDlg, szProto, dwStatus); } if (dat->hSeq == NULL) { ACKDATA ack = {0}; ack.cbSize = sizeof(ack); ack.hContact = dat->hContact; ack.type = ACKTYPE_AWAYMSG; ack.result = ACKRESULT_SUCCESS; SendMessage(hwndDlg, HM_AWAYMSG, 0, (LPARAM)&ack); } Utils_RestoreWindowPosition(hwndDlg, (HANDLE)lParam, "SRAway", "AwayMsgDlg"); return TRUE; case HM_AWAYMSG: { ACKDATA *ack = (ACKDATA*)lParam; if (ack->hContact != dat->hContact || ack->type != ACKTYPE_AWAYMSG) break; if (ack->result != ACKRESULT_SUCCESS) break; if (dat->hAwayMsgEvent && ack->hProcess == dat->hSeq) { UnhookEvent(dat->hAwayMsgEvent); dat->hAwayMsgEvent = NULL; } #ifdef _UNICODE DBVARIANT dbv; bool unicode = !DBGetContactSetting(dat->hContact, "CList", "StatusMsg", &dbv) && (dbv.type == DBVT_UTF8 || dbv.type == DBVT_WCHAR); DBFreeVariant(&dbv); if (unicode) { DBGetContactSettingWString(dat->hContact, "CList", "StatusMsg", &dbv); SetDlgItemText(hwndDlg, IDC_MSG, dbv.pwszVal); } else #endif SetDlgItemTextA(hwndDlg, IDC_MSG, (const char*)ack->lParam); ShowWindow(GetDlgItem(hwndDlg,IDC_RETRIEVING), SW_HIDE); ShowWindow(GetDlgItem(hwndDlg,IDC_MSG), SW_SHOW); SetDlgItemText(hwndDlg, IDOK, TranslateT("&Close")); break; } case WM_COMMAND: switch(LOWORD(wParam)) { case IDCANCEL: case IDOK: DestroyWindow(hwndDlg); break; } break; case WM_CLOSE: DestroyWindow(hwndDlg); break; case WM_DESTROY: if (dat->hAwayMsgEvent) UnhookEvent(dat->hAwayMsgEvent); Utils_SaveWindowPosition(hwndDlg,dat->hContact,"SRAway","AwayMsgDlg"); WindowList_Remove(hWindowList,hwndDlg); Window_FreeIcon_IcoLib(hwndDlg); mir_free(dat); break; } return FALSE; }
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) { 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; }
void GetNewsData(TCHAR *tszUrl, char **szData, MCONTACT hContact, HWND hwndDlg) { Netlib_LogfT(hNetlibUser, _T("Getting feed data %s."), tszUrl); NETLIBHTTPREQUEST nlhr = { 0 }; // initialize the netlib request nlhr.cbSize = sizeof(nlhr); nlhr.requestType = REQUEST_GET; nlhr.flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_REDIRECT; if (_tcsstr(tszUrl, _T("https://")) != NULL) nlhr.flags |= NLHRF_SSL; char *szUrl = mir_t2a(tszUrl); nlhr.szUrl = szUrl; nlhr.nlc = hNetlibHttp; // change the header so the plugin is pretended to be IE 6 + WinXP NETLIBHTTPHEADER headers[5]; nlhr.headersCount = 4; nlhr.headers = headers; nlhr.headers[0].szName = "User-Agent"; nlhr.headers[0].szValue = NETLIB_USER_AGENT; nlhr.headers[1].szName = "Cache-Control"; nlhr.headers[1].szValue = "no-cache"; nlhr.headers[2].szName = "Pragma"; nlhr.headers[2].szValue = "no-cache"; nlhr.headers[3].szName = "Connection"; nlhr.headers[3].szValue = "close"; char auth[256]; if (db_get_b(hContact, MODULE, "UseAuth", 0) || IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)) { nlhr.headersCount++; nlhr.headers[4].szName = "Authorization"; CreateAuthString(auth, hContact, hwndDlg); nlhr.headers[4].szValue = auth; } // download the page NETLIBHTTPREQUEST *nlhrReply = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&nlhr); if (nlhrReply) { // if the recieved code is 200 OK if (nlhrReply->resultCode == 200 && nlhrReply->dataLength > 0) { Netlib_LogfT(hNetlibUser, _T("Code 200: Succeeded getting feed data %s."), tszUrl); // allocate memory and save the retrieved data *szData = (char *)mir_alloc((size_t)(nlhrReply->dataLength + 2)); memcpy(*szData, nlhrReply->pData, (size_t)nlhrReply->dataLength); (*szData)[nlhrReply->dataLength] = 0; } else if (nlhrReply->resultCode == 401) { Netlib_LogfT(hNetlibUser, _T("Code 401: feed %s needs auth data."), tszUrl); ItemInfo SelItem = { 0 }; SelItem.hwndList = hwndDlg; SelItem.hContact = hContact; if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_AUTHENTICATION), hwndDlg, AuthenticationProc, (LPARAM)&SelItem) == IDOK) GetNewsData(tszUrl, szData, hContact, hwndDlg); } else Netlib_LogfT(hNetlibUser, _T("Code %d: Failed getting feed data %s."), nlhrReply->resultCode, tszUrl); CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)nlhrReply); } else Netlib_LogfT(hNetlibUser, _T("Failed getting feed data %s, no response."), tszUrl); mir_free(szUrl); }
//--------------------------------------------------------------------------- void CSendImageShack::Send() { // check Netlib if( !hNetlibUser ) { //PrintError(1,TRUE); return; } if (!m_pszFileName) { m_pszFileName = (LPSTR)GetFileName(m_pszFile, DBVT_ASCIIZ); } if (!m_pszContentType) GetContentType(); // create new boundary MFDR_Reset(); // initialize the netlib request ZeroMemory(&m_nlhr, sizeof(m_nlhr)); m_nlhr.cbSize = sizeof(m_nlhr); m_nlhr.requestType = REQUEST_POST; m_nlhr.flags = NLHRF_HTTP11; //NLHRF_DUMPASTEXT; m_nlhr.szUrl = "http://www.imageshack.us/upload_api.php"; m_nlhr.headersCount = 6; { //NETLIBHTTPHEADER start m_nlhr.headers=(NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)*m_nlhr.headersCount); m_nlhr.headers[0].szName = "Referer"; m_nlhr.headers[0].szValue = "http://www.imageshack.us/upload_api.php"; m_nlhr.headers[1].szName = "Connection"; m_nlhr.headers[1].szValue = "Keep-alive"; m_nlhr.headers[2].szName = "AcceptLanguage"; m_nlhr.headers[2].szValue = "en-us, pt-br"; m_nlhr.headers[3].szName = "Host"; m_nlhr.headers[3].szValue = "imageshack.us"; m_nlhr.headers[4].szName = "User-Agent"; m_nlhr.headers[4].szValue = __USER_AGENT_STRING; //szAgent; /; //nlhr.headers[x].szName = "Authorization"; //nlhr.headers[x].szValue = auth; //Basic base-64-authorization //$header .= "Content-type: multipart/form-data; boundary=" . part::getBoundary() . "\r\n"; mir_snprintf(m_nlheader_ContentType, SIZEOF(m_nlheader_ContentType), "multipart/form-data; boundary=%s", m_MFDRboundary); m_nlhr.headers[m_nlhr.headersCount-1].szName = "Content-Type"; m_nlhr.headers[m_nlhr.headersCount-1].szValue = m_nlheader_ContentType; } //NETLIBHTTPHEADER end //POST DATA file-header, init DATA with MultipartFormDataRequest //$params[] = new filepart('fileupload', $file, basename($file), $contentType, 'iso-8859-1'); //($this->sendStart($h);) AppendToData("--"); AppendToData(m_MFDRboundary); AppendToData("\r\n"); //($this->sendDispositionHeader($h);) AppendToData("Content-Disposition: form-data; name=\""); AppendToData("fileupload"); AppendToData("\"; filename=\""); AppendToData(m_pszFileName); AppendToData("\""); AppendToData("\r\n"); //($this->sendContentTypeHeader($h);) AppendToData("Content-Type: "); AppendToData(m_pszContentType); AppendToData("; charset="); AppendToData("iso-8859-1"); //($this->sendEndOfHeader($h);) AppendToData("\r\n"); AppendToData("\r\n"); //Now we add the file binary ($this->sendData($h)) FILE * fileId = _tfsopen(m_pszFile, _T("rb"), _SH_DENYWR ); if( !fileId) { //PrintError(1,TRUE); return; } fseek(fileId, NULL, SEEK_END); size_t lenFile = ftell(fileId); size_t sizeDest = sizeof(char)*(m_nlhr.dataLength + lenFile + 1); m_nlhr.pData = (char *) mir_realloc(m_nlhr.pData, sizeDest); fseek(fileId, NULL, SEEK_SET ); int i; int ch = fgetc( fileId ); for( i=0; (i < (int)lenFile ) && ( feof( fileId ) == 0 ); i++ ) { m_nlhr.pData[m_nlhr.dataLength+i] = (char)ch; ch = fgetc( fileId ); } m_nlhr.pData[sizeDest-1] = 0; //NULL Termination for binary data m_nlhr.dataLength = (int)sizeDest - 1; fclose(fileId); //($this->sendEnd($h);) AppendToData("\r\n"); //POST DATA footer (for "optimage", 1) //POST DATA footer (for "optsize", optsize) //POST DATA footer (for "tags", tags) //POST DATA footer (for "rembar", "yes" : "no") //POST DATA footer (for "public", "yes" : "no") //POST DATA footer (for "cookie", cookie) //POST DATA footer (for "key", DEVKEY_IMAGESHACK) //($this->sendStart($h);) AppendToData("--"); AppendToData(m_MFDRboundary); AppendToData("\r\n"); //($this->sendDispositionHeader($h);) AppendToData("Content-Disposition: form-data; name=\""); AppendToData("key"); AppendToData("\""); //($this->sendTransferEncodingHeader($h); ) AppendToData("\r\n"); AppendToData("Content-Transfer-Encoding: "); AppendToData("8bit"); //??"binary" //($this->sendEndOfHeader($h);) AppendToData("\r\n"); AppendToData("\r\n"); //($this->sendData($h);) AppendToData(DEVKEY_IMAGESHACK); //($this->sendEnd($h);) AppendToData("\r\n"); //POST DATA Exit //$postdata = "--" . part::getBoundary() . "--\r\n"; AppendToData("--"); AppendToData(m_MFDRboundary); AppendToData("--\r\n"); //start upload thread if (m_SendSync) { m_bFreeOnExit = FALSE; SendThread(); return; } m_bFreeOnExit = TRUE; mir_forkthread(&CSendImageShack::SendThreadWrapper, this); }
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { osdmsg *ms; switch (message) { case WM_CREATE: logmsg("WindowProcedure::CREATE"); SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&defstr); return 0; case WM_DESTROY: logmsg("WindowProcedure::DESTROY"); return 0; case WM_PAINT: logmsg("WindowProcedure::PAINT"); ms = (osdmsg*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (ms) return DrawMe(hwnd, ms->text, ms->color); PAINTSTRUCT ps; BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); return 0; case WM_NCRBUTTONDOWN: logmsg("WindowProcedure::NCRBUTTONDOWN"); ms = (osdmsg*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (ms) { if (ms->callback) ms->callback(ms->param); SendMessage(hwnd, WM_USER + 3, 0, 0); } return 0; case WM_TIMER: logmsg("WindowProcedure::TIMER"); SendMessage(hwnd, WM_USER + 3, wParam, 0); return 0; case WM_USER + 1: //draw text ((char *)string, (int) timeout logmsg("WindowProcedure::USER+1"); ms = (osdmsg*)mir_alloc(sizeof(osdmsg)); ms->text = mir_tstrdup((TCHAR *)wParam); if (lParam == 0) lParam = db_get_dw(NULL, THIS_MODULE, "timeout", DEFAULT_TIMEOUT); ms->timeout = lParam; ms->callback = 0; ms->color = db_get_dw(NULL, THIS_MODULE, "clr_msg", DEFAULT_CLRMSG); ms->param = 0; SendMessage(hwnd, WM_USER + 4, (WPARAM)ms, 0); mir_free(ms->text); mir_free(ms); return 0; case WM_USER + 2: //show logmsg("WindowProcedure::USER+2"); SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE); return 0; case WM_USER + 3: //hide ms = (osdmsg*)GetWindowLongPtr(hwnd, GWLP_USERDATA); logmsg("WindowProcedure::USER+3"); if (!ms) return 0; logmsg("WindowProcedure::USER+3/om"); KillTimer(hwnd, (UINT_PTR)ms); mir_free(ms->text); mir_free(ms); SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); ShowWindow(hwnd, SW_HIDE); return 0; case WM_USER + 4: logmsg("WindowProcedure::USER+4"); ms = (osdmsg*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (ms != 0) { logmsg("WindowProcedure::USER+4/old"); KillTimer(hwnd, (UINT_PTR)ms); mir_free(ms->text); mir_free(ms); SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); } ms = (osdmsg*)mir_alloc(sizeof(osdmsg)); memcpy(ms, (osdmsg*)wParam, sizeof(osdmsg)); ms->text = mir_tstrdup(ms->text); SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)ms); SetTimer(hwnd, (UINT_PTR)ms, (UINT)ms->timeout, 0); InvalidateRect(hwnd, 0, TRUE); SendMessage(hwnd, WM_USER + 2, 0, 0); return 0; case WM_NCHITTEST: { RECT rect; GetWindowRect(hwnd, &rect); logmsg("WindowProcedure::NCHITTEST"); if (LOWORD(lParam) >= (rect.left + 5) && LOWORD(lParam) <= (rect.right - 5) && HIWORD(lParam) >= (rect.top + 5) && HIWORD(lParam) <= (rect.bottom - 5)) return HTCAPTION; return DefWindowProc(hwnd, message, wParam, lParam); } //here will be the doubleclick => open-message-window solution ;-) //case WM_NCLBUTTONDBLCLK: // CallService(MS_MSG_SENDMESSAGE, wparam,(LPARAM)&odp); // return 0; default: return DefWindowProc(hwnd, message, wParam, lParam); } }
bool CToxProto::SetToxAvatar(std::tstring path, bool checkHash) { int length; uint8_t *data; FILE *hFile = _tfopen(path.c_str(), L"rb"); if (!hFile) { debugLogA("CToxProto::SetMyAvatar: failed to open avatar file"); return false; } fseek(hFile, 0, SEEK_END); length = ftell(hFile); rewind(hFile); if (length > TOX_AVATAR_MAX_DATA_LENGTH) { fclose(hFile); debugLogA("CToxProto::SetMyAvatar: new avatar size is excessive"); return false; } data = (uint8_t*)mir_alloc(length); size_t readed = fread(data, sizeof(uint8_t), length, hFile); if (readed != length) { fclose(hFile); debugLogA("CToxProto::SetMyAvatar: failed to read avatar file"); return false; } fclose(hFile); DBVARIANT dbv; uint8_t hash[TOX_HASH_LENGTH]; tox_hash(hash, data, TOX_HASH_LENGTH); if (checkHash && !db_get(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, &dbv)) { if (memcmp(hash, dbv.pbVal, TOX_HASH_LENGTH) == 0) { db_free(&dbv); mir_free(data); debugLogA("CToxProto::SetMyAvatar: new avatar is same with old"); return false; } db_free(&dbv); } if (tox_set_avatar(tox, TOX_AVATAR_FORMAT_PNG, data, length) == TOX_ERROR) { mir_free(data); debugLogA("CToxProto::SetMyAvatar: failed to set new avatar"); return false; } mir_free(data); if (checkHash) { db_set_blob(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, (void*)hash, TOX_HASH_LENGTH); } return true; }
int ModernDrawStatusBarWorker(HWND hWnd, HDC hDC) { int iconHeight = GetSystemMetrics(SM_CYSMICON)+2; int i; // Count visible protos RECT rc; GetClientRect(hWnd, &rc); if (g_CluiData.fDisableSkinEngine) { if (g_StatusBarData.bkUseWinColors && xpt_IsThemed(g_StatusBarData.hTheme)) xpt_DrawTheme(g_StatusBarData.hTheme, hWnd, hDC, 0, 0, &rc, &rc); else DrawBackGround(hWnd, hDC, g_StatusBarData.hBmpBackground, g_StatusBarData.bkColour, g_StatusBarData.backgroundBmpUse); } else SkinDrawGlyph(hDC, &rc, &rc, "Main,ID=StatusBar"); //TBD g_StatusBarData.nProtosPerLine = db_get_b(NULL,"CLUI","StatusBarProtosPerLine",SETTING_PROTOSPERLINE_DEFAULT); HFONT hOldFont = g_clcPainter.ChangeToFont(hDC,NULL,FONTID_STATUSBAR_PROTONAME,NULL); SIZE textSize = {0}; GetTextExtentPoint32A(hDC, " ", 1, &textSize); int spaceWidth = textSize.cx; int textY = rc.top+((rc.bottom-rc.top-textSize.cy)>>1); int iconY = rc.top+((rc.bottom-rc.top-GetSystemMetrics(SM_CXSMICON))>>1); ProtosData.destroy(); int protoCount; PROTOACCOUNT **accs; ProtoEnumAccounts( &protoCount, &accs ); if (protoCount == 0) return 0; for (int j = 0; j < protoCount; j++) { int i = pcli->pfnGetAccountIndexByPos(j); if (i == -1 || !pcli->pfnGetProtocolVisibility(accs[i]->szModuleName)) continue; char buf[256]; mir_snprintf(buf, SIZEOF(buf), "SBarAccountIsCustom_%s", accs[i]->szModuleName); ProtoItemData *p = new ProtoItemData; if (g_StatusBarData.perProtoConfig && db_get_b(NULL, "CLUI", buf, SETTING_SBARACCOUNTISCUSTOM_DEFAULT)) { mir_snprintf(buf, SIZEOF(buf), "HideAccount_%s", accs[i]->szModuleName); if ( db_get_b(NULL, "CLUI", buf, SETTING_SBARHIDEACCOUNT_DEFAULT)) continue; mir_snprintf(buf, SIZEOF(buf), "SBarShow_%s", accs[i]->szModuleName); BYTE showOps = db_get_b(NULL,"CLUI", buf, SETTING_SBARSHOW_DEFAULT); p->showProtoIcon = showOps & 1; p->showProtoName = showOps & 2; p->showStatusName = showOps & 4; mir_snprintf(buf, SIZEOF(buf), "ShowXStatus_%s", accs[i]->szModuleName); p->xStatusMode = db_get_b(NULL,"CLUI", buf, SETTING_SBARSHOW_DEFAULT); mir_snprintf(buf, SIZEOF(buf), "UseConnectingIcon_%s", accs[i]->szModuleName); p->connectingIcon = db_get_b(NULL,"CLUI", buf, SETTING_USECONNECTINGICON_DEFAULT); mir_snprintf(buf, SIZEOF(buf), "ShowUnreadEmails_%s", accs[i]->szModuleName); p->showProtoEmails = db_get_b(NULL,"CLUI", buf, SETTING_SHOWUNREADEMAILS_DEFAULT); mir_snprintf(buf, SIZEOF(buf), "SBarRightClk_%s", accs[i]->szModuleName); p->SBarRightClk = db_get_b(NULL,"CLUI", buf, SETTING_SBARRIGHTCLK_DEFAULT); mir_snprintf(buf, SIZEOF(buf), "PaddingLeft_%s", accs[i]->szModuleName); p->PaddingLeft = db_get_dw(NULL,"CLUI", buf, SETTING_PADDINGLEFT_DEFAULT); mir_snprintf(buf, SIZEOF(buf), "PaddingRight_%s", accs[i]->szModuleName); p->PaddingRight = db_get_dw(NULL,"CLUI", buf, SETTING_PADDINGRIGHT_DEFAULT); } else { p->showProtoIcon = g_StatusBarData.showProtoIcon; p->showProtoName = g_StatusBarData.showProtoName; p->showStatusName = g_StatusBarData.showStatusName; p->xStatusMode = g_StatusBarData.xStatusMode; p->connectingIcon = g_StatusBarData.connectingIcon; p->showProtoEmails = g_StatusBarData.showProtoEmails; p->SBarRightClk = 0; p->PaddingLeft = 0; p->PaddingRight = 0; } p->ProtoStatus = CallProtoService(accs[i]->szModuleName,PS_GETSTATUS, 0, 0); if (p->ProtoStatus > ID_STATUS_OFFLINE) { if (p->showProtoEmails == 1 && ProtoServiceExists(accs[i]->szModuleName, PS_GETUNREADEMAILCOUNT)) { char buf[40]; mir_snprintf(buf, SIZEOF(buf),"[%d]", (int)ProtoCallService(accs[i]->szModuleName, PS_GETUNREADEMAILCOUNT, 0, 0)); p->ProtoEMailCount = mir_strdup(buf); } } p->ProtoHumanName = mir_tstrdup(accs[i]->tszAccountName); p->AccountName = mir_strdup(accs[i]->szModuleName); p->ProtoName = mir_strdup(accs[i]->szProtoName); p->ProtoStatusText = mir_tstrdup(pcli->pfnGetStatusModeDescription(p->ProtoStatus, 0)); p->ProtoPos = ProtosData.getCount(); p->isDimmed = 0; if (g_CluiData.bFilterEffective & CLVM_FILTER_PROTOS) { char szTemp[2048]; mir_snprintf(szTemp, SIZEOF(szTemp), "%s|", p->AccountName ); p->isDimmed = strstr(g_CluiData.protoFilter, szTemp) ? 0 : 1; } ProtosData.insert(p); } if ( ProtosData.getCount() == 0) return 0; //START MULTILINE HERE int orig_protoCount = protoCount; int orig_visProtoCount = ProtosData.getCount(); int protosperline = 0; if (g_StatusBarData.nProtosPerLine) protosperline = g_StatusBarData.nProtosPerLine; else if (orig_visProtoCount) protosperline = orig_visProtoCount; else if (protoCount) { protosperline = protoCount; orig_visProtoCount = protoCount; } else { protosperline = 1; orig_visProtoCount = 1; } protosperline = min(protosperline,orig_visProtoCount); int linecount = protosperline ? (orig_visProtoCount+(protosperline-1))/protosperline : 1; //divide with rounding to up for (int line = 0; line < linecount; line++) { int rowheight = max(textSize.cy+2, iconHeight); protoCount = min(protosperline,(orig_protoCount-line*protosperline)); int visProtoCount = min(protosperline,(orig_visProtoCount-line*protosperline)); GetClientRect(hWnd,&rc); rc.top += g_StatusBarData.rectBorders.top; rc.bottom -= g_StatusBarData.rectBorders.bottom; int aligndx = 0, maxwidth = 0, xstatus = 0, SumWidth = 0; int height = (rowheight*linecount); if (height > (rc.bottom - rc.top)) { rowheight = (rc.bottom - rc.top) / linecount; height = (rowheight*linecount); } int rowsdy = ((rc.bottom-rc.top)-height)/2; if (rowheight*(line)+rowsdy < rc.top-rowheight) continue; if (rowheight*(line+1)+rowsdy>rc.bottom+rowheight) break; if (g_StatusBarData.VAlign == 0) { //top rc.bottom = rc.top+rowheight*(line+1); rc.top = rc.top+rowheight*line+1; } else if (g_StatusBarData.VAlign == 1) { //center rc.bottom = rc.top+rowsdy+rowheight*(line+1); rc.top = rc.top+rowsdy+rowheight*line+1; } else if (g_StatusBarData.VAlign == 2) { //bottom rc.top = rc.bottom - (rowheight*(linecount - line)); rc.bottom = rc.bottom - (rowheight*(linecount - line - 1)+1); } textY = rc.top + (((rc.bottom-rc.top) - textSize.cy)/2); iconY = rc.top + (((rc.bottom-rc.top) - iconHeight)/2); //Code for each line DWORD sw; int rectwidth = rc.right - rc.left - g_StatusBarData.rectBorders.left - g_StatusBarData.rectBorders.right; if (visProtoCount > 1) sw = (rectwidth - (g_StatusBarData.extraspace*(visProtoCount-1))) / visProtoCount; else sw = rectwidth; int *ProtoWidth = (int*)mir_alloc(sizeof(int)*visProtoCount); for (i=0; i < visProtoCount; i++) { ProtoItemData &p = ProtosData[line*protosperline + i]; DWORD w = p.PaddingLeft; w += p.PaddingRight; if (p.showProtoIcon) { w += GetSystemMetrics(SM_CXSMICON)+1; p.extraIcon = NULL; if ((p.xStatusMode & 8) && p.ProtoStatus > ID_STATUS_OFFLINE) { TCHAR str[512]; CUSTOM_STATUS cs = { sizeof(cs) }; cs.flags = CSSF_MASK_NAME | CSSF_TCHAR; cs.ptszName = str; if ( CallProtoService(p.AccountName, PS_GETCUSTOMSTATUSEX, 0, (LPARAM)&cs) == 0) p.ProtoXStatus = mir_tstrdup(str); } if ((p.xStatusMode & 3)) { if (p.ProtoStatus > ID_STATUS_OFFLINE) { if ( ProtoServiceExists(p.AccountName, PS_GETCUSTOMSTATUSICON)) p.extraIcon = (HICON)ProtoCallService(p.AccountName, PS_GETCUSTOMSTATUSICON, 0, 0); if (p.extraIcon && (p.xStatusMode & 3) == 3) w += GetSystemMetrics(SM_CXSMICON)+1; } } } SIZE textSize; if (p.showProtoName) { GetTextExtentPoint32(hDC, p.ProtoHumanName, lstrlen(p.ProtoHumanName), &textSize); w += textSize.cx + 3 + spaceWidth; } if (p.showProtoEmails && p.ProtoEMailCount) { GetTextExtentPoint32A(hDC, p.ProtoEMailCount, lstrlenA(p.ProtoEMailCount), &textSize); w += textSize.cx + 3 + spaceWidth; } if (p.showStatusName) { GetTextExtentPoint32(hDC, p.ProtoStatusText, lstrlen(p.ProtoStatusText), &textSize); w += textSize.cx + 3 + spaceWidth; } if ((p.xStatusMode & 8) && p.ProtoXStatus) { GetTextExtentPoint32(hDC, p.ProtoXStatus, lstrlen(p.ProtoXStatus), &textSize); w += textSize.cx + 3 + spaceWidth; } if (p.showProtoName || (p.showProtoEmails && p.ProtoEMailCount) || p.showStatusName || ((p.xStatusMode & 8) && p.ProtoXStatus)) w -= spaceWidth; p.fullWidth = w; if (g_StatusBarData.sameWidth) { ProtoWidth[i] = sw; SumWidth += w; } else { ProtoWidth[i] = w; SumWidth += w; } } // Reposition rects for (i=0; i < visProtoCount; i++) if (ProtoWidth[i] > maxwidth) maxwidth = ProtoWidth[i]; if (g_StatusBarData.sameWidth) { for (i=0; i < visProtoCount; i++) ProtoWidth[i] = maxwidth; SumWidth = maxwidth * visProtoCount; } SumWidth += (visProtoCount-1) * (g_StatusBarData.extraspace+1); if (SumWidth > rectwidth) { float f = (float)rectwidth/SumWidth; SumWidth = 0; for (i=0; i < visProtoCount; i++) { ProtoWidth[i] = (int)((float)ProtoWidth[i]*f); SumWidth += ProtoWidth[i]; } SumWidth += (visProtoCount-1)*(g_StatusBarData.extraspace+1); } if (g_StatusBarData.Align == 1) //center aligndx = (rectwidth-SumWidth)>>1; else if (g_StatusBarData.Align == 2) //right aligndx = (rectwidth-SumWidth); // Draw in rects RECT r = rc; r.left += g_StatusBarData.rectBorders.left+aligndx; for (i=0; i < visProtoCount; i++) { ProtoItemData& p = ProtosData[line*protosperline + i]; HRGN rgn; HICON hIcon = NULL; HICON hxIcon = NULL; BOOL NeedDestroy = FALSE; int x = r.left; x += p.PaddingLeft; r.right = r.left+ProtoWidth[i]; if (p.showProtoIcon) { if (p.ProtoStatus > ID_STATUS_OFFLINE && (p.xStatusMode & 3) > 0) { if ( ProtoServiceExists(p.AccountName, PS_GETCUSTOMSTATUSICON)) { hxIcon = p.extraIcon; if (hxIcon) { if ((p.xStatusMode & 3) == 2) { hIcon = GetMainStatusOverlay(p.ProtoStatus); NeedDestroy = TRUE; } else if ((p.xStatusMode & 3) == 1) { hIcon = hxIcon; NeedDestroy = TRUE; hxIcon = NULL; } } } } if (hIcon == NULL && (hxIcon == NULL || ((p.xStatusMode & 3) == 3))) { if ((p.connectingIcon == 1) && p.ProtoStatus >= ID_STATUS_CONNECTING && p.ProtoStatus <= ID_STATUS_CONNECTING + MAX_CONNECT_RETRIES) { hIcon = (HICON)CLUI_GetConnectingIconService((WPARAM)p.AccountName,0); if (hIcon) NeedDestroy = TRUE; else hIcon = LoadSkinnedProtoIcon(p.AccountName,p.ProtoStatus); } else hIcon = LoadSkinnedProtoIcon(p.AccountName,p.ProtoStatus); } rgn = CreateRectRgn(r.left,r.top,r.right,r.bottom); if (g_StatusBarData.sameWidth) { int fw = p.fullWidth; int rw = r.right-r.left; if (g_StatusBarData.Align == 1) x = r.left+((rw-fw)/2); else if (g_StatusBarData.Align == 2) x = r.left+((rw-fw)); else x = r.left; } SelectClipRgn(hDC,rgn); p.DoubleIcons = FALSE; DWORD dim = p.isDimmed ? (( 64 << 24 ) | 0x80 ) : 0; if ((p.xStatusMode&3) == 3) { if (hIcon) mod_DrawIconEx_helper(hDC,x,iconY,hIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL|dim ); if (hxIcon) { mod_DrawIconEx_helper(hDC,x+GetSystemMetrics(SM_CXSMICON)+1,iconY,hxIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), 0, NULL,DI_NORMAL|dim); x += GetSystemMetrics(SM_CXSMICON)+1; } p.DoubleIcons = hIcon && hxIcon; } else { if (hxIcon) mod_DrawIconEx_helper(hDC,x,iconY,hxIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), 0, NULL,DI_NORMAL|dim); if (hIcon) mod_DrawIconEx_helper(hDC,x,iconY,hIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), 0, NULL,DI_NORMAL| ((hxIcon && (p.xStatusMode&4))?(192 << 24):0 ) | dim ); } if (hxIcon || hIcon) { /* TODO g_StatusBarData.bDrawLockOverlay options to draw locked proto*/ if ( db_get_b(NULL, p.AccountName,"LockMainStatus", 0)) { HICON hLockOverlay = LoadSkinnedIcon(SKINICON_OTHER_STATUS_LOCKED); if (hLockOverlay != NULL) { mod_DrawIconEx_helper(hDC, x, iconY, hLockOverlay, GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), 0, NULL,DI_NORMAL | dim); Skin_ReleaseIcon(hLockOverlay); } } } if (hxIcon) DestroyIcon_protect(hxIcon); if (NeedDestroy) DestroyIcon_protect(hIcon); else Skin_ReleaseIcon(hIcon); x += GetSystemMetrics(SM_CXSMICON)+1; } if (p.showProtoName) { SIZE textSize; RECT rt = r; rt.left = x+(spaceWidth>>1); rt.top = textY; ske_DrawText(hDC, p.ProtoHumanName, lstrlen(p.ProtoHumanName), &rt, 0); if ((p.showProtoEmails && p.ProtoEMailCount != NULL) || p.showStatusName || ((p.xStatusMode & 8) && p.ProtoXStatus)) { GetTextExtentPoint32(hDC, p.ProtoHumanName, lstrlen(p.ProtoHumanName), &textSize); x += textSize.cx + 3; } } if (p.showProtoEmails && p.ProtoEMailCount != NULL) { SIZE textSize; RECT rt = r; rt.left = x+(spaceWidth>>1); rt.top = textY; ske_DrawTextA(hDC, p.ProtoEMailCount, lstrlenA(p.ProtoEMailCount), &rt, 0); if (p.showStatusName || ((p.xStatusMode & 8) && p.ProtoXStatus)) { GetTextExtentPoint32A(hDC,p.ProtoEMailCount,lstrlenA(p.ProtoEMailCount),&textSize); x += textSize.cx+3; } }
VarDescr(LPCSTR var, PBYTE value, int len) : szVar(mir_strdup(var)), szValue((char*)memcpy(mir_alloc(len), value, len)), iLen(len) {}
static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam) { switch(msg) { case WM_INITDIALOG: { LCID locale; hwndSettingsDlg=hwndDlg; TranslateDialogDefault(hwndDlg); locale=CallService(MS_LANGPACK_GETLOCALE,0,0); SendDlgItemMessage(hwndDlg,IDC_ICON_HEADER,STM_SETIMAGE,IMAGE_ICON,(LPARAM)Skin_GetIcon("AutoShutdown_Header")); { HFONT hBoldFont; LOGFONT lf; if (GetObject((HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0),sizeof(lf),&lf)) { lf.lfWeight=FW_BOLD; hBoldFont=CreateFontIndirect(&lf); } else hBoldFont=NULL; SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_SETFONT,(WPARAM)hBoldFont,FALSE); } /* read-in watcher flags */ { WORD watcherType=db_get_w(NULL,"AutoShutdown","WatcherFlags",SETTING_WATCHERFLAGS_DEFAULT); CheckRadioButton(hwndDlg,IDC_RADIO_STTIME,IDC_RADIO_STCOUNTDOWN,(watcherType&SDWTF_ST_TIME)?IDC_RADIO_STTIME:IDC_RADIO_STCOUNTDOWN); CheckDlgButton(hwndDlg,IDC_CHECK_SPECIFICTIME,(watcherType&SDWTF_SPECIFICTIME) != 0 ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg,IDC_CHECK_MESSAGE,(watcherType&SDWTF_MESSAGE) != 0 ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg,IDC_CHECK_FILETRANSFER,(watcherType&SDWTF_FILETRANSFER) != 0 ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg,IDC_CHECK_IDLE,(watcherType&SDWTF_IDLE) != 0 ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg,IDC_CHECK_STATUS,(watcherType&SDWTF_STATUS) != 0 ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg,IDC_CHECK_CPUUSAGE,(watcherType&SDWTF_CPUUSAGE) != 0 ? BST_CHECKED : BST_UNCHECKED); } /* read-in countdown val */ { SYSTEMTIME st; if (!TimeStampToSystemTime((time_t)db_get_dw(NULL,"AutoShutdown","TimeStamp",SETTING_TIMESTAMP_DEFAULT),&st)) GetLocalTime(&st); DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),GDT_VALID,&st); DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),GDT_VALID,&st); SendMessage(hwndDlg,M_CHECK_DATETIME,0,0); } { DWORD setting=db_get_dw(NULL,"AutoShutdown","Countdown",SETTING_COUNTDOWN_DEFAULT); if (setting<1) setting=SETTING_COUNTDOWN_DEFAULT; SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETRANGE,0,MAKELPARAM(UD_MAXVAL,1)); SendDlgItemMessage(hwndDlg,IDC_EDIT_COUNTDOWN,EM_SETLIMITTEXT,(WPARAM)10,0); SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETPOS,0,MAKELPARAM(setting,0)); SetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,setting,FALSE); } { HWND hwndCombo=GetDlgItem(hwndDlg,IDC_COMBO_COUNTDOWNUNIT); DWORD lastUnit=db_get_dw(NULL,"AutoShutdown","CountdownUnit",SETTING_COUNTDOWNUNIT_DEFAULT); SendMessage(hwndCombo,CB_SETLOCALE,(WPARAM)locale,0); /* sort order */ SendMessage(hwndCombo,CB_INITSTORAGE,SIZEOF(unitNames),SIZEOF(unitNames)*16); /* approx. */ for(int i=0;i<SIZEOF(unitNames);++i) { int index=SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)TranslateTS(unitNames[i])); if (index != LB_ERR) { SendMessage(hwndCombo,CB_SETITEMDATA,index,(LPARAM)unitValues[i]); if (i==0 || unitValues[i]==lastUnit) SendMessage(hwndCombo,CB_SETCURSEL,index,0); } } } { DBVARIANT dbv; if (!db_get_ts(NULL,"AutoShutdown","Message",&dbv)) { SetDlgItemText(hwndDlg,IDC_EDIT_MESSAGE,dbv.ptszVal); mir_free(dbv.ptszVal); } } /* cpuusage threshold */ { BYTE setting=DBGetContactSettingRangedByte(NULL,"AutoShutdown","CpuUsageThreshold",SETTING_CPUUSAGETHRESHOLD_DEFAULT,1,100); SendDlgItemMessage(hwndDlg,IDC_SPIN_CPUUSAGE,UDM_SETRANGE,0,MAKELPARAM(100,1)); SendDlgItemMessage(hwndDlg,IDC_EDIT_CPUUSAGE,EM_SETLIMITTEXT,(WPARAM)3,0); SendDlgItemMessage(hwndDlg,IDC_SPIN_CPUUSAGE,UDM_SETPOS,0,MAKELPARAM(setting,0)); SetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,setting,FALSE); } /* shutdown types */ { HWND hwndCombo=GetDlgItem(hwndDlg,IDC_COMBO_SHUTDOWNTYPE); BYTE lastShutdownType=db_get_b(NULL,"AutoShutdown","ShutdownType",SETTING_SHUTDOWNTYPE_DEFAULT); SendMessage(hwndCombo,CB_SETLOCALE,(WPARAM)locale,0); /* sort order */ SendMessage(hwndCombo,CB_SETEXTENDEDUI,TRUE,0); SendMessage(hwndCombo,CB_INITSTORAGE,SDSDT_MAX,SDSDT_MAX*32); for(BYTE shutdownType=1;shutdownType<=SDSDT_MAX;++shutdownType) if (ServiceIsTypeEnabled(shutdownType,0)) { TCHAR *pszText=(TCHAR*)ServiceGetTypeDescription(shutdownType,GSTDF_TCHAR); /* never fails */ int index=SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)pszText); if (index != LB_ERR) { SendMessage(hwndCombo,CB_SETITEMDATA,index,(LPARAM)shutdownType); if (shutdownType==1 || shutdownType==lastShutdownType) SendMessage(hwndCombo,CB_SETCURSEL,(WPARAM)index,0); } } SendMessage(hwndDlg,M_UPDATE_SHUTDOWNDESC,0,(LPARAM)hwndCombo); } /* check if proto is installed that supports instant messages and check if a message dialog plugin is installed */ if (!AnyProtoHasCaps(PF1_IMRECV) || !ServiceExists(MS_MSG_SENDMESSAGE)) { /* no srmessage present? */ CheckDlgButton(hwndDlg, IDC_CHECK_MESSAGE, BST_UNCHECKED); EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_MESSAGE),FALSE); EnableWindow(GetDlgItem(hwndDlg,IDC_EDIT_MESSAGE),FALSE); } /* check if proto is installed that supports file transfers and check if a file transfer dialog is available */ if (!AnyProtoHasCaps(PF1_FILESEND) && !AnyProtoHasCaps(PF1_FILERECV)) { /* no srfile present? */ CheckDlgButton(hwndDlg, IDC_CHECK_FILETRANSFER, BST_UNCHECKED); EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_FILETRANSFER),FALSE); } /* check if cpu usage can be detected */ if (!PollCpuUsage(DisplayCpuUsageProc,(LPARAM)GetDlgItem(hwndDlg,IDC_TEXT_CURRENTCPU),1800)) { CheckDlgButton(hwndDlg, IDC_CHECK_CPUUSAGE, BST_UNCHECKED); EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_CPUUSAGE),FALSE); } SendMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0); Utils_RestoreWindowPositionNoSize(hwndDlg,NULL,"AutoShutdown","SettingsDlg_"); return TRUE; /* default focus */ } case WM_DESTROY: { Utils_SaveWindowPosition(hwndDlg,NULL,"AutoShutdown","SettingsDlg_"); HICON hIcon=(HICON)SendDlgItemMessage(hwndDlg,IDC_ICON_HEADER,STM_SETIMAGE,IMAGE_ICON,0); HFONT hFont=(HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0); SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_SETFONT,0,FALSE); /* no return value */ if (hFont != NULL) DeleteObject(hFont); hwndSettingsDlg=NULL; } return TRUE; case WM_CTLCOLORSTATIC: switch(GetDlgCtrlID((HWND)lParam)) { case IDC_ICON_HEADER: SetBkMode((HDC)wParam,TRANSPARENT); case IDC_RECT_HEADER: /* need to set COLOR_WINDOW manually for Win9x */ SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW)); return (BOOL)GetSysColorBrush(COLOR_WINDOW); case IDC_TEXT_HEADER: case IDC_TEXT_HEADERDESC: SetBkMode((HDC)wParam,TRANSPARENT); return (BOOL)GetStockObject(NULL_BRUSH); } break; case M_ENABLE_SUBCTLS: { BOOL checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE) != 0; EnableDlgItem(hwndDlg,IDC_EDIT_MESSAGE,checked); checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) != 0; EnableDlgItem(hwndDlg,IDC_RADIO_STTIME,checked); EnableDlgItem(hwndDlg,IDC_RADIO_STCOUNTDOWN,checked); checked=(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) && IsDlgButtonChecked(hwndDlg,IDC_RADIO_STTIME)); EnableDlgItem(hwndDlg,IDC_TIME_TIMESTAMP,checked); EnableDlgItem(hwndDlg,IDC_DATE_TIMESTAMP,checked); checked=(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) && IsDlgButtonChecked(hwndDlg,IDC_RADIO_STCOUNTDOWN)); EnableDlgItem(hwndDlg,IDC_EDIT_COUNTDOWN,checked); EnableDlgItem(hwndDlg,IDC_SPIN_COUNTDOWN,checked); EnableDlgItem(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,checked); checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE) != 0; EnableDlgItem(hwndDlg,IDC_URL_IDLE,checked); checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE) != 0; EnableDlgItem(hwndDlg,IDC_EDIT_CPUUSAGE,checked); EnableDlgItem(hwndDlg,IDC_SPIN_CPUUSAGE,checked); EnableDlgItem(hwndDlg,IDC_TEXT_PERCENT,checked); EnableDlgItem(hwndDlg,IDC_TEXT_CURRENTCPU,checked); checked=(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) || IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE) || IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE) || IsDlgButtonChecked(hwndDlg,IDC_CHECK_STATUS) || IsDlgButtonChecked(hwndDlg,IDC_CHECK_FILETRANSFER) || IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE)); EnableDlgItem(hwndDlg,IDOK,checked); } return TRUE; case M_UPDATE_SHUTDOWNDESC: /* lParam=(LPARAM)(HWND)hwndCombo */ { BYTE shutdownType = (BYTE)SendMessage((HWND)lParam,CB_GETITEMDATA,SendMessage((HWND)lParam,CB_GETCURSEL,0,0),0); SetDlgItemText(hwndDlg,IDC_TEXT_SHUTDOWNTYPE,(TCHAR*)ServiceGetTypeDescription(shutdownType,GSTDF_LONGDESC|GSTDF_TCHAR)); } return TRUE; case WM_TIMECHANGE: /* system time changed */ SendMessage(hwndDlg,M_CHECK_DATETIME,0,0); return TRUE; case M_CHECK_DATETIME: { SYSTEMTIME st,stBuf; time_t timestamp; DateTime_GetSystemtime(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),&stBuf); DateTime_GetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),&st); st.wDay=stBuf.wDay; st.wDayOfWeek=stBuf.wDayOfWeek; st.wMonth=stBuf.wMonth; st.wYear=stBuf.wYear; GetLocalTime(&stBuf); if (SystemTimeToTimeStamp(&st,×tamp)) { /* set to current date if earlier */ if (timestamp<time(NULL)) { st.wDay=stBuf.wDay; st.wDayOfWeek=stBuf.wDayOfWeek; st.wMonth=stBuf.wMonth; st.wYear=stBuf.wYear; if (SystemTimeToTimeStamp(&st,×tamp)) { /* step one day up if still earlier */ if (timestamp<time(NULL)) { timestamp+=24*60*60; TimeStampToSystemTime(timestamp,&st); } } } } DateTime_SetRange(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),GDTR_MIN,&stBuf); DateTime_SetRange(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),GDTR_MIN,&stBuf); DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),GDT_VALID,&st); DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),GDT_VALID,&st); return TRUE; } case WM_NOTIFY: switch(((NMHDR*)lParam)->idFrom) { case IDC_TIME_TIMESTAMP: case IDC_DATE_TIMESTAMP: switch(((NMHDR*)lParam)->code) { case DTN_CLOSEUP: case NM_KILLFOCUS: PostMessage(hwndDlg,M_CHECK_DATETIME,0,0); return TRUE; } } break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_CHECK_MESSAGE: case IDC_CHECK_FILETRANSFER: case IDC_CHECK_IDLE: case IDC_CHECK_CPUUSAGE: case IDC_CHECK_STATUS: case IDC_CHECK_SPECIFICTIME: case IDC_RADIO_STTIME: case IDC_RADIO_STCOUNTDOWN: SendMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0); return TRUE; case IDC_EDIT_COUNTDOWN: if (HIWORD(wParam)==EN_KILLFOCUS) { if ((int)GetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,NULL,TRUE)<1) { SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETPOS,0,MAKELPARAM(1,0)); SetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,1,FALSE); } return TRUE; } break; case IDC_EDIT_CPUUSAGE: if (HIWORD(wParam)==EN_KILLFOCUS) { WORD val=(WORD)GetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,NULL,FALSE); if (val<1) val=1; else if (val>100) val=100; SendDlgItemMessage(hwndDlg,IDC_SPIN_CPUUSAGE,UDM_SETPOS,0,MAKELPARAM(val,0)); SetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,val,FALSE); return TRUE; } break; case IDC_URL_IDLE: { OPENOPTIONSDIALOG ood; ood.cbSize = sizeof(ood); ood.pszGroup = "Status"; /* autotranslated */ ood.pszPage = "Idle"; /* autotranslated */ ood.pszTab = NULL; Options_Open(&ood); return TRUE; } case IDC_COMBO_SHUTDOWNTYPE: if (HIWORD(wParam)==CBN_SELCHANGE) SendMessage(hwndDlg,M_UPDATE_SHUTDOWNDESC,0,lParam); return TRUE; case IDOK: /* save settings and start watcher */ ShowWindow(hwndDlg,SW_HIDE); /* message text */ { HWND hwndEdit=GetDlgItem(hwndDlg,IDC_EDIT_MESSAGE); int len=GetWindowTextLength(hwndEdit)+1; TCHAR *pszText=(TCHAR*)mir_alloc(len*sizeof(TCHAR)); if (pszText != NULL && GetWindowText(hwndEdit,pszText,len+1)) { TrimString(pszText); db_set_ts(NULL,"AutoShutdown","Message",pszText); } mir_free(pszText); /* does NULL check */ } /* timestamp */ { SYSTEMTIME st; time_t timestamp; DateTime_GetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),&st); /* time gets synchronized */ if (!SystemTimeToTimeStamp(&st,×tamp)) timestamp=time(NULL); db_set_dw(NULL,"AutoShutdown","TimeStamp",(DWORD)timestamp); } /* shutdown type */ { int index = SendDlgItemMessage(hwndDlg,IDC_COMBO_SHUTDOWNTYPE,CB_GETCURSEL,0,0); if (index != LB_ERR) db_set_b(NULL,"AutoShutdown","ShutdownType",(BYTE)SendDlgItemMessage(hwndDlg,IDC_COMBO_SHUTDOWNTYPE,CB_GETITEMDATA,(WPARAM)index,0)); index=SendDlgItemMessage(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,CB_GETCURSEL,0,0); if (index != LB_ERR) db_set_dw(NULL,"AutoShutdown","CountdownUnit",(DWORD)SendDlgItemMessage(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,CB_GETITEMDATA,(WPARAM)index,0)); db_set_dw(NULL,"AutoShutdown","Countdown",(DWORD)GetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,NULL,FALSE)); db_set_b(NULL,"AutoShutdown","CpuUsageThreshold",(BYTE)GetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,NULL,FALSE)); } /* watcher type */ { WORD watcherType = (WORD)(IsDlgButtonChecked(hwndDlg,IDC_RADIO_STTIME)?SDWTF_ST_TIME:SDWTF_ST_COUNTDOWN); if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME)) watcherType|=SDWTF_SPECIFICTIME; if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE)) watcherType|=SDWTF_MESSAGE; if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_FILETRANSFER)) watcherType|=SDWTF_FILETRANSFER; if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE)) watcherType|=SDWTF_IDLE; if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_STATUS)) watcherType|=SDWTF_STATUS; if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE)) watcherType|=SDWTF_CPUUSAGE; db_set_w(NULL,"AutoShutdown","WatcherFlags",watcherType); ServiceStartWatcher(0,watcherType); } DestroyWindow(hwndDlg); return TRUE; /* fall through */ case IDCANCEL: /* WM_CLOSE */ DestroyWindow(hwndDlg); SetShutdownToolbarButton(false); SetShutdownMenuItem(false); return TRUE; } break; } return FALSE; }
static INT_PTR CALLBACK FtMgrPageDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { struct TFtPageData *dat = (struct TFtPageData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: { // Force scrollbar visibility SCROLLINFO si = {0}; si.cbSize = sizeof(si); si.fMask = SIF_DISABLENOSCROLL; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); dat = (struct TFtPageData *)mir_alloc(sizeof(struct TFtPageData)); dat->wnds = (struct TLayoutWindowList *)List_Create(0, 1); dat->scrollPos = 0; dat->runningCount = 0; SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat); break; } case WM_FT_ADD: { struct TLayoutWindowInfo *wnd = (struct TLayoutWindowInfo *)mir_alloc(sizeof(struct TLayoutWindowInfo)); wnd->hwnd = (HWND)lParam; GetWindowRect(wnd->hwnd, &wnd->rc); List_Insert((SortedList *)dat->wnds, wnd, dat->wnds->realCount); LayoutTransfers(hwnd, dat); dat->runningCount++; PostMessage(GetParent(hwnd), WM_TIMER, 1, NULL); break; } case WM_FT_RESIZE: { int i; for (i = 0; i < dat->wnds->realCount; ++i) if (dat->wnds->items[i]->hwnd == (HWND)lParam) { GetWindowRect(dat->wnds->items[i]->hwnd, &dat->wnds->items[i]->rc); break; } LayoutTransfers(hwnd, dat); break; } case WM_FT_REMOVE: { int i; for (i = 0; i < dat->wnds->realCount; ++i) if (dat->wnds->items[i]->hwnd == (HWND)lParam) { mir_free(dat->wnds->items[i]); List_Remove((SortedList *)dat->wnds, i); break; } LayoutTransfers(hwnd, dat); break; } case WM_FT_COMPLETED: { //wParam: { ACKRESULT_SUCCESS | ACKRESULT_FAILED | ACKRESULT_DENIED } dat->runningCount--; int i = 0; while (i < dat->wnds->realCount) { // no error when canceling (WM_FT_REMOVE is send first, check if hwnd is still registered) if (dat->wnds->items[i]->hwnd == (HWND)lParam) { SendMessage(GetParent(hwnd), WM_TIMER, 1, (LPARAM)wParam); break; } ++i; } if (i == dat->wnds->realCount) PostMessage(GetParent(hwnd), WM_TIMER, 1, NULL); if(dat->runningCount == 0 && (int)wParam == ACKRESULT_SUCCESS && DBGetContactSettingByte(NULL,"SRFile","AutoClose",0)) ShowWindow(hwndFtMgr, SW_HIDE); break; } case WM_FT_CLEANUP: { int i; for (i = 0; i < dat->wnds->realCount; ++i) SendMessage(dat->wnds->items[i]->hwnd, WM_FT_CLEANUP, wParam, lParam); break; } case WM_SIZE: { LayoutTransfers(hwnd, dat); break; } case WM_MOUSEWHEEL: { int zDelta = GET_WHEEL_DELTA_WPARAM(wParam); if (zDelta) { int i, nScrollLines = 0; SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, (void*)&nScrollLines, 0); for (i = 0; i < (nScrollLines + 1) / 2; i++ ) SendMessage(hwnd, WM_VSCROLL, (zDelta < 0) ? SB_LINEDOWN : SB_LINEUP, 0); } SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0); return TRUE; } case WM_VSCROLL: { int pos = dat->scrollPos; switch (LOWORD(wParam)) { case SB_LINEDOWN: pos += 15; break; case SB_LINEUP: pos -= 15; break; case SB_PAGEDOWN: pos += dat->height - 10; break; case SB_PAGEUP: pos -= dat->height - 10; break; case SB_THUMBTRACK: pos = HIWORD(wParam); break; } if (pos > dat->dataHeight - dat->height) pos = dat->dataHeight - dat->height; if (pos < 0) pos = 0; if (dat->scrollPos != pos) { ScrollWindow(hwnd, 0, dat->scrollPos - pos, NULL, NULL); SetScrollPos(hwnd, SB_VERT, pos, TRUE); dat->scrollPos = pos; } break; } case M_PRESHUTDOWN: { int i; for (i = 0; i < dat->wnds->realCount; ++i) PostMessage(dat->wnds->items[i]->hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED), 0); break; } case WM_DESTROY: { int i; for (i = 0; i < dat->wnds->realCount; ++i) mir_free(dat->wnds->items[i]); List_Destroy((SortedList *)dat->wnds); mir_free(dat->wnds); mir_free(dat); break; } case M_CALCPROGRESS: { int i; TFtProgressData * prg = (TFtProgressData *)wParam; for (i = 0; i < dat->wnds->realCount; ++i) { struct FileDlgData *trdat = (struct FileDlgData *)GetWindowLongPtr(dat->wnds->items[i]->hwnd, GWLP_USERDATA); if (trdat->transferStatus.totalBytes && trdat->fs && !trdat->send && (trdat->transferStatus.totalBytes == trdat->transferStatus.totalProgress)) { prg->scan++; } else if (trdat->transferStatus.totalBytes && trdat->fs) { // in progress prg->run++; prg->totalBytes += trdat->transferStatus.totalBytes; prg->totalProgress += trdat->transferStatus.totalProgress; } else if (trdat->fs) { // starting prg->init++; } } } } return FALSE; }
CMsnProto::CMsnProto(const char* aProtoName, const TCHAR* aUserName) : PROTO<CMsnProto>(aProtoName, aUserName), m_arContacts(10, CompareLists), m_arGroups(10, CompareId), m_arThreads(10, PtrKeySortT), m_arGCThreads(10, PtrKeySortT), #ifdef OBSOLETE m_arSessions(10, PtrKeySortT), m_arDirect(10, PtrKeySortT), #endif lsMessageQueue(1), lsAvatarQueue(1), msgCache(5, CompareId) { db_set_resident(m_szModuleName, "IdleTS"); db_set_resident(m_szModuleName, "p2pMsgId"); db_set_resident(m_szModuleName, "MobileEnabled"); db_set_resident(m_szModuleName, "MobileAllowed"); // Protocol services and events... CreateProtoService(PS_CREATEACCMGRUI, &CMsnProto::SvcCreateAccMgrUI); CreateProtoService(PS_GETAVATARINFO, &CMsnProto::GetAvatarInfo); CreateProtoService(PS_GETMYAWAYMSG, &CMsnProto::GetMyAwayMsg); CreateProtoService(PS_LEAVECHAT, &CMsnProto::OnLeaveChat); CreateProtoService(PS_GETMYAVATAR, &CMsnProto::GetAvatar); CreateProtoService(PS_SETMYAVATAR, &CMsnProto::SetAvatar); CreateProtoService(PS_GETAVATARCAPS, &CMsnProto::GetAvatarCaps); CreateProtoService(PS_SETMYNICKNAME, &CMsnProto::SetNickName); #ifdef OBSOLETE CreateProtoService(PS_GET_LISTENINGTO, &CMsnProto::GetCurrentMedia); CreateProtoService(PS_SET_LISTENINGTO, &CMsnProto::SetCurrentMedia); MsgQueue_Init(); #endif hMSNNudge = CreateProtoEvent("/Nudge"); CreateProtoService(PS_SEND_NUDGE, &CMsnProto::SendNudge); CreateProtoService(PS_GETUNREADEMAILCOUNT, &CMsnProto::GetUnreadEmailCount); // event hooks HookProtoEvent(ME_MSG_WINDOWPOPUP, &CMsnProto::OnWindowPopup); HookProtoEvent(ME_CLIST_GROUPCHANGE, &CMsnProto::OnGroupChange); HookProtoEvent(ME_OPT_INITIALISE, &CMsnProto::OnOptionsInit); HookProtoEvent(ME_CLIST_DOUBLECLICKED, &CMsnProto::OnContactDoubleClicked); LoadOptions(); for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { delSetting(hContact, "Status"); delSetting(hContact, "IdleTS"); delSetting(hContact, "p2pMsgId"); delSetting(hContact, "AccList"); } delSetting("MobileEnabled"); delSetting("MobileAllowed"); char path[MAX_PATH]; if (db_get_static(NULL, m_szModuleName, "LoginServer", path, sizeof(path)) == 0 && (mir_strcmp(path, MSN_DEFAULT_LOGIN_SERVER) == 0 || mir_strcmp(path, MSN_DEFAULT_GATEWAY) == 0)) delSetting("LoginServer"); if (MyOptions.SlowSend) { if (db_get_dw(NULL, "SRMsg", "MessageTimeout", 10000) < 60000) db_set_dw(NULL, "SRMsg", "MessageTimeout", 60000); if (db_get_dw(NULL, "SRMM", "MessageTimeout", 10000) < 60000) db_set_dw(NULL, "SRMM", "MessageTimeout", 60000); } mailsoundname = (char*)mir_alloc(64); mir_snprintf(mailsoundname, 64, "%s:Hotmail", m_szModuleName); SkinAddNewSoundExT(mailsoundname, m_tszUserName, LPGENT("Live Mail")); alertsoundname = (char*)mir_alloc(64); mir_snprintf(alertsoundname, 64, "%s:Alerts", m_szModuleName); SkinAddNewSoundExT(alertsoundname, m_tszUserName, LPGENT("Live Alert")); AvatarQueue_Init(); InitCustomFolders(); TCHAR szBuffer[MAX_PATH]; char szDbsettings[64]; NETLIBUSER nlu1 = { 0 }; nlu1.cbSize = sizeof(nlu1); nlu1.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR; nlu1.szSettingsModule = szDbsettings; nlu1.ptszDescriptiveName = szBuffer; mir_snprintf(szDbsettings, _countof(szDbsettings), "%s_HTTPS", m_szModuleName); mir_sntprintf(szBuffer, TranslateT("%s plugin HTTPS connections"), m_tszUserName); hNetlibUserHttps = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu1); NETLIBUSER nlu = { 0 }; nlu.cbSize = sizeof(nlu); nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR; nlu.szSettingsModule = m_szModuleName; nlu.ptszDescriptiveName = szBuffer; nlu.szHttpGatewayUserAgent = (char*)MSN_USER_AGENT; nlu.pfnHttpGatewayInit = msn_httpGatewayInit; nlu.pfnHttpGatewayWrapSend = msn_httpGatewayWrapSend; nlu.pfnHttpGatewayUnwrapRecv = msn_httpGatewayUnwrapRecv; mir_sntprintf(szBuffer, TranslateT("%s plugin connections"), m_tszUserName); m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); m_DisplayNameCache = NULL; }
//see Q160957 and http://developer.netscape.com/docs/manuals/communicator/DDE/index.htm static void GetOpenBrowserUrlsForBrowser(const char *szBrowser, HWND hwndDlg, HWND hwndCombo) { ATOM hSzBrowser, hSzTopic; int windowCount, i; DWORD *windowId; DWORD dwResult; HGLOBAL hData; DDEDATA *data; int dataLength; hSzBrowser = GlobalAddAtomA(szBrowser); hSzTopic = GlobalAddAtomA("WWW_ListWindows"); ddeAcked = 0; if ( !SendMessageTimeout(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)hwndDlg, MAKELPARAM(hSzBrowser, hSzTopic), SMTO_ABORTIFHUNG|SMTO_NORMAL, DDEMESSAGETIMEOUT, (PDWORD_PTR)&dwResult) || !ddeAcked) { GlobalDeleteAtom(hSzTopic); GlobalDeleteAtom(hSzBrowser); return; } hData = DoDdeRequest("WWW_ListWindows", hwndDlg); if (hData == NULL) { GlobalDeleteAtom(hSzTopic); GlobalDeleteAtom(hSzBrowser); return; } dataLength = GlobalSize(hData)-offsetof(DDEDATA, Value); data = (DDEDATA*)GlobalLock(hData); windowCount = dataLength/sizeof(DWORD); windowId = (PDWORD)mir_alloc(sizeof(DWORD)*windowCount); memcpy(windowId, data->Value, windowCount*sizeof(DWORD)); GlobalUnlock(hData); FreeDdeRequestData(hData); PostMessage(hwndDde, WM_DDE_TERMINATE, (WPARAM)hwndDlg, 0); GlobalDeleteAtom(hSzTopic); hSzTopic = GlobalAddAtomA("WWW_GetWindowInfo"); ddeAcked = 0; if ( !SendMessageTimeout(HWND_BROADCAST, WM_DDE_INITIATE, (WPARAM)hwndDlg, MAKELPARAM(hSzBrowser, hSzTopic), SMTO_ABORTIFHUNG|SMTO_NORMAL, DDEMESSAGETIMEOUT, (PDWORD_PTR)&dwResult) || !ddeAcked) { GlobalDeleteAtom(hSzTopic); GlobalDeleteAtom(hSzBrowser); mir_free(windowId); return; } for (i=0;i<windowCount;i++) { if (windowId[i] == 0) break; { char str[16]; mir_snprintf(str, SIZEOF(str), "%d", windowId[i]); hData = DoDdeRequest(str, hwndDlg); } if (hData != NULL) { dataLength = GlobalSize(hData)-offsetof(DDEDATA, Value); data = (DDEDATA*)GlobalLock(hData); AddBrowserPageToCombo((char*)data->Value, hwndCombo); GlobalUnlock(hData); FreeDdeRequestData(hData); } } PostMessage(hwndDde, WM_DDE_TERMINATE, (WPARAM)hwndDlg, 0); GlobalDeleteAtom(hSzTopic); GlobalDeleteAtom(hSzBrowser); mir_free(windowId); }
void InitIcons() { // all those flag icons storing in a large 24bit opaque bitmap to reduce file size FIBITMAP *dib = LoadResource(IDB_FLAGSPNG, _T("PNG")); if (dib == NULL) return; if (FIP->FI_GetBPP(dib) != ILC_COLOR32) if (NULL == (dib = ConvertTo(dib, ILC_COLOR32, 0))) return; // create new dib FIBITMAP *dib_ico = FIP->FI_Allocate(FIP->FI_GetWidth(dib), 16, ILC_COLOR32, 0, 0, 0); if (dib_ico == NULL) { FIP->FI_Unload(dib); return; } UINT h = FIP->FI_GetHeight(dib_ico); UINT w = FIP->FI_GetWidth(dib_ico); UINT t = ((h - FIP->FI_GetHeight(dib)) / 2) + 1; UINT b = t + FIP->FI_GetHeight(dib); // copy dib to new dib_ico (centered) if (FIP->FI_Paste(dib_ico, dib, 0, t - 1, 255 + 1)) { FIP->FI_Unload(dib); dib = NULL; // Calculate the number of bytes per pixel (3 for 24-bit or 4 for 32-bit) int bytespp = FIP->FI_GetLine(dib_ico) / w; // set alpha schannel for (unsigned y = 0; y < h; y++) { BYTE *bits = FIP->FI_GetScanLine(dib_ico, y); for (unsigned x = 0; x < w; x++) { bits[FI_RGBA_ALPHA] = (y < t || y >= b) ? 0 : 255; // jump to next pixel bits += bytespp; } } } else { FIP->FI_Unload(dib); FIP->FI_Unload(dib_ico); return; } HBITMAP hScrBM = FIP->FI_CreateHBITMAPFromDIB(dib_ico); FIP->FI_Unload(dib_ico); if (!hScrBM) return; // create ImageList HIMAGELIST himl = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, nCountriesCount); ImageList_Add(himl, hScrBM, NULL); DeleteObject(hScrBM); hScrBM = NULL; if (himl != NULL) { phIconHandles = (HANDLE*)mir_alloc(nCountriesCount*sizeof(HANDLE)); if (phIconHandles != NULL) { char szId[20]; SKINICONDESC sid = { 0 }; sid.section.t = LPGENT("Country flags"); sid.pszName = szId; // name to refer to icon when playing and in db sid.flags = SIDF_SORTED | SIDF_TCHAR; for (int i=0; i < nCountriesCount; i++) { sid.description.t = mir_a2t(LPGEN(countries[i].szName)); /* create identifier */ mir_snprintf(szId, _countof(szId), (countries[i].id == 0xFFFF) ? "%s0x%X" : "%s%i", "flags_", countries[i].id); /* buffer safe */ int index = CountryNumberToBitmapIndex(countries[i].id); /* create icon */ sid.hDefaultIcon = ImageList_ExtractIcon(NULL, himl, index); index = CountryNumberToIndex(countries[i].id); phIconHandles[index] = IcoLib_AddIcon(&sid); if (sid.hDefaultIcon != NULL) DestroyIcon(sid.hDefaultIcon); mir_free(sid.description.t); sid.description.t = NULL; } } ImageList_Destroy(himl); } // create services CreateServiceFunction(MS_FLAGS_LOADFLAGICON,ServiceLoadFlagIcon); CreateServiceFunction(MS_FLAGS_CREATEMERGEDFLAGICON,ServiceCreateMergedFlagIcon); }
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+lstrlenA((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, SIZEOF(msg), TranslateT("URL from %s"), contactName); SetWindowText(hwndDlg, msg); SetDlgItemText(hwndDlg, IDC_FROM, contactName); SendDlgItemMessage(hwndDlg, IDOK, BUTTONSETARROW, 1, 0); TCHAR str[128]; tmi.printTimeStamp(NULL, dbei.timestamp, _T("t d"), str, SIZEOF(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 CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam); case WM_DRAWITEM: { LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL)) { char *szProto; szProto = GetContactProto(dat->hContact); if (szProto) { HICON 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 CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam); case DM_UPDATETITLE: sttUpdateTitle(hwndDlg, dat->hContact); break; case WM_COMMAND: if (dat) if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) break; switch(LOWORD(wParam)) { case IDOK: { HMENU hMenu, hSubMenu; RECT rc; char url[256]; hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXT)); hSubMenu = GetSubMenu(hMenu, 6); TranslateMenu(hSubMenu); GetWindowRect((HWND)lParam, &rc); GetDlgItemTextA(hwndDlg, IDC_URL, url, SIZEOF(url)); switch(TrackPopupMenu(hSubMenu, TPM_RETURNCMD, rc.left, rc.bottom, 0, hwndDlg, NULL)) { case IDM_OPENNEW: CallService(MS_UTILS_OPENURL, 1, (LPARAM)url); break; case IDM_OPENEXISTING: CallService(MS_UTILS_OPENURL, 0, (LPARAM)url); break; case IDM_COPYLINK: { HGLOBAL hData; if ( !OpenClipboard(hwndDlg)) break; EmptyClipboard(); hData = GlobalAlloc(GMEM_MOVEABLE, lstrlenA(url)+1); lstrcpyA((char*)GlobalLock(hData), url); GlobalUnlock(hData); SetClipboardData(CF_TEXT, hData); CloseClipboard(); break; } } DestroyMenu(hMenu); } return TRUE; case IDC_USERMENU: { RECT rc; HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); 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; }
static int httpTransact(char* szUrl, char* szResult, int resSize, char* szActionName, ReqType reqtype) { // Parse URL char szHost[256], szPath[256], szRes[16]; int sz = 0, res = 0; unsigned short sPort; bool needClose = false; const char* szPostHdr = soap_post_hdr; char* szData = (char*)mir_alloc(4096); char* szReq = NULL; parseURL(szUrl, szHost, &sPort, szPath); if (sPort != sConnPort || _stricmp(szHost, szConnHost)) closeRouterConnection(); else validateSocket(); while(true) { retryCount = 0; switch(reqtype) { case DeviceGetReq: sz = mir_snprintf (szData, 4096, xml_get_hdr, szPath, szHost, sPort); break; case ControlAction: { char szData1[1024]; szReq = mir_strdup(szResult); sz = mir_snprintf (szData1, SIZEOF(szData1), soap_action, szActionName, szDev, szReq, szActionName); sz = mir_snprintf (szData, 4096, szPostHdr, szPath, szHost, sPort, sz, szDev, szActionName, szData1); } break; case ControlQuery: { char szData1[1024]; sz = mir_snprintf (szData1, SIZEOF(szData1), soap_query, szActionName); sz = mir_snprintf (szData, 4096, szPostHdr, szPath, szHost, sPort, sz, "urn:schemas-upnp-org:control-1-0", "QueryStateVariable", szData1); } break; } szResult[0] = 0; { static const TIMEVAL tv = { 6, 0 }; static unsigned ttl = 4; static u_long mode = 1; fd_set rfd, wfd, efd; SOCKADDR_IN enetaddr; retrycon: if (sock == INVALID_SOCKET) { sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); enetaddr.sin_family = AF_INET; enetaddr.sin_port = htons(sPort); enetaddr.sin_addr.s_addr = inet_addr(szHost); // Resolve host name if needed if (enetaddr.sin_addr.s_addr == INADDR_NONE) { PHOSTENT he = gethostbyname(szHost); if (he) enetaddr.sin_addr.s_addr = *(unsigned*)he->h_addr_list[0]; } NetlibLogf(NULL, "UPnP HTTP connection Host: %s Port: %u", szHost, sPort); FD_ZERO(&rfd); FD_ZERO(&wfd); FD_ZERO(&efd); FD_SET(sock, &rfd); FD_SET(sock, &wfd); FD_SET(sock, &efd); // Limit the scope of the connection (does not work for setsockopt(sock, IPPROTO_IP, IP_TTL, (char *)&ttl, sizeof(unsigned)); // Put socket into non-blocking mode for timeout on connect ioctlsocket(sock, FIONBIO, &mode); // Connect to the remote host if (connect(sock, (SOCKADDR*)&enetaddr, sizeof(enetaddr)) == SOCKET_ERROR) { int err = WSAGetLastError(); // Socket connection failed if (err != WSAEWOULDBLOCK) { closeRouterConnection(); NetlibLogf(NULL, "UPnP connect failed %d", err); break; } // Wait for socket to connect else if (select(1, &rfd, &wfd, &efd, &tv) != 1) { closeRouterConnection(); NetlibLogf(NULL, "UPnP connect timeout"); break; } else if (!FD_ISSET(sock, &wfd)) { closeRouterConnection(); NetlibLogf(NULL, "UPnP connect failed"); break; } } strcpy(szConnHost, szHost); sConnPort = sPort; } if (send(sock, szData, sz, 0) != SOCKET_ERROR) { char *hdrend = NULL; int acksz = 0, pktsz = 0; if (szActionName == NULL) { int len = sizeof(locIP); getsockname(sock, (SOCKADDR*)&locIP, &len); if (locIP.sin_addr.S_un.S_addr == 0x0100007f) { struct hostent *he; gethostname(szPath, sizeof(szPath)); he = gethostbyname(szPath); if (he != NULL) locIP.sin_addr.S_un.S_addr = *(PDWORD)he->h_addr_list[0]; } } LongLog(szData); sz = 0; while(true) { int bytesRecv; FD_ZERO(&rfd); FD_SET(sock, &rfd); // Wait for the next packet if (select(1, &rfd, NULL, NULL, &tv) != 1) { closeRouterConnection(); NetlibLogf(NULL, "UPnP recieve timeout"); break; } // bytesRecv = recv(sock, &szResult[sz], resSize-sz, 0); // Connection closed or aborted, all data received if (bytesRecv == 0 || bytesRecv == SOCKET_ERROR) { closeRouterConnection(); if ((bytesRecv == SOCKET_ERROR || sz == 0) && retryCount < 2) { ++retryCount; goto retrycon; } break; } sz += bytesRecv; // Insert null terminator to use string functions if (sz >= (resSize-1)) { szResult[resSize-1] = 0; break; } else szResult[sz] = 0; // HTTP header found? if (hdrend == NULL) { // Find HTTP header end hdrend = strstr(szResult, "\r\n\r\n"); if (hdrend == NULL) { hdrend = strstr(szResult, "\n\n"); if (hdrend) hdrend += 2; } else hdrend += 4; if (hdrend != NULL) { // Get packet size if provided if (txtParseParam(szResult, NULL, "Content-Length:", "\n", szRes, sizeof(szRes)) || txtParseParam(szResult, NULL, "CONTENT-LENGTH:", "\n", szRes, sizeof(szRes))) { // Add size of HTTP header to the packet size to compute full transmission size pktsz = atol(ltrimp(szRes)) + (hdrend - szResult); } // Get encoding type if provided else if (txtParseParam(szResult, NULL, "Transfer-Encoding:", "\n", szRes, sizeof(szRes))) { if (_stricmp(lrtrimp(szRes), "Chunked") == 0) acksz = hdrend - szResult; } if (txtParseParam(szResult, NULL, "Connection:", "\n", szRes, sizeof(szRes))) { needClose = (_stricmp(lrtrimp(szRes), "close") == 0); } } } // Content-Length bytes reached, all data received if (sz >= pktsz && pktsz != 0) { szResult[pktsz] = 0; break; } // Chunked encoding processing if (sz > acksz && acksz != 0) { retry: // Parse out chunk size char* data = szResult + acksz; char* peol1 = data == hdrend ? data - 1 : strchr(data, '\n'); if (peol1 != NULL) { char *peol2 = strchr(++peol1, '\n'); if (peol2 != NULL) { // Get chunk size int chunkBytes = strtol(peol1, NULL, 16); acksz += chunkBytes; peol2++; memmove(data, peol2, strlen(peol2) + 1); sz -= peol2 - data; // Last chunk, all data received if (chunkBytes == 0) break; if (sz > acksz) goto retry; } } } } LongLog(szResult); } else { if (retryCount < 2) { closeRouterConnection(); ++retryCount; goto retrycon; } else NetlibLogf(NULL, "UPnP send failed %d", WSAGetLastError()); } } txtParseParam(szResult, "HTTP", " ", " ", szRes, sizeof(szRes)); res = atol(szRes); if (szActionName != NULL && res == 405 && szPostHdr == soap_post_hdr) szPostHdr = soap_post_hdr_m; else break; } if (needClose) closeRouterConnection(); mir_free(szData); mir_free(szReq); return res; }
static int CustomButtonPressed(WPARAM, LPARAM lParam) { CustomButtonClickData *cbcd = (CustomButtonClickData *)lParam; CHARRANGE cr; HWND hEdit = NULL; BOOL bCTRL = 0; BOOL bIsService = 0; TCHAR* pszText = NULL; TCHAR* pszCBText = NULL; TCHAR* ptszQValue = NULL; UINT textlenght = 0; SortedList* sl = NULL; int state = 0; if (mir_strcmp(cbcd->pszModule, PLGNAME)) return 0; if (!ButtonsList[cbcd->dwButtonId]) return 1; sl = ButtonsList[cbcd->dwButtonId]->sl; if (!sl) return 1; if (IsClipboardFormatAvailable(CF_TEXT)) { if (OpenClipboard(cbcd->hwndFrom)) { HANDLE hData = NULL; TCHAR* chBuffer = NULL; int textLength = 0; hData = GetClipboardData(CF_UNICODETEXT); chBuffer = (TCHAR*)GlobalLock(hData); textLength = (int)mir_tstrlen(chBuffer); pszCBText = mir_tstrdup(chBuffer); GlobalUnlock(hData); CloseClipboard(); } } qsort(sl->items, sl->realCount, sizeof(ButtonData *), sstSortButtons); hEdit = GetDlgItem(cbcd->hwndFrom, IDC_MESSAGE); if (!hEdit) hEdit = GetDlgItem(cbcd->hwndFrom, IDC_CHATMESSAGE); cr.cpMin = cr.cpMax = 0; SendMessage(hEdit, EM_EXGETSEL, 0, (LPARAM)&cr); textlenght = cr.cpMax - cr.cpMin; if (textlenght) { pszText = (TCHAR *)mir_alloc((textlenght + 10)*sizeof(TCHAR)); memset(pszText, 0, ((textlenght + 10) * sizeof(TCHAR))); SendMessage(hEdit, EM_GETSELTEXT, 0, (LPARAM)pszText); } if (cbcd->flags&BBCF_RIGHTBUTTON) state = 1; else if (sl->realCount == 1) state = 2; else state = 3; switch (state) { case 1: if (ButtonsList[cbcd->dwButtonId]->ptszQValue) ptszQValue = ParseString(cbcd->hContact, ButtonsList[cbcd->dwButtonId]->ptszQValue, pszText ? pszText : _T(""), pszCBText ? pszCBText : _T(""), (int)mir_tstrlen(ButtonsList[cbcd->dwButtonId]->ptszQValue), textlenght, pszCBText ? (int)mir_tstrlen(pszCBText) : 0); if ((bIsService = ButtonsList[cbcd->dwButtonId]->bIsServName) && ptszQValue) CallService(mir_u2a(ptszQValue), (WPARAM)cbcd->hContact, 0); break; case 2: { ButtonData *bd = (ButtonData *)sl->items[0]; if (bd && bd->pszValue) { ptszQValue = ParseString(cbcd->hContact, bd->pszValue, pszText ? pszText : _T(""), pszCBText ? pszCBText : _T(""), (int)mir_tstrlen(bd->pszValue), textlenght, pszCBText ? (int)mir_tstrlen(pszCBText) : 0); if ((bIsService = bd->bIsServName) && ptszQValue) CallService(mir_u2a(ptszQValue), (WPARAM)cbcd->hContact, 0); } } break; case 3: if (!g_iButtonsCount) break; HMENU hMenu = CreatePopupMenu(), hSubMenu = NULL; for (int menunum = 0; menunum < sl->realCount; menunum++) { ButtonData *bd = (ButtonData *)sl->items[menunum]; if (bd->dwOPFlags&QMF_NEW) continue; BOOL bSetPopupMark = FALSE; if (bd->pszValue == 0 && bd->fEntryType == 0) { hSubMenu = CreatePopupMenu(); bSetPopupMark = TRUE; } if (bd->pszValue && bd->fEntryType == 0) hSubMenu = NULL; if (bd->fEntryType&QMF_EX_SEPARATOR) AppendMenu((HMENU)((hSubMenu && !bSetPopupMark) ? hSubMenu : hMenu), MF_SEPARATOR, 0, NULL); else AppendMenu((HMENU)((hSubMenu && !bSetPopupMark) ? hSubMenu : hMenu), MF_STRING | (bSetPopupMark ? MF_POPUP : 0), (bSetPopupMark ? (UINT_PTR)hSubMenu : (menunum + 1)), bd->pszName); } int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbcd->pt.x, cbcd->pt.y, 0, cbcd->hwndFrom, NULL); if (res == 0) break; ButtonData *bd = (ButtonData *)sl->items[res - 1]; bCTRL = (GetKeyState(VK_CONTROL) & 0x8000) ? 1 : 0; if (bd->pszValue) { ptszQValue = ParseString(cbcd->hContact, bd->pszValue, pszText ? pszText : _T(""), pszCBText ? pszCBText : _T(""), (int)mir_tstrlen(bd->pszValue), textlenght, pszCBText ? (int)mir_tstrlen(pszCBText) : 0); if ((bIsService = bd->bIsServName) && ptszQValue) CallService(mir_u2a(ptszQValue), (WPARAM)cbcd->hContact, 0); } break; } if (ptszQValue) { if (!bIsService) { SendMessage(hEdit, EM_REPLACESEL, TRUE, (LPARAM)ptszQValue); if ((g_bLClickAuto&&state != 1) || (g_bRClickAuto&&state == 1) || cbcd->flags&BBCF_CONTROLPRESSED || bCTRL) SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0); } free(ptszQValue); } mir_free(pszText); mir_free(pszCBText); return 1; }
static void discoverUPnP(void) { char* buf; int buflen; unsigned i, j, nip = 0; unsigned* ips = NULL; static const unsigned any = INADDR_ANY; static const TIMEVAL tv = { 1, 600000 }; char szUrl[256] = ""; char hostname[256]; PHOSTENT he; fd_set readfd; SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); SOCKADDR_IN enetaddr; enetaddr.sin_family = AF_INET; enetaddr.sin_port = htons(1900); enetaddr.sin_addr.s_addr = inet_addr("239.255.255.250"); gethostname(hostname, sizeof(hostname)); he = gethostbyname(hostname); if (he) { while (he->h_addr_list[nip]) ++nip; ips = (unsigned*)mir_alloc(nip * sizeof(unsigned)); for (j = 0; j < nip; j++) ips[j] = *(unsigned*)he->h_addr_list[j]; } buf = (char*)mir_alloc(1500); for (i = 3; --i && szUrl[0] == 0;) { for (j = 0; j < nip; j++) { if (ips) setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&ips[j], sizeof(unsigned)); buflen = mir_snprintf(buf, 1500, search_request_msg, "WANIPConnection:1"); sendto(sock, buf, buflen, 0, (SOCKADDR*)&enetaddr, sizeof(enetaddr)); LongLog(buf); buflen = mir_snprintf(buf, 1500, search_request_msg, "WANPPPConnection:1"); sendto(sock, buf, buflen, 0, (SOCKADDR*)&enetaddr, sizeof(enetaddr)); LongLog(buf); } if (Miranda_Terminated()) break; FD_ZERO(&readfd); FD_SET(sock, &readfd); while (select(1, &readfd, NULL, NULL, &tv) >= 1) { buflen = recv(sock, buf, 1500, 0); if (buflen != SOCKET_ERROR) { buf[buflen] = 0; LongLog(buf); if (txtParseParam(buf, NULL, "LOCATION:", "\n", szUrl, sizeof(szUrl)) || txtParseParam(buf, NULL, "Location:", "\n", szUrl, sizeof(szUrl))) { char age[30]; char szHostNew[256], szHostExist[256]; lrtrim(szUrl); parseURL(szUrl, szHostNew, NULL, NULL); parseURL(szCtlUrl, szHostExist, NULL, NULL); if (strcmp(szHostNew, szHostExist) == 0) { gatewayFound = true; break; } txtParseParam(buf, NULL, "ST:", "\n", szDev, sizeof(szDev)); txtParseParam(buf, "max-age", " = ", "\n", age, sizeof(age)); expireTime = atoi(lrtrimp(age)); lrtrim(szDev); if (getUPnPURLs(szUrl, sizeof(szUrl))) { gatewayFound = getExtIP() != 0; if (gatewayFound) break; } } } FD_ZERO(&readfd); FD_SET(sock, &readfd); } } mir_free(buf); mir_free(ips); setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&any, sizeof(unsigned)); closesocket(sock); }
// load the station data from a file // pszFile = the file name + path for the ini file to be loaded // pszShortFile = the file name of the ini file, but not including the path // Data = the struct to load the ini content to, and return to previous function void LoadStationData(TCHAR *pszFile, TCHAR *pszShortFile, WIDATA *Data) { WIDATAITEM DataItem; char *Group, *Temp; char *ValName, *Value; static const char *statusStr[10] = { "LIGHTNING", "FOG", "SNOW SHOWER", "SNOW", "RAIN SHOWER", "RAIN", "PARTLY CLOUDY", "CLOUDY", "SUNNY", "N/A" }; // clean up old stuff ZeroMemory(Data, sizeof(Data)); Data->Enabled = FALSE; // open the ini file FILE *pfile = _tfsopen(pszFile, _T("rt"), _SH_DENYWR); if (pfile != NULL) { char Line[4096]; fgets(Line, SIZEOF(Line), pfile); TrimString(Line); // make sure it is a valid weather protocol ini file if ( !strcmp(Line, "[Weather 0.3.x Update Data]")) Data->InternalVer = 1; else if ( !strcmp(Line, "[Weather 0.3.x Update Data 1.1]")) Data->InternalVer = 2; else if ( !strcmp(Line, "[Weather 0.3.x Update Data 1.1a]")) Data->InternalVer = 3; else if ( !strcmp(Line, "[Weather 0.3.x Update Data 1.2]")) Data->InternalVer = 4; else if ( !strcmp(Line, "[Weather 0.3.x Update Data 1.3]")) Data->InternalVer = 5; else if ( !strcmp(Line, "[Weather 0.3.x Update Data 1.4]")) Data->InternalVer = 6; else { TCHAR str[4096]; mir_sntprintf(str, SIZEOF(str), TranslateT("Invalid ini format for: %s"), pszFile); MessageBox(NULL, str, TranslateT("Weather Protocol"), MB_OK|MB_ICONERROR); fclose(pfile); return; } // initialize all data fields Group = ""; Data->DisplayName = _T(""); Data->InternalName = _T(""); Data->Description = _T(""); Data->Author = _T(""); Data->Version = _T(""); Data->DefaultURL = ""; Data->DefaultMap = _T(""); Data->UpdateURL = ""; Data->UpdateURL2 = ""; Data->UpdateURL3 = ""; Data->UpdateURL4 = ""; Data->Cookie = ""; Data->IDSearch.SearchURL = ""; Data->IDSearch.NotFoundStr = _T(""); Data->NameSearch.SearchURL = ""; Data->NameSearch.NotFoundStr = _T(""); Data->NameSearch.SingleStr = _T(""); Data->NameSearch.Single.First = _T(""); Data->NameSearch.Multiple.First = _T(""); Data->IDSearch.Available = FALSE; Data->NameSearch.Single.Available = FALSE; Data->NameSearch.Multiple.Available = FALSE; wSetData(&Data->FileName, pszFile); wSetData(&Data->ShortFileName, pszShortFile); ResetDataItem(&Data->IDSearch.Name, _T("ID Search - Station Name")); ResetDataItem(&Data->NameSearch.Single.Name, _T("Name Search Single Result - Station Name")); ResetDataItem(&Data->NameSearch.Single.ID, _T("Name Search Single Result - Station ID")); ResetDataItem(&Data->NameSearch.Multiple.Name, _T("Name Search Multiple Result - Station Name")); ResetDataItem(&Data->NameSearch.Multiple.ID, _T("Name Search Multiple Result - Station ID")); DataItem.Name = _T(""); DataItem.Start = _T(""); DataItem.End = _T(""); DataItem.Unit = _T(""); DataItem.Url = ""; DataItem.Break = _T(""); DataItem.Type = 0; Temp = ""; // initialize the linked list for update items Data->UpdateDataCount = 0; Data->MemUsed = sizeof(WIDATA) + sizeof(WIDATALIST) + (_tcslen(pszShortFile) + _tcslen(pszFile) + 20)*sizeof( TCHAR ); Data->UpdateData = NULL; Data->UpdateDataTail = NULL; // initialize the icon assignment list for (int i=0; i<10; i++) WICondListInit( &Data->CondList[i] ); while (!feof(pfile)) { // determine current tag if (fgets(Line, SIZEOF(Line), pfile) == NULL) break; TrimString(Line); // if the line is a group header/footer if (Line[0] == '[') { char *chop = strchr(Line+1,']'); if (chop == NULL) continue; if (Line[1] != '/') { // if it is not a footer (for old ini) // save the group name Temp = (char *)mir_alloc(strlen(Line)+10); strncpy(Temp, Line+1, chop-Line-1); Temp[chop-Line-1] = 0; wfree(&Group); wSetData(&Group, Temp); // see if it is a update item, if it is, add a new item to the linked list // if (_stricmp(Group, "HEADER") && _stricmp(Group, "DEFAULT") && _stricmp(Group, "ID SEARCH") && // strcmpi(Group, "NAME SEARCH")) // wSetData(&DataItem.Name, Group); if (_stricmp(Group, "HEADER") && _stricmp(Group, "DEFAULT") && _stricmp(Group, "ID SEARCH") && _stricmp(Group, "NAME SEARCH") && _stricmp(Group, "ICONS")) { wSetData(&DataItem.Name, Temp); DataItem.Type = WID_NORMAL; WIItemListAdd(&DataItem, Data); Data->UpdateDataCount++; } mir_free(Temp); } else { wfree(&Group); wSetData(&Group, ""); } } // ignore comments and all lines without an '=' Value = strstr(Line, "="); if (Value == NULL) continue; // get the string before '=' (ValName) and after '=' (Value) ValName = (char *)mir_alloc(strlen(Line)+1); strncpy(ValName, Line, Value-Line); ValName[Value-Line] = 0; Value++; ConvertBackslashes(Value); // store the value for each string if ( !_stricmp(Group, "HEADER")) { if ( !_stricmp(ValName, "NAME")) wSetData(&Data->DisplayName, Value); else if ( !_stricmp(ValName, "INTERNAL NAME")) wSetData(&Data->InternalName, Value); else if ( !_stricmp(ValName, "DESCRIPTION")) wSetData(&Data->Description, Value); else if ( !_stricmp(ValName, "AUTHOR")) wSetData(&Data->Author, Value); else if ( !_stricmp(ValName, "VERSION")) wSetData(&Data->Version, Value); } else if ( !_stricmp(Group, "DEFAULT")) { if ( !_stricmp(ValName, "DEFAULT URL")) wSetData(&Data->DefaultURL, Value); else if ( !_stricmp(ValName, "DEFAULT MAP")) wSetData(&Data->DefaultMap, Value); else if ( !_stricmp(ValName, "UPDATE URL")) wSetData(&Data->UpdateURL, Value); else if ( !_stricmp(ValName, "UPDATE URL2")) wSetData(&Data->UpdateURL2, Value); else if ( !_stricmp(ValName, "UPDATE URL3")) wSetData(&Data->UpdateURL3, Value); else if ( !_stricmp(ValName, "UPDATE URL4")) wSetData(&Data->UpdateURL4, Value); else if ( !_stricmp(ValName, "COOKIE")) wSetData(&Data->Cookie, Value); } else if ( !_stricmp(Group, "ID SEARCH")) { if ( !_stricmp(ValName, "AVAILABLE")) { if ( !_stricmp(Value, "TRUE")) Data->IDSearch.Available = TRUE; else Data->IDSearch.Available = FALSE; } else if ( !_stricmp(ValName, "SEARCH URL")) wSetData(&Data->IDSearch.SearchURL, Value); else if ( !_stricmp(ValName, "NOT FOUND STR")) wSetData(&Data->IDSearch.NotFoundStr, Value); else if ( !_stricmp(ValName, "NAME START")) wSetData(&Data->IDSearch.Name.Start, Value); else if ( !_stricmp(ValName, "NAME END")) wSetData(&Data->IDSearch.Name.End, Value); } else if ( !_stricmp(Group, "NAME SEARCH")) { if ( !_stricmp(ValName, "SINGLE RESULT")) { if ( !_stricmp(Value, "TRUE")) Data->NameSearch.Single.Available = TRUE; else Data->NameSearch.Single.Available = FALSE; } else if ( !_stricmp(ValName, "MULTIPLE RESULT")) { if ( !_stricmp(Value, "TRUE")) Data->NameSearch.Multiple.Available = TRUE; else Data->NameSearch.Multiple.Available = FALSE; } else if ( !_stricmp(ValName, "SEARCH URL")) wSetData(&Data->NameSearch.SearchURL, Value); else if ( !_stricmp(ValName, "NOT FOUND STR")) wSetData(&Data->NameSearch.NotFoundStr, Value); else if ( !_stricmp(ValName, "SINGLE RESULT STR")) wSetData(&Data->NameSearch.SingleStr, Value); else if ( !_stricmp(ValName, "SINGLE FIRST")) wSetData(&Data->NameSearch.Single.First, Value); else if ( !_stricmp(ValName, "SINGLE NAME START"))wSetData(&Data->NameSearch.Single.Name.Start, Value); else if ( !_stricmp(ValName, "SINGLE NAME END")) wSetData(&Data->NameSearch.Single.Name.End, Value); else if ( !_stricmp(ValName, "SINGLE ID START")) wSetData(&Data->NameSearch.Single.ID.Start, Value); else if ( !_stricmp(ValName, "SINGLE ID END")) wSetData(&Data->NameSearch.Single.ID.End, Value); else if ( !_stricmp(ValName, "MULT FIRST")) wSetData(&Data->NameSearch.Multiple.First, Value); else if ( !_stricmp(ValName, "MULT NAME START")) wSetData(&Data->NameSearch.Multiple.Name.Start, Value); else if ( !_stricmp(ValName, "MULT NAME END")) wSetData(&Data->NameSearch.Multiple.Name.End, Value); else if ( !_stricmp(ValName, "MULT ID START")) wSetData(&Data->NameSearch.Multiple.ID.Start, Value); else if ( !_stricmp(ValName, "MULT ID END")) wSetData(&Data->NameSearch.Multiple.ID.End, Value); } else if ( !_stricmp(Group, "ICONS")) { for (int i=0; i<10; i++) { if ( !_stricmp(ValName, statusStr[i])) { WICondListAdd(Value, &Data->CondList[i]); break; } } } else if (Data->UpdateDataCount != 0) { if ( !_stricmp(ValName, "START")) wSetData(&Data->UpdateDataTail->Item.Start, Value); else if ( !_stricmp(ValName, "SOURCE")) wSetData(&Data->UpdateDataTail->Item.Start, Value); else if ( !_stricmp(ValName, "END")) wSetData(&Data->UpdateDataTail->Item.End, Value); else if ( !_stricmp(ValName, "UNIT")) wSetData(&Data->UpdateDataTail->Item.Unit, Value); else if ( !_stricmp(ValName, "URL")) wSetData(&Data->UpdateDataTail->Item.Url, Value); else if ( !_stricmp(ValName, "HIDDEN")) { if ( !_stricmp(Value, "TRUE")) { TCHAR *nm = Data->UpdateDataTail->Item.Name; size_t len = _tcslen(nm) + 1; Data->UpdateDataTail->Item.Name = nm = ( TCHAR* )mir_realloc(nm, sizeof(TCHAR)*(len + 3)); memmove(nm + 1, nm, len*sizeof( TCHAR )); *nm = '#'; } } else if ( !_stricmp(ValName, "SET DATA")) { Data->UpdateDataTail->Item.Type = WID_SET; wSetData(&Data->UpdateDataTail->Item.End, Value); } else if ( !_stricmp(ValName, "BREAK DATA")) { Data->UpdateDataTail->Item.Type = WID_BREAK; wSetData(&Data->UpdateDataTail->Item.Break, Value); } } // recalculate memory used Data->MemUsed += (strlen(Value) + 10); wfree(&ValName); } // calcualate memory used for the ini and close the file Data->MemUsed += sizeof(WIDATAITEMLIST)*Data->UpdateDataCount; Data->Enabled = TRUE; // enable the service fclose(pfile); wfree(&Group); } }
static void GetPluginsString(CMString& buffer, unsigned& flags) { buffer.AppendFormat(TEXT("Service Mode: %s\r\n"), servicemode ? TEXT("Yes") : TEXT("No")); TCHAR path[MAX_PATH]; GetModuleFileName(NULL, path, MAX_PATH); LPTSTR fname = _tcsrchr(path, TEXT('\\')); if (fname == NULL) fname = path; mir_sntprintf(fname, MAX_PATH - (fname - path), TEXT("\\plugins\\*.dll")); WIN32_FIND_DATA FindFileData; HANDLE hFind = FindFirstFile(path, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) return; size_t count = 0, ucount = 0; CMString ubuffer; ListItem* dlllist = NULL; static const TCHAR format[] = TEXT("%c %s v.%s%d.%d.%d.%d%s [%s] - %S %s\r\n"); do { bool loaded = false; mir_sntprintf(fname, MAX_PATH - (fname - path), TEXT("\\plugins\\%s"), FindFileData.cFileName); HMODULE hModule = GetModuleHandle(path); if (hModule == NULL && servicemode) { hModule = LoadLibrary(path); loaded = true; } if (hModule == NULL) { if ((flags & VI_FLAG_PRNVAR) && IsPluginEnabled(FindFileData.cFileName)) { TCHAR timebuf[30] = TEXT(""); GetLastWriteTime(&FindFileData.ftLastWriteTime, timebuf, 30); ubuffer.AppendFormat(format, TEXT(' '), FindFileData.cFileName, (flags & VI_FLAG_FORMAT) ? TEXT("[b]") : TEXT(""), 0, 0, 0, 0, (flags & VI_FLAG_FORMAT) ? TEXT("[/b]") : TEXT(""), timebuf, "<unknown>", TEXT("")); GetLinkedModulesInfo(path, ubuffer); ubuffer.Append(TEXT("\r\n")); ++ucount; } continue; } PLUGININFOEX* pi = GetMirInfo(hModule); if (pi != NULL) { TCHAR timebuf[30] = TEXT(""); GetLastWriteTime(&FindFileData.ftLastWriteTime, timebuf, 30); bool ep = (size_t)pi->cbSize > sizeof(PLUGININFOEX); const TCHAR *unica = (ep && ((PLUGININFOEX*)pi)->flags & 1) ? TEXT("|Unicode aware|") : TEXT(""); ListItem* lst = new ListItem; int v1, v2, v3, v4; DWORD unused, verInfoSize = GetFileVersionInfoSize(path, &unused); if (verInfoSize != 0) { UINT blockSize; VS_FIXEDFILEINFO* fi; void* pVerInfo = mir_alloc(verInfoSize); GetFileVersionInfo(path, 0, verInfoSize, pVerInfo); VerQueryValue(pVerInfo, _T("\\"), (LPVOID*)&fi, &blockSize); v1 = HIWORD(fi->dwProductVersionMS), v2 = LOWORD(fi->dwProductVersionMS), v3 = HIWORD(fi->dwProductVersionLS), v4 = LOWORD(fi->dwProductVersionLS); mir_free(pVerInfo); } else { DWORD ver = pi->version; v1 = HIBYTE(HIWORD(ver)), v2 = LOBYTE(HIWORD(ver)), v3 = HIBYTE(LOWORD(ver)), v4 = LOBYTE(LOWORD(ver)); } lst->str.AppendFormat(format, ep ? TEXT('\xa4') : TEXT(' '), FindFileData.cFileName, (flags & VI_FLAG_FORMAT) ? TEXT("[b]") : TEXT(""), v1, v2, v3, v4, (flags & VI_FLAG_FORMAT) ? TEXT("[/b]") : TEXT(""), timebuf, pi->shortName ? pi->shortName : "", unica); ListItem* lsttmp = dlllist; ListItem* lsttmppv = NULL; while (lsttmp != NULL) { if (lsttmp->str.CompareNoCase(lst->str) > 0) break; lsttmppv = lsttmp; lsttmp = lsttmp->next; } lst->next = lsttmp; if (lsttmppv == NULL) dlllist = lst; else lsttmppv->next = lst; if (_tcsicmp(FindFileData.cFileName, TEXT("weather.dll")) == 0) flags |= VI_FLAG_WEATHER; ++count; } if (loaded) FreeLibrary(hModule); } while (FindNextFile(hFind, &FindFileData)); FindClose(hFind); buffer.AppendFormat(TEXT("\r\n%sActive Plugins (%u):%s\r\n"), (flags & VI_FLAG_FORMAT) ? TEXT("[b]") : TEXT(""), count, (flags & VI_FLAG_FORMAT) ? TEXT("[/b]") : TEXT("")); ListItem* lsttmp = dlllist; while (lsttmp != NULL) { buffer.Append(lsttmp->str); ListItem* lsttmp1 = lsttmp->next; delete lsttmp; lsttmp = lsttmp1; } if (ucount) { buffer.AppendFormat(TEXT("\r\n%sUnloadable Plugins (%u):%s\r\n"), (flags & VI_FLAG_FORMAT) ? TEXT("[b]") : TEXT(""), ucount, (flags & VI_FLAG_FORMAT) ? TEXT("[/b]") : TEXT("")); buffer.Append(ubuffer); } }
// this function is called from an APC into the main thread void __stdcall ipcService(ULONG_PTR dwParam) { HANDLE hSignal; TSlotIPC *pct; LPSTR szBuf; char szGroupStr[32]; DBVARIANT dbv; LPSTR szMiranda; // try to open the file mapping object the caller must make sure no other // running instance is using this file HANDLE hMap = OpenFileMappingA(FILE_MAP_ALL_ACCESS, false, IPC_PACKET_NAME); if (hMap == 0) return; // map the file to this process THeaderIPC *pMMT = (THeaderIPC*)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); // if it fails the caller should of had some timeout in wait if (pMMT != NULL && pMMT->cbSize == sizeof(THeaderIPC) && pMMT->dwVersion == PLUGIN_MAKE_VERSION(2, 0, 1, 2)) { // toggle the right bits int *bits = &pMMT->fRequests; // jump right to a worker thread for file processing? if (*bits & REQUEST_XFRFILES) { THeaderIPC *cloned = (THeaderIPC*)mir_alloc(IPC_PACKET_SIZE); // translate from client space to cloned heap memory pMMT->pServerBaseAddress = pMMT->pClientBaseAddress; pMMT->pClientBaseAddress = cloned; CopyMemory(cloned, pMMT, IPC_PACKET_SIZE); ipcFixupAddresses(true, cloned); DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &cloned->Param, THREAD_SET_CONTEXT, false, 0); mir_forkthread(&IssueTransferThread, cloned); goto Reply; } // the request was to clear the MRU entries, we have no return data if (*bits & REQUEST_CLEARMRU) { mir_forkthread(&ClearMRUThread, NULL); goto Reply; } // the IPC header may have pointers that need to be translated // in either case the supplied data area pointers has to be // translated to this address space. // the server base address is always removed to get an offset // to which the client base is added, this is what ipcFixupAddresses() does pMMT->pServerBaseAddress = pMMT->pClientBaseAddress; pMMT->pClientBaseAddress = pMMT; // translate to the server space map ipcFixupAddresses(true, pMMT); // store the address map offset so the caller can retranslate pMMT->pServerBaseAddress = pMMT; // return some options to the client if (db_get_b(0, SHLExt_Name, SHLExt_ShowNoIcons, 0) != 0) pMMT->dwFlags = HIPC_NOICONS; // see if we have a custom string for 'Miranda' szMiranda = Translate("Miranda"); lstrcpynA(pMMT->MirandaName, szMiranda, sizeof(pMMT->MirandaName) - 1); // for the MRU menu szBuf = Translate("Recently"); lstrcpynA(pMMT->MRUMenuName, szBuf, sizeof(pMMT->MRUMenuName) - 1); // and a custom string for "clear entries" szBuf = Translate("Clear entries"); lstrcpynA(pMMT->ClearEntries, szBuf, sizeof(pMMT->ClearEntries) - 1); // if the group mode is on, check if they want the CList setting bool bGroupMode = (BST_CHECKED == db_get_b(0, SHLExt_Name, SHLExt_UseGroups, BST_UNCHECKED)); if (bGroupMode && BST_CHECKED == db_get_b(0, SHLExt_Name, SHLExt_UseCListSetting, BST_UNCHECKED)) bGroupMode = db_get_b(0, "CList", "UseGroups", true) != 0; int iSlot = 0; // return profile if set if (BST_UNCHECKED == db_get_b(0, SHLExt_Name, SHLExt_ShowNoProfile, BST_UNCHECKED)) { pct = ipcAlloc(pMMT, 50); if (pct != NULL) { // will actually return with .dat if there's space for it, not what the docs say pct->Status = STATUS_PROFILENAME; CallService(MS_DB_GETPROFILENAME, 49, UINT_PTR(pct) + sizeof(TSlotIPC)); } } if (*bits & REQUEST_NEWICONS) ipcGetSkinIcons(pMMT); if (*bits & REQUEST_GROUPS) { // return contact's grouping if it's present while (bGroupMode) { _itoa(iSlot, szGroupStr, 10); if ( db_get_s(0, "CListGroups", szGroupStr, &dbv) != 0) break; pct = ipcAlloc(pMMT, lstrlenA(dbv.pszVal + 1) + 1); // first byte has flags, need null term if (pct != NULL) { if (pMMT->GroupsBegin == NULL) pMMT->GroupsBegin = pct; pct->fType = REQUEST_GROUPS; pct->hContact = 0; szBuf = LPSTR(pct) + sizeof(TSlotIPC); // get the end of the slot lstrcpyA(szBuf, dbv.pszVal + 1); pct->hGroup = 0; db_free(&dbv); // free the string } else { // outta space db_free(&dbv); break; } iSlot++; } // if there was no space left, it'll } on null if (pct == NULL) *bits = (*bits | GROUPS_NOTIMPL) & ~REQUEST_GROUPS; } // SHOULD check slot space. if (*bits & REQUEST_CONTACTS) { if (!ipcGetSortedContacts(pMMT, &iSlot, bGroupMode)) // fail if there were no contacts AT ALL *bits = (*bits | CONTACTS_NOTIMPL) & ~REQUEST_CONTACTS; } // store the number of slots allocated pMMT->Slots = iSlot; Reply: // get the handle the caller wants to be signalled on hSignal = OpenEventA(EVENT_ALL_ACCESS, false, pMMT->SignalEventName); if (hSignal != 0) { SetEvent(hSignal); CloseHandle(hSignal); } UnmapViewOfFile(pMMT); } CloseHandle(hMap); }
static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { struct DetailsData* dat = ( struct DetailsData* )GetWindowLongPtr( hwndDlg, GWLP_USERDATA ); switch (msg) { case WM_INITDIALOG: { struct DlgProfData * prof = (struct DlgProfData *)lParam; PROPSHEETHEADER *psh = prof->psh; TranslateDialogDefault(hwndDlg); SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hMirandaInst, MAKEINTRESOURCE(IDI_USERDETAILS),IMAGE_ICON,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0)); SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadImage(hMirandaInst, MAKEINTRESOURCE(IDI_USERDETAILS),IMAGE_ICON,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0)); dat = (struct DetailsData*)mir_alloc(sizeof(struct DetailsData)); dat->prof = prof; prof->hwndOK = GetDlgItem( hwndDlg, IDOK ); EnableWindow( prof->hwndOK, FALSE ); SetWindowLongPtr( hwndDlg, GWLP_USERDATA, (LONG_PTR)dat ); { TCHAR buf[512]; mir_sntprintf(buf, SIZEOF(buf), _T("%s: %s\n%s"), TranslateT("Miranda Profiles from"), prof->pd->szProfileDir, TranslateT("Select or create your Miranda IM user profile")); SetDlgItemText(hwndDlg, IDC_NAME, buf); } { OPTIONSDIALOGPAGE *odp; int i; TCITEM tci; dat->currentPage = 0; dat->pageCount = psh->nPages; dat->opd = ( struct DetailsPageData* )mir_calloc( sizeof( struct DetailsPageData )*dat->pageCount ); odp = ( OPTIONSDIALOGPAGE* )psh->ppsp; tci.mask = TCIF_TEXT; for( i=0; i < dat->pageCount; i++ ) { dat->opd[i].pTemplate = (DLGTEMPLATE *)LockResource(LoadResource(odp[i].hInstance,FindResourceA(odp[i].hInstance,odp[i].pszTemplate,MAKEINTRESOURCEA(5)))); dat->opd[i].dlgProc = odp[i].pfnDlgProc; dat->opd[i].hInst = odp[i].hInstance; dat->opd[i].hwnd = NULL; dat->opd[i].changed = 0; tci.pszText = ( TCHAR* )odp[i].ptszTitle; if (dat->prof->pd->noProfiles || shouldAutoCreate(dat->prof->pd->szProfile)) dat->currentPage = 1; TabCtrl_InsertItem( GetDlgItem(hwndDlg,IDC_TABS), i, &tci ); } } GetWindowRect(GetDlgItem(hwndDlg,IDC_TABS),&dat->rcDisplay); TabCtrl_AdjustRect(GetDlgItem(hwndDlg,IDC_TABS),FALSE,&dat->rcDisplay); { POINT pt = {0,0}; ClientToScreen( hwndDlg, &pt ); OffsetRect( &dat->rcDisplay, -pt.x, -pt.y ); } TabCtrl_SetCurSel( GetDlgItem( hwndDlg, IDC_TABS ), dat->currentPage ); dat->opd[dat->currentPage].hwnd = CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst,dat->opd[dat->currentPage].pTemplate,hwndDlg,dat->opd[dat->currentPage].dlgProc,(LPARAM)dat->prof); ThemeDialogBackground( dat->opd[dat->currentPage].hwnd ); SetWindowPos( dat->opd[dat->currentPage].hwnd, HWND_TOP, dat->rcDisplay.left, dat->rcDisplay.top, 0, 0, SWP_NOSIZE ); { PSHNOTIFY pshn; pshn.hdr.code = PSN_INFOCHANGED; pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; pshn.hdr.idFrom = 0; pshn.lParam = ( LPARAM )0; SendMessage( dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn ); } // service mode combobox { char **list = GetSeviceModePluginsList(); if ( !list ) { ShowWindow( GetDlgItem(hwndDlg, IDC_SM_LABEL ), FALSE ); ShowWindow( GetDlgItem(hwndDlg, IDC_SM_COMBO ), FALSE ); } else { int i = 0; LRESULT index; HWND hwndCombo = GetDlgItem(hwndDlg, IDC_SM_COMBO ); index = SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)_T("") ); SendMessage( hwndCombo, CB_SETITEMDATA, index, (LPARAM)-1 ); SendMessage( hwndCombo, CB_SETCURSEL, 0, 0); while ( list[i] ) { TCHAR *str = LangPackPcharToTchar( list[i] ); index = SendMessage( hwndCombo, CB_ADDSTRING, 0, (LPARAM)str ); mir_free(str); SendMessage( hwndCombo, CB_SETITEMDATA, index, (LPARAM)i ); i++; } mir_free(list); } } ShowWindow( dat->opd[dat->currentPage].hwnd, SW_SHOW ); return TRUE; } case WM_CTLCOLORSTATIC: switch ( GetDlgCtrlID(( HWND )lParam )) { case IDC_WHITERECT: SetBkColor(( HDC )wParam, GetSysColor( COLOR_WINDOW )); return ( INT_PTR )GetSysColorBrush( COLOR_WINDOW ); } break; case PSM_CHANGED: dat->opd[dat->currentPage].changed=1; return TRUE; case PSM_FORCECHANGED: { PSHNOTIFY pshn; int i; pshn.hdr.code = PSN_INFOCHANGED; pshn.hdr.idFrom = 0; pshn.lParam = (LPARAM)0; for ( i=0; i < dat->pageCount; i++ ) { pshn.hdr.hwndFrom = dat->opd[i].hwnd; if ( dat->opd[i].hwnd != NULL ) SendMessage(dat->opd[i].hwnd,WM_NOTIFY,0,(LPARAM)&pshn); } break; } case WM_NOTIFY: switch(wParam) { case IDC_TABS: switch(((LPNMHDR)lParam)->code) { case TCN_SELCHANGING: { PSHNOTIFY pshn; if ( dat->currentPage == -1 || dat->opd[dat->currentPage].hwnd == NULL ) break; pshn.hdr.code = PSN_KILLACTIVE; pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; pshn.hdr.idFrom = 0; pshn.lParam = 0; if ( SendMessage( dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn )) { SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, TRUE ); return TRUE; } break; } case TCN_SELCHANGE: if ( dat->currentPage != -1 && dat->opd[dat->currentPage].hwnd != NULL ) ShowWindow( dat->opd[ dat->currentPage ].hwnd, SW_HIDE ); dat->currentPage = TabCtrl_GetCurSel(GetDlgItem(hwndDlg,IDC_TABS)); if ( dat->currentPage != -1 ) { if ( dat->opd[dat->currentPage].hwnd == NULL ) { PSHNOTIFY pshn; dat->opd[dat->currentPage].hwnd=CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst,dat->opd[dat->currentPage].pTemplate,hwndDlg,dat->opd[dat->currentPage].dlgProc,(LPARAM)dat->prof); ThemeDialogBackground(dat->opd[dat->currentPage].hwnd); SetWindowPos(dat->opd[dat->currentPage].hwnd,HWND_TOP,dat->rcDisplay.left,dat->rcDisplay.top,0,0,SWP_NOSIZE); pshn.hdr.code=PSN_INFOCHANGED; pshn.hdr.hwndFrom=dat->opd[dat->currentPage].hwnd; pshn.hdr.idFrom=0; pshn.lParam=(LPARAM)0; SendMessage(dat->opd[dat->currentPage].hwnd,WM_NOTIFY,0,(LPARAM)&pshn); } ShowWindow(dat->opd[dat->currentPage].hwnd,SW_SHOW); } break; } break; } break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDCANCEL: { int i; PSHNOTIFY pshn; pshn.hdr.idFrom=0; pshn.lParam=0; pshn.hdr.code=PSN_RESET; for(i=0;i<dat->pageCount;i++) { if (dat->opd[i].hwnd==NULL || !dat->opd[i].changed) continue; pshn.hdr.hwndFrom=dat->opd[i].hwnd; SendMessage(dat->opd[i].hwnd,WM_NOTIFY,0,(LPARAM)&pshn); } EndDialog(hwndDlg,0); } break; case IDC_REMOVE: if (!dat->prof->pd->noProfiles) { HWND hwndList = GetDlgItem(dat->opd[0].hwnd, IDC_PROFILELIST); DeleteProfile(hwndList, ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL), dat->prof); } break; case IDOK: { int i; PSHNOTIFY pshn; pshn.hdr.idFrom=0; pshn.lParam=(LPARAM)0; if ( dat->currentPage != -1 ) { pshn.hdr.code = PSN_KILLACTIVE; pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; if ( SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn )) break; } pshn.hdr.code=PSN_APPLY; for ( i=0; i < dat->pageCount; i++ ) { if ( dat->opd[i].hwnd == NULL || !dat->opd[i].changed ) continue; pshn.hdr.hwndFrom = dat->opd[i].hwnd; SendMessage( dat->opd[i].hwnd, WM_NOTIFY, 0, ( LPARAM )&pshn ); if ( GetWindowLongPtr( dat->opd[i].hwnd, DWLP_MSGRESULT ) == PSNRET_INVALID_NOCHANGEPAGE) { TabCtrl_SetCurSel( GetDlgItem( hwndDlg, IDC_TABS ), i ); if ( dat->currentPage != -1 ) ShowWindow( dat->opd[ dat->currentPage ].hwnd, SW_HIDE ); dat->currentPage = i; ShowWindow( dat->opd[dat->currentPage].hwnd, SW_SHOW ); return 0; } } EndDialog(hwndDlg,1); break; } } break; case WM_DESTROY: { LRESULT curSel = SendDlgItemMessage(hwndDlg,IDC_SM_COMBO,CB_GETCURSEL,0,0); if ( curSel != CB_ERR ) { int idx = SendDlgItemMessage( hwndDlg, IDC_SM_COMBO, CB_GETITEMDATA, ( WPARAM )curSel, 0 ); SetServiceModePlugin(idx); } } DestroyIcon(( HICON )SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0)); DestroyIcon(( HICON )SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); DeleteObject( dat->hBoldFont ); { int i; for ( i=0; i < dat->pageCount; i++ ) if ( dat->opd[i].hwnd != NULL ) DestroyWindow( dat->opd[i].hwnd ); } mir_free( dat->opd ); mir_free( dat ); break; } return FALSE; }
STDMETHODIMP_(BOOL) CDataBase::GetContactSetting(HANDLE hContact, DBCONTACTGETSETTING *dbcgs) { dbcgs->pValue->type = 0; char namebuf[512]; namebuf[0] = 0; if (!(dbcgs->szModule || dbcgs->szSetting)) return -1; if (dbcgs->szModule) strcpy_s(namebuf, dbcgs->szModule); strcat_s(namebuf, "/"); if (dbcgs->szSetting) strcat_s(namebuf, dbcgs->szSetting); TDBTSettingDescriptor desc = {0,0,0,0,0,0,0,0}; TDBTSetting set = {0,0,0,0}; desc.cbSize = sizeof(desc); desc.Entity = (WPARAM)hContact; desc.pszSettingName = namebuf; set.cbSize = sizeof(set); set.Descriptor = &desc; if (DBSettingRead(reinterpret_cast<WPARAM>(&set), 0) == DBT_INVALIDPARAM) return -1; switch (set.Type) { case DBT_ST_ANSI: dbcgs->pValue->type = DBVT_ASCIIZ; dbcgs->pValue->pszVal = set.Value.pAnsi; dbcgs->pValue->cchVal = set.Value.Length - 1; if (isEncrypted(dbcgs->szModule, dbcgs->szSetting)) DecodeString(dbcgs->pValue->pszVal); break; case DBT_ST_UTF8: if (isEncrypted(dbcgs->szModule, dbcgs->szSetting)) DecodeString(set.Value.pUTF8); dbcgs->pValue->type = DBVT_WCHAR; dbcgs->pValue->pwszVal = mir_utf8decodeW(set.Value.pUTF8); if (dbcgs->pValue->pwszVal) dbcgs->pValue->cchVal = static_cast<uint32_t>(wcslen(dbcgs->pValue->pwszVal)); else dbcgs->pValue->cchVal = 0; mir_free(set.Value.pUTF8); break; case DBT_ST_WCHAR: dbcgs->pValue->type = DBVT_WCHAR; dbcgs->pValue->pwszVal = set.Value.pWide; dbcgs->pValue->cchVal = set.Value.Length - 1; break; case DBT_ST_BLOB: dbcgs->pValue->type = DBVT_BLOB; dbcgs->pValue->pbVal = set.Value.pBlob; dbcgs->pValue->cpbVal = set.Value.Length; break; case DBT_ST_BOOL: dbcgs->pValue->type = DBVT_BYTE; dbcgs->pValue->bVal = (uint8_t)set.Value.Bool; break; case DBT_ST_BYTE: case DBT_ST_CHAR: dbcgs->pValue->type = DBVT_BYTE; dbcgs->pValue->bVal = set.Value.Byte; break; case DBT_ST_SHORT: case DBT_ST_WORD: dbcgs->pValue->type = DBVT_WORD; dbcgs->pValue->wVal = set.Value.Word; break; case DBT_ST_INT: case DBT_ST_DWORD: dbcgs->pValue->type = DBVT_DWORD; dbcgs->pValue->dVal = set.Value.DWord; break; case DBT_ST_INT64: case DBT_ST_QWORD: case DBT_ST_DOUBLE: case DBT_ST_FLOAT: dbcgs->pValue->type = DBVT_BLOB; dbcgs->pValue->cpbVal = sizeof(set.Value); dbcgs->pValue->pbVal = reinterpret_cast<BYTE*>(mir_alloc(sizeof(set.Value))); memcpy(dbcgs->pValue->pbVal, &set.Value, sizeof(set.Value)); break; default: return -1; } return 0; }
INT_PTR CDropbox::ProtoSendMessage(void *obj, WPARAM, LPARAM lParam) { CDropbox *instance = (CDropbox*)obj; if (!instance->HasAccessToken()) return ACKRESULT_FAILED; CCSDATA *pccsd = (CCSDATA*)lParam; char *message = (char*)pccsd->lParam; DBEVENTINFO dbei = { sizeof(dbei) }; dbei.szModule = MODULE; dbei.timestamp = time(NULL); dbei.eventType = EVENTTYPE_MESSAGE; dbei.cbBlob = strlen(message); dbei.pBlob = (PBYTE)message; dbei.flags = DBEF_SENT | DBEF_READ | DBEF_UTF; db_event_add(pccsd->hContact, &dbei); char help[1024]; if (message[0] && message[0] == '/') { // parse commands char *sep = strchr(message, ' '); int len = strlen(message) - (sep ? strlen(sep) : 0) - 1; ptrA cmd((char*)mir_alloc(len + 1)); strncpy(cmd, message + 1, len); cmd[len] = 0; if (instance->commands.find((char*)cmd) != instance->commands.end()) { ULONG messageId = InterlockedIncrement(&instance->hMessageProcess); CommandParam *param = new CommandParam(); param->instance = instance; param->hContact = pccsd->hContact; param->hProcess = (HANDLE)messageId; param->data = (sep ? sep + 1 : NULL); mir_forkthread(instance->commands[(char*)cmd], param); return messageId; } else { mir_snprintf( help, SIZEOF(help), Translate("Unknown command \"%s\".\nUse \"/help\" for more info."), message); CallContactService(instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help); return 0; } } mir_snprintf( help, SIZEOF(help), Translate("\"%s\" is not valid.\nUse \"/help\" for more info."), message); CallContactService(instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help); return 0; }