masqmail-0.2

annotate src/mserver.c @ 68:08e258ed1ebc

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