Mercurial > masqmail
comparison src/mserver.c @ 10:26e34ae9a3e3
changed indention and line wrapping to a more consistent style
author | meillo@marmaro.de |
---|---|
date | Mon, 27 Oct 2008 16:23:10 +0100 |
parents | 08114f7dcc23 |
children |
comparison
equal
deleted
inserted
replaced
9:31cc8a89cb74 | 10:26e34ae9a3e3 |
---|---|
20 #include "readsock.h" | 20 #include "readsock.h" |
21 #include "mserver.h" | 21 #include "mserver.h" |
22 | 22 |
23 #ifdef ENABLE_MSERVER | 23 #ifdef ENABLE_MSERVER |
24 | 24 |
25 gchar *mserver_detect_online(interface *iface) | 25 gchar* |
26 mserver_detect_online(interface * iface) | |
26 { | 27 { |
27 struct sockaddr_in saddr; | 28 struct sockaddr_in saddr; |
28 gchar *ret = NULL; | 29 gchar *ret = NULL; |
29 | 30 |
30 if(init_sockaddr(&saddr, iface)){ | 31 if (init_sockaddr(&saddr, iface)) { |
31 int sock = socket(PF_INET, SOCK_STREAM, 0); | 32 int sock = socket(PF_INET, SOCK_STREAM, 0); |
32 int dup_sock; | 33 int dup_sock; |
33 if(connect(sock, (struct sockaddr *)(&saddr), sizeof(saddr)) == 0){ | 34 if (connect(sock, (struct sockaddr *) (&saddr), sizeof(saddr)) == 0) { |
34 FILE *in, *out; | 35 FILE *in, *out; |
35 char buf[256]; | 36 char buf[256]; |
36 | 37 |
37 dup_sock = dup(sock); | 38 dup_sock = dup(sock); |
38 out = fdopen(sock, "w"); | 39 out = fdopen(sock, "w"); |
39 in = fdopen(dup_sock, "r"); | 40 in = fdopen(dup_sock, "r"); |
40 | 41 |
41 if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){ | 42 if (read_sockline(in, buf, 256, 15, READSOCKL_CHUG)) { |
42 if(strncmp(buf, "READY", 5) == 0){ | 43 if (strncmp(buf, "READY", 5) == 0) { |
43 fprintf(out, "STAT\n"); fflush(out); | 44 fprintf(out, "STAT\n"); |
44 if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){ | 45 fflush(out); |
45 if(strncmp(buf, "DOWN", 4) == 0){ | 46 if (read_sockline(in, buf, 256, 15, READSOCKL_CHUG)) { |
46 ret = NULL; | 47 if (strncmp(buf, "DOWN", 4) == 0) { |
47 }else if(strncmp(buf, "UP", 2) == 0){ | 48 ret = NULL; |
48 gchar *p = buf+3; | 49 } else if (strncmp(buf, "UP", 2) == 0) { |
49 while((*p != ':') && *p) p++; | 50 gchar *p = buf + 3; |
50 if(*p){ | 51 while ((*p != ':') && *p) |
51 *p = 0; | 52 p++; |
52 p++; | 53 if (*p) { |
53 if((atoi(p) >= 0) && *p) | 54 *p = 0; |
54 ret = g_strdup(buf+3); | 55 p++; |
55 }else | 56 if ((atoi(p) >= 0) && *p) |
56 logwrite(LOG_ALERT, | 57 ret = g_strdup(buf + 3); |
57 "unexpected response from mserver after STAT cmd: %s", | 58 } else |
58 buf); | 59 logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf); |
59 }else{ | 60 } else { |
60 logwrite(LOG_ALERT, | 61 logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf); |
61 "unexpected response from mserver after STAT cmd: %s", | 62 } |
62 buf); | 63 } |
63 } | 64 } |
64 } | 65 fprintf(out, "QUIT"); |
66 fflush(out); | |
67 | |
68 close(sock); | |
69 close(dup_sock); | |
70 fclose(in); | |
71 fclose(out); | |
72 } | |
73 } | |
65 } | 74 } |
66 fprintf(out, "QUIT"); fflush(out); | 75 return ret; |
67 | |
68 close(sock); | |
69 close(dup_sock); | |
70 fclose(in); | |
71 fclose(out); | |
72 } | |
73 } | |
74 } | |
75 return ret; | |
76 } | 76 } |
77 | 77 |
78 #endif | 78 #endif |