/*
- * "$Id: auth.c,v 1.68 2003/01/31 17:48:23 mike Exp $"
+ * "$Id: auth.c,v 1.69 2003/03/30 19:50:33 mike Exp $"
*
* Authorization routines for the Common UNIX Printing System (CUPS).
*
const char *group, /* I - Group */
char passwd[33]) /* O - MD5 password string */
{
- FILE *fp; /* passwd.md5 file */
- char filename[1024], /* passwd.md5 filename */
- line[256], /* Line from file */
- tempuser[33], /* User from file */
- tempgroup[33]; /* Group from file */
+ cups_file_t *fp; /* passwd.md5 file */
+ char filename[1024], /* passwd.md5 filename */
+ line[256], /* Line from file */
+ tempuser[33], /* User from file */
+ tempgroup[33]; /* Group from file */
LogMessage(L_DEBUG2, "GetMD5Passwd(username=\"%s\", group=\"%s\", passwd=%p)",
username, group ? group : "(null)", passwd);
snprintf(filename, sizeof(filename), "%s/passwd.md5", ServerRoot);
- if ((fp = fopen(filename, "r")) == NULL)
+ if ((fp = cupsFileOpen(filename, "r")) == NULL)
{
LogMessage(L_ERROR, "Unable to open %s - %s", filename, strerror(errno));
return (NULL);
}
- while (fgets(line, sizeof(line), fp) != NULL)
+ while (cupsFileGets(fp, line, sizeof(line)) != NULL)
{
if (sscanf(line, "%32[^:]:%32[^:]:%32s", tempuser, tempgroup, passwd) != 3)
{
LogMessage(L_DEBUG2, "Found MD5 user %s, group %s...", username,
tempgroup);
- fclose(fp);
+ cupsFileClose(fp);
return (passwd);
}
}
* Didn't find a password entry - return NULL!
*/
- fclose(fp);
+ cupsFileClose(fp);
return (NULL);
}
/*
- * End of "$Id: auth.c,v 1.68 2003/01/31 17:48:23 mike Exp $".
+ * End of "$Id: auth.c,v 1.69 2003/03/30 19:50:33 mike Exp $".
*/
/*
- * "$Id: cert.c,v 1.16 2003/01/24 20:39:43 mike Exp $"
+ * "$Id: cert.c,v 1.17 2003/03/30 19:50:33 mike Exp $"
*
* Authentication certificate routines for the Common UNIX
* Printing System (CUPS).
void
InitCerts(void)
{
- FILE *fp; /* /dev/random file */
+ cups_file_t *fp; /* /dev/random file */
unsigned seed; /* Seed for random number generator */
struct timeval tod; /* Time of day */
* the current time, as available...
*/
- if ((fp = fopen("/dev/urandom", "rb")) == NULL)
+ if ((fp = cupsFileOpen("/dev/urandom", "rb")) == NULL)
{
/*
* Get the time in usecs and use it as the initial seed...
* them as the seed...
*/
- seed = getc(fp);
- seed = (seed << 8) | getc(fp);
- seed = (seed << 8) | getc(fp);
- seed = (seed << 8) | getc(fp);
+ seed = cupsFileGetChar(fp);
+ seed = (seed << 8) | cupsFileGetChar(fp);
+ seed = (seed << 8) | cupsFileGetChar(fp);
+ seed = (seed << 8) | cupsFileGetChar(fp);
- fclose(fp);
+ cupsFileClose(fp);
}
srandom(seed);
/*
- * End of "$Id: cert.c,v 1.16 2003/01/24 20:39:43 mike Exp $".
+ * End of "$Id: cert.c,v 1.17 2003/03/30 19:50:33 mike Exp $".
*/
/*
- * "$Id: classes.c,v 1.48 2003/03/10 19:27:50 mike Exp $"
+ * "$Id: classes.c,v 1.49 2003/03/30 19:50:33 mike Exp $"
*
* Printer class routines for the Common UNIX Printing System (CUPS).
*
void
LoadAllClasses(void)
{
- FILE *fp; /* classes.conf file */
+ cups_file_t *fp; /* classes.conf file */
int linenum; /* Current line number */
int len; /* Length of line */
char line[1024], /* Line from file */
*/
snprintf(line, sizeof(line), "%s/classes.conf", ServerRoot);
- if ((fp = fopen(line, "r")) == NULL)
+ if ((fp = cupsFileOpen(line, "r")) == NULL)
{
LogMessage(L_ERROR, "LoadAllClasses: Unable to open %s - %s", line,
strerror(errno));
linenum = 0;
p = NULL;
- while (fgets(line, sizeof(line), fp) != NULL)
+ while (cupsFileGets(fp, line, sizeof(line)) != NULL)
{
linenum ++;
}
}
- fclose(fp);
+ cupsFileClose(fp);
}
void
SaveAllClasses(void)
{
- FILE *fp; /* classes.conf file */
+ cups_file_t *fp; /* classes.conf file */
char temp[1024]; /* Temporary string */
char backup[1024]; /* classes.conf.O file */
printer_t *pclass; /* Current printer class */
if (rename(temp, backup))
LogMessage(L_ERROR, "Unable to backup classes.conf - %s", strerror(errno));
- if ((fp = fopen(temp, "w")) == NULL)
+ if ((fp = cupsFileOpen(temp, "w")) == NULL)
{
LogMessage(L_ERROR, "Unable to save classes.conf - %s", strerror(errno));
* Restrict access to the file...
*/
- fchown(fileno(fp), User, Group);
- fchmod(fileno(fp), 0600);
+ fchown(cupsFileNumber(fp), User, Group);
+ fchmod(cupsFileNumber(fp), 0600);
/*
* Write a small header to the file...
curdate = gmtime(&curtime);
strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
- fputs("# Class configuration file for " CUPS_SVERSION "\n", fp);
- fprintf(fp, "# Written by cupsd on %s\n", temp);
+ cupsFilePuts(fp, "# Class configuration file for " CUPS_SVERSION "\n");
+ cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
/*
* Write each local class known to the system...
*/
if (pclass == DefaultPrinter)
- fprintf(fp, "<DefaultClass %s>\n", pclass->name);
+ cupsFilePrintf(fp, "<DefaultClass %s>\n", pclass->name);
else
- fprintf(fp, "<Class %s>\n", pclass->name);
+ cupsFilePrintf(fp, "<Class %s>\n", pclass->name);
if (pclass->info)
- fprintf(fp, "Info %s\n", pclass->info);
+ cupsFilePrintf(fp, "Info %s\n", pclass->info);
if (pclass->location)
- fprintf(fp, "Location %s\n", pclass->location);
+ cupsFilePrintf(fp, "Location %s\n", pclass->location);
if (pclass->state == IPP_PRINTER_STOPPED)
{
- fputs("State Stopped\n", fp);
- fprintf(fp, "StateMessage %s\n", pclass->state_message);
+ cupsFilePuts(fp, "State Stopped\n");
+ cupsFilePrintf(fp, "StateMessage %s\n", pclass->state_message);
}
else
- fputs("State Idle\n", fp);
+ cupsFilePuts(fp, "State Idle\n");
if (pclass->accepting)
- fputs("Accepting Yes\n", fp);
+ cupsFilePuts(fp, "Accepting Yes\n");
else
- fputs("Accepting No\n", fp);
+ cupsFilePuts(fp, "Accepting No\n");
- fprintf(fp, "JobSheets %s %s\n", pclass->job_sheets[0],
- pclass->job_sheets[1]);
+ cupsFilePrintf(fp, "JobSheets %s %s\n", pclass->job_sheets[0],
+ pclass->job_sheets[1]);
for (i = 0; i < pclass->num_printers; i ++)
- fprintf(fp, "Printer %s\n", pclass->printers[i]->name);
+ cupsFilePrintf(fp, "Printer %s\n", pclass->printers[i]->name);
- fprintf(fp, "QuotaPeriod %d\n", pclass->quota_period);
- fprintf(fp, "PageLimit %d\n", pclass->page_limit);
- fprintf(fp, "KLimit %d\n", pclass->k_limit);
+ cupsFilePrintf(fp, "QuotaPeriod %d\n", pclass->quota_period);
+ cupsFilePrintf(fp, "PageLimit %d\n", pclass->page_limit);
+ cupsFilePrintf(fp, "KLimit %d\n", pclass->k_limit);
for (i = 0; i < pclass->num_users; i ++)
- fprintf(fp, "%sUser %s\n", pclass->deny_users ? "Deny" : "Allow",
- pclass->users[i]);
+ cupsFilePrintf(fp, "%sUser %s\n", pclass->deny_users ? "Deny" : "Allow",
+ pclass->users[i]);
- fputs("</Class>\n", fp);
+ cupsFilePuts(fp, "</Class>\n");
}
- fclose(fp);
+ cupsFileClose(fp);
}
/*
- * End of "$Id: classes.c,v 1.48 2003/03/10 19:27:50 mike Exp $".
+ * End of "$Id: classes.c,v 1.49 2003/03/30 19:50:33 mike Exp $".
*/
/*
- * "$Id: client.c,v 1.154 2003/03/28 22:27:59 mike Exp $"
+ * "$Id: client.c,v 1.155 2003/03/30 19:50:33 mike Exp $"
*
* Client routines for the Common UNIX Printing System (CUPS) scheduler.
*
static http_status_t /* O - Status */
install_conf_file(client_t *con) /* I - Connection */
{
- FILE *in, /* Input file */
+ cups_file_t *in, /* Input file */
*out; /* Output file */
char buffer[1024]; /* Copy buffer */
int bytes; /* Number of bytes */
* Open the request file and new config file...
*/
- if ((in = fopen(con->filename, "rb")) == NULL)
+ if ((in = cupsFileOpen(con->filename, "rb")) == NULL)
{
LogMessage(L_ERROR, "Unable to open request file \"%s\" - %s",
con->filename, strerror(errno));
return (HTTP_SERVER_ERROR);
}
- if ((out = fopen(newfile, "wb")) == NULL)
+ if ((out = cupsFileOpen(newfile, "wb")) == NULL)
{
- fclose(in);
+ cupsFileClose(in);
LogMessage(L_ERROR, "Unable to open config file \"%s\" - %s",
newfile, strerror(errno));
return (HTTP_SERVER_ERROR);
}
- fchmod(fileno(out), confinfo.st_mode);
- fchown(fileno(out), confinfo.st_uid, confinfo.st_gid);
+ fchmod(cupsFileNumber(out), confinfo.st_mode);
+ fchown(cupsFileNumber(out), confinfo.st_uid, confinfo.st_gid);
/*
* Copy from the request to the new config file...
*/
- while ((bytes = fread(buffer, 1, sizeof(buffer), in)) > 0)
- if (fwrite(buffer, 1, bytes, out) < bytes)
+ while ((bytes = cupsFileRead(in, buffer, sizeof(buffer))) > 0)
+ if (cupsFileWrite(out, buffer, bytes) < bytes)
{
LogMessage(L_ERROR, "Unable to copy to config file \"%s\" - %s",
newfile, strerror(errno));
- fclose(in);
- fclose(out);
+ cupsFileClose(in);
+ cupsFileClose(out);
unlink(newfile);
return (HTTP_SERVER_ERROR);
* Close the files...
*/
- fclose(in);
- if (fclose(out))
+ cupsFileClose(in);
+ if (cupsFileClose(out))
{
LogMessage(L_ERROR, "Error file closing config file \"%s\" - %s",
newfile, strerror(errno));
/*
- * End of "$Id: client.c,v 1.154 2003/03/28 22:27:59 mike Exp $".
+ * End of "$Id: client.c,v 1.155 2003/03/30 19:50:33 mike Exp $".
*/
/*
- * "$Id: conf.c,v 1.127 2003/03/19 06:06:02 mike Exp $"
+ * "$Id: conf.c,v 1.128 2003/03/30 19:50:34 mike Exp $"
*
* Configuration routines for the Common UNIX Printing System (CUPS).
*
* Local functions...
*/
-static int read_configuration(FILE *fp);
-static int read_location(FILE *fp, char *name, int linenum);
+static int read_configuration(cups_file_t *fp);
+static int read_location(cups_file_t *fp, char *name, int linenum);
static int get_address(char *value, unsigned defaddress, int defport,
struct sockaddr_in *address);
ReadConfiguration(void)
{
int i; /* Looping var */
- FILE *fp; /* Configuration file */
+ cups_file_t *fp; /* Configuration file */
int status; /* Return status */
char temp[1024], /* Temporary buffer */
*slash; /* Directory separator */
* Read the configuration file...
*/
- if ((fp = fopen(ConfigurationFile, "r")) == NULL)
+ if ((fp = cupsFileOpen(ConfigurationFile, "r")) == NULL)
return (0);
status = read_configuration(fp);
- fclose(fp);
+ cupsFileClose(fp);
if (!status)
return (0);
*/
static int /* O - 1 on success, 0 on failure */
-read_configuration(FILE *fp) /* I - File to read from */
+read_configuration(cups_file_t *fp) /* I - File to read from */
{
int i; /* Looping var */
int linenum; /* Current line number */
dirsvc_poll_t *poll; /* Polling data */
struct sockaddr_in polladdr; /* Polling address */
location_t *location; /* Browse location */
- FILE *incfile; /* Include file */
+ cups_file_t *incfile; /* Include file */
char incname[1024]; /* Include filename */
static unsigned netmasks[4] = /* Standard netmasks... */
{
linenum = 0;
- while (fgets(line, sizeof(line), fp) != NULL)
+ while (cupsFileGets(fp, line, sizeof(line)) != NULL)
{
linenum ++;
else
snprintf(incname, sizeof(incname), "%s/%s", ServerRoot, value);
- if ((incfile = fopen(incname, "rb")) == NULL)
+ if ((incfile = cupsFileOpen(incname, "rb")) == NULL)
LogMessage(L_ERROR, "Unable to include config file \"%s\" - %s",
incname, strerror(errno));
else
{
read_configuration(incfile);
- fclose(incfile);
+ cupsFileClose(incfile);
}
}
else if (strcasecmp(name, "<Location") == 0)
* 'read_location()' - Read a <Location path> definition.
*/
-static int /* O - New line number or 0 on error */
-read_location(FILE *fp, /* I - Configuration file */
- char *location, /* I - Location name/path */
- int linenum) /* I - Current line number */
+static int /* O - New line number or 0 on error */
+read_location(cups_file_t *fp, /* I - Configuration file */
+ char *location, /* I - Location name/path */
+ int linenum) /* I - Current line number */
{
int i; /* Looping var */
location_t *loc, /* New location */
parent->limit = AUTH_LIMIT_ALL;
loc = parent;
- while (fgets(line, sizeof(line), fp) != NULL)
+ while (cupsFileGets(fp, line, sizeof(line)) != NULL)
{
linenum ++;
/*
- * End of "$Id: conf.c,v 1.127 2003/03/19 06:06:02 mike Exp $".
+ * End of "$Id: conf.c,v 1.128 2003/03/30 19:50:34 mike Exp $".
*/
/*
- * "$Id: conf.h,v 1.55 2003/03/19 06:06:02 mike Exp $"
+ * "$Id: conf.h,v 1.56 2003/03/30 19:50:34 mike Exp $"
*
* Configuration file definitions for the Common UNIX Printing System (CUPS)
* scheduler.
/* Run as unpriviledged user? */
PrintcapFormat VALUE(PRINTCAP_BSD);
/* Format of printcap file? */
-VAR FILE *AccessFile VALUE(NULL),
+VAR cups_file_t *AccessFile VALUE(NULL),
/* Access log file */
*ErrorFile VALUE(NULL),
/* Error log file */
/*
- * End of "$Id: conf.h,v 1.55 2003/03/19 06:06:02 mike Exp $".
+ * End of "$Id: conf.h,v 1.56 2003/03/30 19:50:34 mike Exp $".
*/
/*
- * "$Id: file.c,v 1.1 2003/03/28 22:27:59 mike Exp $"
+ * "$Id: file.c,v 1.2 2003/03/30 19:50:34 mike Exp $"
*
* File functions for the Common UNIX Printing System (CUPS).
*
* Contents:
*
* cupsFileClose() - Close a CUPS file.
+ * cupsFileFlush() - Flush pending output.
* cupsFileGetChar() - Get a single character from a file.
* cupsFileGets() - Get a CR and/or LF-terminated line.
* cupsFileOpen() - Open a CUPS file.
* cupsFilePrintf() - Write a formatted string.
+ * cupsFilePutChar() - Write a character.
* cupsFilePuts() - Write a string.
+ * cupsFileRead() - Read from a file.
+ * cupsFileSeek() - Seek in a file.
+ * cupsFileWrite() - Write to a file.
* cups_fill() - Fill the input buffer...
* cups_read() - Read from a file descriptor.
* cups_write() - Write to a file descriptor.
inflateEnd(&fp->stream);
#endif /* HAVE_LIBZ */
+ if (fp->mode == 'w')
+ cupsFileFlush(fp);
+
/*
* Save the file descriptor we used and free memory...
*/
}
+/*
+ * 'cupsFileFlush()' - Flush pending output.
+ */
+
+int /* O - 0 on success, -1 on error */
+cupsFileFlush(cups_file_t *fp) /* I - CUPS file */
+{
+ int bytes; /* Bytes to write */
+
+
+ /*
+ * Range check input...
+ */
+
+ if (!fp || fp->mode != 'w')
+ return (-1);
+
+ bytes = fp->ptr - fp->buf;
+
+ if (bytes > 0)
+ {
+ if (cups_write(fp->fd, fp->buf, bytes) < bytes)
+ return (-1);
+
+ fp->ptr = fp->buf;
+ }
+
+ return (0);
+}
+
+
/*
* 'cupsFileGetChar()' - Get a single character from a file.
*/
* Range check input...
*/
- if (!filename || !mode || (*mode != 'r' && *mode != 'w'))
+ if (!filename || !mode || (*mode != 'r' && *mode != 'w' && *mode != 'a'))
return (NULL);
/*
* Open the file...
*/
- if (*mode == 'r')
- o = O_RDONLY;
- else
- o = O_WRONLY | O_TRUNC | O_CREAT;
+ switch (*mode)
+ {
+ case 'a' :
+ o = O_RDWR | O_CREAT;
+ fp->mode = 'w';
+ break;
+
+ case 'r' :
+ o = O_RDONLY;
+ fp->mode = 'r';
+ break;
+
+ case 'w' :
+ o = O_WRONLY | O_TRUNC | O_CREAT;
+ fp->mode = 'w';
+ break;
+ }
if ((fp->fd = open(filename, o, 0644)) < 0)
{
return (NULL);
}
- fp->mode = *mode;
+ if (*mode == 'a')
+ fp->pos = lseek(fp->fd, 0, SEEK_END);
+ else
+ fp->pos = 0;
+
+ if (*mode != 'r')
+ {
+ fp->ptr = fp->buf;
+ fp->end = fp->buf + sizeof(fp->buf);
+ }
return (fp);
}
{
va_list ap; /* Argument list */
int bytes; /* Formatted size */
+ char buf[2048]; /* Formatted text */
if (!fp || !format || fp->mode != 'w')
return (-1);
va_start(ap, format);
- bytes = vsnprintf(fp->buf, sizeof(fp->buf), format, ap);
+ bytes = vsnprintf(buf, sizeof(buf), format, ap);
va_end(ap);
- return (cups_write(fp->fd, fp->buf, bytes));
+ if ((fp->ptr + bytes) > fp->end)
+ if (cupsFileFlush(fp))
+ return (-1);
+
+ fp->pos += bytes;
+
+ if (bytes > sizeof(fp->buf))
+ return (cups_write(fp->fd, buf, bytes));
+ else
+ {
+ memcpy(fp->ptr, buf, bytes);
+ fp->ptr += bytes;
+ return (bytes);
+ }
+}
+
+
+/*
+ * 'cupsFilePutChar()' - Write a character.
+ */
+
+int /* O - 0 on success, -1 on error */
+cupsFilePutChar(cups_file_t *fp, /* I - CUPS file */
+ int c) /* I - Character to write */
+{
+ /*
+ * Range check input...
+ */
+
+ if (!fp || fp->mode != 'w')
+ return (-1);
+
+ /*
+ * Buffer it up...
+ */
+
+ if (fp->ptr >= fp->end)
+ if (cupsFileFlush(fp))
+ return (-1);
+
+ *(fp->ptr) ++ = c;
+ fp->pos ++;
+
+ return (0);
}
cupsFilePuts(cups_file_t *fp, /* I - CUPS file */
const char *s) /* I - String to write */
{
+ int bytes; /* Bytes to write */
+
+
/*
* Range check input...
*/
* Write the string...
*/
- return (cups_write(fp->fd, s, strlen(s)));
+ bytes = strlen(s);
+
+ if ((fp->ptr + bytes) > fp->end)
+ if (cupsFileFlush(fp))
+ return (-1);
+
+ fp->pos += bytes;
+
+ if (bytes > sizeof(fp->buf))
+ return (cups_write(fp->fd, s, bytes));
+ else
+ {
+ memcpy(fp->ptr, s, bytes);
+ fp->ptr += bytes;
+ return (bytes);
+ }
}
}
+/*
+ * 'cupsFileWrite()' - Write to a file.
+ */
+
+int /* O - Number of bytes written */
+cupsFileWrite(cups_file_t *fp, /* I - CUPS file */
+ const char *buf, /* I - Buffer */
+ int bytes) /* I - Number of bytes to write */
+{
+ /*
+ * Range check input...
+ */
+
+ if (!fp || !buf || bytes <= 0 || fp->mode != 'w')
+ return (-1);
+
+ /*
+ * Write the buffer...
+ */
+
+ if ((fp->ptr + bytes) > fp->end)
+ if (cupsFileFlush(fp))
+ return (-1);
+
+ fp->pos += bytes;
+
+ if (bytes > sizeof(fp->buf))
+ return (cups_write(fp->fd, buf, bytes));
+ else
+ {
+ memcpy(fp->ptr, buf, bytes);
+ fp->ptr += bytes;
+ return (bytes);
+ }
+}
+
+
/*
* 'cups_fill()' - Fill the input buffer...
*/
/*
- * End of "$Id: file.c,v 1.1 2003/03/28 22:27:59 mike Exp $".
+ * End of "$Id: file.c,v 1.2 2003/03/30 19:50:34 mike Exp $".
*/
/*
- * "$Id: file.h,v 1.1 2003/03/28 22:28:00 mike Exp $"
+ * "$Id: file.h,v 1.2 2003/03/30 19:50:34 mike Exp $"
*
* File definitions for the Common UNIX Printing System (CUPS).
*
*/
extern int cupsFileClose(cups_file_t *fp);
+#define cupsFileCompressed(fp) (fp)->compressed
+extern int cupsFileFlush(cups_file_t *fp);
extern int cupsFileGetChar(cups_file_t *fp);
extern char *cupsFileGets(cups_file_t *fp, char *buf, int buflen);
+#define cupsFileNumber(fp) (fp)->fd
extern cups_file_t *cupsFileOpen(const char *filename, const char *mode);
extern int cupsFilePrintf(cups_file_t *fp, const char *format, ...);
+extern int cupsFilePutChar(cups_file_t *fp, int c);
extern int cupsFilePuts(cups_file_t *fp, const char *s);
extern int cupsFileRead(cups_file_t *fp, char *buf, int bytes);
extern int cupsFileSeek(cups_file_t *fp, int pos);
+#define cupsFileTell(fp) (fp)->pos
+extern int cupsFileWrite(cups_file_t *fp, const char *buf, int bytes);
# ifdef _cplusplus
#endif /* !_CUPS_FILE_H_ */
/*
- * End of "$Id: file.h,v 1.1 2003/03/28 22:28:00 mike Exp $".
+ * End of "$Id: file.h,v 1.2 2003/03/30 19:50:34 mike Exp $".
*/
/*
- * "$Id: ipp.c,v 1.199 2003/03/28 17:31:22 mike Exp $"
+ * "$Id: ipp.c,v 1.200 2003/03/30 19:50:34 mike Exp $"
*
* IPP routines for the Common UNIX Printing System (CUPS) scheduler.
*
int port; /* Port portion of URI */
printer_t *printer; /* Printer/class */
ipp_attribute_t *attr; /* Printer attribute */
-#ifdef HAVE_LIBZ
- gzFile fp; /* Script/PPD file */
-#else
- FILE *fp; /* Script/PPD file */
-#endif /* HAVE_LIBZ */
+ cups_file_t *fp; /* Script/PPD file */
char line[1024]; /* Line from file... */
char srcfile[1024], /* Source Script/PPD file */
dstfile[1024]; /* Destination Script/PPD file */
printer->name);
unlink(dstfile);
}
-#ifdef HAVE_LIBZ
- else if (srcfile[0] && (fp = gzopen(srcfile, "rb")) != NULL)
-#else
- else if (srcfile[0] && (fp = fopen(srcfile, "rb")) != NULL)
-#endif /* HAVE_LIBZ */
+ else if (srcfile[0] && (fp = cupsFileOpen(srcfile, "rb")) != NULL)
{
/*
* Yes; get the first line from it...
*/
line[0] = '\0';
-#ifdef HAVE_LIBZ
- gzgets(fp, line, sizeof(line));
- gzclose(fp);
-#else
- fgets(line, sizeof(line), fp);
- fclose(fp);
-#endif /* HAVE_LIBZ */
+ cupsFileGets(fp, line, sizeof(line));
+ cupsFileClose(fp);
/*
* Then see what kind of file it is...
int kbytes; /* Size of banner file in kbytes */
char filename[1024]; /* Job filename */
banner_t *banner; /* Pointer to banner */
- FILE *in; /* Input file */
- FILE *out; /* Output file */
+ cups_file_t *in; /* Input file */
+ cups_file_t *out; /* Output file */
int ch; /* Character from file */
char attrname[255], /* Name of attribute */
*s; /* Pointer into name */
snprintf(filename, sizeof(filename), "%s/d%05d-%03d", RequestRoot, job->id,
job->num_files);
- if ((out = fopen(filename, "w")) == NULL)
+ if ((out = cupsFileOpen(filename, "w")) == NULL)
{
LogMessage(L_ERROR, "copy_banner: Unable to create banner job file %s - %s",
filename, strerror(errno));
return (0);
}
- fchmod(fileno(out), 0640);
- fchown(fileno(out), User, Group);
+ fchmod(cupsFileNumber(out), 0640);
+ fchown(cupsFileNumber(out), User, Group);
if (con->language)
{
snprintf(filename, sizeof(filename), "%s/banners/%s", DataDir, name);
}
- if ((in = fopen(filename, "r")) == NULL)
+ if ((in = cupsFileOpen(filename, "r")) == NULL)
{
- fclose(out);
+ cupsFileClose(out);
unlink(filename);
LogMessage(L_ERROR, "copy_banner: Unable to open banner template file %s - %s",
filename, strerror(errno));
* Parse the file to the end...
*/
- while ((ch = getc(in)) != EOF)
+ while ((ch = cupsFileGetChar(in)) != EOF)
if (ch == '{')
{
/*
* Get an attribute name...
*/
- for (s = attrname; (ch = getc(in)) != EOF;)
+ for (s = attrname; (ch = cupsFileGetChar(in)) != EOF;)
if (!isalpha(ch) && ch != '-' && ch != '?')
break;
else if (s < (attrname + sizeof(attrname) - 1))
* Ignore { followed by stuff that is not an attribute name...
*/
- putc('{', out);
- fputs(attrname, out);
- putc(ch, out);
+ cupsFilePrintf(out, "{%s}", attrname);
continue;
}
* Nope, write to file as-is; probably a PostScript procedure...
*/
- putc('{', out);
- fputs(attrname, out);
- putc('}', out);
+ cupsFilePrintf(out, "{%s}", attrname);
}
continue;
for (i = 0; i < attr->num_values; i ++)
{
if (i)
- putc(',', out);
+ cupsFilePutChar(out, ',');
switch (attr->value_tag)
{
case IPP_TAG_INTEGER :
case IPP_TAG_ENUM :
if (strncmp(s, "time-at-", 8) == 0)
- fputs(GetDateTime(attr->values[i].integer), out);
+ cupsFilePuts(out, GetDateTime(attr->values[i].integer));
else
- fprintf(out, "%d", attr->values[i].integer);
+ cupsFilePrintf(out, "%d", attr->values[i].integer);
break;
case IPP_TAG_BOOLEAN :
- fprintf(out, "%d", attr->values[i].boolean);
+ cupsFilePrintf(out, "%d", attr->values[i].boolean);
break;
case IPP_TAG_NOVALUE :
- fputs("novalue", out);
+ cupsFilePuts(out, "novalue");
break;
case IPP_TAG_RANGE :
- fprintf(out, "%d-%d", attr->values[i].range.lower,
+ cupsFilePrintf(out, "%d-%d", attr->values[i].range.lower,
attr->values[i].range.upper);
break;
case IPP_TAG_RESOLUTION :
- fprintf(out, "%dx%d%s", attr->values[i].resolution.xres,
+ cupsFilePrintf(out, "%dx%d%s", attr->values[i].resolution.xres,
attr->values[i].resolution.yres,
attr->values[i].resolution.units == IPP_RES_PER_INCH ?
"dpi" : "dpc");
{
if (*p == '(' || *p == ')' || *p == '\\')
{
- putc('\\', out);
- putc(*p, out);
+ cupsFilePutChar(out, '\\');
+ cupsFilePutChar(out, *p);
}
else if (*p < 32 || *p > 126)
- fprintf(out, "\\%03o", *p);
+ cupsFilePrintf(out, "\\%03o", *p);
else
- putc(*p, out);
+ cupsFilePutChar(out, *p);
}
}
else
- fputs(attr->values[i].string.text, out);
+ cupsFilePuts(out, attr->values[i].string.text);
break;
default :
}
else if (ch == '\\') /* Quoted char */
{
- ch = getc(in);
+ ch = cupsFileGetChar(in);
if (ch != '{') /* Only do special handling for \{ */
- putc('\\', out);
+ cupsFilePutChar(out, '\\');
- putc(ch, out);
+ cupsFilePutChar(out, ch);
}
else
- putc(ch, out);
+ cupsFilePutChar(out, ch);
- fclose(in);
+ cupsFileClose(in);
kbytes = (ftell(out) + 1023) / 1024;
if ((attr = ippFindAttribute(job->attrs, "job-k-octets", IPP_TAG_INTEGER)) != NULL)
attr->values[0].integer += kbytes;
- fclose(out);
+ cupsFileClose(out);
return (kbytes);
}
/*
- * End of "$Id: ipp.c,v 1.199 2003/03/28 17:31:22 mike Exp $".
+ * End of "$Id: ipp.c,v 1.200 2003/03/30 19:50:34 mike Exp $".
*/
/*
- * "$Id: log.c,v 1.30 2003/03/10 15:05:00 mike Exp $"
+ * "$Id: log.c,v 1.31 2003/03/30 19:50:35 mike Exp $"
*
* Log file routines for the Common UNIX Printing System (CUPS).
*
* Local functions...
*/
-static int check_log_file(FILE **, const char *);
+static int check_log_file(cups_file_t **, const char *);
/*
* Print the log level and date/time...
*/
- fprintf(ErrorFile, "%c %s ", levels[level], GetDateTime(time(NULL)));
+ cupsFilePrintf(ErrorFile, "%c %s ", levels[level], GetDateTime(time(NULL)));
/*
* Then the log message...
* Then a newline...
*/
- fputs(line, ErrorFile);
if (len > 0 && line[len - 1] != '\n')
- putc('\n', ErrorFile);
+ cupsFilePrintf(ErrorFile, "%s\n", line);
+ else
+ cupsFilePuts(ErrorFile, line);
- fflush(ErrorFile);
+ cupsFileFlush(ErrorFile);
ReleaseSignals();
* billing hostname
*/
- fprintf(PageFile, "%s %s %d %s %s %s %s\n", job->printer->name,
- job->username ? job->username : "-",
- job->id, GetDateTime(time(NULL)), page,
- billing ? billing->values[0].string.text : "-",
- hostname->values[0].string.text);
- fflush(PageFile);
+ cupsFilePrintf(PageFile, "%s %s %d %s %s %s %s\n", job->printer->name,
+ job->username ? job->username : "-",
+ job->id, GetDateTime(time(NULL)), page,
+ billing ? billing->values[0].string.text : "-",
+ hostname->values[0].string.text);
+ cupsFileFlush(PageFile);
ReleaseSignals();
* Write a log of the request in "common log format"...
*/
- fprintf(AccessFile, "%s - %s %s \"%s %s HTTP/%d.%d\" %d %d\n",
- con->http.hostname, con->username[0] != '\0' ? con->username : "-",
- GetDateTime(con->start), states[con->operation], con->uri,
- con->http.version / 100, con->http.version % 100,
- code, con->bytes);
- fflush(AccessFile);
+ cupsFilePrintf(AccessFile, "%s - %s %s \"%s %s HTTP/%d.%d\" %d %d\n",
+ con->http.hostname, con->username[0] != '\0' ? con->username : "-",
+ GetDateTime(con->start), states[con->operation], con->uri,
+ con->http.version / 100, con->http.version % 100,
+ code, con->bytes);
+ cupsFileFlush(AccessFile);
ReleaseSignals();
*/
static int /* O - 1 if log file open */
-check_log_file(FILE **log, /* IO - Log file */
- const char *logname) /* I - Log filename */
+check_log_file(cups_file_t **log, /* IO - Log file */
+ const char *logname) /* I - Log filename */
{
char backname[1024], /* Backup log filename */
filename[1024], /* Formatted log filename */
*/
if (*log == NULL ||
- (ftell(*log) > MaxLogSize && MaxLogSize > 0))
+ (cupsFileTell(*log) > MaxLogSize && MaxLogSize > 0))
{
/*
* Handle format strings...
* Nope, open the log file...
*/
- if ((*log = fopen(filename, "a")) == NULL)
+ if ((*log = cupsFileOpen(filename, "a")) == NULL)
return (0);
- fchown(fileno(*log), User, Group);
- fchmod(fileno(*log), LogFilePerm);
+ fchown(cupsFileNumber(*log), User, Group);
+ fchmod(cupsFileNumber(*log), LogFilePerm);
}
/*
* Do we need to rotate the log?
*/
- if (ftell(*log) > MaxLogSize && MaxLogSize > 0)
+ if (cupsFileTell(*log) > MaxLogSize && MaxLogSize > 0)
{
/*
* Rotate log file...
*/
- fclose(*log);
+ cupsFileClose(*log);
strcpy(backname, filename);
strlcat(backname, ".O", sizeof(backname));
unlink(backname);
rename(filename, backname);
- if ((*log = fopen(filename, "a")) == NULL)
+ if ((*log = cupsFileOpen(filename, "a")) == NULL)
return (0);
- fchown(fileno(*log), User, Group);
- fchmod(fileno(*log), LogFilePerm);
+ fchown(cupsFileNumber(*log), User, Group);
+ fchmod(cupsFileNumber(*log), LogFilePerm);
}
return (1);
/*
- * End of "$Id: log.c,v 1.30 2003/03/10 15:05:00 mike Exp $".
+ * End of "$Id: log.c,v 1.31 2003/03/30 19:50:35 mike Exp $".
*/
/*
- * "$Id: main.c,v 1.98 2003/03/21 15:09:34 mike Exp $"
+ * "$Id: main.c,v 1.99 2003/03/30 19:50:35 mike Exp $"
*
* Scheduler main loop for the Common UNIX Printing System (CUPS).
*
struct sigaction action; /* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
#ifdef __sgi
- FILE *fp; /* Fake lpsched lock file */
+ cups_file_t *fp; /* Fake lpsched lock file */
#endif /* __sgi */
* printing...
*/
- if ((fp = fopen("/var/spool/lp/SCHEDLOCK", "a")) == NULL)
+ if ((fp = cupsFileOpen("/var/spool/lp/SCHEDLOCK", "w")) == NULL)
{
syslog(LOG_LPR, "Unable to create fake lpsched lock file "
"\"/var/spool/lp/SCHEDLOCK\"\' - %s!",
}
else
{
- fclose(fp);
+ fchmod(cupsFileNumber(fp), 0644);
+ fchown(cupsFileNumber(fp), User, Group);
- chmod("/var/spool/lp/SCHEDLOCK", 0644);
- chown("/var/spool/lp/SCHEDLOCK", User, Group);
+ cupsFileClose(fp);
}
#endif /* __sgi */
FreeAllJobs();
if (AccessFile != NULL)
- fclose(AccessFile);
+ cupsFileClose(AccessFile);
if (ErrorFile != NULL)
- fclose(ErrorFile);
+ cupsFileClose(ErrorFile);
if (PageFile != NULL)
- fclose(PageFile);
+ cupsFileClose(PageFile);
DeleteAllLocations();
/*
- * End of "$Id: main.c,v 1.98 2003/03/21 15:09:34 mike Exp $".
+ * End of "$Id: main.c,v 1.99 2003/03/30 19:50:35 mike Exp $".
*/
/*
- * "$Id: ppds.c,v 1.27 2002/12/17 19:00:17 swdev Exp $"
+ * "$Id: ppds.c,v 1.28 2003/03/30 19:50:35 mike Exp $"
*
* PPD scanning routines for the Common UNIX Printing System (CUPS).
*
#include "cupsd.h"
#include <ctype.h>
-#ifdef HAVE_LIBZ
-# include <zlib.h>
-#else
-# define gzFile FILE *
-# define gzclose fclose
-# define gzread(f,b,l) fread((b), 1, (l), (f))
-# define gzopen fopen
-#endif /* HAVE_LIBZ */
-
/*
* PPD information structures...
} ppd_info_t;
-/*
- * Buffered file structure...
- */
-
-typedef struct
-{
- gzFile fp; /* Pointer to file */
- char *ptr, /* Pointer in buffer */
- *end, /* End of buffer */
- buf[1024]; /* Buffer */
-} buf_t;
-
-
/*
* Local globals...
*/
* Local functions...
*/
-static int buf_read(buf_t *fp);
static int compare_names(const ppd_info_t *p0, const ppd_info_t *p1);
static int compare_ppds(const ppd_info_t *p0, const ppd_info_t *p1);
static void load_ppds(const char *d, const char *p);
-static char *ppd_gets(buf_t *fp, char *buf, int buflen);
/*
*/
void
-LoadPPDs(const char *d) /* I - Directory to scan... */
+LoadPPDs(const char *d) /* I - Directory to scan... */
{
- int i; /* Looping var */
- ppd_info_t *ppd; /* Current PPD file */
- FILE *fp; /* ppds.dat file */
- struct stat fileinfo; /* ppds.dat information */
- char filename[1024]; /* ppds.dat filename */
+ int i; /* Looping var */
+ ppd_info_t *ppd; /* Current PPD file */
+ cups_file_t *fp; /* ppds.dat file */
+ struct stat fileinfo; /* ppds.dat information */
+ char filename[1024]; /* ppds.dat filename */
/*
num_ppds = 0;
alloc_ppds = 0;
}
- else if ((fp = fopen(filename, "rb")) != NULL)
+ else if ((fp = cupsFileOpen(filename, "rb")) != NULL)
{
for (i = num_ppds, ppd = ppds; i > 0; i --, ppd ++)
{
- fread(&(ppd->record), 1, sizeof(ppd_rec_t), fp);
+ cupsFileRead(fp, (char *)&(ppd->record), sizeof(ppd_rec_t));
ppd->found = 0;
}
- fclose(fp);
+ cupsFileClose(fp);
LogMessage(L_INFO, "LoadPPDs: Read \"%s\", %d PPDs...", filename,
num_ppds);
if (changed_ppd)
{
- if ((fp = fopen(filename, "wb")) != NULL)
+ if ((fp = cupsFileOpen(filename, "wb")) != NULL)
{
for (i = num_ppds, ppd = ppds; i > 0; i --, ppd ++)
- fwrite(&(ppd->record), 1, sizeof(ppd_rec_t), fp);
+ cupsFileWrite(fp, (char *)&(ppd->record), sizeof(ppd_rec_t));
- fclose(fp);
+ cupsFileClose(fp);
LogMessage(L_INFO, "LoadPPDs: Wrote \"%s\", %d PPDs...", filename,
num_ppds);
}
-/*
- * 'buf_read()' - Read a buffer of data into memory...
- */
-
-static int /* O - Number of bytes read */
-buf_read(buf_t *fp) /* I - File to read from */
-{
- int count; /* Number of bytes read */
-
-
- if ((count = gzread(fp->fp, fp->buf, sizeof(fp->buf))) > 0)
- {
- fp->ptr = fp->buf;
- fp->end = fp->buf + count;
- }
- else
- {
- fp->ptr = NULL;
- fp->end = NULL;
- }
-
- return (count);
-}
-
-
/*
* 'compare_names()' - Compare PPD filenames for sorting.
*/
const char *p) /* I - Virtual path in name */
{
int i; /* Looping var */
- buf_t fp; /* Pointer to file */
+ cups_file_t *fp; /* Pointer to file */
DIR *dir; /* Directory pointer */
DIRENT *dent; /* Directory entry */
struct stat fileinfo; /* File information */
* No, file is new/changed, so re-scan it...
*/
- if ((fp.fp = gzopen(filename, "rb")) == NULL)
+ if ((fp = cupsFileOpen(filename, "rb")) == NULL)
continue;
- fp.ptr = fp.end = NULL;
-
/*
* Now see if this is a PPD file...
*/
line[0] = '\0';
- ppd_gets(&fp, line, sizeof(line));
+ cupsFileGets(fp, line, sizeof(line));
if (strncmp(line, "*PPD-Adobe:", 11) != 0)
{
* Nope, close the file and continue...
*/
- gzclose(fp.fp);
+ cupsFileClose(fp);
continue;
}
manufacturer[0] = '\0';
strcpy(language, "en");
- while (ppd_gets(&fp, line, sizeof(line)) != NULL)
+ while (cupsFileGets(fp, line, sizeof(line)) != NULL)
{
if (strncmp(line, "*Manufacturer:", 14) == 0)
sscanf(line, "%*[^\"]\"%255[^\"]", manufacturer);
* Close the file...
*/
- gzclose(fp.fp);
+ cupsFileClose(fp);
/*
* See if we got all of the required info...
/*
- * 'ppd_gets()' - Read a line from a PPD file.
- */
-
-static char * /* O - Line from file or NULL on EOF */
-ppd_gets(buf_t *fp, /* I - File to read from */
- char *buf, /* I - Line buffer */
- int buflen) /* I - Length of buffer */
-{
- int ch; /* Character from file */
- char *ptr, /* Current position in line buffer */
- *end; /* End of line buffer */
-
- /*
- * Range check everything...
- */
-
- if (fp == NULL || buf == NULL || buflen < 2)
- return (NULL);
-
- /*
- * Now loop until we have a valid line...
- */
-
- ptr = buf;
- end = buf + buflen - 1;
-
- for (;;)
- {
- if (fp->ptr >= fp->end)
- if (buf_read(fp) <= 0)
- break;
-
- ch = *(fp->ptr)++;
-
- if (ch == '\r' || ch == '\n')
- {
- /*
- * Line feed or carriage return...
- */
-
- if (ptr == buf) /* Skip blank lines */
- continue;
-
- break;
- }
- else if (ptr < end)
- *ptr++ = ch;
- }
-
- if (ptr > buf)
- {
- *ptr = '\0';
-
- return (buf);
- }
- else
- return (NULL);
-}
-
-
-/*
- * End of "$Id: ppds.c,v 1.27 2002/12/17 19:00:17 swdev Exp $".
+ * End of "$Id: ppds.c,v 1.28 2003/03/30 19:50:35 mike Exp $".
*/
/*
- * "$Id: printers.c,v 1.145 2003/03/28 17:31:23 mike Exp $"
+ * "$Id: printers.c,v 1.146 2003/03/30 19:50:35 mike Exp $"
*
* Printer routines for the Common UNIX Printing System (CUPS).
*
void
LoadAllPrinters(void)
{
- FILE *fp; /* printers.conf file */
+ cups_file_t *fp; /* printers.conf file */
int linenum; /* Current line number */
int len; /* Length of line */
char line[1024], /* Line from file */
*/
snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot);
- if ((fp = fopen(line, "r")) == NULL)
+ if ((fp = cupsFileOpen(line, "r")) == NULL)
{
LogMessage(L_ERROR, "LoadAllPrinters: Unable to open %s - %s", line,
strerror(errno));
linenum = 0;
p = NULL;
- while (fgets(line, sizeof(line), fp) != NULL)
+ while (cupsFileGets(fp, line, sizeof(line)) != NULL)
{
linenum ++;
}
}
- fclose(fp);
+ cupsFileClose(fp);
}
SaveAllPrinters(void)
{
int i; /* Looping var */
- FILE *fp; /* printers.conf file */
+ cups_file_t *fp; /* printers.conf file */
char temp[1024]; /* Temporary string */
char backup[1024]; /* printers.conf.O file */
printer_t *printer; /* Current printer class */
if (rename(temp, backup))
LogMessage(L_ERROR, "Unable to backup printers.conf - %s", strerror(errno));
- if ((fp = fopen(temp, "w")) == NULL)
+ if ((fp = cupsFileOpen(temp, "w")) == NULL)
{
LogMessage(L_ERROR, "Unable to save printers.conf - %s", strerror(errno));
* Restrict access to the file...
*/
- fchown(fileno(fp), User, Group);
- fchmod(fileno(fp), 0600);
+ fchown(cupsFileNumber(fp), User, Group);
+ fchmod(cupsFileNumber(fp), 0600);
/*
* Write a small header to the file...
curdate = gmtime(&curtime);
strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
- fputs("# Printer configuration file for " CUPS_SVERSION "\n", fp);
- fprintf(fp, "# Written by cupsd on %s\n", temp);
+ cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");
+ cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
/*
* Write each local printer known to the system...
*/
if (printer == DefaultPrinter)
- fprintf(fp, "<DefaultPrinter %s>\n", printer->name);
+ cupsFilePrintf(fp, "<DefaultPrinter %s>\n", printer->name);
else
- fprintf(fp, "<Printer %s>\n", printer->name);
+ cupsFilePrintf(fp, "<Printer %s>\n", printer->name);
if (printer->info)
- fprintf(fp, "Info %s\n", printer->info);
+ cupsFilePrintf(fp, "Info %s\n", printer->info);
if (printer->location)
- fprintf(fp, "Location %s\n", printer->location);
+ cupsFilePrintf(fp, "Location %s\n", printer->location);
if (printer->device_uri)
- fprintf(fp, "DeviceURI %s\n", printer->device_uri);
+ cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri);
if (printer->state == IPP_PRINTER_STOPPED)
{
- fputs("State Stopped\n", fp);
- fprintf(fp, "StateMessage %s\n", printer->state_message);
+ cupsFilePuts(fp, "State Stopped\n");
+ cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message);
}
else
- fputs("State Idle\n", fp);
+ cupsFilePuts(fp, "State Idle\n");
if (printer->accepting)
- fputs("Accepting Yes\n", fp);
+ cupsFilePuts(fp, "Accepting Yes\n");
else
- fputs("Accepting No\n", fp);
+ cupsFilePuts(fp, "Accepting No\n");
- fprintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
+ cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
printer->job_sheets[1]);
- fprintf(fp, "QuotaPeriod %d\n", printer->quota_period);
- fprintf(fp, "PageLimit %d\n", printer->page_limit);
- fprintf(fp, "KLimit %d\n", printer->k_limit);
+ cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period);
+ cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit);
+ cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit);
for (i = 0; i < printer->num_users; i ++)
- fprintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
+ cupsFilePrintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
printer->users[i]);
- fputs("</Printer>\n", fp);
+ cupsFilePuts(fp, "</Printer>\n");
#ifdef __sgi
/*
#endif /* __sgi */
}
- fclose(fp);
+ cupsFileClose(fp);
}
void
WritePrintcap(void)
{
- FILE *fp; /* printcap file */
+ cups_file_t *fp; /* printcap file */
printer_t *p; /* Current printer */
* Open the printcap file...
*/
- if ((fp = fopen(Printcap, "w")) == NULL)
+ if ((fp = cupsFileOpen(Printcap, "w")) == NULL)
return;
/*
* data has come from...
*/
- fputs("# This file was automatically generated by cupsd(8) from the\n", fp);
- fprintf(fp, "# %s/printers.conf file. All changes to this file\n",
+ cupsFilePuts(fp, "# This file was automatically generated by cupsd(8) from the\n");
+ cupsFilePrintf(fp, "# %s/printers.conf file. All changes to this file\n",
ServerRoot);
- fputs("# will be lost.\n", fp);
+ cupsFilePuts(fp, "# will be lost.\n");
/*
* Write a new printcap with the current list of printers.
*/
if (DefaultPrinter)
- fprintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
+ cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
DefaultPrinter->info, ServerName, DefaultPrinter->name);
for (p = Printers; p != NULL; p = p->next)
if (p != DefaultPrinter)
- fprintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
+ cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
ServerName, p->name);
break;
* :description=Description:
*/
- fputs("_all:all=", fp);
+ cupsFilePuts(fp, "_all:all=");
for (p = Printers; p != NULL; p = p->next)
- fprintf(fp, "%s%c", p->name, p->next ? ',' : '\n');
+ cupsFilePrintf(fp, "%s%c", p->name, p->next ? ',' : '\n');
if (DefaultPrinter)
- fprintf(fp, "_default:use=%s\n", DefaultPrinter->name);
+ cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name);
for (p = Printers; p != NULL; p = p->next)
- fprintf(fp, "%s:\\\n"
+ cupsFilePrintf(fp, "%s:\\\n"
"\t:bsdaddr=%s,%s:\\\n"
"\t:description=%s:\n",
p->name, ServerName, p->name, p->info ? p->info : "");
* Close the file...
*/
- fclose(fp);
+ cupsFileClose(fp);
}
write_irix_config(printer_t *p) /* I - Printer to update */
{
char filename[1024]; /* Interface script filename */
- FILE *fp; /* Interface script file */
+ cups_file_t *fp; /* Interface script file */
ipp_attribute_t *attr; /* Attribute value */
if (p->type & CUPS_PRINTER_CLASS)
unlink(filename);
- else if ((fp = fopen(filename, "w")) != NULL)
+ else if ((fp = cupsFileOpen(filename, "w")) != NULL)
{
- fputs("#!/bin/sh\n", fp);
+ cupsFilePuts(fp, "#!/bin/sh\n");
if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model",
IPP_TAG_TEXT)) != NULL)
- fprintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text);
+ cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text);
else if (p->type & CUPS_PRINTER_CLASS)
- fputs("NAME=\"Printer Class\"\n", fp);
+ cupsFilePuts(fp, "NAME=\"Printer Class\"\n");
else
- fputs("NAME=\"Remote Destination\"\n", fp);
+ cupsFilePuts(fp, "NAME=\"Remote Destination\"\n");
if (p->type & CUPS_PRINTER_COLOR)
- fputs("TYPE=ColorPostScript\n", fp);
+ cupsFilePuts(fp, "TYPE=ColorPostScript\n");
else
- fputs("TYPE=MonoPostScript\n", fp);
+ cupsFilePuts(fp, "TYPE=MonoPostScript\n");
- fprintf(fp, "HOSTNAME=%s\n", ServerName);
- fprintf(fp, "HOSTPRINTER=%s\n", p->name);
+ cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName);
+ cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name);
- fclose(fp);
+ cupsFileClose(fp);
chmod(filename, 0755);
chown(filename, User, Group);
if (p->type & CUPS_PRINTER_CLASS)
unlink(filename);
- else if ((fp = fopen(filename, "w")) != NULL)
+ else if ((fp = cupsFileOpen(filename, "w")) != NULL)
{
- fputs("/dev/null\n", fp);
+ cupsFilePuts(fp, "/dev/null\n");
- fclose(fp);
+ cupsFileClose(fp);
chmod(filename, 0644);
chown(filename, User, Group);
if (p->type & CUPS_PRINTER_CLASS)
unlink(filename);
- else if ((fp = fopen(filename, "w")) != NULL)
+ else if ((fp = cupsFileOpen(filename, "w")) != NULL)
{
- fputs("#!/bin/sh\n", fp);
- fprintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);
+ cupsFilePuts(fp, "#!/bin/sh\n");
+ cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);
- fclose(fp);
+ cupsFileClose(fp);
chmod(filename, 0755);
chown(filename, User, Group);
if (p->type & CUPS_PRINTER_CLASS)
unlink(filename);
- else if ((fp = fopen(filename, "w")) != NULL)
+ else if ((fp = cupsFileOpen(filename, "w")) != NULL)
{
- fprintf(fp, "Printer Class | %s\n",
+ cupsFilePrintf(fp, "Printer Class | %s\n",
(p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript");
- fprintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : "");
- fprintf(fp, "Location Code | %s\n", p->location ? p->location : "");
- fprintf(fp, "Physical Location | %s\n", p->info ? p->info : "");
- fprintf(fp, "Port Path | %s\n", p->device_uri ? p->device_uri : "");
- fprintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name);
- fprintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
- fputs("Status Update Wait | 10 seconds\n", fp);
+ cupsFilePrintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : "");
+ cupsFilePrintf(fp, "Location Code | %s\n", p->location ? p->location : "");
+ cupsFilePrintf(fp, "Physical Location | %s\n", p->info ? p->info : "");
+ cupsFilePrintf(fp, "Port Path | %s\n", p->device_uri ? p->device_uri : "");
+ cupsFilePrintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name);
+ cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
+ cupsFilePuts(fp, "Status Update Wait | 10 seconds\n");
- fclose(fp);
+ cupsFileClose(fp);
chmod(filename, 0664);
chown(filename, User, Group);
*/
static void
-write_irix_state(printer_t *p) /* I - Printer to update */
+write_irix_state(printer_t *p) /* I - Printer to update */
{
- char filename[1024]; /* Interface script filename */
- FILE *fp; /* Interface script file */
- int tag; /* Status tag value */
+ char filename[1024]; /* Interface script filename */
+ cups_file_t *fp; /* Interface script file */
+ int tag; /* Status tag value */
if (p)
if (p->type & CUPS_PRINTER_CLASS)
unlink(filename);
- else if ((fp = fopen(filename, "w")) != NULL)
+ else if ((fp = cupsFileOpen(filename, "w")) != NULL)
{
- fprintf(fp, "Operational Status | %s\n",
+ cupsFilePrintf(fp, "Operational Status | %s\n",
(p->state == IPP_PRINTER_IDLE) ? "Idle" :
(p->state == IPP_PRINTER_PROCESSING) ? "Busy" :
"Faulted");
- fprintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION);
- fprintf(fp, "Information | 02 00 00 | Device URI: %s\n",
+ cupsFilePrintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION);
+ cupsFilePrintf(fp, "Information | 02 00 00 | Device URI: %s\n",
p->device_uri ? p->device_uri : "");
- fprintf(fp, "Information | 03 00 00 | %s jobs\n",
+ cupsFilePrintf(fp, "Information | 03 00 00 | %s jobs\n",
p->accepting ? "Accepting" : "Not accepting");
- fprintf(fp, "Information | 04 00 00 | %s\n", p->state_message);
+ cupsFilePrintf(fp, "Information | 04 00 00 | %s\n", p->state_message);
- fclose(fp);
+ cupsFileClose(fp);
chmod(filename, 0664);
chown(filename, User, Group);
if (p->type & CUPS_PRINTER_CLASS)
unlink(filename);
- else if ((fp = fopen(filename, "w")) != NULL)
+ else if ((fp = cupsFileOpen(filename, "w")) != NULL)
{
if (p->type & CUPS_PRINTER_COLOR)
tag = 66240;
else if (p->state == IPP_PRINTER_STOPPED)
tag |= 2;
- fputs("#!/bin/sh\n", fp);
- fprintf(fp, "#Tag %d\n", tag);
+ cupsFilePuts(fp, "#!/bin/sh\n");
+ cupsFilePrintf(fp, "#Tag %d\n", tag);
- fclose(fp);
+ cupsFileClose(fp);
chmod(filename, 0755);
chown(filename, User, Group);
if (DefaultPrinter != NULL)
{
- if ((fp = fopen(filename, "w")) != NULL)
+ if ((fp = cupsFileOpen(filename, "w")) != NULL)
{
- fprintf(fp, "%s\n", DefaultPrinter->name);
+ cupsFilePrintf(fp, "%s\n", DefaultPrinter->name);
- fclose(fp);
+ cupsFileClose(fp);
chmod(filename, 0644);
chown(filename, User, Group);
/*
- * End of "$Id: printers.c,v 1.145 2003/03/28 17:31:23 mike Exp $".
+ * End of "$Id: printers.c,v 1.146 2003/03/30 19:50:35 mike Exp $".
*/
/*
- * "$Id: server.c,v 1.12 2003/03/28 22:28:00 mike Exp $"
+ * "$Id: server.c,v 1.13 2003/03/30 19:50:35 mike Exp $"
*
* Server start/stop routines for the Common UNIX Printing System (CUPS).
*
if (AccessFile != NULL)
{
- fclose(AccessFile);
+ cupsFileClose(AccessFile);
AccessFile = NULL;
}
if (ErrorFile != NULL)
{
- fclose(ErrorFile);
+ cupsFileClose(ErrorFile);
ErrorFile = NULL;
}
if (PageFile != NULL)
{
- fclose(PageFile);
+ cupsFileClose(PageFile);
PageFile = NULL;
}
/*
- * End of "$Id: server.c,v 1.12 2003/03/28 22:28:00 mike Exp $".
+ * End of "$Id: server.c,v 1.13 2003/03/30 19:50:35 mike Exp $".
*/