annotate src/mservdetect.c @ 168:8630e37ae445

merge
author meillo@marmaro.de
date Tue, 13 Jul 2010 22:54:25 +0200
parents 5b621742b2e7
children bd7c52a36b0c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
1 /* MasqMail
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
2 Copyright (C) 1999-2001 Oliver Kurth
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
3
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
7 (at your option) any later version.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
8
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
12 GNU General Public License for more details.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
13
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
15 along with this program; if not, write to the Free Software
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
17 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
18
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
19
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
20 #include "config.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
21 #include "masqmail.h"
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
22 #include "readsock.h"
164
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
23
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
24
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
25 gchar*
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
26 mserver_detect_online(interface * iface)
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
27 {
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
28 struct sockaddr_in saddr;
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
29 gchar *ret = NULL;
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
30
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
31 if (init_sockaddr(&saddr, iface)) {
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
32 int sock = socket(PF_INET, SOCK_STREAM, 0);
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
33 int dup_sock;
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
34 if (connect(sock, (struct sockaddr *) (&saddr), sizeof(saddr)) == 0) {
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
35 FILE *in, *out;
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
36 char buf[256];
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
37
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
38 dup_sock = dup(sock);
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
39 out = fdopen(sock, "w");
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
40 in = fdopen(dup_sock, "r");
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
41
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
42 if (read_sockline(in, buf, 256, 15, READSOCKL_CHUG)) {
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
43 if (strncmp(buf, "READY", 5) == 0) {
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
44 fprintf(out, "STAT\n");
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
45 fflush(out);
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
46 if (read_sockline(in, buf, 256, 15, READSOCKL_CHUG)) {
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
47 if (strncmp(buf, "DOWN", 4) == 0) {
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
48 ret = NULL;
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
49 } else if (strncmp(buf, "UP", 2) == 0) {
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
50 gchar *p = buf + 3;
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
51 while ((*p != ':') && *p)
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
52 p++;
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
53 if (*p) {
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
54 *p = 0;
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
55 p++;
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
56 if ((atoi(p) >= 0) && *p)
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
57 ret = g_strdup(buf + 3);
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
58 } else
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
59 logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf);
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
60 } else {
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
61 logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf);
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
62 }
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
63 }
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
64 }
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
65 fprintf(out, "QUIT");
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
66 fflush(out);
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
67
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
68 close(sock);
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
69 close(dup_sock);
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
70 fclose(in);
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
71 fclose(out);
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
72 }
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
73 }
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
74 }
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
75 return ret;
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
76 }
5b621742b2e7 removed the mserver feature
meillo@marmaro.de
parents: 10
diff changeset
77
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
78
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
79 void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
80 logwrite(int pri, const char *fmt, ...)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
81 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
82 va_list args;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
83 va_start(args, fmt);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
84
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
85 vfprintf(stdout, fmt, args);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
86
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
87 va_end(args);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
88 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
89
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
90 void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
91 debugf(const char *fmt, ...)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
92 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
93 va_list args;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
94 va_start(args, fmt);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
95
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
96 vfprintf(stdout, fmt, args);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
97
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
98 va_end(args);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
99 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
100
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
101 int
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
102 main(int argc, char *argv[])
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
103 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
104 if (argc == 3) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
105 interface iface;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
106 gchar *name;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
107
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
108 iface.address = g_strdup(argv[1]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
109 iface.port = atoi(argv[2]);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
110
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
111 name = mserver_detect_online(&iface);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
112
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
113 printf("%s\n", name);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
114
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
115 exit(EXIT_SUCCESS);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
116 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
117 fprintf(stderr, "usage %s <host> <port>\n", argv[0]);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
118 exit(EXIT_FAILURE);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
119 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
120 }