summaryrefslogtreecommitdiff
path: root/updater/xmldata.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'updater/xmldata.cpp')
-rw-r--r--updater/xmldata.cpp178
1 files changed, 75 insertions, 103 deletions
diff --git a/updater/xmldata.cpp b/updater/xmldata.cpp
index 132fd7a..bffba57 100644
--- a/updater/xmldata.cpp
+++ b/updater/xmldata.cpp
@@ -5,22 +5,20 @@ const char *category_files[] = { "category_plugins", "category_localisation" };
BYTE *pData[NUM_CATEGORIES] = {0};
int dataLength[NUM_CATEGORIES] = {0};
-TiXmlDocument *doc[NUM_CATEGORIES] = {0};
+ezxml_t doc[NUM_CATEGORIES] = {0};
bool XMLDataAvailable(const Category cat) {
return (pData[cat] && dataLength[cat]);
}
void FreeXMLData(const Category cat) {
- if(pData[cat]) {
- free(pData[cat]);
- pData[cat] = 0;
- }
- if(doc[cat]) {
- delete doc[cat];
- doc[cat] = 0;
- }
- dataLength[cat] = 0;
+ free(pData[cat]);
+ pData[cat] = NULL;
+
+ ezxml_free(doc[cat]);
+ doc[cat] = NULL;
+
+ dataLength[cat] = 0;
}
bool OldXMLDataExists(const Category cat) {
@@ -121,13 +119,8 @@ bool LoadOldXMLData(const Category cat, bool update_age) {
}
if(pData[cat] && dataLength[cat]) {
- doc[cat] = new TiXmlDocument;
- doc[cat]->Parse((char *)pData[cat], 0, TIXML_DEFAULT_ENCODING);
- if(doc[cat]->Error()) {
- FreeXMLData(cat);
- return false;
- }
- return true;
+ doc[cat] = ezxml_parse_str((char*)pData[cat], dataLength[cat]);
+ return doc[cat] != NULL;
}
return false;
}
@@ -271,17 +264,18 @@ bool UpdateXMLData(const Category cat, const char *redirect_url /*= 0*/, int rec
strcpy(URL, redirect_url);
}
req.szUrl = URL;
- //req.flags = NLHRF_DUMPASTEXT; //NLHRF_SMARTREMOVEHOST | NLHRF_SMARTAUTHHEADER;
+ req.flags = NLHRF_HTTP11 | NLHRF_PERSISTENT | NLHRF_REDIRECT;
+ req.nlc = hNetlibHttp;
NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&req);
if(etag_hdr.szValue) free(etag_hdr.szValue);
if(!resp) {
+ hNetlibHttp = NULL;
int err = GetLastError();
if(err) {
TCHAR buff[512];
- _stprintf(buff, TranslateT("Failed to download XML data: "));
- int len = _tcslen(buff);
+ int len = mir_sntprintf(buff, SIZEOF(buff), TranslateT("Failed to download XML data: "));
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, err, 0, buff + len, 512 - len, 0);
ShowError(buff);
//MessageBox(0, buff + len, Translate("Updater: Error Downloading XML Data"), MB_OK | MB_ICONWARNING);
@@ -296,14 +290,17 @@ bool UpdateXMLData(const Category cat, const char *redirect_url /*= 0*/, int rec
return LoadOldXMLData(cat, false);
} else if(resp->resultCode == 304) { // 'Not Modified' response
+ hNetlibHttp = resp->nlc;
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp);
resp = 0;
#ifdef DEBUG_HTTP_POPUPS
PUShowMessage("XML Data unchanged - using local copy", SM_NOTIFY);
#endif
+
// mark data as current
return LoadOldXMLData(cat, true);
} else if(resp->resultCode >= 300 && resp->resultCode < 400) { // redirect response
+ hNetlibHttp = resp->nlc;
// get new location
bool ret = false;
for(int i = 0; i < resp->headersCount; i++) {
@@ -320,8 +317,9 @@ bool UpdateXMLData(const Category cat, const char *redirect_url /*= 0*/, int rec
return ret;
} else if(resp->resultCode != 200) {
+ hNetlibHttp = resp->nlc;
TCHAR buff[512];
- _stprintf(buff, TranslateT("Failed to download XML data - Invalid response, code %d"), resp->resultCode);
+ mir_sntprintf(buff, SIZEOF(buff), TranslateT("Failed to download XML data - Invalid response, code %d"), resp->resultCode);
ShowError(buff);
char *ts = GetAString(buff);
@@ -333,6 +331,7 @@ bool UpdateXMLData(const Category cat, const char *redirect_url /*= 0*/, int rec
}
// resp->resultCode == 200
+ hNetlibHttp = resp->nlc;
if(!bz2_decompress_xml(resp->pData, resp->dataLength, &pData[cat], &dataLength[cat])) {
ShowError(TranslateT("Failed to decompress XML data"));
@@ -356,15 +355,11 @@ bool UpdateXMLData(const Category cat, const char *redirect_url /*= 0*/, int rec
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp);
resp = 0;
- doc[cat] = new TiXmlDocument;
- doc[cat]->Parse((char *)pData[cat], 0, TIXML_DEFAULT_ENCODING);
- if(doc[cat]->Error()) {
- FreeXMLData(cat);
- return false;
- }
-
SaveXMLData(cat);
+ doc[cat] = ezxml_parse_str((char*)pData[cat], strlen((char*)pData[cat]));
+ if (!doc[cat]) return false;
+
return true;
}
@@ -377,7 +372,7 @@ bool GetXMLData(BYTE **pDat, int &dataLen, const Category cat) {
return false;
}
-bool VersionLess(char *current, char *potential) {
+bool VersionLess(const char *current, const char *potential) {
DWORD dwCur, dwPot;
if(VersionFromString(current, &dwCur) && VersionFromString(potential, &dwPot)) {
switch(options.ver_req) {
@@ -401,7 +396,7 @@ bool VersionLess(char *current, char *potential) {
return false;
}
-char *FindVersion(int file_id, BYTE *pbVersionBytes, int cpbVersionBytes, const Category cat) {
+const char *FindVersion(int file_id, BYTE *pbVersionBytes, int cpbVersionBytes, const Category cat) {
if(!doc[cat]) return 0;
@@ -409,78 +404,53 @@ char *FindVersion(int file_id, BYTE *pbVersionBytes, int cpbVersionBytes, const
strncpy(version_string, (char *)pbVersionBytes, cpbVersionBytes);
version_string[cpbVersionBytes] = 0;
- char *version;
- int id = -1;
- TiXmlElement *root = doc[cat]->RootElement();
- for(TiXmlElement *el = root->FirstChildElement()->FirstChildElement(); el; el = el->NextSiblingElement()) {
- if(strcmp(el->Value(), "item") == 0) {
- version = 0;
- for(TiXmlElement *el2 = el->FirstChildElement()->NextSiblingElement(); el2; el2 = el2->NextSiblingElement()) {
- if(strcmp(el2->Value(), "id") == 0) {
- id = atoi(el2->FirstChild()->Value());
- }
- if(strcmp(el2->Value(), "version") == 0) {
- version = _strdup(el2->FirstChild()->Value());
- }
- }
- if(id == file_id && version) {
- if(strncmp(version, (char *)pbVersionBytes, cpbVersionBytes) == 0) {
- free(version);
- return _strdup("same");
- } else {
- if(VersionLess(version_string, version)) {
- return version;
- } else {
- free(version);
- return _strdup("same");
- }
- }
- } else
- if(version) free(version);
- }
- }
+ 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;
}
int FindFileID(const char *name, const Category cat, UpdateList *update_list) {
- if(!doc[cat]) return -1;
+ if (!doc[cat]) return -1;
// ignore case in name
- char *lowname = _strdup(name); strlwr(lowname);
-
- const char *fl_name;
- char *namelwr;
int id = -1;
- TiXmlElement *root = doc[cat]->RootElement();
- for(TiXmlElement *el = root->FirstChildElement("channel")->FirstChildElement("item"); el; el = el->NextSiblingElement("item")) {
- if(strcmp(el->Value(), "item") == 0) {
- fl_name = el->FirstChildElement("title")->FirstChild()->Value();
- namelwr = _strdup(fl_name); strlwr(namelwr);
- if(strcmp(lowname, namelwr) == 0) {
- for(TiXmlElement *el2 = el->FirstChildElement()->NextSiblingElement(); el2; el2 = el2->NextSiblingElement()) {
- if(strcmp(el2->Value(), "id") == 0) {
- id = atoi(el2->FirstChild()->Value());
- } else if(strcmp(el2->Value(), "subcategory") == 0 && strcmp(el2->FirstChild()->Value(), "Archived") == 0) {
- id = -1; // this is an archived release with the same name - skip
- break;
- }
- }
- }
- free(namelwr);
- if(id != -1) break; // we found a non-archived release
- }
- }
-
- free(lowname);
-
- if(id == -1 && update_list) {
+ 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")) {
+ id = atoi(ezxml_txt(ezxml_child(root, "id")));
+ if (id) break; else id = -1;
+ }
+ }
+ root = ezxml_next(root);
+ }
+
+ if(id == -1 && update_list)
+ {
// couldn't find it in xml file - check if a plugin gave us a file id for a different shortName
- for(update_list->reset(); update_list->current(); update_list->next()) {
- if(update_list->current()->file_id != -1 && strcmp(update_list->current()->update.szComponentName, name) == 0) {
- id = update_list->current()->file_id;
+ for (int i = 0; i < update_list->getCount(); ++i)
+ {
+ if ((*update_list)[i].file_id != -1 && strcmp((*update_list)[i].update.szComponentName, name) == 0)
+ {
+ id = (*update_list)[i].file_id;
break;
}
}
@@ -489,22 +459,24 @@ int FindFileID(const char *name, const Category cat, UpdateList *update_list) {
return id;
}
-void UpdateFLIDs(UpdateList &update_list) {
- for(update_list.reset(); update_list.current(); update_list.next()) {
- if(update_list.current()->file_id == -1 && update_list.current()->update.szUpdateURL && strcmp(update_list.current()->update.szUpdateURL, UPDATER_AUTOREGISTER) == 0) {
- int file_id = FindFileID(update_list.current()->update.szComponentName, MC_PLUGINS, 0);
+void UpdateFLIDs(UpdateList &update_list)
+{
+ for (int i = 0; i < update_list.getCount(); ++i)
+ {
+ if(update_list[i].file_id == -1 && update_list[i].update.szUpdateURL && strcmp(update_list[i].update.szUpdateURL, UPDATER_AUTOREGISTER) == 0) {
+ int file_id = FindFileID(update_list[i].update.szComponentName, MC_PLUGINS, 0);
if(file_id == -1)
- file_id = FindFileID(update_list.current()->update.szComponentName, MC_LOCALIZATION, 0);
+ file_id = FindFileID(update_list[i].update.szComponentName, MC_LOCALIZATION, 0);
if(file_id != -1) {
- update_list.current()->file_id = file_id;
- char *buff = (char *)safe_alloc(strlen(MIM_DOWNLOAD_URL_PREFIX) + 9);
+ update_list[i].file_id = file_id;
+ char *buff = (char *)safe_alloc((int)strlen(MIM_DOWNLOAD_URL_PREFIX) + 9);
sprintf(buff, MIM_DOWNLOAD_URL_PREFIX "%d", file_id);
- update_list.current()->update.szUpdateURL = buff;
- update_list.current()->shortName = safe_strdup(update_list.current()->update.szComponentName);
+ update_list[i].update.szUpdateURL = buff;
+ update_list[i].shortName = safe_strdup(update_list[i].update.szComponentName);
- if(update_list.current()->update.szBetaVersionURL) {
- update_list.current()->update_options.fixed = false;
- LoadUpdateOptions(update_list.current()->update.szComponentName, &update_list.current()->update_options);
+ if(update_list[i].update.szBetaVersionURL) {
+ update_list[i].update_options.fixed = false;
+ LoadUpdateOptions(update_list[i].update.szComponentName, &update_list[i].update_options);
}
}
}