// Drop in replacement function for ast_readconfig() in asterisk.c // // (c) 2006 Sunrise Telephone Systems Ltd., Tokyo -- author: benjk // // Released under the GNU General Public License (GPL) version 2 // // for further information on propery list support see: // // http://www.sunrise-tel.com/asterisk-plist-support.html // -------------------------------------------------------------------------- // private function ast_readconfig(plist) // -------------------------------------------------------------------------- // Initialises all configuration parameters of the Asterisk core system from // settings stored in the master configuration property list. // // The parameter 'plist' specifies the name of the property list. It must be // a string taking the form of a Java package name or a NULL pointer. When // NULL is passed, the default property list "com.sunrise-tel.asterisk" will // be used. If an alternative property list name is passed, the alternative // property list will be used instead. // // Any parameters for which there are no settings stored in the property list // will be initialised from Asterisk buildtime defaults. // // If any command line options have been specified, indicated by any value // other than UNDEFINED in any global variable holding option parameters, // then the values stored in the option variable will take precedence over // the corresponding setting stored in the property list. // // dependencies // // preferences.h, preferences.c, Core Foundation or CF-Lite framework // // pre-conditions // // parameters: // parameter 'plist' holds a string with a valid plist name or NULL. // // preprocessor defines: // a preprocessor alias 'UNDEFINED' is defined with a value indicating // that an option variable has not been set by command line arguments. // // global variables: // // option variables // the following global variables of type int have been declared // option_verbose, option_debug, option_nofork, option_quiet, // option_console, option_highpriority, option_initcrypto, option_nocolor, // option_dumpcore, option_cache_record_files, option_overrideconfig. // // pathname variables // the following global variables of type char[] have been declared // ast_config_AST_CONFIG_DIR, ast_config_AST_MODULE_DIR, // ast_config_AST_SPOOL_DIR, ast_config_AST_VAR_DIR, ast_config_AST_LOG_DIR, // ast_config_AST_AGI_DIR, ast_config_AST_DB, ast_config_AST_KEY_DIR, // ast_config_AST_PID, ast_config_AST_SOCKET, ast_config_AST_RUN_DIR, // ast_config_AST_RECORDCACHE_DIR. // // post-conditions // // parameter 'plist' remains unchanged. no side effects. // // all option variables listed under pre-conditions which have had a value // other than UNDEFINED upon entry into this function will have been set to // their corresponding settings stored in the default or an alternative // property list passed in 'plist', or, in the absence of a stored value, // from the corresponding buildtime default. // // all pathname variables listed under pre-conditions will have been set to // their corresponding settings stored in the default or an alternative // property list passed in 'plist', or, in the absence of a stored value, // from the corresponding buildtime default. // // error-conditions // // if parameter 'plist' holds a string that specifies a non-existent // property list, the default property list will be used and the behaviour // of this function will be as if NULL had been passed in 'plist'. // // if any of the objects listed under pre-condtions are undeclared or of a // different data type, compile time or runtime errors are likely to occur // and even if no compile time nor runtime errors occurr, the behaviour of // this function may be unpredictable and the error conditions undefined. // -------------------------------------------------------------------------- static void ast_readconfig(const char *plist) { char tmpStr[80] = ""; #define copyStr(dest,source) strncpy((char *)dest, source, sizeof(dest) - 1) #define concatStr(str1,str2) strncat((char *)str1, str2, sizeof(str2) - 1) // ------------------------------------------------------------ // read/sync entire configuration from/with persistent storage // ------------------------------------------------------------ if (plist == NULL) { // use default plist name "com.sunrise-tel.asterisk" ast_prefs_init(); } else { // use user supplied plist name ast_prefs_initWithAppID(plist); } // end if // ------------------------------------------------------------ // Set Path for AGI Script Directory // ------------------------------------------------------------ // get value for key "AGIDir" ast_prefs_copyStrValueForKey(ast_config_AST_AGI_DIR, "Directories", "AGIDir"); // if not found, get buildtime default if (ast_config_AST_AGI_DIR == NULL) { copyStr(ast_config_AST_AGI_DIR, AST_AGI_DIR); } // end if // ------------------------------------------------------------ // Set Path for Binary Directory // ------------------------------------------------------------ // get value for key "BinDir" ast_prefs_copyStrValueForKey(ast_config_AST_BIN_DIR, "Directories", "BinDir"); // if not found, get buildtime default if (ast_config_AST_BIN_DIR == NULL) { copyStr(ast_config_AST_BIN_DIR, AST_BIN_DIR); } // end if // ------------------------------------------------------------ // Set Path for Etc Directory // ------------------------------------------------------------ // get value for key "EtcDir" ast_prefs_copyStrValueForKey(ast_config_AST_CONFIG_DIR, "Directories", "EtcDir"); // if not found, get buildtime default if (ast_config_AST_CONFIG_DIR == NULL) { copyStr(ast_config_AST_CONFIG_DIR, AST_CONFIG_DIR); } // end if // ------------------------------------------------------------ // Set Path for Image Directory // ------------------------------------------------------------ // get value for key "ImgDir" ast_prefs_copyStrValueForKey(ast_config_AST_IMG_DIR, "Directories", "ImgDir"); // if not found, get buildtime default if (ast_config_AST_IMG_DIR == NULL) { copyStr(ast_config_AST_IMG_DIR, AST_IMAGES); } // end if // ------------------------------------------------------------ // Set Path for Key Directory // ------------------------------------------------------------ // get value for key "KeyDir" ast_prefs_copyStrValueForKey(ast_config_AST_KEY_DIR, "Directories", "KeyDir"); // if not found, get buildtime default if (ast_config_AST_KEY_DIR == NULL) { copyStr(ast_config_AST_KEY_DIR, AST_KEY_DIR); } // end if // ------------------------------------------------------------ // Set Path for Log Directory // ------------------------------------------------------------ // get value for key "LogDir" ast_prefs_copyStrValueForKey(ast_config_AST_LOG_DIR, "Directories", "LogDir"); // if not found, get buildtime default if (ast_config_AST_LOG_DIR == NULL) { copyStr(ast_config_AST_LOG_DIR, AST_LOG_DIR); } // end if // ------------------------------------------------------------ // Set Path for Modules Directory // ------------------------------------------------------------ // get value for key "ModDir" ast_prefs_copyStrValueForKey(ast_config_AST_MODULE_DIR, "Directories", "ModDir"); // if not found, get buildtime default if (ast_config_AST_MODULE_DIR == NULL) { copyStr(ast_config_AST_MODULE_DIR, AST_MODULE_DIR); } // end if // ------------------------------------------------------------ // Set Path for Run Directory // ------------------------------------------------------------ // get value for key "RunDir" ast_prefs_copyStrValueForKey(ast_config_AST_RUN_DIR, "Directories", "RunDir"); // if not found, get buildtime default if (ast_config_AST_RUN_DIR == NULL) { copyStr(ast_config_AST_RUN_DIR, AST_RUN_DIR); } // end if // ------------------------------------------------------------ // Set Path for Sounds Directory // ------------------------------------------------------------ // get value for key "SoundsDir" ast_prefs_copyStrValueForKey(ast_config_AST_SOUNDS_DIR, "Directories", "SoundsDir"); // if not found, get buildtime default if (ast_config_AST_SOUNDS_DIR == NULL) { copyStr(ast_config_AST_SOUNDS_DIR, AST_SOUNDS); } // enf if // ------------------------------------------------------------ // Set Path for Spool Directory // ------------------------------------------------------------ // get value for key "SpoolDir" ast_prefs_copyStrValueForKey(ast_config_AST_SPOOL_DIR, "Directories", "SpoolDir"); // if not found, get buildtime default if (ast_config_AST_SPOOL_DIR == NULL) { copyStr(ast_config_AST_SPOOL_DIR, AST_SPOOL_DIR); } // end if // ------------------------------------------------------------ // Set Path for Temporary Directory // ------------------------------------------------------------ // get value for key "TempDir" ast_prefs_copyStrValueForKey(ast_config_AST_TMP_DIR, "Directories", "TempDir"); // if not found, get buildtime default if (ast_config_AST_TMP_DIR == NULL) { copyStr(ast_config_AST_TMP_DIR, AST_TMP_DIR); } // end if // ------------------------------------------------------------ // Set Path for Sound Record Cache Directory // ------------------------------------------------------------ // record cache directory is the same as temporary directory copyStr(ast_config_AST_RECORDCACHE_DIR, ast_config_AST_TMP_DIR); // ------------------------------------------------------------ // Set Path for VarLib Directory // ------------------------------------------------------------ // get value for key "VarLibDir" ast_prefs_copyStrValueForKey(ast_config_AST_VAR_DIR, "Directories", "VarLibDir"); // if not found, get buildtime default if (ast_config_AST_VAR_DIR == NULL) { copyStr(ast_config_AST_VAR_DIR, AST_VAR_DIR); } // end if // ------------------------------------------------------------ // Set Path for Internal Database // ------------------------------------------------------------ // get value for key "Database" ast_prefs_copyStrValueForKey(tmpStr, "Filenames", "Database"); // if found, prepend VarLibDir path if (tmpStr != NULL) { copyStr(ast_config_AST_DB, AST_VAR_DIR); concatStr(ast_config_AST_DB, "/"); concatStr(ast_config_AST_DB, tmpStr); } // if not found, get buildtime default else { copyStr(ast_config_AST_DB, AST_DB); } // end if // ------------------------------------------------------------ // Set Path for Asterisk PID File // ------------------------------------------------------------ // get value for key "PIDFile" ast_prefs_copyStrValueForKey(tmpStr, "Filenames", "PIDFile"); // if found, prepend RunDir path if (tmpStr != NULL) { copyStr(ast_config_AST_PID, AST_RUN_DIR); concatStr(ast_config_AST_PID, "/"); concatStr(ast_config_AST_PID, tmpStr); } // if not found, get buildtime default else { copyStr(ast_config_AST_PID, AST_PID); } // end if // ------------------------------------------------------------ // Set Path for Remote Control Socket // ------------------------------------------------------------ // get value for key "Socket" ast_prefs_copyStrValueForKey(tmpStr, "Filenames", "Socket"); // if found, prepend RunDir path if (tmpStr != NULL) { copyStr(ast_config_AST_SOCKET, AST_RUN_DIR); concatStr(ast_config_AST_SOCKET, "/"); concatStr(ast_config_AST_SOCKET, tmpStr); } // if not found, get buildtime default else { copyStr(ast_config_AST_SOCKET, AST_SOCKET); } // end if /* ------------------------------------------------------------ Note: the following options are read/set elsewhere ... "AppendHostToLogFiles" in logger.c "AutoLoadModules" in loader.c "AutoRotateQueueLog" in logger.c ------------------------------------------------------------ */ // ------------------------------------------------------------ // Set Option Console Verbosity // ------------------------------------------------------------ // if not set by command line argument ... if (option_verbose == UNDEFINED) { // ... get value for key "ConsoleVerbosityLevel" ast_prefs_copyStrValueForKey(tmpStr, "Options", "ConsoleVerbosityLevel"); // if found, use value if (tmpStr != NULL) { option_verbose = atoi(tmpStr); } // if not found, use buildtime default else { option_verbose = AST_VERBOSE; } // end if } // end if // ------------------------------------------------------------ // Set Option Extended Debug Mode // ------------------------------------------------------------ // if not set by command line argument ... if (option_debug == UNDEFINED) { // ... get value for key "ExtendedDebugMode" ast_prefs_copyStrValueForKey(tmpStr, "Debugging", "ExtendedDebugMode"); // if found, use value if (tmpStr != NULL) { option_debug = ast_true(tmpStr); } // if not found, use buildtime default else { option_debug = AST_DEBUG; } // end if // enabling debug implies nofork if (option_debug == true) { option_nofork = true; } // end if } // end if // ------------------------------------------------------------ // Set Option Quiet Mode (supress output) // ------------------------------------------------------------ // if not set by command line argument ... if (option_quiet == UNDEFINED) { // ... get value for key "QuietMode" ast_prefs_copyStrValueForKey(tmpStr, "Options", "QuietMode"); // if found, use value if (tmpStr != NULL) { option_quiet = ast_true(tmpStr); } // if not found, use buildtime default else { option_quiet = AST_QUIET; } // end if } // end if // ------------------------------------------------------------ // Set Option Dump Core On Crash // ------------------------------------------------------------ // if not set by command line argument ... if (option_dumpcore == UNDEFINED) { // ... get value for key "DumpCoreOnCrash" ast_prefs_copyStrValueForKey(tmpStr, "Options", "DumpCoreOnCrash"); // if found, use value if (tmpStr != NULL) { option_dumpcore = ast_true(tmpStr); } // if not found, use buildtime default else { option_dumpcore = AST_DUMPCORE; } // end if } // end if // ------------------------------------------------------------ // Set Option Pseudo Realtime Mode (high priority) // ------------------------------------------------------------ // if not set by command line argument ... if (option_highpriority == UNDEFINED) { // ... get value for key "PseudoRealtimeMode" ast_prefs_copyStrValueForKey(tmpStr, "Options", "PseudoRealtimeMode"); // if found, use value if (tmpStr != NULL) { option_highpriority = ast_true(tmpStr); } // if not found, use buildtime default else { option_highpriority = AST_HIGHPRIORITY; } // end if } // end if // ------------------------------------------------------------ // Set Option Init Crypto Keys On Launch // ------------------------------------------------------------ // if not set by command line argument ... if (option_initcrypto == UNDEFINED) { // ... get value for key "InitCryptoKeysOnLaunch" ast_prefs_copyStrValueForKey(tmpStr, "Options", "InitCryptoKeysOnLaunch"); // if found, use value if (tmpStr != NULL) { option_initcrypto = ast_true(tmpStr); } // if not found, use buildtime default else { option_initcrypto = AST_INITCRYPTO; } // end if } // end if // ------------------------------------------------------------ // Set Option Colorize Console // ------------------------------------------------------------ // if not set by command line argument ... if (option_nocolor == UNDEFINED) { // ... get value for key "InitCryptoKeysOnLaunch" ast_prefs_copyStrValueForKey(tmpStr, "Options", "ColorizeConsole"); // if found, use value if (tmpStr != NULL) { option_nocolor = !ast_true(tmpStr); } // if not found, use buildtime default else { option_nocolor = AST_NOCOLOR; } // end if } // end if // ------------------------------------------------------------ // Set Option Record Sounds As Temporary Files // ------------------------------------------------------------ // if not set by command line argument ... if (option_cache_record_files == UNDEFINED) { // ... get value for key "RecSoundsAsTempFiles" ast_prefs_copyStrValueForKey(tmpStr, "Options", "RecSoundsAsTempFiles"); // if found, use value if (tmpStr != NULL) { option_cache_record_files = !ast_true(tmpStr); } // if not found, use buildtime default else { option_cache_record_files = AST_CACHERECORDFILES; } // end if } // end if // ------------------------------------------------------------ // Set Option Console Mode -- command line only // ------------------------------------------------------------ // if not set by command line argument ... if (option_console == UNDEFINED) { // ... use buildtime default option_console = false; } // end if // ------------------------------------------------------------ // Set Option Fork Mode -- command line only // ------------------------------------------------------------ // if not set by command line argument ... if (option_nofork == UNDEFINED) { // ... use buildtime default option_nofork = false; } // end if #undef copyStr #undef concatStr } // end ast_readconfig