nfs-ganesha 1.4

9p_read_conf.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright CEA/DAM/DIF  (2011)
00005  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00006  *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
00007  *
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 3 of the License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022  *
00023  * ---------------------------------------
00024  */
00025 
00034 #ifdef HAVE_CONFIG_H
00035 #include "config.h"
00036 #endif
00037 
00038 #ifdef _SOLARIS
00039 #include "solaris_port.h"
00040 #endif
00041 
00042 #include <stdio.h>
00043 #include <string.h>
00044 #include <pthread.h>
00045 #include "nfs_core.h"
00046 #include "log.h"
00047 #include "9p.h"
00048 #include "config_parsing.h"
00049 
00050 int _9p_read_conf( config_file_t   in_config,
00051                    _9p_parameter_t *pparam )
00052 {
00053   int var_max;
00054   int var_index;
00055   int err;
00056   char *key_name;
00057   char *key_value;
00058   config_item_t block;
00059 
00060   int DebugLevel = -1;
00061   char *LogFile = NULL;
00062 
00063   /* Is the config tree initialized ? */
00064   if(in_config == NULL || pparam == NULL)
00065     return -1 ;
00066 
00067   /* Get the config BLOCK */
00068   if((block = config_FindItemByName(in_config, CONF_LABEL_9P )) == NULL)
00069     return -2 ; /* no 9P config, use default */
00070   else if(config_ItemType(block) != CONFIG_ITEM_BLOCK)
00071     return -1 ;
00072 
00073   var_max = config_GetNbItems(block);
00074 
00075   for(var_index = 0; var_index < var_max; var_index++)
00076     {
00077       config_item_t item;
00078 
00079       item = config_GetItemByIndex(block, var_index);
00080 
00081       /* Get key's name */
00082       if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0)
00083         {
00084           fprintf(stderr,
00085                   "Error reading key[%d] from section \"%s\" of configuration file.\n",
00086                   var_index, CONF_LABEL_9P );
00087           return -1 ;
00088         }
00089       if(!strcasecmp(key_name, "_9P_Port"))     
00090         {
00091           pparam->_9p_port = atoi( key_value ) ;
00092         }
00093       else if(!strcasecmp(key_name, "DebugLevel"))
00094         {
00095           DebugLevel = ReturnLevelAscii(key_value);
00096 
00097           if(DebugLevel == -1)
00098             {
00099               fprintf(stderr,
00100                       "9P: ERROR: Invalid debug level name: \"%s\".",
00101                       key_value);
00102               return -1 ;
00103             }
00104         }
00105       else if(!strcasecmp(key_name, "LogFile"))
00106         {
00107           LogFile = key_value;
00108         }
00109       else
00110         {
00111           fprintf(stderr,
00112                   "Unknown or unsettable key: %s (item %s)\n",
00113                   key_name, CONF_LABEL_9P);
00114           return -1 ;
00115         }
00116     } /* for */
00117 
00118   /* init logging */
00119   if(LogFile)
00120     SetComponentLogFile(COMPONENT_9P, LogFile);
00121 
00122   if(DebugLevel > -1)
00123     SetComponentLogLevel(COMPONENT_9P, DebugLevel);
00124 
00125 
00126   return 0 ;
00127 } /* _9p_read_conf */