Proxy removes OtherInfo Proxy Address and Session ID. Other
[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.5  1999-04-27 07:52:13  adam
8  * Improved proxy; added query match for result set re-use.
9  *
10  * Revision 1.4  1999/04/21 12:09:01  adam
11  * Many improvements. Modified to proxy server to work with "sessions"
12  * based on cookies.
13  *
14  * Revision 1.3  1999/04/20 10:30:05  adam
15  * Implemented various stuff for client and proxy. Updated calls
16  * to ODR to reflect new name parameter.
17  *
18  * Revision 1.2  1999/04/09 11:46:57  adam
19  * Added object Yaz_Z_Assoc. Much more functional client.
20  *
21  * Revision 1.1  1999/03/23 14:17:57  adam
22  * More work on timeout handling. Work on yaz-client.
23  *
24  */
25
26 #include <yaz-z-query.h>
27 #include <pquery.h>
28
29 Yaz_Z_Query::Yaz_Z_Query()
30 {
31     odr_encode = odr_createmem (ODR_ENCODE);
32     odr_decode = odr_createmem (ODR_DECODE);
33     odr_print = odr_createmem (ODR_PRINT);
34 }
35
36 int Yaz_Z_Query::set_rpn (const char *rpn)
37 {
38     buf = 0;
39     odr_reset (odr_encode);
40     Z_Query *query = (Z_Query*) odr_malloc (odr_encode, sizeof(*query));
41     query->which = Z_Query_type_1;
42     query->u.type_1 = p_query_rpn (odr_encode, PROTO_Z3950, rpn);
43     if (!query->u.type_1)
44         return -1;
45     if (!z_Query (odr_encode, &query, 0, 0))
46         return -1;
47     z_Query(odr_print, &query, 0, 0);
48     buf = odr_getbuf (odr_encode, &len, 0);
49     return len;
50 }
51
52 void Yaz_Z_Query::set_Z_Query(Z_Query *z_query)
53 {
54     buf = 0;
55     odr_reset (odr_encode);
56     if (!z_Query (odr_encode, &z_query, 0, 0))
57         return;
58     buf = odr_getbuf (odr_encode, &len, 0);
59 }
60
61 Yaz_Z_Query::~Yaz_Z_Query()
62 {
63     odr_destroy (odr_encode);
64     odr_destroy (odr_decode);
65     odr_destroy (odr_print);
66 }
67
68 Z_Query *Yaz_Z_Query::get_Z_Query ()
69 {
70     Z_Query *query;
71     if (!buf)
72         return 0;
73     odr_setbuf (odr_decode, buf, len, 0);
74     if (!z_Query(odr_decode, &query, 0, 0))
75         return 0;
76     return query;
77 }
78
79 void Yaz_Z_Query::print(char *str, int len)
80 {
81
82 }
83
84 int Yaz_Z_Query::match(Yaz_Z_Query *other)
85 {
86     if (len != other->len)
87         return 0;
88     if (!buf || !other->buf)
89         return 0;
90     if (memcmp(buf, other->buf, len))
91         return 0;
92     return 1;
93 }