[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Allow custom user agent string

From: Stefan Küng <tortoisesvn_at_gmail.com>
Date: 2007-11-15 21:37:20 CET

C. Michael Pilato wrote:
> David Glasser wrote:
>> On Nov 15, 2007 12:08 PM, C. Michael Pilato <cmpilato@collab.net> wrote:
>>> Stefan Küng wrote:
>>>> Hi,
>>>>
>>>> The attached patch removes the fixed user-agent strings used in the svn
>>>> library and replaces them with a define. That way, svn clients can set
>>>> that define to a custom user-agent string when compiling the library.
>>>>
>>>> If the client does not define a custom user-agent string, a default
>>>> ("SVN/") is used (the same as before).
>>> Stefan, are you aware of the fact that mod_dav_svn actually pays attention
>>> the User-Agent header, specifically searching for those which begin with
>>> "SVN/"? This is used in the LOCK handling code and, I think, the GET
>>> response handler, too.
>> How about adding a parenthesized identifier, like web browsers do?
>
> +1.
>
> We just need a #define for CUSTOM_USER_AGENT that our libraries use like so:
>
> "User-Agent: SVN/" SVN_VERSION " (" CUSTOM_USER_AGENT ")"
>
> (Or maybe we just ask that the CUSTOM_USER_AGENT value include the space and
> parens ... whatever's easiest.)

See attached patch. I haven't checked, but if mod_dav_svn only checks
the beginning of the user-agent string, then this should work.

Stefan

-- 
        ___
   oo  // \\      "De Chelonian Mobile"
  (_,\/ \_/ \     TortoiseSVN
    \ \_/_\_/>    The coolest Interface to (Sub)Version Control
    /_/   \_\     http://tortoisesvn.net

[[[
Allow the user-agent string sent over http to be defined by the
client. The define CLIENT_USER_AGENT is used as the string. If it is
not defined, the default "SVN/" is used.

* subversion/libsvn_ra_neon/session.c,
  subversion/libsvn_ra_serf/ra_serf.h : use define for user agent
    string instead of fixed string.
]]]
Index: subversion/libsvn_ra_neon/session.c
===================================================================
--- subversion/libsvn_ra_neon/session.c (revision 27831)
+++ subversion/libsvn_ra_neon/session.c (working copy)
@@ -44,6 +44,7 @@
 
 #define DEFAULT_HTTP_TIMEOUT 3600
 
+
 
 /* a cleanup routine attached to the pool that contains the RA session
    baton. */
@@ -930,9 +931,13 @@
     ne_set_read_timeout(sess2, timeout);
   }
 
+#ifdef CLIENT_USER_AGENT
+ ne_set_useragent(sess, "SVN/" SVN_VERSION " (" APR_STRINGIFY(CLIENT_USER_AGENT) ")");
+ ne_set_useragent(sess2,"SVN/" SVN_VERSION " (" APR_STRINGIFY(CLIENT_USER_AGENT) ")");
+#else
   ne_set_useragent(sess, "SVN/" SVN_VERSION);
- ne_set_useragent(sess2, "SVN/" SVN_VERSION);
-
+ ne_set_useragent(sess2,"SVN/" SVN_VERSION);
+#endif
   /* clean up trailing slashes from the URL */
   len = strlen(uri->path);
   if (len > 1 && (uri->path)[len - 1] == '/')
@@ -1206,4 +1211,4 @@
 #define VTBL neon_vtable
 #define INITFUNC svn_ra_neon__init
 #define COMPAT_INITFUNC svn_ra_dav_init
-#include "../libsvn_ra/wrapper_template.h"
+#include "../libsvn_ra/wrapper_template.h"
\ No newline at end of file
Index: subversion/libsvn_ra_serf/ra_serf.h
===================================================================
--- subversion/libsvn_ra_serf/ra_serf.h (revision 27831)
+++ subversion/libsvn_ra_serf/ra_serf.h (working copy)
@@ -38,11 +38,22 @@
 /** Use this to silence compiler warnings about unused parameters. */
 #define UNUSED_CTX(x) ((void)(x))
 
+#ifndef CLIENT_USER_AGENT
+#define CLIENT_USER_AGENT SVN/
+#endif
 /** Our User-Agent string. */
-#define USER_AGENT "SVN/" SVN_VERSION " serf/" \
+#ifdef CLIENT_USER_AGENT
+#define USER_AGENT SVN_VERSION " serf/" \
                    APR_STRINGIFY(SERF_MAJOR_VERSION) "." \
                    APR_STRINGIFY(SERF_MINOR_VERSION) "." \
+ APR_STRINGIFY(SERF_PATCH_VERSION) \
+ " (" APR_STRINGIFY(CLIENT_USER_AGENT) ")"
+#else
+#define USER_AGENT SVN_VERSION " serf/" \
+ APR_STRINGIFY(SERF_MAJOR_VERSION) "." \
+ APR_STRINGIFY(SERF_MINOR_VERSION) "." \
                    APR_STRINGIFY(SERF_PATCH_VERSION)
+#endif
 
 
 /* Forward declarations. */
@@ -1238,4 +1249,4 @@
                          serf_bucket_t *response,
                          apr_pool_t *pool);
 
-#endif /* SVN_LIBSVN_RA_SERF_RA_SERF_H */
+#endif /* SVN_LIBSVN_RA_SERF_RA_SERF_H */
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Nov 15 21:38:04 2007

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.