-CHANGES.txt - 09/18/2005
+CHANGES.txt - 09/21/2005
------------------------
CHANGES IN CUPS V1.2.0b1
+ - Made the CUPS API library thread-safe (STR #1276)
- Added "media" option support for EFI EFMediaType option
(STR #902)
- Added write buffering to the HTTP code to improve
t = (time_t)attr->values[i].integer;
date = localtime(&t);
- strftime(valptr, sizeof(value) - (valptr - value),
- CUPS_STRFTIME_FORMAT, date);
+ strftime(valptr, sizeof(value) - (valptr - value), "%c", date);
}
else
snprintf(valptr, sizeof(value) - (valptr - value),
AC_CHECK_FUNCS(snprintf vsnprintf)
fi
-dnl Check OS version and use appropriate format string for strftime...
-AC_MSG_CHECKING(for correct format string to use with strftime)
-
-case "$uname" in
- IRIX | SunOS*)
- # IRIX and SunOS
- AC_MSG_RESULT(NULL)
- AC_DEFINE(CUPS_STRFTIME_FORMAT, NULL)
- ;;
- *)
- # All others
- AC_MSG_RESULT("%c")
- AC_DEFINE(CUPS_STRFTIME_FORMAT, "%c")
- ;;
-esac
-
dnl Checks for mkstemp and mkstemps functions.
AC_CHECK_FUNCS(mkstemp mkstemps)
--- /dev/null
+dnl
+dnl "$Id$"
+dnl
+dnl Threading stuff for the Common UNIX Printing System (CUPS).
+dnl
+dnl Copyright 1997-2005 by Easy Software Products, all rights reserved.
+dnl
+dnl These coded instructions, statements, and computer programs are the
+dnl property of Easy Software Products and are protected by Federal
+dnl copyright law. Distribution and use rights are outlined in the file
+dnl "LICENSE.txt" which should have been included with this file. If this
+dnl file is missing or damaged please contact Easy Software Products
+dnl at:
+dnl
+dnl Attn: CUPS Licensing Information
+dnl Easy Software Products
+dnl 44141 Airport View Drive, Suite 204
+dnl Hollywood, Maryland 20636 USA
+dnl
+dnl Voice: (301) 373-9600
+dnl EMail: cups-info@cups.org
+dnl WWW: http://www.cups.org
+dnl
+
+AC_ARG_ENABLE(threads, [ --enable-threads enable multi-threading support])
+
+have_pthread=no
+
+if test "x$enable_threads" != xno; then
+ AC_CHECK_HEADER(pthread.h, AC_DEFINE(HAVE_PTHREAD_H))
+ AC_CHECK_LIB(pthread, pthread_create,
+ COMMONLIBS="-lpthread $COMMONLIBS")
+
+ if test "x$ac_cv_lib_pthread_pthread_create" = xyes -a x$ac_cv_header_pthread_h = xyes; then
+ have_pthread=yes
+ else
+ dnl *BSD uses -pthread option...
+ AC_MSG_CHECKING([for pthread_create using -pthread])
+ SAVELIBS="$LIBS"
+ LIBS="-pthread $LIBS"
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_create(0, 0, 0, 0);],
+ COMMONLIBS="-pthread $COMMONLIBS"
+ have_pthread=yes)
+ LIBS="$SAVELIBS"
+ AC_MSG_RESULT([$have_pthread])
+ fi
+fi
+
+
+dnl
+dnl End of "$Id$".
+dnl
#define CUPS_STATEDIR "/var/run/cups"
-/*
- * What is the format string for strftime?
- */
-
-#define CUPS_STRFTIME_FORMAT NULL
-
-
/*
* Do we have various image libraries?
*/
#undef HAVE_USERSEC_H
+/*
+ * Do we have pthread support?
+ */
+
+#undef HAVE_PTHREAD_H
+
/*
* Various scripting languages...
sinclude(config-scripts/cups-slp.m4)
sinclude(config-scripts/cups-ssl.m4)
sinclude(config-scripts/cups-pam.m4)
+sinclude(config-scripts/cups-threads.m4)
MAKEDEFS="../Makedefs"
AC_SUBST(MAKEDEFS)
file.o: md5.h
getputfile.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h file.h
getputfile.o: language.h debug.h
-http.o: http-private.h ../config.h http.h string.h md5.h debug.h
-http-addr.o: http.h string.h ../config.h md5.h debug.h
+globals.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+globals.o: file.h language.h normalize.h transcode.h http-private.h
+http.o: http-private.h ../config.h http.h string.h md5.h globals.h cups.h
+http.o: ipp.h ppd.h file.h language.h normalize.h transcode.h debug.h
+http-addr.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+http-addr.o: file.h language.h normalize.h transcode.h debug.h
http-support.o: string.h ../config.h http.h md5.h ipp.h
-ipp.o: string.h ../config.h ipp.h http.h md5.h debug.h
-ipp-support.o: string.h ../config.h language.h ipp.h http.h md5.h debug.h
+ipp.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h file.h
+ipp.o: language.h normalize.h transcode.h debug.h
+ipp-support.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+ipp-support.o: file.h language.h normalize.h transcode.h debug.h
langprintf.o: string.h ../config.h language.h transcode.h
-language.o: string.h ../config.h language.h debug.h cups_C.h
+language.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+language.o: file.h language.h normalize.h transcode.h debug.h cups_C.h
mark.o: ppd.h file.h string.h ../config.h debug.h
md5.o: md5.h string.h ../config.h
md5passwd.o: http.h string.h ../config.h md5.h
-normalize.o: string.h ../config.h language.h transcode.h normalize.h
+normalize.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+normalize.o: file.h language.h normalize.h transcode.h debug.h
options.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h file.h
options.o: debug.h
page.o: ppd.h file.h string.h ../config.h
-ppd.o: ppd.h file.h string.h ../config.h language.h debug.h
+ppd.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h file.h
+ppd.o: language.h normalize.h transcode.h debug.h
snprintf.o: string.h ../config.h
string.o: string.h ../config.h
-tempfile.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h file.h
-tempfile.o: debug.h
-transcode.o: string.h ../config.h language.h transcode.h
-usersys.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h file.h
-usersys.o: http-private.h
-util.o: cups.h ipp.h http.h string.h ../config.h md5.h ppd.h file.h
-util.o: language.h debug.h
+tempfile.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+tempfile.o: file.h language.h normalize.h transcode.h debug.h
+transcode.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h
+transcode.o: file.h language.h normalize.h transcode.h
+usersys.o: http-private.h ../config.h http.h string.h md5.h globals.h cups.h
+usersys.o: ipp.h ppd.h file.h language.h normalize.h transcode.h
+util.o: globals.h string.h ../config.h cups.h ipp.h http.h md5.h ppd.h file.h
+util.o: language.h normalize.h transcode.h debug.h
testhttp.o: http.h string.h ../config.h md5.h
testi18n.o: language.h string.h ../config.h transcode.h normalize.h
testipp.o: ../cups/string.h ../config.h string.h ipp.h http.h md5.h
# Object files...
#
-LIBOBJS = attr.o auth.o backchannel.o dest.o dir.o emit.o encode.o \
- file.o getputfile.o http.o http-addr.o http-support.o \
- ipp.o ipp-support.o langprintf.o language.o mark.o \
- md5.o md5passwd.o normalize.o options.o page.o ppd.o \
- snprintf.o string.o tempfile.o transcode.o usersys.o util.o
-OBJS = $(LIBOBJS) testhttp.o testi18n.o testipp.o testlang.o \
+LIBOBJS = \
+ attr.o \
+ auth.o \
+ backchannel.o \
+ dest.o \
+ dir.o \
+ emit.o \
+ encode.o \
+ file.o \
+ getputfile.o \
+ globals.o \
+ http.o \
+ http-addr.o \
+ http-support.o \
+ ipp.o \
+ ipp-support.o \
+ langprintf.o \
+ language.o \
+ mark.o \
+ md5.o \
+ md5passwd.o \
+ normalize.o \
+ options.o \
+ page.o \
+ ppd.o \
+ snprintf.o \
+ string.o \
+ tempfile.o \
+ transcode.o \
+ usersys.o \
+ util.o
+OBJS = \
+ $(LIBOBJS) \
+ testhttp.o \
+ testi18n.o \
+ testipp.o \
+ testlang.o \
php_cups_wrap.o
# Header files to install...
#
-HEADERS = cups.h dir.h file.h http.h ipp.h language.h md5.h \
- normalize.h ppd.h transcode.h
+HEADERS = \
+ cups.h \
+ dir.h \
+ file.h \
+ http.h \
+ ipp.h \
+ language.h \
+ md5.h \
+ normalize.h \
+ ppd.h \
+ transcode.h
#
# Targets in this directory...
#
-TARGETS = $(LIBCUPS) libcups.a \
- testhttp testi18n testipp testlang
+TARGETS = \
+ $(LIBCUPS) \
+ libcups.a \
+ testhttp \
+ testi18n \
+ testipp \
+ testlang
#
* Local globals...
*/
-static const char *ppd_custom_code =
+static const char ppd_custom_code[] =
"pop pop pop\n"
"<</PageSize[5 -2 roll]/ImagingBBox null>>setpagedevice\n";
--- /dev/null
+/*
+ * "$Id$"
+ *
+ * Global variable access routines for the Common UNIX Printing System (CUPS).
+ *
+ * Copyright 1997-2005 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
+ * copyright law. Distribution and use rights are outlined in the file
+ * "LICENSE.txt" which should have been included with this file. If this
+ * file is missing or damaged please contact Easy Software Products
+ * at:
+ *
+ * Attn: CUPS Licensing Information
+ * Easy Software Products
+ * 44141 Airport View Drive, Suite 204
+ * Hollywood, Maryland 20636 USA
+ *
+ * Voice: (301) 373-9600
+ * EMail: cups-info@cups.org
+ * WWW: http://www.cups.org
+ *
+ * This file is subject to the Apple OS-Developed Software exception.
+ *
+ * Contents:
+ *
+ * _cupsGlobals() - Return a pointer to thread local storage.
+ * globals_init() - Initialize globals once.
+ * globals_destructor() - Free memory allocated by _cupsGlobals().
+ */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "globals.h"
+#include "http-private.h"
+#include <stdlib.h>
+
+
+#ifdef HAVE_PTHREAD_H
+/*
+ * Implement per-thread globals...
+ */
+
+/*
+ * Local globals...
+ */
+
+static pthread_key_t globals_key = -1;
+ /* Thread local storage key */
+static pthread_once_t globals_key_once = PTHREAD_ONCE_INIT;
+ /* One-time initialization object */
+
+
+/*
+ * Local functions...
+ */
+
+static void globals_init();
+static void globals_destructor(void *value);
+
+
+/*
+ * '_cupsGlobals()' - Return a pointer to thread local storage
+ */
+
+cups_globals_t * /* O - Pointer to global data */
+_cupsGlobals(void)
+{
+ cups_globals_t *globals; /* Pointer to global data */
+
+
+ /*
+ * Initialize the global data exactly once...
+ */
+
+ pthread_once(&globals_key_once, globals_init);
+
+ /*
+ * See if we have allocated the data yet...
+ */
+
+ if ((globals = (cups_globals_t *)pthread_getspecific(globals_key)) == NULL)
+ {
+ /*
+ * No, allocate memory as set the pointer for the key...
+ */
+
+ globals = calloc(1, sizeof(cups_globals_t));
+ pthread_setspecific(globals_key, globals);
+
+ /*
+ * Initialize variables that have non-zero values
+ */
+
+ globals->encryption = (http_encryption_t)-1;
+ globals->password_cb = _cupsGetPassword;
+ }
+
+ /*
+ * Return the pointer to the data...
+ */
+
+ return (globals);
+}
+
+
+/*
+ * 'globals_init()' - Initialize globals once.
+ */
+
+static void
+globals_init()
+{
+ pthread_key_create(&globals_key, globals_destructor);
+}
+
+
+/*
+ * 'globals_destructor()' - Free memory allocated by _cupsGlobals().
+ */
+
+static void
+globals_destructor(void *value) /* I - Data to free */
+{
+ free(value);
+}
+
+
+#else
+/*
+ * Implement static globals...
+ */
+
+/*
+ * '_cupsGlobals()' - Return a pointer to thread local storage.
+ *
+ * @private
+ */
+
+cups_globals_t * /* O - Pointer to global data */
+_cupsGlobals(void)
+{
+ static cups_globals_t globals = { 0 };/* Global data */
+ static int initialized = 0;/* Global data initialized? */
+
+
+ /*
+ * Initialize global data as needed...
+ */
+
+ if (!initialized)
+ {
+ initialized = 1;
+
+ /*
+ * Initialize variables that have non-zero default values...
+ */
+
+ globals.encryption = (http_encryption_t)-1;
+ globals.password_cb = _cupsGetPassword;
+ }
+
+ return (&cups_globals);
+}
+#endif /* HAVE_PTHREAD_H */
+
+
+/*
+ * End of "$Id$".
+ */
--- /dev/null
+/*
+ * "$Id$"
+ *
+ * Global variable definitions for the Common UNIX Printing System (CUPS).
+ *
+ * Copyright 1997-2005 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
+ * copyright law. Distribution and use rights are outlined in the file
+ * "LICENSE.txt" which should have been included with this file. If this
+ * file is missing or damaged please contact Easy Software Products
+ * at:
+ *
+ * Attn: CUPS Licensing Information
+ * Easy Software Products
+ * 44141 Airport View Drive, Suite 204
+ * Hollywood, Maryland 20636 USA
+ *
+ * Voice: (301) 373-9600
+ * EMail: cups-info@cups.org
+ * WWW: http://www.cups.org
+ *
+ * This file is subject to the Apple OS-Developed Software exception.
+ */
+
+#ifndef _CUPS_GLOBALS_H_
+# define _CUPS_GLOBALS_H_
+
+/*
+ * Include necessary headers...
+ */
+
+# include "string.h"
+# include "cups.h"
+# include "language.h"
+# include "normalize.h"
+# include "transcode.h"
+
+# ifdef HAVE_PTHREAD_H
+# include <pthread.h>
+# endif /* HAVE_PTHREAD_H */
+
+
+/*
+ * C++ magic...
+ */
+
+# ifdef __cplusplus
+extern "C" {
+# endif /* __cplusplus */
+
+
+/*
+ * Constants/limits...
+ */
+
+# define CUPS_MAX_ADDRS 100 /* Limit on number of addresses... */
+
+
+/*
+ * To make libcups thread safe, define thread safe globals (aka thread-
+ * specific data) for the static variables used in the library.
+ */
+
+typedef struct cups_globals_s /**** CUPS global state data ****/
+{
+ /* http.c */
+ char http_date[256]; /* Date+time buffer */
+
+ /* http-addr.c */
+ unsigned ip_addrs[CUPS_MAX_ADDRS][4];
+ /* Packed IPv4/6 addresses */
+ char *ip_ptrs[CUPS_MAX_ADDRS + 1];
+ /* Pointer to packed address */
+ struct hostent hostent; /* Host entry for IP address */
+# ifdef HAVE_GETADDRINFO
+ char hostname[1024]; /* Hostname */
+# endif /* HAVE_GETADDRINFO */
+
+ /* ipp.c */
+ ipp_uchar_t ipp_date[11]; /* RFC-1903 date/time data */
+
+ /* ipp-support.c */
+ int ipp_port; /* IPP port number */
+ char ipp_unknown[255];
+ /* Unknown error statuses */
+
+ /* normalize.c */
+ cups_normmap_t *normmap_cache; /* Normalize Map cache */
+ cups_foldmap_t *foldmap_cache; /* Case Fold cache */
+ cups_propmap_t *propmap_cache; /* Char Prop Map Cache */
+ cups_combmap_t *combmap_cache; /* Comb Class Map Cache */
+ cups_breakmap_t *breakmap_cache;/* Line Break Map Cache */
+
+ /* language.c */
+ cups_lang_t *lang_cache; /* Language string cache */
+# ifdef __APPLE__
+# ifdef HAVE_CF_LOCALE_ID
+ char language[32]; /* Cached language */
+# else
+ const char *language; /* Cached language */
+# endif /* HAVE_CF_LOCALE_ID */
+# endif /* __APPLE__ */
+
+ /* ppd.c */
+ ppd_status_t ppd_status; /* Status of last ppdOpen*() */
+ int ppd_line; /* Current line number */
+ ppd_conform_t ppd_conform; /* Level of conformance required */
+
+ /* tempfile.c */
+ char tempfile[1024]; /* cupsTempFd/File buffer */
+
+ /* transcode.c */
+ cups_cmap_t *cmap_cache; /* SBCS Charmap Cache */
+ cups_vmap_t *vmap_cache; /* VBCS Charmap Cache */
+
+ /* usersys.c */
+ http_encryption_t encryption; /* Encryption setting */
+ char user[65], /* User name */
+ server[256]; /* Server address */
+ const char *(*password_cb)(const char *);
+ /* Password callback */
+
+ /* util.c */
+ http_t *http; /* Current server connection */
+ ipp_status_t last_error; /* Last IPP error */
+ char def_printer[256];
+ /* Default printer */
+ char ppd_filename[HTTP_MAX_URI];
+ /* PPD filename */
+} cups_globals_t;
+
+
+/*
+ * Prototypes...
+ */
+
+extern const char *_cupsGetPassword(const char *prompt);
+extern cups_globals_t *_cupsGlobals(void);
+
+
+/*
+ * C++ magic...
+ */
+
+# ifdef __cplusplus
+}
+# endif /* __cplusplus */
+#endif /* !_CUPS_GLOBALS_H_ */
+
+/*
+ * End of "$Id$".
+ */
* Include necessary headers...
*/
-#include "http.h"
+#include "globals.h"
#include "debug.h"
-#include "string.h"
#include <stdlib.h>
int i; /* Looping var */
const char *nameptr; /* Pointer into name */
unsigned ip[4]; /* IP address components */
- static unsigned packed_ip[100][4];/* Packed IPv4/6 addresses */
- static char *packed_ptr[101];/* Pointer to packed address */
- static struct hostent host_ip; /* Host entry for IP/domain address */
-#ifdef HAVE_GETADDRINFO
- static char h_name[1024]; /* Hostname */
-#endif /* HAVE_GETADDRINFO */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
DEBUG_printf(("httpGetHostByName(name=\"%s\")\n", name));
-#if defined(__APPLE__)
- /* OS X hack to avoid it's ocassional long delay in lookupd */
- static const char sLoopback[] = "127.0.0.1";
+ /*
+ * Avoid lookup delays and configuration problems when connecting
+ * to the localhost address...
+ */
+
if (!strcmp(name, "localhost"))
- name = sLoopback;
-#endif /* __APPLE__ */
+ name = "127.0.0.1";
/*
* This function is needed because some operating systems have a
* A domain socket address, so make an AF_LOCAL entry and return it...
*/
- host_ip.h_name = (char *)name;
- host_ip.h_aliases = NULL;
- host_ip.h_addrtype = AF_LOCAL;
- host_ip.h_length = strlen(name) + 1;
- host_ip.h_addr_list = packed_ptr;
- packed_ptr[0] = (char *)name;
- packed_ptr[1] = NULL;
+ cg->hostent.h_name = (char *)name;
+ cg->hostent.h_aliases = NULL;
+ cg->hostent.h_addrtype = AF_LOCAL;
+ cg->hostent.h_length = strlen(name) + 1;
+ cg->hostent.h_addr_list = cg->ip_ptrs;
+ cg->ip_ptrs[0] = (char *)name;
+ cg->ip_ptrs[1] = NULL;
DEBUG_puts("httpGetHostByName: returning domain socket address...");
- return (&host_ip);
+ return (&cg->hostent);
}
#endif /* AF_LOCAL */
#ifdef AF_INET6
* A raw 128-bit IPv6 address of the form "[xxxx:xxxx:xxxx:xxxx]"
*/
- host_ip.h_name = (char *)name;
- host_ip.h_aliases = NULL;
- host_ip.h_addrtype = AF_INET6;
- host_ip.h_length = 16;
- host_ip.h_addr_list = packed_ptr;
- packed_ptr[0] = (char *)(packed_ip[0]);
- packed_ptr[1] = NULL;
+ cg->hostent.h_name = (char *)name;
+ cg->hostent.h_aliases = NULL;
+ cg->hostent.h_addrtype = AF_INET6;
+ cg->hostent.h_length = 16;
+ cg->hostent.h_addr_list = cg->ip_ptrs;
+ cg->ip_ptrs[0] = (char *)(cg->ip_addrs[0]);
+ cg->ip_ptrs[1] = NULL;
for (i = 0, nameptr = name + 1; *nameptr && i < 4; i ++)
{
if (*nameptr == ']')
break;
else if (*nameptr == ':')
- packed_ip[0][i] = 0;
+ cg->ip_addrs[0][i] = 0;
else
- packed_ip[0][i] = htonl(strtoul(nameptr, (char **)&nameptr, 16));
+ cg->ip_addrs[0][i] = htonl(strtoul(nameptr, (char **)&nameptr, 16));
if (*nameptr == ':' || *nameptr == ']')
nameptr ++;
while (i < 4)
{
- packed_ip[0][i] = 0;
+ cg->ip_addrs[0][i] = 0;
i ++;
}
DEBUG_puts("httpGetHostByName: returning IPv6 address...");
- return (&host_ip);
+ return (&cg->hostent);
}
#endif /* AF_INET6 */
if (ip[0] > 255 || ip[1] > 255 || ip[2] > 255 || ip[3] > 255)
return (NULL); /* Invalid byte ranges! */
- packed_ip[0][0] = htonl(((((((ip[0] << 8) | ip[1]) << 8) | ip[2]) << 8) |
+ cg->ip_addrs[0][0] = htonl(((((((ip[0] << 8) | ip[1]) << 8) | ip[2]) << 8) |
ip[3]));
/*
* Fill in the host entry and return it...
*/
- host_ip.h_name = (char *)name;
- host_ip.h_aliases = NULL;
- host_ip.h_addrtype = AF_INET;
- host_ip.h_length = 4;
- host_ip.h_addr_list = packed_ptr;
- packed_ptr[0] = (char *)packed_ip[0];
- packed_ptr[1] = NULL;
+ cg->hostent.h_name = (char *)name;
+ cg->hostent.h_aliases = NULL;
+ cg->hostent.h_addrtype = AF_INET;
+ cg->hostent.h_length = 4;
+ cg->hostent.h_addr_list = cg->ip_ptrs;
+ cg->ip_ptrs[0] = (char *)cg->ip_addrs[0];
+ cg->ip_ptrs[1] = NULL;
DEBUG_puts("httpGetHostByName: returning IPv4 address...");
- return (&host_ip);
+ return (&cg->hostent);
}
else
#ifdef HAVE_GETADDRINFO
}
}
- strlcpy(h_name, current->ai_canonname, sizeof(h_name));
+ strlcpy(cg->hostname, current->ai_canonname, sizeof(cg->hostname));
- host_ip.h_name = h_name;
- host_ip.h_aliases = NULL;
- host_ip.h_addrtype = current->ai_family;
- host_ip.h_addr_list = packed_ptr;
+ cg->hostent.h_name = cg->hostname;
+ cg->hostent.h_aliases = NULL;
+ cg->hostent.h_addrtype = current->ai_family;
+ cg->hostent.h_addr_list = cg->ip_ptrs;
if (current->ai_family == AF_INET6)
- host_ip.h_length = 16;
+ cg->hostent.h_length = 16;
else
- host_ip.h_length = 4;
+ cg->hostent.h_length = 4;
/*
* Convert the address info to a hostent structure...
*/
- for (i = 0, current = results; i < 100 && current; current = current->ai_next)
- if (current->ai_family == host_ip.h_addrtype)
+ for (i = 0, current = results;
+ i < CUPS_MAX_ADDRS && current;
+ current = current->ai_next)
+ if (current->ai_family == cg->hostent.h_addrtype)
{
/*
* Copy this address...
address = (http_addr_t *)(current->ai_addr);
if (current->ai_family == AF_INET)
- memcpy((char *)packed_ip[i], (char *)&(address->ipv4.sin_addr), 4);
+ memcpy((char *)cg->ip_addrs[i], (char *)&(address->ipv4.sin_addr), 4);
else
- memcpy((char *)packed_ip[i], (char *)&(address->ipv6.sin6_addr), 16);
+ memcpy((char *)cg->ip_addrs[i], (char *)&(address->ipv6.sin6_addr), 16);
- packed_ptr[i] = (char *)packed_ip[i];
+ cg->ip_ptrs[i] = (char *)cg->ip_addrs[i];
i ++;
}
- packed_ptr[i] = NULL;
+ cg->ip_ptrs[i] = NULL;
/*
* Free the getaddrinfo() results and return the hostent structure...
freeaddrinfo(results);
- return (&host_ip);
+ return (&cg->hostent);
}
#else
{
*/
#include "http-private.h"
-
-#include <stdio.h>
+#include "globals.h"
+#include "debug.h"
#include <stdlib.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include "string.h"
#include <fcntl.h>
#include <errno.h>
-
-#include "http.h"
-#include "debug.h"
-
#ifndef WIN32
# include <signal.h>
# include <sys/time.h>
/*
* 'httpGetDateString()' - Get a formatted date/time string from a time value.
*
- * This function is not thread-safe and is therefore deprecated.
+ * @deprecated
*/
const char * /* O - Date/time string */
httpGetDateString(time_t t) /* I - UNIX time */
{
- static char datetime[256]; /* Date/time string */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
- return (httpGetDateString2(t, datetime, sizeof(datetime)));
+ return (httpGetDateString2(t, cg->http_date, sizeof(cg->http_date)));
}
* Include necessary headers...
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include "string.h"
-#include "language.h"
-
-#include "ipp.h"
+#include "globals.h"
#include "debug.h"
-#include <ctype.h>
+#include <stdlib.h>
/*
* Local globals...
*/
-static int ipp_port = 0;
static const char * const ipp_status_oks[] = /* "OK" status codes */
{
"successful-ok",
* 'ippErrorString()' - Return a name for the given status code.
*/
-const char * /* O - Text string */
-ippErrorString(ipp_status_t error) /* I - Error status */
+const char * /* O - Text string */
+ippErrorString(ipp_status_t error) /* I - Error status */
{
- static char unknown[255]; /* Unknown error statuses */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
/*
* No, build an "unknown-xxxx" error string...
*/
- sprintf(unknown, "unknown-%04x", error);
+ sprintf(cg->ipp_unknown, "unknown-%04x", error);
- return (unknown);
+ return (cg->ipp_unknown);
}
const char * /* O - Name */
ippOpString(ipp_op_t op) /* I - Operation ID */
{
- static char unknown[255]; /* Unknown error statuses */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
/*
* No, build an "unknown-xxxx" operation string...
*/
- sprintf(unknown, "unknown-%04x", op);
+ sprintf(cg->ipp_unknown, "unknown-%04x", op);
- return (unknown);
+ return (cg->ipp_unknown);
}
* 'ippPort()' - Return the default IPP port number.
*/
-int /* O - Port number */
+int /* O - Port number */
ippPort(void)
{
- const char *server_port; /* SERVER_PORT environment variable */
- struct servent *port; /* Port number info */
+ const char *server_port; /* SERVER_PORT environment variable */
+ struct servent *port; /* Port number info */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
- if (ipp_port)
- return (ipp_port);
+ if (cg->ipp_port)
+ return (cg->ipp_port);
else if ((server_port = getenv("IPP_PORT")) != NULL)
- return (ipp_port = atoi(server_port));
+ return (cg->ipp_port = atoi(server_port));
else if ((port = getservbyname("ipp", NULL)) == NULL)
- return (ipp_port = CUPS_DEFAULT_IPP_PORT);
+ return (cg->ipp_port = CUPS_DEFAULT_IPP_PORT);
else
- return (ipp_port = ntohs(port->s_port));
+ return (cg->ipp_port = ntohs(port->s_port));
}
*/
void
-ippSetPort(int p) /* I - Port number to use */
+ippSetPort(int p) /* I - Port number to use */
{
- ipp_port = p;
+ _cupsGlobals()->ipp_port = p;
}
* Include necessary headers...
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include "string.h"
-
-#include "ipp.h"
+#include "globals.h"
#include "debug.h"
-#include <ctype.h>
+#include <stdlib.h>
#include <errno.h>
-
#ifdef WIN32
# include <io.h>
#endif /* WIN32 */
* 'ippAddBoolean()' - Add a boolean attribute to an IPP request.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddBoolean(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- const char *name, /* I - Name of attribute */
- char value) /* I - Value of attribute */
+ipp_attribute_t * /* O - New attribute */
+ippAddBoolean(ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ const char *name, /* I - Name of attribute */
+ char value) /* I - Value of attribute */
{
- ipp_attribute_t *attr; /* New attribute */
+ ipp_attribute_t *attr; /* New attribute */
DEBUG_printf(("ippAddBoolean(%p, %02x, \'%s\', %d)\n", ipp, group, name, value));
* 'ippAddBooleans()' - Add an array of boolean values.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddBooleans(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- const char *name, /* I - Name of attribute */
- int num_values, /* I - Number of values */
- const char *values) /* I - Values */
+ipp_attribute_t * /* O - New attribute */
+ippAddBooleans(ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ const char *name, /* I - Name of attribute */
+ int num_values, /* I - Number of values */
+ const char *values) /* I - Values */
{
- int i; /* Looping var */
- ipp_attribute_t *attr; /* New attribute */
- ipp_value_t *value; /* Current value */
+ int i; /* Looping var */
+ ipp_attribute_t *attr; /* New attribute */
+ ipp_value_t *value; /* Current value */
DEBUG_printf(("ippAddBooleans(%p, %02x, \'%s\', %d, %p)\n", ipp,
* 'ippAddCollection()' - Add a collection value.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddCollection(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- const char *name, /* I - Name of attribute */
- ipp_t *value) /* I - Value */
+ipp_attribute_t * /* O - New attribute */
+ippAddCollection(ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ const char *name, /* I - Name of attribute */
+ ipp_t *value) /* I - Value */
{
- ipp_attribute_t *attr; /* New attribute */
+ ipp_attribute_t *attr; /* New attribute */
DEBUG_printf(("ippAddCollection(%p, %02x, \'%s\', %p)\n", ipp, group, name,
* 'ippAddCollections()' - Add an array of collection values.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddCollections(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- const char *name, /* I - Name of attribute */
- int num_values, /* I - Number of values */
- const ipp_t **values) /* I - Values */
+ipp_attribute_t * /* O - New attribute */
+ippAddCollections(
+ ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ const char *name, /* I - Name of attribute */
+ int num_values, /* I - Number of values */
+ const ipp_t **values) /* I - Values */
{
- int i; /* Looping var */
- ipp_attribute_t *attr; /* New attribute */
- ipp_value_t *value; /* Current value */
+ int i; /* Looping var */
+ ipp_attribute_t *attr; /* New attribute */
+ ipp_value_t *value; /* Current value */
DEBUG_printf(("ippAddCollections(%p, %02x, \'%s\', %d, %p)\n", ipp,
* 'ippAddDate()' - Add a date attribute to an IPP request.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddDate(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- const char *name, /* I - Name of attribute */
- const ipp_uchar_t *value) /* I - Value */
+ipp_attribute_t * /* O - New attribute */
+ippAddDate(ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ const char *name, /* I - Name of attribute */
+ const ipp_uchar_t *value) /* I - Value */
{
- ipp_attribute_t *attr; /* New attribute */
+ ipp_attribute_t *attr; /* New attribute */
DEBUG_printf(("ippAddDate(%p, %02x, \'%s\', %p)\n", ipp, group, name,
* 'ippAddInteger()' - Add a integer attribute to an IPP request.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddInteger(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- ipp_tag_t type, /* I - Type of attribute */
- const char *name, /* I - Name of attribute */
- int value) /* I - Value of attribute */
+ipp_attribute_t * /* O - New attribute */
+ippAddInteger(ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ ipp_tag_t type, /* I - Type of attribute */
+ const char *name, /* I - Name of attribute */
+ int value) /* I - Value of attribute */
{
- ipp_attribute_t *attr; /* New attribute */
+ ipp_attribute_t *attr; /* New attribute */
DEBUG_printf(("ippAddInteger(%p, %d, \'%s\', %d)\n", ipp, group, name,
* 'ippAddIntegers()' - Add an array of integer values.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddIntegers(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- ipp_tag_t type, /* I - Type of attribute */
- const char *name, /* I - Name of attribute */
- int num_values, /* I - Number of values */
- const int *values) /* I - Values */
+ipp_attribute_t * /* O - New attribute */
+ippAddIntegers(ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ ipp_tag_t type, /* I - Type of attribute */
+ const char *name, /* I - Name of attribute */
+ int num_values, /* I - Number of values */
+ const int *values) /* I - Values */
{
- int i; /* Looping var */
- ipp_attribute_t *attr; /* New attribute */
- ipp_value_t *value; /* Current value */
+ int i; /* Looping var */
+ ipp_attribute_t *attr; /* New attribute */
+ ipp_value_t *value; /* Current value */
if (ipp == NULL || name == NULL || num_values < 1)
* 'ippAddString()' - Add a language-encoded string to an IPP request.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddString(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- ipp_tag_t type, /* I - Type of attribute */
- const char *name, /* I - Name of attribute */
- const char *charset, /* I - Character set */
- const char *value) /* I - Value */
+ipp_attribute_t * /* O - New attribute */
+ippAddString(ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ ipp_tag_t type, /* I - Type of attribute */
+ const char *name, /* I - Name of attribute */
+ const char *charset, /* I - Character set */
+ const char *value) /* I - Value */
{
- ipp_attribute_t *attr; /* New attribute */
+ ipp_attribute_t *attr; /* New attribute */
if (ipp == NULL || name == NULL)
* 'ippAddStrings()' - Add language-encoded strings to an IPP request.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddStrings(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- ipp_tag_t type, /* I - Type of attribute */
- const char *name, /* I - Name of attribute */
- int num_values, /* I - Number of values */
- const char *charset, /* I - Character set */
- const char * const *values) /* I - Values */
+ipp_attribute_t * /* O - New attribute */
+ippAddStrings(
+ ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ ipp_tag_t type, /* I - Type of attribute */
+ const char *name, /* I - Name of attribute */
+ int num_values, /* I - Number of values */
+ const char *charset, /* I - Character set */
+ const char * const *values) /* I - Values */
{
- int i; /* Looping var */
- ipp_attribute_t *attr; /* New attribute */
- ipp_value_t *value; /* Current value */
+ int i; /* Looping var */
+ ipp_attribute_t *attr; /* New attribute */
+ ipp_value_t *value; /* Current value */
if (ipp == NULL || name == NULL || num_values < 1)
* 'ippAddRange()' - Add a range of values to an IPP request.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddRange(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- const char *name, /* I - Name of attribute */
- int lower, /* I - Lower value */
- int upper) /* I - Upper value */
+ipp_attribute_t * /* O - New attribute */
+ippAddRange(ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ const char *name, /* I - Name of attribute */
+ int lower, /* I - Lower value */
+ int upper) /* I - Upper value */
{
- ipp_attribute_t *attr; /* New attribute */
+ ipp_attribute_t *attr; /* New attribute */
if (ipp == NULL || name == NULL)
* 'ippAddRanges()' - Add ranges of values to an IPP request.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddRanges(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- const char *name, /* I - Name of attribute */
- int num_values, /* I - Number of values */
- const int *lower, /* I - Lower values */
- const int *upper) /* I - Upper values */
+ipp_attribute_t * /* O - New attribute */
+ippAddRanges(ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ const char *name, /* I - Name of attribute */
+ int num_values, /* I - Number of values */
+ const int *lower, /* I - Lower values */
+ const int *upper) /* I - Upper values */
{
- int i; /* Looping var */
- ipp_attribute_t *attr; /* New attribute */
- ipp_value_t *value; /* Current value */
+ int i; /* Looping var */
+ ipp_attribute_t *attr; /* New attribute */
+ ipp_value_t *value; /* Current value */
if (ipp == NULL || name == NULL || num_values < 1)
* 'ippAddResolution()' - Add a resolution value to an IPP request.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddResolution(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- const char *name, /* I - Name of attribute */
- ipp_res_t units, /* I - Units for resolution */
- int xres, /* I - X resolution */
- int yres) /* I - Y resolution */
+ipp_attribute_t * /* O - New attribute */
+ippAddResolution(ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ const char *name, /* I - Name of attribute */
+ ipp_res_t units, /* I - Units for resolution */
+ int xres, /* I - X resolution */
+ int yres) /* I - Y resolution */
{
- ipp_attribute_t *attr; /* New attribute */
+ ipp_attribute_t *attr; /* New attribute */
if (ipp == NULL || name == NULL)
* 'ippAddResolutions()' - Add resolution values to an IPP request.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddResolutions(ipp_t *ipp, /* I - IPP request */
- ipp_tag_t group, /* I - IPP group */
- const char *name, /* I - Name of attribute */
- int num_values, /* I - Number of values */
- ipp_res_t units, /* I - Units for resolution */
- const int *xres, /* I - X resolutions */
- const int *yres) /* I - Y resolutions */
+ipp_attribute_t * /* O - New attribute */
+ippAddResolutions(ipp_t *ipp, /* I - IPP request */
+ ipp_tag_t group, /* I - IPP group */
+ const char *name, /* I - Name of attribute */
+ int num_values,/* I - Number of values */
+ ipp_res_t units, /* I - Units for resolution */
+ const int *xres, /* I - X resolutions */
+ const int *yres) /* I - Y resolutions */
{
- int i; /* Looping var */
- ipp_attribute_t *attr; /* New attribute */
- ipp_value_t *value; /* Current value */
+ int i; /* Looping var */
+ ipp_attribute_t *attr; /* New attribute */
+ ipp_value_t *value; /* Current value */
if (ipp == NULL || name == NULL || num_values < 1)
* 'ippAddSeparator()' - Add a group separator to an IPP request.
*/
-ipp_attribute_t * /* O - New attribute */
-ippAddSeparator(ipp_t *ipp) /* I - IPP request */
+ipp_attribute_t * /* O - New attribute */
+ippAddSeparator(ipp_t *ipp) /* I - IPP request */
{
- ipp_attribute_t *attr; /* New attribute */
+ ipp_attribute_t *attr; /* New attribute */
DEBUG_printf(("ippAddSeparator(%p)\n", ipp));
* in seconds.
*/
-time_t /* O - UNIX time value */
-ippDateToTime(const ipp_uchar_t *date) /* I - RFC 1903 date info */
+time_t /* O - UNIX time value */
+ippDateToTime(const ipp_uchar_t *date) /* I - RFC 1903 date info */
{
- struct tm unixdate; /* UNIX date/time info */
- time_t t; /* Computed time */
+ struct tm unixdate; /* UNIX date/time info */
+ time_t t; /* Computed time */
memset(&unixdate, 0, sizeof(unixdate));
*/
void
-ippDelete(ipp_t *ipp) /* I - IPP request */
+ippDelete(ipp_t *ipp) /* I - IPP request */
{
- ipp_attribute_t *attr, /* Current attribute */
- *next; /* Next attribute */
+ ipp_attribute_t *attr, /* Current attribute */
+ *next; /* Next attribute */
DEBUG_printf(("ippDelete(): %p\n", ipp));
*/
void
-ippDeleteAttribute(ipp_t *ipp, /* I - IPP request */
- ipp_attribute_t *attr) /* I - Attribute to delete */
+ippDeleteAttribute(
+ ipp_t *ipp, /* I - IPP request */
+ ipp_attribute_t *attr) /* I - Attribute to delete */
{
+ ipp_attribute_t *current, /* Current attribute */
+ *prev; /* Previous attribute */
+
+
+ /*
+ * Find the attribute in the list...
+ */
+
+ for (current = ipp->attrs, prev = NULL;
+ current != NULL && current != attr;
+ prev = current, current = current->next);
+
+ if (current)
+ {
+ /*
+ * Found it, remove the attribute from the list...
+ */
+
+ if (prev)
+ prev->next = current->next;
+ else
+ ipp->attrs = current->next;
+
+ if (current == ipp->last)
+ ipp->last = prev;
+
+ /*
+ * Free memory used by the attribute...
+ */
+
+ _ipp_free_attr(current);
+ }
}
* 'ippFindAttribute()' - Find a named attribute in a request...
*/
-ipp_attribute_t * /* O - Matching attribute */
-ippFindAttribute(ipp_t *ipp, /* I - IPP request */
- const char *name, /* I - Name of attribute */
- ipp_tag_t type) /* I - Type of attribute */
+ipp_attribute_t * /* O - Matching attribute */
+ippFindAttribute(ipp_t *ipp, /* I - IPP request */
+ const char *name, /* I - Name of attribute */
+ ipp_tag_t type) /* I - Type of attribute */
{
DEBUG_printf(("ippFindAttribute(%p, \'%s\')\n", ipp, name));
* 'ippFindNextAttribute()' - Find the next named attribute in a request...
*/
-ipp_attribute_t * /* O - Matching attribute */
-ippFindNextAttribute(ipp_t *ipp, /* I - IPP request */
- const char *name, /* I - Name of attribute */
- ipp_tag_t type) /* I - Type of attribute */
+ipp_attribute_t * /* O - Matching attribute */
+ippFindNextAttribute(ipp_t *ipp, /* I - IPP request */
+ const char *name, /* I - Name of attribute */
+ ipp_tag_t type) /* I - Type of attribute */
{
- ipp_attribute_t *attr; /* Current atttribute */
- ipp_tag_t value_tag; /* Value tag */
+ ipp_attribute_t *attr; /* Current atttribute */
+ ipp_tag_t value_tag; /* Value tag */
DEBUG_printf(("ippFindNextAttribute(%p, \'%s\')\n", ipp, name));
* 'ippLength()' - Compute the length of an IPP request.
*/
-size_t /* O - Size of IPP request */
-ippLength(ipp_t *ipp) /* I - IPP request */
+size_t /* O - Size of IPP request */
+ippLength(ipp_t *ipp) /* I - IPP request */
{
return (ipp_length(ipp, 0));
}
* 'ippRead()' - Read data for an IPP request from a HTTP connection.
*/
-ipp_state_t /* O - Current state */
-ippRead(http_t *http, /* I - HTTP connection */
- ipp_t *ipp) /* I - IPP data */
+ipp_state_t /* O - Current state */
+ippRead(http_t *http, /* I - HTTP connection */
+ ipp_t *ipp) /* I - IPP data */
{
DEBUG_printf(("ippRead(http=%p, ipp=%p), data_remaining=%d\n", http, ipp,
http ? http->data_remaining : -1));
* 'ippReadFile()' - Read data for an IPP request from a file.
*/
-ipp_state_t /* O - Current state */
-ippReadFile(int fd, /* I - HTTP data */
- ipp_t *ipp) /* I - IPP data */
+ipp_state_t /* O - Current state */
+ippReadFile(int fd, /* I - HTTP data */
+ ipp_t *ipp) /* I - IPP data */
{
DEBUG_printf(("ippReadFile(%d, %p)\n", fd, ipp));
* 'ippReadIO()' - Read data for an IPP request.
*/
-ipp_state_t /* O - Current state */
-ippReadIO(void *src, /* I - Data source */
- ipp_iocb_t cb, /* I - Read callback function */
- int blocking, /* I - Use blocking IO? */
- ipp_t *parent, /* I - Parent request, if any */
- ipp_t *ipp) /* I - IPP data */
+ipp_state_t /* O - Current state */
+ippReadIO(void *src, /* I - Data source */
+ ipp_iocb_t cb, /* I - Read callback function */
+ int blocking, /* I - Use blocking IO? */
+ ipp_t *parent, /* I - Parent request, if any */
+ ipp_t *ipp) /* I - IPP data */
{
- int n; /* Length of data */
- unsigned char buffer[32768], /* Data buffer */
- *bufptr; /* Pointer into buffer */
- ipp_attribute_t *attr; /* Current attribute */
- ipp_tag_t tag; /* Current tag */
- ipp_value_t *value; /* Current value */
+ int n; /* Length of data */
+ unsigned char buffer[32768], /* Data buffer */
+ *bufptr; /* Pointer into buffer */
+ ipp_attribute_t *attr; /* Current attribute */
+ ipp_tag_t tag; /* Current tag */
+ ipp_value_t *value; /* Current value */
DEBUG_printf(("ippReadIO(%p, %p, %d, %p, %p)\n", src, cb, blocking,
* 'ippTimeToDate()' - Convert from UNIX time to RFC 1903 format.
*/
-const ipp_uchar_t * /* O - RFC-1903 date/time data */
-ippTimeToDate(time_t t) /* I - UNIX time value */
+const ipp_uchar_t * /* O - RFC-1903 date/time data */
+ippTimeToDate(time_t t) /* I - UNIX time value */
{
- struct tm *unixdate; /* UNIX unixdate/time info */
- static ipp_uchar_t date[11]; /* RFC-1903 date/time data */
+ struct tm *unixdate; /* UNIX unixdate/time info */
+ ipp_uchar_t *date = _cupsGlobals()->ipp_date;
+ /* RFC-1903 date/time data */
/*
* 'ippWrite()' - Write data for an IPP request to a HTTP connection.
*/
-ipp_state_t /* O - Current state */
-ippWrite(http_t *http, /* I - HTTP connection */
- ipp_t *ipp) /* I - IPP data */
+ipp_state_t /* O - Current state */
+ippWrite(http_t *http, /* I - HTTP connection */
+ ipp_t *ipp) /* I - IPP data */
{
DEBUG_printf(("ippWrite(%p, %p)\n", http, ipp));
* 'ippWriteFile()' - Write data for an IPP request to a file.
*/
-ipp_state_t /* O - Current state */
-ippWriteFile(int fd, /* I - HTTP data */
- ipp_t *ipp) /* I - IPP data */
+ipp_state_t /* O - Current state */
+ippWriteFile(int fd, /* I - HTTP data */
+ ipp_t *ipp) /* I - IPP data */
{
DEBUG_printf(("ippWriteFile(%d, %p)\n", fd, ipp));
* 'ippWriteIO()' - Write data for an IPP request.
*/
-ipp_state_t /* O - Current state */
-ippWriteIO(void *dst, /* I - Destination */
- ipp_iocb_t cb, /* I - Write callback function */
- int blocking, /* I - Use blocking IO? */
- ipp_t *parent, /* I - Parent IPP request */
- ipp_t *ipp) /* I - IPP data */
+ipp_state_t /* O - Current state */
+ippWriteIO(void *dst, /* I - Destination */
+ ipp_iocb_t cb, /* I - Write callback function */
+ int blocking, /* I - Use blocking IO? */
+ ipp_t *parent, /* I - Parent IPP request */
+ ipp_t *ipp) /* I - IPP data */
{
- int i; /* Looping var */
- int n; /* Length of data */
- unsigned char buffer[32768], /* Data buffer */
- *bufptr; /* Pointer into buffer */
- ipp_attribute_t *attr; /* Current attribute */
- ipp_value_t *value; /* Current value */
+ int i; /* Looping var */
+ int n; /* Length of data */
+ unsigned char buffer[32768], /* Data buffer */
+ *bufptr; /* Pointer into buffer */
+ ipp_attribute_t *attr; /* Current attribute */
+ ipp_value_t *value; /* Current value */
DEBUG_printf(("ippWriteIO(%p, %p, %d, %p, %p)\n", dst, cb, blocking,
* '_ipp_add_attr()' - Add a new attribute to the request.
*/
-ipp_attribute_t * /* O - New attribute */
-_ipp_add_attr(ipp_t *ipp, /* I - IPP request */
- int num_values) /* I - Number of values */
+ipp_attribute_t * /* O - New attribute */
+_ipp_add_attr(ipp_t *ipp, /* I - IPP request */
+ int num_values) /* I - Number of values */
{
- ipp_attribute_t *attr; /* New attribute */
+ ipp_attribute_t *attr; /* New attribute */
DEBUG_printf(("_ipp_add_attr(%p, %d)\n", ipp, num_values));
*/
void
-_ipp_free_attr(ipp_attribute_t *attr) /* I - Attribute to free */
+_ipp_free_attr(ipp_attribute_t *attr) /* I - Attribute to free */
{
- int i; /* Looping var */
- ipp_value_t *value; /* Current value */
+ int i; /* Looping var */
+ ipp_value_t *value; /* Current value */
DEBUG_printf(("_ipp_free_attr(): %p\n", attr));
* 'ipp_length()' - Compute the length of an IPP request or collection value.
*/
-static size_t /* O - Size of IPP request */
-ipp_length(ipp_t *ipp, /* I - IPP request or collection */
- int collection) /* I - 1 if a collection, 0 otherwise */
+static size_t /* O - Size of IPP request */
+ipp_length(ipp_t *ipp, /* I - IPP request or collection */
+ int collection) /* I - 1 if a collection, 0 otherwise */
{
- int i; /* Looping var */
- int bytes; /* Number of bytes */
- ipp_attribute_t *attr; /* Current attribute */
- ipp_tag_t group; /* Current group */
- ipp_value_t *value; /* Current value */
+ int i; /* Looping var */
+ int bytes; /* Number of bytes */
+ ipp_attribute_t *attr; /* Current attribute */
+ ipp_tag_t group; /* Current group */
+ ipp_value_t *value; /* Current value */
if (ipp == NULL)
* 'ipp_read_http()' - Semi-blocking read on a HTTP connection...
*/
-static int /* O - Number of bytes read */
-ipp_read_http(http_t *http, /* I - Client connection */
- ipp_uchar_t *buffer, /* O - Buffer for data */
- int length) /* I - Total length */
+static int /* O - Number of bytes read */
+ipp_read_http(http_t *http, /* I - Client connection */
+ ipp_uchar_t *buffer, /* O - Buffer for data */
+ int length) /* I - Total length */
{
- int tbytes, /* Total bytes read */
- bytes; /* Bytes read this pass */
- char len[32]; /* Length string */
+ int tbytes, /* Total bytes read */
+ bytes; /* Bytes read this pass */
+ char len[32]; /* Length string */
DEBUG_printf(("ipp_read_http(http=%p, buffer=%p, length=%d)\n",
* 'ipp_read_file()' - Read IPP data from a file.
*/
-static int /* O - Number of bytes read */
-ipp_read_file(int *fd, /* I - File descriptor */
- ipp_uchar_t *buffer, /* O - Read buffer */
- int length) /* I - Number of bytes to read */
+static int /* O - Number of bytes read */
+ipp_read_file(int *fd, /* I - File descriptor */
+ ipp_uchar_t *buffer, /* O - Read buffer */
+ int length) /* I - Number of bytes to read */
{
return (read(*fd, buffer, length));
}
* 'ipp_write_file()' - Write IPP data to a file.
*/
-static int /* O - Number of bytes written */
-ipp_write_file(int *fd, /* I - File descriptor */
- ipp_uchar_t *buffer, /* I - Data to write */
- int length) /* I - Number of bytes to write */
+static int /* O - Number of bytes written */
+ipp_write_file(int *fd, /* I - File descriptor */
+ ipp_uchar_t *buffer, /* I - Data to write */
+ int length) /* I - Number of bytes to write */
{
return (write(*fd, buffer, length));
}
* Include necessary headers...
*/
-#include "string.h"
-#include "language.h"
+#include "globals.h"
#include "debug.h"
#include <stdlib.h>
#ifdef HAVE_LANGINFO_H
# include <CoreFoundation/CoreFoundation.h>
static const char *appleLangDefault(void);
#endif /* __APPLE__ */
-
static cups_lang_t *cups_cache_lookup(const char *name,
cups_encoding_t encoding);
* Local globals...
*/
-static cups_lang_t *lang_cache = NULL;
- /* Language string cache */
-static const char *lang_blank = "";
+static const char lang_blank[] = "";
/* Blank constant string */
static const char * const lang_encodings[] =
{ /* Encoding strings */
*/
const char * /* O - Character encoding */
-cupsEncodingName(cups_encoding_t encoding)
- /* I - Encoding enum */
+cupsEncodingName(
+ cups_encoding_t encoding) /* I - Encoding value */
{
if (encoding < 0 ||
encoding >= (sizeof(lang_encodings) / sizeof(const char *)))
int i; /* Looping var */
cups_lang_t *lang, /* Current language */
*next; /* Next language */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
/*
* Free all languages in the cache...
*/
- for (lang = lang_cache; lang != NULL; lang = next)
+ for (lang = cg->lang_cache; lang != NULL; lang = next)
{
/*
* Free all messages...
free(lang);
}
- lang_cache = NULL;
+ cg->lang_cache = NULL;
}
*/
void
-cupsLangFree(cups_lang_t *lang) /* I - Language to free */
+cupsLangFree(cups_lang_t *lang) /* I - Language to free */
{
if (lang != NULL && lang->used > 0)
lang->used --;
char *text; /* Message text */
cups_lang_t *lang; /* Current language... */
char *oldlocale; /* Old locale name */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
static const char * const locale_encodings[] =
{ /* Locale charset names */
"ASCII", "ISO88591", "ISO88592", "ISO88593",
#if defined(__APPLE__)
/* The ctype bug isn't in Apple's libc */
+ (void)locale; /* anti-compiler-warning-code */
+ (void)oldlocale; /* anti-compiler-warning-code */
#elif !defined(LC_CTYPE)
oldlocale = _cupsSaveLocale(LC_ALL, "C");
#else
* record...
*/
- for (lang = lang_cache; lang != NULL; lang = lang->next)
+ for (lang = cg->lang_cache; lang != NULL; lang = lang->next)
if (lang->used == 0)
break;
return (NULL);
}
- lang->next = lang_cache;
- lang_cache = lang;
+ lang->next = cg->lang_cache;
+ cg->lang_cache = lang;
}
/*
lang->encoding = CUPS_US_ASCII;
for (i = 0; i < (sizeof(lang_encodings) / sizeof(lang_encodings[0])); i ++)
- if (strcmp(lang_encodings[i], line) == 0)
+ if (!strcmp(lang_encodings[i], line))
{
lang->encoding = (cups_encoding_t)i;
break;
/* List of localization data */
CFStringRef languageName; /* Current name */
CFStringRef localeName; /* Canonical from of name */
- static char language[32] = "";
- /* Cached language */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
/*
* Only do the lookup and translation the first time.
*/
- if (!language[0])
+ if (!cg->language[0])
{
localizationList =
CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),
if (localeName != NULL)
{
- CFStringGetCString(localeName, language, sizeof(language),
+ CFStringGetCString(localeName, cg->language, sizeof(cg->language),
kCFStringEncodingASCII);
CFRelease(localeName);
- if (!strcmp(language, "en"))
- strlcpy(language, "en_US.UTF-8", sizeof(language));
- else if (strchr(language, '.') == NULL)
- strlcat(language, ".UTF-8", sizeof(language));
+ if (!strcmp(cg->language, "en"))
+ strlcpy(cg->language, "en_US.UTF-8", sizeof(cg->language));
+ else if (strchr(cg->language, '.') == NULL)
+ strlcat(cg->language, ".UTF-8", sizeof(cg->language));
}
}
}
* If we didn't find the language, default to en_US...
*/
- if (!language[0])
- strlcpy(language, "en_US.UTF-8", sizeof(language));
+ if (!cg->language[0])
+ strlcpy(cg->language, "en_US.UTF-8", sizeof(cg->language));
}
/*
* Return the cached locale...
*/
- return (language);
+ return (cg->language);
}
# else
/*
CFStringRef localizationName;
/* Current name */
char buff[256]; /* Temporary buffer */
- static const char *language = NULL;
- /* Cached language */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
/*
* Only do the lookup and translation the first time.
*/
- if (language == NULL)
+ if (cg->language == NULL)
{
localizationList =
CFPreferencesCopyAppValue(CFSTR("AppleLanguages"),
{
if (strcasecmp(buff, apple_name_locale[i].name) == 0)
{
- language = apple_name_locale[i].locale;
+ cg->language = apple_name_locale[i].locale;
break;
}
}
* If we didn't find the language, default to en_US...
*/
- if (language == NULL)
- language = apple_name_locale[0].locale;
+ if (cg->language == NULL)
+ cg->language = apple_name_locale[0].locale;
}
/*
* Return the cached locale...
*/
- return (language);
+ return (cg->language);
}
# endif /* HAVE_CF_LOCALE_ID */
#endif /* __APPLE__ */
* Loop through the cache and return a match if found...
*/
- for (lang = lang_cache; lang != NULL; lang = lang->next)
+ for (lang = _cupsGlobals()->lang_cache; lang != NULL; lang = lang->next)
{
DEBUG_printf(("cups_cache_lookup: lang=%p, language=\"%s\", encoding=%d(%s)\n",
lang, lang->language, lang->encoding,
* Include necessary headers...
*/
-#include <stdio.h>
+#include "globals.h"
+#include "debug.h"
#include <stdlib.h>
-#include <string.h>
#include <errno.h>
-#include <ctype.h>
#include <time.h>
-#include "language.h"
-#include "string.h"
-#include "transcode.h"
-#include "normalize.h"
-/*
- * Local Globals...
- */
-
-static cups_normmap_t *normmap_cache = NULL;/* Normalize Map cache */
-static cups_foldmap_t *foldmap_cache = NULL;/* Case Fold cache */
-static cups_propmap_t *propmap_cache = NULL;/* Char Prop Map Cache */
-static cups_combmap_t *combmap_cache = NULL;/* Comb Class Map Cache */
-static cups_breakmap_t *breakmap_cache = NULL;/* Line Break Map Cache */
-
-typedef struct /**** General Category Index Struct****/
+typedef struct /**** General Category Index Struct****/
{
- cups_gencat_t gencat; /* General Category Value */
- const char *str; /* General Category String */
+ cups_gencat_t gencat; /* General Category Value */
+ const char *str; /* General Category String */
} gencat_t;
-static gencat_t gencat_index[] = /* General Category Index */
+static const gencat_t gencat_index[] = /* General Category Index */
{
- { CUPS_GENCAT_LU, "Lu" }, /* Letter, Uppercase */
- { CUPS_GENCAT_LL, "Ll" }, /* Letter, Lowercase */
- { CUPS_GENCAT_LT, "Lt" }, /* Letter, Titlecase */
- { CUPS_GENCAT_LM, "Lm" }, /* Letter, Modifier */
- { CUPS_GENCAT_LO, "Lo" }, /* Letter, Other */
- { CUPS_GENCAT_MN, "Mn" }, /* Mark, Non-Spacing */
- { CUPS_GENCAT_MC, "Mc" }, /* Mark, Spacing Combining */
- { CUPS_GENCAT_ME, "Me" }, /* Mark, Enclosing */
- { CUPS_GENCAT_ND, "Nd" }, /* Number, Decimal Digit */
- { CUPS_GENCAT_NL, "Nl" }, /* Number, Letter */
- { CUPS_GENCAT_NO, "No" }, /* Number, Other */
- { CUPS_GENCAT_PC, "Pc" }, /* Punctuation, Connector */
- { CUPS_GENCAT_PD, "Pd" }, /* Punctuation, Dash */
- { CUPS_GENCAT_PS, "Ps" }, /* Punctuation, Open (start) */
- { CUPS_GENCAT_PE, "Pe" }, /* Punctuation, Close (end) */
- { CUPS_GENCAT_PI, "Pi" }, /* Punctuation, Initial Quote */
- { CUPS_GENCAT_PF, "Pf" }, /* Punctuation, Final Quote */
- { CUPS_GENCAT_PO, "Po" }, /* Punctuation, Other */
- { CUPS_GENCAT_SM, "Sm" }, /* Symbol, Math */
- { CUPS_GENCAT_SC, "Sc" }, /* Symbol, Currency */
- { CUPS_GENCAT_SK, "Sk" }, /* Symbol, Modifier */
- { CUPS_GENCAT_SO, "So" }, /* Symbol, Other */
- { CUPS_GENCAT_ZS, "Zs" }, /* Separator, Space */
- { CUPS_GENCAT_ZL, "Zl" }, /* Separator, Line */
- { CUPS_GENCAT_ZP, "Zp" }, /* Separator, Paragraph */
- { CUPS_GENCAT_CC, "Cc" }, /* Other, Control */
- { CUPS_GENCAT_CF, "Cf" }, /* Other, Format */
- { CUPS_GENCAT_CS, "Cs" }, /* Other, Surrogate */
- { CUPS_GENCAT_CO, "Co" }, /* Other, Private Use */
- { CUPS_GENCAT_CN, "Cn" }, /* Other, Not Assigned */
+ { CUPS_GENCAT_LU, "Lu" }, /* Letter, Uppercase */
+ { CUPS_GENCAT_LL, "Ll" }, /* Letter, Lowercase */
+ { CUPS_GENCAT_LT, "Lt" }, /* Letter, Titlecase */
+ { CUPS_GENCAT_LM, "Lm" }, /* Letter, Modifier */
+ { CUPS_GENCAT_LO, "Lo" }, /* Letter, Other */
+ { CUPS_GENCAT_MN, "Mn" }, /* Mark, Non-Spacing */
+ { CUPS_GENCAT_MC, "Mc" }, /* Mark, Spacing Combining */
+ { CUPS_GENCAT_ME, "Me" }, /* Mark, Enclosing */
+ { CUPS_GENCAT_ND, "Nd" }, /* Number, Decimal Digit */
+ { CUPS_GENCAT_NL, "Nl" }, /* Number, Letter */
+ { CUPS_GENCAT_NO, "No" }, /* Number, Other */
+ { CUPS_GENCAT_PC, "Pc" }, /* Punctuation, Connector */
+ { CUPS_GENCAT_PD, "Pd" }, /* Punctuation, Dash */
+ { CUPS_GENCAT_PS, "Ps" }, /* Punctuation, Open (start) */
+ { CUPS_GENCAT_PE, "Pe" }, /* Punctuation, Close (end) */
+ { CUPS_GENCAT_PI, "Pi" }, /* Punctuation, Initial Quote */
+ { CUPS_GENCAT_PF, "Pf" }, /* Punctuation, Final Quote */
+ { CUPS_GENCAT_PO, "Po" }, /* Punctuation, Other */
+ { CUPS_GENCAT_SM, "Sm" }, /* Symbol, Math */
+ { CUPS_GENCAT_SC, "Sc" }, /* Symbol, Currency */
+ { CUPS_GENCAT_SK, "Sk" }, /* Symbol, Modifier */
+ { CUPS_GENCAT_SO, "So" }, /* Symbol, Other */
+ { CUPS_GENCAT_ZS, "Zs" }, /* Separator, Space */
+ { CUPS_GENCAT_ZL, "Zl" }, /* Separator, Line */
+ { CUPS_GENCAT_ZP, "Zp" }, /* Separator, Paragraph */
+ { CUPS_GENCAT_CC, "Cc" }, /* Other, Control */
+ { CUPS_GENCAT_CF, "Cf" }, /* Other, Format */
+ { CUPS_GENCAT_CS, "Cs" }, /* Other, Surrogate */
+ { CUPS_GENCAT_CO, "Co" }, /* Other, Private Use */
+ { CUPS_GENCAT_CN, "Cn" }, /* Other, Not Assigned */
{ 0, NULL }
};
-static const char *bidicat_index[] = /* Bidi Category Index */
+static const char * const bidicat_index[] =
+ /* Bidi Category Index */
{
- "L", /* Left-to-Right (Alpha, Syllabic, Ideographic) */
- "LRE",/* Left-to-Right Embedding (explicit) */
- "LRO",/* Left-to-Right Override (explicit) */
- "R", /* Right-to-Left (Hebrew alphabet and most punct) */
- "AL", /* Right-to-Left Arabic (Arabic, Thaana, Syriac) */
- "RLE",/* Right-to-Left Embedding (explicit) */
- "RLO",/* Right-to-Left Override (explicit) */
- "PDF",/* Pop Directional Format */
- "EN", /* Euro Number (Euro and East Arabic-Indic digits) */
- "ES", /* Euro Number Separator (Slash) */
- "ET", /* Euro Number Termintor (Plus, Minus, Degree, etc) */
- "AN", /* Arabic Number (Arabic-Indic digits, separators) */
- "CS", /* Common Number Separator (Colon, Comma, Dot, etc) */
- "NSM",/* Non-Spacing Mark (category Mn / Me in UCD) */
- "BN", /* Boundary Neutral (Formatting / Control chars) */
- "B", /* Paragraph Separator */
- "S", /* Segment Separator (Tab) */
- "WS", /* Whitespace Space (Space, Line Separator, etc) */
- "ON", /* Other Neutrals */
+ "L", /* Left-to-Right (Alpha, Syllabic, Ideographic) */
+ "LRE", /* Left-to-Right Embedding (explicit) */
+ "LRO", /* Left-to-Right Override (explicit) */
+ "R", /* Right-to-Left (Hebrew alphabet and most punct) */
+ "AL", /* Right-to-Left Arabic (Arabic, Thaana, Syriac) */
+ "RLE", /* Right-to-Left Embedding (explicit) */
+ "RLO", /* Right-to-Left Override (explicit) */
+ "PDF", /* Pop Directional Format */
+ "EN", /* Euro Number (Euro and East Arabic-Indic digits) */
+ "ES", /* Euro Number Separator (Slash) */
+ "ET", /* Euro Number Termintor (Plus, Minus, Degree, etc) */
+ "AN", /* Arabic Number (Arabic-Indic digits, separators) */
+ "CS", /* Common Number Separator (Colon, Comma, Dot, etc) */
+ "NSM", /* Non-Spacing Mark (category Mn / Me in UCD) */
+ "BN", /* Boundary Neutral (Formatting / Control chars) */
+ "B", /* Paragraph Separator */
+ "S", /* Segment Separator (Tab) */
+ "WS", /* Whitespace Space (Space, Line Separator, etc) */
+ "ON", /* Other Neutrals */
NULL
};
-typedef struct /**** Line Break Class Index Struct****/
+typedef struct /**** Line Break Class Index Struct****/
{
- cups_breakclass_t breakclass; /* Line Break Class Value */
- const char *str; /* Line Break Class String */
+ cups_breakclass_t breakclass; /* Line Break Class Value */
+ const char *str; /* Line Break Class String */
} break_t;
-static break_t break_index[] = /* Line Break Class Index */
+static const break_t break_index[] = /* Line Break Class Index */
{
- { CUPS_BREAK_AI, "AI" }, /* Ambiguous (Alphabetic or Ideograph) */
- { CUPS_BREAK_AL, "AL" }, /* Ordinary Alpha/Symbol Chars (XP) */
- { CUPS_BREAK_BA, "BA" }, /* Break Opportunity After Chars (A) */
- { CUPS_BREAK_BB, "BB" }, /* Break Opportunities Before Chars (B) */
- { CUPS_BREAK_B2, "B2" }, /* Break Opportunity Either (B/A/XP) */
- { CUPS_BREAK_BK, "BK" }, /* Mandatory Break (A) (norm) */
- { CUPS_BREAK_CB, "CB" }, /* Contingent Break (B/A) (norm) */
- { CUPS_BREAK_CL, "CL" }, /* Closing Punctuation (XB) */
- { CUPS_BREAK_CM, "CM" }, /* Attached/Combining (XB) (norm) */
- { CUPS_BREAK_CR, "CR" }, /* Carriage Return (A) (norm) */
- { CUPS_BREAK_EX, "EX" }, /* Exclamation / Interrogation (XB) */
- { CUPS_BREAK_GL, "GL" }, /* Non-breaking ("Glue") (XB/XA) (norm) */
- { CUPS_BREAK_HY, "HY" }, /* Hyphen (XA) */
- { CUPS_BREAK_ID, "ID" }, /* Ideographic (B/A) */
- { CUPS_BREAK_IN, "IN" }, /* Inseparable chars (XP) */
- { CUPS_BREAK_IS, "IS" }, /* Numeric Separator (Infix) (XB) */
- { CUPS_BREAK_LF, "LF" }, /* Line Feed (A) (norm) */
- { CUPS_BREAK_NS, "NS" }, /* Non-starters (XB) */
- { CUPS_BREAK_NU, "NU" }, /* Numeric (XP) */
- { CUPS_BREAK_OP, "OP" }, /* Opening Punctuation (XA) */
- { CUPS_BREAK_PO, "PO" }, /* Postfix (Numeric) (XB) */
- { CUPS_BREAK_PR, "PR" }, /* Prefix (Numeric) (XA) */
- { CUPS_BREAK_QU, "QU" }, /* Ambiguous Quotation (XB/XA) */
- { CUPS_BREAK_SA, "SA" }, /* Context Dependent (SE Asian) (P) */
- { CUPS_BREAK_SG, "SG" }, /* Surrogates (XP) (norm) */
- { CUPS_BREAK_SP, "SP" }, /* Space (A) (norm) */
- { CUPS_BREAK_SY, "SY" }, /* Symbols Allowing Break After (A) */
- { CUPS_BREAK_XX, "XX" }, /* Unknown (XP) */
- { CUPS_BREAK_ZW, "ZW" }, /* Zero Width Space (A) (norm) */
+ { CUPS_BREAK_AI, "AI" }, /* Ambiguous (Alphabetic or Ideograph) */
+ { CUPS_BREAK_AL, "AL" }, /* Ordinary Alpha/Symbol Chars (XP) */
+ { CUPS_BREAK_BA, "BA" }, /* Break Opportunity After Chars (A) */
+ { CUPS_BREAK_BB, "BB" }, /* Break Opportunities Before Chars (B) */
+ { CUPS_BREAK_B2, "B2" }, /* Break Opportunity Either (B/A/XP) */
+ { CUPS_BREAK_BK, "BK" }, /* Mandatory Break (A) (norm) */
+ { CUPS_BREAK_CB, "CB" }, /* Contingent Break (B/A) (norm) */
+ { CUPS_BREAK_CL, "CL" }, /* Closing Punctuation (XB) */
+ { CUPS_BREAK_CM, "CM" }, /* Attached/Combining (XB) (norm) */
+ { CUPS_BREAK_CR, "CR" }, /* Carriage Return (A) (norm) */
+ { CUPS_BREAK_EX, "EX" }, /* Exclamation / Interrogation (XB) */
+ { CUPS_BREAK_GL, "GL" }, /* Non-breaking ("Glue") (XB/XA) (norm) */
+ { CUPS_BREAK_HY, "HY" }, /* Hyphen (XA) */
+ { CUPS_BREAK_ID, "ID" }, /* Ideographic (B/A) */
+ { CUPS_BREAK_IN, "IN" }, /* Inseparable chars (XP) */
+ { CUPS_BREAK_IS, "IS" }, /* Numeric Separator (Infix) (XB) */
+ { CUPS_BREAK_LF, "LF" }, /* Line Feed (A) (norm) */
+ { CUPS_BREAK_NS, "NS" }, /* Non-starters (XB) */
+ { CUPS_BREAK_NU, "NU" }, /* Numeric (XP) */
+ { CUPS_BREAK_OP, "OP" }, /* Opening Punctuation (XA) */
+ { CUPS_BREAK_PO, "PO" }, /* Postfix (Numeric) (XB) */
+ { CUPS_BREAK_PR, "PR" }, /* Prefix (Numeric) (XA) */
+ { CUPS_BREAK_QU, "QU" }, /* Ambiguous Quotation (XB/XA) */
+ { CUPS_BREAK_SA, "SA" }, /* Context Dependent (SE Asian) (P) */
+ { CUPS_BREAK_SG, "SG" }, /* Surrogates (XP) (norm) */
+ { CUPS_BREAK_SP, "SP" }, /* Space (A) (norm) */
+ { CUPS_BREAK_SY, "SY" }, /* Symbols Allowing Break After (A) */
+ { CUPS_BREAK_XX, "XX" }, /* Unknown (XP) */
+ { CUPS_BREAK_ZW, "ZW" }, /* Zero Width Space (A) (norm) */
{ 0, NULL }
};
* Prototypes...
*/
+static int compare_breakchar(const void *k1, const void *k2);
+static int compare_combchar(const void *k1, const void *k2);
+static int compare_compose(const void *k1, const void *k2);
+static int compare_decompose(const void *k1, const void *k2);
+static int compare_foldchar(const void *k1, const void *k2);
+static int compare_propchar(const void *k1, const void *k2);
static int get_bidi_category(const cups_utf32_t ch);
-static int get_combining_class(const cups_utf32_t ch);
static int get_break_class(const cups_utf32_t ch);
+static int get_breakmap(void);
+static int get_combining_class(const cups_utf32_t ch);
+static int get_combmap(void);
+static int get_foldmap(const cups_folding_t fold);
static int get_general_category(const cups_utf32_t ch);
static int get_map_count(const char *filename);
static int get_normmap(const cups_normalize_t normalize);
-static int get_foldmap(const cups_folding_t fold);
static int get_propmap(void);
-static int get_combmap(void);
-static int get_breakmap(void);
-static int compare_compose(const void *k1, const void *k2);
-static int compare_decompose(const void *k1, const void *k2);
-static int compare_foldchar(const void *k1, const void *k2);
-static int compare_combchar(const void *k1, const void *k2);
-static int compare_propchar(const void *k1, const void *k2);
-static int compare_breakchar(const void *k1, const void *k2);
+
/*
* 'cupsNormalizeMapsGet()' - Get all normalization maps to cache.
*/
-int /* O - Zero or -1 on error */
+
+int /* O - Zero or -1 on error */
cupsNormalizeMapsGet(void)
{
- cups_normmap_t *nmap; /* Unicode Normalization Map */
- cups_foldmap_t *fmap; /* Unicode Case Folding Map */
+ cups_normmap_t *nmap; /* Unicode Normalization Map */
+ cups_foldmap_t *fmap; /* Unicode Case Folding Map */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* See if we already have normalization maps loaded...
*/
- if (normmap_cache)
+
+ if (cg->normmap_cache)
{
- for (nmap = normmap_cache; nmap != NULL; nmap = nmap->next)
+ for (nmap = cg->normmap_cache; nmap != NULL; nmap = nmap->next)
nmap->used ++;
- for (fmap = foldmap_cache; fmap != NULL; fmap = fmap->next)
+
+ for (fmap = cg->foldmap_cache; fmap != NULL; fmap = fmap->next)
fmap->used ++;
- if (combmap_cache)
- combmap_cache->used ++;
- if (propmap_cache)
- propmap_cache->used ++;
- if (breakmap_cache)
- breakmap_cache->used ++;
+
+ if (cg->combmap_cache)
+ cg->combmap_cache->used ++;
+
+ if (cg->propmap_cache)
+ cg->propmap_cache->used ++;
+
+ if (cg->breakmap_cache)
+ cg->breakmap_cache->used ++;
+
return (0);
}
/*
* Get normalization maps...
*/
+
if (get_normmap(CUPS_NORM_NFD) < 0)
return (-1);
+
if (get_normmap(CUPS_NORM_NFKD) < 0)
return (-1);
+
if (get_normmap(CUPS_NORM_NFC) < 0)
return (-1);
/*
* Get case folding, combining class, character property maps...
*/
+
if (get_foldmap(CUPS_FOLD_SIMPLE) < 0)
return (-1);
+
if (get_foldmap(CUPS_FOLD_FULL) < 0)
return (-1);
+
if (get_propmap() < 0)
return (-1);
+
if (get_combmap() < 0)
return (-1);
+
if (get_breakmap() < 0)
return (-1);
+
return (0);
}
+
/*
* 'cupsNormalizeMapsFree()' - Free all normalization maps in cache.
*
* This does not actually free; use 'cupsNormalizeMapsFlush()' for that.
*/
-int /* O - Zero or -1 on error */
+
+int /* O - Zero or -1 on error */
cupsNormalizeMapsFree(void)
{
- cups_normmap_t *nmap; /* Unicode Normalization Map */
- cups_foldmap_t *fmap; /* Unicode Case Folding Map */
+ cups_normmap_t *nmap; /* Unicode Normalization Map */
+ cups_foldmap_t *fmap; /* Unicode Case Folding Map */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* See if we already have normalization maps loaded...
*/
- if (normmap_cache == NULL)
+
+ if (cg->normmap_cache == NULL)
return (-1);
- for (nmap = normmap_cache; nmap != NULL; nmap = nmap->next)
+
+ for (nmap = cg->normmap_cache; nmap != NULL; nmap = nmap->next)
if (nmap->used > 0)
nmap->used --;
- for (fmap = foldmap_cache; fmap != NULL; fmap = fmap->next)
+
+ for (fmap = cg->foldmap_cache; fmap != NULL; fmap = fmap->next)
if (fmap->used > 0)
fmap->used --;
- if (propmap_cache && (propmap_cache->used > 0))
- propmap_cache->used --;
- if (combmap_cache && (combmap_cache->used > 0))
- combmap_cache->used --;
- if (breakmap_cache && (breakmap_cache->used > 0))
- breakmap_cache->used --;
+
+ if (cg->propmap_cache && (cg->propmap_cache->used > 0))
+ cg->propmap_cache->used --;
+
+ if (cg->combmap_cache && (cg->combmap_cache->used > 0))
+ cg->combmap_cache->used --;
+
+ if (cg->breakmap_cache && (cg->breakmap_cache->used > 0))
+ cg->breakmap_cache->used --;
+
return (0);
}
+
/*
* 'cupsNormalizeMapsFlush()' - Flush all normalization maps in cache.
*/
+
void
cupsNormalizeMapsFlush(void)
{
- cups_normmap_t *nmap; /* Unicode Normalization Map */
- cups_normmap_t *nextnorm; /* Next Unicode Normalization Map */
- cups_foldmap_t *fmap; /* Unicode Case Folding Map */
- cups_foldmap_t *nextfold; /* Next Unicode Case Folding Map */
+ cups_normmap_t *nmap; /* Unicode Normalization Map */
+ cups_normmap_t *nextnorm; /* Next Unicode Normalization Map */
+ cups_foldmap_t *fmap; /* Unicode Case Folding Map */
+ cups_foldmap_t *nextfold; /* Next Unicode Case Folding Map */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* Flush all normalization maps...
*/
- for (nmap = normmap_cache; nmap != NULL; nmap = nextnorm)
+
+ for (nmap = cg->normmap_cache; nmap != NULL; nmap = nextnorm)
{
free(nmap->uni2norm);
nextnorm = nmap->next;
free(nmap);
}
- normmap_cache = NULL;
- for (fmap = foldmap_cache; fmap != NULL; fmap = nextfold)
+
+ cg->normmap_cache = NULL;
+
+ for (fmap = cg->foldmap_cache; fmap != NULL; fmap = nextfold)
{
free(fmap->uni2fold);
nextfold = fmap->next;
free(fmap);
}
- foldmap_cache = NULL;
- if (propmap_cache)
+
+ cg->foldmap_cache = NULL;
+
+ if (cg->propmap_cache)
{
- free(propmap_cache->uni2prop);
- free(propmap_cache);
- propmap_cache = NULL;
+ free(cg->propmap_cache->uni2prop);
+ free(cg->propmap_cache);
+ cg->propmap_cache = NULL;
}
- if (combmap_cache)
+
+ if (cg->combmap_cache)
{
- free(combmap_cache->uni2comb);
- free(combmap_cache);
- combmap_cache = NULL;
+ free(cg->combmap_cache->uni2comb);
+ free(cg->combmap_cache);
+ cg->combmap_cache = NULL;
}
- if (breakmap_cache)
+
+ if (cg->breakmap_cache)
{
- free(breakmap_cache->uni2break);
- free(breakmap_cache);
- breakmap_cache = NULL;
+ free(cg->breakmap_cache->uni2break);
+ free(cg->breakmap_cache);
+ cg->breakmap_cache = NULL;
}
- return;
}
+
/*
* 'cupsUTF8Normalize()' - Normalize UTF-8 string.
*
* Note - Compatibility Normalization Forms (NFKD/NFKC) are
* unsafe for subsequent transcoding to legacy charsets
*/
-int /* O - Count or -1 on error */
-cupsUTF8Normalize(cups_utf8_t *dest, /* O - Target string */
- const cups_utf8_t *src, /* I - Source string */
- const int maxout, /* I - Max output */
- const cups_normalize_t normalize) /* I - Normalization */
+
+int /* O - Count or -1 on error */
+cupsUTF8Normalize(
+ cups_utf8_t *dest, /* O - Target string */
+ const cups_utf8_t *src, /* I - Source string */
+ const int maxout, /* I - Max output */
+ const cups_normalize_t normalize) /* I - Normalization */
{
- int len; /* String length */
- cups_utf32_t work1[CUPS_MAX_USTRING];
- /* First internal UCS-4 string */
- cups_utf32_t work2[CUPS_MAX_USTRING];
- /* Second internal UCS-4 string */
+ int len; /* String length */
+ cups_utf32_t work1[CUPS_MAX_USTRING];/* First internal UCS-4 string */
+ cups_utf32_t work2[CUPS_MAX_USTRING];/* Second internal UCS-4 string */
+
/*
* Check for valid arguments and clear output...
*/
- if ((dest == NULL)
- || (src == NULL)
- || (maxout < 1)
- || (maxout > CUPS_MAX_USTRING))
+
+ if (!dest || !src || maxout < 1 || maxout > CUPS_MAX_USTRING)
return (-1);
+
*dest = 0;
/*
* Convert input UTF-8 to internal UCS-4 (and insert BOM)...
*/
+
len = cupsUTF8ToUTF32(work1, src, CUPS_MAX_USTRING);
+
if (len < 0)
return (-1);
/*
* Normalize internal UCS-4 to second internal UCS-4...
*/
+
len = cupsUTF32Normalize(work2, work1, CUPS_MAX_USTRING, normalize);
+
if (len < 0)
return (-1);
/*
* Convert internal UCS-4 to output UTF-8 (and delete BOM)...
*/
+
len = cupsUTF32ToUTF8(dest, work2, maxout);
+
return (len);
}
+
/*
* 'cupsUTF32Normalize()' - Normalize UTF-32 string.
*
* Note - Compatibility Normalization Forms (NFKD/NFKC) are
* unsafe for subsequent transcoding to legacy charsets
*/
-int /* O - Count or -1 on error */
-cupsUTF32Normalize(cups_utf32_t *dest, /* O - Target string */
- const cups_utf32_t *src, /* I - Source string */
- const int maxout, /* I - Max output */
- const cups_normalize_t normalize) /* I - Normalization */
+
+int /* O - Count or -1 on error */
+cupsUTF32Normalize(
+ cups_utf32_t *dest, /* O - Target string */
+ const cups_utf32_t *src, /* I - Source string */
+ const int maxout, /* I - Max output */
+ const cups_normalize_t normalize) /* I - Normalization */
{
- int i; /* Looping variable */
- int result; /* Result Value */
- cups_ucs2_t *mp; /* Map char pointer */
- int pass; /* Pass count for each transform */
- int hit; /* Hit count from binary search */
- cups_utf32_t unichar1; /* Unicode character value */
- cups_utf32_t unichar2; /* Unicode character value */
- cups_combclass_t class1; /* First Combining Class */
- cups_combclass_t class2; /* Second Combining Class */
- int len; /* String length */
- cups_utf32_t work1[CUPS_MAX_USTRING];
- /* First internal UCS-4 string */
- cups_utf32_t work2[CUPS_MAX_USTRING];
- /* Second internal UCS-4 string */
- cups_utf32_t *p1; /* First UCS-4 string pointer */
- cups_utf32_t *p2; /* Second UCS-4 string pointer */
- cups_normmap_t *nmap; /* Unicode Normalization Map */
- cups_normalize_t decompose; /* Decomposition Type */
+ int i; /* Looping variable */
+ int result; /* Result Value */
+ cups_ucs2_t *mp; /* Map char pointer */
+ int pass; /* Pass count for each transform */
+ int hit; /* Hit count from binary search */
+ cups_utf32_t unichar1; /* Unicode character value */
+ cups_utf32_t unichar2; /* Unicode character value */
+ cups_combclass_t class1; /* First Combining Class */
+ cups_combclass_t class2; /* Second Combining Class */
+ int len; /* String length */
+ cups_utf32_t work1[CUPS_MAX_USTRING];
+ /* First internal UCS-4 string */
+ cups_utf32_t work2[CUPS_MAX_USTRING];
+ /* Second internal UCS-4 string */
+ cups_utf32_t *p1; /* First UCS-4 string pointer */
+ cups_utf32_t *p2; /* Second UCS-4 string pointer */
+ cups_normmap_t *nmap; /* Unicode Normalization Map */
+ cups_normalize_t decompose; /* Decomposition Type */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* Check for valid arguments and clear output...
*/
- if ((dest == NULL)
- || (src == NULL)
- || (maxout < 1)
- || (maxout > CUPS_MAX_USTRING))
+
+ if (!dest || !src || maxout < 1 || maxout > CUPS_MAX_USTRING)
return (-1);
+
*dest = 0;
+
result = cupsNormalizeMapsGet();
+
if (result < 0)
return (-1);
/*
* Find decomposition map...
*/
+
switch (normalize)
{
case CUPS_NORM_NFD:
case CUPS_NORM_NFC:
- decompose = CUPS_NORM_NFD;
- break;
+ decompose = CUPS_NORM_NFD;
+ break;
+
case CUPS_NORM_NFKD:
case CUPS_NORM_NFKC:
- decompose = CUPS_NORM_NFKD;
- break;
+ decompose = CUPS_NORM_NFKD;
+ break;
+
default:
- return (-1);
+ return (-1);
}
- for (nmap = normmap_cache; nmap != NULL; nmap = nmap->next)
+
+ for (nmap = cg->normmap_cache; nmap != NULL; nmap = nmap->next)
if (nmap->normalize == decompose)
break;
+
if (nmap == NULL)
return (-1);
/*
* Copy input to internal buffer...
*/
+
p1 = &work1[0];
+
for (i = 0; i < CUPS_MAX_USTRING; i ++)
{
if (*src == 0)
break;
+
*p1 ++ = *src ++;
}
+
*p1 = 0;
len = i;
/*
* Decompose until no further decomposition...
*/
+
for (pass = 0; pass < 20; pass ++)
{
p1 = &work1[0];
p2 = &work2[0];
+
for (hit = 0; *p1 != 0; p1 ++)
{
/*
* Check for decomposition defined...
*/
- mp = (cups_ucs2_t *) bsearch(p1,
- nmap->uni2norm,
- nmap->normcount,
- (sizeof(cups_ucs2_t) * 3),
- compare_decompose);
+
+ mp = (cups_ucs2_t *)bsearch(p1, nmap->uni2norm, nmap->normcount,
+ (sizeof(cups_ucs2_t) * 3), compare_decompose);
if (mp == NULL)
{
*p2 ++ = *p1;
/*
* Decompose input character to one or two output characters...
*/
+
hit ++;
mp ++;
*p2 ++ = (cups_utf32_t) *mp ++;
+
if (*mp != 0)
*p2 ++ = (cups_utf32_t) *mp;
}
+
*p2 = 0;
- len = (int) (p2 - &work2[0]);
+ len = (int)(p2 - &work2[0]);
/*
* Check for decomposition finished...
/*
* Canonical reorder until no further reordering...
*/
+
for (pass = 0; pass < 20; pass ++)
{
p1 = &work1[0];
+
for (hit = 0; *p1 != 0; p1 ++)
{
/*
* Check for combining characters to reorder...
*/
+
unichar1 = *p1;
unichar2 = *(p1 + 1);
+
if (unichar2 == 0)
break;
+
class1 = get_combining_class(unichar1);
class2 = get_combining_class(unichar2);
+
if ((class1 < 0) || (class2 < 0))
return (-1);
+
if ((class1 == 0) || (class2 == 0))
continue;
+
if (class1 <= class2)
continue;
/*
* Swap two combining characters...
*/
- {
- *p1 = unichar2;
- p1 ++;
- *p1 = unichar1;
- hit ++;
- }
+
+ *p1 = unichar2;
+ p1 ++;
+ *p1 = unichar1;
+ hit ++;
}
+
if (hit == 0)
break;
}
/*
* Check for decomposition only...
*/
- if ((normalize == CUPS_NORM_NFD) || (normalize == CUPS_NORM_NFKD))
+
+ if (normalize == CUPS_NORM_NFD || normalize == CUPS_NORM_NFKD)
{
- memcpy (dest, work1, sizeof(cups_utf32_t) * (len + 1));
+ memcpy(dest, work1, sizeof(cups_utf32_t) * (len + 1));
return (len);
}
/*
* Find composition map...
*/
- for (nmap = normmap_cache; nmap != NULL; nmap = nmap->next)
+
+ for (nmap = cg->normmap_cache; nmap != NULL; nmap = nmap->next)
if (nmap->normalize == CUPS_NORM_NFC)
break;
+
if (nmap == NULL)
return (-1);
/*
* Compose until no further composition...
*/
+
for (pass = 0; pass < 20; pass ++)
{
p1 = &work1[0];
p2 = &work2[0];
+
for (hit = 0; *p1 != 0; p1 ++)
{
/*
* Check for composition defined...
*/
+
unichar1 = *p1;
unichar2 = *(p1 + 1);
+
if (unichar2 == 0)
{
*p2 ++ = unichar1;
break;
}
- mp = (cups_ucs2_t *) bsearch(p1,
- nmap->uni2norm,
- nmap->normcount,
- (sizeof(cups_ucs2_t) * 3),
- compare_compose);
+
+ mp = (cups_ucs2_t *)bsearch(p1, nmap->uni2norm, nmap->normcount,
+ (sizeof(cups_ucs2_t) * 3), compare_compose);
if (mp == NULL)
{
*p2 ++ = *p1;
/*
* Compose two input characters to one output character...
*/
+
hit ++;
mp += 2;
*p2 ++ = (cups_utf32_t) *mp;
p1 ++;
}
+
*p2 = 0;
len = (int) (p2 - &work2[0]);
/*
* Check for composition finished...
*/
+
if (hit == 0)
break;
+
memcpy (work1, work2, sizeof(cups_utf32_t) * (len + 1));
}
+
memcpy (dest, work1, sizeof(cups_utf32_t) * (len + 1));
+
cupsNormalizeMapsFree();
+
return (len);
}
+
/*
* 'cupsUTF8CaseFold()' - Case fold UTF-8 string.
*
* Note - Case folding output is
* unsafe for subsequent transcoding to legacy charsets
*/
-int /* O - Count or -1 on error */
-cupsUTF8CaseFold(cups_utf8_t *dest, /* O - Target string */
- const cups_utf8_t *src, /* I - Source string */
- const int maxout, /* I - Max output */
- const cups_folding_t fold) /* I - Fold Mode */
+
+int /* O - Count or -1 on error */
+cupsUTF8CaseFold(
+ cups_utf8_t *dest, /* O - Target string */
+ const cups_utf8_t *src, /* I - Source string */
+ const int maxout, /* I - Max output */
+ const cups_folding_t fold) /* I - Fold Mode */
{
- int len; /* String length */
- cups_utf32_t work1[CUPS_MAX_USTRING];
- /* First internal UCS-4 string */
- cups_utf32_t work2[CUPS_MAX_USTRING];
- /* Second internal UCS-4 string */
+ int len; /* String length */
+ cups_utf32_t work1[CUPS_MAX_USTRING];/* First internal UCS-4 string */
+ cups_utf32_t work2[CUPS_MAX_USTRING];/* Second internal UCS-4 string */
+
/*
* Check for valid arguments and clear output...
*/
- if ((dest == NULL)
- || (src == NULL)
- || (maxout < 1)
- || (maxout > CUPS_MAX_USTRING))
+
+ if (!dest || !src || maxout < 1 || maxout > CUPS_MAX_USTRING)
return (-1);
+
*dest = 0;
- if ((fold != CUPS_FOLD_SIMPLE) && (fold != CUPS_FOLD_FULL))
+
+ if (fold != CUPS_FOLD_SIMPLE && fold != CUPS_FOLD_FULL)
return (-1);
/*
* Convert input UTF-8 to internal UCS-4 (and insert BOM)...
*/
+
len = cupsUTF8ToUTF32(work1, src, CUPS_MAX_USTRING);
+
if (len < 0)
return (-1);
/*
* Case Fold internal UCS-4 to second internal UCS-4...
*/
+
len = cupsUTF32CaseFold(work2, work1, CUPS_MAX_USTRING, fold);
+
if (len < 0)
return (-1);
/*
* Convert internal UCS-4 to output UTF-8 (and delete BOM)...
*/
+
len = cupsUTF32ToUTF8(dest, work2, maxout);
+
return (len);
}
+
/*
* 'cupsUTF32CaseFold()' - Case fold UTF-32 string.
*
* Note - Case folding output is
* unsafe for subsequent transcoding to legacy charsets
*/
-int /* O - Count or -1 on error */
-cupsUTF32CaseFold(cups_utf32_t *dest, /* O - Target string */
- const cups_utf32_t *src, /* I - Source string */
- const int maxout, /* I - Max output */
- const cups_folding_t fold) /* I - Fold Mode */
+
+int /* O - Count or -1 on error */
+cupsUTF32CaseFold(
+ cups_utf32_t *dest, /* O - Target string */
+ const cups_utf32_t *src, /* I - Source string */
+ const int maxout, /* I - Max output */
+ const cups_folding_t fold) /* I - Fold Mode */
{
- cups_utf32_t *start = dest; /* Start of destination string */
- int i; /* Looping variable */
- int result; /* Result Value */
- cups_ucs2_t *mp; /* Map char pointer */
- cups_foldmap_t *fmap; /* Unicode Case Folding Map */
+ cups_utf32_t *start = dest; /* Start of destination string */
+ int i; /* Looping variable */
+ int result; /* Result Value */
+ cups_ucs2_t *mp; /* Map char pointer */
+ cups_foldmap_t *fmap; /* Unicode Case Folding Map */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* Check for valid arguments and clear output...
*/
- if ((dest == NULL)
- || (src == NULL)
- || (maxout < 1)
- || (maxout > CUPS_MAX_USTRING))
+
+ if (!dest || !src || maxout < 1 || maxout > CUPS_MAX_USTRING)
return (-1);
+
*dest = 0;
- if ((fold != CUPS_FOLD_SIMPLE) && (fold != CUPS_FOLD_FULL))
+
+ if (fold != CUPS_FOLD_SIMPLE && fold != CUPS_FOLD_FULL)
return (-1);
/*
* Find case folding map...
*/
+
result = cupsNormalizeMapsGet();
+
if (result < 0)
return (-1);
- for (fmap = foldmap_cache; fmap != NULL; fmap = fmap->next)
+
+ for (fmap = cg->foldmap_cache; fmap != NULL; fmap = fmap->next)
if (fmap->fold == fold)
break;
+
if (fmap == NULL)
return (-1);
/*
* Case fold input string to output string...
*/
+
for (i = 0; i < (maxout - 1); i ++, src ++)
{
/*
* Check for case folding defined...
*/
- mp = (cups_ucs2_t *) bsearch(src,
- fmap->uni2fold,
- fmap->foldcount,
- (sizeof(cups_ucs2_t) * 4),
- compare_foldchar);
+
+ mp = (cups_ucs2_t *)bsearch(src, fmap->uni2fold, fmap->foldcount,
+ (sizeof(cups_ucs2_t) * 4), compare_foldchar);
if (mp == NULL)
{
*dest ++ = *src;
/*
* Case fold input character to one or two output characters...
*/
+
mp ++;
*dest ++ = (cups_utf32_t) *mp ++;
- if ((*mp != 0) && (fold == CUPS_FOLD_FULL))
+
+ if (*mp != 0 && fold == CUPS_FOLD_FULL)
{
i ++;
- if (i >= (maxout -1))
+ if (i >= (maxout - 1))
break;
+
*dest ++ = (cups_utf32_t) *mp;
}
}
+
*dest = 0;
+
cupsNormalizeMapsFree();
+
return (dest - start);
}
+
/*
* 'cupsUTF8CompareCaseless()' - Compare case folded UTF-8 strings.
*/
-int /* O - Difference of strings */
-cupsUTF8CompareCaseless(const cups_utf8_t *s1,
- /* I - String1 */
- const cups_utf8_t *s2) /* I - String2 */
+
+int /* O - Difference of strings */
+cupsUTF8CompareCaseless(
+ const cups_utf8_t *s1, /* I - String1 */
+ const cups_utf8_t *s2) /* I - String2 */
{
- int difference; /* Difference of two strings */
- int len; /* String length */
- cups_utf32_t work1[CUPS_MAX_USTRING];
- /* First internal UCS-4 string */
- cups_utf32_t work2[CUPS_MAX_USTRING];
- /* Second internal UCS-4 string */
+ int difference; /* Difference of two strings */
+ int len; /* String length */
+ cups_utf32_t work1[CUPS_MAX_USTRING];/* First internal UCS-4 string */
+ cups_utf32_t work2[CUPS_MAX_USTRING];/* Second internal UCS-4 string */
+
/*
* Check for valid arguments...
*/
- if ((s1 == NULL)
- || (s2 == NULL))
+
+ if (!s1 || !s2)
return (-1);
/*
* Convert input UTF-8 to internal UCS-4 (and insert BOM)...
*/
+
len = cupsUTF8ToUTF32(work1, s1, CUPS_MAX_USTRING);
+
if (len < 0)
return (-1);
+
len = cupsUTF8ToUTF32(work2, s2, CUPS_MAX_USTRING);
+
if (len < 0)
return (-1);
/*
* Compare first internal UCS-4 to second internal UCS-4...
*/
+
difference = cupsUTF32CompareCaseless(work1, work2);
+
return (difference);
}
+
/*
* 'cupsUTF32CompareCaseless()' - Compare case folded UTF-32 strings.
*/
-int /* O - Difference of strings */
-cupsUTF32CompareCaseless(const cups_utf32_t *s1,
- /* I - String1 */
- const cups_utf32_t *s2) /* I - String2 */
+
+int /* O - Difference of strings */
+cupsUTF32CompareCaseless(
+ const cups_utf32_t *s1, /* I - String1 */
+ const cups_utf32_t *s2) /* I - String2 */
{
- int difference; /* Difference of two strings */
- int len; /* String length */
- cups_folding_t fold = CUPS_FOLD_FULL;
- /* Case folding mode */
- cups_utf32_t fold1[CUPS_MAX_USTRING];
- /* First UCS-4 folded string */
- cups_utf32_t fold2[CUPS_MAX_USTRING];
- /* Second UCS-4 folded string */
- cups_utf32_t *p1; /* First UCS-4 string pointer */
- cups_utf32_t *p2; /* Second UCS-4 string pointer */
+ int difference; /* Difference of two strings */
+ int len; /* String length */
+ cups_folding_t fold = CUPS_FOLD_FULL;
+ /* Case folding mode */
+ cups_utf32_t fold1[CUPS_MAX_USTRING];
+ /* First UCS-4 folded string */
+ cups_utf32_t fold2[CUPS_MAX_USTRING];
+ /* Second UCS-4 folded string */
+ cups_utf32_t *p1; /* First UCS-4 string pointer */
+ cups_utf32_t *p2; /* Second UCS-4 string pointer */
+
/*
* Check for valid arguments...
*/
- if ((s1 == NULL)
- || (s2 == NULL))
+
+ if (!s1 || !s2)
return (-1);
/*
* Case Fold input UTF-32 strings to internal UCS-4 strings...
*/
+
len = cupsUTF32CaseFold(fold1, s1, CUPS_MAX_USTRING, fold);
+
if (len < 0)
return (-1);
+
len = cupsUTF32CaseFold(fold2, s2, CUPS_MAX_USTRING, fold);
+
if (len < 0)
return (-1);
/*
* Compare first internal UCS-4 to second internal UCS-4...
*/
+
p1 = &fold1[0];
p2 = &fold2[0];
+
for (;; p1 ++, p2 ++)
{
difference = (int) (*p1 - *p2);
+
if (difference != 0)
break;
+
if ((*p1 == 0) && (*p2 == 0))
break;
}
+
return (difference);
}
+
/*
* 'cupsUTF8CompareIdentifier()' - Compare folded NFKC UTF-8 strings.
*/
-int
-cupsUTF8CompareIdentifier(const cups_utf8_t *s1,
- /* I - String1 */
- const cups_utf8_t *s2) /* I - String2 */
+
+int /* O - Result of comparison */
+cupsUTF8CompareIdentifier(
+ const cups_utf8_t *s1, /* I - String1 */
+ const cups_utf8_t *s2) /* I - String2 */
{
- int difference; /* Difference of two strings */
- int len; /* String length */
- cups_utf32_t work1[CUPS_MAX_USTRING];
- /* First internal UCS-4 string */
- cups_utf32_t work2[CUPS_MAX_USTRING];
- /* Second internal UCS-4 string */
+ int difference; /* Difference of two strings */
+ int len; /* String length */
+ cups_utf32_t work1[CUPS_MAX_USTRING];/* First internal UCS-4 string */
+ cups_utf32_t work2[CUPS_MAX_USTRING];/* Second internal UCS-4 string */
+
/*
* Check for valid arguments...
*/
- if ((s1 == NULL)
- || (s2 == NULL))
+
+ if (!s1 || !s2)
return (-1);
/*
* Convert input UTF-8 to internal UCS-4 (and insert BOM)...
*/
+
len = cupsUTF8ToUTF32(work1, s1, CUPS_MAX_USTRING);
+
if (len < 0)
return (-1);
+
len = cupsUTF8ToUTF32(work2, s2, CUPS_MAX_USTRING);
+
if (len < 0)
return (-1);
/*
* Compare first internal UCS-4 to second internal UCS-4...
*/
+
difference = cupsUTF32CompareIdentifier(work1, work2);
+
return (difference);
}
+
/*
* 'cupsUTF32CompareIdentifier()' - Compare folded NFKC UTF-32 strings.
*/
-int
-cupsUTF32CompareIdentifier(const cups_utf32_t *s1,
- /* I - String1 */
- const cups_utf32_t *s2) /* I - String2 */
+
+int /* O - Result of comparison */
+cupsUTF32CompareIdentifier(
+ const cups_utf32_t *s1, /* I - String1 */
+ const cups_utf32_t *s2) /* I - String2 */
{
- int difference; /* Difference of two strings */
- int len; /* String length */
- cups_folding_t fold = CUPS_FOLD_FULL;
- /* Case folding mode */
- cups_utf32_t fold1[CUPS_MAX_USTRING];
- /* First UCS-4 folded string */
- cups_utf32_t fold2[CUPS_MAX_USTRING];
- /* Second UCS-4 folded string */
- cups_normalize_t normalize = CUPS_NORM_NFKC;
- /* Normalization form */
- cups_utf32_t norm1[CUPS_MAX_USTRING];
- /* First UCS-4 normalized string */
- cups_utf32_t norm2[CUPS_MAX_USTRING];
- /* Second UCS-4 normalized string */
- cups_utf32_t *p1; /* First UCS-4 string pointer */
- cups_utf32_t *p2; /* Second UCS-4 string pointer */
+ int difference; /* Difference of two strings */
+ int len; /* String length */
+ cups_folding_t fold = CUPS_FOLD_FULL;
+ /* Case folding mode */
+ cups_utf32_t fold1[CUPS_MAX_USTRING];
+ /* First UCS-4 folded string */
+ cups_utf32_t fold2[CUPS_MAX_USTRING];
+ /* Second UCS-4 folded string */
+ cups_normalize_t normalize = CUPS_NORM_NFKC;
+ /* Normalization form */
+ cups_utf32_t norm1[CUPS_MAX_USTRING];
+ /* First UCS-4 normalized string */
+ cups_utf32_t norm2[CUPS_MAX_USTRING];
+ /* Second UCS-4 normalized string */
+ cups_utf32_t *p1; /* First UCS-4 string pointer */
+ cups_utf32_t *p2; /* Second UCS-4 string pointer */
+
/*
* Check for valid arguments...
*/
- if ((s1 == NULL)
- || (s2 == NULL))
+
+ if (!s1 || !s2)
return (-1);
/*
* Case Fold input UTF-32 strings to internal UCS-4 strings...
*/
+
len = cupsUTF32CaseFold(fold1, s1, CUPS_MAX_USTRING, fold);
+
if (len < 0)
return (-1);
+
len = cupsUTF32CaseFold(fold2, s2, CUPS_MAX_USTRING, fold);
+
if (len < 0)
return (-1);
/*
* Normalize internal UCS-4 strings to NFKC...
*/
+
len = cupsUTF32Normalize(norm1, fold1, CUPS_MAX_USTRING, normalize);
+
if (len < 0)
return (-1);
+
len = cupsUTF32Normalize(norm2, fold2, CUPS_MAX_USTRING, normalize);
+
if (len < 0)
return (-1);
/*
* Compare first internal UCS-4 to second internal UCS-4...
*/
+
p1 = &norm1[0];
p2 = &norm2[0];
+
for (;; p1 ++, p2 ++)
{
difference = (int) (*p1 - *p2);
+
if (difference != 0)
break;
+
if ((*p1 == 0) && (*p2 == 0))
break;
}
+
return (difference);
}
+
/*
* 'cupsUTF32CharacterProperty()' - Get UTF-32 character property.
*/
-int
-cupsUTF32CharacterProperty(const cups_utf32_t ch,
- /* I - Source char */
- const cups_property_t prop) /* I - Char Property */
+
+int /* O - Result of comparison */
+cupsUTF32CharacterProperty(
+ const cups_utf32_t ch, /* I - Source char */
+ const cups_property_t prop) /* I - Char Property */
{
- int result; /* Result Value */
+ int result; /* Result Value */
+
/*
* Check for valid arguments...
*/
+
if (ch == 0)
return (-1);
/*
* Find character property...
*/
+
switch (prop)
{
case CUPS_PROP_GENERAL_CATEGORY:
- result = (get_general_category(ch));
- break;
+ result = (get_general_category(ch));
+ break;
+
case CUPS_PROP_BIDI_CATEGORY:
- result = (get_bidi_category(ch));
- break;
+ result = (get_bidi_category(ch));
+ break;
+
case CUPS_PROP_COMBINING_CLASS:
- result = (get_combining_class(ch));
- break;
+ result = (get_combining_class(ch));
+ break;
case CUPS_PROP_BREAK_CLASS:
- result = (get_break_class(ch));
- break;
+ result = (get_break_class(ch));
+ break;
+
default:
- return (-1);
+ return (-1);
}
+
return (result);
}
+
/*
* 'get_general_category()' - Get UTF-32 Character General Category.
*/
-static int /* O - Class or -1 on error */
-get_general_category(const cups_utf32_t ch)
- /* I - Source char */
+
+static int /* O - Class or -1 on error */
+get_general_category(
+ const cups_utf32_t ch) /* I - Source char */
{
- int result; /* Result Value */
- cups_gencat_t gencat; /* General Category Value */
- cups_propmap_t *pmap; /* Unicode Property Map */
- cups_prop_t *uni2prop; /* Unicode Char -> Properties */
+ int result; /* Result Value */
+ cups_gencat_t gencat; /* General Category Value */
+ cups_propmap_t *pmap; /* Unicode Property Map */
+ cups_prop_t *uni2prop; /* Unicode Char -> Properties */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* Check for valid argument...
*/
+
if (ch == 0)
return (-1);
/*
* Find property map...
*/
+
result = cupsNormalizeMapsGet();
+
if (result < 0)
return (-1);
- pmap = propmap_cache;
+
+ pmap = cg->propmap_cache;
+
if (pmap == NULL)
return (-1);
/*
* Find character in map...
*/
- uni2prop = (cups_prop_t *) bsearch(&ch,
- pmap->uni2prop,
- pmap->propcount,
- (sizeof(cups_prop_t)),
- compare_propchar);
+
+ uni2prop = (cups_prop_t *)bsearch(&ch, pmap->uni2prop, pmap->propcount,
+ (sizeof(cups_prop_t)), compare_propchar);
+
cupsNormalizeMapsFree();
+
if (uni2prop == NULL)
gencat = CUPS_GENCAT_CN; /* Other, Not Assigned */
else
- gencat = (cups_gencat_t) uni2prop->gencat;
- result = (int) gencat;
+ gencat = (cups_gencat_t)uni2prop->gencat;
+
+ result = (int)gencat;
+
return (result);
}
+
/*
* 'get_bidi_category()' - Get UTF-32 Character Bidi Category.
*/
-static int /* O - Class or -1 on error */
-get_bidi_category(const cups_utf32_t ch)
- /* I - Source char */
+
+static int /* O - Class or -1 on error */
+get_bidi_category(const cups_utf32_t ch)/* I - Source char */
{
- int result; /* Result Value */
- cups_bidicat_t bidicat; /* Bidi Category Value */
- cups_propmap_t *pmap; /* Unicode Property Map */
- cups_prop_t *uni2prop; /* Unicode Char -> Properties */
+ int result; /* Result Value */
+ cups_bidicat_t bidicat; /* Bidi Category Value */
+ cups_propmap_t *pmap; /* Unicode Property Map */
+ cups_prop_t *uni2prop; /* Unicode Char -> Properties */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* Check for valid argument...
*/
+
if (ch == 0)
return (-1);
/*
* Find property map...
*/
+
result = cupsNormalizeMapsGet();
+
if (result < 0)
return (-1);
- pmap = propmap_cache;
+
+ pmap = cg->propmap_cache;
+
if (pmap == NULL)
return (-1);
/*
* Find character in map...
*/
- uni2prop = (cups_prop_t *) bsearch(&ch,
- pmap->uni2prop,
- pmap->propcount,
- (sizeof(cups_prop_t)),
- compare_propchar);
+
+ uni2prop = (cups_prop_t *)bsearch(&ch, pmap->uni2prop, pmap->propcount,
+ (sizeof(cups_prop_t)), compare_propchar);
+
cupsNormalizeMapsFree();
+
if (uni2prop == NULL)
bidicat = CUPS_BIDI_ON; /* Other Neutral */
else
- bidicat = (cups_bidicat_t) uni2prop->bidicat;
- result = (int) bidicat;
+ bidicat = (cups_bidicat_t)uni2prop->bidicat;
+
+ result = (int)bidicat;
+
return (result);
}
*
* Note - Zero is non-combining (base character)
*/
-static int /* O - Class or -1 on error */
-get_combining_class(const cups_utf32_t ch)
- /* I - Source char */
+
+static int /* O - Class or -1 on error */
+get_combining_class(
+ const cups_utf32_t ch) /* I - Source char */
{
- int result; /* Result Value */
- cups_combmap_t *cmap; /* Unicode Combining Class Map */
- cups_combclass_t combclass; /* Unicode Combining Class */
- cups_comb_t *uni2comb; /* Unicode Char -> Combining Class */
+ int result; /* Result Value */
+ cups_combmap_t *cmap; /* Unicode Combining Class Map */
+ cups_combclass_t combclass; /* Unicode Combining Class */
+ cups_comb_t *uni2comb; /* Unicode Char -> Combining Class */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* Check for valid argument...
*/
+
if (ch == 0)
return (-1);
/*
* Find combining class map...
*/
+
result = cupsNormalizeMapsGet();
+
if (result < 0)
return (-1);
- cmap = combmap_cache;
+
+ cmap = cg->combmap_cache;
+
if (cmap == NULL)
return (-1);
/*
* Find combining character in map...
*/
- uni2comb = (cups_comb_t *) bsearch(&ch,
- cmap->uni2comb,
- cmap->combcount,
- (sizeof(cups_comb_t)),
- compare_combchar);
+
+ uni2comb = (cups_comb_t *)bsearch(&ch, cmap->uni2comb, cmap->combcount,
+ (sizeof(cups_comb_t)), compare_combchar);
+
cupsNormalizeMapsFree();
+
if (uni2comb == NULL)
combclass = 0;
else
- combclass = (cups_combclass_t) uni2comb->combclass;
- result = (int) combclass;
+ combclass = (cups_combclass_t)uni2comb->combclass;
+
+ result = (int)combclass;
+
return (result);
}
+
/*
* 'get_break_class()' - Get UTF-32 Character Line Break Class.
*/
-static int /* O - Class or -1 on error */
-get_break_class(const cups_utf32_t ch) /* I - Source char */
+
+static int /* O - Class or -1 on error */
+get_break_class(const cups_utf32_t ch) /* I - Source char */
{
- int result; /* Result Value */
- cups_breakmap_t *bmap; /* Unicode Line Break Class Map */
- cups_breakclass_t breakclass; /* Unicode Line Break Class */
- cups_ucs2_t *uni2break; /* Unicode -> Line Break Class */
+ int result; /* Result Value */
+ cups_breakmap_t *bmap; /* Unicode Line Break Class Map */
+ cups_breakclass_t breakclass; /* Unicode Line Break Class */
+ cups_ucs2_t *uni2break; /* Unicode -> Line Break Class */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* Check for valid argument...
*/
+
if (ch == 0)
return (-1);
/*
* Find line break class map...
*/
+
result = cupsNormalizeMapsGet();
+
if (result < 0)
return (-1);
- bmap = breakmap_cache;
+
+ bmap = cg->breakmap_cache;
+
if (bmap == NULL)
return (-1);
/*
* Find line break character in map...
*/
- uni2break = (cups_ucs2_t *) bsearch(&ch,
- bmap->uni2break,
- bmap->breakcount,
- (sizeof(cups_ucs2_t) * 3),
- compare_breakchar);
+
+ uni2break = (cups_ucs2_t *)bsearch(&ch, bmap->uni2break, bmap->breakcount,
+ (sizeof(cups_ucs2_t) * 3),
+ compare_breakchar);
+
cupsNormalizeMapsFree();
+
if (uni2break == NULL)
breakclass = CUPS_BREAK_AI;
else
- breakclass = (cups_breakclass_t) *(uni2break + 2);
- result = (int) breakclass;
+ breakclass = (cups_breakclass_t)*(uni2break + 2);
+
+ result = (int)breakclass;
+
return (result);
}
+
/*
* 'get_map_count()' - Count lines in a map file.
*/
-static int /* O - Count or -1 on error */
-get_map_count(const char *filename) /* I - Map Filename */
+
+static int /* O - Count or -1 on error */
+get_map_count(const char *filename) /* I - Map Filename */
{
- int i; /* Looping variable */
- FILE *fp; /* Map input file pointer */
- char *s; /* Line parsing pointer */
- char line[256]; /* Line from input map file */
- cups_utf32_t unichar; /* Unicode character value */
+ int i; /* Looping variable */
+ cups_file_t *fp; /* Map input file pointer */
+ char *s; /* Line parsing pointer */
+ char line[256]; /* Line from input map file */
+ cups_utf32_t unichar; /* Unicode character value */
+
/*
* Open map input file...
*/
- if ((filename == NULL) || (*filename == '\0'))
+
+ if (!filename || !*filename)
return (-1);
- fp = fopen(filename, "r");
+
+ fp = cupsFileOpen(filename, "r");
if (fp == NULL)
return (-1);
/*
* Count lines in map input file...
*/
+
for (i = 0; i < 50000;)
{
- s = fgets(&line[0], sizeof(line), fp);
+ s = cupsFileGets(fp, line, sizeof(line));
if (s == NULL)
break;
if ((*s == '#') || (*s == '\n') || (*s == '\0'))
/*
* Close file and return map count (non-comment line count)...
*/
- fclose(fp);
+
+ cupsFileClose(fp);
+
return (i);
}
+
/*
* 'get_normmap()' - Get Unicode normalization map to cache.
*/
-static int /* O - Zero or -1 on error */
-get_normmap(const cups_normalize_t normalize)
- /* I - Normalization Form */
+
+static int /* O - Zero or -1 on error */
+get_normmap(
+ const cups_normalize_t normalize) /* I - Normalization Form */
{
- int i; /* Looping variable */
- cups_utf32_t unichar1; /* Unicode character value */
- cups_utf32_t unichar2; /* Unicode character value */
- cups_utf32_t unichar3; /* Unicode character value */
- cups_normmap_t *nmap; /* Unicode Normalization Map */
- int normcount; /* Count of Unicode Source Chars */
- cups_ucs2_t *uni2norm; /* Unicode Char -> Normalization */
- char *datadir; /* CUPS_DATADIR environment variable */
- char *mapname; /* Normalization map name */
- char filename[256]; /* Filename for charset map file */
- FILE *fp; /* Normalization map file pointer */
- char *s; /* Line parsing pointer */
- char line[256]; /* Line from input map file */
+ int i; /* Looping variable */
+ cups_utf32_t unichar1; /* Unicode character value */
+ cups_utf32_t unichar2; /* Unicode character value */
+ cups_utf32_t unichar3; /* Unicode character value */
+ cups_normmap_t *nmap; /* Unicode Normalization Map */
+ int normcount; /* Count of Unicode Source Chars */
+ cups_ucs2_t *uni2norm; /* Unicode Char -> Normalization */
+ char *datadir; /* CUPS_DATADIR environment variable */
+ char *mapname; /* Normalization map name */
+ char filename[1024]; /* Filename for charset map file */
+ cups_file_t *fp; /* Normalization map file pointer */
+ char *s; /* Line parsing pointer */
+ char line[256]; /* Line from input map file */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* See if we already have this normalization map loaded...
*/
- for (nmap = normmap_cache; nmap != NULL; nmap = nmap->next)
+
+ for (nmap = cg->normmap_cache; nmap != NULL; nmap = nmap->next)
if (nmap->normalize == normalize)
return (0);
/*
* Get the data directory and mapping name...
*/
+
if ((datadir = getenv("CUPS_DATADIR")) == NULL)
datadir = CUPS_DATADIR;
+
switch (normalize)
{
case CUPS_NORM_NFD: /* Canonical Decomposition */
- mapname = "uni-nfd.txt";
- break;
+ mapname = "uni-nfd.txt";
+ break;
+
case CUPS_NORM_NFKD: /* Compatibility Decomposition */
- mapname = "uni-nfkd.txt";
- break;
+ mapname = "uni-nfkd.txt";
+ break;
+
case CUPS_NORM_NFC: /* Canonical Composition */
- mapname = "uni-nfc.txt";
- break;
+ mapname = "uni-nfc.txt";
+ break;
+
case CUPS_NORM_NFKC: /* no such map file... */
default:
- return (-1);
+ return (-1);
}
/*
* Open normalization map input file...
*/
+
snprintf(filename, sizeof(filename), "%s/charmaps/%s",
datadir, mapname);
if ((normcount = get_map_count(filename)) <= 0)
return (-1);
- fp = fopen(filename, "r");
+
+ fp = cupsFileOpen(filename, "r");
if (fp == NULL)
return (-1);
/*
* Allocate memory for normalization map and add to cache...
*/
- nmap = (cups_normmap_t *)
- calloc(1, sizeof(cups_normmap_t));
+
+ nmap = (cups_normmap_t *)calloc(1, sizeof(cups_normmap_t));
if (nmap == NULL)
{
- fclose(fp);
+ cupsFileClose(fp);
return (-1);
}
- uni2norm = (cups_ucs2_t *)
- calloc(1, sizeof(cups_ucs2_t) * 3 * normcount);
+
+ uni2norm = (cups_ucs2_t *)calloc(1, sizeof(cups_ucs2_t) * 3 * normcount);
if (uni2norm == NULL)
{
- fclose(fp);
+ free(nmap);
+ cupsFileClose(fp);
return (-1);
}
- nmap->next = normmap_cache;
- normmap_cache = nmap;
+ nmap->next = cg->normmap_cache;
+ cg->normmap_cache = nmap;
nmap->used ++;
nmap->normalize = normalize;
nmap->normcount = normcount;
*/
for (i = 0; i < normcount; )
{
- s = fgets(&line[0], sizeof(line), fp);
+ s = cupsFileGets(fp, line, sizeof(line));
if (s == NULL)
break;
if ((*s == '#') || (*s == '\n') || (*s == '\0'))
}
if (i < normcount)
nmap->normcount = i;
- fclose(fp);
+ cupsFileClose(fp);
return (0);
}
+
/*
* 'get_foldmap()' - Get Unicode case folding map to cache.
*/
-static int /* O - Zero or -1 on error */
-get_foldmap(const cups_folding_t fold) /* I - Case folding type */
+
+static int /* O - Zero or -1 on error */
+get_foldmap(const cups_folding_t fold) /* I - Case folding type */
{
- int i; /* Looping variable */
- cups_utf32_t unichar1; /* Unicode character value */
- cups_utf32_t unichar2; /* Unicode character value */
- cups_utf32_t unichar3; /* Unicode character value */
- cups_utf32_t unichar4; /* Unicode character value */
- cups_foldmap_t *fmap; /* Unicode Case Folding Map */
- int foldcount; /* Count of Unicode Source Chars */
- cups_ucs2_t *uni2fold; /* Unicode -> Folded Char(s) */
- char *datadir; /* CUPS_DATADIR env variable */
- char *mapname; /* Case Folding map name */
- char filename[256]; /* Filename for charset map file */
- FILE *fp; /* Case Folding map file pointer */
- char *s; /* Line parsing pointer */
- char line[256]; /* Line from input map file */
+ int i; /* Looping variable */
+ cups_utf32_t unichar1; /* Unicode character value */
+ cups_utf32_t unichar2; /* Unicode character value */
+ cups_utf32_t unichar3; /* Unicode character value */
+ cups_utf32_t unichar4; /* Unicode character value */
+ cups_foldmap_t *fmap; /* Unicode Case Folding Map */
+ int foldcount; /* Count of Unicode Source Chars */
+ cups_ucs2_t *uni2fold; /* Unicode -> Folded Char(s) */
+ char *datadir; /* CUPS_DATADIR env variable */
+ char *mapname; /* Case Folding map name */
+ char filename[1024]; /* Filename for charset map file */
+ cups_file_t *fp; /* Case Folding map file pointer */
+ char *s; /* Line parsing pointer */
+ char line[256]; /* Line from input map file */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* See if we already have this case folding map loaded...
*/
- for (fmap = foldmap_cache; fmap != NULL; fmap = fmap->next)
+
+ for (fmap = cg->foldmap_cache; fmap != NULL; fmap = fmap->next)
if (fmap->fold == fold)
return (0);
/*
* Get the data directory and mapping name...
*/
+
if ((datadir = getenv("CUPS_DATADIR")) == NULL)
datadir = CUPS_DATADIR;
+
switch (fold)
{
case CUPS_FOLD_SIMPLE: /* Simple case folding */
- mapname = "uni-fold.txt";
- break;
+ mapname = "uni-fold.txt";
+ break;
case CUPS_FOLD_FULL: /* Full case folding */
- mapname = "uni-full.txt";
- break;
+ mapname = "uni-full.txt";
+ break;
default:
- return (-1);
+ return (-1);
}
/*
* Open case folding map input file...
*/
+
snprintf(filename, sizeof(filename), "%s/charmaps/%s",
datadir, mapname);
if ((foldcount = get_map_count(filename)) <= 0)
return (-1);
- fp = fopen(filename, "r");
+ fp = cupsFileOpen(filename, "r");
if (fp == NULL)
return (-1);
/*
* Allocate memory for case folding map and add to cache...
*/
- fmap = (cups_foldmap_t *)
- calloc(1, sizeof(cups_foldmap_t));
+ fmap = (cups_foldmap_t *)calloc(1, sizeof(cups_foldmap_t));
if (fmap == NULL)
{
- fclose(fp);
+ cupsFileClose(fp);
return (-1);
}
- uni2fold = (cups_ucs2_t *)
- calloc(1, sizeof(cups_ucs2_t) * 4 * foldcount);
+ uni2fold = (cups_ucs2_t *)calloc(1, sizeof(cups_ucs2_t) * 4 * foldcount);
if (uni2fold == NULL)
{
- fclose(fp);
+ free(fmap);
+ cupsFileClose(fp);
return (-1);
}
- fmap->next = foldmap_cache;
- foldmap_cache = fmap;
+ fmap->next = cg->foldmap_cache;
+ cg->foldmap_cache = fmap;
fmap->used ++;
fmap->fold = fold;
fmap->foldcount = foldcount;
/*
* Save case folding map into memory for later use...
*/
+
for (i = 0; i < foldcount; )
{
- s = fgets(&line[0], sizeof(line), fp);
+ s = cupsFileGets(fp, line, sizeof(line));
if (s == NULL)
break;
if ((*s == '#') || (*s == '\n') || (*s == '\0'))
}
if (i < foldcount)
fmap->foldcount = i;
- fclose(fp);
+ cupsFileClose(fp);
return (0);
}
/*
* 'get_propmap()' - Get Unicode character property map to cache.
*/
-static int /* O - Zero or -1 on error */
+
+static int /* O - Zero or -1 on error */
get_propmap(void)
{
- int i, j; /* Looping variables */
- int len; /* String length */
- cups_utf32_t unichar; /* Unicode character value */
- cups_gencat_t gencat; /* General Category Value */
- cups_bidicat_t bidicat; /* Bidi Category Value */
- cups_propmap_t *pmap; /* Unicode Char Property Map */
- int propcount; /* Count of Unicode Source Chars */
- cups_prop_t *uni2prop; /* Unicode Char -> Properties */
- char *datadir; /* CUPS_DATADIR environment variable */
- char *mapname; /* Char Property map name */
- char filename[256]; /* Filename for charset map file */
- FILE *fp; /* Char Property map file pointer */
- char *s; /* Line parsing pointer */
- char line[256]; /* Line from input map file */
+ int i, j; /* Looping variables */
+ int len; /* String length */
+ cups_utf32_t unichar; /* Unicode character value */
+ cups_gencat_t gencat; /* General Category Value */
+ cups_bidicat_t bidicat; /* Bidi Category Value */
+ cups_propmap_t *pmap; /* Unicode Char Property Map */
+ int propcount; /* Count of Unicode Source Chars */
+ cups_prop_t *uni2prop; /* Unicode Char -> Properties */
+ char *datadir; /* CUPS_DATADIR environment variable */
+ char *mapname; /* Char Property map name */
+ char filename[1024]; /* Filename for charset map file */
+ cups_file_t *fp; /* Char Property map file pointer */
+ char *s; /* Line parsing pointer */
+ char line[256]; /* Line from input map file */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* See if we already have this char properties map loaded...
*/
- if ((pmap = propmap_cache) != NULL)
+
+ if ((pmap = cg->propmap_cache) != NULL)
return (0);
/*
* Get the data directory and mapping name...
*/
+
if ((datadir = getenv("CUPS_DATADIR")) == NULL)
datadir = CUPS_DATADIR;
+
mapname = "uni-prop.txt";
/*
datadir, mapname);
if ((propcount = get_map_count(filename)) <= 0)
return (-1);
- fp = fopen(filename, "r");
+ fp = cupsFileOpen(filename, "r");
if (fp == NULL)
return (-1);
/*
* Allocate memory for char properties map and add to cache...
*/
- pmap = (cups_propmap_t *)
- calloc(1, sizeof(cups_propmap_t));
+ pmap = (cups_propmap_t *)calloc(1, sizeof(cups_propmap_t));
if (pmap == NULL)
{
- fclose(fp);
+ cupsFileClose(fp);
return (-1);
}
- uni2prop = (cups_prop_t *)
- calloc(1, sizeof(cups_prop_t) * propcount);
+ uni2prop = (cups_prop_t *)calloc(1, sizeof(cups_prop_t) * propcount);
if (uni2prop == NULL)
{
- fclose(fp);
+ free(pmap);
+ cupsFileClose(fp);
return (-1);
}
- propmap_cache = pmap;
+ cg->propmap_cache = pmap;
pmap->used ++;
pmap->propcount = propcount;
pmap->uni2prop = uni2prop;
*/
for (i = 0; i < propcount; )
{
- s = fgets(&line[0], sizeof(line), fp);
+ s = cupsFileGets(fp, line, sizeof(line));
if (s == NULL)
break;
if (strlen(s) > 0)
}
if (i < propcount)
pmap->propcount = i;
- fclose(fp);
+ cupsFileClose(fp);
return (0);
}
+
/*
* 'get_combmap()' - Get Unicode combining class map to cache.
*/
-static int /* O - Zero or -1 on error */
+
+static int /* O - Zero or -1 on error */
get_combmap(void)
{
- int i; /* Looping variable */
- cups_utf32_t unichar; /* Unicode character value */
- int combclass; /* Unicode char combining class */
- cups_combmap_t *cmap; /* Unicode Comb Class Map */
- int combcount; /* Count of Unicode Source Chars */
- cups_comb_t *uni2comb; /* Unicode Char -> Combining Class */
- char *datadir; /* CUPS_DATADIR environment variable */
- char *mapname; /* Comb Class map name */
- char filename[256]; /* Filename for charset map file */
- FILE *fp; /* Comb Class map file pointer */
- char *s; /* Line parsing pointer */
- char line[256]; /* Line from input map file */
+ int i; /* Looping variable */
+ cups_utf32_t unichar; /* Unicode character value */
+ int combclass; /* Unicode char combining class */
+ cups_combmap_t *cmap; /* Unicode Comb Class Map */
+ int combcount; /* Count of Unicode Source Chars */
+ cups_comb_t *uni2comb; /* Unicode Char -> Combining Class */
+ char *datadir; /* CUPS_DATADIR environment variable */
+ char *mapname; /* Comb Class map name */
+ char filename[1024]; /* Filename for charset map file */
+ cups_file_t *fp; /* Comb Class map file pointer */
+ char *s; /* Line parsing pointer */
+ char line[256]; /* Line from input map file */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* See if we already have this combining class map loaded...
*/
- if ((cmap = combmap_cache) != NULL)
+
+ if ((cmap = cg->combmap_cache) != NULL)
return (0);
/*
* Get the data directory and mapping name...
*/
+
if ((datadir = getenv("CUPS_DATADIR")) == NULL)
datadir = CUPS_DATADIR;
+
mapname = "uni-comb.txt";
/*
* Open combining class map input file...
*/
+
snprintf(filename, sizeof(filename), "%s/charmaps/%s",
datadir, mapname);
if ((combcount = get_map_count(filename)) <= 0)
return (-1);
- fp = fopen(filename, "r");
+ fp = cupsFileOpen(filename, "r");
if (fp == NULL)
return (-1);
/*
* Allocate memory for combining class map and add to cache...
*/
- cmap = (cups_combmap_t *)
- calloc(1, sizeof(cups_combmap_t));
+
+ cmap = (cups_combmap_t *)calloc(1, sizeof(cups_combmap_t));
if (cmap == NULL)
{
- fclose(fp);
+ cupsFileClose(fp);
return (-1);
}
- uni2comb = (cups_comb_t *)
- calloc(1, sizeof(cups_comb_t) * combcount);
+
+ uni2comb = (cups_comb_t *)calloc(1, sizeof(cups_comb_t) * combcount);
if (uni2comb == NULL)
{
- fclose(fp);
+ free(cmap);
+ cupsFileClose(fp);
return (-1);
}
- combmap_cache = cmap;
+ cg->combmap_cache = cmap;
cmap->used ++;
cmap->combcount = combcount;
cmap->uni2comb = uni2comb;
*/
for (i = 0; i < combcount; )
{
- s = fgets(&line[0], sizeof(line), fp);
+ s = cupsFileGets(fp, line, sizeof(line));
if (s == NULL)
break;
if ((*s == '#') || (*s == '\n') || (*s == '\0'))
}
if (i < combcount)
cmap->combcount = i;
- fclose(fp);
+ cupsFileClose(fp);
return (0);
}
+
/*
* 'get_breakmap()' - Get Unicode line break class map to cache.
*/
-static int /* O - Zero or -1 on error */
+
+static int /* O - Zero or -1 on error */
get_breakmap(void)
{
- int i, j; /* Looping variables */
- int len; /* String length */
- cups_utf32_t unichar1; /* Unicode character value */
- cups_utf32_t unichar2; /* Unicode character value */
- cups_breakclass_t breakclass; /* Unicode char line break class */
- cups_breakmap_t *bmap; /* Unicode Line Break Class Map */
- int breakcount; /* Count of Unicode Source Chars */
- cups_ucs2_t *uni2break; /* Unicode -> Line Break Class */
- char *datadir; /* CUPS_DATADIR environment variable */
- char *mapname; /* Comb Class map name */
- char filename[256]; /* Filename for charset map file */
- FILE *fp; /* Comb Class map file pointer */
- char *s; /* Line parsing pointer */
- char line[256]; /* Line from input map file */
+ int i, j; /* Looping variables */
+ int len; /* String length */
+ cups_utf32_t unichar1; /* Unicode character value */
+ cups_utf32_t unichar2; /* Unicode character value */
+ cups_breakclass_t breakclass; /* Unicode char line break class */
+ cups_breakmap_t *bmap; /* Unicode Line Break Class Map */
+ int breakcount; /* Count of Unicode Source Chars */
+ cups_ucs2_t *uni2break; /* Unicode -> Line Break Class */
+ char *datadir; /* CUPS_DATADIR environment variable */
+ char *mapname; /* Comb Class map name */
+ char filename[1024]; /* Filename for charset map file */
+ cups_file_t *fp; /* Comb Class map file pointer */
+ char *s; /* Line parsing pointer */
+ char line[256]; /* Line from input map file */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
+
/*
* See if we already have this line break class map loaded...
*/
- if ((bmap = breakmap_cache) != NULL)
+
+ if ((bmap = cg->breakmap_cache) != NULL)
return (0);
/*
* Get the data directory and mapping name...
*/
+
if ((datadir = getenv("CUPS_DATADIR")) == NULL)
datadir = CUPS_DATADIR;
+
mapname = "uni-line.txt";
/*
* Open line break class map input file...
*/
+
snprintf(filename, sizeof(filename), "%s/charmaps/%s",
datadir, mapname);
if ((breakcount = get_map_count(filename)) <= 0)
return (-1);
- fp = fopen(filename, "r");
+ fp = cupsFileOpen(filename, "r");
if (fp == NULL)
return (-1);
/*
* Allocate memory for line break class map and add to cache...
*/
- bmap = (cups_breakmap_t *)
- calloc(1, sizeof(cups_breakmap_t));
+
+ bmap = (cups_breakmap_t *)calloc(1, sizeof(cups_breakmap_t));
if (bmap == NULL)
{
- fclose(fp);
+ cupsFileClose(fp);
return (-1);
}
- uni2break = (cups_ucs2_t *)
- calloc(1, sizeof(cups_ucs2_t) * 3 * breakcount);
+
+ uni2break = (cups_ucs2_t *)calloc(1, sizeof(cups_ucs2_t) * 3 * breakcount);
if (uni2break == NULL)
{
- fclose(fp);
+ free(bmap);
+ cupsFileClose(fp);
return (-1);
}
- breakmap_cache = bmap;
+ cg->breakmap_cache = bmap;
bmap->used ++;
bmap->breakcount = breakcount;
bmap->uni2break = uni2break;
*/
for (i = 0; i < breakcount; )
{
- s = fgets(&line[0], sizeof(line), fp);
+ s = cupsFileGets(fp, line, sizeof(line));
if (s == NULL)
break;
if (strlen(s) > 0)
}
if (i < breakcount)
bmap->breakcount = i;
- fclose(fp);
+ cupsFileClose(fp);
return (0);
}
+
/*
* 'compare_compose()' - Compare key for compose match.
*
* Note - This function cannot be easily modified for 32-bit Unicode.
*/
-static int
-compare_compose(const void *k1, /* I - Key char */
- const void *k2) /* I - Map char */
+
+static int /* O - Result of comparison */
+compare_compose(const void *k1, /* I - Key char */
+ const void *k2) /* I - Map char */
{
- cups_utf32_t *kp = (cups_utf32_t *) k1;
- /* Key char pointer */
- cups_ucs2_t *mp = (cups_ucs2_t *) k2;
- /* Map char pointer */
- unsigned long key; /* Pair of key characters */
- unsigned long map; /* Pair of map characters */
- int result; /* Result Value */
+ cups_utf32_t *kp = (cups_utf32_t *)k1;
+ /* Key char pointer */
+ cups_ucs2_t *mp = (cups_ucs2_t *)k2;/* Map char pointer */
+ unsigned long key; /* Pair of key characters */
+ unsigned long map; /* Pair of map characters */
+ int result; /* Result Value */
+
key = (*kp << 16);
key |= *(kp + 1);
map = (unsigned long) (*mp << 16);
map |= (unsigned long) *(mp + 1);
+
if (key >= map)
result = (int) (key - map);
else
result = -1 * ((int) (map - key));
+
return (result);
}
+
/*
* 'compare_decompose()' - Compare key for decompose match.
*/
-static int
-compare_decompose(const void *k1, /* I - Key char */
- const void *k2) /* I - Map char */
+
+static int /* O - Result of comparison */
+compare_decompose(const void *k1, /* I - Key char */
+ const void *k2) /* I - Map char */
{
- cups_utf32_t *kp = (cups_utf32_t *) k1;
- /* Key char pointer */
- cups_ucs2_t *mp = (cups_ucs2_t *) k2;
- /* Map char pointer */
- cups_ucs2_t ch; /* Key char as UCS-2 */
- int result; /* Result Value */
+ cups_utf32_t *kp = (cups_utf32_t *)k1;
+ /* Key char pointer */
+ cups_ucs2_t *mp = (cups_ucs2_t *)k2;/* Map char pointer */
+ cups_ucs2_t ch; /* Key char as UCS-2 */
+ int result; /* Result Value */
+
ch = (cups_ucs2_t) *kp;
+
if (ch >= *mp)
result = (int) (ch - *mp);
else
result = -1 * ((int) (*mp - ch));
+
return (result);
}
+
/*
* 'compare_foldchar()' - Compare key for case fold match.
*/
-static int
-compare_foldchar(const void *k1, /* I - Key char */
- const void *k2) /* I - Map char */
+
+static int /* O - Result of comparison */
+compare_foldchar(const void *k1, /* I - Key char */
+ const void *k2) /* I - Map char */
{
- cups_utf32_t *kp = (cups_utf32_t *) k1;
- /* Key char pointer */
- cups_ucs2_t *mp = (cups_ucs2_t *) k2;
- /* Map char pointer */
- cups_ucs2_t ch; /* Key char as UCS-2 */
- int result; /* Result Value */
+ cups_utf32_t *kp = (cups_utf32_t *)k1;
+ /* Key char pointer */
+ cups_ucs2_t *mp = (cups_ucs2_t *)k2;/* Map char pointer */
+ cups_ucs2_t ch; /* Key char as UCS-2 */
+ int result; /* Result Value */
+
ch = (cups_ucs2_t) *kp;
+
if (ch >= *mp)
result = (int) (ch - *mp);
else
result = -1 * ((int) (*mp - ch));
+
return (result);
}
+
/*
* 'compare_combchar()' - Compare key for combining char match.
*/
-static int
-compare_combchar(const void *k1, /* I - Key char */
- const void *k2) /* I - Map char */
+
+static int /* O - Result of comparison */
+compare_combchar(const void *k1, /* I - Key char */
+ const void *k2) /* I - Map char */
{
- cups_utf32_t *kp = (cups_utf32_t *) k1;
- /* Key char pointer */
- cups_comb_t *cp = (cups_comb_t *) k2;
- /* Combining map row pointer */
- cups_ucs2_t ch; /* Key char as UCS-2 */
- int result; /* Result Value */
+ cups_utf32_t *kp = (cups_utf32_t *)k1;
+ /* Key char pointer */
+ cups_comb_t *cp = (cups_comb_t *)k2;/* Combining map row pointer */
+ cups_ucs2_t ch; /* Key char as UCS-2 */
+ int result; /* Result Value */
+
ch = (cups_ucs2_t) *kp;
+
if (ch >= cp->ch)
result = (int) (ch - cp->ch);
else
result = -1 * ((int) (cp->ch - ch));
+
return (result);
}
+
/*
* 'compare_breakchar()' - Compare key for line break char match.
*/
-static int
-compare_breakchar(const void *k1, /* I - Key char */
- const void *k2) /* I - Map char */
+
+static int /* O - Result of comparison */
+compare_breakchar(const void *k1, /* I - Key char */
+ const void *k2) /* I - Map char */
{
- cups_utf32_t *kp = (cups_utf32_t *) k1;
- /* Key char pointer */
- cups_ucs2_t *mp = (cups_ucs2_t *) k2;
- /* Map char pointer */
- cups_ucs2_t ch; /* Key char as UCS-2 */
- int result; /* Result Value */
+ cups_utf32_t *kp = (cups_utf32_t *)k1;
+ /* Key char pointer */
+ cups_ucs2_t *mp = (cups_ucs2_t *)k2;/* Map char pointer */
+ cups_ucs2_t ch; /* Key char as UCS-2 */
+ int result; /* Result Value */
+
ch = (cups_ucs2_t) *kp;
+
if (ch < *mp)
result = -1 * (int) (*mp - ch);
else if (ch > *(mp + 1))
result = (int) (ch - *(mp + 1));
else
result = 0;
+
return (result);
}
+
/*
* 'compare_propchar()' - Compare key for property char match.
*/
-static int
-compare_propchar(const void *k1, /* I - Key char */
- const void *k2) /* I - Map char */
+
+static int /* O - Result of comparison */
+compare_propchar(const void *k1, /* I - Key char */
+ const void *k2) /* I - Map char */
{
- cups_utf32_t *kp = (cups_utf32_t *) k1;
- /* Key char pointer */
- cups_prop_t *pp = (cups_prop_t *) k2;
- /* Property map row pointer */
- cups_ucs2_t ch; /* Key char as UCS-2 */
- int result; /* Result Value */
+ cups_utf32_t *kp = (cups_utf32_t *)k1;
+ /* Key char pointer */
+ cups_prop_t *pp = (cups_prop_t *)k2;/* Property map row pointer */
+ cups_ucs2_t ch; /* Key char as UCS-2 */
+ int result; /* Result Value */
+
ch = (cups_ucs2_t) *kp;
+
if (ch >= pp->ch)
result = (int) (ch - pp->ch);
else
result = -1 * ((int) (pp->ch - ch));
+
return (result);
}
+
/*
* End of "$Id$"
*/
* Include necessary headers.
*/
-#include "ppd.h"
-#include <stdlib.h>
-#include <ctype.h>
-#include "string.h"
-#include "language.h"
+#include "globals.h"
#include "debug.h"
+#include <stdlib.h>
/*
#define PPD_STRING 8 /* Line contained a string or code */
-/*
- * Local globals...
- */
-
-static ppd_status_t ppd_status = PPD_OK;
- /* Status of last ppdOpen*() */
-static int ppd_line = 0; /* Current line number */
-static ppd_conform_t ppd_conform = PPD_CONFORM_RELAXED;
- /* Level of conformance required */
-
-
/*
* Local functions...
*/
const char *text);
#endif /* 0 */
static ppd_group_t *ppd_get_group(ppd_file_t *ppd, const char *name,
- const char *text);
+ const char *text, cups_globals_t *cg);
static ppd_option_t *ppd_get_option(ppd_group_t *group, const char *name);
static int ppd_read(cups_file_t *fp, char *keyword, char *option,
- char *text, char **string, int ignoreblank);
+ char *text, char **string, int ignoreblank,
+ cups_globals_t *cg);
/*
ppd_status_t /* O - Status code */
ppdLastError(int *line) /* O - Line number */
{
+ cups_globals_t *cg = _cupsGlobals();
+ /* Global data */
+
+
if (line)
- *line = ppd_line;
+ *line = cg->ppd_line;
- return (ppd_status);
+ return (cg->ppd_status);
}
char **filter; /* Pointer to filter */
cups_lang_t *language; /* Default language */
int ui_keyword; /* Is this line a UI keyword? */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Global data */
static const char * const ui_keywords[] =
{
/* Boolean keywords */
* Default to "OK" status...
*/
- ppd_status = PPD_OK;
- ppd_line = 0;
+ cg->ppd_status = PPD_OK;
+ cg->ppd_line = 0;
/*
* Range check input...
if (fp == NULL)
{
- ppd_status = PPD_NULL_FILE;
+ cg->ppd_status = PPD_NULL_FILE;
return (NULL);
}
* Grab the first line and make sure it reads '*PPD-Adobe: "major.minor"'...
*/
- mask = ppd_read(fp, keyword, name, text, &string, 0);
+ mask = ppd_read(fp, keyword, name, text, &string, 0, cg);
DEBUG_printf(("mask=%x, keyword=\"%s\"...\n", mask, keyword));
* Either this is not a PPD file, or it is not a 4.x PPD file.
*/
- if (ppd_status == PPD_OK)
- ppd_status = PPD_MISSING_PPDADOBE4;
+ if (cg->ppd_status == PPD_OK)
+ cg->ppd_status = PPD_MISSING_PPDADOBE4;
ppd_free(string);
if ((ppd = calloc(1, sizeof(ppd_file_t))) == NULL)
{
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
return (NULL);
}
choice = NULL;
ui_keyword = 0;
- while ((mask = ppd_read(fp, keyword, name, text, &string, 1)) != 0)
+ while ((mask = ppd_read(fp, keyword, name, text, &string, 1, cg)) != 0)
{
#ifdef DEBUG
printf("mask = %x, keyword = \"%s\"", mask, keyword);
* Need a string value!
*/
- ppd_status = PPD_MISSING_VALUE;
+ cg->ppd_status = PPD_MISSING_VALUE;
goto error;
}
strcmp(keyword, "OutputMode") && strcmp(keyword, "OutputOrder") &&
strcmp(keyword, "PageSize") && strcmp(keyword, "PageRegion"))
group = ppd_get_group(ppd, "Extra",
- cupsLangString(language, CUPS_MSG_EXTRA));
+ cupsLangString(language, CUPS_MSG_EXTRA), cg);
else
group = ppd_get_group(ppd, "General",
- cupsLangString(language, CUPS_MSG_GENERAL));
+ cupsLangString(language, CUPS_MSG_GENERAL), cg);
if (group == NULL)
goto error;
if (option == NULL)
{
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
{
ppd_free(filter);
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
if (tempfonts == NULL)
{
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
if ((gtemp = ppd_get_group(ppd, "General",
cupsLangString(language,
- CUPS_MSG_GENERAL))) == NULL)
+ CUPS_MSG_GENERAL), cg)) == NULL)
{
DEBUG_puts("Unable to get general group!");
{
DEBUG_puts("Unable to get PageSize option!");
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
{
DEBUG_puts("Unable to add Custom choice!");
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
{
DEBUG_puts("Unable to find PageSize option!");
- ppd_status = PPD_INTERNAL_ERROR;
+ cg->ppd_status = PPD_INTERNAL_ERROR;
goto error;
}
{
DEBUG_puts("Unable to find Custom choice!");
- ppd_status = PPD_INTERNAL_ERROR;
+ cg->ppd_status = PPD_INTERNAL_ERROR;
goto error;
}
strlen(string) + 1);
if (temp == NULL)
{
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
* Don't allow nesting of options...
*/
- if (option && ppd_conform == PPD_CONFORM_STRICT)
+ if (option && cg->ppd_conform == PPD_CONFORM_STRICT)
{
- ppd_status = PPD_NESTED_OPEN_UI;
+ cg->ppd_status = PPD_NESTED_OPEN_UI;
goto error;
}
strcmp(name, "OutputMode") && strcmp(name, "OutputOrder") &&
strcmp(name, "PageSize") && strcmp(name, "PageRegion"))
group = ppd_get_group(ppd, "Extra",
- cupsLangString(language, CUPS_MSG_EXTRA));
+ cupsLangString(language, CUPS_MSG_EXTRA), cg);
else
group = ppd_get_group(ppd, "General",
- cupsLangString(language, CUPS_MSG_GENERAL));
+ cupsLangString(language, CUPS_MSG_GENERAL), cg);
if (group == NULL)
goto error;
if (option == NULL)
{
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
option->ui = PPD_UI_BOOLEAN;
else if (string && strcmp(string, "PickOne") == 0)
option->ui = PPD_UI_PICKONE;
- else if (ppd_conform == PPD_CONFORM_STRICT)
+ else if (cg->ppd_conform == PPD_CONFORM_STRICT)
{
- ppd_status = PPD_BAD_OPEN_UI;
+ cg->ppd_status = PPD_BAD_OPEN_UI;
goto error;
}
* Don't allow nesting of options...
*/
- if (option && ppd_conform == PPD_CONFORM_STRICT)
+ if (option && cg->ppd_conform == PPD_CONFORM_STRICT)
{
- ppd_status = PPD_NESTED_OPEN_UI;
+ cg->ppd_status = PPD_NESTED_OPEN_UI;
goto error;
}
* Find the JCL group, and add if needed...
*/
- group = ppd_get_group(ppd, "JCL", "JCL");
+ group = ppd_get_group(ppd, "JCL", "JCL", cg);
if (group == NULL)
goto error;
if (option == NULL)
{
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
option->ui = PPD_UI_PICKONE;
else
{
- ppd_status = PPD_BAD_OPEN_UI;
+ cg->ppd_status = PPD_BAD_OPEN_UI;
goto error;
}
if (group != NULL)
{
- ppd_status = PPD_NESTED_OPEN_GROUP;
+ cg->ppd_status = PPD_NESTED_OPEN_GROUP;
goto error;
}
if (!string)
{
- ppd_status = PPD_BAD_OPEN_GROUP;
+ cg->ppd_status = PPD_BAD_OPEN_GROUP;
goto error;
}
* Find/add the group...
*/
- group = ppd_get_group(ppd, string, sptr);
+ group = ppd_get_group(ppd, string, sptr, cg);
if (group == NULL)
goto error;
{
if (sscanf(string, "%f%40s%40s", &order, name, keyword) != 3)
{
- ppd_status = PPD_BAD_ORDER_DEPENDENCY;
+ cg->ppd_status = PPD_BAD_ORDER_DEPENDENCY;
goto error;
}
if (constraint == NULL)
{
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
{
case 0 : /* Error */
case 1 : /* Error */
- ppd_status = PPD_BAD_UI_CONSTRAINTS;
+ cg->ppd_status = PPD_BAD_UI_CONSTRAINTS;
goto error;
case 2 : /* Two options... */
* Unable to add or find size!
*/
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
* Unable to add or find size!
*/
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
goto error;
}
printf("Premature EOF at %lu...\n", (unsigned long)ftell(fp));
#endif /* DEBUG */
- if (ppd_status != PPD_OK)
+ if (cg->ppd_status != PPD_OK)
{
/*
* Had an error reading the PPD file, cannot continue!
ppd_file_t * /* O - PPD file record */
ppdOpenFd(int fd) /* I - File to read from */
{
- FILE *fp; /* File pointer */
- ppd_file_t *ppd; /* PPD file record */
+ FILE *fp; /* File pointer */
+ ppd_file_t *ppd; /* PPD file record */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Global data */
/*
* Set the line number to 0...
*/
- ppd_line = 0;
+ cg->ppd_line = 0;
/*
* Range check input...
if (fd < 0)
{
- ppd_status = PPD_NULL_FILE;
+ cg->ppd_status = PPD_NULL_FILE;
return (NULL);
}
}
else
{
- ppd_status = PPD_FILE_OPEN_ERROR;
+ cg->ppd_status = PPD_FILE_OPEN_ERROR;
ppd = NULL;
}
ppd_file_t * /* O - PPD file record */
ppdOpenFile(const char *filename) /* I - File to read from */
{
- FILE *fp; /* File pointer */
- ppd_file_t *ppd; /* PPD file record */
+ cups_file_t *fp; /* File pointer */
+ ppd_file_t *ppd; /* PPD file record */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Global data */
/*
* Set the line number to 0...
*/
- ppd_line = 0;
+ cg->ppd_line = 0;
/*
* Range check input...
if (filename == NULL)
{
- ppd_status = PPD_NULL_FILE;
+ cg->ppd_status = PPD_NULL_FILE;
return (NULL);
}
* Try to open the file and parse it...
*/
- if ((fp = fopen(filename, "r")) != NULL)
+ if ((fp = cupsFileOpen(filename, "r")) != NULL)
{
- ppd = ppdOpen(fp);
+ ppd = ppdOpen2(fp);
- fclose(fp);
+ cupsFileClose(fp);
}
else
{
- ppd_status = PPD_FILE_OPEN_ERROR;
- ppd = NULL;
+ cg->ppd_status = PPD_FILE_OPEN_ERROR;
+ ppd = NULL;
}
return (ppd);
void
ppdSetConformance(ppd_conform_t c) /* I - Conformance level */
{
- ppd_conform = c;
+ cups_globals_t *cg = _cupsGlobals();
+ /* Global data */
+
+
+ cg->ppd_conform = c;
}
*/
static ppd_group_t * /* O - Named group */
-ppd_get_group(ppd_file_t *ppd, /* I - PPD file */
- const char *name, /* I - Name of group */
- const char *text) /* I - Text for group */
+ppd_get_group(ppd_file_t *ppd, /* I - PPD file */
+ const char *name, /* I - Name of group */
+ const char *text, /* I - Text for group */
+ cups_globals_t *cg) /* I - Global data */
{
int i; /* Looping var */
ppd_group_t *group; /* Group */
- DEBUG_printf(("ppd_get_group(%p, \"%s\")\n", ppd, name));
+ DEBUG_printf(("ppd_get_group(ppd=%p, name=\"%s\", text=\"%s\", cg=%p)\n",
+ ppd, name, text, cg));
for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, group ++)
if (strcmp(group->name, name) == 0)
{
DEBUG_printf(("Adding group %s...\n", name));
- if (ppd_conform == PPD_CONFORM_STRICT && strlen(text) >= sizeof(group->text))
+ if (cg->ppd_conform == PPD_CONFORM_STRICT && strlen(text) >= sizeof(group->text))
{
- ppd_status = PPD_ILLEGAL_TRANSLATION;
+ cg->ppd_status = PPD_ILLEGAL_TRANSLATION;
return (NULL);
}
if (group == NULL)
{
- ppd_status = PPD_ALLOC_ERROR;
+ cg->ppd_status = PPD_ALLOC_ERROR;
return (NULL);
}
*/
static int /* O - Bitmask of fields read */
-ppd_read(cups_file_t *fp, /* I - File to read from */
- char *keyword, /* O - Keyword from line */
- char *option, /* O - Option from line */
- char *text, /* O - Human-readable text from line */
- char **string, /* O - Code/string data */
- int ignoreblank) /* I - Ignore blank lines? */
+ppd_read(cups_file_t *fp, /* I - File to read from */
+ char *keyword, /* O - Keyword from line */
+ char *option, /* O - Option from line */
+ char *text, /* O - Human-readable text from line */
+ char **string, /* O - Code/string data */
+ int ignoreblank, /* I - Ignore blank lines? */
+ cups_globals_t *cg) /* I - Global data */
{
int ch, /* Character from file */
col, /* Column in line */
*string = NULL;
col = 0;
- startline = ppd_line + 1;
+ startline = cg->ppd_line + 1;
linesize = 1024;
line = malloc(linesize);
* Don't allow lines longer than 256k!
*/
- ppd_line = startline;
- ppd_status = PPD_LINE_TOO_LONG;
+ cg->ppd_line = startline;
+ cg->ppd_status = PPD_LINE_TOO_LONG;
free(line);
temp = realloc(line, linesize);
if (!temp)
{
- ppd_line = startline;
- ppd_status = PPD_LINE_TOO_LONG;
+ cg->ppd_line = startline;
+ cg->ppd_status = PPD_LINE_TOO_LONG;
free(line);
* Line feed or carriage return...
*/
- ppd_line ++;
+ cg->ppd_line ++;
col = 0;
if (ch == '\r')
*lineptr++ = '\n';
}
- else if (ch < ' ' && ch != '\t' && ppd_conform == PPD_CONFORM_STRICT)
+ else if (ch < ' ' && ch != '\t' && cg->ppd_conform == PPD_CONFORM_STRICT)
{
/*
* Other control characters...
*/
- ppd_line = startline;
- ppd_status = PPD_ILLEGAL_CHARACTER;
+ cg->ppd_line = startline;
+ cg->ppd_status = PPD_ILLEGAL_CHARACTER;
free(line);
* Line is too long...
*/
- ppd_line = startline;
- ppd_status = PPD_LINE_TOO_LONG;
+ cg->ppd_line = startline;
+ cg->ppd_status = PPD_LINE_TOO_LONG;
free(line);
break;
else if (ch == '\r' || ch == '\n')
{
- ppd_line ++;
+ cg->ppd_line ++;
col = 0;
if (ch == '\r')
ch = '\n';
}
- else if (ch < ' ' && ch != '\t' && ppd_conform == PPD_CONFORM_STRICT)
+ else if (ch < ' ' && ch != '\t' && cg->ppd_conform == PPD_CONFORM_STRICT)
{
/*
* Other control characters...
*/
- ppd_line = startline;
- ppd_status = PPD_ILLEGAL_CHARACTER;
+ cg->ppd_line = startline;
+ cg->ppd_status = PPD_ILLEGAL_CHARACTER;
free(line);
* Line is too long...
*/
- ppd_line = startline;
- ppd_status = PPD_LINE_TOO_LONG;
+ cg->ppd_line = startline;
+ cg->ppd_status = PPD_LINE_TOO_LONG;
free(line);
* Line feed or carriage return...
*/
- ppd_line ++;
+ cg->ppd_line ++;
col = 0;
if (ch == '\r')
break;
}
- else if (ch < ' ' && ch != '\t' && ppd_conform == PPD_CONFORM_STRICT)
+ else if (ch < ' ' && ch != '\t' && cg->ppd_conform == PPD_CONFORM_STRICT)
{
/*
* Other control characters...
*/
- ppd_line = startline;
- ppd_status = PPD_ILLEGAL_CHARACTER;
+ cg->ppd_line = startline;
+ cg->ppd_status = PPD_ILLEGAL_CHARACTER;
free(line);
* Line is too long...
*/
- ppd_line = startline;
- ppd_status = PPD_LINE_TOO_LONG;
+ cg->ppd_line = startline;
+ cg->ppd_status = PPD_LINE_TOO_LONG;
free(line);
strcmp(line, "*End") == 0) && /* End of multi-line string */
ignoreblank) /* Ignore these? */
{
- startline = ppd_line + 1;
+ startline = cg->ppd_line + 1;
continue;
}
if (strcmp(line, "*") == 0) /* (Bad) comment line */
{
- if (ppd_conform == PPD_CONFORM_RELAXED)
+ if (cg->ppd_conform == PPD_CONFORM_RELAXED)
{
- startline = ppd_line + 1;
+ startline = cg->ppd_line + 1;
continue;
}
else
{
- ppd_line = startline;
- ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
+ cg->ppd_line = startline;
+ cg->ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
free(line);
return (0);
if (line[0] != '*') /* All lines start with an asterisk */
{
- if (ppd_conform == PPD_CONFORM_STRICT)
+ if (cg->ppd_conform == PPD_CONFORM_STRICT)
{
- ppd_status = PPD_MISSING_ASTERISK;
+ cg->ppd_status = PPD_MISSING_ASTERISK;
free(line);
return (0);
}
if (*lineptr)
{
- ppd_status = PPD_MISSING_ASTERISK;
+ cg->ppd_status = PPD_MISSING_ASTERISK;
free(line);
return (0);
}
if (*lineptr <= ' ' || *lineptr > 126 || *lineptr == '/' ||
(keyptr - keyword) >= (PPD_MAX_NAME - 1))
{
- ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
+ cg->ppd_status = PPD_ILLEGAL_MAIN_KEYWORD;
free(line);
return (0);
}
if (*lineptr <= ' ' || *lineptr > 126 ||
(optptr - option) >= (PPD_MAX_NAME - 1))
{
- ppd_status = PPD_ILLEGAL_OPTION_KEYWORD;
+ cg->ppd_status = PPD_ILLEGAL_OPTION_KEYWORD;
free(line);
return (0);
}
*optptr = '\0';
- if (isspace(*lineptr & 255) && ppd_conform == PPD_CONFORM_STRICT)
+ if (isspace(*lineptr & 255) && cg->ppd_conform == PPD_CONFORM_STRICT)
{
- ppd_status = PPD_ILLEGAL_WHITESPACE;
+ cg->ppd_status = PPD_ILLEGAL_WHITESPACE;
free(line);
return (0);
}
if (((unsigned char)*lineptr < ' ' && *lineptr != '\t') ||
(textptr - text) >= (PPD_MAX_LINE - 1))
{
- ppd_status = PPD_ILLEGAL_TRANSLATION;
+ cg->ppd_status = PPD_ILLEGAL_TRANSLATION;
free(line);
return (0);
}
*textptr = '\0';
textlen = ppd_decode(text);
- if (textlen > PPD_MAX_TEXT && ppd_conform == PPD_CONFORM_STRICT)
+ if (textlen > PPD_MAX_TEXT && cg->ppd_conform == PPD_CONFORM_STRICT)
{
- ppd_status = PPD_ILLEGAL_TRANSLATION;
+ cg->ppd_status = PPD_ILLEGAL_TRANSLATION;
free(line);
return (0);
}
/* DEBUG_printf(("text = \"%s\", lineptr = \"%s\"\n", text, lineptr));*/
}
- if (isspace(*lineptr & 255) && ppd_conform == PPD_CONFORM_STRICT)
+ if (isspace(*lineptr & 255) && cg->ppd_conform == PPD_CONFORM_STRICT)
{
- ppd_status = PPD_ILLEGAL_WHITESPACE;
+ cg->ppd_status = PPD_ILLEGAL_WHITESPACE;
free(line);
return (0);
}
* Include necessary headers...
*/
-#include "cups.h"
-#include "string.h"
+#include "globals.h"
#include "debug.h"
#include <stdlib.h>
-#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#else
struct timeval curtime; /* Current time */
#endif /* WIN32 */
- static char *buf = NULL; /* Buffer if you pass in NULL and 0 */
- /*
- * See if a filename was specified...
- */
-
- if (filename == NULL)
- {
- if (buf == NULL)
- buf = calloc(1024, sizeof(char));
-
- if (buf == NULL)
- return (-1);
-
- filename = buf;
- len = 1024;
- }
-
/*
* See if TMPDIR is defined...
*/
int len) /* I - Size of buffer */
{
int fd; /* File descriptor for temp file */
- static char buf[1024] = ""; /* Buffer if you pass in NULL and 0 */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
/*
if (filename == NULL)
{
- filename = buf;
- len = sizeof(buf);
+ filename = cg->tempfile;
+ len = sizeof(cg->tempfile);
}
/*
* Include necessary headers...
*/
-#include <stdio.h>
+#include "globals.h"
#include <stdlib.h>
-#include <string.h>
#include <errno.h>
-#include <ctype.h>
#include <time.h>
-#include "language.h"
-#include "string.h"
-#include "transcode.h"
-
-
-/*
- * Local Globals...
- */
-
-static cups_cmap_t *cmap_cache = NULL; /* SBCS Charmap Cache */
-static cups_vmap_t *vmap_cache = NULL; /* VBCS Charmap Cache */
/*
* Prototypes...
{
char *datadir; /* CUPS_DATADIR environment variable */
char mapname[80]; /* Name of charset map */
- char filename[256]; /* Filename for charset map file */
+ char filename[1024]; /* Filename for charset map file */
/*
* Check for valid arguments...
{
cups_cmap_t *cmap; /* Legacy SBCS / Unicode Charset Map */
cups_vmap_t *vmap; /* Legacy VBCS / Unicode Charset Map */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
/*
* See if we already have this SBCS charset map loaded...
*/
- for (cmap = cmap_cache; cmap != NULL; cmap = cmap->next)
+ for (cmap = cg->cmap_cache; cmap != NULL; cmap = cmap->next)
{
if (cmap->encoding == encoding)
{
/*
* See if we already have this DBCS/VBCS charset map loaded...
*/
- for (vmap = vmap_cache; vmap != NULL; vmap = vmap->next)
+ for (vmap = cg->vmap_cache; vmap != NULL; vmap = vmap->next)
{
if (vmap->encoding == encoding)
{
cups_ucs2_t *crow; /* Pointer to UCS-2 row in 'char2uni' */
cups_sbcs_t *srow; /* Pointer to SBCS row in 'uni2char' */
cups_vbcs_t *vrow; /* Pointer to VBCS row in 'uni2char' */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
/*
* Loop through SBCS charset map cache, free all memory...
*/
- for (cmap = cmap_cache; cmap != NULL; cmap = cnext)
+ for (cmap = cg->cmap_cache; cmap != NULL; cmap = cnext)
{
for (i = 0; i < 256; i ++)
{
cnext = cmap->next;
free(cmap);
}
- cmap_cache = NULL;
+ cg->cmap_cache = NULL;
/*
* Loop through DBCS/VBCS charset map cache, free all memory...
*/
- for (vmap = vmap_cache; vmap != NULL; vmap = vnext)
+ for (vmap = cg->vmap_cache; vmap != NULL; vmap = vnext)
{
for (i = 0; i < 256; i ++)
{
vnext = vmap->next;
free(vmap);
}
- vmap_cache = NULL;
+ cg->vmap_cache = NULL;
return;
}
get_charmap_count(const char *filename) /* I - Charmap Filename */
{
int i; /* Looping variable */
- FILE *fp; /* Map input file pointer */
+ cups_file_t *fp; /* Map input file pointer */
char *s; /* Line parsing pointer */
char line[256]; /* Line from input map file */
cups_utf32_t unichar; /* Unicode character value */
*/
if ((filename == NULL) || (*filename == '\0'))
return (-1);
- fp = fopen(filename, "r");
+ fp = cupsFileOpen(filename, "r");
if (fp == NULL)
return (-1);
*/
for (i = 0; i < CUPS_MAX_CHARMAP_LINES;)
{
- s = fgets(&line[0], sizeof(line), fp);
+ s = cupsFileGets(fp, line, sizeof(line));
if (s == NULL)
break;
if ((*s == '#') || (*s == '\n') || (*s == '\0'))
if ((sscanf(s, "%lx", &unichar) != 1)
|| (unichar > 0xffff))
{
- fclose(fp);
+ cupsFileClose(fp);
return (-1);
}
i ++;
/*
* Close file and return charmap count (non-comment line count)...
*/
- fclose(fp);
+ cupsFileClose(fp);
return (i);
}
unsigned long legchar; /* Legacy character value */
cups_utf32_t unichar; /* Unicode character value */
cups_cmap_t *cmap; /* Legacy SBCS / Unicode Charset Map */
- FILE *fp; /* Charset map file pointer */
+ cups_file_t *fp; /* Charset map file pointer */
char *s; /* Line parsing pointer */
cups_ucs2_t *crow; /* Pointer to UCS-2 row in 'char2uni' */
cups_sbcs_t *srow; /* Pointer to SBCS row in 'uni2char' */
char line[256]; /* Line from charset map file */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
/*
* Check for valid arguments...
/*
* See if we already have this SBCS charset map loaded...
*/
- for (cmap = cmap_cache; cmap != NULL; cmap = cmap->next)
+ for (cmap = cg->cmap_cache; cmap != NULL; cmap = cmap->next)
{
if (cmap->encoding == encoding)
{
/*
* Open SBCS charset map input file...
*/
- fp = fopen(filename, "r");
+ fp = cupsFileOpen(filename, "r");
if (fp == NULL)
return (NULL);
cmap = (cups_cmap_t *) calloc(1, sizeof(cups_cmap_t));
if (cmap == NULL)
{
- fclose(fp);
+ cupsFileClose(fp);
return (NULL);
}
- cmap->next = cmap_cache;
- cmap_cache = cmap;
+ cmap->next = cg->cmap_cache;
+ cg->cmap_cache = cmap;
cmap->used ++;
cmap->encoding = encoding;
*/
for (i = 0; i < CUPS_MAX_CHARMAP_LINES;)
{
- s = fgets(&line[0], sizeof(line), fp);
+ s = cupsFileGets(fp, line, sizeof(line));
if (s == NULL)
break;
if ((*s == '#') || (*s == '\n') || (*s == '\0'))
if ((sscanf(s, "%lx", &legchar) != 1)
|| (legchar > 0xff))
{
- fclose(fp);
+ cupsFileClose(fp);
cupsCharmapFlush();
return (NULL);
}
s += 2;
if (sscanf(s, "%lx", &unichar) != 1)
{
- fclose(fp);
+ cupsFileClose(fp);
cupsCharmapFlush();
return (NULL);
}
srow = (cups_sbcs_t *) calloc(256, sizeof(cups_sbcs_t));
if (srow == NULL)
{
- fclose(fp);
+ cupsFileClose(fp);
cupsCharmapFlush();
return (NULL);
}
if (*srow == 0)
*srow = (cups_sbcs_t) legchar;
}
- fclose(fp);
+ cupsFileClose(fp);
return (cmap);
}
unsigned long legchar; /* Legacy character value */
cups_utf32_t unichar; /* Unicode character value */
int mapcount; /* Count of lines in charmap file */
- FILE *fp; /* Charset map file pointer */
+ cups_file_t *fp; /* Charset map file pointer */
char *s; /* Line parsing pointer */
char line[256]; /* Line from charset map file */
int i; /* Loop variable */
int wide; /* 32-bit legacy char */
+ cups_globals_t *cg = _cupsGlobals();
+ /* Pointer to library globals */
/*
* Check for valid arguments...
/*
* See if we already have this DBCS/VBCS charset map loaded...
*/
- for (vmap = vmap_cache; vmap != NULL; vmap = vmap->next)
+ for (vmap = cg->vmap_cache; vmap != NULL; vmap = vmap->next)
{
if (vmap->encoding == encoding)
{
/*
* Open VBCS charset map input file...
*/
- fp = fopen(filename, "r");
+ fp = cupsFileOpen(filename, "r");
if (fp == NULL)
return (NULL);
vmap = (cups_vmap_t *) calloc(1, sizeof(cups_vmap_t));
if (vmap == NULL)
{
- fclose(fp);
+ cupsFileClose(fp);
return (NULL);
}
- vmap->next = vmap_cache;
- vmap_cache = vmap;
+ vmap->next = cg->vmap_cache;
+ cg->vmap_cache = vmap;
vmap->used ++;
vmap->encoding = encoding;
for (i = 0, wide = 0; i < mapcount; )
{
- s = fgets(&line[0], sizeof(line), fp);
+ s = cupsFileGets(fp, line, sizeof(line));
if (s == NULL)
break;
if ((*s == '#') || (*s == '\n') || (*s == '\0'))
if ((sscanf(s, "%lx", &legchar) != 1)
|| ((legchar > 0xffff) && (encoding < CUPS_ENCODING_DBCS_END)))
{
- fclose(fp);
+ cupsFileClose(fp);
cupsCharmapFlush();
return (NULL);
}
s += 2;
if (sscanf(s, "%lx", &unichar) != 1)
{
- fclose(fp);
+ cupsFileClose(fp);
cupsCharmapFlush();
return (NULL);
}
crow = (cups_ucs2_t *) calloc(256, sizeof(cups_ucs2_t));
if (crow == NULL)
{
- fclose(fp);
+ cupsFileClose(fp);
cupsCharmapFlush();
return (NULL);
}
calloc(vmap->widecount, sizeof(cups_wide2uni_t));
if (wide2uni == NULL)
{
- fclose(fp);
+ cupsFileClose(fp);
cupsCharmapFlush();
return (NULL);
}
vrow = (cups_vbcs_t *) calloc(256, sizeof(cups_vbcs_t));
if (vrow == NULL)
{
- fclose(fp);
+ cupsFileClose(fp);
cupsCharmapFlush();
return (NULL);
}
*vrow = (cups_vbcs_t) legchar;
}
vmap->charcount = (i - vmap->widecount);
- fclose(fp);
+ cupsFileClose(fp);
return (vmap);
}
* cupsSetServer() - Set the default server name...
* cupsSetUser() - Set the default user name...
* cupsUser() - Return the current users name.
- * cups_get_password() - Get a password from the user...
- * cups_get_line() - Get a line from a file...
+ * _cupsGetPassword() - Get a password from the user...
*/
/*
* Include necessary headers...
*/
-#include "cups.h"
-#include "string.h"
#include "http-private.h"
+#include "globals.h"
#include <stdlib.h>
-
#ifdef WIN32
# include <windows.h>
#endif /* WIN32 */
-/*
- * Local functions...
- */
-
-static const char *cups_get_password(const char *prompt);
-static char *cups_get_line(char *buf, int buflen, FILE *fp);
-
-
-/*
- * Local globals...
- */
-
-static http_encryption_t cups_encryption = (http_encryption_t)-1;
-static char cups_user[65] = "",
- cups_server[256] = "";
-static const char *(*cups_pwdcb)(const char *) = cups_get_password;
-
-#ifdef HAVE_DOMAINSOCKETS
-char cups_server_domainsocket[104] = "";
-#endif /* HAVE_DOMAINSOCKETS */
-
/*
* 'cupsEncryption()' - Get the default encryption settings...
*/
http_encryption_t
cupsEncryption(void)
{
- FILE *fp; /* client.conf file */
+ cups_file_t *fp; /* client.conf file */
char *encryption; /* CUPS_ENCRYPTION variable */
const char *home; /* Home directory of user */
char line[1024]; /* Line from file */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
/*
* First see if we have already set the encryption stuff...
*/
- if (cups_encryption == (http_encryption_t)-1)
+ if (cg->encryption == (http_encryption_t)-1)
{
/*
* Then see if the CUPS_ENCRYPTION environment variable is set...
if ((home = getenv("HOME")) != NULL)
{
snprintf(line, sizeof(line), "%s/.cupsrc", home);
- fp = fopen(line, "r");
+ fp = cupsFileOpen(line, "r");
}
else
fp = NULL;
if ((home = getenv("CUPS_SERVERROOT")) != NULL)
{
snprintf(line, sizeof(line), "%s/client.conf", home);
- fp = fopen(line, "r");
+ fp = cupsFileOpen(line, "r");
}
else
- fp = fopen(CUPS_SERVERROOT "/client.conf", "r");
+ fp = cupsFileOpen(CUPS_SERVERROOT "/client.conf", "r");
}
encryption = "IfRequested";
* Read the config file and look for an Encryption line...
*/
- while (cups_get_line(line, sizeof(line), fp) != NULL)
+ while (cupsFileGets(fp, line, sizeof(line)) != NULL)
if (strncmp(line, "Encryption ", 11) == 0 ||
strncmp(line, "Encryption\t", 11) == 0)
{
break;
}
- fclose(fp);
+ cupsFileClose(fp);
}
}
*/
if (strcasecmp(encryption, "never") == 0)
- cups_encryption = HTTP_ENCRYPT_NEVER;
+ cg->encryption = HTTP_ENCRYPT_NEVER;
else if (strcasecmp(encryption, "always") == 0)
- cups_encryption = HTTP_ENCRYPT_ALWAYS;
+ cg->encryption = HTTP_ENCRYPT_ALWAYS;
else if (strcasecmp(encryption, "required") == 0)
- cups_encryption = HTTP_ENCRYPT_REQUIRED;
+ cg->encryption = HTTP_ENCRYPT_REQUIRED;
else
- cups_encryption = HTTP_ENCRYPT_IF_REQUESTED;
+ cg->encryption = HTTP_ENCRYPT_IF_REQUESTED;
}
- return (cups_encryption);
+ return (cg->encryption);
}
const char * /* O - Password */
cupsGetPassword(const char *prompt) /* I - Prompt string */
{
- return ((*cups_pwdcb)(prompt));
+ return ((*_cupsGlobals()->password_cb)(prompt));
}
void
cupsSetEncryption(http_encryption_t e) /* I - New encryption preference */
{
- cups_encryption = e;
+ _cupsGlobals()->encryption = e;
}
const char * /* O - Server name */
cupsServer(void)
{
- FILE *fp; /* client.conf file */
+ cups_file_t *fp; /* client.conf file */
char *server; /* Pointer to server name */
const char *home; /* Home directory of user */
char *port; /* Port number */
- char line[1024]; /* Line from file */
+ char line[1024], /* Line from file */
+ *value; /* Value on line */
+ int linenum; /* Line number in file */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
/*
* First see if we have already set the server name...
*/
- if (!cups_server[0])
+ if (!cg->server[0])
{
/*
* Then see if the CUPS_SERVER environment variable is set...
if ((home = getenv("HOME")) != NULL)
{
snprintf(line, sizeof(line), "%s/.cupsrc", home);
- fp = fopen(line, "r");
+ fp = cupsFileOpen(line, "r");
}
else
fp = NULL;
if ((home = getenv("CUPS_SERVERROOT")) != NULL)
{
snprintf(line, sizeof(line), "%s/client.conf", home);
- fp = fopen(line, "r");
+ fp = cupsFileOpen(line, "r");
}
else
- fp = fopen(CUPS_SERVERROOT "/client.conf", "r");
+ fp = cupsFileOpen(CUPS_SERVERROOT "/client.conf", "r");
}
server = "localhost";
* Read the config file and look for a ServerName line...
*/
- while (cups_get_line(line, sizeof(line), fp) != NULL)
- if (strncmp(line, "ServerName ", 11) == 0 ||
- strncmp(line, "ServerName\t", 11) == 0)
+ linenum = 0;
+ while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum) != NULL)
+ if (!strcmp(line, "ServerName") && value)
{
/*
- * Got it! Drop any trailing newline and find the name...
+ * Got it!
*/
- server = line + strlen(line) - 1;
- if (*server == '\n')
- *server = '\0';
-
- for (server = line + 11; isspace(*server & 255); server ++);
+ server = value;
break;
}
- fclose(fp);
+ cupsFileClose(fp);
}
}
* Copy the server name over and set the port number, if any...
*/
- strlcpy(cups_server, server, sizeof(cups_server));
+ strlcpy(cg->server, server, sizeof(cg->server));
- if (cups_server[0] != '/' && (port = strrchr(cups_server, ':')) != NULL &&
+ if (cg->server[0] != '/' && (port = strrchr(cg->server, ':')) != NULL &&
isdigit(port[1] & 255))
{
*port++ = '\0';
}
}
- return (cups_server);
+ return (cg->server);
}
void
cupsSetPasswordCB(const char *(*cb)(const char *)) /* I - Callback function */
{
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
+
if (cb == (const char *(*)(const char *))0)
- cups_pwdcb = cups_get_password;
+ cg->password_cb = _cupsGetPassword;
else
- cups_pwdcb = cb;
+ cg->password_cb = cb;
}
void
cupsSetServer(const char *server) /* I - Server name */
{
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
+
if (server)
- strlcpy(cups_server, server, sizeof(cups_server));
+ strlcpy(cg->server, server, sizeof(cg->server));
else
- cups_server[0] = '\0';
+ cg->server[0] = '\0';
}
void
cupsSetUser(const char *user) /* I - User name */
{
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
+
if (user)
- strlcpy(cups_user, user, sizeof(cups_user));
+ strlcpy(cg->user, user, sizeof(cg->user));
else
- cups_user[0] = '\0';
+ cg->user[0] = '\0';
}
const char * /* O - User name */
cupsUser(void)
{
- if (!cups_user[0])
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
+
+ if (!cg->user[0])
{
DWORD size; /* Size of string */
- size = sizeof(cups_user);
- if (!GetUserName(cups_user, &size))
+ size = sizeof(cg->user);
+ if (!GetUserName(cg->user, &size))
{
/*
* Use the default username...
*/
- strcpy(cups_user, "unknown");
+ strcpy(cg->user, "unknown");
}
}
- return (cups_user);
+ return (cg->user);
}
/*
- * 'cups_get_password()' - Get a password from the user...
+ * '_cupsGetPassword()' - Get a password from the user...
*/
-static const char * /* O - Password */
-cups_get_password(const char *prompt) /* I - Prompt string */
+const char * /* O - Password */
+_cupsGetPassword(const char *prompt) /* I - Prompt string */
{
return (NULL);
}
cupsUser(void)
{
struct passwd *pwd; /* User/password entry */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
- if (!cups_user[0])
+ if (!cg->user[0])
{
/*
* Rewind the password file...
*/
if ((pwd = getpwuid(getuid())) == NULL)
- strcpy(cups_user, "unknown"); /* Unknown user! */
+ strcpy(cg->user, "unknown"); /* Unknown user! */
else
{
/*
setpwent();
- strlcpy(cups_user, pwd->pw_name, sizeof(cups_user));
+ strlcpy(cg->user, pwd->pw_name, sizeof(cg->user));
}
/*
setpwent();
}
- return (cups_user);
+ return (cg->user);
}
/*
- * 'cups_get_password()' - Get a password from the user...
+ * '_cupsGetPassword()' - Get a password from the user...
*/
-static const char * /* O - Password */
-cups_get_password(const char *prompt) /* I - Prompt string */
+const char * /* O - Password */
+_cupsGetPassword(const char *prompt) /* I - Prompt string */
{
return (getpass(prompt));
}
#endif /* WIN32 */
-/*
- * 'cups_get_line()' - Get a line from a file.
- */
-
-static char * /* O - Line from file */
-cups_get_line(char *buf, /* I - Line buffer */
- int buflen, /* I - Size of line buffer */
- FILE *fp) /* I - File to read from */
-{
- char *bufptr; /* Pointer to end of buffer */
-
-
- /*
- * Get the line from a file...
- */
-
- if (fgets(buf, buflen, fp) == NULL)
- return (NULL);
-
- /*
- * Remove all trailing whitespace...
- */
-
- bufptr = buf + strlen(buf) - 1;
- if (bufptr < buf)
- return (NULL);
-
- while (bufptr >= buf && isspace(*bufptr & 255))
- *bufptr-- = '\0';
-
- return (buf);
-}
-
-
/*
* End of "$Id$".
*/
* Include necessary headers...
*/
-#include "cups.h"
-#include "language.h"
-#include "string.h"
+#include "globals.h"
#include "debug.h"
#include <stdlib.h>
-#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#endif /* WIN32 || __EMX__ */
-/*
- * Local globals...
- */
-
-static http_t *cups_server = NULL; /* Current server connection */
-static ipp_status_t last_error = IPP_OK; /* Last IPP error */
-
-
/*
* Local functions...
*/
ipp_t *request, /* IPP request */
*response; /* IPP response */
cups_lang_t *language; /* Language info */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
/*
if (!cups_connect(name, printer, hostname))
{
DEBUG_puts("Unable to connect to server!");
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
return (0);
}
* Do the request...
*/
- if ((response = cupsDoRequest(cups_server, request, "/jobs/")) != NULL)
+ if ((response = cupsDoRequest(cg->http, request, "/jobs/")) != NULL)
ippDelete(response);
- return (last_error < IPP_REDIRECTION_OTHER_SITE);
+ return (cg->last_error < IPP_REDIRECTION_OTHER_SITE);
}
struct stat fileinfo; /* File information */
int bytes; /* Number of bytes read/written */
char buffer[32768]; /* Output buffer */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
DEBUG_printf(("cupsDoFileRequest(%p, %p, \'%s\', \'%s\')\n",
if (request != NULL)
ippDelete(request);
- last_error = IPP_INTERNAL_ERROR;
+ cg->last_error = IPP_INTERNAL_ERROR;
return (NULL);
}
*/
ippDelete(request);
- last_error = IPP_NOT_FOUND;
+ cg->last_error = IPP_NOT_FOUND;
return (NULL);
}
*/
ippDelete(request);
- last_error = IPP_NOT_POSSIBLE;
+ cg->last_error = IPP_NOT_POSSIBLE;
return (NULL);
}
*/
ippDelete(request);
- last_error = IPP_NOT_FOUND;
+ cg->last_error = IPP_NOT_FOUND;
return (NULL);
}
}
httpFlush(http);
/* Reconnect... */
- httpReconnect(http);
+ if (httpReconnect(http))
+ {
+ status = HTTP_ERROR;
+ break;
+ }
/* Upgrade with encryption... */
httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
ippDelete(response);
response = NULL;
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
break;
}
}
ippDelete(request);
if (response)
- last_error = response->request.status.status_code;
+ cg->last_error = response->request.status.status_code;
else if (status != HTTP_OK)
{
switch (status)
{
case HTTP_NOT_FOUND :
- last_error = IPP_NOT_FOUND;
+ cg->last_error = IPP_NOT_FOUND;
break;
case HTTP_UNAUTHORIZED :
- last_error = IPP_NOT_AUTHORIZED;
+ cg->last_error = IPP_NOT_AUTHORIZED;
break;
case HTTP_FORBIDDEN :
- last_error = IPP_FORBIDDEN;
+ cg->last_error = IPP_FORBIDDEN;
break;
case HTTP_BAD_REQUEST :
- last_error = IPP_BAD_REQUEST;
+ cg->last_error = IPP_BAD_REQUEST;
break;
case HTTP_REQUEST_TOO_LARGE :
- last_error = IPP_REQUEST_VALUE;
+ cg->last_error = IPP_REQUEST_VALUE;
break;
case HTTP_NOT_IMPLEMENTED :
- last_error = IPP_OPERATION_NOT_SUPPORTED;
+ cg->last_error = IPP_OPERATION_NOT_SUPPORTED;
break;
case HTTP_NOT_SUPPORTED :
- last_error = IPP_VERSION_NOT_SUPPORTED;
+ cg->last_error = IPP_VERSION_NOT_SUPPORTED;
break;
default :
DEBUG_printf(("HTTP error %d mapped to IPP_SERVICE_UNAVAILABLE!\n",
status));
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
break;
}
}
ipp_attribute_t *attr; /* Current attribute */
cups_lang_t *language; /* Default language */
char **temp; /* Temporary pointer */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
if (classes == NULL)
{
- last_error = IPP_INTERNAL_ERROR;
+ cg->last_error = IPP_INTERNAL_ERROR;
return (0);
}
if (!cups_connect("default", NULL, NULL))
{
DEBUG_puts("Unable to connect to server!");
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
return (0);
}
n = 0;
*classes = NULL;
- if ((response = cupsDoRequest(cups_server, request, "/")) != NULL)
+ if ((response = cupsDoRequest(cg->http, request, "/")) != NULL)
{
- last_error = response->request.status.status_code;
+ cg->last_error = response->request.status.status_code;
for (attr = response->attrs; attr != NULL; attr = attr->next)
if (attr->name != NULL &&
ippDelete(response);
}
else
- last_error = IPP_BAD_REQUEST;
+ cg->last_error = IPP_BAD_REQUEST;
return (n);
}
cupsGetDefault(void)
{
const char *var; /* Environment variable */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
/*
if (!cups_connect("default", NULL, NULL))
{
DEBUG_puts("Unable to connect to server!");
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
return (NULL);
}
* Return the default printer...
*/
- return (cupsGetDefault2(cups_server));
+ return (cupsGetDefault2(cg->http));
}
ipp_attribute_t *attr; /* Current attribute */
cups_lang_t *language; /* Default language */
const char *var; /* Environment variable */
- static char def_printer[256]; /* Default printer */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
/*
if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
- last_error = response->request.status.status_code;
+ cg->last_error = response->request.status.status_code;
if ((attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME)) != NULL)
{
- strlcpy(def_printer, attr->values[0].string.text, sizeof(def_printer));
+ strlcpy(cg->def_printer, attr->values[0].string.text, sizeof(cg->def_printer));
ippDelete(response);
- return (def_printer);
+ return (cg->def_printer);
}
ippDelete(response);
}
else
- last_error = IPP_BAD_REQUEST;
+ cg->last_error = IPP_BAD_REQUEST;
return (NULL);
}
int myjobs, /* I - Only show my jobs? */
int completed) /* I - Only show completed jobs? */
{
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
/*
* Try to connect to the server...
*/
if (!cups_connect("default", NULL, NULL))
{
DEBUG_puts("Unable to connect to server!");
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
return (-1);
}
* Return the jobs...
*/
- return (cupsGetJobs2(cups_server, jobs, mydest, myjobs, completed));
+ return (cupsGetJobs2(cg->http, jobs, mydest, myjobs, completed));
}
*title, /* job-name */
*user; /* job-originating-user-name */
char uri[HTTP_MAX_URI]; /* URI for jobs */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
static const char * const attrs[] = /* Requested attributes */
{
"job-id",
if (!http || !jobs)
{
- last_error = IPP_INTERNAL_ERROR;
+ cg->last_error = IPP_INTERNAL_ERROR;
return (-1);
}
if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
- last_error = response->request.status.status_code;
+ cg->last_error = response->request.status.status_code;
for (attr = response->attrs; attr != NULL; attr = attr->next)
{
ippDelete(response);
}
else
- last_error = IPP_BAD_REQUEST;
+ cg->last_error = IPP_BAD_REQUEST;
- if (n == 0 && last_error >= IPP_BAD_REQUEST)
+ if (n == 0 && cg->last_error >= IPP_BAD_REQUEST)
return (-1);
else
return (n);
const char * /* O - Filename for PPD file */
cupsGetPPD(const char *name) /* I - Printer name */
{
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
/*
* See if we can connect to the server...
*/
if (!cups_connect(name, NULL, NULL))
{
DEBUG_puts("Unable to connect to server!");
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
return (NULL);
}
* Return the PPD file...
*/
- return (cupsGetPPD2(cups_server, name));
+ return (cupsGetPPD2(cg->http, name));
}
resource[HTTP_MAX_URI]; /* Resource name */
int port; /* Port number */
http_status_t status; /* HTTP status from server */
- static char filename[HTTP_MAX_URI]; /* Local filename */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
static const char * const requested_attrs[] =
{ /* Requested attributes */
"printer-uri-supported",
if (!http || !name)
{
- last_error = IPP_INTERNAL_ERROR;
+ cg->last_error = IPP_INTERNAL_ERROR;
return (NULL);
}
if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
- last_error = response->request.status.status_code;
+ cg->last_error = response->request.status.status_code;
printer[0] = '\0';
hostname[0] = '\0';
if (!printer[0])
{
- last_error = IPP_NOT_FOUND;
+ cg->last_error = IPP_NOT_FOUND;
return (NULL);
}
cupsEncryption())) == NULL)
{
DEBUG_puts("Unable to connect to server!");
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
return (NULL);
}
* Get a temp file...
*/
- if ((fd = cupsTempFd(filename, sizeof(filename))) < 0)
+ if ((fd = cupsTempFd(cg->ppd_filename, sizeof(cg->ppd_filename))) < 0)
{
/*
* Can't open file; close the server connection and return NULL...
*/
- last_error = IPP_INTERNAL_ERROR;
+ cg->last_error = IPP_INTERNAL_ERROR;
if (http2 != http)
httpClose(http2);
switch (status)
{
case HTTP_NOT_FOUND :
- last_error = IPP_NOT_FOUND;
+ cg->last_error = IPP_NOT_FOUND;
break;
case HTTP_ERROR :
DEBUG_puts("Mapping HTTP error to IPP_ERROR");
- last_error = IPP_ERROR;
+ cg->last_error = IPP_ERROR;
break;
case HTTP_UNAUTHORIZED :
- last_error = IPP_NOT_AUTHORIZED;
+ cg->last_error = IPP_NOT_AUTHORIZED;
break;
default :
- last_error = IPP_INTERNAL_ERROR;
+ cg->last_error = IPP_INTERNAL_ERROR;
break;
}
- unlink(filename);
+ unlink(cg->ppd_filename);
return (NULL);
}
* Return the PPD file...
*/
- return (filename);
+ return (cg->ppd_filename);
}
ipp_attribute_t *attr; /* Current attribute */
cups_lang_t *language; /* Default language */
char **temp; /* Temporary pointer */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
if (printers == NULL)
{
- last_error = IPP_INTERNAL_ERROR;
+ cg->last_error = IPP_INTERNAL_ERROR;
return (0);
}
if (!cups_connect("default", NULL, NULL))
{
DEBUG_puts("Unable to connect to server!");
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
return (0);
}
n = 0;
*printers = NULL;
- if ((response = cupsDoRequest(cups_server, request, "/")) != NULL)
+ if ((response = cupsDoRequest(cg->http, request, "/")) != NULL)
{
- last_error = response->request.status.status_code;
+ cg->last_error = response->request.status.status_code;
for (attr = response->attrs; attr != NULL; attr = attr->next)
if (attr->name != NULL &&
ippDelete(response);
}
else
- last_error = IPP_BAD_REQUEST;
+ cg->last_error = IPP_BAD_REQUEST;
return (n);
}
ipp_status_t /* O - IPP error code */
cupsLastError(void)
{
- return (last_error);
+ return (_cupsGlobals()->last_error);
}
+
/*
* 'cupsPrintFile()' - Print a file to a printer or class.
*/
/* I - Number of options */
cups_option_t *options) /* I - Options */
{
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
+
DEBUG_printf(("cupsPrintFiles(name=\"%s\", num_files=%d, "
"files=%p, title=\"%s\", num_options=%d, options=%p)\n",
name, num_files, files, title, num_options, options));
DEBUG_printf(("cupsPrintFiles: Unable to open connection - %s.\n",
strerror(errno)));
DEBUG_puts("Unable to connect to server!");
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
return (0);
}
* Print the file(s)...
*/
- return (cupsPrintFiles2(cups_server, name, num_files, files, title,
+ return (cupsPrintFiles2(cg->http, name, num_files, files, title,
num_options, options));
}
char uri[HTTP_MAX_URI]; /* Printer URI */
cups_lang_t *language; /* Language to use */
int jobid; /* New job ID */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
DEBUG_printf(("cupsPrintFiles(http=%p, name=\"%s\", num_files=%d, "
{
DEBUG_puts("No job ID!");
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
jobid = 0;
}
char *hostname) /* O - Hostname [HTTP_MAX_URI] */
{
char hostbuf[HTTP_MAX_URI]; /* Name of host */
+ cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
DEBUG_printf(("cups_connect(\"%s\", %p, %p)\n", name, printer, hostname));
if (name == NULL)
{
- last_error = IPP_BAD_REQUEST;
+ cg->last_error = IPP_BAD_REQUEST;
return (NULL);
}
else
printer = (char *)name;
- if (cups_server != NULL)
+ if (cg->http != NULL)
{
- if (strcasecmp(cups_server->hostname, hostname) == 0)
+ if (strcasecmp(cg->http->hostname, hostname) == 0)
return (printer);
- httpClose(cups_server);
+ httpClose(cg->http);
}
DEBUG_printf(("connecting to %s on port %d...\n", hostname, ippPort()));
- if ((cups_server = httpConnectEncrypt(hostname, ippPort(),
+ if ((cg->http = httpConnectEncrypt(hostname, ippPort(),
cupsEncryption())) == NULL)
{
DEBUG_puts("Unable to connect to server!");
- last_error = IPP_SERVICE_UNAVAILABLE;
+ cg->last_error = IPP_SERVICE_UNAVAILABLE;
return (NULL);
}
else
puts("%%DocumentSuppliedResources: procset hpgltops 1.1 0");
puts("%%DocumentNeededResources: font Courier Helvetica");
puts("%%Creator: hpgltops/" CUPS_SVERSION);
- strftime(line, sizeof(line), CUPS_STRFTIME_FORMAT, curtm);
+ strftime(line, sizeof(line), "%c", curtm);
printf("%%%%CreationDate: %s\n", line);
printf("%%%%Title: %s\n", title);
printf("%%%%For: %s\n", user);
puts("%%DocumentData: Clean7Bit");
puts("%%DocumentNeededResources: font Helvetica-Bold");
puts("%%Creator: imagetops/" CUPS_SVERSION);
- strftime(curdate, sizeof(curdate), CUPS_STRFTIME_FORMAT, curtm);
+ strftime(curdate, sizeof(curdate), "%c", curtm);
printf("%%%%CreationDate: %s\n", curdate);
printf("%%%%Title: %s\n", argv[3]);
printf("%%%%For: %s\n", argv[2]);
curtime = time(NULL);
curtm = localtime(&curtime);
- strftime(curdate, sizeof(curdate), CUPS_STRFTIME_FORMAT, curtm);
+ strftime(curdate, sizeof(curdate), "%c", curtm);
puts("%!PS-Adobe-3.0");
printf("%%%%BoundingBox: 0 0 %.0f %.0f\n", PageWidth, PageLength);
testmime: testmime.o libmime.a
echo Linking $@...
- $(CC) $(LDFLAGS) -o $@ testmime.o libmime.a ../cups/libcups.a $(LIBZ)
+ $(CC) $(LDFLAGS) -o $@ testmime.o libmime.a ../cups/libcups.a $(COMMONLIBS) $(LIBZ)
#
curtime = time(NULL);
curdate = localtime(&curtime);
- strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
+ strftime(temp, sizeof(temp) - 1, "%c", curdate);
cupsFilePuts(fp, "# Class configuration file for " CUPS_SVERSION "\n");
cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
curtime = time(NULL);
curdate = localtime(&curtime);
- strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
+ strftime(temp, sizeof(temp) - 1, "%c", curdate);
cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");
cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
curtime = time(NULL);
curdate = localtime(&curtime);
- strftime(temp, sizeof(temp) - 1, CUPS_STRFTIME_FORMAT, curdate);
+ strftime(temp, sizeof(temp) - 1, "%c", curdate);
cupsFilePuts(fp, "# Subscription configuration file for " CUPS_SVERSION "\n");
cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
}
else
{
- if (!strftime(date, sizeof(date), CUPS_STRFTIME_FORMAT, jobdate))
+ if (!strftime(date, sizeof(date), "%c", jobdate))
strcpy(date, "Unknown");
if (ranking)