summaryrefslogtreecommitdiff
path: root/plugins/UserInfoEx/ex_import
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
commit48540940b6c28bb4378abfeb500ec45a625b37b6 (patch)
tree2ef294c0763e802f91d868bdef4229b6868527de /plugins/UserInfoEx/ex_import
parent5c350913f011e119127baeb32a6aedeb4f0d33bc (diff)
initial commit
git-svn-id: http://svn.miranda-ng.org/main/trunk@2 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/UserInfoEx/ex_import')
-rw-r--r--plugins/UserInfoEx/ex_import/classExImContactBase.cpp581
-rw-r--r--plugins/UserInfoEx/ex_import/classExImContactBase.h103
-rw-r--r--plugins/UserInfoEx/ex_import/classExImContactXML.cpp1141
-rw-r--r--plugins/UserInfoEx/ex_import/classExImContactXML.h103
-rw-r--r--plugins/UserInfoEx/ex_import/dlg_ExImModules.cpp464
-rw-r--r--plugins/UserInfoEx/ex_import/dlg_ExImModules.h39
-rw-r--r--plugins/UserInfoEx/ex_import/dlg_ExImOpenSaveFile.cpp373
-rw-r--r--plugins/UserInfoEx/ex_import/dlg_ExImOpenSaveFile.h39
-rw-r--r--plugins/UserInfoEx/ex_import/dlg_ExImProgress.cpp244
-rw-r--r--plugins/UserInfoEx/ex_import/dlg_ExImProgress.h56
-rw-r--r--plugins/UserInfoEx/ex_import/mir_rfcCodecs.h371
-rw-r--r--plugins/UserInfoEx/ex_import/svc_ExImINI.cpp547
-rw-r--r--plugins/UserInfoEx/ex_import/svc_ExImINI.h39
-rw-r--r--plugins/UserInfoEx/ex_import/svc_ExImVCF.cpp1364
-rw-r--r--plugins/UserInfoEx/ex_import/svc_ExImVCF.h103
-rw-r--r--plugins/UserInfoEx/ex_import/svc_ExImXML.cpp453
-rw-r--r--plugins/UserInfoEx/ex_import/svc_ExImXML.h75
-rw-r--r--plugins/UserInfoEx/ex_import/svc_ExImport.cpp382
-rw-r--r--plugins/UserInfoEx/ex_import/svc_ExImport.h62
-rw-r--r--plugins/UserInfoEx/ex_import/tinystr.cpp143
-rw-r--r--plugins/UserInfoEx/ex_import/tinystr.h335
-rw-r--r--plugins/UserInfoEx/ex_import/tinyxml.cpp1978
-rw-r--r--plugins/UserInfoEx/ex_import/tinyxml.h1597
-rw-r--r--plugins/UserInfoEx/ex_import/tinyxmlerror.cpp76
-rw-r--r--plugins/UserInfoEx/ex_import/tinyxmlparser.cpp1613
25 files changed, 12281 insertions, 0 deletions
diff --git a/plugins/UserInfoEx/ex_import/classExImContactBase.cpp b/plugins/UserInfoEx/ex_import/classExImContactBase.cpp
new file mode 100644
index 0000000000..c0e0bc05ee
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/classExImContactBase.cpp
@@ -0,0 +1,581 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/classExImContactBase.cpp $
+Revision : $Revision: 210 $
+Last change on : $Date: 2010-10-02 22:27:36 +0400 (Сб, 02 окт 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+#include "commonheaders.h"
+#include "..\svc_contactinfo.h"
+#include "classExImContactBase.h"
+#include "mir_rfcCodecs.h"
+
+HANDLE CListFindGroup(LPCSTR pszGroup)
+{
+ CHAR buf[4];
+ BYTE i;
+ DBVARIANT dbv;
+
+ for (i = 0; i < 255; i++) {
+ _itoa(i, buf, 10);
+ if (DB::Setting::GetUString(NULL, "CListGroups", buf, &dbv))
+ break;
+ if (dbv.pszVal && pszGroup && !_stricmp(dbv.pszVal + 1, pszGroup)) {
+ DB::Variant::Free(&dbv);
+ return (HANDLE)(INT_PTR)(i+1);
+ }
+ DB::Variant::Free(&dbv);
+ }
+ return INVALID_HANDLE_VALUE;
+}
+
+/**
+ * name: CExImContactBase
+ * class: CExImContactBase
+ * desc: default constructor
+ * param: none
+ * return: nothing
+ **/
+CExImContactBase::CExImContactBase()
+{
+ _pszNick = NULL;
+ _pszDisp = NULL;
+ _pszGroup = NULL;
+ _pszProto = NULL;
+ _pszProtoOld = NULL;
+ _pszAMPro = NULL;
+ _pszUIDKey = NULL;
+ _dbvUIDHash = NULL;
+ ZeroMemory(&_dbvUID, sizeof(DBVARIANT));
+ _hContact = INVALID_HANDLE_VALUE;
+ _isNewContact = FALSE;
+}
+
+/**
+ * name: ~CExImContactBase
+ * class: CExImContactBase
+ * desc: default denstructor
+ * param: none
+ * return: nothing
+ **/
+CExImContactBase::~CExImContactBase()
+{
+ MIR_FREE(_pszNick);
+ MIR_FREE(_pszDisp);
+ MIR_FREE(_pszGroup);
+ MIR_FREE(_pszProtoOld);
+ MIR_FREE(_pszProto);
+ MIR_FREE(_pszAMPro);
+ MIR_FREE(_pszUIDKey);
+ DB::Variant::Free(&_dbvUID);
+}
+
+/**
+ * name: fromDB
+ * class: CExImContactBase
+ * desc: get contact information from database
+ * param: hContact - handle to contact whose information to read
+ * return: TRUE if successful or FALSE otherwise
+ **/
+BOOLEAN CExImContactBase::fromDB(HANDLE hContact)
+{
+ BOOLEAN ret = FALSE;
+ BOOLEAN isChatRoom = FALSE;
+ LPSTR pszProto;
+ LPCSTR uidSetting;
+ DBVARIANT dbv;
+
+ _hContact = hContact;
+ _dbvUIDHash = 0;
+ MIR_FREE(_pszProtoOld);
+ MIR_FREE(_pszProto);
+ MIR_FREE(_pszAMPro);
+ MIR_FREE(_pszNick);
+ MIR_FREE(_pszDisp);
+ MIR_FREE(_pszGroup);
+ MIR_FREE(_pszUIDKey);
+ DB::Variant::Free(&_dbvUID);
+ ZeroMemory(&_dbvUID, sizeof(DBVARIANT));
+
+ // OWNER
+ if (!_hContact) return TRUE;
+
+ // Proto
+ if (!(pszProto = DB::Contact::Proto(_hContact))) return FALSE;
+ _pszProto = mir_strdup(pszProto);
+
+ // AM_BaseProto
+ if (!DB::Setting::GetUString(NULL, pszProto, "AM_BaseProto", &dbv )) {
+ _pszAMPro = mir_strdup(dbv.pszVal);
+ DB::Variant::Free(&dbv);
+ }
+
+ // unique id (for ChatRoom)
+ if (isChatRoom = DB::Setting::GetByte(_hContact, pszProto, "ChatRoom", 0)) {
+ uidSetting = "ChatRoomID";
+ _pszUIDKey = mir_strdup(uidSetting);
+ if (!DB::Setting::GetAsIs(_hContact, pszProto, uidSetting, &_dbvUID)) {
+ ret = TRUE;
+ }
+ }
+ // unique id (normal)
+ else {
+ uidSetting = (LPCSTR)CallProtoService(pszProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
+ // valid
+ if (uidSetting != NULL && (INT_PTR)uidSetting != CALLSERVICE_NOTFOUND) {
+ _pszUIDKey = mir_strdup(uidSetting);
+ if (!DB::Setting::GetAsIs(_hContact, pszProto, uidSetting, &_dbvUID)) {
+ ret = TRUE;
+ }
+ }
+ // fails because the protocol is no longer installed
+ else {
+ // assert(ret == TRUE);
+ ret = TRUE;
+ }
+ }
+
+ // nickname
+ if (!DB::Setting::GetUString(_hContact, pszProto, SET_CONTACT_NICK, &dbv)) {
+ _pszNick = mir_strdup(dbv.pszVal);
+ DB::Variant::Free(&dbv);
+ }
+
+ if (_hContact && ret) {
+ // Clist Group
+ if (!DB::Setting::GetUString(_hContact, MOD_CLIST, "Group", &dbv)) {
+ _pszGroup = mir_strdup(dbv.pszVal);
+ DB::Variant::Free(&dbv);
+ }
+ // Clist DisplayName
+ if (!DB::Setting::GetUString(_hContact, MOD_CLIST, SET_CONTACT_MYHANDLE, &dbv)) {
+ _pszDisp = mir_strdup(dbv.pszVal);
+ DB::Variant::Free(&dbv);
+ }
+ }
+ return ret;
+}
+
+/**
+ * name: fromIni
+ * class: CExImContactBase
+ * desc: get contact information from a row of a ini file
+ * param: row - the rows data
+ * return: TRUE if successful or FALSE otherwise
+ **/
+BOOLEAN CExImContactBase::fromIni(LPSTR& row)
+{
+ LPSTR p1, p2 = NULL;
+ LPSTR pszUIDValue, pszUIDSetting, pszProto = NULL;
+ LPSTR pszBuf = &row[0];
+ size_t cchBuf = strlen(row);
+
+ MIR_FREE(_pszProtoOld);
+ MIR_FREE(_pszProto);
+ MIR_FREE(_pszAMPro);
+ MIR_FREE(_pszNick);
+ MIR_FREE(_pszDisp);
+ MIR_FREE(_pszGroup);
+ MIR_FREE(_pszUIDKey);
+ DB::Variant::Free(&_dbvUID);
+ ZeroMemory(&_dbvUID, sizeof(DBVARIANT));
+ _dbvUIDHash = 0;
+
+ // read uid value
+ if (cchBuf > 10 && (p1 = mir_strrchr(pszBuf, '*{')) && (p2 = mir_strchr(p1, '}*')) && p1 + 2 < p2) {
+ pszUIDValue = p1 + 1;
+ *p1 = *(p2 - 1) = 0;
+
+ // insulate the uid setting from buffer pointer
+ if (cchBuf > 0 && (p1 = mir_strrchr(pszBuf, '*<')) && (p2 = mir_strchr(p1, '>*')) && p1 + 2 < p2) {
+ pszUIDSetting = p1 + 1;
+ *p1 = *(p2 - 1) = 0;
+
+ // insulate the protocol name from buffer pointer
+ if (cchBuf > 0 && (p1 = mir_strrchr(pszBuf, '*(')) && (p2 = mir_strchr(p1, ')*')) && p1 + 2 < p2) {
+ pszProto = p1 + 1;
+ *(--p1) = *(p2 - 1) = 0;
+
+ // DBVT_DWORD
+ if (strspn(pszUIDValue, "0123456789") == mir_strlen(pszUIDValue)) {
+ _dbvUID.dVal = _atoi64(pszUIDValue);
+ _dbvUID.type = DBVT_DWORD;
+ }
+ else {
+ // DBVT_UTF8
+ _dbvUID.pszVal = mir_strdup(pszUIDValue);
+ _dbvUID.type = DBVT_UTF8;
+ }
+ _pszUIDKey = mir_strdup(pszUIDSetting);
+ _pszProto = mir_strdup(pszProto);
+ } //end insulate the protocol name from buffer pointer
+ } //end insulate the uid setting from buffer pointer
+ } //end read uid value
+
+ // create valid nickname
+ _pszNick = mir_strdup(pszBuf);
+ size_t i = strlen(_pszNick)-1;
+ while (i > 0 && (_pszNick[i] == ' ' || _pszNick[i] == '\t')) {
+ _pszNick[i] = 0;
+ i--;
+ }
+ // finally try to find contact in contact list
+ findHandle();
+ return FALSE;
+}
+
+/**
+ * name: toDB
+ * class: CExImContactBase
+ * desc: searches the database for a contact representing the one
+ * identified by this class or creates a new one if it was not found
+ * param: hMetaContact - a meta contact to add this contact to
+ * return: handle of the contact if successful
+ **/
+HANDLE CExImContactBase::toDB()
+{
+ DBCONTACTWRITESETTING cws;
+
+ // create new contact if none exists
+ if (_hContact == INVALID_HANDLE_VALUE && _pszProto && _pszUIDKey && _dbvUID.type != DBVT_DELETED) {
+ PROTOACCOUNT* pszAccount = 0;
+ if(NULL == (pszAccount = ProtoGetAccount( _pszProto ))) {
+ //account does not exist
+ _hContact = INVALID_HANDLE_VALUE;
+ return INVALID_HANDLE_VALUE;
+ }
+ if(!IsAccountEnabled(pszAccount)) {
+ ;
+ }
+ // create new contact
+ _hContact = DB::Contact::Add();
+ if (!_hContact) {
+ _hContact = INVALID_HANDLE_VALUE;
+ return INVALID_HANDLE_VALUE;
+ }
+ // Add the protocol to the new contact
+ if (CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)_hContact, (LPARAM)_pszProto)) {
+ DB::Contact::Delete(_hContact);
+ _hContact = INVALID_HANDLE_VALUE;
+ return INVALID_HANDLE_VALUE;
+ }
+ // write uid to protocol module
+ cws.szModule = _pszProto;
+ cws.szSetting = _pszUIDKey;
+ cws.value = _dbvUID;
+ if (CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM)_hContact, (LPARAM)&cws)) {
+ DB::Contact::Delete(_hContact);
+ _hContact = INVALID_HANDLE_VALUE;
+ return INVALID_HANDLE_VALUE;
+ }
+ // write nick and display name
+ if (_pszNick) DB::Setting::WriteUString(_hContact, _pszProto, SET_CONTACT_NICK, _pszNick);
+ if (_pszDisp) DB::Setting::WriteUString(_hContact, MOD_CLIST, SET_CONTACT_MYHANDLE, _pszDisp);
+
+ // add group
+ if (_pszGroup) {
+ DB::Setting::WriteUString(_hContact, MOD_CLIST, "Group", _pszGroup);
+ if (CListFindGroup(_pszGroup) == INVALID_HANDLE_VALUE) {
+ WPARAM hGroup = (WPARAM)CallService(MS_CLIST_GROUPCREATE, 0, 0);
+ if (hGroup) {
+ // renaming twice is stupid but the only way to avoid error dialog telling shit like
+ // a group with that name does exist
+ CallService(MS_CLIST_GROUPRENAME, (WPARAM)hGroup, (LPARAM)_pszGroup);
+ }
+ }
+ }
+ }
+ return _hContact;
+}
+
+/**
+ * name: toIni
+ * class: CExImContactBase
+ * desc: writes the line to an opened ini file which identifies the contact
+ * whose information are stored in this class
+ * param: file - pointer to the opened file
+ * return: nothing
+ **/
+VOID CExImContactBase::toIni(FILE* file, int modCount)
+{
+ // getting dbeditor++ NickFromHContact(hContact)
+ static char name[512] = "";
+ char* ret = 0;
+
+ if (_hContact){
+ int loaded = _pszUIDKey ? 1 : 0;
+ if (_pszProto == NULL || !loaded) {
+ if (_pszProto){
+ if (_pszNick)
+ mir_snprintf(name, sizeof(name),"%s (%s)", _pszNick, _pszProto);
+ else
+ mir_snprintf(name, sizeof(name),"(UNKNOWN) (%s)", _pszProto);
+ }
+ else
+ mir_snprintf(name, sizeof(name),"(UNKNOWN)");
+ }
+ else {
+ // Proto loadet - GetContactName(hContact,pszProto,0)
+ LPSTR pszCI = NULL;
+ CONTACTINFO ci;
+ ZeroMemory(&ci, sizeof(ci));
+
+ ci.cbSize = sizeof(ci);
+ ci.hContact = _hContact;
+ ci.szProto = _pszProto;
+ ci.dwFlag = CNF_DISPLAY;
+
+ if (!GetContactInfo(NULL, (LPARAM) &ci)){
+ // CNF_DISPLAY always returns a string type
+ pszCI = (LPSTR)ci.pszVal;
+ }
+ LPSTR pszUID = uid2String(FALSE);
+ if (_pszUIDKey && pszUID)
+ mir_snprintf(name, sizeof(name), "%s *(%s)*<%s>*{%s}*", pszCI, _pszProto, _pszUIDKey, pszUID);
+ else
+ mir_snprintf(name, sizeof(name), "%s (%s)", pszCI, _pszProto);
+
+ mir_free(pszCI);
+ mir_free(pszUID);
+ } // end else (Proto loadet)
+
+ // it is not the best solution (but still works if only basic modules export) - need rework
+ if (modCount > 3)
+ fprintf(file, "CONTACT: %s\n", name);
+ else
+ fprintf(file, "FROM CONTACT: %s\n", name);
+
+ } // end *if (_hContact)
+ else {
+ fprintf(file, "SETTINGS:\n");
+ }
+}
+
+BOOLEAN CExImContactBase::compareUID(DBVARIANT *dbv)
+{
+ DWORD hash = 0;
+ switch (dbv->type) {
+ case DBVT_BYTE:
+ if (dbv->bVal == _dbvUID.bVal) {
+ _dbvUID.type = dbv->type;
+ return TRUE;
+ }
+ break;
+ case DBVT_WORD:
+ if (dbv->wVal == _dbvUID.wVal) {
+ _dbvUID.type = dbv->type;
+ return TRUE;
+ }
+ break;
+ case DBVT_DWORD:
+ if (dbv->dVal == _dbvUID.dVal) {
+ _dbvUID.type = dbv->type;
+ return TRUE;
+ }
+ break;
+ case DBVT_ASCIIZ:
+ hash = hashSetting_M2(dbv->pszVal);
+ case DBVT_WCHAR:
+ if(!hash) hash = hashSettingW_M2((const char *)dbv->pwszVal);
+ case DBVT_UTF8:
+ if(!hash) {
+ LPWSTR tmp = mir_utf8decodeW(dbv->pszVal);
+ hash = hashSettingW_M2((const char *)tmp);
+ mir_free(tmp);
+ }
+ if(hash == _dbvUIDHash) return TRUE;
+ break;
+ case DBVT_BLOB: //'n' cpbVal and pbVal are valid
+ if (_dbvUID.type == dbv->type &&
+ _dbvUID.cpbVal == dbv->cpbVal &&
+ memcmp(_dbvUID.pbVal, dbv->pbVal, dbv->cpbVal) == 0) {
+ return TRUE;
+ }
+ break;
+ default:
+ return FALSE;
+ }
+ return FALSE;
+}
+
+LPSTR CExImContactBase::uid2String(BOOLEAN bPrependType)
+{
+ CHAR szUID[MAX_PATH];
+ LPSTR ptr = szUID;
+
+ switch (_dbvUID.type) {
+ case DBVT_BYTE: //'b' bVal and cVal are valid
+ if (bPrependType) *ptr++ = 'b';
+ _itoa(_dbvUID.bVal, ptr, 10);
+ break;
+ case DBVT_WORD: //'w' wVal and sVal are valid
+ if (bPrependType) *ptr++ = 'w';
+ _itoa(_dbvUID.wVal, ptr, 10);
+ break;
+ case DBVT_DWORD: //'d' dVal and lVal are valid
+ if (bPrependType) *ptr++ = 'd';
+ _itoa(_dbvUID.dVal, ptr, 10);
+ break;
+ case DBVT_WCHAR: //'u' pwszVal is valid
+ {
+ LPSTR r = mir_utf8encodeW(_dbvUID.pwszVal);
+ if (bPrependType) {
+ LPSTR t = (LPSTR)mir_alloc(strlen(r)+2);
+ t[0] = 'u';
+ strcpy(t+1, r);
+ mir_free(r);
+ r = t;
+ }
+ return r;
+ }
+ case DBVT_UTF8: //'u' pszVal is valid
+ {
+ if (bPrependType) *ptr++ = 'u';
+ mir_strncpy(ptr, _dbvUID.pszVal, SIZEOF(szUID)-1);
+ }
+ break;
+ case DBVT_ASCIIZ: {
+ LPSTR r = mir_utf8encode(_dbvUID.pszVal);
+ if (bPrependType) {
+ LPSTR t = (LPSTR)mir_alloc(strlen(r)+2);
+ t[0] = 's';
+ strcpy(t+1, r);
+ mir_free(r);
+ r = t;
+ }
+ return r;
+ }
+ case DBVT_BLOB: //'n' cpbVal and pbVal are valid
+ {
+ if (bPrependType) { //True = XML
+ INT_PTR baselen = Base64EncodeGetRequiredLength(_dbvUID.cpbVal, BASE64_FLAG_NOCRLF);
+ LPSTR t = (LPSTR)mir_alloc(baselen + 5 + bPrependType);
+ assert(t != NULL);
+ if (Base64Encode(_dbvUID.pbVal, _dbvUID.cpbVal, t + bPrependType, &baselen, BASE64_FLAG_NOCRLF)){
+ if (baselen){
+ t[baselen + bPrependType] = 0;
+ if (bPrependType) t[0] = 'n';
+ return t;
+ }
+ }
+ mir_free(t);
+ return NULL;
+ }
+ else { //FALSE = INI
+ WORD j;
+ INT_PTR baselen = (_dbvUID.cpbVal * 3);
+ LPSTR t = (LPSTR)mir_alloc(3 + baselen);
+ ZeroMemory(t, (3 + baselen));
+ for (j = 0; j < _dbvUID.cpbVal; j++) {
+ mir_snprintf((t + bPrependType + (j * 3)), 4,"%02X ", (BYTE)_dbvUID.pbVal[j]);
+ }
+ if (t){
+ if (bPrependType) t[0] = 'n';
+ return t;
+ }
+ else {
+ mir_free(t);
+ return NULL;
+ }
+ }
+ break;
+ }
+ default:
+ return NULL;
+ }
+ return mir_strdup(szUID);
+}
+
+BOOLEAN CExImContactBase::isMeta() const
+{
+ return DB::Module::IsMeta(_pszProto);
+}
+
+BOOLEAN CExImContactBase::isHandle(HANDLE hContact)
+{
+ LPCSTR pszProto;
+ DBVARIANT dbv;
+ BOOLEAN isEqual = FALSE;
+
+ // owner contact ?
+ if (!_pszProto) return hContact == NULL;
+
+ // compare protocols
+ pszProto = DB::Contact::Proto(hContact);
+ if (pszProto == NULL || (INT_PTR)pszProto == CALLSERVICE_NOTFOUND || mir_stricmp(pszProto, _pszProto))
+ return FALSE;
+
+ // compare uids
+ if (_pszUIDKey) {
+ // get uid
+ if (DB::Setting::GetAsIs(hContact, pszProto,_pszUIDKey, &dbv))
+ return FALSE;
+
+ isEqual = compareUID (&dbv);
+ DB::Variant::Free(&dbv);
+ }
+ // compare nicknames if no UID
+ else if (!DB::Setting::GetUString(hContact, _pszProto, SET_CONTACT_NICK, &dbv)) {
+ if (dbv.type == DBVT_UTF8 && dbv.pszVal && !mir_stricmp(dbv.pszVal,_pszNick)) {
+ LPTSTR ptszNick = mir_utf8decodeT(_pszNick);
+ LPTSTR ptszProto = mir_a2t(_pszProto);
+ INT ans = MsgBox(NULL, MB_ICONQUESTION|MB_YESNO, LPGENT("Question"), LPGENT("contact identificaion"),
+ LPGENT("The contact %s(%s) has no unique id in the vCard,\nbut there is a contact in your clist with the same nick and protocol.\nDo you wish to use this contact?"),
+ ptszNick, ptszProto);
+ MIR_FREE(ptszNick);
+ MIR_FREE(ptszProto);
+ isEqual = ans == IDYES;
+ }
+ DB::Variant::Free(&dbv);
+ }
+ return isEqual;
+}
+
+/**
+ * name: handle
+ * class: CExImContactBase
+ * desc: return the handle of the contact
+ * whose information are stored in this class
+ * param: none
+ * return: handle if successful, INVALID_HANDLE_VALUE otherwise
+ **/
+HANDLE CExImContactBase::findHandle()
+{
+ HANDLE hContact;
+
+ for (hContact = DB::Contact::FindFirst();
+ hContact != NULL;
+ hContact = DB::Contact::FindNext(hContact))
+ {
+ if (isHandle(hContact)) {
+ _hContact = hContact;
+ _isNewContact = FALSE;
+ return hContact;
+ }
+ }
+ _isNewContact = TRUE;
+ _hContact = INVALID_HANDLE_VALUE;
+ return INVALID_HANDLE_VALUE;
+}
diff --git a/plugins/UserInfoEx/ex_import/classExImContactBase.h b/plugins/UserInfoEx/ex_import/classExImContactBase.h
new file mode 100644
index 0000000000..55e5d94f67
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/classExImContactBase.h
@@ -0,0 +1,103 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/classExImContactBase.h $
+Revision : $Revision: 196 $
+Last change on : $Date: 2010-09-21 03:24:30 +0400 (Вт, 21 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+#pragma once
+
+#include "tinyxml.h"
+#include "..\svc_gender.h"
+
+HANDLE CListFindGroup(LPCSTR pszGroup);
+
+class CExImContactBase {
+ BOOLEAN compareUID(DBVARIANT *dbv);
+
+protected:
+ LPSTR _pszNick; // utf8 encoded
+ LPSTR _pszDisp; // utf8 encoded
+ LPSTR _pszGroup; // utf8 encoded
+ LPSTR _pszAMPro;
+ LPSTR _pszProto;
+ LPSTR _pszProtoOld;
+ LPSTR _pszUIDKey;
+ DWORD _dbvUIDHash;
+ DBVARIANT _dbvUID;
+ HANDLE _hContact;
+ BOOLEAN _isNewContact; // is this contact a new one?
+
+ HANDLE findHandle();
+
+public:
+ CExImContactBase();
+ ~CExImContactBase();
+
+// __inline LPCSTR disp() const { return mir_strcmp(_pszDisp,"")? _pszDisp : NULL; }
+// __inline LPCSTR group() const { return mir_strcmp(_pszGroup,"")? _pszGroup : NULL; }
+// __inline LPCSTR nick() const { return mir_strcmp(_pszNick,"")? _pszNick : NULL; }
+// __inline LPCSTR proto() const { return mir_strcmp(_pszProto,"")? _pszProto : NULL; }
+// __inline LPCSTR ampro() const { return mir_strcmp(_pszAMPro,"")? _pszAMPro : NULL; }
+// __inline LPCSTR uidk() const { return mir_strcmp(_pszUIDKey,"")? _pszUIDKey : NULL; }
+ __inline DBVARIANT& uid() { return _dbvUID; }
+ __inline HANDLE handle() const { return _hContact; }
+
+ __inline VOID disp(LPCSTR val) { _pszDisp = val ? mir_strdup(val): NULL; }
+ __inline VOID group(LPCSTR val) { _pszGroup = val ? mir_strdup(val): NULL; }
+ __inline VOID nick(LPCSTR val) { _pszNick = val ? mir_strdup(val): NULL; }
+ __inline VOID proto(LPCSTR val) { _pszProto = val ? mir_strdup(val): NULL; }
+ __inline VOID ampro(LPCSTR val) { _pszAMPro = val ? mir_strdup(val): NULL; }
+ __inline VOID uidk(LPCSTR val) { _pszUIDKey = val ? mir_strdup(val): NULL; }
+ __inline VOID uid(BYTE val) { _dbvUID.type = DBVT_BYTE; _dbvUID.bVal = val; }
+ __inline VOID uid(WORD val) { _dbvUID.type = DBVT_WORD; _dbvUID.wVal = val; }
+ __inline VOID uid(DWORD val) { _dbvUID.type = DBVT_DWORD; _dbvUID.dVal = val; }
+ __inline VOID uidn(PBYTE val, DWORD len) { _dbvUID.type = DBVT_BLOB; _dbvUID.pbVal= val; _dbvUID.cpbVal = (WORD)len; }
+ __inline VOID uida(LPCSTR val)
+ {
+ _dbvUID.type = (_dbvUID.pszVal = mir_utf8decodeA(val))? DBVT_ASCIIZ : DBVT_DELETED;
+ _dbvUIDHash = hashSetting_M2(_dbvUID.pszVal);
+ }
+ __inline VOID uidu(LPCSTR val)
+ {
+ _dbvUID.type = (_dbvUID.pszVal = mir_strdup(val))? DBVT_UTF8 : DBVT_DELETED;
+ LPWSTR temp = mir_utf8decodeW(val);
+ _dbvUIDHash = hashSettingW_M2((const char *)temp);
+ mir_free(temp);
+ }
+
+ BOOLEAN isHandle(HANDLE hContact);
+ BOOLEAN isMeta() const;
+
+ LPSTR uid2String(BOOLEAN bPrependType);
+
+ BOOLEAN fromDB(HANDLE hContact);
+ BOOLEAN fromIni(LPSTR& row);
+
+ HANDLE toDB();
+ VOID toIni(FILE* file, int modCount);
+
+ BOOLEAN operator = (HANDLE hContact) { return fromDB(hContact); }
+};
diff --git a/plugins/UserInfoEx/ex_import/classExImContactXML.cpp b/plugins/UserInfoEx/ex_import/classExImContactXML.cpp
new file mode 100644
index 0000000000..ecd7bd73c9
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/classExImContactXML.cpp
@@ -0,0 +1,1141 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/classExImContactXML.cpp $
+Revision : $Revision: 210 $
+Last change on : $Date: 2010-10-02 22:27:36 +0400 (Сб, 02 окт 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+#include "commonheaders.h"
+#include "classExImContactXML.h"
+#include "svc_ExImXML.h"
+#include "mir_rfcCodecs.h"
+
+/***********************************************************************************************************
+ * common stuff
+ ***********************************************************************************************************/
+
+/**
+ * name: SortProc
+ * desc: used for bsearch in CExImContactXML::IsContactInfo
+ * param: item1 - item to compare
+ * item2 - item to compare
+ * return: the difference
+ **/
+static INT SortProc(const LPDWORD item1, const LPDWORD item2)
+{
+ return *item1 - *item2;
+}
+
+/**
+ * name: CExImContactXML
+ * class: CExImContactXML
+ * desc: the constructor for the contact class
+ * param: pXmlFile - the owning xml file
+ * return: nothing
+ **/
+CExImContactXML::CExImContactXML(CFileXml * pXmlFile)
+ : CExImContactBase()
+{
+ _xmlNode = NULL;
+ _pXmlFile = pXmlFile;
+ _hEvent = NULL;
+}
+
+/**
+ * name: IsContactInfo
+ * class: CExImContactXML
+ * desc: this function compares the given setting key to the list of known contact
+ * information keys
+ * param: pszKey - the settings key to check
+ * return: TRUE if pszKey is a valid contact information
+ **/
+BOOLEAN CExImContactXML::IsContactInfo(LPCSTR pszKey)
+{
+ // This is a sorted list of all hashvalues of the contact information.
+ // This is the same as the szCiKey[] array below but sorted
+ const DWORD dwCiHash[] = {
+ 0x6576F145,0x65780A70,0x6719120C,0x6776F145,0x67780A70,0x6EDB33D7,0x6F0466B5,
+ 0x739B6915,0x73B11E48,0x760D8AD5,0x786A70D0,0x8813C350,0x88641AF8,0x8ED5652D,
+ 0x96D64541,0x97768A14,0x9B786F9C,0x9B7889F9,0x9C26E6ED,0xA6675748,0xA813C350,
+ 0xA8641AF8,0xAC408FCC,0xAC40AFCC,0xAC40CFCC,0xAEC6EA4C,0xB813C350,0xB8641AF8,
+ 0xC5227954,0xCC68DE0E,0xCCD62E70,0xCCFBAAF4,0xCD715E13,0xD36182CF,0xD361C2CF,
+ 0xD361E2CF,0xD42638DE,0xD4263956,0xD426395E,0xD453466E,0xD778D233,0xDB59D87A,
+ 0xE406F60E,0xE406FA0E,0xE406FA4E,0xECF7E910,0xEF660441,0x00331041,0x0039AB3A,
+ 0x003D88A6,0x07ABA803,0x113D8227,0x113DC227,0x113DE227,0x2288784F,0x238643D6,
+ 0x2671C03E,0x275F720B,0x2EBDC0D6,0x3075C8C5,0x32674C9F,0x33EEAE73,0x40239C1C,
+ 0x44DB75D0,0x44FA69D0,0x4C76989B,0x4FF38979,0x544B2F44,0x55AFAF8C,0x567A6BC5,
+ 0x5A96C47F,0x6376F145,0x63780A70
+ };
+ if (pszKey && *pszKey) {
+ char buf[MAXSETTING];
+ // convert to hash and make bsearch as it is much faster then working with strings
+ const DWORD dwHash = hashSetting(_strlwr(mir_strncpy(buf, pszKey, SIZEOF(buf))));
+ return bsearch(&dwHash, dwCiHash, SIZEOF(dwCiHash), sizeof(dwCiHash[0]), (INT (*)(const VOID*, const VOID*))SortProc) != NULL;
+ }
+ return FALSE;
+/*
+ WORD i;
+ const LPCSTR szCiKey[] = {
+ // naming
+ SET_CONTACT_TITLE,SET_CONTACT_FIRSTNAME,SET_CONTACT_SECONDNAME,SET_CONTACT_LASTNAME,SET_CONTACT_PREFIX,
+ // private address
+ SET_CONTACT_STREET,SET_CONTACT_ZIP,SET_CONTACT_CITY,SET_CONTACT_STATE,SET_CONTACT_COUNTRY,
+ SET_CONTACT_PHONE,SET_CONTACT_FAX,SET_CONTACT_CELLULAR,
+ SET_CONTACT_EMAIL,SET_CONTACT_EMAIL0,SET_CONTACT_EMAIL1,SET_CONTACT_HOMEPAGE,
+ // origin
+ SET_CONTACT_ORIGIN_STREET,SET_CONTACT_ORIGIN_ZIP,SET_CONTACT_ORIGIN_CITY,SET_CONTACT_ORIGIN_STATE,SET_CONTACT_ORIGIN_COUNTRY,
+ // company
+ SET_CONTACT_COMPANY_POSITION,SET_CONTACT_COMPANY_OCCUPATION,SET_CONTACT_COMPANY_SUPERIOR,SET_CONTACT_COMPANY_ASSISTENT
+ SET_CONTACT_COMPANY,SET_CONTACT_COMPANY_DEPARTMENT,SET_CONTACT_COMPANY_OFFICE,
+ SET_CONTACT_COMPANY_STREET,SET_CONTACT_COMPANY_ZIP,SET_CONTACT_COMPANY_CITY,SET_CONTACT_COMPANY_STATE,SET_CONTACT_COMPANY_COUNTRY,
+ SET_CONTACT_COMPANY_PHONE,SET_CONTACT_COMPANY_FAX,SET_CONTACT_COMPANY_CELLULAR,
+ SET_CONTACT_COMPANY_EMAIL,SET_CONTACT_COMPANY_EMAIL0,SET_CONTACT_COMPANY_EMAIL1,SET_CONTACT_COMPANY_HOMEPAGE,
+ // personal information
+ SET_CONTACT_ABOUT,SET_CONTACT_MYNOTES,SET_CONTACT_MARITAL,SET_CONTACT_PARTNER,
+ SET_CONTACT_LANG1,SET_CONTACT_LANG2,SET_CONTACT_LANG3,SET_CONTACT_TIMEZONE,SET_CONTACT_TIMEZONENAME,SET_CONTACT_TIMEZONEINDEX,
+ SET_CONTACT_AGE,SET_CONTACT_GENDER,SET_CONTACT_BIRTHDAY,SET_CONTACT_BIRTHMONTH,SET_CONTACT_BIRTHYEAR,
+ "Past0", "Past0Text","Past1", "Past1Text","Past2", "Past2Text",
+ "Affiliation0", "Affiliation0Text","Affiliation1", "Affiliation1Text","Affiliation2", "Affiliation2Text",
+ "Interest0Cat", "Interest0Text","Interest1Cat", "Interest1Text","Interest2Cat", "Interest2Text"
+ };
+ DWORD *hash = new DWORD[SIZEOF(szCiKey)];
+ char buf[MAX_PATH];
+
+ for (i = 0; i < SIZEOF(szCiKey); i++) {
+ strcpy(buf, szCiKey[i]);
+ hash[i] = hashSetting(_strlwr((char*)buf));
+ }
+ qsort(hash, SIZEOF(szCiKey), sizeof(hash[0]),
+ (INT (*)(const VOID*, const VOID*))SortProc);
+
+ FILE* fil = fopen("D:\\temp\\id.txt", "wt");
+ for (i = 0; i < SIZEOF(szCiKey); i++) {
+ fprintf(fil, "0x%08X,", hash[i]);
+ }
+ fclose(fil);
+ return FALSE;
+ */
+}
+
+/***********************************************************************************************************
+ * exporting stuff
+ ***********************************************************************************************************/
+
+/**
+ * name: CreateXmlNode
+ * class: CExImContactXML
+ * desc: creates a new TiXmlElement representing the contact
+ * whose information are stored in this class
+ * param: none
+ * return: pointer to the newly created TiXmlElement
+ **/
+TiXmlElement* CExImContactXML::CreateXmlElement()
+{
+ if (_hContact) {
+ if (_pszProto) {
+ _xmlNode = new TiXmlElement(XKEY_CONTACT);
+
+ if (_xmlNode) {
+ LPSTR pszUID = uid2String(TRUE);
+ _xmlNode->SetAttribute("ampro", _pszAMPro);
+ _xmlNode->SetAttribute("proto", _pszProto);
+
+ if (_pszDisp) _xmlNode->SetAttribute("disp", _pszDisp);
+ if (_pszNick) _xmlNode->SetAttribute("nick", _pszNick);
+ if (_pszGroup) _xmlNode->SetAttribute("group",_pszGroup);
+
+ if (pszUID) {
+
+ if (_pszUIDKey) {
+ _xmlNode->SetAttribute("uidk", _pszUIDKey);
+ _xmlNode->SetAttribute("uidv", pszUID);
+ }
+ else {
+ _xmlNode->SetAttribute("uidk", "#NV");
+ _xmlNode->SetAttribute("uidv", "UNLOADED");
+ }
+ mir_free(pszUID);
+ }
+ }
+ }
+ else
+ _xmlNode = NULL;
+ }
+ else {
+ _xmlNode = new TiXmlElement(XKEY_OWNER);
+ }
+ return _xmlNode;
+}
+
+/**
+ * name: ExportContact
+ * class: CExImContactXML
+ * desc: exports a contact
+ * param: none
+ * return: ERROR_OK on success or any other on failure
+ **/
+INT CExImContactXML::ExportContact(DB::CEnumList* pModules)
+{
+ if (_pXmlFile->_wExport & EXPORT_DATA)
+ {
+ if (pModules)
+ {
+ INT i;
+ LPSTR p;
+
+ for (i = 0; i < pModules->getCount(); i++)
+ {
+ p = (*pModules)[i];
+
+ /*Filter/
+ if (mir_stricmp(p, "Protocol") && !DB::Module::IsMeta(p))*/
+ {
+ ExportModule(p);
+ }
+ }
+ }
+ else
+ {
+ ExportModule(USERINFO);
+ ExportModule(MOD_MBIRTHDAY);
+ }
+ }
+
+ // export contact's events
+ if (_pXmlFile->_wExport & EXPORT_HISTORY)
+ {
+ ExportEvents();
+ }
+
+ return ERROR_OK;
+}
+
+/**
+ * name: ExportSubContact
+ * class: CExImContactXML
+ * desc: exports a meta sub contact
+ * param: none
+ * return: ERROR_OK on success or any other on failure
+ **/
+INT CExImContactXML::ExportSubContact(CExImContactXML *vMetaContact, DB::CEnumList* pModules)
+{
+ // create xmlNode
+ if (!CreateXmlElement())
+ {
+ return ERROR_INVALID_CONTACT;
+ }
+ if (ExportContact(pModules) == ERROR_OK)
+ {
+ if (!_xmlNode->NoChildren() && vMetaContact->_xmlNode->LinkEndChild(_xmlNode))
+ {
+ return ERROR_OK;
+ }
+ }
+ if (_xmlNode) delete _xmlNode;
+ return ERROR_NOT_ADDED;
+}
+
+/**
+ * name: Export
+ * class: CExImContactXML
+ * desc: exports a contact
+ * param: xmlfile - handle to the open file to write the contact to
+ * pModules - list of modules to export for each contact
+ * return: ERROR_OK on success or any other on failure
+ **/
+INT CExImContactXML::Export(FILE *xmlfile, DB::CEnumList* pModules)
+{
+ if (!xmlfile)
+ {
+ return ERROR_INVALID_PARAMS;
+ }
+
+ if (_hContact == INVALID_HANDLE_VALUE)
+ {
+ return ERROR_INVALID_CONTACT;
+ }
+
+ if (!CreateXmlElement())
+ {
+ return ERROR_INVALID_CONTACT;
+ }
+
+ // export meta
+ if (isMeta())
+ {
+ CExImContactXML vContact(_pXmlFile);
+
+ const INT cnt = DB::MetaContact::SubCount(_hContact);
+ const INT def = DB::MetaContact::SubDefNum(_hContact);
+ HANDLE hSubContact = DB::MetaContact::Sub(_hContact, def);
+ INT i;
+
+ // export default subcontact
+ if (hSubContact && vContact.fromDB(hSubContact))
+ {
+ vContact.ExportSubContact(this, pModules);
+ }
+
+ for (i = 0; i < cnt; i++)
+ {
+ if (i != def)
+ {
+ hSubContact = DB::MetaContact::Sub(_hContact, i);
+ if (hSubContact && vContact.fromDB(hSubContact))
+ {
+ vContact.ExportSubContact(this, pModules);
+ }
+ }
+ }
+ }
+ ExportContact(pModules);
+
+ // add xContact to document
+ if (_xmlNode->NoChildren())
+ {
+ delete _xmlNode;
+ _xmlNode = NULL;
+ return ERROR_NOT_ADDED;
+ }
+ _xmlNode->Print(xmlfile, 1);
+ fputc('\n', xmlfile);
+
+ delete _xmlNode;
+ _xmlNode = NULL;
+
+ return ERROR_OK;
+}
+
+/**
+ * name: ExportModule
+ * class: CExImContactXML
+ * desc: enumerates all settings of a database module and adds them to the xml tree
+ * params: pszModule - the module which is to export
+ * return: ERROR_OK on success or any other on failure
+ **/
+INT CExImContactXML::ExportModule(LPCSTR pszModule)
+{
+ DB::CEnumList Settings;
+ if (!pszModule || !*pszModule) {
+ return ERROR_INVALID_PARAMS;
+ }
+ if (!Settings.EnumSettings(_hContact, pszModule)) {
+ INT i;
+ TiXmlElement *xmod;
+ xmod = new TiXmlElement(XKEY_MOD);
+ if (!xmod) {
+ return ERROR_MEMORY_ALLOC;
+ }
+ xmod->SetAttribute("key", pszModule);
+ for (i = 0; i < Settings.getCount(); i++) {
+ ExportSetting(xmod, pszModule, Settings[i]);
+ }
+
+ if (!xmod->NoChildren() && _xmlNode->LinkEndChild(xmod)) {
+ return ERROR_OK;
+ }
+ delete xmod;
+ }
+ return ERROR_EMPTY_MODULE;
+}
+
+/**
+ * name: ExportSetting
+ * desc: read a setting from database and add an xmlelement to contact node
+ * params: xmlModule - xml node to add the setting to
+ * hContact - handle of the contact whose event chain is to export
+ * pszModule - the module which is to export
+ * pszSetting - the setting which is to export
+ * return: pointer to the added element
+ **/
+INT CExImContactXML::ExportSetting(TiXmlElement *xmlModule, LPCSTR pszModule, LPCSTR pszSetting)
+{
+ DBVARIANT dbv;
+ TiXmlElement *xmlEntry = NULL;
+ TiXmlText *xmlValue = NULL;
+ CHAR buf[32];
+ LPSTR str = NULL;
+
+ if (DB::Setting::GetAsIs(_hContact, pszModule, pszSetting, &dbv))
+ return ERROR_INVALID_VALUE;
+ switch (dbv.type) {
+ case DBVT_BYTE: //'b' bVal and cVal are valid
+ buf[0] = 'b';
+ _ultoa(dbv.bVal, buf + 1, 10);
+ xmlValue = new TiXmlText(buf);
+ break;
+ case DBVT_WORD: //'w' wVal and sVal are valid
+ buf[0] = 'w';
+ _ultoa(dbv.wVal, buf + 1, 10);
+ xmlValue = new TiXmlText(buf);
+ break;
+ case DBVT_DWORD: //'d' dVal and lVal are valid
+ buf[0] = 'd';
+ _ultoa(dbv.dVal, buf + 1, 10);
+ xmlValue = new TiXmlText(buf);
+ break;
+ case DBVT_ASCIIZ: //'s' pszVal is valid
+ {
+ if(mir_IsEmptyA(dbv.pszVal)) break;
+ DB::Variant::ConvertString(&dbv, DBVT_UTF8);
+ if (str = (LPSTR)mir_alloc(mir_strlen(dbv.pszVal) + 2)) {
+ str[0] = 's';
+ mir_strcpy(&str[1], dbv.pszVal);
+ xmlValue = new TiXmlText(str);
+ mir_free(str);
+ }
+ break;
+ }
+ case DBVT_UTF8: //'u' pszVal is valid
+ {
+ if(mir_IsEmptyA(dbv.pszVal)) break;
+ if (str = (LPSTR)mir_alloc(mir_strlen(dbv.pszVal) + 2)) {
+ str[0] = 'u';
+ mir_strcpy(&str[1], dbv.pszVal);
+ xmlValue = new TiXmlText(str);
+ mir_free(str);
+ }
+ break;
+ }
+ case DBVT_WCHAR: //'u' pwszVal is valid
+ {
+ if(mir_IsEmptyW(dbv.pwszVal)) break;
+ DB::Variant::ConvertString(&dbv, DBVT_UTF8);
+ if (str = (LPSTR)mir_alloc(mir_strlen(dbv.pszVal) + 2)) {
+ str[0] = 'u';
+ mir_strcpy(&str[1], dbv.pszVal);
+ xmlValue = new TiXmlText(str);
+ mir_free(str);
+ }
+ break;
+ }
+ case DBVT_BLOB: //'n' cpbVal and pbVal are valid
+ {
+ // new buffer for base64 encoded data
+ INT_PTR baselen = Base64EncodeGetRequiredLength(dbv.cpbVal, BASE64_FLAG_NOCRLF);
+ str = (LPSTR)mir_alloc(baselen + 6);
+ assert(str != NULL);
+ // encode data
+ if (Base64Encode(dbv.pbVal, dbv.cpbVal, str+1, &baselen, BASE64_FLAG_NOCRLF)){
+ if (baselen){
+ str[baselen+1] = 0;
+ str[0] = 'n';
+ xmlValue = new TiXmlText(str);
+ }
+ }
+ mir_free(str);
+ break;
+ }
+ case DBVT_DELETED: //this setting just got deleted, no other values are valid
+ #if defined(_DEBUG)
+ OutputDebugStringA("DBVT_DELETED\n");
+ #endif
+ break;
+ default:
+ #if defined(_DEBUG)
+ OutputDebugStringA("DBVT_TYPE unknown\n");
+ #endif
+ ; // nothing
+ }
+ DB::Variant::Free(&dbv);
+ if (xmlValue) {
+ xmlEntry = new TiXmlElement(XKEY_SET);
+ if (xmlEntry) {
+ xmlEntry->SetAttribute("key", pszSetting);
+ if (xmlEntry->LinkEndChild(xmlValue) && xmlModule->LinkEndChild(xmlEntry))
+ return ERROR_OK;
+ delete xmlEntry;
+ }
+ delete xmlValue;
+ }
+ return ERROR_MEMORY_ALLOC;
+}
+
+/**
+ * name: ExportEvents
+ * desc: adds the event chain for a given contact to the xml tree
+ * params: xContact - the xml node to add the events as childs to
+ * hContact - handle of the contact whose event chain is to export
+ * return: TRUE on success, FALSE otherwise
+ **/
+BOOLEAN CExImContactXML::ExportEvents()
+{
+ DBEVENTINFO dbei;
+ HANDLE hDbEvent;
+ PBYTE pbEventBuf = NULL;
+ DWORD cbEventBuf = 0,
+ dwNumEvents = 0,
+ dwNumEventsAdded = 0;
+ LPSTR pBase64Data = NULL;
+ INT_PTR cbBase64Data = 0,
+ cbNewBase64Data = 0;
+
+ TiXmlNode *xmlModule = NULL;
+ TiXmlElement *xmlEvent = NULL;
+ TiXmlText *xmlText = NULL;
+
+ dwNumEvents = CallService(MS_DB_EVENT_GETCOUNT, (WPARAM)_hContact, NULL);
+ if(dwNumEvents == 0) return FALSE;
+
+ try {
+ ZeroMemory(&dbei, sizeof(DBEVENTINFO));
+ dbei.cbSize = sizeof(DBEVENTINFO);
+
+ // read out all events for the current contact
+ for (hDbEvent = DB::Event::FindFirst(_hContact); hDbEvent != NULL; hDbEvent = DB::Event::FindNext(hDbEvent)) {
+ if (!DB::Event::GetInfoWithData(hDbEvent, &dbei)) {
+ // new buffer for base64 encoded data
+ cbNewBase64Data = Base64EncodeGetRequiredLength(dbei.cbBlob, BASE64_FLAG_NOCRLF);
+ if (cbNewBase64Data > cbBase64Data) {
+ pBase64Data = (LPSTR)mir_realloc(pBase64Data, cbNewBase64Data + 5);
+ if (pBase64Data == NULL) {
+ MessageBoxA(NULL, "mir_realloc(cbNewBase64Data + 5) == NULL", "Error", 0);
+ break;
+ }
+ cbBase64Data = cbNewBase64Data;
+ }
+
+ // encode data
+ if (Base64Encode(dbei.pBlob, dbei.cbBlob, pBase64Data, &cbNewBase64Data, BASE64_FLAG_NOCRLF)) {
+ pBase64Data[cbNewBase64Data] = 0;
+ xmlEvent = new TiXmlElement("evt");
+ if (xmlEvent) {
+ xmlEvent->SetAttribute("type", dbei.eventType);
+ xmlEvent->SetAttribute("time", dbei.timestamp);
+ xmlEvent->SetAttribute("flag", dbei.flags);
+
+ xmlText = new TiXmlText(pBase64Data);
+ xmlEvent->LinkEndChild(xmlText);
+
+ // find module
+ for (xmlModule = _xmlNode->FirstChild(); xmlModule != NULL; xmlModule = xmlModule->NextSibling()) {
+ if (!mir_stricmp(((TiXmlElement*)xmlModule)->Attribute("key"), dbei.szModule)) break;
+ }
+ // create new module
+ if (!xmlModule) {
+ xmlModule = _xmlNode->InsertEndChild(TiXmlElement(XKEY_MOD));
+ if (!xmlModule) break;
+ ((TiXmlElement*)xmlModule)->SetAttribute("key", dbei.szModule);
+ }
+
+ xmlModule->LinkEndChild(xmlEvent);
+ dwNumEventsAdded++;
+ xmlEvent = NULL; // avoid final deleting
+ }
+ }
+ MIR_FREE(dbei.pBlob);
+ }
+ }
+ }
+ catch(...) {
+ // fuck, do nothing
+ MIR_FREE(dbei.pBlob);
+ dwNumEventsAdded = 0;
+ }
+
+ mir_free(pbEventBuf);
+ mir_free(pBase64Data);
+ if (xmlEvent) delete xmlEvent;
+
+ return dwNumEventsAdded == dwNumEvents;
+}
+
+/***********************************************************************************************************
+ * importing stuff
+ ***********************************************************************************************************/
+
+/**
+ * name: CountKeys
+ * desc: Counts the number of events and settings stored for a contact
+ * params: xmlContact - the contact, who is the owner of the keys to count
+ * return: nothing
+ **/
+VOID CExImContactXML::CountKeys(DWORD &numSettings, DWORD &numEvents)
+{
+ TiXmlNode *xmod, *xkey;
+
+ numSettings = numEvents = 0;
+ for (xmod = _xmlNode->FirstChild();
+ xmod != NULL;
+ xmod = xmod->NextSibling(XKEY_MOD) ) {
+ for (xkey = xmod->FirstChild();
+ xkey != NULL;
+ xkey = xkey->NextSibling() ) {
+ if (!mir_stricmp(xkey->Value(), XKEY_SET)) numSettings++;
+ else numEvents++;
+ }
+ }
+}
+
+/**
+ * name: LoadXmlElemnt
+ * class: CExImContactXML
+ * desc: get contact information from XML-file
+ * param: xContact - TiXmlElement representing a contact
+ * return: ERROR_OK if successful or any other error number otherwise
+ **/
+INT CExImContactXML::LoadXmlElemnt(TiXmlElement *xContact)
+{
+ if (xContact == NULL) return ERROR_INVALID_PARAMS;
+
+ LPSTR pszMetaProto = myGlobals.szMetaProto ? myGlobals.szMetaProto : "MetaContacts";
+
+ // delete last contact
+ DB::Variant::Free(&_dbvUID);
+ _hContact = INVALID_HANDLE_VALUE;
+
+ _xmlNode = xContact;
+ MIR_FREE(_pszAMPro); ampro(xContact->Attribute("ampro"));
+ 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);
+ MIR_FREE(_pszUIDKey);
+
+ // is contact a metacontact
+ if (_pszAMPro && !strcmp(_pszAMPro, pszMetaProto) /*_xmlNode->FirstChildElement(XKEY_CONTACT)*/) {
+ TiXmlElement *xSub;
+ proto(pszMetaProto);
+
+ // 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 != NULL;
+ xSub = xSub->NextSiblingElement(XKEY_CONTACT)) {
+ CExImContactXML vSub(_pXmlFile);
+ if (vSub = xSub) {
+ // identify metacontact by the first valid subcontact in xmlfile
+ if (_hContact == INVALID_HANDLE_VALUE && vSub.handle() != INVALID_HANDLE_VALUE) {
+ HANDLE hMeta = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM)vSub.handle(), NULL);
+ if (hMeta != NULL) {
+ _hContact = hMeta;
+ break;
+ }
+ }
+ }
+ }
+ // if no handle was found, this is a new meta contact
+ _isNewContact = _hContact == INVALID_HANDLE_VALUE;
+ }
+ // entry is a default contact
+ else {
+ proto(xContact->Attribute("proto"));
+ uidk (xContact->Attribute("uidk"));
+ if (!_pszProto) {
+ // check if this is the owner contact
+ if (mir_stricmp(xContact->Value(), XKEY_OWNER))
+ return ERROR_INVALID_PARAMS;
+ _hContact = NULL;
+ _xmlNode = xContact;
+ return ERROR_OK;
+ }
+
+ if (_pszUIDKey && mir_strcmp("#NV", _pszUIDKey) !=0) {
+ LPCSTR pUID = xContact->Attribute("uidv");
+
+ if (pUID != NULL) {
+ size_t len = 0;
+ INT_PTR baselen = NULL;
+ PBYTE pbVal = NULL;
+
+ switch (*(pUID++)) {
+ case 'b':
+ uid((BYTE)atoi(pUID));
+ break;
+ case 'w':
+ uid((WORD)atoi(pUID));
+ break;
+ case 'd':
+ uid((DWORD)_atoi64(pUID));
+ break;
+ case 's':
+ // utf8 -> asci
+ uida(pUID);
+ break;
+ case 'u':
+ uidu(pUID);
+ break;
+ case 'n':
+ len = strlen(pUID);
+ baselen = Base64DecodeGetRequiredLength(len);
+ pbVal = (PBYTE)mir_alloc(baselen /*+1*/);
+ if (pbVal != NULL){
+ if (Base64Decode(pUID, len, pbVal, &baselen)){
+ uidn(pbVal, baselen);
+ }
+ else {
+ assert(pUID != NULL);
+ }
+ }
+ break;
+ default:
+ uidu((LPCSTR)NULL);
+ break;
+ }
+ }
+ }
+ // finally try to find contact in contact list
+ findHandle();
+ }
+ return ERROR_OK;
+}
+
+/**
+ * name: ImportContact
+ * class: CExImContactXML
+ * desc: create the contact if neccessary and copy
+ * all information from the xmlNode to database
+ * param: none
+ * return: ERROR_OK on success or any other error number otherwise
+ **/
+INT CExImContactXML::ImportContact()
+{
+ TiXmlNode *xmod;
+
+ // create the contact if not yet exists
+ if (toDB() != INVALID_HANDLE_VALUE) {
+ DWORD numSettings, numEvents;
+
+ _hEvent = NULL;
+
+ // count settings and events and init progress dialog
+ CountKeys(numSettings, numEvents);
+ _pXmlFile->_progress.SetSettingsCount(numSettings + numEvents);
+ _pXmlFile->_numSettingsTodo += numSettings;
+ _pXmlFile->_numEventsTodo += numEvents;
+
+ // import all modules
+ for(xmod = _xmlNode->FirstChild();
+ xmod != NULL;
+ xmod = xmod->NextSibling(XKEY_MOD)) {
+
+ // import module
+ if (ImportModule(xmod) == ERROR_ABORTED) {
+ // ask to delete new incomplete contact
+ if (_isNewContact && _hContact != NULL) {
+ INT result = MsgBox(NULL, MB_YESNO|MB_ICONWARNING,
+ LPGENT("Question"),
+ LPGENT("Importing a new contact was aborted!"),
+ LPGENT("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::Contact::Delete(_hContact);
+ _hContact = INVALID_HANDLE_VALUE;
+ }
+ }
+ return ERROR_ABORTED;
+ }
+ }
+ return ERROR_OK;
+ }
+ return ERROR_NOT_ADDED;
+}
+
+/**
+ * name: ImportNormalContact
+ * class: CExImContactXML
+ * desc: create the contact if neccessary and copy
+ * all information from the xmlNode to database.
+ * Remove contact from a metacontact if it is a subcontact
+ * param: none
+ * return: ERROR_OK on success or any other error number otherwise
+ **/
+INT CExImContactXML::ImportNormalContact()
+{
+ INT err = ImportContact();
+
+ // remove contact from a metacontact
+ if (err == ERROR_OK && CallService(MS_MC_GETMETACONTACT, (WPARAM)_hContact, NULL)) {
+ CallService(MS_MC_REMOVEFROMMETA, NULL, (LPARAM)_hContact);
+ }
+ return err;
+}
+
+/**
+ * name: Import
+ * class: CExImContactXML
+ * desc: create the contact if neccessary and copy
+ * all information from the xmlNode to database.
+ * Remove contact from a metacontact if it is a subcontact
+ * param: TRUE = keepMetaSubContact
+ * return: ERROR_OK on success or any other error number otherwise
+ **/
+INT CExImContactXML::Import(BOOLEAN keepMetaSubContact)
+{
+ INT result;
+ TiXmlElement *xContact = _xmlNode->FirstChildElement("CONTACT");
+
+ // xml contact contains subcontacts?
+ if (xContact) {
+
+ // contact is a metacontact and metacontacts plugin is installed?
+ if (isMeta()) {
+ // create object for first sub contact
+ CExImContactXML vContact(_pXmlFile);
+ LPTSTR pszNick;
+
+ // the contact does not yet exist
+ if (_isNewContact) {
+ // import default contact as normal contact and convert to meta contact
+ if (!(vContact = xContact)) {
+ return ERROR_CONVERT_METACONTACT;
+ }
+ // import as normal contact
+ result = vContact.ImportContact();
+ if (result != ERROR_OK) return result;
+ // convert default subcontact to metacontact
+ _hContact = (HANDLE)CallService(MS_MC_CONVERTTOMETA, (WPARAM)vContact.handle(), NULL);
+ if (_hContact == NULL) {
+ _hContact = INVALID_HANDLE_VALUE;
+ return ERROR_CONVERT_METACONTACT;
+ }
+
+ _pXmlFile->_numContactsDone++;
+ // do not load first meta contact twice
+ xContact = xContact->NextSiblingElement("CONTACT");
+ }
+ // xml contact contains more than one subcontacts?
+ if (xContact) {
+ // load all subcontacts
+ do {
+ // update progressbar and abort if user clicked cancel
+ pszNick = mir_utf8decodeT(xContact->Attribute("nick"));
+ result = _pXmlFile->_progress.UpdateContact(_T("Sub Contact: %s (") _T(TCHAR_STR_PARAM) _T(")"), pszNick, xContact->Attribute("proto"));
+ if (pszNick) mir_free(pszNick);
+ // user clicked abort button
+ if (!result) break;
+ if (vContact = xContact) {
+ if (vContact.ImportMetaSubContact(this) == ERROR_ABORTED)
+ return ERROR_ABORTED;
+ _pXmlFile->_numContactsDone++;
+ }
+ }
+ while (xContact = xContact->NextSiblingElement("CONTACT"));
+ }
+ // load metacontact information (after subcontact for faster import)
+ ImportContact();
+ return ERROR_OK;
+ }
+ // import sub contacts as normal contacts
+ return _pXmlFile->ImportContacts(_xmlNode);
+ }
+
+ // load contact information
+ result = ImportContact();
+ if (result == ERROR_OK && !keepMetaSubContact)
+ {
+ CallService(MS_MC_REMOVEFROMMETA, NULL, (LPARAM)_hContact);
+ }
+
+ return result;
+}
+
+/**
+ * name: ImportMetaSubContact
+ * class: CExImContactXML
+ * desc: create the contact if neccessary and copy
+ * 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:
+ **/
+INT CExImContactXML::ImportMetaSubContact(CExImContactXML * pMetaContact)
+{
+ INT err = ImportContact();
+
+ // abort here if contact was not imported correctly
+ if (err != ERROR_OK) return err;
+
+ // check if contact is subcontact of the desired meta contact
+ if ((HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM)_hContact, NULL) != pMetaContact->handle()) {
+ // add contact to the metacontact (this service returns TRUE if successful)
+ err = CallService(MS_MC_ADDTOMETA, (WPARAM)_hContact, (LPARAM)pMetaContact->handle());
+ if (err == FALSE) {
+ // ask to delete new contact
+ if (_isNewContact && _hContact != NULL) {
+ LPTSTR ptszNick = mir_utf8decodeT(_pszNick);
+ LPTSTR ptszMetaNick = mir_utf8decodeT(pMetaContact->_pszNick);
+ INT result = MsgBox(NULL, MB_YESNO|MB_ICONWARNING,
+ LPGENT("Question"),
+ LPGENT("Importing a new meta subcontact failed!"),
+ LPGENT("The newly created MetaSubContact '%s'\ncould not be added to MetaContact '%s'!\n\nDo you want to delete this contact?"),
+ ptszNick, ptszMetaNick);
+ MIR_FREE(ptszNick);
+ MIR_FREE(ptszMetaNick);
+ if (result == IDYES) {
+ DB::Contact::Delete(_hContact);
+ _hContact = INVALID_HANDLE_VALUE;
+ }
+ }
+ return ERROR_ADDTO_METACONTACT;
+ }
+ }
+ return ERROR_OK;
+}
+
+/**
+ * name: ImportModule
+ * class: CExImContactXML
+ * desc: interprete an xmlnode as module and add the children to database.
+ * params: hContact - handle to the contact, who is the owner of the setting to import
+ * xmlModule - xmlnode representing the module
+ * 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 CExImContactXML::ImportModule(TiXmlNode* xmlModule)
+{
+ TiXmlElement *xMod;
+ TiXmlElement *xKey;
+ LPCSTR pszModule;
+ BOOLEAN isProtoModule;
+ BOOLEAN isMetaModule;
+
+ // check if parent is really a module
+ if (!xmlModule || mir_stricmp(xmlModule->Value(), XKEY_MOD))
+ return ERROR_INVALID_SIGNATURE;
+ // convert to element
+ if (!(xMod = xmlModule->ToElement()))
+ return ERROR_INVALID_PARAMS;
+ // get module name
+ pszModule = xMod->Attribute("key");
+ if (!pszModule || !*pszModule)
+ return ERROR_INVALID_PARAMS;
+ // ignore Modul 'Protocol' as it would cause trouble
+ if (!mir_stricmp(pszModule, "Protocol"))
+ return ERROR_OK;
+
+ for (xKey = xmlModule->FirstChildElement(); xKey != NULL; xKey = xKey->NextSiblingElement()) {
+ // import setting
+ if (!mir_stricmp(xKey->Value(), XKEY_SET)) {
+ // check if the module to import is the contact's protocol module
+ isProtoModule = !mir_stricmp(pszModule, _pszProto)/* || DB::Module::IsMeta(pszModule)*/;
+ isMetaModule = DB::Module::IsMeta(pszModule);
+
+ // just ignore MetaModule on normal contact to avoid errors (only keys)
+ if(!isProtoModule && isMetaModule) {
+ continue;
+ }
+ // just ignore MetaModule on Meta to avoid errors (only import spetial keys)
+ else if(isProtoModule && isMetaModule) {
+ if (!mir_stricmp(xKey->Attribute("key"),"Nick") ||
+ !mir_stricmp(xKey->Attribute("key"),"TzName") ||
+ !mir_stricmp(xKey->Attribute("key"),"Timezone") ){
+ if (ImportSetting(pszModule, xKey->ToElement()) == 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) {
+ _pXmlFile->_numSettingsDone++;
+ }
+ }
+ }
+ // other module
+ else if (ImportSetting(pszModule, xKey->ToElement()) == ERROR_OK) {
+ _pXmlFile->_numSettingsDone++;
+ }
+ if (!_pXmlFile->_progress.UpdateSetting(LPGENT("Settings: %S"), pszModule))
+ return ERROR_ABORTED;
+ }
+ // import event
+ else if (!mir_stricmp(xKey->Value(), XKEY_EVT)) {
+ INT error = ImportEvent(pszModule, xKey->ToElement());
+ switch (error) {
+ case ERROR_OK:
+ _pXmlFile->_numEventsDone++;
+ break;
+ case ERROR_DUPLICATED:
+ _pXmlFile->_numEventsDuplicated++;
+ break;
+ }
+ if (!_pXmlFile->_progress.UpdateSetting(LPGENT("Events: %S"), pszModule))
+ return ERROR_ABORTED;
+ }
+ } //*end for
+ return ERROR_OK;
+}
+
+/**
+ * name: ImportSetting
+ * class: CExImContactXML
+ * desc: interprete an setting representing xmlnode and write the corresponding setting to database.
+ * params: xmlModule - xmlnode representing the module to write the setting to in the database
+ * xmlEntry - xmlnode representing the setting to import
+ * return: ERROR_OK on success or one other element of ImportError to tell the type of failure
+ **/
+INT CExImContactXML::ImportSetting(LPCSTR pszModule, TiXmlElement *xmlEntry)
+{
+ DBCONTACTWRITESETTING cws = {0};
+ TiXmlText* xval;
+ LPCSTR value;
+
+ // validate parameter
+ if (!xmlEntry || !pszModule || !*pszModule)
+ return ERROR_INVALID_PARAMS;
+
+ // validate value
+ xval = (TiXmlText*)xmlEntry->FirstChild();
+ if (!xval || xval->Type() != TiXmlText::TEXT)
+ return ERROR_INVALID_VALUE;
+ value = xval->Value();
+
+ // init write structure
+ cws.szModule = (LPSTR)pszModule;
+ cws.szSetting = xmlEntry->Attribute("key");
+
+ // convert data
+ size_t len = 0;
+ INT_PTR baselen = NULL;
+
+ switch (value[0]) {
+ case 'b': //'b' bVal and cVal are valid
+ cws.value.type = DBVT_BYTE;
+ cws.value.bVal = (BYTE)atoi(value + 1);
+ break;
+ case 'w': //'w' wVal and sVal are valid
+ cws.value.type = DBVT_WORD;
+ cws.value.wVal = (WORD)atoi(value + 1);
+ break;
+ case 'd': //'d' dVal and lVal are valid
+ cws.value.type = DBVT_DWORD;
+ cws.value.dVal = (DWORD)_atoi64(value + 1);
+// cws.value.dVal = (DWORD)atoi(value + 1);
+ break;
+ case 's': //'s' pszVal is valid
+ cws.value.type = DBVT_ASCIIZ;
+ cws.value.pszVal = (LPSTR)mir_utf8decodeA((LPSTR)(value + 1));
+ break;
+ case 'u':
+ cws.value.type = DBVT_UTF8;
+ cws.value.pszVal = (LPSTR)mir_strdup((LPSTR)(value + 1));
+ break;
+ case 'n':
+ len = strlen(value + 1);
+ baselen = Base64DecodeGetRequiredLength(len);
+ cws.value.type = DBVT_BLOB;
+ cws.value.pbVal = (PBYTE)mir_alloc(baselen +1);
+ if (cws.value.pbVal != NULL){
+ if (Base64Decode((value + 1), len, cws.value.pbVal, &baselen)){
+ cws.value.cpbVal = baselen;
+ }
+ else {
+ mir_free(cws.value.pbVal);
+ return ERROR_NOT_ADDED;
+ }
+ }
+ break;
+ default:
+ return ERROR_INVALID_TYPE;
+ }
+ // write value to db
+ if (CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM)_hContact, (LPARAM)&cws)) {
+ //if (cws.value.pbVal>0)
+ mir_free(cws.value.pbVal);
+ if(cws.value.type == DBVT_ASCIIZ || cws.value.type == DBVT_UTF8) mir_free(cws.value.pszVal);
+ return ERROR_NOT_ADDED;
+ }
+ //if (cws.value.pbVal>0)
+ mir_free(cws.value.pbVal);
+ if(cws.value.type == DBVT_ASCIIZ || cws.value.type == DBVT_UTF8) mir_free(cws.value.pszVal);
+ return ERROR_OK;
+}
+
+/**
+ * name: ImportEvent
+ * class: CExImContactXML
+ * desc: interprete an xmlnode and add the corresponding event to database.
+ * params: hContact - handle to the contact, who is the owner of the setting to import
+ * xmlModule - xmlnode representing the module to write the setting to in the database
+ * xmlEvent - xmlnode representing the event to import
+ * return: ERROR_OK on success or one other element of ImportError to tell the type of failure
+ **/
+INT CExImContactXML::ImportEvent(LPCSTR pszModule, TiXmlElement *xmlEvent)
+{
+ DBEVENTINFO dbei;
+ TiXmlText *xmlValue;
+ LPCSTR tmp;
+ size_t cbSrc;
+ INT_PTR baselen;
+
+ // dont import events from metacontact
+ if (isMeta()) {
+ return ERROR_DUPLICATED;
+ }
+
+ if (!xmlEvent || !pszModule || !*pszModule)
+ return ERROR_INVALID_PARAMS;
+
+ if (stricmp(xmlEvent->Value(), "evt"))
+ return ERROR_NOT_ADDED;
+
+ // timestamp must be valid
+ xmlEvent->Attribute("time", (LPINT)&dbei.timestamp);
+ if (dbei.timestamp == 0) return ERROR_INVALID_TIMESTAMP;
+
+ xmlValue = (TiXmlText*)xmlEvent->FirstChild();
+ if (!xmlValue || xmlValue->Type() != TiXmlText::TEXT)
+ return ERROR_INVALID_VALUE;
+ tmp = xmlValue->Value();
+ if (!tmp || tmp[0] == 0)
+ return ERROR_INVALID_VALUE;
+
+ cbSrc = strlen(tmp);
+ baselen = Base64DecodeGetRequiredLength(cbSrc);
+ dbei.cbBlob = NULL;
+ dbei.pBlob = NULL;
+ dbei.pBlob = (PBYTE)mir_alloc(baselen + 1);
+ if (dbei.pBlob != NULL) {
+ if (Base64Decode(tmp, cbSrc, dbei.pBlob, &baselen)) {
+ INT_PTR hEvent;
+
+ // event owning module
+ dbei.cbSize = sizeof(dbei);
+ dbei.szModule = (LPSTR)pszModule;
+ dbei.cbBlob = baselen;
+
+ xmlEvent->Attribute("type", (LPINT)&dbei.eventType);
+ xmlEvent->Attribute("flag", (LPINT)&dbei.flags);
+ if (dbei.flags == 0) dbei.flags = DBEF_READ;
+
+ // search in new and existing contact for existing event to avoid duplicates
+ if (/*!_isNewContact && */DB::Event::Exists(_hContact, _hEvent, &dbei)) {
+ mir_free(dbei.pBlob);
+ return ERROR_DUPLICATED;
+ }
+
+ hEvent = CallService(MS_DB_EVENT_ADD, (WPARAM)_hContact, (LPARAM)&dbei);
+ mir_free(dbei.pBlob);
+ if (hEvent) {
+ _hEvent = (HANDLE)hEvent;
+ return ERROR_OK;
+ }
+ }
+ mir_free(dbei.pBlob);
+ }
+ return ERROR_NOT_ADDED;
+}
diff --git a/plugins/UserInfoEx/ex_import/classExImContactXML.h b/plugins/UserInfoEx/ex_import/classExImContactXML.h
new file mode 100644
index 0000000000..52ad2ef087
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/classExImContactXML.h
@@ -0,0 +1,103 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/classExImContactXML.h $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#ifndef _CLASS_EXIM_CONTACT_XML_INCLUDED_
+#define _CLASS_EXIM_CONTACT_XML_INCLUDED_ 1
+
+#include "svc_ExImport.h"
+#include "classExImContactBase.h"
+#include "svc_ExImXML.h"
+#include "dlg_ExImProgress.h"
+
+#define XKEY_MOD "MOD"
+#define XKEY_SET "SET"
+#define XKEY_EVT "evt"
+#define XKEY_CONTACT "CONTACT"
+#define XKEY_OWNER "OWNER"
+
+enum EError {
+ ERROR_OK = 0,
+ ERROR_NOT_ADDED = 1,
+ ERROR_INVALID_PARAMS = 2,
+ ERROR_INVALID_VALUE = 3,
+ ERROR_INVALID_TIMESTAMP = 4,
+ ERROR_INVALID_TYPE = 5,
+ ERROR_DUPLICATED = 6,
+ ERROR_MEMORY_ALLOC = 7,
+ ERROR_INVALID_CONTACT = 8,
+ ERROR_INVALID_SIGNATURE = 9,
+ ERROR_ABORTED = 10,
+ ERROR_CONVERT_METACONTACT = 11,
+ ERROR_ADDTO_METACONTACT = 12,
+ ERROR_EMPTY_MODULE = 13
+};
+
+class CExImContactXML : public CExImContactBase {
+
+ CFileXml* _pXmlFile; // the xmlfile
+ TiXmlElement* _xmlNode; // xmlnode with contact information
+ HANDLE _hEvent;
+
+ BOOLEAN IsContactInfo(LPCSTR pszKey);
+
+ // private importing methods
+ INT ImportModule(TiXmlNode* xmlModule);
+ INT ImportSetting(LPCSTR pszModule, TiXmlElement *xmlEntry);
+ INT ImportEvent(LPCSTR pszModule, TiXmlElement *xmlEvent);
+ INT ImportContact();
+ INT ImportNormalContact();
+ INT ImportMetaSubContact(CExImContactXML * pMetaContact);
+ VOID CountKeys(DWORD &numSettings, DWORD &numEvents);
+
+ // private exporting methods
+ INT ExportModule(LPCSTR pszModule);
+ INT ExportSetting(TiXmlElement *xmlModule, LPCSTR pszModule, LPCSTR pszSetting);
+ BOOLEAN ExportEvents();
+
+ INT ExportContact(DB::CEnumList* pModules);
+ INT ExportSubContact(CExImContactXML *vMetaContact, DB::CEnumList* pModules);
+
+public:
+ CExImContactXML(CFileXml * pXmlFile);
+
+ // exporting stuff
+ TiXmlElement* CreateXmlElement();
+ INT Export(FILE *xmlfile, DB::CEnumList* pModules);
+
+ // importing stuff
+ INT LoadXmlElemnt(TiXmlElement *xContact);
+ INT Import(BOOLEAN keepMetaSubContact = FALSE);
+
+ BOOLEAN operator = (TiXmlElement* xmlContact) {
+ return LoadXmlElemnt(xmlContact) == ERROR_OK;
+ }
+};
+
+#endif /* _CLASS_EXIM_CONTACT_XML_INCLUDED_ */
diff --git a/plugins/UserInfoEx/ex_import/dlg_ExImModules.cpp b/plugins/UserInfoEx/ex_import/dlg_ExImModules.cpp
new file mode 100644
index 0000000000..ba026e2c52
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/dlg_ExImModules.cpp
@@ -0,0 +1,464 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/dlg_ExImModules.cpp $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#include "commonheaders.h"
+//#include "svc_ExImport.h"
+#include "dlg_ExImModules.h"
+
+/***********************************************************************************************************
+ * typedefs
+ ***********************************************************************************************************/
+
+typedef struct {
+ lpExImParam ExImContact;
+ DB::CEnumList* pModules;
+} EXPORTDATA, *LPEXPORTDATA;
+
+/***********************************************************************************************************
+ * modules stuff
+ ***********************************************************************************************************/
+
+/**
+ * name: ExportTree_AppendModuleList
+ * desc: according to the checked list items create the module list for exporting
+ * param: hTree - handle to the window of the treeview
+ * hParent - parent tree item for the item to add
+ * pModules - module list to fill
+ * return: nothing
+ **/
+void ExportTree_AppendModuleList(HWND hTree, HTREEITEM hParent, DB::CEnumList* pModules)
+{
+ TVITEMA tvi;
+
+ // add all checked modules
+ if (tvi.hItem = TreeView_GetChild(hTree, hParent)) {
+ CHAR szModule[MAXSETTING];
+
+ // add optional items
+ tvi.mask = TVIF_STATE|TVIF_TEXT;
+ tvi.stateMask = TVIS_STATEIMAGEMASK;
+ tvi.pszText = szModule;
+ tvi.cchTextMax = MAXSETTING;
+
+ do {
+ if (
+ SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&tvi) &&
+ (
+ tvi.state == INDEXTOSTATEIMAGEMASK(0) ||
+ tvi.state == INDEXTOSTATEIMAGEMASK(2)
+ )
+ )
+ {
+ pModules->Insert(tvi.pszText);
+ }
+ }
+ while (tvi.hItem = TreeView_GetNextSibling(hTree, tvi.hItem));
+ }
+}
+
+/**
+ * name: ExportTree_FindItem
+ * desc: find a item by its label
+ * param: hTree - handle to the window of the treeview
+ * hParent - parent tree item for the item to add
+ * pszText - text to match the label against
+ * return: a handle to the found treeitem or NULL
+ **/
+HTREEITEM ExportTree_FindItem(HWND hTree, HTREEITEM hParent, LPSTR pszText)
+{
+ TVITEMA tvi;
+ CHAR szBuf[128];
+
+ if (!pszText || !*pszText) return NULL;
+
+ tvi.mask = TVIF_TEXT;
+ tvi.pszText = szBuf;
+ tvi.cchTextMax = SIZEOF(szBuf);
+
+ for (tvi.hItem = TreeView_GetChild(hTree, hParent);
+ tvi.hItem != NULL;
+ tvi.hItem = TreeView_GetNextSibling(hTree, tvi.hItem))
+ {
+ if (SendMessageA(hTree, TVM_GETITEMA, NULL, (LPARAM)&tvi) && !mir_stricmp(tvi.pszText, pszText))
+ return tvi.hItem;
+ }
+ return NULL;
+}
+
+/**
+ * name: ExportTree_AddItem
+ * desc: add an item to the tree view with given options
+ * param: hTree - handle to the window of the treeview
+ * hParent - parent tree item for the item to add
+ * pszDesc - item label
+ * bUseImages - icons are loaded
+ * bState - 0-hide checkbox/1-unchecked/2-checked
+ * return: return handle to added treeitem
+ **/
+HTREEITEM ExportTree_AddItem(HWND hTree, HTREEITEM hParent, LPSTR pszDesc, BOOLEAN bUseImages, BYTE bState)
+{
+ TVINSERTSTRUCTA tvii;
+ HTREEITEM hItem = NULL;
+
+ tvii.hParent = hParent;
+ tvii.hInsertAfter = TVI_SORT;
+ tvii.itemex.mask = TVIF_TEXT;
+ if (bUseImages) {
+ tvii.itemex.mask |= TVIF_IMAGE|TVIF_SELECTEDIMAGE;
+ tvii.itemex.iImage = tvii.itemex.iSelectedImage = 1;
+ }
+ tvii.itemex.pszText = pszDesc;
+ if (hItem = (HTREEITEM)SendMessageA(hTree, TVM_INSERTITEMA, NULL, (LPARAM)&tvii))
+ TreeView_SetItemState(hTree, hItem, INDEXTOSTATEIMAGEMASK(bState), TVIS_STATEIMAGEMASK);
+ return hItem;
+}
+
+/**
+ * name: SelectModulesToExport_DlgProc
+ * desc: dialog procedure for a dialogbox, which lists modules for a specific contact
+ * param: hDlg - handle to the window of the dialogbox
+ * uMsg - message to handle
+ * wParam - message specific parameter
+ * lParam - message specific parameter
+ * return: message specific
+ **/
+INT_PTR CALLBACK SelectModulesToExport_DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ LPEXPORTDATA pDat = (LPEXPORTDATA)GetUserData(hDlg);
+
+ switch (uMsg) {
+
+ case WM_INITDIALOG:
+ {
+ HWND hTree;
+ BOOLEAN bImagesLoaded = 0;
+
+ // get tree handle and set treeview style
+ if (!(hTree = GetDlgItem(hDlg, IDC_TREE))) break;
+ SetWindowLongPtr(hTree, GWL_STYLE, GetWindowLongPtr(hTree, GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES);
+
+ // init the datastructure
+ if (!(pDat = (LPEXPORTDATA)mir_alloc(sizeof(EXPORTDATA))))
+ return FALSE;
+ pDat->ExImContact = ((LPEXPORTDATA)lParam)->ExImContact;
+ pDat->pModules = ((LPEXPORTDATA)lParam)->pModules;
+ SetUserData(hDlg, pDat);
+
+ // set icons
+ {
+ HICON hIcon;
+ HIMAGELIST hImages;
+ OSVERSIONINFO osvi;
+ const ICONCTRL idIcon[] = {
+ { ICO_DLG_EXPORT, WM_SETICON, NULL },
+ { ICO_DLG_EXPORT, STM_SETIMAGE, ICO_DLGLOGO },
+ { ICO_BTN_EXPORT, BM_SETIMAGE, IDOK },
+ { ICO_BTN_CANCEL, BM_SETIMAGE, IDCANCEL }
+ };
+ const INT numIconsToSet = DB::Setting::GetByte(SET_ICONS_BUTTONS, 1) ? SIZEOF(idIcon) : 2;
+ IcoLib_SetCtrlIcons(hDlg, idIcon, numIconsToSet);
+
+ // create imagelist for treeview
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&osvi);
+ if ((hImages = ImageList_Create(
+ GetSystemMetrics(SM_CXSMICON),
+ GetSystemMetrics(SM_CYSMICON),
+ ((osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion >= 5 && osvi.dwMinorVersion >= 1) ? ILC_COLOR32 : ILC_COLOR16)|ILC_MASK,
+ 0, 1)
+ ) != NULL)
+ {
+ SendMessage(hTree, TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)hImages);
+
+ bImagesLoaded
+ = ((((hIcon = IcoLib_GetIcon(ICO_LST_MODULES)) != NULL) && 0 == ImageList_AddIcon(hImages, hIcon))
+ && (((hIcon = IcoLib_GetIcon(ICO_LST_FOLDER)) != NULL) && 1 == ImageList_AddIcon(hImages, hIcon)));
+ }
+ }
+ // do the translation stuff
+ {
+ SendDlgItemMessage(hDlg, BTN_CHECK, BUTTONTRANSLATE, NULL, NULL);
+ SendDlgItemMessage(hDlg, BTN_UNCHECK, BUTTONTRANSLATE, NULL, NULL);
+ SendDlgItemMessage(hDlg, IDOK, BUTTONTRANSLATE, NULL, NULL);
+ SendDlgItemMessage(hDlg, IDCANCEL, BUTTONTRANSLATE, NULL, NULL);
+ }
+ // Set the Window Title and description
+ {
+ LPCTSTR name = NULL;
+ TCHAR oldTitle[MAXDATASIZE],
+ newTitle[MAXDATASIZE];
+ switch (pDat->ExImContact->Typ) {
+ case EXIM_ALL:
+ case EXIM_GROUP:
+ name = TranslateT("All Contacts");
+ break;
+ case EXIM_CONTACT:
+ if (pDat->ExImContact->hContact == NULL) {
+ name = TranslateT("Owner");
+ }
+ else {
+ name = DB::Contact::DisplayName(pDat->ExImContact->hContact);
+ }
+ break;
+ case EXIM_SUBGROUP:
+ name = (LPCTSTR) pDat->ExImContact->ptszName;
+ break;
+ case EXIM_ACCOUNT:
+ PROTOACCOUNT* acc = ProtoGetAccount(pDat->ExImContact->pszName);
+ name = (LPCTSTR) acc->tszAccountName;
+ break;
+ }
+ TranslateDialogDefault(hDlg); //to translate oldTitle
+ GetWindowText(hDlg, oldTitle, MAXSETTING);
+ mir_sntprintf(newTitle, MAXDATASIZE - 1, _T("%s - %s"), name, oldTitle);
+ SetWindowText(hDlg, newTitle);
+ }
+
+ {
+ LPSTR pszProto;
+ TVINSERTSTRUCT tviiT;
+ DB::CEnumList Modules;
+ HTREEITEM hItemEssential, hItemOptional;
+
+ TreeView_SetIndent(hTree, 6);
+ TreeView_SetItemHeight(hTree, 18);
+
+ pszProto = (pDat->ExImContact->Typ == EXIM_CONTACT && pDat->ExImContact->hContact != NULL)
+ ? (LPSTR)DB::Contact::Proto(pDat->ExImContact->hContact)
+ : NULL;
+
+ // add items that are always exported
+ tviiT.hParent = TVI_ROOT;
+ tviiT.hInsertAfter = TVI_FIRST;
+ tviiT.itemex.mask = TVIF_TEXT|TVIF_STATE;
+ tviiT.itemex.pszText = TranslateT("Required modules");
+ tviiT.itemex.state = tviiT.itemex.stateMask = TVIS_EXPANDED;
+ if (bImagesLoaded) {
+ tviiT.itemex.mask |= TVIF_IMAGE|TVIF_SELECTEDIMAGE;
+ tviiT.itemex.iImage = tviiT.itemex.iSelectedImage = 0;
+ }
+ if (hItemEssential = TreeView_InsertItem(hTree, &tviiT)) {
+ // disable state images
+ TreeView_SetItemState(hTree, hItemEssential, INDEXTOSTATEIMAGEMASK(0), TVIS_STATEIMAGEMASK);
+
+ // insert essential items (modul from UIEX)
+ ExportTree_AddItem(hTree, hItemEssential, USERINFO, bImagesLoaded, 0);
+ ExportTree_AddItem(hTree, hItemEssential, MOD_MBIRTHDAY, bImagesLoaded, 0);
+
+ /*Filter/ protocol module is ignored for owner contact
+ if (pDat->hContact != NULL) {
+ ExportTree_AddItem(hTree, hItemEssential, "Protocol", bImagesLoaded, 0);
+ }*/
+
+ // base protocol is only valid for single exported contact at this position
+ if (pszProto) {
+ ExportTree_AddItem(hTree, hItemEssential, pszProto, bImagesLoaded, 0);
+ }
+ }
+
+ // add items that are optional (and more essential)
+ tviiT.hInsertAfter = TVI_LAST;
+ tviiT.itemex.pszText = TranslateT("Optional modules");
+ if (hItemOptional = TreeView_InsertItem(hTree, &tviiT)) {
+ TreeView_SetItemState(hTree, hItemOptional, INDEXTOSTATEIMAGEMASK(0), TVIS_STATEIMAGEMASK);
+
+ if (!Modules.EnumModules()) // init Modul list
+ {
+ INT i;
+ LPSTR p;
+
+ for (i = 0; i < Modules.getCount(); i++)
+ {
+ p = Modules[i];
+ /*Filter/
+ if (!DB::Module::IsMeta(p))/end Filter*/
+ {
+ // module must exist in at least one contact
+ if (pDat->ExImContact->Typ != EXIM_CONTACT) // TRUE = All Contacts
+ {
+ HANDLE hContact;
+
+ for (hContact = DB::Contact::FindFirst();
+ hContact != NULL;
+ hContact = DB::Contact::FindNext(hContact))
+ {
+ // ignore empty modules
+ if (!DB::Module::IsEmpty(hContact, p)) {
+ pszProto = DB::Contact::Proto(hContact);
+ // Filter by mode
+ switch (pDat->ExImContact->Typ)
+ {
+ case EXIM_ALL:
+ case EXIM_GROUP:
+ break;
+ case EXIM_SUBGROUP:
+ if (mir_tcsncmp(pDat->ExImContact->ptszName, DB::Setting::GetTString(hContact, "CList", "Group"), mir_tcslen(pDat->ExImContact->ptszName))) {
+ continue;
+ }
+ break;
+ case EXIM_ACCOUNT:
+ if (mir_strcmp(pDat->ExImContact->pszName, pszProto)) {
+ continue;
+ }
+ break;
+ }
+
+ // contact's base protocol is to be added to the treeview uniquely
+ if (!mir_stricmp(p, pszProto))
+ {
+ if (!ExportTree_FindItem(hTree, hItemEssential, p))
+ {
+ ExportTree_AddItem(hTree, hItemEssential, p, bImagesLoaded, 0);
+ }
+ break;
+ }
+
+ // add optional module, which is valid for at least one contact
+ /*/Filter/*/
+ if ( mir_stricmp(p, USERINFO) &&
+ mir_stricmp(p, MOD_MBIRTHDAY) &&
+ // Meta is only valid as base Proto at this point
+ mir_stricmp(p, myGlobals.szMetaProto) /*&&
+ mir_stricmp(p, "Protocol")*/
+ )
+ {
+ ExportTree_AddItem(hTree, hItemOptional, p, bImagesLoaded, 1);
+ break;
+ }
+ }
+ } // end for
+ } // end TRUE = All Contacts
+
+ // module must exist in the selected contact
+ else if (
+ /*Filter/*/
+ !DB::Module::IsEmpty(pDat->ExImContact->hContact, p) &&
+ (!pDat->ExImContact->hContact || mir_stricmp(p, pszProto)) &&
+ //mir_stricmp(p, "Protocol") &&
+ mir_stricmp(p, USERINFO) &&
+ mir_stricmp(p, MOD_MBIRTHDAY) )
+ {
+ ExportTree_AddItem(hTree, hItemOptional, (LPSTR)p, bImagesLoaded, 1);
+ }
+ } // end
+ }
+ }
+ }
+ }
+ TranslateDialogDefault(hDlg);
+ return TRUE;
+ }
+ case WM_CTLCOLORSTATIC:
+ if (GetDlgItem(hDlg, STATIC_WHITERECT) == (HWND)lParam || GetDlgItem(hDlg, ICO_DLGLOGO) == (HWND)lParam) {
+ SetBkColor((HDC)wParam, RGB(255, 255, 255));
+ return (INT_PTR)GetStockObject(WHITE_BRUSH);
+ }
+ SetBkMode((HDC)wParam, TRANSPARENT);
+ return (INT_PTR)GetStockObject(NULL_BRUSH);
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDOK:
+ {
+ HWND hTree = GetDlgItem(hDlg, IDC_TREE);
+ HTREEITEM hParent;
+
+ // search the tree item of optional items
+ for (hParent = TreeView_GetRoot(hTree);
+ hParent != NULL;
+ hParent = TreeView_GetNextSibling(hTree, hParent))
+ {
+ ExportTree_AppendModuleList(hTree, hParent, pDat->pModules);
+ }
+ return EndDialog(hDlg, IDOK);
+ }
+ case IDCANCEL:
+ return EndDialog(hDlg, IDCANCEL);
+
+ case BTN_CHECK:
+ case BTN_UNCHECK:
+ {
+ HWND hTree = GetDlgItem(hDlg, IDC_TREE);
+ LPCSTR pszRoot = Translate("Optional modules");
+ TVITEMA tvi;
+ CHAR szText[128];
+
+ tvi.mask = TVIF_TEXT;
+ tvi.pszText = szText;
+ tvi.cchTextMax = sizeof(szText);
+
+ // search the tree item of optional items
+ for (tvi.hItem = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_ROOT, NULL);
+ tvi.hItem != NULL && SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&tvi);
+ tvi.hItem = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)tvi.hItem))
+ {
+ if (!mir_stricmp(tvi.pszText, pszRoot)) {
+ tvi.mask = TVIF_STATE;
+ tvi.state = INDEXTOSTATEIMAGEMASK(LOWORD(wParam) == BTN_UNCHECK ? 1 : 2);
+ tvi.stateMask = TVIS_STATEIMAGEMASK;
+
+ for (tvi.hItem = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)tvi.hItem);
+ tvi.hItem != NULL;
+ tvi.hItem = (HTREEITEM)SendMessageA(hTree, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)tvi.hItem))
+ {
+ SendMessageA(hTree, TVM_SETITEMA, NULL, (LPARAM)&tvi);
+ }
+ break;
+ }
+ }
+ break;
+ }
+ }
+ break;
+
+ case WM_DESTROY:
+ mir_free(pDat);
+ break;
+ }
+ return 0;
+}
+
+/**
+ * name: DlgExImModules_SelectModulesToExport
+ * desc: calls a dialog box that lists all modules for a specific contact
+ * param: ExImContact - lpExImParam
+ * pModules - pointer to an ENUMLIST structure that retrieves the resulting list of modules
+ * hParent - handle to a window which should act as the parent of the created dialog
+ * return: 0 if user pressed ok, 1 on cancel
+ **/
+INT DlgExImModules_SelectModulesToExport(lpExImParam ExImContact, DB::CEnumList* pModules, HWND hParent)
+{
+ EXPORTDATA dat;
+
+ dat.ExImContact = ExImContact;
+ dat.pModules = pModules;
+ return (IDOK != DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_EXPORT), hParent, SelectModulesToExport_DlgProc, (LPARAM)&dat));
+}
+
diff --git a/plugins/UserInfoEx/ex_import/dlg_ExImModules.h b/plugins/UserInfoEx/ex_import/dlg_ExImModules.h
new file mode 100644
index 0000000000..69ca65ddd3
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/dlg_ExImModules.h
@@ -0,0 +1,39 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/dlg_ExImModules.h $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#ifndef _DLG_EXIMMODULES_H_
+#define _DLG_EXIMMODULES_H_
+
+#pragma once
+#include "svc_ExImport.h"
+
+INT DlgExImModules_SelectModulesToExport(lpExImParam ExImContact, DB::CEnumList* pModules, HWND hParent);
+
+#endif /* _DLG_EXIMMODULES_H_ */
diff --git a/plugins/UserInfoEx/ex_import/dlg_ExImOpenSaveFile.cpp b/plugins/UserInfoEx/ex_import/dlg_ExImOpenSaveFile.cpp
new file mode 100644
index 0000000000..ae11ed0a5f
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/dlg_ExImOpenSaveFile.cpp
@@ -0,0 +1,373 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/dlg_ExImOpenSaveFile.cpp $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#include "commonheaders.h"
+
+#ifdef _UNICODE
+ #include <dlgs.h>
+#endif
+
+#include "m_db3xSA.h"
+#include "dlg_ExImOpenSaveFile.h"
+
+#ifdef _UNICODE
+
+#define HKEY_MIRANDA_PLACESBAR _T("Software\\Miranda IM\\PlacesBar")
+#define HKEY_WINPOL_PLACESBAR _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\ComDlg32\\PlacesBar")
+
+static WNDPROC DefPlacesBarProc;
+
+/**
+ * This function maps the current users registry to a dummy key and
+ * changes the policy hive which is responsible for the places to be displayed,
+ * so the desired places are visible.
+ *
+ * @param nothing
+ * @return nothing
+ **/
+static VOID InitAlteredPlacesBar()
+{
+ // do not try it on a win9x Box
+ if (IsWinVer2000Plus())
+ {
+ HKEY hkMiranda;
+ LONG result;
+
+ // create or open temporary hive for miranda specific places
+ result = RegCreateKey(HKEY_CURRENT_USER, HKEY_MIRANDA_PLACESBAR, &hkMiranda);
+ if (SUCCEEDED(result))
+ {
+ HKEY hkPlacesBar;
+
+ // map the current users registry
+ RegOverridePredefKey(HKEY_CURRENT_USER, hkMiranda);
+ // open the policy key
+ result = RegCreateKey(HKEY_CURRENT_USER, HKEY_WINPOL_PLACESBAR, &hkPlacesBar);
+ // install the places bar
+ if (SUCCEEDED(result))
+ {
+ DWORD dwFolderID;
+ LPSTR p;
+ CHAR szMirandaPath[MAX_PATH];
+ CHAR szProfilePath[MAX_PATH];
+
+ // default places: Desktop, My Documents, My Computer
+ dwFolderID = 0; RegSetValueEx(hkPlacesBar, _T("Place0"), 0, REG_DWORD, (PBYTE)&dwFolderID, sizeof(DWORD));
+ dwFolderID = 5; RegSetValueEx(hkPlacesBar, _T("Place1"), 0, REG_DWORD, (PBYTE)&dwFolderID, sizeof(DWORD));
+ dwFolderID = 17; RegSetValueEx(hkPlacesBar, _T("Place2"), 0, REG_DWORD, (PBYTE)&dwFolderID, sizeof(DWORD));
+
+ // Miranda's installation path
+ GetModuleFileNameA(GetModuleHandle(NULL), szMirandaPath, SIZEOF(szMirandaPath));
+ p = mir_strrchr(szMirandaPath, '\\');
+ if (p)
+ {
+ RegSetValueExA(hkPlacesBar, "Place3", 0, REG_SZ, (PBYTE)szMirandaPath, (p - szMirandaPath) + 1);
+ }
+
+ // Miranda's profile path
+ if (!CallService(MS_DB_GETPROFILEPATH, SIZEOF(szProfilePath), (LPARAM)szProfilePath))
+ {
+ // only add if different from profile path
+ RegSetValueExA(hkPlacesBar, "Place4", 0, REG_SZ, (PBYTE)szProfilePath, (DWORD)strlen(szProfilePath) + 1);
+ }
+
+ RegCloseKey(hkPlacesBar);
+ }
+ RegCloseKey(hkMiranda);
+ }
+ }
+}
+
+/**
+ * name: ResetAlteredPlaceBars
+ * desc: Remove the mapping of current users registry
+ * and delete the temporary registry hive
+ * params: nothing
+ * return: nothing
+ **/
+static VOID ResetAlteredPlaceBars()
+{
+ // make sure not to call the following on a Win9x Box
+ if (IsWinVer2000Plus())
+ {
+ RegOverridePredefKey(HKEY_CURRENT_USER, NULL);
+ SHDeleteKey(HKEY_CURRENT_USER, HKEY_MIRANDA_PLACESBAR);
+ }
+}
+
+/**
+ * name: PlacesBarSubclassProc
+ * params: hWnd - handle, to control's window
+ * uMsg - the message to handle
+ * wParam - message dependend parameter
+ * lParam - message dependend parameter
+ * return: depends on message
+ **/
+static LRESULT PlacesBarSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg)
+ {
+ case TB_ADDBUTTONS:
+ {
+ TBBUTTON *tbb = (TBBUTTON *)lParam;
+ TCHAR szBtnText[MAX_PATH];
+ INT iString;
+ HWND hWndToolTip;
+
+ if (tbb)
+ {
+ switch (tbb->idCommand)
+ {
+ // miranda button
+ case 41063:
+ ZeroMemory(szBtnText, sizeof(szBtnText));
+
+ mir_tcsncpy(szBtnText, TranslateT("Miranda IM"), SIZEOF(szBtnText));
+ iString = SendMessage(hWnd, TB_ADDSTRING, NULL, (LPARAM)szBtnText);
+ if (iString != -1) tbb->iString = iString;
+ // set tooltip
+ hWndToolTip = (HWND)SendMessage(hWnd, TB_GETTOOLTIPS, NULL, NULL);
+ if (hWndToolTip) {
+ TOOLINFO ti;
+
+ ZeroMemory(&ti, sizeof(ti));
+ ti.cbSize = sizeof(ti);
+ ti.hwnd = hWnd;
+ ti.lpszText = TranslateT("Shows Miranda's installation directory.");
+ ti.uId = tbb->idCommand;
+ SendMessage(hWndToolTip, TTM_ADDTOOL, NULL, (LPARAM)&ti);
+ }
+ break;
+ // profile button
+ case 41064:
+ // set button text
+ iString = SendMessage(hWnd, TB_ADDSTRING, NULL, (LPARAM) TranslateT("Profile") );
+ if (iString != -1) tbb->iString = iString;
+
+ // set tooltip
+ hWndToolTip = (HWND)SendMessage(hWnd, TB_GETTOOLTIPS, NULL, NULL);
+ if (hWndToolTip) {
+ TOOLINFO ti;
+
+ ZeroMemory(&ti, sizeof(ti));
+ ti.cbSize = sizeof(ti);
+ ti.hwnd = hWnd;
+ ti.lpszText = TranslateT("Shows the directory with all your Miranda's profiles.");
+ ti.uId = tbb->idCommand;
+ SendMessage(hWndToolTip, TTM_ADDTOOL, NULL, (LPARAM)&ti);
+ }
+ // unmap registry and delete keys
+ ResetAlteredPlaceBars();
+ break;
+ }
+ }
+ break;
+ }
+ }
+ return CallWindowProc(DefPlacesBarProc, hWnd, uMsg, wParam,lParam);
+}
+
+/**
+ * name: OpenSaveFileDialogHook
+ * desc: it subclasses the places bar to provide the own interface for adding places
+ * params: hDlg - handle, to control's window
+ * uMsg - the message to handle
+ * wParam - message dependend parameter
+ * lParam - message dependend parameter
+ * return: depends on message
+ **/
+static UINT_PTR CALLBACK OpenSaveFileDialogHook(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ switch (uMsg) {
+ case WM_NOTIFY:
+ if (((LPNMHDR)lParam)->code == CDN_INITDONE) {
+ HWND hPlacesBar = GetDlgItem(GetParent(hDlg), ctl1);
+
+ // we have a places bar?
+ if (hPlacesBar != NULL) {
+ InitAlteredPlacesBar();
+ // finally subclass the places bar
+ DefPlacesBarProc = SubclassWindow(hPlacesBar, PlacesBarSubclassProc);
+ }
+ }
+ break;
+ case WM_DESTROY:
+ // unmap registry and delete keys
+ // (is to make it sure, if somehow the last places button was not added which also calls this function)
+ ResetAlteredPlaceBars();
+ break;
+ }
+ return FALSE;
+}
+
+#endif
+
+/**
+ * name: GetInitialDir
+ * desc: read the last vCard directory from database
+ * pszInitialDir - buffer to store the initial dir to (size must be MAX_PATH)
+ * return: nothing
+ **/
+static VOID GetInitialDir(LPSTR pszInitialDir)
+{
+ CHAR szRelative[MAX_PATH];
+
+ ZeroMemory(szRelative, SIZEOF(szRelative));
+
+ // is some standard path defined
+ if (!DB::Setting::GetStatic(0, MODNAME, "vCardPath", szRelative, SIZEOF(szRelative))) {
+ if (!CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)szRelative, (WPARAM)pszInitialDir))
+ strcpy(pszInitialDir, szRelative);
+ }
+ else if (//try to use environment variables supported by pathpatch of db3xSA
+ !ServiceExists(MS_DB_GETPROFILEPATH_BASIC) ||
+ !CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)PROFILEPATH "\\" PROFILENAME, (WPARAM)pszInitialDir)
+ ) {
+ // use standard path to absolute
+ if (!CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"", (WPARAM)pszInitialDir))
+ *pszInitialDir = 0;
+ }
+ else
+ *pszInitialDir = 0;
+}
+
+/**
+ * name: SaveInitialDir
+ * desc: save the last vCard directory from database
+ * pszInitialDir - buffer to store the initial dir to (size must be MAX_PATH)
+ * return: nothing
+ **/
+static VOID SaveInitialDir(LPSTR pszInitialDir)
+{
+ CHAR szRelative[MAX_PATH];
+ LPSTR p;
+
+ if (p = mir_strrchr(pszInitialDir, '\\')) {
+ *p = 0;
+ if (CallService(MS_UTILS_PATHTORELATIVE, (WPARAM)pszInitialDir, (LPARAM)szRelative))
+ DB::Setting::WriteAString(0, MODNAME, "vCardPath", szRelative);
+ else
+ DB::Setting::WriteAString(0, MODNAME, "vCardPath", pszInitialDir);
+ *p = '\\';
+ }
+}
+
+/**
+ * name: InitOpenFileNameStruct
+ * desc: initialize the openfilename structure
+ * params: pofn - OPENFILENAME structure to initialize
+ * hWndParent - parent window
+ * pszTitle - title for the dialog
+ * pszFilter - the filters to offer
+ * pszInitialDir - buffer to store the initial dir to (size must be MAX_PATH)
+ * pszFile - this is the buffer to store the file to (size must be MAX_PATH)
+ * return: nothing
+ **/
+static VOID InitOpenFileNameStruct(OPENFILENAMEA *pofn, HWND hWndParent, LPCSTR pszTitle, LPCSTR pszFilter, LPSTR pszInitialDir, LPSTR pszFile)
+{
+ ZeroMemory(pofn, sizeof(OPENFILENAME));
+
+ pofn->Flags = OFN_NONETWORKBUTTON|OFN_ENABLESIZING;
+ pofn->hwndOwner = hWndParent;
+ pofn->lpstrTitle = pszTitle;
+ pofn->lpstrFilter = pszFilter;
+ pofn->lpstrFile = pszFile;
+ pofn->nMaxFile = MAX_PATH;
+ pofn->lpstrDefExt = "xml";
+
+ GetInitialDir(pszInitialDir);
+ pofn->lpstrInitialDir = pszInitialDir;
+
+#ifdef _UNICODE
+ if (IsWinVer2000Plus()) {
+ pofn->lStructSize = sizeof (OPENFILENAME);
+ pofn->Flags |= OFN_ENABLEHOOK|OFN_EXPLORER;
+ pofn->lpfnHook = (LPOFNHOOKPROC)OpenSaveFileDialogHook;
+ }
+ else {
+ pofn->lStructSize = OPENFILENAME_SIZE_VERSION_400;
+ }
+#else
+ pofn->lStructSize = sizeof (OPENFILENAME);
+#endif
+}
+
+
+/**
+ * name: DlgExIm_OpenFileName
+ * desc: displayes a slightly modified OpenFileName DialogBox
+ * params: hWndParent - parent window
+ * pszTitle - title for the dialog
+ * pszFilter - the filters to offer
+ * pszFile - this is the buffer to store the file to (size must be MAX_PATH)
+ * return: -1 on error/abort or filter index otherwise
+ **/
+INT DlgExIm_OpenFileName(HWND hWndParent, LPCSTR pszTitle, LPCSTR pszFilter, LPSTR pszFile)
+{
+ OPENFILENAMEA ofn;
+ CHAR szInitialDir[MAX_PATH];
+
+ InitOpenFileNameStruct(&ofn, hWndParent, pszTitle, pszFilter, szInitialDir, pszFile);
+ ofn.Flags |= OFN_PATHMUSTEXIST;
+ if (!GetOpenFileNameA(&ofn)) {
+ DWORD dwError = CommDlgExtendedError();
+ if (dwError) MsgErr(ofn.hwndOwner, LPGENT("The OpenFileDialog returned an error: %d!"), dwError);
+ return -1;
+ }
+ SaveInitialDir(pszFile);
+ return ofn.nFilterIndex;
+}
+
+/**
+ * name: DlgExIm_SaveFileName
+ * desc: displayes a slightly modified SaveFileName DialogBox
+ * params: hWndParent - parent window
+ * pszTitle - title for the dialog
+ * pszFilter - the filters to offer
+ * pszFile - this is the buffer to store the file to (size must be MAX_PATH)
+ * return: -1 on error/abort or filter index otherwise
+ **/
+INT DlgExIm_SaveFileName(HWND hWndParent, LPCSTR pszTitle, LPCSTR pszFilter, LPSTR pszFile)
+{
+ OPENFILENAMEA ofn;
+ CHAR szInitialDir[MAX_PATH];
+
+ InitOpenFileNameStruct(&ofn, hWndParent, pszTitle, pszFilter, szInitialDir, pszFile);
+ ofn.Flags |= OFN_OVERWRITEPROMPT;
+
+ if (!GetSaveFileNameA(&ofn)) {
+ DWORD dwError = CommDlgExtendedError();
+
+ if (dwError) MsgErr(ofn.hwndOwner, LPGENT("The SaveFileDialog returned an error: %d!"), dwError);
+ return -1;
+ }
+ SaveInitialDir(pszFile);
+ return ofn.nFilterIndex;
+}
diff --git a/plugins/UserInfoEx/ex_import/dlg_ExImOpenSaveFile.h b/plugins/UserInfoEx/ex_import/dlg_ExImOpenSaveFile.h
new file mode 100644
index 0000000000..eb47e9ab30
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/dlg_ExImOpenSaveFile.h
@@ -0,0 +1,39 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/dlg_ExImOpenSaveFile.h $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#ifndef _DLG_EXIMOPENSAVEFFILE_H_
+#define _DLG_EXIMOPENSAVEFFILE_H_
+
+#pragma once
+
+INT DlgExIm_OpenFileName(HWND hWndParent, LPCSTR pszTitle, LPCSTR pszFilter, LPSTR pszFile);
+INT DlgExIm_SaveFileName(HWND hWndParent, LPCSTR pszTitle, LPCSTR pszFilter, LPSTR pszFile);
+
+#endif /* _DLG_EXIMOPENSAVEFFILE_H_ */
diff --git a/plugins/UserInfoEx/ex_import/dlg_ExImProgress.cpp b/plugins/UserInfoEx/ex_import/dlg_ExImProgress.cpp
new file mode 100644
index 0000000000..9da4ee4373
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/dlg_ExImProgress.cpp
@@ -0,0 +1,244 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/dlg_ExImProgress.cpp $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#include "commonheaders.h"
+#include "dlg_ExImProgress.h"
+
+/***********************************************************************************************************
+ * windows procedure
+ ***********************************************************************************************************/
+
+/**
+ * name: DlgProcProgress
+ * desc: dialog procedure for the progress dialog
+ * params: none
+ * return: nothing
+ **/
+LRESULT CALLBACK DlgProcProgress(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ const ICONCTRL idIcon[] = {
+ { ICO_DLG_IMPORT, WM_SETICON, NULL },
+ { ICO_DLG_IMPORT, STM_SETIMAGE, ICO_DLGLOGO },
+ { ICO_BTN_CANCEL, BM_SETIMAGE, IDCANCEL }
+ };
+ const INT numIconsToSet = DB::Setting::GetByte(SET_ICONS_BUTTONS, 1) ? SIZEOF(idIcon) : 2;
+ IcoLib_SetCtrlIcons(hDlg, idIcon, numIconsToSet);
+
+ TranslateDialogDefault(hDlg);
+ SendDlgItemMessage(hDlg, IDCANCEL, BUTTONTRANSLATE, NULL, NULL);
+ SendDlgItemMessage(hDlg, IDC_PROGRESS, PBM_SETPOS, 0, 0);
+ SendDlgItemMessage(hDlg, IDC_PROGRESS2, PBM_SETPOS, 0, 0);
+ SetWindowLongPtr(hDlg, GWLP_USERDATA, 0);
+ UpdateWindow(hDlg);
+ break;
+ }
+ case WM_CTLCOLORSTATIC:
+ switch (GetWindowLongPtr((HWND)lParam, GWLP_ID)) {
+ //case IDC_HEADERBAR
+ case STATIC_WHITERECT:
+ case TXT_SETTING:
+ case IDC_PROGRESS:
+ case TXT_CONTACT:
+ case IDC_PROGRESS2:
+ //case ICO_DLGLOGO:
+ //case IDC_INFO:
+ SetBkColor((HDC)wParam, RGB(255, 255, 255));
+ return (INT_PTR)GetStockObject(WHITE_BRUSH);
+ }
+ return FALSE;
+ case WM_COMMAND:
+ if (HIWORD(wParam) == BN_CLICKED) {
+ switch (LOWORD(wParam)) {
+ case IDCANCEL:
+ // in the progress dialog, use the user data to indicate that the user has pressed cancel
+ ShowWindow(hDlg, SW_HIDE);
+ SetWindowLongPtr(hDlg, GWLP_USERDATA, 1);
+ return TRUE;
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
+
+/**
+ * name: CProgress
+ * class: CProgress
+ * desc: create the progress dialog and return a handle as pointer to the datastructure
+ * params: none
+ * return: nothing
+ **/
+CProgress::CProgress()
+{
+ _dwStartTime = GetTickCount();
+ _hDlg = CreateDialog(ghInst, MAKEINTRESOURCE(IDD_COPYPROGRESS), 0, (DLGPROC)DlgProcProgress);
+}
+
+/**
+ * name: ~CProgress
+ * class: CProgress
+ * desc: destroy the progress dialog and its data structure
+ * params: none
+ * return: nothing
+ **/
+CProgress::~CProgress()
+{
+ if(IsWindow(_hDlg)) DestroyWindow(_hDlg);
+}
+
+/**
+ * name: SetContactCount
+ * class: CProgress
+ * desc: number of contacts to show 100% for
+ * params: numContacts - the number of contacts
+ * return: nothing
+ **/
+VOID CProgress::SetContactCount(DWORD numContacts)
+{
+ if (_hDlg) {
+ HWND hProgress = GetDlgItem(_hDlg, IDC_PROGRESS2);
+ SendMessage(hProgress, PBM_SETRANGE32, 0, numContacts);
+ SendMessage(hProgress, PBM_SETPOS, 0, 0);
+ }
+}
+
+/**
+ * name: SetSettingsCount
+ * class: CProgress
+ * desc: number of settings & events to show 100% for
+ * params: numSettings - the number of settings & events
+ * return: nothing
+ **/
+VOID CProgress::SetSettingsCount(DWORD numSettings)
+{
+ if (_hDlg) {
+ HWND hProgress = GetDlgItem(_hDlg, IDC_PROGRESS);
+ SendMessage(hProgress, PBM_SETRANGE32, 0, numSettings);
+ SendMessage(hProgress, PBM_SETPOS, 0, 0);
+ }
+}
+
+/**
+ * name: Hide
+ * class: CProgress
+ * desc: hides the dialog
+ * params: none
+ * return: nothing
+ **/
+VOID CProgress::Hide()
+{
+ ShowWindow(_hDlg, SW_HIDE);
+}
+
+/**
+ * name: Update
+ * class: CProgress
+ * desc: update the progress dialog
+ * params: nothing
+ * return: FALSE if user pressed cancel, TRUE otherwise
+ **/
+BOOLEAN CProgress::Update()
+{
+ MSG msg;
+
+ // show dialog after one second
+ if (GetTickCount() > _dwStartTime + 1000) {
+ ShowWindow(_hDlg, SW_SHOW);
+ }
+
+ UpdateWindow(_hDlg);
+
+ while (PeekMessage(&msg, _hDlg, 0, 0, PM_REMOVE) != 0) {
+ if (!IsDialogMessage(_hDlg, &msg)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ return GetWindowLongPtr(_hDlg, GWLP_USERDATA) == 0;
+}
+
+/**
+ * name: UpdateContact
+ * class: CProgress
+ * desc: increase contact's progressbar by one and set new text
+ * params: pszFormat - the text to display for the contact
+ * return: FALSE if user pressed cancel, TRUE otherwise
+ **/
+BOOLEAN CProgress::UpdateContact(LPCTSTR pszFormat, ...)
+{
+ if (_hDlg != NULL) {
+ HWND hProg = GetDlgItem(_hDlg, IDC_PROGRESS2);
+ if (pszFormat) {
+ TCHAR buf[MAX_PATH];
+ va_list vl;
+
+ va_start(vl, pszFormat);
+ mir_vsntprintf(buf, SIZEOF(buf), TranslateTS(pszFormat), vl);
+ va_end(vl);
+ SetDlgItemText(_hDlg, TXT_CONTACT, buf);
+ }
+ SendMessage(hProg, PBM_SETPOS, (INT)SendMessage(hProg, PBM_GETPOS, 0, 0) + 1, 0);
+ return Update();
+ }
+ return TRUE;
+}
+
+/**
+ * name: UpdateContact
+ * class: CProgress
+ * desc: increase setting's progressbar by one and set new text
+ * params: pszFormat - the text to display for the setting
+ * return: FALSE if user pressed cancel, TRUE otherwise
+ **/
+BOOLEAN CProgress::UpdateSetting(LPCTSTR pszFormat, ...)
+{
+ if (_hDlg != NULL) {
+ HWND hProg = GetDlgItem(_hDlg, IDC_PROGRESS);
+ if (pszFormat) {
+ TCHAR buf[MAX_PATH];
+ TCHAR tmp[MAX_PATH];
+ va_list vl;
+
+ va_start(vl, pszFormat);
+ mir_vsntprintf(buf, SIZEOF(buf), TranslateTS(pszFormat), vl);
+ va_end(vl);
+ GetDlgItemText(_hDlg, TXT_SETTING, tmp, SIZEOF(tmp));
+ if(mir_tcsicmp(tmp,buf))
+ SetDlgItemText(_hDlg, TXT_SETTING, buf);
+ }
+ SendMessage(hProg, PBM_SETPOS, (INT)SendMessage(hProg, PBM_GETPOS, 0, 0) + 1, 0);
+ return Update();
+ }
+ return TRUE;
+}
diff --git a/plugins/UserInfoEx/ex_import/dlg_ExImProgress.h b/plugins/UserInfoEx/ex_import/dlg_ExImProgress.h
new file mode 100644
index 0000000000..55ab614cfe
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/dlg_ExImProgress.h
@@ -0,0 +1,56 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/dlg_ExImProgress.h $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#ifndef _DLG_EXIMPROGRESS_H_
+#define _DLG_EXIMPROGRESS_H_
+
+#pragma once
+
+class CProgress
+{
+ HWND _hDlg;
+ DWORD _dwStartTime;
+
+ BOOLEAN Update();
+
+public:
+ CProgress();
+ ~CProgress();
+
+ VOID Hide();
+
+ VOID SetContactCount(DWORD numContacts);
+ VOID SetSettingsCount(DWORD numSettings);
+
+ BOOLEAN UpdateContact(LPCTSTR pszFormat, ...);
+ BOOLEAN UpdateSetting(LPCTSTR pszFormat, ...);
+};
+
+#endif /* _DLG_EXIMPROGRESS_H_ */
diff --git a/plugins/UserInfoEx/ex_import/mir_rfcCodecs.h b/plugins/UserInfoEx/ex_import/mir_rfcCodecs.h
new file mode 100644
index 0000000000..0fe287ec93
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/mir_rfcCodecs.h
@@ -0,0 +1,371 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/mir_rfcCodecs.h $
+Revision : $Revision: 190 $
+Last change on : $Date: 2010-09-14 14:32:57 +0400 (Вт, 14 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#include <stdlib.h>
+
+//Not including CRLFs
+//NOTE: For BASE64 and UUENCODE, this actually
+//represents the amount of unencoded characters
+//per line
+#define TSSMTPMAX_QP_LINE_LENGTH 76
+#define TSSMTPMAX_BASE64_LINE_LENGTH 57
+#define TSSMTPMAX_UUENCODE_LINE_LENGTH 45
+
+//=======================================================================
+// Base64Encode/Base64Decode
+// compliant with RFC 2045
+//=======================================================================
+//
+#define BASE64_FLAG_NONE 0
+#define BASE64_FLAG_NOPAD 1
+#define BASE64_FLAG_NOCRLF 2
+
+inline INT_PTR Base64EncodeGetRequiredLength(INT_PTR nSrcLen, DWORD dwFlags = BASE64_FLAG_NONE)
+{
+ INT_PTR nRet = nSrcLen*4/3;
+
+ if ((dwFlags & BASE64_FLAG_NOPAD) == 0)
+ nRet += nSrcLen % 3;
+
+ INT_PTR nCRLFs = nRet / 76 + 3;
+ INT_PTR nOnLastLine = nRet % 76;
+
+ if (nOnLastLine) {
+ if (nOnLastLine % 4)
+ nRet += 4 - (nOnLastLine % 4);
+ }
+
+ nCRLFs *= 2;
+
+ if ((dwFlags & BASE64_FLAG_NOCRLF) == 0)
+ nRet += nCRLFs;
+
+ return nRet;
+}
+
+inline INT_PTR Base64DecodeGetRequiredLength(INT_PTR nSrcLen)
+{
+ return nSrcLen;
+}
+
+inline BOOL Base64Encode(
+ const BYTE *pbSrcData,
+ INT_PTR nSrcLen,
+ LPSTR szDest,
+ INT_PTR *pnDestLen,
+ DWORD dwFlags = BASE64_FLAG_NONE)
+{
+ static const char s_chBase64EncodingTable[64] = {
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
+ 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
+ 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
+ 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' };
+
+ if (!pbSrcData || !szDest || !pnDestLen)
+ return FALSE;
+
+ INT_PTR nWritten(0);
+ INT_PTR nLen1((nSrcLen / 3) * 4);
+ INT_PTR nLen2(nLen1 / 76);
+ INT_PTR nLen3(19);
+ INT_PTR i, j, k, n;
+
+ for (i = 0; i <= nLen2; i++) {
+ if (i == nLen2)
+ nLen3 = (nLen1 % 76) / 4;
+
+ for (j = 0; j < nLen3; j++) {
+ DWORD dwCurr(0);
+ for (INT_PTR n = 0; n < 3; n++) {
+ dwCurr |= *pbSrcData++;
+ dwCurr <<= 8;
+ }
+ for (k = 0; k < 4; k++) {
+ BYTE b = (BYTE)(dwCurr >> 26);
+ *szDest++ = s_chBase64EncodingTable[b];
+ dwCurr <<= 6;
+ }
+ }
+ nWritten += nLen3 * 4;
+
+ if ((dwFlags & BASE64_FLAG_NOCRLF) == 0) {
+ *szDest++ = '\r';
+ *szDest++ = '\n';
+ *szDest++ = '\t'; // as vcards have tabs in second line of binary data
+ nWritten += 3;
+ }
+ }
+
+ if (nWritten && (dwFlags & BASE64_FLAG_NOCRLF) == 0) {
+ szDest -= 2;
+ nWritten -= 2;
+ }
+
+ nLen2 = nSrcLen % 3 ? nSrcLen % 3 + 1 : 0;
+ if (nLen2) {
+ DWORD dwCurr(0);
+ for (n = 0; n < 3; n++)
+ {
+ if (n < (nSrcLen % 3))
+ dwCurr |= *pbSrcData++;
+ dwCurr <<= 8;
+ }
+ for (k = 0; k < nLen2; k++) {
+ BYTE b = (BYTE)(dwCurr >> 26);
+ *szDest++ = s_chBase64EncodingTable[b];
+ dwCurr <<= 6;
+ }
+ nWritten+= nLen2;
+ if ((dwFlags & BASE64_FLAG_NOPAD) == 0) {
+ nLen3 = nLen2 ? 4 - nLen2 : 0;
+ for (j = 0; j < nLen3; j++) {
+ *szDest++ = '=';
+ }
+ nWritten+= nLen3;
+ }
+ }
+
+ *pnDestLen = nWritten;
+ return TRUE;
+}
+
+inline INT_PTR DecodeBase64Char(UINT ch) throw()
+{
+ // returns -1 if the character is invalid
+ // or should be skipped
+ // otherwise, returns the 6-bit code for the character
+ // from the encoding table
+ if (ch >= 'A' && ch <= 'Z')
+ return ch - 'A' + 0; // 0 range starts at 'A'
+ if (ch >= 'a' && ch <= 'z')
+ return ch - 'a' + 26; // 26 range starts at 'a'
+ if (ch >= '0' && ch <= '9')
+ return ch - '0' + 52; // 52 range starts at '0'
+ if (ch == '+')
+ return 62;
+ if (ch == '/')
+ return 63;
+ return -1;
+}
+
+inline BOOL Base64Decode(LPCSTR szSrc, INT_PTR nSrcLen, BYTE *pbDest, INT_PTR *pnDestLen) throw()
+{
+ // walk the source buffer
+ // each four character sequence is converted to 3 bytes
+ // CRLFs and =, and any characters not in the encoding table
+ // are skiped
+
+ if (szSrc == NULL || pnDestLen == NULL) {
+ return FALSE;
+ }
+
+ LPCSTR szSrcEnd = szSrc + nSrcLen;
+ INT_PTR nWritten = 0;
+
+ BOOL bOverflow = (pbDest == NULL) ? TRUE : FALSE;
+
+ while (szSrc < szSrcEnd) {
+ DWORD dwCurr = 0;
+ INT_PTR i;
+ INT_PTR nBits = 0;
+ for (i=0; i<4; i++) {
+ if (szSrc >= szSrcEnd)
+ break;
+ INT_PTR nCh = DecodeBase64Char(*szSrc);
+ szSrc++;
+ if (nCh == -1) {
+ // skip this char
+ i--;
+ continue;
+ }
+ dwCurr <<= 6;
+ dwCurr |= nCh;
+ nBits += 6;
+ }
+
+ if (!bOverflow && nWritten + (nBits/8) > (*pnDestLen))
+ bOverflow = TRUE;
+
+ // dwCurr has the 3 bytes to write to the output buffer
+ // left to right
+ dwCurr <<= 24-nBits;
+ for (i=0; i<nBits/8; i++) {
+ if (!bOverflow) {
+ *pbDest = (BYTE) ((dwCurr & 0x00ff0000) >> 16);
+ pbDest++;
+ }
+ dwCurr <<= 8;
+ nWritten++;
+ }
+ }
+ *pnDestLen = nWritten;
+ return bOverflow ? FALSE:TRUE;
+}
+
+//=======================================================================
+// Quoted Printable encode/decode
+// compliant with RFC 2045
+//=======================================================================
+//
+#define TSSMTPQPENCODE_DOT 1
+#define TSSMTPQPENCODE_TRAILING_SOFT 2
+
+inline INT_PTR QPEncodeGetRequiredLength(INT_PTR nSrcLen)
+{
+ INT_PTR nRet = 3*((3*nSrcLen)/(TSSMTPMAX_QP_LINE_LENGTH-8));
+ nRet += 3*nSrcLen;
+ nRet += 3;
+ return nRet;
+}
+
+inline INT_PTR QPDecodeGetRequiredLength(INT_PTR nSrcLen)
+{
+ return nSrcLen;
+}
+
+inline BOOL QPEncode(BYTE* pbSrcData, INT_PTR nSrcLen, LPSTR szDest, INT_PTR* pnDestLen, BOOLEAN *bEncoded, DWORD dwFlags = 0)
+{
+ //The hexadecimal character set
+ static const CHAR s_chHexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'A', 'B', 'C', 'D', 'E', 'F'};
+ INT_PTR nRead = 0, nWritten = 0, nLineLen = 0;
+ CHAR ch;
+ BOOLEAN bChanged = FALSE;
+
+
+ if (!pbSrcData || !szDest || !pnDestLen) {
+ return FALSE;
+ }
+
+ while (nRead < nSrcLen) {
+ ch = *pbSrcData++;
+ nRead++;
+ if (nLineLen == 0 && ch == '.' && (dwFlags & TSSMTPQPENCODE_DOT)) {
+ *szDest++ = '.';
+ nWritten++;
+ nLineLen++;
+ bChanged = TRUE;
+ }
+ if ((ch > 32 && ch < 61) || (ch > 61 && ch < 127)) {
+ *szDest++ = ch;
+ nWritten++;
+ nLineLen++;
+ }
+ else
+ if ((ch == ' ' || ch == '\t') && (nLineLen < (TSSMTPMAX_QP_LINE_LENGTH - 12))) {
+ *szDest++ = ch;
+ nWritten++;
+ nLineLen++;
+ }
+ else {
+ *szDest++ = '=';
+ *szDest++ = s_chHexChars[(ch >> 4) & 0x0F];
+ *szDest++ = s_chHexChars[ch & 0x0F];
+ nWritten += 3;
+ nLineLen += 3;
+ bChanged = TRUE;
+ }
+ if (nLineLen >= (TSSMTPMAX_QP_LINE_LENGTH - 11)) {
+ *szDest++ = '=';
+ *szDest++ = '\r';
+ *szDest++ = '\n';
+ nLineLen = 0;
+ nWritten += 3;
+ bChanged = TRUE;
+ }
+ }
+ if (dwFlags & TSSMTPQPENCODE_TRAILING_SOFT) {
+ *szDest++ = '=';
+ *szDest++ = '\r';
+ *szDest++ = '\n';
+ nWritten += 3;
+ bChanged = TRUE;
+ }
+ *pnDestLen = nWritten;
+ if (bEncoded) *bEncoded = bChanged;
+ return TRUE;
+}
+
+
+inline BOOL QPDecode(BYTE* pbSrcData, INT_PTR nSrcLen, LPSTR szDest, INT_PTR* pnDestLen, DWORD dwFlags = 0)
+{
+ if (!pbSrcData || !szDest || !pnDestLen)
+ {
+ return FALSE;
+ }
+
+ INT_PTR nRead = 0, nWritten = 0, nLineLen = -1;
+ char ch;
+ while (nRead <= nSrcLen)
+ {
+ ch = *pbSrcData++;
+ nRead++;
+ nLineLen++;
+ if (ch == '=')
+ {
+ //if the next character is a digit or a character, convert
+ if (nRead < nSrcLen && (isdigit(*pbSrcData) || isalpha(*pbSrcData)))
+ {
+ char szBuf[5];
+ szBuf[0] = *pbSrcData++;
+ szBuf[1] = *pbSrcData++;
+ szBuf[2] = '\0';
+ char* tmp = '\0';
+ *szDest++ = (BYTE)strtoul(szBuf, &tmp, 16);
+ nWritten++;
+ nRead += 2;
+ continue;
+ }
+ //if the next character is a carriage return or line break, eat it
+ if (nRead < nSrcLen && *pbSrcData == '\r' && (nRead+1 < nSrcLen) && *(pbSrcData+1)=='\n')
+ {
+ pbSrcData++;
+ nRead++;
+ nLineLen = -1;
+ continue;
+ }
+ return FALSE;
+ }
+ if (ch == '\r' || ch == '\n')
+ {
+ nLineLen = -1;
+ continue;
+ }
+ if ((dwFlags & TSSMTPQPENCODE_DOT) && ch == '.' && nLineLen == 0)
+ {
+ continue;
+ }
+ *szDest++ = ch;
+ nWritten++;
+ }
+
+ *pnDestLen = nWritten-1;
+ return TRUE;
+}
diff --git a/plugins/UserInfoEx/ex_import/svc_ExImINI.cpp b/plugins/UserInfoEx/ex_import/svc_ExImINI.cpp
new file mode 100644
index 0000000000..f3c4ce6362
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/svc_ExImINI.cpp
@@ -0,0 +1,547 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/svc_ExImINI.cpp $
+Revision : $Revision: 196 $
+Last change on : $Date: 2010-09-21 03:24:30 +0400 (Вт, 21 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+/**
+ * system & local includes:
+ **/
+#include "commonheaders.h"
+#include "classExImContactBase.h"
+#include "dlg_ExImModules.h"
+#include "svc_ExImport.h"
+#include "svc_ExImINI.h"
+
+/**
+ * Miranda includes
+ **/
+#include <m_protocols.h>
+#include <m_protosvc.h>
+
+/***********************************************************************************************************
+ * exporting stuff
+ ***********************************************************************************************************/
+
+/**
+ * name: ExportModule
+ * desc: write all settings from a database module to file
+ * param: hContact - handle of contact the module is owned from
+ * pszModule - name of the module to save
+ * file - file to write the settings to
+ * return nothing
+ **/
+static VOID ExportModule(HANDLE hContact, LPCSTR pszModule, FILE* file)
+{
+ DB::CEnumList Settings;
+
+ if (!Settings.EnumSettings(hContact, pszModule))
+ {
+ DBVARIANT dbv;
+ LPSTR here;
+ WORD j;
+ INT i;
+ LPSTR pszSetting;
+ //char tmp[32];
+
+ // print the module header..
+ fprintf(file, "\n[%s]\n", pszModule);
+
+ for (i = 0; i < Settings.getCount(); i++)
+ {
+ pszSetting = Settings[i];
+
+ if (!DB::Setting::GetAsIs(hContact, pszModule, pszSetting, &dbv))
+ {
+ switch (dbv.type)
+ {
+ case DBVT_BYTE:
+ {
+ fprintf(file, "%s=b%u\n", pszSetting, dbv.bVal);
+ }
+ break;
+
+ case DBVT_WORD:
+ {
+ fprintf(file, "%s=w%u\n", pszSetting, dbv.wVal);
+ }
+ break;
+
+ case DBVT_DWORD:
+ {
+ fprintf(file, "%s=d%u\n", pszSetting, dbv.dVal);
+ }
+ break;
+
+ case DBVT_ASCIIZ:
+ case DBVT_UTF8:
+ {
+ for (here = dbv.pszVal; here && *here; here++)
+ {
+ switch (*here) {
+ // convert \r to STX
+ case '\r':
+ *here = 2;
+ break;
+
+ // convert \n to ETX
+ case '\n':
+ *here = 3;
+ }
+ }
+ if (dbv.type == DBVT_UTF8)
+ fprintf(file, "%s=u%s\n", pszSetting, dbv.pszVal);
+ else
+ fprintf(file, "%s=s%s\n", pszSetting, dbv.pszVal);
+ }
+ break;
+
+ case DBVT_BLOB:
+ {
+ fprintf(file, "%s=n", pszSetting);
+ for (j = 0; j < dbv.cpbVal; j++)
+ {
+ fprintf(file, "%02X ", (BYTE)dbv.pbVal[j]);
+ }
+ fputc('\n', file);
+ }
+ break;
+ }
+ DB::Variant::Free(&dbv);
+ }
+ }
+ }
+}
+
+/**
+ * name: ExportContact
+ * desc: Exports a certain contact to an ini file.
+ * param: hContact - contact to export or -1 to export all contacts
+ * pModules - module to export, NULL to export all modules of a contact
+ * file - ini file to write the contact to
+ **/
+static BOOLEAN ExportContact(HANDLE hContact, DB::CEnumList* pModules, FILE* file)
+{
+ CExImContactBase vcc;
+
+ if (pModules)
+ {
+ if ((vcc = hContact) >= NULL)
+ {
+ INT i;
+ LPSTR p;
+
+ vcc.toIni(file, pModules->getCount()-1);
+
+ for (i = 0; i < pModules->getCount(); i++)
+ {
+ p = (*pModules)[i];
+
+ /*Filter/
+ if (mir_stricmp(p, "Protocol"))*/
+ {
+ ExportModule(hContact, p, file);
+ }
+ }
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/**
+ * name: SvcExImINI_Export
+ * desc: Exports a certain contact or all contacts to an ini file.
+ * param: hContact - contact to export or -1 to export all contacts
+ * pszFileName - ini-filename to write the contact to
+ **/
+INT SvcExImINI_Export(lpExImParam ExImContact, LPCSTR pszFileName)
+{
+ FILE* file;
+ errno_t err;
+ DB::CEnumList Modules;
+ SYSTEMTIME now;
+ HANDLE hContact;
+
+ if (!DlgExImModules_SelectModulesToExport(ExImContact, &Modules, NULL))
+ {
+ if ((err = fopen_s(&file, pszFileName, "wt")) != NULL)
+ {
+ MsgErr(NULL,
+ LPGENT("The ini-file \"%s\"\nfor saving contact information could not be opened."),
+ pszFileName);
+ return 1;
+ }
+
+ SetCursor(LoadCursor(NULL, IDC_WAIT));
+
+ // write header
+ GetLocalTime(&now);
+ fprintf(file,
+ ";DATE = %04d-%02d-%02d %02d:%02d:%02d\n\n",
+ now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond
+ );
+
+ if (Modules.getCount() == 0)
+ {
+ Modules.EnumModules();
+ }
+
+ // hContact == -1 export entire db.
+ if (ExImContact->Typ != EXIM_CONTACT)
+ {
+ // Owner
+ ExportContact(NULL, &Modules, file);
+ fprintf(file, "\n\n");
+ // Contacts
+ for (hContact = DB::Contact::FindFirst();
+ hContact != NULL;
+ hContact = DB::Contact::FindNext(hContact))
+ {
+ ExportContact(hContact, &Modules, file);
+ fprintf(file, "\n\n");
+ }
+ }
+ // export only one contact
+ else
+ {
+ ExportContact(ExImContact->hContact, &Modules, file);
+ }
+
+ if (file)
+ fclose(file);
+ SetCursor(LoadCursor(NULL, IDC_ARROW));
+ }
+ return 0;
+}
+
+/***********************************************************************************************************
+ * importing stuff
+ ***********************************************************************************************************/
+
+LPSTR strnrchr(LPSTR string, INT ch, DWORD len)
+{
+ LPSTR start = (LPSTR)string;
+
+ string += len; /* find end of string */
+ /* search towards front */
+ while (--string != start && *string != (CHAR)ch);
+ if (*string == (CHAR)ch) /* char found ? */
+ return ((LPSTR)string);
+ return(NULL);
+}
+
+/**
+ * name: ImportreadLine
+ * desc: read exactly one line into a buffer and return its pointer. Size of buffer is managed.
+ * param: file - pointer to a file
+ * string - the string to write the read line to
+ * return: pointer to the buffer on success or NULL on error
+ **/
+static DWORD ImportreadLine(FILE* file, LPSTR &str)
+{
+ CHAR c;
+ DWORD l = 0;
+ BOOLEAN bComment = 0;
+
+ str[0] = 0;
+ while (!feof(file)) {
+ switch (c = fgetc(file)) {
+ case EOF:
+ // reading error
+ if (ferror(file)) {
+ MIR_FREE(str);
+ return 0;
+ }
+ // end of line & file
+ return l;
+
+ case '\r':
+ case '\n':
+ // ignore empty lines
+ if (l == 0) {
+ bComment = 0;
+ continue;
+ }
+ return l;
+
+ case ';':
+ // found a comment line
+ bComment |= l == 0;
+ case '\t':
+ case ' ':
+ // ignore space and tab at the beginning of the line
+ if (l == 0) break;
+
+ default:
+ if (!bComment) {
+ str = mir_strncat_c(str, c);
+ l++;
+ }
+ break;
+ }
+ }
+ return 0;
+}
+
+/**
+ * name: ImportFindContact
+ * desc: This function decodes the given line, which is already identified to be a contact line.
+ * The resulting information is matcht to the given hContact if it isn't NULL.
+ * Otherwise all existing contacts are matched.
+ * param: hContact - handle to contact to match or NULL to match all existing
+ * pszBuf - pointer to the buffer holding the string of the current line in the ini.-file
+ * cchBuf - character count of the buffer
+ * return: handle to the contact that matches the information or NULL if no match
+ **/
+static HANDLE ImportFindContact(HANDLE hContact, LPSTR &strBuf, BOOLEAN bCanCreate)
+{
+ CExImContactBase vcc;
+
+ vcc.fromIni(strBuf);
+ if (vcc.handle() != INVALID_HANDLE_VALUE) {
+ //if (vcc.isHandle(hContact))
+ // return hContact;
+ return vcc.handle();
+ }
+ else if (bCanCreate)
+ return vcc.toDB();
+
+ return vcc.handle();
+}
+
+/**
+ * name: ImportSetting
+ * desc: This function writes a line identified as a setting to the database
+ * param: hContact - handle to contact to match or NULL to match all existing
+ * pszModule - module to write the setting to
+ * strLine - string with the setting and its value to write to db
+ * return: 0 if writing was ok, 1 otherwise
+ **/
+INT ImportSetting(HANDLE hContact, LPCSTR pszModule, LPSTR &strLine)
+{
+ DBCONTACTWRITESETTING cws;
+ LPSTR end, value;
+ size_t numLines = 0;
+ size_t brk;
+ LPSTR pszLine = strLine;
+
+ // check Module and filter "Protocol"
+ if (!pszModule || !*pszModule || mir_strncmp(pszModule,"Protocol",8) == 0)
+ return 1;
+ if ((end = value = mir_strchr(pszLine, '=')) == NULL)
+ return 1;
+
+ // truncate setting string if it has spaces at the end
+ do {
+ if (end == pszLine)
+ return 1;
+ *(end--) = 0;
+ } while (*end == '\t' || *end == ' ' || *end < 27);
+
+ cws.szModule = pszModule;
+ cws.szSetting = pszLine;
+
+ // skip spaces from the beginning of the value
+ do {
+ value++;
+ // if the value is empty, delete it from db
+ if (*value == '\0')
+ return DB::Setting::Delete(hContact, pszModule, pszLine);
+ } while (*value == '\t' || *value == ' ');
+
+ // decode database type and value
+ switch (*(value++)) {
+ case 'b':
+ case 'B':
+ if (brk = strspn(value, "0123456789-"))
+ *(value + brk) = 0;
+ cws.value.type = DBVT_BYTE;
+ cws.value.bVal = (BYTE)atoi(value);
+ break;
+ case 'w':
+ case 'W':
+ if (brk = strspn(value, "0123456789-"))
+ *(value + brk) = 0;
+ cws.value.type = DBVT_WORD;
+ cws.value.wVal = (WORD)atoi(value);
+ break;
+ case 'd':
+ case 'D':
+ if (brk = strspn(value, "0123456789-"))
+ *(value + brk) = 0;
+ cws.value.type = DBVT_DWORD;
+ cws.value.dVal = (DWORD)_atoi64(value);
+ break;
+ case 's':
+ case 'S':
+ case 'u':
+ case 'U':
+ for (end = value; end && *end; end++) {
+ switch (*end) {
+ // convert STX back to \r
+ case 2:
+ *end = '\r';
+ break;
+ // convert ETX back to \n
+ case 3:
+ *end = '\n';
+ break;
+ }
+ }
+ switch (*(value - 1)) {
+ case 's':
+ case 'S':
+ cws.value.type = DBVT_ASCIIZ;
+ cws.value.pszVal = value;
+ break;
+ case 'u':
+ case 'U':
+ cws.value.type = DBVT_UTF8;
+ cws.value.pszVal = value;
+ break;
+ }
+ break;
+ case 'n':
+ case 'N':
+ {
+ PBYTE dest;
+ cws.value.type = DBVT_BLOB;
+ cws.value.cpbVal = (WORD)mir_strlen(value) / 3;
+ cws.value.pbVal = (PBYTE)value;
+ for ( dest = cws.value.pbVal, value = strtok(value, " ");
+ value && *value;
+ value = strtok(NULL, " "))
+ *(dest++) = (BYTE)strtol(value, NULL, 16);
+ *dest = 0;
+ break;
+ }
+ default:
+ cws.value.type = DBVT_DELETED;
+ //return 1;
+ }
+ return CallService(MS_DB_CONTACT_WRITESETTING, (WPARAM)hContact, (LPARAM)&cws);
+}
+
+/**
+ * name: Import
+ * desc: This function imports an ini file
+ * param: hContact - handle to contact to match or NULL to match all existing
+ * file - module to write the setting to
+ * strLine - string with the setting and its value to write to db
+ * return: 0 if writing was ok, 1 otherwise
+ **/
+INT SvcExImINI_Import(HANDLE hContact, LPCSTR pszFileName)
+{
+ FILE *file;
+ HANDLE hNewContact = INVALID_HANDLE_VALUE;
+ DWORD end,
+ numLines = 0;
+ CHAR szModule[MAXSETTING] = {0};
+ WORD numContactsInFile = 0, // number of contacts in the inifile
+ numContactsAdded = 0; // number of contacts, that were added to the database
+ CHAR *strBuf = (CHAR *) mir_alloc(1);
+ *strBuf = 0;
+
+ if (file = fopen(pszFileName, "rt")) {
+ SetCursor(LoadCursor(NULL, IDC_WAIT));
+
+ while (ImportreadLine(file, strBuf)) {
+ numLines++;
+
+ // contact was found and imported
+ if (hContact != INVALID_HANDLE_VALUE && hNewContact != INVALID_HANDLE_VALUE)
+ break;
+
+ // importing settings is only valid vor the main menu item
+ if (hContact == INVALID_HANDLE_VALUE) {
+ if (!strncmp(strBuf, "SETTINGS:", 9)) {
+ *szModule = 0;
+ hNewContact = NULL;
+ continue;
+ }
+ }
+
+ // there are some modules of a contact (import only if contact exist)
+ if (!strncmp(strBuf, "FROM CONTACT:", 13)) {
+ strBuf = mir_strnerase(strBuf, 0, 13);
+ while (strBuf[0] == ' ' || strBuf[0] == '\t')
+ strBuf = mir_strnerase(strBuf, 0, 1);
+
+ numContactsInFile++;
+ if ((hNewContact = ImportFindContact(hContact, strBuf, FALSE)) != INVALID_HANDLE_VALUE)
+ numContactsAdded++;
+ continue;
+ }
+
+ // there is a contact to import / add
+ if (!strncmp(strBuf, "CONTACT:", 8)) {
+ strBuf = mir_strnerase(strBuf, 0, 8);
+ while (strBuf[0] == ' ' || strBuf[0] == '\t')
+ strBuf = mir_strnerase(strBuf, 0, 1);
+
+ *szModule = 0;
+ numContactsInFile++;
+ if ((hNewContact = ImportFindContact(hContact, strBuf, TRUE)) != INVALID_HANDLE_VALUE)
+ numContactsAdded++;
+ continue;
+ }
+
+ // read modules and settings only for valid contacts
+ if (hNewContact != INVALID_HANDLE_VALUE) {
+ // found a module line
+ if (strBuf[0] == '[' && (end = (strchr(strBuf, ']') - strBuf)) > 0) {
+ mir_strncpy(szModule, &strBuf[1], end);
+ continue;
+ }
+ // try to import a setting
+ ImportSetting(hNewContact, szModule, strBuf);
+ }
+ } //end while
+ fclose(file);
+ mir_free(strBuf);
+ SetCursor(LoadCursor(NULL, IDC_ARROW));
+
+ // the contact was not found in the file
+ if (numContactsInFile > 0 && !numContactsAdded) {
+ MsgErr(NULL,
+ LPGENT("None of the %d contacts, stored in the ini-file, match the selected contact!\nNothing will be imported"),
+ numContactsInFile);
+ }
+ // Import complete
+ else{
+ MsgBox(NULL, MB_ICON_INFO, LPGENT("Import complete"), LPGENT("Some basic statistics"),
+ LPGENT("Added %d of %d contacts stored in the ini-file."),
+ numContactsAdded, numContactsInFile);
+ }
+ return 0;
+ }
+ MsgErr(NULL,
+ LPGENT("The ini-file \"%s\"\nfor reading contact information could not be opened."),
+ pszFileName);
+ return 1;
+}
diff --git a/plugins/UserInfoEx/ex_import/svc_ExImINI.h b/plugins/UserInfoEx/ex_import/svc_ExImINI.h
new file mode 100644
index 0000000000..63ecce7cbd
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/svc_ExImINI.h
@@ -0,0 +1,39 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/svc_ExImINI.h $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#ifndef _SVC_EXIMINI_H_
+#define _SVC_EXIMINI_H_
+
+#pragma once
+
+ INT SvcExImINI_Export(lpExImParam ExImContact, LPCSTR pszFileName);
+ INT SvcExImINI_Import(HANDLE hContact, LPCSTR pszFileName);
+
+#endif /* _SVC_EXIMINI_H_ */
diff --git a/plugins/UserInfoEx/ex_import/svc_ExImVCF.cpp b/plugins/UserInfoEx/ex_import/svc_ExImVCF.cpp
new file mode 100644
index 0000000000..53faf60c02
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/svc_ExImVCF.cpp
@@ -0,0 +1,1364 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/svc_ExImVCF.cpp $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+/**
+ * system & local includes:
+ **/
+#include "commonheaders.h"
+#include "../svc_reminder.h"
+#include "svc_ExImport.h"
+#include "svc_ExImVCF.h"
+
+#include <m_protosvc.h>
+
+#define BLOCKSIZE 260
+
+#define DELIM ";"
+
+/**
+ * name: IsUSASCII
+ * desc: determine whether the pBuffer string is ascii or not
+ * param: pBuffer - string to check
+ *
+ * return TRUE or FALSE
+ **/
+BOOLEAN IsUSASCII(LPCSTR pBuffer, LPDWORD pcbBuffer)
+{
+ BYTE c;
+ PBYTE s = (PBYTE)pBuffer;
+ BOOLEAN bIsUTF = 0;
+
+ if (s == NULL) return 1;
+ while ((c = *s++) != 0) {
+ if (c < 0x80) continue;
+ if (!pcbBuffer) return 0;
+ bIsUTF = 1;
+ }
+ if (pcbBuffer) *pcbBuffer = s - (PBYTE)pBuffer;
+ return !bIsUTF;
+}
+
+/*
+=========================================================================================================================
+ class CLineBuffer
+=========================================================================================================================
+*/
+
+
+/**
+ * name: CLineBuffer::CLineBuffer
+ * desc: initializes all members on construction of the class
+ * param: none
+ *
+ * return: nothing
+ **/
+CLineBuffer::CLineBuffer()
+{
+ _pVal = NULL;
+ _pTok = NULL;
+ _cbVal = 0;
+ _cbUsed = 0;
+}
+
+/**
+ * name: CLineBuffer::~CLineBuffer
+ * desc: frees up all memory on class destruction
+ * param: none
+ *
+ * return: nothing
+ **/
+CLineBuffer::~CLineBuffer()
+{
+ if (_pVal) mir_free(_pVal);
+}
+
+/**
+ * name: CLineBuffer::_resizeBuf
+ * desc: ensure, the right size for the buffer
+ * param: cbReq - number of bytes required for the next operation
+ *
+ * return: TRUE if reallocation successful or memoryblock is large enough, FALSE otherwise
+ **/
+BOOLEAN CLineBuffer::_resizeBuf(const size_t cbReq)
+{
+ if (cbReq > _cbVal - _cbUsed) {
+ if (!(_pVal = (PBYTE)mir_realloc(_pVal, BLOCKSIZE + _cbVal + 1))) {
+ _cbVal = 0;
+ _cbUsed = 0;
+ return FALSE;
+ }
+ _cbVal += BLOCKSIZE;
+ }
+ return TRUE;
+}
+
+/**
+ * name: CLineBuffer::operator =
+ * desc: applys the specified string to the class's _pVal member
+ * param: szVal - string to apply
+ *
+ * return: length of the string, added
+ **/
+size_t CLineBuffer::operator = (const CHAR *szVal)
+{
+ if (szVal) {
+ size_t cbLength = mir_strlen(szVal);
+
+ _cbUsed = 0;
+ if (_resizeBuf(cbLength)) {
+ memcpy(_pVal, szVal, cbLength);
+ _cbUsed += cbLength;
+ return cbLength;
+ }
+ }
+ return 0;
+}
+
+/**
+ * name: CLineBuffer::operator +
+ * desc: appends the specified string to the class's _pVal member
+ * param: szVal - string to add
+ *
+ * return: length of the string, added
+ **/
+size_t CLineBuffer::operator + (const CHAR *szVal)
+{
+ if (szVal) {
+ size_t cbLength = mir_strlen(szVal);
+
+ if (_resizeBuf(cbLength)) {
+ memcpy(_pVal + _cbUsed, szVal, cbLength);
+ _cbUsed += cbLength;
+ return cbLength;
+ }
+ }
+ return 0;
+}
+
+/**
+ * name: CLineBuffer::operator +
+ * desc: appends the specified unicode string to the class's _pVal member
+ * param: wszVal - string to add
+ *
+ * return: length of the string, added
+ **/
+size_t CLineBuffer::operator + (const WCHAR *wszVal)
+{
+ if (wszVal) {
+ size_t cbLength = mir_wcslen(wszVal);
+ CHAR* szVal = mir_u2a(wszVal);
+
+ if (szVal) {
+ size_t cbLength = mir_strlen(szVal);
+
+ if (_resizeBuf(cbLength)) {
+ memcpy(_pVal + _cbUsed, szVal, cbLength);
+ _cbUsed += cbLength;
+ return cbLength;
+ }
+ }
+ }
+ return 0;
+}
+
+/**
+ * name: CLineBuffer::operator +
+ * desc: appends the specified character's value (-127 ... 128) as a string to the class's _pVal member
+ * param: cVal - character whose value to add
+ *
+ * return: length of the string, added
+ **/
+size_t CLineBuffer::operator + (const CHAR cVal)
+{
+ if (_resizeBuf(1)) {
+ *(_pVal + _cbUsed++) = cVal;
+ return 1;
+ }
+ return 0;
+}
+
+/**
+ * name: CLineBuffer::operator +
+ * desc: appends the specified bytes's value (0 ... 255) as a string to the class's _pVal member
+ * param: bVal - character whose value to add
+ *
+ * return: length of the string, added
+ **/
+size_t CLineBuffer::operator + (const BYTE bVal)
+{
+ size_t cbLength = 3;
+
+ if (_resizeBuf(cbLength)) {
+ cbLength = mir_strlen(_itoa(bVal, (LPSTR)(_pVal + _cbUsed), 10));
+ _cbUsed += cbLength;
+ return cbLength;
+ }
+ return 0;
+}
+
+/**
+ * name: CLineBuffer::operator +
+ * desc: appends the specified short integer as a string to the class's _pVal member
+ * param: sVal - short integer whose value to add
+ *
+ * return: length of the string, added
+ **/
+size_t CLineBuffer::operator + (const SHORT sVal)
+{
+ size_t cbLength = 6;
+
+ if (_resizeBuf(cbLength)) {
+ cbLength = mir_strlen(_itoa(sVal, (LPSTR)(_pVal + _cbUsed), 10));
+ _cbUsed += cbLength;
+ return cbLength;
+ }
+ return 0;
+}
+
+/**
+ * name: CLineBuffer::operator +
+ * desc: appends the specified word as a string to the class's _pVal member
+ * param: wVal - word whose value to add
+ *
+ * return: length of the string, added
+ **/
+size_t CLineBuffer::operator + (const WORD wVal)
+{
+ size_t cbLength = 5;
+
+ if (_resizeBuf(cbLength)) {
+ cbLength = mir_strlen(_itoa(wVal, (LPSTR)(_pVal + _cbUsed), 10));
+ _cbUsed += cbLength;
+ return cbLength;
+ }
+ return 0;
+}
+
+/**
+ * name: CLineBuffer::operator +
+ * desc: appends the specified long integer as a string to the class's _pVal member
+ * param: lVal - long integer whose value to add
+ *
+ * return: length of the string, added
+ **/
+size_t CLineBuffer::operator + (const LONG lVal)
+{
+ size_t cbLength = 11;
+
+ if (_resizeBuf(cbLength)) {
+ cbLength = mir_strlen(_ltoa(lVal, (LPSTR)(_pVal + _cbUsed), 10));
+ _cbUsed += cbLength;
+ return cbLength;
+ }
+ return 0;
+}
+
+/**
+ * name: CLineBuffer::operator +
+ * desc: appends the specified double word integer as a string to the class's _pVal member
+ * param: dVal - double word integer whose value to add
+ *
+ * return: length of the string, added
+ **/
+size_t CLineBuffer::operator + (const DWORD dVal)
+{
+ size_t cbLength = 10;
+
+ if (_resizeBuf(cbLength)) {
+ cbLength = mir_strlen(_ltoa(dVal, (LPSTR)(_pVal + _cbUsed), 10));
+ _cbUsed += cbLength;
+ return cbLength;
+ }
+ return 0;
+}
+
+/**
+ * name: CLineBuffer::GetLength
+ * desc: returns the length of the _pVal string
+ * param: nothing
+ *
+ * return: length of the string
+ **/
+size_t CLineBuffer::GetLength()
+{
+ return _cbUsed;
+}
+
+/**
+ * name: CLineBuffer::GetBuffer
+ * desc: returns the pointer of the _pVal string
+ * !!Use carefully
+ * param: nothing
+ *
+ * return: pointer to _pVal
+ **/
+LPCSTR CLineBuffer::GetBuffer()
+{
+ return (LPCSTR)_pVal;
+}
+
+/**
+ * name: CLineBuffer::TruncToLength
+ * desc: resulting string has cbLength characters
+ * param: cbLength - desired length of the string member
+ *
+ * return: nothing
+ **/
+VOID CLineBuffer::TruncToLength(size_t cbLength)
+{
+ if (cbLength < _cbUsed) {
+ _cbUsed = cbLength;
+ _pVal[cbLength] = 0;
+ }
+}
+
+/**
+ * name: CLineBuffer::TruncToLength
+ * desc: resulting string is Truncated by the specified number of bytes
+ * param: count - desired count of bytes to Truncate
+ *
+ * return: nothing
+ **/
+VOID CLineBuffer::Truncate(size_t count)
+{
+ if (_cbUsed <= count) {
+ _cbUsed = 0;
+ *_pVal = 0;
+ }
+ else {
+ _cbUsed -= count;
+ _pVal[_cbUsed] = 0;
+ }
+}
+
+/**
+ * name: CLineBuffer::TruncateSMS
+ * desc: resulting string is Truncated by the " SMS" if found
+ * param: nothing
+ *
+ * return: nothing
+ **/
+VOID CLineBuffer::TruncateSMS()
+{
+ if (!strncmp((LPSTR)(_pVal + _cbUsed - 4), " SMS", 4)) {
+ _cbUsed -= 4;
+ _pVal[_cbUsed] = 0;
+ }
+}
+
+/**
+ * name: CLineBuffer::fput
+ * desc: string member is written to the specified stream and Truncated to zero afterwards
+ * param: outfile - the stream to write to
+ *
+ * return: nothing
+ **/
+VOID CLineBuffer::fput(FILE *outfile)
+{
+ if (_pVal) {
+ _pVal[_cbUsed] = 0;
+ fputs((LPCSTR)_pVal, outfile);
+ _cbUsed = 0;
+ *_pVal = 0;
+ }
+}
+
+/**
+ * name: CLineBuffer::fputEncoded
+ * desc: string member is encoded and written to the specified stream and Truncated to zero afterwards
+ * param: outfile - the stream to write to
+ *
+ * return: nothing
+ **/
+VOID CLineBuffer::fputEncoded(FILE *outFile)
+{
+ PBYTE pVal = _pVal;
+
+ if (pVal && _cbUsed > 0) {
+ _pVal[_cbUsed] = 0;
+ while (_cbUsed > 0 && *pVal) {
+ switch (*pVal) {
+ // translate special characters
+ case ':':
+ case ';':
+ case '\r':
+ case '\n':
+ case '\t':
+ fprintf(outFile, "=%02X", *pVal);
+ break;
+ // Some database texts may contain encoded escapes, that have to be translated too.
+ case '\\':
+ if (*(pVal+1) == 'r') {
+ fprintf(outFile, "=%02X", '\r');
+ pVal++;
+ break;
+ }
+ if (*(pVal+1) == 't') {
+ fprintf(outFile, "=%02X", '\t');
+ pVal++;
+ break;
+ }
+ if (*(pVal+1) == 'n') {
+ fprintf(outFile, "=%02X", '\n');
+ pVal++;
+ break;
+ }
+ // translate all characters which are not contained in the USASCII code
+ default:
+ if (*pVal > 127) fprintf(outFile, "=%02X", *pVal);
+ else fputc(*pVal, outFile);
+ break;
+ }
+ pVal++;
+ (_cbUsed)--;
+ }
+ *_pVal = 0;
+ }
+}
+
+/**
+ * name: CLineBuffer::fgetEncoded
+ * desc: string member is read from the specified stream decoded
+ * param: outfile - the stream to write to
+ *
+ * return: nothing
+ **/
+INT CLineBuffer::fgetEncoded(FILE *inFile)
+{
+ CHAR c;
+ CHAR hex[3];
+ WORD wAdd = 0;
+
+ hex[2] = 0;
+
+ _cbUsed = 0;
+
+ while (EOF != (c = fgetc(inFile))) {
+ switch (c) {
+ case '\n':
+ if (_cbUsed > 0 && _pVal[_cbUsed - 1] == '\r') {
+ _pVal[--_cbUsed] = 0;
+ wAdd--;
+ }
+ else
+ _pVal[_cbUsed] = 0;
+ return wAdd;
+ case '=':
+ if (_resizeBuf(1)) {
+ fread(hex, 2, 1, inFile);
+ *(_pVal + _cbUsed++) = (BYTE)strtol(hex, NULL, 16);
+ wAdd++;
+ }
+ break;
+ default:
+ if (_resizeBuf(1)) {
+ *(_pVal + _cbUsed++) = c;
+ wAdd++;
+ }
+ break;
+ }
+ }
+ _pVal[_cbUsed] = 0;
+ return _cbUsed > 0 ? wAdd : EOF;
+}
+
+/**
+ * name: CLineBuffer::GetTokenFirst
+ * desc: scans for the first <delim> in the _pVal member and returns all characters
+ * that come before the first <delim> in a new CLineBuffer class
+ * param: delim - the deliminer which delimins the string
+ * pBuf - pointer to a new CLineBuffer class holding the result
+ *
+ * return: length of the found string value
+ **/
+size_t CLineBuffer::GetTokenFirst(const CHAR delim, CLineBuffer * pBuf)
+{
+ PBYTE here;
+ size_t wLength;
+
+ _pTok = _pVal;
+
+ if (!_pTok || !*_pTok)
+ return 0;
+
+ for (here = _pTok;; here++) {
+ if (*here == 0 || *here == '\n' || *here == delim) {
+ wLength = here - _pTok;
+ if (pBuf) {
+ CHAR c = *here;
+ *here = 0;
+ *pBuf = (LPCSTR)_pTok;
+ *here = c;
+ }
+ _pTok = (*here == 0 || *here == '\n') ? NULL : ++here;
+ break;
+ }
+ }
+ return wLength;
+}
+
+/**
+ * name: CLineBuffer::GetTokenNext
+ * desc: scans for the next <delim> in the _pVal member and returns all characters
+ * that come before the first <delim> in a new CLineBuffer class
+ * param: delim - the deliminer which delimins the string
+ * pBuf - pointer to a new CLineBuffer class holding the result
+ *
+ * return: length of the found string value
+ **/
+size_t CLineBuffer::GetTokenNext(const CHAR delim, CLineBuffer * pBuf)
+{
+ PBYTE here;
+ size_t wLength;
+
+ if (!_pTok || !*_pTok)
+ return 0;
+
+ for (here = _pTok;; here++) {
+ if (*here == 0 || *here == '\n' || *here == delim) {
+ wLength = here - _pTok;
+
+ if (pBuf) {
+ CHAR c = *here;
+
+ *here = 0;
+ *pBuf = (LPCSTR)_pTok;
+ *here = c;
+ }
+ _pTok = (*here == 0 || *here == '\n') ? NULL : ++here;
+ break;
+ }
+ }
+ return wLength;
+}
+
+/**
+ * name: CLineBuffer::DBWriteTokenFirst
+ * desc: scans for the first <delim> in the _pVal member and writes all characters
+ * that come before the first <delim> to database
+ * param: hContact - handle to the contact to write the setting to
+ * pszModule - destination module
+ * pszSetting - destination setting for the value
+ * delim - the deliminer which delimins the string
+ *
+ * return: 0 if successful, 1 otherwise
+ **/
+INT CLineBuffer::DBWriteTokenFirst(HANDLE hContact, const CHAR* pszModule, const CHAR* pszSetting, const CHAR delim)
+{
+ PBYTE here;
+ INT iRet = 1;
+ _pTok = _pVal;
+
+ if (_pTok && *_pTok) {
+ for (here = _pTok;; here++) {
+ if (*here == 0 || *here == '\n' || *here == delim) {
+
+ if (here - _pTok > 0) {
+ CHAR c = *here;
+
+ *here = 0;
+ iRet = DB::Setting::WriteAString(hContact, pszModule, pszSetting, (LPSTR)_pTok);
+ *here = c;
+ }
+ _pTok = (*here == 0 || *here == '\n') ? NULL : ++here;
+ break;
+ }
+ }
+ }
+ if (iRet) iRet = DB::Setting::Delete(hContact, pszModule, pszSetting);
+ return iRet;
+}
+
+/**
+ * name: CLineBuffer::GetTokenNext
+ * desc: scans for the next <delim> in the _pVal member and writes all characters
+ * that come before the first <delim> to database
+ * param: hContact - handle to the contact to write the setting to
+ * pszModule - destination module
+ * pszSetting - destination setting for the value
+ * delim - the deliminer which delimins the string
+ *
+ * return: 0 if successful, 1 otherwise
+ **/
+INT CLineBuffer::DBWriteTokenNext(HANDLE hContact, const CHAR* pszModule, const CHAR* pszSetting, const CHAR delim)
+{
+ PBYTE here;
+ INT iRet = 1;
+
+ if (_pTok && *_pTok) {
+ for (here = _pTok;; here++) {
+ if (*here == 0 || *here == '\n' || *here == delim) {
+
+ if (here - _pTok > 0) {
+ CHAR c = *here;
+
+ *here = 0;
+ iRet = DB::Setting::WriteAString(hContact, pszModule, pszSetting, (LPSTR)_pTok);
+ *here = c;
+ }
+ _pTok = (*here == 0 || *here == '\n') ? NULL : ++here;
+ break;
+ }
+ }
+ }
+ if (iRet) iRet = DB::Setting::Delete(hContact, pszModule, pszSetting);
+ return iRet;
+}
+
+/**
+ * name: CLineBuffer::GetTokenNext
+ * desc: writes _pVal member to database
+ * param: hContact - handle to the contact to write the setting to
+ * pszModule - destination module
+ * pszSetting - destination setting for the value
+ *
+ * return: 0 if successful, 1 otherwise
+ **/
+INT CLineBuffer::DBWriteSettingString(HANDLE hContact, const CHAR* pszModule, const CHAR* pszSetting)
+{
+ if (_pVal && _cbUsed > 0)
+ return DB::Setting::WriteAString(hContact, pszModule, pszSetting, (LPSTR)_pVal);
+ return 1;
+}
+
+/*
+=========================================================================================================================
+ class CVCardFileVCF
+=========================================================================================================================
+*/
+
+/**
+ * name: CVCardFileVCF
+ * desc: default constructor
+ * param: none
+ * return none
+ **/
+CVCardFileVCF::CVCardFileVCF()
+{
+ _pFile = NULL;
+ _hContact = INVALID_HANDLE_VALUE;
+ _pszBaseProto = NULL;
+ _hasUtf8 = 0;
+ _useUtf8 = FALSE;
+}
+
+/**
+ * name: CVCardFileVCF::CVCardFileVCF
+ * desc: searches a static stringlist for the occureance of iID and adds
+ * the translated string value to the line buffer
+ * param: pList - pointer to the list to search in
+ * nList - number of items in the list
+ * iID - the id to search for
+ * cbRew - number of characters to truncate the _clVal by before writing to file
+ *
+ * return number of the added bytes
+ **/
+size_t CVCardFileVCF::packList(LPIDSTRLIST pList, UINT nList, INT iID, size_t *cbRew)
+{
+ UINT i;
+ WORD wAdd = 0;
+
+ for (i = 0; i < nList; i++) {
+ if (pList[i].nID == iID) {
+ return (_clVal + pList[i].ptszTranslated);
+ }
+ }
+ if (cbRew) (*cbRew)++;
+ return 0;
+}
+
+/**
+ * name: CVCardFileVCF::GetSetting
+ * desc: trys to read a value from the pszModule and than from the basic protocol module of the contact
+ * where strings are converted to ansi
+ * param: pszModule - module to read the value from
+ * pszSetting - setting to read the value from
+ * dbv - pointer to the structure holding the result
+ *
+ * return value type
+ **/
+BOOLEAN CVCardFileVCF::GetSetting(const CHAR *pszModule, const CHAR *pszSetting, DBVARIANT *dbv)
+{
+ DBCONTACTGETSETTING cgs;
+
+ cgs.szModule = pszModule;
+ cgs.szSetting = pszSetting;
+ cgs.pValue = dbv;
+ dbv->type = _useUtf8 ? DBVT_UTF8 : DBVT_ASCIIZ;
+ dbv->pszVal = NULL;
+ if (!pszModule || CallService(MS_DB_CONTACT_GETSETTING_STR, (WPARAM)_hContact, (LPARAM)&cgs) || (dbv->type == DBVT_ASCIIZ && !dbv->pszVal && !*dbv->pszVal)) {
+ cgs.szModule = _pszBaseProto;
+ cgs.szSetting = pszSetting;
+ cgs.pValue = dbv;
+ dbv->type = DBVT_ASCIIZ;
+ if (!_pszBaseProto || CallService(MS_DB_CONTACT_GETSETTING_STR, (WPARAM)_hContact, (LPARAM)&cgs) || (dbv->type == DBVT_ASCIIZ && !dbv->pszVal && !*dbv->pszVal)) {
+ return DBVT_DELETED;
+ }
+ }
+ _hasUtf8 += _useUtf8 && !IsUSASCII(dbv->pszVal, NULL);
+ return dbv->type;
+}
+
+/**
+ * name: CVCardFileVCF::packDB
+ * desc: read a value from the database and add it to the line buffer
+ * param: pszModule - module to read the value from
+ * pszSetting - setting to read the value from
+ * cbRew - number of characters to truncate the _clVal by before writing to file
+ *
+ * return number of bytes, added to the linebuffer
+ **/
+size_t CVCardFileVCF::packDB(const CHAR *pszModule, const CHAR *pszSetting, size_t *cbRew)
+{
+ DBVARIANT dbv;
+
+ switch (GetSetting(pszModule, pszSetting, &dbv)) {
+ case DBVT_DELETED:
+ if (cbRew) (*cbRew)++;
+ break;
+ case DBVT_BYTE:
+ return _clVal + dbv.bVal;
+ case DBVT_WORD:
+ return _clVal + dbv.wVal;
+ case DBVT_DWORD:
+ return _clVal + dbv.dVal;
+ case DBVT_UTF8:
+ case DBVT_ASCIIZ:
+ {
+ size_t wAdd = _clVal + dbv.pszVal;
+ DB::Variant::Free(&dbv);
+ return wAdd;
+ }
+ default:
+ if (cbRew) (*cbRew)++;
+ DB::Variant::Free(&dbv);
+ break;
+ }
+ return 0;
+}
+
+/**
+ * name: CVCardFileVCF::packDBList
+ * desc: read a value from the database and add a found list item to the line buffer
+ * param: pszModule - module to read the value from
+ * pszSetting - setting to read the value from
+ * GetList - pointer to a function retrieving the list pointer
+ * bSigned - is the read database value signed?
+ * cbRew - number of characters to truncate the _clVal by before writing to file
+ *
+ * return number of bytes, added to the linebuffer
+ **/
+size_t CVCardFileVCF::packDBList(const CHAR *pszModule, const CHAR *pszSetting, MIRANDASERVICE GetList, BOOLEAN bSigned, size_t *cbRew)
+{
+ DBVARIANT dbv;
+ UINT nList;
+ LPIDSTRLIST pList;
+ size_t wAdd = 0;
+
+ GetList((WPARAM)&nList, (LPARAM)&pList);
+ switch (GetSetting(pszModule, pszSetting, &dbv)) {
+ case DBVT_BYTE:
+ wAdd = packList(pList, nList, (INT)(bSigned ? dbv.cVal : dbv.bVal), cbRew);
+ break;
+ case DBVT_WORD:
+ wAdd = packList(pList, nList, (INT)(bSigned ? dbv.sVal : dbv.wVal), cbRew);
+ break;
+ case DBVT_DWORD:
+ wAdd = packList(pList, nList, (INT)(bSigned ? dbv.lVal : dbv.dVal), cbRew);
+ break;
+ case DBVT_UTF8:
+ case DBVT_ASCIIZ:
+ wAdd = _clVal + Translate(dbv.pszVal);
+ DB::Variant::Free(&dbv);
+ break;
+ case DBVT_DELETED:
+ wAdd = 0;
+ break;
+ default:
+ wAdd = 0;
+ DB::Variant::Free(&dbv);
+ break;
+ }
+ if (cbRew) *cbRew = wAdd ? 0 : *cbRew + 1;
+ return wAdd;
+}
+
+/**
+ * name: CVCardFileVCF::writeLine
+ * desc: write a line as clear text to the vcard file
+ * param: szSet - the string, which identifies the line
+ * cbRew - number of characters to truncate the _clVal by before writing to file
+ *
+ * return number of bytes, added to the linebuffer
+ **/
+VOID CVCardFileVCF::writeLine(const CHAR *szSet, size_t *cbRew)
+{
+ if (cbRew) {
+ _clVal.Truncate(*cbRew);
+ *cbRew = 0;
+ }
+ if (_clVal.GetLength() > 0) {
+ fputs(szSet, _pFile);
+ if (_hasUtf8) {
+ fputs(";CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:", _pFile);
+ _clVal.fputEncoded(_pFile);
+ _hasUtf8 = FALSE;
+ }
+ else {
+ fputc(':', _pFile);
+ _clVal.fput(_pFile);
+ }
+ fputc('\n', _pFile);
+ }
+}
+
+/**
+ * name: CVCardFileVCF::writeLineEncoded
+ * desc: write a line as encoded text to the vcard file
+ * param: szSet - the string, which identifies the line
+ * cbRew - number of characters to truncate the _clVal by before writing to file
+ *
+ * return number of bytes, added to the linebuffer
+ **/
+VOID CVCardFileVCF::writeLineEncoded(const CHAR *szSet, size_t *cbRew)
+{
+ if (cbRew) {
+ _clVal.Truncate(*cbRew);
+ *cbRew = 0;
+ }
+ if (_clVal.GetLength() > 0) {
+ fputs(szSet, _pFile);
+ if (_hasUtf8) {
+ fputs(";CHARSET=UTF-8", _pFile);
+ _hasUtf8 = FALSE;
+ }
+ fputs(";ENCODING=QUOTED-PRINTABLE:", _pFile);
+ _clVal.fputEncoded(_pFile);
+ fputc('\n', _pFile);
+ }
+}
+
+/**
+ * name: Open
+ * desc: open a specified filename and link to the contact
+ * param: hContact - handle to the contact to link with the vCard file
+ * pszFileName - path to the file to open
+ * pszMode - the mode the file should be opened with
+ * return TRUE or FALSE
+ **/
+BOOLEAN CVCardFileVCF::Open(HANDLE hContact, LPCSTR pszFileName, LPCSTR pszMode)
+{
+ if (!(_pFile = fopen(pszFileName, pszMode)))
+ return FALSE;
+ if ((_hContact = hContact) == INVALID_HANDLE_VALUE)
+ return FALSE;
+ if (!(_pszBaseProto = DB::Contact::Proto(_hContact)))
+ return FALSE;
+ return TRUE;
+}
+
+/**
+ * name: Close
+ * desc: close up the file
+ * param: hContact - handle to the contact to link with the vCard file
+ * pszFileName - path to the file to open
+ * pszMode - the mode the file should be opened with
+ * return TRUE or FALSE
+ **/
+VOID CVCardFileVCF::Close(VOID)
+{
+ if (_pFile)
+ fclose(_pFile);
+ _pFile = NULL;
+ _hContact = INVALID_HANDLE_VALUE;
+ _pszBaseProto = NULL;
+}
+
+/**
+ * name: Export
+ * desc: export the contacts information
+ * param: none
+ * return TRUE or FALSE
+ **/
+BOOLEAN CVCardFileVCF::Export(BOOLEAN bExportUtf)
+{
+ size_t cbRew = 0;
+
+ _useUtf8 = bExportUtf;
+
+ fputs("BEGIN:VCARD\nVERSION:2.1\n", _pFile);
+
+ //
+ // naming
+ //
+ packDB(USERINFO, SET_CONTACT_LASTNAME, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_FIRSTNAME, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_SECONDNAME, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_TITLE, &cbRew);
+ _clVal + DELIM;
+ packDBList(USERINFO, SET_CONTACT_PREFIX, (MIRANDASERVICE)GetNamePrefixList, FALSE, &cbRew);
+ writeLine("N", &cbRew);
+
+ if (packDB(USERINFO, SET_CONTACT_TITLE))
+ _clVal + " ";
+
+ if (packDB(USERINFO, SET_CONTACT_FIRSTNAME))
+ _clVal + " ";
+ else
+ cbRew = 1;
+
+ if (packDB(USERINFO, SET_CONTACT_SECONDNAME))
+ _clVal + " ";
+ else
+ cbRew = 1;
+
+ if (packDB(USERINFO, SET_CONTACT_LASTNAME))
+ _clVal + " ";
+ else
+ cbRew = 1;
+
+ packDBList(USERINFO, SET_CONTACT_PREFIX, (MIRANDASERVICE)GetNamePrefixList, FALSE, &cbRew);
+ writeLine("FN");
+
+ packDB(USERINFO, SET_CONTACT_NICK);
+ writeLine("NICKNAME");
+
+ //
+ // organisation
+ //
+ packDB(USERINFO, SET_CONTACT_COMPANY, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_COMPANY_DEPARTMENT, &cbRew);
+ writeLine("ORG", &cbRew);
+ packDB(USERINFO, SET_CONTACT_COMPANY_POSITION);
+ writeLine("TITLE");
+ packDBList(USERINFO, SET_CONTACT_COMPANY_OCCUPATION, (MIRANDASERVICE)GetOccupationList, FALSE);
+ writeLine("ROLE");
+
+ //
+ // phone numbers
+ //
+ if (packDB(USERINFO, SET_CONTACT_PHONE)) {
+ _clVal.TruncateSMS();
+ writeLine("TEL;HOME;VOICE");
+ }
+ if (packDB(USERINFO, SET_CONTACT_FAX)) {
+ _clVal.TruncateSMS();
+ writeLine("TEL;HOME;FAX");
+ }
+ if (packDB(USERINFO, SET_CONTACT_CELLULAR)) {
+ _clVal.TruncateSMS();
+ writeLine("TEL;CELL;VOICE");
+ }
+ if (packDB(USERINFO, SET_CONTACT_COMPANY_PHONE)) {
+ _clVal.TruncateSMS();
+ writeLine("TEL;WORK;VOICE");
+ }
+ if (packDB(USERINFO, SET_CONTACT_COMPANY_FAX)) {
+ _clVal.TruncateSMS();
+ writeLine("TEL;WORK;FAX");
+ }
+ if (packDB(USERINFO, SET_CONTACT_COMPANY_CELLULAR)) {
+ _clVal.TruncateSMS();
+ writeLine("TEL;PAGER;VOICE");
+ }
+
+ //
+ // private address
+ //
+ _clVal + ";;";
+ cbRew = 1;
+ packDB(USERINFO, SET_CONTACT_STREET, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_CITY, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_STATE, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_ZIP, &cbRew);
+ _clVal + DELIM;
+ packDBList(USERINFO, SET_CONTACT_COUNTRY, (MIRANDASERVICE)GetCountryList, FALSE, &cbRew);
+ writeLine("ADR;HOME", &cbRew);
+
+ //
+ // company address
+ //
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_COMPANY_OFFICE, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_COMPANY_STREET, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_COMPANY_CITY, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_COMPANY_STATE, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_COMPANY_ZIP, &cbRew);
+ _clVal + DELIM;
+ packDBList(USERINFO, SET_CONTACT_COMPANY_COUNTRY, (MIRANDASERVICE)GetCountryList, FALSE, &cbRew);
+ writeLine("ADR;WORK", &cbRew);
+
+ //
+ // origin address
+ //
+ _clVal + ";;";
+ cbRew = 1;
+ packDB(USERINFO, SET_CONTACT_ORIGIN_STREET, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_ORIGIN_CITY, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_ORIGIN_STATE, &cbRew);
+ _clVal + DELIM;
+ packDB(USERINFO, SET_CONTACT_ORIGIN_ZIP, &cbRew);
+ _clVal + DELIM;
+ packDBList(USERINFO, SET_CONTACT_ORIGIN_COUNTRY, (MIRANDASERVICE)GetCountryList, FALSE, &cbRew);
+ writeLine("ADR;POSTAL", &cbRew);
+
+ //
+ // homepages
+ //
+ if (packDB(USERINFO, SET_CONTACT_HOMEPAGE))
+ writeLine("URL;HOME");
+ if (packDB(USERINFO, SET_CONTACT_COMPANY_HOMEPAGE))
+ writeLine("URL;WORK");
+
+ //
+ // e-mails
+ //
+ if (packDB(USERINFO, SET_CONTACT_EMAIL))
+ writeLine("EMAIL;PREF;intERNET");
+ if (packDB(USERINFO, SET_CONTACT_EMAIL0))
+ writeLine("EMAIL;intERNET");
+ if (packDB(USERINFO, SET_CONTACT_EMAIL1))
+ writeLine("EMAIL;intERNET");
+
+ //
+ // gender
+ //
+ {
+ BYTE gender = DB::Setting::GetByte(_hContact, USERINFO, SET_CONTACT_GENDER, 0);
+ if (!gender) gender = DB::Setting::GetByte(_hContact, _pszBaseProto, SET_CONTACT_GENDER, 0);
+ switch (gender) {
+ case 'F':
+ fputs("X-WAB-GENDER:1\n", _pFile);
+ break;
+ case 'M':
+ fputs("X-WAB-GENDER:2\n", _pFile);
+ break;
+ }
+ }
+
+ //
+ // birthday
+ //
+ {
+ MAnnivDate mdb;
+
+ if (!mdb.DBGetBirthDate(_hContact, NULL))
+ fprintf(_pFile, "BDAY:%d%02d%02d\n\0", mdb.Year(), mdb.Month(), mdb.Day());
+ }
+
+ //
+ // notes
+ //
+ if (packDB(USERINFO, SET_CONTACT_MYNOTES))
+ writeLineEncoded("NOTE");
+
+ //
+ // about
+ //
+ if (packDB(USERINFO, SET_CONTACT_ABOUT))
+ writeLineEncoded("ABOUT");
+
+ //
+ // contacts protocol, uin setting, uin value
+ //
+ {
+ CHAR szUID[MAXUID];
+ LPCSTR uid;
+
+ uid = (LPCSTR)CallProtoService(_pszBaseProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
+ if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid) {
+ if (!DB::Setting::GetStatic(_hContact, _pszBaseProto, uid, szUID, sizeof(szUID)))
+ fprintf(_pFile, "IM;%s;%s:%s\n", _pszBaseProto, uid, szUID);
+ }
+ }
+
+ //
+ // time of creation
+ //
+ {
+ SYSTEMTIME st;
+
+ GetLocalTime(&st);
+ fprintf(_pFile, "REV:%04d%02d%02dD%02d%02d%02dT\n", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
+ }
+
+ fputs("END:VCARD", _pFile);
+ return 0;
+}
+
+/**
+ * name: CVCardFileVCF::readLine
+ * desc: read one line from the VCF file and return the setting string
+ * to the szVCFSetting and the value to _clVal
+ * param: szVCFSetting - string holding the setting information
+ * cchSetting - number of bytes the szVCFSetting can hold
+ *
+ * return: number of characters read from the file or EOF
+ **/
+INT CVCardFileVCF::readLine(LPSTR szVCFSetting, WORD cchSetting)
+{
+ LPSTR here;
+
+ // read setting (size is never larger than MAX_SETTING, error otherwise!)
+ for (here = szVCFSetting; here - szVCFSetting < cchSetting && EOF != (*here = fgetc(_pFile)); here++) {
+ // end of the setting string
+ if (*here == ':') {
+ *here = 0;
+ break;
+ }
+ // end of line before value?
+ if (*here == '\n')
+ return 0;
+ }
+ // ignore line if setting was not read correctly
+ if (here - szVCFSetting == cchSetting)
+ return 0;
+
+ // read the value to the linebuffer, because its length may be very large
+ return _clVal.fgetEncoded(_pFile);
+}
+
+/**
+ * name: CVCardFileVCF::Import
+ * desc: imports all lines from the file and writes them to database
+ * param: nothing
+ *
+ * return: number of characters read from the file or EOF
+ **/
+BOOLEAN CVCardFileVCF::Import()
+{
+ CHAR szEnt[MAX_PATH];
+ LPSTR pszParam;
+ INT cbLine;
+ BYTE numEmails = 0;
+
+ while (EOF != (cbLine = readLine(szEnt, MAX_PATH))) {
+
+ // ignore empty lines
+ if (!cbLine) continue;
+
+ // isolate the param string
+ if (pszParam = mir_strchr(szEnt, ';')) {
+ *(pszParam++) = 0;
+ }
+ switch (*szEnt) {
+ case 'A':
+ if (!strcmp(szEnt, "ABOUT")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_ABOUT);
+ continue;
+ }
+ if (!strcmp(szEnt, "ADR")) {
+ if (!pszParam) continue;
+ if (!strcmp(pszParam, "HOME")) {
+ _clVal.GetTokenFirst(';', NULL);
+ _clVal.GetTokenNext(';', NULL);
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_STREET, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_CITY, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_STATE, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_ZIP, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_COUNTRY, ';');
+ continue;
+ }
+ if (!strcmp(pszParam, "WORK")) {
+ _clVal.GetTokenFirst(';', NULL);
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_COMPANY_OFFICE, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_COMPANY_STREET, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_COMPANY_CITY, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_COMPANY_STATE, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_COMPANY_ZIP, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_COMPANY_COUNTRY, ';');
+ continue;
+ }
+ if (!strcmp(pszParam, "POSTAL")) {
+ _clVal.GetTokenFirst(';', NULL);
+ _clVal.GetTokenNext(';', NULL);
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_ORIGIN_STREET, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_ORIGIN_CITY, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_ORIGIN_STATE, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_ORIGIN_ZIP, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_ORIGIN_COUNTRY, ';');
+ }
+ }
+ continue;
+
+ case 'B':
+ if (!strcmp(szEnt, "BDAY")) {
+ if (_clVal.GetLength() == 8) {
+ CHAR buf[5];
+
+ memcpy(buf, _clVal.GetBuffer(), 4);
+ buf[4] = 0;
+ DB::Setting::WriteWord(_hContact, MOD_MBIRTHDAY, SET_CONTACT_BIRTHYEAR, (WORD)strtol(buf, NULL, 10));
+ memcpy(buf, _clVal.GetBuffer() + 4, 2);
+ buf[2] = 0;
+ DB::Setting::WriteByte(_hContact, MOD_MBIRTHDAY, SET_CONTACT_BIRTHMONTH, (BYTE)strtol(buf, NULL, 10));
+ memcpy(buf, _clVal.GetBuffer() + 6, 2);
+ buf[2] = 0;
+ DB::Setting::WriteByte(_hContact, MOD_MBIRTHDAY, SET_CONTACT_BIRTHDAY, (BYTE)strtol(buf, NULL, 10));
+ }
+ }
+ continue;
+
+ case 'E':
+ if (!strcmp(szEnt, "EMAIL")) {
+ if (!pszParam || !strstr(pszParam, "intERNET"))
+ continue;
+ if (strstr(pszParam, "PREF")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_EMAIL);
+ continue;
+ }
+ switch (numEmails++) {
+ case 0:
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_EMAIL0);
+ break;
+ case 1:
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_EMAIL1);
+ break;
+ }
+ }
+ continue;
+ /*
+ case 'I':
+ if (!strcmp(szEnt, "IM")) {
+ LPSTR pszModule, pszSetting;
+
+ if (pszParam && (pszModule = strtok(pszParam, DELIM)) && (pszSetting = strtok(NULL, DELIM)))
+ _clVal.DBWriteSettingString(_hContact, pszModule, pszSetting);
+ }
+ continue;
+ */
+ case 'N':
+ if (!strcmp(szEnt, "N")) {
+ _clVal.DBWriteTokenFirst(_hContact, USERINFO, SET_CONTACT_LASTNAME, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_FIRSTNAME, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_SECONDNAME, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_TITLE, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_PREFIX, ';');
+ continue;
+ }
+ if (!strcmp(szEnt, "NICKNAME")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_NICK);
+ continue;
+ }
+ if (!strcmp(szEnt, "NOTE")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_MYNOTES);
+ }
+ continue;
+
+ case 'O':
+ if (!strcmp(szEnt, "ORG")) {
+ _clVal.DBWriteTokenFirst(_hContact, USERINFO, SET_CONTACT_COMPANY, ';');
+ _clVal.DBWriteTokenNext(_hContact, USERINFO, SET_CONTACT_COMPANY_DEPARTMENT, ';');
+ }
+ continue;
+
+ case 'R':
+ if (!strcmp(szEnt, "ROLE")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_COMPANY_OCCUPATION);
+ }
+ continue;
+
+ case 'T':
+ if (!strcmp(szEnt, "TITLE")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_COMPANY_POSITION);
+ continue;
+ }
+ if (!strcmp(szEnt, "TEL")) {
+
+ if (!pszParam) continue;
+
+ if (!strcmp(pszParam, "HOME;VOICE")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_PHONE);
+ continue;
+ }
+ if (!strcmp(pszParam, "HOME;FAX")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_FAX);
+ continue;
+ }
+ if (!strcmp(pszParam, "CELL;VOICE")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_CELLULAR);
+ continue;
+ }
+ if (!strcmp(pszParam, "WORK;VOICE")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_COMPANY_PHONE);
+ continue;
+ }
+ if (!strcmp(pszParam, "WORK;FAX")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_COMPANY_FAX);
+ continue;
+ }
+ if (!strcmp(pszParam, "PAGER;VOICE")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_COMPANY_CELLULAR);
+ continue;
+ }
+ }
+ continue;
+
+ case 'U':
+ if (!strcmp(szEnt, "URL")) {
+
+ if (!pszParam) continue;
+
+ if (!strcmp(pszParam, "HOME")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_HOMEPAGE);
+ continue;
+ }
+ if (!strcmp(pszParam, "WORK")) {
+ _clVal.DBWriteSettingString(_hContact, USERINFO, SET_CONTACT_COMPANY_HOMEPAGE);
+ }
+ }
+ continue;
+
+ case 'X':
+ if (!strcmp(szEnt, "X-WAB-GENDER")) {
+ if (!strcmp(_clVal.GetBuffer(), "1"))
+ DB::Setting::WriteByte(_hContact, USERINFO, SET_CONTACT_GENDER, 'F');
+ else
+ if (!strcmp(_clVal.GetBuffer(), "2"))
+ DB::Setting::WriteByte(_hContact, USERINFO, SET_CONTACT_GENDER, 'M');
+ }
+ continue;
+ }
+ }
+ return TRUE;
+}
diff --git a/plugins/UserInfoEx/ex_import/svc_ExImVCF.h b/plugins/UserInfoEx/ex_import/svc_ExImVCF.h
new file mode 100644
index 0000000000..4465614b80
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/svc_ExImVCF.h
@@ -0,0 +1,103 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/svc_ExImVCF.h $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#pragma once
+
+class CLineBuffer
+{
+private:
+ PBYTE _pVal;
+ PBYTE _pTok;
+ size_t _cbVal;
+ size_t _cbUsed;
+
+ BOOLEAN _resizeBuf(const size_t cbReq);
+
+public:
+ CLineBuffer();
+ ~CLineBuffer();
+
+ size_t operator = (const CHAR *szVal);
+
+ size_t operator + (const CHAR *szVal);
+ size_t operator + (const WCHAR *wszVal);
+ size_t operator + (const CHAR cVal);
+ size_t operator + (const BYTE bVal);
+ size_t operator + (const SHORT sVal);
+ size_t operator + (const WORD wVal);
+ size_t operator + (const LONG lVal);
+ size_t operator + (const DWORD dVal);
+
+ size_t GetLength();
+ LPCSTR GetBuffer();
+
+ VOID TruncToLength(size_t cbLength);
+ VOID Truncate(size_t count);
+ VOID TruncateSMS();
+
+ VOID fput(FILE *outfile);
+ VOID fputEncoded(FILE *outFile);
+ INT fgetEncoded(FILE *inFile);
+
+ size_t GetTokenFirst(const CHAR delim, CLineBuffer * pBuf);
+ size_t GetTokenNext(const CHAR delim, CLineBuffer * pBuf);
+ INT DBWriteTokenFirst(HANDLE hContact, const CHAR* pszModule, const CHAR* pszSetting, const CHAR delim);
+ INT DBWriteTokenNext(HANDLE hContact, const CHAR* pszModule, const CHAR* pszSetting, const CHAR delim);
+ INT DBWriteSettingString(HANDLE hContact, const CHAR* pszModule, const CHAR* pszSetting);
+};
+
+class CVCardFileVCF
+{
+private:
+ CLineBuffer _clVal;
+ FILE *_pFile;
+ HANDLE _hContact;
+ const CHAR *_pszBaseProto;
+ WORD _cbRew;
+ BOOLEAN _useUtf8;
+ WORD _hasUtf8;
+
+ size_t packList(LPIDSTRLIST pList, UINT nList, INT iID, size_t *cbRew = NULL);
+ BOOLEAN GetSetting(const CHAR *pszModule, const CHAR *pszSetting, DBVARIANT *dbv);
+ size_t packDB(const CHAR *pszModule, const CHAR *pszSetting, size_t *cbRew = NULL);
+ size_t packDBList(const CHAR *pszModule, const CHAR *pszSetting, MIRANDASERVICE GetList, BOOLEAN bSigned = FALSE, size_t *cbRew = NULL);
+
+ VOID writeLine(const CHAR *szSet, size_t *cbRew = NULL);
+ VOID writeLineEncoded(const CHAR *szSet, size_t *cbRew = NULL);
+ INT readLine(LPSTR szVCFSetting, WORD cchSetting);
+
+public:
+ CVCardFileVCF();
+
+ BOOLEAN Open(HANDLE hContact, LPCSTR pszFileName, LPCSTR pszMode);
+ VOID Close(VOID);
+ BOOLEAN Export(BOOLEAN bExportUtf);
+ BOOLEAN Import();
+};
diff --git a/plugins/UserInfoEx/ex_import/svc_ExImXML.cpp b/plugins/UserInfoEx/ex_import/svc_ExImXML.cpp
new file mode 100644
index 0000000000..dca52f1685
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/svc_ExImXML.cpp
@@ -0,0 +1,453 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/svc_ExImXML.cpp $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+#include "commonheaders.h"
+
+#define XMLCARD_VERSION "1.1"
+
+/**
+ * system & local includes:
+ **/
+#include "dlg_ExImModules.h"
+#include "classExImContactXML.h"
+#include "svc_ExImport.h"
+
+LRESULT CALLBACK DlgProc_DataHistory(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ const ICONCTRL idIcon[] = {
+ { ICO_DLG_EXPORT, WM_SETICON, NULL },
+ { ICO_DLG_EXPORT, STM_SETIMAGE, ICO_DLGLOGO },
+ { ICO_BTN_EXPORT, BM_SETIMAGE, IDOK },
+ { ICO_BTN_CANCEL, BM_SETIMAGE, IDCANCEL }
+ };
+ const INT numIconsToSet = DB::Setting::GetByte(SET_ICONS_BUTTONS, 1) ? SIZEOF(idIcon) : 2;
+ IcoLib_SetCtrlIcons(hDlg, idIcon, numIconsToSet);
+
+ TranslateDialogDefault(hDlg);
+ SendDlgItemMessage(hDlg, IDOK, BUTTONTRANSLATE, NULL, NULL);
+ SendDlgItemMessage(hDlg, IDCANCEL, BUTTONTRANSLATE, NULL, NULL);
+ break;
+ }
+ case WM_CTLCOLORSTATIC:
+ switch (GetWindowLongPtr((HWND)lParam, GWLP_ID)) {
+ case STATIC_WHITERECT:
+ case ICO_DLGLOGO:
+ case IDC_INFO:
+ SetBkColor((HDC)wParam, RGB(255, 255, 255));
+ return (INT_PTR)GetStockObject(WHITE_BRUSH);
+ }
+ return FALSE;
+ case WM_COMMAND:
+ if (HIWORD(wParam) == BN_CLICKED) {
+ switch (LOWORD(wParam)) {
+ case IDCANCEL:
+ EndDialog(hDlg, 0);
+ break;
+ case IDOK: {
+ WORD hiWord = 0;
+
+ if (IsDlgButtonChecked(hDlg, IDC_CHECK1))
+ hiWord |= EXPORT_DATA;
+ if (IsDlgButtonChecked(hDlg, IDC_CHECK2))
+ hiWord |= EXPORT_HISTORY;
+ EndDialog(hDlg, (INT_PTR)MAKELONG(IDOK, hiWord));
+ break;
+ }
+ }
+ }
+ break;
+ }
+ return FALSE;
+}
+
+/***********************************************************************************************************
+ * exporting stuff
+ ***********************************************************************************************************/
+
+/**
+ * name: Export
+ * desc: globally accessible function which does the whole export stuff.
+ * params: hContact - handle to the contact who is to export
+ * pszFileName - full qualified path to the xml file which is destination for the export process
+ * return: 0 on success, 1 otherwise
+ **/
+INT CFileXml::Export(lpExImParam ExImContact, LPCSTR pszFileName)
+{
+ FILE *xmlfile;
+ DB::CEnumList Modules;
+ LONG cbHeader;
+ SYSTEMTIME now;
+ DWORD result;
+ HANDLE hContact;
+
+ result = (DWORD)DialogBox(ghInst,
+ MAKEINTRESOURCE(IDD_EXPORT_DATAHISTORY),
+ NULL, (DLGPROC)DlgProc_DataHistory);
+ if (LOWORD(result) != IDOK)
+ {
+ return 0;
+ }
+ _wExport = HIWORD(result);
+
+ // show dialog to enable user to select modules for export
+ if (!(_wExport & EXPORT_DATA) ||
+ !DlgExImModules_SelectModulesToExport(ExImContact, &Modules, NULL))
+ {
+
+ xmlfile = fopen(pszFileName, "wt");
+ if (!xmlfile)
+ {
+ MsgErr(NULL, LPGENT("Can't create xml file!\n%S"), pszFileName);
+ return 1;
+ }
+
+ GetLocalTime(&now);
+
+ // write xml header raw as it is without using the tinyxml api
+ fprintf(xmlfile,
+ "%c%c%c<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
+ "<XMLCard ver=\""XMLCARD_VERSION"\" ref=\"%04d-%02d-%02d %02d:%02d:%02d\">\n",
+ 0xefU, 0xbbU, 0xbfU, now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond
+ );
+ // remember the header's size
+ cbHeader = ftell(xmlfile);
+
+ CExImContactXML vContact(this);
+
+ // write data
+ if ( ExImContact->Typ == EXIM_CONTACT) {
+ // export single contact
+ _hContactToWorkOn = ExImContact->hContact;
+ if (vContact.fromDB(ExImContact->hContact)) {
+ vContact.Export(xmlfile, &Modules);
+ }
+ }
+ else {
+ // other export mode
+ _hContactToWorkOn = INVALID_HANDLE_VALUE;
+#ifdef _DEBUG
+ LARGE_INTEGER freq, t1, t2;
+
+ QueryPerformanceFrequency(&freq);
+ QueryPerformanceCounter(&t1);
+#endif
+ // export owner contact
+ if (ExImContact->Typ == EXIM_ALL && vContact.fromDB(NULL)) {
+ vContact.Export(xmlfile, &Modules);
+ }
+ // loop for all other contact
+ for (hContact = DB::Contact::FindFirst();
+ hContact != NULL;
+ hContact = DB::Contact::FindNext(hContact))
+ {
+ switch (ExImContact->Typ)
+ {
+ case EXIM_ALL:
+ case EXIM_GROUP:
+ // dont export meta subcontacts by default
+ if (!DB::MetaContact::IsSub(hContact)) {
+ if (vContact.fromDB(hContact)) {
+ vContact.Export(xmlfile, &Modules);
+ }
+ }
+ break;
+ case EXIM_SUBGROUP:
+ // dont export meta subcontacts by default and
+ // export only contact with selectet group name
+ if (!DB::MetaContact::IsSub(hContact) &&
+ mir_tcsncmp(ExImContact->ptszName, DB::Setting::GetTString(hContact, "CList", "Group"), mir_tcslen(ExImContact->ptszName))== 0)
+ {
+ if (vContact.fromDB(hContact)) {
+ vContact.Export(xmlfile, &Modules);
+ }
+ }
+ break;
+ case EXIM_ACCOUNT:
+ // export only contact with selectet account name
+ if (!mir_strncmp(ExImContact->pszName, DB::Contact::Proto(hContact), mir_strlen(ExImContact->pszName))) {
+ if (vContact.fromDB(hContact)) {
+ vContact.Export(xmlfile, &Modules);
+ }
+ }
+ break;
+ }
+ } // *end for
+#ifdef _DEBUG
+ QueryPerformanceCounter(&t2);
+ MsgErr(NULL, LPGENT("Export took %f msec"),
+ (long double)(t2.QuadPart - t1.QuadPart) / freq.QuadPart * 1000.);
+#endif
+ }// *end other export mode
+
+ // nothing exported?
+ if (cbHeader == ftell(xmlfile)) {
+ fclose(xmlfile);
+ DeleteFileA(pszFileName);
+ return 1;
+ }
+ fputs("</XMLCard>\n", xmlfile);
+ fclose(xmlfile);
+ }
+ return 0;
+}
+
+
+/***********************************************************************************************************
+ * importing stuff
+ ***********************************************************************************************************/
+
+CFileXml::CFileXml()
+{
+ _numContactsTodo = 0;
+ _numContactsDone = 0;
+ _numSettingsTodo = 0;
+ _numSettingsDone = 0;
+ _numEventsTodo = 0;
+ _numEventsDone = 0;
+ _numEventsDuplicated = 0;
+}
+
+/**
+ * name: ImportOwner
+ * desc: Interpretes an xmlnode as owner contact, finds a corresponding contact in database
+ * or adds a new one including all xml childnodes.
+ * params: xContact - xmlnode representing the contact
+ * 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)
+{
+ CExImContactXML vContact(this);
+
+ if (vContact = xContact) {
+ vContact.Import();
+ return ERROR_OK;
+ }
+ return ERROR_NOT_ADDED;
+}
+
+/**
+ * name: ImportContacts
+ * desc: Parse all child nodes of an given parent node and try to import all found contacts
+ * params: xmlParent - xmlnode representing the parent of the list of contacts
+ * hContact - handle to the contact, who is the owner of the setting to import
+ * stat - structure used to collect some statistics
+ * return: ERROR_OK if at least one contact was successfully imported
+ **/
+INT CFileXml::ImportContacts(TiXmlElement* xmlParent)
+{
+ TiXmlElement *xContact;
+ CExImContactXML vContact(this);
+ INT result;
+ LPTSTR pszNick;
+
+ // import contacts
+ for (xContact = xmlParent->FirstChildElement(); xContact != NULL; xContact = xContact->NextSiblingElement()) {
+ if (!mir_stricmp(xContact->Value(), XKEY_CONTACT)) {
+ // update progressbar and abort if user clicked cancel
+ pszNick = mir_utf8decodeT(xContact->Attribute("nick"));
+ // user clicked abort button
+ if (_progress.UpdateContact(LPGENT("Contact: %s (%S)"), pszNick, xContact->Attribute("proto"))) {
+ result = vContact.LoadXmlElemnt(xContact);
+ switch (result) {
+ case ERROR_OK:
+ // init contact class and import if matches the user desires
+ if (_hContactToWorkOn == INVALID_HANDLE_VALUE || vContact.handle() == _hContactToWorkOn) {
+ result = vContact.Import(_hContactToWorkOn != INVALID_HANDLE_VALUE);
+ switch (result) {
+ case ERROR_OK:
+ _numContactsDone++;
+ break;
+ case ERROR_ABORTED:
+ if (pszNick) mir_free(pszNick);
+ return ERROR_ABORTED;
+#ifdef _DEBUG
+ default:
+ MsgErr(NULL, LPGENT("Importing %s caused error %d"), pszNick, result);
+ break;
+#endif
+ }
+ }
+ break;
+ case ERROR_ABORTED:
+ if (pszNick) mir_free(pszNick);
+ return ERROR_ABORTED;
+#ifdef _DEBUG
+ default:
+ MsgErr(NULL, LPGENT("Loading contact %s from xml failed with error %d"), pszNick, result);
+ break;
+#endif
+ }
+ }
+ if (pszNick) mir_free(pszNick);
+ }
+ // import owner contact
+ else if (_hContactToWorkOn == INVALID_HANDLE_VALUE && !mir_stricmp(xContact->Value(), XKEY_OWNER) && (vContact = xContact)) {
+ result = vContact.Import();
+ switch (result) {
+ case ERROR_OK:
+ _numContactsDone++;
+ break;
+ case ERROR_ABORTED:
+ return ERROR_ABORTED;
+#ifdef _DEBUG
+ default:
+ MsgErr(NULL, LPGENT("Importing Owner caused error %d"), result);
+#endif
+ }
+ }
+ }
+ return ERROR_OK;
+}
+
+/**
+ * name: CountContacts
+ * desc: Counts the number of contacts stored in the file
+ * params: xContact - the contact, who is the owner of the keys to count
+ * return: nothing
+ **/
+DWORD CFileXml::CountContacts(TiXmlElement* xmlParent)
+{
+ DWORD dwCount = 0;
+ TiXmlNode *xContact;
+
+ try {
+ // count contacts in file for progress bar
+ for (xContact = xmlParent->FirstChild(); xContact != NULL; xContact = xContact->NextSibling()) {
+ if (!mir_stricmp(xContact->Value(), XKEY_CONTACT) || !mir_stricmp(xContact->Value(), XKEY_OWNER)) {
+ dwCount += CountContacts(xContact->ToElement()) + 1;
+ }
+ }
+ }
+ catch(...) {
+ return 0;
+ }
+ return dwCount;
+}
+
+/**
+ * name: Import
+ * desc: Interpretes an xmlnode as owner contact, finds a corresponding contact in database
+ * or adds a new one including all xml childnodes.
+ * params: hContact - handle to the contact, who is the owner of the setting to import
+ * pszFileName - full qualified path to the xml file which is to import
+ * return: ERROR_OK on success or one other element of ImportError to tell the type of failure
+ **/
+INT CFileXml::Import(HANDLE hContact, LPCSTR pszFileName)
+{
+ TiXmlDocument doc;
+ TiXmlElement *xmlCard = NULL;
+
+ try {
+ _hContactToWorkOn = hContact;
+ // load xml file
+ if (!doc.LoadFile(pszFileName)) {
+ MsgErr(NULL, LPGENT("Parser is unable to load XMLCard \"%s\"\nError: %d\nDescription: %s"),
+ pszFileName, doc.ErrorId(), doc.ErrorDesc());
+ return 1;
+ }
+ // is xmlfile a XMLCard ?
+ if ((xmlCard = doc.FirstChildElement("XMLCard")) == NULL) {
+ MsgErr(NULL, LPGENT("The selected file is no valid XMLCard"));
+ return 1;
+ }
+ // check version
+ if (mir_strcmp(xmlCard->Attribute("ver"), XMLCARD_VERSION)) {
+ MsgErr(NULL, LPGENT("The version of the XMLCard is not supported by UserInfoEx"));
+ return 1;
+ }
+
+ // is owner contact to import ?
+ if (_hContactToWorkOn == NULL) {
+ INT ret;
+
+ // disable database safty mode to speed up the operation
+ CallService(MS_DB_SETSAFETYMODE, 0, 0);
+ // import owner contact
+ ret = ImportOwner(xmlCard->FirstChildElement(XKEY_OWNER));
+ // as soon as possible enable safty mode again!
+ CallService(MS_DB_SETSAFETYMODE, 1, 0);
+
+ if (!ret) {
+ MsgBox(NULL, MB_ICONINFORMATION,
+ LPGENT("Complete"),
+ LPGENT("Import complete"),
+ LPGENT("Owner contact successfully imported."));
+ return 0;
+ } else {
+ MsgErr(NULL, LPGENT("Selected XMLCard does not contain an owner contact!"));
+ return 1;
+ }
+ }
+ else {
+#ifdef _DEBUG
+ LARGE_INTEGER freq, t1, t2;
+
+ QueryPerformanceFrequency(&freq);
+ QueryPerformanceCounter(&t1);
+#endif
+ // count contacts in file for progress bar
+ _numContactsTodo = CountContacts(xmlCard);
+ if (_numContactsTodo > 0) {
+ _progress.SetContactCount(_numContactsTodo);
+ // disable database safty mode to speed up the operation
+ CallService(MS_DB_SETSAFETYMODE, 0, 0);
+ // import the contacts
+ ImportContacts(xmlCard);
+ // as soon as possible enable safty mode again!
+ CallService(MS_DB_SETSAFETYMODE, 1, 0);
+ }
+ // finally hide the progress dialog
+ _progress.Hide();
+
+#ifdef _DEBUG
+ QueryPerformanceCounter(&t2);
+ MsgErr(NULL, LPGENT("Import took %f msec"),
+ (long double)(t2.QuadPart - t1.QuadPart) / freq.QuadPart * 1000.);
+#endif
+ // show results
+ MsgBox(NULL, MB_ICONINFORMATION, LPGENT("Import complete"), LPGENT("Some basic statistics"),
+ LPGENT("added contacts: %u / %u\nadded settings: %u / %u\nadded events %u / %u\nduplicated events: %u"),
+ _numContactsDone, _numContactsTodo,
+ _numSettingsDone, _numSettingsTodo,
+ _numEventsDone, _numEventsTodo,
+ _numEventsDuplicated);
+
+ }
+ }
+ catch(...) {
+ MsgErr(NULL, LPGENT("FATAL: An exception was thrown while importing contacts from xmlCard!"));
+ return 1;
+ }
+ return 0;
+}
diff --git a/plugins/UserInfoEx/ex_import/svc_ExImXML.h b/plugins/UserInfoEx/ex_import/svc_ExImXML.h
new file mode 100644
index 0000000000..a2524a7dd6
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/svc_ExImXML.h
@@ -0,0 +1,75 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/svc_ExImXML.h $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+#ifndef _SVC_FILEXML_INCLUDED_
+#define _SVC_FILEXML_INCLUDED_ 1
+
+#include "svc_ExImport.h"
+#include "classExImContactBase.h"
+#include "dlg_ExImProgress.h"
+
+#define EXPORT_DATA 1
+#define EXPORT_HISTORY 2
+#define EXPORT_ALL (EXPORT_DATA|EXPORT_HISTORY)
+
+class CFileXml {
+ friend class CExImContactXML;
+
+ DWORD _numContactsTodo;
+ DWORD _numContactsDone;
+ DWORD _numSettingsTodo;
+ DWORD _numSettingsDone;
+ DWORD _numEventsTodo;
+ DWORD _numEventsDone;
+ DWORD _numEventsDuplicated;
+
+ HANDLE _hContactToWorkOn; // contact to ex/import (NULL=owner|INVALID_HANDLE_VALUE=all|HADNLE=one user)
+
+ WORD _wExport;
+
+ CProgress _progress;
+
+ INT ImportOwner(TiXmlElement* xmlContact);
+ INT ImportContacts(TiXmlElement* xmlParent);
+
+ DWORD CountContacts(TiXmlElement* xmlParent);
+
+ /*
+ INT ExportOwner(FILE *xmlfile, BOOLEAN bExportEvents);
+ INT ExportContact(FILE *xmlfile, HANDLE hContact, BOOLEAN bExportEvents, LPENUMLIST pModules);
+ INT ExportSubContact(TiXmlElement *xContact, HANDLE hContact, BOOLEAN bExportEvents);
+ */
+
+public:
+ CFileXml();
+ INT Import(HANDLE hContact, LPCSTR pszFileName);
+ INT Export(lpExImParam ExImContact, LPCSTR pszFileName);
+};
+
+#endif /* _SVC_FILEXML_INCLUDED_ */ \ No newline at end of file
diff --git a/plugins/UserInfoEx/ex_import/svc_ExImport.cpp b/plugins/UserInfoEx/ex_import/svc_ExImport.cpp
new file mode 100644
index 0000000000..b44f455cb8
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/svc_ExImport.cpp
@@ -0,0 +1,382 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/svc_ExImport.cpp $
+Revision : $Revision: 210 $
+Last change on : $Date: 2010-10-02 22:27:36 +0400 (Сб, 02 окт 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#include "commonheaders.h"
+#include "classExImContactBase.h"
+#include "dlg_ExImModules.h"
+#include "dlg_ExImOpenSaveFile.h"
+#include "svc_ExImport.h"
+#include "svc_ExImINI.h"
+#include "svc_ExImVCF.h"
+#include "svc_ExImXML.h"
+
+#include <m_clui.h>
+#include <m_clc.h>
+
+/***********************************************************************************************************
+ * internal functions
+ ***********************************************************************************************************/
+
+/**
+ * name: DisplayNameToFileName
+ * desc: convert contact's display name to valid filename
+ * param: hContact - handle of contact to create the filename for
+ * pszFileName - buffer, retrieving the converted filename
+ * cchFileName - number of maximum characters the filename can be
+ * return: nothing
+ **/
+static VOID DisplayNameToFileName(lpExImParam ExImContact, LPSTR pszFileName, WORD cchFileName)
+{
+ LPCSTR disp = 0;
+ LPSTR temp = 0;
+
+ cchFileName--;
+
+ ZeroMemory(pszFileName, cchFileName);
+
+ switch (ExImContact->Typ) {
+ case EXIM_ALL:
+ case EXIM_GROUP:
+ mir_strncpy(pszFileName, Translate("all Contacts"), cchFileName);
+ return;
+ case EXIM_CONTACT:
+ if (ExImContact->hContact == NULL) {
+ mir_strncpy(pszFileName, Translate("Owner"), cchFileName);
+ return;
+ }
+ else {
+ disp = (LPCSTR)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ExImContact->hContact, NULL);
+ }
+ break;
+ case EXIM_SUBGROUP:
+ temp = mir_t2a(ExImContact->ptszName);
+ disp = temp;
+ break;
+ case EXIM_ACCOUNT:
+ PROTOACCOUNT* acc = ProtoGetAccount(ExImContact->pszName);
+ temp = mir_t2a(acc->tszAccountName);
+ disp = temp;
+ break;
+ }
+
+ // replace unwanted characters
+ while (*disp != 0 && cchFileName > 1) {
+ switch (*disp) {
+ case '?': case '*': case ':':
+ case '\\': case '|': case '/':
+ case '<': case '>': case '"':
+ *(pszFileName++) = '_';
+ break;
+ default:
+ *(pszFileName++) = *disp;
+ break;
+ }
+ disp++;
+ cchFileName--;
+ }
+ mir_free(temp);
+}
+
+LPCSTR FilterString(lpExImParam ExImContact)
+{
+ LPCSTR pszFilter = 0;
+ switch (ExImContact->Typ) {
+ case EXIM_SUBGROUP:
+ case EXIM_ACCOUNT:
+ pszFilter = ("XMLCard 1.0 (*.xml)\0*.xml\0");
+ break;
+ case EXIM_ALL:
+ case EXIM_GROUP:
+ pszFilter = ("XMLCard 1.0 (*.xml)\0*.xml\0DBEditor++ File (*.ini)\0*.ini\0");
+ break;
+ case EXIM_CONTACT:
+ pszFilter = ("XMLCard 1.0 (*.xml)\0*.xml\0DBEditor++ File (*.ini)\0*.ini\0Standard vCard 2.1 (*.vcf)\0*.vcf\0");
+ break;
+ }
+ return pszFilter;
+}
+
+/**
+ * name: SvcExImport_Export
+ * desc: service function to export contact information
+ * param: wParam - handle to contact or NULL
+ * lParam - parent window
+ * return: 0 always
+ **/
+INT_PTR SvcExImport_Export(lpExImParam ExImContact, HWND hwndParent)
+{
+ CHAR szFileName[MAX_PATH] = { 0 };
+ // create the filename to suggest the user for the to export contact
+ DisplayNameToFileName(ExImContact, szFileName, SIZEOF(szFileName));
+ INT nIndex = DlgExIm_SaveFileName(hwndParent,
+ Translate("Select a destination file..."),
+ FilterString(ExImContact),
+ szFileName);
+
+ switch (nIndex) {
+ case 1: // .xml
+ {
+ CFileXml xmlFile;
+ return xmlFile.Export(ExImContact, szFileName);
+ }
+ case 2: // .ini
+ {
+ return SvcExImINI_Export(ExImContact, szFileName);
+ }
+ case 3: // .vcf
+ {
+ CVCardFileVCF vcfFile;
+ SetCursor(LoadCursor(NULL, IDC_WAIT));
+ if (vcfFile.Open(ExImContact->hContact, szFileName, "wt")) {
+ vcfFile.Export(FALSE);
+ vcfFile.Close();
+ }
+ SetCursor(LoadCursor(NULL, IDC_ARROW));
+ return 0;
+ }
+ }
+ return 1;
+}
+
+/**
+ * name: SvcExImport_Import
+ * desc: service function to export contact information
+ * param: wParam - handle to contact or NULL
+ * lParam - parent window
+ * return: 0 always
+ **/
+INT_PTR SvcExImport_Import(lpExImParam ExImContact, HWND hwndParent)
+{
+ CHAR szFileName[MAX_PATH] = { 0 };
+
+ // create the filename to suggest the user for the to export contact
+ DisplayNameToFileName(ExImContact, szFileName, SIZEOF(szFileName));
+
+ INT nIndex = DlgExIm_OpenFileName(hwndParent,
+ Translate("Import User Details from VCard"),
+ FilterString(ExImContact),
+ szFileName);
+
+// Stop during develop
+if (ExImContact->Typ == EXIM_ACCOUNT ||
+ ExImContact->Typ == EXIM_GROUP) return 1;
+
+ switch (nIndex) {
+ case 1:
+ {
+ CFileXml xmlFile;
+ CallService(MS_CLIST_SETHIDEOFFLINE, -1, 0); //workarround to refresh the clist....
+ xmlFile.Import(ExImContact->hContact, szFileName);
+ CallService(MS_CLIST_SETHIDEOFFLINE, -1, 0); //...after import.
+ //pcli->pfnClcBroadcast(CLM_AUTOREBUILD, 0, 0); //does not work
+ return 0;
+ }
+ // .ini
+ case 2:
+ return SvcExImINI_Import(ExImContact->hContact, szFileName);
+
+ // .vcf
+ case 3:
+ {
+ CVCardFileVCF vcfFile;
+
+ if (vcfFile.Open(ExImContact->hContact, szFileName, "rt")) {
+ SetCursor(LoadCursor(NULL, IDC_WAIT));
+ vcfFile.Import();
+ vcfFile.Close();
+ SetCursor(LoadCursor(NULL, IDC_ARROW));
+ }
+ return 0;
+ }
+ }
+ return 1;
+}
+
+/***********************************************************************************************************
+ * service functions
+ ***********************************************************************************************************/
+
+/*********************************
+ * Ex/import All (MainMenu)
+ *********************************/
+INT_PTR svcExIm_MainExport_Service(WPARAM wParam, LPARAM lParam)
+{
+ ExImParam ExIm;
+ ZeroMemory(&ExIm, sizeof(ExIm));
+ ExIm.hContact = INVALID_HANDLE_VALUE;
+ ExIm.Typ = EXIM_ALL;
+ return SvcExImport_Export(&ExIm, (HWND)lParam);
+}
+
+INT_PTR svcExIm_MainImport_Service(WPARAM wParam, LPARAM lParam)
+{
+ ExImParam ExIm;
+ ZeroMemory(&ExIm, sizeof(ExIm));
+ ExIm.hContact = INVALID_HANDLE_VALUE;
+ ExIm.Typ = EXIM_ALL;
+ return SvcExImport_Import(&ExIm, (HWND)lParam);
+}
+
+
+/*********************************
+ * Ex/import Contact (ContactMenu)
+ *********************************/
+INT_PTR svcExIm_ContactExport_Service(WPARAM wParam, LPARAM lParam)
+{
+ ExImParam ExIm;
+ ZeroMemory(&ExIm, sizeof(ExIm));
+ ExIm.hContact = (HANDLE)wParam;
+ ExIm.Typ = EXIM_CONTACT;
+ return SvcExImport_Export(&ExIm, (HWND)lParam);
+}
+
+INT_PTR svcExIm_ContactImport_Service(WPARAM wParam, LPARAM lParam)
+{
+ ExImParam ExIm;
+ ZeroMemory(&ExIm, sizeof(ExIm));
+ ExIm.hContact = (HANDLE)wParam;
+ ExIm.Typ = EXIM_CONTACT;
+ return SvcExImport_Import(&ExIm, (HWND)lParam);
+}
+
+
+/*********************************
+ *Ex/import (Sub)Group (GroupMenu)
+ *********************************/
+
+/**
+ * This service is call by (Sub)Group MenuItem Export and MenuItem Import
+ *
+ * @param wParam - gmp.wParam = 0 ->Import
+ * @param wParam - gmp.wParam != 0 ->Export
+ * @param lParam - gmp.lParam not used
+ *
+ * @return always 0
+ **/
+INT_PTR svcExIm_Group_Service(WPARAM wParam, LPARAM lParam)
+{
+ ExImParam ExIm;
+ INT_PTR hItem = 0, hRoot = 0, hParent = 0;
+ TCHAR tszGroup[120], tszItem[120];
+ ZeroMemory(&tszGroup, sizeof(tszGroup));
+ ZeroMemory(&tszItem, sizeof(tszItem));
+ ZeroMemory(&ExIm, sizeof(ExIm));
+ LPTSTR ptszGroup = tszGroup;
+ LPTSTR ptszItem = tszItem;
+
+ HWND hClist = (HWND)CallService(MS_CLUI_GETHWNDTREE,0,0);
+ // get clist selection
+ hItem = SendMessage(hClist,CLM_GETSELECTION,0,0);
+ hRoot = SendMessage(hClist,CLM_GETNEXTITEM, (WPARAM)CLGN_ROOT, (LPARAM)hItem);
+ while (hItem) {
+ if (SendMessage(hClist,CLM_GETITEMTYPE, (WPARAM)hItem, 0) == CLCIT_GROUP) {
+ SendMessage(hClist,CLM_GETITEMTEXT, (WPARAM)hItem, (LPARAM)ptszItem);
+ LPTSTR temp = mir_tstrdup(ptszGroup);
+ mir_sntprintf(tszGroup, SIZEOF(tszGroup),_T("%s%s%s"), ptszItem, _tcslen(temp)? _T("\\"):_T(""), temp);
+ mir_free (temp);
+ }
+ hParent = SendMessage(hClist,CLM_GETNEXTITEM, (WPARAM)CLGN_PARENT, (LPARAM)hItem);
+ hItem = (hParent != hRoot) ? hParent : 0;
+ }
+ ExIm.ptszName = ptszGroup;
+ ExIm.Typ = EXIM_SUBGROUP;
+
+ if (wParam) {
+ //Export "/ExportGroup"
+ SvcExImport_Export(&ExIm, hClist);
+ }
+ else {
+ //Import "/ImportGroup"
+ SvcExImport_Import(&ExIm, hClist);
+ }
+
+ return 0;
+};
+
+
+/*********************************
+ *Ex/Import Account (AccountMenu)
+ *********************************/
+typedef struct
+// neeed for MO_MENUITEMGETOWNERDATA
+// taken from core clistmenus.ccp
+{
+ char *proto; //This is unique protoname
+ int protoindex;
+ int status;
+
+ BOOL custom;
+ char *svc;
+ HANDLE hMenuItem;
+} StatusMenuExecParam,*lpStatusMenuExecParam;
+
+/**
+ * This service is call by Account MenuItem Export and MenuItem Import
+ *
+ * @param wParam - not used
+ * @param lParam - MenuItem from MS_CLIST_ADDSTATUSMENUITEM
+ *
+ * @return always 0
+ **/
+INT_PTR svcExIm_Account_Service(WPARAM wParam, LPARAM lParam)
+{
+ ExImParam ExIm;
+ ZeroMemory(&ExIm, sizeof(ExIm));
+ HWND hClist = (HWND)CallService(MS_CLUI_GETHWNDTREE,0,0);
+ lpStatusMenuExecParam smep = (lpStatusMenuExecParam) CallService(MO_MENUITEMGETOWNERDATA, (WPARAM) lParam, NULL);
+ ExIm.pszName = mir_strdup(smep->proto);
+ ExIm.Typ = EXIM_ACCOUNT;
+
+ if (strstr( smep->svc, "/ExportAccount" )) {
+ //Export "/ExportAccount"
+ SvcExImport_Export(&ExIm, hClist);
+ }
+ else {
+ //Import "/ImportAccount"
+ SvcExImport_Import(&ExIm, hClist);
+ }
+ mir_free(ExIm.pszName);
+ return 0;
+};
+
+/**
+ * name: SvcExImport_LoadModule()
+ * desc: initializes the Ex/Import Services
+ *
+ * return: 0 or 1
+ **/
+VOID SvcExImport_LoadModule()
+{
+ myCreateServiceFunction(MS_USERINFO_VCARD_EXPORTALL, svcExIm_MainExport_Service);
+ myCreateServiceFunction(MS_USERINFO_VCARD_IMPORTALL, svcExIm_MainImport_Service);
+ myCreateServiceFunction(MS_USERINFO_VCARD_EXPORT, svcExIm_ContactExport_Service);
+ myCreateServiceFunction(MS_USERINFO_VCARD_IMPORT, svcExIm_ContactImport_Service);
+ return;
+}
diff --git a/plugins/UserInfoEx/ex_import/svc_ExImport.h b/plugins/UserInfoEx/ex_import/svc_ExImport.h
new file mode 100644
index 0000000000..3539ad72cd
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/svc_ExImport.h
@@ -0,0 +1,62 @@
+/*
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/svc_ExImport.h $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#ifndef _SVC_EXIMPORT_INCLUDED_
+#define _SVC_EXIMPORT_INCLUDED_ 1
+
+typedef struct
+{
+ BYTE Typ;
+ union {
+ HANDLE hContact;
+ LPSTR pszName;
+ LPTSTR ptszName;
+ };
+}
+ ExImParam,*lpExImParam;
+
+enum ExImType {
+ EXIM_ALL = 1,
+ EXIM_CONTACT = 2,
+ EXIM_GROUP = 4,
+ EXIM_SUBGROUP = 8,
+ EXIM_ACCOUNT = 16
+};
+
+INT_PTR svcExIm_MainExport_Service(WPARAM wParam, LPARAM lParam);
+INT_PTR svcExIm_MainImport_Service(WPARAM wParam, LPARAM lParam);
+INT_PTR svcExIm_ContactExport_Service(WPARAM wParam, LPARAM lParam);
+INT_PTR svcExIm_ContactImport_Service(WPARAM wParam, LPARAM lParam);
+INT_PTR svcExIm_Group_Service(WPARAM wParam,LPARAM lParam);
+INT_PTR svcExIm_Account_Service(WPARAM wParam,LPARAM lParam);
+
+VOID SvcExImport_LoadModule();
+
+#endif /* _SVC_EXIMPORT_INCLUDED_ */ \ No newline at end of file
diff --git a/plugins/UserInfoEx/ex_import/tinystr.cpp b/plugins/UserInfoEx/ex_import/tinystr.cpp
new file mode 100644
index 0000000000..3ec0fe4676
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/tinystr.cpp
@@ -0,0 +1,143 @@
+/*
+www.sourceforge.net/projects/tinyxml
+Original file by Yves Berquin.
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
+damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
+redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
+would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and
+must not be misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
+*/
+
+/*
+ * THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005.
+ *
+ * - completely rewritten. compact, clean, and fast implementation.
+ * - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems)
+ * - fixed reserve() to work as per specification.
+ * - fixed buggy compares operator==(), operator<(), and operator>()
+ * - fixed operator+=() to take a const ref argument, following spec.
+ * - added "copy" constructor with length, and most compare operators.
+ * - added swap(), clear(), size(), capacity(), operator+().
+
+===============================================================================
+
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/tinystr.cpp $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+ */
+
+#ifndef TIXML_USE_STL
+
+#ifdef USE_MMGR
+#include <assert.h>
+#include <string.h>
+
+#include "mmgr.h"
+#endif
+
+#include "tinystr.h"
+
+// Error value for find primitive
+const TiXmlString::size_type TiXmlString::npos = static_cast< size_type >(-1);
+
+// Null rep.
+TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, '\0' };
+
+
+void TiXmlString::reserve (size_type cap)
+{
+ if (cap > capacity())
+ {
+ TiXmlString tmp;
+ tmp.init(length(), cap);
+ memcpy(tmp.start(), data(), length());
+ swap(tmp);
+ }
+}
+
+
+TiXmlString& TiXmlString::assign(const char* str, size_type len)
+{
+ size_type cap = capacity();
+ if (len > cap || cap > 3*(len + 8))
+ {
+ TiXmlString tmp;
+ tmp.init(len);
+ memcpy(tmp.start(), str, len);
+ swap(tmp);
+ }
+ else
+ {
+ memmove(start(), str, len);
+ set_size(len);
+ }
+ return *this;
+}
+
+
+TiXmlString& TiXmlString::append(const char* str, size_type len)
+{
+ size_type newsize = length() + len;
+ if (newsize > capacity())
+ {
+ reserve (newsize + capacity());
+ }
+ memmove(finish(), str, len);
+ set_size(newsize);
+ return *this;
+}
+
+
+TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
+{
+ TiXmlString tmp;
+ tmp.reserve(a.length() + b.length());
+ tmp += a;
+ tmp += b;
+ return tmp;
+}
+
+TiXmlString operator + (const TiXmlString & a, const char* b)
+{
+ TiXmlString tmp;
+ TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>(strlen(b));
+ tmp.reserve(a.length() + b_len);
+ tmp += a;
+ tmp.append(b, b_len);
+ return tmp;
+}
+
+TiXmlString operator + (const char* a, const TiXmlString & b)
+{
+ TiXmlString tmp;
+ TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>(strlen(a));
+ tmp.reserve(a_len + b.length());
+ tmp.append(a, a_len);
+ tmp += b;
+ return tmp;
+}
+
+
+#endif // TIXML_USE_STL
diff --git a/plugins/UserInfoEx/ex_import/tinystr.h b/plugins/UserInfoEx/ex_import/tinystr.h
new file mode 100644
index 0000000000..1061e795d8
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/tinystr.h
@@ -0,0 +1,335 @@
+/*
+www.sourceforge.net/projects/tinyxml
+Original file by Yves Berquin.
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
+damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
+redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
+would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and
+must not be misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
+*/
+
+/*
+ * THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005.
+ *
+ * - completely rewritten. compact, clean, and fast implementation.
+ * - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems)
+ * - fixed reserve() to work as per specification.
+ * - fixed buggy compares operator==(), operator<(), and operator>()
+ * - fixed operator+=() to take a const ref argument, following spec.
+ * - added "copy" constructor with length, and most compare operators.
+ * - added swap(), clear(), size(), capacity(), operator+().
+
+===============================================================================
+
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/tinystr.h $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+ */
+
+#ifndef TIXML_USE_STL
+
+#ifndef TIXML_STRING_INCLUDED
+#define TIXML_STRING_INCLUDED
+
+#ifndef USE_MMGR
+#include <assert.h>
+#include <string.h>
+#endif
+
+/* The support for explicit isn't that universal, and it isn't really
+ required - it is used to check that the TiXmlString class isn't incorrectly
+ used. Be nice to old compilers and macro it here:
+*/
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+ // Microsoft visual studio, version 6 and higher.
+ #define TIXML_EXPLICIT explicit
+#elif defined(__GNUC__) && (__GNUC__ >= 3)
+ // GCC version 3 and higher.s
+ #define TIXML_EXPLICIT explicit
+#else
+ #define TIXML_EXPLICIT
+#endif
+
+
+/*
+ TiXmlString is an emulation of a subset of the std::string template.
+ Its purpose is to allow compiling TinyXML on compilers with no or poor STL support.
+ Only the member functions relevant to the TinyXML project have been implemented.
+ The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase
+ a string and there's no more room, we allocate a buffer twice as big as we need.
+*/
+class TiXmlString
+{
+ public :
+ // The size type used
+ typedef size_t size_type;
+
+ // Error value for find primitive
+ static const size_type npos; // = -1;
+
+
+ // TiXmlString empty constructor
+ TiXmlString () : rep_(&nullrep_)
+ {
+ }
+
+ // TiXmlString copy constructor
+ TiXmlString (const TiXmlString & copy)
+ {
+ init(copy.length());
+ memcpy(start(), copy.data(), length());
+ }
+
+ // TiXmlString constructor, based on a string
+ TIXML_EXPLICIT TiXmlString (const char * copy)
+ {
+ init(static_cast<size_type>(strlen(copy)));
+ memcpy(start(), copy, length());
+ }
+
+ // TiXmlString constructor, based on a string
+ TIXML_EXPLICIT TiXmlString (const char * str, size_type len)
+ {
+ init(len);
+ memcpy(start(), str, len);
+ }
+
+ // TiXmlString destructor
+ ~TiXmlString ()
+ {
+ quit();
+ }
+
+ // = operator
+ TiXmlString& operator = (const char * copy)
+ {
+ return assign(copy, (size_type)strlen(copy));
+ }
+
+ // = operator
+ TiXmlString& operator = (const TiXmlString & copy)
+ {
+ return assign(copy.start(), copy.length());
+ }
+
+
+ // += operator. Maps to append
+ TiXmlString& operator += (const char * suffix)
+ {
+ return append(suffix, static_cast<size_type>(strlen(suffix)));
+ }
+
+ // += operator. Maps to append
+ TiXmlString& operator += (char single)
+ {
+ return append(&single, 1);
+ }
+
+ // += operator. Maps to append
+ TiXmlString& operator += (const TiXmlString & suffix)
+ {
+ return append(suffix.data(), suffix.length());
+ }
+
+
+ // Convert a TiXmlString into a null-terminated char *
+ const char * c_str () const { return rep_->str; }
+
+ // Convert a TiXmlString into a char * (need not be null terminated).
+ const char * data () const { return rep_->str; }
+
+ // Return the length of a TiXmlString
+ size_type length () const { return rep_->size; }
+
+ // Alias for length()
+ size_type size () const { return rep_->size; }
+
+ // Checks if a TiXmlString is empty
+ bool empty () const { return rep_->size == 0; }
+
+ // Return capacity of string
+ size_type capacity () const { return rep_->capacity; }
+
+
+ // single char extraction
+ const char& at (size_type index) const
+ {
+ assert(index < length());
+ return rep_->str[ index ];
+ }
+
+ // [] operator
+ char& operator [] (size_type index) const
+ {
+ assert(index < length());
+ return rep_->str[ index ];
+ }
+
+ // find a char in a string. Return TiXmlString::npos if not found
+ size_type find (char lookup) const
+ {
+ return find(lookup, 0);
+ }
+
+ // find a char in a string from an offset. Return TiXmlString::npos if not found
+ size_type find (char tofind, size_type offset) const
+ {
+ if (offset >= length()) return npos;
+
+ for (const char* p = c_str() + offset; *p != '\0'; ++p)
+ {
+ if (*p == tofind) return static_cast< size_type >(p - c_str());
+ }
+ return npos;
+ }
+
+ void clear ()
+ {
+ //Lee:
+ //The original was just too strange, though correct:
+ // TiXmlString().swap(*this);
+ //Instead use the quit & re-init:
+ quit();
+ init(0,0);
+ }
+
+ /* Function to reserve a big amount of data when we know we'll need it. Be aware that this
+ function DOES NOT clear the content of the TiXmlString if any exists.
+ */
+ void reserve (size_type cap);
+
+ TiXmlString& assign (const char* str, size_type len);
+
+ TiXmlString& append (const char* str, size_type len);
+
+ void swap (TiXmlString& other)
+ {
+ Rep* r = rep_;
+ rep_ = other.rep_;
+ other.rep_ = r;
+ }
+
+ private:
+
+ void init(size_type sz) { init(sz, sz); }
+ void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
+ char* start() const { return rep_->str; }
+ char* finish() const { return rep_->str + rep_->size; }
+
+ struct Rep
+ {
+ size_type size, capacity;
+ char str[1];
+ };
+
+ void init(size_type sz, size_type cap)
+ {
+ if (cap)
+ {
+ // Lee: the original form:
+ // rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
+ // doesn't work in some cases of new being overloaded. Switching
+ // to the normal allocation, although use an 'int' for systems
+ // that are overly picky about structure alignment.
+ const size_type bytesNeeded = sizeof(Rep) + cap;
+ const size_type intsNeeded = (bytesNeeded + sizeof(int) - 1) / sizeof(int);
+ rep_ = reinterpret_cast<Rep*>(new int[ intsNeeded ]);
+
+ rep_->str[ rep_->size = sz ] = '\0';
+ rep_->capacity = cap;
+ }
+ else
+ {
+ rep_ = &nullrep_;
+ }
+ }
+
+ void quit()
+ {
+ if (rep_ != &nullrep_)
+ {
+ // The rep_ is really an array of ints. (see the allocator, above).
+ // Cast it back before delete, so the compiler won't incorrectly call destructors.
+ delete [] (reinterpret_cast<int*>(rep_));
+ }
+ }
+
+ Rep * rep_;
+ static Rep nullrep_;
+
+} ;
+
+
+inline bool operator == (const TiXmlString & a, const TiXmlString & b)
+{
+ return (a.length() == b.length()) // optimization on some platforms
+ && (strcmp(a.c_str(), b.c_str()) == 0); // actual compare
+}
+inline bool operator < (const TiXmlString & a, const TiXmlString & b)
+{
+ return strcmp(a.c_str(), b.c_str()) < 0;
+}
+
+inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
+inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; }
+inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); }
+inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); }
+
+inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; }
+inline bool operator == (const char* a, const TiXmlString & b) { return b == a; }
+inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); }
+inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); }
+
+TiXmlString operator + (const TiXmlString & a, const TiXmlString & b);
+TiXmlString operator + (const TiXmlString & a, const char* b);
+TiXmlString operator + (const char* a, const TiXmlString & b);
+
+
+/*
+ TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString.
+ Only the operators that we need for TinyXML have been developped.
+*/
+class TiXmlOutStream : public TiXmlString
+{
+public :
+
+ // TiXmlOutStream << operator.
+ TiXmlOutStream & operator << (const TiXmlString & in)
+ {
+ *this += in;
+ return *this;
+ }
+
+ // TiXmlOutStream << operator.
+ TiXmlOutStream & operator << (const char * in)
+ {
+ *this += in;
+ return *this;
+ }
+
+} ;
+
+#endif // TIXML_STRING_INCLUDED
+#endif // TIXML_USE_STL
diff --git a/plugins/UserInfoEx/ex_import/tinyxml.cpp b/plugins/UserInfoEx/ex_import/tinyxml.cpp
new file mode 100644
index 0000000000..2eba13a7ea
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/tinyxml.cpp
@@ -0,0 +1,1978 @@
+/*
+www.sourceforge.net/projects/tinyxml
+Original code (2.0 and earlier)copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
+damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
+redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
+would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and
+must not be misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
+
+===============================================================================
+
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/tinyxml.cpp $
+Revision : $Revision: 196 $
+Last change on : $Date: 2010-09-21 03:24:30 +0400 (Вт, 21 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+ */
+#include "tinyxml.h"
+
+#include <ctype.h>
+
+#ifdef TIXML_USE_STL
+#include <sstream>
+#include <iostream>
+#endif
+
+#ifdef USE_MMGR
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "mmgr.h"
+#endif
+
+
+bool TiXmlBase::condenseWhiteSpace = true;
+
+void TiXmlBase::StreamDepth(TIXML_OSTREAM* stream, int depth) const
+{
+ for (int i = 0; i < depth; ++i)
+ {
+ (*stream) << " ";
+ }
+}
+
+void TiXmlBase::PutString(const TIXML_STRING& str, TIXML_OSTREAM* stream)
+{
+ TIXML_STRING buffer;
+ PutString(str, &buffer);
+ (*stream) << buffer;
+}
+
+void TiXmlBase::PutString(const TIXML_STRING& str, TIXML_STRING* outString)
+{
+ int i=0;
+
+ while (i<(int)str.length())
+ {
+ unsigned char c = (unsigned char) str[i];
+
+ if ( c == '&'
+ && i < ((int)str.length() - 2)
+ && str[i+1] == '#'
+ && str[i+2] == 'x')
+ {
+ // Hexadecimal character reference.
+ // Pass through unchanged.
+ // &#xA9; -- copyright symbol, for example.
+ //
+ // The -1 is a bug fix from Rob Laveaux. It keeps
+ // an overflow from happening if there is no ';'.
+ // There are actually 2 ways to exit this loop -
+ // while fails (error case) and break (semicolon found).
+ // However, there is no mechanism (currently) for
+ // this function to return an error.
+ while (i<(int)str.length()-1)
+ {
+ outString->append(str.c_str() + i, 1);
+ ++i;
+ if (str[i] == ';')
+ break;
+ }
+ }
+ else if (c == '&')
+ {
+ outString->append(entity[0].str, entity[0].strLength);
+ ++i;
+ }
+ else if (c == '<')
+ {
+ outString->append(entity[1].str, entity[1].strLength);
+ ++i;
+ }
+ else if (c == '>')
+ {
+ outString->append(entity[2].str, entity[2].strLength);
+ ++i;
+ }
+ else if (c == '\"')
+ {
+ outString->append(entity[3].str, entity[3].strLength);
+ ++i;
+ }
+ else if (c == '\'')
+ {
+ outString->append(entity[4].str, entity[4].strLength);
+ ++i;
+ }
+ else if (c < 32)
+ {
+ // Easy pass at non-alpha/numeric/symbol
+ // Below 32 is symbolic.
+ char buf[ 32 ];
+
+ #if defined(TIXML_SNPRINTF)
+ TIXML_SNPRINTF(buf, sizeof(buf), "&#x%02X;", (unsigned) (c & 0xff));
+ #else
+ sprintf(buf, "&#x%02X;", (unsigned) (c & 0xff));
+ #endif
+
+ //*ME: warning C4267: convert 'size_t' to 'int'
+ //*ME: Int-Cast to make compiler happy ...
+ outString->append(buf, (int)strlen(buf));
+ ++i;
+ }
+ else
+ {
+ //char realc = (char) c;
+ //outString->append(&realc, 1);
+ *outString += (char) c; // somewhat more efficient function call.
+ ++i;
+ }
+ }
+}
+
+
+// <-- Strange class for a bug fix. Search for STL_STRING_BUG
+TiXmlBase::StringToBuffer::StringToBuffer(const TIXML_STRING& str)
+{
+ buffer = new char[ str.length()+1 ];
+ if (buffer)
+ {
+ strcpy(buffer, str.c_str());
+ }
+}
+
+
+TiXmlBase::StringToBuffer::~StringToBuffer()
+{
+ delete [] buffer;
+}
+// End strange bug fix. -->
+
+
+TiXmlNode::TiXmlNode(NodeType _type) : TiXmlBase()
+{
+ parent = 0;
+ type = _type;
+ firstChild = 0;
+ lastChild = 0;
+ prev = 0;
+ next = 0;
+}
+
+
+TiXmlNode::~TiXmlNode()
+{
+ TiXmlNode* node = firstChild;
+ TiXmlNode* temp = 0;
+
+ while (node)
+ {
+ temp = node;
+ node = node->next;
+
+ delete temp;
+ }
+}
+
+
+void TiXmlNode::CopyTo(TiXmlNode* target) const
+{
+ target->SetValue (value.c_str());
+ target->userData = userData;
+}
+
+
+void TiXmlNode::Clear()
+{
+ TiXmlNode* node = firstChild;
+ TiXmlNode* temp = 0;
+
+ while (node)
+ {
+ temp = node;
+ node = node->next;
+ delete temp;
+ }
+
+ firstChild = 0;
+ lastChild = 0;
+}
+
+
+TiXmlNode* TiXmlNode::LinkEndChild(TiXmlNode* node)
+{
+ assert(node->parent == 0 || node->parent == this);
+ assert(node->GetDocument() == 0 || node->GetDocument() == this->GetDocument());
+
+ if (node->Type() == TiXmlNode::DOCUMENT)
+ {
+ delete node;
+ if (GetDocument()) GetDocument()->SetError(TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return 0;
+ }
+
+ node->parent = this;
+
+ node->prev = lastChild;
+ node->next = 0;
+
+ if (lastChild)
+ lastChild->next = node;
+ else
+ firstChild = node; // it was an empty list.
+
+ lastChild = node;
+ return node;
+}
+
+
+TiXmlNode* TiXmlNode::InsertEndChild(const TiXmlNode& addThis)
+{
+ if (addThis.Type() == TiXmlNode::DOCUMENT)
+ {
+ if (GetDocument()) GetDocument()->SetError(TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return 0;
+ }
+ TiXmlNode* node = addThis.Clone();
+ if (!node)
+ return 0;
+
+ return LinkEndChild(node);
+}
+
+
+TiXmlNode* TiXmlNode::InsertBeforeChild(TiXmlNode* beforeThis, const TiXmlNode& addThis)
+{
+ if (!beforeThis || beforeThis->parent != this) {
+ return 0;
+ }
+ if (addThis.Type() == TiXmlNode::DOCUMENT)
+ {
+ if (GetDocument()) GetDocument()->SetError(TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return 0;
+ }
+
+ TiXmlNode* node = addThis.Clone();
+ if (!node)
+ return 0;
+ node->parent = this;
+
+ node->next = beforeThis;
+ node->prev = beforeThis->prev;
+ if (beforeThis->prev)
+ {
+ beforeThis->prev->next = node;
+ }
+ else
+ {
+ assert(firstChild == beforeThis);
+ firstChild = node;
+ }
+ beforeThis->prev = node;
+ return node;
+}
+
+
+TiXmlNode* TiXmlNode::InsertAfterChild(TiXmlNode* afterThis, const TiXmlNode& addThis)
+{
+ if (!afterThis || afterThis->parent != this) {
+ return 0;
+ }
+ if (addThis.Type() == TiXmlNode::DOCUMENT)
+ {
+ if (GetDocument()) GetDocument()->SetError(TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return 0;
+ }
+
+ TiXmlNode* node = addThis.Clone();
+ if (!node)
+ return 0;
+ node->parent = this;
+
+ node->prev = afterThis;
+ node->next = afterThis->next;
+ if (afterThis->next)
+ {
+ afterThis->next->prev = node;
+ }
+ else
+ {
+ assert(lastChild == afterThis);
+ lastChild = node;
+ }
+ afterThis->next = node;
+ return node;
+}
+
+
+TiXmlNode* TiXmlNode::ReplaceChild(TiXmlNode* replaceThis, const TiXmlNode& withThis)
+{
+ if (replaceThis->parent != this)
+ return 0;
+
+ TiXmlNode* node = withThis.Clone();
+ if (!node)
+ return 0;
+
+ node->next = replaceThis->next;
+ node->prev = replaceThis->prev;
+
+ if (replaceThis->next)
+ replaceThis->next->prev = node;
+ else
+ lastChild = node;
+
+ if (replaceThis->prev)
+ replaceThis->prev->next = node;
+ else
+ firstChild = node;
+
+ delete replaceThis;
+ node->parent = this;
+ return node;
+}
+
+
+bool TiXmlNode::RemoveChild(TiXmlNode* removeThis)
+{
+ if (removeThis->parent != this)
+ {
+ assert(0);
+ return false;
+ }
+
+ if (removeThis->next)
+ removeThis->next->prev = removeThis->prev;
+ else
+ lastChild = removeThis->prev;
+
+ if (removeThis->prev)
+ removeThis->prev->next = removeThis->next;
+ else
+ firstChild = removeThis->next;
+
+ delete removeThis;
+ return true;
+}
+
+const TiXmlNode* TiXmlNode::FirstChild(const char * _value) const
+{
+ const TiXmlNode* node;
+ for (node = firstChild; node; node = node->next)
+ {
+ if (strcmp(node->Value(), _value) == 0)
+ return node;
+ }
+ return 0;
+}
+
+
+TiXmlNode* TiXmlNode::FirstChild(const char * _value)
+{
+ TiXmlNode* node;
+ for (node = firstChild; node; node = node->next)
+ {
+ if (strcmp(node->Value(), _value) == 0)
+ return node;
+ }
+ return 0;
+}
+
+
+const TiXmlNode* TiXmlNode::LastChild(const char * _value) const
+{
+ const TiXmlNode* node;
+ for (node = lastChild; node; node = node->prev)
+ {
+ if (strcmp(node->Value(), _value) == 0)
+ return node;
+ }
+ return 0;
+}
+
+TiXmlNode* TiXmlNode::LastChild(const char * _value)
+{
+ TiXmlNode* node;
+ for (node = lastChild; node; node = node->prev)
+ {
+ if (strcmp(node->Value(), _value) == 0)
+ return node;
+ }
+ return 0;
+}
+
+const TiXmlNode* TiXmlNode::IterateChildren(const TiXmlNode* previous) const
+{
+ if (!previous)
+ {
+ return FirstChild();
+ }
+ else
+ {
+ assert(previous->parent == this);
+ return previous->NextSibling();
+ }
+}
+
+TiXmlNode* TiXmlNode::IterateChildren(TiXmlNode* previous)
+{
+ if (!previous)
+ {
+ return FirstChild();
+ }
+ else
+ {
+ assert(previous->parent == this);
+ return previous->NextSibling();
+ }
+}
+
+const TiXmlNode* TiXmlNode::IterateChildren(const char * val, const TiXmlNode* previous) const
+{
+ if (!previous)
+ {
+ return FirstChild(val);
+ }
+ else
+ {
+ assert(previous->parent == this);
+ return previous->NextSibling(val);
+ }
+}
+
+TiXmlNode* TiXmlNode::IterateChildren(const char * val, TiXmlNode* previous)
+{
+ if (!previous)
+ {
+ return FirstChild(val);
+ }
+ else
+ {
+ assert(previous->parent == this);
+ return previous->NextSibling(val);
+ }
+}
+
+const TiXmlNode* TiXmlNode::NextSibling(const char * _value) const
+{
+ const TiXmlNode* node;
+ for (node = next; node; node = node->next)
+ {
+ if (strcmp(node->Value(), _value) == 0)
+ return node;
+ }
+ return 0;
+}
+
+TiXmlNode* TiXmlNode::NextSibling(const char * _value)
+{
+ TiXmlNode* node;
+ for (node = next; node; node = node->next)
+ {
+ if (strcmp(node->Value(), _value) == 0)
+ return node;
+ }
+ return 0;
+}
+
+const TiXmlNode* TiXmlNode::PreviousSibling(const char * _value) const
+{
+ const TiXmlNode* node;
+ for (node = prev; node; node = node->prev)
+ {
+ if (strcmp(node->Value(), _value) == 0)
+ return node;
+ }
+ return 0;
+}
+
+TiXmlNode* TiXmlNode::PreviousSibling(const char * _value)
+{
+ TiXmlNode* node;
+ for (node = prev; node; node = node->prev)
+ {
+ if (strcmp(node->Value(), _value) == 0)
+ return node;
+ }
+ return 0;
+}
+
+void TiXmlElement::RemoveAttribute(const char * name)
+{
+ TIXML_STRING str(name);
+ TiXmlAttribute* node = attributeSet.Find(str);
+ if (node)
+ {
+ attributeSet.Remove(node);
+ delete node;
+ }
+}
+
+const TiXmlElement* TiXmlNode::FirstChildElement() const
+{
+ const TiXmlNode* node;
+
+ for ( node = FirstChild();
+ node;
+ node = node->NextSibling())
+ {
+ if (node->ToElement())
+ return node->ToElement();
+ }
+ return 0;
+}
+
+TiXmlElement* TiXmlNode::FirstChildElement()
+{
+ TiXmlNode* node;
+
+ for ( node = FirstChild();
+ node;
+ node = node->NextSibling())
+ {
+ if (node->ToElement())
+ return node->ToElement();
+ }
+ return 0;
+}
+
+const TiXmlElement* TiXmlNode::FirstChildElement(const char * _value) const
+{
+ const TiXmlNode* node;
+
+ for ( node = FirstChild(_value);
+ node;
+ node = node->NextSibling(_value))
+ {
+ if (node->ToElement())
+ return node->ToElement();
+ }
+ return 0;
+}
+
+TiXmlElement* TiXmlNode::FirstChildElement(const char * _value)
+{
+ TiXmlNode* node;
+
+ for ( node = FirstChild(_value);
+ node;
+ node = node->NextSibling(_value))
+ {
+ if (node->ToElement())
+ return node->ToElement();
+ }
+ return 0;
+}
+
+const TiXmlElement* TiXmlNode::NextSiblingElement() const
+{
+ const TiXmlNode* node;
+
+ for ( node = NextSibling();
+ node;
+ node = node->NextSibling())
+ {
+ if (node->ToElement())
+ return node->ToElement();
+ }
+ return 0;
+}
+
+TiXmlElement* TiXmlNode::NextSiblingElement()
+{
+ TiXmlNode* node;
+
+ for ( node = NextSibling();
+ node;
+ node = node->NextSibling())
+ {
+ if (node->ToElement())
+ return node->ToElement();
+ }
+ return 0;
+}
+
+const TiXmlElement* TiXmlNode::NextSiblingElement(const char * _value) const
+{
+ const TiXmlNode* node;
+
+ for ( node = NextSibling(_value);
+ node;
+ node = node->NextSibling(_value))
+ {
+ if (node->ToElement())
+ return node->ToElement();
+ }
+ return 0;
+}
+
+TiXmlElement* TiXmlNode::NextSiblingElement(const char * _value)
+{
+ TiXmlNode* node;
+
+ for ( node = NextSibling(_value);
+ node;
+ node = node->NextSibling(_value))
+ {
+ if (node->ToElement())
+ return node->ToElement();
+ }
+ return 0;
+}
+
+
+const TiXmlDocument* TiXmlNode::GetDocument() const
+{
+ const TiXmlNode* node;
+
+ for (node = this; node; node = node->parent)
+ {
+ if (node->ToDocument())
+ return node->ToDocument();
+ }
+ return 0;
+}
+
+TiXmlDocument* TiXmlNode::GetDocument()
+{
+ TiXmlNode* node;
+
+ for (node = this; node; node = node->parent)
+ {
+ if (node->ToDocument())
+ return node->ToDocument();
+ }
+ return 0;
+}
+
+TiXmlElement::TiXmlElement (const char * _value)
+ : TiXmlNode(TiXmlNode::ELEMENT)
+{
+ firstChild = lastChild = 0;
+ value = _value;
+}
+
+
+#ifdef TIXML_USE_STL
+TiXmlElement::TiXmlElement(const std::string& _value)
+ : TiXmlNode(TiXmlNode::ELEMENT)
+{
+ firstChild = lastChild = 0;
+ value = _value;
+}
+#endif
+
+
+TiXmlElement::TiXmlElement(const TiXmlElement& copy)
+ : TiXmlNode(TiXmlNode::ELEMENT)
+{
+ firstChild = lastChild = 0;
+ copy.CopyTo(this);
+}
+
+
+void TiXmlElement::operator=(const TiXmlElement& base)
+{
+ ClearThis();
+ base.CopyTo(this);
+}
+
+
+TiXmlElement::~TiXmlElement()
+{
+ ClearThis();
+}
+
+
+void TiXmlElement::ClearThis()
+{
+ Clear();
+ while (attributeSet.First())
+ {
+ TiXmlAttribute* node = attributeSet.First();
+ attributeSet.Remove(node);
+ delete node;
+ }
+}
+
+
+const char * TiXmlElement::Attribute(const char * name) const
+{
+ TIXML_STRING str(name);
+ const TiXmlAttribute* node = attributeSet.Find(str);
+
+ if (node)
+ return node->Value();
+
+ return 0;
+}
+
+
+const char * TiXmlElement::Attribute(const char * name, int* i) const
+{
+ const char * s = Attribute(name);
+ if (i)
+ {
+ if (s)
+ *i = (int)_atoi64(s);
+ else
+ *i = 0;
+ }
+ return s;
+}
+
+
+const char * TiXmlElement::Attribute(const char * name, double* d) const
+{
+ const char * s = Attribute(name);
+ if (d)
+ {
+ if (s)
+ *d = atof(s);
+ else
+ *d = 0;
+ }
+ return s;
+}
+
+
+int TiXmlElement::QueryIntAttribute(const char* name, int* ival) const
+{
+ TIXML_STRING str(name);
+ const TiXmlAttribute* node = attributeSet.Find(str);
+ if (!node)
+ return TIXML_NO_ATTRIBUTE;
+
+ return node->QueryIntValue(ival);
+}
+
+
+int TiXmlElement::QueryDoubleAttribute(const char* name, double* dval) const
+{
+ TIXML_STRING str(name);
+ const TiXmlAttribute* node = attributeSet.Find(str);
+ if (!node)
+ return TIXML_NO_ATTRIBUTE;
+
+ return node->QueryDoubleValue(dval);
+}
+
+
+void TiXmlElement::SetAttribute(const char * name, int val)
+{
+ char buf[64];
+ #if defined(TIXML_SNPRINTF)
+ TIXML_SNPRINTF(buf, sizeof(buf), "%d", val);
+ #else
+ sprintf(buf, "%d", val);
+ #endif
+ SetAttribute(name, buf);
+}
+
+
+#ifdef TIXML_USE_STL
+void TiXmlElement::SetAttribute(const std::string& name, int val)
+{
+ std::ostringstream oss;
+ oss << val;
+ SetAttribute(name, oss.str());
+}
+#endif
+
+
+void TiXmlElement::SetDoubleAttribute(const char * name, double val)
+{
+ char buf[256];
+ #if defined(TIXML_SNPRINTF)
+ TIXML_SNPRINTF(buf, sizeof(buf), "%f", val);
+ #else
+ sprintf(buf, "%f", val);
+ #endif
+ SetAttribute(name, buf);
+}
+
+
+void TiXmlElement::SetAttribute(const char * cname, const char * cvalue)
+{
+ TIXML_STRING _name(cname);
+ TIXML_STRING _value(cvalue);
+
+ TiXmlAttribute* node = attributeSet.Find(_name);
+ if (node)
+ {
+ node->SetValue(cvalue);
+ return;
+ }
+
+ TiXmlAttribute* attrib = new TiXmlAttribute(cname, cvalue);
+ if (attrib)
+ {
+ attributeSet.Add(attrib);
+ }
+ else
+ {
+ TiXmlDocument* document = GetDocument();
+ if (document) document->SetError(TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN);
+ }
+}
+
+
+#ifdef TIXML_USE_STL
+void TiXmlElement::SetAttribute(const std::string& name, const std::string& _value)
+{
+ TiXmlAttribute* node = attributeSet.Find(name);
+ if (node)
+ {
+ node->SetValue(_value);
+ return;
+ }
+
+ TiXmlAttribute* attrib = new TiXmlAttribute(name, _value);
+ if (attrib)
+ {
+ attributeSet.Add(attrib);
+ }
+ else
+ {
+ TiXmlDocument* document = GetDocument();
+ if (document) document->SetError(TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN);
+ }
+}
+#endif
+
+
+void TiXmlElement::Print(FILE* cfile, int depth) const
+{
+ int i;
+ for (i=0; i<depth; i++)
+ {
+ fprintf(cfile, " ");
+ }
+
+ fprintf(cfile, "<%s", value.c_str());
+
+ const TiXmlAttribute* attrib;
+ for (attrib = attributeSet.First(); attrib; attrib = attrib->Next())
+ {
+ fprintf(cfile, " ");
+ attrib->Print(cfile, depth);
+ }
+
+ // There are 3 different formatting approaches:
+ // 1) An element without children is printed as a <foo /> node
+ // 2) An element with only a text child is printed as <foo> text </foo>
+ // 3) An element with children is printed on multiple lines.
+ TiXmlNode* node;
+ if (!firstChild)
+ {
+ fprintf(cfile, " />");
+ }
+ else if (firstChild == lastChild && firstChild->ToText())
+ {
+ fprintf(cfile, ">");
+ firstChild->Print(cfile, depth + 1);
+ fprintf(cfile, "</%s>", value.c_str());
+ }
+ else
+ {
+ fprintf(cfile, ">");
+
+ for (node = firstChild; node; node=node->NextSibling())
+ {
+ if (!node->ToText())
+ {
+ fprintf(cfile, "\n");
+ }
+ node->Print(cfile, depth+1);
+ }
+ fprintf(cfile, "\n");
+ for (i=0; i<depth; ++i)
+ fprintf(cfile, " ");
+ fprintf(cfile, "</%s>", value.c_str());
+ }
+}
+
+void TiXmlElement::StreamOut(TIXML_OSTREAM * stream) const
+{
+ (*stream) << "<" << value;
+
+ const TiXmlAttribute* attrib;
+ for (attrib = attributeSet.First(); attrib; attrib = attrib->Next())
+ {
+ (*stream) << " ";
+ attrib->StreamOut(stream);
+ }
+
+ // If this node has children, give it a closing tag. Else
+ // make it an empty tag.
+ TiXmlNode* node;
+ if (firstChild)
+ {
+ (*stream) << ">";
+
+ for (node = firstChild; node; node=node->NextSibling())
+ {
+ node->StreamOut(stream);
+ }
+ (*stream) << "</" << value << ">";
+ }
+ else
+ {
+ (*stream) << " />";
+ }
+}
+
+void TiXmlElement::FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const
+{
+ // Adding tabs to get the proper tree format
+ int oldDepth = depth;
+ StreamDepth(stream, depth);
+
+ // Element name
+ (*stream) << "<" << value;
+
+ // Attributes
+ const TiXmlAttribute* attrib;
+ for (attrib = attributeSet.First(); attrib; attrib = attrib->Next())
+ {
+ (*stream) << " ";
+ attrib->StreamOut(stream);
+ }
+
+ // There are 3 different formatting approaches:
+ // 1) An element without children is printed as a <foo /> node
+ // 2) An element with only a text child is printed as <foo> text </foo>
+ // 3) An element with children is printed on multiple lines.
+ TiXmlNode* node;
+ if (!firstChild)
+ {
+ (*stream) << " />" << TIXML_ENDL;
+ }
+ else if (firstChild == lastChild && firstChild->ToText())
+ {
+ (*stream) << ">";
+ firstChild->FormattedStreamOut(stream, depth + 1);
+ (*stream) << "</" << value << ">" << TIXML_ENDL;
+ }
+ else
+ {
+ (*stream) << ">" << TIXML_ENDL;
+
+ // Children
+ depth++;
+ for (node = firstChild; node; node=node->NextSibling())
+ {
+ node->FormattedStreamOut(stream, depth);
+ }
+ StreamDepth(stream, oldDepth);
+ (*stream) << "</" << value << ">" << TIXML_ENDL;
+ }
+}
+
+void TiXmlElement::CopyTo(TiXmlElement* target) const
+{
+ // superclass:
+ TiXmlNode::CopyTo(target);
+
+ // Element class:
+ // Clone the attributes, then clone the children.
+ const TiXmlAttribute* attribute = 0;
+ for ( attribute = attributeSet.First();
+ attribute;
+ attribute = attribute->Next())
+ {
+ target->SetAttribute(attribute->Name(), attribute->Value());
+ }
+
+ TiXmlNode* node = 0;
+ for (node = firstChild; node; node = node->NextSibling())
+ {
+ target->LinkEndChild(node->Clone());
+ }
+}
+
+
+TiXmlNode* TiXmlElement::Clone() const
+{
+ TiXmlElement* clone = new TiXmlElement(Value());
+ if (!clone)
+ return 0;
+
+ CopyTo(clone);
+ return clone;
+}
+
+
+const char* TiXmlElement::GetText() const
+{
+ const TiXmlNode* child = this->FirstChild();
+ if (child) {
+ const TiXmlText* childText = child->ToText();
+ if (childText) {
+ return childText->Value();
+ }
+ }
+ return 0;
+}
+
+
+TiXmlDocument::TiXmlDocument() : TiXmlNode(TiXmlNode::DOCUMENT)
+{
+ tabsize = 4;
+ useMicrosoftBOM = false;
+ ClearError();
+}
+
+TiXmlDocument::TiXmlDocument(const char * documentName) : TiXmlNode(TiXmlNode::DOCUMENT)
+{
+ tabsize = 4;
+ useMicrosoftBOM = false;
+ value = documentName;
+ ClearError();
+}
+
+
+#ifdef TIXML_USE_STL
+TiXmlDocument::TiXmlDocument(const std::string& documentName) : TiXmlNode(TiXmlNode::DOCUMENT)
+{
+ tabsize = 4;
+ useMicrosoftBOM = false;
+ value = documentName;
+ ClearError();
+}
+#endif
+
+
+TiXmlDocument::TiXmlDocument(const TiXmlDocument& copy) : TiXmlNode(TiXmlNode::DOCUMENT)
+{
+ copy.CopyTo(this);
+}
+
+
+void TiXmlDocument::operator=(const TiXmlDocument& copy)
+{
+ Clear();
+ copy.CopyTo(this);
+}
+
+
+bool TiXmlDocument::LoadFile(TiXmlEncoding encoding)
+{
+ // See STL_STRING_BUG below.
+ StringToBuffer buf(value);
+
+ if (buf.buffer && LoadFile(buf.buffer, encoding))
+ return true;
+
+ return false;
+}
+
+
+bool TiXmlDocument::SaveFile() const
+{
+ // See STL_STRING_BUG below.
+ StringToBuffer buf(value);
+
+ if (buf.buffer && SaveFile(buf.buffer))
+ return true;
+
+ return false;
+}
+
+#ifdef TIXML_USE_STL
+std::string TiXmlDocument::GetAsString()
+{
+ std::stringstream out;
+ FormattedStreamOut(&out, 0);
+ return out.str();
+}
+#endif
+
+bool TiXmlDocument::GetAsCharBuffer(char* buffer, size_t bufferSize)
+{
+ #ifdef TIXML_USE_STL
+ std::string data = GetAsString();
+ #else
+ TIXML_OSTREAM data;
+ FormattedStreamOut(&data, 0);
+ #endif
+
+ if (bufferSize < data.length())
+ {
+ return false;
+ }
+ else
+ {
+ strcpy(buffer, data.c_str());
+ return true;
+ }
+}
+
+bool TiXmlDocument::LoadFile(const char* filename, TiXmlEncoding encoding)
+{
+ // There was a really terrifying little bug here. The code:
+ // value = filename
+ // in the STL case, cause the assignment method of the std::string to
+ // be called. What is strange, is that the std::string had the same
+ // address as it's c_str() method, and so bad things happen. Looks
+ // like a bug in the Microsoft STL implementation.
+ // See STL_STRING_BUG above.
+ // Fixed with the StringToBuffer class.
+ value = filename;
+
+ // reading in binary mode so that tinyxml can normalize the EOL
+ FILE* file = fopen(value.c_str (), "rb");
+
+ if (file)
+ {
+ bool result = LoadFile(file, encoding);
+ fclose(file);
+ return result;
+ }
+ else
+ {
+ SetError(TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return false;
+ }
+}
+
+bool TiXmlDocument::LoadFile(FILE* file, TiXmlEncoding encoding)
+{
+ if (!file)
+ {
+ SetError(TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return false;
+ }
+
+ // Delete the existing data:
+ Clear();
+ location.Clear();
+
+ // Get the file size, so we can pre-allocate the string. HUGE speed impact.
+ long length = 0;
+ fseek(file, 0, SEEK_END);
+ length = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ // Strange case, but good to handle up front.
+ if (length == 0)
+ {
+ SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return false;
+ }
+
+ // If we have a file, assume it is all one big XML file, and read it in.
+ // The document parser may decide the document ends sooner than the entire file, however.
+ TIXML_STRING data;
+ data.reserve(length);
+
+ // Subtle bug here. TinyXml did use fgets. But from the XML spec:
+ // 2.11 End-of-Line Handling
+ // <snip>
+ // <quote>
+ // ...the XML processor MUST behave as if it normalized all line breaks in external
+ // parsed entities (including the document entity) on input, before parsing, by translating
+ // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to
+ // a single #xA character.
+ // </quote>
+ //
+ // It is not clear fgets does that, and certainly isn't clear it works cross platform.
+ // Generally, you expect fgets to translate from the convention of the OS to the c/unix
+ // convention, and not work generally.
+
+ /*
+ while (fgets(buf, sizeof(buf), file))
+ {
+ data += buf;
+ }
+ */
+
+ char* buf = new char[ length+1 ];
+ buf[0] = 0;
+
+ if (fread(buf, length, 1, file) != 1) {
+ delete [] buf;
+ SetError(TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return false;
+ }
+
+ const char* lastPos = buf;
+ const char* p = buf;
+
+ buf[length] = 0;
+ while (*p) {
+ assert(p < (buf+length));
+ if (*p == 0xa) {
+ // Newline character. No special rules for this. Append all the characters
+ // since the last string, and include the newline.
+ data.append(lastPos, (p-lastPos+1)); // append, include the newline
+ ++p; // move past the newline
+ lastPos = p; // and point to the new buffer (may be 0)
+ assert(p <= (buf+length));
+ }
+ else if (*p == 0xd) {
+ // Carriage return. Append what we have so far, then
+ // handle moving forward in the buffer.
+ if ((p-lastPos) > 0) {
+ data.append(lastPos, p-lastPos); // do not add the CR
+ }
+ data += (char)0xa; // a proper newline
+
+ if (*(p+1) == 0xa) {
+ // Carriage return - new line sequence
+ p += 2;
+ lastPos = p;
+ assert(p <= (buf+length));
+ }
+ else {
+ // it was followed by something else...that is presumably characters again.
+ ++p;
+ lastPos = p;
+ assert(p <= (buf+length));
+ }
+ }
+ else {
+ ++p;
+ }
+ }
+ // Handle any left over characters.
+ if (p-lastPos) {
+ data.append(lastPos, p-lastPos);
+ }
+ delete [] buf;
+ buf = 0;
+
+ Parse(data.c_str(), 0, encoding);
+
+ if ( Error())
+ return false;
+ else
+ return true;
+}
+
+
+bool TiXmlDocument::SaveFile(const char * filename) const
+{
+ // The old c stuff lives on...
+ FILE* fp = fopen(filename, "w");
+ if (fp)
+ {
+ bool result = SaveFile(fp);
+ fclose(fp);
+ return result;
+ }
+ return false;
+}
+
+
+bool TiXmlDocument::SaveFile(FILE* fp) const
+{
+ if (useMicrosoftBOM)
+ {
+ const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
+ const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
+ const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
+
+ fputc(TIXML_UTF_LEAD_0, fp);
+ fputc(TIXML_UTF_LEAD_1, fp);
+ fputc(TIXML_UTF_LEAD_2, fp);
+ }
+ Print(fp, 0);
+ return true;
+}
+
+
+void TiXmlDocument::CopyTo(TiXmlDocument* target) const
+{
+ TiXmlNode::CopyTo(target);
+
+ target->error = error;
+ target->errorDesc = errorDesc.c_str ();
+
+ TiXmlNode* node = 0;
+ for (node = firstChild; node; node = node->NextSibling())
+ {
+ target->LinkEndChild(node->Clone());
+ }
+}
+
+
+TiXmlNode* TiXmlDocument::Clone() const
+{
+ TiXmlDocument* clone = new TiXmlDocument();
+ if (!clone)
+ return 0;
+
+ CopyTo(clone);
+ return clone;
+}
+
+
+void TiXmlDocument::Print(FILE* cfile, int depth) const
+{
+ const TiXmlNode* node;
+ for (node=FirstChild(); node; node=node->NextSibling())
+ {
+ node->Print(cfile, depth);
+ fprintf(cfile, "\n");
+ }
+}
+
+void TiXmlDocument::StreamOut(TIXML_OSTREAM * out) const
+{
+ const TiXmlNode* node;
+ for (node=FirstChild(); node; node=node->NextSibling())
+ {
+ node->StreamOut(out);
+
+ // Special rule for streams: stop after the root element.
+ // The stream in code will only read one element, so don't
+ // write more than one.
+ if (node->ToElement())
+ break;
+ }
+}
+
+void TiXmlDocument::FormattedStreamOut(TIXML_OSTREAM * out, int depth) const
+{
+ const TiXmlNode* node;
+ for (node=FirstChild(); node; node=node->NextSibling())
+ {
+ node->FormattedStreamOut(out, depth);
+
+ // Special rule for streams: stop after the root element.
+ // The stream in code will only read one element, so don't
+ // write more than one.
+ if (node->ToElement())
+ break;
+ }
+}
+
+const TiXmlAttribute* TiXmlAttribute::Next() const
+{
+ // We are using knowledge of the sentinel. The sentinel
+ // have a value or name.
+ if (next->value.empty() && next->name.empty())
+ return 0;
+ return next;
+}
+
+TiXmlAttribute* TiXmlAttribute::Next()
+{
+ // We are using knowledge of the sentinel. The sentinel
+ // have a value or name.
+ if (next->value.empty() && next->name.empty())
+ return 0;
+ return next;
+}
+
+const TiXmlAttribute* TiXmlAttribute::Previous() const
+{
+ // We are using knowledge of the sentinel. The sentinel
+ // have a value or name.
+ if (prev->value.empty() && prev->name.empty())
+ return 0;
+ return prev;
+}
+
+TiXmlAttribute* TiXmlAttribute::Previous()
+{
+ // We are using knowledge of the sentinel. The sentinel
+ // have a value or name.
+ if (prev->value.empty() && prev->name.empty())
+ return 0;
+ return prev;
+}
+
+void TiXmlAttribute::Print(FILE* cfile, int /*depth*/) const
+{
+ TIXML_STRING n, v;
+
+ PutString(name, &n);
+ PutString(value, &v);
+
+ if (value.find ('\"') == TIXML_STRING::npos)
+ fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str());
+ else
+ fprintf (cfile, "%s='%s'", n.c_str(), v.c_str());
+}
+
+
+void TiXmlAttribute::StreamOut(TIXML_OSTREAM * stream) const
+{
+ if (value.find('\"') != TIXML_STRING::npos)
+ {
+ PutString(name, stream);
+ (*stream) << "=" << "'";
+ PutString(value, stream);
+ (*stream) << "'";
+ }
+ else
+ {
+ PutString(name, stream);
+ (*stream) << "=" << "\"";
+ PutString(value, stream);
+ (*stream) << "\"";
+ }
+}
+
+int TiXmlAttribute::QueryIntValue(int* ival) const
+{
+ if (sscanf(value.c_str(), "%d", ival) == 1)
+ return TIXML_SUCCESS;
+ return TIXML_WRONG_TYPE;
+}
+
+int TiXmlAttribute::QueryDoubleValue(double* dval) const
+{
+ if (sscanf(value.c_str(), "%lf", dval) == 1)
+ return TIXML_SUCCESS;
+ return TIXML_WRONG_TYPE;
+}
+
+void TiXmlAttribute::SetIntValue(int _value)
+{
+ char buf [64];
+ #if defined(TIXML_SNPRINTF)
+ TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value);
+ #else
+ sprintf (buf, "%d", _value);
+ #endif
+ SetValue (buf);
+}
+
+void TiXmlAttribute::SetDoubleValue(double _value)
+{
+ char buf [256];
+ #if defined(TIXML_SNPRINTF)
+ TIXML_SNPRINTF(buf, sizeof(buf), "%lf", _value);
+ #else
+ sprintf (buf, "%lf", _value);
+ #endif
+ SetValue (buf);
+}
+
+int TiXmlAttribute::IntValue() const
+{
+ return (int)_atoi64(value.c_str ());
+}
+
+double TiXmlAttribute::DoubleValue() const
+{
+ return atof (value.c_str ());
+}
+
+
+TiXmlComment::TiXmlComment(const TiXmlComment& copy) : TiXmlNode(TiXmlNode::COMMENT)
+{
+ copy.CopyTo(this);
+}
+
+
+void TiXmlComment::operator=(const TiXmlComment& base)
+{
+ Clear();
+ base.CopyTo(this);
+}
+
+
+void TiXmlComment::Print(FILE* cfile, int depth) const
+{
+ for (int i=0; i<depth; i++)
+ {
+ fputs(" ", cfile);
+ }
+ fprintf(cfile, "<!--%s-->", value.c_str());
+}
+
+void TiXmlComment::StreamOut(TIXML_OSTREAM * stream) const
+{
+ (*stream) << "<!--";
+ //PutString(value, stream);
+ (*stream) << value;
+ (*stream) << "-->";
+}
+
+void TiXmlComment::FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const
+{
+ StreamDepth(stream, depth);
+
+ StreamOut(stream);
+
+ (*stream) << TIXML_ENDL;
+}
+
+void TiXmlComment::CopyTo(TiXmlComment* target) const
+{
+ TiXmlNode::CopyTo(target);
+}
+
+
+TiXmlNode* TiXmlComment::Clone() const
+{
+ TiXmlComment* clone = new TiXmlComment();
+
+ if (!clone)
+ return 0;
+
+ CopyTo(clone);
+ return clone;
+}
+
+
+void TiXmlText::Print(FILE* cfile, int depth) const
+{
+ if (cdata)
+ {
+ int i;
+ fprintf(cfile, "\n");
+ for (i=0; i<depth; i++) {
+ fprintf(cfile, " ");
+ }
+ fprintf(cfile, "<![CDATA[");
+ fprintf(cfile, "%s", value.c_str()); // unformatted output
+ fprintf(cfile, "]]>\n");
+ }
+ else
+ {
+ TIXML_STRING buffer;
+ PutString(value, &buffer);
+ fprintf(cfile, "%s", buffer.c_str());
+ }
+}
+
+
+void TiXmlText::StreamOut(TIXML_OSTREAM * stream) const
+{
+ if (cdata)
+ {
+ (*stream) << "<![CDATA[" << value << "]]>";
+ }
+ else
+ {
+ PutString(value, stream);
+ }
+}
+
+void TiXmlText::FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const
+{
+ if (cdata)
+ {
+ (*stream) << TIXML_ENDL;
+ StreamDepth(stream, depth);
+ (*stream) << "<![CDATA[" << value << "]]>" << TIXML_ENDL;
+ }
+ else
+ {
+ PutString(value, stream);
+ }
+}
+
+void TiXmlText::CopyTo(TiXmlText* target) const
+{
+ TiXmlNode::CopyTo(target);
+ target->cdata = cdata;
+}
+
+
+TiXmlNode* TiXmlText::Clone() const
+{
+ TiXmlText* clone = 0;
+ clone = new TiXmlText("");
+
+ if (!clone)
+ return 0;
+
+ CopyTo(clone);
+ return clone;
+}
+
+
+TiXmlDeclaration::TiXmlDeclaration(const char * _version,
+ const char * _encoding,
+ const char * _standalone)
+ : TiXmlNode(TiXmlNode::DECLARATION)
+{
+ version = _version;
+ encoding = _encoding;
+ standalone = _standalone;
+}
+
+
+#ifdef TIXML_USE_STL
+TiXmlDeclaration::TiXmlDeclaration( const std::string& _version,
+ const std::string& _encoding,
+ const std::string& _standalone)
+ : TiXmlNode(TiXmlNode::DECLARATION)
+{
+ version = _version;
+ encoding = _encoding;
+ standalone = _standalone;
+}
+#endif
+
+
+TiXmlDeclaration::TiXmlDeclaration(const TiXmlDeclaration& copy)
+ : TiXmlNode(TiXmlNode::DECLARATION)
+{
+ copy.CopyTo(this);
+}
+
+
+void TiXmlDeclaration::operator=(const TiXmlDeclaration& copy)
+{
+ Clear();
+ copy.CopyTo(this);
+}
+
+
+void TiXmlDeclaration::Print(FILE* cfile, int /*depth*/) const
+{
+ fprintf (cfile, "<?xml ");
+
+ if (!version.empty())
+ fprintf (cfile, "version=\"%s\" ", version.c_str ());
+ if (!encoding.empty())
+ fprintf (cfile, "encoding=\"%s\" ", encoding.c_str ());
+ if (!standalone.empty())
+ fprintf (cfile, "standalone=\"%s\" ", standalone.c_str ());
+ fprintf (cfile, "?>");
+}
+
+void TiXmlDeclaration::StreamOut(TIXML_OSTREAM * stream) const
+{
+ (*stream) << "<?xml ";
+
+ if (!version.empty())
+ {
+ (*stream) << "version=\"";
+ PutString(version, stream);
+ (*stream) << "\" ";
+ }
+ if (!encoding.empty())
+ {
+ (*stream) << "encoding=\"";
+ PutString(encoding, stream);
+ (*stream) << "\" ";
+ }
+ if (!standalone.empty())
+ {
+ (*stream) << "standalone=\"";
+ PutString(standalone, stream);
+ (*stream) << "\" ";
+ }
+ (*stream) << "?>";
+}
+
+void TiXmlDeclaration::FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const
+{
+ StreamDepth(stream, depth);
+ StreamOut(stream);
+ (*stream) << TIXML_ENDL;
+}
+
+void TiXmlDeclaration::CopyTo(TiXmlDeclaration* target) const
+{
+ TiXmlNode::CopyTo(target);
+
+ target->version = version;
+ target->encoding = encoding;
+ target->standalone = standalone;
+}
+
+
+TiXmlNode* TiXmlDeclaration::Clone() const
+{
+ TiXmlDeclaration* clone = new TiXmlDeclaration();
+
+ if (!clone)
+ return 0;
+
+ CopyTo(clone);
+ return clone;
+}
+
+
+void TiXmlUnknown::Print(FILE* cfile, int depth) const
+{
+ for (int i=0; i<depth; i++)
+ fprintf(cfile, " ");
+ fprintf(cfile, "<%s>", value.c_str());
+}
+
+
+void TiXmlUnknown::StreamOut(TIXML_OSTREAM * stream) const
+{
+ (*stream) << "<" << value << ">"; // Don't use entities here! It is unknown.
+}
+
+void TiXmlUnknown::FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const
+{
+ StreamDepth(stream, depth);
+ (*stream) << "<" << value << ">" << TIXML_ENDL; // Don't use entities here! It is unknown.
+}
+
+void TiXmlUnknown::CopyTo(TiXmlUnknown* target) const
+{
+ TiXmlNode::CopyTo(target);
+}
+
+
+TiXmlNode* TiXmlUnknown::Clone() const
+{
+ TiXmlUnknown* clone = new TiXmlUnknown();
+
+ if (!clone)
+ return 0;
+
+ CopyTo(clone);
+ return clone;
+}
+
+
+TiXmlAttributeSet::TiXmlAttributeSet()
+{
+ sentinel.next = &sentinel;
+ sentinel.prev = &sentinel;
+}
+
+
+TiXmlAttributeSet::~TiXmlAttributeSet()
+{
+ assert(sentinel.next == &sentinel);
+ assert(sentinel.prev == &sentinel);
+}
+
+
+void TiXmlAttributeSet::Add(TiXmlAttribute* addMe)
+{
+ assert(!Find(TIXML_STRING(addMe->Name()))); // Shouldn't be multiply adding to the set.
+
+ addMe->next = &sentinel;
+ addMe->prev = sentinel.prev;
+
+ sentinel.prev->next = addMe;
+ sentinel.prev = addMe;
+}
+
+void TiXmlAttributeSet::Remove(TiXmlAttribute* removeMe)
+{
+ TiXmlAttribute* node;
+
+ for (node = sentinel.next; node != &sentinel; node = node->next)
+ {
+ if (node == removeMe)
+ {
+ node->prev->next = node->next;
+ node->next->prev = node->prev;
+ node->next = 0;
+ node->prev = 0;
+ return;
+ }
+ }
+ assert(0); // we tried to remove a non-linked attribute.
+}
+
+const TiXmlAttribute* TiXmlAttributeSet::Find(const TIXML_STRING& name) const
+{
+ const TiXmlAttribute* node;
+
+ for (node = sentinel.next; node != &sentinel; node = node->next)
+ {
+ if (node->name == name)
+ return node;
+ }
+ return 0;
+}
+
+TiXmlAttribute* TiXmlAttributeSet::Find(const TIXML_STRING& name)
+{
+ TiXmlAttribute* node;
+
+ for (node = sentinel.next; node != &sentinel; node = node->next)
+ {
+ if (node->name == name)
+ return node;
+ }
+ return 0;
+}
+
+#ifdef TIXML_USE_STL
+TIXML_ISTREAM & operator >> (TIXML_ISTREAM & in, TiXmlNode & base)
+{
+ TIXML_STRING tag;
+ tag.reserve(8 * 1000);
+ base.StreamIn(&in, &tag);
+
+ base.Parse(tag.c_str(), 0, TIXML_DEFAULT_ENCODING);
+ return in;
+}
+#endif
+
+
+TIXML_OSTREAM & operator<< (TIXML_OSTREAM & out, const TiXmlNode & base)
+{
+ base.StreamOut (& out);
+ return out;
+}
+
+
+#ifdef TIXML_USE_STL
+std::string & operator<< (std::string& out, const TiXmlNode& base)
+{
+ std::ostringstream os_stream(std::ostringstream::out);
+ base.StreamOut(&os_stream);
+
+ out.append(os_stream.str());
+ return out;
+}
+#endif
+
+
+TiXmlHandle TiXmlHandle::FirstChild() const
+{
+ if (node)
+ {
+ TiXmlNode* child = node->FirstChild();
+ if (child)
+ return TiXmlHandle(child);
+ }
+ return TiXmlHandle(0);
+}
+
+
+TiXmlHandle TiXmlHandle::FirstChild(const char * value) const
+{
+ if (node)
+ {
+ TiXmlNode* child = node->FirstChild(value);
+ if (child)
+ return TiXmlHandle(child);
+ }
+ return TiXmlHandle(0);
+}
+
+
+TiXmlHandle TiXmlHandle::FirstChildElement() const
+{
+ if (node)
+ {
+ TiXmlElement* child = node->FirstChildElement();
+ if (child)
+ return TiXmlHandle(child);
+ }
+ return TiXmlHandle(0);
+}
+
+
+TiXmlHandle TiXmlHandle::FirstChildElement(const char * value) const
+{
+ if (node)
+ {
+ TiXmlElement* child = node->FirstChildElement(value);
+ if (child)
+ return TiXmlHandle(child);
+ }
+ return TiXmlHandle(0);
+}
+
+
+TiXmlHandle TiXmlHandle::Child(int count) const
+{
+ if (node)
+ {
+ int i;
+ TiXmlNode* child = node->FirstChild();
+ for ( i=0;
+ child && i<count;
+ child = child->NextSibling(), ++i)
+ {
+ // nothing
+ }
+ if (child)
+ return TiXmlHandle(child);
+ }
+ return TiXmlHandle(0);
+}
+
+
+TiXmlHandle TiXmlHandle::Child(const char* value, int count) const
+{
+ if (node)
+ {
+ int i;
+ TiXmlNode* child = node->FirstChild(value);
+ for ( i=0;
+ child && i<count;
+ child = child->NextSibling(value), ++i)
+ {
+ // nothing
+ }
+ if (child)
+ return TiXmlHandle(child);
+ }
+ return TiXmlHandle(0);
+}
+
+
+TiXmlHandle TiXmlHandle::ChildElement(int count) const
+{
+ if (node)
+ {
+ int i;
+ TiXmlElement* child = node->FirstChildElement();
+ for ( i=0;
+ child && i<count;
+ child = child->NextSiblingElement(), ++i)
+ {
+ // nothing
+ }
+ if (child)
+ return TiXmlHandle(child);
+ }
+ return TiXmlHandle(0);
+}
+
+
+TiXmlHandle TiXmlHandle::ChildElement(const char* value, int count) const
+{
+ if (node)
+ {
+ int i;
+ TiXmlElement* child = node->FirstChildElement(value);
+ for ( i=0;
+ child && i<count;
+ child = child->NextSiblingElement(value), ++i)
+ {
+ // nothing
+ }
+ if (child)
+ return TiXmlHandle(child);
+ }
+ return TiXmlHandle(0);
+}
diff --git a/plugins/UserInfoEx/ex_import/tinyxml.h b/plugins/UserInfoEx/ex_import/tinyxml.h
new file mode 100644
index 0000000000..b8246f4953
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/tinyxml.h
@@ -0,0 +1,1597 @@
+/*
+www.sourceforge.net/projects/tinyxml
+Original code (2.0 and earlier)copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
+damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
+redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
+would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and
+must not be misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
+
+===============================================================================
+
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/tinyxml.h $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+
+#ifndef TINYXML_INCLUDED
+#define TINYXML_INCLUDED
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4530)
+#pragma warning(disable : 4786)
+#endif
+
+#ifndef USE_MMGR
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#endif
+
+// Help out windows:
+#if defined(_DEBUG) && !defined(DEBUG)
+#define DEBUG
+#endif
+
+#ifdef TIXML_USE_TICPP
+ #ifndef TIXML_USE_STL
+ #define TIXML_USE_STL
+ #endif
+#endif
+
+#ifdef TIXML_USE_STL
+ #include <string>
+ #include <iostream>
+ #include <sstream>
+ #define TIXML_STRING std::string
+ #define TIXML_ISTREAM std::istream
+ #define TIXML_OSTREAM std::ostream
+ #define TIXML_ENDL std::endl
+#else
+ #include "tinystr.h"
+ #define TIXML_STRING TiXmlString
+ #define TIXML_OSTREAM TiXmlOutStream
+ #define TIXML_ENDL "\n"
+#endif
+
+// Deprecated library function hell. Compilers want to use the
+// new safe versions. This probably doesn't fully address the problem,
+// but it gets closer. There are too many compilers for me to fully
+// test. If you get compilation troubles, undefine TIXML_SAFE
+
+#define TIXML_SAFE // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress.
+#ifdef TIXML_SAFE
+ #if defined(_MSC_VER) && (_MSC_VER >= 1400)
+ // Microsoft visual studio, version 2005 and higher.
+ #define TIXML_SNPRINTF _snprintf_s
+ #define TIXML_SNSCANF _snscanf_s
+ #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
+ // Microsoft visual studio, version 6 and higher.
+ //#pragma message("Using _sn* functions.")
+ #define TIXML_SNPRINTF _snprintf
+ #define TIXML_SNSCANF _snscanf
+ #elif defined(__GNUC__) && (__GNUC__ >= 3)
+ // GCC version 3 and higher.s
+ //#warning("Using sn* functions.")
+ #define TIXML_SNPRINTF snprintf
+ #define TIXML_SNSCANF snscanf
+ #endif
+#endif
+
+class TiXmlDocument;
+class TiXmlElement;
+class TiXmlComment;
+class TiXmlUnknown;
+class TiXmlAttribute;
+class TiXmlText;
+class TiXmlDeclaration;
+class TiXmlParsingData;
+
+const int TIXML_MAJOR_VERSION = 2;
+const int TIXML_MINOR_VERSION = 4;
+const int TIXML_PATCH_VERSION = 3;
+
+/* Internal structure for tracking location of items
+ in the XML file.
+*/
+struct TiXmlCursor
+{
+ TiXmlCursor() { Clear(); }
+ void Clear() { row = col = -1; }
+
+ int row; // 0 based.
+ int col; // 0 based.
+};
+
+
+// Only used by Attribute::Query functions
+enum
+{
+ TIXML_SUCCESS,
+ TIXML_NO_ATTRIBUTE,
+ TIXML_WRONG_TYPE
+};
+
+
+// Used by the parsing routines.
+enum TiXmlEncoding
+{
+ TIXML_ENCODING_UNKNOWN,
+ TIXML_ENCODING_UTF8,
+ TIXML_ENCODING_LEGACY
+};
+
+const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
+
+/** TiXmlBase is a base class for every class in TinyXml.
+ It does little except to establish that TinyXml classes
+ can be printed and provide some utility functions.
+
+ In XML, the document and elements can contain
+ other elements and other types of nodes.
+
+ @verbatim
+ A Document can contain: Element (container or leaf)
+ Comment (leaf)
+ Unknown (leaf)
+ Declaration(leaf)
+
+ An Element can contain: Element (container or leaf)
+ Text (leaf)
+ Attributes (not on tree)
+ Comment (leaf)
+ Unknown (leaf)
+
+ A Decleration contains: Attributes (not on tree)
+ @endverbatim
+*/
+#ifdef TIXML_USE_TICPP
+#include "ticpprc.h"
+class TiXmlBase : public TiCppRC
+#else
+class TiXmlBase
+#endif
+{
+ friend class TiXmlNode;
+ friend class TiXmlElement;
+ friend class TiXmlDocument;
+
+public:
+ TiXmlBase() : userData(0) {}
+ virtual ~TiXmlBase() {}
+
+ /** All TinyXml classes can print themselves to a filestream.
+ This is a formatted print, and will insert tabs and newlines.
+
+ (For an unformatted stream, use the << operator.)
+ */
+ virtual void Print(FILE* cfile, int depth) const = 0;
+
+ /** The world does not agree on whether white space should be kept or
+ not. In order to make everyone happy, these global, static functions
+ are provided to set whether or not TinyXml will condense all white space
+ into a single space or not. The default is to condense. Note changing this
+ values is not thread safe.
+ */
+ static void SetCondenseWhiteSpace(bool condense) { condenseWhiteSpace = condense; }
+
+ /// Return the current white space setting.
+ static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
+
+ /** Return the position, in the original source file, of this node or attribute.
+ The row and column are 1-based. (That is the first row and first column is
+ 1,1). If the returns values are 0 or less, then the parser does not have
+ a row and column value.
+
+ Generally, the row and column value will be set when the TiXmlDocument::Load(),
+ TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set
+ when the DOM was created from operator>>.
+
+ The values reflect the initial load. Once the DOM is modified programmatically
+ (by adding or changing nodes and attributes) the new values will NOT update to
+ reflect changes in the document.
+
+ There is a minor performance cost to computing the row and column. Computation
+ can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value.
+
+ @sa TiXmlDocument::SetTabSize()
+ */
+ int Row() const { return location.row + 1; }
+ int Column() const { return location.col + 1; } ///< See Row()
+
+ void _SetUserData(void* user) { userData = user; }
+ void* _GetUserData() { return userData; }
+
+ // Table that returs, for a given lead byte, the total number of bytes
+ // in the UTF-8 sequence.
+ static const int utf8ByteTable[256];
+
+ virtual const char* Parse( const char* p,
+ TiXmlParsingData* data,
+ TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */) = 0;
+
+ enum
+ {
+ TIXML_NO_ERROR = 0,
+ TIXML_ERROR,
+ TIXML_ERROR_OPENING_FILE,
+ TIXML_ERROR_OUT_OF_MEMORY,
+ TIXML_ERROR_PARSING_ELEMENT,
+ TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
+ TIXML_ERROR_READING_ELEMENT_VALUE,
+ TIXML_ERROR_READING_ATTRIBUTES,
+ TIXML_ERROR_PARSING_EMPTY,
+ TIXML_ERROR_READING_END_TAG,
+ TIXML_ERROR_PARSING_UNKNOWN,
+ TIXML_ERROR_PARSING_COMMENT,
+ TIXML_ERROR_PARSING_DECLARATION,
+ TIXML_ERROR_DOCUMENT_EMPTY,
+ TIXML_ERROR_EMBEDDED_NULL,
+ TIXML_ERROR_PARSING_CDATA,
+ TIXML_ERROR_DOCUMENT_TOP_ONLY,
+
+ TIXML_ERROR_STRING_COUNT
+ };
+
+protected:
+
+ void StreamDepth(TIXML_OSTREAM* stream, int depth) const;
+
+ // See STL_STRING_BUG
+ // Utility class to overcome a bug.
+ class StringToBuffer
+ {
+ public:
+ StringToBuffer(const TIXML_STRING& str);
+ ~StringToBuffer();
+ char* buffer;
+ };
+
+ static const char* SkipWhiteSpace(const char*, TiXmlEncoding encoding);
+ inline static bool IsWhiteSpace(char c)
+ {
+ return (isspace((unsigned char) c) || c == '\n' || c == '\r');
+ }
+ inline static bool IsWhiteSpace(int c)
+ {
+ if (c < 256)
+ return IsWhiteSpace((char) c);
+ return false; // Again, only truly correct for English/Latin...but usually works.
+ }
+
+ virtual void StreamOut (TIXML_OSTREAM *) const = 0;
+ virtual void FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const = 0;
+
+ #ifdef TIXML_USE_STL
+ static bool StreamWhiteSpace(TIXML_ISTREAM * in, TIXML_STRING * tag);
+ static bool StreamTo(TIXML_ISTREAM * in, int character, TIXML_STRING * tag);
+ #endif
+
+ /* Reads an XML name into the string provided. Returns
+ a pointer just past the last character of the name,
+ or 0 if the function has an error.
+ */
+ static const char* ReadName(const char* p, TIXML_STRING* name, TiXmlEncoding encoding);
+
+ /* Reads text. Returns a pointer past the given end tag.
+ Wickedly complex options, but it keeps the (sensitive) code in one place.
+ */
+ static const char* ReadText( const char* in, // where to start
+ TIXML_STRING* text, // the string read
+ bool ignoreWhiteSpace, // whether to keep the white space
+ const char* endTag, // what ends this text
+ bool ignoreCase, // whether to ignore case in the end tag
+ TiXmlEncoding encoding); // the current encoding
+
+ // If an entity has been found, transform it into a character.
+ static const char* GetEntity(const char* in, char* value, int* length, TiXmlEncoding encoding);
+
+ // Get a character, while interpreting entities.
+ // The length can be from 0 to 4 bytes.
+ inline static const char* GetChar(const char* p, char* _value, int* length, TiXmlEncoding encoding)
+ {
+ assert(p);
+ if (encoding == TIXML_ENCODING_UTF8)
+ {
+ *length = utf8ByteTable[ *((unsigned char*)p) ];
+ assert(*length >= 0 && *length < 5);
+ }
+ else
+ {
+ *length = 1;
+ }
+
+ if (*length == 1)
+ {
+ if (*p == '&')
+ return GetEntity(p, _value, length, encoding);
+ *_value = *p;
+ return p+1;
+ }
+ else if (*length)
+ {
+ //strncpy(_value, p, *length); // lots of compilers don't like this function (unsafe),
+ // and the null terminator isn't needed
+ for (int i=0; p[i] && i<*length; ++i) {
+ _value[i] = p[i];
+ }
+ return p + (*length);
+ }
+ else
+ {
+ // Not valid text.
+ return 0;
+ }
+ }
+
+ // Puts a string to a stream, expanding entities as it goes.
+ // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
+ static void PutString(const TIXML_STRING& str, TIXML_OSTREAM* out);
+
+ static void PutString(const TIXML_STRING& str, TIXML_STRING* out);
+
+ // Return true if the next characters in the stream are any of the endTag sequences.
+ // Ignore case only works for english, and should only be relied on when comparing
+ // to English words: StringEqual(p, "version", true) is fine.
+ static bool StringEqual( const char* p,
+ const char* endTag,
+ bool ignoreCase,
+ TiXmlEncoding encoding);
+
+ static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
+
+ TiXmlCursor location;
+
+ /// Field containing a generic user pointer
+ void* userData;
+
+ // None of these methods are reliable for any language except English.
+ // Good for approximation, not great for accuracy.
+ static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding);
+ static int IsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding);
+ inline static int ToLower(int v, TiXmlEncoding encoding)
+ {
+ if (encoding == TIXML_ENCODING_UTF8)
+ {
+ if (v < 128) return tolower(v);
+ return v;
+ }
+ else
+ {
+ return tolower(v);
+ }
+ }
+ static void ConvertUTF32ToUTF8(unsigned long input, char* output, int* length);
+
+private:
+ TiXmlBase(const TiXmlBase&); // not implemented.
+ void operator=(const TiXmlBase& base); // not allowed.
+
+ struct Entity
+ {
+ const char* str;
+ unsigned int strLength;
+ char chr;
+ };
+ enum
+ {
+ NUM_ENTITY = 5,
+ MAX_ENTITY_LENGTH = 6
+
+ };
+ static Entity entity[ NUM_ENTITY ];
+ static bool condenseWhiteSpace;
+};
+
+
+/** The parent class for everything in the Document Object Model.
+ (Except for attributes).
+ Nodes have siblings, a parent, and children. A node can be
+ in a document, or stand on its own. The type of a TiXmlNode
+ can be queried, and it can be cast to its more defined type.
+*/
+class TiXmlNode : public TiXmlBase
+{
+ friend class TiXmlDocument;
+ friend class TiXmlElement;
+
+public:
+ #ifdef TIXML_USE_STL
+
+ /** An input stream operator, for every class. Tolerant of newlines and
+ formatting, but doesn't expect them.
+ */
+ friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
+
+ /** An output stream operator, for every class. Note that this outputs
+ without any newlines or formatting, as opposed to Print(), which
+ includes tabs and new lines.
+
+ The operator<< and operator>> are not completely symmetric. Writing
+ a node to a stream is very well defined. You'll get a nice stream
+ of output, without any extra whitespace or newlines.
+
+ But reading is not as well defined. (As it always is.) If you create
+ a TiXmlElement (for example) and read that from an input stream,
+ the text needs to define an element or junk will result. This is
+ true of all input streams, but it's worth keeping in mind.
+
+ A TiXmlDocument will read nodes until it reads a root element, and
+ all the children of that root element.
+ */
+ friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
+
+ /// Appends the XML node or attribute to a std::string.
+ friend std::string& operator<< (std::string& out, const TiXmlNode& base);
+
+ #else
+ // Used internally, not part of the public API.
+ friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
+ #endif
+
+ /** The types of XML nodes supported by TinyXml. (All the
+ unsupported types are picked up by UNKNOWN.)
+ */
+ enum NodeType
+ {
+ DOCUMENT,
+ ELEMENT,
+ COMMENT,
+ UNKNOWN,
+ TEXT,
+ DECLARATION,
+ TYPECOUNT
+ };
+
+ virtual ~TiXmlNode();
+
+ /** The meaning of 'value' changes for the specific type of
+ TiXmlNode.
+ @verbatim
+ Document: filename of the xml file
+ Element: name of the element
+ Comment: the comment text
+ Unknown: the tag contents
+ Text: the text string
+ @endverbatim
+
+ The subclasses will wrap this function.
+ */
+ const char *Value() const { return value.c_str (); }
+
+ #ifdef TIXML_USE_STL
+ /** Return Value() as a std::string. If you only use STL,
+ this is more efficient than calling Value().
+ Only available in STL mode.
+ */
+ const std::string& ValueStr() const { return value; }
+ #endif
+
+ /** Changes the value of the node. Defined as:
+ @verbatim
+ Document: filename of the xml file
+ Element: name of the element
+ Comment: the comment text
+ Unknown: the tag contents
+ Text: the text string
+ @endverbatim
+ */
+ void SetValue(const char * _value) { value = _value;}
+
+ #ifdef TIXML_USE_STL
+ /// STL std::string form.
+ void SetValue(const std::string& _value) { value = _value; }
+ #endif
+
+ /// Delete all the children of this node. Does not affect 'this'.
+ void Clear();
+
+ /// One step up the DOM.
+ TiXmlNode* Parent() { return parent; }
+ const TiXmlNode* Parent() const { return parent; }
+
+ const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children.
+ TiXmlNode* FirstChild() { return firstChild; }
+ const TiXmlNode* FirstChild(const char * value) const; ///< The first child of this node with the matching 'value'. Will be null if none found.
+ TiXmlNode* FirstChild(const char * value); ///< The first child of this node with the matching 'value'. Will be null if none found.
+
+ const TiXmlNode* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children.
+ TiXmlNode* LastChild() { return lastChild; }
+ const TiXmlNode* LastChild(const char * value) const; /// The last child of this node matching 'value'. Will be null if there are no children.
+ TiXmlNode* LastChild(const char * value);
+
+ #ifdef TIXML_USE_STL
+ const TiXmlNode* FirstChild(const std::string& _value) const { return FirstChild (_value.c_str ()); } ///< STL std::string form.
+ TiXmlNode* FirstChild(const std::string& _value) { return FirstChild (_value.c_str ()); } ///< STL std::string form.
+ const TiXmlNode* LastChild(const std::string& _value) const { return LastChild (_value.c_str ()); } ///< STL std::string form.
+ TiXmlNode* LastChild(const std::string& _value) { return LastChild (_value.c_str ()); } ///< STL std::string form.
+ #endif
+
+ /** An alternate way to walk the children of a node.
+ One way to iterate over nodes is:
+ @verbatim
+ for (child = parent->FirstChild(); child; child = child->NextSibling())
+ @endverbatim
+
+ IterateChildren does the same thing with the syntax:
+ @verbatim
+ child = 0;
+ while (child = parent->IterateChildren(child))
+ @endverbatim
+
+ IterateChildren takes the previous child as input and finds
+ the next one. If the previous child is null, it returns the
+ first. IterateChildren will return null when done.
+ */
+ const TiXmlNode* IterateChildren(const TiXmlNode* previous) const;
+ TiXmlNode* IterateChildren(TiXmlNode* previous);
+
+ /// This flavor of IterateChildren searches for children with a particular 'value'
+ const TiXmlNode* IterateChildren(const char * value, const TiXmlNode* previous) const;
+ TiXmlNode* IterateChildren(const char * value, TiXmlNode* previous);
+
+ #ifdef TIXML_USE_STL
+ const TiXmlNode* IterateChildren(const std::string& _value, const TiXmlNode* previous) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form.
+ TiXmlNode* IterateChildren(const std::string& _value, TiXmlNode* previous) { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form.
+ #endif
+
+ /** Add a new node related to this. Adds a child past the LastChild.
+ Returns a pointer to the new object or NULL if an error occured.
+ */
+ TiXmlNode* InsertEndChild(const TiXmlNode& addThis);
+
+
+ /** Add a new node related to this. Adds a child past the LastChild.
+
+ NOTE: the node to be added is passed by pointer, and will be
+ henceforth owned (and deleted) by tinyXml. This method is efficient
+ and avoids an extra copy, but should be used with care as it
+ uses a different memory model than the other insert functions.
+
+ @sa InsertEndChild
+ */
+ TiXmlNode* LinkEndChild(TiXmlNode* addThis);
+
+ /** Add a new node related to this. Adds a child before the specified child.
+ Returns a pointer to the new object or NULL if an error occured.
+ */
+ TiXmlNode* InsertBeforeChild(TiXmlNode* beforeThis, const TiXmlNode& addThis);
+
+ /** Add a new node related to this. Adds a child after the specified child.
+ Returns a pointer to the new object or NULL if an error occured.
+ */
+ TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis);
+
+ /** Replace a child of this node.
+ Returns a pointer to the new object or NULL if an error occured.
+ */
+ TiXmlNode* ReplaceChild(TiXmlNode* replaceThis, const TiXmlNode& withThis);
+
+ /// Delete a child of this node.
+ bool RemoveChild(TiXmlNode* removeThis);
+
+ /// Navigate to a sibling node.
+ const TiXmlNode* PreviousSibling() const { return prev; }
+ TiXmlNode* PreviousSibling() { return prev; }
+
+ /// Navigate to a sibling node.
+ const TiXmlNode* PreviousSibling(const char *) const;
+ TiXmlNode* PreviousSibling(const char *);
+
+ #ifdef TIXML_USE_STL
+ const TiXmlNode* PreviousSibling(const std::string& _value) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form.
+ TiXmlNode* PreviousSibling(const std::string& _value) { return PreviousSibling (_value.c_str ()); } ///< STL std::string form.
+ const TiXmlNode* NextSibling(const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form.
+ TiXmlNode* NextSibling(const std::string& _value) { return NextSibling (_value.c_str ()); } ///< STL std::string form.
+ #endif
+
+ /// Navigate to a sibling node.
+ const TiXmlNode* NextSibling() const { return next; }
+ TiXmlNode* NextSibling() { return next; }
+
+ /// Navigate to a sibling node with the given 'value'.
+ const TiXmlNode* NextSibling(const char *) const;
+ TiXmlNode* NextSibling(const char *);
+
+ /** Convenience function to get through elements.
+ Calls NextSibling and ToElement. Will skip all non-Element
+ nodes. Returns 0 if there is not another element.
+ */
+ const TiXmlElement* NextSiblingElement() const;
+ TiXmlElement* NextSiblingElement();
+
+ /** Convenience function to get through elements.
+ Calls NextSibling and ToElement. Will skip all non-Element
+ nodes. Returns 0 if there is not another element.
+ */
+ const TiXmlElement* NextSiblingElement(const char *) const;
+ TiXmlElement* NextSiblingElement(const char *);
+
+ #ifdef TIXML_USE_STL
+ const TiXmlElement* NextSiblingElement(const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form.
+ TiXmlElement* NextSiblingElement(const std::string& _value) { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form.
+ #endif
+
+ /// Convenience function to get through elements.
+ const TiXmlElement* FirstChildElement() const;
+ TiXmlElement* FirstChildElement();
+
+ /// Convenience function to get through elements.
+ const TiXmlElement* FirstChildElement(const char * value) const;
+ TiXmlElement* FirstChildElement(const char * value);
+
+ #ifdef TIXML_USE_STL
+ const TiXmlElement* FirstChildElement(const std::string& _value) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form.
+ TiXmlElement* FirstChildElement(const std::string& _value) { return FirstChildElement (_value.c_str ()); } ///< STL std::string form.
+ #endif
+
+ /** Query the type (as an enumerated value, above) of this node.
+ The possible types are: DOCUMENT, ELEMENT, COMMENT,
+ UNKNOWN, TEXT, and DECLARATION.
+ */
+ int Type() const { return type; }
+
+ /** Return a pointer to the Document this node lives in.
+ Returns null if not in a document.
+ */
+ const TiXmlDocument* GetDocument() const;
+ TiXmlDocument* GetDocument();
+
+ /// Returns true if this node has no children.
+ bool NoChildren() const { return !firstChild; }
+
+ virtual const TiXmlDocument* ToDocument() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+ virtual const TiXmlElement* ToElement() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+ virtual const TiXmlComment* ToComment() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+ virtual const TiXmlUnknown* ToUnknown() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+ virtual const TiXmlText* ToText() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+ virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+
+ virtual TiXmlDocument* ToDocument() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+ virtual TiXmlElement* ToElement() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+ virtual TiXmlComment* ToComment() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+ virtual TiXmlUnknown* ToUnknown() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+ virtual TiXmlText* ToText() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+ virtual TiXmlDeclaration* ToDeclaration() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
+
+ /** Create an exact duplicate of this node and return it. The memory must be deleted
+ by the caller.
+ */
+ virtual TiXmlNode* Clone() const = 0;
+
+protected:
+ TiXmlNode(NodeType _type);
+
+ // Copy to the allocated object. Shared functionality between Clone, Copy constructor,
+ // and the assignment operator.
+ void CopyTo(TiXmlNode* target) const;
+
+ #ifdef TIXML_USE_STL
+ // The real work of the input operator.
+ virtual void StreamIn(TIXML_ISTREAM* in, TIXML_STRING* tag) = 0;
+ #endif
+
+ // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
+ TiXmlNode* Identify(const char* start, TiXmlEncoding encoding);
+
+ TiXmlNode* parent;
+ NodeType type;
+
+ TiXmlNode* firstChild;
+ TiXmlNode* lastChild;
+
+ TIXML_STRING value;
+
+ TiXmlNode* prev;
+ TiXmlNode* next;
+
+private:
+ TiXmlNode(const TiXmlNode&); // not implemented.
+ void operator=(const TiXmlNode& base); // not allowed.
+};
+
+/** An attribute is a name-value pair. Elements have an arbitrary
+ number of attributes, each with a unique name.
+
+ @note The attributes are not TiXmlNodes, since they are not
+ part of the tinyXML document object model. There are other
+ suggested ways to look at this problem.
+*/
+class TiXmlAttribute : public TiXmlBase
+{
+ friend class TiXmlAttributeSet;
+
+public:
+ /// Construct an empty attribute.
+ TiXmlAttribute() : TiXmlBase()
+ {
+ document = 0;
+ prev = next = 0;
+ }
+
+ #ifdef TIXML_USE_STL
+ /// std::string constructor.
+ TiXmlAttribute(const std::string& _name, const std::string& _value)
+ {
+ name = _name;
+ value = _value;
+ document = 0;
+ prev = next = 0;
+ }
+ #endif
+
+ /// Construct an attribute with a name and value.
+ TiXmlAttribute(const char * _name, const char * _value)
+ {
+ name = _name;
+ value = _value;
+ document = 0;
+ prev = next = 0;
+ }
+
+ const char* Name() const { return name.c_str(); } ///< Return the name of this attribute.
+ const char* Value() const { return value.c_str(); } ///< Return the value of this attribute.
+ #ifdef TIXML_USE_STL
+ const std::string& ValueStr() const { return value; } ///< Return the value of this attribute.
+ #endif
+ int IntValue() const; ///< Return the value of this attribute, converted to an integer.
+ double DoubleValue() const; ///< Return the value of this attribute, converted to a double.
+
+ // Get the tinyxml string representation
+ const TIXML_STRING& NameTStr() const { return name; }
+
+ /** QueryIntValue examines the value string. It is an alternative to the
+ IntValue() method with richer error checking.
+ If the value is an integer, it is stored in 'value' and
+ the call returns TIXML_SUCCESS. If it is not
+ an integer, it returns TIXML_WRONG_TYPE.
+
+ A specialized but useful call. Note that for success it returns 0,
+ which is the opposite of almost all other TinyXml calls.
+ */
+ int QueryIntValue(int* _value) const;
+ /// QueryDoubleValue examines the value string. See QueryIntValue().
+ int QueryDoubleValue(double* _value) const;
+
+ void SetName(const char* _name) { name = _name; } ///< Set the name of this attribute.
+ void SetValue(const char* _value) { value = _value; } ///< Set the value.
+
+ void SetIntValue(int _value); ///< Set the value from an integer.
+ void SetDoubleValue(double _value); ///< Set the value from a double.
+
+ #ifdef TIXML_USE_STL
+ /// STL std::string form.
+ void SetName(const std::string& _name) { name = _name; }
+ /// STL std::string form.
+ void SetValue(const std::string& _value) { value = _value; }
+ #endif
+
+ /// Get the next sibling attribute in the DOM. Returns null at end.
+ const TiXmlAttribute* Next() const;
+ TiXmlAttribute* Next();
+ /// Get the previous sibling attribute in the DOM. Returns null at beginning.
+ const TiXmlAttribute* Previous() const;
+ TiXmlAttribute* Previous();
+
+ bool operator==(const TiXmlAttribute& rhs) const { return rhs.name == name; }
+ bool operator<(const TiXmlAttribute& rhs) const { return name < rhs.name; }
+ bool operator>(const TiXmlAttribute& rhs) const { return name > rhs.name; }
+
+ /* Attribute parsing starts: first letter of the name
+ returns: the next char after the value end quote
+ */
+ virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding);
+
+ // Prints this Attribute to a FILE stream.
+ virtual void Print(FILE* cfile, int depth) const;
+
+ virtual void StreamOut(TIXML_OSTREAM * out) const;
+ virtual void FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const {}
+
+ // [internal use]
+ // Set the document pointer so the attribute can report errors.
+ void SetDocument(TiXmlDocument* doc) { document = doc; }
+
+private:
+ TiXmlAttribute(const TiXmlAttribute&); // not implemented.
+ void operator=(const TiXmlAttribute& base); // not allowed.
+
+ TiXmlDocument* document; // A pointer back to a document, for error reporting.
+ TIXML_STRING name;
+ TIXML_STRING value;
+ TiXmlAttribute* prev;
+ TiXmlAttribute* next;
+};
+
+
+/* A class used to manage a group of attributes.
+ It is only used internally, both by the ELEMENT and the DECLARATION.
+
+ The set can be changed transparent to the Element and Declaration
+ classes that use it, but NOT transparent to the Attribute
+ which has to implement a next() and previous() method. Which makes
+ it a bit problematic and prevents the use of STL.
+
+ This version is implemented with circular lists because:
+ - I like circular lists
+ - it demonstrates some independence from the (typical) doubly linked list.
+*/
+class TiXmlAttributeSet
+{
+public:
+ TiXmlAttributeSet();
+ ~TiXmlAttributeSet();
+
+ void Add(TiXmlAttribute* attribute);
+ void Remove(TiXmlAttribute* attribute);
+
+ const TiXmlAttribute* First() const { return (sentinel.next == &sentinel) ? 0 : sentinel.next; }
+ TiXmlAttribute* First() { return (sentinel.next == &sentinel) ? 0 : sentinel.next; }
+ const TiXmlAttribute* Last() const { return (sentinel.prev == &sentinel) ? 0 : sentinel.prev; }
+ TiXmlAttribute* Last() { return (sentinel.prev == &sentinel) ? 0 : sentinel.prev; }
+
+ const TiXmlAttribute* Find(const TIXML_STRING& name) const;
+ TiXmlAttribute* Find(const TIXML_STRING& name);
+
+private:
+ //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),
+ //*ME: this class must be also use a hidden/disabled copy-constructor !!!
+ TiXmlAttributeSet(const TiXmlAttributeSet&); // not allowed
+ void operator=(const TiXmlAttributeSet&); // not allowed (as TiXmlAttribute)
+
+ TiXmlAttribute sentinel;
+};
+
+
+/** The element is a container class. It has a value, the element name,
+ and can contain other elements, text, comments, and unknowns.
+ Elements also contain an arbitrary number of attributes.
+*/
+class TiXmlElement : public TiXmlNode
+{
+public:
+ /// Construct an element.
+ TiXmlElement (const char * in_value);
+
+ #ifdef TIXML_USE_STL
+ /// std::string constructor.
+ TiXmlElement(const std::string& _value);
+ #endif
+
+ TiXmlElement(const TiXmlElement&);
+
+ void operator=(const TiXmlElement& base);
+
+ virtual ~TiXmlElement();
+
+ /** Given an attribute name, Attribute() returns the value
+ for the attribute of that name, or null if none exists.
+ */
+ const char* Attribute(const char* name) const;
+
+ /** Given an attribute name, Attribute() returns the value
+ for the attribute of that name, or null if none exists.
+ If the attribute exists and can be converted to an integer,
+ the integer value will be put in the return 'i', if 'i'
+ is non-null.
+ */
+ const char* Attribute(const char* name, int* i) const;
+
+ /** Given an attribute name, Attribute() returns the value
+ for the attribute of that name, or null if none exists.
+ If the attribute exists and can be converted to an double,
+ the double value will be put in the return 'd', if 'd'
+ is non-null.
+ */
+ const char* Attribute(const char* name, double* d) const;
+
+ /** QueryIntAttribute examines the attribute - it is an alternative to the
+ Attribute() method with richer error checking.
+ If the attribute is an integer, it is stored in 'value' and
+ the call returns TIXML_SUCCESS. If it is not
+ an integer, it returns TIXML_WRONG_TYPE. If the attribute
+ does not exist, then TIXML_NO_ATTRIBUTE is returned.
+ */
+ int QueryIntAttribute(const char* name, int* _value) const;
+ /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
+ int QueryDoubleAttribute(const char* name, double* _value) const;
+ /// QueryFloatAttribute examines the attribute - see QueryIntAttribute().
+ int QueryFloatAttribute(const char* name, float* _value) const {
+ double d;
+ int result = QueryDoubleAttribute(name, &d);
+ if (result == TIXML_SUCCESS) {
+ *_value = (float)d;
+ }
+ return result;
+ }
+ #ifdef TIXML_USE_STL
+ /** Template form of the attribute query which will try to read the
+ attribute into the specified type. Very easy, very powerful, but
+ be careful to make sure to call this with the correct type.
+
+ @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE
+ */
+ template< typename T > int QueryValueAttribute(const std::string& name, T* outValue) const
+ {
+ const TiXmlAttribute* node = attributeSet.Find(name);
+ if (!node)
+ return TIXML_NO_ATTRIBUTE;
+
+ std::stringstream sstream(node->ValueStr());
+ sstream >> *outValue;
+ if (!sstream.fail())
+ return TIXML_SUCCESS;
+ return TIXML_WRONG_TYPE;
+ }
+ #endif
+
+ /** Sets an attribute of name to a given value. The attribute
+ will be created if it does not exist, or changed if it does.
+ */
+ void SetAttribute(const char* name, const char * _value);
+
+ #ifdef TIXML_USE_STL
+ const char* Attribute(const std::string& name) const { return Attribute(name.c_str()); }
+ const char* Attribute(const std::string& name, int* i) const { return Attribute(name.c_str(), i); }
+ const char* Attribute(const std::string& name, double* d) const { return Attribute(name.c_str(), d); }
+ int QueryIntAttribute(const std::string& name, int* _value) const { return QueryIntAttribute(name.c_str(), _value); }
+ int QueryDoubleAttribute(const std::string& name, double* _value) const { return QueryDoubleAttribute(name.c_str(), _value); }
+
+ /// STL std::string form.
+ void SetAttribute(const std::string& name, const std::string& _value);
+ ///< STL std::string form.
+ void SetAttribute(const std::string& name, int _value);
+ #endif
+
+ /** Sets an attribute of name to a given value. The attribute
+ will be created if it does not exist, or changed if it does.
+ */
+ void SetAttribute(const char * name, int value);
+
+ /** Sets an attribute of name to a given value. The attribute
+ will be created if it does not exist, or changed if it does.
+ */
+ void SetDoubleAttribute(const char * name, double value);
+
+ /** Deletes an attribute with the given name.
+ */
+ void RemoveAttribute(const char * name);
+ #ifdef TIXML_USE_STL
+ void RemoveAttribute(const std::string& name) { RemoveAttribute (name.c_str ()); } ///< STL std::string form.
+ #endif
+
+ const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element.
+ TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
+ const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element.
+ TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
+
+ /** Convenience function for easy access to the text inside an element. Although easy
+ and concise, GetText() is limited compared to getting the TiXmlText child
+ and accessing it directly.
+
+ If the first child of 'this' is a TiXmlText, the GetText()
+ returns the character string of the Text node, else null is returned.
+
+ This is a convenient method for getting the text of simple contained text:
+ @verbatim
+ <foo>This is text</foo>
+ const char* str = fooElement->GetText();
+ @endverbatim
+
+ 'str' will be a pointer to "This is text".
+
+ Note that this function can be misleading. If the element foo was created from
+ this XML:
+ @verbatim
+ <foo><b>This is text</b></foo>
+ @endverbatim
+
+ then the value of str would be null. The first child node isn't a text node, it is
+ another element. From this XML:
+ @verbatim
+ <foo>This is <b>text</b></foo>
+ @endverbatim
+ GetText() will return "This is ".
+
+ WARNING: GetText() accesses a child node - don't become confused with the
+ similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are
+ safe type casts on the referenced node.
+ */
+ const char* GetText() const;
+
+ /// Creates a new Element and returns it - the returned element is a copy.
+ virtual TiXmlNode* Clone() const;
+ // Print the Element to a FILE stream.
+ virtual void Print(FILE* cfile, int depth) const;
+
+ /* Attribtue parsing starts: next char past '<'
+ returns: next char past '>'
+ */
+ virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding);
+
+ virtual const TiXmlElement* ToElement() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+ virtual TiXmlElement* ToElement() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+
+protected:
+
+ void CopyTo(TiXmlElement* target) const;
+ void ClearThis(); // like clear, but initializes 'this' object as well
+
+ // Used to be public [internal use]
+ #ifdef TIXML_USE_STL
+ virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
+ #endif
+ virtual void StreamOut(TIXML_OSTREAM * out) const;
+ virtual void FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const;
+
+ /* [internal use]
+ Reads the "value" of the element -- another element, or text.
+ This should terminate with the current end tag.
+ */
+ const char* ReadValue(const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding);
+
+private:
+
+ TiXmlAttributeSet attributeSet;
+};
+
+
+/** An XML comment.
+*/
+class TiXmlComment : public TiXmlNode
+{
+public:
+ /// Constructs an empty comment.
+ TiXmlComment() : TiXmlNode(TiXmlNode::COMMENT) {}
+ TiXmlComment(const TiXmlComment&);
+ void operator=(const TiXmlComment& base);
+
+ virtual ~TiXmlComment() {}
+
+ /// Returns a copy of this Comment.
+ virtual TiXmlNode* Clone() const;
+ /// Write this Comment to a FILE stream.
+ virtual void Print(FILE* cfile, int depth) const;
+
+ /* Attribtue parsing starts: at the ! of the !--
+ returns: next char past '>'
+ */
+ virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding);
+
+ virtual const TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+ virtual TiXmlComment* ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+
+protected:
+ void CopyTo(TiXmlComment* target) const;
+
+ // used to be public
+ #ifdef TIXML_USE_STL
+ virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
+ #endif
+ virtual void StreamOut(TIXML_OSTREAM * out) const;
+ virtual void FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const;
+
+private:
+
+};
+
+
+/** XML text. A text node can have 2 ways to output the next. "normal" output
+ and CDATA. It will default to the mode it was parsed from the XML file and
+ you generally want to leave it alone, but you can change the output mode with
+ SetCDATA() and query it with CDATA().
+*/
+class TiXmlText : public TiXmlNode
+{
+ friend class TiXmlElement;
+public:
+ /** Constructor for text element. By default, it is treated as
+ normal, encoded text. If you want it be output as a CDATA text
+ element, set the parameter _cdata to 'true'
+ */
+ TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
+ {
+ SetValue(initValue);
+ cdata = false;
+ }
+ virtual ~TiXmlText() {}
+
+ #ifdef TIXML_USE_STL
+ /// Constructor.
+ TiXmlText(const std::string& initValue) : TiXmlNode (TiXmlNode::TEXT)
+ {
+ SetValue(initValue);
+ cdata = false;
+ }
+ #endif
+
+ TiXmlText(const TiXmlText& copy) : TiXmlNode(TiXmlNode::TEXT) { copy.CopyTo(this); }
+ void operator=(const TiXmlText& base) { base.CopyTo(this); }
+
+ /// Write this text object to a FILE stream.
+ virtual void Print(FILE* cfile, int depth) const;
+
+ /// Queries whether this represents text using a CDATA section.
+ bool CDATA() { return cdata; }
+ /// Turns on or off a CDATA representation of text.
+ void SetCDATA(bool _cdata) { cdata = _cdata; }
+
+ virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding);
+
+ virtual const TiXmlText* ToText() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+ virtual TiXmlText* ToText() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+
+protected :
+ /// [internal use] Creates a new Element and returns it.
+ virtual TiXmlNode* Clone() const;
+ void CopyTo(TiXmlText* target) const;
+
+ virtual void StreamOut (TIXML_OSTREAM * out) const;
+ virtual void FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const;
+
+ bool Blank() const; // returns true if all white space and new lines
+ // [internal use]
+ #ifdef TIXML_USE_STL
+ virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
+ #endif
+
+private:
+ bool cdata; // true if this should be input and output as a CDATA style text element
+};
+
+
+/** In correct XML the declaration is the first entry in the file.
+ @verbatim
+ <?xml version="1.0" standalone="yes"?>
+ @endverbatim
+
+ TinyXml will happily read or write files without a declaration,
+ however. There are 3 possible attributes to the declaration:
+ version, encoding, and standalone.
+
+ Note: In this version of the code, the attributes are
+ handled as special cases, not generic attributes, simply
+ because there can only be at most 3 and they are always the same.
+*/
+class TiXmlDeclaration : public TiXmlNode
+{
+public:
+ /// Construct an empty declaration.
+ TiXmlDeclaration() : TiXmlNode(TiXmlNode::DECLARATION) {}
+
+#ifdef TIXML_USE_STL
+ /// Constructor.
+ TiXmlDeclaration( const std::string& _version,
+ const std::string& _encoding,
+ const std::string& _standalone);
+#endif
+
+ /// Construct.
+ TiXmlDeclaration( const char* _version,
+ const char* _encoding,
+ const char* _standalone);
+
+ TiXmlDeclaration(const TiXmlDeclaration& copy);
+ void operator=(const TiXmlDeclaration& copy);
+
+ virtual ~TiXmlDeclaration() {}
+
+ /// Version. Will return an empty string if none was found.
+ const char *Version() const { return version.c_str (); }
+ /// Encoding. Will return an empty string if none was found.
+ const char *Encoding() const { return encoding.c_str (); }
+ /// Is this a standalone document?
+ const char *Standalone() const { return standalone.c_str (); }
+
+ /// Creates a copy of this Declaration and returns it.
+ virtual TiXmlNode* Clone() const;
+ /// Print this declaration to a FILE stream.
+ virtual void Print(FILE* cfile, int depth) const;
+
+ virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding);
+
+ virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+ virtual TiXmlDeclaration* ToDeclaration() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+
+protected:
+ void CopyTo(TiXmlDeclaration* target) const;
+ // used to be public
+ #ifdef TIXML_USE_STL
+ virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
+ #endif
+ virtual void StreamOut (TIXML_OSTREAM * out) const;
+ virtual void FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const;
+
+private:
+
+ TIXML_STRING version;
+ TIXML_STRING encoding;
+ TIXML_STRING standalone;
+};
+
+
+/** Any tag that tinyXml doesn't recognize is saved as an
+ unknown. It is a tag of text, but should not be modified.
+ It will be written back to the XML, unchanged, when the file
+ is saved.
+
+ DTD tags get thrown into TiXmlUnknowns.
+*/
+class TiXmlUnknown : public TiXmlNode
+{
+public:
+ TiXmlUnknown() : TiXmlNode(TiXmlNode::UNKNOWN) {}
+ virtual ~TiXmlUnknown() {}
+
+ TiXmlUnknown(const TiXmlUnknown& copy) : TiXmlNode(TiXmlNode::UNKNOWN) { copy.CopyTo(this); }
+ void operator=(const TiXmlUnknown& copy) { copy.CopyTo(this); }
+
+ /// Creates a copy of this Unknown and returns it.
+ virtual TiXmlNode* Clone() const;
+ /// Print this Unknown to a FILE stream.
+ virtual void Print(FILE* cfile, int depth) const;
+
+ virtual const char* Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding);
+
+ virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+ virtual TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+
+protected:
+ void CopyTo(TiXmlUnknown* target) const;
+
+ #ifdef TIXML_USE_STL
+ virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
+ #endif
+ virtual void StreamOut (TIXML_OSTREAM * out) const;
+ virtual void FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const;
+
+private:
+
+};
+
+
+/** Always the top level node. A document binds together all the
+ XML pieces. It can be saved, loaded, and printed to the screen.
+ The 'value' of a document node is the xml file name.
+*/
+class TiXmlDocument : public TiXmlNode
+{
+public:
+ /// Create an empty document, that has no name.
+ TiXmlDocument();
+ /// Create a document with a name. The name of the document is also the filename of the xml.
+ TiXmlDocument(const char * documentName);
+
+ #ifdef TIXML_USE_STL
+ /// Constructor.
+ TiXmlDocument(const std::string& documentName);
+ #endif
+
+ TiXmlDocument(const TiXmlDocument& copy);
+ void operator=(const TiXmlDocument& copy);
+
+ virtual ~TiXmlDocument() {}
+
+ /** Load a file using the current document value.
+ Returns true if successful. Will delete any existing
+ document data before loading.
+ */
+ bool LoadFile(TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
+ /// Save a file using the current document value. Returns true if successful.
+ bool SaveFile() const;
+ /// Load a file using the given filename. Returns true if successful.
+ bool LoadFile(const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
+ /// Save a file using the given filename. Returns true if successful.
+ bool SaveFile(const char * filename) const;
+ /** Load a file using the given FILE*. Returns true if successful. Note that this method
+ doesn't stream - the entire object pointed at by the FILE*
+ will be interpreted as an XML file. TinyXML doesn't stream in XML from the current
+ file location. Streaming may be added in the future.
+ */
+ bool LoadFile(FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
+ /// Save a file using the given FILE*. Returns true if successful.
+ bool SaveFile(FILE*) const;
+
+ #ifdef TIXML_USE_STL
+ bool LoadFile(const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING) ///< STL std::string version.
+ {
+ StringToBuffer f(filename);
+ return (f.buffer && LoadFile(f.buffer, encoding));
+ }
+ bool SaveFile(const std::string& filename) const ///< STL std::string version.
+ {
+ StringToBuffer f(filename);
+ return (f.buffer && SaveFile(f.buffer));
+ }
+ /** Write the document to a string using formatted printing ("pretty print").
+ @return the document as a formatted standard string.
+ */
+ std::string GetAsString();
+ #endif
+
+ /** Write the document to a string using formatted printing ("pretty print").
+ @param buffer A character buffer that should be big enough to hold your document.
+ @param bufferSize The size of @p buffer.
+
+ @return True if the document could be copied into @p buffer, else false.
+ */
+ bool GetAsCharBuffer(char* buffer, size_t bufferSize);
+
+ /** Parse the given null terminated block of xml data. Passing in an encoding to this
+ method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml
+ to use that encoding, regardless of what TinyXml might otherwise try to detect.
+ */
+ virtual const char* Parse(const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING);
+
+ /** Get the root element -- the only top level element -- of the document.
+ In well formed XML, there should only be one. TinyXml is tolerant of
+ multiple elements at the document level.
+ */
+ const TiXmlElement* RootElement() const { return FirstChildElement(); }
+ TiXmlElement* RootElement() { return FirstChildElement(); }
+
+ /** If an error occurs, Error will be set to true. Also,
+ - The ErrorId() will contain the integer identifier of the error (not generally useful)
+ - The ErrorDesc() method will return the name of the error. (very useful)
+ - The ErrorRow() and ErrorCol() will return the location of the error (if known)
+ */
+ bool Error() const { return error; }
+
+ /// Contains a textual (english) description of the error if one occurs.
+ const char * ErrorDesc() const { return errorDesc.c_str (); }
+
+ /** Generally, you probably want the error string (ErrorDesc()). But if you
+ prefer the ErrorId, this function will fetch it.
+ */
+ int ErrorId() const { return errorId; }
+
+ /** Returns the location (if known) of the error. The first column is column 1,
+ and the first row is row 1. A value of 0 means the row and column wasn't applicable
+ (memory errors, for example, have no row/column) or the parser lost the error. (An
+ error in the error reporting, in that case.)
+
+ @sa SetTabSize, Row, Column
+ */
+ int ErrorRow() { return errorLocation.row+1; }
+ int ErrorCol() { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow()
+
+ /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol())
+ to report the correct values for row and column. It does not change the output
+ or input in any way.
+
+ By calling this method, with a tab size
+ greater than 0, the row and column of each node and attribute is stored
+ when the file is loaded. Very useful for tracking the DOM back in to
+ the source file.
+
+ The tab size is required for calculating the location of nodes. If not
+ set, the default of 4 is used. The tabsize is set per document. Setting
+ the tabsize to 0 disables row/column tracking.
+
+ Note that row and column tracking is not supported when using operator>>.
+
+ The tab size needs to be enabled before the parse or load. Correct usage:
+ @verbatim
+ TiXmlDocument doc;
+ doc.SetTabSize(8);
+ doc.Load("myfile.xml");
+ @endverbatim
+
+ @sa Row, Column
+ */
+ void SetTabSize(int _tabsize) { tabsize = _tabsize; }
+
+ int TabSize() const { return tabsize; }
+
+ /** If you have handled the error, it can be reset with this call. The error
+ state is automatically cleared if you Parse a new XML block.
+ */
+ void ClearError() { error = false;
+ errorId = 0;
+ errorDesc = "";
+ errorLocation.row = errorLocation.col = 0;
+ //errorLocation.last = 0;
+ }
+
+ /** Dump the document to standard out. */
+ void Print() const { Print(stdout, 0); }
+
+ /// Print this Document to a FILE stream.
+ virtual void Print(FILE* cfile, int depth = 0) const;
+ // [internal use]
+ void SetError(int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding);
+
+ virtual const TiXmlDocument* ToDocument() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+ virtual TiXmlDocument* ToDocument() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
+
+protected :
+ virtual void StreamOut (TIXML_OSTREAM * out) const;
+ virtual void FormattedStreamOut(TIXML_OSTREAM * stream, int depth) const;
+ // [internal use]
+ virtual TiXmlNode* Clone() const;
+ #ifdef TIXML_USE_STL
+ virtual void StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag);
+ #endif
+
+private:
+ void CopyTo(TiXmlDocument* target) const;
+
+ bool error;
+ int errorId;
+ TIXML_STRING errorDesc;
+ int tabsize;
+ TiXmlCursor errorLocation;
+ bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write.
+};
+
+
+/**
+ A TiXmlHandle is a class that wraps a node pointer with null checks; this is
+ an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml
+ DOM structure. It is a separate utility class.
+
+ Take an example:
+ @verbatim
+ <Document>
+ <Element attributeA = "valueA">
+ <Child attributeB = "value1" />
+ <Child attributeB = "value2" />
+ </Element>
+ <Document>
+ @endverbatim
+
+ Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very
+ easy to write a *lot* of code that looks like:
+
+ @verbatim
+ TiXmlElement* root = document.FirstChildElement("Document");
+ if (root)
+ {
+ TiXmlElement* element = root->FirstChildElement("Element");
+ if (element)
+ {
+ TiXmlElement* child = element->FirstChildElement("Child");
+ if (child)
+ {
+ TiXmlElement* child2 = child->NextSiblingElement("Child");
+ if (child2)
+ {
+ // Finally do something useful.
+ @endverbatim
+
+ And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity
+ of such code. A TiXmlHandle checks for null pointers so it is perfectly safe
+ and correct to use:
+
+ @verbatim
+ TiXmlHandle docHandle(&document);
+ TiXmlElement* child2 = docHandle.FirstChild("Document").FirstChild("Element").Child("Child", 1).Element();
+ if (child2)
+ {
+ // do something useful
+ @endverbatim
+
+ Which is MUCH more concise and useful.
+
+ It is also safe to copy handles - internally they are nothing more than node pointers.
+ @verbatim
+ TiXmlHandle handleCopy = handle;
+ @endverbatim
+
+ What they should not be used for is iteration:
+
+ @verbatim
+ int i=0;
+ while (true)
+ {
+ TiXmlElement* child = docHandle.FirstChild("Document").FirstChild("Element").Child("Child", i).Element();
+ if (!child)
+ break;
+ // do something
+ ++i;
+ }
+ @endverbatim
+
+ It seems reasonable, but it is in fact two embedded while loops. The Child method is
+ a linear walk to find the element, so this code would iterate much more than it needs
+ to. Instead, prefer:
+
+ @verbatim
+ TiXmlElement* child = docHandle.FirstChild("Document").FirstChild("Element").FirstChild("Child").Element();
+
+ for (child; child; child=child->NextSiblingElement())
+ {
+ // do something
+ }
+ @endverbatim
+*/
+class TiXmlHandle
+{
+public:
+ /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
+ TiXmlHandle(TiXmlNode* _node) { this->node = _node; }
+ /// Copy constructor
+ TiXmlHandle(const TiXmlHandle& ref) { this->node = ref.node; }
+ TiXmlHandle operator=(const TiXmlHandle& ref) { this->node = ref.node; return *this; }
+
+ /// Return a handle to the first child node.
+ TiXmlHandle FirstChild() const;
+ /// Return a handle to the first child node with the given name.
+ TiXmlHandle FirstChild(const char * value) const;
+ /// Return a handle to the first child element.
+ TiXmlHandle FirstChildElement() const;
+ /// Return a handle to the first child element with the given name.
+ TiXmlHandle FirstChildElement(const char * value) const;
+
+ /** Return a handle to the "index" child with the given name.
+ The first child is 0, the second 1, etc.
+ */
+ TiXmlHandle Child(const char* value, int index) const;
+ /** Return a handle to the "index" child.
+ The first child is 0, the second 1, etc.
+ */
+ TiXmlHandle Child(int index) const;
+ /** Return a handle to the "index" child element with the given name.
+ The first child element is 0, the second 1, etc. Note that only TiXmlElements
+ are indexed: other types are not counted.
+ */
+ TiXmlHandle ChildElement(const char* value, int index) const;
+ /** Return a handle to the "index" child element.
+ The first child element is 0, the second 1, etc. Note that only TiXmlElements
+ are indexed: other types are not counted.
+ */
+ TiXmlHandle ChildElement(int index) const;
+
+ #ifdef TIXML_USE_STL
+ TiXmlHandle FirstChild(const std::string& _value) const { return FirstChild(_value.c_str()); }
+ TiXmlHandle FirstChildElement(const std::string& _value) const { return FirstChildElement(_value.c_str()); }
+
+ TiXmlHandle Child(const std::string& _value, int index) const { return Child(_value.c_str(), index); }
+ TiXmlHandle ChildElement(const std::string& _value, int index) const { return ChildElement(_value.c_str(), index); }
+ #endif
+
+ /// Return the handle as a TiXmlNode. This may return null.
+ TiXmlNode* Node() const { return node; }
+ /// Return the handle as a TiXmlElement. This may return null.
+ TiXmlElement* Element() const { return ((node && node->ToElement()) ? node->ToElement() : 0); }
+ /// Return the handle as a TiXmlText. This may return null.
+ TiXmlText* Text() const { return ((node && node->ToText()) ? node->ToText() : 0); }
+ /// Return the handle as a TiXmlUnknown. This may return null;
+ TiXmlUnknown* Unknown() const { return ((node && node->ToUnknown()) ? node->ToUnknown() : 0); }
+
+private:
+ TiXmlNode* node;
+};
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+#endif
+
diff --git a/plugins/UserInfoEx/ex_import/tinyxmlerror.cpp b/plugins/UserInfoEx/ex_import/tinyxmlerror.cpp
new file mode 100644
index 0000000000..3c42354d11
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/tinyxmlerror.cpp
@@ -0,0 +1,76 @@
+/*
+www.sourceforge.net/projects/tinyxml
+Original code (2.0 and earlier)copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
+damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
+redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
+would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and
+must not be misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
+
+===============================================================================
+
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/tinyxmlerror.cpp $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#ifdef USE_MMGR
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "mmgr.h"
+#endif
+
+#include "tinyxml.h"
+
+// The goal of the seperate error file is to make the first
+// step towards localization. tinyxml (currently) only supports
+// english error messages, but the could now be translated.
+//
+// It also cleans up the code a bit.
+//
+
+const char* TiXmlBase::errorString[ TIXML_ERROR_STRING_COUNT ] =
+{
+ "No error",
+ "Error",
+ "Failed to open file",
+ "Memory allocation failed.",
+ "Error parsing Element.",
+ "Failed to read Element name",
+ "Error reading Element value.",
+ "Error reading Attributes.",
+ "Error: empty tag.",
+ "Error reading end tag.",
+ "Error parsing Unknown.",
+ "Error parsing Comment.",
+ "Error parsing Declaration.",
+ "Error document empty.",
+ "Error null (0) or unexpected EOF found in input stream.",
+ "Error parsing CDATA.",
+ "Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.",
+};
diff --git a/plugins/UserInfoEx/ex_import/tinyxmlparser.cpp b/plugins/UserInfoEx/ex_import/tinyxmlparser.cpp
new file mode 100644
index 0000000000..73f2c18679
--- /dev/null
+++ b/plugins/UserInfoEx/ex_import/tinyxmlparser.cpp
@@ -0,0 +1,1613 @@
+/*
+www.sourceforge.net/projects/tinyxml
+Original code (2.0 and earlier)copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any
+damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any
+purpose, including commercial applications, and to alter it and
+redistribute it freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must
+not claim that you wrote the original software. If you use this
+software in a product, an acknowledgment in the product documentation
+would be appreciated but is not required.
+
+2. Altered source versions must be plainly marked as such, and
+must not be misrepresented as being the original software.
+
+3. This notice may not be removed or altered from any source
+distribution.
+
+===============================================================================
+
+UserinfoEx plugin for Miranda IM
+
+Copyright:
+ 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol
+
+File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/ex_import/tinyxmlparser.cpp $
+Revision : $Revision: 187 $
+Last change on : $Date: 2010-09-08 16:05:54 +0400 (Ср, 08 сен 2010) $
+Last change by : $Author: ing.u.horn $
+
+===============================================================================
+*/
+
+#include <ctype.h>
+#include <stddef.h>
+
+#ifdef USE_MMGR
+#include <string.h>
+#include <assert.h>
+#include <stdio.h>
+#include "mmgr.h"
+#endif
+
+#include "tinyxml.h"
+
+//#define DEBUG_PARSER
+#if defined(DEBUG_PARSER)
+# if defined(DEBUG) && defined(_MSC_VER)
+# include <windows.h>
+# define TIXML_LOG OutputDebugString
+# else
+# define TIXML_LOG printf
+# endif
+#endif
+
+// Note tha "PutString" hardcodes the same list. This
+// is less flexible than it appears. Changing the entries
+// or order will break putstring.
+TiXmlBase::Entity TiXmlBase::entity[ NUM_ENTITY ] =
+{
+ { "&amp;", 5, '&' },
+ { "&lt;", 4, '<' },
+ { "&gt;", 4, '>' },
+ { "&quot;", 6, '\"' },
+ { "&apos;", 6, '\'' }
+};
+
+// Bunch of unicode info at:
+// http://www.unicode.org/faq/utf_bom.html
+// Including the basic of this table, which determines the #bytes in the
+// sequence from the lead byte. 1 placed for invalid sequences --
+// although the result will be junk, pass it through as much as possible.
+// Beware of the non-characters in UTF-8:
+// ef bb bf (Microsoft "lead bytes")
+// ef bf be
+// ef bf bf
+
+const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
+const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
+const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
+
+const int TiXmlBase::utf8ByteTable[256] =
+{
+ // 0 1 2 3 4 5 6 7 8 9 a b c d e f
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x00
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x10
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x20
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x30
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x50
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x70 End of ASCII range
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x80 0x80 to 0xc1 invalid
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x90
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xa0
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xb0
+ 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xc0 0xc2 to 0xdf 2 byte
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xd0
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xe0 0xe0 to 0xef 3 byte
+ 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid
+};
+
+
+void TiXmlBase::ConvertUTF32ToUTF8(unsigned long input, char* output, int* length)
+{
+ const unsigned long BYTE_MASK = 0xBF;
+ const unsigned long BYTE_MARK = 0x80;
+ const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
+
+ if (input < 0x80)
+ *length = 1;
+ else if (input < 0x800)
+ *length = 2;
+ else if (input < 0x10000)
+ *length = 3;
+ else if (input < 0x200000)
+ *length = 4;
+ else
+ { *length = 0; return; } // This code won't covert this correctly anyway.
+
+ output += *length;
+
+ // Scary scary fall throughs.
+ switch (*length)
+ {
+ case 4:
+ --output;
+ *output = (char)((input | BYTE_MARK) & BYTE_MASK);
+ input >>= 6;
+ case 3:
+ --output;
+ *output = (char)((input | BYTE_MARK) & BYTE_MASK);
+ input >>= 6;
+ case 2:
+ --output;
+ *output = (char)((input | BYTE_MARK) & BYTE_MASK);
+ input >>= 6;
+ case 1:
+ --output;
+ *output = (char)(input | FIRST_BYTE_MARK[*length]);
+ }
+}
+
+
+/*static*/ int TiXmlBase::IsAlpha(unsigned char anyByte, TiXmlEncoding /*encoding*/)
+{
+ // This will only work for low-ascii, everything else is assumed to be a valid
+ // letter. I'm not sure this is the best approach, but it is quite tricky trying
+ // to figure out alhabetical vs. not across encoding. So take a very
+ // conservative approach.
+
+// if (encoding == TIXML_ENCODING_UTF8)
+// {
+ if (anyByte < 127)
+ return isalpha(anyByte);
+ else
+ return 1; // What else to do? The unicode set is huge...get the english ones right.
+// }
+// else
+// {
+// return isalpha(anyByte);
+// }
+}
+
+
+/*static*/ int TiXmlBase::IsAlphaNum(unsigned char anyByte, TiXmlEncoding /*encoding*/)
+{
+ // This will only work for low-ascii, everything else is assumed to be a valid
+ // letter. I'm not sure this is the best approach, but it is quite tricky trying
+ // to figure out alhabetical vs. not across encoding. So take a very
+ // conservative approach.
+
+// if (encoding == TIXML_ENCODING_UTF8)
+// {
+ if (anyByte < 127)
+ return isalnum(anyByte);
+ else
+ return 1; // What else to do? The unicode set is huge...get the english ones right.
+// }
+// else
+// {
+// return isalnum(anyByte);
+// }
+}
+
+
+class TiXmlParsingData
+{
+ friend class TiXmlDocument;
+ public:
+ void Stamp(const char* now, TiXmlEncoding encoding);
+
+ const TiXmlCursor& Cursor() { return cursor; }
+
+ private:
+ // Only used by the document!
+ TiXmlParsingData(const char* start, int _tabsize, int row, int col)
+ {
+ assert(start);
+ stamp = start;
+ tabsize = _tabsize;
+ cursor.row = row;
+ cursor.col = col;
+ }
+
+ TiXmlCursor cursor;
+ const char* stamp;
+ int tabsize;
+};
+
+
+void TiXmlParsingData::Stamp(const char* now, TiXmlEncoding encoding)
+{
+ assert(now);
+
+ // Do nothing if the tabsize is 0.
+ if (tabsize < 1)
+ {
+ return;
+ }
+
+ // Get the current row, column.
+ int row = cursor.row;
+ int col = cursor.col;
+ const char* p = stamp;
+ assert(p);
+
+ while (p < now)
+ {
+ // Treat p as unsigned, so we have a happy compiler.
+ const unsigned char* pU = (const unsigned char*)p;
+
+ // Code contributed by Fletcher Dunn: (modified by lee)
+ switch (*pU) {
+ case 0:
+ // We *should* never get here, but in case we do, don't
+ // advance past the terminating null character, ever
+ return;
+
+ case '\r':
+ // bump down to the next line
+ ++row;
+ col = 0;
+ // Eat the character
+ ++p;
+
+ // Check for \r\n sequence, and treat this as a single character
+ if (*p == '\n') {
+ ++p;
+ }
+ break;
+
+ case '\n':
+ // bump down to the next line
+ ++row;
+ col = 0;
+
+ // Eat the character
+ ++p;
+
+ // Check for \n\r sequence, and treat this as a single
+ // character. (Yes, this bizarre thing does occur still
+ // on some arcane platforms...)
+ if (*p == '\r') {
+ ++p;
+ }
+ break;
+
+ case '\t':
+ // Eat the character
+ ++p;
+
+ // Skip to next tab stop
+ col = (col / tabsize + 1) * tabsize;
+ break;
+
+ case TIXML_UTF_LEAD_0:
+ if (encoding == TIXML_ENCODING_UTF8)
+ {
+ if (*(p+1) && *(p+2))
+ {
+ // In these cases, don't advance the column. These are
+ // 0-width spaces.
+ if (*(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2)
+ p += 3;
+ else if (*(pU+1)==0xbfU && *(pU+2)==0xbeU)
+ p += 3;
+ else if (*(pU+1)==0xbfU && *(pU+2)==0xbfU)
+ p += 3;
+ else
+ { p +=3; ++col; } // A normal character.
+ }
+ }
+ else
+ {
+ ++p;
+ ++col;
+ }
+ break;
+
+ default:
+ if (encoding == TIXML_ENCODING_UTF8)
+ {
+ // Eat the 1 to 4 byte utf8 character.
+ int step = TiXmlBase::utf8ByteTable[*((unsigned char*)p)];
+ if (step == 0)
+ step = 1; // Error case from bad encoding, but handle gracefully.
+ p += step;
+
+ // Just advance one column, of course.
+ ++col;
+ }
+ else
+ {
+ ++p;
+ ++col;
+ }
+ break;
+ }
+ }
+ cursor.row = row;
+ cursor.col = col;
+ assert(cursor.row >= -1);
+ assert(cursor.col >= -1);
+ stamp = p;
+ assert(stamp);
+}
+
+
+const char* TiXmlBase::SkipWhiteSpace(const char* p, TiXmlEncoding encoding)
+{
+ if (!p || !*p)
+ {
+ return 0;
+ }
+ if (encoding == TIXML_ENCODING_UTF8)
+ {
+ while (*p)
+ {
+ const unsigned char* pU = (const unsigned char*)p;
+
+ // Skip the stupid Microsoft UTF-8 Byte order marks
+ if ( *(pU+0)==TIXML_UTF_LEAD_0
+ && *(pU+1)==TIXML_UTF_LEAD_1
+ && *(pU+2)==TIXML_UTF_LEAD_2)
+ {
+ p += 3;
+ continue;
+ }
+ else if (*(pU+0)==TIXML_UTF_LEAD_0
+ && *(pU+1)==0xbfU
+ && *(pU+2)==0xbeU)
+ {
+ p += 3;
+ continue;
+ }
+ else if (*(pU+0)==TIXML_UTF_LEAD_0
+ && *(pU+1)==0xbfU
+ && *(pU+2)==0xbfU)
+ {
+ p += 3;
+ continue;
+ }
+
+ if (IsWhiteSpace(*p) || *p == '\n' || *p =='\r') // Still using old rules for white space.
+ ++p;
+ else
+ break;
+ }
+ }
+ else
+ {
+ while (*p && IsWhiteSpace(*p) || *p == '\n' || *p =='\r')
+ ++p;
+ }
+
+ return p;
+}
+
+#ifdef TIXML_USE_STL
+/*static*/ bool TiXmlBase::StreamWhiteSpace(TIXML_ISTREAM * in, TIXML_STRING * tag)
+{
+ for (;;)
+ {
+ if (!in->good()) return false;
+
+ int c = in->peek();
+ // At this scope, we can't get to a document. So fail silently.
+ if (!IsWhiteSpace(c) || c <= 0)
+ return true;
+
+ *tag += (char) in->get();
+ }
+}
+
+/*static*/ bool TiXmlBase::StreamTo(TIXML_ISTREAM * in, int character, TIXML_STRING * tag)
+{
+ //assert(character > 0 && character < 128); // else it won't work in utf-8
+ while (in->good())
+ {
+ int c = in->peek();
+ if (c == character)
+ return true;
+ if (c <= 0) // Silent failure: can't get document at this scope
+ return false;
+
+ in->get();
+ *tag += (char) c;
+ }
+ return false;
+}
+#endif
+
+const char* TiXmlBase::ReadName(const char* p, TIXML_STRING * name, TiXmlEncoding encoding)
+{
+ *name = "";
+ assert(p);
+
+ // Names start with letters or underscores.
+ // Of course, in unicode, tinyxml has no idea what a letter *is*. The
+ // algorithm is generous.
+ //
+ // After that, they can be letters, underscores, numbers,
+ // hyphens, or colons. (Colons are valid ony for namespaces,
+ // but tinyxml can't tell namespaces from names.)
+ if ( p && *p
+ && (IsAlpha((unsigned char) *p, encoding) || *p == '_'))
+ {
+ while ( p && *p
+ && ( IsAlphaNum((unsigned char) *p, encoding)
+ || *p == '_'
+ || *p == '-'
+ || *p == '.'
+ || *p == ':'))
+ {
+ (*name) += *p;
+ ++p;
+ }
+ return p;
+ }
+ return 0;
+}
+
+const char* TiXmlBase::GetEntity(const char* p, char* value, int* length, TiXmlEncoding encoding)
+{
+ // Presume an entity, and pull it out.
+ TIXML_STRING ent;
+ int i;
+ *length = 0;
+
+ if (*(p+1) && *(p+1) == '#' && *(p+2))
+ {
+ unsigned long ucs = 0;
+ ptrdiff_t delta = 0;
+ unsigned mult = 1;
+
+ if (*(p+2) == 'x')
+ {
+ // Hexadecimal.
+ if (!*(p+3)) return 0;
+
+ const char* q = p+3;
+ q = strchr(q, ';');
+
+ if (!q || !*q) return 0;
+
+ delta = q-p;
+ --q;
+
+ while (*q != 'x')
+ {
+ if (*q >= '0' && *q <= '9')
+ ucs += mult * (*q - '0');
+ else if (*q >= 'a' && *q <= 'f')
+ ucs += mult * (*q - 'a' + 10);
+ else if (*q >= 'A' && *q <= 'F')
+ ucs += mult * (*q - 'A' + 10);
+ else
+ return 0;
+ mult *= 16;
+ --q;
+ }
+ }
+ else
+ {
+ // Decimal.
+ if (!*(p+2)) return 0;
+
+ const char* q = p+2;
+ q = strchr(q, ';');
+
+ if (!q || !*q) return 0;
+
+ delta = q-p;
+ --q;
+
+ while (*q != '#')
+ {
+ if (*q >= '0' && *q <= '9')
+ ucs += mult * (*q - '0');
+ else
+ return 0;
+ mult *= 10;
+ --q;
+ }
+ }
+ if (encoding == TIXML_ENCODING_UTF8)
+ {
+ // convert the UCS to UTF-8
+ ConvertUTF32ToUTF8(ucs, value, length);
+ }
+ else
+ {
+ *value = (char)ucs;
+ *length = 1;
+ }
+ return p + delta + 1;
+ }
+
+ // Now try to match it.
+ for (i=0; i<NUM_ENTITY; ++i)
+ {
+ if (strncmp(entity[i].str, p, entity[i].strLength) == 0)
+ {
+ assert(strlen(entity[i].str) == entity[i].strLength);
+ *value = entity[i].chr;
+ *length = 1;
+ return (p + entity[i].strLength);
+ }
+ }
+
+ // So it wasn't an entity, its unrecognized, or something like that.
+ *value = *p; // Don't put back the last one, since we return it!
+ //*length = 1; // Leave unrecognized entities - this doesn't really work.
+ // Just writes strange XML.
+ return p+1;
+}
+
+
+bool TiXmlBase::StringEqual(const char* p,
+ const char* tag,
+ bool ignoreCase,
+ TiXmlEncoding encoding)
+{
+ assert(p);
+ assert(tag);
+ if (!p || !*p)
+ {
+ assert(0);
+ return false;
+ }
+
+ const char* q = p;
+
+ if (ignoreCase)
+ {
+ while (*q && *tag && ToLower(*q, encoding) == ToLower(*tag, encoding))
+ {
+ ++q;
+ ++tag;
+ }
+
+ if (*tag == 0)
+ return true;
+ }
+ else
+ {
+ while (*q && *tag && *q == *tag)
+ {
+ ++q;
+ ++tag;
+ }
+
+ if (*tag == 0) // Have we found the end of the tag, and everything equal?
+ return true;
+ }
+ return false;
+}
+
+const char* TiXmlBase::ReadText( const char* p,
+ TIXML_STRING * text,
+ bool trimWhiteSpace,
+ const char* endTag,
+ bool caseInsensitive,
+ TiXmlEncoding encoding)
+{
+ *text = "";
+ if ( !trimWhiteSpace // certain tags always keep whitespace
+ || !condenseWhiteSpace) // if true, whitespace is always kept
+ {
+ // Keep all the white space.
+ while ( p && *p
+ && !StringEqual(p, endTag, caseInsensitive, encoding)
+ )
+ {
+ int len;
+ char cArr[4] = { 0, 0, 0, 0 };
+ p = GetChar(p, cArr, &len, encoding);
+ text->append(cArr, len);
+ }
+ }
+ else
+ {
+ bool whitespace = false;
+
+ // Remove leading white space:
+ p = SkipWhiteSpace(p, encoding);
+ while ( p && *p
+ && !StringEqual(p, endTag, caseInsensitive, encoding))
+ {
+ if (*p == '\r' || *p == '\n')
+ {
+ whitespace = true;
+ ++p;
+ }
+ else if (IsWhiteSpace(*p))
+ {
+ whitespace = true;
+ ++p;
+ }
+ else
+ {
+ // If we've found whitespace, add it before the
+ // new character. Any whitespace just becomes a space.
+ if (whitespace)
+ {
+ (*text) += ' ';
+ whitespace = false;
+ }
+ int len;
+ char cArr[4] = { 0, 0, 0, 0 };
+ p = GetChar(p, cArr, &len, encoding);
+ if (len == 1)
+ (*text) += cArr[0]; // more efficient
+ else
+ text->append(cArr, len);
+ }
+ }
+ }
+ return p + strlen(endTag);
+}
+
+#ifdef TIXML_USE_STL
+
+void TiXmlDocument::StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag)
+{
+ // The basic issue with a document is that we don't know what we're
+ // streaming. Read something presumed to be a tag (and hope), then
+ // identify it, and call the appropriate stream method on the tag.
+ //
+ // This "pre-streaming" will never read the closing ">" so the
+ // sub-tag can orient itself.
+
+ if (!StreamTo(in, '<', tag))
+ {
+ SetError(TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return;
+ }
+
+ while (in->good())
+ {
+ int tagIndex = (int) tag->length();
+ while (in->good() && in->peek() != '>')
+ {
+ int c = in->get();
+ if (c <= 0)
+ {
+ SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN);
+ break;
+ }
+ (*tag) += (char) c;
+ }
+
+ if (in->good())
+ {
+ // We now have something we presume to be a node of
+ // some sort. Identify it, and call the node to
+ // continue streaming.
+ TiXmlNode* node = Identify(tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING);
+
+ if (node)
+ {
+ node->StreamIn(in, tag);
+ bool isElement = node->ToElement() != 0;
+ delete node;
+ node = 0;
+
+ // If this is the root element, we're done. Parsing will be
+ // done by the >> operator.
+ if (isElement)
+ {
+ return;
+ }
+ }
+ else
+ {
+ SetError(TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return;
+ }
+ }
+ }
+ // We should have returned sooner.
+ SetError(TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN);
+}
+
+#endif
+
+const char* TiXmlDocument::Parse(const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding)
+{
+ ClearError();
+
+ // Parse away, at the document level. Since a document
+ // contains nothing but other tags, most of what happens
+ // here is skipping white space.
+ if (!p || !*p)
+ {
+ SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return 0;
+ }
+
+ // Note that, for a document, this needs to come
+ // before the while space skip, so that parsing
+ // starts from the pointer we are given.
+ location.Clear();
+ if (prevData)
+ {
+ location.row = prevData->cursor.row;
+ location.col = prevData->cursor.col;
+ }
+ else
+ {
+ location.row = 0;
+ location.col = 0;
+ }
+ TiXmlParsingData data(p, TabSize(), location.row, location.col);
+ location = data.Cursor();
+
+ if (encoding == TIXML_ENCODING_UNKNOWN)
+ {
+ // Check for the Microsoft UTF-8 lead bytes.
+ const unsigned char* pU = (const unsigned char*)p;
+ if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
+ && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
+ && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2)
+ {
+ encoding = TIXML_ENCODING_UTF8;
+ useMicrosoftBOM = true;
+ }
+ }
+
+ p = SkipWhiteSpace(p, encoding);
+ if (!p)
+ {
+ SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return 0;
+ }
+
+ while (p && *p)
+ {
+ TiXmlNode* node = Identify(p, encoding);
+ if (node)
+ {
+ p = node->Parse(p, &data, encoding);
+ LinkEndChild(node);
+ }
+ else
+ {
+ break;
+ }
+
+ // Did we get encoding info?
+ if ( encoding == TIXML_ENCODING_UNKNOWN
+ && node->ToDeclaration())
+ {
+ TiXmlDeclaration* dec = node->ToDeclaration();
+ const char* enc = dec->Encoding();
+ assert(enc);
+
+ if (*enc == 0)
+ encoding = TIXML_ENCODING_UTF8;
+ else if (StringEqual(enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN))
+ encoding = TIXML_ENCODING_UTF8;
+ else if (StringEqual(enc, "UTF8", true, TIXML_ENCODING_UNKNOWN))
+ encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice
+ else
+ encoding = TIXML_ENCODING_LEGACY;
+ }
+
+ p = SkipWhiteSpace(p, encoding);
+ }
+
+ // Was this empty?
+ if (!firstChild) {
+ SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding);
+ return 0;
+ }
+
+ // All is well.
+ return p;
+}
+
+void TiXmlDocument::SetError(int err, const char* pError, TiXmlParsingData* data, TiXmlEncoding encoding)
+{
+ // The first error in a chain is more accurate - don't set again!
+ if (error)
+ return;
+
+ assert(err > 0 && err < TIXML_ERROR_STRING_COUNT);
+ error = true;
+ errorId = err;
+ errorDesc = errorString[ errorId ];
+
+ errorLocation.Clear();
+ if (pError && data)
+ {
+ data->Stamp(pError, encoding);
+ errorLocation = data->Cursor();
+ }
+}
+
+
+TiXmlNode* TiXmlNode::Identify(const char* p, TiXmlEncoding encoding)
+{
+ TiXmlNode* returnNode = 0;
+
+ p = SkipWhiteSpace(p, encoding);
+ if (!p || !*p || *p != '<')
+ {
+ return 0;
+ }
+
+ TiXmlDocument* doc = GetDocument();
+ p = SkipWhiteSpace(p, encoding);
+
+ if (!p || !*p)
+ {
+ return 0;
+ }
+
+ // What is this thing?
+ // - Elements start with a letter or underscore, but xml is reserved.
+ // - Comments: <!--
+ // - Decleration: <?xml
+ // - Everthing else is unknown to tinyxml.
+ //
+
+ const char* xmlHeader = { "<?xml" };
+ const char* commentHeader = { "<!--" };
+ const char* dtdHeader = { "<!" };
+ const char* cdataHeader = { "<![CDATA[" };
+
+ if (StringEqual(p, xmlHeader, true, encoding))
+ {
+ #ifdef DEBUG_PARSER
+ TIXML_LOG("XML parsing Declaration\n");
+ #endif
+ returnNode = new TiXmlDeclaration();
+ }
+ else if (StringEqual(p, commentHeader, false, encoding))
+ {
+ #ifdef DEBUG_PARSER
+ TIXML_LOG("XML parsing Comment\n");
+ #endif
+ returnNode = new TiXmlComment();
+ }
+ else if (StringEqual(p, cdataHeader, false, encoding))
+ {
+ #ifdef DEBUG_PARSER
+ TIXML_LOG("XML parsing CDATA\n");
+ #endif
+ TiXmlText* text = new TiXmlText("");
+ text->SetCDATA(true);
+ returnNode = text;
+ }
+ else if (StringEqual(p, dtdHeader, false, encoding))
+ {
+ #ifdef DEBUG_PARSER
+ TIXML_LOG("XML parsing Unknown(1)\n");
+ #endif
+ returnNode = new TiXmlUnknown();
+ }
+ else if ( IsAlpha(*(p+1), encoding)
+ || *(p+1) == '_')
+ {
+ #ifdef DEBUG_PARSER
+ TIXML_LOG("XML parsing Element\n");
+ #endif
+ returnNode = new TiXmlElement("");
+ }
+ else
+ {
+ #ifdef DEBUG_PARSER
+ TIXML_LOG("XML parsing Unknown(2)\n");
+ #endif
+ returnNode = new TiXmlUnknown();
+ }
+
+ if (returnNode)
+ {
+ // Set the parent, so it can report errors
+ returnNode->parent = this;
+ }
+ else
+ {
+ if (doc)
+ doc->SetError(TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN);
+ }
+ return returnNode;
+}
+
+#ifdef TIXML_USE_STL
+
+void TiXmlElement::StreamIn (TIXML_ISTREAM * in, TIXML_STRING * tag)
+{
+ // We're called with some amount of pre-parsing. That is, some of "this"
+ // element is in "tag". Go ahead and stream to the closing ">"
+ while (in->good())
+ {
+ int c = in->get();
+ if (c <= 0)
+ {
+ TiXmlDocument* document = GetDocument();
+ if (document)
+ document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return;
+ }
+ (*tag) += (char) c ;
+
+ if (c == '>')
+ break;
+ }
+
+ if (tag->length() < 3) return;
+
+ // Okay...if we are a "/>" tag, then we're done. We've read a complete tag.
+ // If not, identify and stream.
+
+ if ( tag->at(tag->length() - 1) == '>'
+ && tag->at(tag->length() - 2) == '/')
+ {
+ // All good!
+ return;
+ }
+ else if (tag->at(tag->length() - 1) == '>')
+ {
+ // There is more. Could be:
+ // text
+ // closing tag
+ // another node.
+ for (;;)
+ {
+ StreamWhiteSpace(in, tag);
+
+ // Do we have text?
+ if (in->good() && in->peek() != '<')
+ {
+ // Yep, text.
+ TiXmlText text("");
+ text.StreamIn(in, tag);
+
+ // What follows text is a closing tag or another node.
+ // Go around again and figure it out.
+ continue;
+ }
+
+ // We now have either a closing tag...or another node.
+ // We should be at a "<", regardless.
+ if (!in->good()) return;
+ assert(in->peek() == '<');
+ int tagIndex = (int) tag->length();
+
+ bool closingTag = false;
+ bool firstCharFound = false;
+
+ for (;;)
+ {
+ if (!in->good())
+ return;
+
+ int c = in->peek();
+ if (c <= 0)
+ {
+ TiXmlDocument* document = GetDocument();
+ if (document)
+ document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return;
+ }
+
+ if (c == '>')
+ break;
+
+ *tag += (char) c;
+ in->get();
+
+ if (!firstCharFound && c != '<' && !IsWhiteSpace(c))
+ {
+ firstCharFound = true;
+ if (c == '/')
+ closingTag = true;
+ }
+ }
+ // If it was a closing tag, then read in the closing '>' to clean up the input stream.
+ // If it was not, the streaming will be done by the tag.
+ if (closingTag)
+ {
+ if (!in->good())
+ return;
+
+ int c = in->get();
+ if (c <= 0)
+ {
+ TiXmlDocument* document = GetDocument();
+ if (document)
+ document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return;
+ }
+ assert(c == '>');
+ *tag += (char) c;
+
+ // We are done, once we've found our closing tag.
+ return;
+ }
+ else
+ {
+ // If not a closing tag, id it, and stream.
+ const char* tagloc = tag->c_str() + tagIndex;
+ TiXmlNode* node = Identify(tagloc, TIXML_DEFAULT_ENCODING);
+ if (!node)
+ return;
+ node->StreamIn(in, tag);
+ delete node;
+ node = 0;
+
+ // No return: go around from the beginning: text, closing tag, or node.
+ }
+ }
+ }
+}
+#endif
+
+const char* TiXmlElement::Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)
+{
+ p = SkipWhiteSpace(p, encoding);
+ TiXmlDocument* document = GetDocument();
+
+ if (!p || !*p)
+ {
+ if (document) document->SetError(TIXML_ERROR_PARSING_ELEMENT, 0, 0, encoding);
+ return 0;
+ }
+
+ if (data)
+ {
+ data->Stamp(p, encoding);
+ location = data->Cursor();
+ }
+
+ if (*p != '<')
+ {
+ if (document) document->SetError(TIXML_ERROR_PARSING_ELEMENT, p, data, encoding);
+ return 0;
+ }
+
+ p = SkipWhiteSpace(p+1, encoding);
+
+ // Read the name.
+ const char* pErr = p;
+
+ p = ReadName(p, &value, encoding);
+ if (!p || !*p)
+ {
+ if (document) document->SetError(TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, pErr, data, encoding);
+ return 0;
+ }
+
+ TIXML_STRING endTag ("</");
+ endTag += value;
+ endTag += ">";
+
+ // Check for and read attributes. Also look for an empty
+ // tag or an end tag.
+ while (p && *p)
+ {
+ pErr = p;
+ p = SkipWhiteSpace(p, encoding);
+ if (!p || !*p)
+ {
+ if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding);
+ return 0;
+ }
+ if (*p == '/')
+ {
+ ++p;
+ // Empty tag.
+ if (*p != '>')
+ {
+ if (document) document->SetError(TIXML_ERROR_PARSING_EMPTY, p, data, encoding);
+ return 0;
+ }
+ return (p+1);
+ }
+ else if (*p == '>')
+ {
+ // Done with attributes (if there were any.)
+ // Read the value -- which can include other
+ // elements -- read the end tag, and return.
+ ++p;
+ p = ReadValue(p, data, encoding); // Note this is an Element method, and will set the error if one happens.
+ if (!p || !*p)
+ return 0;
+
+ // We should find the end tag now
+ if (StringEqual(p, endTag.c_str(), false, encoding))
+ {
+ p += endTag.length();
+ return p;
+ }
+ else
+ {
+ if (document) document->SetError(TIXML_ERROR_READING_END_TAG, p, data, encoding);
+ return 0;
+ }
+ }
+ else
+ {
+ // Try to read an attribute:
+ TiXmlAttribute* attrib = new TiXmlAttribute();
+ if (!attrib)
+ {
+ if (document) document->SetError(TIXML_ERROR_OUT_OF_MEMORY, pErr, data, encoding);
+ return 0;
+ }
+
+ attrib->SetDocument(document);
+ const char* pErr = p;
+ p = attrib->Parse(p, data, encoding);
+
+ if (!p || !*p)
+ {
+ if (document) document->SetError(TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding);
+ delete attrib;
+ return 0;
+ }
+
+ // Handle the strange case of double attributes:
+ TiXmlAttribute* node = attributeSet.Find(attrib->NameTStr());
+ if (node)
+ {
+ node->SetValue(attrib->Value());
+ delete attrib;
+ return 0;
+ }
+
+ attributeSet.Add(attrib);
+ }
+ }
+ return p;
+}
+
+
+const char* TiXmlElement::ReadValue(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)
+{
+ TiXmlDocument* document = GetDocument();
+
+ // Read in text and elements in any order.
+ const char* pWithWhiteSpace = p;
+ p = SkipWhiteSpace(p, encoding);
+
+ while (p && *p)
+ {
+ if (*p != '<')
+ {
+ // Take what we have, make a text element.
+ TiXmlText* textNode = new TiXmlText("");
+
+ if (!textNode)
+ {
+ if (document) document->SetError(TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding);
+ return 0;
+ }
+
+ if (TiXmlBase::IsWhiteSpaceCondensed())
+ {
+ p = textNode->Parse(p, data, encoding);
+ }
+ else
+ {
+ // Special case: we want to keep the white space
+ // so that leading spaces aren't removed.
+ p = textNode->Parse(pWithWhiteSpace, data, encoding);
+ }
+
+ if (!textNode->Blank())
+ LinkEndChild(textNode);
+ else
+ delete textNode;
+ }
+ else
+ {
+ // We hit a '<'
+ // Have we hit a new element or an end tag? This could also be
+ // a TiXmlText in the "CDATA" style.
+ if (StringEqual(p, "</", false, encoding))
+ {
+ return p;
+ }
+ else
+ {
+ TiXmlNode* node = Identify(p, encoding);
+ if (node)
+ {
+ p = node->Parse(p, data, encoding);
+ LinkEndChild(node);
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ }
+ pWithWhiteSpace = p;
+ p = SkipWhiteSpace(p, encoding);
+ }
+
+ if (!p)
+ {
+ if (document) document->SetError(TIXML_ERROR_READING_ELEMENT_VALUE, 0, 0, encoding);
+ }
+ return p;
+}
+
+
+#ifdef TIXML_USE_STL
+void TiXmlUnknown::StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag)
+{
+ while (in->good())
+ {
+ int c = in->get();
+ if (c <= 0)
+ {
+ TiXmlDocument* document = GetDocument();
+ if (document)
+ document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return;
+ }
+ (*tag) += (char) c;
+
+ if (c == '>')
+ {
+ // All is well.
+ return;
+ }
+ }
+}
+#endif
+
+
+const char* TiXmlUnknown::Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)
+{
+ TiXmlDocument* document = GetDocument();
+ p = SkipWhiteSpace(p, encoding);
+
+ if (data)
+ {
+ data->Stamp(p, encoding);
+ location = data->Cursor();
+ }
+ if (!p || !*p || *p != '<')
+ {
+ if (document) document->SetError(TIXML_ERROR_PARSING_UNKNOWN, p, data, encoding);
+ return 0;
+ }
+ ++p;
+ value = "";
+
+ while (p && *p && *p != '>')
+ {
+ value += *p;
+ ++p;
+ }
+
+ if (!p)
+ {
+ if (document) document->SetError(TIXML_ERROR_PARSING_UNKNOWN, 0, 0, encoding);
+ }
+ if (*p == '>')
+ return p+1;
+ return p;
+}
+
+#ifdef TIXML_USE_STL
+void TiXmlComment::StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag)
+{
+ while (in->good())
+ {
+ int c = in->get();
+ if (c <= 0)
+ {
+ TiXmlDocument* document = GetDocument();
+ if (document)
+ document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return;
+ }
+
+ (*tag) += (char) c;
+
+ if (c == '>'
+ && tag->at(tag->length() - 2) == '-'
+ && tag->at(tag->length() - 3) == '-')
+ {
+ // All is well.
+ return;
+ }
+ }
+}
+#endif
+
+
+const char* TiXmlComment::Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)
+{
+ TiXmlDocument* document = GetDocument();
+ value = "";
+
+ p = SkipWhiteSpace(p, encoding);
+
+ if (data)
+ {
+ data->Stamp(p, encoding);
+ location = data->Cursor();
+ }
+ const char* startTag = "<!--";
+ const char* endTag = "-->";
+
+ if (!StringEqual(p, startTag, false, encoding))
+ {
+ document->SetError(TIXML_ERROR_PARSING_COMMENT, p, data, encoding);
+ return 0;
+ }
+ p += strlen(startTag);
+ p = ReadText(p, &value, false, endTag, false, encoding);
+ return p;
+}
+
+
+const char* TiXmlAttribute::Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)
+{
+ p = SkipWhiteSpace(p, encoding);
+ if (!p || !*p) return 0;
+
+// int tabsize = 4;
+// if (document)
+// tabsize = document->TabSize();
+
+ if (data)
+ {
+ data->Stamp(p, encoding);
+ location = data->Cursor();
+ }
+ // Read the name, the '=' and the value.
+ const char* pErr = p;
+ p = ReadName(p, &name, encoding);
+ if (!p || !*p)
+ {
+ if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding);
+ return 0;
+ }
+ p = SkipWhiteSpace(p, encoding);
+ if (!p || !*p || *p != '=')
+ {
+ if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding);
+ return 0;
+ }
+
+ ++p; // skip '='
+ p = SkipWhiteSpace(p, encoding);
+ if (!p || !*p)
+ {
+ if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding);
+ return 0;
+ }
+
+ const char* end;
+ const char SINGLE_QUOTE = '\'';
+ const char DOUBLE_QUOTE = '\"';
+
+ if (*p == SINGLE_QUOTE)
+ {
+ ++p;
+ end = "\'"; // single quote in string
+ p = ReadText(p, &value, false, end, false, encoding);
+ }
+ else if (*p == DOUBLE_QUOTE)
+ {
+ ++p;
+ end = "\""; // double quote in string
+ p = ReadText(p, &value, false, end, false, encoding);
+ }
+ else
+ {
+ // All attribute values should be in single or double quotes.
+ // But this is such a common error that the parser will try
+ // its best, even without them.
+ value = "";
+ while ( p && *p // existence
+ && !IsWhiteSpace(*p) && *p != '\n' && *p != '\r' // whitespace
+ && *p != '/' && *p != '>') // tag end
+ {
+ if (*p == SINGLE_QUOTE || *p == DOUBLE_QUOTE) {
+ // [ 1451649 ] Attribute values with trailing quotes not handled correctly
+ // We did not have an opening quote but seem to have a
+ // closing one. Give up and throw an error.
+ if (document) document->SetError(TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding);
+ return 0;
+ }
+ value += *p;
+ ++p;
+ }
+ }
+ return p;
+}
+
+#ifdef TIXML_USE_STL
+void TiXmlText::StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag)
+{
+ if (cdata)
+ {
+ int c = in->get();
+ if (c <= 0)
+ {
+ TiXmlDocument* document = GetDocument();
+ if (document)
+ document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return;
+ }
+
+ (*tag) += (char) c;
+
+ if (c == '>'
+ && tag->at(tag->length() - 2) == ']'
+ && tag->at(tag->length() - 3) == ']')
+ {
+ // All is well.
+ return;
+ }
+ }
+ else
+ {
+ while (in->good())
+ {
+ int c = in->peek();
+ if (c == '<')
+ return;
+ if (c <= 0)
+ {
+ TiXmlDocument* document = GetDocument();
+ if (document)
+ document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return;
+ }
+
+ (*tag) += (char) c;
+ in->get();
+ }
+ }
+}
+#endif
+
+const char* TiXmlText::Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding encoding)
+{
+ value = "";
+ TiXmlDocument* document = GetDocument();
+
+ if (data)
+ {
+ data->Stamp(p, encoding);
+ location = data->Cursor();
+ }
+
+ const char* const startTag = "<![CDATA[";
+ const char* const endTag = "]]>";
+
+ if (cdata || StringEqual(p, startTag, false, encoding))
+ {
+ cdata = true;
+
+ if (!StringEqual(p, startTag, false, encoding))
+ {
+ document->SetError(TIXML_ERROR_PARSING_CDATA, p, data, encoding);
+ return 0;
+ }
+ p += strlen(startTag);
+
+ // Keep all the white space, ignore the encoding, etc.
+ while ( p && *p
+ && !StringEqual(p, endTag, false, encoding)
+ )
+ {
+ value += *p;
+ ++p;
+ }
+
+ TIXML_STRING dummy;
+ p = ReadText(p, &dummy, false, endTag, false, encoding);
+ return p;
+ }
+ else
+ {
+ bool ignoreWhite = true;
+
+ const char* end = "<";
+ p = ReadText(p, &value, ignoreWhite, end, false, encoding);
+ if (p)
+ return p-1; // don't truncate the '<'
+ return 0;
+ }
+}
+
+#ifdef TIXML_USE_STL
+void TiXmlDeclaration::StreamIn(TIXML_ISTREAM * in, TIXML_STRING * tag)
+{
+ while (in->good())
+ {
+ int c = in->get();
+ if (c <= 0)
+ {
+ TiXmlDocument* document = GetDocument();
+ if (document)
+ document->SetError(TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN);
+ return;
+ }
+ (*tag) += (char) c;
+
+ if (c == '>')
+ {
+ // All is well.
+ return;
+ }
+ }
+}
+#endif
+
+const char* TiXmlDeclaration::Parse(const char* p, TiXmlParsingData* data, TiXmlEncoding _encoding)
+{
+ p = SkipWhiteSpace(p, _encoding);
+ // Find the beginning, find the end, and look for
+ // the stuff in-between.
+ TiXmlDocument* document = GetDocument();
+ if (!p || !*p || !StringEqual(p, "<?xml", true, _encoding))
+ {
+ if (document) document->SetError(TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding);
+ return 0;
+ }
+ if (data)
+ {
+ data->Stamp(p, _encoding);
+ location = data->Cursor();
+ }
+ p += 5;
+
+ version = "";
+ encoding = "";
+ standalone = "";
+
+ while (p && *p)
+ {
+ if (*p == '>')
+ {
+ ++p;
+ return p;
+ }
+
+ p = SkipWhiteSpace(p, _encoding);
+ if (StringEqual(p, "version", true, _encoding))
+ {
+ TiXmlAttribute attrib;
+ p = attrib.Parse(p, data, _encoding);
+ version = attrib.Value();
+ }
+ else if (StringEqual(p, "encoding", true, _encoding))
+ {
+ TiXmlAttribute attrib;
+ p = attrib.Parse(p, data, _encoding);
+ encoding = attrib.Value();
+ }
+ else if (StringEqual(p, "standalone", true, _encoding))
+ {
+ TiXmlAttribute attrib;
+ p = attrib.Parse(p, data, _encoding);
+ standalone = attrib.Value();
+ }
+ else
+ {
+ // Read over whatever it is.
+ while (p && *p && *p != '>' && !IsWhiteSpace(*p))
+ ++p;
+ }
+ }
+ return 0;
+}
+
+bool TiXmlText::Blank() const
+{
+ for (unsigned i=0; i<value.length(); i++)
+ if (!IsWhiteSpace(value[i]))
+ return false;
+ return true;
+}
+