const char *FindVersion(int file_id, BYTE *pbVersionBytes, int cpbVersionBytes, const Category cat) { if(!doc[cat]) return 0; char version_string[128]; strncpy(version_string, (char *)pbVersionBytes, cpbVersionBytes); version_string[sizeof(version_string)-1] = 0; ezxml_t root = ezxml_get(doc[cat], "channel", 0, "item", -1); while (root) { int id = atoi(ezxml_txt(ezxml_child(root, "id"))); const char* version = ezxml_txt(ezxml_child(root, "version")); if (id == file_id && version[0]) { if (strncmp(version, (char*)pbVersionBytes, cpbVersionBytes) && VersionLess(version_string, version)) { return version; } else { return "same"; } } root = ezxml_next(root); } return 0; }
static void process_import_map(ezxml_t root, struct _import_map *import_map, const char *map_name) { ezxml_t node; for(node = ezxml_child(root, map_name); node != NULL; node = ezxml_next(node)) { const char *id = ezxml_attr(node, "id"); const char *map = ezxml_attr(node, "map"); if(id == NULL) fprintf(stderr, "WARNING: <%s /> element missing required element \"id\"; ignoring\n", map_name); else if(map == NULL) fprintf(stderr, "WARNING: <%s /> element missing required element \"map\"; ignoring\n", map_name); import_map[strtoul(id, NULL, 0)].map = (unsigned char)strtoul(map, NULL, 0); } }
int FindFileID(const char *name, const Category cat, UpdateList *update_list) { if (!doc[cat]) return -1; if (update_list) { // couldn't find it in xml file - check if a plugin gave us a file id for a different shortName for (int i = 0; i < update_list->getCount(); ++i) { UpdateInternal &ui = (*update_list)[i]; if (ui.file_id != -1 && strcmp(ui.update.szComponentName, name) == 0) return ui.file_id; } } // ignore case in name int id = -1; char *version = NULL; ezxml_t root = ezxml_get(doc[cat], "channel", 0, "item", -1); while (root) { const char* title = ezxml_txt(ezxml_child(root, "title")); if (_stricmp(title, name) == 0) { const char* subcategory = ezxml_txt(ezxml_child(root, "subcategory")); if (strcmp(subcategory, "Archived")) { int id1 = atoi(ezxml_txt(ezxml_child(root, "id"))); if (id1) { char *version1 = ezxml_txt(ezxml_child(root, "version")); if (!version || (version1 && VersionLess(version, version1))) { version = version1; id = id1; } } } } root = ezxml_next(root); } return id; }
void CMsnProto::MSN_ChatStart(ezxml_t xmli) { if (!mir_strcmp(xmli->txt, "thread")) return; // If Chat ID already exists, don'T create a new one const char *pszID = ezxml_txt(ezxml_child(xmli, "id")); GCThreadData* info = MSN_GetThreadByChatId(_A2T(pszID)); if (info == NULL) { info = new GCThreadData; { mir_cslock lck(m_csThreads); m_arGCThreads.insert(info); } MSN_ChatInit(info, pszID, ezxml_txt(ezxml_get(xmli, "properties", 0, "topic", -1))); MSN_StartStopTyping(info, false); } else { GCDEST gcd = { m_szModuleName, info->mChatID, GC_EVENT_CONTROL }; GCEVENT gce = { sizeof(gce), &gcd }; CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce); } const char *pszCreator = ezxml_txt(ezxml_get(xmli, "properties", 0, "creator", -1)); for (ezxml_t memb = ezxml_get(xmli, "members", 0, "member", -1); memb != NULL; memb = ezxml_next(memb)) { const char *mri = ezxml_txt(ezxml_child(memb, "mri")); const char *role = ezxml_txt(ezxml_child(memb, "role")); GCUserItem *gcu = NULL; for (int j = 0; j < info->mJoinedContacts.getCount(); j++) { if (!mir_strcmp(info->mJoinedContacts[j]->WLID, mri)) { gcu = info->mJoinedContacts[j]; break; } } if (!gcu) { gcu = new GCUserItem; info->mJoinedContacts.insert(gcu); strncpy(gcu->WLID, mri, sizeof(gcu->WLID)); } mir_tstrcpy(gcu->role, _A2T(role)); if (pszCreator && !mir_strcmp(mri, pszCreator)) info->mCreator = gcu; char* szEmail, *szNet; parseWLID(NEWSTR_ALLOCA(mri), &szNet, &szEmail, NULL); if (!mir_strcmpi(szEmail, GetMyUsername(atoi(szNet)))) info->mMe = gcu; gcu->btag = 1; } // Remove contacts not on list (not tagged) for (int j = 0; j < info->mJoinedContacts.getCount(); j++) { if (!info->mJoinedContacts[j]->btag) { info->mJoinedContacts.remove(j); j--; } else info->mJoinedContacts[j]->btag = 0; } }
void CMsnProto::MSN_GCProcessThreadActivity(ezxml_t xmli, const TCHAR *mChatID) { if (!mir_strcmp(xmli->name, "topicupdate")) { ezxml_t initiator = ezxml_child(xmli, "initiator"); GCDEST gcd = { m_szModuleName, mChatID, GC_EVENT_TOPIC}; GCEVENT gce = { sizeof(gce), &gcd }; gce.dwFlags = GCEF_ADDTOLOG; gce.time = MsnTSToUnixtime(ezxml_txt(ezxml_child(xmli, "eventtime"))); gce.ptszUID = initiator?mir_a2t(initiator->txt):NULL; MCONTACT hContInitiator = MSN_HContactFromEmail(initiator->txt); gce.ptszNick = GetContactNameT(hContInitiator); gce.ptszText = mir_a2t(ezxml_txt(ezxml_child(xmli, "value"))); CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); mir_free((TCHAR*)gce.ptszUID); mir_free((TCHAR*)gce.ptszText); } else if (ezxml_t target = ezxml_child(xmli, "target")) { MCONTACT hContInitiator = NULL; GCDEST gcd = { m_szModuleName, mChatID, 0}; GCEVENT gce = { sizeof(gce), &gcd }; gce.dwFlags = GCEF_ADDTOLOG; if (!mir_strcmp(xmli->name, "deletemember")) { gcd.iType = GC_EVENT_PART; if (ezxml_t initiator = ezxml_child(xmli, "initiator")) { if (mir_strcmp(initiator->txt, target->txt)) { hContInitiator = MSN_HContactFromEmail(initiator->txt); gce.ptszStatus = GetContactNameT(hContInitiator); gcd.iType = GC_EVENT_KICK; } } } else if (!mir_strcmp(xmli->name, "addmember")) { gcd.iType = GC_EVENT_JOIN; } else if (!mir_strcmp(xmli->name, "roleupdate")) { gcd.iType = GC_EVENT_ADDSTATUS; if (ezxml_t initiator = ezxml_child(xmli, "initiator")) { hContInitiator = MSN_HContactFromEmail(initiator->txt); gce.ptszText= GetContactNameT(hContInitiator); } gce.ptszStatus = _T("admin"); } if (gcd.iType) { gce.time = MsnTSToUnixtime(ezxml_txt(ezxml_child(xmli, "eventtime"))); const char *pszTarget = NULL; while (target) { switch (gcd.iType) { case GC_EVENT_JOIN: gce.ptszStatus = MSN_GCGetRole(MSN_GetThreadByChatId(mChatID), target->txt); // ..fall through.. // case GC_EVENT_KICK: case GC_EVENT_PART: pszTarget = target->txt; break; case GC_EVENT_ADDSTATUS: case GC_EVENT_REMOVESTATUS: gcd.iType = mir_strcmp(ezxml_txt(ezxml_child(target, "role")), "admin") == 0 ? GC_EVENT_ADDSTATUS : GC_EVENT_REMOVESTATUS; pszTarget = ezxml_txt(ezxml_child(target, "id")); break; } char *szEmail, *szNet; parseWLID(NEWSTR_ALLOCA(pszTarget), &szNet, &szEmail, NULL); gce.bIsMe = !mir_strcmpi(szEmail, GetMyUsername(atoi(szNet))); gce.ptszUID = mir_a2t(pszTarget); MCONTACT hContTarget = MSN_HContactFromEmail(pszTarget); gce.ptszNick = GetContactNameT(hContTarget); CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); mir_free((TCHAR*)gce.ptszUID); if ((gcd.iType == GC_EVENT_PART || gcd.iType == GC_EVENT_KICK) && gce.bIsMe) { GCDEST gcd2 = { m_szModuleName, mChatID, GC_EVENT_CONTROL }; GCEVENT gce2 = { sizeof(gce2), &gcd2 }; CallServiceSync(MS_GC_EVENT, SESSION_OFFLINE, (LPARAM)&gce2); break; } target = ezxml_next(target); } } } }
bool CMsnProto::MSN_StoreGetProfile(bool allowRecurse) { char* reqHdr; ezxml_t tbdy; ezxml_t xmlp = storeSoapHdr("GetProfile", "Initial", tbdy, reqHdr); ezxml_t prohndl = ezxml_add_child(tbdy, "profileHandle", 0); ezxml_t alias = ezxml_add_child(prohndl, "Alias", 0); ezxml_t node = ezxml_add_child(alias, "Name", 0); ezxml_set_txt(node, mycid); node = ezxml_add_child(alias, "NameSpace", 0); ezxml_set_txt(node, "MyCidStuff"); node = ezxml_add_child(prohndl, "RelationshipName", 0); ezxml_set_txt(node, "MyProfile"); ezxml_t proattr = ezxml_add_child(tbdy, "profileAttributes", 0); node = ezxml_add_child(proattr, "ResourceID", 0); ezxml_set_txt(node, "true"); node = ezxml_add_child(proattr, "DateModified", 0); ezxml_set_txt(node, "true"); ezxml_t exproattr = ezxml_add_child(proattr, "ExpressionProfileAttributes", 0); node = ezxml_add_child(exproattr, "ResourceID", 0); ezxml_set_txt(node, "true"); node = ezxml_add_child(exproattr, "DateModified", 0); ezxml_set_txt(node, "true"); node = ezxml_add_child(exproattr, "DisplayName", 0); ezxml_set_txt(node, "true"); node = ezxml_add_child(exproattr, "DisplayNameLastModified", 0); ezxml_set_txt(node, "true"); node = ezxml_add_child(exproattr, "PersonalStatus", 0); ezxml_set_txt(node, "true"); node = ezxml_add_child(exproattr, "PersonalStatusLastModified", 0); ezxml_set_txt(node, "true"); node = ezxml_add_child(exproattr, "StaticUserTilePublicURL", 0); ezxml_set_txt(node, "true"); node = ezxml_add_child(exproattr, "Photo", 0); ezxml_set_txt(node, "true"); node = ezxml_add_child(exproattr, "Flags", 0); ezxml_set_txt(node, "true"); char* szData = ezxml_toxml(xmlp, true); ezxml_free(xmlp); unsigned status = 0; char *storeUrl = NULL, *tResult = NULL; for (int k = 4; --k;) { mir_free(storeUrl); storeUrl = GetStoreHost("GetProfile"); tResult = getSslResult(&storeUrl, szData, reqHdr, status); if (tResult == NULL) UpdateStoreHost("GetProfile", NULL); else break; } mir_free(reqHdr); free(szData); if (tResult != NULL) { if (status == 200) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); ezxml_t body = getSoapResponse(xmlm, "GetProfile"); UpdateStoreHost("GetProfile", body ? storeUrl : NULL); mir_snprintf(proresid, sizeof(proresid), "%s", ezxml_txt(ezxml_child(body, "ResourceID"))); ezxml_t expr = ezxml_child(body, "ExpressionProfile"); if (expr == NULL) { MSN_StoreShareItem(proresid); MSN_SharingMyProfile(); if (allowRecurse) MSN_StoreGetProfile(false); } else { const char* szNick = ezxml_txt(ezxml_child(expr, "DisplayName")); setStringUtf(NULL, "Nick", (char*)szNick); const char* szStatus = ezxml_txt(ezxml_child(expr, "PersonalStatus")); replaceStr(msnLastStatusMsg, szStatus); mir_snprintf(expresid, sizeof(expresid), "%s", ezxml_txt(ezxml_child(expr, "ResourceID"))); ezxml_t photo = ezxml_child(expr, "Photo"); mir_snprintf(photoid, sizeof(photoid), "%s", ezxml_txt(ezxml_child(photo, "ResourceID"))); ezxml_t docstr = ezxml_get(photo, "DocumentStreams", 0, "DocumentStream", -1); while (docstr) { const char *docname = ezxml_txt(ezxml_child(docstr, "DocumentStreamName")); if (!strcmp(docname, "UserTileStatic")) { getMyAvatarFile(ezxml_txt(ezxml_child(docstr, "PreAuthURL")), _T("miranda_avatar.tmp")); break; } docstr = ezxml_next(docstr); } } ezxml_free(xmlm); } else if (status == 500 && allowRecurse) { ezxml_t xmlm = ezxml_parse_str(tResult, strlen(tResult)); const char* szErr = ezxml_txt(getSoapFault(xmlm, true)); if (strcmp(szErr, "PassportAuthFail") == 0) { MSN_GetPassportAuth(); MSN_StoreGetProfile(false); } else { MSN_StoreCreateProfile(); if (MSN_StoreGetProfile(false)) status = 200; } ezxml_free(xmlm); } else UpdateStoreHost("GetProfile", NULL); } mir_free(tResult); mir_free(storeUrl); return status == 200; }
void CMsnProto::getOIMs(ezxml_t xmli) { ezxml_t toki = ezxml_child(xmli, "M"); if (toki == NULL) return; char* getReqHdr; ezxml_t reqmsg; ezxml_t xmlreq = oimRecvHdr("GetMessage", reqmsg, getReqHdr); ezxml_t reqmid = ezxml_add_child(reqmsg, "messageId", 0); ezxml_t reqmrk = ezxml_add_child(reqmsg, "alsoMarkAsRead", 0); ezxml_set_txt(reqmrk, "false"); char* delReqHdr; ezxml_t delmsg; ezxml_t xmldel = oimRecvHdr("DeleteMessages", delmsg, delReqHdr); ezxml_t delmids = ezxml_add_child(delmsg, "messageIds", 0); while (toki != NULL) { const char* szId = ezxml_txt(ezxml_child(toki, "I")); const char* szEmail = ezxml_txt(ezxml_child(toki, "E")); ezxml_set_txt(reqmid, szId); char* szData = ezxml_toxml(xmlreq, true); unsigned status; char* url = (char*)mir_strdup(oimRecvUrl); char* tResult = getSslResult(&url, szData, getReqHdr, status); free(szData); mir_free(url); if (tResult != NULL && status == 200) { ezxml_t xmlm = ezxml_parse_str(tResult, mir_strlen(tResult)); ezxml_t body = getSoapResponse(xmlm, "GetMessage"); MimeHeaders mailInfo; const char* mailbody = mailInfo.readFromBuffer((char*)ezxml_txt(body)); time_t evtm = time(NULL); const char* arrTime = mailInfo["X-OriginalArrivalTime"]; if (arrTime != NULL) { char szTime[32], *p; txtParseParam(arrTime, "FILETIME", "[", "]", szTime, sizeof(szTime)); unsigned filetimeLo = strtoul(szTime, &p, 16); if (*p == ':') { unsigned __int64 filetime = strtoul(p + 1, &p, 16); filetime <<= 32; filetime |= filetimeLo; filetime /= 10000000; #ifndef __GNUC__ filetime -= 11644473600ui64; #else filetime -= 11644473600ull; #endif evtm = (time_t)filetime; } } PROTORECVEVENT pre = { 0 }; pre.szMessage = mailInfo.decodeMailBody((char*)mailbody); pre.timestamp = evtm; ProtoChainRecvMsg(MSN_HContactFromEmail(szEmail), &pre); mir_free(pre.szMessage); ezxml_t delmid = ezxml_add_child(delmids, "messageId", 0); ezxml_set_txt(delmid, szId); ezxml_free(xmlm); } mir_free(tResult); toki = ezxml_next(toki); } ezxml_free(xmlreq); mir_free(getReqHdr); if (ezxml_child(delmids, "messageId") != NULL) { char* szData = ezxml_toxml(xmldel, true); unsigned status; char* url = (char*)mir_strdup(oimRecvUrl); char* tResult = getSslResult(&url, szData, delReqHdr, status); mir_free(url); mir_free(tResult); free(szData); } ezxml_free(xmldel); mir_free(delReqHdr); }
/** * \return <si/> response to <si/> request */ static int xmlns_si_file_accept(struct x_bus *sess, ezxml_t __stnz) { char *str; int err; ezxml_t stream_job; ezxml_t _stnz1; ezxml_t _stnz2; char *fname, *siz; ENTER; _stnz1 = ezxml_child(__stnz, "file"); if (!_stnz1) goto ftexception; fname = (char *) ezxml_attr(_stnz1, "name"); siz = (char *) ezxml_attr(_stnz1, "size"); // get features for (_stnz2 = ezxml_get(__stnz, "feature", -1); _stnz2; _stnz2 = ezxml_next(_stnz2)) { str = (char *) ezxml_attr(_stnz2, "xmlns"); if (str && strstr(str, "feature-neg")) break; }; if (!_stnz2) goto ftexception; // find stream-method for (_stnz2 = ezxml_get(_stnz2, "x", 0, "field", -1); _stnz2; _stnz2 = ezxml_next(_stnz2)) { str = (char *) ezxml_attr(_stnz2, "var"); if (str && strstr(str, "stream-method")) break; }; if (!_stnz2) goto ftexception; // get all stream methods for (_stnz2 = ezxml_child(_stnz2, "option"); _stnz2; _stnz2 = ezxml_next(_stnz2)) { _stnz1 = ezxml_child(_stnz2, "value"); if (_stnz1) printf("STREAM: %s\n", _stnz1->txt); if (!strcmp(_stnz1->txt, XMLNS_BYTESTREAMS)) break; }; if (!_stnz2) goto ftexception; /* enter critical section */ pthread_mutex_lock(&sess->lock); // create new file transfer job _stnz2 = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1); if (!_stnz2) { _stnz2 = ezxml_child(sess->dbcore, "bytestreams"); _stnz2 = ezxml_add_child(_stnz2, "pending", 0); } err = !_stnz2->child; /* if some pending job already exists */ if (err) { stream_job = ezxml_new("job"); ezxml_set_attr(stream_job, "type", "file-transfer"); ezxml_set_attr_d(stream_job, "id", ezxml_attr(__stnz,"id")); if (ezxml_attr(__stnz, "mime-type")) ezxml_set_attr_d(stream_job, "mime-type", ezxml_attr(__stnz,"mime-type")); ezxml_set_attr_d(stream_job, "profile", ezxml_attr(__stnz,"profile")); ezxml_set_attr_d(stream_job, "name", fname); ezxml_set_attr(stream_job, "source", "remote"); ezxml_set_attr(stream_job, "src_fd", "0"); ezxml_set_attr(stream_job, "dst_fd", "0"); ezxml_set_attr(stream_job, "status", "0"); _stnz2 = ezxml_get(sess->dbcore, "bytestreams", 0, "pending", -1); ezxml_insert(stream_job, _stnz2, 0); /* leave critical section */ pthread_mutex_unlock(&sess->lock); } else { /* leave critical section */ pthread_mutex_unlock(&sess->lock); goto ftexception; } // create si response _stnz1 = ezxml_new("si"); ezxml_set_attr(_stnz1, "xmlns", XMLNS_SI); _stnz2 = ezxml_add_child(_stnz1, "feature", 0); ezxml_set_attr(_stnz2, "xmlns", XMLNS_FEATURE_NEG); _stnz2 = ezxml_add_child(_stnz2, "x", 0); ezxml_set_attr(_stnz2, "xmlns", XMLNS_X_DATA); ezxml_set_attr(_stnz2, "type", "submit"); _stnz2 = ezxml_add_child(_stnz2, "field", 0); ezxml_set_attr(_stnz2, "var", "stream-method"); _stnz2 = ezxml_add_child(_stnz2, "value", 0); ezxml_set_txt(_stnz2, XMLNS_BYTESTREAMS); EXIT; xmpp_session_reply_iq_stanza(sess,__stnz,_stnz1); return 0; ftexception: // create si response _stnz1 = ezxml_new("error"); ezxml_set_attr(_stnz1, "code", "400"); ezxml_set_attr_d(_stnz1,"type","cancel"); _stnz2 = ezxml_add_child(_stnz1, "bad-request", 0); ezxml_set_attr(_stnz2, "xmlns", XMLNS_XMPP_STANZAS); _stnz2 = ezxml_add_child(_stnz1, "no-valid-streams", 0); ezxml_set_attr(_stnz2, "xmlns", XMLNS_SI); EXIT; xmpp_session_reply_iq_stanza(sess,__stnz,_stnz1); return -1; }