[continued from previous message]
+ "Bad magic number (tagfilter_entities_conf)");
+
+ if ((*ptr)->filename) {
+ free((*ptr)->filename);
+ (*ptr)->filename = NULL;
+ }
+
+ if ((*ptr)->root)
+ free_sort_list(& ((*ptr)->root));
+
+ (*ptr)->magic = 0; /* Invalidate */
+ free(*ptr);
+ *ptr = NULL;
+ }
+
+
+ struct name_entity_walk * tagfilter_start_reference(ents)
+ struct tagfilter_entities *ents;
+ {
+ struct name_entity_walk * ret;
+
+ if (TAGFILTER_ENTITIES_magic != ents->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_start_reference",
+ "Bad magic number");
+
+ if (! ents->builtin_generated) {
+ DPRINT(Debug,14,(&Debug,
+ "tagfilter_start_reference: Generating builtin defaults for %s\n",
+ ents->type_tag));
+
+ tagfilter_generate_defaults(ents);
+ }
+
+ ret = ents->ampersand; /* Parsing ampersand */
+ if (ret)
+ inc_name_entity_walk_refcount(ret);
+ else {
+ /* Make dummy if not tree */
+ ret = malloc_name_entity_walk(ents,0x0026 /* & */);
+
+ DPRINT(Debug,14,(&Debug,
+ "tagfilter_start_reference: No root record for %s - generated dummy\n",
+ ents->type_tag));
+ }
+
+ return ret;
+ }
+
+ static struct name_entity_walk * malloc_name_entity_walk(ents,code)
+ struct tagfilter_entities * ents;
+ uint16 code;
+ {
+ struct name_entity_walk * ret;
+
+ if (TAGFILTER_ENTITIES_magic != ents->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_start_reference",
+ "Bad magic number");
+
+ ret = safe_zero_alloc(sizeof(*ret));
+
+ ret->refcount = 1;
+ ret->magic = NAME_ENTITY_WALK_magic;
+ ret->ents = ents;
+
+ ret->code = code;
+ ret->alternatives = NULL;
+ ret->alternatives_count = 0;
+
+ ret->results = NULL;
+ ret->results_count = 0;
+
+ return ret;
+ }
+
+ static void inc_name_entity_walk_refcount(ptr)
+ struct name_entity_walk *ptr;
+ {
+ if (NAME_ENTITY_WALK_magic != ptr->magic)
+ mime_panic(__FILE__,__LINE__,"inc_name_entity_walk_refcount",
+ "Bad magic number");
+
+ ptr->refcount++;
+ }
+
+ void free_name_entity_walk(ptr)
+ struct name_entity_walk **ptr;
+ {
+ if (NAME_ENTITY_WALK_magic != (*ptr)->magic)
+ mime_panic(__FILE__,__LINE__,"free_name_entity_walk",
+ "Bad magic number");
+
+ if ((*ptr)->refcount < 1)
+ mime_panic(__FILE__,__LINE__,"free_name_entity_walk",
+ "Bad refcount");
+
+ (*ptr)->refcount--;
+ if ((*ptr)->refcount > 0) {
+ *ptr = NULL;
+ return;
+ }
+
+ (*ptr)->ents = NULL; /* struct tagfilter_entities is static, not dynamically
+ alloced
+ */
+
+ if ((*ptr)->alternatives) {
+ size_t x;
+
+ /* Remove recursively */
+
+ for (x = 0; x < (*ptr)->alternatives_count; x++) {
+
+ if ((*ptr)->alternatives[x])
+ free_name_entity_walk(& ((*ptr)->alternatives[x]));
+ }
+
+ free((*ptr)->alternatives);
+ (*ptr)->alternatives = NULL;
+ }
+ (*ptr)->alternatives_count = 0;
+
+
+ if ((*ptr)->results) {
+ size_t x;
+
+ for (x = 0; x < (*ptr)->results_count; x++) {
+
+ if ((*ptr)->results[x]) {
+ if (NAME_ENTITY_MATCH_magic != (*ptr)->results[x]->magic)
+ mime_panic(__FILE__,__LINE__,"free_name_entity_walk",
+ "Bad magic number (name_entity_match)");
+
+ if ((*ptr)->results[x]->linked_walk != (*ptr))
+ mime_panic(__FILE__,__LINE__,"free_name_entity_walk",
+ "Bad linked walk (name_entity_match)");
+
+ (*ptr)->results[x]->linked_walk = NULL;
+
+ free_name_entity_match(& ((*ptr)->results[x]));
+ }
+ }
+
+ free((*ptr)->results);
+ (*ptr)->results = NULL;
+ }
+ (*ptr)->results_count = 0;
+
+
+ (*ptr)->magic = 0; /* Invalidate */
+ free (*ptr);
+ *ptr = NULL;
+ }
+
+ /* free'es struct name_entity_walk, if no match */
+ void advance_entity_walk(walk,u)
+ struct name_entity_walk **walk;
+ uint16 u;
+ {
+ struct name_entity_walk * res = NULL;
+
+ if (NAME_ENTITY_WALK_magic != (*walk)->magic)
+ mime_panic(__FILE__,__LINE__,"advance_entity_walk",
+ "Bad magic number");
+
+ res = advance_walk(*walk,u,walk_search,(*walk)->ents);
+
+ free_name_entity_walk(walk);
+
+ *walk = res;
+ }
+
+ static struct name_entity_match * malloc_name_entity_match(entity_value,
+ unicode_value,
+ conf,lineno,
+ ne_match_flags)
+ struct string * entity_value;
+ uint16 unicode_value;
+ struct tagfilter_entities_conf * conf;
+ int lineno;
+ unsigned ne_match_flags;
+ {
+ struct name_entity_match * ret = safe_zero_alloc(sizeof(*ret));
+
+ ret->magic = NAME_ENTITY_MATCH_magic;
+ ret->refcount = 1;
+
+ ret->conf = conf;
+ ret->lineno = lineno;
+
+ if (entity_value)
+ ret->entity_value = dup_string(entity_value);
+ else
+ ret->entity_value = NULL;
+ ret->unicode_value = unicode_value;
+
+ ret->linked_walk = NULL;
+
+ ret->flags = ne_match_flags;
+
+ return ret;
+ }
+
+ /* increment refcount */
+ static struct name_entity_match * tagfilter_match_ref_conf P_((struct name_entity_walk *walk,
+ enum tagfilter_match have_semicolon,
+ struct tagfilter_entities_conf * conf));
+
+ static struct name_entity_match * tagfilter_match_ref_conf(walk,have_semicolon,conf)
+ struct name_entity_walk *walk;
+ enum tagfilter_match have_semicolon;
+ struct tagfilter_entities_conf * conf; /* NULL if builtin */
+ {
+ struct name_entity_match *ret = NULL;
+
+ if (NAME_ENTITY_WALK_magic != walk->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_match_ref_conf",
+ "Bad magic number");
+
+
+ if (walk->results) {
+ size_t i;
+
+ for (i = 0; i < walk->results_count; i++) {
+
+ if (NAME_ENTITY_MATCH_magic != walk->results[i]->magic)
+ mime_panic(__FILE__,__LINE__," tagfilter_match_reference",
+ "Bad magic number (name_entity_match)");
+
+ if (conf != walk->results[i]->conf)
+ continue;
+
+ if (ison(walk->results[i]->flags,ne_match_IGNORE)) {
+ continue;
+ }
+
+ switch (have_semicolon) {
+ case tagfilter_match_prefix:
+ if (isoff(walk->results[i]->flags,ne_match_SEMICOLON)) {
+ ret = walk->results[i];
+ goto found;
+ }
+ break;
+ case tagfilter_match_semicolon:
+ if (ison(walk->results[i]->flags,ne_match_SEMICOLON)) {
+ ret = walk->results[i];
+ goto found;
+ }
+ break;
+ }
+ }
+ }
+
+
+ if (ret) {
+ found:
+ inc_name_entity_match_refcount(ret);
+
+ }
+
+ return ret;
+ }
+
+
+ /* increment refcount */
+ struct name_entity_match * tagfilter_match_reference(walk,have_semicolon)
+ struct name_entity_walk *walk;
+ enum tagfilter_match have_semicolon;
+ {
+ struct name_entity_match *ret = NULL;
+
+ if (NAME_ENTITY_WALK_magic != walk->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_match_reference",
+ "Bad magic number");
+
+ if (!ret && user_tagfilter_entities_conf) {
+ if (TAGFILTER_ENTITIES_CONF_magic != user_tagfilter_entities_conf->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_match_reference",
+ "Bad magic number (user_tagfilter_entities_conf)");
+
+ ret = tagfilter_match_ref_conf(walk, have_semicolon,user_tagfilter_entities_conf);
+
+
+ if (ret) {
+ DPRINT(Debug,14,(&Debug,
+ "tagfilter_match_reference: Found user conf %s match\n",
+ user_tagfilter_entities_conf->filename));
+ }
+ }
+
+ if (!ret && system_tagfilter_entities_conf) {
+ if (TAGFILTER_ENTITIES_CONF_magic != system_tagfilter_entities_conf->magic)
+ mime_panic(__FILE__,__LINE__,"tagfilter_match_reference",
+ "Bad magic number (system_tagfilter_entities_conf)");
+
+ ret = tagfilter_match_ref_conf(walk, have_semicolon,system_tagfilter_entities_conf);
+
+ if (ret) {
+ DPRINT(Debug,14,(&Debug,
+ "tagfilter_match_reference: Found system conf %s match\n",
+ system_tagfilter_entities_conf->filename));
+ }
+ }
+
+ if (!ret) {
+
+ ret = tagfilter_match_ref_conf(walk, have_semicolon,NULL);
+
+ if (ret) {
+ DPRINT(Debug,14,(&Debug,"tagfilter_match_reference: Found builtin match\n"));
+ }
+
+ }
+
+ return ret;
+ }
+
+ static void inc_name_entity_match_refcount(ptr)
+ struct name_entity_match *ptr;
+ {
+ if (NAME_ENTITY_MATCH_magic != ptr->magic)
+ mime_panic(__FILE__,__LINE__,"inc_name_entity_match_refcount",
+ "Bad magic number");
+
+ ptr->refcount++;
+ }
+
+ void free_name_entity_match(ptr)
+ struct name_entity_match **ptr;
+ {
+ if (NAME_ENTITY_MATCH_magic != (*ptr)->magic)
+ mime_panic(__FILE__,__LINE__,"free_name_entity_match",
+ "Bad magic number");
+
+ if ((*ptr)->refcount < 1)
+ mime_panic(__FILE__,__LINE__,"free_name_entity_match",
+ "Bad refcount");
+
+ (*ptr)->refcount--;
+
+ if ((*ptr)->refcount > 0) {
+ *ptr = NULL;
+ return;
+ }
+
+ if ((*ptr)->conf) {
+ mime_panic(__FILE__,__LINE__,"free_name_entity_match",
+ "Backlink (conf) not cleared");
+ }
+
+ if ((*ptr)->linked_walk) {
+ mime_panic(__FILE__,__LINE__,"free_name_entity_match",
+ "Backlink (linked_walk) not cleared");
+ }
+
+ if (ison((*ptr)->flags,ne_match_STATIC)) {
+ /* Not malloced */
+
+ *ptr = NULL;
+ return;
+ }
+
+ if ((*ptr)->entity_value)
+ free_string(& ((*ptr)->entity_value));
+
+ (*ptr)->unicode_value = 0;
+ (*ptr)->flags = 0;
+
+ (*ptr)->magic = 0; /* Invalidate */
+ free(*ptr);
+ *ptr = NULL;
+ }
+
+ struct out_entity * out_entity_from_match(reference_key,
+ match,
+ reference_key_pg_flags)
+ struct string * reference_key;
+ struct name_entity_match * match;
+ int reference_key_pg_flags;
+ {
+ if (NAME_ENTITY_MATCH_magic != match->magic)
+ mime_panic(__FILE__,__LINE__,"out_entity_from_match",
+ "Bad magic number (name_entity_match)");
+
+ DPRINT(Debug,22,(&Debug,
+ "out_entity_from_match: reference_key=%S",
+ reference_key));
+ if (match->entity_value) {
+ DPRINT(Debug,22,(&Debug,", entity_value %S",
+ match->entity_value));
+ }
+ DPRINT(Debug,22,(&Debug,", unicode value x%04x",
+ match->unicode_value));
+ switch(match->unicode_value) {
+ case UNICODE_NO_BREAK_SPACE: DPRINT(Debug,22,(&Debug,
+ " UNICODE_NO_BREAK_SPACE")); + break;
+ case UNICODE_SOFT_HYPHEN: DPRINT(Debug,22,(&Debug,
+ " UNICODE_SOFT_HYPHEN"));
+ break;
+ case UNICODE_BAD_CHAR: DPRINT(Debug,22,(&Debug,
+ " UNICODE_BAD_CHAR"));
+ break;
+ }
+ DPRINT(Debug,22,(&Debug,"\n"));
+
+ return new_out_entity(reference_key,
+ match->entity_value,
+ match->unicode_value,
+ reference_key_pg_flags);
+ }
+
+
+
+ /*
+ * Local Variables:
+ * mode:c
+ * c-basic-offset:4
+ * buffer-file-coding-system: iso-8859-1
+ * End:
+ */
+
Index: elmME+.2.5.alpha63-cvs/melib/tagfilter_html.c
*** /tmp/2707-very-long-file-name/NULL-2707-comes-in-here--XXXXXXXXX Mon Jan 1 21:13:30 2024
--- elmME+.2.5.alpha63-cvs/melib/tagfilter_html.c Wed Dec 13 18:55:32 2023
***************
*** 0 ****
--- 1,3109 ----
+ static char rcsid[] = "@(#)$Id: tagfilter_html.c,v 2.1 2023/12/13 16:55:32 hurtta Exp $";
+
+ /************************************************************************
+ * The Elm (ME+) Mail System - $Revision: 2.1 $ $State: Exp $
+ *
+ * Author: Kari Hurtta <
hurtta+elm@siilo.FMI.FI>
+ * or Kari Hurtta <
elm@elmme-mailer.org>
+ ************************************************************************/
+
+ #include "def_melib.h"
+ #include "tagfilter_imp.h"
+
+ DEBUG_VAR(Debug,__FILE__,"mime");
+
+ #if ANSI_C
+ #define E_(x) extern x;
+ #else
+ #define E_(x)
+ #endif
+
+ /* The Html Command */
+
+ static struct TAGFILTER_CMD html_start_tag =
+ { TAGFILTER_CMD_magic, 1, "html", 0, baseC(tfc_none), &text_html_head_body,
+ TAGFLT_CMD_is_static|
+ TAGFLT_CMD_nested_search| /* Opening tag is optional */
+ TAGFLT_CMD_hide_text,