Esempio n. 1
0
/** \brief build a 100 level query */
void test1(void)
{
    ODR odr = odr_createmem(ODR_ENCODE);
    YAZ_PQF_Parser parser = yaz_pqf_create();
    Z_RPNQuery *rpn_query;
    char qstr[10000];
    int i;
    int ret;

    YAZ_CHECK(odr);
    YAZ_CHECK(parser);

    *qstr = '\0';
    for (i = 0; i<100; i++)
        strcat(qstr, "@and 1 ");
    strcat(qstr, "1");

    rpn_query = yaz_pqf_parse (parser, odr, qstr);
    YAZ_CHECK(rpn_query);

    ret = z_RPNQuery(odr, &rpn_query, 0, 0);
    YAZ_CHECK(ret);

    yaz_pqf_destroy(parser);
    odr_destroy(odr);
}
Esempio n. 2
0
Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p)
{
    YAZ_PQF_Parser parser = yaz_pqf_create();
    WRBUF wr = wrbuf_alloc();
    Z_RPNQuery *q;

    ccl_pquery(wr, p);

    q = yaz_pqf_parse(parser, o, wrbuf_cstr(wr));

    wrbuf_destroy(wr);
    yaz_pqf_destroy(parser);
    return q;
}
Esempio n. 3
0
int expect_pqf(const char *pqf, const char *expect_pqf, int expect_error)
{
    YAZ_PQF_Parser parser = yaz_pqf_create();
    int res = 0;
    ODR odr = odr_createmem(ODR_ENCODE);
    Z_RPNQuery *rpn;

    if (!parser)
        return 0;

    if (!odr)
        return 0;

    rpn = yaz_pqf_parse(parser, odr, pqf);

    if (!rpn)
    {
        const char *msg;
        size_t offset;
        int got_error = yaz_pqf_error (parser, &msg, &offset);

        if (expect_error == got_error)
            res = 1;
    }
    else if (expect_error == YAZ_PQF_ERROR_NONE)
    {
        WRBUF wrbuf = wrbuf_alloc();
        
        if (wrbuf)
        {
            yaz_rpnquery_to_wrbuf(wrbuf, rpn);
            
            if (!strcmp(wrbuf_cstr(wrbuf), expect_pqf))
                res = 1;
            wrbuf_destroy(wrbuf);
        }
    }
    yaz_pqf_destroy(parser);
    odr_destroy(odr);
    return res;
}
Esempio n. 4
0
/** \brief build a circular referenced query */
void test2(void)
{
    ODR odr = odr_createmem(ODR_ENCODE);
    YAZ_PQF_Parser parser = yaz_pqf_create();
    Z_RPNQuery *rpn_query;
    int ret;

    YAZ_CHECK(odr);

    rpn_query = yaz_pqf_parse (parser, odr, "@and @and a b c");
    YAZ_CHECK(rpn_query);

    /* make the circular reference */
    rpn_query->RPNStructure->u.complex->s1 = rpn_query->RPNStructure;

    ret = z_RPNQuery(odr, &rpn_query, 0, 0);  /* should fail */
    YAZ_CHECK(!ret);

    yaz_pqf_destroy(parser);
    odr_destroy(odr);
}
Esempio n. 5
0
Zlint_code Zlint_test_search_01::sendTest(Zlint *z)
{
    if (!m_got_result_set)
    {
        Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_searchRequest);
        Z_SearchRequest *sr;
        sr = apdu->u.searchRequest;
        sr->query = (Z_Query *) odr_malloc(z->odr_encode(), sizeof(*sr->query));
        if (try_query[m_query_no] && sr)
        {
            sr->query->which = Z_Query_type_1;
            Z_RPNQuery *rpn;
            YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();

            z->getDatabase(&sr->databaseNames, &sr->num_databaseNames);

            rpn = yaz_pqf_parse(pqf_parser, z->odr_encode(),
                                try_query[m_query_no]);

            yaz_pqf_destroy (pqf_parser);

            if (!rpn)
            {
                z->msg_check_fail("Query %s invalid", try_query[m_query_no]);
                return TEST_FINISHED;
            }
            int len;
            sr->query->u.type_1 = rpn;
            z->send_Z_PDU(apdu, &len);
        }
        else
        {
            z->msg_check_notapp();
            z->msg_check_info("unable to get any hit count");
            return TEST_FINISHED;
        }
    }
    else if (m_got_result_set && try_syntax[m_record_syntax_no])
    {
        int len;
        Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_presentRequest);
        Z_PresentRequest *pr = apdu->u.presentRequest;
        *pr->numberOfRecordsRequested = 1;
        *pr->resultSetStartPoint = 1;

        z->msg_check_for("record syntax %s", try_syntax[m_record_syntax_no]);
        pr->preferredRecordSyntax =
            yaz_string_to_oid_odr(yaz_oid_std(),
                                  CLASS_RECSYN, try_syntax[m_record_syntax_no],
                                  z->odr_encode());
        z->send_Z_PDU(apdu, &len);
        return TEST_CONTINUE;
    }
    else if(m_got_result_set && !try_syntax[m_record_syntax_no])
    {
        Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_sortRequest);
        if (apdu && try_sort[m_sort_no])
        {
            z->msg_check_for("sort %s", try_sort[m_sort_no]);

            const char *setstring = "default";
            int len;
            Z_SortRequest *sr = apdu->u.sortRequest;

            sr->num_inputResultSetNames = 1;
            sr->num_inputResultSetNames = 1;
            sr->inputResultSetNames = (Z_InternationalString **)
                odr_malloc (z->odr_encode(), sizeof(*sr->inputResultSetNames));
            sr->inputResultSetNames[0] = odr_strdup (z->odr_encode(), setstring);
            sr->sortedResultSetName = odr_strdup(z->odr_encode(), setstring);
            sr->sortSequence = yaz_sort_spec(z->odr_encode(), try_sort[m_sort_no]);
            z->send_Z_PDU(apdu, &len);
        }
        else
            return TEST_FINISHED;
    }
    else
    {
        printf ("finished...\n");
        return TEST_FINISHED;
    }
    return TEST_CONTINUE;
}
Esempio n. 6
0
void pqftoxmlquery(const char *pqf)
{
    YAZ_PQF_Parser parser = yaz_pqf_create();
    ODR odr = odr_createmem(ODR_ENCODE);
    Z_RPNQuery *rpn;

    if (!parser)
    {
	fprintf(stderr, "%s: cannot create parser\n", prog);
	exit(1);
    }

    if (!odr)
    {
	fprintf(stderr, "%s: cannot create parser\n", prog);
	exit(1);
    }

    rpn = yaz_pqf_parse(parser, odr, pqf);

    yaz_pqf_destroy(parser);

    if (!rpn)
    {
	fprintf(stderr, "%s: pqf parse error for query %s\n", prog, pqf);
	exit(2);
    }
    else
    {
	xmlDocPtr doc = 0;
	
        yaz_rpnquery2xml(rpn, &doc);
        
        if (!doc)
	{
	    fprintf(stderr, "%s: yaz_rpnquery2xml failed for query %s\n",
		    prog, pqf);
	    exit(3);
	}
        else
        {
            xmlChar *buf_out = 0;
            int len_out = 0;

            xmlDocDumpMemory(doc, &buf_out, &len_out);

            if (!len_out || !buf_out)
	    {
		fprintf(stderr, "%s: xmlDocDumpMemory failed for query %s\n",
			prog, pqf);
		exit(4);
	    }
	    else
	    {
		if (fwrite(buf_out, len_out, 1, stdout) != 1)
		{
		    fprintf(stderr, "%s: write failed\n", prog);
		    exit(5);
		}
	    }
            xmlFreeDoc(doc);
	}
    }    
    odr_destroy(odr);
}
Esempio n. 7
0
int main(int argc, char **argv)
{
    cql_transform_t ct;
    int i, iterations = 1;
    char *query = 0;
    char *fname = 0;
    int reverse = 0;

    int ret;
    char *arg;

    while ((ret = options("n:r", argv, argc, &arg)) != -2)
    {
        switch (ret)
        {
        case 0:
            if (!fname)
                fname = arg;
            else
                query = arg;
            break;
        case 'r':
            reverse = 1;
            break;
        case 'n':
            iterations = atoi(arg);
            break;
        default:
            usage();
        }
    }
    if (!fname)
        usage();
    if (!strcmp(fname, "-"))
        ct = cql_transform_create();
    else
        ct = cql_transform_open_fname(fname);
    if (!ct)
    {
        fprintf(stderr, "failed to read properties %s\n", fname);
        exit(1);
    }

    if (reverse)
    {
        if (!query)
            usage();
        else
        {
            ODR odr = odr_createmem(ODR_ENCODE);
            YAZ_PQF_Parser pp = yaz_pqf_create();
            Z_RPNQuery *rpn = yaz_pqf_parse(pp, odr, query);
            if (!rpn)
            {
                fprintf(stderr, "PQF syntax error\n");
            }
            else 
            {
                int ret = cql_transform_rpn2cql_stream(ct, cql_fputs,
                                                       stdout, rpn);
                
                if (ret)
                {
                    const char *addinfo;
                    int r = cql_transform_error(ct, &addinfo);
                    printf("Transform error %d %s\n", r, addinfo ? addinfo : "");
                }
                else
                    printf("\n");
            }
            yaz_pqf_destroy(pp);
            odr_destroy(odr);
        }
    }
    else
    {
        CQL_parser cp = cql_parser_create();
        int r = 0;
        
        if (query)
        {
            for (i = 0; i<iterations; i++)
                r = cql_parser_string(cp, query);
        }
        else
            r = cql_parser_stdio(cp, stdin);
        
        if (r)
            fprintf(stderr, "Syntax error\n");
        else
        {
            r = cql_transform_FILE(ct, cql_parser_result(cp), stdout);
            printf("\n");
            if (r)
            {
                const char *addinfo;
                r = cql_transform_error(ct, &addinfo);
                printf("Transform error %d %s\n", r, addinfo ? addinfo : "");
            }
            else
            {
                FILE *null = fopen("/dev/null", "w");
                for (i = 1; i<iterations; i++)
                    cql_transform_FILE(ct, cql_parser_result(cp), null);
                fclose(null);
            }
        }
        cql_parser_destroy(cp);
    }
    cql_transform_close(ct);
    return 0;
}
Esempio n. 8
0
enum pqf2xml_status pqf2xml_text(const char *pqf, const char *expect_xml,
                                 const char *expect_pqf)
{
    YAZ_PQF_Parser parser = yaz_pqf_create();
    ODR odr = odr_createmem(ODR_ENCODE);
    Z_RPNQuery *rpn;
    enum pqf2xml_status status = XML_NO_ERROR;

    YAZ_CHECK(parser);

    YAZ_CHECK(odr);

    rpn = yaz_pqf_parse(parser, odr, pqf);

    yaz_pqf_destroy(parser);

    if (!rpn)
        status = PQF_FAILED;
    else
    {
#if YAZ_HAVE_XML2
        xmlDocPtr doc = 0;

        yaz_rpnquery2xml(rpn, &doc);

        if (!doc)
            status = QUERY2XML_FAILED;
        else
        {
            char *buf_out;
            int len_out;

            xmlDocDumpMemory(doc, (xmlChar **) &buf_out, &len_out);

            if (len_out == (int) strlen(expect_xml)
                && memcmp(buf_out, expect_xml, len_out) == 0)
            {
                Z_Query *query2 = 0;
                int error_code = 0;
                const char *addinfo = 0;
                const xmlNode *root_element = xmlDocGetRootElement(doc);
                ODR odr2 = odr_createmem(ODR_ENCODE);

                yaz_xml2query(root_element, &query2, odr2,
                              &error_code, &addinfo);
                if (error_code || !query2)
                    status = XML_NO_MATCH;
                else
                {
                    WRBUF w = wrbuf_alloc();
                    yaz_query_to_wrbuf(w, query2);
                    if (!expect_pqf || strcmp(expect_pqf, wrbuf_cstr(w)) == 0)
                        status = XML_MATCH;
                    else
                    {
                        status = XML_NO_MATCH;
                        printf("Result: %s\n", wrbuf_cstr(w));
                    }
                    wrbuf_destroy(w);
                }
                odr_destroy(odr2);
            }
            else
            {
                printf("%.*s\n", len_out, buf_out);
                status = XML_NO_MATCH;
            }
            xmlFreeDoc(doc);
            xmlFree(buf_out);
        }
#else
        status = QUERY2XML_FAILED;
#endif
    }
    odr_destroy(odr);
    return status;
}