Use CONNECT for SSL backends and for Z39.50 thru HTTP proxy YAZ-825 yaz-825
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 3 Mar 2015 11:30:41 +0000 (12:30 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 3 Mar 2015 11:31:32 +0000 (12:31 +0100)
Introduce cs_create_host2 which returns if connection should be
proxy aware (HTTP:absoluteUri or Z39.50 proxy:vhost in init).. For CONNECT,
the connection is NOT proxy aware (no absoluteUri and no Z39.50 vhost).

client/client.c
include/yaz/comstack.h
src/comstack.c
src/url.c
src/zoom-c.c
src/zoom-p.h
src/zoom-sru.c
src/zoom-z3950.c

index 31fd6f8..3f79e7a 100644 (file)
@@ -127,6 +127,7 @@ static char ccl_fields[512] = "default.bib";
 static char cql_fields[512] = "/usr/local/share/yaz/etc/pqf.properties";
 static char *esPackageName = 0;
 static char *yazProxy = 0;
 static char cql_fields[512] = "/usr/local/share/yaz/etc/pqf.properties";
 static char *esPackageName = 0;
 static char *yazProxy = 0;
+static int proxy_mode = 0;
 static int kilobytes = 64 * 1024;
 static char *negotiationCharset = 0;
 static int  negotiationCharsetRecords = 1;
 static int kilobytes = 64 * 1024;
 static char *negotiationCharset = 0;
 static int  negotiationCharsetRecords = 1;
@@ -349,7 +350,7 @@ static void send_Z3950_initRequest(const char* type_and_host)
 
     req->referenceId = set_refid(out);
 
 
     req->referenceId = set_refid(out);
 
-    if (yazProxy && type_and_host)
+    if (proxy_mode && type_and_host)
     {
         yaz_oi_set_string_oid(&req->otherInfo, out, yaz_oid_userinfo_proxy,
                               1, type_and_host);
     {
         yaz_oi_set_string_oid(&req->otherInfo, out, yaz_oid_userinfo_proxy,
                               1, type_and_host);
@@ -703,7 +704,7 @@ static int session_connect_base(const char *arg, const char **basep)
     strncpy(type_and_host, arg, sizeof(type_and_host)-1);
     type_and_host[sizeof(type_and_host)-1] = '\0';
 
     strncpy(type_and_host, arg, sizeof(type_and_host)-1);
     type_and_host[sizeof(type_and_host)-1] = '\0';
 
-    conn = cs_create_host_proxy(arg, 1, &add, yazProxy);
+    conn = cs_create_host2(arg, 1, &add, yazProxy, &proxy_mode);
     if (!conn)
     {
         printf("Could not resolve address %s\n", arg);
     if (!conn)
     {
         printf("Could not resolve address %s\n", arg);
@@ -1320,7 +1321,7 @@ static int send_srw_host_path(Z_SRW_PDU *sr, const char *host_port,
     const char *charset = negotiationCharset;
     Z_GDU *gdu;
 
     const char *charset = negotiationCharset;
     Z_GDU *gdu;
 
-    gdu = z_get_HTTP_Request_uri(out, host_port, path, yazProxy ? 1 : 0);
+    gdu = z_get_HTTP_Request_uri(out, host_port, path, proxy_mode);
 
     if (auth)
     {
 
     if (auth)
     {
index 2b4b4d5..4456dd6 100644 (file)
@@ -123,6 +123,8 @@ YAZ_EXPORT COMSTACK cs_create_host(const char *type_and_host,
 YAZ_EXPORT COMSTACK cs_create_host_proxy(const char *vhost,
                                          int blocking, void **vp,
                                          const char *proxy_host);
 YAZ_EXPORT COMSTACK cs_create_host_proxy(const char *vhost,
                                          int blocking, void **vp,
                                          const char *proxy_host);
+YAZ_EXPORT COMSTACK cs_create_host2(const char *vhost, int blocking, void **vp,
+                                    const char *proxy_host, int *proxy_mode);
 YAZ_EXPORT void cs_get_host_args(const char *type_and_host, const char **args);
 YAZ_EXPORT int cs_complete_auto_head(const char *buf, int len);
 YAZ_EXPORT int cs_complete_auto(const char *buf, int len);
 YAZ_EXPORT void cs_get_host_args(const char *type_and_host, const char **args);
 YAZ_EXPORT int cs_complete_auto_head(const char *buf, int len);
 YAZ_EXPORT int cs_complete_auto(const char *buf, int len);
index 0d069b0..3948cc5 100644 (file)
@@ -178,38 +178,71 @@ COMSTACK cs_create_host(const char *vhost, int blocking, void **vp)
 COMSTACK cs_create_host_proxy(const char *vhost, int blocking, void **vp,
                               const char *proxy_host)
 {
 COMSTACK cs_create_host_proxy(const char *vhost, int blocking, void **vp,
                               const char *proxy_host)
 {
+    int proxy_mode;
+    return cs_create_host2(vhost, blocking, vp, proxy_host, &proxy_mode);
+}
+
+COMSTACK cs_create_host2(const char *vhost, int blocking, void **vp,
+                         const char *proxy_host, int *proxy_mode)
+{
     enum oid_proto proto = PROTO_Z3950;
     const char *host = 0;
     COMSTACK cs;
     CS_TYPE t;
     char *connect_host = 0;
     enum oid_proto proto = PROTO_Z3950;
     const char *host = 0;
     COMSTACK cs;
     CS_TYPE t;
     char *connect_host = 0;
+
     const char *bind_host = strchr(vhost, ' ');
     if (bind_host && bind_host[1])
         bind_host++;
     else
         bind_host = 0;
 
     const char *bind_host = strchr(vhost, ' ');
     if (bind_host && bind_host[1])
         bind_host++;
     else
         bind_host = 0;
 
+    *proxy_mode = 0;
     if (!cs_parse_host(vhost, &host, &t, &proto, &connect_host))
         return 0;
     if (!cs_parse_host(vhost, &host, &t, &proto, &connect_host))
         return 0;
-    if (proxy_host)
+
+    /*  vhost      proxy       proxy method  proxy-flag */
+    /*  TCP+Z3950  TCP+Z3950   TCP+Z3950      1 */
+    /*  TCP+Z3950  TCP+HTTP    CONNECT        0 */
+    /*  TCP+HTTP   TCP+Z3950   TCP+HTTP       1 */
+    /*  TCP+HTTP   TCP+HTTP    TCP+HTTP       1 */
+    /*  SSL+*      TCP+*       CONNECT        0 */
+    /*  ?          SSL         error */
+
+    if (proxy_host && !connect_host)
     {
         enum oid_proto proto1;
         CS_TYPE t1;
     {
         enum oid_proto proto1;
         CS_TYPE t1;
+        const char *host1 = 0;
 
 
-        xfree(connect_host);
-        if (!cs_parse_host(proxy_host, &host, &t1, &proto1, &connect_host))
+        if (!cs_parse_host(proxy_host, &host1, &t1, &proto1, &connect_host))
+            return 0;
+        if (connect_host)
+        {
+            xfree(connect_host);
+            return 0;
+        }
+        if (t1 != tcpip_type)
             return 0;
             return 0;
+
+        if (t == ssl_type || (proto == PROTO_Z3950 && proto1 == PROTO_HTTP))
+            connect_host = xstrdup(host1);
+        else
+        {
+            *proxy_mode = 1;
+            host = host1;
+        }
     }
 
     if (t == tcpip_type)
     {
         cs = yaz_tcpip_create3(-1, blocking, proto, connect_host ? host : 0,
     }
 
     if (t == tcpip_type)
     {
         cs = yaz_tcpip_create3(-1, blocking, proto, connect_host ? host : 0,
-                               0, bind_host);
+                               0 /* user:pass */, bind_host);
     }
     else if (t == ssl_type)
     {
         cs = yaz_ssl_create(-1, blocking, proto, connect_host ? host : 0,
     }
     else if (t == ssl_type)
     {
         cs = yaz_ssl_create(-1, blocking, proto, connect_host ? host : 0,
-                            0, bind_host);
+                            0 /* user:pass */, bind_host);
     }
     else
     {
     }
     else
     {
index f954bce..3aae5b0 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -20,6 +20,7 @@ struct yaz_url {
     ODR odr_in;
     ODR odr_out;
     char *proxy;
     ODR odr_in;
     ODR odr_out;
     char *proxy;
+    int proxy_mode;
     int max_redirects;
     WRBUF w_error;
     int verbose;
     int max_redirects;
     WRBUF w_error;
     int verbose;
@@ -32,6 +33,7 @@ yaz_url_t yaz_url_create(void)
     p->odr_in = odr_createmem(ODR_DECODE);
     p->odr_out = odr_createmem(ODR_ENCODE);
     p->proxy = 0;
     p->odr_in = odr_createmem(ODR_DECODE);
     p->odr_out = odr_createmem(ODR_ENCODE);
     p->proxy = 0;
+    p->proxy_mode = 0;
     p->max_redirects = 10;
     p->w_error = wrbuf_alloc();
     p->verbose = 0;
     p->max_redirects = 10;
     p->w_error = wrbuf_alloc();
     p->verbose = 0;
@@ -142,7 +144,7 @@ Z_HTTP_Response *yaz_url_exec(yaz_url_t p, const char *uri,
         extract_user_pass(p->odr_out->mem, uri, &uri_lean,
                           &http_user, &http_pass);
 
         extract_user_pass(p->odr_out->mem, uri, &uri_lean,
                           &http_user, &http_pass);
 
-        gdu = z_get_HTTP_Request_uri(p->odr_out, uri_lean, 0, p->proxy ? 1 : 0);
+        gdu = z_get_HTTP_Request_uri(p->odr_out, uri_lean, 0, p->proxy_mode);
         gdu->u.HTTP_Request->method = odr_strdup(p->odr_out, method);
 
         yaz_cookies_request(p->cookies, p->odr_out, gdu->u.HTTP_Request);
         gdu->u.HTTP_Request->method = odr_strdup(p->odr_out, method);
 
         yaz_cookies_request(p->cookies, p->odr_out, gdu->u.HTTP_Request);
@@ -177,7 +179,7 @@ Z_HTTP_Response *yaz_url_exec(yaz_url_t p, const char *uri,
             log_warn(p);
             return 0;
         }
             log_warn(p);
             return 0;
         }
-        conn = cs_create_host_proxy(uri_lean, 1, &add, p->proxy);
+        conn = cs_create_host2(uri_lean, 1, &add, p->proxy, &p->proxy_mode);
         if (!conn)
         {
             wrbuf_printf(p->w_error, "Can not resolve URL %s", uri);
         if (!conn)
         {
             wrbuf_printf(p->w_error, "Can not resolve URL %s", uri);
index f97123d..b53dceb 100644 (file)
@@ -266,6 +266,7 @@ ZOOM_API(ZOOM_connection)
     c->host_port = 0;
     c->proxy = 0;
     c->tproxy = 0;
     c->host_port = 0;
     c->proxy = 0;
     c->tproxy = 0;
+    c->proxy_mode = 0;
 
     c->charset = c->lang = 0;
 
 
     c->charset = c->lang = 0;
 
@@ -1078,8 +1079,9 @@ static zoom_ret do_connect_host(ZOOM_connection c, const char *logical_url)
 
     if (c->cs)
         cs_close(c->cs);
 
     if (c->cs)
         cs_close(c->cs);
-    c->cs = cs_create_host_proxy(logical_url, CS_FLAGS_DNS_NO_BLOCK, &add,
-                                 c->tproxy ? c->tproxy : c->proxy);
+    c->cs = cs_create_host2(logical_url, CS_FLAGS_DNS_NO_BLOCK, &add,
+                            c->tproxy ? c->tproxy : c->proxy,
+                            &c->proxy_mode);
 
     if (c->cs && c->cs->protocol == PROTO_HTTP)
     {
 
     if (c->cs && c->cs->protocol == PROTO_HTTP)
     {
index 7990d36..236313b 100644 (file)
@@ -83,6 +83,7 @@ struct ZOOM_connection_p {
     int len_out;
     char *proxy;
     char *tproxy;
     int len_out;
     char *proxy;
     char *tproxy;
+    int proxy_mode;
     char *charset;
     char *lang;
     char *cookie_out;
     char *charset;
     char *lang;
     char *cookie_out;
index 7657773..17f7c18 100644 (file)
@@ -35,8 +35,7 @@ static zoom_ret send_srw(ZOOM_connection c, Z_SRW_PDU *sr)
     const char *database =  ZOOM_options_get(c->options, "databaseName");
 
     gdu = z_get_HTTP_Request_uri(c->odr_out, c->host_port,
     const char *database =  ZOOM_options_get(c->options, "databaseName");
 
     gdu = z_get_HTTP_Request_uri(c->odr_out, c->host_port,
-                                 database,
-                                 c->proxy ? 1 : 0);
+                                 database, c->proxy_mode);
 
     if (c->sru_mode == zoom_sru_get)
     {
 
     if (c->sru_mode == zoom_sru_get)
     {
index 67a6b47..701f5a4 100644 (file)
@@ -609,7 +609,7 @@ zoom_ret ZOOM_connection_Z3950_send_init(ZOOM_connection c)
         auth->u.open = odr_strdup(c->odr_out, c->user);
         ireq->idAuthentication = auth;
     }
         auth->u.open = odr_strdup(c->odr_out, c->user);
         ireq->idAuthentication = auth;
     }
-    if (c->proxy)
+    if (c->proxy_mode)
     {
         yaz_oi_set_string_oid(&ireq->otherInfo, c->odr_out,
                               yaz_oid_userinfo_proxy, 1, c->host_port);
     {
         yaz_oi_set_string_oid(&ireq->otherInfo, c->odr_out,
                               yaz_oid_userinfo_proxy, 1, c->host_port);