]> git.sesse.net Git - vlc/blobdiff - src/misc/messages.c
For consistency, remove references to vlc from libvlc
[vlc] / src / misc / messages.c
index 2f2fcd0b88a094cdb27be0974d2d5d59a397f485..a83821ee6779ecf135518299e26712a3c9480dba 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+
+#include <vlc/vlc.h>
+
 #include <stdio.h>                                               /* required */
 #include <stdarg.h>                                       /* va_list for BSD */
 #include <stdlib.h>                                              /* malloc() */
 #include <string.h>                                            /* strerror() */
 
-#include <vlc/vlc.h>
 
 #ifdef HAVE_FCNTL_H
 #   include <fcntl.h>                  /* O_CREAT, O_TRUNC, O_WRONLY, O_SYNC */
@@ -45,6 +47,7 @@
 #endif
 
 #include "vlc_interface.h"
+#include "charset.h"
 
 /*****************************************************************************
  * Local macros
@@ -72,17 +75,17 @@ static void CreateMsgQueue( vlc_object_t *p_this, int i_queue );
  */
 void __msg_Create( vlc_object_t *p_this )
 {
-    vlc_mutex_init( p_this, &(p_this->p_libvlc->msg_bank.lock) );
+    vlc_mutex_init( p_this, &(p_this->p_libvlc_global->msg_bank.lock) );
 
     CreateMsgQueue( p_this, MSG_QUEUE_NORMAL );
     CreateMsgQueue( p_this, MSG_QUEUE_HTTPD_ACCESS );
 
 #ifdef UNDER_CE
-    p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile =
+    p_this->p_libvlc_global->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile =
         CreateFile( L"vlc-log.txt", GENERIC_WRITE,
                     FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
                     CREATE_ALWAYS, 0, NULL );
-    SetFilePointer( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->
+    SetFilePointer( p_this->p_libvlc_global->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->
                                      logfile, 0, NULL, FILE_END );
 #endif
 
@@ -102,8 +105,8 @@ static void CreateMsgQueue( vlc_object_t *p_this, int i_queue )
     p_queue->i_sub = 0;
     p_queue->pp_sub = NULL;
 
-    INSERT_ELEM( p_this->p_libvlc->msg_bank.pp_queues,
-                 p_this->p_libvlc->msg_bank.i_queues,
+    INSERT_ELEM( p_this->p_libvlc_global->msg_bank.pp_queues,
+                 p_this->p_libvlc_global->msg_bank.i_queues,
                  i_queue,
                  p_queue );
 }
@@ -115,11 +118,11 @@ void __msg_Flush( vlc_object_t *p_this )
 {
     int i;
 
-    for( i = 0 ; i < p_this->p_libvlc->msg_bank.i_queues; i++ )
+    for( i = 0 ; i < p_this->p_libvlc_global->msg_bank.i_queues; i++ )
     {
-        vlc_mutex_lock( &p_this->p_libvlc->msg_bank.pp_queues[i]->lock );
-        FlushMsg( p_this->p_libvlc->msg_bank.pp_queues[i] );
-        vlc_mutex_unlock( &p_this->p_libvlc->msg_bank.pp_queues[i]->lock );
+        vlc_mutex_lock( &p_this->p_libvlc_global->msg_bank.pp_queues[i]->lock );
+        FlushMsg( p_this->p_libvlc_global->msg_bank.pp_queues[i] );
+        vlc_mutex_unlock( &p_this->p_libvlc_global->msg_bank.pp_queues[i]->lock );
     }
 }
 
@@ -133,9 +136,9 @@ void __msg_Flush( vlc_object_t *p_this )
 void __msg_Destroy( vlc_object_t *p_this )
 {
     int i;
-    for( i =  0 ; i < p_this->p_libvlc->msg_bank.i_queues; i++ )
+    for( i = p_this->p_libvlc_global->msg_bank.i_queues -1 ; i >= 0;  i-- )
     {
-        msg_queue_t *p_queue = p_this->p_libvlc->msg_bank.pp_queues[i];
+        msg_queue_t *p_queue = p_this->p_libvlc_global->msg_bank.pp_queues[i];
         if( p_queue->i_sub )
         {
             msg_Err( p_this, "stale interface subscribers" );
@@ -144,12 +147,15 @@ void __msg_Destroy( vlc_object_t *p_this )
 
 #ifdef UNDER_CE
         if( i == MSG_QUEUE_NORMAL )
-            CloseHandle( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile );
+            CloseHandle( p_this->p_libvlc_global->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile );
 #endif
         /* Destroy lock */
         vlc_mutex_destroy( &p_queue->lock );
+        REMOVE_ELEM( p_this->p_libvlc_global->msg_bank.pp_queues,
+                     p_this->p_libvlc_global->msg_bank.i_queues, i );
+        free( p_queue );
     }
-    vlc_mutex_destroy( &(p_this->p_libvlc->msg_bank.lock) );
+    vlc_mutex_destroy( &(p_this->p_libvlc_global->msg_bank.lock) );
 }
 
 /**
@@ -157,7 +163,7 @@ void __msg_Destroy( vlc_object_t *p_this )
  */
 msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i_queue )
 {
-    msg_bank_t *p_bank = &p_this->p_libvlc->msg_bank;
+    msg_bank_t *p_bank = &p_this->p_libvlc_global->msg_bank;
     msg_subscription_t *p_sub = malloc( sizeof( msg_subscription_t ) );
     msg_queue_t *p_queue = NULL;
     int i;
@@ -203,7 +209,7 @@ msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i_queue )
  */
 void __msg_Unsubscribe( vlc_object_t *p_this, msg_subscription_t *p_sub )
 {
-    msg_bank_t *p_bank = &p_this->p_libvlc->msg_bank;
+    msg_bank_t *p_bank = &p_this->p_libvlc_global->msg_bank;
     int i,j;
 
     vlc_mutex_lock( &p_bank->lock );
@@ -292,9 +298,9 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
                       const char *psz_module,
                       const char *psz_format, va_list _args )
 {
-    int         i_header_size;               /* Size of the additionnal header */
+    int         i_header_size;             /* Size of the additionnal header */
     vlc_object_t *p_obj;
-    msg_bank_t * p_bank = &p_this->p_libvlc->msg_bank;       /* message bank */
+    msg_bank_t  *p_bank;                                     /* message bank */
     msg_queue_t *p_queue = NULL;
     char *       psz_str = NULL;                 /* formatted message string */
     char *       psz_header = NULL;
@@ -302,22 +308,23 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
     msg_item_t * p_item = NULL;                        /* pointer to message */
     msg_item_t   item;                    /* message in case of a full queue */
 
-#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
+#if !defined(HAVE_VASPRINTF) || defined(__APPLE__) || defined(SYS_BEOS)
     int          i_size = strlen(psz_format) + INTF_MAX_MSG_SIZE;
 #endif
     int i;
 
-    if( p_this->i_flags & OBJECT_FLAGS_QUIET ||
-        (p_this->i_flags & OBJECT_FLAGS_NODBG &&
-         i_type == VLC_MSG_DBG ) )
+    if( p_this == NULL || p_this->i_flags & OBJECT_FLAGS_QUIET ||
+        (p_this->i_flags & OBJECT_FLAGS_NODBG && i_type == VLC_MSG_DBG) )
     {
         return;
     }
 
+    p_bank = &p_this->p_libvlc_global->msg_bank;
+
     /*
      * Convert message to string
      */
-#if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined( SYS_BEOS )
+#if defined(HAVE_VASPRINTF) && !defined(__APPLE__) && !defined( SYS_BEOS )
     vlc_va_copy( args, _args );
     vasprintf( &psz_str, psz_format, args );
     va_end( args );
@@ -330,9 +337,10 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
         fprintf( stderr, "main warning: can't store message (%s): ",
                  strerror(errno) );
         vlc_va_copy( args, _args );
+        /* We should use utf8_vfprintf - but it calls malloc()... */
         vfprintf( stderr, psz_format, args );
         va_end( args );
-        fprintf( stderr, "\n" );
+        fputs( "\n", stderr );
         return;
     }
 
@@ -363,7 +371,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
         p_obj = p_obj->p_parent;
     }
 
-#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
+#if !defined(HAVE_VASPRINTF) || defined(__APPLE__) || defined(SYS_BEOS)
     vlc_va_copy( args, _args );
     vsnprintf( psz_str, i_size, psz_format, args );
     va_end( args );
@@ -539,23 +547,23 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
     switch( i_type )
     {
         case VLC_MSG_ERR:
-            if( p_this->p_libvlc->i_verbose < 0 ) return;
+            if( p_this->p_libvlc_global->i_verbose < 0 ) return;
             break;
         case VLC_MSG_INFO:
-            if( p_this->p_libvlc->i_verbose < 0 ) return;
+            if( p_this->p_libvlc_global->i_verbose < 0 ) return;
             break;
         case VLC_MSG_WARN:
-            if( p_this->p_libvlc->i_verbose < 1 ) return;
+            if( p_this->p_libvlc_global->i_verbose < 1 ) return;
             break;
         case VLC_MSG_DBG:
-            if( p_this->p_libvlc->i_verbose < 2 ) return;
+            if( p_this->p_libvlc_global->i_verbose < 2 ) return;
             break;
     }
 
     switch( p_item->i_object_type )
     {
         case VLC_OBJECT_ROOT: psz_object = "root"; break;
-        case VLC_OBJECT_VLC: psz_object = "vlc"; break;
+        case VLC_OBJECT_LIBVLC: psz_object = "libvlc"; break;
         case VLC_OBJECT_MODULE: psz_object = "module"; break;
         case VLC_OBJECT_INTF: psz_object = "interface"; break;
         case VLC_OBJECT_PLAYLIST: psz_object = "playlist"; break;
@@ -567,7 +575,8 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
         case VLC_OBJECT_VOUT: psz_object = "video output"; break;
         case VLC_OBJECT_AOUT: psz_object = "audio output"; break;
         case VLC_OBJECT_SOUT: psz_object = "stream output"; break;
-        case VLC_OBJECT_HTTPD: psz_object = "http daemon"; break;
+        case VLC_OBJECT_HTTPD: psz_object = "http server"; break;
+        case VLC_OBJECT_HTTPD_HOST: psz_object = "http server"; break;
         case VLC_OBJECT_DIALOGS: psz_object = "dialogs provider"; break;
         case VLC_OBJECT_VLM: psz_object = "vlm"; break;
         case VLC_OBJECT_ANNOUNCE: psz_object = "announce handler"; break;
@@ -576,7 +585,7 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
     }
 
 #ifdef UNDER_CE
-#   define CE_WRITE(str) WriteFile( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile, \
+#   define CE_WRITE(str) WriteFile( p_this->p_libvlc_global->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile, \
                                     str, strlen(str), &i_dummy, NULL );
     CE_WRITE( p_item->psz_module );
     CE_WRITE( " " );
@@ -585,15 +594,15 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
     CE_WRITE( ": " );
     CE_WRITE( p_item->psz_msg );
     CE_WRITE( "\r\n" );
-    FlushFileBuffers( p_this->p_libvlc->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile );
+    FlushFileBuffers( p_this->p_libvlc_global->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile );
 
 #else
     /* Send the message to stderr */
-    if( p_this->p_libvlc->b_color )
+    if( p_this->p_libvlc_global->b_color )
     {
         if( p_item->psz_header )
         {
-            fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s %s%s: %s%s" GRAY
+            utf8_fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s %s%s: %s%s" GRAY
                               "\n",
                          p_item->i_object_id, p_item->psz_header,
                          p_item->psz_module, psz_object,
@@ -602,7 +611,7 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
         }
         else
         {
-             fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
+             utf8_fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
                          p_item->i_object_id, p_item->psz_module, psz_object,
                          ppsz_type[i_type], ppsz_color[i_type],
                          p_item->psz_msg );
@@ -612,13 +621,13 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
     {
         if( p_item->psz_header )
         {
-            fprintf( stderr, "[%.8i] %s %s %s%s: %s\n", p_item->i_object_id,
+            utf8_fprintf( stderr, "[%.8i] %s %s %s%s: %s\n", p_item->i_object_id,
                          p_item->psz_header, p_item->psz_module,
                          psz_object, ppsz_type[i_type], p_item->psz_msg );
         }
         else
         {
-            fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
+            utf8_fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
                          p_item->psz_module, psz_object, ppsz_type[i_type],
                          p_item->psz_msg );
         }