/* Asterisk INI to Property List File Conversion Utility -- Version 1.10 * * (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 /* command line argument processing */ #include "hash.h" #include "pathnames.h" #include "keywords.h" #include "symdump.h" #include "parser.h" #include "converter.h" #define NONE 0x35048678 #define CORE 0x353D8F3F #define PLUGIN 0x51E15E73 #define DIALPLAN 0x29992519 // -------------------------------------------------------------------------- // Version info string // -------------------------------------------------------------------------- // #define VERSION_INFO \ "aini2plist version 1.10\n" // -------------------------------------------------------------------------- // Copyright notice // -------------------------------------------------------------------------- // #define COPYRIGHT_NOTICE \ "Asterisk INI file to property list converter\n" \ "Copyright (C) 2006 Sunrise Telephone Systems Ltd.\n" \ "This software is provided without warranty of any kind.\n" // -------------------------------------------------------------------------- // function print_version() // -------------------------------------------------------------------------- // void print_version() { printf(VERSION_INFO); } // end print_version // -------------------------------------------------------------------------- // function print_copyright() // -------------------------------------------------------------------------- // void print_copyright() { printf(COPYRIGHT_NOTICE); } // end print_copyright // -------------------------------------------------------------------------- // function print_usage() // -------------------------------------------------------------------------- // void print_usage() { print_version(); print_copyright(); printf("usage: aini2plist [options] infile outfile\n"); printf("options:\n"); printf(" -h display help and exit\n"); printf(" -c ask for confirmation before overwriting files\n"); printf(" -d dictionary to use, 'none', 'core', 'plugin' or 'dialplan'\n"); printf(" -D dump infile symbol stream (for debugging)\n"); printf(" -v increase verbosity level (max: %i)\n", MAX_VERBOSITY); printf(" -V display software version and exit\n"); printf(" -x increase comment exclusion level (max: %i)\n", MAX_COMMENT_EXCLUSION); } // end print_usage // -------------------------------------------------------------------------- // function main() // -------------------------------------------------------------------------- // int main (int argc, const char * argv[]) { int c, index, status, confirm = 0, dump = 0, verbosity = 0, comment_exclusion = 0; char _filename[MAX_PATHNAME_LENGTH] = ""; // private char _infile[MAX_PATHNAME_LENGTH] = ""; // private char _outfile[MAX_PATHNAME_LENGTH] = ""; // private char *filename = (char *)&_filename; // for use char *infile = (char *)&_infile; // for use char *outfile = (char *)&_outfile; // for use unsigned int hash = 0; KeywordDictionary dictionary; while ((c = getopt (argc, (void *)argv, "hcd:DvVx")) != -1) { switch (c) { case 'h': print_usage(); return 0; case 'c': confirm = 1; break; case 'D': dump = 1; break; case 'd': hash = calc_hash(optarg); break; case 'v': if (verbosity < MAX_VERBOSITY) { verbosity++; } // end if break; case 'V': print_version(); return 0; case 'x': if (comment_exclusion < MAX_COMMENT_EXCLUSION) { comment_exclusion++; } // end if break; case '?': print_usage(); return 1; default: // just in case print_usage(); } // end switch } // end while print_version(); print_copyright(); printf("\n"); // fprintf(stderr, "test writing to stderr.\n\n"); if (verbosity > 0) printf("verbosity level: %i\n", verbosity); // determine dictionary to use if ((hash == 0) || (hash == NONE)) { // no dictionary if (verbosity > 0) printf("proceeding without dictionary.\n"); dictionary = NO_DICTIONARY; } else if (hash == CORE) { // core dictionary if (verbosity > 0) printf("proceeding with core dictionary.\n"); dictionary = CORE_DICTIONARY; } else if (hash == PLUGIN) { // plugin dictionary if (verbosity > 0) printf("proceeding with plugins dictionary.\n"); dictionary = PLUGIN_DICTIONARY; } else if (hash == DIALPLAN) { // dialplan dictionary printf("dialplan mode has not been implemented yet.\n"); return 1; // dictionary = DIALPLAN_DICTIONARY; } else { printf("invalid dictionary specified, proceeding without dictionary.\n"); dictionary = NO_DICTIONARY; } // end if // determine infile index = optind; if (index >= argc) { printf("infile not specified, conversion aborted."); return 1; } else { strncpy(filename, argv[index], strlen(argv[index])); } // end if // check if infile is a path if (isPathname(filename)) { // just in case it's got a leading dot-slash ... copyStrPathnameByExpandingLeadingDotInPath(infile, filename); } else { // prepend filename with user's working directory copyStrFromWorkingDirectory(infile); modifyPathnameByAppendingFilename(infile, filename); } // end if if (verbosity > 0) printf("infile: %s\n", infile); // check if infile exists, abort if it doesn't if (fileDoesNotExistAtPath(infile)) { if (errno == EACCES) { printf("access to infile denied\n"); } else { printf("infile does not exist\n"); } // end if return 1; } // end if // determine outfile index++; if (index >= argc) { if (verbosity > 0) printf("outfile not specified, using default.\n"); // copy directory name from expanded infile to outfile copyStrDirectoryByRemovingFilenameAndExtension(outfile, infile); // obtain filename from infile and replace extension with plist extension strncat(filename, infile, strlen(filename)); modifyFilenameByReplacingFileExtension(filename, PLIST_FILE_EXTENSION); // append the new filename to outfile modifyPathnameByAppendingFilename(outfile, filename); } else { strncpy(filename, argv[index], strlen(argv[index]) + 1); // check if outfile is a path if (isPathname(filename)) { // just in case it's got a leading dot-slash ... copyStrPathnameByExpandingLeadingDotInPath(outfile, filename); } else { // prepend filename with user's working directory copyStrFromWorkingDirectory(outfile); modifyPathnameByAppendingFilename(outfile, filename); } // end if } // end if if (verbosity > 0) printf("outfile: %s\n", outfile); // TO DO: handle confirmation mode if (dump == 0) { // set verbosity and comment exclusion levels set_global_converter_defaults(verbosity, comment_exclusion); // convert infile to outfile status = convert_aini_to_plist(dictionary, infile, outfile); } else { // dump symbol stream status = dump_file(infile); // TO DO: outfile support } // end if return (status == 0); // shell expects 0 for success } // end main // END OF FILE