1 /* $Id: error.c 448 2010-08-22 09:20:48Z tsaviran $
2  * -------------------------------------------------------
3  * Copyright (C) 2003-2006 Tommi Saviranta <wnd@iki.fi>
4  * -------------------------------------------------------
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
15 
16 #ifdef HAVE_CONFIG_H
17 #include <config.h>
18 #endif /* ifdef HAVE_CONFIG_H */
19 
20 #include "tools.h"
21 #ifndef TESTING
22 #include "irc.h"
23 #endif /* ifndef TESTING */
24 #include "client.h"
25 #include "miau.h"
26 
27 #include <stdio.h>
28 #include <stdarg.h>
29 
30 
31 
32 #define ERRBUFSIZE	256
33 
34 
35 
36 #ifdef ENDUSERDEBUG
37 #define ENDUSER_BUF_SIZE	8196
38 
39 void
enduserdebug(char * format,...)40 enduserdebug(char *format, ...)
41 {
42 	va_list va;
43 	char buf0[ENDUSER_BUF_SIZE];
44 
45 	va_start(va, format);
46 	vsnprintf(buf0, ENDUSER_BUF_SIZE, format, va);
47 	va_end(va);
48 	buf0[ENDUSER_BUF_SIZE - 1] = '\0';
49 #ifndef TESTING
50 	if (c_clients.connected > 0) {
51 		char buf1[ENDUSER_BUF_SIZE + 160];
52 		/* termination and validity guaranteed */
53 		snprintf(buf1, ENDUSER_BUF_SIZE + 159,
54 				":debug PRIVMSG %s :%s: %s",
55 				status.nickname,
56 				get_timestamp(NULL, TIMESTAMP_LONG),
57 				buf0);
58 		buf1[ENDUSER_BUF_SIZE + 159] = '\0';
59 		irc_mwrite(&c_clients, "%s", buf1);
60 	}
61 #endif /* ifndef TESTING */
62 } /* void enduserdebug(char *format, ...) */
63 #endif /* ifdef ENDUSERDEBUG */
64 
65 
66 
67 void
report(char * format,...)68 report(char *format, ...)
69 {
70 	char	buffer[ERRBUFSIZE];
71 	va_list	va;
72 
73 	va_start(va, format);
74 	vsnprintf(buffer, ERRBUFSIZE, format, va);
75 	va_end(va);
76 	buffer[ERRBUFSIZE - 1] = '\0';
77 
78 	fprintf(stdout, "%s + %s\n", get_short_localtime(), buffer);
79 #ifndef TESTING
80 	irc_mnotice(&c_clients, status.nickname, "%s", buffer);
81 #endif /* ifndef TESTING */
82 } /* void report(char *format, ...) */
83 
84 
85 
86 void
error(char * format,...)87 error(char *format, ...)
88 {
89 	char buffer[ERRBUFSIZE];
90 	va_list va;
91 
92 	va_start(va, format);
93 	vsnprintf(buffer, ERRBUFSIZE, format, va);
94 	va_end(va);
95 	buffer[ERRBUFSIZE - 1] = '\0';
96 
97 	fprintf(stdout, "%s - %s\n", get_short_localtime(), buffer);
98 #ifndef TESTING
99 	irc_mnotice(&c_clients, status.nickname, "%s", buffer);
100 #endif /* ifndef TESTING */
101 } /* void error(char *format, ...) */
102