From 95a76bd311b56586f2f3e9bb6e2e2a6c3f2dbce4 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 19 Jun 2012 12:33:42 +0200 Subject: [PATCH] render_render: Change spec for base64 record embedding Syntax is now base64=x-path .. part of record_render. For example, to produce embedded Turbomarc that comes in marc-8 encoding (usmarc typically), you could use: txml; charset=marc-8; base64=myxpath . --- include/yaz/record_render.h | 2 +- src/record_render.c | 52 +++++++++++++++++-------------------------- test/test_embed_record.c | 8 +++---- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/include/yaz/record_render.h b/include/yaz/record_render.h index 66eacab..7bbc48b 100644 --- a/include/yaz/record_render.h +++ b/include/yaz/record_render.h @@ -51,7 +51,7 @@ YAZ_BEGIN_CDECL txml; charset=marc-8 xml; charset=utf-8 - xml; charset=utf-8; base64(/rec/my/text(), txml; charset=marc-8) + txml; charset=marc-8; base64=/rec/my/text() */ YAZ_EXPORT const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema, diff --git a/src/record_render.c b/src/record_render.c index ba5311e..983667a 100644 --- a/src/record_render.c +++ b/src/record_render.c @@ -252,16 +252,15 @@ static int replace_node(NMEM nmem, xmlNode *ptr, if (res) { xmlDoc *doc = xmlParseMemory(res, strlen(res)); - xmlNode *nptr; if (doc) { - nptr = xmlCopyNode(xmlDocGetRootElement(doc), 1); + xmlNode *nptr = xmlCopyNode(xmlDocGetRootElement(doc), 1); xmlReplaceNode(ptr, nptr); xmlFreeDoc(doc); } else { - nptr = xmlNewText(BAD_CAST res); + xmlNode *nptr = xmlNewText(BAD_CAST res); xmlReplaceNode(ptr, nptr); } ret = 0; @@ -342,7 +341,6 @@ const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema, const char *ret = 0; NMEM nmem = 0; char *base64_xpath = 0; - char *base64_type_spec = 0; size_t i; char type[40]; char charset[40]; @@ -386,34 +384,17 @@ const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema, } format[j] = '\0'; } - else if (!strncmp(cp + i, "base64", 6)) + else if (!strncmp(cp + i, "base64=", 7)) { - i = i + 6; + size_t i0; + i = i + 7; - while (cp[i] == ' ') - i++; - if (cp[i] == '(') - { - size_t i0; - nmem = nmem_create(); + i0 = i; + while (cp[i] && cp[i] != ';') i++; - while (cp[i] == ' ') - i++; - i0 = i; - while (cp[i] != ',' && cp[i]) - i++; - base64_xpath = nmem_strdupn(nmem, cp + i0, i - i0); - if (cp[i]) - i++; - while (cp[i] == ' ') - i++; - i0 = i; - while (cp[i] != ')' && cp[i]) - i++; - base64_type_spec = nmem_strdupn(nmem, cp + i0, i - i0); - if (cp[i]) - i++; - } + + nmem = nmem_create(); + base64_xpath = nmem_strdupn(nmem, cp + i0, i - i0); } } if (!strcmp(type, "database")) @@ -476,8 +457,17 @@ const char *yaz_record_render(Z_NamePlusRecord *npr, const char *schema, } if (base64_xpath) - ret = base64_render(nmem, wrbuf, - ret, len, base64_xpath, base64_type_spec); + { + char *type_spec = nmem_malloc(nmem, + strlen(format) + strlen(charset) + 11); + strcpy(type_spec, type); + if (*charset) + { + strcat(type_spec, "; charset="); + strcat(type_spec, charset); + } + ret = base64_render(nmem, wrbuf, ret, len, base64_xpath, type_spec); + } nmem_destroy(nmem); return ret; } diff --git a/test/test_embed_record.c b/test/test_embed_record.c index aac2987..e5e6a02 100644 --- a/test/test_embed_record.c +++ b/test/test_embed_record.c @@ -145,7 +145,7 @@ int main(int argc, char **argv) YAZ_CHECK(test_render("xml", 0, "", "")); YAZ_CHECK(test_render( - "xml; base64(/my/text(),xml)", 0, + "xml; base64=/my/text()", 0, "" "MDAxMzhuYW0gIDIyMDAwNzM4YSA0NTAwMDAxMDAxMzAwMDAwMDAzMDAwNDAwMDEzMTAwMDAxNzAw" "MDE3MjQ1MDAzMDAwMDM0HiAgIDExMjI0NDY2IB5ETEMeMTAfYUphY2sgQ29sbGlucx4xMB9hSG93" @@ -165,7 +165,7 @@ int main(int argc, char **argv) "\n")); YAZ_CHECK(test_render( - "xml; charset=utf-8; base64(/my/text(),xml)", 0, + "xml; charset=utf-8; base64=/my/text()", 0, "" "MDAxMzhuYW0gIDIyMDAwNzM4YSA0NTAwMDAxMDAxMzAwMDAwMDAzMDAwNDAwMDEzMTAwMDAxNzAw" "MDE3MjQ1MDAzMDAwMDM0HiAgIDExMjI0NDY2IB5ETEMeMTAfYUphY2sgQ29sbGlucx4xMB9hSG93" @@ -185,7 +185,7 @@ int main(int argc, char **argv) "\n")); YAZ_CHECK(test_render( - "xml; base64(/my/text(),xml);charset=utf-8", 0, + "xml; base64=/my/text();charset=utf-8", 0, "" "MDAxMzhuYW0gIDIyMDAwNzM4YSA0NTAwMDAxMDAxMzAwMDAwMDAzMDAwNDAwMDEzMTAwMDAxNzAw" "MDE3MjQ1MDAzMDAwMDM0HiAgIDExMjI0NDY2IB5ETEMeMTAfYUphY2sgQ29sbGlucx4xMB9hSG93" @@ -205,7 +205,7 @@ int main(int argc, char **argv) "\n")); YAZ_CHECK(test_render( - "xml; base64(/my/text(),txml;charset=utf-8)", 0, + "txml;base64=/my/text();charset=utf-8", 0, "" "MDAxMzhuYW0gIDIyMDAwNzM4YSA0NTAwMDAxMDAxMzAwMDAwMDAzMDAwNDAwMDEzMTAwMDAxNzAw" "MDE3MjQ1MDAzMDAwMDM0HiAgIDExMjI0NDY2IB5ETEMeMTAfYUphY2sgQ29sbGlucx4xMB9hSG93" -- 1.7.10.4