[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mgp-users-jp 00797] mgpnet patch



mgpnetが動かないというバグレポートがあったので
Debianでも動くようにしてみました。(from mgp-snap-20010212)

* date は LC_ALL=C にしておかないと http response header で
  日本語がでたりしてました:-)

* GNU/Linux の ifconfig (netbase 3.18-4)では

eth0      Link encap:Ethernet  HWaddr 00:90:27:36:24:F1  
          inet addr:172.20.182.38  Bcast:172.20.182.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:38320983 errors:0 dropped:0 overruns:0 frame:0
          TX packets:55538607 errors:0 dropped:0 overruns:0 carrier:0
          collisions:3224621 txqueuelen:100 
          Interrupt:12 Base address:0x2000 

  なので addr: をとらないと変です。

* typo s/connetion/connection/

* .gif やめて .png に

* @CPP@ は cc -E になりますが、入力ファイルとして - を指定しないと
  うまく動いてくれません。

* cpp で sys/socket.h や sys/wait.h をとおして定数を調べていますが、
  glibc 2.2 だと SOCK_STREAM とかが enum なのでこの方法だと駄目です。
  というわけで use Socket; してみました。

* あと、Mozilla とかは HTTP/1.1 をしゃべってくるので
  単純に HTTP/1.1 も許可しちゃいましたが。

Index: contrib/mgpnet.in
===================================================================
RCS file: /var/cvs/debian/mgp/contrib/mgpnet.in,v
retrieving revision 1.1.1.3
diff -u -u -r1.1.1.3 mgpnet.in
--- contrib/mgpnet.in	1998/09/07 10:10:44	1.1.1.3
+++ contrib/mgpnet.in	2001/02/14 09:36:39
@@ -32,7 +32,7 @@
 
 # configurations
 $tmpdir = '/tmp';
-$httpdatestr = "date '+\%a, \%d \%b \%Y \%H:\%M:\%S \%Z'";
+$httpdatestr = "env LC_ALL=C date '+\%a, \%d \%b \%Y \%H:\%M:\%S \%Z'";
 $seltimeout = 1;
 $refreshtimeout = 10;
 $debug = 0;
@@ -53,6 +53,7 @@
 		} while ($hostname =~ /^127\./);
 		close(IN);
 	};
+	$hostname =~ s/^addr://; # for GNU/Linux, by ukai
 	print "http://$hostname:$port/\n";;
 	exit 0;
 }
@@ -150,19 +151,19 @@
 	vec($rin, fileno(S), 1) = 1;
 	vec($win, fileno(S), 1) = 1;
 	$ewin = $rin | $win;
-	print STDERR "waiting for connetion...\n" if ($debug);
+	print STDERR "waiting for connection...\n" if ($debug);
 	($nfound, $timeleft) = 
 		select($rout = $rin, $wout = $win, $eout = $ein, $seltimeout);
 	next if ($nfound <= 0);
 	if (vec($rout, fileno(S), 1)) {
-		print STDERR "accepting connetion...\n" if ($debug);
+		print STDERR "accepting connection...\n" if ($debug);
 		accept(NS, S) || do {
 			print STDERR "server: accept fail\n" if ($debug);
 			next;
 		};
 
 		$acceptstat++;
-		print STDERR "connetion accepted...\n" if ($debug);
+		print STDERR "connection accepted...\n" if ($debug);
 
 		$pid = fork;
 		if ($pid < 0) {
@@ -185,7 +186,7 @@
 	}
 }
 print STDERR "leaving MagicPoint Netserver...\n";
-print STDERR "accepted $acceptstat connetions so far.\n";
+print STDERR "accepted $acceptstat connections so far.\n";
 close(NS);
 close(S);
 unlink($imagefile);
@@ -214,7 +215,7 @@
 		$imgtmp = &tmpname;
 		$errout = ($debug ? '' : '2>&-');
 		system "xwintoppm -silent -name MagicPoint | ".
-			"ppmquant 256 $errout | ppmtogif $errout > $imgtmp";
+			"ppmquant 256 $errout | pnmtopng $errout > $imgtmp";
 		if (-z $imgtmp) {
 			unlink $imgtmp;
 			$checkcontent = '';
@@ -245,10 +246,10 @@
 	local($httpreq, $httpmethod, $httppath, $httpver, $httphost);
 	local($httpagent);
 	local($imgplace, $imgwidth, $imgheight, $buf, $imglen);
-	local($cthtml, $ctgif);
+	local($cthtml, $ctpng);
 
 	$cthtml = ($usecharset ? 'text/html; charset=us-ascii' : 'text/html');
-	$ctgif = 'image/gif';
+	$ctpng = 'image/png';
 
 	$httpreq = <NS>;
 	print STDERR 'HTTP in> ' . $httpreq if ($debug);
@@ -256,7 +257,7 @@
 	$httpmethod = $httppath = $httpver = '';
 	($httpmethod, $httppath, $httpver) = split(/\s+/, $httpreq);
 	$httppath =~ s/http:\/\/[^:\/]+(:\d+)\//\//;
-	if ($httpver eq '' || $httpver eq 'HTTP/1.0') {
+	if ($httpver eq '' || $httpver =~ m'HTTP/1.[01]') {
 		;	# ok
 	} else {
 		&httpheader(501, $cthtml) if ($httpver);
@@ -318,7 +319,7 @@
 		print <<EOF;
 <HEAD><TITLE>MagicPoint Netserver</TITLE></HEAD>
 <BODY>
-<IMG SRC=\"/presentation.gif\" ALT=\"presentation image\"
+<IMG SRC=\"/presentation.png\" ALT=\"presentation image\"
 $imgplace ALIGN=left><BR>
 <TABLE border=0>
 <TR><TD NOWRAP><A HREF=/index.html>normal</A>
@@ -340,7 +341,7 @@
 </TABLE>
 </BODY></HTML>
 EOF
-	} elsif ($httppath eq '/presentation.gif') {
+	} elsif ($httppath eq '/presentation.png') {
 		open(IMG, "< $imagefile") || do {
 			$checkcontent = '';	# invalidate
 			&httpheader(404, $cthtml) if ($httpver);
@@ -350,13 +351,13 @@
 <HEAD><TITLE>File Not found</TITLE></HEAD>
 <BODY><H1>File Not found</H1>
 The requested URL $httppath was not found on this server.<P>
-Looks like a mitake in configuration.
+Looks like a mistake in configuration.
 Contact the administrator.<P>
 </BODY>
 EOF
 			return;
 		};
-		&httpheader(200, $ctgif) if ($httpver);
+		&httpheader(200, $ctpng) if ($httpver);
 		return if ($httpmethod ne 'GET');
 
 		while (0 < ($imglen = sysread(IMG, $buf, 4096))) {
@@ -415,7 +416,7 @@
 'XXX4', 'SO_REUSEPORT',	'XXX5', 'SOCK_STREAM',	'XXX6', 'WNOHANG',
 );
 	$tmpnam = &tmpname;
-	open(CPP, "| @CPP@ >$tmpnam") || return;
+	open(CPP, "| @CPP@ - >$tmpnam") || return;
 	print CPP "#include <sys/socket.h>\n";
 	print CPP "#include <sys/wait.h>\n";
 	foreach $tmp (keys %varnames) {
@@ -439,12 +440,19 @@
 		$havesinlen = 0; $sockaddr = 'S n a4 x8';
 	}
 
+	use Socket;
 	foreach $i (keys %varnames) {
 		if (@tmp2 = grep($_ =~ /^$i/, @tmp1)) {
 			$tmp = (split(/\s+/, @tmp2[0]))[1];
 			$tmp = oct($tmp) if ($tmp =~ /^0/);
-			next if ($tmp !~ /^[0-9]+$/);
-			eval "\$$varnames{$i} = \$tmp;";
+			if ($tmp =~ /^[0-9]+$/) {
+			    eval "\$$varnames{$i} = \$tmp;";
+			} else {
+			    # some constant defined by enum, so we can not
+			    # always use cpp as above. I believe use Socket
+			    # is more reliable in these days.
+			    eval "\$$varnames{$i} = &$varnames{$i};";
+			}
 		}
 	}
 }


-- 
鵜飼文敏