+/** \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)
+ {
+ size_t len;
+ const char *eq = strchr(s, '=');
+ if (eq)
+ len = eq - s;
+ else
+ len = strlen(s);
+ if (len == strlen((const char *)type) &&
+ !memcmp((const char *) type, s, len))
+ {
+ xmlChar *value = xmlNodeGetContent(n);
+ if (value && *value)
+ {
+ if (!eq || strstr((const char *) value, eq+1))
+ match = 1;
+ }
+ xmlFree(value);
+ }
+ xmlFree(type);
+ }
+ }
+ }
+ return match;
+}