[vlc-commits] commit: Add a proper API to set the user agent ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Thu Jul 8 22:01:39 CEST 2010


vlc/vlc-1.1 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jul  8 22:59:48 2010 +0300| [2618ee6c4dde6b98ed25e16a4b9e08851930fbd3] | committer: Rémi Denis-Courmont 

Add a proper API to set the user agent

(cherry picked from commit 7f9b7d3e31101f97831b2e62ca25dc671de14c6b)

Conflicts:

	bin/vlc.c
	src/libvlc.c

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=2618ee6c4dde6b98ed25e16a4b9e08851930fbd3
---

 bin/vlc.c            |    2 ++
 include/vlc/libvlc.h |   13 +++++++++++++
 src/control/core.c   |   12 ++++++++++++
 src/libvlc.c         |    4 ++++
 src/libvlc.sym       |    1 +
 5 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/bin/vlc.c b/bin/vlc.c
index 759bc32..51633b2 100644
--- a/bin/vlc.c
+++ b/bin/vlc.c
@@ -182,6 +182,8 @@ int main( int i_argc, const char *ppsz_argv[] )
 
     if (vlc != NULL)
     {
+        libvlc_set_user_agent (vlc, "VLC media player", NULL);
+
         if (libvlc_add_intf (vlc, "signals"))
             pthread_sigmask (SIG_UNBLOCK, &set, NULL);
 #if !defined (HAVE_MAEMO) && !defined __APPLE__
diff --git a/include/vlc/libvlc.h b/include/vlc/libvlc.h
index 2b67cf0..a24d6eb 100644
--- a/include/vlc/libvlc.h
+++ b/include/vlc/libvlc.h
@@ -156,6 +156,19 @@ VLC_PUBLIC_API
 void libvlc_wait( libvlc_instance_t *p_instance );
 
 /**
+ * Sets the application name. LibVLC passes this as the user agent string
+ * when a protocol requires it.
+ *
+ * \param p_instance LibVLC instance
+ * \param name human-readable application name, e.g. "FooBar player 1.2.3"
+ * \param http HTTP User Agent, e.g. "FooBar/1.2.3 Python/2.6.0"
+ * \version LibVLC 1.1.1 or later
+ */
+VLC_PUBLIC_API
+void libvlc_set_user_agent( libvlc_instance_t *p_instance,
+                            const char *name, const char *http );
+
+/**
  * Retrieve libvlc version.
  *
  * Example: "1.1.0-git The Luggage"
diff --git a/src/control/core.c b/src/control/core.c
index a0a5278..4b6b77d 100644
--- a/src/control/core.c
+++ b/src/control/core.c
@@ -69,6 +69,8 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv )
     p_new->verbosity = 1;
     p_new->p_callback_list = NULL;
     vlc_mutex_init(&p_new->instance_lock);
+    var_Create( p_libvlc_int, "http-user-agent",
+                VLC_VAR_STRING|VLC_VAR_DOINHERIT );
     return p_new;
 
 error:
@@ -120,6 +122,16 @@ void libvlc_wait( libvlc_instance_t *p_i )
     libvlc_InternalWait( p_libvlc );
 }
 
+void libvlc_set_user_agent (libvlc_instance_t *p_i,
+                            const char *name, const char *http)
+{
+    libvlc_int_t *p_libvlc = p_i->p_libvlc_int;
+
+    var_SetString (p_libvlc, "user-agent", name);
+    if (http != NULL)
+        var_SetString (p_libvlc, "http-user-agent", http);
+}
+
 const char * libvlc_get_version(void)
 {
     return VLC_Version();
diff --git a/src/libvlc.c b/src/libvlc.c
index 06449a9..cb73175 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -802,6 +802,10 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING );
     var_Create( p_libvlc, "record-file", VLC_VAR_STRING );
 
+    /* some default internal settings */
+    var_Create( p_libvlc, "user-agent", VLC_VAR_STRING );
+    var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" );
+
     /* Initialize playlist and get commandline files */
     p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) );
     if( !p_playlist )
diff --git a/src/libvlc.sym b/src/libvlc.sym
index 671643c..c9bc222 100644
--- a/src/libvlc.sym
+++ b/src/libvlc.sym
@@ -160,6 +160,7 @@ libvlc_release
 libvlc_retain
 libvlc_set_fullscreen
 libvlc_set_log_verbosity
+libvlc_set_user_agent
 libvlc_toggle_fullscreen
 libvlc_toggle_teletext
 libvlc_track_description_release



More information about the vlc-commits mailing list