+ Yaz_Proxy *new_proxy = new Yaz_Proxy(the_PDU_Observable);
+ new_proxy->m_parent = this;
+ new_proxy->timeout(120);
+ return new_proxy;
+}
+
+char *Yaz_Proxy::get_cookie(Z_OtherInformation **otherInfo)
+{
+ int oid[OID_SIZE];
+ Z_OtherInformationUnit *oi;
+ struct oident ent;
+ ent.proto = PROTO_Z3950;
+ ent.oclass = CLASS_USERINFO;
+ ent.value = (oid_value) VAL_COOKIE;
+ assert (oid_ent_to_oid (&ent, oid));
+
+ if (oid_ent_to_oid (&ent, oid) &&
+ (oi = update_otherInformation(otherInfo, 0, oid, 1)) &&
+ oi->which == Z_OtherInfo_characterInfo)
+ return oi->information.characterInfo;
+ return 0;
+}
+
+char *Yaz_Proxy::get_proxy(Z_OtherInformation **otherInfo)
+{
+ int oid[OID_SIZE];
+ Z_OtherInformationUnit *oi;
+ struct oident ent;
+ ent.proto = PROTO_Z3950;
+ ent.oclass = CLASS_USERINFO;
+ ent.value = (oid_value) VAL_PROXY;
+ if (oid_ent_to_oid (&ent, oid) &&
+ (oi = update_otherInformation(otherInfo, 0, oid, 1)) &&
+ oi->which == Z_OtherInfo_characterInfo)
+ return oi->information.characterInfo;
+ return 0;
+}
+
+Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu)
+{
+ assert (m_parent);
+ Yaz_Proxy *parent = m_parent;
+ Z_OtherInformation **oi;
+ Yaz_ProxyClient *c = m_client;
+
+ get_otherInfoAPDU(apdu, &oi);
+ char *cookie = get_cookie(oi);
+ logf (LOG_LOG, "Yaz_Proxy::get_client cookie=%s", cookie ? cookie :
+ "<null>");
+ if (cookie)
+ {
+ for (c = parent->m_clientPool; c; c = c->m_next)
+ {
+ assert (c->m_prev);
+ assert (*c->m_prev == c);
+ if (!strcmp(cookie,c->m_cookie))
+ {
+ logf (LOG_LOG, "Yaz_Proxy::get_client cached");
+ break;
+ }
+ }
+ }
+ else if (!m_client)
+ {
+ logf (LOG_LOG, "Yaz_Proxy::get_client creating new");
+ c = new Yaz_ProxyClient(m_PDU_Observable->clone());
+ c->m_next = parent->m_clientPool;
+ if (c->m_next)
+ c->m_next->m_prev = &c->m_next;
+ parent->m_clientPool = c;
+ c->m_prev = &parent->m_clientPool;
+
+ sprintf (c->m_cookie, "%d", parent->m_seqno);
+ (parent->m_seqno)++;
+
+ if (apdu->which == Z_APDU_initRequest)
+ {
+ logf (LOG_LOG, "got InitRequest");
+
+ char *proxy_host = get_proxy(&apdu->u.initRequest->otherInfo);
+ if (proxy_host)
+ c->client(proxy_host);
+ else
+ c->client("localhost:9999");
+ }
+ c->timeout(600);
+ }
+ return c;