コード例 #1
0
ファイル: cclqfile.c プロジェクト: dcrossleyau/yaz
int ccl_qual_fname (CCL_bibset bibset, const char *fname)
{
    FILE *inf;
    inf = fopen (fname, "r");
    if (!inf)
        return -1;
    ccl_qual_file (bibset, inf);
    fclose (inf);
    return 0;
}
コード例 #2
0
static void xml_config_read(void)
{
    struct gfs_server **gfsp = &gfs_server_list;
    struct gfs_listen **gfslp = &gfs_listen_list;
    xmlNodePtr ptr = xml_config_get_root();

    if (!ptr)
        return;
    for (ptr = ptr->children; ptr; ptr = ptr->next)
    {
        struct _xmlAttr *attr;
        if (ptr->type != XML_ELEMENT_NODE)
            continue;
        attr = ptr->properties;
        if (!strcmp((const char *) ptr->name, "listen"))
        {
            /*
              <listen id="listenerid">tcp:@:9999</listen>
            */
            const char *id = 0;
            const char *address =
                nmem_dup_xml_content(gfs_nmem, ptr->children);
            for ( ; attr; attr = attr->next)
                if (!xmlStrcmp(attr->name, BAD_CAST "id")
                    && attr->children && attr->children->type == XML_TEXT_NODE)
                    id = nmem_dup_xml_content(gfs_nmem, attr->children);
            if (address)
            {
                *gfslp = gfs_listen_new(id, address);
                gfslp = &(*gfslp)->next;
                *gfslp = 0; /* make listener list consistent for search */
            }
        }
        else if (!strcmp((const char *) ptr->name, "server"))
        {
            xmlNodePtr ptr_server = ptr;
            xmlNodePtr ptr;
            const char *listenref = 0;
            const char *id = 0;
            struct gfs_server *gfs;

            for ( ; attr; attr = attr->next)
                if (!xmlStrcmp(attr->name, BAD_CAST "listenref") 
                    && attr->children && attr->children->type == XML_TEXT_NODE)
                    listenref = nmem_dup_xml_content(gfs_nmem, attr->children);
                else if (!xmlStrcmp(attr->name, BAD_CAST "id")
                         && attr->children
                         && attr->children->type == XML_TEXT_NODE)
                    id = nmem_dup_xml_content(gfs_nmem, attr->children);
                else
                    yaz_log(YLOG_WARN, "Unknown attribute '%s' for server",
                            attr->name);
            gfs = *gfsp = gfs_server_new();
            gfs->server_node_ptr = ptr_server;
            if (listenref)
            {
                int id_no;
                struct gfs_listen *gl = gfs_listen_list;
                for (id_no = 1; gl; gl = gl->next, id_no++)
                    if (gl->id && !strcmp(gl->id, listenref))
                    {
                        gfs->listen_ref = id_no;
                        break;
                    }
                if (!gl)
                    yaz_log(YLOG_WARN, "Non-existent listenref '%s' in server "
                            "config element", listenref);
            }
            for (ptr = ptr_server->children; ptr; ptr = ptr->next)
            {
                if (ptr->type != XML_ELEMENT_NODE)
                    continue;
                if (!strcmp((const char *) ptr->name, "host"))
                {
                    gfs->host = nmem_dup_xml_content(gfs_nmem,
                                                     ptr->children);
                }
                else if (!strcmp((const char *) ptr->name, "config"))
                {
                    strcpy(gfs->cb.configname,
                           nmem_dup_xml_content(gfs_nmem, ptr->children));
                }
                else if (!strcmp((const char *) ptr->name, "cql2rpn"))
                {
                    gfs->cql_transform = cql_transform_open_fname(
                        nmem_dup_xml_content(gfs_nmem, ptr->children)
                        );
                }
                else if (!strcmp((const char *) ptr->name, "ccl2rpn"))
                {
                    char *name;
                    FILE *f;

                    name = nmem_dup_xml_content(gfs_nmem, ptr->children);
                    if ((f = fopen(name, "r")) == 0) {
                        yaz_log(YLOG_FATAL, "can't open CCL file '%s'", name);
                        exit(1);
                    }
                    gfs->ccl_transform = ccl_qual_mk();
                    ccl_qual_file (gfs->ccl_transform, f);
                    fclose(f);
                }
                else if (!strcmp((const char *) ptr->name, "directory"))
                {
                    gfs->directory = 
                        nmem_dup_xml_content(gfs_nmem, ptr->children);
                }
                else if (!strcmp((const char *) ptr->name, "docpath"))
                {
                    gfs->docpath = 
                        nmem_dup_xml_content(gfs_nmem, ptr->children);
                }
                else if (!strcmp((const char *) ptr->name, "maximumrecordsize"))
                {
                    gfs->cb.maxrecordsize = atoi(
                        nmem_dup_xml_content(gfs_nmem, ptr->children));
                }
                else if (!strcmp((const char *) ptr->name, "stylesheet"))
                {
                    char *s = nmem_dup_xml_content(gfs_nmem, ptr->children);
                    gfs->stylesheet = (char *)
                        nmem_malloc(gfs_nmem, strlen(s) + 2);
                    sprintf(gfs->stylesheet, "/%s", s);
                }
                else if (!strcmp((const char *) ptr->name, "explain"))
                {
                    ; /* being processed separately */
                }
                else if (!strcmp((const char *) ptr->name, "retrievalinfo"))
                {
                    if (yaz_retrieval_configure(gfs->retrieval, ptr))
                    {       
                        yaz_log(YLOG_FATAL, "%s in config %s",
                                yaz_retrieval_get_error(gfs->retrieval),
                                control_block.xml_config);
                        exit(1);
                    }
                }
                else
                {
                    yaz_log(YLOG_FATAL, "Unknown element '%s' in config %s",
                            ptr->name, control_block.xml_config);
                    exit(1);
                }
            }
            gfsp = &(*gfsp)->next;
        }
    }
    *gfsp = 0;
}