]> git.sesse.net Git - vlc/blob - src/config/file.c
Config lock is pointless while reading/resetting the configuration
[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, const char *mode )
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, mode );
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 && mode[0] == 'r' )
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, mode );
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     return p_stream;
125 }
126
127
128 static int strtoi (const char *str)
129 {
130     char *end;
131     long l;
132
133     errno = 0;
134     l = strtol (str, &end, 0);
135
136     if (!errno)
137     {
138         if ((l > INT_MAX) || (l < INT_MIN))
139             errno = ERANGE;
140         if (*end)
141             errno = EINVAL;
142     }
143     return (int)l;
144 }
145
146
147 /*****************************************************************************
148  * config_LoadConfigFile: loads the configuration file.
149  *****************************************************************************
150  * This function is called to load the config options stored in the config
151  * file.
152  *****************************************************************************/
153 int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
154 {
155     FILE *file;
156
157     file = config_OpenConfigFile (p_this, "rt");
158     if (file == NULL)
159         return VLC_EGENERIC;
160
161     /* Look for the selected module, if NULL then save everything */
162     module_t **list = module_list_get (NULL);
163
164     /* Look for UTF-8 Byte Order Mark */
165     char * (*convert) (const char *) = strdupnull;
166     char bom[3];
167
168     if ((fread (bom, 1, 3, file) != 3)
169      || memcmp (bom, "\xEF\xBB\xBF", 3))
170     {
171         convert = FromLocaleDup;
172         rewind (file); /* no BOM, rewind */
173     }
174
175     module_t *module = NULL;
176     char line[1024], section[1022];
177     section[0] = '\0';
178
179     /* Ensure consistent number formatting... */
180     locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
181     locale_t baseloc = uselocale (loc);
182
183     while (fgets (line, 1024, file) != NULL)
184     {
185         /* Ignore comments and empty lines */
186         switch (line[0])
187         {
188             case '#':
189             case '\n':
190             case '\0':
191                 continue;
192         }
193
194         if (line[0] == '[')
195         {
196             char *ptr = strchr (line, ']');
197             if (ptr == NULL)
198                 continue; /* syntax error; */
199             *ptr = '\0';
200
201             /* New section ( = a given module) */
202             strcpy (section, line + 1);
203             module = NULL;
204
205             if ((psz_module_name == NULL)
206              || (strcmp (psz_module_name, section) == 0))
207             {
208                 for (int i = 0; list[i]; i++)
209                 {
210                     module_t *m = list[i];
211
212                     if ((strcmp (section, m->psz_object_name) == 0)
213                      && (m->i_config_items > 0)) /* ignore config-less modules */
214                     {
215                         module = m;
216                         if (psz_module_name != NULL)
217                             msg_Dbg (p_this,
218                                      "loading config for module \"%s\"",
219                                      section);
220                         break;
221                     }
222                 }
223             }
224
225             continue;
226         }
227
228         if (module == NULL)
229             continue; /* no need to parse if there is no matching module */
230
231         char *ptr = strchr (line, '\n');
232         if (ptr != NULL)
233             *ptr = '\0';
234
235         /* look for option name */
236         const char *psz_option_name = line;
237
238         ptr = strchr (line, '=');
239         if (ptr == NULL)
240             continue; /* syntax error */
241
242         *ptr = '\0';
243         const char *psz_option_value = ptr + 1;
244
245         /* try to match this option with one of the module's options */
246         for (size_t i = 0; i < module->confsize; i++)
247         {
248             module_config_t *p_item = module->p_config + i;
249
250             if ((p_item->i_type & CONFIG_HINT)
251              || strcmp (p_item->psz_name, psz_option_name))
252                 continue;
253
254             /* We found it */
255             errno = 0;
256
257             vlc_mutex_lock( p_item->p_lock );
258             switch( p_item->i_type )
259             {
260                 case CONFIG_ITEM_BOOL:
261                 case CONFIG_ITEM_INTEGER:
262                 {
263                     long l = strtoi (psz_option_value);
264                     if (errno)
265                         msg_Warn (p_this, "Integer value (%s) for %s: %m",
266                                   psz_option_value, psz_option_name);
267                     else
268                         p_item->saved.i = p_item->value.i = (int)l;
269                     break;
270                 }
271
272                 case CONFIG_ITEM_FLOAT:
273                     if( !*psz_option_value )
274                         break;                    /* ignore empty option */
275                     p_item->value.f = (float)atof (psz_option_value);
276                     p_item->saved.f = p_item->value.f;
277                     break;
278
279                 case CONFIG_ITEM_KEY:
280                     if( !*psz_option_value )
281                         break;                    /* ignore empty option */
282                     p_item->value.i = ConfigStringToKey(psz_option_value);
283                     p_item->saved.i = p_item->value.i;
284                     break;
285
286                 default:
287                     /* free old string */
288                     free( (char*) p_item->value.psz );
289                     free( (char*) p_item->saved.psz );
290
291                     p_item->value.psz = convert (psz_option_value);
292                     p_item->saved.psz = strdupnull (p_item->value.psz);
293                     break;
294             }
295             vlc_mutex_unlock( p_item->p_lock );
296             break;
297         }
298     }
299
300     if (ferror (file))
301     {
302         msg_Err (p_this, "error reading configuration: %m");
303         clearerr (file);
304     }
305     fclose (file);
306
307     module_list_free (list);
308     if (loc != (locale_t)0)
309     {
310         uselocale (baseloc);
311         freelocale (loc);
312     }
313     return 0;
314 }
315
316 /*****************************************************************************
317  * config_CreateDir: Create configuration directory if it doesn't exist.
318  *****************************************************************************/
319 int config_CreateDir( vlc_object_t *p_this, const char *psz_dirname )
320 {
321     if( !psz_dirname || !*psz_dirname ) return -1;
322
323     if( utf8_mkdir( psz_dirname, 0700 ) == 0 )
324         return 0;
325
326     switch( errno )
327     {
328         case EEXIST:
329             return 0;
330
331         case ENOENT:
332         {
333             /* Let's try to create the parent directory */
334             char psz_parent[strlen( psz_dirname ) + 1], *psz_end;
335             strcpy( psz_parent, psz_dirname );
336
337             psz_end = strrchr( psz_parent, DIR_SEP_CHAR );
338             if( psz_end && psz_end != psz_parent )
339             {
340                 *psz_end = '\0';
341                 if( config_CreateDir( p_this, psz_parent ) == 0 )
342                 {
343                     if( !utf8_mkdir( psz_dirname, 0700 ) )
344                         return 0;
345                 }
346             }
347         }
348     }
349
350     msg_Err( p_this, "could not create %s: %m", psz_dirname );
351     return -1;
352 }
353
354 static int
355 config_Write (FILE *file, const char *type, const char *desc,
356               bool comment, const char *name, const char *fmt, ...)
357 {
358     va_list ap;
359     int ret;
360
361     if (desc == NULL)
362         desc = "?";
363
364     if (fprintf (file, "# %s (%s)\n%s%s=", desc, vlc_gettext (type),
365                  comment ? "#" : "", name) < 0)
366         return -1;
367
368     va_start (ap, fmt);
369     ret = vfprintf (file, fmt, ap);
370     va_end (ap);
371     if (ret < 0)
372         return -1;
373
374     if (fputs ("\n\n", file) == EOF)
375         return -1;
376     return 0;
377 }
378
379
380 static int config_PrepareDir (vlc_object_t *obj)
381 {
382     char *psz_configdir = config_GetUserConfDir ();
383     if (psz_configdir == NULL) /* XXX: This should never happen */
384         return -1;
385
386     int ret = config_CreateDir (obj, psz_configdir);
387     free (psz_configdir);
388     return ret;
389 }
390
391 /*****************************************************************************
392  * config_SaveConfigFile: Save a module's config options.
393  *****************************************************************************
394  * This will save the specified module's config options to the config file.
395  * If psz_module_name is NULL then we save all the modules config options.
396  * It's no use to save the config options that kept their default values, so
397  * we'll try to be a bit clever here.
398  *
399  * When we save we mustn't delete the config options of the modules that
400  * haven't been loaded. So we cannot just create a new config file with the
401  * config structures we've got in memory.
402  * I don't really know how to deal with this nicely, so I will use a completly
403  * dumb method ;-)
404  * I will load the config file in memory, but skipping all the sections of the
405  * modules we want to save. Then I will create a brand new file, dump the file
406  * loaded in memory and then append the sections of the modules we want to
407  * save.
408  * Really stupid no ?
409  *****************************************************************************/
410 static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
411                            bool b_autosave )
412 {
413     libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc);
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     /* Acquire config file lock */
424     vlc_mutex_lock( &priv->config_lock );
425
426     if( config_PrepareDir( p_this ) )
427     {
428         msg_Err( p_this, "no configuration directory" );
429         goto error;
430     }
431
432     file = config_OpenConfigFile( p_this, "rt" );
433     if( file != NULL )
434     {
435         /* look for file size */
436         fseek( file, 0L, SEEK_END );
437         i_sizebuf = ftell( file );
438         fseek( file, 0L, SEEK_SET );
439         if( i_sizebuf >= LONG_MAX )
440             i_sizebuf = 0;
441     }
442
443     p_bigbuffer = p_index = malloc( i_sizebuf+1 );
444     if( !p_bigbuffer )
445         goto error;
446     p_bigbuffer[0] = 0;
447
448     /* List all available modules */
449     module_t **list = module_list_get (NULL);
450
451     /* backup file into memory, we only need to backup the sections we won't
452      * save later on */
453     b_backup = false;
454     while( file && fgets( p_line, 1024, file ) )
455     {
456         if( (p_line[0] == '[') && (p_index2 = strchr(p_line,']')))
457         {
458
459             /* we found a section, check if we need to do a backup */
460             for( i_index = 0; (p_parser = list[i_index]) != NULL; i_index++ )
461             {
462                 if( ((p_index2 - &p_line[1])
463                        == (int)strlen(p_parser->psz_object_name) )
464                     && !memcmp( &p_line[1], p_parser->psz_object_name,
465                                 strlen(p_parser->psz_object_name) ) )
466                 {
467                     if( !psz_module_name )
468                         break;
469                     else if( !strcmp( psz_module_name,
470                                       p_parser->psz_object_name ) )
471                         break;
472                 }
473             }
474
475             if( list[i_index] == NULL )
476             {
477                 /* we don't have this section in our list so we need to back
478                  * it up */
479                 *p_index2 = 0;
480 #if 0
481                 msg_Dbg( p_this, "backing up config for unknown module \"%s\"",
482                                  &p_line[1] );
483 #endif
484                 *p_index2 = ']';
485
486                 b_backup = true;
487             }
488             else
489             {
490                 b_backup = false;
491             }
492         }
493
494         /* save line if requested and line is valid (doesn't begin with a
495          * space, tab, or eol) */
496         if( b_backup && (p_line[0] != '\n') && (p_line[0] != ' ')
497             && (p_line[0] != '\t') )
498         {
499             strcpy( p_index, p_line );
500             p_index += strlen( p_line );
501         }
502     }
503     if( file )
504         fclose( file );
505     file = NULL;
506
507     /*
508      * Save module config in file
509      */
510     permanent = config_GetConfigFile (p_this);
511     if (!permanent)
512     {
513         module_list_free (list);
514         goto error;
515     }
516
517     if (asprintf (&temporary, "%s.%u", permanent, getpid ()) == -1)
518     {
519         temporary = NULL;
520         module_list_free (list);
521         goto error;
522     }
523
524     int fd = utf8_open (temporary, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
525     if (fd == -1)
526     {
527         module_list_free (list);
528         goto error;
529     }
530     file = fdopen (fd, "wt");
531     if (file == NULL)
532     {
533         close (fd);
534         module_list_free (list);
535         goto error;
536     }
537
538     fprintf( file, "\xEF\xBB\xBF###\n###  " COPYRIGHT_MESSAGE "\n###\n\n"
539        "###\n### lines beginning with a '#' character are comments\n###\n\n" );
540
541     /* Ensure consistent number formatting... */
542     locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
543     locale_t baseloc = uselocale (loc);
544
545     /* Look for the selected module, if NULL then save everything */
546     for( i_index = 0; (p_parser = list[i_index]) != NULL; i_index++ )
547     {
548         module_config_t *p_item, *p_end;
549
550         if( psz_module_name && strcmp( psz_module_name,
551                                        p_parser->psz_object_name ) )
552             continue;
553
554         if( !p_parser->i_config_items )
555             continue;
556
557         if( psz_module_name )
558             msg_Dbg( p_this, "saving config for module \"%s\"",
559                      p_parser->psz_object_name );
560
561         fprintf( file, "[%s]", p_parser->psz_object_name );
562         if( p_parser->psz_longname )
563             fprintf( file, " # %s\n\n", p_parser->psz_longname );
564         else
565             fprintf( file, "\n\n" );
566
567         for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
568              p_item < p_end;
569              p_item++ )
570         {
571             if ((p_item->i_type & CONFIG_HINT) /* ignore hint */
572              || p_item->b_removed              /* ignore deprecated option */
573              || p_item->b_unsaveable)          /* ignore volatile option */
574                 continue;
575
576             vlc_mutex_lock (p_item->p_lock);
577
578             /* Do not save the new value in the configuration file
579              * if doing an autosave, and the item is not an "autosaved" one. */
580             bool b_retain = b_autosave && !p_item->b_autosave;
581
582             if (IsConfigIntegerType (p_item->i_type))
583             {
584                 int val = b_retain ? p_item->saved.i : p_item->value.i;
585                 if (p_item->i_type == CONFIG_ITEM_KEY)
586                 {
587                     char *psz_key = ConfigKeyToString (val);
588                     config_Write (file, p_item->psz_text, N_("key"),
589                                   val == p_item->orig.i,
590                                   p_item->psz_name, "%s",
591                                   psz_key ? psz_key : "");
592                     free (psz_key);
593                 }
594                 else
595                     config_Write (file, p_item->psz_text,
596                                   (p_item->i_type == CONFIG_ITEM_BOOL)
597                                       ? N_("boolean") : N_("integer"),
598                                   val == p_item->orig.i,
599                                   p_item->psz_name, "%d", val);
600                 p_item->saved.i = val;
601             }
602             else
603             if (IsConfigFloatType (p_item->i_type))
604             {
605                 float val = b_retain ? p_item->saved.f : p_item->value.f;
606                 config_Write (file, p_item->psz_text, N_("float"),
607                               val == p_item->orig.f,
608                               p_item->psz_name, "%f", val);
609                 p_item->saved.f = val;
610             }
611             else
612             {
613                 const char *psz_value = b_retain ? p_item->saved.psz
614                                                  : p_item->value.psz;
615                 bool modified;
616
617                 assert (IsConfigStringType (p_item->i_type));
618
619                 if (b_retain && (psz_value == NULL)) /* FIXME: hack */
620                     psz_value = p_item->orig.psz;
621
622                 modified =
623                     (psz_value != NULL)
624                         ? ((p_item->orig.psz != NULL)
625                             ? (strcmp (psz_value, p_item->orig.psz) != 0)
626                             : true)
627                         : (p_item->orig.psz != NULL);
628
629                 config_Write (file, p_item->psz_text, N_("string"),
630                               !modified, p_item->psz_name, "%s",
631                               psz_value ? psz_value : "");
632
633                 if ( !b_retain )
634                 {
635
636                     free ((char *)p_item->saved.psz);
637                     if( (psz_value && p_item->orig.psz &&
638                          strcmp( psz_value, p_item->orig.psz )) ||
639                         !psz_value || !p_item->orig.psz)
640                         p_item->saved.psz = strdupnull (psz_value);
641                     else
642                         p_item->saved.psz = NULL;
643                 }
644             }
645
646             if (!b_retain)
647                 p_item->b_dirty = false;
648             vlc_mutex_unlock (p_item->p_lock);
649         }
650     }
651
652     module_list_free (list);
653     if (loc != (locale_t)0)
654     {
655         uselocale (baseloc);
656         freelocale (loc);
657     }
658
659     /*
660      * Restore old settings from the config in file
661      */
662     fputs( p_bigbuffer, file );
663     free( p_bigbuffer );
664
665     /*
666      * Flush to disk and replace atomically
667      */
668     fflush (file); /* Flush from run-time */
669 #ifndef WIN32
670     fdatasync (fd); /* Flush from OS */
671     /* Atomically replace the file... */
672     rename (temporary, permanent);
673     /* (...then synchronize the directory, err, TODO...) */
674     /* ...and finally close the file */
675 #endif
676     vlc_mutex_unlock (&priv->config_lock);
677     fclose (file);
678 #ifdef WIN32
679     /* Windows cannot remove open files nor overwrite existing ones */
680     remove (permanent);
681     rename (temporary, permanent);
682 #endif
683
684     free (temporary);
685     free (permanent);
686     return 0;
687
688 error:
689     if( file )
690         fclose( file );
691     vlc_mutex_unlock( &priv->config_lock );
692     free (temporary);
693     free (permanent);
694     free( p_bigbuffer );
695     return -1;
696 }
697
698 int config_AutoSaveConfigFile( vlc_object_t *p_this )
699 {
700     size_t i_index;
701     bool save = false;
702
703     assert( p_this );
704
705     /* Check if there's anything to save */
706     module_t **list = module_list_get (NULL);
707     for( i_index = 0; list[i_index] && !save; i_index++ )
708     {
709         module_t *p_parser = list[i_index];
710         module_config_t *p_item, *p_end;
711
712         if( !p_parser->i_config_items ) continue;
713
714         for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
715              p_item < p_end && !save;
716              p_item++ )
717         {
718             vlc_mutex_lock (p_item->p_lock);
719             save = p_item->b_autosave && p_item->b_dirty;
720             vlc_mutex_unlock (p_item->p_lock);
721         }
722     }
723     module_list_free (list);
724
725     return save ? VLC_SUCCESS : SaveConfigFile( p_this, NULL, true );
726 }
727
728 int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name )
729 {
730     return SaveConfigFile( p_this, psz_module_name, false );
731 }
732
733 int ConfigStringToKey( const char *psz_key )
734 {
735     int i_key = 0;
736     unsigned int i;
737     const char *psz_parser = strchr( psz_key, '-' );
738     while( psz_parser && psz_parser != psz_key )
739     {
740         for( i = 0; i < sizeof(vlc_modifiers) / sizeof(key_descriptor_t); i++ )
741         {
742             if( !strncasecmp( vlc_modifiers[i].psz_key_string, psz_key,
743                               strlen( vlc_modifiers[i].psz_key_string ) ) )
744             {
745                 i_key |= vlc_modifiers[i].i_key_code;
746             }
747         }
748         psz_key = psz_parser + 1;
749         psz_parser = strchr( psz_key, '-' );
750     }
751     for( i = 0; i < sizeof(vlc_keys) / sizeof( key_descriptor_t ); i++ )
752     {
753         if( !strcasecmp( vlc_keys[i].psz_key_string, psz_key ) )
754         {
755             i_key |= vlc_keys[i].i_key_code;
756             break;
757         }
758     }
759     return i_key;
760 }
761
762 char *ConfigKeyToString( int i_key )
763 {
764     char *psz_key = malloc( 100 );
765     char *p;
766     size_t index;
767
768     if ( !psz_key )
769     {
770         return NULL;
771     }
772     *psz_key = '\0';
773     p = psz_key;
774
775     for( index = 0; index < (sizeof(vlc_modifiers) / sizeof(key_descriptor_t));
776          index++ )
777     {
778         if( i_key & vlc_modifiers[index].i_key_code )
779         {
780             p += sprintf( p, "%s-", vlc_modifiers[index].psz_key_string );
781         }
782     }
783     for( index = 0; index < (sizeof(vlc_keys) / sizeof( key_descriptor_t));
784          index++)
785     {
786         if( (int)( i_key & ~KEY_MODIFIER ) == vlc_keys[index].i_key_code )
787         {
788             p += sprintf( p, "%s", vlc_keys[index].psz_key_string );
789             break;
790         }
791     }
792     return psz_key;
793 }
794