From 4400e98de24bd267328aa20d57951fb6678297fe Mon Sep 17 00:00:00 2001 From: jlovell Date: Fri, 3 Feb 2006 00:47:45 +0000 Subject: [PATCH] Load cups into easysw/current. git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@54 a1ca3aef-8c08-0410-bb20-df032aa958be --- backend/Makefile | 7 +- cgi-bin/admin.c | 14 +- cups/file.c | 11 +- cups/file.h | 7 +- cups/globals.c | 5 +- cups/globals.h | 8 +- cups/http-private.h | 10 +- cups/ipp.c | 164 ++++++++++++-------- cups/string.c | 251 ++++++++++++++++++++++++++++-- cups/string.h | 25 ++- cups/testfile.c | 8 +- doc/Makefile | 3 +- packaging/cups.spec.in | 1 + scheduler/banners.c | 6 +- scheduler/client.c | 12 +- scheduler/cups-lpd.c | 5 +- scheduler/cupsd.h | 8 +- scheduler/dirsvc.c | 7 +- scheduler/ipp.c | 61 ++++---- scheduler/job.c | 6 +- scheduler/listen.c | 25 ++- scheduler/main.c | 60 ++++---- scheduler/mime.c | 277 ++++++++++++++++++++++------------ scheduler/mime.h | 16 +- scheduler/printers.c | 36 ++--- scheduler/process.c | 9 +- scheduler/sysman.c | 6 +- scheduler/testmime.c | 87 ++++++++++- scheduler/type.c | 241 ++++++++++++++++------------- templates/Makefile | 6 +- templates/samba-export.tmpl | 55 +++++++ templates/samba-exported.tmpl | 1 + 32 files changed, 1008 insertions(+), 430 deletions(-) create mode 100644 templates/samba-export.tmpl create mode 100644 templates/samba-exported.tmpl diff --git a/backend/Makefile b/backend/Makefile index 92a721a7e..8ec13cf7c 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile 5044 2006-02-01 21:35:30Z mike $" +# "$Id: Makefile 5047 2006-02-02 05:14:15Z mike $" # # Backend makefile for the Common UNIX Printing System (CUPS). # @@ -87,7 +87,8 @@ betest: betest.o ../cups/$(LIBCUPS) test1284: test1284.o ../cups/libcups.a echo Linking $@... - $(CC) $(LDFLAGS) -o test1284 test1284.o ../cups/libcups.a + $(CC) $(LDFLAGS) -o test1284 test1284.o ../cups/libcups.a \ + $(SSLLIBS) $(COMMONLIBS) $(LIBZ) # @@ -178,5 +179,5 @@ include Dependencies # -# End of "$Id: Makefile 5044 2006-02-01 21:35:30Z mike $". +# End of "$Id: Makefile 5047 2006-02-02 05:14:15Z mike $". # diff --git a/cgi-bin/admin.c b/cgi-bin/admin.c index 55ab8fd4d..254c32097 100644 --- a/cgi-bin/admin.c +++ b/cgi-bin/admin.c @@ -1,5 +1,5 @@ /* - * "$Id: admin.c 5023 2006-01-29 14:39:44Z mike $" + * "$Id: admin.c 5057 2006-02-02 20:38:29Z mike $" * * Administration CGI for the Common UNIX Printing System (CUPS). * @@ -2621,7 +2621,7 @@ do_export(http_t *http) /* I - HTTP connection */ } else { - cgiCopyTemplateLang("samba-exported"); + cgiCopyTemplateLang("samba-exported.tmpl"); cgiEndHTML(); return; } @@ -3088,15 +3088,15 @@ do_menu(http_t *http) /* I - HTTP connection */ * rpcclient... */ - if (cupsFileFind("smbclient", getenv("PATH"), line, sizeof(line)) && - cupsFileFind("rpcclient", getenv("PATH"), line, sizeof(line))) + if (cupsFileFind("smbclient", getenv("PATH"), 1, line, sizeof(line)) && + cupsFileFind("rpcclient", getenv("PATH"), 1, line, sizeof(line))) cgiSetVariable("HAVE_SAMBA", "Y"); else { - if (!cupsFileFind("smbclient", getenv("PATH"), line, sizeof(line))) + if (!cupsFileFind("smbclient", getenv("PATH"), 1, line, sizeof(line))) fputs("ERROR: smbclient not found!\n", stderr); - if (!cupsFileFind("rpcclient", getenv("PATH"), line, sizeof(line))) + if (!cupsFileFind("rpcclient", getenv("PATH"), 1, line, sizeof(line))) fputs("ERROR: rpcclient not found!\n", stderr); } } @@ -3590,5 +3590,5 @@ match_string(const char *a, /* I - First string */ /* - * End of "$Id: admin.c 5023 2006-01-29 14:39:44Z mike $". + * End of "$Id: admin.c 5057 2006-02-02 20:38:29Z mike $". */ diff --git a/cups/file.c b/cups/file.c index e0c135c98..afc0f08fc 100644 --- a/cups/file.c +++ b/cups/file.c @@ -1,5 +1,5 @@ /* - * "$Id: file.c 5026 2006-01-30 21:59:02Z mike $" + * "$Id: file.c 5057 2006-02-02 20:38:29Z mike $" * * File functions for the Common UNIX Printing System (CUPS). * @@ -285,7 +285,8 @@ cupsFileEOF(cups_file_t *fp) /* I - CUPS file */ const char * /* O - Full path to file or NULL */ cupsFileFind(const char *filename, /* I - File to find */ const char *path, /* I - Colon/semicolon-separated path */ - char *buffer, /* I - Filename buffer */ + int executable, /* I - 1 = executable files, 0 = any file/dir */ + char *buffer, /* I - Filename buffer */ int bufsize) /* I - Size of filename buffer */ { char *bufptr, /* Current position in buffer */ @@ -330,7 +331,11 @@ cupsFileFind(const char *filename, /* I - File to find */ strlcpy(bufptr, filename, bufend - bufptr); +#ifdef WIN32 if (!access(buffer, 0)) +#else + if (!access(buffer, executable ? X_OK : 0)) +#endif /* WIN32 */ return (buffer); bufptr = buffer; @@ -1770,5 +1775,5 @@ cups_write(cups_file_t *fp, /* I - CUPS file */ /* - * End of "$Id: file.c 5026 2006-01-30 21:59:02Z mike $". + * End of "$Id: file.c 5057 2006-02-02 20:38:29Z mike $". */ diff --git a/cups/file.h b/cups/file.h index fa9088c15..39cc07008 100644 --- a/cups/file.h +++ b/cups/file.h @@ -1,5 +1,5 @@ /* - * "$Id: file.h 4933 2006-01-16 00:26:57Z mike $" + * "$Id: file.h 5057 2006-02-02 20:38:29Z mike $" * * Public file definitions for the Common UNIX Printing System (CUPS). * @@ -75,7 +75,8 @@ extern int cupsFileClose(cups_file_t *fp); extern int cupsFileCompression(cups_file_t *fp); extern int cupsFileEOF(cups_file_t *fp); extern const char *cupsFileFind(const char *filename, const char *path, - char *buffer, int bufsize); + int executable, char *buffer, + int bufsize); extern int cupsFileFlush(cups_file_t *fp); extern int cupsFileGetChar(cups_file_t *fp); extern char *cupsFileGetConf(cups_file_t *fp, char *buf, size_t buflen, @@ -103,5 +104,5 @@ extern ssize_t cupsFileWrite(cups_file_t *fp, const char *buf, size_t bytes); #endif /* !_CUPS_FILE_H_ */ /* - * End of "$Id: file.h 4933 2006-01-16 00:26:57Z mike $". + * End of "$Id: file.h 5057 2006-02-02 20:38:29Z mike $". */ diff --git a/cups/globals.c b/cups/globals.c index 3335e5163..3cbcadd17 100644 --- a/cups/globals.c +++ b/cups/globals.c @@ -1,5 +1,5 @@ /* - * "$Id: globals.c 4967 2006-01-24 03:42:15Z mike $" + * "$Id: globals.c 5047 2006-02-02 05:14:15Z mike $" * * Global variable access routines for the Common UNIX Printing System (CUPS). * @@ -160,6 +160,7 @@ globals_destructor(void *value) /* I - Data to free */ if (cg->http) httpClose(cg->http); + _cups_sp_flush(cg); _cupsLangFlush(cg); _cupsCharmapFlush(cg); _cupsNormalizeMapsFlush(cg); @@ -210,5 +211,5 @@ _cupsGlobals(void) /* - * End of "$Id: globals.c 4967 2006-01-24 03:42:15Z mike $". + * End of "$Id: globals.c 5047 2006-02-02 05:14:15Z mike $". */ diff --git a/cups/globals.h b/cups/globals.h index e1db6dc00..81e7384e9 100644 --- a/cups/globals.h +++ b/cups/globals.h @@ -1,5 +1,5 @@ /* - * "$Id: globals.h 4967 2006-01-24 03:42:15Z mike $" + * "$Id: globals.h 5047 2006-02-02 05:14:15Z mike $" * * Global variable definitions for the Common UNIX Printing System (CUPS). * @@ -132,6 +132,9 @@ typedef struct _cups_globals_s /**** CUPS global state data ****/ /* Default printer */ char ppd_filename[HTTP_MAX_URI]; /* PPD filename */ + + /* string.c */ + cups_array_t *stringpool; /* String pool */ } _cups_globals_t; @@ -144,6 +147,7 @@ extern _cups_globals_t *_cupsGlobals(void); extern void _cupsLangFlush(_cups_globals_t *cg); extern void _cupsCharmapFlush(_cups_globals_t *cg); extern void _cupsNormalizeMapsFlush(_cups_globals_t *cg); +extern void _cups_sp_flush(_cups_globals_t *cg); /* @@ -156,5 +160,5 @@ extern void _cupsNormalizeMapsFlush(_cups_globals_t *cg); #endif /* !_CUPS_GLOBALS_H_ */ /* - * End of "$Id: globals.h 4967 2006-01-24 03:42:15Z mike $". + * End of "$Id: globals.h 5047 2006-02-02 05:14:15Z mike $". */ diff --git a/cups/http-private.h b/cups/http-private.h index dd6fb2256..0f66ed8c6 100644 --- a/cups/http-private.h +++ b/cups/http-private.h @@ -1,5 +1,5 @@ /* - * "$Id: http-private.h 4973 2006-01-25 02:36:02Z mike $" + * "$Id: http-private.h 5049 2006-02-02 14:50:57Z mike $" * * Private HTTP definitions for the Common UNIX Printing System (CUPS). * @@ -54,14 +54,14 @@ # define closesocket(f) close(f) # endif /* WIN32 */ -# ifdef __sgi +# if defined(__sgi) || (defined(__APPLE__) && !defined(_SOCKLEN_T)) /* - * IRIX does not define socklen_t, and in fact uses an int instead of + * IRIX and MacOS X 10.2.x do not define socklen_t, and in fact use an int instead of * unsigned type for length values... */ typedef int socklen_t; -# endif /* __sgi */ +# endif /* __sgi || (__APPLE__ && !_SOCKLEN_T) */ # include "http.h" # include "ipp-private.h" @@ -123,5 +123,5 @@ extern const char *hstrerror(int error); #endif /* !_CUPS_HTTP_PRIVATE_H_ */ /* - * End of "$Id: http-private.h 4973 2006-01-25 02:36:02Z mike $". + * End of "$Id: http-private.h 5049 2006-02-02 14:50:57Z mike $". */ diff --git a/cups/ipp.c b/cups/ipp.c index be6f0bbc9..e9be31fe6 100644 --- a/cups/ipp.c +++ b/cups/ipp.c @@ -1,5 +1,5 @@ /* - * "$Id: ipp.c 5023 2006-01-29 14:39:44Z mike $" + * "$Id: ipp.c 5047 2006-02-02 05:14:15Z mike $" * * Internet Printing Protocol support functions for the Common UNIX * Printing System (CUPS). @@ -114,7 +114,7 @@ ippAddBoolean(ipp_t *ipp, /* I - IPP message */ if ((attr = _ipp_add_attr(ipp, 1)) == NULL) return (NULL); - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = IPP_TAG_BOOLEAN; attr->values[0].boolean = value; @@ -148,7 +148,7 @@ ippAddBooleans(ipp_t *ipp, /* I - IPP message */ if ((attr = _ipp_add_attr(ipp, num_values)) == NULL) return (NULL); - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = IPP_TAG_BOOLEAN; @@ -186,7 +186,7 @@ ippAddCollection(ipp_t *ipp, /* I - IPP message */ if ((attr = _ipp_add_attr(ipp, 1)) == NULL) return (NULL); - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = IPP_TAG_BEGIN_COLLECTION; attr->values[0].collection = value; @@ -223,7 +223,7 @@ ippAddCollections( if ((attr = _ipp_add_attr(ipp, num_values)) == NULL) return (NULL); - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = IPP_TAG_BEGIN_COLLECTION; @@ -259,7 +259,7 @@ ippAddDate(ipp_t *ipp, /* I - IPP message */ if ((attr = _ipp_add_attr(ipp, 1)) == NULL) return (NULL); - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = IPP_TAG_DATE; memcpy(attr->values[0].date, value, 11); @@ -291,7 +291,7 @@ ippAddInteger(ipp_t *ipp, /* I - IPP message */ if ((attr = _ipp_add_attr(ipp, 1)) == NULL) return (NULL); - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = type; attr->values[0].integer = value; @@ -323,7 +323,7 @@ ippAddIntegers(ipp_t *ipp, /* I - IPP message */ if ((attr = _ipp_add_attr(ipp, num_values)) == NULL) return (NULL); - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = type; @@ -363,7 +363,7 @@ ippAddOctetString(ipp_t *ipp, /* I - IPP message */ * Initialize the attribute data... */ - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = IPP_TAG_STRING; attr->values[0].unknown.length = datalen; @@ -395,6 +395,8 @@ ippAddString(ipp_t *ipp, /* I - IPP message */ const char *value) /* I - Value */ { ipp_attribute_t *attr; /* New attribute */ + char buffer[1024], /* Language/charset value buffer */ + *bufptr; /* Pointer into buffer */ if (ipp == NULL || name == NULL) @@ -407,38 +409,37 @@ ippAddString(ipp_t *ipp, /* I - IPP message */ * Force value to be English for the POSIX locale... */ - if (type == IPP_TAG_LANGUAGE && strcasecmp(value, "C") == 0) + if (type == IPP_TAG_LANGUAGE && !strcasecmp(value, "C")) value = "en"; - /* - * Initialize the attribute data... - */ - - attr->name = strdup(name); - attr->group_tag = group; - attr->value_tag = type; - attr->values[0].string.charset = ((int)type & IPP_TAG_COPY) ? (char *)charset : - charset ? strdup(charset) : NULL; - attr->values[0].string.text = ((int)type & IPP_TAG_COPY) ? (char *)value : - value ? strdup(value) : NULL; - /* * Convert language values to lowercase and change _ to - as needed... */ - if ((type == IPP_TAG_LANGUAGE || type == IPP_TAG_CHARSET) && - attr->values[0].string.text) + if ((type == IPP_TAG_LANGUAGE || type == IPP_TAG_CHARSET) && value) { - char *p; - + strlcpy(buffer, value, sizeof(buffer)); + value = buffer; - for (p = attr->values[0].string.text; *p; p ++) - if (*p == '_') - *p = '-'; + for (bufptr = buffer; *bufptr; bufptr ++) + if (*bufptr == '_') + *bufptr = '-'; else - *p = tolower(*p & 255); + *bufptr = tolower(*bufptr & 255); } + /* + * Initialize the attribute data... + */ + + attr->name = _cups_sp_alloc(name); + attr->group_tag = group; + attr->value_tag = type; + attr->values[0].string.charset = ((int)type & IPP_TAG_COPY) ? (char *)charset : + charset ? _cups_sp_alloc(charset) : NULL; + attr->values[0].string.text = ((int)type & IPP_TAG_COPY) ? (char *)value : + value ? _cups_sp_alloc(value) : NULL; + return (attr); } @@ -472,7 +473,7 @@ ippAddStrings( * Initialize the attribute data... */ - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = type; @@ -482,7 +483,7 @@ ippAddStrings( { if (i == 0) value->string.charset = ((int)type & IPP_TAG_COPY) ? (char *)charset : - charset ? strdup(charset) : NULL; + charset ? _cups_sp_alloc(charset) : NULL; else value->string.charset = attr->values[0].string.charset; @@ -492,12 +493,12 @@ ippAddStrings( * Force language to be English for the POSIX locale... */ - if (type == IPP_TAG_LANGUAGE && strcasecmp(values[i], "C") == 0) + if (type == IPP_TAG_LANGUAGE && !strcasecmp(values[i], "C")) value->string.text = ((int)type & IPP_TAG_COPY) ? "en" : - strdup("en"); + _cups_sp_alloc("en"); else value->string.text = ((int)type & IPP_TAG_COPY) ? (char *)values[i] : - strdup(values[i]); + _cups_sp_alloc(values[i]); } } @@ -525,7 +526,7 @@ ippAddRange(ipp_t *ipp, /* I - IPP message */ if ((attr = _ipp_add_attr(ipp, 1)) == NULL) return (NULL); - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = IPP_TAG_RANGE; attr->values[0].range.lower = lower; @@ -558,7 +559,7 @@ ippAddRanges(ipp_t *ipp, /* I - IPP message */ if ((attr = _ipp_add_attr(ipp, num_values)) == NULL) return (NULL); - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = IPP_TAG_RANGE; @@ -596,7 +597,7 @@ ippAddResolution(ipp_t *ipp, /* I - IPP message */ if ((attr = _ipp_add_attr(ipp, 1)) == NULL) return (NULL); - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = IPP_TAG_RESOLUTION; attr->values[0].resolution.xres = xres; @@ -631,7 +632,7 @@ ippAddResolutions(ipp_t *ipp, /* I - IPP message */ if ((attr = _ipp_add_attr(ipp, num_values)) == NULL) return (NULL); - attr->name = strdup(name); + attr->name = _cups_sp_alloc(name); attr->group_tag = group; attr->value_tag = IPP_TAG_RESOLUTION; @@ -1011,7 +1012,7 @@ ippReadFile(int fd, /* I - HTTP data */ /* * 'ippReadIO()' - Read data for an IPP message. * - * @since CUPS 1.1.19@ + * @since CUPS 1.2@ */ ipp_state_t /* O - Current state */ @@ -1023,6 +1024,7 @@ ippReadIO(void *src, /* I - Data source */ { int n; /* Length of data */ unsigned char buffer[32768], /* Data buffer */ + string[255], /* Small string buffer */ *bufptr; /* Pointer into buffer */ ipp_attribute_t *attr; /* Current attribute */ ipp_tag_t tag; /* Current tag */ @@ -1285,7 +1287,7 @@ ippReadIO(void *src, /* I - Data source */ attr->group_tag = ipp->curtag; attr->value_tag = tag; - attr->name = strdup((char *)buffer); + attr->name = _cups_sp_alloc((char *)buffer); attr->num_values = 0; } else @@ -1338,14 +1340,14 @@ ippReadIO(void *src, /* I - Data source */ case IPP_TAG_CHARSET : case IPP_TAG_LANGUAGE : case IPP_TAG_MIMETYPE : - value->string.text = calloc(n + 1, 1); - - if ((*cb)(src, (ipp_uchar_t *)value->string.text, n) < n) + if ((*cb)(src, buffer, n) < n) { - DEBUG_puts("ippReadIO: Unable to read string value!"); + DEBUG_puts("ippReadIO: unable to read name!"); return (IPP_ERROR); } + buffer[n] = '\0'; + value->string.text = _cups_sp_alloc((char *)buffer); DEBUG_printf(("ippReadIO: value = \'%s\'\n", value->string.text)); break; @@ -1414,18 +1416,24 @@ ippReadIO(void *src, /* I - Data source */ n = (bufptr[0] << 8) | bufptr[1]; - value->string.charset = calloc(n + 1, 1); + if (n >= sizeof(string)) + { + memcpy(string, bufptr + 2, sizeof(string) - 1); + string[sizeof(string) - 1] = '\0'; + } + else + { + memcpy(string, bufptr + 2, n); + string[n] = '\0'; + } - memcpy(value->string.charset, - bufptr + 2, n); + value->string.charset = _cups_sp_alloc((char *)string); bufptr += 2 + n; n = (bufptr[0] << 8) | bufptr[1]; - value->string.text = calloc(n + 1, 1); - - memcpy(value->string.text, - bufptr + 2, n); + bufptr[2 + n] = '\0'; + value->string.text = _cups_sp_alloc((char *)bufptr + 2); break; case IPP_TAG_BEGIN_COLLECTION : @@ -1461,18 +1469,19 @@ ippReadIO(void *src, /* I - Data source */ case IPP_TAG_MEMBERNAME : /* - * The value is the name of the member in the collection, - * which we need to carry over... + * The value the name of the member in the collection, which + * we need to carry over... */ - attr->name = calloc(n + 1, 1); - - if ((*cb)(src, (ipp_uchar_t *)attr->name, n) < n) + if ((*cb)(src, buffer, n) < n) { DEBUG_puts("ippReadIO: Unable to read member name value!"); return (IPP_ERROR); } + buffer[n] = '\0'; + attr->name = _cups_sp_alloc((char *)buffer); + /* * Since collection members are encoded differently than * regular attributes, make sure we don't start with an @@ -1609,7 +1618,7 @@ ippWriteFile(int fd, /* I - HTTP data */ /* * 'ippWriteIO()' - Write data for an IPP message. * - * @since CUPS 1.1.19@ + * @since CUPS 1.2@ */ ipp_state_t /* O - Current state */ @@ -2454,7 +2463,7 @@ _ipp_free_attr(ipp_attribute_t *attr) /* I - Attribute to free */ for (i = 0, value = attr->values; i < attr->num_values; i ++, value ++) - free(value->string.text); + _cups_sp_free(value->string.text); break; case IPP_TAG_TEXTLANG : @@ -2464,17 +2473,40 @@ _ipp_free_attr(ipp_attribute_t *attr) /* I - Attribute to free */ i ++, value ++) { if (value->string.charset && i == 0) - free(value->string.charset); - free(value->string.text); + _cups_sp_free(value->string.charset); + _cups_sp_free(value->string.text); } break; + case IPP_TAG_INTEGER : + case IPP_TAG_ENUM : + case IPP_TAG_BOOLEAN : + case IPP_TAG_DATE : + case IPP_TAG_RESOLUTION : + case IPP_TAG_RANGE : + break; + + case IPP_TAG_BEGIN_COLLECTION : + for (i = 0, value = attr->values; + i < attr->num_values; + i ++, value ++) + ippDelete(value->collection); + break; + default : - break; /* anti-compiler-warning-code */ + if (!((int)attr->value_tag & IPP_TAG_COPY)) + { + for (i = 0, value = attr->values; + i < attr->num_values; + i ++, value ++) + if (value->unknown.data) + free(value->unknown.data); + } + break; } if (attr->name) - free(attr->name); + _cups_sp_free(attr->name); free(attr); } @@ -2594,14 +2626,14 @@ ipp_length(ipp_t *ipp, /* I - IPP message or collection */ for (i = 0, value = attr->values; i < attr->num_values; i ++, value ++) - bytes += ipp_length(attr->values[i].collection, 1); + bytes += ipp_length(value->collection, 1); break; default : for (i = 0, value = attr->values; i < attr->num_values; i ++, value ++) - bytes += attr->values[0].unknown.length; + bytes += value->unknown.length; break; } } @@ -2766,5 +2798,5 @@ ipp_write_file(int *fd, /* I - File descriptor */ /* - * End of "$Id: ipp.c 5023 2006-01-29 14:39:44Z mike $". + * End of "$Id: ipp.c 5047 2006-02-02 05:14:15Z mike $". */ diff --git a/cups/string.c b/cups/string.c index d071d8519..b30c77075 100644 --- a/cups/string.c +++ b/cups/string.c @@ -1,9 +1,9 @@ /* - * "$Id: string.c 4683 2005-09-21 22:17:44Z mike $" + * "$Id: string.c 5047 2006-02-02 05:14:15Z mike $" * * String functions for the Common UNIX Printing System (CUPS). * - * Copyright 1997-2005 by Easy Software Products. + * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the * property of Easy Software Products and are protected by Federal @@ -25,19 +25,240 @@ * * Contents: * - * _cups_strcpy() - Copy a string allowing for overlapping strings. - * _cups_strdup() - Duplicate a string. - * _cups_strcasecmp() - Do a case-insensitive comparison. - * _cups_strncasecmp() - Do a case-insensitive comparison on up to N chars. - * _cups_strlcat() - Safely concatenate two strings. - * _cups_strlcpy() - Safely copy two strings. + * _cups_sp_alloc() - Allocate/reference a string. + * _cups_sp_flush() - Flush the string pool... + * _cups_sp_free() - Free/dereference a string. + * _cups_sp_statistics() - Return allocation statistics for string pool. + * _cups_strcpy() - Copy a string allowing for overlapping strings. + * _cups_strdup() - Duplicate a string. + * _cups_strcasecmp() - Do a case-insensitive comparison. + * _cups_strncasecmp() - Do a case-insensitive comparison on up to N chars. + * _cups_strlcat() - Safely concatenate two strings. + * _cups_strlcpy() - Safely copy two strings. + * compare_sp_items() - Compare two string pool items... */ /* * Include necessary headers... */ +#include +#include +#include "debug.h" #include "string.h" +#include "globals.h" + + +/* + * Local functions... + */ + +static int compare_sp_items(_cups_sp_item_t *a, _cups_sp_item_t *b); + + +/* + * '_cups_sp_alloc()' - Allocate/reference a string. + */ + +char * /* O - String pointer */ +_cups_sp_alloc(const char *s) /* I - String */ +{ + _cups_globals_t *cg; /* Global data */ + _cups_sp_item_t *item, /* String pool item */ + key; /* Search key */ + + + /* + * Range check input... + */ + + if (!s) + return (NULL); + + /* + * Get the string pool... + */ + + cg = _cupsGlobals(); + + if (!cg->stringpool) + cg->stringpool = cupsArrayNew((cups_array_func_t)compare_sp_items, NULL); + + if (!cg->stringpool) + return (NULL); + + /* + * See if the string is already in the pool... + */ + + key.str = (char *)s; + + if ((item = (_cups_sp_item_t *)cupsArrayFind(cg->stringpool, &key)) != NULL) + { + /* + * Found it, return the cached string... + */ + + item->ref_count ++; + + return (item->str); + } + + /* + * Not found, so allocate a new one... + */ + + item = (_cups_sp_item_t *)calloc(1, sizeof(_cups_sp_item_t)); + if (!item) + return (NULL); + + item->ref_count = 1; + item->str = strdup(s); + + if (!item->str) + { + free(item); + return (NULL); + } + + /* + * Add the string to the pool and return it... + */ + + cupsArrayAdd(cg->stringpool, item); + + return (item->str); +} + + +/* + * '_cups_sp_flush()' - Flush the string pool... + */ + +void +_cups_sp_flush(_cups_globals_t *cg) /* I - Global data */ +{ + _cups_sp_item_t *item; /* Current item */ + + + for (item = (_cups_sp_item_t *)cupsArrayFirst(cg->stringpool); + item; + item = (_cups_sp_item_t *)cupsArrayNext(cg->stringpool)) + { + free(item->str); + free(item); + } + + cupsArrayDelete(cg->stringpool); +} + + +/* + * '_cups_sp_free()' - Free/dereference a string. + */ + +void +_cups_sp_free(const char *s) +{ + _cups_globals_t *cg; /* Global data */ + _cups_sp_item_t *item, /* String pool item */ + key; /* Search key */ + + + /* + * Range check input... + */ + + if (!s) + return; + + /* + * Get the string pool... + */ + + cg = _cupsGlobals(); + + if (!cg->stringpool) + return; + + /* + * See if the string is already in the pool... + */ + + key.str = (char *)s; + + if ((item = (_cups_sp_item_t *)cupsArrayFind(cg->stringpool, &key)) != NULL) + { + /* + * Found it, dereference... + */ + + item->ref_count --; + + if (!item->ref_count) + { + /* + * Remove and free... + */ + + cupsArrayRemove(cg->stringpool, item); + + free(item->str); + free(item); + } + } +} + + +/* + * '_cups_sp_statistics()' - Return allocation statistics for string pool. + */ + +size_t /* O - Number of strings */ +_cups_sp_statistics(size_t *alloc_bytes,/* O - Allocated bytes */ + size_t *total_bytes)/* O - Total string bytes */ +{ + size_t count, /* Number of strings */ + abytes, /* Allocated string bytes */ + tbytes, /* Total string bytes */ + len; /* Length of string */ + _cups_sp_item_t *item; /* Current item */ + _cups_globals_t *cg; /* Global data */ + + + /* + * Loop through strings in pool, counting everything up... + */ + + cg = _cupsGlobals(); + + for (count = 0, abytes = 0, tbytes = 0, + item = (_cups_sp_item_t *)cupsArrayFirst(cg->stringpool); + item; + item = (_cups_sp_item_t *)cupsArrayNext(cg->stringpool)) + { + /* + * Count allocated memory, using a 64-bit aligned buffer as a basis. + */ + + count += item->ref_count; + len = (strlen(item->str) + 8) & ~7; + abytes += sizeof(_cups_sp_item_t) + len; + tbytes += item->ref_count * len; + } + + /* + * Return values... + */ + + if (alloc_bytes) + *alloc_bytes = abytes; + + if (total_bytes) + *total_bytes = tbytes; + + return (count); +} /* @@ -222,5 +443,17 @@ _cups_strlcpy(char *dst, /* O - Destination string */ /* - * End of "$Id: string.c 4683 2005-09-21 22:17:44Z mike $". + * 'compare_sp_items()' - Compare two string pool items... + */ + +static int /* O - Result of comparison */ +compare_sp_items(_cups_sp_item_t *a, /* I - First item */ + _cups_sp_item_t *b) /* I - Second item */ +{ + return (strcmp(a->str, b->str)); +} + + +/* + * End of "$Id: string.c 5047 2006-02-02 05:14:15Z mike $". */ diff --git a/cups/string.h b/cups/string.h index 5d2e778f0..124cc7ede 100644 --- a/cups/string.h +++ b/cups/string.h @@ -1,9 +1,9 @@ /* - * "$Id: string.h 4683 2005-09-21 22:17:44Z mike $" + * "$Id: string.h 5047 2006-02-02 05:14:15Z mike $" * * String definitions for the Common UNIX Printing System (CUPS). * - * Copyright 1997-2005 by Easy Software Products. + * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the * property of Easy Software Products and are protected by Federal @@ -69,6 +69,17 @@ extern "C" { # endif /* __cplusplus */ +/* + * String pool structures... + */ + +typedef struct _cups_sp_item_s /**** String Pool Item ****/ +{ + char *str; /* String */ + unsigned int ref_count; /* Reference count */ +} _cups_sp_item_t; + + /* * Prototypes... */ @@ -114,6 +125,14 @@ extern int _cups_vsnprintf(char *, size_t, const char *, va_list); # define vsnprintf _cups_vsnprintf # endif /* !HAVE_VSNPRINTF */ +/* + * String pool functions... + */ + +extern char *_cups_sp_alloc(const char *s); +extern void _cups_sp_free(const char *s); +extern size_t _cups_sp_statistics(size_t *alloc_bytes, size_t *total_bytes); + /* * C++ magic... @@ -126,5 +145,5 @@ extern int _cups_vsnprintf(char *, size_t, const char *, va_list); #endif /* !_CUPS_STRING_H_ */ /* - * End of "$Id: string.h 4683 2005-09-21 22:17:44Z mike $". + * End of "$Id: string.h 5047 2006-02-02 05:14:15Z mike $". */ diff --git a/cups/testfile.c b/cups/testfile.c index 60822a276..aa4a6fd7a 100644 --- a/cups/testfile.c +++ b/cups/testfile.c @@ -1,5 +1,5 @@ /* - * "$Id: testfile.c 4942 2006-01-18 19:49:15Z mike $" + * "$Id: testfile.c 5057 2006-02-02 20:38:29Z mike $" * * File test program for the Common UNIX Printing System (CUPS). * @@ -84,8 +84,8 @@ main(int argc, /* I - Number of command-line arguments */ */ fputs("cupsFileFind: ", stdout); - if (cupsFileFind("cat", "/bin", filename, sizeof(filename)) && - cupsFileFind("cat", "/bin:/usr/bin", filename, sizeof(filename))) + if (cupsFileFind("cat", "/bin", 1, filename, sizeof(filename)) && + cupsFileFind("cat", "/bin:/usr/bin", 1, filename, sizeof(filename))) printf("PASS (%s)\n", filename); else { @@ -442,5 +442,5 @@ read_write_tests(int compression) /* I - Use compression? */ /* - * End of "$Id: testfile.c 4942 2006-01-18 19:49:15Z mike $". + * End of "$Id: testfile.c 5057 2006-02-02 20:38:29Z mike $". */ diff --git a/doc/Makefile b/doc/Makefile index c8f86cdba..3482b78a8 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile 5020 2006-01-28 13:36:15Z mike $" +# "$Id: Makefile 5054 2006-02-02 18:16:27Z mike $" # # Documentation makefile for the Common UNIX Printing System (CUPS). # @@ -47,6 +47,7 @@ WEBIMAGES = \ images/delete-printer.gif \ images/edit-configuration-file.gif \ images/esp-logo.gif \ + images/export-samba.gif \ images/happy.gif \ images/help.gif \ images/hold-job.gif \ diff --git a/packaging/cups.spec.in b/packaging/cups.spec.in index 4dc600984..6a881dd8e 100644 --- a/packaging/cups.spec.in +++ b/packaging/cups.spec.in @@ -176,6 +176,7 @@ rm -rf $RPM_BUILD_ROOT /usr/lib/cups/backend/parallel /usr/lib/cups/backend/scsi /usr/lib/cups/backend/serial +/usr/lib/cups/backend/socket /usr/lib/cups/backend/usb %dir /usr/lib/cups/cgi-bin /usr/lib/cups/cgi-bin/* diff --git a/scheduler/banners.c b/scheduler/banners.c index 71cb9d4f0..c95ea0d9e 100644 --- a/scheduler/banners.c +++ b/scheduler/banners.c @@ -1,5 +1,5 @@ /* - * "$Id: banners.c 4968 2006-01-24 03:56:31Z mike $" + * "$Id: banners.c 5051 2006-02-02 16:13:16Z mike $" * * Banner routines for the Common UNIX Printing System (CUPS). * @@ -61,7 +61,7 @@ cupsdAddBanner(const char *name, /* I - Name of banner */ * See what the filetype is... */ - if ((filetype = mimeFileType(MimeDatabase, filename, NULL)) == NULL) + if ((filetype = mimeFileType(MimeDatabase, filename, NULL, NULL)) == NULL) { cupsdLogMessage(CUPSD_LOG_WARN, "cupsdAddBanner: Banner \"%s\" (\"%s\") is of an unknown file type - skipping!", @@ -208,5 +208,5 @@ compare_banners( /* - * End of "$Id: banners.c 4968 2006-01-24 03:56:31Z mike $". + * End of "$Id: banners.c 5051 2006-02-02 16:13:16Z mike $". */ diff --git a/scheduler/client.c b/scheduler/client.c index 396b817d4..7cf0cea3c 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -1,5 +1,5 @@ /* - * "$Id: client.c 5046 2006-02-01 22:11:58Z mike $" + * "$Id: client.c 5051 2006-02-02 16:13:16Z mike $" * * Client routines for the Common UNIX Printing System (CUPS) scheduler. * @@ -755,7 +755,7 @@ cupsdEncryptClient(cupsd_client_t *con) /* I - Client to encrypt */ cupsdLogMessage(CUPSD_LOG_ERROR, "EncryptClient: Could not find signing key in keychain " "\"%s\"", ServerCertificate); - error = errSSLBadConfiguration; + error = errSSLBadCert; /* errSSLBadConfiguration is a better choice, but not available on 10.2.x */ } if (!error) @@ -1506,7 +1506,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ break; } - type = mimeFileType(MimeDatabase, filename, NULL); + type = mimeFileType(MimeDatabase, filename, NULL, NULL); if (cupsdIsCGI(con, filename, &filestats, type)) { @@ -1661,7 +1661,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ break; } - type = mimeFileType(MimeDatabase, filename, NULL); + type = mimeFileType(MimeDatabase, filename, NULL, NULL); if (!cupsdIsCGI(con, filename, &filestats, type)) { @@ -1837,7 +1837,7 @@ cupsdReadClient(cupsd_client_t *con) /* I - Client to read from */ * Serve a file... */ - type = mimeFileType(MimeDatabase, filename, NULL); + type = mimeFileType(MimeDatabase, filename, NULL, NULL); if (type == NULL) strcpy(line, "text/plain"); else @@ -3486,5 +3486,5 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */ /* - * End of "$Id: client.c 5046 2006-02-01 22:11:58Z mike $". + * End of "$Id: client.c 5051 2006-02-02 16:13:16Z mike $". */ diff --git a/scheduler/cups-lpd.c b/scheduler/cups-lpd.c index 1f7bdcf0b..16cf24359 100644 --- a/scheduler/cups-lpd.c +++ b/scheduler/cups-lpd.c @@ -1,5 +1,5 @@ /* - * "$Id: cups-lpd.c 5023 2006-01-29 14:39:44Z mike $" + * "$Id: cups-lpd.c 5049 2006-02-02 14:50:57Z mike $" * * Line Printer Daemon interface for the Common UNIX Printing System (CUPS). * @@ -36,6 +36,7 @@ * Include necessary headers... */ +#include #include #include #include @@ -1437,5 +1438,5 @@ smart_gets(char *s, /* I - Pointer to line buffer */ /* - * End of "$Id: cups-lpd.c 5023 2006-01-29 14:39:44Z mike $". + * End of "$Id: cups-lpd.c 5049 2006-02-02 14:50:57Z mike $". */ diff --git a/scheduler/cupsd.h b/scheduler/cupsd.h index e6f0fa0ed..e543d5f94 100644 --- a/scheduler/cupsd.h +++ b/scheduler/cupsd.h @@ -1,5 +1,5 @@ /* - * "$Id: cupsd.h 5046 2006-02-01 22:11:58Z mike $" + * "$Id: cupsd.h 5053 2006-02-02 18:14:38Z mike $" * * Main header file for the Common UNIX Printing System (CUPS) scheduler. * @@ -160,6 +160,10 @@ VAR time_t ReloadTime VALUE(0); /* Time of reload request... */ VAR int NeedReload VALUE(RELOAD_ALL); /* Need to load configuration? */ +#ifdef HAVE_LAUNCH_H +VAR int Launchd VALUE(0); + /* Running from launchd */ +#endif /* HAVE_LAUNCH_H */ /* @@ -200,5 +204,5 @@ extern int cupsdStartProcess(const char *command, char *argv[], /* - * End of "$Id: cupsd.h 5046 2006-02-01 22:11:58Z mike $". + * End of "$Id: cupsd.h 5053 2006-02-02 18:14:38Z mike $". */ diff --git a/scheduler/dirsvc.c b/scheduler/dirsvc.c index e48250d38..f2a0b0f62 100644 --- a/scheduler/dirsvc.c +++ b/scheduler/dirsvc.c @@ -1,5 +1,5 @@ /* - * "$Id: dirsvc.c 5043 2006-02-01 18:55:16Z mike $" + * "$Id: dirsvc.c 5059 2006-02-02 23:17:16Z mike $" * * Directory services routines for the Common UNIX Printing System (CUPS). * @@ -267,7 +267,10 @@ cupsdLoadRemoteCache(void) else if (!strcasecmp(line, "DeviceURI")) { if (value) + { + cupsdSetString(&p->uri, value); cupsdSetString(&p->device_uri, value); + } else { cupsdLogMessage(CUPSD_LOG_ERROR, @@ -2714,5 +2717,5 @@ slp_url_callback( /* - * End of "$Id: dirsvc.c 5043 2006-02-01 18:55:16Z mike $". + * End of "$Id: dirsvc.c 5059 2006-02-02 23:17:16Z mike $". */ diff --git a/scheduler/ipp.c b/scheduler/ipp.c index 0c96cf7b1..5c3b061af 100644 --- a/scheduler/ipp.c +++ b/scheduler/ipp.c @@ -1,5 +1,5 @@ /* - * "$Id: ipp.c 5046 2006-02-01 22:11:58Z mike $" + * "$Id: ipp.c 5051 2006-02-02 16:13:16Z mike $" * * IPP routines for the Common UNIX Printing System (CUPS) scheduler. * @@ -412,7 +412,8 @@ cupsdProcessIPPRequest( * Remote unauthenticated user masquerading as local root... */ - cupsdSetString(&(username->values[0].string.text), RemoteRoot); + _cups_sp_free(username->values[0].string.text); + username->values[0].string.text = _cups_sp_alloc(RemoteRoot); } } @@ -2784,7 +2785,7 @@ copy_attribute( else { for (i = 0; i < attr->num_values; i ++) - toattr->values[i].string.text = strdup(attr->values[i].string.text); + toattr->values[i].string.text = _cups_sp_alloc(attr->values[i].string.text); } break; @@ -2837,12 +2838,12 @@ copy_attribute( { if (!i) toattr->values[i].string.charset = - strdup(attr->values[i].string.charset); + _cups_sp_alloc(attr->values[i].string.charset); else toattr->values[i].string.charset = toattr->values[0].string.charset; - toattr->values[i].string.text = strdup(attr->values[i].string.text); + toattr->values[i].string.text = _cups_sp_alloc(attr->values[i].string.text); } } break; @@ -4148,11 +4149,11 @@ create_job(cupsd_client_t *con, /* I - Client connection */ for (i = 0; i < attr->num_values; i ++) { - free(attr->values[i].string.text); + _cups_sp_free(attr->values[i].string.text); attr->values[i].string.text = NULL; if (attr->values[i].string.charset) { - free(attr->values[i].string.charset); + _cups_sp_free(attr->values[i].string.charset); attr->values[i].string.charset = NULL; } } @@ -4167,7 +4168,7 @@ create_job(cupsd_client_t *con, /* I - Client connection */ attr->value_tag = IPP_TAG_NAME; attr->num_values = 1; - attr->values[0].string.text = strdup(con->http.hostname); + attr->values[0].string.text = _cups_sp_alloc(con->http.hostname); } attr->group_tag = IPP_TAG_JOB; @@ -4249,8 +4250,8 @@ create_job(cupsd_client_t *con, /* I - Client connection */ attr = ippAddStrings(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-sheets", 2, NULL, NULL); - attr->values[0].string.text = strdup(printer->job_sheets[0]); - attr->values[1].string.text = strdup(printer->job_sheets[1]); + attr->values[0].string.text = _cups_sp_alloc(printer->job_sheets[0]); + attr->values[1].string.text = _cups_sp_alloc(printer->job_sheets[1]); } job->job_sheets = attr; @@ -6097,17 +6098,18 @@ hold_job(cupsd_client_t *con, /* I - Client connection */ * Free the old hold value and copy the new one over... */ - free(attr->values[0].string.text); + _cups_sp_free(attr->values[0].string.text); if (newattr) { attr->value_tag = newattr->value_tag; - attr->values[0].string.text = strdup(newattr->values[0].string.text); + attr->values[0].string.text = + _cups_sp_alloc(newattr->values[0].string.text); } else { attr->value_tag = IPP_TAG_KEYWORD; - attr->values[0].string.text = strdup("indefinite"); + attr->values[0].string.text = _cups_sp_alloc("indefinite"); } /* @@ -6117,7 +6119,8 @@ hold_job(cupsd_client_t *con, /* I - Client connection */ cupsdSetJobHoldUntil(job, attr->values[0].string.text); } - cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was held by \"%s\".", jobid, username); + cupsdLogMessage(CUPSD_LOG_INFO, "Job %d was held by \"%s\".", jobid, + username); con->response->request.status.status_code = IPP_OK; } @@ -6656,7 +6659,7 @@ print_job(cupsd_client_t *con, /* I - Client connection */ cupsdLogMessage(CUPSD_LOG_DEBUG, "print_job: auto-typing file..."); - filetype = mimeFileType(MimeDatabase, con->filename, &compression); + filetype = mimeFileType(MimeDatabase, con->filename, NULL, &compression); if (filetype) { @@ -6669,8 +6672,9 @@ print_job(cupsd_client_t *con, /* I - Client connection */ if (format) { - free(format->values[0].string.text); - format->values[0].string.text = strdup(mimetype); + _cups_sp_free(format->values[0].string.text); + + format->values[0].string.text = _cups_sp_alloc(mimetype); } else ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, @@ -6887,11 +6891,11 @@ print_job(cupsd_client_t *con, /* I - Client connection */ for (i = 0; i < attr->num_values; i ++) { - free(attr->values[i].string.text); + _cups_sp_free(attr->values[i].string.text); attr->values[i].string.text = NULL; if (attr->values[i].string.charset) { - free(attr->values[i].string.charset); + _cups_sp_free(attr->values[i].string.charset); attr->values[i].string.charset = NULL; } } @@ -6906,7 +6910,7 @@ print_job(cupsd_client_t *con, /* I - Client connection */ attr->value_tag = IPP_TAG_NAME; attr->num_values = 1; - attr->values[0].string.text = strdup(con->http.hostname); + attr->values[0].string.text = _cups_sp_alloc(con->http.hostname); } attr->group_tag = IPP_TAG_JOB; @@ -6988,8 +6992,8 @@ print_job(cupsd_client_t *con, /* I - Client connection */ attr = ippAddStrings(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-sheets", 2, NULL, NULL); - attr->values[0].string.text = strdup(printer->job_sheets[0]); - attr->values[1].string.text = strdup(printer->job_sheets[1]); + attr->values[0].string.text = _cups_sp_alloc(printer->job_sheets[0]); + attr->values[1].string.text = _cups_sp_alloc(printer->job_sheets[1]); } job->job_sheets = attr; @@ -7599,9 +7603,10 @@ release_job(cupsd_client_t *con, /* I - Client connection */ if (attr) { - free(attr->values[0].string.text); + _cups_sp_free(attr->values[0].string.text); + attr->value_tag = IPP_TAG_KEYWORD; - attr->values[0].string.text = strdup("no-hold"); + attr->values[0].string.text = _cups_sp_alloc("no-hold"); } /* @@ -8037,7 +8042,7 @@ send_document(cupsd_client_t *con, /* I - Client connection */ cupsdLogMessage(CUPSD_LOG_DEBUG, "send_document: auto-typing file..."); - filetype = mimeFileType(MimeDatabase, con->filename, &compression); + filetype = mimeFileType(MimeDatabase, con->filename, NULL, &compression); if (filetype) { @@ -8050,8 +8055,8 @@ send_document(cupsd_client_t *con, /* I - Client connection */ if (format) { - free(format->values[0].string.text); - format->values[0].string.text = strdup(mimetype); + _cups_sp_free(format->values[0].string.text); + format->values[0].string.text = _cups_sp_alloc(mimetype); } else ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, @@ -9079,5 +9084,5 @@ validate_user(cupsd_job_t *job, /* I - Job */ /* - * End of "$Id: ipp.c 5046 2006-02-01 22:11:58Z mike $". + * End of "$Id: ipp.c 5051 2006-02-02 16:13:16Z mike $". */ diff --git a/scheduler/job.c b/scheduler/job.c index 3905c408b..cdeaec6d6 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -1,5 +1,5 @@ /* - * "$Id: job.c 5046 2006-02-01 22:11:58Z mike $" + * "$Id: job.c 5051 2006-02-02 16:13:16Z mike $" * * Job management routines for the Common UNIX Printing System (CUPS). * @@ -1013,7 +1013,7 @@ cupsdLoadAllJobs(void) job->num_files = fileid; } - job->filetypes[fileid - 1] = mimeFileType(MimeDatabase, filename, + job->filetypes[fileid - 1] = mimeFileType(MimeDatabase, filename, NULL, job->compressions + fileid - 1); if (job->filetypes[fileid - 1] == NULL) @@ -2741,5 +2741,5 @@ set_hold_until(cupsd_job_t *job, /* I - Job to update */ /* - * End of "$Id: job.c 5046 2006-02-01 22:11:58Z mike $". + * End of "$Id: job.c 5051 2006-02-02 16:13:16Z mike $". */ diff --git a/scheduler/listen.c b/scheduler/listen.c index d5b9ea579..42e1d3e0a 100644 --- a/scheduler/listen.c +++ b/scheduler/listen.c @@ -1,10 +1,10 @@ /* - * "$Id: listen.c 5041 2006-02-01 16:54:50Z mike $" + * "$Id: listen.c 5053 2006-02-02 18:14:38Z mike $" * * Server listening routines for the Common UNIX Printing System (CUPS) * scheduler. * - * Copyright 1997-2005 by Easy Software Products, all rights reserved. + * Copyright 1997-2006 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the * property of Easy Software Products and are protected by Federal @@ -293,10 +293,17 @@ cupsdStartListening(void) "cupsdStartListening: Listening to %s:%d on fd %d...", s, p, lis->fd); else + { cupsdLogMessage(CUPSD_LOG_INFO, "cupsdStartListening: Listening to %s on fd %d...", s, lis->fd); + if (chmod(s, 0140777)) + cupsdLogMessage(CUPSD_LOG_ERROR, + "cupsdStartListening: Unable to change permisssions on " + "domain socket \"%s\" - %s", s, strerror(errno)); + } + /* * Save the first port that is bound to the local loopback or * "any" address... @@ -372,7 +379,7 @@ cupsdStartListening(void) void cupsdStopListening(void) { - int i; /* Looping var */ + int i; /* Looping var */ cupsd_listener_t *lis; /* Current listening socket */ @@ -392,11 +399,15 @@ cupsdStopListening(void) #endif /* WIN32 */ #ifdef AF_LOCAL - /* - * Remove domain sockets... - */ + /* + * Remove domain sockets... + */ +# ifdef HAVE_LAUNCH_H + if (lis->address.addr.sa_family == AF_LOCAL && !Launchd) +# else if (lis->address.addr.sa_family == AF_LOCAL) +# endif /* HAVE_LAUNCH_H */ unlink(lis->address.un.sun_path); #endif /* AF_LOCAL */ } @@ -405,5 +416,5 @@ cupsdStopListening(void) /* - * End of "$Id: listen.c 5041 2006-02-01 16:54:50Z mike $". + * End of "$Id: listen.c 5053 2006-02-02 18:14:38Z mike $". */ diff --git a/scheduler/main.c b/scheduler/main.c index 7016fa6e8..0e9e808dc 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -1,5 +1,5 @@ /* - * "$Id: main.c 5042 2006-02-01 18:17:34Z mike $" + * "$Id: main.c 5056 2006-02-02 19:46:32Z mike $" * * Scheduler main loop for the Common UNIX Printing System (CUPS). * @@ -37,7 +37,7 @@ * launchd_reload() - Tell launchd to reload the configuration * file to pick up the new listening directives. * launchd_sync_conf() - Re-write the launchd(8) config file - * com.easysw.cupsd.plist based on cupsd.conf. + * org.cups.cupsd.plist based on cupsd.conf. * parent_handler() - Catch USR1/CHLD signals... * process_children() - Process all dead children... * sigchld_handler() - Handle 'child' signals from old processes. @@ -126,9 +126,10 @@ main(int argc, /* I - Number of command-line arguments */ browse_time, /* Next browse send time */ senddoc_time, /* Send-Document time */ expire_time; /* Subscription expire time */ -#ifdef HAVE_MALLINFO time_t mallinfo_time; /* Malloc information time */ -#endif /* HAVE_MALLINFO */ + size_t string_count, /* String count */ + alloc_bytes, /* Allocated string bytes */ + total_bytes; /* Total string bytes */ struct timeval timeout; /* select() timeout */ struct rlimit limit; /* Runtime limit */ #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) @@ -139,8 +140,7 @@ main(int argc, /* I - Number of command-line arguments */ struct stat statbuf; /* Needed for checking lpsched FIFO */ #endif /* __sgi */ #if HAVE_LAUNCHD - int launchd, /* Started with the -l option? */ - launchd_idle_exit; + int launchd_idle_exit; /* Idle exit on select timeout? */ #endif /* HAVE_LAUNCHD */ @@ -149,10 +149,7 @@ main(int argc, /* I - Number of command-line arguments */ * Check for command-line arguments... */ - fg = 0; -#if HAVE_LAUNCHD - launchd = 0; -#endif /* HAVE_LAUNCHD */ + fg = 0; for (i = 1; i < argc; i ++) if (argv[i][0] == '-') @@ -215,7 +212,7 @@ main(int argc, /* I - Number of command-line arguments */ case 'l' : /* Started by launchd... */ #ifdef HAVE_LAUNCHD - launchd = 1; + Launchd = 1; fg = 1; #else _cupsLangPuts(stderr, _("cupsd: launchd(8) support not compiled " @@ -395,7 +392,7 @@ main(int argc, /* I - Number of command-line arguments */ } #if HAVE_LAUNCHD - if (launchd) + if (Launchd) { /* * If we were started by launchd make sure the cupsd plist file contains the @@ -550,9 +547,7 @@ main(int argc, /* I - Number of command-line arguments */ * Loop forever... */ -#ifdef HAVE_MALLINFO mallinfo_time = 0; -#endif /* HAVE_MALLINFO */ browse_time = time(NULL); senddoc_time = time(NULL); expire_time = time(NULL); @@ -633,7 +628,7 @@ main(int argc, /* I - Number of command-line arguments */ } #if HAVE_LAUNCHD - if (launchd) + if (Launchd) { if (launchd_sync_conf()) { @@ -681,7 +676,7 @@ main(int argc, /* I - Number of command-line arguments */ * inactivity... */ - if (timeout.tv_sec == 86400 && launchd && LaunchdTimeout && + if (timeout.tv_sec == 86400 && Launchd && LaunchdTimeout && (!Browsing || !(BrowseLocalProtocols & BROWSE_DNSSD) || cupsArrayCount(Printers) == 0)) { @@ -977,13 +972,13 @@ main(int argc, /* I - Number of command-line arguments */ senddoc_time = current_time; } -#ifdef HAVE_MALLINFO /* * Log memory usage every minute... */ if ((current_time - mallinfo_time) >= 60 && LogLevel >= CUPSD_LOG_DEBUG) { +#ifdef HAVE_MALLINFO struct mallinfo mem; /* Malloc information */ @@ -992,9 +987,17 @@ main(int argc, /* I - Number of command-line arguments */ "mallinfo: arena = %d, used = %d, free = %d\n", mem.arena, mem.usmblks + mem.uordblks, mem.fsmblks + mem.fordblks); +#endif /* HAVE_MALLINFO */ + + string_count = _cups_sp_statistics(&alloc_bytes, &total_bytes); + cupsdLogMessage(CUPSD_LOG_DEBUG, + "stringpool: " CUPS_LLFMT " strings, " + CUPS_LLFMT " allocated, " CUPS_LLFMT " total bytes", + CUPS_LLCAST string_count, CUPS_LLCAST alloc_bytes, + CUPS_LLCAST total_bytes); + mallinfo_time = current_time; } -#endif /* HAVE_MALLINFO */ /* * Update the root certificate once every 5 minutes... @@ -1488,17 +1491,6 @@ launchd_checkin(void) portnum = ntohs(addr.ipv6.sin6_port); else # endif /* AF_INET6 */ -# ifdef AF_LOCAL - if (addr.addr.sa_family == AF_LOCAL) - { - /* - * Make sure the domain socket is accessible to all... - */ - - fchmod(lis->fd, 0140777); - } - else -# endif /* AF_LOCAL */ if (addr.addr.sa_family == AF_INET) portnum = ntohs(addr.ipv4.sin_port); @@ -1651,7 +1643,7 @@ launchd_sync_conf(void) { int i, /* Looping var */ portnum; /* Port number */ - CFMutableDictionaryRef cupsd_dict, /* com.easysw.cupsd.plist dictionary */ + CFMutableDictionaryRef cupsd_dict, /* org.cups.cupsd.plist dictionary */ sockets, /* Sockets dictionary */ listener; /* Listener dictionary */ CFDataRef resourceData; /* XML representation of the property list */ @@ -1665,7 +1657,7 @@ launchd_sync_conf(void) struct servent *service; /* Services data base entry */ char temp[1024]; /* Temporary buffer for value */ struct stat cupsd_sb, /* File info for cupsd.conf */ - launchd_sb; /* File info for com.easysw.cupsd.plist */ + launchd_sb; /* File info for org.cups.cupsd.plist */ /* @@ -1684,7 +1676,7 @@ launchd_sync_conf(void) } /* - * Time to write a new 'com.easysw.cupsd.plist' file. + * Time to write a new 'org.cups.cupsd.plist' file. * Create the new dictionary and populate it with values... */ @@ -1706,8 +1698,10 @@ launchd_sync_conf(void) CFDictionaryAddValue(cupsd_dict, CFSTR(LAUNCH_JOBKEY_RUNATLOAD), kCFBooleanFalse); +#ifdef LAUNCH_JOBKEY_SERVICEIPC CFDictionaryAddValue(cupsd_dict, CFSTR(LAUNCH_JOBKEY_SERVICEIPC), kCFBooleanTrue); +#endif /* LAUNCH_JOBKEY_SERVICEIPC */ if ((array = CFArrayCreateMutable(kCFAllocatorDefault, 2, &kCFTypeArrayCallBacks)) != NULL) @@ -2316,5 +2310,5 @@ usage(int status) /* O - Exit status */ /* - * End of "$Id: main.c 5042 2006-02-01 18:17:34Z mike $". + * End of "$Id: main.c 5056 2006-02-02 19:46:32Z mike $". */ diff --git a/scheduler/mime.c b/scheduler/mime.c index 903f66f2f..1de12fe34 100644 --- a/scheduler/mime.c +++ b/scheduler/mime.c @@ -1,5 +1,5 @@ /* - * "$Id: mime.c 4970 2006-01-24 14:05:45Z mike $" + * "$Id: mime.c 5057 2006-02-02 20:38:29Z mike $" * * MIME database file routines for the Common UNIX Printing System (CUPS). * @@ -28,7 +28,6 @@ * mimeDeleteType() - Delete a type from the MIME database. * mimeFirstFilter() - Get the first filter in the MIME database. * mimeFirstType() - Get the first type in the MIME database. - * mimeNextType() - Get the next type in the MIME database. * mimeLoad() - Create a new MIME database from disk. * mimeMerge() - Merge a MIME database from disk with the current one. * mimeNew() - Create a new, empty MIME database. @@ -36,9 +35,12 @@ * mimeNextType() - Get the next type in the MIME database. * mimeNumFilters() - Get the number of filters in a MIME database. * mimeNumTypes() - Get the number of types in a MIME database. - * load_types() - Load a xyz.types file... + * add_fcache() - Add a filter to the filter cache. + * compare_fcache() - Compare two filter cache entries. + * delete_fcache() - Free all memory used by the filter cache. * delete_rules() - Free all memory for the given rule tree. * load_convs() - Load a xyz.convs file... + * load_types() - Load a xyz.types file... */ /* @@ -54,14 +56,30 @@ #include "mime.h" +/* + * Local types... + */ + +typedef struct _mime_fcache_s /**** Filter cache structure ****/ +{ + char *name, /* Filter name */ + *path; /* Full path to filter if available */ +} _mime_fcache_t; + + /* * Local functions... */ -static void load_types(mime_t *mime, const char *filename); -static void load_convs(mime_t *mime, const char *filename, - const char *filterpath); +static const char *add_fcache(cups_array_t *filtercache, const char *name, + const char *filterpath); +static int compare_fcache(_mime_fcache_t *a, _mime_fcache_t *b); +static void delete_fcache(cups_array_t *filtercache); static void delete_rules(mime_magic_t *rules); +static void load_convs(mime_t *mime, const char *filename, + const char *filterpath, + cups_array_t *filtercache); +static void load_types(mime_t *mime, const char *filename); /* @@ -192,6 +210,7 @@ mimeMerge(mime_t *mime, /* I - MIME database to add to */ cups_dir_t *dir; /* Directory */ cups_dentry_t *dent; /* Directory entry */ char filename[1024]; /* Full filename of types/converts file */ + cups_array_t *filtercache; /* Filter cache */ /* @@ -238,6 +257,8 @@ mimeMerge(mime_t *mime, /* I - MIME database to add to */ * Read all the .convs files... */ + filtercache = cupsArrayNew((cups_array_func_t)compare_fcache, NULL); + while ((dent = cupsDirRead(dir)) != NULL) { if (strlen(dent->filename) > 6 && @@ -248,10 +269,12 @@ mimeMerge(mime_t *mime, /* I - MIME database to add to */ */ snprintf(filename, sizeof(filename), "%s/%s", pathname, dent->filename); - load_convs(mime, filename, filterpath); + load_convs(mime, filename, filterpath, filtercache); } } + delete_fcache(filtercache); + cupsDirClose(dir); return (mime); @@ -326,94 +349,99 @@ mimeNumTypes(mime_t *mime) /* I - MIME database */ /* - * 'load_types()' - Load a xyz.types file... + * 'add_fcache()' - Add a filter to the filter cache. */ -static void -load_types(mime_t *mime, /* I - MIME database */ - const char *filename) /* I - Types file to load */ +static const char * /* O - Full path to filter or NULL */ +add_fcache(cups_array_t *filtercache, /* I - Filter cache */ + const char *name, /* I - Filter name */ + const char *filterpath) /* I - Filter path */ { - cups_file_t *fp; /* Types file */ - int linelen; /* Length of line */ - char line[65536], /* Input line from file */ - *lineptr, /* Current position in line */ - super[MIME_MAX_SUPER], /* Super-type name */ - type[MIME_MAX_TYPE], /* Type name */ - *temp; /* Temporary pointer */ - mime_type_t *typeptr; /* New MIME type */ + _mime_fcache_t key, /* Search key */ + *temp; /* New filter cache */ + char path[1024]; /* Full path to filter */ - /* - * First try to open the file... - */ + key.name = (char *)name; + if ((temp = (_mime_fcache_t *)cupsArrayFind(filtercache, &key)) != NULL) + return (temp->path); - if ((fp = cupsFileOpen(filename, "r")) == NULL) - return; + if ((temp = calloc(1, sizeof(_mime_fcache_t))) == NULL) + return (NULL); - /* - * Then read each line from the file, skipping any comments in the file... - */ + temp->name = strdup(name); - while (cupsFileGets(fp, line, sizeof(line)) != NULL) - { - /* - * Skip blank lines and lines starting with a #... - */ + if (cupsFileFind(name, filterpath, 1, path, sizeof(path))) + temp->path = strdup(path); - if (!line[0] || line[0] == '#') - continue; + cupsArrayAdd(filtercache, temp); - /* - * While the last character in the line is a backslash, continue on to the - * next line (and the next, etc.) - */ + return (temp->path); +} - linelen = strlen(line); - while (line[linelen - 1] == '\\') - { - linelen --; +/* + * 'compare_fcache()' - Compare two filter cache entries. + */ - if (cupsFileGets(fp, line + linelen, sizeof(line) - linelen) == NULL) - line[linelen] = '\0'; - else - linelen += strlen(line + linelen); - } +static int /* O - Result of comparison */ +compare_fcache(_mime_fcache_t *a, /* I - First entry */ + _mime_fcache_t *b) /* I - Second entry */ +{ + return (strcmp(a->name, b->name)); +} - /* - * Extract the super-type and type names from the beginning of the line. - */ - lineptr = line; - temp = super; +/* + * 'delete_fcache()' - Free all memory used by the filter cache. + */ - while (*lineptr != '/' && *lineptr != '\n' && *lineptr != '\0' && - (temp - super + 1) < MIME_MAX_SUPER) - *temp++ = tolower(*lineptr++ & 255); +static void +delete_fcache(cups_array_t *filtercache)/* I - Filter cache */ +{ + _mime_fcache_t *current; /* Current cache entry */ - *temp = '\0'; - if (*lineptr != '/') - continue; + for (current = (_mime_fcache_t *)cupsArrayFirst(filtercache); + current; + current = (_mime_fcache_t *)cupsArrayNext(filtercache)) + { + free(current->name); - lineptr ++; - temp = type; + if (current->path) + free(current->path); - while (*lineptr != ' ' && *lineptr != '\t' && *lineptr != '\n' && - *lineptr != '\0' && (temp - type + 1) < MIME_MAX_TYPE) - *temp++ = tolower(*lineptr++ & 255); + free(current); + } - *temp = '\0'; + cupsArrayDelete(filtercache); +} - /* - * Add the type and rules to the MIME database... - */ - typeptr = mimeAddType(mime, super, type); - mimeAddTypeRule(typeptr, lineptr); - } +/* + * 'delete_rules()' - Free all memory for the given rule tree. + */ - cupsFileClose(fp); +static void +delete_rules(mime_magic_t *rules) /* I - Rules to free */ +{ + mime_magic_t *next; /* Next rule to free */ + + + /* + * Free the rules list, descending recursively to free any child rules. + */ + + while (rules != NULL) + { + next = rules->next; + + if (rules->child != NULL) + delete_rules(rules->child); + + free(rules); + rules = next; + } } @@ -422,9 +450,10 @@ load_types(mime_t *mime, /* I - MIME database */ */ static void -load_convs(mime_t *mime, /* I - MIME database */ - const char *filename, /* I - Convs file to load */ - const char *filterpath) /* I - Path for filters */ +load_convs(mime_t *mime, /* I - MIME database */ + const char *filename, /* I - Convs file to load */ + const char *filterpath, /* I - Path for filters */ + cups_array_t *filtercache) /* I - Filter program cache */ { cups_file_t *fp; /* Convs file */ char line[1024], /* Input line from file */ @@ -436,9 +465,6 @@ load_convs(mime_t *mime, /* I - MIME database */ mime_type_t *temptype, /* MIME type looping var */ *dsttype; /* Destination MIME type */ int cost; /* Cost of filter */ -#ifndef WIN32 - char filterprog[1024]; /* Full path of filter... */ -#endif /* !WIN32 */ /* @@ -530,23 +556,15 @@ load_convs(mime_t *mime, /* I - MIME database */ filter = lineptr; -#ifndef WIN32 if (strcmp(filter, "-")) { /* * Verify that the filter exists and is executable... */ - if (filter[0] == '/') - strlcpy(filterprog, filter, sizeof(filterprog)); - else if (!cupsFileFind(filter, filterpath, filterprog, - sizeof(filterprog))) + if (!add_fcache(filtercache, filter, filterpath)) continue; - - if (access(filterprog, X_OK)) - continue; } -#endif /* !WIN32 */ /* * Finally, get the source super-type and type names from the beginning of @@ -601,32 +619,97 @@ load_convs(mime_t *mime, /* I - MIME database */ /* - * 'delete_rules()' - Free all memory for the given rule tree. + * 'load_types()' - Load a xyz.types file... */ static void -delete_rules(mime_magic_t *rules) /* I - Rules to free */ +load_types(mime_t *mime, /* I - MIME database */ + const char *filename) /* I - Types file to load */ { - mime_magic_t *next; /* Next rule to free */ + cups_file_t *fp; /* Types file */ + int linelen; /* Length of line */ + char line[65536], /* Input line from file */ + *lineptr, /* Current position in line */ + super[MIME_MAX_SUPER], /* Super-type name */ + type[MIME_MAX_TYPE], /* Type name */ + *temp; /* Temporary pointer */ + mime_type_t *typeptr; /* New MIME type */ /* - * Free the rules list, descending recursively to free any child rules. + * First try to open the file... */ - while (rules != NULL) + if ((fp = cupsFileOpen(filename, "r")) == NULL) + return; + + /* + * Then read each line from the file, skipping any comments in the file... + */ + + while (cupsFileGets(fp, line, sizeof(line)) != NULL) { - next = rules->next; + /* + * Skip blank lines and lines starting with a #... + */ - if (rules->child != NULL) - delete_rules(rules->child); + if (!line[0] || line[0] == '#') + continue; - free(rules); - rules = next; + /* + * While the last character in the line is a backslash, continue on to the + * next line (and the next, etc.) + */ + + linelen = strlen(line); + + while (line[linelen - 1] == '\\') + { + linelen --; + + if (cupsFileGets(fp, line + linelen, sizeof(line) - linelen) == NULL) + line[linelen] = '\0'; + else + linelen += strlen(line + linelen); + } + + /* + * Extract the super-type and type names from the beginning of the line. + */ + + lineptr = line; + temp = super; + + while (*lineptr != '/' && *lineptr != '\n' && *lineptr != '\0' && + (temp - super + 1) < MIME_MAX_SUPER) + *temp++ = tolower(*lineptr++ & 255); + + *temp = '\0'; + + if (*lineptr != '/') + continue; + + lineptr ++; + temp = type; + + while (*lineptr != ' ' && *lineptr != '\t' && *lineptr != '\n' && + *lineptr != '\0' && (temp - type + 1) < MIME_MAX_TYPE) + *temp++ = tolower(*lineptr++ & 255); + + *temp = '\0'; + + /* + * Add the type and rules to the MIME database... + */ + + typeptr = mimeAddType(mime, super, type); + mimeAddTypeRule(typeptr, lineptr); } + + cupsFileClose(fp); } /* - * End of "$Id: mime.c 4970 2006-01-24 14:05:45Z mike $". + * End of "$Id: mime.c 5057 2006-02-02 20:38:29Z mike $". */ diff --git a/scheduler/mime.h b/scheduler/mime.h index cd023fa8a..76883d761 100644 --- a/scheduler/mime.h +++ b/scheduler/mime.h @@ -1,5 +1,5 @@ /* - * "$Id: mime.h 4970 2006-01-24 14:05:45Z mike $" + * "$Id: mime.h 5058 2006-02-02 21:58:45Z mike $" * * MIME type/conversion database definitions for the Common UNIX Printing System (CUPS). * @@ -46,7 +46,7 @@ extern "C" { # define MIME_MAX_SUPER 16 /* Maximum size of supertype name */ # define MIME_MAX_TYPE IPP_MAX_NAME /* Maximum size of type name */ # define MIME_MAX_FILTER 256 /* Maximum size of filter pathname */ -# define MIME_MAX_BUFFER 8192 /* Maximum size of file buffer */ +# define MIME_MAX_BUFFER 4096 /* Maximum size of file buffer */ /* @@ -70,7 +70,7 @@ typedef enum MIME_MAGIC_ISTRING /* Case-insensitive string matches */ } mime_op_t; -typedef struct mime_magic_str /**** MIME Magic Data ****/ +typedef struct _mime_magic_s /**** MIME Magic Data ****/ { struct mime_magic_str *prev, /* Previous rule */ *next, /* Next rule */ @@ -92,14 +92,14 @@ typedef struct mime_magic_str /**** MIME Magic Data ****/ } value; } mime_magic_t; -typedef struct /**** MIME Type Data ****/ +typedef struct _mime_type_s /**** MIME Type Data ****/ { mime_magic_t *rules; /* Rules used to detect this type */ char super[MIME_MAX_SUPER], /* Super-type name ("image", "application", etc.) */ type[MIME_MAX_TYPE]; /* Type name ("png", "postscript", etc.) */ } mime_type_t; -typedef struct /**** MIME Conversion Filter Data ****/ +typedef struct _mime_filter_s /**** MIME Conversion Filter Data ****/ { mime_type_t *src, /* Source type */ *dst; /* Destination type */ @@ -107,7 +107,7 @@ typedef struct /**** MIME Conversion Filter Data ****/ char filter[MIME_MAX_FILTER];/* Filter program to use */ } mime_filter_t; -typedef struct /**** MIME Database ****/ +typedef struct _mime_s /**** MIME Database ****/ { cups_array_t *types; /* File types */ cups_array_t *filters; /* Type conversion filters */ @@ -129,7 +129,7 @@ extern mime_type_t *mimeAddType(mime_t *mime, const char *super, extern int mimeAddTypeRule(mime_type_t *mt, const char *rule); extern void mimeDeleteType(mime_t *mime, mime_type_t *mt); extern mime_type_t *mimeFileType(mime_t *mime, const char *pathname, - int *compression); + const char *filename, int *compression); extern mime_type_t *mimeFirstType(mime_t *mime); extern mime_type_t *mimeNextType(mime_t *mime); extern int mimeNumTypes(mime_t *mime); @@ -152,5 +152,5 @@ extern int mimeNumFilters(mime_t *mime); #endif /* !_CUPS_MIME_H_ */ /* - * End of "$Id: mime.h 4970 2006-01-24 14:05:45Z mike $". + * End of "$Id: mime.h 5058 2006-02-02 21:58:45Z mike $". */ diff --git a/scheduler/printers.c b/scheduler/printers.c index 801606b4d..f8ea136a4 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -1,5 +1,5 @@ /* - * "$Id: printers.c 5039 2006-02-01 16:29:57Z mike $" + * "$Id: printers.c 5047 2006-02-02 05:14:15Z mike $" * * Printer routines for the Common UNIX Printing System (CUPS). * @@ -521,12 +521,12 @@ cupsdCreateCommonData(void) cupsd_banner_t *banner; /* Current banner */ - attr->values[0].string.text = strdup("none"); + attr->values[0].string.text = _cups_sp_alloc("none"); for (i = 1, banner = (cupsd_banner_t *)cupsArrayFirst(Banners); banner; i ++, banner = (cupsd_banner_t *)cupsArrayNext(Banners)) - attr->values[i].string.text = strdup(banner->name); + attr->values[i].string.text = _cups_sp_alloc(banner->name); } } else @@ -630,7 +630,7 @@ cupsdCreateCommonData(void) attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-op-policy-supported", NumPolicies, NULL, NULL); for (i = 0; i < NumPolicies; i ++) - attr->values[i].string.text = strdup(Policies[i]->name); + attr->values[i].string.text = _cups_sp_alloc(Policies[i]->name); } @@ -1570,9 +1570,9 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */ if (attr != NULL) { - attr->values[0].string.text = strdup(Classification ? + attr->values[0].string.text = _cups_sp_alloc(Classification ? Classification : p->job_sheets[0]); - attr->values[1].string.text = strdup(Classification ? + attr->values[1].string.text = _cups_sp_alloc(Classification ? Classification : p->job_sheets[1]); } } @@ -1640,7 +1640,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */ for (i = 0; i < p->num_printers; i ++) { if (attr != NULL) - attr->values[i].string.text = strdup(p->printers[i]->uri); + attr->values[i].string.text = _cups_sp_alloc(p->printers[i]->uri); p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type; } @@ -1651,7 +1651,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */ if (attr != NULL) { for (i = 0; i < p->num_printers; i ++) - attr->values[i].string.text = strdup(p->printers[i]->name); + attr->values[i].string.text = _cups_sp_alloc(p->printers[i]->name); } } } @@ -1762,20 +1762,20 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */ if (input_slot != NULL) for (i = 0; i < input_slot->num_choices; i ++, val ++) - val->string.text = strdup(input_slot->choices[i].choice); + val->string.text = _cups_sp_alloc(input_slot->choices[i].choice); if (media_type != NULL) for (i = 0; i < media_type->num_choices; i ++, val ++) - val->string.text = strdup(media_type->choices[i].choice); + val->string.text = _cups_sp_alloc(media_type->choices[i].choice); if (media_quality != NULL) for (i = 0; i < media_quality->num_choices; i ++, val ++) - val->string.text = strdup(media_quality->choices[i].choice); + val->string.text = _cups_sp_alloc(media_quality->choices[i].choice); if (page_size != NULL) { for (i = 0; i < page_size->num_choices; i ++, val ++) - val->string.text = strdup(page_size->choices[i].choice); + val->string.text = _cups_sp_alloc(page_size->choices[i].choice); ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default", NULL, page_size->defchoice); @@ -1810,7 +1810,7 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */ for (i = 0, val = attr->values; i < output_bin->num_choices; i ++, val ++) - val->string.text = strdup(output_bin->choices[i].choice); + val->string.text = _cups_sp_alloc(output_bin->choices[i].choice); } } @@ -1901,19 +1901,19 @@ cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */ attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "port-monitor-supported", i, NULL, NULL); - attr->values[0].string.text = strdup("none"); + attr->values[0].string.text = _cups_sp_alloc("none"); for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL); ppdattr; i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL)) - attr->values[i].string.text = strdup(ppdattr->value); + attr->values[i].string.text = _cups_sp_alloc(ppdattr->value); if (ppd->protocols) { if (strstr(ppd->protocols, "TBCP")) - attr->values[i].string.text = strdup("tbcp"); + attr->values[i].string.text = _cups_sp_alloc("tbcp"); else if (strstr(ppd->protocols, "BCP")) - attr->values[i].string.text = strdup("bcp"); + attr->values[i].string.text = _cups_sp_alloc("bcp"); } /* @@ -2898,5 +2898,5 @@ write_irix_state(cupsd_printer_t *p) /* I - Printer to update */ /* - * End of "$Id: printers.c 5039 2006-02-01 16:29:57Z mike $". + * End of "$Id: printers.c 5047 2006-02-02 05:14:15Z mike $". */ diff --git a/scheduler/process.c b/scheduler/process.c index 614ee7ad2..0938f7394 100644 --- a/scheduler/process.c +++ b/scheduler/process.c @@ -1,5 +1,5 @@ /* - * "$Id: process.c 5046 2006-02-01 22:11:58Z mike $" + * "$Id: process.c 5049 2006-02-02 14:50:57Z mike $" * * Process management routines for the Common UNIX Printing System (CUPS). * @@ -35,6 +35,9 @@ #include "cupsd.h" #include +#if defined(__APPLE__) && __GNUC__ < 4 +# include +#endif /* __APPLE__ && __GNUC__ < 4 */ /* @@ -152,7 +155,7 @@ cupsdStartProcess( * We have room, try to read the symlink path for this command... */ - if ((linkbytes = readlink(linkpath, sizeof(linkpath) - 1)) > 0) + if ((linkbytes = readlink(command, linkpath, sizeof(linkpath) - 1)) > 0) { /* * Yes, this is a symlink to the actual program, nul-terminate and @@ -350,5 +353,5 @@ compare_procs(cupsd_proc_t *a, /* I - First process */ /* - * End of "$Id: process.c 5046 2006-02-01 22:11:58Z mike $". + * End of "$Id: process.c 5049 2006-02-02 14:50:57Z mike $". */ diff --git a/scheduler/sysman.c b/scheduler/sysman.c index de312d313..dc6643b7e 100644 --- a/scheduler/sysman.c +++ b/scheduler/sysman.c @@ -1,5 +1,5 @@ /* - * "$Id: sysman.c 5018 2006-01-28 06:06:55Z mike $" + * "$Id: sysman.c 5049 2006-02-02 14:50:57Z mike $" * * System management definitions for the Common UNIX Printing System (CUPS). * @@ -640,7 +640,9 @@ sysEventPowerNotifier( case kIOMessageSystemWillNotPowerOff: case kIOMessageSystemWillNotSleep: +#ifdef kIOMessageSystemWillPowerOn case kIOMessageSystemWillPowerOn: +#endif /* kIOMessageSystemWillPowerOn */ default: sendit = 0; break; @@ -744,5 +746,5 @@ sysEventTimerNotifier( /* - * End of "$Id: sysman.c 5018 2006-01-28 06:06:55Z mike $". + * End of "$Id: sysman.c 5049 2006-02-02 14:50:57Z mike $". */ diff --git a/scheduler/testmime.c b/scheduler/testmime.c index 624be9a8b..bd65fc770 100644 --- a/scheduler/testmime.c +++ b/scheduler/testmime.c @@ -1,5 +1,5 @@ /* - * "$Id: testmime.c 4970 2006-01-24 14:05:45Z mike $" + * "$Id: testmime.c 5051 2006-02-02 16:13:16Z mike $" * * MIME test program for the Common UNIX Printing System (CUPS). * @@ -23,7 +23,9 @@ * * Contents: * - * main() - Main entry for the test program. + * main() - Main entry for the test program. + * print_rules() - Print the rules for a file type... + * type_dir() - Show the MIME types for a given directory. */ /* @@ -34,13 +36,15 @@ #include #include #include "mime.h" +#include /* * Local functions... */ -static void print_rules(mime_magic_t *rules); +static void print_rules(mime_magic_t *rules); +static void type_dir(mime_t *mime, const char *dirname); /* @@ -89,7 +93,7 @@ main(int argc, /* I - Number of command-line args */ if (!mime) mime = mimeLoad("../conf", filter_path); - src = mimeFileType(mime, argv[i], &compression); + src = mimeFileType(mime, argv[i], NULL, &compression); if (src) printf("%s: %s/%s%s\n", argv[i], src->super, src->type, @@ -153,6 +157,8 @@ main(int argc, /* I - Number of command-line args */ filter->src->super, filter->src->type, filter->dst->super, filter->dst->type, filter->filter, filter->cost); + + type_dir(mime, ".."); } return (0); @@ -248,5 +254,76 @@ print_rules(mime_magic_t *rules) /* I - Rules to print */ /* - * End of "$Id: testmime.c 4970 2006-01-24 14:05:45Z mike $". + * 'type_dir()' - Show the MIME types for a given directory. + */ + +static void +type_dir(mime_t *mime, /* I - MIME database */ + const char *dirname) /* I - Directory */ +{ + cups_dir_t *dir; /* Directory */ + cups_dentry_t *dent; /* Directory entry */ + char filename[1024]; /* File to type */ + mime_type_t *filetype; /* File type */ + int compression; /* Compressed file? */ + mime_type_t *pstype; /* application/vnd.cups-postscript */ + cups_array_t *filters; /* Filters to pstype */ + mime_filter_t *filter; /* Current filter */ + int cost; /* Filter cost */ + + + dir = cupsDirOpen(dirname); + if (!dir) + return; + + pstype = mimeType(mime, "application", "vnd.cups-postscript"); + + while ((dent = cupsDirRead(dir)) != NULL) + { + snprintf(filename, sizeof(filename), "%s/%s", dirname, dent->filename); + + if (S_ISDIR(dent->fileinfo.st_mode)) + type_dir(mime, filename); + + if (!S_ISREG(dent->fileinfo.st_mode)) + continue; + + filetype = mimeFileType(mime, filename, NULL, &compression); + + if (filetype) + { + printf("%s: %s/%s%s\n", filename, filetype->super, filetype->type, + compression ? " (compressed)" : ""); + + filters = mimeFilter(mime, filetype, pstype, &cost, 10); + + if (!filters) + puts(" No filters to convert application/vnd.cups-postscript."); + else + { + printf(" Filter cost = %d\n", cost); + + filter = (mime_filter_t *)cupsArrayFirst(filters); + printf(" %s", filter->filter); + + for (filter = (mime_filter_t *)cupsArrayNext(filters); + filter; + filter = (mime_filter_t *)cupsArrayNext(filters)) + printf(" | %s", filter->filter); + + putchar('\n'); + + cupsArrayDelete(filters); + } + } + else + printf("%s: unknown%s\n", filename, compression ? " (compressed)" : ""); + } + + cupsDirClose(dir); +} + + +/* + * End of "$Id: testmime.c 5051 2006-02-02 16:13:16Z mike $". */ diff --git a/scheduler/type.c b/scheduler/type.c index 9aaa10ccd..50d49d26a 100644 --- a/scheduler/type.c +++ b/scheduler/type.c @@ -1,5 +1,5 @@ /* - * "$Id: type.c 4970 2006-01-24 14:05:45Z mike $" + * "$Id: type.c 5052 2006-02-02 16:21:13Z mike $" * * MIME typing routines for the Common UNIX Printing System (CUPS). * @@ -46,13 +46,27 @@ #include +/* + * Local types... + */ + +typedef struct _mime_filebuf_s /**** File buffer for MIME typing ****/ +{ + cups_file_t *fp; /* File pointer */ + int offset, /* Offset in file */ + length; /* Length of buffered data */ + unsigned char buffer[MIME_MAX_BUFFER];/* Buffered data */ +} _mime_filebuf_t; + + /* * Local functions... */ static int compare_types(mime_type_t *t0, mime_type_t *t1); -static int checkrules(const char *, cups_file_t *, mime_magic_t *); -static int patmatch(const char *, const char *); +static int checkrules(const char *filename, _mime_filebuf_t *fb, + mime_magic_t *rules); +static int patmatch(const char *s, const char *pat); /* @@ -182,7 +196,8 @@ mimeAddTypeRule(mime_type_t *mt, /* I - Type to add to */ else if (*rule == '+' && current != NULL) { if (logic != MIME_MAGIC_AND && - current != NULL && current->prev != NULL && current->prev->prev != NULL) + current != NULL && current->prev != NULL && + current->prev->prev != NULL) { /* * OK, we have more than 1 rule in the current tree level... Make a @@ -271,7 +286,8 @@ mimeAddTypeRule(mime_type_t *mt, /* I - Type to add to */ * Read an extension name or a function... */ - for (ptr = name; isalnum(*rule & 255) && (ptr - name) < (sizeof(name) - 1);) + ptr = name; + while (isalnum(*rule & 255) && (ptr - name) < (sizeof(name) - 1)) *ptr++ = *rule++; *ptr = '\0'; @@ -519,16 +535,20 @@ mimeAddTypeRule(mime_type_t *mt, /* I - Type to add to */ mime_type_t * /* O - Type of file */ mimeFileType(mime_t *mime, /* I - MIME database */ - const char *pathname, /* I - Name of file to check */ + const char *pathname, /* I - Name of file to check on disk */ + const char *filename, /* I - Original filename or NULL */ int *compression) /* O - Is the file compressed? */ { - cups_file_t *fp; /* File pointer */ - mime_type_t *type; /* File type */ - const char *filename; /* Base filename of file */ + _mime_filebuf_t fb; /* File buffer */ + const char *base; /* Base filename of file */ + mime_type_t *type; /* File type */ - DEBUG_printf(("mimeFileType(mime=%p, pathname=\"%s\", compression=%p)\n", - mime, pathname ? pathname : "(nil)", compression)); + DEBUG_printf(("mimeFileType(mime=%p, pathname=\"%s\", basename=\"%s\", " + "compression=%p)\n", + mime, pathname ? pathname : "(nil)", + filename ? filename : "(nil)", + basenamecompression)); /* * Range check input parameters... @@ -541,15 +561,25 @@ mimeFileType(mime_t *mime, /* I - MIME database */ * Try to open the file... */ - if ((fp = cupsFileOpen(pathname, "r")) == NULL) + if ((fb.fp = cupsFileOpen(pathname, "r")) == NULL) return (NULL); + fb.offset = -1; + fb.length = 0; + /* - * Figure out the filename (without directory portion)... + * Figure out the base filename (without directory portion)... */ - if ((filename = strrchr(pathname, '/')) != NULL) - filename ++; + if (filename) + { + if ((base = strrchr(filename, '/')) != NULL) + base ++; + else + filename = filename; + } + else if ((base = strrchr(pathname, '/')) != NULL) + base ++; else filename = pathname; @@ -560,7 +590,7 @@ mimeFileType(mime_t *mime, /* I - MIME database */ for (type = (mime_type_t *)cupsArrayFirst(mime->types); type; type = (mime_type_t *)cupsArrayNext(mime->types)) - if (checkrules(filename, fp, type->rules)) + if (checkrules(base, &fb, type->rules)) break; /* @@ -568,9 +598,9 @@ mimeFileType(mime_t *mime, /* I - MIME database */ */ if (compression) - *compression = cupsFileCompression(fp); + *compression = cupsFileCompression(fb.fp); - cupsFileClose(fp); + cupsFileClose(fb.fp); return (type); } @@ -629,9 +659,9 @@ compare_types(mime_type_t *t0, /* I - First type */ */ static int /* O - 1 if match, 0 if no match */ -checkrules(const char *filename, /* I - Filename */ - cups_file_t *fp, /* I - File to check */ - mime_magic_t *rules) /* I - Rules to check */ +checkrules(const char *filename, /* I - Filename */ + _mime_filebuf_t *fb, /* I - File to check */ + mime_magic_t *rules) /* I - Rules to check */ { int n; /* Looping var */ int region; /* Region to look at */ @@ -639,10 +669,7 @@ checkrules(const char *filename, /* I - Filename */ result, /* Result of test */ intv; /* Integer value */ short shortv; /* Short value */ - unsigned char buffer[MIME_MAX_BUFFER],/* Input buffer */ - *bufptr; /* Current buffer position */ - int bufoffset, /* Offset in file for buffer */ - buflength; /* Length of data in buffer */ + unsigned char *bufptr; /* Pointer into buffer */ #ifdef DEBUG const char * const debug_tests[] = /* Test names... */ { @@ -651,7 +678,7 @@ checkrules(const char *filename, /* I - Filename */ "OR", /* Logical OR of all children */ "MATCH", /* Filename match */ "ASCII", /* ASCII characters in range */ - "PRINTABLE", /* Printable characters (32-255) in range */ + "PRINTABLE", /* Printable characters (32-255) */ "STRING", /* String matches */ "CHAR", /* Character/byte matches */ "SHORT", /* Short/16-bit word matches */ @@ -674,9 +701,7 @@ checkrules(const char *filename, /* I - Filename */ else logic = rules->parent->op; - bufoffset = -1; - buflength = 0; - result = 0; + result = 0; while (rules != NULL) { @@ -695,28 +720,29 @@ checkrules(const char *filename, /* I - Filename */ * Load the buffer if necessary... */ - if (bufoffset < 0 || rules->offset < bufoffset || - (rules->offset + rules->length) > (bufoffset + buflength)) + if (fb->offset < 0 || rules->offset < fb->offset || + (rules->offset + rules->length) > (fb->offset + fb->length)) { /* * Reload file buffer... */ - cupsFileSeek(fp, rules->offset); - buflength = cupsFileRead(fp, (char *)buffer, sizeof(buffer)); - bufoffset = rules->offset; + cupsFileSeek(fb->fp, rules->offset); + fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, + sizeof(fb->buffer)); + fb->offset = rules->offset; } /* * Test for ASCII printable characters plus standard control chars. */ - if ((rules->offset + rules->length) > (bufoffset + buflength)) - n = bufoffset + buflength - rules->offset; + if ((rules->offset + rules->length) > (fb->offset + fb->length)) + n = fb->offset + fb->length - rules->offset; else n = rules->length; - bufptr = buffer + rules->offset - bufoffset; + bufptr = fb->buffer + rules->offset - fb->offset; while (n > 0) if ((*bufptr >= 32 && *bufptr <= 126) || (*bufptr >= 8 && *bufptr <= 13) || @@ -736,28 +762,29 @@ checkrules(const char *filename, /* I - Filename */ * Load the buffer if necessary... */ - if (bufoffset < 0 || rules->offset < bufoffset || - (rules->offset + rules->length) > (bufoffset + buflength)) + if (fb->offset < 0 || rules->offset < fb->offset || + (rules->offset + rules->length) > (fb->offset + fb->length)) { /* * Reload file buffer... */ - cupsFileSeek(fp, rules->offset); - buflength = cupsFileRead(fp, (char *)buffer, sizeof(buffer)); - bufoffset = rules->offset; + cupsFileSeek(fb->fp, rules->offset); + fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, + sizeof(fb->buffer)); + fb->offset = rules->offset; } /* * Test for 8-bit printable characters plus standard control chars. */ - if ((rules->offset + rules->length) > (bufoffset + buflength)) - n = bufoffset + buflength - rules->offset; + if ((rules->offset + rules->length) > (fb->offset + fb->length)) + n = fb->offset + fb->length - rules->offset; else n = rules->length; - bufptr = buffer + rules->offset - bufoffset; + bufptr = fb->buffer + rules->offset - fb->offset; while (n > 0) if (*bufptr >= 128 || @@ -782,20 +809,22 @@ checkrules(const char *filename, /* I - Filename */ * Load the buffer if necessary... */ - if (bufoffset < 0 || rules->offset < bufoffset || - (rules->offset + rules->length) > (bufoffset + buflength)) + if (fb->offset < 0 || rules->offset < fb->offset || + (rules->offset + rules->length) > (fb->offset + fb->length)) { /* * Reload file buffer... */ - cupsFileSeek(fp, rules->offset); - buflength = cupsFileRead(fp, (char *)buffer, sizeof(buffer)); - bufoffset = rules->offset; + cupsFileSeek(fb->fp, rules->offset); + fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, + sizeof(fb->buffer)); + fb->offset = rules->offset; - DEBUG_printf((" loaded %d byte buffer at %d, starts with \"%c%c%c%c\"...\n", - buflength, bufoffset, buffer[0], buffer[1], - buffer[2], buffer[3])); + DEBUG_printf((" loaded %d byte fb->buffer at %d, starts " + "with \"%c%c%c%c\"...\n", + fb->length, fb->offset, fb->buffer[0], fb->buffer[1], + fb->buffer[2], fb->buffer[3])); } /* @@ -803,10 +832,10 @@ checkrules(const char *filename, /* I - Filename */ * short then don't compare - it can't match... */ - if ((rules->offset + rules->length) > (bufoffset + buflength)) + if ((rules->offset + rules->length) > (fb->offset + fb->length)) result = 0; else - result = (memcmp(buffer + rules->offset - bufoffset, + result = (memcmp(fb->buffer + rules->offset - fb->offset, rules->value.stringv, rules->length) == 0); DEBUG_printf((" result=%d\n", result)); break; @@ -816,16 +845,17 @@ checkrules(const char *filename, /* I - Filename */ * Load the buffer if necessary... */ - if (bufoffset < 0 || rules->offset < bufoffset || - (rules->offset + rules->length) > (bufoffset + buflength)) + if (fb->offset < 0 || rules->offset < fb->offset || + (rules->offset + rules->length) > (fb->offset + fb->length)) { /* * Reload file buffer... */ - cupsFileSeek(fp, rules->offset); - buflength = cupsFileRead(fp, (char *)buffer, sizeof(buffer)); - bufoffset = rules->offset; + cupsFileSeek(fb->fp, rules->offset); + fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, + sizeof(fb->buffer)); + fb->offset = rules->offset; } /* @@ -833,10 +863,11 @@ checkrules(const char *filename, /* I - Filename */ * short then don't compare - it can't match... */ - if ((rules->offset + rules->length) > (bufoffset + buflength)) + if ((rules->offset + rules->length) > (fb->offset + fb->length)) result = 0; else - result = (strncasecmp((char *)buffer + rules->offset - bufoffset, + result = (strncasecmp((char *)fb->buffer + rules->offset - + fb->offset, rules->value.stringv, rules->length) == 0); break; @@ -845,15 +876,16 @@ checkrules(const char *filename, /* I - Filename */ * Load the buffer if necessary... */ - if (bufoffset < 0 || rules->offset < bufoffset) + if (fb->offset < 0 || rules->offset < fb->offset) { /* * Reload file buffer... */ - cupsFileSeek(fp, rules->offset); - buflength = cupsFileRead(fp, (char *)buffer, sizeof(buffer)); - bufoffset = rules->offset; + cupsFileSeek(fb->fp, rules->offset); + fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, + sizeof(fb->buffer)); + fb->offset = rules->offset; } /* @@ -861,10 +893,11 @@ checkrules(const char *filename, /* I - Filename */ * can't match... */ - if (buflength < 1) + if (fb->length < 1) result = 0; else - result = (buffer[rules->offset - bufoffset] == rules->value.charv); + result = (fb->buffer[rules->offset - fb->offset] == + rules->value.charv); break; case MIME_MAGIC_SHORT : @@ -872,16 +905,17 @@ checkrules(const char *filename, /* I - Filename */ * Load the buffer if necessary... */ - if (bufoffset < 0 || rules->offset < bufoffset || - (rules->offset + 2) > (bufoffset + buflength)) + if (fb->offset < 0 || rules->offset < fb->offset || + (rules->offset + 2) > (fb->offset + fb->length)) { /* * Reload file buffer... */ - cupsFileSeek(fp, rules->offset); - buflength = cupsFileRead(fp, (char *)buffer, sizeof(buffer)); - bufoffset = rules->offset; + cupsFileSeek(fb->fp, rules->offset); + fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, + sizeof(fb->buffer)); + fb->offset = rules->offset; } /* @@ -889,11 +923,11 @@ checkrules(const char *filename, /* I - Filename */ * can't match... */ - if (buflength < 2) + if (fb->length < 2) result = 0; else { - bufptr = buffer + rules->offset - bufoffset; + bufptr = fb->buffer + rules->offset - fb->offset; shortv = (bufptr[0] << 8) | bufptr[1]; result = (shortv == rules->value.shortv); } @@ -904,16 +938,17 @@ checkrules(const char *filename, /* I - Filename */ * Load the buffer if necessary... */ - if (bufoffset < 0 || rules->offset < bufoffset || - (rules->offset + 4) > (bufoffset + buflength)) + if (fb->offset < 0 || rules->offset < fb->offset || + (rules->offset + 4) > (fb->offset + fb->length)) { /* * Reload file buffer... */ - cupsFileSeek(fp, rules->offset); - buflength = cupsFileRead(fp, (char *)buffer, sizeof(buffer)); - bufoffset = rules->offset; + cupsFileSeek(fb->fp, rules->offset); + fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, + sizeof(fb->buffer)); + fb->offset = rules->offset; } /* @@ -921,22 +956,24 @@ checkrules(const char *filename, /* I - Filename */ * can't match... */ - if (buflength < 4) + if (fb->length < 4) result = 0; else { - bufptr = buffer + rules->offset - bufoffset; - intv = (((((bufptr[0] << 8) | bufptr[1]) << 8) | bufptr[2]) << 8) | - bufptr[3];; + bufptr = fb->buffer + rules->offset - fb->offset; + intv = (((((bufptr[0] << 8) | bufptr[1]) << 8) | + bufptr[2]) << 8) | bufptr[3]; result = (intv == rules->value.intv); } break; case MIME_MAGIC_LOCALE : #if defined(WIN32) || defined(__EMX__) || defined(__APPLE__) - result = (strcmp(rules->value.localev, setlocale(LC_ALL, "")) == 0); + result = (strcmp(rules->value.localev, + setlocale(LC_ALL, "")) == 0); #else - result = (strcmp(rules->value.localev, setlocale(LC_MESSAGES, "")) == 0); + result = (strcmp(rules->value.localev, + setlocale(LC_MESSAGES, "")) == 0); #endif /* __APPLE__ */ break; @@ -945,16 +982,17 @@ checkrules(const char *filename, /* I - Filename */ * Load the buffer if necessary... */ - if (bufoffset < 0 || rules->offset < bufoffset || - (rules->offset + rules->region) > (bufoffset + buflength)) + if (fb->offset < 0 || rules->offset < fb->offset || + (rules->offset + rules->region) > (fb->offset + fb->length)) { /* * Reload file buffer... */ - cupsFileSeek(fp, rules->offset); - buflength = cupsFileRead(fp, (char *)buffer, sizeof(buffer)); - bufoffset = rules->offset; + cupsFileSeek(fb->fp, rules->offset); + fb->length = cupsFileRead(fb->fp, (char *)fb->buffer, + sizeof(fb->buffer)); + fb->offset = rules->offset; } /* @@ -962,25 +1000,26 @@ checkrules(const char *filename, /* I - Filename */ * short then don't compare - it can't match... */ - if ((rules->offset + rules->length) > (bufoffset + buflength)) + if ((rules->offset + rules->length) > (fb->offset + fb->length)) result = 0; else { - if (buflength > rules->region) + if (fb->length > rules->region) region = rules->region - rules->length; else - region = buflength - rules->length; + region = fb->length - rules->length; for (n = 0; n < region; n ++) - if ((result = (memcmp(buffer + rules->offset - bufoffset + n, - rules->value.stringv, rules->length) == 0)) != 0) + if ((result = (memcmp(fb->buffer + rules->offset - fb->offset + n, + rules->value.stringv, + rules->length) == 0)) != 0) break; } break; default : if (rules->child != NULL) - result = checkrules(filename, fp, rules->child); + result = checkrules(filename, fb, rules->child); else result = 0; break; @@ -1047,7 +1086,7 @@ patmatch(const char *s, /* I - String to match against */ pat ++; if (*pat == '\0') - return (1); /* Last pattern char is *, so everything matches now... */ + return (1); /* Last pattern char is *, so everything matches... */ /* * Test all remaining combinations until we get to the end of the string. @@ -1113,8 +1152,8 @@ patmatch(const char *s, /* I - String to match against */ } /* - * Done parsing the pattern and string; return 1 if the last character matches - * and 0 otherwise... + * Done parsing the pattern and string; return 1 if the last character + * matches and 0 otherwise... */ return (*s == *pat); @@ -1122,5 +1161,5 @@ patmatch(const char *s, /* I - String to match against */ /* - * End of "$Id: type.c 4970 2006-01-24 14:05:45Z mike $". + * End of "$Id: type.c 5052 2006-02-02 16:21:13Z mike $". */ diff --git a/templates/Makefile b/templates/Makefile index 31f7d7dce..4572248cc 100644 --- a/templates/Makefile +++ b/templates/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile 4950 2006-01-19 16:07:57Z mike $" +# "$Id: Makefile 5055 2006-02-02 18:25:38Z mike $" # # Template makefile for the Common UNIX Printing System (CUPS). # @@ -81,6 +81,8 @@ FILES = \ printers.tmpl \ printers-header.tmpl \ restart.tmpl \ + samba-export.tmpl \ + samba-exported.tmpl \ search.tmpl \ set-printer-options-header.tmpl \ set-printer-options-trailer.tmpl \ @@ -115,5 +117,5 @@ install: all # -# End of "$Id: Makefile 4950 2006-01-19 16:07:57Z mike $". +# End of "$Id: Makefile 5055 2006-02-02 18:25:38Z mike $". # diff --git a/templates/samba-export.tmpl b/templates/samba-export.tmpl new file mode 100644 index 000000000..0510f550c --- /dev/null +++ b/templates/samba-export.tmpl @@ -0,0 +1,55 @@ + + +
+ + +

Export Printers to Samba

+ +{error?

Unable to export printers to Samba\:

+
{error}
+

Consult the error_log file for more information.

: +

This page allows you to export printers to Samba so that +Windows clients can access them through the Network +Neighborhood or Network Places icons on their +desktop. You must previously install the Windows PostScript +printer drivers as described in the cupsaddsmb(8) man page.

} + + + + + + + + + + + + + + + + + + +
Printers: +
+ Export All Printers +
Samba Username: (required)
Samba Password: (required)
+ +
diff --git a/templates/samba-exported.tmpl b/templates/samba-exported.tmpl new file mode 100644 index 000000000..6fa8eb4a6 --- /dev/null +++ b/templates/samba-exported.tmpl @@ -0,0 +1 @@ +

Printers exported to samba successfully.

-- 2.39.5