void CJabberProto::DBAddAuthRequest(const TCHAR *jid, const TCHAR *nick) { MCONTACT hContact = DBCreateContact(jid, nick, TRUE, TRUE); delSetting(hContact, "Hidden"); T2Utf szJid(jid); T2Utf szNick(nick); // blob is: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ) // blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), email(ASCIIZ), ""(ASCIIZ) DBEVENTINFO dbei = { sizeof(DBEVENTINFO) }; dbei.szModule = m_szModuleName; dbei.timestamp = (DWORD)time(NULL); dbei.flags = DBEF_UTF; dbei.eventType = EVENTTYPE_AUTHREQUEST; dbei.cbBlob = (DWORD)(sizeof(DWORD) * 2 + mir_strlen(szNick) + mir_strlen(szJid) + 5); PBYTE pCurBlob = dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); *((PDWORD)pCurBlob) = 0; pCurBlob += sizeof(DWORD); *((PDWORD)pCurBlob) = (DWORD)hContact; pCurBlob += sizeof(DWORD); mir_strcpy((char*)pCurBlob, szNick); pCurBlob += mir_strlen(szNick) + 1; *pCurBlob = '\0'; pCurBlob++; //firstName *pCurBlob = '\0'; pCurBlob++; //lastName mir_strcpy((char*)pCurBlob, szJid); pCurBlob += mir_strlen(szJid) + 1; *pCurBlob = '\0'; //reason db_event_add(NULL, &dbei); debugLogA("Setup DBAUTHREQUEST with nick='%s' jid='%s'", szNick, szJid); }
INT_PTR __cdecl CJabberProto::JabberServiceParseXmppURI(WPARAM, LPARAM lParam) { TCHAR *arg = (TCHAR *)lParam; if (arg == NULL) return 1; // skip leading prefix TCHAR szUri[ 1024 ]; _tcsncpy_s(szUri, SIZEOF(szUri), arg, _TRUNCATE); TCHAR *szJid = _tcschr(szUri, _T(':')); if (szJid == NULL) return 1; // skip // for (++szJid; *szJid == _T('/'); ++szJid); // empty jid? if (!*szJid) return 1; // command code TCHAR *szCommand = szJid; szCommand = _tcschr(szCommand, _T('?')); if (szCommand) *(szCommand++) = 0; // parameters TCHAR *szSecondParam = szCommand ? _tcschr(szCommand, _T(';')) : NULL; if (szSecondParam) *(szSecondParam++) = 0; // no command or message command if (!szCommand || (szCommand && !_tcsicmp(szCommand, _T("message")))) { // message if (!ServiceExists(MS_MSG_SENDMESSAGEW)) return 1; TCHAR *szMsgBody = NULL; HANDLE hContact = HContactFromJID(szJid, TRUE); if (hContact == NULL) hContact = DBCreateContact(szJid, szJid, TRUE, TRUE); if (hContact == NULL) return 1; if (szSecondParam) { //there are parameters to message szMsgBody = _tcsstr(szSecondParam, _T("body=")); if (szMsgBody) { szMsgBody += 5; TCHAR *szDelim = _tcschr(szMsgBody, _T(';')); if (szDelim) szDelim = 0; JabberHttpUrlDecode(szMsgBody); } } CallService(MS_MSG_SENDMESSAGEW, (WPARAM)hContact, (LPARAM)szMsgBody); return 0; } if (!_tcsicmp(szCommand, _T("roster"))) { if (!HContactFromJID(szJid)) { JABBER_SEARCH_RESULT jsr = { 0 }; jsr.hdr.cbSize = sizeof(JABBER_SEARCH_RESULT); jsr.hdr.flags = PSR_TCHAR; jsr.hdr.nick = szJid; jsr.hdr.id = szJid; _tcsncpy(jsr.jid, szJid, SIZEOF(jsr.jid) - 1); ADDCONTACTSTRUCT acs; acs.handleType = HANDLE_SEARCHRESULT; acs.szProto = m_szModuleName; acs.psr = &jsr.hdr; CallService(MS_ADDCONTACT_SHOW, 0, (LPARAM)&acs); } return 0; } // chat join invitation if (!_tcsicmp(szCommand, _T("join"))) { GroupchatJoinRoomByJid(NULL, szJid); return 0; } // service discovery request if (!_tcsicmp(szCommand, _T("disco"))) { OnMenuHandleServiceDiscovery(0, (LPARAM)szJid); return 0; } // ad-hoc commands if (!_tcsicmp(szCommand, _T("command"))) { if (szSecondParam) { if (!_tcsnicmp(szSecondParam, _T("node="), 5)) { szSecondParam += 5; if (!*szSecondParam) szSecondParam = NULL; } else szSecondParam = NULL; } CJabberAdhocStartupParams* pStartupParams = new CJabberAdhocStartupParams(this, szJid, szSecondParam); ContactMenuRunCommands(0, (LPARAM)pStartupParams); return 0; } // send file if (!_tcsicmp(szCommand, _T("sendfile"))) { if (!ServiceExists(MS_FILE_SENDFILE)) return 1; HANDLE hContact = HContactFromJID(szJid, TRUE); if (hContact == NULL) hContact = DBCreateContact(szJid, szJid, TRUE, TRUE); if (hContact == NULL) return 1; CallService(MS_FILE_SENDFILE, (WPARAM)hContact, (LPARAM)NULL); return 0; } return 1; /* parse failed */ }
BOOL CJabberProto::OnRosterPushRequest(HXML, CJabberIqInfo *pInfo) { HXML queryNode = pInfo->GetChildNode(); // RFC 3921 #7.2 Business Rules if (pInfo->GetFrom()) { TCHAR *szFrom = JabberPrepareJid(pInfo->GetFrom()); if (!szFrom) return TRUE; TCHAR *szTo = JabberPrepareJid(m_ThreadInfo->fullJID); if (!szTo) { mir_free(szFrom); return TRUE; } TCHAR *pDelimiter = _tcschr(szFrom, _T('/')); if (pDelimiter) *pDelimiter = 0; pDelimiter = _tcschr(szTo, _T('/')); if (pDelimiter) *pDelimiter = 0; BOOL bRetVal = mir_tstrcmp(szFrom, szTo) == 0; mir_free(szFrom); mir_free(szTo); // invalid JID if (!bRetVal) { debugLog(_T("<iq/> attempt to hack via roster push from %s"), pInfo->GetFrom()); return TRUE; } } JABBER_LIST_ITEM *item; MCONTACT hContact = NULL; const TCHAR *jid, *str; debugLogA("<iq/> Got roster push, query has %d children", XmlGetChildCount(queryNode)); for (int i = 0;; i++) { HXML itemNode = XmlGetChild(queryNode, i); if (!itemNode) break; if (mir_tstrcmp(XmlGetName(itemNode), _T("item")) != 0) continue; if ((jid = XmlGetAttrValue(itemNode, _T("jid"))) == NULL) continue; if ((str = XmlGetAttrValue(itemNode, _T("subscription"))) == NULL) continue; // we will not add new account when subscription=remove if (!mir_tstrcmp(str, _T("to")) || !mir_tstrcmp(str, _T("both")) || !mir_tstrcmp(str, _T("from")) || !mir_tstrcmp(str, _T("none"))) { const TCHAR *name = XmlGetAttrValue(itemNode, _T("name")); ptrT nick((name != NULL) ? mir_tstrdup(name) : JabberNickFromJID(jid)); if (nick != NULL) { if ((item = ListAdd(LIST_ROSTER, jid)) != NULL) { replaceStrT(item->nick, nick); HXML groupNode = XmlGetChild(itemNode, "group"); replaceStrT(item->group, XmlGetText(groupNode)); if ((hContact = HContactFromJID(jid, 0)) == NULL) { // Received roster has a new JID. // Add the jid (with empty resource) to Miranda contact list. hContact = DBCreateContact(jid, nick, FALSE, FALSE); } else setTString(hContact, "jid", jid); if (name != NULL) { ptrT tszNick(getTStringA(hContact, "Nick")); if (tszNick != NULL) { if (mir_tstrcmp(nick, tszNick) != 0) db_set_ts(hContact, "CList", "MyHandle", nick); else db_unset(hContact, "CList", "MyHandle"); } else db_set_ts(hContact, "CList", "MyHandle", nick); } else db_unset(hContact, "CList", "MyHandle"); if (!m_options.IgnoreRosterGroups) { if (item->group != NULL) { Clist_CreateGroup(0, item->group); db_set_ts(hContact, "CList", "Group", item->group); } else db_unset(hContact, "CList", "Group"); } } } } if ((item = ListGetItemPtr(LIST_ROSTER, jid)) != NULL) { if (!mir_tstrcmp(str, _T("both"))) item->subscription = SUB_BOTH; else if (!mir_tstrcmp(str, _T("to"))) item->subscription = SUB_TO; else if (!mir_tstrcmp(str, _T("from"))) item->subscription = SUB_FROM; else item->subscription = SUB_NONE; debugLog(_T("Roster push for jid=%s, set subscription to %s"), jid, str); // subscription = remove is to remove from roster list // but we will just set the contact to offline and not actually // remove, so that history will be retained. if (!mir_tstrcmp(str, _T("remove"))) { if ((hContact = HContactFromJID(jid)) != NULL) { SetContactOfflineStatus(hContact); ListRemove(LIST_ROSTER, jid); } } else if (isChatRoom(hContact)) db_unset(hContact, "CList", "Hidden"); else UpdateSubscriptionInfo(hContact, item); } } UI_SAFE_NOTIFY(m_pDlgServiceDiscovery, WM_JABBER_TRANSPORT_REFRESH); RebuildInfoFrame(); return TRUE; }