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