コード例 #1
0
ファイル: record_conv.c プロジェクト: dcrossleyau/yaz
static void *construct_select(const xmlNode *ptr,
                              const char *path, WRBUF wr_error)
{
    if (strcmp((const char *) ptr->name, "select"))
        return 0;
    else
    {
        NMEM nmem = nmem_create();
        struct select_info *info = nmem_malloc(nmem, sizeof(*info));
        const char *attr_str;
        const char *xpath = 0;

        info->nmem = nmem;
        info->xpath_expr = 0;
        attr_str = yaz_xml_get_prop(ptr, "path%s", &xpath);
        if (attr_str)
        {
            wrbuf_printf(wr_error, "Bad attribute '%s'"
                         "Expected xpath.", attr_str);
            nmem_destroy(nmem);
                return 0;
        }
        if (xpath)
            info->xpath_expr = nmem_strdup(nmem, xpath);
        return info;
    }
}
コード例 #2
0
ファイル: http_command.c プロジェクト: piskvorky/pazpar2
void http_session_destroy(struct http_session *s)
{
    int must_destroy = 0;

    http_sessions_t http_sessions = s->http_sessions;

    yaz_log(http_sessions->log_level, "Session %u destroy", s->session_id);
    yaz_mutex_enter(http_sessions->mutex);
    /* only if http_session has no active http sessions on it can be destroyed */
    if (s->destroy_counter == s->activity_counter)
    {
        struct http_session **p = 0;
        must_destroy = 1;
        for (p = &http_sessions->session_list; *p; p = &(*p)->next)
            if (*p == s)
            {
                *p = (*p)->next;
                break;
            }
    }
    yaz_mutex_leave(http_sessions->mutex);
    if (must_destroy)
    {   /* destroying for real */
        yaz_log(http_sessions->log_level, "Session %u destroyed", s->session_id);
        iochan_destroy(s->timeout_iochan);
        session_destroy(s->psession);
        http_session_use(-1);
        nmem_destroy(s->nmem);
    }
    else {
        yaz_log(http_sessions->log_level, "Session %u destroying delayed. Active clients (%d-%d). Waiting for new timeout.",
                s->session_id, s->activity_counter, s->destroy_counter);
    }

}
コード例 #3
0
ファイル: record_conv.c プロジェクト: dcrossleyau/yaz
static void destroy_select(void *vinfo)
{
    struct select_info *info = vinfo;

    if (info)
        nmem_destroy(info->nmem);
}
コード例 #4
0
ファイル: relevance.c プロジェクト: piskvorky/pazpar2
void relevance_destroy(struct relevance **rp)
{
    if (*rp)
    {
        pp2_charset_token_destroy((*rp)->prt);
        nmem_destroy((*rp)->nmem);
        *rp = 0;
    }
}
コード例 #5
0
ファイル: marcdisp.c プロジェクト: drigolin/node-zoom
void yaz_marc_destroy(yaz_marc_t mt)
{
    if (!mt)
        return ;
    nmem_destroy(mt->nmem);
    wrbuf_destroy(mt->m_wr);
    xfree(mt->leader_spec);
    xfree(mt);
}
コード例 #6
0
ファイル: record_conv.c プロジェクト: dcrossleyau/yaz
static void destroy_xslt(void *vinfo)
{
    struct xslt_info *info = vinfo;

    if (info)
    {
        xmlFreeDoc(info->xsp_doc);
        nmem_destroy(info->nmem);
    }
}
コード例 #7
0
ファイル: normalize_cache.c プロジェクト: dcrossleyau/pazpar2
void normalize_cache_destroy(normalize_cache_t nc)
{
    if (nc)
    {
        struct cached_item *ci = nc->items;
        for (; ci; ci = ci->next)
            normalize_record_destroy(ci->nt);
        yaz_mutex_destroy(&nc->mutex);
        nmem_destroy(nc->nmem);
    }
}
コード例 #8
0
ファイル: record_conv.c プロジェクト: dcrossleyau/yaz
void yaz_record_conv_destroy(yaz_record_conv_t p)
{
    if (p)
    {
        yaz_record_conv_reset(p);
        nmem_destroy(p->nmem);
        wrbuf_destroy(p->wr_error);

        xfree(p->path);
        xfree(p);
    }
}
コード例 #9
0
ファイル: sel_thread.c プロジェクト: saiful76/pazpar2
sel_thread_t sel_thread_create(void (*work_handler)(void *work_data),
                               void (*work_destroy)(void *work_data),
                               int *read_fd, int no_of_threads)
{
    int i;
    NMEM nmem = nmem_create();
    sel_thread_t p = nmem_malloc(nmem, sizeof(*p));

    assert(work_handler);
    /* work_destroy may be NULL */
    assert(read_fd);
    assert(no_of_threads >= 1);

    p->nmem = nmem;

#ifdef WIN32
    /* use port 12119 temporarily on Windos and hope for the best */
    p->spipe = yaz_spipe_create(12119, 0);
#else
    p->spipe = yaz_spipe_create(0, 0);
#endif
    if (!p->spipe)
    {
        nmem_destroy(nmem);
        return 0;
    }    

    *read_fd = p->read_fd = yaz_spipe_get_read_fd(p->spipe);
    p->write_fd = yaz_spipe_get_write_fd(p->spipe);

    p->input_queue = 0;
    p->output_queue = 0;
    p->free_queue = 0;
    p->work_handler = work_handler;
    p->work_destroy = work_destroy;
    p->no_threads = 0; /* we if need to destroy */
    p->stop_flag = 0;
    p->mutex = 0;
    yaz_mutex_create(&p->mutex);
    yaz_cond_create(&p->input_data);
    if (p->input_data == 0) /* condition variable could not be created? */
    {
        sel_thread_destroy(p);
        return 0;
    }

    p->no_threads = no_of_threads;
    p->thread_id = nmem_malloc(nmem, sizeof(*p->thread_id) * p->no_threads);
    for (i = 0; i < p->no_threads; i++)
        p->thread_id[i] = yaz_thread_create(sel_thread_handler, p);
    return p;
}
コード例 #10
0
ファイル: normalize_record.c プロジェクト: jajm/pazpar2
void normalize_record_destroy(normalize_record_t nt)
{
    if (nt)
    {
        struct normalize_step *m;
        for (m = nt->steps; m; m = m->next)
        {
            if (m->stylesheet)
                xsltFreeStylesheet(m->stylesheet);
        }
        nmem_destroy(nt->nmem);
    }
}
コード例 #11
0
ファイル: http_command.c プロジェクト: piskvorky/pazpar2
void http_sessions_destroy(http_sessions_t hs)
{
    if (hs)
    {
        struct http_session *s = hs->session_list;
        while (s)
        {
            struct http_session *s_next = s->next;
            iochan_destroy(s->timeout_iochan);
            session_destroy(s->psession);
            nmem_destroy(s->nmem);
            s = s_next;
        }
        yaz_mutex_destroy(&hs->mutex);
        xfree(hs);
    }
}
コード例 #12
0
static void xml_config_close(void)
{
#if YAZ_HAVE_XML2
    if (xml_config_doc)
    {
        xmlFreeDoc(xml_config_doc);
        xml_config_doc = 0;
    }
#endif
    gfs_server_list = 0;
    nmem_destroy(gfs_nmem);
#ifdef WIN32
    if (init_control_tls)
        TlsFree(current_control_tls);
#elif YAZ_POSIX_THREADS
    if (init_control_tls)
        pthread_key_delete(current_control_tls);
#endif
}
コード例 #13
0
ファイル: cqltransform.c プロジェクト: nla/yaz
void cql_transform_close(cql_transform_t ct)
{
    struct cql_prop_entry *pe;
    if (!ct)
        return;
    pe = ct->entry;
    while (pe)
    {
        struct cql_prop_entry *pe_next = pe->next;
        xfree(pe->pattern);
        xfree(pe->value);
        xfree(pe);
        pe = pe_next;
    }
    xfree(ct->addinfo);
    yaz_tok_cfg_destroy(ct->tok_cfg);
    wrbuf_destroy(ct->w);
    nmem_destroy(ct->nmem);
    xfree(ct);
}
コード例 #14
0
ファイル: sel_thread.c プロジェクト: saiful76/pazpar2
void sel_thread_destroy(sel_thread_t p)
{
    int i;
    yaz_mutex_enter(p->mutex);
    p->stop_flag = 1;
    yaz_cond_broadcast(p->input_data);
    yaz_mutex_leave(p->mutex);
    
    for (i = 0; i< p->no_threads; i++)
        yaz_thread_join(&p->thread_id[i], 0);

    if (p->work_destroy)
    {
        queue_trav(p->input_queue, p->work_destroy);
        queue_trav(p->output_queue, p->work_destroy);
    }

    yaz_spipe_destroy(p->spipe);
    yaz_cond_destroy(&p->input_data);
    yaz_mutex_destroy(&p->mutex);
    nmem_destroy(p->nmem);
}
コード例 #15
0
ファイル: cqltransform.c プロジェクト: nla/yaz
int cql_transform(cql_transform_t ct, struct cql_node *cn,
                  void (*pr)(const char *buf, void *client_data),
                  void *client_data)
{
    struct cql_prop_entry *e;
    NMEM nmem = nmem_create();

    ct->error = 0;
    xfree(ct->addinfo);
    ct->addinfo = 0;

    for (e = ct->entry; e ; e = e->next)
    {
        if (!cql_strncmp(e->pattern, "set.", 4))
            cql_apply_prefix(nmem, cn, e->pattern+4, e->value);
        else if (!cql_strcmp(e->pattern, "set"))
            cql_apply_prefix(nmem, cn, 0, e->value);
    }
    cql_transform_r(ct, cn, pr, client_data);
    nmem_destroy(nmem);
    return ct->error;
}
コード例 #16
0
ファイル: http.c プロジェクト: saiful76/pazpar2
// Cleanup channel
static void http_channel_destroy(IOCHAN i)
{
    struct http_channel *s = iochan_getdata(i);
    http_server_t http_server;

    if (s->proxy)
    {
        if (s->proxy->iochan)
        {
#ifdef WIN32
            closesocket(iochan_getfd(s->proxy->iochan));
#else
            close(iochan_getfd(s->proxy->iochan));
#endif
            iochan_destroy(s->proxy->iochan);
        }
        http_buf_destroy_queue(s->http_server, s->proxy->oqueue);
        xfree(s->proxy);
    }
    http_buf_destroy_queue(s->http_server, s->iqueue);
    http_buf_destroy_queue(s->http_server, s->oqueue);
    http_fire_observers(s);
    http_destroy_observers(s);

    http_server = s->http_server; /* save it for destroy (decref) */

    http_server_destroy(http_server);

#ifdef WIN32
    closesocket(iochan_getfd(i));
#else
    close(iochan_getfd(i));
#endif
    iochan_destroy(i);
    nmem_destroy(s->nmem);
    wrbuf_destroy(s->wrbuf);
    xfree(s);
}
コード例 #17
0
ファイル: test_record_conv.c プロジェクト: dcrossleyau/yaz
static void tst_convert4(void)
{
    NMEM nmem = nmem_create();
    int ret;

    const char *opacxml_rec =
        "<opacRecord>\n"
        "  <bibliographicRecord>\n"
        "<record xmlns=\"http://www.loc.gov/MARC21/slim\">\n"
        "  <leader>00077nam a22000498a 4500</leader>\n"
        "  <controlfield tag=\"001\">   11224466 </controlfield>\n"
        "  <datafield tag=\"010\" ind1=\" \" ind2=\" \">\n"
        "    <subfield code=\"a\">k" "\xc3" "\xb8" /* oslash in UTF_8 */
        "benhavn</subfield>\n"
        "  </datafield>\n"
        "</record>\n"
        "  </bibliographicRecord>\n"
        "  <holdings>\n"
        "   <holding>\n"
        "    <shelvingLocation>Sprague Library hidden basement</shelvingLocation>\n"
        "    <callNumber>E98.L7L44 1976 </callNumber>\n"
        "    <volumes/>\n"
        "   </holding>\n"
        "  </holdings>\n"
        " </opacRecord>\n"
        ;

    Z_OPACRecord *opac = 0;
    yaz_marc_t mt =  yaz_marc_create();
    ret = yaz_xml_to_opac(mt, opacxml_rec, strlen(opacxml_rec),
                          &opac, 0 /* iconv */, nmem, 0);
    YAZ_CHECK(ret);
    YAZ_CHECK(opac);
    yaz_marc_destroy(mt);
    nmem_destroy(nmem);
}
コード例 #18
0
ファイル: record_conv.c プロジェクト: dcrossleyau/yaz
static void destroy_marc(void *info)
{
    struct marc_info *mi = info;

    nmem_destroy(mi->nmem);
}
コード例 #19
0
ファイル: record_conv.c プロジェクト: dcrossleyau/yaz
static void *construct_marc(const xmlNode *ptr,
                            const char *path, WRBUF wr_error)
{
    NMEM nmem = nmem_create();
    struct marc_info *info = nmem_malloc(nmem, sizeof(*info));
    struct _xmlAttr *attr;
    const char *input_format = 0;
    const char *output_format = 0;

    if (strcmp((const char *) ptr->name, "marc"))
    {
        nmem_destroy(nmem);
        return 0;
    }
    info->nmem = nmem;
    info->input_charset = 0;
    info->output_charset = 0;
    info->input_format_mode = 0;
    info->output_format_mode = 0;
    info->leader_spec = 0;

    for (attr = ptr->properties; attr; attr = attr->next)
    {
        if (!xmlStrcmp(attr->name, BAD_CAST "inputcharset") &&
            attr->children && attr->children->type == XML_TEXT_NODE)
            info->input_charset = (const char *) attr->children->content;
        else if (!xmlStrcmp(attr->name, BAD_CAST "outputcharset") &&
            attr->children && attr->children->type == XML_TEXT_NODE)
            info->output_charset = (const char *) attr->children->content;
        else if (!xmlStrcmp(attr->name, BAD_CAST "inputformat") &&
            attr->children && attr->children->type == XML_TEXT_NODE)
            input_format = (const char *) attr->children->content;
        else if (!xmlStrcmp(attr->name, BAD_CAST "outputformat") &&
            attr->children && attr->children->type == XML_TEXT_NODE)
            output_format = (const char *) attr->children->content;
        else if (!xmlStrcmp(attr->name, BAD_CAST "leaderspec") &&
                 attr->children && attr->children->type == XML_TEXT_NODE)
            info->leader_spec =
                nmem_strdup(info->nmem,(const char *) attr->children->content);
        else
        {
            wrbuf_printf(wr_error, "Element <marc>: expected attributes"
                         "'inputformat', 'inputcharset', 'outputformat' or"
                         " 'outputcharset', got attribute '%s'",
                         attr->name);
            nmem_destroy(info->nmem);
            return 0;
        }
    }
    if (!input_format)
    {
        wrbuf_printf(wr_error, "Element <marc>: "
                     "attribute 'inputformat' required");
        nmem_destroy(info->nmem);
        return 0;
    }
    else if (!strcmp(input_format, "marc"))
    {
        info->input_format_mode = YAZ_MARC_ISO2709;
    }
    else if (!strcmp(input_format, "xml"))
    {
        info->input_format_mode = YAZ_MARC_MARCXML;
        /** Libxml2 generates UTF-8 encoding by default .
            So we convert from UTF-8 to outputcharset (if defined)
        */
        if (!info->input_charset && info->output_charset)
            info->input_charset = "utf-8";
    }
    else if (!strcmp(input_format, "json"))
    {
        info->input_format_mode = YAZ_MARC_JSON;
    }
    else
    {
        wrbuf_printf(wr_error, "Element <marc inputformat='%s'>: "
                     " Unsupported input format"
                     " defined by attribute value",
                     input_format);
        nmem_destroy(info->nmem);
        return 0;
    }

    if (!output_format)
    {
        wrbuf_printf(wr_error,
                     "Element <marc>: attribute 'outputformat' required");
        nmem_destroy(info->nmem);
        return 0;
    }
    else if (!strcmp(output_format, "line"))
    {
        info->output_format_mode = YAZ_MARC_LINE;
    }
    else if (!strcmp(output_format, "marcxml"))
    {
        info->output_format_mode = YAZ_MARC_MARCXML;
        if (info->input_charset && !info->output_charset)
            info->output_charset = "utf-8";
    }
    else if (!strcmp(output_format, "turbomarc"))
    {
        info->output_format_mode = YAZ_MARC_TURBOMARC;
        if (info->input_charset && !info->output_charset)
            info->output_charset = "utf-8";
    }
    else if (!strcmp(output_format, "marc"))
    {
        info->output_format_mode = YAZ_MARC_ISO2709;
    }
    else if (!strcmp(output_format, "marcxchange"))
    {
        info->output_format_mode = YAZ_MARC_XCHANGE;
        if (info->input_charset && !info->output_charset)
            info->output_charset = "utf-8";
    }
    else if (!strcmp(output_format, "json"))
    {
        info->output_format_mode = YAZ_MARC_JSON;
        if (info->input_charset && !info->output_charset)
            info->output_charset = "utf-8";
    }
    else
    {
        wrbuf_printf(wr_error, "Element <marc outputformat='%s'>: "
                     " Unsupported output format"
                     " defined by attribute value",
                     output_format);
        nmem_destroy(info->nmem);
        return 0;
    }
    if (info->input_charset && info->output_charset)
    {
        yaz_iconv_t cd = yaz_iconv_open(info->output_charset,
                                        info->input_charset);
        if (!cd)
        {
            wrbuf_printf(wr_error,
                         "Element <marc inputcharset='%s' outputcharset='%s'>:"
                         " Unsupported character set mapping"
                         " defined by attribute values",
                         info->input_charset, info->output_charset);
            nmem_destroy(info->nmem);
            return 0;
        }
        yaz_iconv_close(cd);
    }
    else if (!info->output_charset)
    {
        wrbuf_printf(wr_error, "Element <marc>: "
                     "attribute 'outputcharset' missing");
        nmem_destroy(info->nmem);
        return 0;
    }
    else if (!info->input_charset)
    {
        wrbuf_printf(wr_error, "Element <marc>: "
                     "attribute 'inputcharset' missing");
        nmem_destroy(info->nmem);
        return 0;
    }
    info->input_charset = nmem_strdup(info->nmem, info->input_charset);
    info->output_charset = nmem_strdup(info->nmem, info->output_charset);
    return info;
}
コード例 #20
0
ファイル: record_conv.c プロジェクト: dcrossleyau/yaz
static void *construct_xslt(const xmlNode *ptr,
                            const char *path, WRBUF wr_error)
{
    struct _xmlAttr *attr;
    const char *stylesheet = 0;
    struct xslt_info *info = 0;
    NMEM nmem = 0;
    int max_parms = 10;
    int no_parms = 0;

    if (strcmp((const char *) ptr->name, "xslt"))
        return 0;

    for (attr = ptr->properties; attr; attr = attr->next)
    {
        if (!xmlStrcmp(attr->name, BAD_CAST "stylesheet") &&
            attr->children && attr->children->type == XML_TEXT_NODE)
            stylesheet = (const char *) attr->children->content;
        else
        {
            wrbuf_printf(wr_error, "Bad attribute '%s'"
                         "Expected stylesheet.", attr->name);
            return 0;
        }
    }
    nmem = nmem_create();
    info = nmem_malloc(nmem, sizeof(*info));
    info->nmem = nmem;
    info->xsl_parms = nmem_malloc(
        nmem, (2 * max_parms + 1) * sizeof(*info->xsl_parms));

    for (ptr = ptr->children; ptr; ptr = ptr->next)
    {
        const char *name = 0;
        const char *value = 0;
        char *qvalue = 0;
        if (ptr->type != XML_ELEMENT_NODE)
            continue;
        if (strcmp((const char *) ptr->name, "param"))
        {
            wrbuf_printf(wr_error, "Bad element '%s'"
                         "Expected param.", ptr->name);
            nmem_destroy(nmem);
            return 0;
        }
        for (attr = ptr->properties; attr; attr = attr->next)
        {
            if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
                attr->children && attr->children->type == XML_TEXT_NODE)
                name = (const char *) attr->children->content;
            else if (!xmlStrcmp(attr->name, BAD_CAST "value") &&
                attr->children && attr->children->type == XML_TEXT_NODE)
                value = (const char *) attr->children->content;
            else
            {
                wrbuf_printf(wr_error, "Bad attribute '%s'"
                             "Expected name or value.", attr->name);
                nmem_destroy(nmem);
                return 0;
            }
        }
        if (!name || !value)
        {
            wrbuf_printf(wr_error, "Missing attributes name or value");
            nmem_destroy(nmem);
            return 0;
        }
        if (no_parms >= max_parms)
        {
            wrbuf_printf(wr_error, "Too many parameters given");
            nmem_destroy(nmem);
            return 0;
        }

        qvalue = nmem_malloc(nmem, strlen(value) + 3);
        strcpy(qvalue, "\'");
        strcat(qvalue, value);
        strcat(qvalue, "\'");

        info->xsl_parms[2 * no_parms] = nmem_strdup(nmem, name);
        info->xsl_parms[2 * no_parms + 1] = qvalue;
        no_parms++;
    }
    info->xsl_parms[2 * no_parms] = 0;

    if (!stylesheet)
    {
        wrbuf_printf(wr_error, "Element <xslt>: "
                     "attribute 'stylesheet' expected");
        nmem_destroy(nmem);
    }
    else
    {
        char fullpath[1024];
        xsltStylesheetPtr xsp;
        if (!yaz_filepath_resolve(stylesheet, path, 0, fullpath))
        {
            wrbuf_printf(wr_error, "Element <xslt stylesheet=\"%s\"/>:"
                         " could not locate stylesheet '%s'",
                         stylesheet, stylesheet);
            if (path)
                wrbuf_printf(wr_error, " with path '%s'", path);

            nmem_destroy(nmem);
            return 0;
        }
        info->xsp_doc = xmlParseFile(fullpath);
        if (!info->xsp_doc)
        {
            wrbuf_printf(wr_error, "Element: <xslt stylesheet=\"%s\"/>:"
                         " xml parse failed: %s", stylesheet, fullpath);
            if (path)
                wrbuf_printf(wr_error, " with path '%s'", path);
            nmem_destroy(nmem);
            return 0;
        }
        /* need to copy this before passing it to the processor. It will
           be encapsulated in the xsp and destroyed by xsltFreeStylesheet */
        xsp = xsltParseStylesheetDoc(xmlCopyDoc(info->xsp_doc, 1));
        if (!xsp)
        {
            wrbuf_printf(wr_error, "Element: <xslt stylesheet=\"%s\"/>:"
                         " xslt parse failed: %s", stylesheet, fullpath);
            if (path)
                wrbuf_printf(wr_error, " with path '%s'", path);
            wrbuf_printf(wr_error, " ("
#if YAZ_HAVE_EXSLT

                         "EXSLT enabled"
#else
                         "EXSLT not supported"
#endif
                         ")");
            xmlFreeDoc(info->xsp_doc);
            nmem_destroy(info->nmem);
        }
        else
        {
            xsltFreeStylesheet(xsp);
            return info;
        }
    }
    return 0;
}
コード例 #21
0
ファイル: icu_chain.c プロジェクト: dcrossleyau/yaz
struct icu_chain *icu_chain_xml_config(const xmlNode *xml_node,
                                       int sort,
                                       UErrorCode *status)
{
    xmlNode *node = 0;
    int no_errors = 0;
    struct icu_chain *chain = 0;
    NMEM nmem = 0;

    *status = U_ZERO_ERROR;

    if (xml_node && xml_node->type == XML_ELEMENT_NODE)
    {
        const char *xml_locale = yaz_xml_get_prop((xmlNode *) xml_node,
                                                  "locale");
        if (xml_locale)
            chain = icu_chain_create((const char *) xml_locale, sort, status);
    }

    if (!chain)
        return 0;

    nmem = nmem_create();
    for (node = xml_node->children; node; node = node->next)
    {
        char *rule = 0;
        struct icu_chain_step *step = 0;
        const char *attr_str;

        nmem_reset(nmem);
        if (node->type != XML_ELEMENT_NODE)
            continue;
        attr_str = yaz_xml_get_prop(node, "rule%s", &rule);
        if (attr_str)
        {
            yaz_log(YLOG_WARN, "Unsupported attribute '%s' for "
                    "element '%s'", attr_str, node->name);
            no_errors++;
        }
        if (!rule && node->children)
            rule = nmem_text_node_cdata(node->children, nmem);

        if (!rule && strcmp((const char *) node->name, "display"))
        {
            yaz_log(YLOG_WARN, "Missing attribute 'rule' for element %s",
                    (const char *) node->name);
            no_errors++;
            continue;
        }
        if (!strcmp((const char *) node->name, "casemap"))
            step = icu_chain_insert_step(chain,
                                         ICU_chain_step_type_casemap,
                                         rule, status);
        else if (!strcmp((const char *) node->name, "transform"))
            step = icu_chain_insert_step(chain,
                                         ICU_chain_step_type_transform,
                                         rule, status);
        else if (!strcmp((const char *) node->name, "transliterate"))
            step = icu_chain_insert_step(chain,
                                         ICU_chain_step_type_transliterate,
                                         rule, status);
        else if (!strcmp((const char *) node->name, "tokenize"))
            step = icu_chain_insert_step(chain, ICU_chain_step_type_tokenize,
                                         rule, status);
        else if (!strcmp((const char *) node->name, "display"))
            step = icu_chain_insert_step(chain, ICU_chain_step_type_display,
                                         rule, status);
        else if (!strcmp((const char *) node->name, "stemming"))
            step = icu_chain_insert_step(chain, YAZ_chain_step_type_stemming,
                                         rule, status);
        else if (!strcmp((const char *) node->name, "join"))
            step = icu_chain_insert_step(chain, ICU_chain_step_type_join,
                                         rule, status);
        else if (!strcmp((const char *) node->name, "normalize"))
        {
            yaz_log(YLOG_WARN, "Element %s is deprecated. "
                    "Use transform instead", node->name);
            step = icu_chain_insert_step(chain, ICU_chain_step_type_transform,
                                         rule, status);
        }
        else if (!strcmp((const char *) node->name, "index")
                 || !strcmp((const char *) node->name, "sortkey"))
        {
            yaz_log(YLOG_WARN, "Element %s is no longer needed. "
                    "Remove it from the configuration", node->name);
        }
        else
        {
            yaz_log(YLOG_WARN, "Unknown element %s", node->name);
            no_errors++;
            continue;
        }
        if (!step)
        {
            yaz_log(YLOG_WARN, "Step not created for %s", node->name);
            no_errors++;
        }
        if (step && U_FAILURE(*status))
        {
            yaz_log(YLOG_WARN, "ICU Error %d %s for element %s, rule %s",
                    *status, u_errorName(*status), node->name, rule ?
                    rule : "");
            no_errors++;
            break;
        }
    }
    nmem_destroy(nmem);
    if (no_errors)
    {
        icu_chain_destroy(chain);
        return 0;
    }
    return chain;
}
コード例 #22
0
ファイル: marcmap.c プロジェクト: saiful76/pazpar2
xmlDoc *marcmap_apply(struct marcmap *marcmap, xmlDoc *xml_in)
{
    char mergekey[1024];
    char medium[32];
    char *s;
    NMEM nmem;
    xmlNsPtr ns_pz;
    xmlDocPtr xml_out;
    xmlNodePtr xml_out_root;
    xmlNodePtr rec_node;
    xmlNodePtr meta_node; 
    struct marchash *marchash;
    struct marcfield *field;
    struct marcsubfield *subfield;
    struct marcmap *mmcur;
     
    xml_out = xmlNewDoc(BAD_CAST "1.0");
    xml_out->encoding = xmlCharStrdup("UTF-8");
    xml_out_root = xmlNewNode(NULL, BAD_CAST "record");
    xmlDocSetRootElement(xml_out, xml_out_root);
    ns_pz = xmlNewNs(xml_out_root, BAD_CAST "http://www.indexdata.com/pazpar2/1.0", BAD_CAST "pz"); 
    xmlSetNs(xml_out_root, ns_pz);
    nmem = nmem_create();
    rec_node = xmlDocGetRootElement(xml_in);
    marchash = marchash_create(nmem);
    marchash_ingest_marcxml(marchash, rec_node);

    mmcur = marcmap;
    while (mmcur != NULL)
    {
        field = 0;
        while ((field = marchash_get_field(marchash, mmcur->field, field)) != 0)
        {
            // field value
            if ((mmcur->subfield == '$') && (s = field->val))
            {
                meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s);
                xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz); 
            }
            // catenate all subfields
            else if ((mmcur->subfield == '*') && (s = marchash_catenate_subfields(field, " ", nmem)))
            {
                meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s);
                xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz);
            }
            // subfield value
            else if (mmcur->subfield) 
            {
                subfield = 0;
                while ((subfield = 
                        marchash_get_subfield(mmcur->subfield,
                                              field, subfield)) != 0)
                {
                    if ((s = subfield->val) != 0)
                    {
                        meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s);
                        xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz);
                    }
                }
            }
            
        }
        mmcur = mmcur->next;
    }

    // hard coded mappings

    // medium
    if ((field = marchash_get_field(marchash, "245", NULL)) && (subfield = marchash_get_subfield('h', field, NULL)))
    {
       strncpy(medium, subfield->val, 32);
    }
    else if ((field = marchash_get_field(marchash, "900", NULL)) && (subfield = marchash_get_subfield('a', field, NULL)))
       strcpy(medium, "electronic resource");
    else if ((field = marchash_get_field(marchash, "900", NULL)) && (subfield = marchash_get_subfield('b', field, NULL)))
       strcpy(medium, "electronic resource");
    else if ((field = marchash_get_field(marchash, "773", NULL)) && (subfield = marchash_get_subfield('t', field, NULL)))
       strcpy(medium, "article");
    else
       strcpy(medium, "book");

    meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST medium);
    xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST "medium");

    // merge key
    memset(mergekey, 0, 1024);
    strcpy(mergekey, "title ");
    if ((field = marchash_get_field(marchash, "245", NULL)) && (subfield = marchash_get_subfield('a', field, NULL)))
        strncat(mergekey, subfield->val, 1023 - strlen(mergekey));
    strncat(mergekey, " author ", 1023 - strlen(mergekey));
    if ((field = marchash_get_field(marchash, "100", NULL)) && (subfield = marchash_get_subfield('a', field, NULL)))
        strncat(mergekey, subfield->val, 1023 - strlen(mergekey));
    strncat(mergekey, " medium ", 1023 - strlen(mergekey));
    strncat(mergekey, medium, 1023 - strlen(mergekey));

//    xmlSetProp(xml_out_root, BAD_CAST "mergekey", BAD_CAST mergekey);

    nmem_destroy(nmem);
    return xml_out;
}
コード例 #23
0
ファイル: test_record_conv.c プロジェクト: dcrossleyau/yaz
static void tst_convert3(void)
{
    NMEM nmem = nmem_create();
    int ret;
    yaz_record_conv_t p = 0;

    const char *iso2709_rec =
        "\x30\x30\x30\x37\x37\x6E\x61\x6D\x20\x20\x32\x32\x30\x30\x30\x34"
        "\x39\x38\x61\x20\x34\x35\x30\x30\x30\x30\x31\x30\x30\x31\x33\x30"
        "\x30\x30\x30\x30\x30\x31\x30\x30\x30\x31\x34\x30\x30\x30\x31\x33"
        "\x1E\x20\x20\x20\x31\x31\x32\x32\x34\x34\x36\x36\x20\x1E\x20\x20"
        "\x1F\x61\x6b\xb2\x62\x65\x6e\x68\x61\x76\x6e\x1E\x1D";

    const char *opacxml_rec =
        "<opacRecord>\n"
        "  <bibliographicRecord>\n"
        "<record xmlns=\"http://www.loc.gov/MARC21/slim\">\n"
        "  <leader>00077nam a22000498a 4500</leader>\n"
        "  <controlfield tag=\"001\">   11224466 </controlfield>\n"
        "  <datafield tag=\"010\" ind1=\" \" ind2=\" \">\n"
        "    <subfield code=\"a\">k" "\xc3" "\xb8" /* oslash in UTF_8 */
        "benhavn</subfield>\n"
        "  </datafield>\n"
        "</record>\n"
        "  </bibliographicRecord>\n"
        "<holdings>\n"
        " <holding>\n"
        "  <typeOfRecord>u</typeOfRecord>\n"
        "  <encodingLevel>U</encodingLevel>\n"
        "  <receiptAcqStatus>0</receiptAcqStatus>\n"
        "  <dateOfReport>000000</dateOfReport>\n"
        "  <nucCode>s-FM/GC</nucCode>\n"
        "  <localLocation>Main or Science/Business Reading Rms - STORED OFFSITE</localLocation>\n"
        "  <callNumber>MLCM 89/00602 (N)</callNumber>\n"
        "  <shelvingData>FT MEADE</shelvingData>\n"
        "  <copyNumber>Copy 1</copyNumber>\n"
        "  <volumes>\n"
        "   <volume>\n"
        "    <enumeration>1</enumeration>\n"
        "    <chronology>2</chronology>\n"
        "    <enumAndChron>3</enumAndChron>\n"
        "   </volume>\n"
        "   <volume>\n"
        "    <enumeration>1</enumeration>\n"
        "    <chronology>2</chronology>\n"
        "    <enumAndChron>3</enumAndChron>\n"
        "   </volume>\n"
        "  </volumes>\n"
        "  <circulations>\n"
        "   <circulation>\n"
        "    <availableNow value=\"1\"/>\n"
        "    <availabilityDate>20130129</availabilityDate>\n"
        "    <itemId>1226176</itemId>\n"
        "    <renewable value=\"0\"/>\n"
        "    <onHold value=\"0\"/>\n"
        "   </circulation>\n"
        "  </circulations>\n"
        " </holding>\n"
        "</holdings>\n"
        "</opacRecord>\n";

    Z_OPACRecord *z_opac = nmem_malloc(nmem, sizeof(*z_opac));
    Z_HoldingsAndCircData *h;
    Z_CircRecord *circ;

    z_opac->bibliographicRecord =
        z_ext_record_oid_nmem(nmem, yaz_oid_recsyn_usmarc,
                              iso2709_rec, strlen(iso2709_rec));
    z_opac->num_holdingsData = 1;
    z_opac->holdingsData = (Z_HoldingsRecord **)
        nmem_malloc(nmem, sizeof(Z_HoldingsRecord *) * 1);
    z_opac->holdingsData[0] = (Z_HoldingsRecord *)
        nmem_malloc(nmem, sizeof(Z_HoldingsRecord));
    z_opac->holdingsData[0]->which = Z_HoldingsRecord_holdingsAndCirc;
    h = z_opac->holdingsData[0]->u.holdingsAndCirc = (Z_HoldingsAndCircData *)
         nmem_malloc(nmem, sizeof(*h));
    h->typeOfRecord = nmem_strdup(nmem, "u");
    h->encodingLevel = nmem_strdup(nmem, "U");
    h->format = 0;
    h->receiptAcqStatus = nmem_strdup(nmem, "0");
    h->generalRetention = 0;
    h->completeness = 0;
    h->dateOfReport = nmem_strdup(nmem, "000000");
    h->nucCode = nmem_strdup(nmem, "s-FM/GC");
    h->localLocation = nmem_strdup(nmem,
                                   "Main or Science/Business Reading "
                                   "Rms - STORED OFFSITE");
    h->shelvingLocation = 0;
    h->callNumber = nmem_strdup(nmem, "MLCM 89/00602 (N)");
    h->shelvingData = nmem_strdup(nmem, "FT MEADE");
    h->copyNumber = nmem_strdup(nmem, "Copy 1");
    h->publicNote = 0;
    h->reproductionNote = 0;
    h->termsUseRepro = 0;
    h->enumAndChron = 0;
    h->num_volumes = 2;
    h->volumes = 0;

    h->volumes = (Z_Volume **)
        nmem_malloc(nmem, 2 * sizeof(Z_Volume *));

    h->volumes[0] = (Z_Volume *)
        nmem_malloc(nmem, sizeof(Z_Volume));
    h->volumes[1] = h->volumes[0];

    h->volumes[0]->enumeration = nmem_strdup(nmem, "1");
    h->volumes[0]->chronology = nmem_strdup(nmem, "2");
    h->volumes[0]->enumAndChron = nmem_strdup(nmem, "3");

    h->num_circulationData = 1;
    h->circulationData = (Z_CircRecord **)
        nmem_malloc(nmem, 1 * sizeof(Z_CircRecord *));
    circ = h->circulationData[0] = (Z_CircRecord *)
        nmem_malloc(nmem, sizeof(Z_CircRecord));
    circ->availableNow = nmem_booldup(nmem, 1);
    circ->availablityDate = nmem_strdup(nmem, "20130129");
    circ->availableThru = 0;
    circ->restrictions = 0;
    circ->itemId = nmem_strdup(nmem, "1226176");
    circ->renewable = nmem_booldup(nmem, 0);
    circ->onHold = nmem_booldup(nmem, 0);
    circ->enumAndChron = 0;
    circ->midspine = 0;
    circ->temporaryLocation = 0;

    YAZ_CHECK(conv_configure_test("<backend>"
                                  "<marc"
                                  " inputcharset=\"marc-8\""
                                  " outputcharset=\"utf-8\""
                                  " inputformat=\"marc\""
                                  " outputformat=\"marcxml\""
                                  "/>"
                                  "</backend>",
                                  0, &p));

    if (p)
    {
        WRBUF output_record = wrbuf_alloc();
        ret = yaz_record_conv_opac_record(p, z_opac, output_record);
        YAZ_CHECK(ret == 0);
        if (ret == 0)
        {
            ret = strcmp(wrbuf_cstr(output_record), opacxml_rec);
            YAZ_CHECK(ret == 0);
            if (ret)
            {
                printf("got-output_record len=%ld: %s\n",
                       (long) wrbuf_len(output_record),
                       wrbuf_cstr(output_record));
                printf("output_expect_record len=%ld %s\n",
                       (long) strlen(opacxml_rec),
                       opacxml_rec);
            }
        }
        yaz_record_conv_destroy(p);
        wrbuf_destroy(output_record);
    }
    {
        Z_OPACRecord *opac = 0;
        yaz_marc_t mt =  yaz_marc_create();
        ret = yaz_xml_to_opac(mt, opacxml_rec, strlen(opacxml_rec),
                              &opac, 0 /* iconv */, nmem, 0);
        YAZ_CHECK(ret);
        YAZ_CHECK(opac);

        if (opac)
        {
            WRBUF output_record = wrbuf_alloc();
            char *p;

            yaz_marc_xml(mt, YAZ_MARC_MARCXML);
            yaz_opac_decode_wrbuf(mt, opac, output_record);

            /* change MARC size to 00077 from 00078, due to
               encoding of the aring (two bytes in UTF-8) */
            p = strstr(wrbuf_buf(output_record), "00078");
            YAZ_CHECK(p);
            if (p)
                p[4] = '7';

            ret = strcmp(wrbuf_cstr(output_record), opacxml_rec);
            YAZ_CHECK(ret == 0);
            if (ret)
            {
                printf("got-output_record len=%ld: %s\n",
                       (long) wrbuf_len(output_record),
                       wrbuf_cstr(output_record));
                printf("output_expect_record len=%ld %s\n",
                       (long) strlen(opacxml_rec),
                       opacxml_rec);
            }
            wrbuf_destroy(output_record);
        }
        yaz_marc_destroy(mt);
    }
    nmem_destroy(nmem);
}