9c6fb5a7b73f62d88ba397ea049fcf53344d9027
[citadel.git] / citadel / modules / network / serv_network.c
1 /*
2  * This module handles shared rooms, inter-Citadel mail, and outbound
3  * mailing list processing.
4  *
5  * Copyright (c) 2000-2012 by the citadel.org team
6  *
7  *  This program is open source software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  * ** NOTE **   A word on the S_NETCONFIGS semaphore:
22  * This is a fairly high-level type of critical section.  It ensures that no
23  * two threads work on the netconfigs files at the same time.  Since we do
24  * so many things inside these, here are the rules:
25  *  1. begin_critical_section(S_NETCONFIGS) *before* begin_ any others.
26  *  2. Do *not* perform any I/O with the client during these sections.
27  *
28  */
29
30 /*
31  * Duration of time (in seconds) after which pending list subscribe/unsubscribe
32  * requests that have not been confirmed will be deleted.
33  */
34 #define EXP     259200  /* three days */
35
36 #include "sysdep.h"
37 #include <stdlib.h>
38 #include <unistd.h>
39 #include <stdio.h>
40 #include <fcntl.h>
41 #include <ctype.h>
42 #include <signal.h>
43 #include <pwd.h>
44 #include <errno.h>
45 #include <sys/stat.h>
46 #include <sys/types.h>
47 #include <dirent.h>
48 #if TIME_WITH_SYS_TIME
49 # include <sys/time.h>
50 # include <time.h>
51 #else
52 # if HAVE_SYS_TIME_H
53 #  include <sys/time.h>
54 # else
55 #  include <time.h>
56 # endif
57 #endif
58 #ifdef HAVE_SYSCALL_H
59 # include <syscall.h>
60 #else 
61 # if HAVE_SYS_SYSCALL_H
62 #  include <sys/syscall.h>
63 # endif
64 #endif
65
66 #include <sys/wait.h>
67 #include <string.h>
68 #include <limits.h>
69 #include <libcitadel.h>
70 #include "citadel.h"
71 #include "server.h"
72 #include "citserver.h"
73 #include "support.h"
74 #include "config.h"
75 #include "user_ops.h"
76 #include "database.h"
77 #include "msgbase.h"
78 #include "internet_addressing.h"
79 #include "serv_network.h"
80 #include "clientsocket.h"
81 #include "file_ops.h"
82 #include "citadel_dirs.h"
83 #include "threads.h"
84
85 #ifndef HAVE_SNPRINTF
86 #include "snprintf.h"
87 #endif
88
89 #include "context.h"
90 #include "netconfig.h"
91 #include "netspool.h"
92 #include "netmail.h"
93 #include "ctdl_module.h"
94
95 int NetQDebugEnabled = 0;
96 struct CitContext networker_spool_CC;
97
98 /* comes from lookup3.c from libcitadel... */
99 extern uint32_t hashlittle( const void *key, size_t length, uint32_t initval);
100
101 typedef struct __roomlists {
102         RoomProcList *rplist;
103         HashList *RoomsInterestedIn;
104 }roomlists;
105 /*
106  * When we do network processing, it's accomplished in two passes; one to
107  * gather a list of rooms and one to actually do them.  It's ok that rplist
108  * is global; we have a mutex that keeps it safe.
109  */
110 struct RoomProcList *rplist = NULL;
111
112 int GetNetworkedRoomNumbers(const char *DirName, HashList *DirList)
113 {
114         DIR *filedir = NULL;
115         struct dirent *d;
116         struct dirent *filedir_entry;
117         long RoomNR;
118         long Count = 0;
119                 
120         filedir = opendir (DirName);
121         if (filedir == NULL) {
122                 return 0;
123         }
124
125         d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 1);
126         if (d == NULL) {
127                 return 0;
128         }
129
130         while ((readdir_r(filedir, d, &filedir_entry) == 0) &&
131                (filedir_entry != NULL))
132         {
133                 RoomNR = atol(filedir_entry->d_name);
134                 if (RoomNR != 0) {
135                         Count++;
136                         Put(DirList, LKEY(RoomNR), &Count, reference_free_handler);
137                 }
138         }
139         free(d);
140         closedir(filedir);
141         return Count;
142 }
143
144
145
146
147 /*
148  * Check the use table.  This is a list of messages which have recently
149  * arrived on the system.  It is maintained and queried to prevent the same
150  * message from being entered into the database multiple times if it happens
151  * to arrive multiple times by accident.
152  */
153 int network_usetable(struct CtdlMessage *msg)
154 {
155         struct CitContext *CCC = CC;
156         char msgid[SIZ];
157         struct cdbdata *cdbut;
158         struct UseTable ut;
159
160         /* Bail out if we can't generate a message ID */
161         if (msg == NULL) {
162                 return(0);
163         }
164         if (msg->cm_fields['I'] == NULL) {
165                 return(0);
166         }
167         if (IsEmptyStr(msg->cm_fields['I'])) {
168                 return(0);
169         }
170
171         /* Generate the message ID */
172         strcpy(msgid, msg->cm_fields['I']);
173         if (haschar(msgid, '@') == 0) {
174                 strcat(msgid, "@");
175                 if (msg->cm_fields['N'] != NULL) {
176                         strcat(msgid, msg->cm_fields['N']);
177                 }
178                 else {
179                         return(0);
180                 }
181         }
182
183         cdbut = cdb_fetch(CDB_USETABLE, msgid, strlen(msgid));
184         if (cdbut != NULL) {
185                 cdb_free(cdbut);
186                 QN_syslog(LOG_DEBUG, "network_usetable() : we already have %s\n", msgid);
187                 return(1);
188         }
189
190         /* If we got to this point, it's unique: add it. */
191         strcpy(ut.ut_msgid, msgid);
192         ut.ut_timestamp = time(NULL);
193         cdb_store(CDB_USETABLE, msgid, strlen(msgid), &ut, sizeof(struct UseTable) );
194         return(0);
195 }
196
197
198
199
200
201
202
203
204
205
206 /*
207  * Send the *entire* contents of the current room to one specific network node,
208  * ignoring anything we know about which messages have already undergone
209  * network processing.  This can be used to bring a new node into sync.
210  */
211 int network_sync_to(char *target_node, long len)
212 {
213         struct CitContext *CCC = CC;
214         SpoolControl sc;
215         int num_spooled = 0;
216         int found_node = 0;
217         char buf[256];
218         char sc_type[256];
219         char sc_node[256];
220         char sc_room[256];
221         char filename[PATH_MAX];
222         FILE *fp;
223
224         /* Grab the configuration line we're looking for */
225         assoc_file_name(filename, sizeof filename, &CC->room, ctdl_netcfg_dir);
226         begin_critical_section(S_NETCONFIGS);
227         fp = fopen(filename, "r");
228         if (fp == NULL) {
229                 end_critical_section(S_NETCONFIGS);
230                 return(-1);
231         }
232         while (fgets(buf, sizeof buf, fp) != NULL)
233         {
234                 buf[strlen(buf)-1] = 0;
235
236                 extract_token(sc_type, buf, 0, '|', sizeof sc_type);
237                 if (strcasecmp(sc_type, "ignet_push_share"))
238                         continue;
239
240                 extract_token(sc_node, buf, 1, '|', sizeof sc_node);
241                 if (strcasecmp(sc_node, target_node))
242                         continue;
243
244                 extract_token(sc_room, buf, 2, '|', sizeof sc_room);
245                 found_node = 1;
246                         
247                 /* Concise syntax because we don't need a full linked-list */
248                 memset(&sc, 0, sizeof(SpoolControl));
249                 sc.ignet_push_shares = (maplist *)
250                         malloc(sizeof(maplist));
251                 sc.ignet_push_shares->next = NULL;
252                 safestrncpy(sc.ignet_push_shares->remote_nodename,
253                             sc_node,
254                             sizeof sc.ignet_push_shares->remote_nodename);
255                 safestrncpy(sc.ignet_push_shares->remote_roomname,
256                             sc_room,
257                             sizeof sc.ignet_push_shares->remote_roomname);
258         }
259         fclose(fp);
260         end_critical_section(S_NETCONFIGS);
261
262         if (!found_node) {
263                 free(sc.ignet_push_shares);
264                 return(-1);
265         }
266
267         sc.working_ignetcfg = load_ignetcfg();
268         sc.the_netmap = read_network_map();
269
270         /* Send ALL messages */
271         num_spooled = CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL,
272                 network_spool_msg, &sc);
273
274         /* Concise cleanup because we know there's only one node in the sc */
275         free(sc.ignet_push_shares);
276
277         DeleteHash(&sc.working_ignetcfg);
278         DeleteHash(&sc.the_netmap);
279
280         QN_syslog(LOG_NOTICE, "Synchronized %d messages to <%s>\n",
281                   num_spooled, target_node);
282         return(num_spooled);
283 }
284
285
286 /*
287  * Implements the NSYN command
288  */
289 void cmd_nsyn(char *argbuf) {
290         int num_spooled;
291         long len;
292         char target_node[256];
293
294         if (CtdlAccessCheck(ac_aide)) return;
295
296         len = extract_token(target_node, argbuf, 0, '|', sizeof target_node);
297         num_spooled = network_sync_to(target_node, len);
298         if (num_spooled >= 0) {
299                 cprintf("%d Spooled %d messages.\n", CIT_OK, num_spooled);
300         }
301         else {
302                 cprintf("%d No such room/node share exists.\n",
303                         ERROR + ROOM_NOT_FOUND);
304         }
305 }
306
307
308
309 /*
310  * Batch up and send all outbound traffic from the current room
311  */
312 void network_queue_interesting_rooms(struct ctdlroom *qrbuf, void *data) {
313         int i;
314         struct RoomProcList *ptr;
315         long QRNum = qrbuf->QRnumber;
316         void *v;
317         roomlists *RP = (roomlists*) data;
318
319         if (!GetHash(RP->RoomsInterestedIn, LKEY(QRNum), &v))
320                 return;
321
322         ptr = (struct RoomProcList *) malloc(sizeof (struct RoomProcList));
323         if (ptr == NULL) return;
324
325         ptr->namelen = strlen(qrbuf->QRname);
326         if (ptr->namelen > ROOMNAMELEN)
327                 ptr->namelen = ROOMNAMELEN - 1;
328
329         memcpy (ptr->name, qrbuf->QRname, ptr->namelen);
330         ptr->name[ptr->namelen] = '\0';
331         ptr->QRNum = qrbuf->QRnumber;
332
333         for (i = 0; i < ptr->namelen; i++)
334         {
335                 ptr->lcname[i] = tolower(ptr->name[i]);
336         }
337
338         ptr->lcname[ptr->namelen] = '\0';
339         ptr->key = hashlittle(ptr->lcname, ptr->namelen, 9872345);
340         ptr->next = RP->rplist;
341         RP->rplist = ptr;
342 }
343
344 /*
345  * Batch up and send all outbound traffic from the current room
346  */
347 void network_queue_room(struct ctdlroom *qrbuf, void *data) {
348         int i;
349         struct RoomProcList *ptr;
350
351         if (qrbuf->QRdefaultview == VIEW_QUEUE)
352                 return;
353         ptr = (struct RoomProcList *) malloc(sizeof (struct RoomProcList));
354         if (ptr == NULL) return;
355
356         ptr->namelen = strlen(qrbuf->QRname);
357         if (ptr->namelen > ROOMNAMELEN)
358                 ptr->namelen = ROOMNAMELEN - 1;
359
360         memcpy (ptr->name, qrbuf->QRname, ptr->namelen);
361         ptr->name[ptr->namelen] = '\0';
362         ptr->QRNum = qrbuf->QRnumber;
363
364         for (i = 0; i < ptr->namelen; i++)
365         {
366                 ptr->lcname[i] = tolower(ptr->name[i]);
367         }
368         ptr->lcname[ptr->namelen] = '\0';
369         ptr->key = hashlittle(ptr->lcname, ptr->namelen, 9872345);
370
371         begin_critical_section(S_RPLIST);
372         ptr->next = rplist;
373         rplist = ptr;
374         end_critical_section(S_RPLIST);
375 }
376
377 void destroy_network_queue_room(RoomProcList *rplist)
378 {
379         struct RoomProcList *cur, *p;
380
381         cur = rplist;
382         while (cur != NULL)
383         {
384                 p = cur->next;
385                 free (cur);
386                 cur = p;                
387         }
388 }
389
390 void destroy_network_queue_room_locked (void)
391 {
392         begin_critical_section(S_RPLIST);
393         destroy_network_queue_room(rplist);
394         end_critical_section(S_RPLIST);
395 }
396
397
398
399 /*
400  * Bounce a message back to the sender
401  */
402 void network_bounce(struct CtdlMessage *msg, char *reason)
403 {
404         struct CitContext *CCC = CC;
405         char *oldpath = NULL;
406         char buf[SIZ];
407         char bouncesource[SIZ];
408         char recipient[SIZ];
409         struct recptypes *valid = NULL;
410         char force_room[ROOMNAMELEN];
411         static int serialnum = 0;
412         size_t size;
413
414         QNM_syslog(LOG_DEBUG, "entering network_bounce()\n");
415
416         if (msg == NULL) return;
417
418         snprintf(bouncesource, sizeof bouncesource, "%s@%s", BOUNCESOURCE, config.c_nodename);
419
420         /* 
421          * Give it a fresh message ID
422          */
423         if (msg->cm_fields['I'] != NULL) {
424                 free(msg->cm_fields['I']);
425         }
426         snprintf(buf, sizeof buf, "%ld.%04lx.%04x@%s",
427                 (long)time(NULL), (long)getpid(), ++serialnum, config.c_fqdn);
428         msg->cm_fields['I'] = strdup(buf);
429
430         /*
431          * FIXME ... right now we're just sending a bounce; we really want to
432          * include the text of the bounced message.
433          */
434         if (msg->cm_fields['M'] != NULL) {
435                 free(msg->cm_fields['M']);
436         }
437         msg->cm_fields['M'] = strdup(reason);
438         msg->cm_format_type = 0;
439
440         /*
441          * Turn the message around
442          */
443         if (msg->cm_fields['R'] == NULL) {
444                 free(msg->cm_fields['R']);
445         }
446
447         if (msg->cm_fields['D'] == NULL) {
448                 free(msg->cm_fields['D']);
449         }
450
451         snprintf(recipient, sizeof recipient, "%s@%s",
452                 msg->cm_fields['A'], msg->cm_fields['N']);
453
454         if (msg->cm_fields['A'] == NULL) {
455                 free(msg->cm_fields['A']);
456         }
457
458         if (msg->cm_fields['N'] == NULL) {
459                 free(msg->cm_fields['N']);
460         }
461
462         if (msg->cm_fields['U'] == NULL) {
463                 free(msg->cm_fields['U']);
464         }
465
466         msg->cm_fields['A'] = strdup(BOUNCESOURCE);
467         msg->cm_fields['N'] = strdup(config.c_nodename);
468         msg->cm_fields['U'] = strdup("Delivery Status Notification (Failure)");
469
470         /* prepend our node to the path */
471         if (msg->cm_fields['P'] != NULL) {
472                 oldpath = msg->cm_fields['P'];
473                 msg->cm_fields['P'] = NULL;
474         }
475         else {
476                 oldpath = strdup("unknown_user");
477         }
478         size = strlen(oldpath) + SIZ;
479         msg->cm_fields['P'] = malloc(size);
480         snprintf(msg->cm_fields['P'], size, "%s!%s", config.c_nodename, oldpath);
481         free(oldpath);
482
483         /* Now submit the message */
484         valid = validate_recipients(recipient, NULL, 0);
485         if (valid != NULL) if (valid->num_error != 0) {
486                 free_recipients(valid);
487                 valid = NULL;
488         }
489         if ( (valid == NULL) || (!strcasecmp(recipient, bouncesource)) ) {
490                 strcpy(force_room, config.c_aideroom);
491         }
492         else {
493                 strcpy(force_room, "");
494         }
495         if ( (valid == NULL) && IsEmptyStr(force_room) ) {
496                 strcpy(force_room, config.c_aideroom);
497         }
498         CtdlSubmitMsg(msg, valid, force_room, 0);
499
500         /* Clean up */
501         if (valid != NULL) free_recipients(valid);
502         CtdlFreeMessage(msg);
503         QNM_syslog(LOG_DEBUG, "leaving network_bounce()\n");
504 }
505
506
507
508
509
510
511
512 /*
513  * network_do_queue()
514  * 
515  * Run through the rooms doing various types of network stuff.
516  */
517 void network_do_queue(void)
518 {
519         struct CitContext *CCC = CC;
520         static int doing_queue = 0;
521         static time_t last_run = 0L;
522         int full_processing = 1;
523         HashList *working_ignetcfg;
524         HashList *the_netmap = NULL;
525         int netmap_changed = 0;
526         roomlists RL;
527
528         /*
529          * Run the full set of processing tasks no more frequently
530          * than once every n seconds
531          */
532         if ( (time(NULL) - last_run) < config.c_net_freq ) {
533                 full_processing = 0;
534                 syslog(LOG_DEBUG, "Network full processing in %ld seconds.\n",
535                        config.c_net_freq - (time(NULL)- last_run)
536                 );
537         }
538
539         /*
540          * This is a simple concurrency check to make sure only one queue run
541          * is done at a time.  We could do this with a mutex, but since we
542          * don't really require extremely fine granularity here, we'll do it
543          * with a static variable instead.
544          */
545         if (doing_queue) {
546                 return;
547         }
548         doing_queue = 1;
549
550         become_session(&networker_spool_CC);
551         begin_critical_section(S_RPLIST);
552         RL.rplist = rplist;
553         rplist = NULL;
554         end_critical_section(S_RPLIST);
555
556         RL.RoomsInterestedIn = NewHash(1, lFlathash);
557         if (full_processing &&
558             (GetNetworkedRoomNumbers(ctdl_netcfg_dir, RL.RoomsInterestedIn)==0))
559         {
560                 doing_queue = 0;
561                 DeleteHash(&RL.RoomsInterestedIn);
562                 if (RL.rplist == NULL)
563                         return;
564         }
565         /* Load the IGnet Configuration into memory */
566         working_ignetcfg = load_ignetcfg();
567
568         /*
569          * Load the network map and filter list into memory.
570          */
571         if (!server_shutting_down)
572                 the_netmap = read_network_map();
573         if (!server_shutting_down)
574                 load_network_filter_list();
575
576         /* 
577          * Go ahead and run the queue
578          */
579         if (full_processing && !server_shutting_down) {
580                 QNM_syslog(LOG_DEBUG, "network: loading outbound queue");
581                 CtdlForEachRoom(network_queue_interesting_rooms, &RL);
582         }
583
584         if ((RL.rplist != NULL) && (!server_shutting_down)) {
585                 RoomProcList *ptr, *cmp;
586                 ptr = RL.rplist;
587                 QNM_syslog(LOG_DEBUG, "network: running outbound queue");
588                 while (ptr != NULL && !server_shutting_down) {
589                         
590                         cmp = ptr->next;
591
592                         while (cmp != NULL) {
593                                 if ((cmp->namelen > 0) &&
594                                     (cmp->key == ptr->key) &&
595                                     (cmp->namelen == ptr->namelen) &&
596                                     (strcmp(cmp->lcname, ptr->lcname) == 0))
597                                 {
598                                         cmp->namelen = 0;
599                                 }
600                                 cmp = cmp->next;
601                         }
602
603                         if (ptr->namelen > 0) {
604                                 network_spoolout_room(ptr, 
605                                                       working_ignetcfg,
606                                                       the_netmap);
607                         }
608                         ptr = ptr->next;
609                 }
610         }
611
612         /* If there is anything in the inbound queue, process it */
613         if (!server_shutting_down) {
614                 network_do_spoolin(working_ignetcfg, 
615                                    the_netmap,
616                                    &netmap_changed);
617         }
618
619         /* Free the filter list in memory */
620         free_netfilter_list();
621
622         /* Save the network map back to disk */
623         if (netmap_changed) {
624                 StrBuf *MapStr = SerializeNetworkMap(the_netmap);
625                 CtdlPutSysConfig(IGNETMAP, SmashStrBuf(&MapStr));
626         }
627
628         /* combine singe message files into one spool entry per remote node. */
629         network_consolidate_spoolout(working_ignetcfg, the_netmap);
630
631         /* shut down. */
632
633         DeleteHash(&the_netmap);
634
635         DeleteHash(&working_ignetcfg);
636
637         QNM_syslog(LOG_DEBUG, "network: queue run completed");
638
639         if (full_processing) {
640                 last_run = time(NULL);
641         }
642         DeleteHash(&RL.RoomsInterestedIn);
643         destroy_network_queue_room(RL.rplist);
644         doing_queue = 0;
645 }
646
647
648
649
650 int network_room_handler (struct ctdlroom *room)
651 {
652         network_queue_room(room, NULL);
653         return 0;
654 }
655
656 int NTTDebugEnabled = 0;
657
658 /*
659  * network_talking_to()  --  concurrency checker
660  */
661 static HashList *nttlist = NULL;
662 int network_talking_to(const char *nodename, long len, int operation) {
663
664         int retval = 0;
665         HashPos *Pos = NULL;
666         void *vdata;
667
668         begin_critical_section(S_NTTLIST);
669
670         switch(operation) {
671
672                 case NTT_ADD:
673                         if (nttlist == NULL) 
674                                 nttlist = NewHash(1, NULL);
675                         Put(nttlist, nodename, len, NewStrBufPlain(nodename, len), HFreeStrBuf);
676                         if (NTTDebugEnabled) syslog(LOG_DEBUG, "nttlist: added <%s>\n", nodename);
677                         break;
678                 case NTT_REMOVE:
679                         if ((nttlist == NULL) ||
680                             (GetCount(nttlist) == 0))
681                                 break;
682                         Pos = GetNewHashPos(nttlist, 1);
683                         if (GetHashPosFromKey (nttlist, nodename, len, Pos))
684                                 DeleteEntryFromHash(nttlist, Pos);
685                         DeleteHashPos(&Pos);
686                         if (NTTDebugEnabled) syslog(LOG_DEBUG, "nttlist: removed <%s>\n", nodename);
687
688                         break;
689
690                 case NTT_CHECK:
691                         if ((nttlist == NULL) ||
692                             (GetCount(nttlist) == 0))
693                                 break;
694                         if (GetHash(nttlist, nodename, len, &vdata))
695                                 retval ++;
696                         if (NTTDebugEnabled) syslog(LOG_DEBUG, "nttlist: have [%d] <%s>\n", retval, nodename);
697                         break;
698         }
699
700         end_critical_section(S_NTTLIST);
701         return(retval);
702 }
703
704 void cleanup_nttlist(void)
705 {
706         begin_critical_section(S_NTTLIST);
707         DeleteHash(&nttlist);
708         end_critical_section(S_NTTLIST);
709 }
710
711
712
713 void network_logout_hook(void)
714 {
715         CitContext *CCC = MyContext();
716
717         /*
718          * If we were talking to a network node, we're not anymore...
719          */
720         if (!IsEmptyStr(CCC->net_node)) {
721                 network_talking_to(CCC->net_node, strlen(CCC->net_node), NTT_REMOVE);
722                 CCC->net_node[0] = '\0';
723         }
724 }
725 void network_cleanup_function(void)
726 {
727         struct CitContext *CCC = CC;
728
729         if (!IsEmptyStr(CCC->net_node)) {
730                 network_talking_to(CCC->net_node, strlen(CCC->net_node), NTT_REMOVE);
731                 CCC->net_node[0] = '\0';
732         }
733 }
734
735
736 /*
737  * Module entry point
738  */
739 void SetNTTDebugEnabled(const int n)
740 {
741         NTTDebugEnabled = n;
742 }
743 void SetNetQDebugEnabled(const int n)
744 {
745         NetQDebugEnabled = n;
746 }
747
748 CTDL_MODULE_INIT(network)
749 {
750         if (!threading)
751         {
752                 CtdlFillSystemContext(&networker_spool_CC, "CitNetSpool");
753                 CtdlRegisterDebugFlagHook(HKEY("networktalkingto"), SetNTTDebugEnabled, &NTTDebugEnabled);
754                 CtdlRegisterDebugFlagHook(HKEY("networkqueue"), SetNetQDebugEnabled, &NetQDebugEnabled);
755                 CtdlRegisterCleanupHook(cleanup_nttlist);
756                 CtdlRegisterSessionHook(network_cleanup_function, EVT_STOP, PRIO_STOP + 30);
757                 CtdlRegisterSessionHook(network_logout_hook, EVT_LOGOUT, PRIO_LOGOUT + 10);
758                 CtdlRegisterProtoHook(cmd_nsyn, "NSYN", "Synchronize room to node");
759                 CtdlRegisterRoomHook(network_room_handler);
760                 CtdlRegisterCleanupHook(destroy_network_queue_room_locked);
761                 CtdlRegisterSessionHook(network_do_queue, EVT_TIMER, PRIO_QUEUE + 10);
762         }
763         return "network";
764 }