]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpadmin.c
Import CUPS v2.0.3
[thirdparty/cups.git] / systemv / lpadmin.c
index 2431edc91a1edad77e6c7d8e356c21f36ff2cc08..1f6f9da19f91faed5e352095600d8e558b4b0ae4 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: lpadmin.c 11558 2014-02-06 18:33:34Z msweet $"
+ * "$Id: lpadmin.c 12604 2015-05-06 01:43:05Z msweet $"
  *
  * "lpadmin" command for CUPS.
  *
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2015 by Apple Inc.
  * Copyright 1997-2006 by Easy Software Products.
  *
  * These coded instructions, statements, and computer programs are the
@@ -1233,7 +1233,7 @@ set_printer_options(
 {
   ipp_t                *request;               /* IPP Request */
   const char   *ppdfile;               /* PPD filename */
-  int          ppdchanged;             /* PPD changed? */
+  int          ppdchanged = 0;         /* PPD changed? */
   ppd_file_t   *ppd;                   /* PPD file */
   ppd_choice_t *choice;                /* Marked choice */
   char         uri[HTTP_MAX_URI],      /* URI for printer/class */
@@ -1243,11 +1243,13 @@ set_printer_options(
                tempfile[1024];         /* Temporary filename */
   cups_file_t  *in,                    /* PPD file */
                *out;                   /* Temporary file */
-  const char   *protocol,              /* Old protocol option */
+  const char   *ppdname,               /* ppd-name value */
+               *protocol,              /* Old protocol option */
                *customval,             /* Custom option value */
                *boolval;               /* Boolean value */
   int          wrote_ipp_supplies = 0, /* Wrote cupsIPPSupplies keyword? */
-               wrote_snmp_supplies = 0;/* Wrote cupsSNMPSupplies keyword? */
+               wrote_snmp_supplies = 0,/* Wrote cupsSNMPSupplies keyword? */
+               copied_options = 0;     /* Copied options? */
 
 
   DEBUG_printf(("set_printer_options(http=%p, printer=\"%s\", num_options=%d, "
@@ -1294,6 +1296,26 @@ set_printer_options(
 
   if (file)
     ppdfile = file;
+  else if ((ppdname = cupsGetOption("ppd-name", num_options, options)) != NULL && strcmp(ppdname, "raw") && num_options > 1)
+  {
+    if ((ppdfile = cupsGetServerPPD(http, ppdname)) != NULL)
+    {
+     /*
+      * Copy options array and remove ppd-name from it...
+      */
+
+      cups_option_t *temp = NULL, *optr;
+      int i, num_temp = 0;
+      for (i = num_options, optr = options; i > 0; i --, optr ++)
+        if (strcmp(optr->name, "ppd-name"))
+         num_temp = cupsAddOption(optr->name, optr->value, num_temp, &temp);
+
+      copied_options = 1;
+      ppdchanged     = 1;
+      num_options    = num_temp;
+      options        = temp;
+    }
+  }
   else if (request->request.op.operation_id == CUPS_ADD_MODIFY_PRINTER)
     ppdfile = cupsGetPPD(printer);
   else
@@ -1305,7 +1327,15 @@ set_printer_options(
     * Set default options in the PPD file...
     */
 
-    ppd = ppdOpenFile(ppdfile);
+    if ((ppd = ppdOpenFile(ppdfile)) == NULL)
+    {
+      int              linenum;        /* Line number of error */
+      ppd_status_t     status = ppdLastError(&linenum);
+                                       /* Status code */
+
+      _cupsLangPrintf(stderr, _("lpadmin: Unable to open PPD \"%s\": %s on line %d."), ppdfile, ppdErrorString(status), linenum);
+    }
+
     ppdMarkDefaults(ppd);
     cupsMarkOptions(ppd, num_options, options);
 
@@ -1315,6 +1345,8 @@ set_printer_options(
       ippDelete(request);
       if (ppdfile != file)
         unlink(ppdfile);
+      if (copied_options)
+        cupsFreeOptions(num_options, options);
       return (1);
     }
 
@@ -1326,13 +1358,13 @@ set_printer_options(
       ippDelete(request);
       if (ppdfile != file)
        unlink(ppdfile);
+      if (copied_options)
+        cupsFreeOptions(num_options, options);
       cupsFileClose(out);
       unlink(tempfile);
       return (1);
     }
 
-    ppdchanged = 0;
-
     while (cupsFileGets(in, line, sizeof(line)))
     {
       if (!strncmp(line, "*cupsIPPSupplies:", 17) &&
@@ -1454,6 +1486,9 @@ set_printer_options(
     ippDelete(cupsDoRequest(http, request, "/admin/"));
   }
 
+  if (copied_options)
+    cupsFreeOptions(num_options, options);
+
  /*
   * Check the response...
   */
@@ -1499,5 +1534,5 @@ validate_name(const char *name)           /* I - Name to check */
 
 
 /*
- * End of "$Id: lpadmin.c 11558 2014-02-06 18:33:34Z msweet $".
+ * End of "$Id: lpadmin.c 12604 2015-05-06 01:43:05Z msweet $".
  */