1*5b9c547cSRui Paulo /* 2*5b9c547cSRui Paulo * Generic XML helper functions 3*5b9c547cSRui Paulo * Copyright (c) 2012-2013, Qualcomm Atheros, Inc. 4*5b9c547cSRui Paulo * 5*5b9c547cSRui Paulo * This software may be distributed under the terms of the BSD license. 6*5b9c547cSRui Paulo * See README for more details. 7*5b9c547cSRui Paulo */ 8*5b9c547cSRui Paulo 9*5b9c547cSRui Paulo #ifndef XML_UTILS_H 10*5b9c547cSRui Paulo #define XML_UTILS_H 11*5b9c547cSRui Paulo 12*5b9c547cSRui Paulo struct xml_node_ctx; 13*5b9c547cSRui Paulo typedef struct xml_node xml_node_t; 14*5b9c547cSRui Paulo typedef struct xml_namespace_foo xml_namespace_t; 15*5b9c547cSRui Paulo 16*5b9c547cSRui Paulo /* XML library wrappers */ 17*5b9c547cSRui Paulo 18*5b9c547cSRui Paulo int xml_validate(struct xml_node_ctx *ctx, xml_node_t *node, 19*5b9c547cSRui Paulo const char *xml_schema_fname, char **ret_err); 20*5b9c547cSRui Paulo int xml_validate_dtd(struct xml_node_ctx *ctx, xml_node_t *node, 21*5b9c547cSRui Paulo const char *dtd_fname, char **ret_err); 22*5b9c547cSRui Paulo void xml_node_free(struct xml_node_ctx *ctx, xml_node_t *node); 23*5b9c547cSRui Paulo xml_node_t * xml_node_get_parent(struct xml_node_ctx *ctx, xml_node_t *node); 24*5b9c547cSRui Paulo xml_node_t * xml_node_from_buf(struct xml_node_ctx *ctx, const char *buf); 25*5b9c547cSRui Paulo const char * xml_node_get_localname(struct xml_node_ctx *ctx, 26*5b9c547cSRui Paulo xml_node_t *node); 27*5b9c547cSRui Paulo char * xml_node_to_str(struct xml_node_ctx *ctx, xml_node_t *node); 28*5b9c547cSRui Paulo void xml_node_detach(struct xml_node_ctx *ctx, xml_node_t *node); 29*5b9c547cSRui Paulo void xml_node_add_child(struct xml_node_ctx *ctx, xml_node_t *parent, 30*5b9c547cSRui Paulo xml_node_t *child); 31*5b9c547cSRui Paulo xml_node_t * xml_node_create_root(struct xml_node_ctx *ctx, const char *ns_uri, 32*5b9c547cSRui Paulo const char *ns_prefix, 33*5b9c547cSRui Paulo xml_namespace_t **ret_ns, const char *name); 34*5b9c547cSRui Paulo xml_node_t * xml_node_create(struct xml_node_ctx *ctx, xml_node_t *parent, 35*5b9c547cSRui Paulo xml_namespace_t *ns, const char *name); 36*5b9c547cSRui Paulo xml_node_t * xml_node_create_text(struct xml_node_ctx *ctx, 37*5b9c547cSRui Paulo xml_node_t *parent, xml_namespace_t *ns, 38*5b9c547cSRui Paulo const char *name, const char *value); 39*5b9c547cSRui Paulo xml_node_t * xml_node_create_text_ns(struct xml_node_ctx *ctx, 40*5b9c547cSRui Paulo xml_node_t *parent, const char *ns_uri, 41*5b9c547cSRui Paulo const char *name, const char *value); 42*5b9c547cSRui Paulo void xml_node_set_text(struct xml_node_ctx *ctx, xml_node_t *node, 43*5b9c547cSRui Paulo const char *value); 44*5b9c547cSRui Paulo int xml_node_add_attr(struct xml_node_ctx *ctx, xml_node_t *node, 45*5b9c547cSRui Paulo xml_namespace_t *ns, const char *name, const char *value); 46*5b9c547cSRui Paulo char * xml_node_get_attr_value(struct xml_node_ctx *ctx, xml_node_t *node, 47*5b9c547cSRui Paulo char *name); 48*5b9c547cSRui Paulo char * xml_node_get_attr_value_ns(struct xml_node_ctx *ctx, xml_node_t *node, 49*5b9c547cSRui Paulo const char *ns_uri, char *name); 50*5b9c547cSRui Paulo void xml_node_get_attr_value_free(struct xml_node_ctx *ctx, char *val); 51*5b9c547cSRui Paulo xml_node_t * xml_node_first_child(struct xml_node_ctx *ctx, 52*5b9c547cSRui Paulo xml_node_t *parent); 53*5b9c547cSRui Paulo xml_node_t * xml_node_next_sibling(struct xml_node_ctx *ctx, 54*5b9c547cSRui Paulo xml_node_t *node); 55*5b9c547cSRui Paulo int xml_node_is_element(struct xml_node_ctx *ctx, xml_node_t *node); 56*5b9c547cSRui Paulo char * xml_node_get_text(struct xml_node_ctx *ctx, xml_node_t *node); 57*5b9c547cSRui Paulo void xml_node_get_text_free(struct xml_node_ctx *ctx, char *val); 58*5b9c547cSRui Paulo char * xml_node_get_base64_text(struct xml_node_ctx *ctx, xml_node_t *node, 59*5b9c547cSRui Paulo int *ret_len); 60*5b9c547cSRui Paulo xml_node_t * xml_node_copy(struct xml_node_ctx *ctx, xml_node_t *node); 61*5b9c547cSRui Paulo 62*5b9c547cSRui Paulo #define xml_node_for_each_child(ctx, child, parent) \ 63*5b9c547cSRui Paulo for (child = xml_node_first_child(ctx, parent); \ 64*5b9c547cSRui Paulo child; \ 65*5b9c547cSRui Paulo child = xml_node_next_sibling(ctx, child)) 66*5b9c547cSRui Paulo 67*5b9c547cSRui Paulo #define xml_node_for_each_sibling(ctx, node) \ 68*5b9c547cSRui Paulo for (; \ 69*5b9c547cSRui Paulo node; \ 70*5b9c547cSRui Paulo node = xml_node_next_sibling(ctx, node)) 71*5b9c547cSRui Paulo 72*5b9c547cSRui Paulo #define xml_node_for_each_check(ctx, child) \ 73*5b9c547cSRui Paulo if (!xml_node_is_element(ctx, child)) \ 74*5b9c547cSRui Paulo continue 75*5b9c547cSRui Paulo 76*5b9c547cSRui Paulo 77*5b9c547cSRui Paulo struct xml_node_ctx * xml_node_init_ctx(void *upper_ctx, 78*5b9c547cSRui Paulo const void *env); 79*5b9c547cSRui Paulo void xml_node_deinit_ctx(struct xml_node_ctx *ctx); 80*5b9c547cSRui Paulo 81*5b9c547cSRui Paulo 82*5b9c547cSRui Paulo xml_node_t * get_node_uri(struct xml_node_ctx *ctx, xml_node_t *root, 83*5b9c547cSRui Paulo const char *uri); 84*5b9c547cSRui Paulo xml_node_t * get_node(struct xml_node_ctx *ctx, xml_node_t *root, 85*5b9c547cSRui Paulo const char *path); 86*5b9c547cSRui Paulo xml_node_t * get_child_node(struct xml_node_ctx *ctx, xml_node_t *root, 87*5b9c547cSRui Paulo const char *path); 88*5b9c547cSRui Paulo xml_node_t * node_from_file(struct xml_node_ctx *ctx, const char *name); 89*5b9c547cSRui Paulo int node_to_file(struct xml_node_ctx *ctx, const char *fname, xml_node_t *node); 90*5b9c547cSRui Paulo xml_node_t * mo_to_tnds(struct xml_node_ctx *ctx, xml_node_t *mo, 91*5b9c547cSRui Paulo int use_path, const char *urn, const char *ns_uri); 92*5b9c547cSRui Paulo xml_node_t * tnds_to_mo(struct xml_node_ctx *ctx, xml_node_t *tnds); 93*5b9c547cSRui Paulo 94*5b9c547cSRui Paulo xml_node_t * soap_build_envelope(struct xml_node_ctx *ctx, xml_node_t *node); 95*5b9c547cSRui Paulo xml_node_t * soap_get_body(struct xml_node_ctx *ctx, xml_node_t *soap); 96*5b9c547cSRui Paulo 97*5b9c547cSRui Paulo #endif /* XML_UTILS_H */ 98