Hi,
As discussed before
(http://subversion.tigris.org/servlets/BrowseList?list=dev&by=thread&from=620729),
I took another shot at this.
The attached patch introduces two new functions:
svn_ra_set_client_namestring and svn_ra_get_client_namestring to allow
the clients set the last part of the useragent string. The first part of
the useragent string is not changed, it's still "SVN/" with the svn
library version.
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.
* subversion/include/svn_ra.h
(svn_ra_set_client_namestring): new function.
(svn_ra_get_client_namestring): new function.
* subversion/libsvn_ra/clientstring.c : new file containing helper
functions
* subversion/libsvn_ra_neon/session.c
(svn_ra_neon__open)
subversion/libsvn_ra_serf/propfind_buckets.c
(become_request)
subversion/libsvn_ra_serf/util.c
(svn_ra_serf__setup_serf_req) : use svn_ra_get_client_namestring to
create the useragent string.
]]]
Index: subversion/include/svn_ra.h
===================================================================
--- subversion/include/svn_ra.h (revision 28326)
+++ subversion/include/svn_ra.h (working copy)
@@ -40,7 +40,29 @@
/* Misc. declarations */
+
/**
+ * Use @a name for the client string for http headers.
+ * Use @a pool for any temporary allocations.
+ *
+ * @note This function changes global (per-process) state and must be
+ * called in a single-threaded context during the initialization of a
+ * Subversion client.
+ *
+ * @since New in 1.5.
+ */
+svn_error_t *
+svn_ra_set_client_namestring(const char *name, apr_pool_t *pool);
+
+/**
+ * returns the svn client name string used in http headers
+ *
+ * @since New in 1.5.
+ */
+const char * svn_ra_get_client_namestring(apr_pool_t *pool);
+
+
+/**
* Get libsvn_ra version information.
*
* @since New in 1.1.
Index: subversion/libsvn_ra/clientstring.c
===================================================================
--- subversion/libsvn_ra/clientstring.c (revision 0)
+++ subversion/libsvn_ra/clientstring.c (revision 0)
@@ -0,0 +1,55 @@
+/*
+ * clientstring.c: client string handling for http headers.
+ *
+ * ====================================================================
+ * Copyright (c) 2007 CollabNet. All rights reserved.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://subversion.tigris.org/license-1.html.
+ * If newer versions of this license are posted there, you may use a
+ * newer version instead, at your option.
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals. For exact contribution history, see the revision
+ * history and logs, available at http://subversion.tigris.org/.
+ * ====================================================================
+ */
+
+/* ==================================================================== */
+
+/*** Includes. ***/
+#include <apr_pools.h>
+#include <apr_strings.h>
+
+#include "svn_error.h"
+#include "svn_error_codes.h"
+#include "svn_ra.h"
+
+
+/* The default client name string */
+static const char default_ra_client_name[] = "SVN";
+
+/* The client name string that is actually used. */
+static const char *ra_client_name = default_ra_client_name;
+
+
+
+const char *
+svn_ra_get_client_namestring(apr_pool_t *pool)
+{
+ return ra_client_name;
+}
+
+
+svn_error_t *
+svn_ra_set_client_namestring(const char *name, apr_pool_t *pool)
+{
+ apr_pool_t *rootpool;
+ if (apr_pool_create(&rootpool, NULL))
+ abort();
+
+ ra_client_name = apr_pstrdup(rootpool, name);
+
+ return SVN_NO_ERROR;
+}
Property changes on: subversion\libsvn_ra\clientstring.c
___________________________________________________________________
Added: svn:eol-style
+ native
Index: subversion/libsvn_ra_neon/session.c
===================================================================
--- subversion/libsvn_ra_neon/session.c (revision 28326)
+++ subversion/libsvn_ra_neon/session.c (working copy)
@@ -821,7 +821,14 @@
unsigned int neon_auth_types = 0;
neonprogress_baton_t *neonprogress_baton =
apr_pcalloc(pool, sizeof(*neonprogress_baton));
+ const char * useragent = NULL;
+ useragent = apr_pstrcat(pool,
+ "SVN/",
+ SVN_VERSION,
+ "/",
+ svn_ra_get_client_namestring(pool));
+
/* Sanity check the URI */
SVN_ERR(parse_url(uri, repos_URL));
@@ -930,8 +937,8 @@
ne_set_read_timeout(sess2, timeout);
}
- ne_set_useragent(sess, "SVN/" SVN_VERSION);
- ne_set_useragent(sess2, "SVN/" SVN_VERSION);
+ ne_set_useragent(sess, useragent);
+ ne_set_useragent(sess2, useragent);
/* clean up trailing slashes from the URL */
len = strlen(uri->path);
Index: subversion/libsvn_ra_serf/propfind_buckets.c
===================================================================
--- subversion/libsvn_ra_serf/propfind_buckets.c (revision 28326)
+++ subversion/libsvn_ra_serf/propfind_buckets.c (working copy)
@@ -141,10 +141,16 @@
{
prop_context_t *ctx = bucket->data;
serf_bucket_t *hdrs_bkt, *body_bkt;
+ const char * useragent = NULL;
+ useragent = apr_pstrcat(ctx->conn->session->pool,
+ USER_AGENT,
+ "/",
+ svn_ra_get_client_namestring(ctx->conn->session->pool));
body_bkt = create_propfind_body(bucket);
serf_bucket_request_become(bucket, "PROPFIND", ctx->path, body_bkt);
+
#if SERF_VERSION_AT_LEAST(0,1,3)
if (ctx->conn->session->using_proxy)
{
@@ -158,7 +164,7 @@
hdrs_bkt = serf_bucket_request_get_headers(bucket);
serf_bucket_headers_setn(hdrs_bkt, "Host", ctx->conn->hostinfo);
- serf_bucket_headers_setn(hdrs_bkt, "User-Agent", USER_AGENT);
+ serf_bucket_headers_setn(hdrs_bkt, "User-Agent", useragent);
if (ctx->conn->using_compression == TRUE)
{
serf_bucket_headers_setn(hdrs_bkt, "Accept-Encoding", "gzip");
Index: subversion/libsvn_ra_serf/util.c
===================================================================
--- subversion/libsvn_ra_serf/util.c (revision 28326)
+++ subversion/libsvn_ra_serf/util.c (working copy)
@@ -265,13 +265,19 @@
serf_bucket_t *body_bkt, const char *content_type)
{
serf_bucket_t *hdrs_bkt;
+ const char * useragent = NULL;
+ useragent = apr_pstrcat(conn->session->pool,
+ USER_AGENT,
+ "/",
+ svn_ra_get_client_namestring(conn->session->pool));
+
*req_bkt = serf_bucket_request_create(method, url, body_bkt,
serf_request_get_alloc(request));
hdrs_bkt = serf_bucket_request_get_headers(*req_bkt);
serf_bucket_headers_setn(hdrs_bkt, "Host", conn->hostinfo);
- serf_bucket_headers_setn(hdrs_bkt, "User-Agent", USER_AGENT);
+ serf_bucket_headers_setn(hdrs_bkt, "User-Agent", useragent);
if (content_type)
{
serf_bucket_headers_setn(hdrs_bkt, "Content-Type", content_type);
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Dec 7 21:14:31 2007