]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add support for auto-configuration (STR #1440)
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 24 Sep 2008 23:08:34 +0000 (23:08 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 24 Sep 2008 23:08:34 +0000 (23:08 +0000)
Fix modify-printer usage.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@7980 7a7537e8-13f0-0310-91df-b6672ffda945

CHANGES.txt
cgi-bin/admin.c
cups/cups.h
templates/set-printer-options-header.tmpl

index db5c885bf4bc7eded3008fdc9a0f97486c5c3b5c..5d1f556204cfb7103528d35ba4c14674f6b0f684 100644 (file)
@@ -1,9 +1,11 @@
-CHANGES.txt - 2008-09-20
+CHANGES.txt - 2008-09-24
 ------------------------
 
 CHANGES IN CUPS V1.4b1
 
        - Documentation updates (STR #2567)
+       - The "set printer options" page now supports auto-configuration
+         of printer options (STR #1440)
        - The web interface now provides an advanced server settings
          form.
        - The web interface's "modify printer" pages now make it
index ad6ed09479e8321af82ce1f9ca5eebc81b7b22c6..df95197a5cb53c7e35ddc34827faf1e32365aaf1 100644 (file)
@@ -910,7 +910,7 @@ do_am_printer(http_t *http,         /* I - HTTP connection */
       */
 
       if (strncmp(attr->values[0].string.text, var, strlen(var)) == 0)
-       cgiSetVariable("DEVICE_URI", attr->values[0].string.text);
+       cgiSetVariable("CURRENT_DEVICE_URI", attr->values[0].string.text);
     }
 
    /*
@@ -957,7 +957,15 @@ do_am_printer(http_t *http,                /* I - HTTP connection */
       */
 
       if (oldinfo)
-       cgiSetIPPVars(oldinfo, NULL, NULL, NULL, 0);
+      {
+        if ((attr = ippFindAttribute(oldinfo, "printer-info",
+                                    IPP_TAG_TEXT)) != NULL)
+          cgiSetVariable("PRINTER_INFO", attr->values[0].string.text);
+
+        if ((attr = ippFindAttribute(oldinfo, "printer-location",
+                                    IPP_TAG_TEXT)) != NULL)
+          cgiSetVariable("PRINTER_LOCATION", attr->values[0].string.text);
+      }
 
       cgiCopyTemplateLang("modify-printer.tmpl");
     }
@@ -3041,7 +3049,7 @@ do_set_options(http_t *http,              /* I - HTTP connection */
   ppd_option_t *option;                /* Option */
   ppd_coption_t        *coption;               /* Custom option */
   ppd_cparam_t *cparam;                /* Custom parameter */
-  ppd_attr_t   *protocol;              /* cupsProtocol attribute */
+  ppd_attr_t   *ppdattr;               /* PPD attribute */
   const char   *title;                 /* Page title */
 
 
@@ -3069,6 +3077,67 @@ do_set_options(http_t *http,             /* I - HTTP connection */
 
   fprintf(stderr, "DEBUG: printer=\"%s\", uri=\"%s\"...\n", printer, uri);
 
+ /*
+  * If the user clicks on the Auto-Configure button, send an AutoConfigure
+  * command file to the printer...
+  */
+
+  if (cgiGetVariable("AUTOCONFIGURE"))
+  {
+    int                        job_id;         /* Command file job */
+    char               refresh[1024];  /* Refresh URL */
+    http_status_t      status;         /* Document status */
+    static const char  *autoconfigure =/* Command file */
+                       "#CUPS-COMMAND\n"
+                       "AutoConfigure\n";
+
+
+    if ((job_id = cupsCreateJob(CUPS_HTTP_DEFAULT, printer, "Auto-Configure",
+                                0, NULL)) < 1)
+    {
+      cgiSetVariable("ERROR", cgiText(_("Unable to send auto-configure command "
+                                        "to printer driver!")));
+      cgiStartHTML(title);
+      cgiCopyTemplateLang("error.tmpl");
+      cgiEndHTML();
+      return;
+    }
+
+    status = cupsStartDocument(CUPS_HTTP_DEFAULT, printer, job_id,
+                               "AutoConfigure.command", CUPS_FORMAT_COMMAND, 1);
+    if (status == HTTP_CONTINUE)
+      status = cupsWriteRequestData(CUPS_HTTP_DEFAULT, autoconfigure,
+                                    strlen(autoconfigure));
+    if (status == HTTP_CONTINUE)
+      cupsFinishDocument(CUPS_HTTP_DEFAULT, printer);
+
+    if (cupsLastError() >= IPP_REDIRECTION_OTHER_SITE)
+    {
+      cgiSetVariable("ERROR", cupsLastErrorString());
+      cgiStartHTML(title);
+      cgiCopyTemplateLang("error.tmpl");
+      cgiEndHTML();
+
+      cupsCancelJob(job_id);
+      return;
+    }
+
+   /*
+    * Redirect successful updates back to the printer page...
+    */
+
+    cgiFormEncode(uri, printer, sizeof(uri));
+    snprintf(refresh, sizeof(refresh), "5;URL=/admin/?OP=redirect&URL=/%s/%s",
+            is_class ? "classes" : "printers", uri);
+    cgiSetVariable("refresh_page", refresh);
+
+    cgiStartHTML(title);
+
+    cgiCopyTemplateLang("printer-configured.tmpl");
+    cgiEndHTML();
+    return;
+  }
+
  /*
   * Get the PPD file...
   */
@@ -3126,6 +3195,23 @@ do_set_options(http_t *http,             /* I - HTTP connection */
 
     fputs("DEBUG: Showing options...\n", stderr);
 
+    if (ppd)
+    {
+      if (ppd->num_filters == 0 ||
+          ((ppdattr = ppdFindAttr(ppd, "cupsCommands", NULL)) != NULL &&
+           ppdattr->value && strstr(ppdattr->value, "AutoConfigure")))
+        cgiSetVariable("HAVE_AUTOCONFIGURE", "YES");
+      else 
+      {
+        for (i = 0; i < ppd->num_filters; i ++)
+         if (!strncmp(ppd->filters[i], "application/vnd.cups-postscript", 31))
+         {
+           cgiSetVariable("HAVE_AUTOCONFIGURE", "YES");
+           break;
+         }
+      }
+    }
+
     cgiStartHTML(cgiText(_("Set Printer Options")));
     cgiCopyTemplateLang("set-printer-options-header.tmpl");
 
@@ -3458,7 +3544,7 @@ do_set_options(http_t *http,              /* I - HTTP connection */
 
     if (ppd && ppd->protocols && strstr(ppd->protocols, "BCP"))
     {
-      protocol = ppdFindAttr(ppd, "cupsProtocol", NULL);
+      ppdattr = ppdFindAttr(ppd, "cupsProtocol", NULL);
 
       cgiSetVariable("GROUP", cgiText(_("PS Binary Protocol")));
       cgiCopyTemplateLang("option-header.tmpl");
@@ -3481,7 +3567,7 @@ do_set_options(http_t *http,              /* I - HTTP connection */
 
       cgiSetVariable("KEYWORD", "protocol");
       cgiSetVariable("KEYTEXT", cgiText(_("PS Binary Protocol")));
-      cgiSetVariable("DEFCHOICE", protocol ? protocol->value : "None");
+      cgiSetVariable("DEFCHOICE", ppdattr ? ppdattr->value : "None");
 
       cgiCopyTemplateLang("option-pickone.tmpl");
 
index bf2e9a06d34d28406fd9eb1ca14acbe726bd14ac..886a793b342aecc0372c0cfb1f36f31aa9a4df6f 100644 (file)
@@ -68,6 +68,7 @@ extern "C" {
 #  define CUPS_DATE_ANY                (time_t)-1
 #  define CUPS_EXCLUDE_NONE    (const char *)0
 #  define CUPS_FORMAT_AUTO     "application/octet-stream"
+#  define CUPS_FORMAT_COMMAND  "application/vnd.cups-command"
 #  define CUPS_FORMAT_PDF      "application/pdf"
 #  define CUPS_FORMAT_POSTSCRIPT "application/postscript"
 #  define CUPS_FORMAT_RAW      "application/vnd.cups-raw"
index fb59e65d4cd469cbe4a5fa36056b2b8b938150fa..dad328a83a1409c71ed2b18438bbba33e764d9bb 100644 (file)
@@ -3,6 +3,7 @@
 <FORM METHOD="POST" ACTION="/admin">
 <INPUT TYPE="HIDDEN" NAME="PRINTER_NAME" VALUE="{printer_name}">
 <INPUT TYPE="HIDDEN" NAME="OP" VALUE="{op}">
+{HAVE_AUTOCONFIGURE?<INPUT TYPE="SUBMIT" NAME="AUTOCONFIGURE" VALUE="Auto-Configure Options">:}
 
 <SCRIPT TYPE="text/javascript"><!--
 function update_paramtable(option)