]> git.sesse.net Git - vlc/blobdiff - src/misc/messages.c
Display IP of client in debug
[vlc] / src / misc / messages.c
index 3a2905a104397054769147bf335fd6a5cf57bf64..c26ab934568a01e4e43e4e66859f309d91f30356 100644 (file)
@@ -21,7 +21,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -45,6 +45,7 @@
 #endif
 
 #include "vlc_interface.h"
+#include "charset.h"
 
 /*****************************************************************************
  * Local macros
@@ -133,7 +134,7 @@ 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->msg_bank.i_queues -1 ; i >= 0;  i-- )
     {
         msg_queue_t *p_queue = p_this->p_libvlc->msg_bank.pp_queues[i];
         if( p_queue->i_sub )
@@ -148,6 +149,9 @@ void __msg_Destroy( vlc_object_t *p_this )
 #endif
         /* Destroy lock */
         vlc_mutex_destroy( &p_queue->lock );
+        REMOVE_ELEM( p_this->p_libvlc->msg_bank.pp_queues,
+                     p_this->p_libvlc->msg_bank.i_queues, i );
+        free( p_queue );
     }
     vlc_mutex_destroy( &(p_this->p_libvlc->msg_bank.lock) );
 }
@@ -292,22 +296,34 @@ 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 )
 {
-    msg_bank_t * p_bank = &p_this->p_libvlc->msg_bank;       /* message bank */
+    int         i_header_size;             /* Size of the additionnal header */
+    vlc_object_t *p_obj;
+    msg_bank_t  *p_bank;                                     /* message bank */
     msg_queue_t *p_queue = NULL;
     char *       psz_str = NULL;                 /* formatted message string */
+    char *       psz_header = NULL;
     va_list      args;
     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 == 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->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 );
@@ -320,13 +336,41 @@ 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;
     }
 
-#if !defined(HAVE_VASPRINTF) || defined(SYS_DARWIN) || defined(SYS_BEOS)
+    i_header_size = 0;
+    p_obj = p_this;
+    while( p_obj != NULL )
+    {
+        char *psz_old = NULL;
+        if( p_obj == NULL ) break;
+        if( p_obj->psz_header )
+        {
+            i_header_size += strlen( p_obj->psz_header ) + 4;
+            if( psz_header )
+            {
+                psz_old = strdup( psz_header );
+                psz_header = (char*)realloc( psz_header, i_header_size );
+                snprintf( psz_header, i_header_size , "[%s] %s",
+                          p_obj->psz_header, psz_old );
+            }
+            else
+            {
+                psz_header = (char *)malloc( i_header_size );
+                snprintf( psz_header, i_header_size, "[%s]",
+                          p_obj->psz_header );
+            }
+        }
+        if( psz_old ) free( psz_old );
+        p_obj = p_obj->p_parent;
+    }
+
+#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 );
@@ -343,7 +387,13 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
         }
     }
 
-    if( p_queue == NULL ) return;
+    if( p_queue == NULL )
+    {
+        vlc_mutex_unlock( &p_bank->lock );
+        if( psz_str ) free( psz_str );
+        if( psz_header ) free( psz_header );
+        return;
+    }
 
     vlc_mutex_lock( &p_queue->lock );
 
@@ -382,6 +432,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
                 p_item->i_object_type = p_this->i_object_type;
                 p_item->psz_module =    strdup( "message" );
                 p_item->psz_msg =       strdup( "message queue overflowed" );
+                p_item->psz_header =    NULL;
 
                PrintMsg( p_this, p_item );
                /* We print from a dummy item */
@@ -403,6 +454,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
     p_item->i_object_type = p_this->i_object_type;
     p_item->psz_module =    strdup( psz_module );
     p_item->psz_msg =       psz_str;
+    p_item->psz_header =    psz_header;
 
     if( p_queue->i_id == MSG_QUEUE_NORMAL )
         PrintMsg( p_this, p_item );
@@ -413,6 +465,8 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
             free( p_item->psz_module );
         if( p_item->psz_msg )
             free( p_item->psz_msg );
+        if( p_item->psz_header )
+            free( p_item->psz_header );
     }
 
     vlc_mutex_unlock ( &p_queue->lock );
@@ -459,6 +513,8 @@ static void FlushMsg ( msg_queue_t *p_queue )
             free( p_queue->msg[i_index].psz_msg );
         if( p_queue->msg[i_index].psz_module )
             free( p_queue->msg[i_index].psz_module );
+        if( p_queue->msg[i_index].psz_header )
+            free( p_queue->msg[i_index].psz_header );
     }
 
     /* Update the new start value */
@@ -518,7 +574,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;
@@ -542,16 +599,37 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
     /* Send the message to stderr */
     if( p_this->p_libvlc->b_color )
     {
-        fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
+        if( p_item->psz_header )
+        {
+            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,
+                         ppsz_type[i_type], ppsz_color[i_type],
+                         p_item->psz_msg );
+        }
+        else
+        {
+             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 );
+        }
     }
     else
     {
-        fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
+        if( p_item->psz_header )
+        {
+            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
+        {
+            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 );
+        }
     }
 
 #   if defined(WIN32)