};
static entity entities_defs_num[ (G_N_ELEMENTS (entities_defs)) ];
+static struct html_tag_def tag_defs_num[ (G_N_ELEMENTS (tag_defs)) ];
static gint
tag_cmp (const void *m1, const void *m2)
return l1 - l2;
}
+static gint
+tag_cmp_id (const void *m1, const void *m2)
+{
+ const struct html_tag_def *p1 = m1;
+ const struct html_tag_def *p2 = m2;
+
+ return p1->id - p2->id;
+}
+
+static gint
+tag_find_id (const void *skey, const void *elt)
+{
+ const struct html_tag *tag = skey;
+ const struct html_tag_def *d = elt;
+
+ return tag->id - d->id;
+}
+
static gint
tag_find (const void *skey, const void *elt)
{
return FALSE;
}
+const gchar*
+rspamd_html_tag_by_id (gint id)
+{
+ struct html_tag tag;
+ struct html_tag_def *found;
+
+ /* Should work as IDs monotonically increase */
+ found = bsearch (&tag, tag_defs_num, G_N_ELEMENTS (tag_defs_num),
+ sizeof (tag_defs_num[0]), tag_find_id);
+
+ if (found) {
+ return found->name;
+ }
+
+ return NULL;
+}
+
/* Decode HTML entitles in text */
guint
rspamd_html_decode_entitles_inplace (gchar *s, guint len)
if (!tags_sorted) {
qsort (tag_defs, G_N_ELEMENTS (
tag_defs), sizeof (struct html_tag_def), tag_cmp);
+ memcpy (tag_defs_num, tag_defs, sizeof (tag_defs));
+ qsort (tag_defs_num, G_N_ELEMENTS (tag_defs_num),
+ sizeof (struct html_tag_def), tag_cmp_id);
tags_sorted = 1;
}
if (!entities_sorted) {