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

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