masqmail

diff src/mserver.c @ 10:26e34ae9a3e3

changed indention and line wrapping to a more consistent style
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:23:10 +0100
parents 08114f7dcc23
children
line diff
     1.1 --- a/src/mserver.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/mserver.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -22,57 +22,57 @@
     1.4  
     1.5  #ifdef ENABLE_MSERVER
     1.6  
     1.7 -gchar *mserver_detect_online(interface *iface)
     1.8 +gchar*
     1.9 +mserver_detect_online(interface * iface)
    1.10  {
    1.11 -  struct sockaddr_in saddr;
    1.12 -  gchar *ret = NULL;
    1.13 +	struct sockaddr_in saddr;
    1.14 +	gchar *ret = NULL;
    1.15  
    1.16 -  if(init_sockaddr(&saddr, iface)){
    1.17 -    int sock = socket(PF_INET, SOCK_STREAM, 0);
    1.18 -    int dup_sock;
    1.19 -    if(connect(sock, (struct sockaddr *)(&saddr), sizeof(saddr)) == 0){
    1.20 -      FILE *in, *out;
    1.21 -      char buf[256];
    1.22 +	if (init_sockaddr(&saddr, iface)) {
    1.23 +		int sock = socket(PF_INET, SOCK_STREAM, 0);
    1.24 +		int dup_sock;
    1.25 +		if (connect(sock, (struct sockaddr *) (&saddr), sizeof(saddr)) == 0) {
    1.26 +			FILE *in, *out;
    1.27 +			char buf[256];
    1.28  
    1.29 -      dup_sock = dup(sock);
    1.30 -      out = fdopen(sock, "w");
    1.31 -      in = fdopen(dup_sock, "r");
    1.32 +			dup_sock = dup(sock);
    1.33 +			out = fdopen(sock, "w");
    1.34 +			in = fdopen(dup_sock, "r");
    1.35  
    1.36 -      if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
    1.37 -	if(strncmp(buf, "READY", 5) == 0){
    1.38 -	  fprintf(out, "STAT\n"); fflush(out);
    1.39 -	  if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
    1.40 -	    if(strncmp(buf, "DOWN", 4) == 0){
    1.41 -	      ret = NULL;
    1.42 -	    }else if(strncmp(buf, "UP", 2) == 0){
    1.43 -	      gchar *p = buf+3;
    1.44 -	      while((*p != ':') && *p) p++;
    1.45 -	      if(*p){
    1.46 -		*p = 0;
    1.47 -		p++;
    1.48 -		if((atoi(p) >= 0) && *p)
    1.49 -		  ret = g_strdup(buf+3);
    1.50 -	      }else
    1.51 -		logwrite(LOG_ALERT,
    1.52 -			 "unexpected response from mserver after STAT cmd: %s",
    1.53 -			 buf);
    1.54 -	    }else{
    1.55 -	      logwrite(LOG_ALERT,
    1.56 -		       "unexpected response from mserver after STAT cmd: %s",
    1.57 -		       buf);
    1.58 -	    }
    1.59 -	  }
    1.60 +			if (read_sockline(in, buf, 256, 15, READSOCKL_CHUG)) {
    1.61 +				if (strncmp(buf, "READY", 5) == 0) {
    1.62 +					fprintf(out, "STAT\n");
    1.63 +					fflush(out);
    1.64 +					if (read_sockline(in, buf, 256, 15, READSOCKL_CHUG)) {
    1.65 +						if (strncmp(buf, "DOWN", 4) == 0) {
    1.66 +							ret = NULL;
    1.67 +						} else if (strncmp(buf, "UP", 2) == 0) {
    1.68 +							gchar *p = buf + 3;
    1.69 +							while ((*p != ':') && *p)
    1.70 +								p++;
    1.71 +							if (*p) {
    1.72 +								*p = 0;
    1.73 +								p++;
    1.74 +								if ((atoi(p) >= 0) && *p)
    1.75 +									ret = g_strdup(buf + 3);
    1.76 +							} else
    1.77 +								logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf);
    1.78 +						} else {
    1.79 +							logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf);
    1.80 +						}
    1.81 +					}
    1.82 +				}
    1.83 +				fprintf(out, "QUIT");
    1.84 +				fflush(out);
    1.85 +
    1.86 +				close(sock);
    1.87 +				close(dup_sock);
    1.88 +				fclose(in);
    1.89 +				fclose(out);
    1.90 +			}
    1.91 +		}
    1.92  	}
    1.93 -	fprintf(out, "QUIT"); fflush(out);
    1.94 -
    1.95 -	close(sock);
    1.96 -	close(dup_sock);
    1.97 -	fclose(in);
    1.98 -	fclose(out);
    1.99 -      }
   1.100 -    }
   1.101 -  }
   1.102 -  return ret;
   1.103 +	return ret;
   1.104  }
   1.105  
   1.106  #endif