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