Logo Search packages:      
Sourcecode: rapple version File versions  Download package

int rpl_cfg_parse ( rpl_str_t  cfg_filename  ) 

Performs configuration parsing.

Uses the EXPAT library to parse the XML formatted configuration file.

cfg_filename Configuration file to parse.
-1 if config file cannot be found, -2 if parsing error occurs, otherwise 0.

Definition at line 353 of file confp.c.

References config_characters(), config_end(), config_start(), rpl_list_init(), rpl_me_free(), rpl_me_malloc(), and rpl_message_get().

Referenced by check_config().

    XML_Parser parser;
    char *xml_buf;
    int flag;
    size_t length;
    FILE *fp;
    rpl_str_t msg;

    if(cfg_filename == NULL)
        cfg_filename = (getenv(RPL_CFG_ENV_VAR) == NULL) ? RPL_CFG_DEFAULT_FILE_NAME :
      cfg_conf_filename = strdup(cfg_filename);

    /* open the file (and acquire a descriptor for it) */
    /* binary "b" is req'd for ANSI C portability but has no effect on POSIX platforms */
    errno = 0;
    if((fp=fopen(cfg_filename, "rb")) == NULL) {
        msg = rpl_message_get("RPL_CFG_FILE_NOT_FOUND", RPL_EOM);
        fprintf(stderr, "[FATAL] %s: %s\n", msg, cfg_filename);
        return RPL_CFG_FILE_NOT_FOUND;
    /* log_fatal(get_message("FS_OPEN_FAILED", strerror(errno), EOM)); */

    rpl_list_init (&cfg_dg_dir_names);
    rpl_list_init (&cfg_dg_dir_titles);

    if((parser = XML_ParserCreate(NULL)) == NULL) {
        fprintf(stderr, rpl_message_get("OUT_OF_MEMORY", "config XML parser", RPL_EOM));
        return RPL_CFG_PARSE_ERROR;

    XML_SetElementHandler(parser, config_start, config_end);
    XML_SetCharacterDataHandler(parser, config_characters);

    cfg_str_buf = (rpl_str_t)rpl_me_malloc(RPL_XML_MAX_VALUE_LEN + 1);

    xml_buf = (rpl_str_t)rpl_me_malloc(RPL_XML_BUFFER_BLK + 1);
    do {
        length = fread(xml_buf, 1, RPL_XML_BUFFER_BLK, fp);
        flag = length < strlen(xml_buf);
        if (XML_Parse(parser, xml_buf, length, flag) == XML_STATUS_ERROR) {
            fprintf(stderr,"Error:  configuration file is not well formed!\n");
            fprintf(stderr,"%s at line %d\n", XML_ErrorString(XML_GetErrorCode(parser)),
            return RPL_CFG_PARSE_ERROR;
    } while(!flag);

    fclose (fp);
    rpl_me_free (cfg_str_buf);
    rpl_me_free (xml_buf);

    return 0;

Generated by  Doxygen 1.6.0   Back to index