1 /* cvm/module_log.c - CVM server module logging functions
2  * Copyright (C) 2010  Bruce Guenter <bruce@untroubled.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
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  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18 #include <string.h>
19 #include <unistd.h>
20 #include "module.h"
21 
cvm_module_log_startup(void)22 void cvm_module_log_startup(void)
23 {
24   write(1, "Starting.\n", 10);
25 }
26 
cvm_module_log_shutdown(void)27 void cvm_module_log_shutdown(void)
28 {
29   write(1, "Stopping.\n", 10);
30 }
31 
cvm_module_log_request(void)32 void cvm_module_log_request(void)
33 {
34   char buf[BUFSIZE+4];
35   char* ptr;
36 
37   ptr = buf;
38   switch (cvm_module_outbuffer[0]) {
39   case 0: *ptr++ = '+'; break;
40   case CVME_PERMFAIL: *ptr++ = '-'; break;
41   default: *ptr++ = '?'; break;
42   }
43   *ptr++ = ' ';
44   if (cvm_module_credentials[CVM_CRED_ACCOUNT].s != 0) {
45     memcpy(ptr,
46 	   cvm_module_credentials[CVM_CRED_ACCOUNT].s,
47 	   cvm_module_credentials[CVM_CRED_ACCOUNT].len);
48     ptr += cvm_module_credentials[CVM_CRED_ACCOUNT].len;
49   }
50   if (cvm_module_credentials[CVM_CRED_DOMAIN].s != 0) {
51     *ptr++ = '@';
52     memcpy(ptr,
53 	   cvm_module_credentials[CVM_CRED_DOMAIN].s,
54 	   cvm_module_credentials[CVM_CRED_DOMAIN].len);
55     ptr += cvm_module_credentials[CVM_CRED_DOMAIN].len;
56   }
57   *ptr++ = '\n';
58   *ptr = 0;
59   write(1, buf, ptr-buf);
60 }
61