--- VANILLA/http.php	2005-12-19 05:27:28.000000000 +0100
+++ http.php	2006-01-03 18:29:33.874319000 +0100
@@ -2,7 +2,38 @@
 /*
  * http.php
  *
- * @(#) $Header: /home/mlemos/cvsroot/http/http.php,v 1.55 2005/12/19 02:53:47 mlemos Exp $
+ * @(#) $Header: /sources/phpprintipp/phpprintipp/HTTP/http.php,v 1.4 2006/01/02 20:42:02 harding Exp $
+ * Hacked 2005-12-17 and 2005/12/31 by Thomas Harding to allow special applications (currently IPP: Internet Printing Protocol)
+ *
+ * Copyright (c) 2001-2005, Manuel Lemos
+ * Copyright (c) 2005-2006, Thomas Harding
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Manuel Lemos nor the names of its
+ *       contributors may be used to endorse or promote products derived from
+ *       this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ *
  *
  */
 
@@ -15,7 +46,7 @@
 
 	var $protocol="http";
 	var $request_method="GET";
-	var $user_agent='httpclient (http://www.phpclasses.org/httpclient $Revision: 1.55 $)';
+	var $user_agent='httpclient V1.55-IPP (http://sv.nongnu.org/projects/phpprintipp)';
 	var $authentication_mechanism="";
 	var $user;
 	var $password;
@@ -84,6 +115,8 @@
 		"Dec"=>"12");
 	var $session='';
 	var $connection_close=0;
+    var $memorized_args; // part of IPP HACK
+    var $request_file; // part of IPP HACK
 
 	/* Private methods - DO NOT CALL */
 
@@ -195,18 +228,32 @@
 
 	Function PutLine($line)
 	{
+
+        // {{{ HACKED FOR IPP
+        $read = array($this->connection);
+        if(stream_select($read, $write = NULL, $except = NULL, 0))
+            return 1;
+        // }}} END OF HACK
+        
 		if($this->debug)
 			$this->OutputDebug("C $line");
 		if(!fputs($this->connection,$line."\r\n"))
 		{
+
 			$this->SetDataAccessError("it was not possible to send a line to the HTTP server");
 			return(0);
 		}
+
 		return(1);
 	}
 
 	Function PutData(&$data)
 	{
+        // {{{ HACKED For IPP
+        $read = array($this->connection);
+        if(stream_select($read, $write = NULL, $except = NULL, 0))
+            return 1;
+        // }}} END OF HACK
 		if(strlen($data))
 		{
 			if($this->debug)
@@ -839,6 +886,49 @@
 					$end=(GetType($input=Key($files))!="string");
 				}
 			}
+            
+            // {{{ HACK by Thomas Harding for IPP (Internet Printing Protocol)
+            elseif(array_key_exists("PostValues",$arguments) && is_array($arguments["PostValues"]) && array_key_exists("Content-Type",$arguments["PostValues"]) && $arguments["PostValues"]["Content-Type"] == "application/ipp" )
+            {   
+                $this->memorized_args = array_merge($arguments["PostValues"], "BodyFile" => $arguments["BodyFile"]);
+                $values=$arguments["PostValues"];
+                $this->request_body="";
+                if (array_key_exists("Data",$values))
+                    $this->request_body .= $values["Data"];
+                if (array_key_exists("BodyFile",$arguments))
+                    $this->body_file = $arguments["BodyFile"];
+                $this->request_headers["Content-Type"]=$values["Content-Type"];
+                $body_length = strlen($values["Data"]);
+                if ($this->body_file && file_exists($this->body_file))
+                    $body_length += filesize($this->body_file);
+                if (array_key_exists("Filetype",$values) && $values["Filetype"] == "TEXT") {
+                    $body_length += 1;
+                    $added_char = chr(0x0c);
+                }
+            }
+            elseif(is_array($this->memorized_args))
+            {
+                $values=$this->memorized_args;
+                
+                $this->request_headers["Content-Type"]=$values["Content-Type"];
+                $body_length = 0; 
+                $this->request_body="";
+                if (array_key_exists("Data",$values)) {
+                    $this->request_body .= $values["Data"];
+                    $body_length = strlen($values["Data"]);
+                    }
+                if (array_key_exists("BodyFile",$values)) {
+                    $this->body_file = $values["BodyFile"];
+                    if ($this->body_file && file_exists($this->body_file))
+                        $body_length+=filesize($this->body_file);
+                    } 
+                if (array_key_exists("Filetype",$values) && $values["Filetype"] == "TEXT") {
+                    $body_length += 1;
+                    $added_char = chr(0x0c);
+                    }
+            }
+            // }}}
+
 			elseif(IsSet($arguments["PostValues"]))
 			{
 				$values=$arguments["PostValues"];
@@ -1035,7 +1125,35 @@
 				&& $body_length)
 				{
 					if(strlen($this->request_body))
+                    // {{{ BEGIN OF IPP HACK
+                        {
 						$success=$this->PutData($this->request_body);
+                        if ($success && $this->body_file) 
+                            {
+					        if(!($file=@fopen($this->body_file,"rb")))
+								{
+								$this->SetPHPError(sprintf(_("could not open upload file %s"),$this->body_file), $php_errormsg);
+								$success=0;
+								}
+                                $i = 0;
+   								while(!feof($file) && $success)
+								    {
+                                    $i++;
+									if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
+									    {
+										$this->SetPHPError(_("could not read upload file"), $php_errormsg);
+										$success=0;
+										break;
+									    }
+									if(!($success=$this->PutData($block)))
+										break;
+								    }
+                                if($success) 
+                                    $success = $this->PutData($added_char);
+								fclose($file);
+                            }
+                    }
+                    // }}} END OF HACK
 					else
 					{
 						for($part=0;$part<count($post_parts);$part++)
@@ -1072,8 +1190,14 @@
 						if($success)
 							$success=$this->PutLine("--".$boundary."--");
 					}
-					if($success)
+                    // {{{ HACKED FOR IPP
+                    $read = array($this->connection);
+					if($success )
+                        if(!stream_select($read, $write = NULL, $except = NULL, 0))
 						$sucess=$this->FlushData();
+					//if($success )
+						   //$sucess=$this->FlushData();
+                    // }}} END OF HACK    
 				}
 			}
 		}
