X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Flogic.c;h=ea6e66f56fe72463306fbb034a85adcf57652575;hb=e8df9cb14a5e59e8e5e94b944ef39a97ded152cf;hp=b484279429d0d5e6eb6bd77d550a988c64df81a8;hpb=69ae0b0ac176c892d6fd9d3b1e0c9d0e4a5c6b64;p=pazpar2-moved-to-github.git diff --git a/src/logic.c b/src/logic.c index b484279..ea6e66f 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1,4 +1,4 @@ -/* $Id: logic.c,v 1.28 2007-05-14 08:01:39 marc Exp $ +/* $Id: logic.c,v 1.35 2007-06-02 04:32:28 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -82,7 +82,8 @@ struct parameters global_parameters = "", "", 0, - 0, + 0, /* dump_records */ + 0, /* debug_mode */ 30, "81", "Index Data PazPar2", @@ -153,48 +154,73 @@ xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec) { struct database_retrievalmap *m; struct database *db = sdb->database; - xmlNode *res; - xmlDoc *rdoc; + xmlDoc *rdoc = 0; + const Odr_oid *oid = rec->direct_reference; - // First normalize to XML - if (sdb->yaz_marc) + /* convert response record to XML somehow */ + if (rec->which == Z_External_octet && oid + && !oid_oidcmp(oid, yaz_oid_recsyn_xml)) { - char *buf; - int len; - if (rec->which != Z_External_octet) + /* xml already */ + rdoc = xmlParseMemory((char*) rec->u.octet_aligned->buf, + rec->u.octet_aligned->len); + if (!rdoc) { - yaz_log(YLOG_WARN, "Unexpected external branch, probably BER %s", + yaz_log(YLOG_FATAL, "Non-wellformed XML received from %s", db->url); return 0; } - buf = (char*) rec->u.octet_aligned->buf; - len = rec->u.octet_aligned->len; - if (yaz_marc_read_iso2709(sdb->yaz_marc, buf, len) < 0) + } + else if (oid && yaz_oid_is_iso2709(oid)) + { + /* ISO2709 gets converted to MARCXML */ + if (!sdb->yaz_marc) { - yaz_log(YLOG_WARN, "Failed to decode MARC %s", db->url); + yaz_log(YLOG_FATAL, "Unable to handle ISO2709 record"); return 0; } - - yaz_marc_write_using_libxml2(sdb->yaz_marc, 1); - if (yaz_marc_write_xml(sdb->yaz_marc, &res, - "http://www.loc.gov/MARC21/slim", 0, 0) < 0) + else { - yaz_log(YLOG_WARN, "Failed to encode as XML %s", - db->url); - return 0; + xmlNode *res; + char *buf; + int len; + + if (rec->which != Z_External_octet) + { + yaz_log(YLOG_WARN, "Unexpected external branch, probably BER %s", + db->url); + return 0; + } + buf = (char*) rec->u.octet_aligned->buf; + len = rec->u.octet_aligned->len; + if (yaz_marc_read_iso2709(sdb->yaz_marc, buf, len) < 0) + { + yaz_log(YLOG_WARN, "Failed to decode MARC %s", db->url); + return 0; + } + + yaz_marc_write_using_libxml2(sdb->yaz_marc, 1); + if (yaz_marc_write_xml(sdb->yaz_marc, &res, + "http://www.loc.gov/MARC21/slim", 0, 0) < 0) + { + yaz_log(YLOG_WARN, "Failed to encode as XML %s", + db->url); + return 0; + } + rdoc = xmlNewDoc((xmlChar *) "1.0"); + xmlDocSetRootElement(rdoc, res); } - rdoc = xmlNewDoc((xmlChar *) "1.0"); - xmlDocSetRootElement(rdoc, res); - } else { + char oid_name_buf[OID_STR_MAX]; + const char *oid_name = yaz_oid_to_string_buf(oid, 0, oid_name_buf); yaz_log(YLOG_FATAL, - "Unknown native_syntax in normalize_record from %s", - db->url); + "Unable to handle record of type %s from %s", + oid_name, db->url); return 0; } - + if (global_parameters.dump_records){ fprintf(stderr, "Input Record (normalized) from %s\n----------------\n", @@ -476,9 +502,7 @@ char *search(struct session *se, char *query, char *filter) } for (cl = se->clients; cl; cl = client_next_in_session(cl)) - { client_prep_connection(cl); - } return 0; } @@ -493,7 +517,16 @@ static void session_init_databases_fun(void *context, struct database *db) new->database = db; new->yaz_marc = 0; - new->pct = pp2_charset_create(); + +#ifdef HAVE_ICU + if (global_parameters.server && global_parameters.server->icu_chn) + new->pct = pp2_charset_create(global_parameters.server->icu_chn); + else + new->pct = pp2_charset_create(0); +#else // HAVE_ICU + new->pct = pp2_charset_create(0); +#endif // HAVE_ICU + new->map = 0; new->settings = nmem_malloc(se->session_nmem, sizeof(struct settings *) * num); @@ -559,13 +592,19 @@ void session_apply_setting(struct session *se, char *dbname, char *setting, { struct session_database *sdb = find_session_database(se, dbname); struct setting *new = nmem_malloc(se->session_nmem, sizeof(*new)); - int offset = settings_offset(setting); + int offset = settings_offset_cprefix(setting); if (offset < 0) { yaz_log(YLOG_WARN, "Unknown setting %s", setting); return; } + // Jakub: This breaks the filter setting. + /*if (offset == PZ_ID) + { + yaz_log(YLOG_WARN, "No need to set pz:id setting. Ignoring"); + return; + }*/ new->precedence = 0; new->target = dbname; new->name = setting;