return mergekey_norm;
}
+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;
+}
/** \brief ingest XML record
struct record *ingest_record(struct client *cl, const char *rec,
int record_no)
{
- xmlDoc *xdoc = normalize_record(client_get_database(cl),
- client_get_session(cl), rec);
+ struct session_database *sdb = client_get_database(cl);
+ struct session *se = client_get_session(cl);
+ xmlDoc *xdoc = normalize_record(sdb, se, rec);
xmlNode *root, *n;
struct record *record;
struct record_cluster *cluster;
- struct session *se = client_get_session(cl);
const char *mergekey_norm;
xmlChar *type = 0;
xmlChar *value = 0;
root = xmlDocGetRootElement(xdoc);
+ if (!check_record_filter(root, sdb))
+ {
+ yaz_log(YLOG_WARN, "Filtered out record no %d from %s", record_no,
+ sdb->database->url);
+ xmlFreeDoc(xdoc);
+ return 0;
+ }
+
mergekey_norm = get_mergekey(xdoc, cl, record_no, service, se->nmem);
if (!mergekey_norm)
{
&se->total_merged);
if (global_parameters.dump_records)
yaz_log(YLOG_LOG, "Cluster id %s from %s (#%d)", cluster->recid,
- client_get_database(cl)->database->url, record_no);
+ sdb->database->url, record_no);
if (!cluster)
{
/* no room for record */