iochan_man_t in logic.c gone
[pazpar2-moved-to-github.git] / src / connection.c
index 7b0a027..dd61f1c 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Pazpar2.
-   Copyright (C) 2006-2009 Index Data
+   Copyright (C) 2006-2010 Index Data
 
 Pazpar2 is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -68,9 +68,9 @@ struct connection {
     struct connection *next; // next for same host or next in free list
 };
 
-static struct connection *connection_freelist = 0;
+static struct connection *connection_freelist = 0; /* thread pr */
 
-static int connection_connect(struct connection *con);
+static int connection_connect(struct connection *con, iochan_man_t iochan_man);
 
 static int connection_is_idle(struct connection *co)
 {
@@ -135,7 +135,8 @@ void connection_destroy(struct connection *co)
 // client's database
 static struct connection *connection_create(struct client *cl,
                                             int operation_timeout,
-                                            int session_timeout)
+                                            int session_timeout,
+                                            iochan_man_t iochan_man)
 {
     struct connection *new;
     struct host *host = client_get_host(cl);
@@ -159,7 +160,7 @@ static struct connection *connection_create(struct client *cl,
     new->operation_timeout = operation_timeout;
     new->session_timeout = session_timeout;
     if (host->ipport)
-        connection_connect(new);
+        connection_connect(new, iochan_man);
     return new;
 }
 
@@ -183,12 +184,14 @@ static void non_block_events(struct connection *co)
         case ZOOM_EVENT_END:
             {
                 const char *error, *addinfo;
-                if (ZOOM_connection_error(link, &error, &addinfo))
+               int err;
+                if ((err = ZOOM_connection_error(link, &error, &addinfo)))
                 {
                     yaz_log(YLOG_LOG, "Error %s from %s",
                             error, client_get_url(cl));
                 }
                 iochan_settimeout(iochan, co->session_timeout);
+               client_set_diagnostic(cl, err);
                 client_set_state(cl, Client_Idle);
             }
             break;
@@ -276,7 +279,7 @@ void connection_release(struct connection *co)
     co->client = 0;
 }
 
-void connect_resolver_host(struct host *host)
+void connect_resolver_host(struct host *host, iochan_man_t iochan_man)
 {
     struct connection *con = host->connections;
     while (con)
@@ -299,7 +302,7 @@ void connect_resolver_host(struct host *host)
             }
             else
             {
-                connection_connect(con);
+                connection_connect(con, iochan_man);
                 client_start_search(con->client);
             }
         }
@@ -338,15 +341,15 @@ static int maskfun(IOCHAN c)
     return ZOOM_connection_get_mask(co->link);
 }
 
-static int connection_connect(struct connection *con)
+static int connection_connect(struct connection *con, iochan_man_t iochan_man)
 {
     ZOOM_connection link = 0;
     struct host *host = connection_get_host(con);
     ZOOM_options zoptions = ZOOM_options_create();
     const char *auth;
+    const char *charset;
     const char *sru;
     const char *sru_version = 0;
-    char ipport[512] = "";
 
     struct session_database *sdb = client_get_database(con->client);
     const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
@@ -358,6 +361,10 @@ static int connection_connect(struct connection *con)
     ZOOM_options_set(zoptions, "async", "1");
     ZOOM_options_set(zoptions, "implementationName", PACKAGE_NAME);
     ZOOM_options_set(zoptions, "implementationVersion", VERSION);
+       
+    if ((charset = session_setting_oneval(sdb, PZ_NEGOTIATION_CHARSET)))
+        ZOOM_options_set(zoptions, "charset", charset);
+    
     if (zproxy && *zproxy)
     {
         con->zproxy = xstrdup(zproxy);
@@ -382,10 +389,14 @@ static int connection_connect(struct connection *con)
     }
 
     if (sru && *sru)
-        strcpy(ipport, "http://");
-    strcat(ipport, host->ipport);
-
-    ZOOM_connection_connect(link, ipport, 0);
+    {
+        char http_hostport[512];
+        strcpy(http_hostport, "http://");
+        strcat(http_hostport, host->hostport);
+        ZOOM_connection_connect(link, http_hostport, 0);
+    }
+    else
+        ZOOM_connection_connect(link, host->ipport, 0);
     
     con->link = link;
     con->iochan = iochan_create(0, connection_handler, 0);
@@ -394,7 +405,7 @@ static int connection_connect(struct connection *con)
     iochan_setdata(con->iochan, con);
     iochan_setsocketfun(con->iochan, socketfun);
     iochan_setmaskfun(con->iochan, maskfun);
-    pazpar2_add_channel(con->iochan);
+    iochan_add(iochan_man, con->iochan);
 
     /* this fragment is bad DRY: from client_prep_connection */
     client_set_state(con->client, Client_Connecting);
@@ -409,7 +420,8 @@ const char *connection_get_url(struct connection *co)
 
 // Ensure that client has a connection associated
 int client_prep_connection(struct client *cl,
-                           int operation_timeout, int session_timeout)
+                           int operation_timeout, int session_timeout,
+                           iochan_man_t iochan_man)
 {
     struct connection *co;
     struct session *se = client_get_session(cl);
@@ -456,7 +468,8 @@ int client_prep_connection(struct client *cl,
         }
         else
         {
-            co = connection_create(cl, operation_timeout, session_timeout);
+            co = connection_create(cl, operation_timeout, session_timeout,
+                                   iochan_man);
         }
     }