X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=cups%2Fglobals.c;h=b343bcf322bf8a806063d3652934b3e0affd06ec;hb=f2d18633e2916a90bbbe5ae039d1f0acc430dc0b;hp=00a73691cfb5eb8237ee3707b6d9f8b38112f5de;hpb=6d2f911bdd077fee9489b1084b960c4e68fc0658;p=thirdparty%2Fcups.git diff --git a/cups/globals.c b/cups/globals.c index 00a73691c..b343bcf32 100644 --- a/cups/globals.c +++ b/cups/globals.c @@ -1,9 +1,9 @@ /* - * "$Id: globals.c 7870 2008-08-27 18:14:10Z mike $" + * "$Id$" * * Global variable access routines for CUPS. * - * Copyright 2007-2010 by Apple Inc. + * Copyright 2007-2013 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * These coded instructions, statements, and computer programs are the @@ -20,6 +20,7 @@ * _cupsGlobals() - Return a pointer to thread local storage * _cupsGlobalUnlock() - Unlock the global mutex. * DllMain() - Main entry for library. + * cups_fix_path() - Fix a file path to use forward slashes consistently. * cups_globals_alloc() - Allocate and initialize global data. * cups_globals_free() - Free global data. * cups_globals_init() - Initialize environment variables. @@ -37,22 +38,33 @@ */ +#ifdef DEBUG +static int cups_global_index = 0; + /* Next thread number */ +#endif /* DEBUG */ static _cups_threadkey_t cups_globals_key = _CUPS_THREADKEY_INITIALIZER; /* Thread local storage key */ #ifdef HAVE_PTHREAD_H static pthread_once_t cups_globals_key_once = PTHREAD_ONCE_INIT; /* One-time initialization object */ #endif /* HAVE_PTHREAD_H */ +#if defined(HAVE_PTHREAD_H) || defined(WIN32) static _cups_mutex_t cups_global_mutex = _CUPS_MUTEX_INITIALIZER; /* Global critical section */ +#endif /* HAVE_PTHREAD_H || WIN32 */ /* * Local functions... */ +#ifdef WIN32 +static void cups_fix_path(char *path); +#endif /* WIN32 */ static _cups_globals_t *cups_globals_alloc(void); +#if defined(HAVE_PTHREAD_H) || defined(WIN32) static void cups_globals_free(_cups_globals_t *g); +#endif /* HAVE_PTHREAD_H || WIN32 */ #ifdef HAVE_PTHREAD_H static void cups_globals_init(void); #endif /* HAVE_PTHREAD_H */ @@ -68,7 +80,7 @@ _cupsGlobalLock(void) #ifdef HAVE_PTHREAD_H pthread_mutex_lock(&cups_global_mutex); #elif defined(WIN32) - EnterCriticalSection(&cups_global_mutex->m_criticalSection); + EnterCriticalSection(&cups_global_mutex.m_criticalSection); #endif /* HAVE_PTHREAD_H */ } @@ -123,7 +135,7 @@ _cupsGlobalUnlock(void) #ifdef HAVE_PTHREAD_H pthread_mutex_unlock(&cups_global_mutex); #elif defined(WIN32) - LeaveCriticalSection(&cups_global_mutex->m_criticalSection); + LeaveCriticalSection(&cups_global_mutex.m_criticalSection); #endif /* HAVE_PTHREAD_H */ } @@ -147,7 +159,7 @@ DllMain(HINSTANCE hinst, /* I - DLL module handle */ switch (reason) { case DLL_PROCESS_ATTACH : /* Called on library initialization */ - InitializeCriticalSection(&cups_global_lock); + InitializeCriticalSection(&cups_global_mutex.m_criticalSection); if ((cups_globals_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) return (FALSE); @@ -163,7 +175,7 @@ DllMain(HINSTANCE hinst, /* I - DLL module handle */ cups_globals_free(cg); TlsFree(cups_globals_key); - DeleteCriticalSection(&cups_global_lock); + DeleteCriticalSection(&cups_global_mutex.m_criticalSection); break; default: @@ -187,9 +199,9 @@ cups_globals_alloc(void) #ifdef WIN32 HKEY key; /* Registry key */ DWORD size; /* Size of string */ - static char installdir[1024], /* Install directory */ - confdir[1024], /* Server root directory */ - localedir[1024]; /* Locale directory */ + static char installdir[1024] = "", /* Install directory */ + confdir[1024] = "", /* Server root directory */ + localedir[1024] = ""; /* Locale directory */ #endif /* WIN32 */ @@ -202,35 +214,67 @@ cups_globals_alloc(void) */ memset(cg, 0, sizeof(_cups_globals_t)); - cg->encryption = (http_encryption_t)-1; - cg->password_cb = (cups_password_cb2_t)_cupsGetPassword; - + cg->encryption = (http_encryption_t)-1; + cg->password_cb = (cups_password_cb2_t)_cupsGetPassword; + cg->any_root = 1; + cg->expired_certs = 1; + cg->expired_root = 1; + cg->server_version = 20; + +#ifdef DEBUG /* - * Then set directories as appropriate... + * Friendly thread ID for debugging... */ -#ifdef WIN32 + cg->thread_id = ++ cups_global_index; +#endif /* DEBUG */ + /* - * Open the registry... + * Then set directories as appropriate... */ - strcpy(installdir, "C:/Program Files/cups.org"); - - if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\cups.org", 0, KEY_READ, - &key)) +#ifdef WIN32 + if (!installdir[0]) { /* - * Grab the installation directory... + * Open the registry... */ - size = sizeof(installdir); - RegQueryValueEx(key, "installdir", NULL, NULL, installdir, &size); - RegCloseKey(key); + strlcpy(installdir, "C:/Program Files/cups.org", sizeof(installdir)); + + if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\cups.org", 0, KEY_READ, + &key)) + { + /* + * Grab the installation directory... + */ + + char *ptr; /* Pointer into installdir */ + + size = sizeof(installdir); + RegQueryValueEx(key, "installdir", NULL, NULL, installdir, &size); + RegCloseKey(key); + + for (ptr = installdir; *ptr;) + { + if (*ptr == '\\') + { + if (ptr[1]) + *ptr++ = '/'; + else + *ptr = '\0'; /* Strip trailing \ */ + } + else if (*ptr == '/' && !ptr[1]) + *ptr = '\0'; /* Strip trailing / */ + else + ptr ++; + } + } + + snprintf(confdir, sizeof(confdir), "%s/conf", installdir); + snprintf(localedir, sizeof(localedir), "%s/locale", installdir); } - snprintf(confdir, sizeof(confdir), "%s/conf", installdir); - snprintf(localedir, sizeof(localedir), "%s/locale", installdir); - if ((cg->cups_datadir = getenv("CUPS_DATADIR")) == NULL) cg->cups_datadir = installdir; @@ -295,27 +339,31 @@ cups_globals_alloc(void) * 'cups_globals_free()' - Free global data. */ +#if defined(HAVE_PTHREAD_H) || defined(WIN32) static void cups_globals_free(_cups_globals_t *cg) /* I - Pointer to global data */ { - _ipp_buffer_t *buffer, /* Current IPP read/write buffer */ + _cups_buffer_t *buffer, /* Current read/write buffer */ *next; /* Next buffer */ if (cg->last_status_message) _cupsStrFree(cg->last_status_message); - for (buffer = cg->ipp_buffers; buffer; buffer = next) + for (buffer = cg->cups_buffers; buffer; buffer = next) { next = buffer->next; free(buffer); } - cupsArrayDelete(cg->pwg_size_lut); cupsArrayDelete(cg->leg_size_lut); + cupsArrayDelete(cg->ppd_size_lut); + cupsArrayDelete(cg->pwg_size_lut); httpClose(cg->http); + _httpFreeCredentials(cg->tls_credentials); + cupsFileClose(cg->stdio_files[0]); cupsFileClose(cg->stdio_files[1]); cupsFileClose(cg->stdio_files[2]); @@ -324,6 +372,7 @@ cups_globals_free(_cups_globals_t *cg) /* I - Pointer to global data */ free(cg); } +#endif /* HAVE_PTHREAD_H || WIN32 */ #ifdef HAVE_PTHREAD_H @@ -344,5 +393,5 @@ cups_globals_init(void) /* - * End of "$Id: globals.c 7870 2008-08-27 18:14:10Z mike $". + * End of "$Id$". */