2 * Copyright (c) 1998-1999, Index Data.
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
6 * $Log: yaz-proxy.cpp,v $
7 * Revision 1.4 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.
11 * Revision 1.3 1999/04/09 11:46:57 adam
12 * Added object Yaz_Z_Assoc. Much more functional client.
14 * Revision 1.2 1999/01/28 13:08:46 adam
15 * Yaz_PDU_Assoc better encapsulated. Memory leak fix in
16 * yaz-socket-manager.cc.
18 * Revision 1.1.1.1 1999/01/28 09:41:07 adam
19 * First implementation of YAZ++.
27 #include <yaz-proxy.h>
29 Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable) :
30 Yaz_Z_Assoc(the_PDU_Observable)
32 m_PDU_Observable = the_PDU_Observable;
36 Yaz_Proxy::~Yaz_Proxy()
40 IYaz_PDU_Observer *Yaz_Proxy::clone(IYaz_PDU_Observable
43 return new Yaz_Proxy(the_PDU_Observable);
46 char *Yaz_Proxy::get_cookie(Z_OtherInformation **otherInfo)
49 Z_OtherInformationUnit *oi;
51 ent.proto = PROTO_Z3950;
52 ent.oclass = CLASS_USERINFO;
53 ent.value = (oid_value) VAL_COOKIE;
54 if (oid_ent_to_oid (&ent, oid) &&
55 (oi = update_otherInformation(otherInfo, 0, oid, 1)) &&
56 oi->which == Z_OtherInfo_characterInfo)
57 return oi->information.characterInfo;
61 char *Yaz_Proxy::get_proxy(Z_OtherInformation **otherInfo)
64 Z_OtherInformationUnit *oi;
66 ent.proto = PROTO_Z3950;
67 ent.oclass = CLASS_USERINFO;
68 ent.value = (oid_value) VAL_PROXY;
69 if (oid_ent_to_oid (&ent, oid) &&
70 (oi = update_otherInformation(otherInfo, 0, oid, 1)) &&
71 oi->which == Z_OtherInfo_characterInfo)
72 return oi->information.characterInfo;
76 void Yaz_Proxy::recv_Z_PDU(Z_APDU *apdu)
78 if (apdu->which == Z_APDU_initRequest)
80 assert (m_client == 0);
81 logf (LOG_LOG, "got InitRequest");
82 m_client = new Yaz_ProxyClient(m_PDU_Observable->clone());
83 m_client->m_server = this;
85 char *proxy_host = get_cookie(&apdu->u.initRequest->otherInfo);
87 m_client->client(proxy_host);
89 m_client->client("localhost:8888");
92 logf (LOG_LOG, "sending PDU");
93 m_client->send_Z_PDU(apdu);
96 void Yaz_Proxy::failNotify()
98 logf (LOG_LOG, "failNotity server");
103 void Yaz_ProxyClient::failNotify()
105 logf (LOG_LOG, "failNotity client");
110 IYaz_PDU_Observer *Yaz_ProxyClient::clone(IYaz_PDU_Observable
113 return new Yaz_ProxyClient(the_PDU_Observable);
116 Yaz_ProxyClient::Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable) :
117 Yaz_Z_Assoc (the_PDU_Observable)
123 void Yaz_ProxyClient::recv_Z_PDU(Z_APDU *apdu)
125 m_server->send_Z_PDU(apdu);