Back to index

avfs  1.0.1
Classes | Defines | Typedefs | Functions
hip_xml.h File Reference
#include "string_utils.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  hip_xml_elm

Defines

#define HIP_ELM_unknown   -1
#define HIP_ELM_root   0
#define HIP_ELM_UNUSED   (100)
#define HIP_XML_VALID   (0)
#define HIP_XML_INVALID   (-1)
#define HIP_XML_DECLINE   (-2)
#define HIP_XML_CDATA   (1<<1)
#define HIP_XML_COLLECT   ((1<<2) | HIP_XML_CDATA)
#define HIP_XML_UTF8DECODE   (1<<3)
#define HIP_XML_MIXED   (1<<4)

Typedefs

typedef int hip_xml_elmid
typedef int(* hip_xml_validate_cb )(hip_xml_elmid parent, hip_xml_elmid child)
typedef int(* hip_xml_startelm_cb )(void *userdata, const struct hip_xml_elm *elm, const char **atts)
typedef int(* hip_xml_endelm_cb )(void *userdata, const struct hip_xml_elm *s, const char *cdata)
typedef void(* hip_xml_cdata_cb )(void *userdata, const struct hip_xml_elm *s, const char *cdata, int len)
typedef struct hip_xml_parser_s

Functions

hip_xml_parser * hip_xml_create (void)
void hip_xml_push_handler (hip_xml_parser *p, const struct hip_xml_elm *elements, hip_xml_validate_cb validate_cb, hip_xml_startelm_cb startelm_cb, hip_xml_endelm_cb endelm_cb, void *userdata)
void hip_xml_push_mixed_handler (hip_xml_parser *p, const struct hip_xml_elm *elements, hip_xml_validate_cb validate_cb, hip_xml_startelm_cb startelm_cb, hip_xml_cdata_cb cdata_cb, hip_xml_endelm_cb endelm_cb, void *userdata)
int hip_xml_valid (hip_xml_parser *p)
void hip_xml_destroy (hip_xml_parser *p)
void hip_xml_parse (hip_xml_parser *p, const char *block, size_t len)
void hip_xml_parse_v (void *userdata, const char *block, size_t len)
int hip_xml_currentline (hip_xml_parser *p)
void hip_xml_set_error (hip_xml_parser *p, const char *msg)
const char * hip_xml_get_error (hip_xml_parser *p)

Class Documentation

struct hip_xml_elm

Definition at line 77 of file hip_xml.h.

Class Members
unsigned int flags
hip_xml_elmid id
const char * name
const char * nspace

Define Documentation

#define HIP_ELM_root   0

Definition at line 68 of file hip_xml.h.

#define HIP_ELM_unknown   -1

Definition at line 67 of file hip_xml.h.

#define HIP_ELM_UNUSED   (100)

Definition at line 70 of file hip_xml.h.

#define HIP_XML_CDATA   (1<<1)

Definition at line 118 of file hip_xml.h.

#define HIP_XML_COLLECT   ((1<<2) | HIP_XML_CDATA)

Definition at line 120 of file hip_xml.h.

#define HIP_XML_DECLINE   (-2)

Definition at line 97 of file hip_xml.h.

#define HIP_XML_INVALID   (-1)

Definition at line 96 of file hip_xml.h.

#define HIP_XML_MIXED   (1<<4)

Definition at line 124 of file hip_xml.h.

#define HIP_XML_UTF8DECODE   (1<<3)

Definition at line 122 of file hip_xml.h.

#define HIP_XML_VALID   (0)

Definition at line 95 of file hip_xml.h.


Typedef Documentation

typedef void(* hip_xml_cdata_cb)(void *userdata, const struct hip_xml_elm *s, const char *cdata, int len)

Definition at line 110 of file hip_xml.h.

typedef int hip_xml_elmid

Definition at line 72 of file hip_xml.h.

typedef int(* hip_xml_endelm_cb)(void *userdata, const struct hip_xml_elm *s, const char *cdata)

Definition at line 107 of file hip_xml.h.

typedef struct hip_xml_parser_s

Definition at line 114 of file hip_xml.h.

typedef int(* hip_xml_startelm_cb)(void *userdata, const struct hip_xml_elm *elm, const char **atts)

Definition at line 103 of file hip_xml.h.

typedef int(* hip_xml_validate_cb)(hip_xml_elmid parent, hip_xml_elmid child)

Definition at line 100 of file hip_xml.h.


Function Documentation

hip_xml_parser* hip_xml_create ( void  )

Definition at line 633 of file hip_xml.c.

{
    hip_xml_parser *p = ne_calloc(sizeof *p);
    /* Initialize other stuff */
    p->valid = 1;
    /* Placeholder for the root element */
    p->current = p->root = ne_calloc(sizeof(struct hip_xml_state));
    p->root->elm = &root_element;
    /* Initialize the cdata buffer */
    p->buffer = sbuffer_create();
#ifdef HAVE_EXPAT
    p->parser = XML_ParserCreate(NULL);
    if (p->parser == NULL) {
       abort();
    }
    XML_SetElementHandler(p->parser, start_element, end_element);
    XML_SetCharacterDataHandler(p->parser, char_data);
    XML_SetUserData(p->parser, (void *) p);
#else
    p->parser = xmlCreatePushParserCtxt(&sax_handler, 
                                   (void *)p, NULL, 0, NULL);
    if (p->parser == NULL) {
       abort();
    }
#endif
    return p;
}

Here is the call graph for this function:

int hip_xml_currentline ( hip_xml_parser *  p)

Definition at line 241 of file hip_xml.c.

{
#ifdef HAVE_EXPAT
    return XML_GetCurrentLineNumber(p->parser);
#else
    return p->parser->input->line;
#endif
}
void hip_xml_destroy ( hip_xml_parser *  p)

Definition at line 769 of file hip_xml.c.

{
    struct hip_xml_state *s, *parent;
    struct hip_xml_handler *hand, *next;

    sbuffer_destroy(p->buffer);
    /* Clean up any states which may remain.
     * If p.valid, then this should be only the root element. */
    for (s = p->current; s!=NULL; s=parent) {
       parent = s->parent;
       destroy_state(s);
    }

    /* Free up the handlers on the stack: the base of the stack
     * is the handler in the root element, so start there. */
    for (hand = p->root->handler; hand!=NULL; hand=next) {
       next = hand->next;
       free(hand);
    }
        
#ifdef HAVE_EXPAT
    XML_ParserFree(p->parser);
#else
    xmlFreeParserCtxt(p->parser);
#endif

    free(p);
}

Here is the call graph for this function:

const char* hip_xml_get_error ( hip_xml_parser *  p)

Definition at line 803 of file hip_xml.c.

{
    return p->error;
}
void hip_xml_parse ( hip_xml_parser *  p,
const char *  block,
size_t  len 
)

Definition at line 724 of file hip_xml.c.

{
    int ret, flag;
    /* duck out if it's broken */
    if (!p->valid) {
       DEBUG(DEBUG_XML, "Not parsing %d bytes.\n", len);
       return;
    }
    if (len == 0) {
       flag = -1;
       block = "";
       DEBUG(DEBUG_XML, "Got 0-length buffer, end of document.\n");
    } else {  
       DEBUG(DEBUG_XML, "Parsing %d length buffer.\n", len);
       flag = 0;
    }
    /* Note, don't write a parser error if !p->valid, since an error
     * will already have been written in that case. */
#ifdef HAVE_EXPAT
    ret = XML_Parse(p->parser, block, len, flag);
    DEBUG(DEBUG_XMLPARSE, "XML_Parse returned %d\n", ret);
    if (ret == 0 && p->valid) {
       snprintf(p->error, HIP_ERR_SIZE,
                "XML parse error at line %d: %s", 
                XML_GetCurrentLineNumber(p->parser),
                XML_ErrorString(XML_GetErrorCode(p->parser)));
       p->valid = 0;
    }
#else
    ret = xmlParseChunk(p->parser, block, len, flag);
    DEBUG(DEBUG_XMLPARSE, "xmlParseChunk returned %d\n", ret);
    if (p->parser->errNo && p->valid) {
       /* FIXME: error handling */
       snprintf(p->error, HIP_ERR_SIZE, "XML parse error at line %d.", 
                hip_xml_currentline(p));
       p->valid = 0;
    }
#endif
}
void hip_xml_parse_v ( void *  userdata,
const char *  block,
size_t  len 
)

Definition at line 714 of file hip_xml.c.

{
    hip_xml_parser *p = userdata;
    /* FIXME: The two XML parsers break all our nice abstraction by
     * choosing different char *'s. The swine. This cast will come
     * back and bite us someday, no doubt. */
    hip_xml_parse(p, block, len);
}
void hip_xml_push_handler ( hip_xml_parser *  p,
const struct hip_xml_elm elements,
hip_xml_validate_cb  validate_cb,
hip_xml_startelm_cb  startelm_cb,
hip_xml_endelm_cb  endelm_cb,
void *  userdata 
)

Definition at line 676 of file hip_xml.c.

{
    struct hip_xml_handler *hand = ne_calloc(sizeof(struct hip_xml_handler));

    hand->elements = elements;
    hand->validate_cb = validate_cb;
    hand->startelm_cb = startelm_cb;
    hand->endelm_cb = endelm_cb;
    hand->userdata = userdata;

    push_handler(p, hand);
}

Here is the call graph for this function:

void hip_xml_push_mixed_handler ( hip_xml_parser *  p,
const struct hip_xml_elm elements,
hip_xml_validate_cb  validate_cb,
hip_xml_startelm_cb  startelm_cb,
hip_xml_cdata_cb  cdata_cb,
hip_xml_endelm_cb  endelm_cb,
void *  userdata 
)

Definition at line 694 of file hip_xml.c.

{
    struct hip_xml_handler *hand = ne_calloc(sizeof *hand);
    
    hand->elements = elements;
    hand->validate_cb = validate_cb;
    hand->startelm_cb = startelm_cb;
    hand->cdata_cb = cdata_cb;
    hand->endelm_cb = endelm_cb;
    hand->userdata = userdata;
    
    push_handler(p, hand);
}

Here is the call graph for this function:

void hip_xml_set_error ( hip_xml_parser *  p,
const char *  msg 
)

Definition at line 798 of file hip_xml.c.

{
    snprintf(p->error, HIP_ERR_SIZE, msg);
}
int hip_xml_valid ( hip_xml_parser *  p)

Definition at line 764 of file hip_xml.c.

{
    return p->valid;
}