+static const char *str_tok_n(const char *s, const char *delim,
+ const char **res, size_t *len)
+{
+ *res = s;
+ while (*s && !strchr(delim, *s))
+ s++;
+ *len = s - *res;
+ if (*len == 0)
+ return 0;
+ if (*s && strchr(delim, *s))
+ s++;
+ return s;
+}
+
+/** \brief see if metadata for pz:recordfilter exists
+ \param root xml root element of normalized record
+ \param sdb session database for client
+ \retval 0 if there is no metadata for pz:recordfilter
+ \retval 1 if there is metadata for pz:recordfilter
+
+ If there is no pz:recordfilter defined, this function returns 1
+ as well.
+*/
+
+static int check_record_filter(xmlNode *root, struct session_database *sdb)
+{
+ int match = 0;
+ xmlNode *n;
+ const char *s;
+ s = session_setting_oneval(sdb, PZ_RECORDFILTER);
+
+ if (!s || !*s)
+ return 1;
+
+ for (n = root->children; n; n = n->next)
+ {
+ if (n->type != XML_ELEMENT_NODE)
+ continue;
+ if (!strcmp((const char *) n->name, "metadata"))
+ {
+ xmlChar *type = xmlGetProp(n, (xmlChar *) "type");
+ if (type)
+ {
+ const char *s1 = s;
+ size_t len;
+ const char *value;
+ while ((s1 = str_tok_n(s1, ",", &value, &len)) != 0)
+ {
+ if (len == strlen((const char *)type) &&
+ !memcmp((const char *) type, s, len))
+ {
+ xmlChar *value = xmlNodeGetContent(n);
+ if (value && *value)
+ {
+ xmlFree(value);
+ match = 1;
+ }
+ }
+ }
+ xmlFree(type);
+ }
+ }
+ }
+ return match;
+}