masqmail

annotate 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
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@0 25 gchar *mserver_detect_online(interface *iface)
meillo@0 26 {
meillo@0 27 struct sockaddr_in saddr;
meillo@0 28 gchar *ret = NULL;
meillo@0 29
meillo@0 30 if(init_sockaddr(&saddr, iface)){
meillo@0 31 int sock = socket(PF_INET, SOCK_STREAM, 0);
meillo@0 32 int dup_sock;
meillo@0 33 if(connect(sock, (struct sockaddr *)(&saddr), sizeof(saddr)) == 0){
meillo@0 34 FILE *in, *out;
meillo@0 35 char buf[256];
meillo@0 36
meillo@0 37 dup_sock = dup(sock);
meillo@0 38 out = fdopen(sock, "w");
meillo@0 39 in = fdopen(dup_sock, "r");
meillo@0 40
meillo@0 41 if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
meillo@0 42 if(strncmp(buf, "READY", 5) == 0){
meillo@0 43 fprintf(out, "STAT\n"); fflush(out);
meillo@0 44 if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
meillo@0 45 if(strncmp(buf, "DOWN", 4) == 0){
meillo@0 46 ret = NULL;
meillo@0 47 }else if(strncmp(buf, "UP", 2) == 0){
meillo@0 48 gchar *p = buf+3;
meillo@0 49 while((*p != ':') && *p) p++;
meillo@0 50 if(*p){
meillo@0 51 *p = 0;
meillo@0 52 p++;
meillo@0 53 if((atoi(p) >= 0) && *p)
meillo@0 54 ret = g_strdup(buf+3);
meillo@0 55 }else
meillo@0 56 logwrite(LOG_ALERT,
meillo@0 57 "unexpected response from mserver after STAT cmd: %s",
meillo@0 58 buf);
meillo@0 59 }else{
meillo@0 60 logwrite(LOG_ALERT,
meillo@0 61 "unexpected response from mserver after STAT cmd: %s",
meillo@0 62 buf);
meillo@0 63 }
meillo@0 64 }
meillo@0 65 }
meillo@0 66 fprintf(out, "QUIT"); fflush(out);
meillo@0 67
meillo@0 68 close(sock);
meillo@0 69 close(dup_sock);
meillo@0 70 fclose(in);
meillo@0 71 fclose(out);
meillo@0 72 }
meillo@0 73 }
meillo@0 74 }
meillo@0 75 return ret;
meillo@0 76 }
meillo@0 77
meillo@0 78 #endif