From 32d55d69260109c360dd735bdc1718b3f166ff7e Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 22 Jul 2008 12:16:26 +0200 Subject: [PATCH] Convert nativesyntax charset to ZOOM charset properly. --- m4 | 2 +- src/client.c | 44 ++++++++++++++++++++++++++++---------------- test/test_http_7.res | 34 ++++++++++++++++++++++++++++++++-- test/test_http_urls | 1 + test/test_icu_2.res | 4 +--- 5 files changed, 63 insertions(+), 22 deletions(-) diff --git a/m4 b/m4 index a3d7a33..b076b76 160000 --- a/m4 +++ b/m4 @@ -1 +1 @@ -Subproject commit a3d7a3375702caae9794ae3a724e51ae9ee46ac3 +Subproject commit b076b768162950579fb9831b1f8dd8be5fdc3154 diff --git a/src/client.c b/src/client.c index 603ee21..26d1f51 100644 --- a/src/client.c +++ b/src/client.c @@ -303,24 +303,41 @@ static void client_send_raw_present(struct client *cl) connection_continue(co); } +static int nativesyntax_to_type(struct session_database *sdb, char *type) +{ + const char *s = session_setting_oneval(sdb, PZ_NATIVESYNTAX); + + if (s && *s) + { + if (!strncmp(s, "iso2709", 7)) + { + const char *cp = strchr(s, ';'); + yaz_snprintf(type, 80, "xml; charset=%s", cp ? cp+1 : "marc-8s"); + } + else if (!strncmp(s, "xml", 3)) + { + strcpy(type, "xml"); + } + else + return -1; + yaz_log(YLOG_LOG, "Returned type %s", type); + return 0; + } + return -1; +} + static void ingest_raw_record(struct client *cl, ZOOM_record rec) { const char *buf; int len; - char type[50]; + char type[80]; if (cl->show_raw->binary) strcpy(type, "raw"); else { struct session_database *sdb = client_get_database(cl); - const char *cset; - - const char *nativesyntax = session_setting_oneval(sdb, PZ_NATIVESYNTAX); - if (*nativesyntax && (cset = strchr(nativesyntax, ';'))) - yaz_snprintf(type, sizeof(type)-1, "xml; charset=%s", cset); - else - strcpy(type, "xml"); + nativesyntax_to_type(sdb, type); } buf = ZOOM_record_get(rec, type, &len); @@ -414,6 +431,7 @@ void client_search_response(struct client *cl) } } + void client_record_response(struct client *cl) { struct connection *co = cl->connection; @@ -459,14 +477,8 @@ void client_record_response(struct client *cl) { struct session_database *sdb = client_get_database(cl); const char *xmlrec; - char type[128] = "xml"; - const char *nativesyntax = - session_setting_oneval(sdb, PZ_NATIVESYNTAX); - char *cset; - - if (*nativesyntax && (cset = strchr(nativesyntax, ';'))) - sprintf(type, "xml; charset=%s", cset + 1); - + char type[80]; + nativesyntax_to_type(sdb, type); if ((xmlrec = ZOOM_record_get(rec, type, NULL))) { if (ingest_record(cl, xmlrec, cl->records)) diff --git a/test/test_http_7.res b/test/test_http_7.res index 781b985..838cea5 100644 --- a/test/test_http_7.res +++ b/test/test_http_7.res @@ -1,2 +1,32 @@ - -00362nam 22001698a 4504 11224467 DLC00000000000000.0910710c19910701nju 00010 eng 11224467DLCDLC123-xyzJack CollinsHow to program a computerPenguin8710p. cm. + + 00362nam a22001698a 4504 + 11224467 + DLC + 00000000000000.0 + 910710c19910701nju 00010 eng + + 11224467 + + + DLC + DLC + + + 123-xyz + + + Jack Collins + + + How to program a computer + + + Penguin + + + 8710 + + + p. cm. + + diff --git a/test/test_http_urls b/test/test_http_urls index bc84f81..335c5e9 100644 --- a/test/test_http_urls +++ b/test/test_http_urls @@ -23,5 +23,6 @@ http://localhost:9763/search.pz2?session=2&command=search&query=kubiak%20sts%C5% 2 http://localhost:9763/search.pz2?session=2&command=bytarget http://localhost:9763/search.pz2?session=1&command=search&query=computer +1 http://localhost:9763/search.pz2?session=1&command=record&id=title+how+to+program+a+computer+author+jack+collins+medium+book http://localhost:9763/search.pz2?session=1&command=record&id=title+how+to+program+a+computer+author+jack+collins+medium+book&offset=0&binary=1 diff --git a/test/test_icu_2.res b/test/test_icu_2.res index 48f18ee..27822f6 100644 --- a/test/test_icu_2.res +++ b/test/test_icu_2.res @@ -4,9 +4,7 @@ 0 0 0 -0 -0 -0 +0 0 0 0 -- 1.7.10.4