masqmail

diff src/mservdetect.c @ 164:5b621742b2e7

removed the mserver feature i.e. the functionality itself in the code the `mserver' value of online_detect and `mserver_iface' config options and the --enable-mserver configure option All functionality, however, is still available through mservdetect
author meillo@marmaro.de
date Thu, 08 Jul 2010 22:01:33 +0200
parents 26e34ae9a3e3
children bd7c52a36b0c
line diff
     1.1 --- a/src/mservdetect.c	Thu Jul 08 14:04:39 2010 +0200
     1.2 +++ b/src/mservdetect.c	Thu Jul 08 22:01:33 2010 +0200
     1.3 @@ -16,23 +16,65 @@
     1.4      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     1.5  */
     1.6  
     1.7 -/*
     1.8 +
     1.9 +#include "config.h"
    1.10  #include "masqmail.h"
    1.11  #include "readsock.h"
    1.12 -#include "mserver.h"
    1.13 -*/
    1.14  
    1.15 -#include "config.h"
    1.16  
    1.17 -/* ugly hack */
    1.18 -#ifndef ENABLE_MSERVER
    1.19 -#define ENABLE_MSERVER 1
    1.20 -#include "mserver.c"
    1.21 -#else
    1.22 -#include "masqmail.h"
    1.23 -#include "readsock.h"
    1.24 -#include "mserver.h"
    1.25 -#endif  /* ENABLE_MSERVER */
    1.26 +gchar*
    1.27 +mserver_detect_online(interface * iface)
    1.28 +{
    1.29 +	struct sockaddr_in saddr;
    1.30 +	gchar *ret = NULL;
    1.31 +
    1.32 +	if (init_sockaddr(&saddr, iface)) {
    1.33 +		int sock = socket(PF_INET, SOCK_STREAM, 0);
    1.34 +		int dup_sock;
    1.35 +		if (connect(sock, (struct sockaddr *) (&saddr), sizeof(saddr)) == 0) {
    1.36 +			FILE *in, *out;
    1.37 +			char buf[256];
    1.38 +
    1.39 +			dup_sock = dup(sock);
    1.40 +			out = fdopen(sock, "w");
    1.41 +			in = fdopen(dup_sock, "r");
    1.42 +
    1.43 +			if (read_sockline(in, buf, 256, 15, READSOCKL_CHUG)) {
    1.44 +				if (strncmp(buf, "READY", 5) == 0) {
    1.45 +					fprintf(out, "STAT\n");
    1.46 +					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)
    1.53 +								p++;
    1.54 +							if (*p) {
    1.55 +								*p = 0;
    1.56 +								p++;
    1.57 +								if ((atoi(p) >= 0) && *p)
    1.58 +									ret = g_strdup(buf + 3);
    1.59 +							} else
    1.60 +								logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf);
    1.61 +						} else {
    1.62 +							logwrite(LOG_ALERT, "unexpected response from mserver after STAT cmd: %s", buf);
    1.63 +						}
    1.64 +					}
    1.65 +				}
    1.66 +				fprintf(out, "QUIT");
    1.67 +				fflush(out);
    1.68 +
    1.69 +				close(sock);
    1.70 +				close(dup_sock);
    1.71 +				fclose(in);
    1.72 +				fclose(out);
    1.73 +			}
    1.74 +		}
    1.75 +	}
    1.76 +	return ret;
    1.77 +}
    1.78 +
    1.79  
    1.80  void
    1.81  logwrite(int pri, const char *fmt, ...)