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