diff options
author | admin@progandy.co.cc <admin@progandy.co.cc@eced67a3-f377-a0ae-92ae-d6de1850b05a> | 2010-09-13 18:11:13 +0000 |
---|---|---|
committer | admin@progandy.co.cc <admin@progandy.co.cc@eced67a3-f377-a0ae-92ae-d6de1850b05a> | 2010-09-13 18:11:13 +0000 |
commit | 376594ac1d65cbb31165f5a74775d624c3fd2981 (patch) | |
tree | b1f9bf2ee2f1a82c5d9378c03cf09f72535c001d /MirOTR | |
parent | 99ef7f1cfcaa4ead4b860faec88754abbe31ebfc (diff) |
- added basic html conversion for receiving (maybe a bit too powerful)
- some bugfixes
git-svn-id: http://mirotr.googlecode.com/svn/trunk@12 eced67a3-f377-a0ae-92ae-d6de1850b05a
Diffstat (limited to 'MirOTR')
-rw-r--r-- | MirOTR/MirOTR.vcproj | 30 | ||||
-rw-r--r-- | MirOTR/dllmain.cpp | 2 | ||||
-rw-r--r-- | MirOTR/entities.cpp | 395 | ||||
-rw-r--r-- | MirOTR/entities.h | 22 | ||||
-rw-r--r-- | MirOTR/otr.cpp | 1 | ||||
-rw-r--r-- | MirOTR/striphtml.cpp | 114 | ||||
-rw-r--r-- | MirOTR/striphtml.h | 11 | ||||
-rw-r--r-- | MirOTR/svcs_proto.cpp | 14 | ||||
-rw-r--r-- | MirOTR/version.h | 8 |
9 files changed, 583 insertions, 14 deletions
diff --git a/MirOTR/MirOTR.vcproj b/MirOTR/MirOTR.vcproj index 11c59a0..a03fe12 100644 --- a/MirOTR/MirOTR.vcproj +++ b/MirOTR/MirOTR.vcproj @@ -42,7 +42,7 @@ Name="VCCLCompilerTool"
AdditionalOptions="/D "_CRT_SECURE_NO_WARNINGS" /D "_CRT_NON_CONFORMING_SWPRINTFS""
Optimization="0"
- AdditionalIncludeDirectories=""$(SolutionDir)\miranda\include";"$(SolutionDir)\libotr-3.2.0\src";"$(SolutionDir)\libgcrypt-1.4.6\src";"$(SolutionDir)\libgpg-error-1.9\src""
+ AdditionalIncludeDirectories=""$(SolutionDir)\miranda\include";"$(SolutionDir)\libotr-3.2.0\src";"$(SolutionDir)\libgcrypt-1.4.6\src";"$(SolutionDir)\libgpg-error-1.9\src";"$(SolutionDir)\ekhtml\include""
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;MIROTR_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@@ -65,7 +65,7 @@ Name="VCLinkerTool"
AdditionalDependencies="libgcrypt.lib libotr.lib Comctl32.lib"
LinkIncremental="2"
- AdditionalLibraryDirectories="..\gpg.vs\bin.vs\libgcrypt\debug\static;..\otr.vs\bin.vs\libotr\debug\static"
+ AdditionalLibraryDirectories="..\gpg.vs\bin.vs\libgcrypt\debug\static;..\otr.vs\bin.vs\libotr\debug\static;"..\ekhtml\vc9\$(PlatformName)\debug""
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
@@ -122,7 +122,7 @@ InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="2"
- AdditionalIncludeDirectories=""$(SolutionDir)\miranda\include";"$(SolutionDir)\libotr-3.2.0\src";"$(SolutionDir)\libgcrypt-1.4.6\src";"$(SolutionDir)\libgpg-error-1.9\src""
+ AdditionalIncludeDirectories=""$(SolutionDir)\miranda\include";"$(SolutionDir)\libotr-3.2.0\src";"$(SolutionDir)\libgcrypt-1.4.6\src";"$(SolutionDir)\libgpg-error-1.9\src";"$(SolutionDir)\ekhtml\include""
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MIROTR_EXPORTS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
@@ -142,9 +142,9 @@ />
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="libgcrypt.lib libotr.lib Comctl32.lib"
+ AdditionalDependencies="libgcrypt.lib libotr.lib Comctl32.lib EkHtml.lib"
LinkIncremental="1"
- AdditionalLibraryDirectories="..\gpg.vs\bin.vs\libgcrypt\release\static;..\otr.vs\bin.vs\libotr\release\static"
+ AdditionalLibraryDirectories="..\gpg.vs\bin.vs\libgcrypt\release\static;..\otr.vs\bin.vs\libotr\release\static;"..\ekhtml\vc9\$(PlatformName)\release""
GenerateDebugInformation="false"
SubSystem="2"
OptimizeReferences="2"
@@ -203,7 +203,7 @@ InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="2"
- AdditionalIncludeDirectories=""$(SolutionDir)\miranda\include";"$(SolutionDir)\libotr-3.2.0\src";"$(SolutionDir)\libgcrypt-1.4.6\src";"$(SolutionDir)\libgpg-error-1.9\src""
+ AdditionalIncludeDirectories=""$(SolutionDir)\miranda\include";"$(SolutionDir)\libotr-3.2.0\src";"$(SolutionDir)\libgcrypt-1.4.6\src";"$(SolutionDir)\libgpg-error-1.9\src";"$(SolutionDir)\ekhtml\include""
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;MIROTR_EXPORTS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
@@ -226,7 +226,7 @@ AdditionalDependencies="libgcrypt.lib libotr.lib Comctl32.lib"
OutputFile="$(OutDir)\$(ProjectName)A.dll"
LinkIncremental="1"
- AdditionalLibraryDirectories="..\gpg.vs\bin.vs\libgcrypt\release\static;..\otr.vs\bin.vs\libotr\release\static"
+ AdditionalLibraryDirectories="..\gpg.vs\bin.vs\libgcrypt\release\static;..\otr.vs\bin.vs\libotr\release\static;"..\ekhtml\vc9\$(PlatformName)\release""
GenerateDebugInformation="false"
SubSystem="2"
OptimizeReferences="2"
@@ -312,6 +312,10 @@ </FileConfiguration>
</File>
<File
+ RelativePath=".\entities.cpp"
+ >
+ </File>
+ <File
RelativePath=".\icons.cpp"
>
</File>
@@ -364,6 +368,10 @@ </FileConfiguration>
</File>
<File
+ RelativePath=".\striphtml.cpp"
+ >
+ </File>
+ <File
RelativePath=".\svcs_menu.cpp"
>
</File>
@@ -398,6 +406,10 @@ >
</File>
<File
+ RelativePath=".\entities.h"
+ >
+ </File>
+ <File
RelativePath=".\icons.h"
>
</File>
@@ -426,6 +438,10 @@ >
</File>
<File
+ RelativePath=".\striphtml.h"
+ >
+ </File>
+ <File
RelativePath=".\svcs_menu.h"
>
</File>
diff --git a/MirOTR/dllmain.cpp b/MirOTR/dllmain.cpp index 0db4cb7..aa02340 100644 --- a/MirOTR/dllmain.cpp +++ b/MirOTR/dllmain.cpp @@ -110,7 +110,7 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) { db_byte_set(0, MODULENAME, "sim_warned", 1);
options.default_policy = OTRL_POLICY_MANUAL_MOD;
SaveOptions();
- MessageBox(0, TranslateT(LANG_OTR_SECUREIM_TITLE), TranslateT(LANG_OTR_SECUREIM_TEXT), 0x30);
+ MessageBox(0, TranslateT(LANG_OTR_SECUREIM_TEXT), TranslateT(LANG_OTR_SECUREIM_TITLE), 0x30);
}
// HookEvent(ME_OPT_INITIALISE, OptInit);
diff --git a/MirOTR/entities.cpp b/MirOTR/entities.cpp new file mode 100644 index 0000000..c757b70 --- /dev/null +++ b/MirOTR/entities.cpp @@ -0,0 +1,395 @@ +// (C) of entities.cpp: Christoph +// http://mercurial.intuxication.org/hg/cstuff/raw-file/tip/entities.c +// http://stackoverflow.com/questions/1082162/how-to-unescape-html-in-c/1082191#1082191 +// modified by ProgAndy + +#include "stdafx.h" +#include "entities.h" + +#include <errno.h> +#include <string.h> +#include <stdlib.h> +using namespace std; + +#define UNICODE_MAX 0x10FFFFul + + +static const char *named_entities[][2] = +{ + { "AElig;", "Æ" }, + { "Aacute;", "Á" }, + { "Acirc;", "Â" }, + { "Agrave;", "À" }, + { "Alpha;", "Α" }, + { "Aring;", "Å" }, + { "Atilde;", "Ã" }, + { "Auml;", "Ä" }, + { "Beta;", "Β" }, + { "Ccedil;", "Ç" }, + { "Chi;", "Χ" }, + { "Dagger;", "‡" }, + { "Delta;", "Δ" }, + { "ETH;", "Ð" }, + { "Eacute;", "É" }, + { "Ecirc;", "Ê" }, + { "Egrave;", "È" }, + { "Epsilon;", "Ε" }, + { "Eta;", "Η" }, + { "Euml;", "Ë" }, + { "Gamma;", "Γ" }, + { "Iacute;", "Í" }, + { "Icirc;", "Î" }, + { "Igrave;", "Ì" }, + { "Iota;", "Ι" }, + { "Iuml;", "Ï" }, + { "Kappa;", "Κ" }, + { "Lambda;", "Λ" }, + { "Mu;", "Μ" }, + { "Ntilde;", "Ñ" }, + { "Nu;", "Ν" }, + { "OElig;", "Œ" }, + { "Oacute;", "Ó" }, + { "Ocirc;", "Ô" }, + { "Ograve;", "Ò" }, + { "Omega;", "Ω" }, + { "Omicron;", "Ο" }, + { "Oslash;", "Ø" }, + { "Otilde;", "Õ" }, + { "Ouml;", "Ö" }, + { "Phi;", "Φ" }, + { "Pi;", "Π" }, + { "Prime;", "″" }, + { "Psi;", "Ψ" }, + { "Rho;", "Ρ" }, + { "Scaron;", "Š" }, + { "Sigma;", "Σ" }, + { "THORN;", "Þ" }, + { "Tau;", "Τ" }, + { "Theta;", "Θ" }, + { "Uacute;", "Ú" }, + { "Ucirc;", "Û" }, + { "Ugrave;", "Ù" }, + { "Upsilon;", "Υ" }, + { "Uuml;", "Ü" }, + { "Xi;", "Ξ" }, + { "Yacute;", "Ý" }, + { "Yuml;", "Ÿ" }, + { "Zeta;", "Ζ" }, + { "aacute;", "á" }, + { "acirc;", "â" }, + { "acute;", "´" }, + { "aelig;", "æ" }, + { "agrave;", "à" }, + { "alefsym;", "ℵ" }, + { "alpha;", "α" }, + { "amp;", "&" }, + { "and;", "∧" }, + { "ang;", "∠" }, + { "apos;", "'" }, + { "aring;", "å" }, + { "asymp;", "≈" }, + { "atilde;", "ã" }, + { "auml;", "ä" }, + { "bdquo;", "„" }, + { "beta;", "β" }, + { "brvbar;", "¦" }, + { "bull;", "•" }, + { "cap;", "∩" }, + { "ccedil;", "ç" }, + { "cedil;", "¸" }, + { "cent;", "¢" }, + { "chi;", "χ" }, + { "circ;", "ˆ" }, + { "clubs;", "♣" }, + { "cong;", "≅" }, + { "copy;", "©" }, + { "crarr;", "↵" }, + { "cup;", "∪" }, + { "curren;", "¤" }, + { "dArr;", "⇓" }, + { "dagger;", "†" }, + { "darr;", "↓" }, + { "deg;", "°" }, + { "delta;", "δ" }, + { "diams;", "♦" }, + { "divide;", "÷" }, + { "eacute;", "é" }, + { "ecirc;", "ê" }, + { "egrave;", "è" }, + { "empty;", "∅" }, + { "emsp;", " " }, + { "ensp;", " " }, + { "epsilon;", "ε" }, + { "equiv;", "≡" }, + { "eta;", "η" }, + { "eth;", "ð" }, + { "euml;", "ë" }, + { "euro;", "€" }, + { "exist;", "∃" }, + { "fnof;", "ƒ" }, + { "forall;", "∀" }, + { "frac12;", "½" }, + { "frac14;", "¼" }, + { "frac34;", "¾" }, + { "frasl;", "⁄" }, + { "gamma;", "γ" }, + { "ge;", "≥" }, + { "gt;", ">" }, + { "hArr;", "⇔" }, + { "harr;", "↔" }, + { "hearts;", "♥" }, + { "hellip;", "…" }, + { "iacute;", "í" }, + { "icirc;", "î" }, + { "iexcl;", "¡" }, + { "igrave;", "ì" }, + { "image;", "ℑ" }, + { "infin;", "∞" }, + { "int;", "∫" }, + { "iota;", "ι" }, + { "iquest;", "¿" }, + { "isin;", "∈" }, + { "iuml;", "ï" }, + { "kappa;", "κ" }, + { "lArr;", "⇐" }, + { "lambda;", "λ" }, + { "lang;", "〈" }, + { "laquo;", "«" }, + { "larr;", "←" }, + { "lceil;", "⌈" }, + { "ldquo;", "“" }, + { "le;", "≤" }, + { "lfloor;", "⌊" }, + { "lowast;", "∗" }, + { "loz;", "◊" }, + { "lrm;", "\xE2\x80\x8E" }, + { "lsaquo;", "‹" }, + { "lsquo;", "‘" }, + { "lt;", "<" }, + { "macr;", "¯" }, + { "mdash;", "—" }, + { "micro;", "µ" }, + { "middot;", "·" }, + { "minus;", "−" }, + { "mu;", "μ" }, + { "nabla;", "∇" }, + { "nbsp;", " " }, + { "ndash;", "–" }, + { "ne;", "≠" }, + { "ni;", "∋" }, + { "not;", "¬" }, + { "notin;", "∉" }, + { "nsub;", "⊄" }, + { "ntilde;", "ñ" }, + { "nu;", "ν" }, + { "oacute;", "ó" }, + { "ocirc;", "ô" }, + { "oelig;", "œ" }, + { "ograve;", "ò" }, + { "oline;", "‾" }, + { "omega;", "ω" }, + { "omicron;", "ο" }, + { "oplus;", "⊕" }, + { "or;", "∨" }, + { "ordf;", "ª" }, + { "ordm;", "º" }, + { "oslash;", "ø" }, + { "otilde;", "õ" }, + { "otimes;", "⊗" }, + { "ouml;", "ö" }, + { "para;", "¶" }, + { "part;", "∂" }, + { "permil;", "‰" }, + { "perp;", "⊥" }, + { "phi;", "φ" }, + { "pi;", "π" }, + { "piv;", "ϖ" }, + { "plusmn;", "±" }, + { "pound;", "£" }, + { "prime;", "′" }, + { "prod;", "∏" }, + { "prop;", "∝" }, + { "psi;", "ψ" }, + { "quot;", "\"" }, + { "rArr;", "⇒" }, + { "radic;", "√" }, + { "rang;", "〉" }, + { "raquo;", "»" }, + { "rarr;", "→" }, + { "rceil;", "⌉" }, + { "rdquo;", "”" }, + { "real;", "ℜ" }, + { "reg;", "®" }, + { "rfloor;", "⌋" }, + { "rho;", "ρ" }, + { "rlm;", "\xE2\x80\x8F" }, + { "rsaquo;", "›" }, + { "rsquo;", "’" }, + { "sbquo;", "‚" }, + { "scaron;", "š" }, + { "sdot;", "⋅" }, + { "sect;", "§" }, + { "shy;", "\xC2\xAD" }, + { "sigma;", "σ" }, + { "sigmaf;", "ς" }, + { "sim;", "∼" }, + { "spades;", "♠" }, + { "sub;", "⊂" }, + { "sube;", "⊆" }, + { "sum;", "∑" }, + { "sup;", "⊃" }, + { "sup1;", "¹" }, + { "sup2;", "²" }, + { "sup3;", "³" }, + { "supe;", "⊇" }, + { "szlig;", "ß" }, + { "tau;", "τ" }, + { "there4;", "∴" }, + { "theta;", "θ" }, + { "thetasym;", "ϑ" }, + { "thinsp;", " " }, + { "thorn;", "þ" }, + { "tilde;", "˜" }, + { "times;", "×" }, + { "trade;", "™" }, + { "uArr;", "⇑" }, + { "uacute;", "ú" }, + { "uarr;", "↑" }, + { "ucirc;", "û" }, + { "ugrave;", "ù" }, + { "uml;", "¨" }, + { "upsih;", "ϒ" }, + { "upsilon;", "υ" }, + { "uuml;", "ü" }, + { "weierp;", "℘" }, + { "xi;", "ξ" }, + { "yacute;", "ý" }, + { "yen;", "¥" }, + { "yuml;", "ÿ" }, + { "zeta;", "ζ" }, + { "zwj;", "\xE2\x80\x8D" }, + { "zwnj;", "\xE2\x80\x8C" } +}; + +static int cmp(const void *key, const void *element) +{ + return strncmp((const char *)key, *(const char **)element, + strlen(*(const char **)element)); +} + +static const char *get_named_entity(const char *name) +{ + const char **entity = (const char **)bsearch(name, named_entities, + sizeof(named_entities) / sizeof(*named_entities), + sizeof(*named_entities), cmp); + + return entity ? entity[1] : NULL; +} + +static size_t putc_utf8(unsigned long cp, char *buffer) +{ + unsigned char *bytes = (unsigned char *)buffer; + + if(cp <= 0x007Ful) + { + bytes[0] = (unsigned char)cp; + return 1; + } + + if(cp <= 0x07FFul) + { + bytes[1] = (unsigned char)((2u << 6) | (cp & 0x3Fu)); + bytes[0] = (unsigned char)((6u << 5) | (cp >> 6)); + return 2; + } + + if(cp <= 0xFFFFul) + { + bytes[2] = (unsigned char)(( 2u << 6) | ( cp & 0x3Fu)); + bytes[1] = (unsigned char)(( 2u << 6) | ((cp >> 6) & 0x3Fu)); + bytes[0] = (unsigned char)((14u << 4) | (cp >> 12)); + return 3; + } + + if(cp <= 0x10FFFFul) + { + bytes[3] = (unsigned char)(( 2u << 6) | ( cp & 0x3Fu)); + bytes[2] = (unsigned char)(( 2u << 6) | ((cp >> 6) & 0x3Fu)); + bytes[1] = (unsigned char)(( 2u << 6) | ((cp >> 12) & 0x3Fu)); + bytes[0] = (unsigned char)((30u << 3) | (cp >> 18)); + return 4; + } + + return 0; +} + +static _Bool parse_entity(const char *current, char **to, + const char **from, size_t len) +{ + const char *end = (const char *)memchr(current, ';', len); + if(!end) return 0; + + if(current[1] == '#') + { + char *tail = NULL; + errno = 0; + + _Bool hex = current[2] == 'x' || current[2] == 'X'; + + unsigned long cp = strtoul( + current + (hex ? 3 : 2), &tail, hex ? 16 : 10); + + if(tail == end && !errno && cp <= UNICODE_MAX) + { + *to += putc_utf8(cp, *to); + *from = end + 1; + + return 1; + } + } + else + { + const char *entity = get_named_entity(¤t[1]); + if(entity) + { + size_t len = strlen(entity); + memcpy(*to, entity, len); + + *to += len; + *from = end + 1; + + return 1; + } + } + + return 0; +} + +size_t decode_html_entities_utf8(char *dest, const char *src, size_t len) +{ + if(!src) src = dest; + + char *to = dest; + const char *from = src; + + const char *current; + while((current = (const char*)memchr(from, '&', len))) + { + memcpy(to, from, (size_t)(current - from)); + to += current - from; + + if(parse_entity(current, &to, &from, len)) + continue; + + from = current; + *to++ = *from++; + } + + size_t remaining = strnlen(from, len); + + memcpy(to, from, remaining); + to += remaining; + + *to = 0; + return (size_t)(to - dest); +} diff --git a/MirOTR/entities.h b/MirOTR/entities.h new file mode 100644 index 0000000..2fb84af --- /dev/null +++ b/MirOTR/entities.h @@ -0,0 +1,22 @@ +// (C) of entities.h: Christoph +// http://mercurial.intuxication.org/hg/cstuff/raw-file/tip/entities.h +// http://stackoverflow.com/questions/1082162/how-to-unescape-html-in-c/1082191#1082191 +// modified by ProgAndy + +#ifndef DECODE_HTML_ENTITIES_UTF8 +#define DECODE_HTML_ENTITIES_UTF8 + +#include <stddef.h> + +extern size_t decode_html_entities_utf8(char *dest, const char *src, size_t len); +/* if `src` is `NULL`, input will be taken from `dest`, decoding + the entities in-place + + otherwise, the output will be placed in `dest`, which should point + to a buffer big enough to hold `strlen(src) + 1` characters, while + `src` remains unchanged + + the function returns the length of the decoded string +*/ + +#endif diff --git a/MirOTR/otr.cpp b/MirOTR/otr.cpp index 485e0f7..98ac2a3 100644 --- a/MirOTR/otr.cpp +++ b/MirOTR/otr.cpp @@ -82,6 +82,7 @@ extern "C" { if(hContact) {
pol = DBGetContactSettingDword(hContact, MODULENAME, "Policy", CONTACT_DEFAULT_POLICY);
if (options.bHaveSecureIM && pol != OTRL_POLICY_MANUAL_MOD && pol != OTRL_POLICY_NEVER && db_byte_get(hContact, "SecureIM" , "StatusID", 0)) {
+ // if SecureIM is not disabled for this contact, MirOTR will be set to manual
db_dword_set(hContact, MODULENAME, "Policy", OTRL_POLICY_MANUAL_MOD);
return OTRL_POLICY_MANUAL_MOD;
}
diff --git a/MirOTR/striphtml.cpp b/MirOTR/striphtml.cpp new file mode 100644 index 0000000..f4eebaf --- /dev/null +++ b/MirOTR/striphtml.cpp @@ -0,0 +1,114 @@ +#include "stdafx.h"
+#include "striphtml.h"
+#include "ekhtml.h"
+#include "entities.h"
+
+void starttag_cb (void *cbdata, ekhtml_string_t *tag, ekhtml_attr_t *attrs) {
+ STRIPHTML_DATA *data = (STRIPHTML_DATA *)cbdata;
+ switch (tag->len) {
+ case 1:
+ switch (*(tag->str)) {
+ case 'a':
+ case 'A':
+ {
+ ekhtml_attr_t *attr = attrs;
+ while (attr) {
+ if (_strnicmp(attr->name.str, "href", attr->name.len)==0) {
+ data->stack.push(strncpy((char*)mir_calloc(attr->val.len+1), attr->val.str, attr->val.len));
+ break;
+ }
+ }
+ }break;
+ case 'i':
+ case 'I':
+ data->buffer.append(" *");
+ break;
+ case 'b':
+ case 'B':
+ data->buffer.append(" _");
+ break;
+ }
+ case 2:
+ if (toupper(tag->str[0]) == 'B' && toupper(tag->str[1]) == 'R')
+ data->buffer.append("\r\n");
+ break;
+ case 3:
+ if (_strnicmp(tag->str, "img", 3) == 0) {
+ ekhtml_attr_t *attr = attrs;
+ data->buffer.append("IMAGE:( ");
+ while (attr) {
+ if (_strnicmp(attr->name.str, "src", attr->name.len)==0) {
+ data->buffer.append(attr->val.str, attr->val.len);
+ break;
+ }
+ }
+ data->buffer.append(" )");
+ }
+ break;
+ }
+}
+
+void endtag_cb (void *cbdata, ekhtml_string_t *tag) {
+ STRIPHTML_DATA *data = (STRIPHTML_DATA *)cbdata;
+ switch (tag->len) {
+ case 1:
+ switch (*(tag->str)) {
+ case 'a':
+ case 'A':
+ data->buffer.append(":( ");
+ data->buffer.append(data->stack.top());
+ mir_free(data->stack.top());
+ data->stack.pop();
+ data->buffer.append(" ) ");
+ break;
+ case 'i':
+ case 'I':
+ data->buffer.append("* ");
+ break;
+ case 'b':
+ case 'B':
+ data->buffer.append("_ ");
+ break;
+ }
+ }
+
+}
+
+void data_cb (void *cbdata, ekhtml_string_t *text) {
+ STRIPHTML_DATA *data = (STRIPHTML_DATA *)cbdata;
+ char* s = (char*) mir_calloc(text->len+1);
+ decode_html_entities_utf8(s, text->str, text->len);
+ data->buffer.append(s);
+ mir_free(s);
+}
+
+char * striphtml(char *html) {
+ STRIPHTML_DATA data;
+ ekhtml_string_t ekstring;
+
+ ekstring.len = strlen(html);
+ ekstring.str = html;
+
+ data.buffer.clear();
+ data.buffer.reserve(ekstring.len);
+
+ ekhtml_parser_t *parser = ekhtml_parser_new(&data);
+ ekhtml_parser_datacb_set(parser, &data_cb);
+ ekhtml_parser_startcb_add(parser, NULL, &starttag_cb);
+ ekhtml_parser_endcb_add(parser, NULL, &endtag_cb);
+
+ ekhtml_parser_feed(parser, &ekstring);
+ ekhtml_parser_flush(parser, 1);
+
+ while (!data.stack.empty()) {
+ mir_free(data.stack.top());
+ data.stack.pop();
+ }
+
+ ekhtml_parser_destroy(parser);
+
+ char *s = mir_strdup(data.buffer.c_str());
+ data.buffer.erase();
+ return s;
+ //ekhtml_parser_create(
+}
diff --git a/MirOTR/striphtml.h b/MirOTR/striphtml.h new file mode 100644 index 0000000..7cffc41 --- /dev/null +++ b/MirOTR/striphtml.h @@ -0,0 +1,11 @@ +#pragma once
+
+#include "stack"
+#include "string"
+
+struct STRIPHTML_DATA {
+ std::stack<char*> stack;
+ std::string buffer;
+};
+
+char * striphtml(char *html);
\ No newline at end of file diff --git a/MirOTR/svcs_proto.cpp b/MirOTR/svcs_proto.cpp index 6e78a23..a679658 100644 --- a/MirOTR/svcs_proto.cpp +++ b/MirOTR/svcs_proto.cpp @@ -1,5 +1,6 @@ #include "stdafx.h"
#include "svcs_proto.h"
+#include "striphtml.h"
//TODO: Social-Millionaire-Dialoge
int SVC_OTRSendMessage(WPARAM wParam,LPARAM lParam){
@@ -319,12 +320,21 @@ int SVC_OTRRecvMessage(WPARAM wParam,LPARAM lParam){ if (context) { TrustLevel level = otr_context_get_trust(context); if (options.prefix_messages && (level == TRUST_PRIVATE || level == TRUST_UNVERIFIED)) { + char* premsg; + if (db_byte_get(ccs->hContact, MODULENAME, "HTMLConv", 0)) { + premsg = striphtml(newmessage); + otrl_message_free(newmessage); + newmessage = premsg; + is_miralloc = true; + } + + DWORD len = (strlen(options.prefix)+strlen(newmessage)+1)*sizeof(char); - char* premsg = (char*)mir_alloc( len ); + premsg = (char*)mir_alloc( len ); memset(premsg, 0, len); strcpy(premsg, options.prefix); strcat(premsg, newmessage); - otrl_message_free(newmessage); + (is_miralloc) ? mir_free(newmessage) : otrl_message_free(newmessage); newmessage = premsg; is_miralloc = true; } diff --git a/MirOTR/version.h b/MirOTR/version.h index d8c314c..936cae7 100644 --- a/MirOTR/version.h +++ b/MirOTR/version.h @@ -3,12 +3,12 @@ /* VERSION DEFINITIONS */
#define VER_MAJOR 0
-#define VER_MINOR 9
-#define VER_RELEASE 4
-#define VER_BUILD 1
+#define VER_MINOR 10
+#define VER_RELEASE 0
+#define VER_BUILD 5
#define __STRINGIZE(x) #x
-#define VER_STRING "0.9.4.1"
+#define VER_STRING "0.10.0.5"
#ifdef _UNICODE #define SHORT_NAME_STRING "Miranda OTR"
|