masqmail

diff src/online.c @ 310:f10a56dc7481

reworked online_detect to the simpler online_query Only pipe is supported now. Use online_query="/bin/cat /path/to/file" instead of online_detect=file online_file=/path/to/file and online_query="/path/to/some/script foo" instead of online_detect=pipe online_pipe="/path/to/some/script foo" See man page masqmail.conf(5) and admin/config-transition.
author meillo@marmaro.de
date Sun, 24 Apr 2011 19:14:38 +0200
parents 1aa107c6b1e5
children 41958685480d
line diff
     1.1 --- a/src/online.c	Sun Apr 24 19:02:09 2011 +0200
     1.2 +++ b/src/online.c	Sun Apr 24 19:14:38 2011 +0200
     1.3 @@ -17,71 +17,31 @@
     1.4      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     1.5  */
     1.6  
     1.7 -#include <sys/stat.h>
     1.8  #include <sys/wait.h>
     1.9  
    1.10  #include "masqmail.h"
    1.11  #include "peopen.h"
    1.12  
    1.13 -gchar *connection_name;
    1.14  
    1.15 -void
    1.16 -set_online_name(gchar * name)
    1.17 +gchar*
    1.18 +online_query()
    1.19  {
    1.20 -	connection_name = g_strdup(name);
    1.21 -}
    1.22 -
    1.23 -static gchar*
    1.24 -detect_online_file(const gchar* file)
    1.25 -{
    1.26 -	struct stat st;
    1.27 -	int err;
    1.28 -	FILE *fptr;
    1.29 -	char buf[256];
    1.30 -
    1.31 -	err = stat(conf.online_file, &st);
    1.32 -
    1.33 -	if (err) {
    1.34 -		if (errno==ENOENT) {
    1.35 -			logwrite(LOG_NOTICE, "not online.\n");
    1.36 -			return NULL;
    1.37 -		}
    1.38 -		logwrite(LOG_ALERT, "stat of %s failed: %s\n", conf.online_file, strerror(errno));
    1.39 -		return NULL;
    1.40 -	}
    1.41 -
    1.42 -	fptr = fopen(conf.online_file, "r");
    1.43 -	if (!fptr) {
    1.44 -		logwrite(LOG_ALERT, "opening of %s failed: %s\n", conf.online_file, strerror(errno));
    1.45 -		return NULL;
    1.46 -	}
    1.47 -	if (fgets(buf, 256, fptr) == NULL) {
    1.48 -		logwrite(LOG_ALERT, "empty online file %s\n", conf.online_file);
    1.49 -		fclose(fptr);
    1.50 -		return NULL;
    1.51 -	}
    1.52 -	g_strstrip(buf);  /* strip whitespace */
    1.53 -	fclose(fptr);
    1.54 -	if (strlen(buf) == 0) {
    1.55 -		logwrite(LOG_ALERT, "only whitespace connection name in %s\n", conf.online_file);
    1.56 -		return NULL;
    1.57 -	}
    1.58 -	return g_strdup(buf);
    1.59 -}
    1.60 -
    1.61 -static gchar*
    1.62 -detect_online_pipe(const gchar * pipe)
    1.63 -{
    1.64 +	gchar* pipe = conf.online_query;
    1.65  	pid_t pid;
    1.66  	void (*old_signal) (int);
    1.67  	int status;
    1.68  	FILE *in;
    1.69  	gchar *name = NULL;
    1.70  
    1.71 +	if (!conf.online_query) {
    1.72 +		return NULL;
    1.73 +	}
    1.74 +	DEBUG(3) debugf("online query `%s'\n", pipe);
    1.75 +
    1.76  	old_signal = signal(SIGCHLD, SIG_DFL);
    1.77  
    1.78  	in = peopen(pipe, "r", environ, &pid);
    1.79 -	if (in == NULL) {
    1.80 +	if (!in) {
    1.81  		logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno));
    1.82  		signal(SIGCHLD, old_signal);
    1.83  		return NULL;
    1.84 @@ -111,37 +71,3 @@
    1.85  
    1.86  	return name;
    1.87  }
    1.88 -
    1.89 -gchar*
    1.90 -detect_online()
    1.91 -{
    1.92 -	if (!conf.online_detect) {
    1.93 -		return NULL;
    1.94 -	}
    1.95 -
    1.96 -	if (strcmp(conf.online_detect, "file") == 0) {
    1.97 -		DEBUG(3) debugf("online detection method 'file'\n");
    1.98 -		if (!conf.online_file) {
    1.99 -			logwrite(LOG_ALERT, "online detection mode is 'file', but online_file is undefined\n");
   1.100 -			return NULL;
   1.101 -		}
   1.102 -		return detect_online_file(conf.online_file);
   1.103 -
   1.104 -	} else if (strcmp(conf.online_detect, "pipe") == 0) {
   1.105 -		DEBUG(3) debugf("connection method 'pipe'\n");
   1.106 -		if (!conf.online_pipe) {
   1.107 -			logwrite(LOG_ALERT, "online detection mode is 'pipe', but online_pipe is undefined\n");
   1.108 -			return NULL;
   1.109 -		}
   1.110 -		return detect_online_pipe(conf.online_pipe);
   1.111 -
   1.112 -	} else if (strcmp(conf.online_detect, "argument") == 0) {
   1.113 -		DEBUG(3) debugf("online route literally defined\n");
   1.114 -		/* use the name set with set_online_name() */
   1.115 -		return connection_name;
   1.116 -
   1.117 -	}
   1.118 -
   1.119 -	DEBUG(3) debugf("unknown online detection method `%s'\n", conf.online_detect);
   1.120 -	return NULL;
   1.121 -}