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