Modified for new location of YAZ header files. Experimental threaded
[yazpp-moved-to-github.git] / src / yaz-z-query.cpp
1 /*
2  * Copyright (c) 1998-1999, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  * 
6  * $Log: yaz-z-query.cpp,v $
7  * Revision 1.6  1999-12-06 13:52:45  adam
8  * Modified for new location of YAZ header files. Experimental threaded
9  * operation.
10  *
11  * Revision 1.5  1999/04/27 07:52:13  adam
12  * Improved proxy; added query match for result set re-use.
13  *
14  * Revision 1.4  1999/04/21 12:09:01  adam
15  * Many improvements. Modified to proxy server to work with "sessions"
16  * based on cookies.
17  *
18  * Revision 1.3  1999/04/20 10:30:05  adam
19  * Implemented various stuff for client and proxy. Updated calls
20  * to ODR to reflect new name parameter.
21  *
22  * Revision 1.2  1999/04/09 11:46:57  adam
23  * Added object Yaz_Z_Assoc. Much more functional client.
24  *
25  * Revision 1.1  1999/03/23 14:17:57  adam
26  * More work on timeout handling. Work on yaz-client.
27  *
28  */
29
30 #include <yaz-z-query.h>
31 #include <yaz/pquery.h>
32
33 Yaz_Z_Query::Yaz_Z_Query()
34 {
35     odr_encode = odr_createmem (ODR_ENCODE);
36     odr_decode = odr_createmem (ODR_DECODE);
37     odr_print = odr_createmem (ODR_PRINT);
38 }
39
40 int Yaz_Z_Query::set_rpn (const char *rpn)
41 {
42     buf = 0;
43     odr_reset (odr_encode);
44     Z_Query *query = (Z_Query*) odr_malloc (odr_encode, sizeof(*query));
45     query->which = Z_Query_type_1;
46     query->u.type_1 = p_query_rpn (odr_encode, PROTO_Z3950, rpn);
47     if (!query->u.type_1)
48         return -1;
49     if (!z_Query (odr_encode, &query, 0, 0))
50         return -1;
51     z_Query(odr_print, &query, 0, 0);
52     buf = odr_getbuf (odr_encode, &len, 0);
53     return len;
54 }
55
56 void Yaz_Z_Query::set_Z_Query(Z_Query *z_query)
57 {
58     buf = 0;
59     odr_reset (odr_encode);
60     if (!z_Query (odr_encode, &z_query, 0, 0))
61         return;
62     buf = odr_getbuf (odr_encode, &len, 0);
63 }
64
65 Yaz_Z_Query::~Yaz_Z_Query()
66 {
67     odr_destroy (odr_encode);
68     odr_destroy (odr_decode);
69     odr_destroy (odr_print);
70 }
71
72 Z_Query *Yaz_Z_Query::get_Z_Query ()
73 {
74     Z_Query *query;
75     if (!buf)
76         return 0;
77     odr_setbuf (odr_decode, buf, len, 0);
78     if (!z_Query(odr_decode, &query, 0, 0))
79         return 0;
80     return query;
81 }
82
83 void Yaz_Z_Query::print(char *str, int len)
84 {
85
86 }
87
88 int Yaz_Z_Query::match(Yaz_Z_Query *other)
89 {
90     if (len != other->len)
91         return 0;
92     if (!buf || !other->buf)
93         return 0;
94     if (memcmp(buf, other->buf, len))
95         return 0;
96     return 1;
97 }