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

int rpl_digest_parse ( rpl_str_t  filename  ) 

Performs digest parsing.

Parameters:
filename 
Returns:
1 on error, 0 on success.

Definition at line 131 of file digestp.c.

References digest_characters(), digest_end(), digest_start(), rpl_log_error(), rpl_me_free(), rpl_me_malloc(), and rpl_message_get().

Referenced by rpl_mod_index_process().

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

    /* 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 */
    if((fp=fopen(filename, "rb")) == NULL) {
        msg = rpl_message_get("DIGEST_FILE_NOT_FOUND", filename, " (", strerror(errno), ")", RPL_EOM);
        rpl_log_error(msg);

        return 1;
    }

    /* configure the parser */
    if((parser = XML_ParserCreate(NULL)) == NULL) {
        fprintf(stderr, rpl_message_get("OUT_OF_MEMORY", "config XML parser", RPL_EOM));
        exit(EXIT_FAILURE);
    }
    XML_SetElementHandler(parser, digest_start, digest_end);
    XML_SetCharacterDataHandler(parser, digest_characters);

    /* parse the document */
    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) {
            /* XML_WELLFORMEDNESS_ERROR */
                  loc = rpl_me_malloc(16);
                  sprintf(loc, " (line %d)", XML_GetCurrentLineNumber(parser));
            msg = rpl_message_get("DIGEST_FILE_NOT_WELLFORMED", filename, loc, RPL_EOM);
            rpl_log_error(msg);
                  rpl_me_free(loc);
                  rpl_me_free(msg);
            return 1;
        }
    } while(!flag);


    /* generate the XHTML fragment for the index file
    *fragment = concat("<dl><dd>", link, "</dd><dt>", digest_summary, "...", more, "</dt></dl>", RPL_STR_EOC);
    */
    return 0;
}


Generated by  Doxygen 1.6.0   Back to index