/* Asterisk INI to Property List File Conversion Utility -- Version 1.10 * * converter.c * aini2plist * * Asterisk INI configuration file converter module * * Author: Benjamin Kowarsch * * (C) 2006 Sunrise Telephone Systems Ltd. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * In countries and territories where the above no-warranty disclaimer is * not permissible by applicable law, the following terms apply: * * NO PERMISSION TO USE THE SOFTWARE IS GRANTED AND THE SOFTWARE MUST NOT BE * USED AT ALL IN SUCH COUNTRIES AND TERRITORIES WHERE THE ABOVE NO-WARRANTY * DISCLAIMER IS NOT PERMISSIBLE AND INVALIDATED BY APPLICABLE LAW. HOWEVER, * THE COPYRIGHT HOLDERS HEREBY WAIVE THEIR RIGHT TO PURSUE OFFENDERS AS LONG * AS THEY OTHERWISE ABIDE BY THE TERMS OF THE LICENSE AS APPLICABLE FOR USE * OF THE SOFTWARE IN COUNTRIES AND TERRITORIES WHERE THE ABOVE NO-WARRANTY * DISCLAIMER IS PERMITTED BY APPLICABLE LAW. THIS WAIVER DOES NOT CONSTITUTE * A LICENSE TO USE THE SOFTWARE IN COUNTRIES AND TERRITORIES WHERE THE ABOVE * NO-WARRANTY DISCLAIMER IS NOT PERMISSIBLE AND INVALIDATED BY APPLICABLE * LAW. ANY LIABILITY OF ANY KIND IS CATEGORICALLY RULED OUT AT ALL TIMES. */ #include #include #include #include "globaldefs.h" #include "pathnames.h" #include "parser.h" #include "keywords.h" #include "intermediate.h" #include "plistgen.h" #include "converter.h" // --------------------------------------------------------------------------- // Global converter defaults // --------------------------------------------------------------------------- static CARDINAL default_converter_verbosity_level = 0; static CARDINAL default_converter_comment_exclusion_level = 0; // -------------------------------------------------------------------------- // private function get_config_path() // -------------------------------------------------------------------------- // static char *get_config_path() { CARDINAL section, key; section = KEYWORD_DIRECTORIES; if (key_is_present(section, KEYWORD_ASTETCDIR) == true) { key = KEYWORD_ASTETCDIR; } else if (key_is_present(section, KEYWORD_OPBXETCDIR) == true) { key = KEYWORD_OPBXETCDIR; } else { // no config path return NULL; } // end if return get_value_for_key_at_index(section, key, 1); } // end get_config_path // -------------------------------------------------------------------------- // function set_global_converter_defaults(verbosity, comment_exclusion) // -------------------------------------------------------------------------- // // verbosity levels: // // level 0 (default) // least verbose // // level 3 // most verbose // // comment exclusion levels: // // level 0 (default) // all comments are processed // // level 1 // comment lines inside sections are ignored // inline comments inside sections are processed // comment lines outside of sections are processed // // level 2 // comment lines inside sections are ignored // inline comments inside sections are ignored // comment lines outside of sections are processed // // level 3 // all comments are ignored void set_global_converter_defaults(CARDINAL verbosity, CARDINAL comment_exclusion) { // set the defaults if ((verbosity >= 0) && (verbosity <= MAX_VERBOSITY)) { default_converter_verbosity_level = verbosity; } // end if if ((comment_exclusion >= 0) && (comment_exclusion <= MAX_COMMENT_EXCLUSION)) { default_converter_comment_exclusion_level = comment_exclusion; } // end if } // end set_global_converter_defaults #define verbosity default_converter_verbosity_level #define comment_exclusion default_converter_comment_exclusion_level // -------------------------------------------------------------------------- // function convert_aini_to_plist(dictionary, infile, outfile) // -------------------------------------------------------------------------- // int convert_aini_to_plist(KeywordDictionary dictionary, const char * infile, const char * outfile) { CARDINAL parser_status = 0, generator_status = 0; char _secondary_file[MAX_PATHNAME_LENGTH]; char *config_path, *secondary_file = (char *) &_secondary_file; init_keywords_with_dict(dictionary); set_global_parser_defaults(verbosity, comment_exclusion); parser_status = parse_file(infile); // TO DO: obtain secondary files to process from EtcDir and invoke parser for each file config_path = get_config_path(); if (config_path != NULL) { if (verbosity > 0) { fprintf(stderr, "configuration path: %s\n", config_path); } // end if strncpy(secondary_file, config_path, strlen(config_path) + 1); strncat(secondary_file, "/logger.conf", 12); fprintf(stderr, "secondary infile: %s\n", secondary_file); parser_status = parser_status && parse_file(secondary_file); } // end if generator_status = create_plist(outfile); return ((parser_status == 1) && (generator_status == 1)); } // end convert_aini_to_plist // END OF FILE