+static void setup_typed_match(TypedMatch *tm, xmlNodePtr n)
+{
+ gchar *s, *type = NULL;
+ if ((s = obt_xml_node_string(n))) {
+ if (!obt_xml_attr_string(n, "type", &type) ||
+ !g_ascii_strcasecmp(type, "pattern"))
+ {
+ tm->type = MATCH_TYPE_PATTERN;
+ tm->m.pattern = g_pattern_spec_new(s);
+ } else if (type && !g_ascii_strcasecmp(type, "regex")) {
+ tm->type = MATCH_TYPE_REGEX;
+ tm->m.regex = g_regex_new(s, 0, 0, NULL);
+ } else if (type && !g_ascii_strcasecmp(type, "exact")) {
+ tm->type = MATCH_TYPE_EXACT;
+ tm->m.exact = g_strdup(s);
+ }
+ g_free(s);
+ }
+}
+
+static void free_typed_match(TypedMatch *tm)
+{
+ switch (tm->type) {
+ case MATCH_TYPE_PATTERN:
+ g_pattern_spec_free(tm->m.pattern);
+ break;
+ case MATCH_TYPE_REGEX:
+ g_regex_unref(tm->m.regex);
+ break;
+ case MATCH_TYPE_EXACT:
+ g_free(tm->m.exact);
+ break;
+ default:
+ break;
+ }
+}
+
+static gboolean check_typed_match(TypedMatch *tm, gchar *s)
+{
+ switch (tm->type) {
+ case MATCH_TYPE_PATTERN:
+ return g_pattern_match_string(tm->m.pattern, s);
+ case MATCH_TYPE_REGEX:
+ return g_regex_match(tm->m.regex,
+ s,
+ 0,
+ NULL);
+ case MATCH_TYPE_EXACT:
+ return !strcmp(tm->m.exact, s);
+ default:
+ return TRUE;
+ }
+
+}
+