masqmail-0.2

diff src/mserver.c @ 0:08114f7dcc23

this is masqmail-0.2.21 from oliver kurth
author meillo@marmaro.de
date Fri, 26 Sep 2008 17:05:23 +0200
parents
children 26e34ae9a3e3
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/mserver.c	Fri Sep 26 17:05:23 2008 +0200
     1.3 @@ -0,0 +1,78 @@
     1.4 +/*  MasqMail
     1.5 +    Copyright (C) 1999/2000/2001 Oliver Kurth
     1.6 +
     1.7 +    This program is free software; you can redistribute it and/or modify
     1.8 +    it under the terms of the GNU General Public License as published by
     1.9 +    the Free Software Foundation; either version 2 of the License, or
    1.10 +    (at your option) any later version.
    1.11 +
    1.12 +    This program is distributed in the hope that it will be useful,
    1.13 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 +    GNU General Public License for more details.
    1.16 +
    1.17 +    You should have received a copy of the GNU General Public License
    1.18 +    along with this program; if not, write to the Free Software
    1.19 +    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    1.20 +*/
    1.21 +
    1.22 +#include "masqmail.h"
    1.23 +#include "readsock.h"
    1.24 +#include "mserver.h"
    1.25 +
    1.26 +#ifdef ENABLE_MSERVER
    1.27 +
    1.28 +gchar *mserver_detect_online(interface *iface)
    1.29 +{
    1.30 +  struct sockaddr_in saddr;
    1.31 +  gchar *ret = NULL;
    1.32 +
    1.33 +  if(init_sockaddr(&saddr, iface)){
    1.34 +    int sock = socket(PF_INET, SOCK_STREAM, 0);
    1.35 +    int dup_sock;
    1.36 +    if(connect(sock, (struct sockaddr *)(&saddr), sizeof(saddr)) == 0){
    1.37 +      FILE *in, *out;
    1.38 +      char buf[256];
    1.39 +
    1.40 +      dup_sock = dup(sock);
    1.41 +      out = fdopen(sock, "w");
    1.42 +      in = fdopen(dup_sock, "r");
    1.43 +
    1.44 +      if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
    1.45 +	if(strncmp(buf, "READY", 5) == 0){
    1.46 +	  fprintf(out, "STAT\n"); fflush(out);
    1.47 +	  if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
    1.48 +	    if(strncmp(buf, "DOWN", 4) == 0){
    1.49 +	      ret = NULL;
    1.50 +	    }else if(strncmp(buf, "UP", 2) == 0){
    1.51 +	      gchar *p = buf+3;
    1.52 +	      while((*p != ':') && *p) p++;
    1.53 +	      if(*p){
    1.54 +		*p = 0;
    1.55 +		p++;
    1.56 +		if((atoi(p) >= 0) && *p)
    1.57 +		  ret = g_strdup(buf+3);
    1.58 +	      }else
    1.59 +		logwrite(LOG_ALERT,
    1.60 +			 "unexpected response from mserver after STAT cmd: %s",
    1.61 +			 buf);
    1.62 +	    }else{
    1.63 +	      logwrite(LOG_ALERT,
    1.64 +		       "unexpected response from mserver after STAT cmd: %s",
    1.65 +		       buf);
    1.66 +	    }
    1.67 +	  }
    1.68 +	}
    1.69 +	fprintf(out, "QUIT"); fflush(out);
    1.70 +
    1.71 +	close(sock);
    1.72 +	close(dup_sock);
    1.73 +	fclose(in);
    1.74 +	fclose(out);
    1.75 +      }
    1.76 +    }
    1.77 +  }
    1.78 +  return ret;
    1.79 +}
    1.80 +
    1.81 +#endif