b2ed3a1
diff -up cups-1.4.2/cups/util.c.str3435 cups-1.4.2/cups/util.c
b2ed3a1
--- cups-1.4.2/cups/util.c.str3435	2009-06-22 21:44:34.000000000 +0100
b2ed3a1
+++ cups-1.4.2/cups/util.c	2009-12-08 12:11:38.647375446 +0000
b2ed3a1
@@ -1511,12 +1511,36 @@ cupsPrintFiles2(
b2ed3a1
       return (0);
b2ed3a1
     }
b2ed3a1
 
b2ed3a1
-    status = cupsStartDocument(http, name, job_id, docname, format,
b2ed3a1
-                               i == (num_files - 1));
b2ed3a1
+    do
b2ed3a1
+    {
b2ed3a1
+      cupsFileRewind(fp);
b2ed3a1
+
b2ed3a1
+      status = cupsStartDocument(http, name, job_id, docname, format,
b2ed3a1
+			         i == (num_files - 1));
b2ed3a1
+
b2ed3a1
+      while (status == HTTP_CONTINUE &&
b2ed3a1
+	     (bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
b2ed3a1
+        status = cupsWriteRequestData(http, buffer, bytes);
b2ed3a1
+
b2ed3a1
+      if (status == HTTP_UNAUTHORIZED)
b2ed3a1
+      {
b2ed3a1
+        char	resource[1024];		/* Printer resource */
b2ed3a1
 
b2ed3a1
-    while (status == HTTP_CONTINUE &&
b2ed3a1
-           (bytes = cupsFileRead(fp, buffer, sizeof(buffer))) > 0)
b2ed3a1
-      status = cupsWriteRequestData(http, buffer, bytes);
b2ed3a1
+        snprintf(resource, sizeof(resource), "/printers/%s", name);
b2ed3a1
+
b2ed3a1
+        if (!cupsDoAuthentication(http, "POST", resource))
b2ed3a1
+        {
b2ed3a1
+	  if (httpReconnect(http))
b2ed3a1
+	  {
b2ed3a1
+	    _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
b2ed3a1
+	    return (0);
b2ed3a1
+	  }
b2ed3a1
+        }
b2ed3a1
+	else
b2ed3a1
+	  status = HTTP_AUTHORIZATION_CANCELED;
b2ed3a1
+      }
b2ed3a1
+    }
b2ed3a1
+    while (status == HTTP_UNAUTHORIZED);
b2ed3a1
 
b2ed3a1
     cupsFileClose(fp);
b2ed3a1