Implemented various stuff for client and proxy. Updated calls
[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.3  1999-04-20 10:30:05  adam
8  * Implemented various stuff for client and proxy. Updated calls
9  * to ODR to reflect new name parameter.
10  *
11  * Revision 1.2  1999/04/09 11:46:57  adam
12  * Added object Yaz_Z_Assoc. Much more functional client.
13  *
14  * Revision 1.1  1999/03/23 14:17:57  adam
15  * More work on timeout handling. Work on yaz-client.
16  *
17  */
18
19 #include <yaz-z-query.h>
20 #include <pquery.h>
21
22 Yaz_Z_Query::Yaz_Z_Query()
23 {
24     odr_encode = odr_createmem (ODR_ENCODE);
25     odr_decode = odr_createmem (ODR_DECODE);
26 }
27
28 int Yaz_Z_Query::set_rpn (const char *rpn)
29 {
30     buf = 0;
31     odr_reset (odr_encode);
32     Z_Query *query = (Z_Query*) odr_malloc (odr_encode, sizeof(*query));
33     query->which = Z_Query_type_1;
34     query->u.type_1 = p_query_rpn (odr_encode, PROTO_Z3950, rpn);
35     if (!query->u.type_1)
36         return -1;
37     if (!z_Query (odr_encode, &query, 0, 0))
38         return -1;
39     buf = odr_getbuf (odr_encode, &len, 0);
40     return len;
41 }
42
43 void Yaz_Z_Query::set_Z_Query(Z_Query *z_query)
44 {
45     buf = 0;
46     odr_reset (odr_encode);
47     if (!z_Query (odr_encode, &z_query, 0, 0))
48         return;
49     buf = odr_getbuf (odr_encode, &len, 0);
50 }
51
52 Yaz_Z_Query::~Yaz_Z_Query()
53 {
54     odr_destroy (odr_encode);
55     odr_destroy (odr_decode);
56 }
57
58 Z_Query *Yaz_Z_Query::get_Z_Query ()
59 {
60     Z_Query *query;
61     if (!buf)
62         return 0;
63     odr_setbuf (odr_decode, buf, len, 0);
64     if (!z_Query(odr_decode, &query, 0, 0))
65         return 0;
66     return query;
67 }
68
69 void Yaz_Z_Query::print(char *str, int len)
70 {
71
72 }