2 * Copyright (c) 1998-2012 by the citadel.org team
4 * This program is open source software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
28 #include <sys/types.h>
31 #if TIME_WITH_SYS_TIME
32 # include <sys/time.h>
36 # include <sys/time.h>
45 #include <sys/socket.h>
46 #include <netinet/in.h>
48 #include <arpa/inet.h>
49 #include <libcitadel.h>
50 #include <curl/curl.h>
51 #include <curl/multi.h>
54 #include "citserver.h"
57 #include "ctdl_module.h"
59 #include "event_client.h"
60 #include "serv_curl.h"
63 int DebugEventLoop = 0;
64 int DebugEventLoopBacktrace = 0;
66 pthread_key_t evConKey;
69 /*****************************************************************************
70 * libevent / curl integration *
71 *****************************************************************************/
72 #define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (DebugCurl != 0))
74 #define EVCURL_syslog(LEVEL, FORMAT, ...) \
75 DBGLOG (LEVEL) syslog(LEVEL, "EVCURL:%s[%ld]CC[%d] " FORMAT, \
76 IOSTR, IO->ID, CCID, __VA_ARGS__)
78 #define EVCURLM_syslog(LEVEL, FORMAT) \
79 DBGLOG (LEVEL) syslog(LEVEL, "EVCURL:%s[%ld]CC[%d] " FORMAT, \
82 #define CURL_syslog(LEVEL, FORMAT, ...) \
83 DBGLOG (LEVEL) syslog(LEVEL, "CURL: " FORMAT, __VA_ARGS__)
85 #define CURLM_syslog(LEVEL, FORMAT) \
86 DBGLOG (LEVEL) syslog(LEVEL, "CURL: " FORMAT)
90 sta = curl_multi_setopt(mhnd, (CURLMOPT_##s), (v)); \
92 EVQ_syslog(LOG_ERR, "error setting option " \
93 #s " on curl multi handle: %s\n", \
94 curl_easy_strerror(sta)); \
100 typedef struct _evcurl_global_data {
105 } evcurl_global_data;
108 evcurl_global_data global;
118 CURLM_syslog(LOG_DEBUG,
119 "gotstatus(): about to call curl_multi_info_read\n");
120 while ((msg = curl_multi_info_read(global.mhnd, &nmsg))) {
121 CURL_syslog(LOG_DEBUG,
122 "got curl multi_info message msg=%d\n",
125 if (CURLMSG_DONE == msg->msg) {
127 char *chandle = NULL;
133 chnd = msg->easy_handle;
134 sta = curl_easy_getinfo(chnd,
139 "error asking curl for private"
140 " cookie of curl handle: %s\n",
141 curl_easy_strerror(sta));
144 IO = (AsyncIO *)chandle;
146 EVCURL_syslog(LOG_ERR,
147 "Error, invalid IO context %p\n",
151 SetEVState(IO, eCurlGotStatus);
153 EVCURLM_syslog(LOG_DEBUG, "request complete\n");
155 IO->Now = ev_now(event_base);
157 ev_io_stop(event_base, &IO->recv_event);
158 ev_io_stop(event_base, &IO->send_event);
160 sta = msg->data.result;
162 EVCURL_syslog(LOG_ERR,
163 "error description: %s\n",
164 IO->HttpReq.errdesc);
165 IO->HttpReq.CurlError = curl_easy_strerror(sta);
166 EVCURL_syslog(LOG_ERR,
167 "error performing request: %s\n",
168 IO->HttpReq.CurlError);
169 if (sta == CURLE_OPERATION_TIMEDOUT)
175 sta = curl_easy_getinfo(chnd,
176 CURLINFO_RESPONSE_CODE,
177 &IO->HttpReq.httpcode);
179 EVCURL_syslog(LOG_ERR,
180 "error asking curl for "
181 "response code from request: %s\n",
182 curl_easy_strerror(sta));
183 EVCURL_syslog(LOG_DEBUG,
184 "http response code was %ld\n",
185 (long)IO->HttpReq.httpcode);
188 curl_slist_free_all(IO->HttpReq.headers);
189 msta = curl_multi_remove_handle(global.mhnd, chnd);
191 EVCURL_syslog(LOG_ERR,
192 "warning problem detaching "
193 "completed handle from curl multi: "
195 curl_multi_strerror(msta));
197 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
199 IO->HttpReq.attached = 0;
200 switch(IO->SendDone(IO))
214 case eTerminateConnection:
216 curl_easy_cleanup(IO->HttpReq.chnd);
217 IO->HttpReq.chnd = NULL;
218 FreeStrBuf(&IO->HttpReq.ReplyData);
219 FreeURL(&IO->ConnectMe);
220 RemoveContext(IO->CitContext);
228 stepmulti(void *data, curl_socket_t fd, int which)
230 int running_handles = 0;
233 msta = curl_multi_socket_action(global.mhnd,
238 CURLM_syslog(LOG_DEBUG, "stepmulti(): calling gotstatus()\n");
241 "error in curl processing events"
242 "on multi handle, fd %d: %s\n",
244 curl_multi_strerror(msta));
246 if (global.nrun != running_handles)
247 gotstatus(running_handles);
251 gottime(struct ev_loop *loop, ev_timer *timeev, int events)
253 CURLM_syslog(LOG_DEBUG, "EVCURL: waking up curl for timeout\n");
254 stepmulti(NULL, CURL_SOCKET_TIMEOUT, 0);
258 got_in(struct ev_loop *loop, ev_io *ioev, int events)
260 CURL_syslog(LOG_DEBUG,
261 "EVCURL: waking up curl for io on fd %d\n",
264 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_IN);
268 got_out(struct ev_loop *loop, ev_io *ioev, int events)
270 CURL_syslog(LOG_DEBUG,
271 "waking up curl for io on fd %d\n",
274 stepmulti(ioev->data, ioev->fd, CURL_CSELECT_OUT);
278 gotdata(void *data, size_t size, size_t nmemb, void *cglobal)
280 AsyncIO *IO = (AsyncIO*) cglobal;
282 SetEVState(IO, eCurlGotData);
283 if (IO->HttpReq.ReplyData == NULL)
285 IO->HttpReq.ReplyData = NewStrBufPlain(NULL, SIZ);
287 IO->Now = ev_now(event_base);
288 return CurlFillStrBuf_callback(data,
291 IO->HttpReq.ReplyData);
295 gotwatchtime(CURLM *multi, long tblock_ms, void *cglobal) {
296 CURL_syslog(LOG_DEBUG, "EVCURL: gotwatchtime called %ld ms\n", tblock_ms);
297 evcurl_global_data *global = cglobal;
298 ev_timer_stop(EV_DEFAULT, &global->timeev);
299 if (tblock_ms < 0 || 14000 < tblock_ms)
301 ev_timer_set(&global->timeev, 0.5e-3 + 1.0e-3 * tblock_ms, 14.0);
302 ev_timer_start(EV_DEFAULT_UC, &global->timeev);
303 curl_multi_perform(global, &global->nrun);
308 gotwatchsock(CURL *easy,
314 evcurl_global_data *global = cglobal;
315 CURLM *mhnd = global->mhnd;
317 AsyncIO *IO = (AsyncIO*) vIO;
322 sta = curl_easy_getinfo(easy, CURLINFO_PRIVATE, &f);
325 "EVCURL: error asking curl for private "
326 "cookie of curl handle: %s\n",
327 curl_easy_strerror(sta));
331 SetEVState(IO, eCurlNewIO);
332 EVCURL_syslog(LOG_DEBUG,
333 "EVCURL: got socket for URL: %s\n",
334 IO->ConnectMe->PlainUrl);
336 if (IO->SendBuf.fd != 0)
338 ev_io_stop(event_base, &IO->recv_event);
339 ev_io_stop(event_base, &IO->send_event);
342 ev_io_init(&IO->recv_event, &got_in, fd, EV_READ);
343 ev_io_init(&IO->send_event, &got_out, fd, EV_WRITE);
344 curl_multi_assign(mhnd, fd, IO);
347 SetEVState(IO, eCurlGotIO);
348 IO->Now = ev_now(event_base);
354 Action = "CURL_POLL_NONE";
356 case CURL_POLL_REMOVE:
357 Action = "CURL_POLL_REMOVE";
360 Action = "CURL_POLL_IN";
363 Action = "CURL_POLL_OUT";
365 case CURL_POLL_INOUT:
366 Action = "CURL_POLL_INOUT";
371 EVCURL_syslog(LOG_DEBUG,
372 "EVCURL: gotwatchsock called fd=%d action=%s[%d]\n",
373 (int)fd, Action, action);
378 EVCURLM_syslog(LOG_DEBUG,
380 "to register this sockwatcker\n");
382 case CURL_POLL_REMOVE:
383 EVCURLM_syslog(LOG_DEBUG,
384 "called last time to unregister "
385 "this sockwatcher\n");
386 ev_io_stop(event_base, &IO->recv_event);
387 ev_io_stop(event_base, &IO->send_event);
390 ev_io_start(event_base, &IO->recv_event);
391 ev_io_stop(event_base, &IO->send_event);
394 ev_io_start(event_base, &IO->send_event);
395 ev_io_stop(event_base, &IO->recv_event);
397 case CURL_POLL_INOUT:
398 ev_io_start(event_base, &IO->send_event);
399 ev_io_start(event_base, &IO->recv_event);
405 void curl_init_connectionpool(void)
409 ev_timer_init(&global.timeev, &gottime, 14.0, 14.0);
410 global.timeev.data = (void *)&global;
412 CURLcode sta = curl_global_init(CURL_GLOBAL_ALL);
417 "error initializing curl library: %s\n",
418 curl_easy_strerror(sta));
422 mhnd = global.mhnd = curl_multi_init();
425 CURLM_syslog(LOG_ERR,
426 "error initializing curl multi handle\n");
430 MOPT(SOCKETFUNCTION, &gotwatchsock);
431 MOPT(SOCKETDATA, (void *)&global);
432 MOPT(TIMERFUNCTION, &gotwatchtime);
433 MOPT(TIMERDATA, (void *)&global);
438 int evcurl_init(AsyncIO *IO)
443 EVCURLM_syslog(LOG_DEBUG, "EVCURL: evcurl_init called ms\n");
444 IO->HttpReq.attached = 0;
445 chnd = IO->HttpReq.chnd = curl_easy_init();
448 EVCURLM_syslog(LOG_ERR, "EVCURL: error initializing curl handle\n");
453 OPT(VERBOSE, (long)1);
458 OPT(FAILONERROR, (long)1);
460 OPT(FOLLOWLOCATION, (long)0);
461 OPT(MAXREDIRS, (long)0);
462 OPT(USERAGENT, CITADEL);
464 OPT(TIMEOUT, (long)1800);
465 OPT(LOW_SPEED_LIMIT, (long)64);
466 OPT(LOW_SPEED_TIME, (long)600);
467 OPT(CONNECTTIMEOUT, (long)600);
468 OPT(PRIVATE, (void *)IO);
470 OPT(FORBID_REUSE, 1);
471 OPT(WRITEFUNCTION, &gotdata);
472 OPT(WRITEDATA, (void *)IO);
473 OPT(ERRORBUFFER, IO->HttpReq.errdesc);
475 if ((!IsEmptyStr(config.c_ip_addr))
476 && (strcmp(config.c_ip_addr, "*"))
477 && (strcmp(config.c_ip_addr, "::"))
478 && (strcmp(config.c_ip_addr, "0.0.0.0"))
481 OPT(INTERFACE, config.c_ip_addr);
484 #ifdef CURLOPT_HTTP_CONTENT_DECODING
485 OPT(HTTP_CONTENT_DECODING, 1);
489 IO->HttpReq.headers = curl_slist_append(IO->HttpReq.headers,
490 "Connection: close");
496 static void IOcurl_abort_shutdown_callback(struct ev_loop *loop,
501 AsyncIO *IO = watcher->data;
506 SetEVState(IO, eCurlShutdown);
507 IO->Now = ev_now(event_base);
508 EVCURL_syslog(LOG_DEBUG, "EVENT Curl: %s\n", __FUNCTION__);
510 curl_slist_free_all(IO->HttpReq.headers);
511 msta = curl_multi_remove_handle(global.mhnd, IO->HttpReq.chnd);
514 EVCURL_syslog(LOG_ERR,
515 "EVCURL: warning problem detaching completed handle "
516 "from curl multi: %s\n",
517 curl_multi_strerror(msta));
520 curl_easy_cleanup(IO->HttpReq.chnd);
521 IO->HttpReq.chnd = NULL;
522 ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
523 ev_io_stop(event_base, &IO->recv_event);
524 ev_io_stop(event_base, &IO->send_event);
525 assert(IO->ShutdownAbort);
526 IO->ShutdownAbort(IO);
529 evcurl_handle_start(AsyncIO *IO)
535 SetEVState(IO, eCurlStart);
536 chnd = IO->HttpReq.chnd;
537 EVCURL_syslog(LOG_DEBUG,
538 "EVCURL: Loading URL: %s\n", IO->ConnectMe->PlainUrl);
539 OPT(URL, IO->ConnectMe->PlainUrl);
540 if (StrLength(IO->ConnectMe->CurlCreds))
542 OPT(HTTPAUTH, (long)CURLAUTH_BASIC);
543 OPT(USERPWD, ChrPtr(IO->ConnectMe->CurlCreds));
545 if (StrLength(IO->HttpReq.PostData) > 0)
547 OPT(POSTFIELDS, ChrPtr(IO->HttpReq.PostData));
548 OPT(POSTFIELDSIZE, StrLength(IO->HttpReq.PostData));
551 else if ((IO->HttpReq.PlainPostDataLen != 0) &&
552 (IO->HttpReq.PlainPostData != NULL))
554 OPT(POSTFIELDS, IO->HttpReq.PlainPostData);
555 OPT(POSTFIELDSIZE, IO->HttpReq.PlainPostDataLen);
557 OPT(HTTPHEADER, IO->HttpReq.headers);
559 IO->NextState = eConnect;
560 EVCURLM_syslog(LOG_DEBUG, "EVCURL: attaching to curl multi handle\n");
561 msta = curl_multi_add_handle(global.mhnd, IO->HttpReq.chnd);
564 EVCURL_syslog(LOG_ERR,
565 "EVCURL: error attaching to curl multi handle: %s\n",
566 curl_multi_strerror(msta));
569 IO->HttpReq.attached = 1;
570 ev_async_send (event_base, &WakeupCurl);
572 ev_cleanup_init(&IO->abort_by_shutdown,
573 IOcurl_abort_shutdown_callback);
575 ev_cleanup_start(event_base, &IO->abort_by_shutdown);
580 static void WakeupCurlCallback(EV_P_ ev_async *w, int revents)
582 CURLM_syslog(LOG_DEBUG, "waking up curl multi handle\n");
584 curl_multi_perform(&global, CURL_POLL_NONE);
587 static void evcurl_shutdown (void)
589 curl_global_cleanup();
590 curl_multi_cleanup(global.mhnd);
591 CURLM_syslog(LOG_DEBUG, "exiting\n");
593 /*****************************************************************************
594 * libevent integration *
595 *****************************************************************************/
597 * client event queue plus its methods.
598 * this currently is the main loop (which may change in some future?)
600 int evbase_count = 0;
601 pthread_mutex_t EventQueueMutex; /* locks the access to the following vars: */
602 pthread_mutex_t EventExitQueueMutex; /* locks the access to the event queue pointer on exit. */
603 HashList *QueueEvents = NULL;
604 HashList *InboundEventQueue = NULL;
605 HashList *InboundEventQueues[2] = { NULL, NULL };
606 extern void ShutDownCLient(AsyncIO *IO);
609 ev_async ExitEventLoop;
611 static void QueueEventAddCallback(EV_P_ ev_async *w, int revents)
623 /* get the control command... */
624 pthread_mutex_lock(&EventQueueMutex);
626 if (InboundEventQueues[0] == InboundEventQueue) {
627 InboundEventQueue = InboundEventQueues[1];
628 q = InboundEventQueues[0];
631 InboundEventQueue = InboundEventQueues[0];
632 q = InboundEventQueues[1];
634 pthread_mutex_unlock(&EventQueueMutex);
635 Now = ev_now (event_base);
636 It = GetNewHashPos(q, 0);
637 while (GetNextHashPos(q, It, &len, &Key, &v))
641 if (h->IO->ID == 0) {
642 h->IO->ID = EvIDSource++;
645 if (h->IO->StartIO == 0.0)
646 h->IO->StartIO = Now;
648 SetEVState(h->IO, eIOAttach);
650 Ctx = h->IO->CitContext;
654 switch (h->EvAttch(h->IO))
668 case eTerminateConnection:
670 ShutDownCLient(h->IO);
675 DeleteHashContent(&q);
676 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] EVENT Q Add %ld done.", IOSTR, IOID, count);
680 static void EventExitCallback(EV_P_ ev_async *w, int revents)
682 ev_break(event_base, EVBREAK_ALL);
684 EVQM_syslog(LOG_DEBUG, "EVENT Q exiting.\n");
689 void InitEventQueue(void)
691 pthread_mutex_init(&EventQueueMutex, NULL);
692 pthread_mutex_init(&EventExitQueueMutex, NULL);
694 QueueEvents = NewHash(1, Flathash);
695 InboundEventQueues[0] = NewHash(1, Flathash);
696 InboundEventQueues[1] = NewHash(1, Flathash);
697 InboundEventQueue = InboundEventQueues[0];
699 extern void CtdlDestroyEVCleanupHooks(void);
701 extern int EVQShutDown;
702 const char *IOLog = "IO";
704 * this thread operates the select() etc. via libev.
706 void *client_event_thread(void *arg)
708 struct CitContext libev_client_CC;
710 CtdlFillSystemContext(&libev_client_CC, "LibEv Thread");
712 pthread_setspecific(evConKey, IOLog);
714 EVQM_syslog(LOG_DEBUG, "client_event_thread() initializing\n");
716 event_base = ev_default_loop (EVFLAG_AUTO);
717 ev_async_init(&AddJob, QueueEventAddCallback);
718 ev_async_start(event_base, &AddJob);
719 ev_async_init(&ExitEventLoop, EventExitCallback);
720 ev_async_start(event_base, &ExitEventLoop);
721 ev_async_init(&WakeupCurl, WakeupCurlCallback);
722 ev_async_start(event_base, &WakeupCurl);
724 curl_init_connectionpool();
726 ev_run (event_base, 0);
728 EVQM_syslog(LOG_DEBUG, "client_event_thread() exiting\n");
730 ///what todo here? CtdlClearSystemContext();
731 pthread_mutex_lock(&EventExitQueueMutex);
732 ev_loop_destroy (EV_DEFAULT_UC);
734 DeleteHash(&QueueEvents);
735 InboundEventQueue = NULL;
736 DeleteHash(&InboundEventQueues[0]);
737 DeleteHash(&InboundEventQueues[1]);
738 /* citthread_mutex_destroy(&EventQueueMutex); TODO */
741 CtdlDestroyEVCleanupHooks();
743 pthread_mutex_unlock(&EventExitQueueMutex);
748 /*----------------------------------------------------------------------------*/
750 * DB-Queue; does async bdb operations.
751 * has its own set of handlers.
755 pthread_mutex_t DBEventQueueMutex; /* locks the access to the following vars: */
756 pthread_mutex_t DBEventExitQueueMutex; /* locks the access to the db-event queue pointer on exit. */
757 HashList *DBQueueEvents = NULL;
758 HashList *DBInboundEventQueue = NULL;
759 HashList *DBInboundEventQueues[2] = { NULL, NULL };
762 ev_async DBExitEventLoop;
764 extern void ShutDownDBCLient(AsyncIO *IO);
766 static void DBQueueEventAddCallback(EV_P_ ev_async *w, int revents)
778 /* get the control command... */
779 pthread_mutex_lock(&DBEventQueueMutex);
781 if (DBInboundEventQueues[0] == DBInboundEventQueue) {
782 DBInboundEventQueue = DBInboundEventQueues[1];
783 q = DBInboundEventQueues[0];
786 DBInboundEventQueue = DBInboundEventQueues[0];
787 q = DBInboundEventQueues[1];
789 pthread_mutex_unlock(&DBEventQueueMutex);
791 Now = ev_now (event_db);
792 It = GetNewHashPos(q, 0);
793 while (GetNextHashPos(q, It, &len, &Key, &v))
799 h->IO->ID = EvIDSource++;
801 if (h->IO->StartDB == 0.0)
802 h->IO->StartDB = Now;
805 SetEVState(h->IO, eDBAttach);
806 Ctx = h->IO->CitContext;
808 ev_cleanup_start(event_db, &h->IO->db_abort_by_shutdown);
809 rc = h->EvAttch(h->IO);
813 ShutDownDBCLient(h->IO);
819 DeleteHashContent(&q);
820 EVQ_syslog(LOG_DEBUG, "%s CC[%ld] DBEVENT Q Add %ld done.", IOSTR, IOID, count);
824 static void DBEventExitCallback(EV_P_ ev_async *w, int revents)
826 EVQM_syslog(LOG_DEBUG, "DB EVENT Q exiting.\n");
827 ev_break(event_db, EVBREAK_ALL);
832 void DBInitEventQueue(void)
834 pthread_mutex_init(&DBEventQueueMutex, NULL);
835 pthread_mutex_init(&DBEventExitQueueMutex, NULL);
837 DBQueueEvents = NewHash(1, Flathash);
838 DBInboundEventQueues[0] = NewHash(1, Flathash);
839 DBInboundEventQueues[1] = NewHash(1, Flathash);
840 DBInboundEventQueue = DBInboundEventQueues[0];
843 const char *DBLog = "BD";
846 * this thread operates writing to the message database via libev.
848 void *db_event_thread(void *arg)
851 struct CitContext libev_msg_CC;
853 pthread_setspecific(evConKey, DBLog);
855 CtdlFillSystemContext(&libev_msg_CC, "LibEv DB IO Thread");
857 EVQM_syslog(LOG_DEBUG, "dbevent_thread() initializing\n");
859 tmp = event_db = ev_loop_new (EVFLAG_AUTO);
861 ev_async_init(&DBAddJob, DBQueueEventAddCallback);
862 ev_async_start(event_db, &DBAddJob);
863 ev_async_init(&DBExitEventLoop, DBEventExitCallback);
864 ev_async_start(event_db, &DBExitEventLoop);
866 ev_run (event_db, 0);
868 pthread_mutex_lock(&DBEventExitQueueMutex);
871 EVQM_syslog(LOG_INFO, "dbevent_thread() exiting\n");
873 DeleteHash(&DBQueueEvents);
874 DBInboundEventQueue = NULL;
875 DeleteHash(&DBInboundEventQueues[0]);
876 DeleteHash(&DBInboundEventQueues[1]);
878 /* citthread_mutex_destroy(&DBEventQueueMutex); TODO */
880 ev_loop_destroy (tmp);
881 pthread_mutex_unlock(&DBEventExitQueueMutex);
885 void ShutDownEventQueues(void)
887 EVQM_syslog(LOG_DEBUG, "EVENT Qs triggering exits.\n");
889 pthread_mutex_lock(&DBEventQueueMutex);
890 ev_async_send (event_db, &DBExitEventLoop);
891 pthread_mutex_unlock(&DBEventQueueMutex);
893 pthread_mutex_lock(&EventQueueMutex);
894 ev_async_send (EV_DEFAULT_ &ExitEventLoop);
895 pthread_mutex_unlock(&EventQueueMutex);
898 void DebugEventloopEnable(const int n)
902 void DebugEventloopBacktraceEnable(const int n)
904 DebugEventLoopBacktrace = n;
907 void DebugCurlEnable(const int n)
912 const char *WLog = "WX";
913 CTDL_MODULE_INIT(event_client)
917 if (pthread_key_create(&evConKey, NULL) != 0) {
918 syslog(LOG_CRIT, "Can't create TSD key: %s", strerror(errno));
920 pthread_setspecific(evConKey, WLog);
922 CtdlRegisterDebugFlagHook(HKEY("eventloop"), DebugEventloopEnable, &DebugEventLoop);
923 CtdlRegisterDebugFlagHook(HKEY("eventloopbacktrace"), DebugEventloopBacktraceEnable, &DebugEventLoopBacktrace);
924 CtdlRegisterDebugFlagHook(HKEY("curl"), DebugCurlEnable, &DebugCurl);
927 CtdlThreadCreate(client_event_thread);
928 CtdlThreadCreate(db_event_thread);