]> git.sesse.net Git - vlc/blob - src/misc/messages.c
Privatize msg_bank
[vlc] / src / misc / messages.c
1 /*****************************************************************************
2  * messages.c: messages interface
3  * This library provides an interface to the message queue to be used by other
4  * modules, especially intf modules. See vlc_config.h for output configuration.
5  *****************************************************************************
6  * Copyright (C) 1998-2005 the VideoLAN team
7  * $Id$
8  *
9  * Authors: Vincent Seguin <seguin@via.ecp.fr>
10  *          Samuel Hocevar <sam@zoy.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <vlc/vlc.h>
36
37 #include <stdarg.h>                                       /* va_list for BSD */
38
39 #ifdef HAVE_FCNTL_H
40 #   include <fcntl.h>                  /* O_CREAT, O_TRUNC, O_WRONLY, O_SYNC */
41 #endif
42
43 #include <errno.h>                                                  /* errno */
44
45 #ifdef WIN32
46 #   include <vlc_network.h>          /* 'net_strerror' and 'WSAGetLastError' */
47 #endif
48
49 #ifdef HAVE_UNISTD_H
50 #   include <unistd.h>                                   /* close(), write() */
51 #endif
52
53 #include <assert.h>
54
55 #include <vlc_charset.h>
56 #include "../libvlc.h"
57
58 /*****************************************************************************
59  * Local macros
60  *****************************************************************************/
61 #if defined(HAVE_VA_COPY)
62 #   define vlc_va_copy(dest,src) va_copy(dest,src)
63 #elif defined(HAVE___VA_COPY)
64 #   define vlc_va_copy(dest,src) __va_copy(dest,src)
65 #else
66 #   define vlc_va_copy(dest,src) (dest)=(src)
67 #endif
68
69 #define QUEUE(i) priv->msg_bank.queues[i]
70 #define LOCK_BANK vlc_mutex_lock( &priv->msg_bank.lock );
71 #define UNLOCK_BANK vlc_mutex_unlock( &priv->msg_bank.lock );
72
73 /*****************************************************************************
74  * Local prototypes
75  *****************************************************************************/
76 static void QueueMsg ( vlc_object_t *, int, int , const char *,
77                        const char *, va_list );
78 static void FlushMsg ( msg_queue_t * );
79 static void PrintMsg ( vlc_object_t *, msg_item_t * );
80
81 /**
82  * Initialize messages queues
83  * This function initializes all message queues
84  */
85 void __msg_Create( vlc_object_t *p_this )
86 {
87     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
88     vlc_mutex_init( &priv->msg_bank.lock );
89
90     for( int i = 0; i < 2; i++ )
91     {
92          vlc_mutex_init( &QUEUE(i).lock );
93          QUEUE(i).b_overflow = false;
94          QUEUE(i).i_id = i;
95          QUEUE(i).i_start = 0;
96          QUEUE(i).i_stop = 0;
97          QUEUE(i).i_sub = 0;
98          QUEUE(i).pp_sub = 0;
99     }
100
101 #ifdef UNDER_CE
102     QUEUE(MSG_QUEUE_NORMAL).logfile =
103         CreateFile( L"vlc-log.txt", GENERIC_WRITE,
104                     FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
105                     CREATE_ALWAYS, 0, NULL );
106     SetFilePointer( QUEUE(MSG_QUEUE_NORMAL).logfile, 0, NULL, FILE_END );
107 #endif
108 }
109
110 /**
111  * Flush all message queues
112  */
113 void __msg_Flush( vlc_object_t *p_this )
114 {
115     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
116
117     for( int i = 0 ; i < NB_QUEUES ; i++ )
118     {
119         vlc_mutex_lock( &QUEUE(i).lock );
120         FlushMsg( &QUEUE(i) );
121         vlc_mutex_unlock( &QUEUE(i).lock );
122     }
123 }
124
125 /**
126  * Destroy the message queues
127  *
128  * This functions prints all messages remaining in the queues,
129  * then frees all the allocated ressources
130  * No other messages interface functions should be called after this one.
131  */
132 void __msg_Destroy( vlc_object_t *p_this )
133 {
134     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
135
136     for( int i = NB_QUEUES -1 ; i >= 0;  i-- )
137     {
138         if( QUEUE(i).i_sub )
139             msg_Err( p_this, "stale interface subscribers" );
140
141         FlushMsg( &QUEUE(i) );
142
143 #ifdef UNDER_CE
144         if( i == MSG_QUEUE_NORMAL )
145             CloseHandle( QUEUE(MSG_QUEUE_NORMAL).logfile );
146 #endif
147         /* Destroy lock */
148         vlc_mutex_destroy( &QUEUE(i).lock );
149     }
150     vlc_mutex_destroy( &priv->msg_bank.lock);
151 }
152
153 /**
154  * Subscribe to a message queue.
155  */
156 msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i )
157 {
158     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
159     msg_subscription_t *p_sub = malloc( sizeof( msg_subscription_t ) );
160
161     if (p_sub == NULL)
162         return NULL;
163
164     assert( i < NB_QUEUES );
165
166     LOCK_BANK;
167     vlc_mutex_lock( &QUEUE(i).lock );
168
169     TAB_APPEND( QUEUE(i).i_sub, QUEUE(i).pp_sub, p_sub );
170
171     p_sub->i_start = QUEUE(i).i_start;
172     p_sub->pi_stop = &QUEUE(i).i_stop;
173     p_sub->p_msg   = QUEUE(i).msg;
174     p_sub->p_lock  = &QUEUE(i).lock;
175
176     vlc_mutex_unlock( &QUEUE(i).lock );
177     UNLOCK_BANK;
178
179     return p_sub;
180 }
181
182 /**
183  * Unsubscribe from a message queue.
184  */
185 void __msg_Unsubscribe( vlc_object_t *p_this, msg_subscription_t *p_sub )
186 {
187     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
188
189     LOCK_BANK;
190     for( int i = 0 ; i< NB_QUEUES ; i++ )
191     {
192         vlc_mutex_lock( &QUEUE(i).lock );
193         for( int j = 0 ; j< QUEUE(i).i_sub ; j++ )
194         {
195             if( QUEUE(i).pp_sub[j] == p_sub )
196             {
197                 REMOVE_ELEM( QUEUE(i).pp_sub, QUEUE(i).i_sub, j );
198                 free( p_sub );
199             }
200         }
201         vlc_mutex_unlock( & QUEUE(i).lock );
202     }
203     UNLOCK_BANK;
204 }
205
206 /*****************************************************************************
207  * __msg_*: print a message
208  *****************************************************************************
209  * These functions queue a message for later printing.
210  *****************************************************************************/
211 void __msg_Generic( vlc_object_t *p_this, int i_queue, int i_type,
212                     const char *psz_module,
213                     const char *psz_format, ... )
214 {
215     va_list args;
216
217     va_start( args, psz_format );
218     QueueMsg( p_this, i_queue, i_type, psz_module, psz_format, args );
219     va_end( args );
220 }
221
222 void __msg_GenericVa( vlc_object_t *p_this, int i_queue,
223                       int i_type, const char *psz_module,
224                       const char *psz_format, va_list args )
225 {
226     QueueMsg( p_this, i_queue, i_type, psz_module, psz_format, args );
227 }
228
229 /* Generic functions used when variadic macros are not available. */
230 #define DECLARE_MSG_FN( FN_NAME, FN_TYPE ) \
231     void FN_NAME( vlc_object_t *p_this, const char *psz_format, ... ) \
232     { \
233         va_list args; \
234         va_start( args, psz_format ); \
235         QueueMsg( p_this,MSG_QUEUE_NORMAL, FN_TYPE, "unknown", \
236                   psz_format, args ); \
237         va_end( args ); \
238     } \
239     struct _
240 /**
241  * Output an informational message.
242  * \note Do not use this for debug messages
243  * \see input_AddInfo
244  */
245 DECLARE_MSG_FN( __msg_Info, VLC_MSG_INFO );
246 /**
247  * Output an error message.
248  */
249 DECLARE_MSG_FN( __msg_Err,  VLC_MSG_ERR );
250 /**
251  * Output a waring message
252  */
253 DECLARE_MSG_FN( __msg_Warn, VLC_MSG_WARN );
254 /**
255  * Output a debug message
256  */
257 DECLARE_MSG_FN( __msg_Dbg,  VLC_MSG_DBG );
258
259 /**
260  * Add a message to a queue
261  *
262  * This function provides basic functionnalities to other msg_* functions.
263  * It adds a message to a queue (after having printed all stored messages if it
264  * is full). If the message can't be converted to string in memory, it issues
265  * a warning.
266  */
267 static void QueueMsg( vlc_object_t *p_this, int i_queue, int i_type,
268                       const char *psz_module,
269                       const char *psz_format, va_list _args )
270 {
271     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
272     int         i_header_size;             /* Size of the additionnal header */
273     vlc_object_t *p_obj;
274     char *       psz_str = NULL;                 /* formatted message string */
275     char *       psz_header = NULL;
276     va_list      args;
277     msg_item_t * p_item = NULL;                        /* pointer to message */
278     msg_item_t   item;                    /* message in case of a full queue */
279     msg_queue_t *p_queue;
280
281 #if !defined(HAVE_VASPRINTF) || defined(__APPLE__) || defined(SYS_BEOS)
282     int          i_size = strlen(psz_format) + INTF_MAX_MSG_SIZE;
283 #endif
284
285     if( p_this == NULL )
286     {
287 #ifndef NDEBUG
288         if( i_type == VLC_MSG_DBG )
289             return;
290 #endif
291         utf8_vfprintf( stderr, psz_format, _args );
292         fputc ('\n', stderr);
293         return;
294     }
295
296     if( p_this->i_flags & OBJECT_FLAGS_QUIET ||
297         (p_this->i_flags & OBJECT_FLAGS_NODBG && i_type == VLC_MSG_DBG) )
298         return;
299
300 #ifndef __GLIBC__
301     /* Expand %m to strerror(errno) - only once */
302     char buf[strlen( psz_format ) + 2001], *ptr;
303     strcpy( buf, psz_format );
304     ptr = (char*)buf;
305     psz_format = (const char*) buf;
306
307     for( ;; )
308     {
309         ptr = strchr( ptr, '%' );
310         if( ptr == NULL )
311             break;
312
313         if( ptr[1] == 'm' )
314         {
315             char errbuf[2001];
316             size_t errlen;
317
318 #ifndef WIN32
319             strerror_r( errno, errbuf, 1001 );
320 #else
321             int sockerr = WSAGetLastError( );
322             if( sockerr )
323             {
324                 strncpy( errbuf, net_strerror( sockerr ), 1001 );
325                 WSASetLastError( sockerr );
326             }
327             if ((sockerr == 0)
328              || (strcmp ("Unknown network stack error", errbuf) == 0))
329                 strncpy( errbuf, strerror( errno ), 1001 );
330 #endif
331             errbuf[1000] = 0;
332
333             /* Escape '%' from the error string */
334             for( char *percent = strchr( errbuf, '%' );
335                  percent != NULL;
336                  percent = strchr( percent + 2, '%' ) )
337             {
338                 memmove( percent + 1, percent, strlen( percent ) + 1 );
339             }
340
341             errlen = strlen( errbuf );
342             memmove( ptr + errlen, ptr + 2, strlen( ptr + 2 ) + 1 );
343             memcpy( ptr, errbuf, errlen );
344             break; /* Only once, so we don't overflow */
345         }
346
347         /* Looks for conversion specifier... */
348         do
349             ptr++;
350         while( *ptr && ( strchr( "diouxXeEfFgGaAcspn%", *ptr ) == NULL ) );
351         if( *ptr )
352             ptr++; /* ...and skip it */
353     }
354 #endif
355
356     /* Convert message to string  */
357 #if defined(HAVE_VASPRINTF) && !defined(__APPLE__) && !defined( SYS_BEOS )
358     vlc_va_copy( args, _args );
359     if( vasprintf( &psz_str, psz_format, args ) == -1 )
360         psz_str = NULL;
361     va_end( args );
362 #else
363     psz_str = (char*) malloc( i_size );
364 #endif
365
366     if( psz_str == NULL )
367     {
368 #ifdef __GLIBC__
369         fprintf( stderr, "main warning: can't store message (%m): " );
370 #else
371         char psz_err[1001];
372 #ifndef WIN32
373         /* we're not using GLIBC, so we are sure that the error description
374          * will be stored in the buffer we provide to strerror_r() */
375         strerror_r( errno, psz_err, 1001 );
376 #else
377         strncpy( psz_err, strerror( errno ), 1001 );
378 #endif
379         psz_err[1000] = '\0';
380         fprintf( stderr, "main warning: can't store message (%s): ", psz_err );
381 #endif
382         vlc_va_copy( args, _args );
383         /* We should use utf8_vfprintf - but it calls malloc()... */
384         vfprintf( stderr, psz_format, args );
385         va_end( args );
386         fputs( "\n", stderr );
387         return;
388     }
389
390     i_header_size = 0;
391     p_obj = p_this;
392     while( p_obj != NULL )
393     {
394         char *psz_old = NULL;
395         if( p_obj->psz_header )
396         {
397             i_header_size += strlen( p_obj->psz_header ) + 4;
398             if( psz_header )
399             {
400                 psz_old = strdup( psz_header );
401                 psz_header = (char*)realloc( psz_header, i_header_size );
402                 snprintf( psz_header, i_header_size , "[%s] %s",
403                           p_obj->psz_header, psz_old );
404             }
405             else
406             {
407                 psz_header = (char *)malloc( i_header_size );
408                 snprintf( psz_header, i_header_size, "[%s]",
409                           p_obj->psz_header );
410             }
411         }
412         free( psz_old );
413         p_obj = p_obj->p_parent;
414     }
415
416 #if !defined(HAVE_VASPRINTF) || defined(__APPLE__) || defined(SYS_BEOS)
417     vlc_va_copy( args, _args );
418     vsnprintf( psz_str, i_size, psz_format, args );
419     va_end( args );
420     psz_str[ i_size - 1 ] = 0; /* Just in case */
421 #endif
422
423     assert( i_queue < NB_QUEUES );
424     LOCK_BANK;
425     p_queue = &QUEUE(i_queue) ;
426     vlc_mutex_lock( &p_queue->lock );
427
428     /* Check there is room in the queue for our message */
429     if( p_queue->b_overflow )
430     {
431         FlushMsg( p_queue );
432
433         if( ((p_queue->i_stop - p_queue->i_start + 1) % VLC_MSG_QSIZE) == 0 )
434         {
435             /* Still in overflow mode, print from a dummy item */
436             p_item = &item;
437         }
438         else
439         {
440             /* Pheeew, at last, there is room in the queue! */
441             p_queue->b_overflow = false;
442         }
443     }
444     else if( ((p_queue->i_stop - p_queue->i_start + 2) % VLC_MSG_QSIZE) == 0 )
445     {
446         FlushMsg( p_queue );
447
448         if( ((p_queue->i_stop - p_queue->i_start + 2) % VLC_MSG_QSIZE) == 0 )
449         {
450             p_queue->b_overflow = true;
451
452             if( p_queue->i_id == MSG_QUEUE_NORMAL )
453             {
454                /* Put the overflow message in the queue */
455                 p_item = p_queue->msg + p_queue->i_stop;
456                 p_queue->i_stop = (p_queue->i_stop + 1) % VLC_MSG_QSIZE;
457
458                 p_item->i_type =        VLC_MSG_WARN;
459                 p_item->i_object_id =   p_this->i_object_id;
460                 p_item->psz_object_type = p_this->psz_object_type;
461                 p_item->psz_module =    strdup( "message" );
462                 p_item->psz_msg =       strdup( "message queue overflowed" );
463                 p_item->psz_header =    NULL;
464
465                PrintMsg( p_this, p_item );
466                /* We print from a dummy item */
467                p_item = &item;
468             }
469         }
470     }
471
472     if( !p_queue->b_overflow )
473     {
474         /* Put the message in the queue */
475         p_item = p_queue->msg + p_queue->i_stop;
476         p_queue->i_stop = (p_queue->i_stop + 1) % VLC_MSG_QSIZE;
477     }
478
479     /* Fill message information fields */
480     p_item->i_type =        i_type;
481     p_item->i_object_id =   p_this->i_object_id;
482     p_item->psz_object_type = p_this->psz_object_type;
483     p_item->psz_module =    strdup( psz_module );
484     p_item->psz_msg =       psz_str;
485     p_item->psz_header =    psz_header;
486
487     if( p_queue->i_id == MSG_QUEUE_NORMAL )
488         PrintMsg( p_this, p_item );
489
490     if( p_queue->b_overflow )
491     {
492         free( p_item->psz_module );
493         free( p_item->psz_msg );
494         free( p_item->psz_header );
495     }
496
497     vlc_mutex_unlock ( &p_queue->lock );
498     UNLOCK_BANK;
499 }
500
501 /* following functions are local */
502
503 /*****************************************************************************
504  * FlushMsg
505  *****************************************************************************
506  * Print all messages remaining in queue. MESSAGE QUEUE MUST BE LOCKED, since
507  * this function does not check the lock.
508  *****************************************************************************/
509 static void FlushMsg ( msg_queue_t *p_queue )
510 {
511     int i_index, i_start, i_stop;
512
513     /* Get the maximum message index that can be freed */
514     i_stop = p_queue->i_stop;
515
516     /* Check until which value we can free messages */
517     for( i_index = 0; i_index < p_queue->i_sub; i_index++ )
518     {
519         i_start = p_queue->pp_sub[ i_index ]->i_start;
520
521         /* If this subscriber is late, we don't free messages before
522          * his i_start value, otherwise he'll miss messages */
523         if(   ( i_start < i_stop
524                && (p_queue->i_stop <= i_start || i_stop <= p_queue->i_stop) )
525            || ( i_stop < i_start
526                && (i_stop <= p_queue->i_stop && p_queue->i_stop <= i_start) ) )
527         {
528             i_stop = i_start;
529         }
530     }
531
532     /* Free message data */
533     for( i_index = p_queue->i_start;
534          i_index != i_stop;
535          i_index = (i_index+1) % VLC_MSG_QSIZE )
536     {
537         free( p_queue->msg[i_index].psz_msg );
538         free( p_queue->msg[i_index].psz_module );
539         free( p_queue->msg[i_index].psz_header );
540     }
541
542     /* Update the new start value */
543     p_queue->i_start = i_index;
544 }
545
546 /*****************************************************************************
547  * PrintMsg: output a standard message item to stderr
548  *****************************************************************************
549  * Print a message to stderr, with colour formatting if needed.
550  *****************************************************************************/
551 static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
552 {
553 #   define COL(x)  "\033[" #x ";1m"
554 #   define RED     COL(31)
555 #   define GREEN   COL(32)
556 #   define YELLOW  COL(33)
557 #   define WHITE   COL(0)
558 #   define GRAY    "\033[0m"
559
560 #ifdef UNDER_CE
561     int i_dummy;
562 #endif
563     static const char * ppsz_type[4] = { "", " error", " warning", " debug" };
564     static const char *ppsz_color[4] = { WHITE, RED, YELLOW, GRAY };
565     const char *psz_object;
566     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
567     int i_type = p_item->i_type;
568
569     switch( i_type )
570     {
571         case VLC_MSG_ERR:
572             if( priv->i_verbose < 0 ) return;
573             break;
574         case VLC_MSG_INFO:
575             if( priv->i_verbose < 0 ) return;
576             break;
577         case VLC_MSG_WARN:
578             if( priv->i_verbose < 1 ) return;
579             break;
580         case VLC_MSG_DBG:
581             if( priv->i_verbose < 2 ) return;
582             break;
583     }
584
585     psz_object = p_item->psz_object_type;
586
587 #ifdef UNDER_CE
588 #   define CE_WRITE(str) WriteFile( QUEUE(MSG_QUEUE_NORMAL).logfile, \
589                                     str, strlen(str), &i_dummy, NULL );
590     CE_WRITE( p_item->psz_module );
591     CE_WRITE( " " );
592     CE_WRITE( psz_object );
593     CE_WRITE( ppsz_type[i_type] );
594     CE_WRITE( ": " );
595     CE_WRITE( p_item->psz_msg );
596     CE_WRITE( "\r\n" );
597     FlushFileBuffers( QUEUE(MSG_QUEUE_NORMAL).logfile );
598
599 #else
600     /* Send the message to stderr */
601     if( priv->b_color )
602     {
603         if( p_item->psz_header )
604         {
605             utf8_fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s %s%s: %s%s" GRAY
606                               "\n",
607                          p_item->i_object_id, p_item->psz_header,
608                          p_item->psz_module, psz_object,
609                          ppsz_type[i_type], ppsz_color[i_type],
610                          p_item->psz_msg );
611         }
612         else
613         {
614              utf8_fprintf( stderr, "[" GREEN "%.8i" GRAY "] %s %s%s: %s%s" GRAY "\n",
615                          p_item->i_object_id, p_item->psz_module, psz_object,
616                          ppsz_type[i_type], ppsz_color[i_type],
617                          p_item->psz_msg );
618         }
619     }
620     else
621     {
622         if( p_item->psz_header )
623         {
624             utf8_fprintf( stderr, "[%.8i] %s %s %s%s: %s\n", p_item->i_object_id,
625                          p_item->psz_header, p_item->psz_module,
626                          psz_object, ppsz_type[i_type], p_item->psz_msg );
627         }
628         else
629         {
630             utf8_fprintf( stderr, "[%.8i] %s %s%s: %s\n", p_item->i_object_id,
631                          p_item->psz_module, psz_object, ppsz_type[i_type],
632                          p_item->psz_msg );
633         }
634     }
635
636 #   if defined(WIN32)
637     fflush( stderr );
638 #   endif
639 #endif
640 }
641
642 static msg_context_t* GetContext(void)
643 {
644     msg_context_t *p_ctx = vlc_threadvar_get( &msg_context_global_key );
645     if( p_ctx == NULL )
646     {
647         MALLOC_NULL( p_ctx, msg_context_t );
648         p_ctx->psz_message = NULL;
649         vlc_threadvar_set( &msg_context_global_key, p_ctx );
650     }
651     return p_ctx;
652 }
653
654 void msg_StackSet( int i_code, const char *psz_message, ... )
655 {
656     va_list ap;
657     msg_context_t *p_ctx = GetContext();
658     assert( p_ctx );
659
660     va_start( ap, psz_message );
661     free( p_ctx->psz_message );
662
663     if( vasprintf( &p_ctx->psz_message, psz_message, ap ) == -1 )
664         p_ctx->psz_message = NULL;
665     va_end( ap );
666
667     p_ctx->i_code = i_code;
668 }
669
670 void msg_StackAdd( const char *psz_message, ... )
671 {
672     char *psz_tmp;
673     va_list ap;
674     msg_context_t *p_ctx = GetContext();
675     assert( p_ctx );
676
677     va_start( ap, psz_message );
678     if( vasprintf( &psz_tmp, psz_message, ap ) == -1 )
679         psz_tmp = NULL;
680     va_end( ap );
681
682     if( !p_ctx->psz_message )
683         p_ctx->psz_message = psz_tmp;
684     else
685     {
686         char *psz_old = malloc( strlen( p_ctx->psz_message ) + 1 );
687         memcpy( psz_old, p_ctx->psz_message, strlen( p_ctx->psz_message ) + 1 );
688         p_ctx->psz_message = realloc( p_ctx->psz_message,
689                                       strlen( p_ctx->psz_message ) +
690                                       /* ':', ' ', '0' */
691                                       strlen( psz_tmp ) + 3 );
692         sprintf( p_ctx->psz_message, "%s: %s", psz_tmp, psz_old );
693         free( psz_tmp ); free( psz_old );
694     }
695 }
696
697 const char* msg_StackMsg( void )
698 {
699     msg_context_t *p_ctx = GetContext();
700     assert( p_ctx );
701     return p_ctx->psz_message;
702 }