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

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