Silence logging in non-debug usecases. The raspii users gonna love this.
[citadel.git] / citadel / modules / ctdlproto / serv_ctdlproto.c
1 /* 
2  * Citadel protocoll main dispatcher
3  *
4  * Copyright (c) 1987-2015 by the citadel.org team
5  *
6  * This program is open source software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License, version 3.
8  *
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.
13  */
14
15 #include <stdio.h>
16 #include <libcitadel.h>
17
18 #include "citserver.h"
19 #include "ctdl_module.h"
20 #include "config.h"
21 /*
22  * This loop recognizes all server commands.
23  */
24 void do_command_loop(void) {
25         struct CitContext *CCC = CC;
26         char cmdbuf[SIZ];
27         
28         time(&CCC->lastcmd);
29         memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
30         if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
31                 CTDLM_syslog(LOG_INFO, "Citadel client disconnected: ending session.");
32                 CCC->kill_me = KILLME_CLIENT_DISCONNECTED;
33                 return;
34         }
35
36         /* Log the server command, but don't show passwords... */
37         if ( (strncasecmp(cmdbuf, "PASS", 4)) && (strncasecmp(cmdbuf, "SETP", 4)) ) {
38                 CTDL_syslog(LOG_DEBUG, "[%s(%ld)] %s",
39                         CCC->curr_user, CCC->user.usernum, cmdbuf
40                 );
41         }
42         else {
43                 CTDL_syslog(LOG_DEBUG, "[%s(%ld)] <password command hidden from log>",
44                             CCC->curr_user, CCC->user.usernum
45                 );
46         }
47
48         buffer_output();
49
50         /*
51          * Let other clients see the last command we executed, and
52          * update the idle time, but not NOOP, QNOP, PEXP, GEXP, RWHO, or TIME.
53          */
54         if ( (strncasecmp(cmdbuf, "NOOP", 4))
55            && (strncasecmp(cmdbuf, "QNOP", 4))
56            && (strncasecmp(cmdbuf, "PEXP", 4))
57            && (strncasecmp(cmdbuf, "GEXP", 4))
58            && (strncasecmp(cmdbuf, "RWHO", 4))
59            && (strncasecmp(cmdbuf, "TIME", 4)) ) {
60                 strcpy(CCC->lastcmdname, "    ");
61                 safestrncpy(CCC->lastcmdname, cmdbuf, sizeof(CCC->lastcmdname));
62                 time(&CCC->lastidle);
63         }
64         
65         if ((strncasecmp(cmdbuf, "ENT0", 4))
66            && (strncasecmp(cmdbuf, "MESG", 4))
67            && (strncasecmp(cmdbuf, "MSGS", 4)))
68         {
69            CCC->cs_flags &= ~CS_POSTING;
70         }
71                    
72         if (!DLoader_Exec_Cmd(cmdbuf)) {
73                 cprintf("%d Unrecognized or unsupported command.\n", ERROR + CMD_NOT_SUPPORTED);
74         }       
75
76         unbuffer_output();
77
78         /* Run any after-each-command routines registered by modules */
79         PerformSessionHooks(EVT_CMD);
80 }
81