]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Rework User-Agent stuff to store the default as a CUPS "global" default.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 18 Jan 2013 17:44:52 +0000 (17:44 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 18 Jan 2013 17:44:52 +0000 (17:44 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@10823 7a7537e8-13f0-0310-91df-b6672ffda945

cups/cups-private.h
cups/cups.h
cups/http.c
cups/usersys.c

index 3d8aaf240665b242f6d9ed8c6da7310e3f6398f2..433ee0c93c1597a798515342e36e7e7bb3b72cd6 100644 (file)
@@ -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 */
index 3277364bf63b05ca2bac6cbcb7526e74480c9599..78645d3838996c020e3fe3d27a5dc5b90585435f 100644 (file)
@@ -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 */
index 0121fc63714a149864f5e0530c20105919a1dc86..c7bd394271cbcc815d81fd6197cbcbe5779e3184 100644 (file)
@@ -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
 #  include <signal.h>
 #  include <sys/time.h>
 #  include <sys/resource.h>
-#  include <sys/utsname.h>
 #endif /* WIN32 */
 #ifdef HAVE_POLL
 #  include <poll.h>
@@ -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());
   }
 
  /*
index ca5ba3c4297156d0fccab2c619357b3f81eabf68..fc2ed9ceda898d631cf3a671d0c9a23c2a95b6da 100644 (file)
@@ -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
  *
  * 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 <pwd.h>
 #  include <termios.h>
+#  include <sys/utsname.h>
 #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.
  */