]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * charybdis: A slightly useful ircd. | |
3 | * libcharybdis.c: library entrypoint | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * Copyright (C) 2005 William Pitcock and Jilles Tjoelker | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
23 | * USA | |
24 | * | |
25 | * $Id: libcharybdis.c 386 2005-12-07 16:21:24Z nenolod $ | |
26 | */ | |
27 | ||
28 | #include "stdinc.h" | |
29 | #include "libcharybdis.h" | |
30 | ||
31 | static void (*log_callback)(const char *str) = NULL; | |
32 | static void (*restart_callback)(const char *str) = NULL; | |
33 | static void (*die_callback)(const char *str) = NULL; | |
34 | static char errbuf[BUFSIZE * 2]; | |
35 | ||
36 | void libcharybdis_log(const char *str, ...) | |
37 | { | |
38 | va_list args; | |
39 | ||
40 | if (log_callback == NULL) | |
41 | return; | |
42 | ||
43 | va_start(args, str); | |
44 | ircvsnprintf(errbuf, BUFSIZE * 2, str, args); | |
45 | va_end(args); | |
46 | ||
47 | log_callback(errbuf); | |
48 | } | |
49 | ||
50 | void libcharybdis_restart(const char *str, ...) | |
51 | { | |
52 | va_list args; | |
53 | ||
54 | if (restart_callback == NULL) | |
55 | return; | |
56 | ||
57 | va_start(args, str); | |
58 | ircvsnprintf(errbuf, BUFSIZE * 2, str, args); | |
59 | va_end(args); | |
60 | ||
61 | restart_callback(errbuf); | |
62 | } | |
63 | ||
64 | void libcharybdis_die(const char *str, ...) | |
65 | { | |
66 | va_list args; | |
67 | ||
68 | if (die_callback == NULL) | |
69 | return; | |
70 | ||
71 | va_start(args, str); | |
72 | ircvsnprintf(errbuf, BUFSIZE * 2, str, args); | |
73 | va_end(args); | |
74 | ||
75 | die_callback(errbuf); | |
76 | } | |
77 | ||
78 | void libcharybdis_init(void (*log_cb)(const char *str), | |
79 | void (*restart_cb)(const char *str), void (*die_cb)(const char *str)) | |
80 | { | |
81 | log_callback = log_cb; | |
82 | restart_callback = restart_cb; | |
83 | die_callback = die_cb; | |
84 | ||
85 | fdlist_init(); | |
86 | init_netio(); | |
87 | eventInit(); | |
88 | initBlockHeap(); | |
89 | init_dlink_nodes(); | |
90 | linebuf_init(); | |
91 | } |