summaryrefslogtreecommitdiff
path: root/mBot/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'mBot/src/utils')
-rw-r--r--mBot/src/utils/cBase64.cpp204
-rw-r--r--mBot/src/utils/cBase64.h57
-rw-r--r--mBot/src/utils/cUtils.cpp334
-rw-r--r--mBot/src/utils/cUtils.h137
-rw-r--r--mBot/src/utils/cXmldoc.cpp899
-rw-r--r--mBot/src/utils/cXmldoc.h153
-rw-r--r--mBot/src/utils/includes.h33
-rw-r--r--mBot/src/utils/utils.vcproj194
8 files changed, 2011 insertions, 0 deletions
diff --git a/mBot/src/utils/cBase64.cpp b/mBot/src/utils/cBase64.cpp
new file mode 100644
index 0000000..294e68e
--- /dev/null
+++ b/mBot/src/utils/cBase64.cpp
@@ -0,0 +1,204 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+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 "includes.h"
+#include "cBase64.h"
+
+#define BASE64_BM 0x000000FC
+
+static const char* base64_etable;
+static unsigned char base64_dtable[256];
+static bool base64_dtable_ok = false;
+
+cBase64::cBase64()
+{
+ if(base64_dtable_ok == false)
+ {
+ int i = 0;
+ memset(base64_dtable,0xAAAAAAAA,sizeof(base64_dtable));
+ for(const char* c = base64_etable; i<67; i++, c++){
+ base64_dtable[*c] = i;
+ }
+ base64_etable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\0";
+ base64_dtable_ok = true;
+ }
+}
+
+cBase64::~cBase64()
+{
+
+}
+
+inline bool cBase64::IsValidB64(register char c)
+{
+ return (base64_dtable[c] != 0xAA);
+}
+
+int cBase64::EncodeRAW(unsigned char* pszIn, int length)
+{
+ m_data.close();
+
+ if(!m_data.create((length * 3) / 2)){
+ return 0;
+ }
+
+ int tocopy = 0;
+ int encoded = 0;
+
+ while(encoded < length)
+ {
+ QUAD q = {0};
+ tocopy = min(3, length - encoded);
+ q.size = tocopy;
+
+ memcpy(&q, pszIn + encoded, tocopy);
+
+ EncodeQuad(q);
+
+ if(!m_data.write(&q,4)){
+ goto Error;
+ }
+ encoded += tocopy;
+ }
+ m_data.putc(0);
+ return encoded;
+Error:
+ m_data.close();
+ return 0;
+}
+
+int cBase64::Encode(const char* pszData)
+{
+ return this->EncodeRAW((unsigned char*)pszData, strlen(pszData));
+}
+
+int cBase64::Decode(const char* pszIn)
+{
+ int len = strlen(pszIn);
+ int done = 0;
+ unsigned long *quads = (unsigned long*)pszIn;
+
+ if(!len || len % 4)return 0;
+
+ for(const char* c=pszIn;*c;c++){
+ if(!IsValidB64(*c)){
+ return 0;
+ }
+ }
+
+ m_data.close();
+ if(!m_data.create(len / 3 + 5)){
+ return 0;
+ }
+
+ while(done < len)
+ {
+ QUAD q ={0};
+ q.size = 4;
+ q.d.bDword = *quads++;
+
+ DecodeQuad(q);
+ if(!m_data.write(&q.d.bDword,q.size)){
+ goto Error;
+ }
+ done += 4;
+ }
+ m_data.putc(0);
+ return 1;
+Error:
+ m_data.close();
+ return 0;
+}
+
+int cBase64::GetString(char* pszOut)
+{
+ strcpy(pszOut, (const char*)m_data.getdata());
+ return m_data.size();
+}
+
+int cBase64::DecodedMessageSize()
+{
+ return m_data.size();
+}
+
+const char* cBase64::GetBuffer()
+{
+ return (const char*)m_data.getdata();
+}
+
+void cBase64::EncodeQuad(QUAD &quad)
+{
+ QUAD out = {0};
+ unsigned char tmp_2 = 0;
+
+ tmp_2 = ((quad.d.bData[0] & BASE64_BM) >> 2);
+ out.d.bData[0] = base64_etable[tmp_2];
+
+ tmp_2 = ((quad.d.bData[0] & 0x03) << 4) | ((quad.d.bData[1] & 0xF0) >> 4);
+ out.d.bData[1] = base64_etable[tmp_2];
+
+ tmp_2 = ((quad.d.bData[1] & 0x0F) << 2) | ((quad.d.bData[2] & 0xC0) >> 6);
+ out.d.bData[2] = base64_etable[tmp_2];
+
+ out.d.bData[3] = base64_etable[quad.d.bData[2] & 0x3F];
+
+ if(quad.size == 1)
+ {
+ out.d.bData[2] = '=';
+ out.d.bData[3] = '=';
+ }
+ else if(quad.size == 2)
+ out.d.bData[3] = '=';
+
+ out.size = 4;
+ quad = out;
+}
+
+void cBase64::DecodeQuad(QUAD &quad)
+{
+ QUAD out = {0};
+ unsigned char tmp_0 = 0;
+ unsigned char tmp_1 = 0;
+
+ quad.d.bData[0] = base64_dtable[quad.d.bData[0]];
+ quad.d.bData[1] = base64_dtable[quad.d.bData[1]];
+ quad.d.bData[2] = base64_dtable[quad.d.bData[2]];
+ quad.d.bData[3] = base64_dtable[quad.d.bData[3]];
+
+ if(quad.d.bData[2]==0xff && quad.d.bData[3]==0xff)
+ out.size = 1;
+ else if(quad.d.bData[3] == 0xff)
+ out.size = 2;
+ else
+ out.size = 3;
+
+ tmp_0 = (quad.d.bData[0]) << 2;
+ tmp_1 = (quad.d.bData[1] & 0x30) >> 4;
+ out.d.bData[0] = tmp_0 | tmp_1;
+
+ if(out.size>1)
+ out.d.bData[1] = ((quad.d.bData[1] & 0x0f) <<4) | ((quad.d.bData[2] & 0x3C) >> 2);
+
+ if(out.size>2)
+ out.d.bData[2] = ((quad.d.bData[2] & 0x03) << 6) | (quad.d.bData[3] & 0x3f);
+
+ out.d.bData[out.size] = '\0';
+ quad = out;
+}
diff --git a/mBot/src/utils/cBase64.h b/mBot/src/utils/cBase64.h
new file mode 100644
index 0000000..4b5b0de
--- /dev/null
+++ b/mBot/src/utils/cBase64.h
@@ -0,0 +1,57 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+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 __cBASE64_H__
+#define __cBASE64_H__
+
+#include "cUtils.h"
+
+typedef struct tagQuad
+{
+ union{
+ unsigned char bData[4];
+ unsigned long bDword;
+ }d;
+ char null;
+ char size;
+}QUAD;
+
+class cBase64
+{
+
+public:
+ cBase64();
+ ~cBase64();
+
+public:
+ int Encode(const char* pszIn);
+ int EncodeRAW(unsigned char* pszIn, int length);
+ int Decode(const char* pszIn);
+ int DecodedMessageSize();
+ int GetString(char* pszOut);
+ const char* GetBuffer();
+protected:
+ static void EncodeQuad(QUAD &q);
+ static void DecodeQuad(QUAD &q);
+ static bool IsValidB64(register char c);
+public:
+ cutMemf m_data;
+};
+#endif //__BASE64_CODER_PIOPAWLU_H__ \ No newline at end of file
diff --git a/mBot/src/utils/cUtils.cpp b/mBot/src/utils/cUtils.cpp
new file mode 100644
index 0000000..8caf341
--- /dev/null
+++ b/mBot/src/utils/cUtils.cpp
@@ -0,0 +1,334 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+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 "includes.h"
+#include "cUtils.h"
+
+cutMemf::cutMemf(void* data,unsigned long length)
+{
+ m_ptr = (unsigned char*)data;
+ m_end = m_ptr + length;
+ m_data = m_ptr;
+ m_flags = 0;
+ m_maxptr = m_ptr;
+}
+
+cutMemf::cutMemf()
+{
+ m_data = m_ptr = m_end = m_maxptr = 0;
+ m_flags = 0;
+}
+
+cutMemf::~cutMemf()
+{
+ close();
+}
+
+int cutMemf::close()
+{
+ if(m_data && (m_flags & 0x01)){
+ free(m_data);
+ }
+ m_data = NULL;
+ m_end = NULL;
+ m_ptr = NULL;
+ m_maxptr = NULL;
+ m_flags = 0;
+ return 1;
+}
+
+int cutMemf::create(unsigned long len)
+{
+ close();
+ m_data = (unsigned char*)malloc(len);
+ if(!m_data)return 0;
+ m_ptr = m_data;
+ m_end = m_data + len;
+ m_maxptr = m_data;
+ m_flags = 0x01;
+ return 1;
+}
+
+void cutMemf::assign(void* data, unsigned long size)
+{
+ close();
+ m_data = (unsigned char*)data;
+ m_ptr = m_data;
+ m_end = m_data + size;
+ m_maxptr = m_end - 1;
+ m_flags = 0x01;
+}
+
+int cutMemf::load(const char* f,int off)
+{
+ cutDiskf df;
+ long fs;
+
+ close();
+ if(!df.open(f,"rb")){
+ goto Error;
+ }
+ fs = df.size();
+ if(fs <= off){
+ goto Error;
+ }
+ fs -= off;
+ df.setpos(off);
+ if(!create(fs + 1)){
+ goto Error;
+ }
+ if(!df.read(m_data,fs)){
+ goto Error;
+ }
+ df.close();
+ m_maxptr = m_data + fs;
+ m_data[fs] = 0;
+ return 1;
+Error:
+ return 0;
+}
+
+int cutMemf::resize(unsigned long ns)
+{
+ //safe
+ void* tmp = malloc(ns);
+ if(!tmp){
+ return 0;
+ }
+ memcpy(tmp,m_data,m_end - m_data);
+ m_ptr = (unsigned char*)tmp + (m_ptr - m_data);
+ m_maxptr = (unsigned char*)tmp + (m_maxptr - m_data);
+ m_end = (unsigned char*)tmp + ns;
+ free(m_data);
+ m_data = (unsigned char*)tmp;
+ return 1;
+}
+
+int cutMemf::removeblock(unsigned long off, unsigned long length)
+{
+ if (m_data + off + length > m_maxptr){
+ return 0;
+ }
+ memcpy(m_data + off, m_data + off + length, (m_maxptr - m_data) - off - length);
+ m_end -= length;
+ return 1;
+}
+
+int cutMemf::read(void* out,unsigned long n)
+{
+ n = min(m_end - m_ptr,n);
+ if(!n)return 0;
+ memcpy(out,m_ptr,n);
+ m_ptr += n;
+ return n;
+}
+
+int cutMemf::gets(char* out, unsigned long n)
+{
+ int c = 0, l = 0;
+
+ while((c = getc()) > 0x10 && n > 0){
+ *out++ = c;
+ n--;
+ l++;
+ }
+ if(c == '\r'){
+ c = getc();
+ }
+ if(c == '\n'){
+ getc();
+ }
+ out[l] = 0;
+ return l;
+}
+
+int cutMemf::write(void* in,unsigned long n)
+{
+ if(!m_flags){
+ n = min(m_end - m_ptr,n);
+ if(!n){
+ return 0;
+ }
+ }else{
+ if(m_ptr + n > m_end){
+ if(!resize(round((m_end - m_data) + n,2048))){
+ return 0;
+ }
+ }
+ }
+ memcpy(m_ptr,in,n);
+ m_ptr += n;
+ if(m_ptr > m_maxptr){
+ m_maxptr = m_ptr;
+ }
+ return n;
+}
+
+int cutMemf::setpos(unsigned long pos)
+{
+ if(m_data + pos >= m_end)return 0;
+ m_ptr = m_data + pos;
+ return 1;
+}
+
+
+cutDiskf::cutDiskf()
+{
+ m_fp = NULL;
+}
+cutDiskf::~cutDiskf()
+{
+ this->close();
+}
+
+int cutDiskf::open(const char* f,const char* mode)
+{
+ close();
+ return (m_fp = (void*)fopen(f,mode))!= NULL;
+}
+
+int cutDiskf::read(void* out,unsigned long n)
+{
+ return (m_fp)?(fread(out,1,n,(FILE*)m_fp)):0;
+}
+int cutDiskf::write(void* in,unsigned long n)
+{
+ return (m_fp)?(fwrite(in,1,n,(FILE*)m_fp)):0;
+}
+int cutDiskf::size()
+{
+ int tp = tellpos();
+ int fs;
+ fseek((FILE*)m_fp,0,SEEK_END);
+ fs = tellpos();
+ fseek((FILE*)m_fp,tp,SEEK_SET);
+ return fs;
+}
+int cutDiskf::tellpos()
+{
+ return (m_fp)?(ftell((FILE*)m_fp)):0;
+}
+int cutDiskf::setpos(unsigned long pos)
+{
+ return (m_fp)?(!fseek((FILE*)m_fp,pos,SEEK_SET)):0;
+}
+
+int cutDiskf::seek(int pos,int method)
+{
+ return (m_fp)?(!fseek((FILE*)m_fp,pos,method)):0;
+}
+int cutDiskf::close()
+{
+ if(m_fp){
+ return fclose((FILE*)m_fp);
+ }else{
+ return 0;
+ }
+}
+int cutDiskf::getc()
+{
+ return (m_fp)?(fgetc((FILE*)m_fp)):0;
+}
+
+cutDiskf::FTYPE cutDiskf::checkFile(const char* path)
+{
+ _finddata_t fd = {0};
+ intptr_t sh = _findfirst(path, &fd);
+
+ if(sh == -1){
+ return FT_NONE;
+ }else{
+ _findclose(sh);
+ if(fd.attrib & _A_SUBDIR){
+ return FT_DIRECTORY;
+ }else{
+ return FT_FILE;
+ }
+ }
+}
+
+int ut_split(char* str, char chr, char** out, int max)
+{
+ int n = 0;
+ char *lchr = str;
+
+ while(*str && max > 0)
+ {
+ if(*str == chr){
+ *str = 0;
+ out[n++] = lchr;
+ lchr = str + 1;
+ }
+ str++;
+ }
+ return n;
+}
+
+void ut_str_replace(const char* from, const char* to, std::string& src)
+{
+ std::string::size_type loc = 0;
+
+ if(!strcmp(from, to))return;
+
+ while(std::string::npos != (loc = src.find(from, 0)))
+ {
+ src.replace(loc, strlen(from), to);
+ }
+}
+
+bool ut_str_match(const char* tmpl, const char* str)
+{
+ const char* c1 = tmpl;
+ const char* c2 = str;
+ unsigned l1 = strlen(tmpl);
+ unsigned l2 = strlen(str);
+
+ while(*c1 && *c2)
+ {
+ if(*c1 == '?'){
+ c1++;
+ c2++;
+ }else if(*c1 == '*'){
+ c1++;
+ if(*c1 == '\0'){
+ return true;
+ }else if(*c1 == '?'){
+ c2 = c2 + (strlen(c2) - strlen(c1));
+ }else{
+ c2 = strchr(c2,*c1);
+ if(!c2){
+ return false;
+ }
+ }
+ }else{
+ if(*c1 != *c2){
+ return false;
+ }
+ c1++;
+ c2++;
+ }
+ }
+
+ if((!(*c1) || (*c1) == '*') && !(*c2)){
+ return true;
+ }else{
+ return false;
+ }
+} \ No newline at end of file
diff --git a/mBot/src/utils/cUtils.h b/mBot/src/utils/cUtils.h
new file mode 100644
index 0000000..72f2858
--- /dev/null
+++ b/mBot/src/utils/cUtils.h
@@ -0,0 +1,137 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+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 _cUTILS_H__
+#define _cUTILS_H__
+
+#include <winsock2.h>
+#include <string>
+
+#ifndef min
+#define min(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
+
+class cutFile
+{
+#ifdef getc
+#undef getc
+#undef putc
+#endif
+public:
+ virtual int read(void* out,unsigned long n)=0;
+ virtual int write(void* out,unsigned long n)=0;
+ virtual int writestring(const char* str){return write((void*)str, strlen(str));}
+ virtual int size()=0;
+ virtual int tellpos()=0;
+ virtual int setpos(unsigned long pos)=0;
+ virtual int close()=0;
+ virtual int getc()=0;
+ virtual int putc(int c)=0;
+};
+
+class cutSockf : public cutFile
+{
+public:
+ int open(SOCKET s){m_written = 0; m_sock = s; return 1;}
+ int read(void* out,unsigned long n){return recv(m_sock, (char*)out, n, 0);}
+ int write(void* out,unsigned long n){m_written += n; return send(m_sock, (const char*)out, n, 0);}
+ int writestring(const char* str){return write((void*)str, strlen(str));}
+ int size(){return m_written;}
+ int tellpos(){return 0;}
+ int setpos(unsigned long pos){return 0;};
+ int close(){closesocket(m_sock); return 1;}
+ int getc(){int c=0; read(&c,1); return c;}
+ int putc(int c){return write(&c, 1);}
+protected:
+ SOCKET m_sock;
+ int m_written;
+};
+
+class cutDiskf : public cutFile
+{
+public:
+ enum FTYPE{FT_NONE, FT_DIRECTORY, FT_FILE};
+public:
+ cutDiskf();
+ ~cutDiskf();
+public:
+ int open(const char* f,const char* mode);
+ //int open(const wchar_t* f, const wchar_t* mode);
+ int read(void* out,unsigned long n);
+ int write(void* in,unsigned long n);
+ int size();
+ int tellpos();
+ int seek(int pos,int method);
+ int setpos(unsigned long pos);
+ int close();
+ int getc();
+ int putc(int c){return fputc(c, (FILE*)m_fp);}
+ void* getfp(){return m_fp;}
+
+ static FTYPE checkFile(const char* path);
+
+ operator FILE* (){return (FILE*)m_fp;}
+protected:
+ void* m_fp;
+};
+
+class cutMemf : public cutFile
+{
+public:
+ cutMemf();
+ cutMemf(void* data,unsigned long length);
+ ~cutMemf();
+public:
+ int create(unsigned long len);
+ int read(void* out,unsigned long n);
+ int write(void* in,unsigned long n);
+ int size(){return (m_end - m_data);}
+ unsigned long written(){return m_maxptr - m_data;}
+ int tellpos(){return (m_ptr - m_data);}
+ int setpos(unsigned long pos);
+ int getc(){return (m_ptr<m_end)?(*m_ptr++):0;}
+ int gets(char* out, unsigned long n);
+ int putc(int c){ return (m_ptr < m_end)?(*m_ptr++ = c):(0); }
+ void* getdata(){return m_data;}
+ void* leave(){void* tmp = m_data; m_data = m_ptr = m_end = m_maxptr = NULL; return tmp;}
+ void assign(void* data, unsigned long size);
+ int close();
+ int load(const char* f,int off);
+ int removeblock(unsigned long off, unsigned long length);
+protected:
+ int resize(unsigned long ns);
+ inline unsigned long round(unsigned long a,unsigned long b){
+ return (a + ((a%b)?(b-(a%b)):0));
+ }
+public:
+ unsigned char* m_data;
+ unsigned char* m_ptr;
+ unsigned char* m_end;
+ unsigned char* m_maxptr;
+ unsigned long m_flags;
+};
+
+#define mb2u(a) a
+int ut_split(char* str, char chr, char** out, int max = 10);
+void ut_str_replace(const char* from, const char* to, std::string& src);
+bool ut_str_match(const char* tmpl, const char* str);
+
+#endif //_cUTILS_H__ \ No newline at end of file
diff --git a/mBot/src/utils/cXmldoc.cpp b/mBot/src/utils/cXmldoc.cpp
new file mode 100644
index 0000000..808f4a0
--- /dev/null
+++ b/mBot/src/utils/cXmldoc.cpp
@@ -0,0 +1,899 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+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 "includes.h"
+#include "cUtils.h"
+#include "cXmlDoc.h"
+
+/*utils*/
+char* xml_strstrx (const char * str1,const char * str2)
+{
+ char *cp = (char*)str1;
+ char *s1, *s2;
+ long in = 0;
+ char term = '\"';
+
+ if (!*str2)return((char*)str1);
+
+ while(*cp)
+ {
+ if(in && *cp == term)
+ {
+ in = 0;
+ }
+ else
+ {
+ if(*cp == '\'' || *cp == '"')
+ {
+ term = *cp;
+ in = 1;
+ }
+ else
+ {
+ s1 = cp;
+ s2 = (char*) str2;
+
+ while (*s1 && *s2 && !(*s1-*s2))
+ {
+ s1++, s2++;
+ }
+
+ if (!*s2)
+ {
+ return(cp);
+ }
+ }
+ }
+ cp++;
+ }
+ return(NULL);
+}
+
+char* xml_strnws(const char* str)
+{
+ while(*str)
+ {
+ if(*str != ' ' && *str != '\r' && *str != '\n' && *str != '\t')
+ {
+ return (char*)str;
+ }
+ else
+ {
+ str++;
+ }
+ }
+ return (NULL);
+}
+
+char* xml_strrnws(const char* s_str)
+{
+ const char* str = s_str + strlen(s_str) - 1;
+
+ if(*str != ' ' && *str != '\r' && *str != '\n' && *str != '\t')
+ {
+ return (char*)str;
+ }
+
+ while(str != s_str)
+ {
+ if(*str != ' ' && *str != '\r' && *str != '\n' && *str != '\t')
+ {
+ break;
+ }
+ else
+ {
+ str--;
+ }
+ }
+ return (char*)str;
+}
+
+char* xml_strfnalnum(const char* str)
+{
+ if(!str)return NULL;
+
+ if(!isalpha(*str) && *str!='_')return (char*)str;
+
+ str++;
+
+ while(*str)
+ {
+ if(!isalnum(*str) && *str != '_' && *str != '.' && *str != '-' && *str != ':')return (char*)str;
+ str ++;
+ }
+ return (NULL);
+}
+char* xml_strndup(const char* str,unsigned int n)
+{
+ char* tmp = NULL;
+ n = xmlmin(strlen(str),n);
+
+ tmp = (char*)malloc(n + 1);
+ if(tmp)
+ {
+ memcpy(tmp,str,n);
+ tmp[n] = '\0';
+ }
+ return tmp;
+}
+
+char* xml_parsendup(char* str,unsigned int n,long fast)
+{
+ long true_length = 0;
+ char* out = NULL;
+ char* o = NULL;
+ const char* x = 0;
+ char ctmp = str[n];
+ str[n] = '\0';
+
+ if(!fast)//calc the real length
+ {
+ for(const char* c=str;*c;)
+ {
+ const char* x = c + 1;
+
+ if(*c=='&')
+ {
+ for(x=c+1;*x && *x!=';';x++);
+ if(!(*x) || (x - c) < 3){
+ true_length++;
+ c++;
+ continue;
+ }
+ //&amp;&gt;&lt;&nbsp;
+ if(*((DWORD*)c) == 'pma&'){
+ true_length++;
+ c+=5;
+ }else if(*((DWORD*)c) == ';tg&' || *((DWORD*)c) == ';tl&'){
+ true_length++;
+ c+=4;
+ }else if(strcmp(c,"&nbsp;")==0){
+ true_length++;
+ c+=6;
+ }else if(*(c+1)=='#' && (x-c)==4){//&#XX;
+ true_length++;
+ c+=5;
+ }else{
+ true_length++;
+ c++;
+ continue;
+ }
+ }
+ else
+ {
+ c++;
+ true_length++;
+ }
+ }//for
+ true_length++;
+ }else{
+ true_length = strlen(str) + 1;
+ }
+ //now do the encoding
+ o = out = (char*)malloc(true_length);
+ if(!out){
+ str[n] = ctmp;
+ return NULL;
+ }
+
+ for(const char* c=str;*c;)
+ {
+ if(*c=='&')
+ {
+ for(x=c+1;*x && *x!=';';x++);
+ if(!(*x) || (x - c) < 3){
+ *o++ = *c++;
+ continue;
+ }
+ //&amp;&gt;&lt;&nbsp;
+ if(*((DWORD*)c) == 'pma&'){
+ *o++ = '&';
+ c+=5;
+ }else if(*((DWORD*)c) == ';tg&'){
+ *o++ = '>';
+ c+=4;
+ }else if(*((DWORD*)c) == ';tl&'){
+ *o++ = '<';
+ c+=4;
+ }else if(strcmp(c,"&nbsp;")==0){
+ *o++ = ' ';
+ c+=6;
+ }else if(*(c+1)=='#' && (x-c)==4){
+ *o = (char)(strtoul((c+2),NULL,16) & 0xFF);
+ if(!*o)*o='?';
+ o++;
+ c+=5;
+ }else{
+ *o++ = *c++;
+ }
+ }
+ else{
+ *o++ = *c++;
+ }
+ }
+ *o++ = '\0';
+ str[n] = ctmp;
+ return out;
+}
+
+void xml_put_tabs(FILE* out,long level)
+{
+ while(level > 0){
+ fputc('\t',out);
+ level--;
+ }
+}
+
+void xml_write_value(FILE* out,const char* val,long length)
+{
+ if(!length){
+ length = strlen(val);
+ }
+
+ for(int i=0;i<length;i++,val++)
+ {
+ if(*val < 0x20 || *val == '#' || *val=='@' || *val=='%' || *val=='>' || *val=='<' || *val=='&'){
+ fprintf(out,"&#%.2x;",*val);
+ }else{
+ fputc(*val,out);
+ }
+ }
+}
+
+cXmlDoc::cXmlDoc()
+{
+ memset(&m_root,0,sizeof(m_root));
+ m_parse_flags = m_flags = m_level = 0;
+}
+
+cXmlDoc::~cXmlDoc()
+{
+ m_root.Free();
+ m_parse_flags = m_flags = m_level = 0;
+}
+
+long cXmlDoc::ParseProperties(char* start,sXmlNode* node)
+{
+ char* s = start;
+ char* ids = NULL;
+ char* ide = NULL;
+ char* vs = NULL;
+ char* ve = NULL;
+ char et = '\0';
+ sXmlProperty prop;
+
+ while((s = xml_strnws(s)) && *s!='\0' && *s!='/') // id = [',"] .... [',"]
+ {
+ ids = s;
+ if(!isalpha(*s))
+ {
+ return (m_parse_flags & cXmlDoc::PARSE_IGNORE_BAD_PROPERTIES)!=0;
+ }
+ s++;
+ while(isalnum(*s) || *s=='_' || *s=='.' || *s=='-' || *s == ':')
+ {
+ s++;
+ }
+ if(*s == '\0')
+ {
+ return (m_parse_flags & cXmlDoc::PARSE_IGNORE_BAD_PROPERTIES)!=0;
+ }
+ ide = s;
+
+ s = xml_strnws(s);
+ if(!s || *s != '=')
+ {
+ return (m_parse_flags & cXmlDoc::PARSE_IGNORE_BAD_PROPERTIES)!=0;
+ }
+ s++;
+
+ s = xml_strnws(s);
+ if(!s || (*s!='\'' && *s != '\"'))
+ {
+ return (m_parse_flags & cXmlDoc::PARSE_IGNORE_BAD_PROPERTIES)!=0;
+ }
+ et = *s;
+ vs = ++s;
+ ve = strchr(vs,et);
+ if(!ve)
+ {
+ return (m_parse_flags & cXmlDoc::PARSE_IGNORE_BAD_PROPERTIES)!=0;
+ }
+
+ prop.name = xml_strndup(ids,ide - ids);
+ prop.value = xml_parsendup(vs,ve - vs,0);//xml_strndup(vs,ve - vs);
+ if(!AddProperty(&prop,node))return 0;
+ memset(&prop,0,sizeof(prop));
+
+ s = ve + 1;
+ }
+ return 1;
+}
+
+long cXmlDoc::AddProperty(sXmlProperty* prop,sXmlNode* node)
+{
+ sXmlProperty* tmp = (sXmlProperty*)malloc(sizeof(sXmlProperty));
+
+ if(!tmp){
+ return 0;
+ }
+ memcpy(tmp,prop,sizeof(sXmlProperty));
+
+ if(node->f_prop == NULL)
+ {
+ node->f_prop = node->l_prop = tmp;
+ }
+ else
+ {
+ node->l_prop->next = tmp;
+ node->l_prop = tmp;
+ }
+ return 1;
+}
+
+long cXmlDoc::AddBinProperty(sXmlBinProperty* prop,sXmlNode* node)
+{
+ sXmlBinProperty* tmp = (sXmlBinProperty*)malloc(sizeof(sXmlBinProperty));
+ if(!tmp)return 0;
+ memcpy(tmp,prop,sizeof(sXmlBinProperty));
+
+ if(node->f_prop == NULL)
+ {
+ node->f_prop = node->l_prop = tmp;
+ }
+ else
+ {
+ node->l_prop->next = tmp;
+ node->l_prop = tmp;
+ }
+ return 1;
+}
+
+long cXmlDoc::AddNewBinProperty(sXmlNode* node,const char* name,void* value)
+{
+ sXmlBinProperty* tmp = (sXmlBinProperty*)malloc(sizeof(sXmlBinProperty));
+ if(!tmp)return 0;
+
+ tmp->name = _strdup(name);
+ tmp->value = (const char*)value;
+
+ if(node->f_prop == NULL)
+ {
+ node->f_prop = node->l_prop = tmp;
+ }
+ else
+ {
+ node->l_prop->next = tmp;
+ node->l_prop = tmp;
+ }
+ return 1;
+}
+
+long cXmlDoc::SetBinPropertyValue(sXmlNode* node,const char* name,void* value)
+{
+ sXmlProperty* p = node->f_prop;
+ while(p)
+ {
+ if(p->type() == 1 && strcmp(p->name,name)==0){
+ p->value = (const char*)value;
+ return 1;
+ }
+ p = p->next;
+ }
+ return 0;
+}
+
+void* cXmlDoc::GetBinPropertyValue(sXmlNode* node,const char* name,long* success)
+{
+ sXmlProperty* p = node->f_prop;
+ while(p)
+ {
+ if(p->type() == 1 && strcmp(p->name,name)==0){
+ *success = TRUE;
+ return (void*)p->value;
+ }
+ p = p->next;
+ }
+ *success = FALSE;
+ return NULL;
+}
+
+long cXmlDoc::JoinParent(sXmlNode* parent,sXmlNode* tmp)
+{
+ tmp->parent = parent;
+ parent->num_children ++;
+
+ if(parent->value){
+ free((void*)parent->value);
+ parent->value = NULL;
+ }
+ parent->type = NODE_PARENT;
+
+ if(parent->f_child == NULL)
+ {
+ parent->f_child = parent->l_child = tmp;
+ return 1;
+ }
+ else
+ {
+ parent->l_child->next = tmp;
+ parent->l_child = tmp;
+ return 1;
+ }
+}
+char* cXmlDoc::ParseNode(char* start,sXmlNode* parent)
+{
+ char* c = xml_strnws(start);
+ char* t = NULL;
+ char* e = NULL;
+ char* x = NULL;
+ sXmlNode* node = (sXmlNode*)malloc(sizeof(sXmlNode));
+ if(!node)return NULL;
+ memset(node,0,sizeof(sXmlNode));
+
+ //<!-- !--> comment
+ //<? ?>
+ //< ... > v />
+ if(!c || *c != '<')
+ {
+ goto Error;
+ }
+ c++;
+ //node type..
+ if(*c == '!' && strncmp(c,"!--",3)==0)/*comment*/
+ {
+ c += 3;
+ e = strstr(c,"-->");
+ if(!e)
+ {
+ goto Error;
+ }
+ else
+ {
+ if(m_parse_flags & cXmlDoc::PARSE_COMMENTS)
+ {
+ node->type = cXmlDoc::NODE_COMMENT;
+ node->value = xml_strndup(c,e - c);
+ JoinParent(parent,node);
+ }
+ else
+ {
+ free(node);
+ }
+ return e + 3;
+ }
+ }
+ else if(*c == '!')/*special command <! blabla bla >*/
+ {
+ c ++;
+ e = xml_strstrx(c,">");
+ if(!e)
+ {
+ goto Error;
+ }
+
+ if(m_parse_flags & cXmlDoc::PARSE_SPECIAL)
+ {
+ node->type = cXmlDoc::NODE_SPECIAL;
+ node->value = xml_strndup(c,e - c);
+ JoinParent(parent,node);
+ }
+ else
+ {
+ free(node);
+ }
+ return e + 1;
+ }
+ else if(*c == '?')/*<?command ?>*/
+ {
+ c++;
+ e = xml_strstrx(c,"?>");
+ if(!e)
+ {
+ goto Error;
+ }
+ if(m_parse_flags & cXmlDoc::PARSE_COMMANDS)
+ {
+ node->type = cXmlDoc::NODE_COMMAND;
+ node->value = xml_strndup(c,e - c);
+ JoinParent(parent,node);
+ }
+ else
+ {
+ free(node);
+ }
+ return c + 2;
+ }
+ else/*normal node*/
+ {
+ if(!isalnum(*c))
+ {
+ goto Error;//improper.. too bad :-)
+ }
+ t = xml_strfnalnum(c);
+ if(!t || (*t != ' ' && *t != '>' && *t != '/' && !isspace(*t)))
+ {
+ goto Error;
+ }
+
+ node->name = xml_strndup(c,t - c);
+
+ e = xml_strstrx(c,">");
+ if(!e)
+ {
+ goto Error;
+ }
+ *e = '\0';//terminate ;-) cool, isn't it?
+ if(!ParseProperties(t,node))
+ {
+ goto Error;
+ }
+ *e = '>';//
+ x = e + 1;
+
+ if(*(e - 1) == '/')
+ {
+ node->type = cXmlDoc::NODE_DATA;
+ JoinParent(parent,node);
+ return e + 1;/*<item />*/
+ }
+ c = e + 1;
+Next:
+ e = strchr(c,'<');
+ if(!e)
+ {
+ goto Error;//error?
+ }
+ else
+ {
+ //end tag, or child
+ if(*(e + 1) == '/')//end tag.. possibly
+ {
+ if(strncmp(e + 2,node->name,strlen(node->name))!=0)
+ {
+ goto Error; // too bad :-)
+ }
+ c = xml_strnws(e + 2 + strlen(node->name));
+ if(!c || *c != '>')
+ {
+ goto Error;
+ }
+ t = strchr(t,'>');
+ if(!t)
+ {
+ goto Error;
+ }
+ /*append as a child, etc...*/
+
+ if(node->f_child == NULL)//no children.. then data is interesting ;-)
+ {
+ t = xml_strnws(x);
+ if(!t)
+ {
+ goto Error;
+ }
+ *e = '\0'; // '<';
+ x = xml_strrnws(t);
+ if(!x)
+ {
+ goto Error;
+ }
+ x++;
+ node->type = cXmlDoc::NODE_DATA;
+ node->value = xml_parsendup(t,x - t,0);//xml_strndup(t,x - t);
+ }
+ else
+ {
+ node->type = node->type = cXmlDoc::NODE_PARENT;
+ }
+ JoinParent(parent,node);
+ return c + 1;
+ }
+ else
+ {
+ c = ParseNode(e,node);
+ if(!c)
+ {
+ goto Error;
+ }
+ else
+ {
+ goto Next;
+ }
+ }
+ }
+ }
+Error:
+ if(node)
+ {
+ node->Free();
+ free(node);
+ }
+ return NULL;
+}
+
+long cXmlDoc::SaveNode(FILE* f,sXmlNode* node)
+{
+ while(node)
+ {
+ switch(node->type)
+ {
+ case cXmlDoc::NODE_COMMAND:
+ xml_put_tabs(f,m_level);
+ fprintf(f,"<?%s?>\r\n",node->value);
+ break;
+ case cXmlDoc::NODE_SPECIAL:
+ xml_put_tabs(f,m_level);
+ fprintf(f,"<!%s >\r\n",node->value);
+ break;
+ case cXmlDoc::NODE_COMMENT:
+ xml_put_tabs(f,m_level);
+ fprintf(f,"<!--%s-->\r\n",node->value);
+ break;
+ case cXmlDoc::NODE_PARENT:
+ xml_put_tabs(f,m_level);
+
+ if(node->f_prop)
+ {
+ fprintf(f,"<%s",node->name);
+ sXmlProperty* p = node->f_prop;
+ while(p)
+ {
+ fprintf(f," %s=\"%s\"",p->name,p->value);
+ p = p->next;
+ }
+ fprintf(f,">\r\n");
+ }
+ else
+ {
+ fprintf(f,"<%s>\r\n",node->name);
+ }
+
+ m_level ++;
+ SaveNode(f,node->f_child);
+ m_level --;
+ xml_put_tabs(f,m_level);
+ fprintf(f,"</%s>\r\n",node->name);
+ break;
+ case cXmlDoc::NODE_DATA:
+ xml_put_tabs(f,m_level);
+
+ if(node->f_prop)
+ {
+ fprintf(f,"<%s",node->name);
+ sXmlProperty* p = node->f_prop;
+ while(p)
+ {
+ fprintf(f," %s=\"",p->name);
+ xml_write_value(f,p->value,0);
+ fputc('\"',f);
+ p = p->next;
+ }
+ }
+ else
+ {
+ fprintf(f,"<%s",node->name);
+ }
+
+ if(node->value)
+ {
+ fputc('>',f);
+ xml_write_value(f,node->value,0);
+ fprintf(f,"</%s>\r\n",node->name);
+ }
+ else
+ {
+ fprintf(f,"/>\r\n");
+ }
+ break;
+ }
+ node = node->next;
+ }
+ return 1;
+}
+
+long cXmlDoc::SaveToFile(const char* file)
+{
+ FILE* f = fopen(file,"wb");
+ m_level = 0;
+ if(f)
+ {
+ fprintf(f,"<?xml version=\"1.0\" ?>\r\n");
+ SaveNode(f,m_root.f_child);
+ fclose(f);
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+void cXmlDoc::Free()
+{
+ m_root.Free();
+}
+
+const char* cXmlDoc::GetProperty(sXmlNode* node,const char* name)
+{
+ sXmlProperty* prop;
+ if(!node || !name)return NULL;
+
+ prop = node->f_prop;
+ while(prop){
+ if(strcmp(prop->name,name)==0){
+ return (const char*)prop->value;
+ }
+ prop = prop->next;
+ }
+ return NULL;
+}
+
+long cXmlDoc::SetValue(sXmlNode* node,const char* value)
+{
+ if(!node || !node->value || !value)return 0;
+
+ char* tmp = _strdup(value);
+ if(!tmp)return 0;
+ free((void*)node->value);
+ node->value = tmp;
+ return 1;
+}
+
+sXmlNode* cXmlDoc::GetNode(const char* path,sXmlNode* parent)
+{
+ sXmlNode* n = NULL;
+ char* c = NULL;
+ char* sc = (char*)path;
+
+ if(!path || !strlen(path))
+ {
+ return NULL;
+ }
+ if(!parent)
+ {
+ parent = &m_root;
+ }
+Next:
+ c = strchr(sc,'/');
+ if(!c)
+ {
+ c = sc + strlen(sc);
+ }
+ if(c == sc)
+ {
+ return NULL;
+ }
+
+ n = parent->f_child;
+ while(n)
+ {
+ if(n->name && strncmp(n->name,sc,c - sc) == 0)
+ {
+ if(*c == '\0')
+ {
+ return n;
+ }
+ else
+ {
+ sc = c + 1;
+ parent = n;
+ goto Next;
+ }
+ }
+ n = n->next;
+ }
+ return NULL;
+}
+
+sXmlNode* cXmlDoc::AddNewNode(const char* name,const char* value,sXmlNode* parent)
+{
+ sXmlNode* tmp;
+
+ if(!parent){parent = &m_root;}
+
+ if(!parent || !name || !value){
+ return NULL;
+ }
+
+ if((tmp = GetNode(name,parent)) && tmp->value && strcmp(tmp->value,value)==0){
+ return tmp;
+ }else{
+ tmp = NULL;
+ }
+
+ tmp = (sXmlNode*)malloc(sizeof(sXmlNode));
+ if(!tmp){
+ return NULL;
+ }
+ memset(tmp,0,sizeof(sXmlNode));
+
+ tmp->name = _strdup(name);
+ tmp->value = _strdup(value);
+ tmp->parent = parent;
+ tmp->type = NODE_DATA;
+ JoinParent(parent,tmp);
+ return tmp;
+}
+
+long cXmlDoc::ParseString(char* buffer, long flags)
+{
+ char* c = NULL;
+ char* s = NULL;
+ long level = 0;
+
+ m_root.Free();
+
+ /*initializing processor*/
+ s = c = buffer;
+ /*processing*/
+ c = xml_strnws(c);
+ if(!c){
+ goto End;//empty?
+ }
+
+ if(strncmp(c,"<?xml ",6)!=0 && !(flags & cXmlDoc::PARSE_NOT_REQUIRE_DEF))
+ {
+ goto Error;
+ }
+ else
+ {
+ c = xml_strstrx(c,"?>");
+ if(!c)
+ {
+ goto Error;
+ }
+ c += 2;
+ }
+ m_parse_flags = flags;
+GoOn:
+ c = ParseNode(c,&m_root);
+ if(!c)
+ {
+ goto Error;
+ }
+ else if(*c != '\0' && ((m_parse_flags & cXmlDoc::PARSE_MULTIPLE_ROOTS) || m_root.l_child == NULL
+ || (m_root.l_child->type != cXmlDoc::NODE_PARENT && m_root.l_child->type != cXmlDoc::NODE_DATA)))
+ {
+ goto GoOn;
+ }
+
+End:
+ return 1;
+Error:
+ m_root.Free();
+ return 0;
+}
+
+long cXmlDoc::ParseFile(const char* file,long flags)
+{
+ cutMemf mf;
+
+ if(!mf.load(mb2u(file), 0)){
+ return 0;
+ }
+
+ if(ParseString((char*)mf.getdata(),flags)){
+ mf.close();
+ return 1;
+ }else{
+ mf.close();
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/mBot/src/utils/cXmldoc.h b/mBot/src/utils/cXmldoc.h
new file mode 100644
index 0000000..71c2cd0
--- /dev/null
+++ b/mBot/src/utils/cXmldoc.h
@@ -0,0 +1,153 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+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 _XML_DOC_H_
+#define _XML_DOC_H_
+
+#include <memory.h>
+
+/*/////////////////////
+//CXmlDoc::Structures
+/////////////////////*/
+
+#define xmlmin(a,b) (((a) < (b)) ? (a) : (b))
+
+struct sXmlProperty
+{
+ const char* name;
+ const char* value;
+ sXmlProperty* next;
+public:
+ sXmlProperty(){
+ name = value = NULL;
+ next = NULL;
+ }
+ void Free()
+ {
+ if(name){
+ free((void*)name);
+ }
+ if(value){
+ free((void*)value);
+ }
+ }
+ int type(){
+ return 0;
+ }
+};
+
+struct sXmlBinProperty : public sXmlProperty
+{
+public:
+ void Free(){
+ value = NULL;
+ sXmlProperty::Free();
+ }
+ int type(){return 1;}
+};
+
+struct sXmlNode
+{
+ const char* name;
+ const char* value;
+ long type;
+ long num_children;
+ sXmlProperty* f_prop;
+ sXmlProperty* l_prop;
+
+ sXmlNode* parent;
+ sXmlNode* f_child;/*first child*/
+ sXmlNode* l_child;/*last child*/
+ sXmlNode* next;
+public:
+ sXmlNode(){memset(this,0,sizeof(sXmlNode));}
+ void Free()
+ {
+ sXmlNode* f = this->f_child;
+ sXmlProperty* p = this->f_prop;
+ while(f)
+ {
+ sXmlNode* tmp = f->next;
+ f->Free();
+ free((void*)f);
+ f = tmp;
+ }
+ while(p)
+ {
+ sXmlProperty* tmp = p->next;
+ p->Free();
+ free((void*)p);
+ p = tmp;
+ }
+ if(this->name)free((void*)this->name);
+ if(this->value)free((void*)this->value);
+ memset(this,0,sizeof(sXmlNode));
+ }
+};
+
+
+
+
+class cXmlDoc
+{
+public:
+
+ enum {NODE_NONE = 0,NODE_DOC_TYPE,NODE_SPECIAL,NODE_COMMAND,NODE_ROOT,NODE_PARENT,NODE_DATA,NODE_COMMENT};
+
+ const static long PARSE_NOT_REQUIRE_DEF = 0x01;
+ const static long PARSE_COMMENTS = 0x02;
+ const static long PARSE_IGNORE_WHITESPACES = 0x04;
+ const static long PARSE_MULTIPLE_ROOTS = 0x08;
+ const static long PARSE_SPECIAL = 0x10;
+ const static long PARSE_COMMANDS = 0x20;
+ const static long PARSE_IGNORE_BAD_PROPERTIES = 0x40;
+
+public:
+ cXmlDoc();
+ ~cXmlDoc();
+public:
+ long ParseFile(const char* file,long flags);
+ long ParseString(char* string, long flags);
+ long SaveToFile(const char* file);
+ void Free();
+public:
+ const char* GetProperty(sXmlNode* node,const char* name);
+ sXmlNode* GetRootNode(){return &m_root;}
+ sXmlNode* GetNode(const char* path,sXmlNode* parent = NULL);
+ sXmlNode* AddNewNode(const char* name,const char* value,sXmlNode* parent = NULL);
+ long SetValue(sXmlNode* node,const char* value);
+protected:
+ long SaveNode(FILE* f,sXmlNode* node);
+ char* ParseNode(char* start,sXmlNode* parent);
+ long ParseProperties(char* start,sXmlNode* node);
+ long JoinParent(sXmlNode* parent,sXmlNode* child);
+ long AddProperty(sXmlProperty* prop,sXmlNode* node);
+ long AddBinProperty(sXmlBinProperty* prop,sXmlNode* node);
+ long AddNewBinProperty(sXmlNode* node,const char* name,void* value);
+ long SetBinPropertyValue(sXmlNode* node,const char* name,void* value);
+ void* GetBinPropertyValue(sXmlNode* node,const char* name,long* success);
+protected:
+ sXmlNode m_root;
+ long m_flags;
+ long m_parse_flags;
+ long m_level;
+};
+
+#endif //_XML_DOC_H_ \ No newline at end of file
diff --git a/mBot/src/utils/includes.h b/mBot/src/utils/includes.h
new file mode 100644
index 0000000..6555294
--- /dev/null
+++ b/mBot/src/utils/includes.h
@@ -0,0 +1,33 @@
+/*
+
+Miranda Scripting Plugin for Miranda-IM
+Copyright 2004-2006 Piotr Pawluczuk (www.pawluczuk.info)
+
+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 _INCLUDES_H__
+#define _INCLUDES_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+#include <string.h>
+#include <memory.h>
+#include <winsock2.h>
+#include <io.h>
+
+#endif //_INCLUDES_H__ \ No newline at end of file
diff --git a/mBot/src/utils/utils.vcproj b/mBot/src/utils/utils.vcproj
new file mode 100644
index 0000000..2a673db
--- /dev/null
+++ b/mBot/src/utils/utils.vcproj
@@ -0,0 +1,194 @@
+<?xml version="1.0" encoding="windows-1250"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8,00"
+ Name="utils"
+ ProjectGUID="{A45C2C2E-2662-48DE-A18D-5F52C9A86253}"
+ RootNamespace="utils"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="..\..\bin"
+ IntermediateDirectory="..\..\obj\$(TargetName)"
+ ConfigurationType="4"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="false"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="..\..\bin"
+ IntermediateDirectory="..\..\obj\$(TargetName)"
+ ConfigurationType="4"
+ CharacterSet="2"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ WholeProgramOptimization="false"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS"
+ RuntimeLibrary="0"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="false"
+ DebugInformationFormat="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\cBase64.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\cUtils.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\cXmldoc.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\cBase64.h"
+ >
+ </File>
+ <File
+ RelativePath=".\cUtils.h"
+ >
+ </File>
+ <File
+ RelativePath=".\cXmldoc.h"
+ >
+ </File>
+ <File
+ RelativePath=".\includes.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>