static char* CreateRTFHeader(SrmmWindowData*) { HDC hdc = GetDC(NULL); logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); CMStringA buffer; buffer.Append("{\\rtf1\\ansi\\deff0{\\fonttbl"); LOGFONT lf; for (int i = 0; LoadMsgDlgFont(i, &lf, NULL); i++) buffer.AppendFormat(FONT_FORMAT, i, lf.lfCharSet, lf.lfFaceName); buffer.Append("}{\\colortbl "); COLORREF colour; for (int i = 0; LoadMsgDlgFont(i, NULL, &colour); i++) buffer.AppendFormat("\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); if (GetSysColorBrush(COLOR_HOTLIGHT) == NULL) colour = RGB(0, 0, 255); else colour = GetSysColor(COLOR_HOTLIGHT); buffer.AppendFormat("\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour)); buffer.Append("}"); return buffer.Detach(); }
int luaM_print(lua_State *L) { CMStringA data; int nargs = lua_gettop(L); for (int i = 1; i <= nargs; ++i) { switch (lua_type(L, i)) { case LUA_TNIL: data.AppendFormat("%s ", "nil"); break; case LUA_TBOOLEAN: data.AppendFormat("%s ", lua_toboolean(L, i) ? "true" : "false"); break; case LUA_TNUMBER: case LUA_TSTRING: data.AppendFormat("%s ", lua_tostring(L, i)); break; case LUA_TTABLE: data.AppendFormat("%s ", "table"); break; default: data.AppendFormat("0x%p ", lua_topointer(L, i)); break; } } data.Delete(data.GetLength() - 3, 3); CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)data.GetBuffer()); return 0; }
void CDropbox::CommandContent(void *arg) { CommandParam *param = (CommandParam*)arg; char *path = (char*)param->data; if (path == NULL) path = ""; ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); ptrA encodedPath(mir_utf8encode(path)); GetMetadataRequest request(token, encodedPath); NLHR_PTR response(request.Send(param->instance->hNetlibConnection)); if (response == NULL || response->resultCode != HTTP_STATUS_OK) { ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); return; } JSONNode root = JSONNode::parse(response->pData); if (root.empty()) { ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); return; } CMStringA message; bool isDir = root.at("is_dir").as_bool(); if (!isDir) message.AppendFormat("\"%s\" %s", encodedPath, T2Utf(TranslateT("is file"))); else { JSONNode content = root.at("contents").as_array(); for (size_t i = 0; i < content.size(); i++) { JSONNode item = content[i]; if (item.empty()) { if (i == 0) message.AppendFormat("\"%s\" %s", encodedPath, T2Utf(TranslateT("is empty"))); break; } CMStringA subName(item.at("path").as_string().c_str()); message.AppendFormat("%s\n", (subName[0] == '/') ? subName.Mid(1) : subName); } } ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer()); }
static void AppendPlainUnicode(CMStringA &buf, const TCHAR *str) { for (; *str; str++) { if (*str < 128) buf.AppendChar((char)*str); else buf.AppendFormat("\\u%d ?", *str); } }
void CVkProto::PollUpdates(JSONNODE *pUpdates) { debugLogA("CVkProto::PollUpdates"); CMStringA mids; int msgid, uid, flags; MCONTACT hContact; JSONNODE *pChild; for (int i = 0; (pChild = json_at(pUpdates, i)) != NULL; i++) { switch (json_as_int(json_at(pChild, 0))) { case VKPOLL_MSG_ADDED: // new message msgid = json_as_int(json_at(pChild, 1)); // skip outgoing messages sent from a client flags = json_as_int(json_at(pChild, 2)); if ((flags & VKFLAG_MSGOUTBOX) && !(flags & VKFLAG_MSGCHAT)) if (CheckMid(msgid)) break; if (!mids.IsEmpty()) mids.AppendChar(','); mids.AppendFormat("%d", msgid); break; case VKPOLL_USR_ONLINE: uid = -json_as_int(json_at(pChild, 1)); if ((hContact = FindUser(uid)) != NULL) setWord(hContact, "Status", ID_STATUS_ONLINE); break; case VKPOLL_USR_OFFLINE: uid = -json_as_int(json_at(pChild, 1)); if ((hContact = FindUser(uid)) != NULL) setWord(hContact, "Status", ID_STATUS_OFFLINE); break; case VKPOLL_USR_UTN: uid = json_as_int(json_at(pChild, 1)); if ((hContact = FindUser(uid)) != NULL) CallService(MS_PROTO_CONTACTISTYPING, hContact, 5); break; case VKPOLL_CHAT_CHANGED: int chat_id = json_as_int(json_at(pChild, 1)); CVkChatInfo *cc = m_chats.find((CVkChatInfo*)&chat_id); if (cc) RetrieveChatInfo(cc); break; } } RetrieveMessagesByIds(mids); }
void CMsnProto::MSN_GCRefreshThreadsInfo(void) { CMStringA buf; MCONTACT hContact; int nThreads = 0; for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { if (isChatRoom(hContact) != 0) { DBVARIANT dbv; if (getString(hContact, "ChatRoomID", &dbv) == 0) { buf.AppendFormat("<thread><id>%s</id></thread>", dbv.pszVal); nThreads++; db_free(&dbv); } } } if (nThreads) msnNsThread->sendPacketPayload("GET", "MSGR\\THREADS", "<threads>%s</threads>", buf); }
// MsnSendContacts - sends contacts to a certain user int __cdecl CMsnProto::SendContacts(MCONTACT hContact, int, int nContacts, MCONTACT *hContactsList) { if (!msnLoggedIn) return 0; char tEmail[MSN_MAX_EMAIL_LEN]; if (MSN_IsMeByContact(hContact, tEmail)) return 0; int seq = 0; int netId = Lists_GetNetId(tEmail); CMStringA msg; msg.Append("<contacts alt=\"[Contacts enclosed. Please upgrade to latest Skype version to receive contacts.]\">"); for (int i = 0; i < nContacts; i++) { ptrA wlid(getStringA(hContactsList[i], "wlid")); if (wlid != NULL) msg.AppendFormat("<c t=\"s\" s=\"%s\"/>", wlid); } msg.Append("</contacts>"); seq = msnNsThread->sendMessage('1', tEmail, netId, msg, MSG_CONTACT); ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this, ACKTYPE_CONTACTS)); return seq; }
void CVkGCCreateForm::btnOk_OnOk(CCtrlButton*) { CMStringA szUIds; for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) { if (m_proto->isChatRoom(hContact)) continue; HANDLE hItem = m_clCList.FindContact(hContact); if (hItem && m_clCList.GetCheck(hItem)) { int uid = m_proto->getDword(hContact, "ID"); if (uid != 0) { if (!szUIds.IsEmpty()) szUIds.AppendChar(','); szUIds.AppendFormat("%d", uid); } } } bool bRes = !szUIds.IsEmpty(); if (bRes) m_proto->CreateNewChat(szUIds, ptrT(m_edtTitle.GetText())); EndDialog(m_hwnd, bRes); }
//mir_free() the return value static char* CreateRTFFromDbEvent(SrmmWindowData *dat, MCONTACT hContact, MEVENT hDbEvent, struct LogStreamData *streamData) { int showColon = 0; DBEVENTINFO dbei = { sizeof(dbei) }; dbei.cbBlob = db_event_getBlobSize(hDbEvent); if (dbei.cbBlob == -1) return NULL; dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); db_event_get(hDbEvent, &dbei); if (!DbEventIsShown(&dbei)) { mir_free(dbei.pBlob); return NULL; } if (!(dbei.flags & DBEF_SENT) && (dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei))) { db_event_markRead(hContact, hDbEvent); pcli->pfnRemoveEvent(hContact, hDbEvent); } else if (dbei.eventType == EVENTTYPE_JABBER_CHATSTATES || dbei.eventType == EVENTTYPE_JABBER_PRESENCE) { db_event_markRead(hContact, hDbEvent); } CMStringA buffer; if (!dat->bIsAutoRTL && !streamData->isEmpty) buffer.Append("\\par"); if (dbei.flags & DBEF_RTL) { buffer.Append("\\rtlpar"); dat->bIsAutoRTL = TRUE; } else buffer.Append("\\ltrpar"); streamData->isEmpty = 0; if (dat->bIsAutoRTL) { if (dbei.flags & DBEF_RTL) buffer.Append("\\ltrch\\rtlch"); else buffer.Append("\\rtlch\\ltrch"); } if (g_dat.flags & SMF_SHOWICONS) { int i = ((dbei.eventType == EVENTTYPE_MESSAGE) ? ((dbei.flags & DBEF_SENT) ? LOGICON_MSG_OUT : LOGICON_MSG_IN): LOGICON_MSG_NOTICE); buffer.Append("\\f0\\fs14"); buffer.Append(pLogIconBmpBits[i]); } if (g_dat.flags & SMF_SHOWTIME) { const TCHAR* szFormat; TCHAR str[64]; if (g_dat.flags & SMF_SHOWSECS) szFormat = g_dat.flags & SMF_SHOWDATE ? _T("d s") : _T("s"); else szFormat = g_dat.flags & SMF_SHOWDATE ? _T("d t") : _T("t"); TimeZone_PrintTimeStamp(NULL, dbei.timestamp, szFormat, str, _countof(str), 0); buffer.AppendFormat(" %s ", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME)); AppendToBufferWithRTF(buffer, str); showColon = 1; } if (!(g_dat.flags & SMF_HIDENAMES) && dbei.eventType != EVENTTYPE_JABBER_CHATSTATES && dbei.eventType != EVENTTYPE_JABBER_PRESENCE) { TCHAR *szName; CONTACTINFO ci = { 0 }; if (dbei.flags & DBEF_SENT) { ci.cbSize = sizeof(ci); ci.szProto = dbei.szModule; ci.dwFlag = CNF_DISPLAY | CNF_TCHAR; if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { // CNF_DISPLAY always returns a string type szName = ci.pszVal; } else // Shouldn't happen? szName = mir_tstrdup(TranslateT("Me")); } else szName = pcli->pfnGetContactDisplayName(hContact, 0); buffer.AppendFormat(" %s ", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYNAME : MSGFONTID_YOURNAME)); AppendToBufferWithRTF(buffer, szName); showColon = 1; if (ci.pszVal) mir_free(ci.pszVal); } if (showColon) buffer.AppendFormat("%s :", SetToStyle(dbei.flags & DBEF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON)); TCHAR *msg, *szName; switch (dbei.eventType) { case EVENTTYPE_JABBER_CHATSTATES: case EVENTTYPE_JABBER_PRESENCE: if (dbei.flags & DBEF_SENT) { CONTACTINFO ci = { sizeof(ci) }; ci.hContact = NULL; ci.szProto = dbei.szModule; ci.dwFlag = CNF_DISPLAY | CNF_TCHAR; // CNF_DISPLAY always returns a string type if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) szName = NEWTSTR_ALLOCA(ci.pszVal); else szName = _T(""); mir_free(ci.pszVal); } else szName = pcli->pfnGetContactDisplayName(hContact, 0); buffer.AppendFormat(" %s ", SetToStyle(MSGFONTID_NOTICE)); AppendToBufferWithRTF(buffer, szName); AppendToBufferWithRTF(buffer, _T(" ")); msg = DbGetEventTextT(&dbei, CP_ACP); if (msg) { AppendToBufferWithRTF(buffer, msg); mir_free(msg); } break; case EVENTTYPE_FILE: { char* filename = (char*)dbei.pBlob + sizeof(DWORD); char* descr = filename + mir_strlen(filename) + 1; ptrT ptszFileName(DbGetEventStringT(&dbei, filename)); buffer.AppendFormat(" %s ", SetToStyle(MSGFONTID_NOTICE)); AppendToBufferWithRTF(buffer, (dbei.flags & DBEF_SENT) ? TranslateT("File sent") : TranslateT("File received")); buffer.Append(": "); AppendToBufferWithRTF(buffer, ptszFileName); if (*descr != 0) { ptrT ptszDescr(DbGetEventStringT(&dbei, descr)); buffer.Append(" ("); AppendToBufferWithRTF(buffer, ptszDescr); buffer.Append(")"); } } break; case EVENTTYPE_MESSAGE: default: msg = DbGetEventTextT(&dbei, CP_ACP); buffer.AppendFormat(" %s ", SetToStyle((dbei.eventType == EVENTTYPE_MESSAGE) ? ((dbei.flags & DBEF_SENT) ? MSGFONTID_MYMSG : MSGFONTID_YOURMSG) : MSGFONTID_NOTICE)); AppendToBufferWithRTF(buffer, msg); mir_free(msg); } if (dat->bIsAutoRTL) buffer.Append("\\par"); mir_free(dbei.pBlob); return buffer.Detach(); }
void CMsnProto::MSN_CreateContList(void) { bool *used = (bool*)mir_calloc(m_arContacts.getCount()*sizeof(bool)); CMStringA cxml; cxml.AppendFormat("<ml l=\"%d\">", MyOptions.netId == NETID_MSN?1:0); { mir_cslock lck(m_csLists); for (int i = 0; i < m_arContacts.getCount(); i++) { if (used[i]) continue; const char* lastds = strchr(m_arContacts[i].email, '@'); bool newdom = true; for (int j = 0; j < m_arContacts.getCount(); j++) { if (used[j]) continue; const MsnContact& C = m_arContacts[j]; if (C.list == LIST_RL || C.list == LIST_PL || C.list == LIST_LL) { used[j] = true; continue; } const char *dom = strchr(C.email, '@'); if (dom == NULL && lastds == NULL) { if (newdom) { cxml.Append("<skp>"); newdom = false; } int list = C.list & ~(LIST_RL | LIST_LL); list = LIST_FL | LIST_AL; /* Seems to be always 3 in Skype... */ cxml.AppendFormat("<c n=\"%s\" t=\"%d\"><s l=\"%d\" n=\"PE\"/><s l=\"%d\" n=\"IM\"/><s l=\"%d\" n=\"SKP\"/><s l=\"%d\" n=\"PUB\"/></c>", C.email, C.netId, list, list, list, list); used[j] = true; } /* Seems to be unused in Skype and causing errors else if (dom != NULL && lastds != NULL && _stricmp(lastds, dom) == 0) { if (newdom) { cxml.AppendFormat("<d n=\"%s\">", lastds + 1); newdom = false; } *(char*)dom = 0; cxml.AppendFormat("<c n=\"%s\" t=\"%d\"><s n=\"IM\" l=\"%d\"/></c>", C.email, C.netId, C.list & ~(LIST_RL | LIST_LL)); *(char*)dom = '@'; used[j] = true; } */ } if (!newdom) cxml.Append(lastds ? "</d>" : "</skp>"); } } cxml.Append("</ml>"); msnNsThread->sendPacketPayload("PUT", "MSGR\\CONTACTS", "%s", cxml); if (msnP24Ver > 1) msnNsThread->sendPacketPayload("PUT", "MSGR\\SUBSCRIPTIONS", "<subscribe><presence><buddies><all /></buddies></presence><messaging><im /><conversations /></messaging><notifications><partners>%s<partner>ABCH</partner></partners></notifications></subscribe>", MyOptions.netId==NETID_MSN?"<partner>Hotmail</partner>":""); mir_free(used); }
INT_PTR CALLBACK DlgInviteToChat(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { InviteChatParam *param = (InviteChatParam*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); param = (InviteChatParam*)lParam; break; case WM_CLOSE: EndDialog(hwndDlg, 0); break; case WM_NCDESTROY: delete param; break; case WM_NOTIFY: NMCLISTCONTROL* nmc; { nmc = (NMCLISTCONTROL*)lParam; if (nmc->hdr.idFrom == IDC_CCLIST) { switch (nmc->hdr.code) { case CLN_NEWCONTACT: if (param && (nmc->flags & (CLNF_ISGROUP | CLNF_ISINFO)) == 0) ChatValidateContact((UINT_PTR)nmc->hItem, nmc->hdr.hwndFrom, param->ppro); break; case CLN_LISTREBUILT: if (param) ChatPrepare(NULL, nmc->hdr.hwndFrom, param->ppro); break; } } } break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_ADDSCR: if (param->ppro->msnLoggedIn) { TCHAR email[MSN_MAX_EMAIL_LEN]; GetDlgItemText(hwndDlg, IDC_EDITSCR, email, _countof(email)); CLCINFOITEM cii = { 0 }; cii.cbSize = sizeof(cii); cii.flags = CLCIIF_CHECKBOX | CLCIIF_BELOWCONTACTS; cii.pszText = _tcslwr(email); HANDLE hItem = (HANDLE)SendDlgItemMessage(hwndDlg, IDC_CCLIST, CLM_ADDINFOITEM, 0, (LPARAM)&cii); SendDlgItemMessage(hwndDlg, IDC_CCLIST, CLM_SETCHECKMARK, (LPARAM)hItem, 1); } break; case IDCANCEL: EndDialog(hwndDlg, IDCANCEL); break; case IDOK: char tEmail[MSN_MAX_EMAIL_LEN]; tEmail[0] = 0; GCThreadData *info = NULL; if (param->id) info = param->ppro->MSN_GetThreadByChatId(param->id); /*else if (param->hContact) { if (!param->ppro->MSN_IsMeByContact(param->hContact, tEmail)) info = param->ppro->MSN_GetThreadByContact(tEmail); }*/ HWND hwndList = GetDlgItem(hwndDlg, IDC_CCLIST); STRLIST *cont = new STRLIST; ChatInviteSend(NULL, hwndList, *cont, param->ppro); if (info) { for (int i = 0; i < cont->getCount(); ++i) ChatInviteUser(param->ppro->msnNsThread, info, (*cont)[i]); delete cont; } else { /* Group chats only work for Skype users */ CMStringA buf; buf.AppendFormat("<thread><id></id><members><member><mri>%d:%s</mri><role>admin</role></member>", NETID_SKYPE, param->ppro->GetMyUsername(NETID_SKYPE)); for (int i = 0; i < cont->getCount(); ++i) { // TODO: Add support for assigning role in invite dialog maybe? buf.AppendFormat("<member><mri>%s</mri><role>user</role></member>", (*cont)[i]); } buf.Append("</members></thread>"); param->ppro->msnNsThread->sendPacketPayload("PUT", "MSGR\\THREAD", buf); } EndDialog(hwndDlg, IDOK); } break; } return FALSE; }
void CVkProto::PollUpdates(const JSONNode &jnUpdates) { debugLogA("CVkProto::PollUpdates"); CMStringA mids; int msgid, uid, flags, platform; MCONTACT hContact; for (auto it = jnUpdates.begin(); it != jnUpdates.end(); ++it) { const JSONNode &jnChild = (*it).as_array(); switch (jnChild[json_index_t(0)].as_int()) { case VKPOLL_MSG_DELFLAGS: if (jnChild.size() < 4) break; msgid = jnChild[1].as_int(); flags = jnChild[2].as_int(); uid = jnChild[3].as_int(); hContact = FindUser(uid); if (hContact != NULL && (flags & VKFLAG_MSGUNREAD) && !CheckMid(m_incIds, msgid)) { setDword(hContact, "LastMsgReadTime", time(NULL)); if (ServiceExists(MS_MESSAGESTATE_UPDATE)) { MessageReadData data(time(NULL), MRD_TYPE_READTIME); CallService(MS_MESSAGESTATE_UPDATE, hContact, (LPARAM)&data); } else SetSrmmReadStatus(hContact); if (m_bUserForceOnlineOnActivity) SetInvisible(hContact); if (m_bSyncReadMessageStatusFromServer) MarkDialogAsRead(hContact); } break; case VKPOLL_MSG_ADDED: // new message msgid = jnChild[1].as_int(); // skip outgoing messages sent from a client flags = jnChild[2].as_int(); if (flags & VKFLAG_MSGOUTBOX && !(flags & VKFLAG_MSGCHAT) && CheckMid(m_sendIds, msgid)) break; if (!mids.IsEmpty()) mids.AppendChar(','); mids.AppendFormat("%d", msgid); break; case VKPOLL_READ_ALL_OUT: uid = jnChild[1].as_int(); hContact = FindUser(uid); if (hContact != NULL) { setDword(hContact, "LastMsgReadTime", time(NULL)); if (ServiceExists(MS_MESSAGESTATE_UPDATE)) { MessageReadData data(time(NULL), MRD_TYPE_READTIME); CallService(MS_MESSAGESTATE_UPDATE, hContact, (LPARAM)&data); } else SetSrmmReadStatus(hContact); if (m_bUserForceOnlineOnActivity) SetInvisible(hContact); } break; case VKPOLL_READ_ALL_IN: uid = jnChild[1].as_int(); hContact = FindUser(uid); if (hContact != NULL && m_bSyncReadMessageStatusFromServer) MarkDialogAsRead(hContact); break; case VKPOLL_USR_ONLINE: uid = -jnChild[1].as_int(); if ((hContact = FindUser(uid)) != NULL) { setWord(hContact, "Status", ID_STATUS_ONLINE); platform = jnChild[2].as_int(); SetMirVer(hContact, platform); } break; case VKPOLL_USR_OFFLINE: uid = -jnChild[1].as_int(); if ((hContact = FindUser(uid)) != NULL) { setWord(hContact, "Status", ID_STATUS_OFFLINE); db_unset(hContact, m_szModuleName, "ListeningTo"); SetMirVer(hContact, -1); } break; case VKPOLL_USR_UTN: uid = jnChild[1].as_int(); hContact = FindUser(uid); if (hContact != NULL) { ForkThread(&CVkProto::ContactTypingThread, (void *)hContact); if (m_bUserForceOnlineOnActivity) SetInvisible(hContact); } break; case VKPOLL_CHAT_UTN: ForkThread(&CVkProto::ChatContactTypingThread, new CVKChatContactTypingParam(jnChild[2].as_int(), jnChild[1].as_int())); break; case VKPOLL_CHAT_CHANGED: int chat_id = jnChild[1].as_int(); CVkChatInfo *cc = m_chats.find((CVkChatInfo*)&chat_id); if (cc) RetrieveChatInfo(cc); break; } } RetrieveMessagesByIds(mids); }
static INT_PTR CALLBACK GcCreateDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { CVkProto *ppro = (CVkProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); NMCLISTCONTROL* nmc; switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); ppro = (CVkProto*)lParam; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); { HWND hwndClist = GetDlgItem(hwndDlg, IDC_CLIST); SetWindowLongPtr(hwndClist, GWL_STYLE, GetWindowLongPtr(hwndClist, GWL_STYLE) | CLS_CHECKBOXES | CLS_HIDEEMPTYGROUPS | CLS_USEGROUPS | CLS_GREYALTERNATE | CLS_GROUPCHECKBOXES); SendMessage(hwndClist, CLM_SETEXSTYLE, CLS_EX_DISABLEDRAGDROP | CLS_EX_TRACKSELECT, 0); ResetOptions(hwndDlg); } return TRUE; case WM_NOTIFY: nmc = (NMCLISTCONTROL*)lParam; if (nmc->hdr.idFrom == IDC_CLIST && nmc->hdr.code == CLN_LISTREBUILT) FilterContacts(hwndDlg, ppro); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: EndDialog(hwndDlg, 0); return TRUE; case IDOK: HWND hwndClist = GetDlgItem(hwndDlg, IDC_CLIST); CMStringA uids; for (HANDLE hContact = db_find_first(ppro->m_szModuleName); hContact; hContact = db_find_next(hContact, ppro->m_szModuleName)) { if (ppro->isChatRoom(hContact)) continue; if (int hItem = SendMessage(hwndClist, CLM_FINDCONTACT, (WPARAM)hContact, 0)) { if (SendMessage(hwndClist, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) { int uid = ppro->getDword(hContact, "ID", 0); if (uid != NULL) { if (!uids.IsEmpty()) uids.AppendChar(','); uids.AppendFormat("%d", uid); } } } } TCHAR tszTitle[1024]; GetDlgItemText(hwndDlg, IDC_TITLE, tszTitle, SIZEOF(tszTitle)); ppro->CreateNewChat(uids, tszTitle); EndDialog(hwndDlg, 0); return TRUE; } } return FALSE; }
INT_PTR CSkypeProto::GetEventText(WPARAM, LPARAM lParam) { DBEVENTGETTEXT *pEvent = (DBEVENTGETTEXT *)lParam; CMStringA szText; BOOL bUseBB = db_get_b(NULL, pEvent->dbei->szModule, "UseBBCodes", 1); switch (pEvent->dbei->eventType) { case SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE: { JSONNode jMsg = JSONNode::parse((char*)pEvent->dbei->pBlob); if (jMsg) { JSONNode &jOriginalMsg = jMsg["original_message"]; szText.AppendFormat(bUseBB ? Translate("[b]Original message:[/b]\n%s\n") : Translate("Original message:\n%s\n"), mir_utf8decodeA(jOriginalMsg["text"].as_string().c_str())); JSONNode &jEdits = jMsg["edits"]; for (auto it = jEdits.begin(); it != jEdits.end(); ++it) { const JSONNode &jEdit = *it; time_t time = jEdit["time"].as_int(); char szTime[MAX_PATH]; strftime(szTime, sizeof(szTime), "%X %x", localtime(&time)); szText.AppendFormat(bUseBB ? Translate("[b]Edited at %s:[/b]\n%s\n") : Translate("Edited at %s:\n%s\n"), szTime, mir_utf8decodeA(jEdit["text"].as_string().c_str())); } } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_CALL_INFO: { 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; time_t callDuration = 0; for (int i = 0; i < xmlGetChildCount(xml); i++) { HXML xmlPart = xmlGetNthChild(xml, _T("part"), i); if (xmlPart != NULL) { HXML xmlDuration = xmlGetChildByPath(xmlPart, _T("duration"), 0); if (xmlDuration != NULL) { callDuration = _ttol(xmlGetText(xmlDuration)); xmlDestroyNode(xmlDuration); xmlDestroyNode(xmlPart); break; } xmlDestroyNode(xmlPart); } } if (bType) { szText = Translate("Call"); } else { if (callDuration == 0) { szText = Translate("Call missed"); } else { char szTime[100]; strftime(szTime, sizeof(szTime), "%X", gmtime(&callDuration)); szText.Format(Translate("Call ended (%s)"), szTime); } } xmlDestroyNode(xml); } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO: { HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("files")); if (xml != NULL) { for (int i = 0; i < xmlGetChildCount(xml); i++) { LONGLONG fileSize = 0; HXML xmlNode = xmlGetNthChild(xml, _T("file"), i); if (xmlNode != NULL) { fileSize = _ttol(xmlGetAttrValue(xmlNode, _T("size"))); char *fileName = _T2A(xmlGetText(xmlNode)); if (fileName != NULL) { szText.AppendFormat(Translate("File transfer:\n\tFile name: %s \n\tSize: %lld bytes \n"), fileName, fileSize); } xmlDestroyNode(xmlNode); } } xmlDestroyNode(xml); } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_MOJI: case SKYPE_DB_EVENT_TYPE_URIOBJ: { HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("URIObject")); if (xml != NULL) { szText.Append(_T2A(xmlGetText(xml))); HXML xmlA = xmlGetChildByPath(xml, _T("a"), 0); if (xmlA != NULL) { szText += _T2A(xmlGetAttrValue(xmlA, _T("href"))); xmlDestroyNode(xmlA); } xmlDestroyNode(xml); } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_INCOMING_CALL: { szText = Translate("Incoming call"); break; } case SKYPE_DB_EVENT_TYPE_UNKNOWN: { szText.Format(Translate("Unknown event, please send this text for developer: \"%s\""), mir_utf8decodeA((char*)pEvent->dbei->pBlob)); break; } default: { szText = ptrA(mir_utf8decodeA((char*)pEvent->dbei->pBlob)); } } switch(pEvent->datatype) { case DBVT_TCHAR: { return (INT_PTR)mir_a2t(szText); } case DBVT_ASCIIZ: { return (INT_PTR)szText.Detach(); } case DBVT_UTF8: { return (INT_PTR)mir_utf8encode(szText); } default: { return NULL; } } }
static void Log_AppendRTF(LOGSTREAMDATA *streamData, BOOL simpleMode, CMStringA &str, const TCHAR *fmt, ...) { int textCharsCount = 0; TCHAR *line = (TCHAR*)_alloca(8001 * sizeof(TCHAR)); va_list va; va_start(va, fmt); int lineLen = mir_vsntprintf(line, 8000, fmt, va); if (lineLen < 0) lineLen = 8000; line[lineLen] = 0; va_end(va); CMStringA res; for (; *line; line++, textCharsCount++) { if (*line == '\r' && line[1] == '\n') { res.Append("\\par "); line++; } else if (*line == '\n') { res.Append("\\line "); } else if (*line == '%' && !simpleMode) { char szTemp[200]; szTemp[0] = '\0'; switch (*++line) { case '\0': case '%': res.AppendChar('%'); break; case 'c': case 'f': if (g_Settings.bStripFormat || streamData->bStripFormat) line += 2; else if (line[1] != '\0' && line[2] != '\0') { TCHAR szTemp3[3], c = *line; int col; szTemp3[0] = line[1]; szTemp3[1] = line[2]; szTemp3[2] = '\0'; line += 2; col = _ttoi(szTemp3); col += (OPTIONS_FONTCOUNT + 1); res.AppendFormat((c == 'c') ? "\\cf%u " : "\\highlight%u ", col); } break; case 'C': case 'F': if (!g_Settings.bStripFormat && !streamData->bStripFormat) { int j = streamData->lin->bIsHighlighted ? 16 : EventToIndex(streamData->lin); if (*line == 'C') res.AppendFormat("\\cf%u ", j + 1); else res.Append("\\highlight0 "); } break; case 'b': case 'u': case 'i': if (!streamData->bStripFormat) res.AppendFormat((*line == 'u') ? "\\%cl " : "\\%c ", *line); break; case 'B': case 'U': case 'I': if (!streamData->bStripFormat) res.AppendFormat((*line == 'U') ? "\\%cl0 " : "\\%c0 ", tolower(*line)); break; case 'r': if (!streamData->bStripFormat) { int index = EventToIndex(streamData->lin); res.AppendFormat("%s ", pci->Log_SetStyle(index)); } break; } } else if (*line == '\t' && !streamData->bStripFormat) { res.Append("\\tab "); } else if ((*line == '\\' || *line == '{' || *line == '}') && !streamData->bStripFormat) { res.AppendChar('\\'); res.AppendChar(*line); } else if (*line > 0 && *line < 128) { res.AppendChar((char)*line); } else res.AppendFormat("\\u%u ?", (WORD)* line); } str += res; }
static void AppendToBufferWithRTF(CMStringA &buf, const TCHAR *line) { if (line == NULL) return; buf.Append("{\\uc1 "); for (; *line; line++) { if (*line == '\r' && line[1] == '\n') { buf.Append("\\par "); line++; } else if (*line == '\n') { buf.Append("\\par "); } else if (*line == '\t') { buf.Append("\\tab "); } else if (*line == '\\' || *line == '{' || *line == '}') { buf.AppendChar('\\'); buf.AppendChar(*line); } else if (*line == '[' && (g_dat.flags & SMF_SHOWFORMAT)) { int i, found = 0; for (i = 0; i < _countof(bbcodes); ++i) { if (line[1] == bbcodes[i][1]) { size_t lenb = mir_tstrlen(bbcodes[i]); if (!_tcsnicmp(line, bbcodes[i], lenb)) { buf.Append(bbcodefmt[i]); line += lenb - 1; found = 1; break; } } } if (!found) { if (!_tcsnicmp(line, _T("[url"), 4)) { const TCHAR* tag = _tcschr(line + 4, ']'); if (tag) { const TCHAR *tagu = (line[4] == '=') ? line + 5 : tag + 1; const TCHAR *tage = _tcsstr(tag, _T("[/url]")); if (!tage) tage = _tcsstr(tag, _T("[/URL]")); if (tage) { *(TCHAR*)tag = 0; *(TCHAR*)tage = 0; buf.Append("{\\field{\\*\\fldinst HYPERLINK \""); AppendPlainUnicode(buf, tagu); buf.Append("\"}{\\fldrslt "); AppendPlainUnicode(buf, tag+1); buf.Append("}}"); line = tage + 5; found = 1; } } } else if (!_tcsnicmp(line, _T("[color="), 7)) { const TCHAR* tag = _tcschr(line + 7, ']'); if (tag) { line = tag; found = 1; } } else if (!_tcsnicmp(line, _T("[/color]"), 8)) { line += 7; found = 1; } } if (!found) { if (*line < 128) buf.AppendChar((char)*line); else buf.AppendFormat("\\u%d ?", *line); } } else if (*line < 128) buf.AppendChar((char)*line); else buf.AppendFormat("\\u%d ?", *line); } buf.AppendChar('}'); }
static char* Log_CreateRTF(LOGSTREAMDATA *streamData) { LOGINFO *lin = streamData->lin; MODULEINFO *mi = pci->MM_FindModule(streamData->si->pszModule); // ### RTF HEADER if (0 == mi->pszHeader) mi->pszHeader = Log_CreateRtfHeader(mi); char *header = mi->pszHeader; streamData->crCount = mi->nColorCount; CMStringA str; if (header) str.Append(header); // ### RTF BODY (one iteration per event that should be streamed in) while (lin) { // filter if ((streamData->si->iType != GCW_CHATROOM && streamData->si->iType != GCW_PRIVMESS) || !streamData->si->bFilterEnabled || (streamData->si->iLogFilterFlags & lin->iType) != 0) { if (lin->next != NULL) str.Append("\\par "); if (streamData->dat->dwFlags & MWF_DIVIDERWANTED || lin->dwFlags & MWF_DIVIDERWANTED) { static char szStyle_div[128] = "\0"; if (szStyle_div[0] == 0) mir_snprintf(szStyle_div, "\\f%u\\cf%u\\ul0\\b%d\\i%d\\fs%u", 17, 18, 0, 0, 5); lin->dwFlags |= MWF_DIVIDERWANTED; if (lin->prev || !streamData->bRedraw) str.AppendFormat("\\qc\\sl-1\\highlight%d %s ---------------------------------------------------------------------------------------\\par ", 18, szStyle_div); streamData->dat->dwFlags &= ~MWF_DIVIDERWANTED; } // create new line, and set font and color str.AppendFormat("\\ql\\sl0%s ", pci->Log_SetStyle(0)); str.AppendFormat("\\v~-+%d+-~\\v0 ", lin); // Insert icon if (g_Settings.bLogSymbols) // use symbols str.AppendFormat("%s %c", pci->Log_SetStyle(17), EventToSymbol(lin)); else if (g_Settings.dwIconFlags) { int iIndex = lin->bIsHighlighted ? ICON_HIGHLIGHT : EventToIcon(lin); str.Append("\\f0\\fs14"); str.AppendFormat(pci->pLogIconBmpBits[iIndex], (int)pci->logIconBmpSize[iIndex]); } if (g_Settings.bTimeStampEventColour) { // colored timestamps static char szStyle[256]; LOGFONT &F = pci->aFonts[0].lf; int iii; if (lin->ptszNick && lin->iType == GC_EVENT_MESSAGE) { iii = lin->bIsHighlighted ? 16 : (lin->bIsMe ? 2 : 1); mir_snprintf(szStyle, "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\ul%d\\fs%u", iii + 1, F.lfWeight >= FW_BOLD ? 1 : 0, F.lfItalic, F.lfUnderline, 2 * abs(F.lfHeight) * 74 / pci->logPixelSY); str.Append(szStyle); } else { iii = lin->bIsHighlighted ? 16 : EventToIndex(lin); mir_snprintf(szStyle, "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\ul%d\\fs%u", iii + 1, F.lfWeight >= FW_BOLD ? 1 : 0, F.lfItalic, F.lfUnderline, 2 * abs(F.lfHeight) * 74 / pci->logPixelSY); str.Append(szStyle); } } else str.Append(pci->Log_SetStyle(0)); str.AppendChar(' '); // insert a TAB if necessary to put the timestamp in the right position if (g_Settings.dwIconFlags) str.Append("\\tab "); //insert timestamp if (g_Settings.bShowTime) { TCHAR szTimeStamp[30], szOldTimeStamp[30]; _tcsncpy_s(szTimeStamp, pci->MakeTimeStamp(g_Settings.pszTimeStamp, lin->time), _TRUNCATE); _tcsncpy_s(szOldTimeStamp, pci->MakeTimeStamp(g_Settings.pszTimeStamp, streamData->si->LastTime), _TRUNCATE); if (!g_Settings.bShowTimeIfChanged || streamData->si->LastTime == 0 || mir_tstrcmp(szTimeStamp, szOldTimeStamp)) { streamData->si->LastTime = lin->time; Log_AppendRTF(streamData, TRUE, str, _T("%s"), szTimeStamp); } str.Append("\\tab "); } // Insert the nick if (lin->ptszNick && lin->iType == GC_EVENT_MESSAGE) { char pszIndicator[3] = "\0\0"; int crNickIndex = 0; if (g_Settings.bLogClassicIndicators || g_Settings.bColorizeNicksInLog) pszIndicator[0] = GetIndicator(streamData->si, lin->ptszNick, &crNickIndex); str.Append(pci->Log_SetStyle(lin->bIsMe ? 2 : 1)); str.AppendChar(' '); if (g_Settings.bLogClassicIndicators) str.Append(pszIndicator); CMString pszTemp(lin->bIsMe ? g_Settings.pszOutgoingNick : g_Settings.pszIncomingNick); pszTemp.Replace(_T("%n"), _T("%s")); if (!lin->bIsMe) { if (g_Settings.bClickableNicks) pszTemp.Replace(_T("%s"), _T("~~++#%s#++~~")); if (g_Settings.bColorizeNicksInLog && pszIndicator[0]) str.AppendFormat("\\cf%u ", OPTIONS_FONTCOUNT + streamData->crCount + crNickIndex); } Log_AppendRTF(streamData, TRUE, str, pszTemp, lin->ptszNick); str.AppendChar(' '); } // Insert the message str.Append(pci->Log_SetStyle(lin->bIsHighlighted ? 16 : EventToIndex(lin))); str.AppendChar(' '); streamData->lin = lin; AddEventToBuffer(str, streamData); } lin = lin->prev; } // ### RTF END if (streamData->bRedraw) str.Append("\\par}"); else str.Append("}"); return str.Detach(); }
void CSkypeProto::ProcessEndpointPresence(const JSONNode &node) { debugLogA("CSkypeProto::ProcessEndpointPresenceRes"); std::string selfLink = node["selfLink"].as_string(); CMStringA skypename(UrlToSkypename(selfLink.c_str())); MCONTACT hContact = FindContact(skypename); if (hContact == NULL) return; const JSONNode &publicInfo = node["publicInfo"]; const JSONNode &privateInfo = node["privateInfo"]; CMStringA MirVer; if (publicInfo) { std::string skypeNameVersion = publicInfo["skypeNameVersion"].as_string(); std::string version = publicInfo["version"].as_string(); std::string typ = publicInfo["typ"].as_string(); int iTyp = atoi(typ.c_str()); switch (iTyp) { case 0: case 1: MirVer.AppendFormat("Skype (Web) %s", ParseUrl(version.c_str(), "/")); break; case 10: MirVer.AppendFormat("Skype (XBOX) %s", ParseUrl(skypeNameVersion.c_str(), "/")); break; case 17: MirVer.AppendFormat("Skype (Android) %s", ParseUrl(skypeNameVersion.c_str(), "/")); break; case 16: MirVer.AppendFormat("Skype (iOS) %s", ParseUrl(skypeNameVersion.c_str(), "/")); break; case 12: MirVer.AppendFormat("Skype (WinRT) %s", ParseUrl(skypeNameVersion.c_str(), "/")); break; case 15: MirVer.AppendFormat("Skype (WP) %s", ParseUrl(skypeNameVersion.c_str(), "/")); break; case 13: MirVer.AppendFormat("Skype (OSX) %s", ParseUrl(skypeNameVersion.c_str(), "/")); break; case 11: MirVer.AppendFormat("Skype (Windows) %s", ParseUrl(skypeNameVersion.c_str(), "/")); break; case 14: MirVer.AppendFormat("Skype (Linux) %s", ParseUrl(skypeNameVersion.c_str(), "/")); break; case 125: MirVer.AppendFormat("Miranda NG Skype %s", version.c_str()); break; default: MirVer.Append("Skype (Unknown)"); } } if (privateInfo != NULL) { std::string epname = privateInfo["epname"].as_string(); if (!epname.empty()) { MirVer.AppendFormat(" [%s]", epname.c_str()); } } db_set_s(hContact, m_szModuleName, "MirVer", MirVer); }
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; }