]> git.sesse.net Git - vlc/blob - src/config/file.c
config: fix memleak.
[vlc] / src / config / file.c
1 /*****************************************************************************
2  * file.c: configuration file handling
3  *****************************************************************************
4  * Copyright (C) 2001-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <vlc_common.h>
29 #include "../libvlc.h"
30 #include "vlc_charset.h"
31 #include "vlc_keys.h"
32
33 #include <errno.h>                                                  /* errno */
34 #include <assert.h>
35 #include <limits.h>
36 #include <fcntl.h>
37 #ifdef __APPLE__
38 #   include <xlocale.h>
39 #else
40 #include <locale.h>
41 #endif
42
43 #include "configuration.h"
44 #include "modules/modules.h"
45
46 static char *ConfigKeyToString( int );
47
48 static inline char *strdupnull (const char *src)
49 {
50     return src ? strdup (src) : NULL;
51 }
52
53 /**
54  * Get the user's configuration file
55  */
56 static char *config_GetConfigFile( vlc_object_t *obj )
57 {
58     char *psz_file = config_GetPsz( obj, "config" );
59     if( psz_file == NULL )
60     {
61         char *psz_dir = config_GetUserConfDir();
62
63         if( asprintf( &psz_file, "%s" DIR_SEP CONFIG_FILE, psz_dir ) == -1 )
64             psz_file = NULL;
65         free( psz_dir );
66     }
67     return psz_file;
68 }
69
70 static FILE *config_OpenConfigFile( vlc_object_t *p_obj )
71 {
72     char *psz_filename = config_GetConfigFile( p_obj );
73     if( psz_filename == NULL )
74         return NULL;
75
76     msg_Dbg( p_obj, "opening config file (%s)", psz_filename );
77
78     FILE *p_stream = utf8_fopen( psz_filename, "rt" );
79     if( p_stream == NULL && errno != ENOENT )
80     {
81         msg_Err( p_obj, "cannot open config file (%s): %m",
82                  psz_filename );
83
84     }
85 #if !( defined(WIN32) || defined(__APPLE__) || defined(SYS_BEOS) )
86     else if( p_stream == NULL && errno == ENOENT )
87     {
88         /* This is the fallback for pre XDG Base Directory
89          * Specification configs */
90         char *psz_old;
91         if( asprintf( &psz_old, "%s" DIR_SEP CONFIG_DIR DIR_SEP CONFIG_FILE,
92                       config_GetHomeDir() ) != -1 )
93         {
94             p_stream = utf8_fopen( psz_old, "rt" );
95             if( p_stream )
96             {
97                 /* Old config file found. We want to write it at the
98                  * new location now. */
99                 msg_Info( p_obj->p_libvlc, "Found old config file at %s. "
100                           "VLC will now use %s.", psz_old, psz_filename );
101                 char *psz_readme;
102                 if( asprintf(&psz_readme,"%s"DIR_SEP CONFIG_DIR DIR_SEP"README",
103                               config_GetHomeDir() ) != -1 )
104                 {
105                     FILE *p_readme = utf8_fopen( psz_readme, "wt" );
106                     if( p_readme )
107                     {
108                         fprintf( p_readme, "The VLC media player "
109                                  "configuration folder has moved to comply\n"
110                                  "with the XDG Base Directory Specification "
111                                  "version 0.6. Your\nconfiguration has been "
112                                  "copied to the new location:\n%s\nYou can "
113                                  "delete this directory and all its contents.",
114                                   psz_filename);
115                         fclose( p_readme );
116                     }
117                     free( psz_readme );
118                 }
119             }
120             free( psz_old );
121         }
122     }
123 #endif
124     free( psz_filename );
125     return p_stream;
126 }
127
128
129 static int strtoi (const char *str)
130 {
131     char *end;
132     long l;
133
134     errno = 0;
135     l = strtol (str, &end, 0);
136
137     if (!errno)
138     {
139         if ((l > INT_MAX) || (l < INT_MIN))
140             errno = ERANGE;
141         if (*end)
142             errno = EINVAL;
143     }
144     return (int)l;
145 }
146
147
148 /*****************************************************************************
149  * config_LoadConfigFile: loads the configuration file.
150  *****************************************************************************
151  * This function is called to load the config options stored in the config
152  * file.
153  *****************************************************************************/
154 int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
155 {
156     FILE *file;
157
158     file = config_OpenConfigFile (p_this);
159     if (file == NULL)
160         return VLC_EGENERIC;
161
162     /* Look for the selected module, if NULL then save everything */
163     module_t **list = module_list_get (NULL);
164
165     /* Look for UTF-8 Byte Order Mark */
166     char * (*convert) (const char *) = strdupnull;
167     char bom[3];
168
169     if ((fread (bom, 1, 3, file) != 3)
170      || memcmp (bom, "\xEF\xBB\xBF", 3))
171     {
172         convert = FromLocaleDup;
173         rewind (file); /* no BOM, rewind */
174     }
175
176     module_t *module = NULL;
177     char line[1024], section[1022];
178     section[0] = '\0';
179
180     /* Ensure consistent number formatting... */
181     locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
182     locale_t baseloc = uselocale (loc);
183
184     while (fgets (line, 1024, file) != NULL)
185     {
186         /* Ignore comments and empty lines */
187         switch (line[0])
188         {
189             case '#':
190             case '\n':
191             case '\0':
192                 continue;
193         }
194
195         if (line[0] == '[')
196         {
197             char *ptr = strchr (line, ']');
198             if (ptr == NULL)
199                 continue; /* syntax error; */
200             *ptr = '\0';
201
202             /* New section ( = a given module) */
203             strcpy (section, line + 1);
204             module = NULL;
205
206             if ((psz_module_name == NULL)
207              || (strcmp (psz_module_name, section) == 0))
208             {
209                 for (int i = 0; list[i]; i++)
210                 {
211                     module_t *m = list[i];
212
213                     if ((strcmp (section, m->psz_object_name) == 0)
214                      && (m->i_config_items > 0)) /* ignore config-less modules */
215                     {
216                         module = m;
217                         if (psz_module_name != NULL)
218                             msg_Dbg (p_this,
219                                      "loading config for module \"%s\"",
220                                      section);
221                         break;
222                     }
223                 }
224             }
225
226             continue;
227         }
228
229         if (module == NULL)
230             continue; /* no need to parse if there is no matching module */
231
232         char *ptr = strchr (line, '\n');
233         if (ptr != NULL)
234             *ptr = '\0';
235
236         /* look for option name */
237         const char *psz_option_name = line;
238
239         ptr = strchr (line, '=');
240         if (ptr == NULL)
241             continue; /* syntax error */
242
243         *ptr = '\0';
244         const char *psz_option_value = ptr + 1;
245
246         /* try to match this option with one of the module's options */
247         for (size_t i = 0; i < module->confsize; i++)
248         {
249             module_config_t *p_item = module->p_config + i;
250
251             if ((p_item->i_type & CONFIG_HINT)
252              || strcmp (p_item->psz_name, psz_option_name))
253                 continue;
254
255             /* We found it */
256             errno = 0;
257
258             vlc_mutex_lock( p_item->p_lock );
259             switch( p_item->i_type )
260             {
261                 case CONFIG_ITEM_BOOL:
262                 case CONFIG_ITEM_INTEGER:
263                 {
264                     long l = strtoi (psz_option_value);
265                     if (errno)
266                         msg_Warn (p_this, "Integer value (%s) for %s: %m",
267                                   psz_option_value, psz_option_name);
268                     else
269                         p_item->saved.i = p_item->value.i = (int)l;
270                     break;
271                 }
272
273                 case CONFIG_ITEM_FLOAT:
274                     if( !*psz_option_value )
275                         break;                    /* ignore empty option */
276                     p_item->value.f = (float)atof (psz_option_value);
277                     p_item->saved.f = p_item->value.f;
278                     break;
279
280                 case CONFIG_ITEM_KEY:
281                     if( !*psz_option_value )
282                         break;                    /* ignore empty option */
283                     p_item->value.i = ConfigStringToKey(psz_option_value);
284                     p_item->saved.i = p_item->value.i;
285                     break;
286
287                 default:
288                     /* free old string */
289                     free( (char*) p_item->value.psz );
290                     free( (char*) p_item->saved.psz );
291
292                     p_item->value.psz = convert (psz_option_value);
293                     p_item->saved.psz = strdupnull (p_item->value.psz);
294                     break;
295             }
296             vlc_mutex_unlock( p_item->p_lock );
297             break;
298         }
299     }
300
301     if (ferror (file))
302     {
303         msg_Err (p_this, "error reading configuration: %m");
304         clearerr (file);
305     }
306     fclose (file);
307
308     module_list_free (list);
309     if (loc != (locale_t)0)
310     {
311         uselocale (baseloc);
312         freelocale (loc);
313     }
314     return 0;
315 }
316
317 /*****************************************************************************
318  * config_CreateDir: Create configuration directory if it doesn't exist.
319  *****************************************************************************/
320 int config_CreateDir( vlc_object_t *p_this, const char *psz_dirname )
321 {
322     if( !psz_dirname || !*psz_dirname ) return -1;
323
324     if( utf8_mkdir( psz_dirname, 0700 ) == 0 )
325         return 0;
326
327     switch( errno )
328     {
329         case EEXIST:
330             return 0;
331
332         case ENOENT:
333         {
334             /* Let's try to create the parent directory */
335             char psz_parent[strlen( psz_dirname ) + 1], *psz_end;
336             strcpy( psz_parent, psz_dirname );
337
338             psz_end = strrchr( psz_parent, DIR_SEP_CHAR );
339             if( psz_end && psz_end != psz_parent )
340             {
341                 *psz_end = '\0';
342                 if( config_CreateDir( p_this, psz_parent ) == 0 )
343                 {
344                     if( !utf8_mkdir( psz_dirname, 0700 ) )
345                         return 0;
346                 }
347             }
348         }
349     }
350
351     msg_Err( p_this, "could not create %s: %m", psz_dirname );
352     return -1;
353 }
354
355 static int
356 config_Write (FILE *file, const char *type, const char *desc,
357               bool comment, const char *name, const char *fmt, ...)
358 {
359     va_list ap;
360     int ret;
361
362     if (desc == NULL)
363         desc = "?";
364
365     if (fprintf (file, "# %s (%s)\n%s%s=", desc, vlc_gettext (type),
366                  comment ? "#" : "", name) < 0)
367         return -1;
368
369     va_start (ap, fmt);
370     ret = vfprintf (file, fmt, ap);
371     va_end (ap);
372     if (ret < 0)
373         return -1;
374
375     if (fputs ("\n\n", file) == EOF)
376         return -1;
377     return 0;
378 }
379
380
381 static int config_PrepareDir (vlc_object_t *obj)
382 {
383     char *psz_configdir = config_GetUserConfDir ();
384     if (psz_configdir == NULL) /* XXX: This should never happen */
385         return -1;
386
387     int ret = config_CreateDir (obj, psz_configdir);
388     free (psz_configdir);
389     return ret;
390 }
391
392 /*****************************************************************************
393  * config_SaveConfigFile: Save a module's config options.
394  *****************************************************************************
395  * This will save the specified module's config options to the config file.
396  * If psz_module_name is NULL then we save all the modules config options.
397  * It's no use to save the config options that kept their default values, so
398  * we'll try to be a bit clever here.
399  *
400  * When we save we mustn't delete the config options of the modules that
401  * haven't been loaded. So we cannot just create a new config file with the
402  * config structures we've got in memory.
403  * I don't really know how to deal with this nicely, so I will use a completly
404  * dumb method ;-)
405  * I will load the config file in memory, but skipping all the sections of the
406  * modules we want to save. Then I will create a brand new file, dump the file
407  * loaded in memory and then append the sections of the modules we want to
408  * save.
409  * Really stupid no ?
410  *****************************************************************************/
411 static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
412                            bool b_autosave )
413 {
414     module_t *p_parser;
415     FILE *file = NULL;
416     char *permanent = NULL, *temporary = NULL;
417     char p_line[1024], *p_index2;
418     unsigned long i_sizebuf = 0;
419     char *p_bigbuffer = NULL, *p_index;
420     bool b_backup;
421     int i_index;
422
423     if( config_PrepareDir( p_this ) )
424     {
425         msg_Err( p_this, "no configuration directory" );
426         goto error;
427     }
428
429     file = config_OpenConfigFile( p_this );
430     if( file != NULL )
431     {
432         /* look for file size */
433         fseek( file, 0L, SEEK_END );
434         i_sizebuf = ftell( file );
435         fseek( file, 0L, SEEK_SET );
436         if( i_sizebuf >= LONG_MAX )
437             i_sizebuf = 0;
438     }
439
440     p_bigbuffer = p_index = malloc( i_sizebuf+1 );
441     if( !p_bigbuffer )
442         goto error;
443     p_bigbuffer[0] = 0;
444
445     /* List all available modules */
446     module_t **list = module_list_get (NULL);
447
448     /* backup file into memory, we only need to backup the sections we won't
449      * save later on */
450     b_backup = false;
451     while( file && fgets( p_line, 1024, file ) )
452     {
453         if( (p_line[0] == '[') && (p_index2 = strchr(p_line,']')))
454         {
455
456             /* we found a section, check if we need to do a backup */
457             for( i_index = 0; (p_parser = list[i_index]) != NULL; i_index++ )
458             {
459                 if( ((p_index2 - &p_line[1])
460                        == (int)strlen(p_parser->psz_object_name) )
461                     && !memcmp( &p_line[1], p_parser->psz_object_name,
462                                 strlen(p_parser->psz_object_name) ) )
463                 {
464                     if( !psz_module_name )
465                         break;
466                     else if( !strcmp( psz_module_name,
467                                       p_parser->psz_object_name ) )
468                         break;
469                 }
470             }
471
472             if( list[i_index] == NULL )
473             {
474                 /* we don't have this section in our list so we need to back
475                  * it up */
476                 *p_index2 = 0;
477 #if 0
478                 msg_Dbg( p_this, "backing up config for unknown module \"%s\"",
479                                  &p_line[1] );
480 #endif
481                 *p_index2 = ']';
482
483                 b_backup = true;
484             }
485             else
486             {
487                 b_backup = false;
488             }
489         }
490
491         /* save line if requested and line is valid (doesn't begin with a
492          * space, tab, or eol) */
493         if( b_backup && (p_line[0] != '\n') && (p_line[0] != ' ')
494             && (p_line[0] != '\t') )
495         {
496             strcpy( p_index, p_line );
497             p_index += strlen( p_line );
498         }
499     }
500     if( file )
501         fclose( file );
502     file = NULL;
503
504     /*
505      * Save module config in file
506      */
507     permanent = config_GetConfigFile (p_this);
508     if (!permanent)
509     {
510         module_list_free (list);
511         goto error;
512     }
513
514     if (asprintf (&temporary, "%s.%u", permanent, getpid ()) == -1)
515     {
516         temporary = NULL;
517         module_list_free (list);
518         goto error;
519     }
520
521     /* The temporary configuration file is per-PID. Therefore SaveConfigFile()
522      * should be serialized against itself within a given process. */
523     static vlc_mutex_t lock = VLC_STATIC_MUTEX;
524     vlc_mutex_lock (&lock);
525
526     int fd = utf8_open (temporary, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
527     if (fd == -1)
528     {
529         vlc_mutex_unlock (&lock);
530         module_list_free (list);
531         goto error;
532     }
533     file = fdopen (fd, "wt");
534     if (file == NULL)
535     {
536         close (fd);
537         vlc_mutex_unlock (&lock);
538         module_list_free (list);
539         goto error;
540     }
541
542     fprintf( file, "\xEF\xBB\xBF###\n###  " COPYRIGHT_MESSAGE "\n###\n\n"
543        "###\n### lines beginning with a '#' character are comments\n###\n\n" );
544
545     /* Ensure consistent number formatting... */
546     locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
547     locale_t baseloc = uselocale (loc);
548
549     /* Look for the selected module, if NULL then save everything */
550     for( i_index = 0; (p_parser = list[i_index]) != NULL; i_index++ )
551     {
552         module_config_t *p_item, *p_end;
553
554         if( psz_module_name && strcmp( psz_module_name,
555                                        p_parser->psz_object_name ) )
556             continue;
557
558         if( !p_parser->i_config_items )
559             continue;
560
561         if( psz_module_name )
562             msg_Dbg( p_this, "saving config for module \"%s\"",
563                      p_parser->psz_object_name );
564
565         fprintf( file, "[%s]", p_parser->psz_object_name );
566         if( p_parser->psz_longname )
567             fprintf( file, " # %s\n\n", p_parser->psz_longname );
568         else
569             fprintf( file, "\n\n" );
570
571         for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
572              p_item < p_end;
573              p_item++ )
574         {
575             if ((p_item->i_type & CONFIG_HINT) /* ignore hint */
576              || p_item->b_removed              /* ignore deprecated option */
577              || p_item->b_unsaveable)          /* ignore volatile option */
578                 continue;
579
580             vlc_mutex_lock (p_item->p_lock);
581
582             /* Do not save the new value in the configuration file
583              * if doing an autosave, and the item is not an "autosaved" one. */
584             bool b_retain = b_autosave && !p_item->b_autosave;
585
586             if (IsConfigIntegerType (p_item->i_type))
587             {
588                 int val = b_retain ? p_item->saved.i : p_item->value.i;
589                 if (p_item->i_type == CONFIG_ITEM_KEY)
590                 {
591                     char *psz_key = ConfigKeyToString (val);
592                     config_Write (file, p_item->psz_text, N_("key"),
593                                   val == p_item->orig.i,
594                                   p_item->psz_name, "%s",
595                                   psz_key ? psz_key : "");
596                     free (psz_key);
597                 }
598                 else
599                     config_Write (file, p_item->psz_text,
600                                   (p_item->i_type == CONFIG_ITEM_BOOL)
601                                       ? N_("boolean") : N_("integer"),
602                                   val == p_item->orig.i,
603                                   p_item->psz_name, "%d", val);
604                 p_item->saved.i = val;
605             }
606             else
607             if (IsConfigFloatType (p_item->i_type))
608             {
609                 float val = b_retain ? p_item->saved.f : p_item->value.f;
610                 config_Write (file, p_item->psz_text, N_("float"),
611                               val == p_item->orig.f,
612                               p_item->psz_name, "%f", val);
613                 p_item->saved.f = val;
614             }
615             else
616             {
617                 const char *psz_value = b_retain ? p_item->saved.psz
618                                                  : p_item->value.psz;
619                 bool modified;
620
621                 assert (IsConfigStringType (p_item->i_type));
622
623                 if (b_retain && (psz_value == NULL)) /* FIXME: hack */
624                     psz_value = p_item->orig.psz;
625
626                 modified =
627                     (psz_value != NULL)
628                         ? ((p_item->orig.psz != NULL)
629                             ? (strcmp (psz_value, p_item->orig.psz) != 0)
630                             : true)
631                         : (p_item->orig.psz != NULL);
632
633                 config_Write (file, p_item->psz_text, N_("string"),
634                               !modified, p_item->psz_name, "%s",
635                               psz_value ? psz_value : "");
636
637                 if ( !b_retain )
638                 {
639
640                     free ((char *)p_item->saved.psz);
641                     if( (psz_value && p_item->orig.psz &&
642                          strcmp( psz_value, p_item->orig.psz )) ||
643                         !psz_value || !p_item->orig.psz)
644                         p_item->saved.psz = strdupnull (psz_value);
645                     else
646                         p_item->saved.psz = NULL;
647                 }
648             }
649
650             if (!b_retain)
651                 p_item->b_dirty = false;
652             vlc_mutex_unlock (p_item->p_lock);
653         }
654     }
655
656     module_list_free (list);
657     if (loc != (locale_t)0)
658     {
659         uselocale (baseloc);
660         freelocale (loc);
661     }
662
663     /*
664      * Restore old settings from the config in file
665      */
666     fputs( p_bigbuffer, file );
667     free( p_bigbuffer );
668
669     /*
670      * Flush to disk and replace atomically
671      */
672     fflush (file); /* Flush from run-time */
673 #ifndef WIN32
674     fdatasync (fd); /* Flush from OS */
675     /* Atomically replace the file... */
676     rename (temporary, permanent);
677     /* (...then synchronize the directory, err, TODO...) */
678     /* ...and finally close the file */
679     vlc_mutex_unlock (&lock);
680 #endif
681     fclose (file);
682 #ifdef WIN32
683     /* Windows cannot remove open files nor overwrite existing ones */
684     remove (permanent);
685     rename (temporary, permanent);
686     vlc_mutex_unlock (&lock);
687 #endif
688
689     free (temporary);
690     free (permanent);
691     return 0;
692
693 error:
694     if( file )
695         fclose( file );
696     free (temporary);
697     free (permanent);
698     free( p_bigbuffer );
699     return -1;
700 }
701
702 int config_AutoSaveConfigFile( vlc_object_t *p_this )
703 {
704     size_t i_index;
705     bool save = false;
706
707     assert( p_this );
708
709     /* Check if there's anything to save */
710     module_t **list = module_list_get (NULL);
711     for( i_index = 0; list[i_index] && !save; i_index++ )
712     {
713         module_t *p_parser = list[i_index];
714         module_config_t *p_item, *p_end;
715
716         if( !p_parser->i_config_items ) continue;
717
718         for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
719              p_item < p_end && !save;
720              p_item++ )
721         {
722             vlc_mutex_lock (p_item->p_lock);
723             save = p_item->b_autosave && p_item->b_dirty;
724             vlc_mutex_unlock (p_item->p_lock);
725         }
726     }
727     module_list_free (list);
728
729     return save ? VLC_SUCCESS : SaveConfigFile( p_this, NULL, true );
730 }
731
732 int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
733 {
734     return SaveConfigFile( p_this, psz_module_name, false );
735 }
736
737 int ConfigStringToKey( const char *psz_key )
738 {
739     int i_key = 0;
740     unsigned int i;
741     const char *psz_parser = strchr( psz_key, '-' );
742     while( psz_parser && psz_parser != psz_key )
743     {
744         for( i = 0; i < sizeof(vlc_modifiers) / sizeof(key_descriptor_t); i++ )
745         {
746             if( !strncasecmp( vlc_modifiers[i].psz_key_string, psz_key,
747                               strlen( vlc_modifiers[i].psz_key_string ) ) )
748             {
749                 i_key |= vlc_modifiers[i].i_key_code;
750             }
751         }
752         psz_key = psz_parser + 1;
753         psz_parser = strchr( psz_key, '-' );
754     }
755     for( i = 0; i < sizeof(vlc_keys) / sizeof( key_descriptor_t ); i++ )
756     {
757         if( !strcasecmp( vlc_keys[i].psz_key_string, psz_key ) )
758         {
759             i_key |= vlc_keys[i].i_key_code;
760             break;
761         }
762     }
763     return i_key;
764 }
765
766 char *ConfigKeyToString( int i_key )
767 {
768     char *psz_key = malloc( 100 );
769     char *p;
770     size_t index;
771
772     if ( !psz_key )
773     {
774         return NULL;
775     }
776     *psz_key = '\0';
777     p = psz_key;
778
779     for( index = 0; index < (sizeof(vlc_modifiers) / sizeof(key_descriptor_t));
780          index++ )
781     {
782         if( i_key & vlc_modifiers[index].i_key_code )
783         {
784             p += sprintf( p, "%s-", vlc_modifiers[index].psz_key_string );
785         }
786     }
787     for( index = 0; index < (sizeof(vlc_keys) / sizeof( key_descriptor_t));
788          index++)
789     {
790         if( (int)( i_key & ~KEY_MODIFIER ) == vlc_keys[index].i_key_code )
791         {
792             p += sprintf( p, "%s", vlc_keys[index].psz_key_string );
793             break;
794         }
795     }
796     return psz_key;
797 }
798