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