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@10: gchar* meillo@10: mserver_detect_online(interface * iface) meillo@0: { meillo@10: struct sockaddr_in saddr; meillo@10: gchar *ret = NULL; meillo@0: meillo@10: if (init_sockaddr(&saddr, iface)) { meillo@10: int sock = socket(PF_INET, SOCK_STREAM, 0); meillo@10: int dup_sock; meillo@10: if (connect(sock, (struct sockaddr *) (&saddr), sizeof(saddr)) == 0) { meillo@10: FILE *in, *out; meillo@10: char buf[256]; meillo@0: meillo@10: dup_sock = dup(sock); meillo@10: out = fdopen(sock, "w"); meillo@10: in = fdopen(dup_sock, "r"); meillo@0: meillo@10: if (read_sockline(in, buf, 256, 15, READSOCKL_CHUG)) { meillo@10: if (strncmp(buf, "READY", 5) == 0) { meillo@10: fprintf(out, "STAT\n"); meillo@10: fflush(out); meillo@10: if (read_sockline(in, buf, 256, 15, READSOCKL_CHUG)) { meillo@10: if (strncmp(buf, "DOWN", 4) == 0) { meillo@10: ret = NULL; meillo@10: } else if (strncmp(buf, "UP", 2) == 0) { meillo@10: gchar *p = buf + 3; meillo@10: while ((*p != ':') && *p) meillo@10: p++; meillo@10: if (*p) { meillo@10: *p = 0; meillo@10: p++; meillo@10: if ((atoi(p) >= 0) && *p) meillo@10: ret = g_strdup(buf + 3); meillo@10: } else meillo@10: logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf); meillo@10: } else { meillo@10: logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf); meillo@10: } meillo@10: } meillo@10: } meillo@10: fprintf(out, "QUIT"); meillo@10: fflush(out); meillo@10: meillo@10: close(sock); meillo@10: close(dup_sock); meillo@10: fclose(in); meillo@10: fclose(out); meillo@10: } meillo@10: } meillo@0: } meillo@10: return ret; meillo@0: } meillo@0: meillo@0: #endif