static void LogPictureMessage(TlenProtocol *proto, const char *jid, const char *filename, BOOL isSent) { char message[1024]; const char *msg = isSent ? LPGEN("Image sent file://%s") : LPGEN("Image received file://%s"); mir_snprintf(message, sizeof(message), Translate(msg), filename); TlenLogMessage(proto, TlenHContactFromJID(proto, jid), isSent ? DBEF_SENT : 0, message); }
static char *getDisplayName(TlenProtocol *proto, const char *id) { char jid[256]; MCONTACT hContact; DBVARIANT dbv; if (!db_get(NULL, proto->m_szModuleName, "LoginServer", &dbv)) { mir_snprintf(jid, SIZEOF(jid), "%s@%s", id, dbv.pszVal); db_free(&dbv); if (((hContact=TlenHContactFromJID(proto, jid)) != NULL) || !strcmp(id, proto->threadData->username)) { CONTACTINFO ci = { sizeof(ci) }; ci.hContact = hContact; ci.szProto = (char *)proto->m_szModuleName; ci.dwFlag = CNF_DISPLAY; if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) & ci)) { if (ci.type == CNFT_ASCIIZ) { if (ci.pszVal) { char* str = mir_t2a(ci.pszVal); mir_free(ci.pszVal); return str; } } } } } return mir_strdup(id); }
int TlenProcessAvatarNode(TlenProtocol *proto, XmlNode *avatarNode, TLEN_LIST_ITEM *item) { XmlNode *aNode; char *oldHash = NULL; char *md5 = NULL, *type = NULL; HANDLE hContact; hContact = NULL; if (item != NULL) { if ((hContact=TlenHContactFromJID(proto, item->jid)) == NULL) return 0; } if (item == NULL) { oldHash = proto->threadData->avatarHash; } else { oldHash = item->avatarHash; } if (avatarNode != NULL) { aNode = TlenXmlGetChild(avatarNode, "a"); if (aNode != NULL) { type = TlenXmlGetAttrValue(aNode, "type"); md5 = TlenXmlGetAttrValue(aNode, "md5"); } } if (md5 != NULL) { /* check contact's avatar hash - md5 */ if (oldHash == NULL || strcmp(oldHash, md5)) { if (item != NULL) { item->newAvatarDownloading = TRUE; } TlenGetAvatar(proto, hContact); return 1; } } else { /* remove avatar */ if (oldHash != NULL) { if (item != NULL) { item->avatarHash = NULL; mir_free(oldHash); item->newAvatarDownloading = FALSE; } RemoveAvatar(proto, hContact); return 1; } } return 0; }
void TlenIqResultInfo(TlenProtocol *proto, XmlNode *iqNode) { XmlNode *queryNode = TlenXmlGetChild(iqNode, "query"); if (queryNode != NULL) { char* from; if (( from=TlenXmlGetAttrValue( queryNode, "from" )) != NULL ) { TLEN_LIST_ITEM *item; if (( item=TlenListGetItemPtr( proto, LIST_ROSTER, from )) != NULL) { MCONTACT hContact; XmlNode *version = TlenXmlGetChild(queryNode, "version"); item->protocolVersion = TlenTextDecode(version->text); if (( hContact=TlenHContactFromJID(proto, item->jid )) != NULL ) { if (item->software == NULL) { char str[128]; mir_snprintf(str, sizeof(str), "Tlen Protocol %s", item->protocolVersion); db_set_s(hContact, proto->m_szModuleName, "MirVer", str); } } } } } }
void TlenIqResultVersion(TlenProtocol *proto, XmlNode *iqNode) { XmlNode *queryNode = TlenXmlGetChild(iqNode, "query"); if (queryNode != NULL) { char* from; if (( from=TlenXmlGetAttrValue( iqNode, "from" )) != NULL ) { TLEN_LIST_ITEM *item; if (( item=TlenListGetItemPtr( proto, LIST_ROSTER, from )) != NULL) { MCONTACT hContact; XmlNode *n; if ( item->software ) mir_free( item->software ); if ( item->version ) mir_free( item->version ); if ( item->system ) mir_free( item->system ); if (( n=TlenXmlGetChild( queryNode, "name" )) != NULL && n->text ) { item->software = TlenTextDecode( n->text ); } else item->software = NULL; if (( n=TlenXmlGetChild( queryNode, "version" )) != NULL && n->text ) item->version = TlenTextDecode( n->text ); else item->version = NULL; if (( n=TlenXmlGetChild( queryNode, "os" )) != NULL && n->text ) item->system = TlenTextDecode( n->text ); else item->system = NULL; if (( hContact=TlenHContactFromJID(proto, item->jid )) != NULL ) { if (item->software != NULL) { db_set_s(hContact, proto->m_szModuleName, "MirVer", item->software); } else { db_unset(hContact, proto->m_szModuleName, "MirVer"); } } } } } }
void TlenProcessPresenceAvatar(TlenProtocol *proto, XmlNode *node, TLEN_LIST_ITEM *item) { HANDLE hContact; if ((hContact=TlenHContactFromJID(proto, item->jid)) == NULL) return; TlenProcessAvatarNode(proto, TlenXmlGetChild(node, "avatar"), item); }
void TlenResultSetRoster(TlenProtocol *proto, XmlNode *queryNode) { DBVARIANT dbv; XmlNode *itemNode, *groupNode; TLEN_LIST_ITEM *item; MCONTACT hContact; char *jid, *name, *nick; int i; char *str; for (i=0; i<queryNode->numChild; i++) { itemNode = queryNode->child[i]; if (!strcmp(itemNode->name, "item")) { if ((jid=TlenXmlGetAttrValue(itemNode, "jid")) != NULL) { str = TlenXmlGetAttrValue(itemNode, "subscription"); if (!strcmp(str, "remove")) { if ((hContact = TlenHContactFromJID(proto, jid)) != NULL) { if (db_get_w(hContact, proto->m_szModuleName, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) db_set_w(hContact, proto->m_szModuleName, "Status", ID_STATUS_OFFLINE); } TlenListRemove(proto, LIST_ROSTER, jid); } else { item = TlenListAdd(proto, LIST_ROSTER, jid); if (item != NULL) { if (str == NULL) item->subscription = SUB_NONE; else if (!strcmp(str, "both")) item->subscription = SUB_BOTH; else if (!strcmp(str, "to")) item->subscription = SUB_TO; else if (!strcmp(str, "from")) item->subscription = SUB_FROM; else item->subscription = SUB_NONE; if ((name=TlenXmlGetAttrValue(itemNode, "name")) != NULL) { nick = TlenTextDecode(name); } else { nick = TlenLocalNickFromJID(jid); } if (nick != NULL) { if (item->nick) mir_free(item->nick); item->nick = nick; if ((hContact=TlenHContactFromJID(proto, jid)) == NULL) { // Received roster has a new JID. // Add the jid (with empty resource) to Miranda contact list. hContact = TlenDBCreateContact(proto, jid, nick, FALSE); } db_set_s(hContact, "CList", "MyHandle", nick); if (item->group) mir_free(item->group); if ((groupNode=TlenXmlGetChild(itemNode, "group")) != NULL && groupNode->text != NULL) { item->group = TlenGroupDecode(groupNode->text); Clist_CreateGroup(0, _A2T(item->group)); // Don't set group again if already correct, or Miranda may show wrong group count in some case if (!db_get(hContact, "CList", "Group", &dbv)) { if (strcmp(dbv.pszVal, item->group)) db_set_s(hContact, "CList", "Group", item->group); db_free(&dbv); } else db_set_s(hContact, "CList", "Group", item->group); } else { item->group = NULL; db_unset(hContact, "CList", "Group"); } } } } } } } }
// Tlen actually use jabber:iq:search for other users vCard or jabber:iq:register for own vCard void TlenIqResultVcard(TlenProtocol *proto, XmlNode *iqNode) { XmlNode *queryNode, *itemNode, *n; char *type, *jid; char text[128]; MCONTACT hContact; char *nText; // TlenLog("<iq/> iqIdGetVcard (tlen)"); if ((type=TlenXmlGetAttrValue(iqNode, "type")) == NULL) return; if (!strcmp(type, "result")) { BOOL hasFirst, hasLast, hasNick, hasEmail, hasCity, hasAge, hasGender, hasSchool, hasLookFor, hasOccupation; DBVARIANT dbv; int i; if ((queryNode=TlenXmlGetChild(iqNode, "query")) == NULL) return; if ((itemNode=TlenXmlGetChild(queryNode, "item")) == NULL) return; if ((jid=TlenXmlGetAttrValue(itemNode, "jid")) != NULL) { if (db_get(NULL, proto->m_szModuleName, "LoginServer", &dbv)) return; if (strchr(jid, '@') != NULL) { mir_snprintf(text, SIZEOF(text), "%s", jid); } else { mir_snprintf(text, SIZEOF(text), "%s@%s", jid, dbv.pszVal); // Add @tlen.pl } db_free(&dbv); if ((hContact=TlenHContactFromJID(proto, text)) == NULL) { if (db_get(NULL, proto->m_szModuleName, "LoginName", &dbv)) return; if (strcmp(dbv.pszVal, jid)) { db_free(&dbv); return; } db_free(&dbv); } } else { hContact = NULL; } hasFirst = hasLast = hasNick = hasEmail = hasCity = hasAge = hasGender = hasOccupation = hasLookFor = hasSchool = FALSE; for (i=0; i<itemNode->numChild; i++) { n = itemNode->child[i]; if (n == NULL || n->name == NULL) continue; if (!strcmp(n->name, "first")) { if (n->text != NULL) { hasFirst = TRUE; nText = TlenTextDecode(n->text); db_set_s(hContact, proto->m_szModuleName, "FirstName", nText); mir_free(nText); } } else if (!strcmp(n->name, "last")) { if (n->text != NULL) { hasLast = TRUE; nText = TlenTextDecode(n->text); db_set_s(hContact, proto->m_szModuleName, "LastName", nText); mir_free(nText); } } else if (!strcmp(n->name, "nick")) { if (n->text != NULL) { hasNick = TRUE; nText = TlenTextDecode(n->text); db_set_s(hContact, proto->m_szModuleName, "Nick", nText); mir_free(nText); } } else if (!strcmp(n->name, "email")) { if (n->text != NULL) { hasEmail = TRUE; nText = TlenTextDecode(n->text); db_set_s(hContact, proto->m_szModuleName, "e-mail", nText); mir_free(nText); } } else if (!strcmp(n->name, "c")) { if (n->text != NULL) { hasCity = TRUE; nText = TlenTextDecode(n->text); db_set_s(hContact, proto->m_szModuleName, "City", nText); mir_free(nText); } } else if (!strcmp(n->name, "b")) { if (n->text != NULL) { WORD nAge; hasAge = TRUE; nAge = atoi(n->text); db_set_w(hContact, proto->m_szModuleName, "Age", nAge); } } else if (!strcmp(n->name, "s")) { if (n->text != NULL && n->text[1] == '\0' && (n->text[0] == '1' || n->text[0] == '2')) { hasGender = TRUE; db_set_b(hContact, proto->m_szModuleName, "Gender", (BYTE) (n->text[0] == '1'?'M':'F')); } } else if (!strcmp(n->name, "e")) { if (n->text != NULL) { hasSchool = TRUE; nText = TlenTextDecode(n->text); db_set_s(hContact, proto->m_szModuleName, "School", nText); mir_free(nText); } } else if (!strcmp(n->name, "j")) { if (n->text != NULL) { WORD nOccupation; hasOccupation = TRUE; nOccupation = atoi(n->text); db_set_w(hContact, proto->m_szModuleName, "Occupation", nOccupation); } } else if (!strcmp(n->name, "r")) { if (n->text != NULL) { WORD nLookFor; hasLookFor = TRUE; nLookFor = atoi(n->text); db_set_w(hContact, proto->m_szModuleName, "LookingFor", nLookFor); } } else if (!strcmp(n->name, "g")) { // voice chat enabled if (n->text != NULL) { BYTE bVoice; bVoice = atoi(n->text); db_set_w(hContact, proto->m_szModuleName, "VoiceChat", bVoice); } } else if (!strcmp(n->name, "v")) { // status visibility if (n->text != NULL) { BYTE bPublic; bPublic = atoi(n->text); db_set_w(hContact, proto->m_szModuleName, "PublicStatus", bPublic); } } } if (!hasFirst) db_unset(hContact, proto->m_szModuleName, "FirstName"); if (!hasLast) db_unset(hContact, proto->m_szModuleName, "LastName"); // We are not removing "Nick" // if (!hasNick) // db_unset(hContact, m_szModuleName, "Nick"); if (!hasEmail) db_unset(hContact, proto->m_szModuleName, "e-mail"); if (!hasCity) db_unset(hContact, proto->m_szModuleName, "City"); if (!hasAge) db_unset(hContact, proto->m_szModuleName, "Age"); if (!hasGender) db_unset(hContact, proto->m_szModuleName, "Gender"); if (!hasSchool) db_unset(hContact, proto->m_szModuleName, "School"); if (!hasOccupation) db_unset(hContact, proto->m_szModuleName, "Occupation"); if (!hasLookFor) db_unset(hContact, proto->m_szModuleName, "LookingFor"); ProtoBroadcastAck(proto->m_szModuleName, hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE) 1, 0); } }
void TlenIqResultRoster(TlenProtocol *proto, XmlNode *iqNode) { XmlNode *queryNode; char *type; char *str; // RECVED: roster information // ACTION: populate LIST_ROSTER and create contact for any new rosters if ((type=TlenXmlGetAttrValue(iqNode, "type")) == NULL) return; if ((queryNode=TlenXmlGetChild(iqNode, "query")) == NULL) return; if (!strcmp(type, "result")) { str = TlenXmlGetAttrValue(queryNode, "xmlns"); if (str != NULL && !strcmp(str, "jabber:iq:roster")) { DBVARIANT dbv; XmlNode *itemNode, *groupNode; TLEN_SUBSCRIPTION sub; TLEN_LIST_ITEM *item; char *jid, *name, *nick; int i, oldStatus; for (i=0; i<queryNode->numChild; i++) { itemNode = queryNode->child[i]; if (!strcmp(itemNode->name, "item")) { str = TlenXmlGetAttrValue(itemNode, "subscription"); if (str == NULL) sub = SUB_NONE; else if (!strcmp(str, "both")) sub = SUB_BOTH; else if (!strcmp(str, "to")) sub = SUB_TO; else if (!strcmp(str, "from")) sub = SUB_FROM; else sub = SUB_NONE; //if (str != NULL && (!strcmp(str, "to") || !strcmp(str, "both"))) { if ((jid=TlenXmlGetAttrValue(itemNode, "jid")) != NULL) { if ((name=TlenXmlGetAttrValue(itemNode, "name")) != NULL) nick = TlenTextDecode(name); else nick = TlenLocalNickFromJID(jid); if (nick != NULL) { MCONTACT hContact; item = TlenListAdd(proto, LIST_ROSTER, jid); if (item->nick) mir_free(item->nick); item->nick = nick; item->subscription = sub; if ((hContact=TlenHContactFromJID(proto, jid)) == NULL) { // Received roster has a new JID. // Add the jid (with empty resource) to Miranda contact list. hContact = TlenDBCreateContact(proto, jid, nick, FALSE); } db_set_s(hContact, "CList", "MyHandle", nick); if (item->group) mir_free(item->group); if ((groupNode=TlenXmlGetChild(itemNode, "group")) != NULL && groupNode->text != NULL) { item->group = TlenGroupDecode(groupNode->text); Clist_CreateGroup(0, _A2T(item->group)); // Don't set group again if already correct, or Miranda may show wrong group count in some case if (!db_get(hContact, "CList", "Group", &dbv)) { if (strcmp(dbv.pszVal, item->group)) db_set_s(hContact, "CList", "Group", item->group); db_free(&dbv); } else db_set_s(hContact, "CList", "Group", item->group); } else { item->group = NULL; db_unset(hContact, "CList", "Group"); } if (!db_get(hContact, proto->m_szModuleName, "AvatarHash", &dbv)) { if (item->avatarHash) mir_free(item->avatarHash); item->avatarHash = mir_strdup(dbv.pszVal); proto->debugLogA("Setting hash [%s] = %s", nick, item->avatarHash); db_free(&dbv); } item->avatarFormat = db_get_dw(hContact, proto->m_szModuleName, "AvatarFormat", PA_FORMAT_UNKNOWN); } } } } // Delete orphaned contacts (if roster sync is enabled) if (db_get_b(NULL, proto->m_szModuleName, "RosterSync", FALSE) == TRUE) { for (MCONTACT hContact = db_find_first(proto->m_szModuleName); hContact; ) { MCONTACT hNext = hContact = db_find_next(hContact, proto->m_szModuleName); ptrA jid( db_get_sa(hContact, proto->m_szModuleName, "jid")); if (jid != NULL) { if (!TlenListExist(proto, LIST_ROSTER, jid)) { proto->debugLogA("Syncing roster: deleting 0x%x", hContact); CallService(MS_DB_CONTACT_DELETE, hContact, 0); } } hContact = hNext; } } CLISTMENUITEM mi = { sizeof(mi) }; mi.flags = CMIM_FLAGS; Menu_ModifyItem(proto->hMenuMUC, &mi); if (proto->hMenuChats != NULL) Menu_ModifyItem(proto->hMenuChats, &mi); proto->isOnline = TRUE; proto->debugLogA("Status changed via THREADSTART"); oldStatus = proto->m_iStatus; TlenSendPresence(proto, proto->m_iDesiredStatus); ProtoBroadcastAck(proto->m_szModuleName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE) oldStatus, proto->m_iStatus); } } }
void __cdecl TlenProcessP2P(XmlNode *node, ThreadData *info) { XmlNode *queryNode; TLEN_LIST_ITEM *item; char *from; if (info == NULL) return; queryNode = TlenXmlGetChild(node, "query"); if ((from=TlenXmlGetAttrValue(node, "from")) != NULL) { XmlNode *fs , *vs, *dcng, *dc; /* file send */ fs = TlenXmlGetChild(queryNode, "fs"); /* voice send */ vs = TlenXmlGetChild(queryNode, "vs"); dcng = TlenXmlGetChild(queryNode, "dcng"); dc = TlenXmlGetChild(queryNode, "dc"); if (fs != NULL) { char *e, *id; /* e - step in the process (starting with 1)*/ /* i - id of the file */ /* s - size of the file */ /* c - number of files */ /* v - ??? */ e = TlenXmlGetAttrValue(fs, "e"); id = TlenXmlGetAttrValue(fs, "i"); if (e != NULL) { if (!strcmp(e, "1")) { char *c, *s; TLEN_FILE_TRANSFER * ft = (TLEN_FILE_TRANSFER *) mir_alloc(sizeof(TLEN_FILE_TRANSFER)); memset(ft, 0, sizeof(TLEN_FILE_TRANSFER)); c = TlenXmlGetAttrValue(fs, "c"); s = TlenXmlGetAttrValue(fs, "s"); ft->jid = mir_strdup(from); ft->proto = info->proto; ft->hContact = TlenHContactFromJID(info->proto, from); ft->iqId = mir_strdup(id); ft->fileTotalSize = atoi(s); ft->newP2P = TRUE; if ((item=TlenListAdd(ft->proto, LIST_FILE, ft->iqId)) != NULL) { char fileInfo[128]; item->ft = ft; mir_snprintf(fileInfo, SIZEOF(fileInfo), "%s file(s), %s bytes", c, s); TCHAR* filenameT = mir_utf8decodeT((char*)fileInfo); PROTORECVFILET pre = {0}; pre.flags = PREF_TCHAR; pre.fileCount = 1; pre.timestamp = time(NULL); pre.tszDescription = filenameT; pre.ptszFiles = &filenameT; pre.lParam = (LPARAM)ft; ft->proto->debugLogA("sending chainrecv"); ProtoChainRecvFile(ft->hContact, &pre); mir_free(filenameT); } } else if (!strcmp(e, "3")) { /* transfer error */ } else if (!strcmp(e, "4")) { /* transfer denied */ } else if (!strcmp(e, "5")) { /* transfer accepted */ if ((item=TlenListGetItemPtr(info->proto, LIST_FILE, id)) != NULL) { item->id2 = mir_strdup("84273372"); item->ft->id2 = mir_strdup("84273372"); TlenSend(info->proto, "<iq to='%s'><query xmlns='p2p'><dcng n='file_send' k='5' v='2' s='1' i='%s' ck='o7a32V9n2UZYCWpBUhSbFw==' ks='16' iv='MhjWEj9WTsovrQc=o7a32V9n2UZYCWpBUhSbFw==' mi='%s'/></query></iq>", from, item->id2, id); } } } } else if (vs != NULL) { } else if (dcng != NULL) { char *s, *id, *id2; info->proto->debugLogA("DCNG"); s = TlenXmlGetAttrValue(dcng, "s"); id2 = TlenXmlGetAttrValue(dcng, "i"); id = TlenXmlGetAttrValue(dcng, "mi"); if (!strcmp(s, "1")) { /* Keys */ /* n - name (file_send) */ /* k - ??? */ /* v - ??? */ /* s - step */ /* i - id of the file */ /* ck - aes key */ /* ks - key size (in bytes) */ /* iv - aes initial vector */ /* mi - p2p connection id */ char *n, *k, *v, *ck, *iv; n = TlenXmlGetAttrValue(dcng, "n"); k = TlenXmlGetAttrValue(dcng, "k"); v = TlenXmlGetAttrValue(dcng, "v"); ck = TlenXmlGetAttrValue(dcng, "ck"); iv = TlenXmlGetAttrValue(dcng, "iv"); if (!strcmp(n, "file_send")) { if ((item=TlenListGetItemPtr(info->proto, LIST_FILE, id)) != NULL) { item->id2 = mir_strdup(id2); item->ft->id2 = mir_strdup(id2); TlenBindUDPSocket(item->ft); TlenSend(info->proto, "<iq to='%s'><query xmlns='p2p'><dcng la='%s' lp='%d' pa='%s' pp='%d' i='%s' v='2' k='5' s='2'/></query></iq>", item->ft->jid, item->ft->localName, item->ft->wLocalPort, item->ft->localName, item->ft->wLocalPort, item->ft->id2); } } } else if (!strcmp(s, "2")) { info->proto->debugLogA("step = 2"); info->proto->debugLogA("%s",from); info->proto->debugLogA("%s",id2); /* IP and port */ if ((item=TlenListFindItemPtrById2(info->proto, LIST_FILE, id2)) != NULL) { item->ft->hostName = mir_strdup(TlenXmlGetAttrValue(dcng, "pa")); item->ft->wPort = atoi(TlenXmlGetAttrValue(dcng, "pp")); TlenBindUDPSocket(item->ft); TlenSend(info->proto, "<iq to='%s'><query xmlns='p2p'><dcng la='%s' lp='%d' pa='%s' pp='%d' i='%s' k='5' s='4'/></query></iq>", item->ft->jid, item->ft->localName, item->ft->wLocalPort, item->ft->localName, item->ft->wLocalPort, item->ft->id2); forkthread((void (__cdecl *)(void*))TlenNewFileReceiveThread, 0, item->ft); forkthread((void (__cdecl *)(void*))TlenNewFileSendThread, 0, item->ft); } } else if (!strcmp(s, "4")) { /* IP and port */ if ((item=TlenListFindItemPtrById2(info->proto, LIST_FILE, id2)) != NULL) { info->proto->debugLogA("step = 4"); item->ft->hostName = mir_strdup(TlenXmlGetAttrValue(dcng, "pa")); item->ft->wPort = atoi(TlenXmlGetAttrValue(dcng, "pp")); forkthread((void (__cdecl *)(void*))TlenNewFileReceiveThread, 0, item->ft); } } } else if (dc != NULL) { } } }
void TlenProcessPresenceAvatar(TlenProtocol *proto, XmlNode *node, TLEN_LIST_ITEM *item) { MCONTACT hContact=TlenHContactFromJID(proto, item->jid); if (hContact != NULL) TlenProcessAvatarNode(proto, TlenXmlGetChild(node, "avatar"), item); }