Skip to content

Commit f666f28

Browse files
committed
Use cupsGetFile() API
1 parent d11164c commit f666f28

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

cgi-bin/admin.c

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -938,34 +938,22 @@ do_am_printer(http_t *http, /* I - HTTP connection */
938938
int fd; /* PPD file */
939939
char filename[1024]; /* PPD filename */
940940
ppd_file_t *ppd; /* PPD information */
941-
char buffer[1024]; /* Buffer */
942-
ssize_t bytes; /* Number of bytes */
943-
http_status_t get_status; /* Status of GET */
944941

945-
946-
/* TODO: Use cupsGetFile() API... */
947-
snprintf(uri, sizeof(uri), "/printers/%s.ppd", name);
948-
949-
if (httpGet(http, uri))
950-
httpGet(http, uri);
951-
952-
while ((get_status = httpUpdate(http)) == HTTP_STATUS_CONTINUE);
953-
954-
if (get_status != HTTP_STATUS_OK)
942+
if ((fd = cupsCreateTempFd(NULL, NULL, filename, sizeof(filename))) < 0)
955943
{
956-
httpFlush(http);
957-
958-
fprintf(stderr, "ERROR: Unable to get PPD file %s: %d - %s\n",
959-
uri, get_status, httpStatus(get_status));
944+
fprintf(stderr, "ERROR: Unable to create temporary file: %s\n",
945+
strerror(errno));
960946
}
961-
else if ((fd = cupsTempFd(filename, sizeof(filename))) >= 0)
947+
else
962948
{
963-
while ((bytes = httpRead2(http, buffer, sizeof(buffer))) > 0)
964-
write(fd, buffer, (size_t)bytes);
965-
966-
close(fd);
967-
968-
if ((ppd = ppdOpenFile(filename)) != NULL)
949+
close(fd); // Close the temp fd since cupsGetFile will reopen it
950+
951+
if (cupsGetFile(http, uri, filename) != HTTP_STATUS_OK)
952+
{
953+
fprintf(stderr, "ERROR: Unable to get PPD file %s: %s\n",
954+
uri, cupsGetErrorString());
955+
}
956+
else if ((ppd = ppdOpenFile(filename)) != NULL)
969957
{
970958
if (ppd->manufacturer)
971959
cgiSetVariable("CURRENT_MAKE", ppd->manufacturer);
@@ -984,14 +972,6 @@ do_am_printer(http_t *http, /* I - HTTP connection */
984972
filename, ppdErrorString(ppdLastError(&linenum)));
985973
}
986974
}
987-
else
988-
{
989-
httpFlush(http);
990-
991-
fprintf(stderr,
992-
"ERROR: Unable to create temporary file for PPD file: %s\n",
993-
strerror(errno));
994-
}
995975
}
996976

997977
/*

0 commit comments

Comments
 (0)