masqmail-0.2

diff src/online.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 f671821d8222
line diff
     1.1 --- a/src/online.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/online.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -24,96 +24,91 @@
     1.4  
     1.5  gchar *connection_name;
     1.6  
     1.7 -void set_online_name(gchar *name)
     1.8 +void
     1.9 +set_online_name(gchar * name)
    1.10  {
    1.11 -  connection_name = g_strdup(name);
    1.12 +	connection_name = g_strdup(name);
    1.13  }
    1.14  
    1.15 -static
    1.16 -gchar *detect_online_pipe(const gchar *pipe)
    1.17 +static gchar*
    1.18 +detect_online_pipe(const gchar * pipe)
    1.19  {
    1.20 -  pid_t pid;
    1.21 -  void (*old_signal)(int);
    1.22 -  int status;
    1.23 -  FILE *in;
    1.24 -  gchar *name = NULL;
    1.25 +	pid_t pid;
    1.26 +	void (*old_signal) (int);
    1.27 +	int status;
    1.28 +	FILE *in;
    1.29 +	gchar *name = NULL;
    1.30  
    1.31 -  old_signal = signal(SIGCHLD, SIG_DFL);
    1.32 +	old_signal = signal(SIGCHLD, SIG_DFL);
    1.33  
    1.34 -  in = peopen(pipe, "r", environ, &pid);
    1.35 -  if(in != NULL){
    1.36 -    gchar output[256];
    1.37 -    if(fgets(output, 255, in)){
    1.38 -      g_strchomp(output);
    1.39 -      name = g_strdup(output);
    1.40 -    }
    1.41 -    fclose(in);
    1.42 -    waitpid(pid, &status, 0);
    1.43 -    if(WEXITSTATUS(status) != EXIT_SUCCESS){
    1.44 -      g_free(name);
    1.45 -      name = NULL;
    1.46 -    }
    1.47 -  }else
    1.48 -    logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno));
    1.49 +	in = peopen(pipe, "r", environ, &pid);
    1.50 +	if (in != NULL) {
    1.51 +		gchar output[256];
    1.52 +		if (fgets(output, 255, in)) {
    1.53 +			g_strchomp(output);
    1.54 +			name = g_strdup(output);
    1.55 +		}
    1.56 +		fclose(in);
    1.57 +		waitpid(pid, &status, 0);
    1.58 +		if (WEXITSTATUS(status) != EXIT_SUCCESS) {
    1.59 +			g_free(name);
    1.60 +			name = NULL;
    1.61 +		}
    1.62 +	} else
    1.63 +		logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno));
    1.64  
    1.65 -  signal(SIGCHLD, old_signal);
    1.66 +	signal(SIGCHLD, old_signal);
    1.67  
    1.68 -  return name;
    1.69 +	return name;
    1.70  }
    1.71  
    1.72 -gchar *detect_online()
    1.73 +gchar*
    1.74 +detect_online()
    1.75  {
    1.76 -  if(conf.online_detect != NULL){
    1.77 -    if(strcmp(conf.online_detect, "file") == 0){
    1.78 -      DEBUG(3) debugf("online detection method 'file'\n");
    1.79 -      if(conf.online_file != NULL){
    1.80 -	struct stat st;
    1.81 -	if(stat(conf.online_file, &st) == 0){
    1.82 -	  FILE *fptr = fopen(conf.online_file, "r");
    1.83 -	  if(fptr){
    1.84 -	    char buf[256];
    1.85 -	    fgets(buf, 256, fptr);
    1.86 -	    g_strchomp(buf);
    1.87 -	    fclose(fptr);
    1.88 -	    return g_strdup(buf);
    1.89 -	  }else{
    1.90 -	    logwrite(LOG_ALERT, "opening of %s failed: %s\n",
    1.91 -		     conf.online_file, strerror(errno));
    1.92 -	    return NULL;
    1.93 -	  }
    1.94 +	if (conf.online_detect != NULL) {
    1.95 +		if (strcmp(conf.online_detect, "file") == 0) {
    1.96 +			DEBUG(3) debugf("online detection method 'file'\n");
    1.97 +			if (conf.online_file != NULL) {
    1.98 +				struct stat st;
    1.99 +				if (stat(conf.online_file, &st) == 0) {
   1.100 +					FILE *fptr = fopen(conf.online_file, "r");
   1.101 +					if (fptr) {
   1.102 +						char buf[256];
   1.103 +						fgets(buf, 256, fptr);
   1.104 +						g_strchomp(buf);
   1.105 +						fclose(fptr);
   1.106 +						return g_strdup(buf);
   1.107 +					} else {
   1.108 +						logwrite(LOG_ALERT, "opening of %s failed: %s\n", conf.online_file, strerror(errno));
   1.109 +						return NULL;
   1.110 +					}
   1.111 +				} else if (errno == ENOENT) {
   1.112 +					logwrite(LOG_NOTICE, "not online.\n");
   1.113 +					return NULL;
   1.114 +				} else {
   1.115 +					logwrite(LOG_ALERT, "stat of %s failed: %s", conf.online_file, strerror(errno));
   1.116 +					return NULL;
   1.117 +				}
   1.118 +			} else
   1.119 +				logwrite(LOG_ALERT, "online detection mode is 'file', but online_file is undefined\n");
   1.120 +#ifdef ENABLE_MSERVER
   1.121 +		} else if (strcmp(conf.online_detect, "mserver") == 0) {
   1.122 +			DEBUG(3) debugf("connection method 'mserver'\n");
   1.123 +			return mserver_detect_online(conf.mserver_iface);
   1.124 +#endif
   1.125 +		} else if (strcmp(conf.online_detect, "pipe") == 0) {
   1.126 +			DEBUG(3) debugf("connection method 'pipe'\n");
   1.127 +			if (conf.online_pipe)
   1.128 +				return detect_online_pipe(conf.online_pipe);
   1.129 +			else {
   1.130 +				logwrite(LOG_ALERT, "online detection mode is 'pipe', but online_pipe is undefined\n");
   1.131 +				return NULL;
   1.132 +			}
   1.133 +		} else if (strcmp(conf.online_detect, "argument") == 0) {
   1.134 +			return connection_name;
   1.135 +		} else {
   1.136 +			DEBUG(3) debugf("no connection method selected\n");
   1.137 +		}
   1.138  	}
   1.139 -	else if(errno == ENOENT){
   1.140 -	  logwrite(LOG_NOTICE, "not online.\n");
   1.141 -	  return NULL;
   1.142 -	}else{
   1.143 -	  logwrite(LOG_ALERT, "stat of %s failed: %s",
   1.144 -		   conf.online_file, strerror(errno));
   1.145 -	  return NULL;
   1.146 -	}
   1.147 -      }else
   1.148 -	logwrite(LOG_ALERT,
   1.149 -		 "online detection mode is 'file', "
   1.150 -		 "but online_file is undefined\n");
   1.151 -#ifdef ENABLE_MSERVER
   1.152 -    }else if(strcmp(conf.online_detect, "mserver") == 0){
   1.153 -      DEBUG(3) debugf("connection method 'mserver'\n");
   1.154 -      return mserver_detect_online(conf.mserver_iface);
   1.155 -#endif
   1.156 -    }else if(strcmp(conf.online_detect, "pipe") == 0){
   1.157 -      DEBUG(3) debugf("connection method 'pipe'\n");
   1.158 -      if(conf.online_pipe)
   1.159 -	return detect_online_pipe(conf.online_pipe);
   1.160 -      else{
   1.161 -	logwrite(LOG_ALERT,
   1.162 -		 "online detection mode is 'pipe', "
   1.163 -		 "but online_pipe is undefined\n");
   1.164  	return NULL;
   1.165 -      }
   1.166 -    }else if(strcmp(conf.online_detect, "argument") == 0){
   1.167 -      return connection_name;
   1.168 -    }else{
   1.169 -      DEBUG(3) debugf("no connection method selected\n");
   1.170 -    }
   1.171 -  }
   1.172 -  return NULL;
   1.173  }