diff src/mserver.c @ 0:08114f7dcc23 0.2.21

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 wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/mserver.c	Fri Sep 26 17:05:23 2008 +0200
@@ -0,0 +1,78 @@
+/*  MasqMail
+    Copyright (C) 1999/2000/2001 Oliver Kurth
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "masqmail.h"
+#include "readsock.h"
+#include "mserver.h"
+
+#ifdef ENABLE_MSERVER
+
+gchar *mserver_detect_online(interface *iface)
+{
+  struct sockaddr_in saddr;
+  gchar *ret = NULL;
+
+  if(init_sockaddr(&saddr, iface)){
+    int sock = socket(PF_INET, SOCK_STREAM, 0);
+    int dup_sock;
+    if(connect(sock, (struct sockaddr *)(&saddr), sizeof(saddr)) == 0){
+      FILE *in, *out;
+      char buf[256];
+
+      dup_sock = dup(sock);
+      out = fdopen(sock, "w");
+      in = fdopen(dup_sock, "r");
+
+      if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
+	if(strncmp(buf, "READY", 5) == 0){
+	  fprintf(out, "STAT\n"); fflush(out);
+	  if(read_sockline(in, buf, 256, 15, READSOCKL_CHUG)){
+	    if(strncmp(buf, "DOWN", 4) == 0){
+	      ret = NULL;
+	    }else if(strncmp(buf, "UP", 2) == 0){
+	      gchar *p = buf+3;
+	      while((*p != ':') && *p) p++;
+	      if(*p){
+		*p = 0;
+		p++;
+		if((atoi(p) >= 0) && *p)
+		  ret = g_strdup(buf+3);
+	      }else
+		logwrite(LOG_ALERT,
+			 "unexpected response from mserver after STAT cmd: %s",
+			 buf);
+	    }else{
+	      logwrite(LOG_ALERT,
+		       "unexpected response from mserver after STAT cmd: %s",
+		       buf);
+	    }
+	  }
+	}
+	fprintf(out, "QUIT"); fflush(out);
+
+	close(sock);
+	close(dup_sock);
+	fclose(in);
+	fclose(out);
+      }
+    }
+  }
+  return ret;
+}
+
+#endif