diff options
Diffstat (limited to 'plugins/helpers')
-rw-r--r-- | plugins/helpers/commonheaders.h | 65 | ||||
-rw-r--r-- | plugins/helpers/db_helpers.cpp | 71 | ||||
-rw-r--r-- | plugins/helpers/db_helpers.h | 489 | ||||
-rw-r--r-- | plugins/helpers/gen_helpers.cpp | 463 | ||||
-rw-r--r-- | plugins/helpers/gen_helpers.h | 125 | ||||
-rw-r--r-- | plugins/helpers/stshelpers.cpp | 303 | ||||
-rw-r--r-- | plugins/helpers/stshelpers.h | 35 | ||||
-rw-r--r-- | plugins/helpers/xmlhelpers.cpp | 418 | ||||
-rw-r--r-- | plugins/helpers/xmlhelpers.h | 17 |
9 files changed, 1986 insertions, 0 deletions
diff --git a/plugins/helpers/commonheaders.h b/plugins/helpers/commonheaders.h new file mode 100644 index 0000000000..7603131670 --- /dev/null +++ b/plugins/helpers/commonheaders.h @@ -0,0 +1,65 @@ +/*
+
+Miranda IM: the free IM client for Microsoft* Windows*
+
+Copyright 2000-2003 Miranda ICQ/IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+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.
+*/
+
+#if defined( UNICODE ) && !defined( _UNICODE )
+# define _UNICODE
+#endif
+
+#include <tchar.h>
+#include <malloc.h>
+
+//#define _WIN32_WINNT 0x0501
+#include <windows.h>
+#include <commctrl.h>
+#include <stdio.h>
+//#include <win2k.h>
+#include <newpluginapi.h>
+#include <m_system.h>
+#include <m_database.h>
+#include <m_clc.h>
+#include <m_clui.h>
+#include <m_langpack.h>
+#include <m_clist.h>
+#include <m_clistint.h>
+#include <m_netlib.h>
+#include <m_button.h>
+#include <m_protosvc.h>
+#include <m_protomod.h>
+#include <m_protocols.h>
+#include <m_plugins.h>
+#include <m_options.h>
+#include <m_utils.h>
+#include <m_skin.h>
+#include <m_contacts.h>
+#include <m_message.h>
+#include <m_userinfo.h>
+#include <m_history.h>
+#include <m_addcontact.h>
+#include <m_findadd.h>
+#include <m_file.h>
+#include <m_email.h>
+#include <m_awaymsg.h>
+#include <m_idle.h>
+#include <m_ignore.h>
+#include <m_utils.h>
+#include <m_variables.h>
diff --git a/plugins/helpers/db_helpers.cpp b/plugins/helpers/db_helpers.cpp new file mode 100644 index 0000000000..cf58b4f3b2 --- /dev/null +++ b/plugins/helpers/db_helpers.cpp @@ -0,0 +1,71 @@ +/*
+ Helper functions for Miranda-IM (www.miranda-im.org)
+ Copyright 2006 P. Boon
+
+ 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
+*/
+#include "db_helpers.h"
+
+struct RemoveSettings{
+ char *szPrefix;
+ int count;
+ char **szSettings;
+};
+
+static int DBRemoveEnumProc(const char *szSetting, LPARAM lParam) {
+
+ struct RemoveSettings *rs;
+
+ rs = (struct RemoveSettings *)lParam;
+ if (!strncmp(szSetting, rs->szPrefix, strlen(rs->szPrefix))) {
+ rs->szSettings = ( char** )realloc(rs->szSettings, (rs->count+1)*sizeof(char *));
+ rs->szSettings[rs->count] = _strdup(szSetting);
+ rs->count += 1;
+ }
+
+ return 0;
+}
+
+int Hlp_RemoveDatabaseSettings(HANDLE hContact, char *szModule, char *szPrefix) {
+
+ DBCONTACTENUMSETTINGS dbces;
+ struct RemoveSettings rs;
+ int i, count;
+
+ ZeroMemory(&rs, sizeof(struct RemoveSettings));
+ rs.szPrefix = szPrefix;
+ ZeroMemory(&dbces, sizeof(DBCONTACTENUMSETTINGS));
+ dbces.pfnEnumProc = DBRemoveEnumProc;
+ dbces.lParam = (LPARAM)&rs;
+ dbces.szModule = szModule;
+ if (CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)(HANDLE)hContact, (LPARAM)&dbces) == -1) {
+
+ return -1;
+ }
+ count = 0;
+ if (rs.szSettings != NULL) {
+ for (i=0;i<rs.count;i++) {
+ if (rs.szSettings[i] != NULL) {
+ if (!DBDeleteContactSetting(hContact, szModule, rs.szSettings[i])) {
+ count += 1;
+ }
+ free(rs.szSettings[i]);
+ }
+ }
+ free(rs.szSettings);
+ }
+
+ return count;
+}
diff --git a/plugins/helpers/db_helpers.h b/plugins/helpers/db_helpers.h new file mode 100644 index 0000000000..c208442db7 --- /dev/null +++ b/plugins/helpers/db_helpers.h @@ -0,0 +1,489 @@ +/*
+ Helper functions for Miranda-IM (www.miranda-im.org)
+ Copyright 2006 P. Boon
+
+ 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
+*/
+#ifndef __DB_HELPERS_H
+#define __DB_HELPERS_H
+
+#include "commonheaders.h"
+
+int Hlp_RemoveDatabaseSettings(HANDLE hContact, char *szModule, char *szPrefix);
+
+/* the Hlp_DBGetContactSetting(X)String(Y) functions return a copy in local memory, free it using your own free() */
+#define db_getb(c,d) DBGetContactSettingByte(NULL,MODULENAME,c,d)
+#define db_getw(c,d) DBGetContactSettingWord(NULL,MODULENAME,c,d)
+#define db_getd(c,d) DBGetContactSettingDword(NULL,MODULENAME,c,d)
+#define db_getAs(c,d) Hlp_DBGetContactSettingString(NULL,MODULENAME,c,d)
+#define db_gets(c,d) Hlp_DBGetContactSettingTString(NULL,MODULENAME,c,d)
+#define db_getWs(c,d) Hlp_DBGetContactSettingWString(NULL,MODULENAME,c,d)
+#define db_getUs(c,d) Hlp_DBGetContactSettingStringUtf(NULL,MODULENAME,c,d)
+
+#define db_setb(c,d) DBWriteContactSettingByte(NULL,MODULENAME,c, (BYTE)d)
+#define db_setw(c,d) DBWriteContactSettingWord(NULL,MODULENAME,c, (WORD)d)
+#define db_setd(c,d) DBWriteContactSettingDword(NULL,MODULENAME,c, (DWORD)d)
+#define db_setAs(c,d) DBWriteContactSettingString(NULL,MODULENAME,c,d)
+#define db_sets(c,d) DBWriteContactSettingTString(NULL,MODULENAME,c,d)
+#define db_setWs(c,d) DBWriteContactSettingWString(NULL,MODULENAME,c,d)
+#define db_setUs(c,d) DBWriteContactSettingStringUtf(NULL,MODULENAME,c,d)
+
+#define db_del(c) DBDeleteContactSetting(NULL,MODULENAME,c);
+
+#define dbi_getb(a,b,c) Hlp_DBGetIthSettingByte(a, NULL, MODULENAME, b, c)
+#define dbi_getw(a,b,c) Hlp_DBGetIthSettingWord(a, NULL, MODULENAME, b, c)
+#define dbi_getd(a,b,c) Hlp_DBGetIthSettingDword(a, NULL, MODULENAME, b, c)
+#define dbi_getAs(a,b,c) Hlp_DBGetIthSettingString(a, NULL, MODULENAME, b, c)
+#define dbi_gets(a,b,c) Hlp_DBGetIthSettingTString(a, NULL, MODULENAME, b, c)
+#define dbi_getWs(a,b,c) Hlp_DBGetIthSettingWString(a, NULL, MODULENAME, b, c)
+#define dbi_getUs(a,b,c) Hlp_DBGetIthSettingStringUtf(a, NULL, MODULENAME, b, c)
+
+#define dbi_setb(a,b,c) Hlp_DBWriteIthSettingByte(a, NULL, MODULENAME, b, (BYTE)c)
+#define dbi_setw(a,b,c) Hlp_DBWriteIthSettingWord(a, NULL, MODULENAME, b, (WORD)c)
+#define dbi_setd(a,b,c) Hlp_DBWriteIthSettingDword(a, NULL, MODULENAME, b, (DWORD)c)
+#define dbi_setAs(a,b,c) Hlp_DBWriteIthSettingString(a, NULL, MODULENAME, b, c)
+#define dbi_sets(a,b,c) Hlp_DBWriteIthSettingTString(a, NULL, MODULENAME, b, c)
+#define dbi_setWs(a,b,c) Hlp_DBWriteIthSettingWString(a, NULL, MODULENAME, b, c)
+#define dbi_setUs(a,b,c) Hlp_DBWriteIthSettingStringUtf(a, NULL, MODULENAME, b, c)
+
+#define dbi_del(a,b) Hlp_DBDeleteIthSetting(a, NULL, MODULENAME, b)
+
+#define dbs_getb(a,b,c) Hlp_DBGetXthSettingByte(a, NULL, MODULENAME, b, c)
+#define dbs_getw(a,b,c) Hlp_DBGetXthSettingWord(a, NULL, MODULENAME, b, c)
+#define dbs_getd(a,b,c) Hlp_DBGetXthSettingDword(a, NULL, MODULENAME, b, c)
+#define dbs_getAs(a,b,c) Hlp_DBGetXthSettingString(a, NULL, MODULENAME, b, c)
+#define dbs_gets(a,b,c) Hlp_DBGetXthSettingTString(a, NULL, MODULENAME, b, c)
+#define dbs_getWs(a,b,c) Hlp_DBGetXthSettingWString(a, NULL, MODULENAME, b, c)
+#define dbs_getUs(a,b,c) Hlp_DBGetXthSettingStringUtf(a, NULL, MODULENAME, b, c)
+
+#define dbs_setb(a,b,c) Hlp_DBWriteXthSettingByte(a, NULL, MODULENAME, b, (BYTE)c)
+#define dbs_setw(a,b,c) Hlp_DBWriteXthSettingWord(a, NULL, MODULENAME, b, (WORD)c)
+#define dbs_setd(a,b,c) Hlp_DBWriteXthSettingDword(a, NULL, MODULENAME, b, (DWORD)c)
+#define dbs_setAs(a,b,c) Hlp_DBWriteXthSettingString(a, NULL, MODULENAME, b, c)
+#define dbs_sets(a,b,c) Hlp_DBWriteXthSettingTString(a, NULL, MODULENAME, b, c)
+#define dbs_setWs(a,b,c) Hlp_DBWriteXthSettingWString(a, NULL, MODULENAME, b, c)
+#define dbs_setUs(a,b,c) Hlp_DBWriteXthSettingStringUtf(a, NULL, MODULENAME, b, c)
+
+#define dbs_del(a,b) Hlp_DBDeleteXthSetting(a, NULL, MODULENAME, b)
+
+__inline static char *Hlp_DBGetContactSettingString(HANDLE hContact,const char *szModule,
+ const char *szSetting,char *errVal)
+{
+ int rc;
+ DBCONTACTGETSETTING cgs;
+ DBVARIANT dbv = {0};
+ char *res;
+ cgs.szModule=szModule;
+ cgs.szSetting=szSetting;
+ cgs.pValue=&dbv;
+ dbv.type = DBVT_ASCIIZ;
+
+ rc=CallService(MS_DB_CONTACT_GETSETTING_STR,(WPARAM)hContact,(LPARAM)&cgs);
+#if defined(_DEBUG) && defined(DBCHECKSETTINGS)
+ if (rc != 0) {
+ char buf[128];
+ _snprintf(buf,sizeof(buf),"%s:%d failed to fetch %s/%s",szFile,nLine,szModule,szSetting);
+ db_msg_dbg(buf);
+ }
+#endif
+ if (rc == 0) {
+ res = _strdup(dbv.pszVal);
+ DBFreeVariant(&dbv);
+ return res;
+ }
+ else {
+ DBFreeVariant(&dbv);
+ return errVal!=NULL?_strdup(errVal):NULL;
+ }
+}
+
+__inline static TCHAR *Hlp_DBGetContactSettingTString(HANDLE hContact,const char *szModule,
+ const char *szSetting,TCHAR *errVal)
+{
+ int rc;
+ DBCONTACTGETSETTING cgs;
+ DBVARIANT dbv = {0};
+ TCHAR *res;
+ cgs.szModule=szModule;
+ cgs.szSetting=szSetting;
+ cgs.pValue=&dbv;
+#if defined(_UNICODE)
+ dbv.type = DBVT_WCHAR;
+#else
+ dbv.type = DBVT_ASCIIZ;
+#endif
+
+ rc=CallService(MS_DB_CONTACT_GETSETTING_STR,(WPARAM)hContact,(LPARAM)&cgs);
+#if defined(_DEBUG) && defined(DBCHECKSETTINGS)
+ if (rc != 0) {
+ char buf[128];
+ _snprintf(buf,sizeof(buf),"%s:%d failed to fetch %s/%s",szFile,nLine,szModule,szSetting);
+ db_msg_dbg(buf);
+ }
+#endif
+ if (rc == 0) {
+ res = _tcsdup(dbv.ptszVal);
+ DBFreeVariant(&dbv);
+ return res;
+ }
+ else {
+ DBFreeVariant(&dbv);
+ return errVal!=NULL?_tcsdup(errVal):NULL;
+ }
+}
+
+__inline static WCHAR *Hlp_DBGetContactSettingWString(HANDLE hContact,const char *szModule,
+ const char *szSetting,WCHAR *errVal)
+{
+ int rc;
+ DBCONTACTGETSETTING cgs;
+ DBVARIANT dbv = {0};
+ WCHAR *res;
+ cgs.szModule=szModule;
+ cgs.szSetting=szSetting;
+ cgs.pValue=&dbv;
+ dbv.type = DBVT_WCHAR;
+
+ rc=CallService(MS_DB_CONTACT_GETSETTING_STR,(WPARAM)hContact,(LPARAM)&cgs);
+#if defined(_DEBUG) && defined(DBCHECKSETTINGS)
+ if (rc != 0) {
+ char buf[128];
+ _snprintf(buf,sizeof(buf),"%s:%d failed to fetch %s/%s",szFile,nLine,szModule,szSetting);
+ db_msg_dbg(buf);
+ }
+#endif
+ if (rc == 0) {
+ res = _wcsdup(dbv.pwszVal);
+ DBFreeVariant(&dbv);
+ return res;
+ }
+ else {
+ DBFreeVariant(&dbv);
+ return errVal!=NULL?_wcsdup(errVal):NULL;
+ }
+}
+
+__inline static char *Hlp_DBGetContactSettingStringUtf(HANDLE hContact,const char *szModule,
+ const char *szSetting,char *errVal)
+{
+ int rc;
+ DBCONTACTGETSETTING cgs;
+ DBVARIANT dbv = {0};
+ char *res;
+ cgs.szModule=szModule;
+ cgs.szSetting=szSetting;
+ cgs.pValue=&dbv;
+ dbv.type = DBVT_UTF8;
+
+ rc=CallService(MS_DB_CONTACT_GETSETTING_STR,(WPARAM)hContact,(LPARAM)&cgs);
+#if defined(_DEBUG) && defined(DBCHECKSETTINGS)
+ if (rc != 0) {
+ char buf[128];
+ _snprintf(buf,sizeof(buf),"%s:%d failed to fetch %s/%s",szFile,nLine,szModule,szSetting);
+ db_msg_dbg(buf);
+ }
+#endif
+ if (rc == 0) {
+ res = _strdup(dbv.pszVal);
+ DBFreeVariant(&dbv);
+ return res;
+ }
+ else {
+ DBFreeVariant(&dbv);
+ return errVal!=NULL?_strdup(errVal):NULL;
+ }
+}
+
+#ifndef PREFIX_ITH
+#define PREFIX_ITH ""
+#endif
+
+__inline static int Hlp_DBWriteIthSettingByte(unsigned int i, HANDLE hContact,const char *szModule,const char *szSetting,BYTE val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBWriteContactSettingByte(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteIthSettingWord(unsigned int i, HANDLE hContact,const char *szModule,const char *szSetting,WORD val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBWriteContactSettingWord(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteIthSettingDword(unsigned int i, HANDLE hContact,const char *szModule,const char *szSetting,DWORD val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBWriteContactSettingDword(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteIthSettingString(unsigned int i, HANDLE hContact,const char *szModule,const char *szSetting,const char *val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBWriteContactSettingString(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteIthSettingTString(unsigned int i, HANDLE hContact,const char *szModule,const char *szSetting,const TCHAR *val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBWriteContactSettingTString(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteIthSettingWString(unsigned int i, HANDLE hContact,const char *szModule,const char *szSetting,const WCHAR *val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBWriteContactSettingWString(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteIthSettingStringUtf(unsigned int i, HANDLE hContact,const char *szModule,const char *szSetting,const char *val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBWriteContactSettingStringUtf(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBGetIthSettingByte(unsigned int i, HANDLE hContact, const char *szModule, const char *szSetting, int errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBGetContactSettingByte(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static WORD Hlp_DBGetIthSettingWord(unsigned int i, HANDLE hContact, const char *szModule, const char *szSetting, int errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBGetContactSettingWord(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static DWORD Hlp_DBGetIthSettingDword(unsigned int i, HANDLE hContact, const char *szModule, const char *szSetting, int errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBGetContactSettingDword(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static char *Hlp_DBGetIthSettingString(unsigned int i, HANDLE hContact, const char *szModule, const char *szSetting, char *errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return Hlp_DBGetContactSettingString(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static TCHAR *Hlp_DBGetIthSettingTString(unsigned int i, HANDLE hContact, const char *szModule, const char *szSetting, TCHAR *errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return Hlp_DBGetContactSettingTString(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static WCHAR *Hlp_DBGetIthSettingWString(unsigned int i, HANDLE hContact, const char *szModule, const char *szSetting, WCHAR *errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return Hlp_DBGetContactSettingWString(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static char *Hlp_DBGetIthSettingStringUtf(unsigned int i, HANDLE hContact, const char *szModule, const char *szSetting, char *errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return Hlp_DBGetContactSettingStringUtf(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static int Hlp_DBGetIthSetting(unsigned int i, HANDLE hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBGetContactSetting(hContact, szModule, dbSetting, dbv);
+}
+
+__inline static int Hlp_DBDeleteIthSetting(unsigned int i, HANDLE hContact,const char *szModule,const char *szSetting) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%u_%s", PREFIX_ITH, i, szSetting);
+ return DBDeleteContactSetting(hContact, szModule, dbSetting);
+}
+
+#ifndef PREFIX_XTH
+#define PREFIX_XTH ""
+#endif
+
+__inline static int Hlp_DBWriteXthSettingByte(char *x, HANDLE hContact,const char *szModule,const char *szSetting,BYTE val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBWriteContactSettingByte(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteXthSettingWord(char *x, HANDLE hContact,const char *szModule,const char *szSetting,WORD val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBWriteContactSettingWord(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteXthSettingDword(char *x, HANDLE hContact,const char *szModule,const char *szSetting,DWORD val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBWriteContactSettingDword(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteXthSettingString(char *x, HANDLE hContact,const char *szModule,const char *szSetting,const char *val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBWriteContactSettingString(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteXthSettingTString(char *x, HANDLE hContact,const char *szModule,const char *szSetting,const TCHAR *val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBWriteContactSettingTString(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteXthSettingWString(char *x, HANDLE hContact,const char *szModule,const char *szSetting,const WCHAR *val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBWriteContactSettingWString(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBWriteXthSettingStringUtf(char *x, HANDLE hContact,const char *szModule,const char *szSetting,const char *val) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBWriteContactSettingStringUtf(hContact, szModule, dbSetting, val);
+}
+
+__inline static int Hlp_DBGetXthSettingByte(char *x, HANDLE hContact, const char *szModule, const char *szSetting, int errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBGetContactSettingByte(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static WORD Hlp_DBGetXthSettingWord(char *x, HANDLE hContact, const char *szModule, const char *szSetting, int errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBGetContactSettingWord(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static DWORD Hlp_DBGetXthSettingDword(char *x, HANDLE hContact, const char *szModule, const char *szSetting, int errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBGetContactSettingDword(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static char *Hlp_DBGetXthSettingString(char *x, HANDLE hContact, const char *szModule, const char *szSetting, char *errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return Hlp_DBGetContactSettingString(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static TCHAR *Hlp_DBGetXthSettingTString(char *x, HANDLE hContact, const char *szModule, const char *szSetting, TCHAR *errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return Hlp_DBGetContactSettingTString(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static WCHAR *Hlp_DBGetXthSettingWString(char *x, HANDLE hContact, const char *szModule, const char *szSetting, WCHAR *errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return Hlp_DBGetContactSettingWString(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static char *Hlp_DBGetXthSettingStringUtf(char *x, HANDLE hContact, const char *szModule, const char *szSetting, char *errorValue) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return Hlp_DBGetContactSettingStringUtf(hContact, szModule, dbSetting, errorValue);
+}
+
+__inline static int Hlp_DBGetXthSetting(char *x, HANDLE hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv) {
+
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBGetContactSetting(hContact, szModule, dbSetting, dbv);
+}
+
+__inline static int Hlp_DBDeleteXthSetting(char *x, HANDLE hContact,const char *szModule,const char *szSetting) {
+
+ char dbSetting[128];
+
+ _snprintf(dbSetting, sizeof(dbSetting), "%s%s_%s", PREFIX_XTH, x, szSetting);
+ return DBDeleteContactSetting(hContact, szModule, dbSetting);
+}
+
+#endif
diff --git a/plugins/helpers/gen_helpers.cpp b/plugins/helpers/gen_helpers.cpp new file mode 100644 index 0000000000..b2e8ff3380 --- /dev/null +++ b/plugins/helpers/gen_helpers.cpp @@ -0,0 +1,463 @@ +/*
+ Helper functions for Miranda-IM (www.miranda-im.org)
+ Copyright 2006 P. Boon
+
+ 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
+*/
+#include "commonheaders.h"
+#include "gen_helpers.h"
+
+int ProtoServiceExists(const char *szModule, const char *szService) {
+
+ char str[MAXMODULELABELLENGTH];
+ mir_snprintf(str, sizeof(str), "%s%s", szModule, szService);
+
+ return ServiceExists(str);
+}
+
+char *Hlp_GetProtocolNameA(const char *proto) {
+
+ char protoname[256];
+
+ if ( (!ProtoServiceExists(proto, PS_GETNAME)) || (CallProtoService(proto, PS_GETNAME, (WPARAM)sizeof(protoname), (LPARAM)protoname)) ) {
+ return NULL;
+ }
+
+ return _strdup(protoname);
+}
+
+TCHAR *Hlp_GetProtocolName(const char *proto) {
+
+ char protoname[256];
+
+ if ( (!ProtoServiceExists(proto, PS_GETNAME)) || (CallProtoService(proto, PS_GETNAME, (WPARAM)sizeof(protoname), (LPARAM)protoname)) ) {
+ return NULL;
+ }
+#ifdef UNICODE
+ return a2u(protoname);
+#else
+ return _strdup(protoname);
+#endif
+}
+
+char *Hlp_GetDlgItemTextA(HWND hwndDlg, int nIDDlgItem) {
+
+ int len = SendDlgItemMessageA(hwndDlg, nIDDlgItem, WM_GETTEXTLENGTH, 0, 0);
+ if (len < 0)
+ return NULL;
+
+ char *res = ( char* )malloc((len+1));
+ ZeroMemory(res, (len+1));
+ GetDlgItemTextA(hwndDlg, nIDDlgItem, res, len+1);
+
+ return res;
+}
+
+TCHAR *Hlp_GetDlgItemText(HWND hwndDlg, int nIDDlgItem) {
+
+ int len = SendDlgItemMessage(hwndDlg, nIDDlgItem, WM_GETTEXTLENGTH, 0, 0);
+ if (len < 0)
+ return NULL;
+
+ TCHAR *res = ( TCHAR* )malloc((len+1)*sizeof(TCHAR));
+ ZeroMemory(res, (len+1)*sizeof(TCHAR));
+ GetDlgItemText(hwndDlg, nIDDlgItem, res, len+1);
+
+ return res;
+}
+
+char *Hlp_GetWindowTextA(HWND hwndDlg) {
+
+ int len = SendMessageA(hwndDlg, WM_GETTEXTLENGTH, 0, 0);
+ if (len < 0)
+ return NULL;
+
+ char *res = ( char* )malloc((len+1));
+ ZeroMemory(res, (len+1));
+ GetWindowTextA(hwndDlg, res, len+1);
+
+ return res;
+}
+
+TCHAR *Hlp_GetWindowText(HWND hwndDlg) {
+
+ int len = SendMessage(hwndDlg, WM_GETTEXTLENGTH, 0, 0);
+ if (len < 0)
+ return NULL;
+
+ TCHAR *res = ( TCHAR* )malloc((len+1)*sizeof(TCHAR));
+ ZeroMemory(res, (len+1)*sizeof(TCHAR));
+ GetWindowText(hwndDlg, res, len+1);
+
+ return res;
+}
+
+/**
+ * Modified from Miranda CList, clistsettings.c
+ **/
+
+char* u2a( wchar_t* src )
+{
+ int cbLen;
+ char* result;
+
+ if (src == NULL) {
+ return NULL;
+ }
+ cbLen = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL );
+ result = ( char* )malloc( cbLen+1 );
+ if ( result == NULL )
+ return NULL;
+
+ WideCharToMultiByte( CP_ACP, 0, src, -1, result, cbLen, NULL, NULL );
+ result[ cbLen ] = 0;
+ return result;
+}
+
+wchar_t* a2u( char* src )
+{
+ int cbLen;
+ wchar_t* result;
+
+ if (src == NULL) {
+ return NULL;
+ }
+ cbLen = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
+ result = ( wchar_t* )malloc( sizeof( wchar_t )*(cbLen+1));
+ if ( result == NULL )
+ return NULL;
+
+ MultiByteToWideChar( CP_ACP, 0, src, -1, result, cbLen );
+ result[ cbLen ] = 0;
+ return result;
+}
+
+// Logging
+static int WriteToDebugLogA(const char *szMsg) {
+
+ int res;
+
+ res = 0;
+ if (ServiceExists(MS_NETLIB_LOG)) {
+ res = CallService(MS_NETLIB_LOG, (WPARAM)NULL, (LPARAM)szMsg);
+ } else {
+ OutputDebugStringA(szMsg);
+ OutputDebugStringA("\r\n");
+ }
+
+ return res;
+}
+
+int AddDebugLogMessageA(const char* fmt, ...) {
+
+ int res;
+ char szText[MAX_DEBUG], szFinal[MAX_DEBUG];
+ va_list va;
+
+ va_start(va,fmt);
+ _vsnprintf(szText, sizeof(szText), fmt, va);
+ va_end(va);
+#ifdef MODULENAME
+ mir_snprintf(szFinal, sizeof(szFinal), "%s: %s", MODULENAME, szText);
+#else
+ strncpy(szFinal, szText, sizeof(szFinal));
+#endif
+ res = WriteToDebugLogA(szFinal);
+
+ return res;
+}
+
+int AddDebugLogMessage(const TCHAR* fmt, ...) {
+
+ int res;
+ TCHAR tszText[MAX_DEBUG], tszFinal[MAX_DEBUG];
+ char *szFinal;
+ va_list va;
+
+ va_start(va,fmt);
+ _vsntprintf(tszText, sizeof(tszText), fmt, va);
+ va_end(va);
+#ifdef MODULENAME
+ mir_sntprintf(tszFinal, SIZEOF(tszFinal), _T("%s: %s"), MODULENAME, tszText);
+#else
+ _tcsncpy(tszFinal, tszText, sizeof(tszFinal));
+#endif
+
+#ifdef UNICODE
+ szFinal = u2a(tszFinal);
+#else
+ szFinal = _strdup(tszFinal);
+#endif
+ res = WriteToDebugLogA(szFinal);
+ free(szFinal);
+
+ return res;
+}
+
+int AddErrorLogMessageA(const char* fmt, ...) {
+
+ int res;
+ char szText[MAX_DEBUG], szFinal[MAX_DEBUG];
+ va_list va;
+
+ va_start(va,fmt);
+ _vsnprintf(szText, sizeof(szText), fmt, va);
+ va_end(va);
+#ifdef MODULENAME
+ mir_snprintf(szFinal, sizeof(szFinal), "%s: %s", MODULENAME, szText);
+#else
+ strncpy(szFinal, szText, sizeof(szFinal));
+#endif
+ res = WriteToDebugLogA(szFinal);
+ MessageBoxA(NULL, szFinal, "Error", MB_OK|MB_ICONERROR);
+
+ return res;
+}
+
+int AddErrorLogMessage(const TCHAR* fmt, ...) {
+
+ int res;
+ TCHAR tszText[MAX_DEBUG], tszFinal[MAX_DEBUG];
+ char *szFinal;
+ va_list va;
+
+ va_start(va,fmt);
+ _vsntprintf(tszText, sizeof(tszText), fmt, va);
+ va_end(va);
+#ifdef MODULENAME
+ mir_sntprintf(tszFinal, SIZEOF(tszFinal), _T("%s: %s"), MODULENAME, tszText);
+#else
+ _tcsncpy(tszFinal, tszText, sizeof(tszFinal));
+#endif
+
+#ifdef UNICODE
+ szFinal = u2a(tszFinal);
+#else
+ szFinal = _strdup(tszFinal);
+#endif
+ res = WriteToDebugLogA(szFinal);
+ MessageBoxA(NULL, szFinal, "Error", MB_OK|MB_ICONERROR);
+ free(szFinal);
+
+ return res;
+}
+
+
+//
+int ttoi(TCHAR *string)
+{
+ return ( string == NULL ) ? 0 : _ttoi( string );
+}
+
+TCHAR *itot(int num) {
+
+ char tRes[32];
+
+ // check this
+ _itoa(num, tRes, 10);
+
+#ifdef UNICODE
+ return a2u(tRes);
+#else
+ return _strdup(tRes);
+#endif
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Utf8Decode - converts UTF8-encoded string to the UCS2/MBCS format
+
+void Utf8Decode( char* str, wchar_t** ucs2 )
+{
+ int len;
+ wchar_t* tempBuf;
+
+ if ( str == NULL )
+ return;
+
+ len = strlen( str );
+ if ( len < 2 ) {
+ if ( ucs2 != NULL ) {
+ *ucs2 = ( wchar_t* )malloc(( len+1 )*sizeof( wchar_t ));
+ MultiByteToWideChar( CP_ACP, 0, str, len, *ucs2, len );
+ ( *ucs2 )[ len ] = 0;
+ }
+ return;
+ }
+
+ tempBuf = ( wchar_t* )alloca(( len+1 )*sizeof( wchar_t ));
+ {
+ wchar_t* d = tempBuf;
+ BYTE* s = ( BYTE* )str;
+
+ while( *s )
+ {
+ if (( *s & 0x80 ) == 0 ) {
+ *d++ = *s++;
+ continue;
+ }
+
+ if (( s[0] & 0xE0 ) == 0xE0 && ( s[1] & 0xC0 ) == 0x80 && ( s[2] & 0xC0 ) == 0x80 ) {
+ *d++ = (( WORD )( s[0] & 0x0F) << 12 ) + ( WORD )(( s[1] & 0x3F ) << 6 ) + ( WORD )( s[2] & 0x3F );
+ s += 3;
+ continue;
+ }
+
+ if (( s[0] & 0xE0 ) == 0xC0 && ( s[1] & 0xC0 ) == 0x80 ) {
+ *d++ = ( WORD )(( s[0] & 0x1F ) << 6 ) + ( WORD )( s[1] & 0x3F );
+ s += 2;
+ continue;
+ }
+
+ *d++ = *s++;
+ }
+
+ *d = 0;
+ }
+
+ if ( ucs2 != NULL ) {
+ int fullLen = ( len+1 )*sizeof( wchar_t );
+ *ucs2 = ( wchar_t* )malloc( fullLen );
+ memcpy( *ucs2, tempBuf, fullLen );
+ }
+
+ WideCharToMultiByte( CP_ACP, 0, tempBuf, -1, str, len, NULL, NULL );
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Utf8Encode - converts MBCS string to the UTF8-encoded format
+
+char* Utf8Encode( const char* src )
+{
+ int len;
+ char* result;
+ wchar_t* tempBuf;
+
+ if ( src == NULL )
+ return NULL;
+
+ len = strlen( src );
+ result = ( char* )malloc( len*3 + 1 );
+ if ( result == NULL )
+ return NULL;
+
+ tempBuf = ( wchar_t* )alloca(( len+1 )*sizeof( wchar_t ));
+ MultiByteToWideChar( CP_ACP, 0, src, -1, tempBuf, len );
+ tempBuf[ len ] = 0;
+ {
+ wchar_t* s = tempBuf;
+ BYTE* d = ( BYTE* )result;
+
+ while( *s ) {
+ int U = *s++;
+
+ if ( U < 0x80 ) {
+ *d++ = ( BYTE )U;
+ }
+ else if ( U < 0x800 ) {
+ *d++ = 0xC0 + (( U >> 6 ) & 0x3F );
+ *d++ = 0x80 + ( U & 0x003F );
+ }
+ else {
+ *d++ = 0xE0 + ( U >> 12 );
+ *d++ = 0x80 + (( U >> 6 ) & 0x3F );
+ *d++ = 0x80 + ( U & 0x3F );
+ } }
+
+ *d = 0;
+ }
+
+ return result;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Utf8Encode - converts UCS2 string to the UTF8-encoded format
+
+char* Utf8EncodeUcs2( const wchar_t* src )
+{
+ int len = wcslen( src );
+ char* result = ( char* )malloc( len*3 + 1 );
+ if ( result == NULL )
+ return NULL;
+
+ { const wchar_t* s = src;
+ BYTE* d = ( BYTE* )result;
+
+ while( *s ) {
+ int U = *s++;
+
+ if ( U < 0x80 ) {
+ *d++ = ( BYTE )U;
+ }
+ else if ( U < 0x800 ) {
+ *d++ = 0xC0 + (( U >> 6 ) & 0x3F );
+ *d++ = 0x80 + ( U & 0x003F );
+ }
+ else {
+ *d++ = 0xE0 + ( U >> 12 );
+ *d++ = 0x80 + (( U >> 6 ) & 0x3F );
+ *d++ = 0x80 + ( U & 0x3F );
+ } }
+
+ *d = 0;
+ }
+
+ return result;
+}
+
+// Helper functions that need MODULENAME
+#define SETTING_NOENCODINGCHECK "NoEncodingCheck"
+
+int Hlp_UnicodeCheck(char *szPluginName, BOOL bForce, const char *szModule) {
+
+#ifndef _DEBUG
+ char *ptr;
+ char szVersionText[256];
+
+ if (!CallService(MS_SYSTEM_GETVERSIONTEXT, (WPARAM)sizeof(szVersionText), (LPARAM)szVersionText)) {
+ ptr = strstr(szVersionText, "Unicode");
+#ifdef UNICODE
+ if ( (ptr == NULL) && (!DBGetContactSettingByte(NULL, szModule, SETTING_NOENCODINGCHECK, 0)) ) {
+ if (bForce) {
+ MessageBoxA(NULL, "You are running the ANSI version Miranda. Please use the ANSI build of this plugin.", szPluginName, MB_OK);
+
+ return -1;
+ }
+ else {
+ MessageBoxA(NULL, "You are running the ANSI version Miranda. It's recommened to use the ANSI build of this plugin.", szPluginName, MB_OK);
+ DBWriteContactSettingByte(NULL, szModule, SETTING_NOENCODINGCHECK, 1);
+
+ return 0;
+ }
+ }
+#else
+ if ( (ptr != NULL) && (!DBGetContactSettingByte(NULL, szModule, SETTING_NOENCODINGCHECK, 0)) ) {
+ if (bForce) {
+ MessageBoxA(NULL, "You are running the UNICODE version Miranda. Please use the UNICODE build of this plugin.", szPluginName, MB_OK);
+
+ return -1;
+ }
+ else {
+ MessageBoxA(NULL, "You are running the UNICODE version Miranda. It's recommened to use the UNICODE build of this plugin.", szPluginName, MB_OK);
+ DBWriteContactSettingByte(NULL, szModule, SETTING_NOENCODINGCHECK, 1);
+
+ return 0;
+ }
+ }
+#endif
+ }
+#endif
+
+ return 0;
+}
\ No newline at end of file diff --git a/plugins/helpers/gen_helpers.h b/plugins/helpers/gen_helpers.h new file mode 100644 index 0000000000..8f4d91b940 --- /dev/null +++ b/plugins/helpers/gen_helpers.h @@ -0,0 +1,125 @@ +/*
+ Helper functions for Miranda-IM (www.miranda-im.org)
+ Copyright 2006 P. Boon
+
+ 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
+*/
+#ifndef __GEN_HELPERS_H
+#define __GEN_HELPERS_H
+
+int ProtoServiceExists(const char *szModule, const char *szService);
+char *Hlp_GetProtocolNameA(const char *proto);
+TCHAR *Hlp_GetProtocolName(const char *proto);
+
+char *Hlp_GetDlgItemTextA(HWND hwndDlg, int nIDDlgItem);
+TCHAR *Hlp_GetDlgItemText(HWND hwndDlg, int nIDDlgItem);
+char *Hlp_GetWindowTextA(HWND hwndDlg);
+TCHAR *Hlp_GetWindowText(HWND hwndDlg);
+
+char* u2a( wchar_t* src );
+wchar_t* a2u( char* src );
+int ttoi(TCHAR *string);
+TCHAR *itot(int num);
+
+char* Utf8EncodeUcs2( const wchar_t* src );
+char* Utf8Encode( const char* src );
+void Utf8Decode( char* str, wchar_t** ucs2 );
+
+#define MAX_DEBUG 1024
+
+#define __LOGLEVEL_DEBUG 10
+#define __LOGLEVEL_INFO 9
+#define __LOGLEVEL_WARN 8
+#define __LOGLEVEL_ERROR 7
+#define __LOGLEVEL_FATAL 6
+
+#ifndef LOGLEVEL
+ #ifdef _DEBUG
+ #define LOGLEVEL __LOGLEVEL_DEBUG
+ #else
+ #define LOGLEVEL __LOGLEVEL_INFO
+ #endif
+#endif
+
+int AddDebugLogMessageA(const char* fmt, ...);
+int AddDebugLogMessage(const TCHAR* fmt, ...);
+int AddErrorLogMessageA(const char* fmt, ...);
+int AddErrorLogMessage(const TCHAR* fmt, ...);
+
+#if LOGLEVEL >= __LOGLEVEL_DEBUG
+#define log_debugA AddDebugLogMessageA
+#define log_debug AddDebugLogMessage
+#else
+static __inline int log_debugA(const char* fmt, ...) { return 0; }
+static __inline int log_debug(const TCHAR* fmt, ...) { return 0; }
+#endif
+
+#if LOGLEVEL >= __LOGLEVEL_INFO
+#define log_infoA AddDebugLogMessageA
+#define log_info AddDebugLogMessage
+#else
+static __inline int log_infoA(const char* fmt, ...) { return 0; }
+static __inline int log_info(const TCHAR* fmt, ...) { return 0; }
+#endif
+
+#if LOGLEVEL >= __LOGLEVEL_WARN
+#define log_warnA AddDebugLogMessageA
+#define log_warn AddDebugLogMessage
+#else
+static __inline int log_warnA(const char* fmt, ...) { return 0; }
+static __inline int log_warn(const TCHAR* fmt, ...) { return 0; }
+#endif
+
+#if LOGLEVEL >= __LOGLEVEL_ERROR
+#define log_errorA AddErrorLogMessageA
+#define log_error AddErrorLogMessage
+#else
+static __inline int log_errorA(const char* fmt, ...) { return 0; }
+static __inline int log_error(const TCHAR* fmt, ...) { return 0; }
+#endif
+
+#if LOGLEVEL >= __LOGLEVEL_FATAL
+#define log_fatalA AddErrorLogMessageA
+#define log_fatal AddErrorMessage
+#else
+static __inline int log_fatalA(const char* fmt, ...) { return 0; }
+static __inline int log_fatal(const TCHAR* fmt, ...) { return 0; }
+#endif
+
+int Hlp_UnicodeCheck(char *szPluginName, BOOL bFore, const char *szModule);
+#define UnicodeCheck(x, y) Hlp_UnicodeCheck(x, y, MODULENAME)
+
+static __inline char *variables_parsedupA(char *szFormat, char *szExtraText, HANDLE hContact) {
+
+ if (ServiceExists(MS_VARS_FORMATSTRING)) {
+ FORMATINFO fi;
+ char *szParsed, *szResult;
+
+ ZeroMemory(&fi, sizeof(fi));
+ fi.cbSize = sizeof(fi);
+ fi.szFormat = szFormat;
+ fi.szExtraText = szExtraText;
+ fi.hContact = hContact;
+ szParsed = (char *)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0);
+ if (szParsed) {
+ szResult = _strdup(szParsed);
+ CallService(MS_VARS_FREEMEMORY, (WPARAM)szParsed, 0);
+ return szResult;
+ }
+ }
+ return szFormat?_strdup(szFormat):szFormat;
+}
+
+#endif
diff --git a/plugins/helpers/stshelpers.cpp b/plugins/helpers/stshelpers.cpp new file mode 100644 index 0000000000..abea62b3ba --- /dev/null +++ b/plugins/helpers/stshelpers.cpp @@ -0,0 +1,303 @@ +#include "commonheaders.h"
+#include "gen_helpers.h"
+#include <m_statusplugins.h>
+#include "stshelpers.h"
+
+static struct ProtoInfo {
+ const char *szProto;
+ UINT idEvent;
+};
+
+// note: accesses to pi are not synchronized... 'cause I'm a lazy SOB (and it's not necessary ATM)
+static struct ProtoInfo *pi = NULL;
+static int piCount = 0;
+static UINT g_idEvent = 0;
+static HWND hMessageWindow = NULL;
+static HANDLE hProtoAckHook = NULL;
+
+static VOID CALLBACK EnableProtoTimer(HWND hwnd, UINT message, UINT idEvent, DWORD dwTime) {
+
+ int i;
+
+ KillTimer(hwnd, idEvent);
+ log_debugA("EnableProtoTimer");
+ for (i=0;i<piCount;i++) {
+ if (pi[i].idEvent == idEvent) {
+ log_debugA("cleaning timer %d (%d) for %s (%x) (%d) (%d events left)", i, idEvent, pi[i].szProto, pi[i].szProto, pi[i].idEvent, piCount);
+ if (i < piCount-1) {
+ log_debugA("(1) pi[%d] (%s %x) pi[%d] (%s %x )", i, pi[i].szProto, pi[i].szProto, i+1, pi[i+1].szProto, pi[i+1].szProto);
+ MoveMemory(&pi[i], &pi[i+1], (piCount-i-1)*sizeof(struct ProtoInfo));
+ log_debugA("(2) pi[%d] (%s %x) pi[%d] (%s %x )", i, pi[i].szProto, pi[i].szProto, i+1, pi[i+1].szProto, pi[i+1].szProto);
+ }
+ if (piCount > 1) {
+ pi = realloc(pi, (piCount-1)*sizeof(struct ProtoInfo));
+ }
+ else {
+ free(pi);
+ pi = NULL;
+ log_debugA("(3) pi freed");
+ }
+ piCount -= 1;
+ }
+ }
+}
+
+static int ProtoAck(WPARAM wParam, LPARAM lParam) {
+
+ int status;
+ ACKDATA *ack;
+
+ ack = (ACKDATA*)lParam;
+ if (ack->type != ACKTYPE_STATUS) return 0;
+ if (ack->result != ACKRESULT_SUCCESS) return 0;
+ log_debugA("StatusHandling ProtoAck");
+ status = CallProtoService(ack->szModule, PS_GETSTATUS, 0, 0);
+ log_debugA("StatusHandling ProtoAck status=%d", status);
+ if ( (status < MIN_STATUS) || (status > MAX_STATUS) ) {
+ return 0;
+ }
+ pi = realloc(pi, (piCount+1)*sizeof(struct ProtoInfo));
+ g_idEvent += 1;
+ pi[piCount].idEvent = g_idEvent;
+ pi[piCount].szProto = ack->szModule;
+ piCount += 1;
+ log_debugA("added timer %d for pi[%d] %s (%x)", pi[piCount-1].idEvent, piCount-1, ack->szModule, ack->szModule);
+ SetTimer(hMessageWindow, g_idEvent, CONNECTIONTIMEOUT, EnableProtoTimer);
+
+ return 0;
+}
+
+int InitProtoStatusChangedHandling() {
+
+ if (hMessageWindow == NULL) {
+ int i, count;
+ PROTOCOLDESCRIPTOR **protos;
+
+ CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&count, (LPARAM)&protos);
+ for(i=0;i<count;i++) {
+ if (protos[i]->type!=PROTOTYPE_PROTOCOL || CallProtoService(protos[i]->szName,PS_GETCAPS,PFLAGNUM_2,0)==0) continue;
+ //pi = realloc(pi, (piCount + 1)*sizeof(struct ProtoInfo));
+ //ZeroMemory(&pi[piCount], sizeof(struct ProtoInfo));
+ //pi[piCount].szProto = protos[i].szName;
+ log_debugA("InitProtoStatusChangedHandling: %s added", protos[i]->szName);
+ }
+ hMessageWindow = CreateWindowExA(0, "STATIC", NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
+ hProtoAckHook = HookEvent(ME_PROTO_ACK, ProtoAck);
+
+ return 0;
+ }
+
+ return 1;
+}
+
+int ProtoChangedStatus(char *szProto) {
+
+ int i;
+
+ log_debugA("ProtoChangedStatus %s", szProto);
+ if (szProto != NULL) {
+ for (i=0;i<piCount;i++) {
+ if ( (pi[i].szProto != NULL) && (szProto != NULL) && (!strcmp(pi[i].szProto, szProto)) ) {
+ log_debugA("%s just changed status", szProto);
+
+ return TRUE;
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+int Flag2Status(unsigned long flag) {
+
+ switch(flag) {
+ case PF2_ONLINE: return ID_STATUS_ONLINE;
+ case PF2_OFFLINE:
+ case 0: return ID_STATUS_OFFLINE;
+ case PF2_INVISIBLE: return ID_STATUS_INVISIBLE;
+ case PF2_OUTTOLUNCH: return ID_STATUS_OUTTOLUNCH;
+ case PF2_ONTHEPHONE: return ID_STATUS_ONTHEPHONE;
+ case PF2_SHORTAWAY: return ID_STATUS_AWAY;
+ case PF2_LONGAWAY: return ID_STATUS_NA;
+ case PF2_LIGHTDND: return ID_STATUS_OCCUPIED;
+ case PF2_HEAVYDND: return ID_STATUS_DND;
+ case PF2_FREECHAT: return ID_STATUS_FREECHAT;
+ case PF2_IDLE: return ID_STATUS_IDLE;
+ case PF2_CURRENT: return ID_STATUS_CURRENT;
+ case PF2_FROMTRIGGER: return ID_STATUS_FROMTRIGGER;
+ }
+ return 0;
+}
+
+unsigned long Status2Flag(int status) {
+
+ switch(status) {
+ case ID_STATUS_ONLINE: return PF2_ONLINE;
+ case ID_STATUS_OFFLINE: return PF2_OFFLINE;
+ case ID_STATUS_INVISIBLE: return PF2_INVISIBLE;
+ case ID_STATUS_OUTTOLUNCH: return PF2_OUTTOLUNCH;
+ case ID_STATUS_ONTHEPHONE: return PF2_ONTHEPHONE;
+ case ID_STATUS_AWAY: return PF2_SHORTAWAY;
+ case ID_STATUS_NA: return PF2_LONGAWAY;
+ case ID_STATUS_OCCUPIED: return PF2_LIGHTDND;
+ case ID_STATUS_DND: return PF2_HEAVYDND;
+ case ID_STATUS_FREECHAT: return PF2_FREECHAT;
+ case ID_STATUS_IDLE: return PF2_IDLE;
+ case ID_STATUS_CURRENT: return PF2_CURRENT;
+ case ID_STATUS_FROMTRIGGER: return PF2_FROMTRIGGER;
+ }
+ return 0;
+}
+
+static int GetActualStatus(SETSTATUSINFO *ssi) {
+
+ if ( (ssi->status == ID_STATUS_CURRENT) || (ssi->flags&SSIF_DONTSETSTATUS) ) {
+ return CallProtoService(ssi->szProto, PS_GETSTATUS, 0, 0);
+ }
+
+ return ssi->status;
+}
+
+static int EqualsGlobalStatus(SETSTATUSINFO *ssi, int count) {
+
+ PROTOCOLDESCRIPTOR **protos;
+ int i, j, protoCount, pstatus, gstatus;
+
+ if ( (count == 1) && (ssi[0].flags&SSIF_USEAWAYSYS) && (ssi[0].szProto == NULL) ) {
+ return ssi[0].status;
+ }
+ pstatus = gstatus = 0;
+ CallService(MS_PROTO_ENUMPROTOCOLS,(WPARAM)&protoCount,(LPARAM)&protos);
+ for (i=0;i<protoCount;i++) {
+ if ( (protos[i]->type != PROTOTYPE_PROTOCOL) || (CallProtoService(ssi[i].szProto, PS_GETCAPS, PFLAGNUM_2, 0) == 0)) continue;
+ pstatus = 0;
+ for (j=0;j<count;j++) {
+ if (!strcmp(protos[i]->szName, ssi[j].szProto)) {
+ if (ssi[j].flags&SSIF_DONTSETSTATUS) {
+ // not all proto's will be set
+ return 0;
+ }
+ if (!(ssi[j].flags&SSIF_USEAWAYSYS)) {
+ // not all proto's handled by awaysys
+ return 0;
+ }
+ pstatus = GetActualStatus(&ssi[j]);
+ }
+ else {
+ // not all proto's will be set
+ return 0;
+ }
+ }
+ if (pstatus == 0) {
+ pstatus = CallProtoService(protos[i]->szName, PS_GETSTATUS, 0, 0);
+ }
+ if (gstatus == 0) {
+ gstatus = pstatus;
+ }
+ if (pstatus != gstatus) {
+ return 0;
+ }
+ }
+
+ return gstatus;
+}
+
+// helper, from core
+static char *GetDefaultMessage(int status)
+{
+ switch(status) {
+ case ID_STATUS_AWAY: return Translate("I've been away since %time%.");
+ case ID_STATUS_NA: return Translate("Give it up, I'm not in!");
+ case ID_STATUS_OCCUPIED: return Translate("Not right now.");
+ case ID_STATUS_DND: return Translate("Give a guy some peace, would ya?");
+ case ID_STATUS_FREECHAT: return Translate("I'm a chatbot!");
+ case ID_STATUS_ONLINE: return Translate("Yep, I'm here.");
+ case ID_STATUS_OFFLINE: return Translate("Nope, not here.");
+ case ID_STATUS_INVISIBLE: return Translate("I'm hiding from the mafia.");
+ case ID_STATUS_ONTHEPHONE: return Translate("That'll be the phone.");
+ case ID_STATUS_OUTTOLUNCH: return Translate("Mmm...food.");
+ case ID_STATUS_IDLE: return Translate("idleeeeeeee");
+ }
+ return NULL;
+}
+
+static char *GetDefaultStatusMessage(int newstatus) {
+
+ char *sMsg, *tMsg;
+
+ sMsg = NULL;
+ if (ServiceExists(MS_AWAYMSG_GETSTATUSMSG)) {
+ tMsg = (char*)CallService(MS_AWAYMSG_GETSTATUSMSG, (WPARAM)newstatus, 0);
+ if (tMsg != NULL) {
+ sMsg = _strdup(tMsg);
+ mir_free(tMsg);
+ }
+ }
+ else {
+ tMsg = GetDefaultMessage(newstatus); /* awaysys doesn't define the service above */
+ if (tMsg != NULL) {
+ sMsg = _strdup(tMsg);
+ }
+ }
+
+ return sMsg;
+}
+
+int Hlp_SetStatus(SETSTATUSINFO *ssi, int count) {
+
+ int i, status;
+ char *szMsg;
+
+ status = EqualsGlobalStatus(ssi, count);
+ if (status != 0) {
+ log_debugA("Hlp_SetStatus: Setting global status");
+ CallService(MS_CLIST_SETSTATUSMODE, (WPARAM)status, 0);
+ return 0;
+ }
+ for (i=0;i<count;i++) {
+ if (!CallService(MS_PROTO_ISPROTOCOLLOADED, 0, (LPARAM)ssi[i].szProto)) {
+ log_debugA("Hlp_SetStatus: %s not loaded", ssi[i].szProto);
+ continue;
+ }
+ status = GetActualStatus(&ssi[i]);
+ if (!(ssi[i].flags&SSIF_DONTSETSTATUS)) {
+ if (ServiceExists(MS_KS_ANNOUNCESTATUSCHANGE)) {
+ log_debugA("Hlp_SetStatus: Announcing status change to KeepStatus");
+ announce_status_change(ssi[i].szProto, status, ssi[i].flags&SSIF_DONTSETMESSAGE?NULL:ssi[i].szMsg);
+ }
+ log_debugA("Hlp_SetStatus: Setting status %d for %s", status, ssi[i].szProto);
+ CallProtoService(ssi[i].szProto, PS_SETSTATUS, (WPARAM)status, 0);
+ }
+ if (!(ssi[i].flags&SSIF_DONTSETMESSAGE)) {
+ if (ssi[i].flags&SSIF_USEAWAYSYS) {
+ szMsg = GetDefaultStatusMessage(status);
+ }
+ else {
+ if (ssi[i].szMsg != NULL) {
+ szMsg = _strdup(ssi[i].szMsg);
+ }
+ else {
+ szMsg = NULL;
+ }
+ }
+ log_debugA("Hlp_SetStatus: Setting statusmessage for %d for %s", status, ssi[i].szProto);
+ CallProtoService(ssi[i].szProto, PS_SETAWAYMSG, (WPARAM)status, (LPARAM)szMsg);
+ if (szMsg != NULL) {
+ free(szMsg);
+ }
+ }
+ }
+
+ return 0;
+}
+
+void Hlp_FreeStatusInfo(SETSTATUSINFO *ssi, int count) {
+
+ int i;
+
+ for (i=0;i<count;i++) {
+ if (ssi[i].szMsg != NULL) {
+ free(ssi[i].szMsg);
+ }
+ }
+}
\ No newline at end of file diff --git a/plugins/helpers/stshelpers.h b/plugins/helpers/stshelpers.h new file mode 100644 index 0000000000..f0fbca8fae --- /dev/null +++ b/plugins/helpers/stshelpers.h @@ -0,0 +1,35 @@ +#ifndef __STSHELPERS__
+#define __STSHELPERS__
+#define PF2_FROMTRIGGER 0x00002000
+#define PF2_CURRENT 0x00001000
+#define PF2_OFFLINE 0x00000800
+#define ID_STATUS_CURRENT 41000
+#define ID_STATUS_FROMTRIGGER 41001
+
+#define MIN_STATUS ID_STATUS_OFFLINE
+#define MAX_STATUS ID_STATUS_OUTTOLUNCH
+
+#define SSIF_DONTSETSTATUS 0x01
+#define SSIF_DONTSETMESSAGE 0x02
+#define SSIF_USEAWAYSYS 0x04
+
+typedef struct {
+ char *szProto;
+ int flags;
+ int status;
+ char *szMsg;
+} SETSTATUSINFO;
+
+// find out whether a proto just changed status
+#define CONNECTIONTIMEOUT 6000 // same value as NewStatusNotify
+// call this...
+int InitProtoStatusChangedHandling();
+// ...if you want to use this
+int ProtoChangedStatus(char *szProto);
+
+int Flag2Status(unsigned long flag); // only if flag is only one status
+unsigned long Status2Flag(int status);
+int Hlp_SetStatus(SETSTATUSINFO *ssi, int count);
+void Hlp_FreeStatusInfo(SETSTATUSINFO *ssi, int count);
+
+#endif
diff --git a/plugins/helpers/xmlhelpers.cpp b/plugins/helpers/xmlhelpers.cpp new file mode 100644 index 0000000000..b6d3fa70c8 --- /dev/null +++ b/plugins/helpers/xmlhelpers.cpp @@ -0,0 +1,418 @@ +#include "commonheaders.h"
+#include "gen_helpers.h"
+
+char *XMLEncodeString(TCHAR *tszSrc) {
+
+ int cur, len;
+ TCHAR *tszEsc, *tszRep;
+ char *szRes;
+
+ if (tszSrc == NULL) {
+ return NULL;
+ }
+ tszEsc = _tcsdup(tszSrc);
+ cur = len = 0;
+ while (tszEsc[cur] != _T('\0')) {
+ tszRep = NULL;
+ switch (tszEsc[cur]) {
+ case _T('<'):
+ len = 1;
+ tszRep = _T("<");
+ break;
+ case _T('>'):
+ len = 1;
+ tszRep = _T(">");
+ break;
+ case _T('&'):
+ len = 1;
+ tszRep = _T("&");
+ break;
+ case _T('\''):
+ len = 1;
+ tszRep = _T("'");
+ break;
+ case _T('"'):
+ len = 1;
+ tszRep = _T(""");
+ break;
+ case _T('\r'):
+ if (tszEsc[cur+1] == _T('\n')) {
+ len = 2;
+ tszRep = _T("
");
+ }
+ break;
+ case _T('\n'):
+ len = 1;
+ tszRep = _T("
");
+ break;
+ }
+ // tszRep > len !!!
+ if (tszRep != NULL) {
+ tszEsc = realloc(tszEsc, (_tcslen(tszEsc) + _tcslen(tszRep) - len + 1)*sizeof(TCHAR));
+ MoveMemory(&tszEsc[cur+_tcslen(tszRep) - len], &tszEsc[cur], _tcslen(&tszEsc[cur]) + 1);
+ CopyMemory(&tszEsc[cur], tszRep, _tcslen(tszRep)*sizeof(TCHAR));
+ cur += _tcslen(tszRep);
+ }
+ else {
+ cur++;
+ }
+ }
+#ifdef UNICODE
+ szRes = Utf8EncodeUcs2(tszEsc);
+#else
+ szRes = Utf8Encode(tszEsc);
+#endif
+ free(tszEsc);
+
+ return szRes;
+}
+
+char *XMLEncodeStringA(char *szSrc) {
+
+ int cur, len;
+ char *szEsc, *szRep;
+
+ if (szSrc == NULL) {
+ return NULL;
+ }
+ szEsc = _strdup(szSrc);
+ cur = len = 0;
+ while (szEsc[cur] != '\0') {
+ szRep = NULL;
+ switch (szEsc[cur]) {
+ case '<':
+ len = 1;
+ szRep = "<";
+ break;
+ case '>':
+ len = 1;
+ szRep = ">";
+ break;
+ case '&':
+ len = 1;
+ szRep = "&";
+ break;
+ case '\'':
+ len = 1;
+ szRep = "'";
+ break;
+ case '"':
+ len = 1;
+ szRep = """;
+ break;
+ case '\r':
+ if (szEsc[cur+1] == '\n') {
+ len = 2;
+ szRep = "
";
+ }
+ break;
+ case '\n':
+ len = 1;
+ szRep = "
";
+ break;
+ }
+ if (szRep != NULL) {
+ szEsc = realloc(szEsc, (strlen(szEsc) + strlen(szRep) - len + 1));
+ MoveMemory(&szEsc[cur+strlen(szRep) - len], &szEsc[cur], strlen(&szEsc[cur]) + 1);
+ CopyMemory(&szEsc[cur], szRep, strlen(szRep));
+ cur+=strlen(szRep);
+ }
+ else {
+ cur++;
+ }
+ }
+
+ return szEsc;
+}
+
+TCHAR *DecodeXMLString(char *szSrc) {
+
+ int cur;
+ TCHAR *tszEsc, *tszRep, *tszTrans;
+ char *szEsc;
+#ifdef UNICODE
+ wchar_t *wszEsc;
+#endif
+
+ if (szSrc == NULL) {
+ return NULL;
+ }
+ szEsc = _strdup(szSrc);
+#ifdef UNICODE
+ Utf8Decode(szEsc, &wszEsc);
+ tszEsc = wszEsc;
+ free(szEsc);
+#else
+ Utf8Decode(szEsc, NULL);
+ tszEsc = szEsc;
+#endif
+ cur= 0;
+ while (tszEsc[cur] != _T('\0')) {
+ tszRep = NULL;
+ if (!_tcsncmp(&tszEsc[cur], _T("<"), 4)) {
+ tszRep = _T("<");
+ tszTrans = _T("<");
+ }
+ else if (!_tcsncmp(&tszEsc[cur], _T(">"), 4)) {
+ tszRep = _T(">");
+ tszTrans = _T(">");
+ }
+ else if (!_tcsncmp(&tszEsc[cur], _T("&"), 5)) {
+ tszRep = _T("&");
+ tszTrans = _T("&");
+ }
+ else if (!_tcsncmp(&tszEsc[cur], _T("'"), 6)) {
+ tszRep = _T("'");
+ tszTrans = _T("\'");
+ }
+ else if (!_tcsncmp(&tszEsc[cur], _T("""), 6)) {
+ tszRep = _T(""");
+ tszTrans = _T("&");
+ }
+ else if (!_tcsncmp(&tszEsc[cur], _T("
"), 5)) {
+ tszRep = _T("
");
+ tszTrans = _T("\r\n");
+ }
+ if (tszRep != NULL) {
+ tszEsc = realloc(tszEsc, (_tcslen(tszEsc) - _tcslen(tszRep) + _tcslen(tszTrans) + 1)*sizeof(TCHAR));
+ MoveMemory(&tszEsc[cur+_tcslen(tszTrans)], &tszEsc[cur+_tcslen(tszRep)], _tcslen(&tszEsc[cur+_tcslen(tszRep)]) + 1);
+ CopyMemory(&tszEsc[cur], tszTrans, _tcslen(tszTrans)*sizeof(TCHAR));
+ cur += _tcslen(tszTrans);
+ }
+ else {
+ cur++;
+ }
+ }
+
+ return tszEsc;
+}
+
+char *DecodeXMLStringA(char *szSrc, BOOL bUtfDecode) {
+
+ int cur;
+ char *szEsc, *szRep, *szTrans;
+
+ if (szSrc == NULL) {
+ return NULL;
+ }
+ szEsc = _strdup(szSrc);
+ if (bUtfDecode) {
+ Utf8Decode(szEsc, NULL);
+ }
+ cur= 0;
+ while (szEsc[cur] != '\0') {
+ szRep = NULL;
+ if (!strncmp(&szEsc[cur], "<", 4)) {
+ szRep = "<";
+ szTrans = "<";
+ }
+ else if (!strncmp(&szEsc[cur], ">", 4)) {
+ szRep = ">";
+ szTrans = ">";
+ }
+ else if (!strncmp(&szEsc[cur], "&", 5)) {
+ szRep = "&";
+ szTrans = "&";
+ }
+ else if (!strncmp(&szEsc[cur], "'", 6)) {
+ szRep = "'";
+ szTrans = "'";
+ }
+ else if (!strncmp(&szEsc[cur], """, 6)) {
+ szRep = """;
+ szTrans = "&";
+ }
+ else if (!strncmp(&szEsc[cur], "
", 5)) {
+ szRep = "
";
+ szTrans = "\r\n";
+ }
+ if (szRep != NULL) {
+ szEsc = realloc(szEsc, (strlen(szEsc) - strlen(szRep) + strlen(szTrans) + 1));
+ MoveMemory(&szEsc[cur+strlen(szTrans)], &szEsc[cur+strlen(szRep)], strlen(&szEsc[cur+strlen(szRep)]) + 1);
+ CopyMemory(&szEsc[cur], szTrans, strlen(szTrans));
+ cur += strlen(szTrans);
+ }
+ else {
+ cur++;
+ }
+ }
+
+ return szEsc;
+}
+
+void AppendXMLOpeningTag(char **szBuf, char *szTag, int *depth) {
+
+ char *cur;
+
+ *depth += 1;
+ *szBuf = realloc(*szBuf, strlen(*szBuf) + strlen(szTag) + *depth + 4);
+ cur = *szBuf+strlen(*szBuf);
+ *cur = '\n';
+ if (*depth > 0) {
+ memset(cur+1, ' ', *depth);
+ }
+ *(cur+1+*depth) = '\0';
+ sprintf(*szBuf+strlen(*szBuf), "<%s>", szTag);
+}
+
+void AppendXMLClosingTag(char **szBuf, char *szTag, int *depth) {
+
+ char *cur;
+
+ *depth -= 1;
+ *szBuf = realloc(*szBuf, strlen(*szBuf) + strlen(szTag) + *depth + 5);
+ cur = *szBuf+strlen(*szBuf);
+ *cur = '\n';
+ if (*depth > 0) {
+ memset(cur+1, ' ', *depth);
+ }
+ *(cur+1+*depth) = '\0';
+ sprintf(*szBuf+strlen(*szBuf), "</%s>", szTag);
+}
+
+void AppendXMLTag(char **szBuf, char *szTag, char *szAtts, int *depth) {
+
+ char *cur;
+
+ *depth += 1;
+ if (szAtts != NULL) {
+ *szBuf = realloc(*szBuf, strlen(*szBuf) + strlen(szTag) + strlen(szAtts) + *depth + 6);
+ }
+ else {
+ *szBuf = realloc(*szBuf, strlen(*szBuf) + strlen(szTag) + *depth + 5);
+ }
+ cur = *szBuf+strlen(*szBuf);
+ *cur = '\n';
+ if (*depth > 0) {
+ memset(cur+1, ' ', *depth);
+ }
+ *(cur+1+*depth) = '\0';
+ if (szAtts != NULL) {
+ sprintf(*szBuf+strlen(*szBuf), "<%s %s/>", szTag, szAtts);
+ }
+ else {
+ sprintf(*szBuf+strlen(*szBuf), "<%s/>", szTag);
+ }
+ *depth -= 1;
+}
+
+char *GetSettingType(BYTE type) {
+
+ switch (type) {
+ case DBVT_BYTE:
+ return "BYTE";
+ case DBVT_WORD:
+ return "WORD";
+ case DBVT_DWORD:
+ return "DWORD";
+ case DBVT_ASCIIZ:
+ return "ASCIIZ";
+ case DBVT_BLOB:
+ return "BLOB";
+ case DBVT_UTF8:
+ return "UTF8";
+ case DBVT_WCHAR:
+ return "WCHAR";
+ }
+ return "UNKNOWN";
+}
+
+void AppendXMLTagTString(char **szBuf, char *szTag, TCHAR *tszVal, int *depth) {
+
+ char *szVal, *szAtts, *szType;
+
+ szVal = XMLEncodeString(tszVal);
+#ifdef UNICODE
+ szType = GetSettingType(DBVT_WCHAR);
+#else
+ szType = GetSettingType(DBVT_ASCIIZ);
+#endif
+ szAtts = malloc(strlen(szVal) + strlen(szType) + 17);
+ sprintf(szAtts, "type=\"%s\" value=\"%s\"", szType, szVal);
+ AppendXMLTag(szBuf, szTag, szAtts, depth);
+ free(szAtts);
+ free(szVal);
+}
+
+void AppendXMLTagString(char **szBuf, char *szTag, char *szVal, int *depth) {
+
+ char *szEnc, *szAtts, *szType;
+
+ szEnc = XMLEncodeStringA(szVal);
+ szType = GetSettingType(DBVT_ASCIIZ);
+ szAtts = malloc(strlen(szEnc) + strlen(szType) + 17);
+ sprintf(szAtts, "type=\"%s\" value=\"%s\"", szType, szEnc);
+ AppendXMLTag(szBuf, szTag, szAtts, depth);
+ free(szAtts);
+ free(szEnc);
+}
+
+void AppendXMLTagUtfString(char **szBuf, char *szTag, char *szVal, int *depth) {
+
+ char *szEnc, *szAtts, *szType;
+
+ szEnc = XMLEncodeStringA(szVal);
+ szType = GetSettingType(DBVT_UTF8);
+ szAtts = malloc(strlen(szEnc) + strlen(szType) + 17);
+ sprintf(szAtts, "type=\"%s\" value=\"%s\"", szType, szEnc);
+ AppendXMLTag(szBuf, szTag, szAtts, depth);
+ free(szAtts);
+ free(szEnc);
+}
+
+void AppendXMLTagByte(char **szBuf, char *szTag, BYTE bVal, int *depth) {
+
+ char szVal[64], *szAtts, *szType;
+
+ mir_snprintf(szVal, sizeof(szVal), "0x%x", bVal);
+ szType = GetSettingType(DBVT_BYTE);
+ szAtts = malloc(strlen(szVal) + strlen(szType) + 17);
+ sprintf(szAtts, "type=\"%s\" value=\"%s\"", szType, szVal);
+ AppendXMLTag(szBuf, szTag, szAtts, depth);
+ free(szAtts);
+}
+
+void AppendXMLTagWord(char **szBuf, char *szTag, WORD wVal, int *depth) {
+
+ char szVal[64], *szAtts, *szType;
+
+ mir_snprintf(szVal, sizeof(szVal), "0x%x", wVal);
+ szType = GetSettingType(DBVT_WORD);
+ szAtts = malloc(strlen(szVal) + strlen(szType) + 17);
+ sprintf(szAtts, "type=\"%s\" value=\"%s\"", szType, szVal);
+ AppendXMLTag(szBuf, szTag, szAtts, depth);
+ free(szAtts);
+}
+
+void AppendXMLTagDword(char **szBuf, char *szTag, DWORD dVal, int *depth) {
+
+ char szVal[64], *szAtts, *szType;
+
+ mir_snprintf(szVal, sizeof(szVal), "0x%x", dVal);
+ szType = GetSettingType(DBVT_DWORD);
+ szAtts = malloc(strlen(szVal) + strlen(szType) + 17);
+ sprintf(szAtts, "type=\"%s\" value=\"%s\"", szType, szVal);
+ AppendXMLTag(szBuf, szTag, szAtts, depth);
+ free(szAtts);
+}
+
+void AppendXMLTagBlob(char **szBuf, char *szTag, BYTE *pBlob, int cbBlob, int *depth) {
+
+ int maxLen;
+ char *szType, *szVal, *szAtts;
+ NETLIBBASE64 nlb;
+
+ maxLen = Netlib_GetBase64EncodedBufferSize(cbBlob);
+ szVal = malloc(maxLen + 1);
+ ZeroMemory(&nlb, sizeof(NETLIBBASE64));
+ nlb.cbDecoded = cbBlob;
+ nlb.pbDecoded = pBlob;
+ nlb.cchEncoded = maxLen;
+ nlb.pszEncoded = szVal;
+ CallService(MS_NETLIB_BASE64ENCODE, 0, (LPARAM)&nlb);
+ szType = GetSettingType(DBVT_BLOB);
+ szAtts = malloc(strlen(szVal) + strlen(szType) + 17);
+ sprintf(szAtts, "type=\"%s\" value=\"%s\"", szType, szVal);
+ AppendXMLTag(szBuf, szTag, szAtts, depth);
+ free(szAtts);
+}
diff --git a/plugins/helpers/xmlhelpers.h b/plugins/helpers/xmlhelpers.h new file mode 100644 index 0000000000..dd0cc822a7 --- /dev/null +++ b/plugins/helpers/xmlhelpers.h @@ -0,0 +1,17 @@ +void AppendXMLOpeningTag(char **szBuf, char *szTag, int *depth);
+void AppendXMLClosingTag(char **szBuf, char *szTag, int *depth);
+void AppendXMLTag(char **szBuf, char *szTag, char *szAtts, int *depth);
+
+char *GetSettingType(BYTE type);
+void AppendXMLTagTString(char **szBuf, char *szTag, TCHAR *tszVal, int *depth);
+void AppendXMLTagString(char **szBuf, char *szTag, char *szVal, int *depth);
+void AppendXMLTagUtfString(char **szBuf, char *szTag, char *szVal, int *depth);
+void AppendXMLTagByte(char **szBuf, char *szTag, BYTE bVal, int *depth);
+void AppendXMLTagWord(char **szBuf, char *szTag, WORD wVal, int *depth);
+void AppendXMLTagDword(char **szBuf, char *szTag, DWORD dVal, int *depth);
+void AppendXMLTagBlob(char **szBuf, char *szTag, BYTE *pBlob, int cbBlob, int *depth);
+
+char *XMLEncodeString(TCHAR *szSrc);
+char *XMLEncodeStringA(char *tszSrc);
+TCHAR *DecodeXMLString(char *szSrc);
+char *DecodeXMLStringA(char *szSrc, BOOL bUtfDecode);
|