Fixed check for application/x-www-form-urlencoded parameters.
[pazpar2-moved-to-github.git] / src / connection.c
index e399161..c330155 100644 (file)
@@ -1,7 +1,5 @@
-/* $Id: connection.c,v 1.10 2007-08-14 14:03:02 adam Exp $
-   Copyright (c) 2006-2007, Index Data.
-
-This file is part of Pazpar2.
+/* This file is part of Pazpar2.
+   Copyright (C) 2006-2008 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
@@ -14,30 +12,43 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with Pazpar2; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+*/
 
 /** \file connection.c
     \brief Z39.50 connection (low-level client)
 */
 
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#if HAVE_SYS_TIME_H
 #include <sys/time.h>
+#endif
+#if HAVE_UNISTD_H
 #include <unistd.h>
+#endif
+#if HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#endif
+#ifdef WIN32
+#include <winsock.h>
+typedef int socklen_t;
+#endif
+#if HAVE_NETDB_H
 #include <netdb.h>
+#endif
+
 #include <signal.h>
 #include <ctype.h>
 #include <assert.h>
 
-#if HAVE_CONFIG_H
-#include "cconfig.h"
-#endif
-
 #include <yaz/log.h>
 #include <yaz/comstack.h>
 #include <yaz/tcpip.h>
@@ -172,7 +183,7 @@ static void connection_handler(IOCHAN i, int event)
        int errcode;
         socklen_t errlen = sizeof(errcode);
 
-       if (getsockopt(cs_fileno(co->link), SOL_SOCKET, SO_ERROR, &errcode,
+       if (getsockopt(cs_fileno(co->link), SOL_SOCKET, SO_ERROR, (char*) &errcode,
            &errlen) < 0 || errcode != 0)
        {
             client_fatal(cl);
@@ -261,7 +272,7 @@ static void connection_handler(IOCHAN i, int event)
             else  // we throw away response and go to idle mode
             {
                 yaz_log(YLOG_DEBUG, "Ignoring result of expired operation");
-                client_set_state(cl, Client_Idle);
+                client_set_state(cl, Client_Continue);
             }
        }
        /* if len==1 we do nothing but wait for more input */
@@ -335,7 +346,7 @@ int connection_send_apdu(struct connection *co, Z_APDU *a)
     else if (r == 1)
     {
         fprintf(stderr, "cs_put incomplete (ParaZ does not handle that)\n");
-        exit(1);
+        return -1;;
     }
     odr_reset(global_parameters.odr_out); /* release the APDU structure  */
     co->state = Conn_Waiting;
@@ -356,7 +367,7 @@ int connection_connect(struct connection *con)
     int res;
 
     struct session_database *sdb = client_get_database(con->client);
-    char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
+    const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
 
     assert(host->ipport);
     assert(con);
@@ -433,7 +444,7 @@ int client_prep_connection(struct client *cl)
     struct session *se = client_get_session(cl);
     struct host *host = client_get_host(cl);
     struct session_database *sdb = client_get_database(cl);
-    char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
+    const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
 
     if (zproxy && zproxy[0] == '\0')
         zproxy = 0;
@@ -477,8 +488,9 @@ int client_prep_connection(struct client *cl)
         else if (co->state == Conn_Open)
         {
             if (client_get_state(cl) == Client_Error 
-                || client_get_state(cl) == Client_Disconnected)
-                client_set_state(cl, Client_Idle);
+                || client_get_state(cl) == Client_Disconnected
+                || client_get_state(cl) == Client_Idle)
+                client_set_state(cl, Client_Continue);
             iochan_setflag(co->iochan, EVENT_OUTPUT);
         }
         return 1;