diff options
author | George Hazan <ghazan@miranda.im> | 2019-02-14 15:47:40 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-02-14 15:47:40 +0300 |
commit | f682bca52b2b1811a823eeac9768f00e850908e7 (patch) | |
tree | 9381e55c23172a9aed0aed36b1b8e9ea6fcaea7d | |
parent | 8368f365becd8668dbce2e40cecc7ba4f882f41b (diff) |
UserInfoEx:
- xml iterators;
- mad code fixing
-rw-r--r-- | plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp | 181 | ||||
-rw-r--r-- | plugins/UserInfoEx/src/ex_import/classExImContactXML.h | 24 | ||||
-rw-r--r-- | plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp | 41 | ||||
-rw-r--r-- | plugins/UserInfoEx/src/ex_import/svc_ExImXML.h | 6 |
4 files changed, 116 insertions, 136 deletions
diff --git a/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp b/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp index c1d0d624cd..82cefe4a85 100644 --- a/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp +++ b/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp @@ -49,7 +49,7 @@ static int SortProc(const LPDWORD item1, const LPDWORD item2) CExImContactXML::CExImContactXML(CFileXml *pXmlFile)
: CExImContactBase()
{
- _xmlNode = nullptr;
+ _xmlReader = nullptr;
_pXmlFile = pXmlFile;
_hEvent = NULL;
}
@@ -84,7 +84,7 @@ BYTE CExImContactXML::IsContactInfo(LPCSTR pszKey) char buf[MAXSETTING];
// convert to hash and make bsearch as it is much faster then working with strings
const DWORD dwHash = mir_hashstr(_strlwr(mir_strncpy(buf, pszKey, _countof(buf))));
- return bsearch(&dwHash, dwCiHash, _countof(dwCiHash), sizeof(dwCiHash[0]), (int (*)(const void*, const void*))SortProc) != nullptr;
+ return bsearch(&dwHash, dwCiHash, _countof(dwCiHash), sizeof(dwCiHash[0]), (int(*)(const void*, const void*))SortProc) != nullptr;
}
return FALSE;
}
@@ -106,33 +106,33 @@ TiXmlElement* CExImContactXML::CreateXmlElement() {
if (_hContact) {
if (_pszProto) {
- _xmlDoc.InsertEndChild(_xmlNode = _xmlDoc.NewElement(XKEY_CONTACT));
+ _xmlDoc.InsertEndChild(_xmlWriter = _xmlDoc.NewElement(XKEY_CONTACT));
LPSTR pszUID = uid2String(TRUE);
- _xmlNode->SetAttribute("ampro", _pszAMPro);
- _xmlNode->SetAttribute("proto", _pszProto);
+ _xmlWriter->SetAttribute("ampro", _pszAMPro);
+ _xmlWriter->SetAttribute("proto", _pszProto);
- if (_pszDisp) _xmlNode->SetAttribute("disp", _pszDisp);
- if (_pszNick) _xmlNode->SetAttribute("nick", _pszNick);
- if (_pszGroup) _xmlNode->SetAttribute("group", _pszGroup);
+ if (_pszDisp) _xmlWriter->SetAttribute("disp", _pszDisp);
+ if (_pszNick) _xmlWriter->SetAttribute("nick", _pszNick);
+ if (_pszGroup) _xmlWriter->SetAttribute("group", _pszGroup);
if (pszUID) {
if (_pszUIDKey) {
- _xmlNode->SetAttribute("uidk", _pszUIDKey);
- _xmlNode->SetAttribute("uidv", pszUID);
+ _xmlWriter->SetAttribute("uidk", _pszUIDKey);
+ _xmlWriter->SetAttribute("uidv", pszUID);
}
else {
- _xmlNode->SetAttribute("uidk", "#NV");
- _xmlNode->SetAttribute("uidv", "UNLOADED");
+ _xmlWriter->SetAttribute("uidk", "#NV");
+ _xmlWriter->SetAttribute("uidv", "UNLOADED");
}
mir_free(pszUID);
}
}
- else _xmlNode = nullptr;
+ else _xmlWriter = nullptr;
}
- else _xmlDoc.InsertEndChild(_xmlNode = _xmlDoc.NewElement(XKEY_OWNER));
+ else _xmlDoc.InsertEndChild(_xmlWriter = _xmlDoc.NewElement(XKEY_OWNER));
- return _xmlNode;
+ return _xmlWriter;
}
/**
@@ -174,11 +174,11 @@ int CExImContactXML::ExportContact(DB::CEnumList* pModules) int CExImContactXML::ExportSubContact(CExImContactXML *vMetaContact, DB::CEnumList* pModules)
{
// create xmlNode
- if (!CreateXmlElement())
+ if (!CreateXmlElement())
return ERROR_INVALID_CONTACT;
- if (ExportContact(pModules) == ERROR_OK)
- if (!_xmlNode->NoChildren() && vMetaContact->_xmlNode->LinkEndChild(_xmlNode))
+ if (ExportContact(pModules) == ERROR_OK)
+ if (!_xmlWriter->NoChildren() && vMetaContact->_xmlWriter->LinkEndChild(_xmlWriter))
return ERROR_OK;
return ERROR_NOT_ADDED;
@@ -195,13 +195,13 @@ int CExImContactXML::ExportSubContact(CExImContactXML *vMetaContact, DB::CEnumLi int CExImContactXML::Export(FILE *xmlfile, DB::CEnumList* pModules)
{
- if (!xmlfile)
+ if (!xmlfile)
return ERROR_INVALID_PARAMS;
if (_hContact == INVALID_CONTACT_ID)
return ERROR_INVALID_CONTACT;
- if (!CreateXmlElement())
+ if (!CreateXmlElement())
return ERROR_INVALID_CONTACT;
// export meta
@@ -227,8 +227,8 @@ int CExImContactXML::Export(FILE *xmlfile, DB::CEnumList* pModules) ExportContact(pModules);
// add xContact to document
- if (_xmlNode->NoChildren()) {
- _xmlNode = nullptr;
+ if (_xmlWriter->NoChildren()) {
+ _xmlWriter = nullptr;
_xmlDoc.Clear();
return ERROR_NOT_ADDED;
}
@@ -237,7 +237,7 @@ int CExImContactXML::Export(FILE *xmlfile, DB::CEnumList* pModules) _xmlDoc.Print(&printer);
fputc('\n', xmlfile);
- _xmlNode = nullptr;
+ _xmlWriter = nullptr;
_xmlDoc.Clear();
return ERROR_OK;
@@ -266,7 +266,7 @@ int CExImContactXML::ExportModule(LPCSTR pszModule) for (auto &it : Settings)
ExportSetting(xmod, pszModule, it);
- if (!xmod->NoChildren() && _xmlNode->LinkEndChild(xmod))
+ if (!xmod->NoChildren() && _xmlWriter->LinkEndChild(xmod))
return ERROR_OK;
}
@@ -346,8 +346,8 @@ int CExImContactXML::ExportSetting(TiXmlElement *xmlModule, LPCSTR pszModule, LP str = (LPSTR)mir_alloc(baselen + 6);
assert(str != nullptr);
// encode data
- if (mir_base64_encodebuf(dbv.pbVal, dbv.cpbVal, str+1, baselen)) {
- str[baselen+1] = 0;
+ if (mir_base64_encodebuf(dbv.pbVal, dbv.cpbVal, str + 1, baselen)) {
+ str[baselen + 1] = 0;
str[0] = 'n';
xmlValue = _xmlDoc.NewText(str);
}
@@ -408,17 +408,18 @@ BYTE CExImContactXML::ExportEvents() xmlEvent->LinkEndChild(xmlText);
// find module
- TiXmlNode *xmlModule;
- for (xmlModule = _xmlNode->FirstChild(); xmlModule != nullptr; xmlModule = xmlModule->NextSibling())
- if (!mir_strcmpi(((TiXmlElement*)xmlModule)->Attribute("key"), dbei.szModule))
+ TiXmlElement *xmlModule = nullptr;
+ for (auto *it : TiXmlEnum(xmlModule))
+ if (!mir_strcmpi(it->Attribute("key"), dbei.szModule)) {
+ xmlModule = (TiXmlElement*)it;
break;
+ }
// create new module
if (!xmlModule) {
- xmlModule = _xmlNode->InsertEndChild(_xmlDoc.NewElement(XKEY_MOD));
- if (!xmlModule)
- break;
- ((TiXmlElement*)xmlModule)->SetAttribute("key", dbei.szModule);
+ xmlModule = _xmlDoc.NewElement(XKEY_MOD);
+ xmlModule->SetAttribute("key", dbei.szModule);
+ _xmlWriter->InsertEndChild(xmlModule);
}
xmlModule->LinkEndChild(xmlEvent);
@@ -446,10 +447,8 @@ void CExImContactXML::CountKeys(DWORD &numSettings, DWORD &numEvents) {
numSettings = numEvents = 0;
- for (TiXmlNode *xmod = _xmlNode->FirstChild(); xmod != nullptr; xmod = xmod->NextSiblingElement(XKEY_MOD)) {
- for (TiXmlNode *xkey = xmod->FirstChild();
- xkey != nullptr;
- xkey = xkey->NextSibling()) {
+ for (auto *xmod : TiXmlFilter(_xmlReader, XKEY_MOD)) {
+ for (auto *xkey : TiXmlEnum(xmod)) {
if (!mir_strcmpi(xkey->Value(), XKEY_SET))
numSettings++;
else
@@ -466,7 +465,7 @@ void CExImContactXML::CountKeys(DWORD &numSettings, DWORD &numEvents) * return: ERROR_OK if successful or any other error number otherwise
**/
-int CExImContactXML::LoadXmlElemnt(TiXmlElement *xContact)
+int CExImContactXML::LoadXmlElement(const TiXmlElement *xContact)
{
if (xContact == nullptr)
return ERROR_INVALID_PARAMS;
@@ -475,10 +474,10 @@ int CExImContactXML::LoadXmlElemnt(TiXmlElement *xContact) db_free(&_dbvUID);
_hContact = INVALID_CONTACT_ID;
- _xmlNode = xContact;
+ _xmlReader = xContact;
MIR_FREE(_pszAMPro); ampro(xContact->Attribute("ampro"));
- MIR_FREE(_pszNick); nick (xContact->Attribute("nick"));
- MIR_FREE(_pszDisp); disp (xContact->Attribute("disp"));
+ MIR_FREE(_pszNick); nick(xContact->Attribute("nick"));
+ MIR_FREE(_pszDisp); disp(xContact->Attribute("disp"));
MIR_FREE(_pszGroup); group(xContact->Attribute("group"));
MIR_FREE(_pszProto);
MIR_FREE(_pszProtoOld);
@@ -486,14 +485,13 @@ int CExImContactXML::LoadXmlElemnt(TiXmlElement *xContact) // is contact a metacontact
if (_pszAMPro && !mir_strcmp(_pszAMPro, META_PROTO)) {
- TiXmlElement *xSub;
proto(META_PROTO);
// meta contact must be uniquelly identified by its subcontacts
// the metaID may change during an export or import call
- for(xSub = xContact->FirstChildElement(XKEY_CONTACT); xSub != nullptr; xSub = xSub->NextSiblingElement(XKEY_CONTACT)) {
+ for (auto *xSub : TiXmlFilter(xContact, XKEY_CONTACT)) {
CExImContactXML vSub(_pXmlFile);
- if (vSub = xSub) {
+ if (vSub.LoadXmlElement(xSub) == ERROR_OK) {
// identify metacontact by the first valid subcontact in xmlfile
if (_hContact == INVALID_CONTACT_ID && vSub.handle() != INVALID_CONTACT_ID) {
MCONTACT hMeta = db_mc_getMeta(vSub.handle());
@@ -510,13 +508,13 @@ int CExImContactXML::LoadXmlElemnt(TiXmlElement *xContact) // entry is a default contact
else {
proto(xContact->Attribute("proto"));
- uidk (xContact->Attribute("uidk"));
+ uidk(xContact->Attribute("uidk"));
if (!_pszProto) {
// check if this is the owner contact
if (mir_strcmpi(xContact->Value(), XKEY_OWNER))
return ERROR_INVALID_PARAMS;
_hContact = NULL;
- _xmlNode = xContact;
+ _xmlReader = xContact;
return ERROR_OK;
}
@@ -584,14 +582,14 @@ int CExImContactXML::ImportContact() _pXmlFile->_numEventsTodo += numEvents;
// import all modules
- for (TiXmlNode *xmod = _xmlNode->FirstChild(); xmod != nullptr; xmod = xmod->NextSiblingElement(XKEY_MOD)) {
+ for (auto *xmod : TiXmlFilter(_xmlReader, XKEY_MOD)) {
// import module
if (ImportModule(xmod) == ERROR_ABORTED) {
// ask to delete new incomplete contact
if (_isNewContact && _hContact != NULL) {
- int result = MsgBox(nullptr, MB_YESNO|MB_ICONWARNING,
- LPGENW("Question"),
- LPGENW("Importing a new contact was aborted!"),
+ int result = MsgBox(nullptr, MB_YESNO | MB_ICONWARNING,
+ LPGENW("Question"),
+ LPGENW("Importing a new contact was aborted!"),
LPGENW("You aborted import of a new contact.\nSome information may be missing for this contact.\n\nDo you want to delete the incomplete contact?"));
if (result == IDYES) {
db_delete_contact(_hContact);
@@ -640,7 +638,7 @@ int CExImContactXML::ImportNormalContact() int CExImContactXML::Import(BYTE keepMetaSubContact)
{
// xml contact contains subcontacts?
- TiXmlElement *xContact = _xmlNode->FirstChildElement("CONTACT");
+ const TiXmlElement *xContact = _xmlReader->FirstChildElement("CONTACT");
if (xContact) {
// contact is a metacontact and metacontacts plugin is installed?
if (isMeta()) {
@@ -650,7 +648,7 @@ int CExImContactXML::Import(BYTE keepMetaSubContact) // the contact does not yet exist
if (_isNewContact) {
// import default contact as normal contact and convert to meta contact
- if (!(vContact = xContact))
+ if (vContact.LoadXmlElement(xContact) != ERROR_OK)
return ERROR_CONVERT_METACONTACT;
// import as normal contact
@@ -674,24 +672,26 @@ int CExImContactXML::Import(BYTE keepMetaSubContact) // load all subcontacts
do {
// update progressbar and abort if user clicked cancel
- int result = _pXmlFile->_progress.UpdateContact(L"Sub Contact: %s (%S)",
+ int result = _pXmlFile->_progress.UpdateContact(L"Sub Contact: %s (%S)",
ptrW(mir_utf8decodeW(xContact->Attribute("nick"))), xContact->Attribute("proto"));
-
+
// user clicked abort button
- if (!result) break;
- if (vContact = xContact) {
+ if (!result)
+ break;
+
+ if (vContact.LoadXmlElement(xContact) == ERROR_OK) {
if (vContact.ImportMetaSubContact(this) == ERROR_ABORTED)
return ERROR_ABORTED;
_pXmlFile->_numContactsDone++;
}
}
- while (xContact = xContact->NextSiblingElement("CONTACT"));
+ while (xContact = xContact->NextSiblingElement("CONTACT"));
}
// load metacontact information (after subcontact for faster import)
return ImportContact();
}
// import sub contacts as normal contacts
- return _pXmlFile->ImportContacts(_xmlNode);
+ return _pXmlFile->ImportContacts(_xmlReader);
}
// load contact information
@@ -709,7 +709,7 @@ int CExImContactXML::Import(BYTE keepMetaSubContact) * all information from the xmlNode to database.
* Add this contact to an meta contact
* param: pMetaContact - the meta contact to add this one to
-* return:
+* return:
**/
int CExImContactXML::ImportMetaSubContact(CExImContactXML * pMetaContact)
@@ -728,9 +728,9 @@ int CExImContactXML::ImportMetaSubContact(CExImContactXML * pMetaContact) if (_isNewContact && _hContact != NULL) {
LPTSTR ptszNick = mir_utf8decodeW(_pszNick);
LPTSTR ptszMetaNick = mir_utf8decodeW(pMetaContact->_pszNick);
- int result = MsgBox(nullptr, MB_YESNO|MB_ICONWARNING,
- LPGENW("Question"),
- LPGENW("Importing a new meta subcontact failed!"),
+ int result = MsgBox(nullptr, MB_YESNO | MB_ICONWARNING,
+ LPGENW("Question"),
+ LPGENW("Importing a new meta subcontact failed!"),
LPGENW("The newly created meta subcontact '%s'\ncould not be added to metacontact '%s'!\n\nDo you want to delete this contact?"),
ptszNick, ptszMetaNick);
MIR_FREE(ptszNick);
@@ -756,27 +756,18 @@ int CExImContactXML::ImportMetaSubContact(CExImContactXML * pMetaContact) * return: ERROR_OK on success or one other element of ImportError to tell the type of failure
**/
-int CExImContactXML::ImportModule(TiXmlNode* xmlModule)
+int CExImContactXML::ImportModule(const TiXmlElement *xmlModule)
{
- // check if parent is really a module
- if (!xmlModule || mir_strcmpi(xmlModule->Value(), XKEY_MOD))
- return ERROR_INVALID_SIGNATURE;
-
- // convert to element
- TiXmlElement *xMod = xmlModule->ToElement();
- if (!xMod)
- return ERROR_INVALID_PARAMS;
-
// get module name
- LPCSTR pszModule = xMod->Attribute("key");
+ LPCSTR pszModule = xmlModule->Attribute("key");
if (!pszModule || !*pszModule)
return ERROR_INVALID_PARAMS;
// ignore Modul 'Protocol' as it would cause trouble
if (!mir_strcmpi(pszModule, "Protocol"))
return ERROR_OK;
-
- for (TiXmlElement *xKey = xmlModule->FirstChildElement(); xKey != nullptr; xKey = xKey->NextSiblingElement()) {
+
+ for (auto *xKey : TiXmlEnum(xmlModule)) {
// import setting
if (!mir_strcmpi(xKey->Value(), XKEY_SET)) {
// check if the module to import is the contact's protocol module
@@ -789,23 +780,22 @@ int CExImContactXML::ImportModule(TiXmlNode* xmlModule) // just ignore MetaModule on Meta to avoid errors (only import spetial keys)
if (isProtoModule && isMetaModule) {
- if (!mir_strcmpi(xKey->Attribute("key"),"Nick") ||
- !mir_strcmpi(xKey->Attribute("key"),"TzName") ||
- !mir_strcmpi(xKey->Attribute("key"),"Timezone"))
- {
- if (ImportSetting(pszModule, xKey->ToElement()) == ERROR_OK)
+ if (!mir_strcmpi(xKey->Attribute("key"), "Nick") ||
+ !mir_strcmpi(xKey->Attribute("key"), "TzName") ||
+ !mir_strcmpi(xKey->Attribute("key"), "Timezone")) {
+ if (ImportSetting(pszModule, xKey) == ERROR_OK)
_pXmlFile->_numSettingsDone++;
}
}
// just ignore some settings of protocol module to avoid errors (only keys)
else if (isProtoModule && !isMetaModule) {
if (!IsContactInfo(xKey->Attribute("key"))) {
- if (ImportSetting(pszModule, xKey->ToElement()) == ERROR_OK)
+ if (ImportSetting(pszModule, xKey) == ERROR_OK)
_pXmlFile->_numSettingsDone++;
}
}
// other module
- else if (ImportSetting(pszModule, xKey->ToElement()) == ERROR_OK) {
+ else if (ImportSetting(pszModule, xKey) == ERROR_OK) {
_pXmlFile->_numSettingsDone++;
}
if (!_pXmlFile->_progress.UpdateSetting(LPGENW("Settings: %S"), pszModule))
@@ -813,7 +803,7 @@ int CExImContactXML::ImportModule(TiXmlNode* xmlModule) }
// import event
else if (!mir_strcmpi(xKey->Value(), XKEY_EVT)) {
- int error = ImportEvent(pszModule, xKey->ToElement());
+ int error = ImportEvent(pszModule, xKey);
switch (error) {
case ERROR_OK:
_pXmlFile->_numEventsDone++;
@@ -838,22 +828,20 @@ int CExImContactXML::ImportModule(TiXmlNode* xmlModule) * return: ERROR_OK on success or one other element of ImportError to tell the type of failure
**/
-int CExImContactXML::ImportSetting(LPCSTR pszModule, TiXmlElement *xmlEntry)
+int CExImContactXML::ImportSetting(LPCSTR pszModule, const TiXmlElement *xmlEntry)
{
// validate parameter
if (!xmlEntry || !pszModule || !*pszModule)
return ERROR_INVALID_PARAMS;
// validate value
- TiXmlText* xval = (TiXmlText*)xmlEntry->FirstChild();
- if (!xval || xval->ToText() == nullptr)
+ LPCSTR value = xmlEntry->GetText();
+ if (!value)
return ERROR_INVALID_VALUE;
- LPCSTR value = xval->Value();
- DBVARIANT dbv = { 0 };
-
// convert data
size_t baselen;
+ DBVARIANT dbv = { 0 };
switch (value[0]) {
case 'b': //'b' bVal and cVal are valid
@@ -913,7 +901,7 @@ int CExImContactXML::ImportSetting(LPCSTR pszModule, TiXmlElement *xmlEntry) * return: ERROR_OK on success or one other element of ImportError to tell the type of failure
**/
-int CExImContactXML::ImportEvent(LPCSTR pszModule, TiXmlElement *xmlEvent)
+int CExImContactXML::ImportEvent(LPCSTR pszModule, const TiXmlElement *xmlEvent)
{
// dont import events from metacontact
if (isMeta())
@@ -927,15 +915,11 @@ int CExImContactXML::ImportEvent(LPCSTR pszModule, TiXmlElement *xmlEvent) // timestamp must be valid
DBEVENTINFO dbei = {};
- xmlEvent->SetAttribute("time", (LPINT)&dbei.timestamp);
+ dbei.timestamp = xmlEvent->IntAttribute("time");
if (dbei.timestamp == 0)
return ERROR_INVALID_TIMESTAMP;
- TiXmlText *xmlValue = (TiXmlText*)xmlEvent->FirstChild();
- if (!xmlValue || xmlValue->ToText() == nullptr)
- return ERROR_INVALID_VALUE;
-
- LPCSTR tmp = xmlValue->Value();
+ LPCSTR tmp = xmlEvent->GetText();
if (!tmp || tmp[0] == 0)
return ERROR_INVALID_VALUE;
@@ -946,9 +930,8 @@ int CExImContactXML::ImportEvent(LPCSTR pszModule, TiXmlElement *xmlEvent) dbei.pBlob = tmpVal;
dbei.cbBlob = (WORD)baselen;
dbei.szModule = (LPSTR)pszModule;
-
- xmlEvent->SetAttribute("type", (LPINT)&dbei.eventType);
- xmlEvent->SetAttribute("flag", (LPINT)&dbei.flags);
+ dbei.eventType = xmlEvent->IntAttribute("type");
+ dbei.flags = xmlEvent->IntAttribute("flag");
if (dbei.flags == 0)
dbei.flags = DBEF_READ;
diff --git a/plugins/UserInfoEx/src/ex_import/classExImContactXML.h b/plugins/UserInfoEx/src/ex_import/classExImContactXML.h index 29c92a3e6e..72a98ad869 100644 --- a/plugins/UserInfoEx/src/ex_import/classExImContactXML.h +++ b/plugins/UserInfoEx/src/ex_import/classExImContactXML.h @@ -47,17 +47,21 @@ enum EError { class CExImContactXML : public CExImContactBase
{
- CFileXml *_pXmlFile; // the xmlfile
- TiXmlDocument _xmlDoc;
- TiXmlElement *_xmlNode; // xmlnode with contact information
- MEVENT _hEvent;
+ CFileXml *_pXmlFile; // the xmlfile
+ TiXmlDocument _xmlDoc; // whole document in memory
+ union {
+ TiXmlElement *_xmlWriter; // xml node being prepared for export
+ const TiXmlElement *_xmlReader; // xml node being used for import
+ };
+
+ MEVENT _hEvent;
BYTE IsContactInfo(LPCSTR pszKey);
// private importing methods
- int ImportModule(TiXmlNode* xmlModule);
- int ImportSetting(LPCSTR pszModule, TiXmlElement *xmlEntry);
- int ImportEvent(LPCSTR pszModule, TiXmlElement *xmlEvent);
+ int ImportModule(const TiXmlElement *xmlModule);
+ int ImportSetting(LPCSTR pszModule, const TiXmlElement *xmlEntry);
+ int ImportEvent(LPCSTR pszModule, const TiXmlElement *xmlEvent);
int ImportContact();
int ImportNormalContact();
int ImportMetaSubContact(CExImContactXML * pMetaContact);
@@ -79,12 +83,8 @@ public: int Export(FILE *xmlfile, DB::CEnumList* pModules);
// importing stuff
- int LoadXmlElemnt(TiXmlElement *xContact);
+ int LoadXmlElement(const TiXmlElement *xContact);
int Import(BYTE keepMetaSubContact = FALSE);
-
- BYTE operator=(TiXmlElement* xmlContact) {
- return LoadXmlElemnt(xmlContact) == ERROR_OK;
- }
};
#endif /* _CLASS_EXIM_CONTACT_XML_INCLUDED_ */
diff --git a/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp b/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp index 196daf6230..67344160c0 100644 --- a/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp +++ b/plugins/UserInfoEx/src/ex_import/svc_ExImXML.cpp @@ -90,12 +90,10 @@ int CFileXml::Export(lpExImParam ExImContact, LPCSTR pszFileName) {
DB::CEnumList Modules;
- DWORD result = (DWORD)DialogBox(g_plugin.getInst(),
- MAKEINTRESOURCE(IDD_EXPORT_DATAHISTORY),
- nullptr, DlgProc_DataHistory);
- if (LOWORD(result) != IDOK) {
+ DWORD result = (DWORD)DialogBox(g_plugin.getInst(), MAKEINTRESOURCE(IDD_EXPORT_DATAHISTORY), nullptr, DlgProc_DataHistory);
+ if (LOWORD(result) != IDOK)
return 0;
- }
+
_wExport = HIWORD(result);
// show dialog to enable user to select modules for export
@@ -126,18 +124,17 @@ int CFileXml::Export(lpExImParam ExImContact, LPCSTR pszFileName) if (ExImContact->Typ == EXIM_CONTACT) {
// export single contact
_hContactToWorkOn = ExImContact->hContact;
- if (vContact.fromDB(ExImContact->hContact)) {
+ if (vContact.fromDB(ExImContact->hContact))
vContact.Export(xmlfile, &Modules);
- }
}
else {
// other export mode
_hContactToWorkOn = INVALID_CONTACT_ID;
// export owner contact
- if (ExImContact->Typ == EXIM_ALL && vContact.fromDB(NULL)) {
+ if (ExImContact->Typ == EXIM_ALL && vContact.fromDB(NULL))
vContact.Export(xmlfile, &Modules);
- }
+
// loop for all other contact
for (MCONTACT hContact = db_find_first(); hContact != NULL; hContact = db_find_next(hContact)) {
switch (ExImContact->Typ) {
@@ -169,7 +166,7 @@ int CFileXml::Export(lpExImParam ExImContact, LPCSTR pszFileName) }
break;
}
- } // *end for
+ }
}
// *end other export mode
@@ -185,7 +182,6 @@ int CFileXml::Export(lpExImParam ExImContact, LPCSTR pszFileName) return 0;
}
-
/***********************************************************************************************************
* importing stuff
***********************************************************************************************************/
@@ -211,11 +207,11 @@ CFileXml::CFileXml() * stat - structure used to collect some statistics
* return: ERROR_OK on success or one other element of ImportError to tell the type of failure
**/
-int CFileXml::ImportOwner(TiXmlElement* xContact)
+
+int CFileXml::ImportOwner(const TiXmlElement* xContact)
{
CExImContactXML vContact(this);
-
- if (vContact = xContact) {
+ if (vContact.LoadXmlElement(xContact) == ERROR_OK) {
vContact.Import();
return ERROR_OK;
}
@@ -230,18 +226,19 @@ int CFileXml::ImportOwner(TiXmlElement* xContact) * stat - structure used to collect some statistics
* return: ERROR_OK if at least one contact was successfully imported
**/
-int CFileXml::ImportContacts(TiXmlElement* xmlParent)
+
+int CFileXml::ImportContacts(const TiXmlElement *xmlParent)
{
CExImContactXML vContact(this);
// import contacts
- for (TiXmlElement *xContact = xmlParent->FirstChildElement(); xContact != nullptr; xContact = xContact->NextSiblingElement()) {
+ for (auto *xContact : TiXmlEnum(xmlParent)) {
if (!mir_strcmpi(xContact->Value(), XKEY_CONTACT)) {
// update progressbar and abort if user clicked cancel
LPTSTR pszNick = mir_utf8decodeW(xContact->Attribute("nick"));
// user clicked abort button
if (_progress.UpdateContact(LPGENW("Contact: %s (%S)"), pszNick, xContact->Attribute("proto"))) {
- int result = vContact.LoadXmlElemnt(xContact);
+ int result = vContact.LoadXmlElement(xContact);
switch (result) {
case ERROR_OK:
// init contact class and import if matches the user desires
@@ -265,7 +262,7 @@ int CFileXml::ImportContacts(TiXmlElement* xmlParent) if (pszNick) mir_free(pszNick);
}
// import owner contact
- else if (_hContactToWorkOn == INVALID_CONTACT_ID && !mir_strcmpi(xContact->Value(), XKEY_OWNER) && (vContact = xContact)) {
+ else if (_hContactToWorkOn == INVALID_CONTACT_ID && !mir_strcmpi(xContact->Value(), XKEY_OWNER) && vContact.LoadXmlElement(xContact) == ERROR_OK) {
int result = vContact.Import();
switch (result) {
case ERROR_OK:
@@ -285,13 +282,13 @@ int CFileXml::ImportContacts(TiXmlElement* xmlParent) * params: xContact - the contact, who is the owner of the keys to count
* return: nothing
**/
-DWORD CFileXml::CountContacts(TiXmlElement* xmlParent)
+DWORD CFileXml::CountContacts(const TiXmlElement *xmlParent)
{
DWORD dwCount = 0;
// count contacts in file for progress bar
- for (TiXmlNode *xContact = xmlParent->FirstChild(); xContact != nullptr; xContact = xContact->NextSibling())
- if (!mir_strcmpi(xContact->Value(), XKEY_CONTACT) || !mir_strcmpi(xContact->Value(), XKEY_OWNER))
- dwCount += CountContacts(xContact->ToElement()) + 1;
+ for (auto *xContact : TiXmlEnum(xmlParent))
+ if (!mir_strcmpi(xContact->Name(), XKEY_CONTACT) || !mir_strcmpi(xContact->Name(), XKEY_OWNER))
+ dwCount += CountContacts(xContact) + 1;
return dwCount;
}
diff --git a/plugins/UserInfoEx/src/ex_import/svc_ExImXML.h b/plugins/UserInfoEx/src/ex_import/svc_ExImXML.h index 21a5c502e5..47f9392caa 100644 --- a/plugins/UserInfoEx/src/ex_import/svc_ExImXML.h +++ b/plugins/UserInfoEx/src/ex_import/svc_ExImXML.h @@ -43,10 +43,10 @@ class CFileXml { CProgress _progress;
- int ImportOwner(TiXmlElement* xmlContact);
- int ImportContacts(TiXmlElement* xmlParent);
+ int ImportOwner(const TiXmlElement* xmlContact);
+ int ImportContacts(const TiXmlElement* xmlParent);
- DWORD CountContacts(TiXmlElement* xmlParent);
+ DWORD CountContacts(const TiXmlElement* xmlParent);
/*
int ExportOwner(FILE *xmlfile, BYTE bExportEvents);
|