]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Use cupsGetFile() API 1193/head
authorRose <gfunni234@gmail.com>
Mon, 10 Mar 2025 00:40:42 +0000 (20:40 -0400)
committerRose <gfunni234@gmail.com>
Mon, 10 Mar 2025 14:01:46 +0000 (10:01 -0400)
cgi-bin/admin.c

index 0032fbd5aa791739a8986b98613023860c0e080f..d02caf3239cd36996bef8333607095e703afb848 100644 (file)
@@ -938,34 +938,22 @@ do_am_printer(http_t *http,               /* I - HTTP connection */
       int              fd;             /* PPD file */
       char             filename[1024]; /* PPD filename */
       ppd_file_t       *ppd;           /* PPD information */
-      char             buffer[1024];   /* Buffer */
-      ssize_t          bytes;          /* Number of bytes */
-      http_status_t    get_status;     /* Status of GET */
 
-
-      /* TODO: Use cupsGetFile() API... */
-      snprintf(uri, sizeof(uri), "/printers/%s.ppd", name);
-
-      if (httpGet(http, uri))
-        httpGet(http, uri);
-
-      while ((get_status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);
-
-      if (get_status != HTTP_STATUS_OK)
+      if ((fd = cupsCreateTempFd(NULL, NULL, filename, sizeof(filename))) < 0)
       {
-        httpFlush(http);
-
-        fprintf(stderr, "ERROR: Unable to get PPD file %s: %d - %s\n",
-               uri, get_status, httpStatus(get_status));
+        fprintf(stderr, "ERROR: Unable to create temporary file: %s\n",
+                strerror(errno));
       }
-      else if ((fd = cupsTempFd(filename, sizeof(filename))) >= 0)
+      else 
       {
-       while ((bytes = httpRead2(http, buffer, sizeof(buffer))) > 0)
-          write(fd, buffer, (size_t)bytes);
-
-       close(fd);
-
-        if ((ppd = ppdOpenFile(filename)) != NULL)
+        close(fd); // Close the temp fd since cupsGetFile will reopen it
+        
+        if (cupsGetFile(http, uri, filename) != HTTP_STATUS_OK)
+        {
+          fprintf(stderr, "ERROR: Unable to get PPD file %s: %s\n",
+                  uri, cupsGetErrorString());
+        }
+        else if ((ppd = ppdOpenFile(filename)) != NULL)
        {
          if (ppd->manufacturer)
            cgiSetVariable("CURRENT_MAKE", ppd->manufacturer);
@@ -984,14 +972,6 @@ do_am_printer(http_t *http,                /* I - HTTP connection */
                  filename, ppdErrorString(ppdLastError(&linenum)));
        }
       }
-      else
-      {
-        httpFlush(http);
-
-        fprintf(stderr,
-               "ERROR: Unable to create temporary file for PPD file: %s\n",
-               strerror(errno));
-      }
     }
 
    /*