From: mike Date: Fri, 18 Jan 2013 17:44:52 +0000 (+0000) Subject: Rework User-Agent stuff to store the default as a CUPS "global" default. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c35095b62f43605942400acfa4736723ecb54a5e;p=thirdparty%2Fcups.git Rework User-Agent stuff to store the default as a CUPS "global" default. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@10823 7a7537e8-13f0-0310-91df-b6672ffda945 --- diff --git a/cups/cups-private.h b/cups/cups-private.h index 3d8aaf2406..433ee0c93c 100644 --- a/cups/cups-private.h +++ b/cups/cups-private.h @@ -151,6 +151,7 @@ typedef struct _cups_globals_s /**** CUPS global state data ****/ /* usersys.c */ http_encryption_t encryption; /* Encryption setting */ char user[65], /* User name */ + user_agent[256],/* User-Agent string */ server[256], /* Server address */ servername[256],/* Server hostname */ password[128]; /* Password for default callback */ diff --git a/cups/cups.h b/cups/cups.h index 3277364bf6..78645d3838 100644 --- a/cups/cups.h +++ b/cups/cups.h @@ -590,6 +590,11 @@ extern http_status_t cupsStartDestDocument(http_t *http, cups_dest_t *dest, cups_option_t *options, int last_document) _CUPS_API_1_6; +/* New in CUPS 1.7 */ +extern void cupsSetUserAgent(const char *user_agent) _CUPS_API_1_7; +extern const char *cupsUserAgent(void) _CUPS_API_1_7; + + # ifdef __cplusplus } # endif /* __cplusplus */ diff --git a/cups/http.c b/cups/http.c index 0121fc6371..c7bd394271 100644 --- a/cups/http.c +++ b/cups/http.c @@ -3,7 +3,7 @@ * * HTTP routines for CUPS. * - * Copyright 2007-2012 by Apple Inc. + * Copyright 2007-2013 by Apple Inc. * Copyright 1997-2007 by Easy Software Products, all rights reserved. * * This file contains Kerberos support code, copyright 2006 by @@ -152,7 +152,6 @@ # include # include # include -# include #endif /* WIN32 */ #ifdef HAVE_POLL # include @@ -4795,43 +4794,9 @@ http_send(http_t *http, /* I - Connection to server */ if (!http->fields[HTTP_FIELD_USER_AGENT][0]) { if (http->default_user_agent) - { httpSetField(http, HTTP_FIELD_USER_AGENT, http->default_user_agent); - } else - { -#ifdef WIN32 - SYSTEM_INFO sysinfo; /* System information */ - OSVERSIONEX version; /* OS version info */ - - version.dwOSVersionInfoSize = sizeof(OSVERSIONEX); - GetVersionInfoEx(&version); - GetNativeSystemInfo(&sysinfo); - - snprintf(buf, sizeof(buf), CUPS_MINIMAL " (Windows %d.%d; %s) IPP/2.0", - version.major, version.minor, - sysinfo.wProcessorArchitecture - == PROCESSOR_ARCHITECTURE_AMD64 ? "amd64" : - sysinfo.wProcessorArchitecture - == PROCESSOR_ARCHITECTURE_ARM ? "arm" : - sysinfo.wProcessorArchitecture - == PROCESSOR_ARCHITECTURE_IA64 ? "ia64" : - sysinfo.wProcessorArchitecture - == PROCESSOR_ARCHITECTURE_INTEL ? "intel" : - "unknown"); - -#else - struct utsname name; /* uname info */ - - uname(&name); - - snprintf(buf, sizeof(buf), CUPS_MINIMAL " (%s %s; %s) IPP/2.0", - name.sysname, name.release, name.machine); -#endif /* WIN32 */ - - DEBUG_printf(("8http_send: Default User-Agent: %s", buf)); - httpSetField(http, HTTP_FIELD_USER_AGENT, buf); - } + httpSetField(http, HTTP_FIELD_USER_AGENT, cupsUserAgent()); } /* diff --git a/cups/usersys.c b/cups/usersys.c index ca5ba3c429..fc2ed9ceda 100644 --- a/cups/usersys.c +++ b/cups/usersys.c @@ -3,7 +3,7 @@ * * User, system, and password routines for CUPS. * - * Copyright 2007-2012 by Apple Inc. + * Copyright 2007-2013 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -16,20 +16,24 @@ * * Contents: * - * cupsEncryption() - Get the current encryption settings. - * cupsGetPassword() - Get a password from the user. + * cupsEncryption() - Get the current encryption settings. + * cupsGetPassword() - Get a password from the user. * cupsGetPassword2() - Get a password from the user using the advanced - * password callback. - * cupsServer() - Return the hostname/address of the current - * server. + * password callback. + * cupsServer() - Return the hostname/address of the current + * server. * cupsSetClientCertCB() - Set the client certificate callback. + * cupsSetCredentials() - Set the default credentials to be used for + * SSL/TLS connections. * cupsSetEncryption() - Set the encryption preference. * cupsSetPasswordCB() - Set the password callback for CUPS. * cupsSetPasswordCB2() - Set the advanced password callback for CUPS. - * cupsSetServer() - Set the default server name and port. + * cupsSetServer() - Set the default server name and port. * cupsSetServerCertCB() - Set the server certificate callback. - * cupsSetUser() - Set the default user name. - * cupsUser() - Return the current user's name. + * cupsSetUser() - Set the default user name. + * cupsSetUserAgent() - Set the default HTTP User-Agent string. + * cupsUser() - Return the current user's name. + * cupsUserAgent() - Return the default HTTP User-Agent string. * _cupsGetPassword() - Get a password from the user. * _cupsGSSServiceName() - Get the GSS (Kerberos) service name. * _cupsSetDefaults() - Set the default server, port, and encryption. @@ -48,6 +52,7 @@ #else # include # include +# include #endif /* WIN32 */ @@ -442,6 +447,62 @@ cupsSetUser(const char *user) /* I - User name */ } +/* + * 'cupsSetUserAgent()' - Set the default HTTP User-Agent string. + * + * Setting the string to NULL forces the default value containing the CUPS + * version, IPP version, and operating system version and architecture. + * + * @since CUPS 1.7@ + */ + +void +cupsSetUserAgent(const char *user_agent)/* I - User-Agent string or @code NULL@ */ +{ + _cups_globals_t *cg = _cupsGlobals(); + /* Thread globals */ +#ifdef WIN32 + SYSTEM_INFO sysinfo; /* System information */ + OSVERSIONEX version; /* OS version info */ +#else + struct utsname name; /* uname info */ +#endif /* WIN32 */ + + + if (user_agent) + { + strlcpy(cg->user_agent, user_agent, sizeof(cg->user_agent)); + return; + } + +#ifdef WIN32 + version.dwOSVersionInfoSize = sizeof(OSVERSIONEX); + GetVersionInfoEx(&version); + GetNativeSystemInfo(&sysinfo); + + snprintf(cg->user_agent, sizeof(cg->user_agent), + CUPS_MINIMAL " (Windows %d.%d; %s) IPP/2.0", + version.major, version.minor, + sysinfo.wProcessorArchitecture + == PROCESSOR_ARCHITECTURE_AMD64 ? "amd64" : + sysinfo.wProcessorArchitecture + == PROCESSOR_ARCHITECTURE_ARM ? "arm" : + sysinfo.wProcessorArchitecture + == PROCESSOR_ARCHITECTURE_IA64 ? "ia64" : + sysinfo.wProcessorArchitecture + == PROCESSOR_ARCHITECTURE_INTEL ? "intel" : + "unknown"); + +#else + uname(&name); + + snprintf(cg->user_agent, sizeof(cg->user_agent), + CUPS_MINIMAL " (%s %s; %s) IPP/2.0", + name.sysname, name.release, name.machine); +#endif /* WIN32 */ +} + + /* * 'cupsUser()' - Return the current user's name. * @@ -464,6 +525,25 @@ cupsUser(void) } +/* + * 'cupsUserAgent()' - Return the default HTTP User-Agent string. + * + * @since CUPS 1.7@ + */ + +const char * /* O - User-Agent string */ +cupsUserAgent(void) +{ + _cups_globals_t *cg = _cupsGlobals(); /* Thread globals */ + + + if (!cg->user_agent[0]) + cupsSetUserAgent(NULL); + + return (cg->user_agent); +} + + /* * '_cupsGetPassword()' - Get a password from the user. */