cleanup includes
[citadel.git] / citadel / event_client.c
index 68995ddf7153401a26f8aa7222285959b33f16ca..7903563c55c9d9ab905af21846b4d779c15a2375 100644 (file)
@@ -9,61 +9,20 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  */
-
 #include "sysdep.h"
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <termios.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <pwd.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <syslog.h>
 
-#if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-#else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
-#endif
-#include <sys/wait.h>
-#include <ctype.h>
+#include <stdio.h>
 #include <string.h>
-#include <limits.h>
+#include <syslog.h>
+#include <assert.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include <assert.h>
-#if HAVE_BACKTRACE
-#include <execinfo.h>
-#endif
 
 #include <libcitadel.h>
-#include "citadel.h"
-#include "server.h"
-#include "citserver.h"
-#include "support.h"
-#include "config.h"
-#include "control.h"
-#include "user_ops.h"
-#include "database.h"
-#include "msgbase.h"
-#include "internet_addressing.h"
-#include "genstamp.h"
-#include "domain.h"
-#include "clientsocket.h"
-#include "locate_host.h"
-#include "citadel_dirs.h"
 
-#include "event_client.h"
 #include "ctdl_module.h"
-
+#include "event_client.h"
 
 ConstStr IOStates[] = {
        {HKEY("DB Queue")},
@@ -295,6 +254,17 @@ eNextState QueueEventContext(AsyncIO *IO, IO_CallBack CB)
        return eSendReply;
 }
 
+eNextState EventQueueDBOperation(AsyncIO *IO, IO_CallBack CB)
+{
+       StopClientWatchers(IO, 0);
+       return QueueDBOperation(IO, CB);
+}
+eNextState DBQueueEventContext(AsyncIO *IO, IO_CallBack CB)
+{
+       StopDBWatchers(IO);
+       return QueueEventContext(IO, CB);
+}
+
 extern eNextState evcurl_handle_start(AsyncIO *IO);
 
 eNextState QueueCurlContext(AsyncIO *IO)
@@ -334,6 +304,13 @@ eNextState QueueCurlContext(AsyncIO *IO)
        return eSendReply;
 }
 
+eNextState CurlQueueDBOperation(AsyncIO *IO, IO_CallBack CB)
+{
+       StopCurlWatchers(IO);
+       return QueueDBOperation(IO, CB);
+}
+
+
 void DestructCAres(AsyncIO *IO);
 void FreeAsyncIOContents(AsyncIO *IO)
 {
@@ -376,6 +353,8 @@ void StopClientWatchers(AsyncIO *IO, int CloseFD)
 
 void StopCurlWatchers(AsyncIO *IO)
 {
+       EVM_syslog(LOG_DEBUG, "EVENT StopCurlWatchers \n");
+
        ev_timer_stop (event_base, &IO->rw_timeout);
        ev_timer_stop(event_base, &IO->conn_fail);
        ev_idle_stop(event_base, &IO->unwind_stack);
@@ -385,6 +364,9 @@ void StopCurlWatchers(AsyncIO *IO)
        ev_io_stop(event_base, &IO->send_event);
        ev_io_stop(event_base, &IO->recv_event);
 
+       curl_easy_cleanup(IO->HttpReq.chnd);
+       IO->HttpReq.chnd = NULL;
+
        if (IO->SendBuf.fd != 0) {
                close(IO->SendBuf.fd);
        }