Mercurial > masqmail
annotate src/online.c @ 434:f2a7271746d1 default tip
Removes Freshmeat.net from the docs
The site, which was later renamed to freecode.com, is no longer
maintained (contains only a static copy).
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Sat, 07 Feb 2015 11:45:07 +0100 |
parents | b27f66555ba8 |
children |
rev | line source |
---|---|
367
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
1 /* |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
2 ** MasqMail |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
3 ** Copyright (C) 1999-2001 Oliver Kurth |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
4 ** Copyright (C) 2008, 2010 markus schnalke <meillo@marmaro.de> |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
5 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
6 ** This program is free software; you can redistribute it and/or modify |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
7 ** it under the terms of the GNU General Public License as published by |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
8 ** the Free Software Foundation; either version 2 of the License, or |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
9 ** (at your option) any later version. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
10 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
11 ** This program is distributed in the hope that it will be useful, |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
14 ** GNU General Public License for more details. |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
15 ** |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
16 ** You should have received a copy of the GNU General Public License |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
17 ** along with this program; if not, write to the Free Software |
b27f66555ba8
Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents:
366
diff
changeset
|
18 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
0 | 19 */ |
20 | |
21 #include <sys/wait.h> | |
15 | 22 |
0 | 23 #include "masqmail.h" |
24 #include "peopen.h" | |
25 | |
26 | |
310
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
27 gchar* |
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
28 online_query() |
279 | 29 { |
366
41958685480d
Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents:
310
diff
changeset
|
30 gchar *pipe = conf.online_query; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
31 pid_t pid; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
32 void (*old_signal) (int); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
33 int status; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
34 FILE *in; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
35 gchar *name = NULL; |
0 | 36 |
310
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
37 if (!conf.online_query) { |
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
38 return NULL; |
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
39 } |
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
40 DEBUG(3) debugf("online query `%s'\n", pipe); |
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
41 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
42 old_signal = signal(SIGCHLD, SIG_DFL); |
0 | 43 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
44 in = peopen(pipe, "r", environ, &pid); |
310
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
45 if (!in) { |
33 | 46 logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno)); |
47 signal(SIGCHLD, old_signal); | |
48 return NULL; | |
49 } | |
50 | |
51 gchar output[256]; | |
52 if (fgets(output, 255, in)) { | |
53 g_strchomp(g_strchug(output)); | |
54 if (strlen(output) == 0) { | |
55 logwrite(LOG_ALERT, "only whitespace connection name\n"); | |
56 name = NULL; | |
18
99c09ed776c1
fixed empty or only-whitespace connection names
meillo@marmaro.de
parents:
15
diff
changeset
|
57 } else { |
33 | 58 name = g_strdup(output); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
59 } |
33 | 60 } else { |
61 logwrite(LOG_ALERT, "nothing read from pipe %s\n", pipe); | |
62 name = NULL; | |
63 } | |
64 fclose(in); | |
65 waitpid(pid, &status, 0); | |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
208
diff
changeset
|
66 if (WEXITSTATUS(status) != 0) { |
33 | 67 g_free(name); |
68 name = NULL; | |
69 } | |
0 | 70 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
71 signal(SIGCHLD, old_signal); |
0 | 72 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
73 return name; |
0 | 74 } |