masqmail
view src/mserver.c @ 8:7e01b9096bb6
removed tests from Makefiles
author | meillo@marmaro.de |
---|---|
date | Mon, 27 Oct 2008 16:20:41 +0100 |
parents | |
children | 26e34ae9a3e3 |
line source
1 /* MasqMail
2 Copyright (C) 1999/2000/2001 Oliver Kurth
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
19 #include "masqmail.h"
20 #include "readsock.h"
21 #include "mserver.h"
23 #ifdef ENABLE_MSERVER
25 gchar *mserver_detect_online(interface *iface)
26 {
27 struct sockaddr_in saddr;
28 gchar *ret = NULL;
30 if(init_sockaddr(&saddr, iface)){
31 int sock = socket(PF_INET, SOCK_STREAM, 0);
32 int dup_sock;
33 if(connect(sock, (struct sockaddr *)(&saddr), sizeof(saddr)) == 0){
34 FILE *in, *out;
35 char buf[256];
37 dup_sock = dup(sock);
38 out = fdopen(sock, "w");
39 in = fdopen(dup_sock, "r");
41 if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
42 if(strncmp(buf, "READY", 5) == 0){
43 fprintf(out, "STAT\n"); fflush(out);
44 if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
45 if(strncmp(buf, "DOWN", 4) == 0){
46 ret = NULL;
47 }else if(strncmp(buf, "UP", 2) == 0){
48 gchar *p = buf+3;
49 while((*p != ':') && *p) p++;
50 if(*p){
51 *p = 0;
52 p++;
53 if((atoi(p) >= 0) && *p)
54 ret = g_strdup(buf+3);
55 }else
56 logwrite(LOG_ALERT,
57 "unexpected response from mserver after STAT cmd: %s",
58 buf);
59 }else{
60 logwrite(LOG_ALERT,
61 "unexpected response from mserver after STAT cmd: %s",
62 buf);
63 }
64 }
65 }
66 fprintf(out, "QUIT"); fflush(out);
68 close(sock);
69 close(dup_sock);
70 fclose(in);
71 fclose(out);
72 }
73 }
74 }
75 return ret;
76 }
78 #endif