Index: SquidUpdate.php
===================================================================
RCS file: /cvsroot/wikipedia/phase3/includes/SquidUpdate.php,v
retrieving revision 1.16.4.5
diff -u -r1.16.4.5 SquidUpdate.php
--- SquidUpdate.php	21 Jan 2005 19:54:47 -0000	1.16.4.5
+++ SquidUpdate.php	30 Mar 2005 20:38:13 -0000
@@ -91,12 +91,15 @@
 	XXX report broken Squids per mail or log */
 
 	/* static */ function purge( $urlArr ) {
-		global  $wgSquidServers, $wgSquidFastPurge;
+		global  $wgSquidServers, $wgHTCPMulticast, $wgHTCPPort, $wgSquidFastPurge;
 
 		if ( $wgSquidServers == 'echo' ) {
 			echo implode("<br />\n", $urlArr);
 			return;
 		}
+
+		if ( $wgHTCPMulticast && $wgHTCPPort )
+			SquidUpdate::HTCPPurge( $urlArr );
 		
 		if ( $wgSquidFastPurge ) {
 			SquidUpdate::fastPurge( $urlArr );
@@ -224,6 +227,46 @@
 		wfProfileOut( $fname );
 	}
 
+	/* static */ function HTCPPurge( $urlArr ) {
+		global $wgHTCPMulticast, $wgHTCPPort;
+		$fname = 'SquidUpdate::HTCPPurge';
+		wfProfileIn( $fname );
+
+		$htcpOpCLR = 4;                 // HTCP CLR
+
+		$conn = pfsockopen( "udp://$wgHTCPMulticastAddress", $wgHTCPPort, $error, $errstr, 3);
+		if ( $conn ) {
+			foreach ( $urlArr as $url ) {
+				// Construct a minimal HTCP request diagram
+				// as per RFC 2756
+				// Opcode 'CLR', no response desired, no auth
+				$htcpTransID = rand();
+				
+				$htcpSpecifier = pack( 'na3na*na8n',
+					3, 'GET', strlen( $url ), $url,
+					8, 'HTTP/1.1', 0 );
+
+				$htcpDataLen = 8 + 2 + strlen( $htcpSpecifier );
+				$htcpLen = 4 + $htcpDataLen + 2;
+				
+				// Note! Squid gets the bit order of the first
+				// word wrong, wrt the RFC. Apparently no other
+				// implementation exists, so adapt to Squid
+				$htcpPacket = pack( 'nxxnCxNxxa*n',
+					$htcpLen, $htcpDataLen, $htcpOpCLR,
+					$htcpTransID, $htcpSpecifier, 2);
+					
+				// Send out
+				wfDebug( "Purging URL $url via HTCP\n" );
+				fwrite( $conn, $htcpPacket );
+			}
+		} else {
+			wfDebug( "SquidUpdate::HTCPPurge(): Error opening UDP socket: $errstr\n" );
+		}
+
+		wfProfileOut( $fname );
+	}
+
 	function debug( $text ) {
 		global $wgDebugSquid;
 		if ( $wgDebugSquid ) {
