]>
jfr.im git - irc/thales.git/blob - src/irc.c
1 /* Main irc module of GNU Thales. Copyright (C)
2 2012 Free Software Foundation, Inc. This file is part of GNU Thales.
4 GNU Thales is free software; you can redistribute it and/or modify it under the
5 terms of the GNU General Public License as published by the Free Software
6 Foundation; either version 3 of the License, or (at your option) any later
9 GNU Make is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <http://www.gnu.org/licenses/>. */
23 config_error(const char *msg
)
25 printf("config error: %s\n");
30 count_occurences(const char *str
, char c
)
34 for (const char *p
= str
; *p
; ++p
)
39 split_at(const char *str
, char delim
)
42 const char *delim_ptr
= str
;
43 /* Alloc NULL-terminated array of strings */
44 result
= xcalloc (count_occurences(str
, delim
)+2, sizeof(char *));
46 for (int index
= 0; *(delim_ptr
= strchr(str
, delim
)); str
= delim
)
47 result
[index
] = strndup(str
, delim_ptr
- str
-1);
53 parse_irc_config(struct irc_options
*irc_opts
, const struct envz
*env
)
55 const char *host
= envz_get(env
->envz
, env
->envz_len
, "host");
56 const char *str_port
= envz_get(env
->envz
, env
->envz_len
, "port");
57 const char *str_channels
= envz_get(env
->envz
, env
->envz_len
, "channels");
58 irc_opts
->host
= host
;
59 irc_opts
->port
= str_port
? atoi(str_port
) : 0;
62 return config_error("no host specified");
64 return config_error("incorrect port");
66 return config_error("No channels specified");
67 irc_opts
->channels
= split_at(str_channels
, ',');