Blame SOURCES/cups-ippeve-web-support.patch

a17bb8
diff --git a/cgi-bin/admin.c b/cgi-bin/admin.c
a17bb8
index a604a8a..e678f24 100644
a17bb8
--- a/cgi-bin/admin.c
a17bb8
+++ b/cgi-bin/admin.c
a17bb8
@@ -974,6 +974,13 @@ do_am_printer(http_t *http,		/* I - HTTP connection */
a17bb8
 
a17bb8
         cgiSetVariable("TEMPLATE_NAME", template);
a17bb8
       }
a17bb8
+
a17bb8
+     /*
a17bb8
+      * Set DEVICE_URI to the actual device uri, without make and model from
a17bb8
+      * html form.
a17bb8
+      */
a17bb8
+
a17bb8
+      cgiSetVariable("DEVICE_URI", var);
a17bb8
     }
a17bb8
   }
a17bb8
 
a17bb8
@@ -1137,6 +1144,8 @@ do_am_printer(http_t *http,		/* I - HTTP connection */
a17bb8
   else if (!file &&
a17bb8
            (!cgiGetVariable("PPD_NAME") || cgiGetVariable("SELECT_MAKE")))
a17bb8
   {
a17bb8
+    int ipp_everywhere = !strncmp(var, "ipp://", 6) || !strncmp(var, "ipps://", 7) || (!strncmp(var, "dnssd://", 8) && (strstr(var, "_ipp._tcp") || strstr(var, "_ipps._tcp")));
a17bb8
+
a17bb8
     if (modify && !cgiGetVariable("SELECT_MAKE"))
a17bb8
     {
a17bb8
      /*
a17bb8
@@ -1282,9 +1291,8 @@ do_am_printer(http_t *http,		/* I - HTTP connection */
a17bb8
         cgiStartHTML(title);
a17bb8
 	if (!cgiGetVariable("PPD_MAKE"))
a17bb8
 	  cgiSetVariable("PPD_MAKE", cgiGetVariable("CURRENT_MAKE"));
a17bb8
-	if (!modify)
a17bb8
-	  cgiSetVariable("CURRENT_MAKE_AND_MODEL",
a17bb8
-	                 cgiGetArray("PPD_MAKE_AND_MODEL", 0));
a17bb8
+        if (ipp_everywhere)
a17bb8
+	  cgiSetVariable("SHOW_IPP_EVERYWHERE", "1");
a17bb8
 	cgiCopyTemplateLang("choose-model.tmpl");
a17bb8
         cgiEndHTML();
a17bb8
       }
a17bb8
@@ -4219,6 +4227,11 @@ get_printer_ppd(const char *uri,	/* I - Printer URI */
a17bb8
 		host[256],		/* Hostname */
a17bb8
 		resource[256];		/* Resource path */
a17bb8
   int		port;			/* Port number */
a17bb8
+  static const char * const pattrs[] =	/* Printer attributes we need */
a17bb8
+  {
a17bb8
+    "all",
a17bb8
+    "media-col-database"
a17bb8
+  };
a17bb8
 
a17bb8
 
a17bb8
  /*
a17bb8
@@ -4259,6 +4272,7 @@ get_printer_ppd(const char *uri,	/* I - Printer URI */
a17bb8
 
a17bb8
   request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
a17bb8
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
a17bb8
+  ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes",  (int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
a17bb8
   response = cupsDoRequest(http, request, resource);
a17bb8
 
a17bb8
   if (!_ppdCreateFromIPP(buffer, bufsize, response))
a17bb8
diff --git a/cups/ppd-cache.c b/cups/ppd-cache.c
a17bb8
index e5f89ee..b8139c8 100644
a17bb8
--- a/cups/ppd-cache.c
a17bb8
+++ b/cups/ppd-cache.c
a17bb8
@@ -3089,8 +3089,8 @@ _ppdCreateFromIPP(char   *buffer,	/* I - Filename buffer */
a17bb8
   cupsFilePrintf(fp, "*Manufacturer: \"%s\"\n", make);
a17bb8
   cupsFilePrintf(fp, "*ModelName: \"%s\"\n", model);
a17bb8
   cupsFilePrintf(fp, "*Product: \"(%s)\"\n", model);
a17bb8
-  cupsFilePrintf(fp, "*NickName: \"%s\"\n", model);
a17bb8
-  cupsFilePrintf(fp, "*ShortNickName: \"%s\"\n", model);
a17bb8
+  cupsFilePrintf(fp, "*NickName: \"%s - IPP Everywhere\"\n", model);
a17bb8
+  cupsFilePrintf(fp, "*ShortNickName: \"%s - IPP Everywhere\"\n", model);
a17bb8
 
a17bb8
   if ((attr = ippFindAttribute(response, "color-supported", IPP_TAG_BOOLEAN)) != NULL && ippGetBoolean(attr, 0))
a17bb8
     cupsFilePuts(fp, "*ColorDevice: True\n");
a17bb8
diff --git a/scheduler/ipp.c b/scheduler/ipp.c
a17bb8
index 5e9a985..4ed3c39 100644
a17bb8
--- a/scheduler/ipp.c
a17bb8
+++ b/scheduler/ipp.c
a17bb8
@@ -5829,6 +5829,12 @@ create_local_bg_thread(
a17bb8
   ipp_t		*request,		/* Request to printer */
a17bb8
 		*response;		/* Response from printer */
a17bb8
   ipp_attribute_t *attr;		/* Attribute in response */
a17bb8
+  ipp_status_t	status;			/* Status code */
a17bb8
+  static const char * const pattrs[] =	/* Printer attributes we need */
a17bb8
+  {
a17bb8
+    "all",
a17bb8
+    "media-col-database"
a17bb8
+  };
a17bb8
 
a17bb8
 
a17bb8
  /*
a17bb8
@@ -5861,12 +5867,35 @@ create_local_bg_thread(
a17bb8
   cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: Connected to %s:%d, sending Get-Printer-Attributes request...", printer->name, host, port);
a17bb8
 
a17bb8
   request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
a17bb8
+  ippSetVersion(request, 2, 0);
a17bb8
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printer->device_uri);
a17bb8
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", NULL, "all");
a17bb8
+  ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", (int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
a17bb8
 
a17bb8
   response = cupsDoRequest(http, request, resource);
a17bb8
+  status   = cupsLastError();
a17bb8
+
a17bb8
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: Get-Printer-Attributes returned %s (%s)", printer->name, ippErrorString(cupsLastError()), cupsLastErrorString());
a17bb8
+
a17bb8
+  if (status == IPP_STATUS_ERROR_BAD_REQUEST || status == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
a17bb8
+  {
a17bb8
+   /*
a17bb8
+    * Try request using IPP/1.1, in case we are talking to an old CUPS server or
a17bb8
+    * printer...
a17bb8
+    */
a17bb8
 
a17bb8
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: Get-Printer-Attributes returned %s", printer->name, ippErrorString(cupsLastError()));
a17bb8
+    ippDelete(response);
a17bb8
+
a17bb8
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: Re-sending Get-Printer-Attributes request using IPP/1.1...", printer->name);
a17bb8
+
a17bb8
+    request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
a17bb8
+    ippSetVersion(request, 1, 1);
a17bb8
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printer->device_uri);
a17bb8
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", NULL, "all");
a17bb8
+
a17bb8
+    response = cupsDoRequest(http, request, resource);
a17bb8
+
a17bb8
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "%s: IPP/1.1 Get-Printer-Attributes returned %s (%s)", printer->name, ippErrorString(cupsLastError()), cupsLastErrorString());
a17bb8
+  }
a17bb8
 
a17bb8
   // TODO: Grab printer icon file...
a17bb8
   httpClose(http);
a17bb8
@@ -5877,6 +5906,8 @@ create_local_bg_thread(
a17bb8
 
a17bb8
   if (_ppdCreateFromIPP(fromppd, sizeof(fromppd), response))
a17bb8
   {
a17bb8
+    _cupsRWLockWrite(&printer->lock);
a17bb8
+
a17bb8
     if ((!printer->info || !*(printer->info)) && (attr = ippFindAttribute(response, "printer-info", IPP_TAG_TEXT)) != NULL)
a17bb8
       cupsdSetString(&printer->info, ippGetString(attr, 0, NULL));
a17bb8
 
a17bb8
@@ -5886,6 +5917,8 @@ create_local_bg_thread(
a17bb8
     if ((!printer->geo_location || !*(printer->geo_location)) && (attr = ippFindAttribute(response, "printer-geo-location", IPP_TAG_URI)) != NULL)
a17bb8
       cupsdSetString(&printer->geo_location, ippGetString(attr, 0, NULL));
a17bb8
 
a17bb8
+    _cupsRWUnlock(&printer->lock);
a17bb8
+
a17bb8
     if ((from = cupsFileOpen(fromppd, "r")) == NULL)
a17bb8
     {
a17bb8
       cupsdLogMessage(CUPSD_LOG_ERROR, "%s: Unable to read generated PPD: %s", printer->name, strerror(errno));
a17bb8
diff --git a/systemv/lpadmin.c b/systemv/lpadmin.c
a17bb8
index bb53565..f3510ca 100644
a17bb8
--- a/systemv/lpadmin.c
a17bb8
+++ b/systemv/lpadmin.c
a17bb8
@@ -33,7 +33,7 @@ static int		delete_printer_from_class(http_t *http, char *printer,
a17bb8
 static int		delete_printer_option(http_t *http, char *printer,
a17bb8
 			                      char *option);
a17bb8
 static int		enable_printer(http_t *http, char *printer);
a17bb8
-static char		*get_printer_ppd(const char *uri, char *buffer, size_t bufsize);
a17bb8
+static char		*get_printer_ppd(const char *uri, char *buffer, size_t bufsize, int *num_options, cups_option_t **options);
a17bb8
 static cups_ptype_t	get_printer_type(http_t *http, char *printer, char *uri,
a17bb8
 			                 size_t urisize);
a17bb8
 static int		set_printer_options(http_t *http, char *printer,
a17bb8
@@ -593,7 +593,7 @@ main(int  argc,			/* I - Number of command-line arguments */
a17bb8
 
a17bb8
   if ((ppd_name = cupsGetOption("ppd-name", num_options, options)) != NULL && !strcmp(ppd_name, "everywhere") && (device_uri = cupsGetOption("device-uri", num_options, options)) != NULL)
a17bb8
   {
a17bb8
-    if ((file = get_printer_ppd(device_uri, evefile, sizeof(evefile))) == NULL)
a17bb8
+    if ((file = get_printer_ppd(device_uri, evefile, sizeof(evefile), &num_options, &options)) == NULL)
a17bb8
       return (1);
a17bb8
 
a17bb8
     num_options = cupsRemoveOption("ppd-name", num_options, &options);
a17bb8
@@ -1144,20 +1144,29 @@ enable_printer(http_t *http,		/* I - Server connection */
a17bb8
  * 'get_printer_ppd()' - Get an IPP Everywhere PPD file for the given URI.
a17bb8
  */
a17bb8
 
a17bb8
-static char *				/* O - Filename or NULL */
a17bb8
-get_printer_ppd(const char *uri,	/* I - Printer URI */
a17bb8
-                char       *buffer,	/* I - Filename buffer */
a17bb8
-		size_t     bufsize)	/* I - Size of filename buffer */
a17bb8
+static char *				/* O  - Filename or NULL */
a17bb8
+get_printer_ppd(
a17bb8
+    const char    *uri,			/* I  - Printer URI */
a17bb8
+    char          *buffer,		/* I  - Filename buffer */
a17bb8
+    size_t        bufsize,		/* I  - Size of filename buffer */
a17bb8
+    int           *num_options,		/* IO - Number of options */
a17bb8
+    cups_option_t **options)		/* IO - Options */
a17bb8
 {
a17bb8
   http_t	*http;			/* Connection to printer */
a17bb8
   ipp_t		*request,		/* Get-Printer-Attributes request */
a17bb8
 		*response;		/* Get-Printer-Attributes response */
a17bb8
+  ipp_attribute_t *attr;		/* Attribute from response */
a17bb8
   char		resolved[1024],		/* Resolved URI */
a17bb8
 		scheme[32],		/* URI scheme */
a17bb8
 		userpass[256],		/* Username:password */
a17bb8
 		host[256],		/* Hostname */
a17bb8
 		resource[256];		/* Resource path */
a17bb8
   int		port;			/* Port number */
a17bb8
+  static const char * const pattrs[] =	/* Attributes to use */
a17bb8
+  {
a17bb8
+    "all",
a17bb8
+    "media-col-database"
a17bb8
+  };
a17bb8
 
a17bb8
 
a17bb8
  /*
a17bb8
@@ -1198,9 +1207,26 @@ get_printer_ppd(const char *uri,	/* I - Printer URI */
a17bb8
 
a17bb8
   request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
a17bb8
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
a17bb8
+  ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]), NULL, pattrs);
a17bb8
   response = cupsDoRequest(http, request, resource);
a17bb8
 
a17bb8
-  if (!_ppdCreateFromIPP(buffer, bufsize, response))
a17bb8
+  if (cupsLastError() >= IPP_STATUS_REDIRECTION_OTHER_SITE)
a17bb8
+  {
a17bb8
+    _cupsLangPrintf(stderr, _("%s: Unable to query printer: %s"), "lpadmin", cupsLastErrorString());
a17bb8
+    buffer[0] = '\0';
a17bb8
+  }
a17bb8
+  else if (_ppdCreateFromIPP(buffer, bufsize, response))
a17bb8
+  {
a17bb8
+    if (!cupsGetOption("printer-geo-location", *num_options, *options) && (attr = ippFindAttribute(response, "printer-geo-location", IPP_TAG_URI)) != NULL)
a17bb8
+      *num_options = cupsAddOption("printer-geo-location", ippGetString(attr, 0, NULL), *num_options, options);
a17bb8
+
a17bb8
+    if (!cupsGetOption("printer-info", *num_options, *options) && (attr = ippFindAttribute(response, "printer-info", IPP_TAG_TEXT)) != NULL)
a17bb8
+      *num_options = cupsAddOption("printer-info", ippGetString(attr, 0, NULL), *num_options, options);
a17bb8
+
a17bb8
+    if (!cupsGetOption("printer-location", *num_options, *options) && (attr = ippFindAttribute(response, "printer-location", IPP_TAG_TEXT)) != NULL)
a17bb8
+      *num_options = cupsAddOption("printer-location", ippGetString(attr, 0, NULL), *num_options, options);
a17bb8
+  }
a17bb8
+  else
a17bb8
     _cupsLangPrintf(stderr, _("%s: Unable to create PPD file: %s"), "lpadmin", strerror(errno));
a17bb8
 
a17bb8
   ippDelete(response);
a17bb8
diff --git a/templates/choose-model.tmpl b/templates/choose-model.tmpl
a17bb8
index ee9338c..9c9b71f 100644
a17bb8
--- a/templates/choose-model.tmpl
a17bb8
+++ b/templates/choose-model.tmpl
a17bb8
@@ -39,6 +39,7 @@
a17bb8
 
a17bb8
 <SELECT NAME="PPD_NAME" SIZE="10">
a17bb8
 {op=add-printer?:<OPTION VALUE="__no_change__" SELECTED>Current Driver - {current_make_and_model}</OPTION>:}
a17bb8
+{show_ipp_everywhere?<OPTION VALUE="everywhere" SELECTED>{current_make_and_model?{current_make_and_model} -:} IPP Everywhere ™</OPTION>:}
a17bb8
 {[ppd_name]<OPTION VALUE="{ppd_name}" {op=modify-printer?:{?current_make_and_model={ppd_make_and_model}?SELECTED:}}>{ppd_make_and_model} ({ppd_natural_language})
a17bb8
 }</SELECT>
a17bb8
 
a17bb8
diff --git a/templates/de/choose-model.tmpl b/templates/de/choose-model.tmpl
a17bb8
index cb9b6f3..c73ccb2 100644
a17bb8
--- a/templates/de/choose-model.tmpl
a17bb8
+++ b/templates/de/choose-model.tmpl
a17bb8
@@ -39,6 +39,7 @@ Drucker {?printer_is_shared=?nicht:{?printer_is_shared=0?nicht:}} im Netzwerk fr
a17bb8
 
a17bb8
 <SELECT NAME="PPD_NAME" SIZE="10">
a17bb8
 {op=add-printer?:<OPTION VALUE="__no_change__" SELECTED>Aktueller Treiber - {current_make_and_model}</OPTION>:}
a17bb8
+{show_ipp_everywhere?<OPTION VALUE="everywhere" SELECTED>{current_make_and_model?{current_make_and_model} -:} IPP Everywhere ™</OPTION>:}
a17bb8
 {[ppd_name]<OPTION VALUE="{ppd_name}" {op=modify-printer?:{?current_make_and_model={ppd_make_and_model}?SELECTED:}}>{ppd_make_and_model} ({ppd_natural_language})
a17bb8
 }</SELECT>
a17bb8
 
a17bb8
diff --git a/templates/es/choose-model.tmpl b/templates/es/choose-model.tmpl
a17bb8
index 8a5a4ba..b5624f2 100644
a17bb8
--- a/templates/es/choose-model.tmpl
a17bb8
+++ b/templates/es/choose-model.tmpl
a17bb8
@@ -39,6 +39,7 @@
a17bb8
 
a17bb8
 <SELECT NAME="PPD_NAME" SIZE="10">
a17bb8
 {op=add-printer?:<OPTION VALUE="__no_change__" SELECTED>Controlador actual - {current_make_and_model}</OPTION>:}
a17bb8
+{show_ipp_everywhere?<OPTION VALUE="everywhere" SELECTED>{current_make_and_model?{current_make_and_model} -:} IPP Everywhere ™</OPTION>:}
a17bb8
 {[ppd_name]<OPTION VALUE="{ppd_name}" {op=modify-printer?:{?current_make_and_model={ppd_make_and_model}?SELECTED:}}>{ppd_make_and_model} ({ppd_natural_language})
a17bb8
 }</SELECT>
a17bb8
 
a17bb8
diff --git a/templates/fr/choose-model.tmpl b/templates/fr/choose-model.tmpl
a17bb8
index a4e771c..07cf93c 100644
a17bb8
--- a/templates/fr/choose-model.tmpl
a17bb8
+++ b/templates/fr/choose-model.tmpl
a17bb8
@@ -39,6 +39,7 @@
a17bb8
 
a17bb8
 <SELECT NAME="PPD_NAME" SIZE="10">
a17bb8
 {op=add-printer?:<OPTION VALUE="__no_change__" SELECTED>Pilote courant - {current_make_and_model}</OPTION>:}
a17bb8
+{show_ipp_everywhere?<OPTION VALUE="everywhere" SELECTED>{current_make_and_model?{current_make_and_model} -:} IPP Everywhere ™</OPTION>:}
a17bb8
 {[ppd_name]<OPTION VALUE="{ppd_name}" {op=modify-printer?:{?current_make_and_model={ppd_make_and_model}?SELECTED:}}>{ppd_make_and_model} ({ppd_natural_language})
a17bb8
 }</SELECT>
a17bb8
 
a17bb8
diff --git a/templates/ja/choose-model.tmpl b/templates/ja/choose-model.tmpl
a17bb8
index daf1375..6a6e4e4 100644
a17bb8
--- a/templates/ja/choose-model.tmpl
a17bb8
+++ b/templates/ja/choose-model.tmpl
a17bb8
@@ -39,6 +39,7 @@
a17bb8
 
a17bb8
 <SELECT NAME="PPD_NAME" SIZE="10">
a17bb8
 {op=add-printer?:<OPTION VALUE="__no_change__" SELECTED>現在のドライバー - {current_make_and_model}</OPTION>:}
a17bb8
+{show_ipp_everywhere?<OPTION VALUE="everywhere" SELECTED>{current_make_and_model?{current_make_and_model} -:} IPP Everywhere ™</OPTION>:}
a17bb8
 {[ppd_name]<OPTION VALUE="{ppd_name}" {op=modify-printer?:{?current_make_and_model={ppd_make_and_model}?SELECTED:}}>{ppd_make_and_model} ({ppd_natural_language})
a17bb8
 }</SELECT>
a17bb8
 
a17bb8
diff --git a/templates/pt_BR/choose-model.tmpl b/templates/pt_BR/choose-model.tmpl
a17bb8
index 55d8bd8..0ed6a3c 100644
a17bb8
--- a/templates/pt_BR/choose-model.tmpl
a17bb8
+++ b/templates/pt_BR/choose-model.tmpl
a17bb8
@@ -39,6 +39,7 @@
a17bb8
 
a17bb8
 <SELECT NAME="PPD_NAME" SIZE="10">
a17bb8
 {op=add-printer?:<OPTION VALUE="__no_change__" SELECTED>Driver atual - {current_make_and_model}</OPTION>:}
a17bb8
+{show_ipp_everywhere?<OPTION VALUE="everywhere" SELECTED>{current_make_and_model?{current_make_and_model} -:} IPP Everywhere ™</OPTION>:}
a17bb8
 {[ppd_name]<OPTION VALUE="{ppd_name}" {op=modify-printer?:{?current_make_and_model={ppd_make_and_model}?SELECTED:}}>{ppd_make_and_model} ({ppd_natural_language})
a17bb8
 }</SELECT>
a17bb8
 
a17bb8
diff --git a/templates/ru/choose-model.tmpl b/templates/ru/choose-model.tmpl
a17bb8
index 2f0d6d9..dedbd49 100644
a17bb8
--- a/templates/ru/choose-model.tmpl
a17bb8
+++ b/templates/ru/choose-model.tmpl
a17bb8
@@ -39,6 +39,7 @@
a17bb8
 
a17bb8
 <SELECT NAME="PPD_NAME" SIZE="10">
a17bb8
 {op=add-printer?:<OPTION VALUE="__no_change__" SELECTED>Текущий драйвер - {current_make_and_model}</OPTION>:}
a17bb8
+{show_ipp_everywhere?<OPTION VALUE="everywhere" SELECTED>{current_make_and_model?{current_make_and_model} -:} IPP Everywhere ™</OPTION>:}
a17bb8
 {[ppd_name]<OPTION VALUE="{ppd_name}" {op=modify-printer?:{?current_make_and_model={ppd_make_and_model}?SELECTED:}}>{ppd_make_and_model} ({ppd_natural_language})
a17bb8
 }</SELECT>
a17bb8