From 946243040b4b9c47fca3d3896a9ba256b3b17fea Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 11 Nov 2013 15:18:05 +0100 Subject: [PATCH] First work on PAZ-900 --- src/session.c | 64 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/src/session.c b/src/session.c index 95d83ca..a42cedc 100644 --- a/src/session.c +++ b/src/session.c @@ -1672,13 +1672,45 @@ static int check_record_filter(xmlNode *root, struct session_database *sdb) return match; } - static int ingest_to_cluster(struct client *cl, xmlDoc *xdoc, xmlNode *root, int record_no, const char *mergekey_norm); +static int ingest_sub_record(struct client *cl, xmlDoc *xdoc, xmlNode *root, + int record_no, NMEM nmem, + struct session_database *sdb) +{ + int ret = 0; + const char *mergekey_norm; + struct session *se = client_get_session(cl); + struct conf_service *service = se->service; + + if (!check_record_filter(root, sdb)) + { + session_log(se, YLOG_LOG, "Filtered out record no %d from %s", record_no, sdb->database->id); + xmlFreeDoc(xdoc); + return -2; + } + + mergekey_norm = get_mergekey(xdoc, cl, record_no, service, nmem, + se->mergekey); + if (!mergekey_norm) + { + session_log(se, YLOG_WARN, "Got no mergekey"); + xmlFreeDoc(xdoc); + return -1; + } + session_enter(se, "ingest_sub_record"); + if (client_get_session(cl) == se && se->relevance) + ret = ingest_to_cluster(cl, xdoc, root, record_no, mergekey_norm); + session_leave(se, "ingest_sub_record"); + + xmlFreeDoc(xdoc); + return ret; +} + /** \brief ingest XML record \param cl client holds the result set for record \param rec record buffer (0 terminated) @@ -1692,42 +1724,34 @@ int ingest_record(struct client *cl, const char *rec, int record_no, NMEM nmem) { struct session *se = client_get_session(cl); - int ret = 0; struct session_database *sdb = client_get_database(cl); struct conf_service *service = se->service; xmlDoc *xdoc = normalize_record(se, sdb, service, rec, nmem); xmlNode *root; - const char *mergekey_norm; if (!xdoc) return -1; root = xmlDocGetRootElement(xdoc); - if (!check_record_filter(root, sdb)) + if (!strcmp((const char *) root->name, "cluster")) { - session_log(se, YLOG_LOG, "Filtered out record no %d from %s", record_no, sdb->database->id); - xmlFreeDoc(xdoc); - return -2; + root = root->children; + return ingest_sub_record(cl, xdoc, root, record_no, nmem, sdb); } - - mergekey_norm = get_mergekey(xdoc, cl, record_no, service, nmem, - se->mergekey); - if (!mergekey_norm) + else if (!strcmp((const char *) root->name, "record")) { - session_log(se, YLOG_WARN, "Got no mergekey"); - xmlFreeDoc(xdoc); + return ingest_sub_record(cl, xdoc, root, record_no, nmem, sdb); + } + else + { + session_log(se, YLOG_WARN, "Bad pz root element: %s", + (const char *) root->name); return -1; } - session_enter(se, "ingest_record"); - if (client_get_session(cl) == se && se->relevance) - ret = ingest_to_cluster(cl, xdoc, root, record_no, mergekey_norm); - session_leave(se, "ingest_record"); - - xmlFreeDoc(xdoc); - return ret; } + // struct conf_metadata *ser_md = &service->metadata[md_field_id]; // struct record_metadata *rec_md = record->metadata[md_field_id]; static int match_metadata_local(struct conf_service *service, -- 1.7.10.4