INT_PTR CSkypeProto::GetCallEventText(WPARAM, LPARAM lParam) { DBEVENTGETTEXT *pEvent = (DBEVENTGETTEXT *)lParam; INT_PTR nRetVal = 0; ptrA pszText; switch (pEvent->dbei->eventType) { case SKYPE_DB_EVENT_TYPE_CALL_INFO: { CMStringA text; HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("partlist")); if (xml != NULL) { ptrA type(mir_t2a(xmlGetAttrValue(xml, _T("type")))); bool bType = (!mir_strcmpi(type, "started")) ? 1 : 0; for (int i = 0; i < xmlGetChildCount(xml); i++) { HXML xmlPart = xmlGetNthChild(xml, _T("part"), i); if (xmlPart != NULL) { HXML xmlName = xmlGetChildByPath(xmlPart, _T("name"), 0); if (xmlName != NULL) { text.AppendFormat(Translate("%s %s this call.\n"), _T2A(xmlGetText(xmlName)), bType ? Translate("enters") : Translate("leaves")); xmlDestroyNode(xmlName); } xmlDestroyNode(xmlPart); } } xmlDestroyNode(xml); } pszText = mir_strdup(text.GetBuffer()); break; } case SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO: { CMStringA text; HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("files")); if (xml != NULL) { for (int i = 0; i < xmlGetChildCount(xml); i++) { size_t fileSize = 0; HXML xmlNode = xmlGetNthChild(xml, _T("file"), i); if (xmlNode != NULL) { fileSize = _ttoi(ptrT((TCHAR*)xmlGetAttrValue(xmlNode, _T("size")))); ptrA fileName(mir_utf8encodeT(ptrT((TCHAR*)xmlGetText(xmlNode)))); if (fileName != NULL) { CMStringA msg(FORMAT, Translate("File transfer:\n\tFile name: %s\n\tSize: %d bytes"), fileName, fileSize); text.AppendFormat("%s\n", msg); } xmlDestroyNode(xmlNode); } } xmlDestroyNode(xml); } pszText = mir_strdup(text.GetBuffer()); break; } case SKYPE_DB_EVENT_TYPE_URIOBJ: { CMStringA text; HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("URIObject")); if (xml != NULL) { text.Append(_T2A(xmlGetText(xml))); xmlDestroyNode(xml); } pszText = mir_strdup(text.GetBuffer()); break; } case SKYPE_DB_EVENT_TYPE_INCOMING_CALL: { pszText = Translate("Incoming call."); break; } default: { pszText = mir_strdup((char*)pEvent->dbei->pBlob); } } if (pEvent->datatype == DBVT_TCHAR) { TCHAR *pwszText = _A2T(pszText); nRetVal = (INT_PTR)mir_tstrdup(pwszText); } else if (pEvent->datatype == DBVT_ASCIIZ) nRetVal = (INT_PTR)mir_strdup(pszText); return nRetVal; }
CJabberInfoFrameItem(char *pszName, bool bCompact = false, LPARAM pUserData = 0) : m_bShow(true), m_bCompact(bCompact), m_pUserData(pUserData) { m_pszName = mir_strdup(pszName); }
int Service_NewChat(WPARAM wParam, LPARAM lParam) { MODULEINFO* mi; GCSESSION *gcw =(GCSESSION *)lParam; if (gcw== NULL) return GC_NEWSESSION_ERROR; if (gcw->cbSize != SIZEOF_STRUCT_GCWINDOW_V1) return GC_NEWSESSION_WRONGVER; EnterCriticalSection(&cs); if (( mi = MM_FindModule( gcw->pszModule )) != NULL ) { TCHAR* ptszID = a2tf( gcw->ptszID, gcw->dwFlags ); SESSION_INFO* si = SM_AddSession( ptszID, gcw->pszModule); if (mi->OnlineIconIndex == -1) { LoadModuleIcons(mi); } // create a new session and set the defaults if ( si != NULL ) { TCHAR szTemp[256]; si->dwItemData = gcw->dwItemData; if ( gcw->iType != GCW_SERVER ) si->wStatus = ID_STATUS_ONLINE; si->iType = gcw->iType; si->dwFlags = gcw->dwFlags; si->ptszName = a2tf( gcw->ptszName, gcw->dwFlags ); si->ptszStatusbarText = a2tf( gcw->ptszStatusbarText, gcw->dwFlags ); si->iSplitterX = g_Settings.iSplitterX; si->iSplitterY = g_Settings.iSplitterY; si->iLogFilterFlags = (int)DBGetContactSettingDword(NULL, "Chat", "FilterFlags", 0x03E0); si->bFilterEnabled = DBGetContactSettingByte(NULL, "Chat", "FilterEnabled", 0); si->bNicklistEnabled = DBGetContactSettingByte(NULL, "Chat", "ShowNicklist", 1); #if defined( _UNICODE ) if ( !( gcw->dwFlags & GC_UNICODE )) { si->pszID = mir_strdup( gcw->pszID ); si->pszName = mir_strdup( gcw->pszName ); } #endif if ( mi->bColor ) { si->iFG = 4; si->bFGSet = TRUE; } if ( mi->bBkgColor ) { si->iBG = 2; si->bBGSet = TRUE; } if (si->iType == GCW_SERVER) mir_sntprintf(szTemp, SIZEOF(szTemp), _T("Server: %s"), si->ptszName); else mir_sntprintf(szTemp, SIZEOF(szTemp), _T("%s"), si->ptszName); si->hContact = CList_AddRoom( gcw->pszModule, ptszID, szTemp, si->iType); DBWriteContactSettingString(si->hContact, si->pszModule , "Topic", ""); DBDeleteContactSetting(si->hContact, "CList", "StatusMsg"); if (si->ptszStatusbarText) DBWriteContactSettingTString(si->hContact, si->pszModule, "StatusBar", si->ptszStatusbarText); else DBWriteContactSettingString(si->hContact, si->pszModule, "StatusBar", ""); } else { SESSION_INFO* si2 = SM_FindSession( ptszID, gcw->pszModule ); if ( si2 ) { UM_RemoveAll(&si2->pUsers); TM_RemoveAll(&si2->pStatuses); si2->iStatusCount = 0; si2->nUsersInNicklist = 0; if (si2->hWnd ) RedrawWindow(GetDlgItem(si2->hWnd, IDC_CHAT_LIST), NULL, NULL, RDW_INVALIDATE); } } LeaveCriticalSection(&cs); mir_free( ptszID ); return 0; } LeaveCriticalSection(&cs); return GC_NEWSESSION_ERROR; }
BaseExtraIcon::BaseExtraIcon(int id, const char *name, const TCHAR *description, const char *descIcon, MIRANDAHOOKPARAM OnClick, LPARAM param) : ExtraIcon(name), id(id), OnClick(OnClick), onClickParam(param), tszDescription(mir_tstrdup(description)), szDescIcon(mir_strdup(descIcon)) { }
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; }
VarDescr(LPCSTR var, PBYTE value, int len) : szVar(mir_strdup(var)), szValue((char*)memcpy(mir_alloc(len), value, len)), iLen(len) {}
// преобразуем текст из чистого UTF8 в формат миранды LPSTR utf8_to_miranda(LPCSTR szUtfMsg, DWORD& flags) { return mir_strdup(szUtfMsg); }
//============ MANAGE THE ITEMS STORED IN DB ============ // get single setting that is found // szSetting = the setting name // lparam = the counter int GetWeatherDataFromDB(const char *szSetting, LPARAM lparam) { LIST<char> *pList = (LIST<char>*)lparam; pList->insert(mir_strdup(szSetting)); return 0; }
/** * name: fromDB * class: CExImContactBase * desc: get contact information from database * param: hContact - handle to contact whose information to read * return: TRUE if successful or FALSE otherwise **/ BYTE CExImContactBase::fromDB(HANDLE hContact) { BYTE ret = FALSE; BYTE isChatRoom = FALSE; LPSTR pszProto; LPCSTR uidSetting; DBVARIANT dbv; _hContact = hContact; _dbvUIDHash = 0; MIR_FREE(_pszProtoOld); MIR_FREE(_pszProto); MIR_FREE(_pszAMPro); MIR_FREE(_pszNick); MIR_FREE(_pszDisp); MIR_FREE(_pszGroup); MIR_FREE(_pszUIDKey); db_free(&_dbvUID); ZeroMemory(&_dbvUID, sizeof(DBVARIANT)); // OWNER if (!_hContact) return TRUE; // Proto if (!(pszProto = DB::Contact::Proto(_hContact))) return FALSE; _pszProto = mir_strdup(pszProto); // AM_BaseProto if (!DB::Setting::GetUString(NULL, pszProto, "AM_BaseProto", &dbv )) { _pszAMPro = mir_strdup(dbv.pszVal); db_free(&dbv); } // unique id (for ChatRoom) if (isChatRoom = db_get_b(_hContact, pszProto, "ChatRoom", 0)) { uidSetting = "ChatRoomID"; _pszUIDKey = mir_strdup(uidSetting); if (!DB::Setting::GetAsIs(_hContact, pszProto, uidSetting, &_dbvUID)) { ret = TRUE; } } // unique id (normal) else { uidSetting = (LPCSTR)CallProtoService(pszProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); // valid if (uidSetting != NULL && (INT_PTR)uidSetting != CALLSERVICE_NOTFOUND) { _pszUIDKey = mir_strdup(uidSetting); if (!DB::Setting::GetAsIs(_hContact, pszProto, uidSetting, &_dbvUID)) { ret = TRUE; } } // fails because the protocol is no longer installed else { // assert(ret == TRUE); ret = TRUE; } } // nickname if (!DB::Setting::GetUString(_hContact, pszProto, SET_CONTACT_NICK, &dbv)) { _pszNick = mir_strdup(dbv.pszVal); db_free(&dbv); } if (_hContact && ret) { // Clist Group if (!DB::Setting::GetUString(_hContact, MOD_CLIST, "Group", &dbv)) { _pszGroup = mir_strdup(dbv.pszVal); db_free(&dbv); } // Clist DisplayName if (!DB::Setting::GetUString(_hContact, MOD_CLIST, SET_CONTACT_MYHANDLE, &dbv)) { _pszDisp = mir_strdup(dbv.pszVal); db_free(&dbv); } } return ret; }
void LoadProtocolIcons() { PROTOCOLDESCRIPTOR **pProtos; int i, j, allProtoNum, k; HICON hIcon; CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM) &allProtoNum, (LPARAM) &pProtos); g_dat->protoNum = 0; for(i = 0; i < allProtoNum; i++) { if (pProtos[i]->type == PROTOTYPE_PROTOCOL) g_dat->protoNum++; } if (g_dat->protoNames != NULL) { for(i = 0; i < g_dat->protoNum; i++) { if (g_dat->protoNames[i] != NULL) { mir_free(g_dat->protoNames[i]); } } mir_free(g_dat->protoNames); } g_dat->protoNames = (char **) mir_alloc(sizeof(char*) * g_dat->protoNum); if (g_dat->hTabIconList == NULL) { g_dat->hTabIconList = ImageList_Create(16, 16, IsWinVerXPPlus() ? ILC_COLOR32 | ILC_MASK : ILC_COLOR8 | ILC_MASK, (g_dat->protoNum + 1) * 12 + 8, 0); ImageList_AddIcon(g_dat->hTabIconList, LoadSkinnedIcon(SKINICON_EVENT_MESSAGE)); ImageList_AddIcon(g_dat->hTabIconList, g_dat->hIcons[SMF_ICON_TYPING]); for (i = ID_STATUS_OFFLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { ImageList_AddIcon(g_dat->hTabIconList, LoadSkinnedProtoIcon(NULL, i)); } for(i = j = 0; i < allProtoNum; i++) { if (pProtos[i]->type != PROTOTYPE_PROTOCOL) continue; g_dat->protoNames[j] = mir_strdup(pProtos[i]->szName); for (k = ID_STATUS_OFFLINE; k <= ID_STATUS_OUTTOLUNCH; k++) { hIcon = LoadSkinnedProtoIcon(pProtos[i]->szName, k); if (hIcon != NULL) { ImageList_AddIcon(g_dat->hTabIconList, hIcon); } else { ImageList_AddIcon(g_dat->hTabIconList, LoadSkinnedProtoIcon(NULL, ID_STATUS_OFFLINE)); } } j++; } } else { int index = 0; ImageList_ReplaceIcon(g_dat->hTabIconList, index++, LoadSkinnedIcon(SKINICON_EVENT_MESSAGE)); ImageList_ReplaceIcon(g_dat->hTabIconList, index++, g_dat->hIcons[SMF_ICON_TYPING]); for (i = ID_STATUS_OFFLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { ImageList_ReplaceIcon(g_dat->hTabIconList, index++, LoadSkinnedProtoIcon(NULL, i)); } for(i = j = 0; i < allProtoNum; i++) { if (pProtos[i]->type != PROTOTYPE_PROTOCOL) continue; g_dat->protoNames[j] = mir_strdup(pProtos[i]->szName); for (k = ID_STATUS_OFFLINE; k <= ID_STATUS_OUTTOLUNCH; k++) { hIcon = LoadSkinnedProtoIcon(pProtos[i]->szName, k); if (hIcon != NULL) { ImageList_ReplaceIcon(g_dat->hTabIconList, index++, hIcon); } else { ImageList_ReplaceIcon(g_dat->hTabIconList, index++, LoadSkinnedProtoIcon(NULL, ID_STATUS_OFFLINE)); } } j++; } } }
LPSTR CExImContactBase::uid2String(BYTE bPrependType) { CHAR szUID[MAX_PATH]; LPSTR ptr = szUID; switch (_dbvUID.type) { case DBVT_BYTE: //'b' bVal and cVal are valid if (bPrependType) *ptr++ = 'b'; _itoa(_dbvUID.bVal, ptr, 10); break; case DBVT_WORD: //'w' wVal and sVal are valid if (bPrependType) *ptr++ = 'w'; _itoa(_dbvUID.wVal, ptr, 10); break; case DBVT_DWORD: //'d' dVal and lVal are valid if (bPrependType) *ptr++ = 'd'; _itoa(_dbvUID.dVal, ptr, 10); break; case DBVT_WCHAR: //'u' pwszVal is valid { LPSTR r = mir_utf8encodeW(_dbvUID.pwszVal); if (bPrependType) { LPSTR t = (LPSTR)mir_alloc(strlen(r)+2); t[0] = 'u'; strcpy(t+1, r); mir_free(r); r = t; } return r; } case DBVT_UTF8: //'u' pszVal is valid { if (bPrependType) *ptr++ = 'u'; mir_strncpy(ptr, _dbvUID.pszVal, SIZEOF(szUID)-1); } break; case DBVT_ASCIIZ: { LPSTR r = mir_utf8encode(_dbvUID.pszVal); if (bPrependType) { LPSTR t = (LPSTR)mir_alloc(strlen(r)+2); t[0] = 's'; strcpy(t+1, r); mir_free(r); r = t; } return r; } case DBVT_BLOB: //'n' cpbVal and pbVal are valid { if (bPrependType) { //True = XML INT_PTR baselen = mir_base64_encode_bufsize(_dbvUID.cpbVal); LPSTR t = (LPSTR)mir_alloc(baselen + 5 + bPrependType); assert(t != NULL); if ( mir_base64_encodebuf(_dbvUID.pbVal, _dbvUID.cpbVal, t + bPrependType, baselen)) { t[baselen + bPrependType] = 0; if (bPrependType) t[0] = 'n'; return t; } mir_free(t); return NULL; } else { //FALSE = INI WORD j; INT_PTR baselen = (_dbvUID.cpbVal * 3); LPSTR t = (LPSTR)mir_alloc(3 + baselen); ZeroMemory(t, (3 + baselen)); for (j = 0; j < _dbvUID.cpbVal; j++) { mir_snprintf((t + bPrependType + (j * 3)), 4,"%02X ", (BYTE)_dbvUID.pbVal[j]); } if (t){ if (bPrependType) t[0] = 'n'; return t; } else { mir_free(t); return NULL; } } break; } default: return NULL; } return mir_strdup(szUID); }
static INT_PTR CALLBACK DlgProcNetlibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { int iUser; switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { int iItem = SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_ADDSTRING, 0, (LPARAM)TranslateT("<All connections>")); SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_SETITEMDATA, iItem, (LPARAM)-1); SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_SETCURSEL, iItem, 0); { mir_cslock lck(csNetlibUser); for (int i = 0; i < netlibUser.getCount(); ++i) { NetlibTempSettings *thisSettings = (NetlibTempSettings*)mir_calloc(sizeof(NetlibTempSettings)); thisSettings->flags = netlibUser[i]->user.flags; thisSettings->szSettingsModule = mir_strdup(netlibUser[i]->user.szSettingsModule); CopySettingsStruct(&thisSettings->settings, &netlibUser[i]->settings); tempSettings.insert(thisSettings); if (netlibUser[i]->user.flags & NUF_NOOPTIONS) continue; iItem = SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_ADDSTRING, 0, (LPARAM)netlibUser[i]->user.ptszDescriptiveName); SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_SETITEMDATA, iItem, i); } } } SendMessage(hwndDlg, M_REFRESHALL, 0, 0); return TRUE; case M_REFRESHALL: iUser = SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETCURSEL, 0, 0), 0); { NETLIBUSERSETTINGS settings = { 0 }; DWORD flags = 0; if (iUser == -1) { settings.cbSize = sizeof(settings); for (int i = 0; i < tempSettings.getCount(); i++) { NetlibTempSettings *p = tempSettings[i]; if (!(p->flags & NUF_NOOPTIONS)) CombineSettingsStructs(&settings, &flags, &p->settings, p->flags); } } else { NetlibFreeUserSettingsStruct(&settings); CopySettingsStruct(&settings, &tempSettings[iUser]->settings); flags = tempSettings[iUser]->flags; } ShowMultipleControls(hwndDlg, outgoingConnectionsControls, _countof(outgoingConnectionsControls), flags&NUF_OUTGOING ? SW_SHOW : SW_HIDE); CheckDlgButton(hwndDlg, IDC_USEPROXY, settings.useProxy ? BST_CHECKED : BST_UNCHECKED); SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_RESETCONTENT, 0, 0); if (settings.proxyType == 0) AddProxyTypeItem(hwndDlg, 0, settings.proxyType); AddProxyTypeItem(hwndDlg, PROXYTYPE_SOCKS4, settings.proxyType); AddProxyTypeItem(hwndDlg, PROXYTYPE_SOCKS5, settings.proxyType); if (flags & (NUF_HTTPCONNS | NUF_HTTPGATEWAY)) AddProxyTypeItem(hwndDlg, PROXYTYPE_HTTP, settings.proxyType); if (!(flags & NUF_NOHTTPSOPTION)) AddProxyTypeItem(hwndDlg, PROXYTYPE_HTTPS, settings.proxyType); if (flags & (NUF_HTTPCONNS | NUF_HTTPGATEWAY) || !(flags & NUF_NOHTTPSOPTION)) AddProxyTypeItem(hwndDlg, PROXYTYPE_IE, settings.proxyType); SetDlgItemTextA(hwndDlg, IDC_PROXYHOST, settings.szProxyServer ? settings.szProxyServer : ""); if (settings.wProxyPort) SetDlgItemInt(hwndDlg, IDC_PROXYPORT, settings.wProxyPort, FALSE); else SetDlgItemTextA(hwndDlg, IDC_PROXYPORT, ""); CheckDlgButton(hwndDlg, IDC_PROXYAUTH, settings.useProxyAuth ? BST_CHECKED : BST_UNCHECKED); SetDlgItemTextA(hwndDlg, IDC_PROXYUSER, settings.szProxyAuthUser ? settings.szProxyAuthUser : ""); SetDlgItemTextA(hwndDlg, IDC_PROXYPASS, settings.szProxyAuthPassword ? settings.szProxyAuthPassword : ""); CheckDlgButton(hwndDlg, IDC_PROXYDNS, settings.dnsThroughProxy ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_VALIDATESSL, settings.validateSSL ? BST_CHECKED : BST_UNCHECKED); ShowMultipleControls(hwndDlg, incomingConnectionsControls, _countof(incomingConnectionsControls), flags&NUF_INCOMING ? SW_SHOW : SW_HIDE); CheckDlgButton(hwndDlg, IDC_SPECIFYPORTS, settings.specifyIncomingPorts ? BST_CHECKED : BST_UNCHECKED); SetDlgItemTextA(hwndDlg, IDC_PORTSRANGE, settings.szIncomingPorts ? settings.szIncomingPorts : ""); CheckDlgButton(hwndDlg, IDC_SPECIFYPORTSO, settings.specifyOutgoingPorts ? BST_CHECKED : BST_UNCHECKED); SetDlgItemTextA(hwndDlg, IDC_PORTSRANGEO, settings.szOutgoingPorts ? settings.szOutgoingPorts : ""); CheckDlgButton(hwndDlg, IDC_ENABLEUPNP, settings.enableUPnP ? BST_CHECKED : BST_UNCHECKED); NetlibFreeUserSettingsStruct(&settings); SendMessage(hwndDlg, M_REFRESHENABLING, 0, 0); } break; case M_REFRESHENABLING: TCHAR str[80]; { int selectedProxyType = SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETCURSEL, 0, 0), 0); mir_sntprintf(str, TranslateT("(often %d)"), oftenProxyPorts[selectedProxyType]); SetDlgItemText(hwndDlg, IDC_STOFTENPORT, str); if (IsDlgButtonChecked(hwndDlg, IDC_USEPROXY) != BST_UNCHECKED) { int enableAuth = 0, enableUser = 0, enablePass = 0, enableServer = 1; EnableMultipleControls(hwndDlg, useProxyControls, _countof(useProxyControls), TRUE); if (selectedProxyType == 0) { for (int i = 0; i < tempSettings.getCount(); i++) { NetlibTempSettings *p = tempSettings[i]; if (!p->settings.useProxy || p->flags & NUF_NOOPTIONS || !(p->flags & NUF_OUTGOING)) continue; if (p->settings.proxyType == PROXYTYPE_SOCKS4) enableUser = 1; else { enableAuth = 1; if (p->settings.useProxyAuth) enableUser = enablePass = 1; } } } else { if (selectedProxyType == PROXYTYPE_SOCKS4) enableUser = 1; else { if (selectedProxyType == PROXYTYPE_IE) enableServer = 0; enableAuth = 1; if (IsDlgButtonChecked(hwndDlg, IDC_PROXYAUTH) != BST_UNCHECKED) enableUser = enablePass = 1; } } EnableWindow(GetDlgItem(hwndDlg, IDC_PROXYAUTH), enableAuth); EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC31), enableUser); EnableWindow(GetDlgItem(hwndDlg, IDC_PROXYUSER), enableUser); EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC32), enablePass); EnableWindow(GetDlgItem(hwndDlg, IDC_PROXYPASS), enablePass); EnableWindow(GetDlgItem(hwndDlg, IDC_PROXYHOST), enableServer); EnableWindow(GetDlgItem(hwndDlg, IDC_PROXYPORT), enableServer); } else EnableMultipleControls(hwndDlg, useProxyControls, _countof(useProxyControls), FALSE); EnableMultipleControls(hwndDlg, specifyPortsControls, _countof(specifyPortsControls), IsDlgButtonChecked(hwndDlg, IDC_SPECIFYPORTS) != BST_UNCHECKED); EnableMultipleControls(hwndDlg, specifyOPortsControls, _countof(specifyOPortsControls), IsDlgButtonChecked(hwndDlg, IDC_SPECIFYPORTSO) != BST_UNCHECKED); } break; case WM_COMMAND: iUser = SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETCURSEL, 0, 0), 0); switch (LOWORD(wParam)) { case IDC_NETLIBUSERS: if (HIWORD(wParam) == CBN_SELCHANGE) SendMessage(hwndDlg, M_REFRESHALL, 0, 0); return 0; case IDC_LOGOPTIONS: NetlibLogShowOptions(); return 0; case IDC_PROXYTYPE: if (HIWORD(wParam) != CBN_SELCHANGE) return 0; { int newValue = SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETCURSEL, 0, 0), 0); if (iUser == -1) { if (newValue == 0) return 0; for (int i=0; i < tempSettings.getCount(); i++) { NetlibTempSettings *p = tempSettings[i]; if (p->flags & NUF_NOOPTIONS) continue; if (newValue == PROXYTYPE_HTTP && !(p->flags & (NUF_HTTPCONNS | NUF_HTTPGATEWAY))) p->settings.proxyType = PROXYTYPE_HTTPS; else if (newValue == PROXYTYPE_HTTPS && p->flags & NUF_NOHTTPSOPTION) p->settings.proxyType = PROXYTYPE_HTTP; else p->settings.proxyType = newValue; } SendMessage(hwndDlg, M_REFRESHALL, 0, 0); } else { tempSettings[iUser]->settings.proxyType = newValue; SendMessage(hwndDlg, M_REFRESHENABLING, 0, 0); } } break; case IDC_USEPROXY: ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, useProxy)); break; case IDC_PROXYAUTH: ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, useProxyAuth)); break; case IDC_PROXYDNS: ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, dnsThroughProxy)); break; case IDC_SPECIFYPORTS: ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, specifyIncomingPorts)); break; case IDC_SPECIFYPORTSO: ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, specifyOutgoingPorts)); break; case IDC_ENABLEUPNP: ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, enableUPnP)); break; case IDC_VALIDATESSL: ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, validateSSL)); break; case IDC_PROXYHOST: if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0; ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szProxyServer)); break; case IDC_PROXYPORT: if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0; { int newValue = GetDlgItemInt(hwndDlg, LOWORD(wParam), NULL, FALSE); if (iUser == -1) { for (int i = 0; i < tempSettings.getCount(); i++) { NetlibTempSettings *p = tempSettings[i]; if (!(p->flags & NUF_NOOPTIONS)) p->settings.wProxyPort = newValue; } } else tempSettings[iUser]->settings.wProxyPort = newValue; } break; case IDC_PROXYUSER: if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0; ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szProxyAuthUser)); break; case IDC_PROXYPASS: if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0; ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szProxyAuthPassword)); break; case IDC_PORTSRANGE: if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0; ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szIncomingPorts)); break; case IDC_PORTSRANGEO: if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0; ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szOutgoingPorts)); break; } ShowWindow(GetDlgItem(hwndDlg, IDC_RECONNECTREQD), SW_SHOW); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: for (iUser = 0; iUser < tempSettings.getCount(); iUser++) NetlibSaveUserSettingsStruct(tempSettings[iUser]->szSettingsModule, &tempSettings[iUser]->settings); return TRUE; } break; } break; case WM_DESTROY: for (int i = 0; i < tempSettings.getCount(); ++i) { NetlibTempSettings *p = tempSettings[i]; mir_free(p->szSettingsModule); NetlibFreeUserSettingsStruct(&p->settings); mir_free(tempSettings[i]); } tempSettings.destroy(); break; } return FALSE; }
static void TlenGetAvatarThread(void *ptr) { TLEN_LIST_ITEM *item = NULL; TLENGETAVATARTHREADDATA *data = (TLENGETAVATARTHREADDATA *)ptr; MCONTACT hContact = data->hContact; char *login = NULL; if (hContact != NULL) { char *jid = TlenJIDFromHContact(data->proto, hContact); login = TlenNickFromJID(jid); item = TlenListGetItemPtr(data->proto, LIST_ROSTER, jid); mir_free(jid); } else { if (data->proto->threadData != NULL) login = mir_strdup(data->proto->threadData->username); } if ((data->proto->threadData != NULL && hContact == NULL) || item != NULL) { DWORD format = PA_FORMAT_UNKNOWN; if (item != NULL) { item->newAvatarDownloading = TRUE; } char *request = replaceTokens(data->proto->threadData->tlenConfig.mailBase, data->proto->threadData->tlenConfig.avatarGet, login, data->proto->threadData->avatarToken, 0, 0); NETLIBHTTPREQUEST req; memset(&req, 0, sizeof(req)); req.cbSize = sizeof(req); req.requestType = data->proto->threadData->tlenConfig.avatarGetMthd; req.flags = 0; req.headersCount = 0; req.headers = NULL; req.dataLength = 0; req.szUrl = request; NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)data->proto->m_hNetlibUser, (LPARAM)&req); if (item != NULL) { item->newAvatarDownloading = FALSE; } if (resp != NULL) { if (resp->resultCode/100 == 2) { if (resp->dataLength > 0) { int i; for (i=0; i<resp->headersCount; i++ ) { if (!strcmpi(resp->headers[i].szName, "Content-Type")) { if (!strcmpi(resp->headers[i].szValue, "image/png")) format = PA_FORMAT_PNG; else if (!strcmpi(resp->headers[i].szValue, "image/x-png")) format = PA_FORMAT_PNG; else if (!strcmpi(resp->headers[i].szValue, "image/jpeg")) format = PA_FORMAT_JPEG; else if (!strcmpi(resp->headers[i].szValue, "image/jpg")) format = PA_FORMAT_JPEG; else if (!strcmpi(resp->headers[i].szValue, "image/gif")) format = PA_FORMAT_GIF; else if (!strcmpi(resp->headers[i].szValue, "image/bmp")) format = PA_FORMAT_BMP; break; } } SetAvatar(data->proto, hContact, item, resp->pData, resp->dataLength, format); } else { RemoveAvatar(data->proto, hContact); } } CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); } mir_free(request); mir_free(login); } if (hContact == NULL) { getAvatarMutex = 0; } mir_free(login); mir_free(data); }
int __cdecl CAimProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) { if (pszSrc == NULL) return 0; if (state != 1) { msg_ack_param *msg_ack = (msg_ack_param*)mir_calloc(sizeof(msg_ack_param)); msg_ack->hContact = hContact; msg_ack->msg = "Message cannot be sent, when protocol offline"; ForkThread(&CAimProto::msg_ack_success, msg_ack); } char *sn = getStringA(hContact, AIM_KEY_SN); if (sn == NULL) { msg_ack_param *msg_ack = (msg_ack_param*)mir_calloc(sizeof(msg_ack_param)); msg_ack->hContact = hContact; msg_ack->msg = "Screen Name for the contact not available"; ForkThread(&CAimProto::msg_ack_success, msg_ack); } char* msg; if (flags & PREF_UNICODE) { const char* p = strchr(pszSrc, '\0'); if (p != pszSrc) { while (*(++p) == '\0'); } msg = mir_utf8encodeW((wchar_t*)p); } else if (flags & PREF_UTF) msg = mir_strdup(pszSrc); else msg = mir_utf8encode(pszSrc); char* smsg = html_encode(msg); mir_free(msg); if (getByte(AIM_KEY_FO, 1)) { msg = bbcodes_to_html(smsg); mir_free(smsg); } else msg = smsg; bool blast = getBool(hContact, AIM_KEY_BLS, false); int res = aim_send_message(hServerConn, seqno, sn, msg, false, blast); mir_free(msg); mir_free(sn); if (!res || blast || 0 == getByte(AIM_KEY_DC, 1)) { msg_ack_param *msg_ack = (msg_ack_param*)mir_alloc(sizeof(msg_ack_param)); msg_ack->hContact = hContact; msg_ack->msg = NULL; msg_ack->id = res; msg_ack->success = res != 0; ForkThread(&CAimProto::msg_ack_success, msg_ack); } return res; }
// преобразуем текст из формата миранды в чистый UTF8 LPSTR miranda_to_utf8(LPCSTR szMirMsg, DWORD flags) { return mir_strdup(szMirMsg); }
int __cdecl CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) { const char *errMsg = NULL; if (!msnLoggedIn) { errMsg = Translate("Protocol is offline"); ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, 999999, errMsg, this)); return 999999; } char tEmail[MSN_MAX_EMAIL_LEN]; if (MSN_IsMeByContact(hContact, tEmail)) { errMsg = Translate("You cannot send message to yourself"); ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, 999999, errMsg, this)); return 999999; } char *msg = (char*)pszSrc; if (msg == NULL) return 0; if (flags & PREF_UNICODE) { char* p = strchr(msg, '\0'); if (p != msg) { while (*(++p) == '\0') {} msg = mir_utf8encodeW((wchar_t*)p); } else msg = mir_strdup(msg); } else msg = (flags & PREF_UTF) ? mir_strdup(msg) : mir_utf8encode(msg); int rtlFlag = (flags & PREF_RTL) ? MSG_RTL : 0; int seq = 0; int netId = Lists_GetNetId(tEmail); switch (netId) { case NETID_MOB: if (strlen(msg) > 133) { errMsg = Translate("Message is too long: SMS page limited to 133 UTF8 chars"); seq = 999997; } else { errMsg = NULL; seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag); } ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this)); break; case NETID_YAHOO: if (strlen(msg) > 1202) { seq = 999996; errMsg = Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars"); ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this)); } else { seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag); ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this)); } break; default: if (strlen(msg) > 1202) { seq = 999996; errMsg = Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars"); ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this)); } else { const char msgType = MyOptions.SlowSend ? 'A' : 'N'; bool isOffline; ThreadData* thread = MSN_StartSB(tEmail, isOffline); if (thread == NULL) { if (isOffline) { if (netId != NETID_LCS) { seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag | MSG_OFFLINE); ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this)); } else { seq = 999993; errMsg = Translate("Offline messaging is not allowed for LCS contacts"); ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this)); } } else seq = MsgQueue_Add(tEmail, msgType, msg, 0, 0, rtlFlag); } else { seq = thread->sendMessage(msgType, tEmail, netId, msg, rtlFlag); if (!MyOptions.SlowSend) ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this)); } } break; } mir_free(msg); return seq; }
static int BuildTree(HWND hwndDlg,int MenuObjectId, BOOL bReread) { char menuItemName[256],MenuNameItems[256]; char buf[256]; FreeTreeData( hwndDlg ); TreeView_DeleteAllItems(GetDlgItem(hwndDlg,IDC_MENUITEMS)); int menupos = GetMenuObjbyId( MenuObjectId ); if ( menupos == -1 ) return FALSE; TIntMenuObject* pimo = g_menus[menupos]; if ( pimo->m_items.first == NULL ) return FALSE; mir_snprintf( MenuNameItems, sizeof(MenuNameItems), "%s_Items", pimo->Name ); int count = 0; { for ( PMO_IntMenuItem p = pimo->m_items.first; p != NULL; p = p->next ) if ( p->mi.root == ( HGENMENU )-1 || p->mi.root == NULL ) count++; } lpMenuItemOptData *PDar = ( lpMenuItemOptData* )mir_alloc( sizeof( lpMenuItemOptData )*count ); count = 0; { for ( PMO_IntMenuItem p = pimo->m_items.first; p != NULL; p = p->next ) { if ( p->mi.root != ( HGENMENU )-1 && p->mi.root != NULL ) continue; MenuItemOptData *PD = ( MenuItemOptData* )mir_calloc( sizeof( MenuItemOptData )); GetMenuItemName( p, menuItemName, sizeof( menuItemName )); { DBVARIANT dbv; mir_snprintf(buf, SIZEOF(buf), "%s_name", menuItemName); if ( !DBGetContactSettingTString( NULL, MenuNameItems, buf, &dbv )) { PD->name = mir_tstrdup( dbv.ptszVal ); DBFreeVariant( &dbv ); } else PD->name = mir_tstrdup( p->mi.ptszName ); } PD->pimi = p; PD->defname = mir_tstrdup( p->mi.ptszName ); mir_snprintf( buf, SIZEOF(buf), "%s_visible", menuItemName ); PD->show = DBGetContactSettingByte( NULL, MenuNameItems, buf, 1 ); if ( bReread ) { mir_snprintf( buf, SIZEOF(buf), "%s_pos", menuItemName ); PD->pos = DBGetContactSettingDword( NULL, MenuNameItems, buf, 1 ); } else PD->pos = ( PD->pimi ) ? PD->pimi->originalPosition : 0; PD->id = p->iCommand; if ( p->UniqName ) PD->uniqname = mir_strdup( p->UniqName ); PDar[ count ] = PD; count++; } } qsort( PDar, count, sizeof( lpMenuItemOptData ), sortfunc ); SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, FALSE, 0); int lastpos = 0; bool first = TRUE; TVINSERTSTRUCT tvis; tvis.hParent = NULL; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; for ( int i=0; i < count; i++ ) { if ( PDar[i]->pos - lastpos >= SEPARATORPOSITIONINTERVAL ) { MenuItemOptData *PD = ( MenuItemOptData* )mir_calloc( sizeof( MenuItemOptData )); PD->id = -1; PD->name = mir_tstrdup( STR_SEPARATOR ); PD->pos = PDar[i]->pos - 1; PD->show = TRUE; tvis.item.lParam = ( LPARAM )PD; tvis.item.pszText = PD->name; tvis.item.iImage = tvis.item.iSelectedImage = PD->show; SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis); } tvis.item.lParam = ( LPARAM )PDar[i]; tvis.item.pszText = PDar[i]->name; tvis.item.iImage = tvis.item.iSelectedImage = PDar[i]->show; HTREEITEM hti = (HTREEITEM)SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis); if ( first ) { TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),hti); first=FALSE; } lastpos = PDar[i]->pos; } SendDlgItemMessage( hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, TRUE, 0 ); mir_free( PDar ); ShowWindow( GetDlgItem( hwndDlg, IDC_NOTSUPPORTWARNING ),( pimo->m_bUseUserDefinedItems ) ? SW_HIDE : SW_SHOW ); EnableWindow( GetDlgItem( hwndDlg, IDC_MENUITEMS ), pimo->m_bUseUserDefinedItems ); EnableWindow( GetDlgItem( hwndDlg, IDC_INSERTSEPARATOR ), pimo->m_bUseUserDefinedItems ); return 1; }
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; } }
// decrypt string using KeyX, return decoded string as ASCII or NULL LPSTR __cdecl cpp_decrypt(pCNTX ptr, LPCSTR szEncMsg) { ptrA ciphered; try { ptr->error = ERROR_SEH; pSIMDATA p = (pSIMDATA) ptr->pdata; unsigned clen = (unsigned)strlen(szEncMsg); if (ptr->features & FEATURES_BASE64) ciphered = (LPSTR)mir_base64_decode(szEncMsg,&clen); else ciphered = base16decode(szEncMsg,&clen); LPSTR bciphered = ciphered; BYTE dataflag=0; if (ptr->features & FEATURES_GZIP) { dataflag = *ciphered; bciphered++; clen--; // cut GZIP flag } if (ptr->features & FEATURES_CRC32) { int len = *( WORD* )bciphered; bciphered+=2; clen-=2; // cut CRC32 length if ((int)clen - CRC32::DIGESTSIZE < len) { // mesage not full #if defined(_DEBUG) || defined(NETLIB_LOG) Sent_NetLog("cpp_decrypt: error bad_len"); #endif ptr->error = ERROR_BAD_LEN; return NULL; } BYTE crc32[CRC32::DIGESTSIZE]; memset(crc32,0,sizeof(crc32)); CRC32().CalculateDigest(crc32, (PBYTE)(bciphered+CRC32::DIGESTSIZE), len); if (memcmp(crc32,bciphered,CRC32::DIGESTSIZE)) { // message is bad crc #if defined(_DEBUG) || defined(NETLIB_LOG) Sent_NetLog("cpp_decrypt: error bad_crc"); #endif ptr->error = ERROR_BAD_CRC; return NULL; } bciphered += CRC32::DIGESTSIZE; // cut CRC32 digest clen = len; } string unciphered; CBC_Mode<AES>::Decryption dec(p->KeyX,Tiger::DIGESTSIZE,IV); StreamTransformationFilter cbcDecryptor(dec,new StringSink(unciphered)); cbcDecryptor.Put((PBYTE)bciphered,clen); cbcDecryptor.MessageEnd(); if (dataflag & DATA_GZIP) { size_t clen2 = clen; LPSTR res = (LPSTR)cpp_gunzip((PBYTE)unciphered.data(),unciphered.length(),clen2); replaceStr(ptr->tmp, mir_strndup(res, clen2)); free(res); } else replaceStr(ptr->tmp, mir_strdup(unciphered.c_str())); ptr->error = ERROR_NONE; return ptr->tmp; } catch (...) { #if defined(_DEBUG) || defined(NETLIB_LOG) Sent_NetLog("cpp_decrypt: error seh"); #endif mir_free(ptr->tmp); ptr->tmp = 0; return NULL; } }
VarDescr(LPCSTR var, LPSTR value) : szVar(mir_strdup(var)), szValue(value) {}
ProtoInfo(LPCSTR _proto, HANDLE _image) : proto(mir_strdup(_proto)), hImage(_image) {}
//======================================================= //Custom status message windows handling //======================================================= static INT_PTR CALLBACK DlgProcSetCustStat(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { DBVARIANT dbv; switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { CYahooProto* ppro = (CYahooProto*)lParam; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)ppro->LoadIconEx("yahoo", true)); SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)ppro->LoadIconEx("yahoo")); if (!ppro->getString(YAHOO_CUSTSTATDB, &dbv)) { SetDlgItemTextA(hwndDlg, IDC_CUSTSTAT, dbv.pszVal); EnableWindow(GetDlgItem(hwndDlg, IDOK), mir_strlen(dbv.pszVal) > 0); db_free(&dbv); } else { SetDlgItemTextA(hwndDlg, IDC_CUSTSTAT, ""); EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE); } CheckDlgButton(hwndDlg, IDC_CUSTSTATBUSY, ppro->getByte("BusyCustStat", 0) ? BST_CHECKED : BST_UNCHECKED); } return TRUE; case WM_COMMAND: switch (wParam) { case IDOK: { char str[255 + 1]; CYahooProto* ppro = (CYahooProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); /* Get String from dialog */ GetDlgItemTextA(hwndDlg, IDC_CUSTSTAT, str, _countof(str)); /* Save it for later use */ ppro->setString(YAHOO_CUSTSTATDB, str); ppro->setByte("BusyCustStat", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_CUSTSTATBUSY)); /* set for Idle/AA */ if (ppro->m_startMsg) mir_free(ppro->m_startMsg); ppro->m_startMsg = mir_strdup(str); /* notify Server about status change */ ppro->set_status(YAHOO_CUSTOM_STATUS, str, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_CUSTSTATBUSY)); /* change local/miranda status */ ppro->BroadcastStatus((BYTE)IsDlgButtonChecked(hwndDlg, IDC_CUSTSTATBUSY) ? ID_STATUS_AWAY : ID_STATUS_ONLINE); } case IDCANCEL: DestroyWindow(hwndDlg); break; } if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) { if (LOWORD(wParam) == IDC_CUSTSTAT) { char str[255 + 1]; BOOL toSet; toSet = GetDlgItemTextA(hwndDlg, IDC_CUSTSTAT, str, _countof(str)) != 0; EnableWindow(GetDlgItem(hwndDlg, IDOK), toSet); } } break; /* case WM_COMMAND */ case WM_CLOSE: DestroyWindow(hwndDlg); break; case WM_DESTROY: { CYahooProto* ppro = (CYahooProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); ppro->ReleaseIconEx("yahoo", true); ppro->ReleaseIconEx("yahoo"); } break; } return FALSE; }
void Template::tokenize() { if (text == NULL) return; char *str = mir_strdup(text); Token *lastToken = NULL; int lastTokenType = Token::PLAIN; int lastTokenEscape = 0; int l = (int)mir_strlen(str); for (int i = 0, lastTokenStart = 0; i <= l;) { Token *newToken; int newTokenType = 0, newTokenSize = 0, newTokenEscape = 0; if (str[i] == '\0') { newTokenType = Token::END; newTokenSize = 1; newTokenEscape = 0; } else { bool found = false; for (unsigned int j = 0; j < (sizeof(tokenNames) / sizeof(tokenNames[0])); j++) { if (!strncmp(str + i, tokenNames[j].tokenString, tokenNames[j].tokenLen)) { newTokenType = tokenNames[j].token; newTokenSize = tokenNames[j].tokenLen; newTokenEscape = tokenNames[j].escape; found = true; break; } } if (!found) { newTokenType = Token::PLAIN; newTokenSize = 1; newTokenEscape = 0; } } if (newTokenType != Token::PLAIN) { if (str[i + newTokenSize] == '%') { //newTokenSize++; } str[i] = '\0'; } if ((lastTokenType != newTokenType || lastTokenEscape != newTokenEscape) && i != lastTokenStart) { if (lastTokenType == Token::PLAIN) newToken = new Token(lastTokenType, str + lastTokenStart, lastTokenEscape); else newToken = new Token(lastTokenType, NULL, lastTokenEscape); if (lastToken != NULL) lastToken->setNext(newToken); else tokens = newToken; lastToken = newToken; lastTokenStart = i; } lastTokenEscape = newTokenEscape; lastTokenType = newTokenType; i += newTokenSize; } mir_free(str); }
/** * name: OnAddPage * class: CPsTreeItem * desc: inits the treeitem's attributes * params: pPsh - pointer to the property page's header structure * odp - OPTIONSDIALOGPAGE structure with the information about the page to add * return: 0 on success, 1 on failure **/ int CPsTreeItem::Create(CPsHdr* pPsh, OPTIONSDIALOGPAGE *odp) { int err; TCHAR szTitle[ MAXSETTING ]; // check parameter if (pPsh && pPsh->_dwSize == sizeof(CPsHdr) && odp && PtrIsValid(odp->hInstance)) { // instance value _hInst = odp->hInstance; _dwFlags = odp->flags; _initParam = odp->dwInitParam; // init page owning contact _hContact = pPsh->_hContact; _pszProto = mir_strdup(pPsh->_pszProto); // global settings prefix for current contact (is dialog owning contact's protocol by default) _pszPrefix = (pPsh->_pszPrefix) ? pPsh->_pszPrefix : "Owner"; if (pPsh->_dwFlags & PSF_PROTOPAGESONLY) { if (_dwFlags & ODPF_USERINFOTAB) mir_sntprintf(szTitle, _T("%s %d\\%s"), odp->ptszTitle, pPsh->_nSubContact+1, odp->ptszTab); else mir_sntprintf(szTitle, _T("%s %d"), odp->ptszTitle, pPsh->_nSubContact+1); } else { if (_dwFlags & ODPF_USERINFOTAB) mir_sntprintf(szTitle, _T("%s\\%s"), odp->ptszTitle, odp->ptszTab); else mir_tstrcpy(szTitle, odp->ptszTitle); } // set the unique utf8 encoded name for the item if (err = Name(szTitle, (_dwFlags & ODPF_UNICODE) == ODPF_UNICODE)) MsgErr(NULL, LPGENT("Creating unique name for a page failed with %d and error code %d"), err, GetLastError()); // read label from database or create it else if (err = ItemLabel(TRUE)) MsgErr(NULL, LPGENT("Creating the label for a page failed with %d and error code %d"), err, GetLastError()); else { // load icon for the item Icon(pPsh->_hImages, odp, (pPsh->_dwFlags & PSTVF_INITICONS) == PSTVF_INITICONS); // the rest is not needed if only icons are loaded if (pPsh->_dwFlags & PSTVF_INITICONS) return 0; // load custom order if (!(pPsh->_dwFlags & PSTVF_SORTTREE)) { _iPosition = (int)db_get_b(NULL, MODNAME, PropertyKey(SET_ITEM_POS), odp->position); if ((_iPosition < 0) && (_iPosition > 0x800000A)) _iPosition = 0; } // read visibility state _bState = db_get_b(NULL, MODNAME, PropertyKey(SET_ITEM_STATE), DBTVIS_EXPANDED); // error for no longer supported dialog template type if (((UINT_PTR)odp->pszTemplate & 0xFFFF0000)) MsgErr(NULL, LPGENT("The dialog template type is no longer supported")); else { // fetch dialog resource id _idDlg = (INT_PTR)odp->pszTemplate; // dialog procedure _pfnDlgProc = odp->pfnDlgProc; // is dummy item? if (!_idDlg && !_pfnDlgProc) return 0; if (_idDlg && _pfnDlgProc) { // lock the property pages dialog resource _pTemplate = (DLGTEMPLATE*)LockResource(LoadResource(_hInst, FindResource(_hInst, (LPCTSTR)(UINT_PTR)_idDlg, RT_DIALOG))); if (_pTemplate) return 0; } } } } return 1; }
ExtraIcon::ExtraIcon(const char *name) : szName(mir_strdup(name)), slot(-1), position(1000), hLangpack(0) { }
void BaseExtraIcon::setDescIcon(const char *icon) { szDescIcon = mir_strdup(icon); }
void CVkProto::OnOAuthAuthorize(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) { debugLogA("CVkProto::OnOAuthAuthorize %d", reply->resultCode); GrabCookies(reply); if (reply->resultCode == 302) { // manual redirect LPCSTR pszLocation = findHeader(reply, "Location"); if (pszLocation) { if (!_strnicmp(pszLocation, szBlankUrl, sizeof(szBlankUrl)-1)) { m_szAccessToken = NULL; LPCSTR p = strstr(pszLocation, VK_TOKEN_BEG); if (p) { p += sizeof(VK_TOKEN_BEG)-1; for (LPCSTR q = p+1; *q; q++) { if (*q == '&' || *q == '=' || *q == '\"') { m_szAccessToken = mir_strndup(p, q-p); break; } } if (m_szAccessToken == NULL) m_szAccessToken = mir_strdup(p); setString("AccessToken", m_szAccessToken); RetrieveMyInfo(); } else { delSetting("AccessToken"); ConnectionFailed(LOGINERR_NOSERVER); } } else { AsyncHttpRequest *pRedirectReq = new AsyncHttpRequest(); pRedirectReq->requestType = REQUEST_GET; pRedirectReq->flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11; pRedirectReq->m_pFunc = &CVkProto::OnOAuthAuthorize; pRedirectReq->AddHeader("Referer", m_prevUrl); pRedirectReq->Redirect(reply); if (!pRedirectReq->m_szUrl.IsEmpty()) { if (pRedirectReq->m_szUrl[0] == '/') pRedirectReq->m_szUrl = VK_LOGIN_DOMAIN + pRedirectReq->m_szUrl; ApplyCookies(pRedirectReq); m_prevUrl = pRedirectReq->m_szUrl; } pRedirectReq->m_bApiReq = false; pRedirectReq->bIsMainConn = true; Push(pRedirectReq); } } else ConnectionFailed(LOGINERR_NOSERVER); return; } if (reply->resultCode != 200 || !strstr(reply->pData, "form method=\"post\"")) { // something went wrong ConnectionFailed(LOGINERR_NOSERVER); return; } if (strstr(reply->pData, "service_msg_warning")) { ConnectionFailed(LOGINERR_WRONGPASSWORD); return; } CMStringA szAction, szBody; bool bSuccess = AutoFillForm(reply->pData, szAction, szBody); if (!bSuccess || szAction.IsEmpty() || szBody.IsEmpty()) { if (m_prevError) { ConnectionFailed(LOGINERR_NOSERVER); return; } m_prevError = true; } pReq = new AsyncHttpRequest(); pReq->requestType = REQUEST_POST; pReq->flags = NLHRF_DUMPASTEXT | NLHRF_HTTP11; pReq->m_szParam = szBody; pReq->m_szUrl = szAction; if (!pReq->m_szUrl.IsEmpty() && pReq->m_szUrl[0] == '/') pReq->m_szUrl = VK_LOGIN_DOMAIN + pReq->m_szUrl; m_prevUrl = pReq->m_szUrl; pReq->m_pFunc = &CVkProto::OnOAuthAuthorize; pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded"); pReq->Redirect(reply); ApplyCookies(pReq); pReq->m_bApiReq = false; pReq->bIsMainConn = true; Push(pReq); }