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