]> git.sesse.net Git - vlc/commitdiff
Add a proper API to set the user agent
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 8 Jul 2010 19:45:43 +0000 (22:45 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 8 Jul 2010 19:56:00 +0000 (22:56 +0300)
bin/vlc.c
include/vlc/libvlc.h
src/control/core.c
src/libvlc.c
src/libvlc.sym

index ef3a4b511e7ec3db1b57d38516f9d1fa02ecde4a..40fa96fbcaeb1d5636c0f1ffce27b66ae18a7f05 100644 (file)
--- a/bin/vlc.c
+++ b/bin/vlc.c
@@ -198,6 +198,8 @@ int main( int i_argc, const char *ppsz_argv[] )
     if (vlc == NULL)
         goto out;
 
+     libvlc_set_user_agent (vlc, "VLC media player", NULL);
+
 #if !defined (HAVE_MAEMO) && !defined __APPLE__
     libvlc_add_intf (vlc, "globalhotkeys,none");
 #endif
index d4151eb0f526590298183a0373d30589028a58b5..36b263feef32c270754f3b06ff778ecaeb363666 100644 (file)
@@ -171,6 +171,19 @@ void libvlc_set_exit_handler( libvlc_instance_t *p_instance,
 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.
  *
index 54e2fd03807d322a675318c2d1f3d0e5bc77bcd0..942212db77b72e65b65046bfdef25d03d74c95da 100644 (file)
@@ -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:
@@ -127,6 +129,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();
index 2f4a6a9bc47361674daeedf609d4bf76badd5866..1349eb67ae2bb599700ededeb90f481f2978c1c4 100644 (file)
@@ -761,8 +761,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 );
 
-    /* vout window provider */
+    /* some default internal settings */
     var_Create( p_libvlc, "window", VLC_VAR_STRING );
+    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) );
index fa92d462dbccb8115e0373de2ef2a3084923b681..0148c11e05d8769e2a9346ac4e73ae4c0697ac88 100644 (file)
@@ -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