meillo@0: /* MasqMail meillo@0: Copyright (C) 1999/2000/2001 Oliver Kurth meillo@0: meillo@0: This program is free software; you can redistribute it and/or modify meillo@0: it under the terms of the GNU General Public License as published by meillo@0: the Free Software Foundation; either version 2 of the License, or meillo@0: (at your option) any later version. meillo@0: meillo@0: This program is distributed in the hope that it will be useful, meillo@0: but WITHOUT ANY WARRANTY; without even the implied warranty of meillo@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the meillo@0: GNU General Public License for more details. meillo@0: meillo@0: You should have received a copy of the GNU General Public License meillo@0: along with this program; if not, write to the Free Software meillo@0: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. meillo@0: */ meillo@0: meillo@0: #include "masqmail.h" meillo@0: #include "readsock.h" meillo@0: #include "mserver.h" meillo@0: meillo@0: #ifdef ENABLE_MSERVER meillo@0: meillo@0: gchar *mserver_detect_online(interface *iface) meillo@0: { meillo@0: struct sockaddr_in saddr; meillo@0: gchar *ret = NULL; meillo@0: meillo@0: if(init_sockaddr(&saddr, iface)){ meillo@0: int sock = socket(PF_INET, SOCK_STREAM, 0); meillo@0: int dup_sock; meillo@0: if(connect(sock, (struct sockaddr *)(&saddr), sizeof(saddr)) == 0){ meillo@0: FILE *in, *out; meillo@0: char buf[256]; meillo@0: meillo@0: dup_sock = dup(sock); meillo@0: out = fdopen(sock, "w"); meillo@0: in = fdopen(dup_sock, "r"); meillo@0: meillo@0: if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){ meillo@0: if(strncmp(buf, "READY", 5) == 0){ meillo@0: fprintf(out, "STAT\n"); fflush(out); meillo@0: if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){ meillo@0: if(strncmp(buf, "DOWN", 4) == 0){ meillo@0: ret = NULL; meillo@0: }else if(strncmp(buf, "UP", 2) == 0){ meillo@0: gchar *p = buf+3; meillo@0: while((*p != ':') && *p) p++; meillo@0: if(*p){ meillo@0: *p = 0; meillo@0: p++; meillo@0: if((atoi(p) >= 0) && *p) meillo@0: ret = g_strdup(buf+3); meillo@0: }else meillo@0: logwrite(LOG_ALERT, meillo@0: "unexpected response from mserver after STAT cmd: %s", meillo@0: buf); meillo@0: }else{ meillo@0: logwrite(LOG_ALERT, meillo@0: "unexpected response from mserver after STAT cmd: %s", meillo@0: buf); meillo@0: } meillo@0: } meillo@0: } meillo@0: fprintf(out, "QUIT"); fflush(out); meillo@0: meillo@0: close(sock); meillo@0: close(dup_sock); meillo@0: fclose(in); meillo@0: fclose(out); meillo@0: } meillo@0: } meillo@0: } meillo@0: return ret; meillo@0: } meillo@0: meillo@0: #endif