xml-utils.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #ifndef XML_UTILS_H
  9. #define XML_UTILS_H
  10. struct xml_node_ctx;
  11. typedef struct xml_node xml_node_t;
  12. typedef struct xml_namespace_foo xml_namespace_t;
  13. /* XML library wrappers */
  14. int xml_validate(struct xml_node_ctx *ctx, xml_node_t *node,
  15. const char *xml_schema_fname, char **ret_err);
  16. int xml_validate_dtd(struct xml_node_ctx *ctx, xml_node_t *node,
  17. const char *dtd_fname, char **ret_err);
  18. void xml_node_free(struct xml_node_ctx *ctx, xml_node_t *node);
  19. xml_node_t * xml_node_get_parent(struct xml_node_ctx *ctx, xml_node_t *node);
  20. xml_node_t * xml_node_from_buf(struct xml_node_ctx *ctx, const char *buf);
  21. const char * xml_node_get_localname(struct xml_node_ctx *ctx,
  22. xml_node_t *node);
  23. char * xml_node_to_str(struct xml_node_ctx *ctx, xml_node_t *node);
  24. void xml_node_detach(struct xml_node_ctx *ctx, xml_node_t *node);
  25. void xml_node_add_child(struct xml_node_ctx *ctx, xml_node_t *parent,
  26. xml_node_t *child);
  27. xml_node_t * xml_node_create_root(struct xml_node_ctx *ctx, const char *ns_uri,
  28. const char *ns_prefix,
  29. xml_namespace_t **ret_ns, const char *name);
  30. xml_node_t * xml_node_create(struct xml_node_ctx *ctx, xml_node_t *parent,
  31. xml_namespace_t *ns, const char *name);
  32. xml_node_t * xml_node_create_text(struct xml_node_ctx *ctx,
  33. xml_node_t *parent, xml_namespace_t *ns,
  34. const char *name, const char *value);
  35. xml_node_t * xml_node_create_text_ns(struct xml_node_ctx *ctx,
  36. xml_node_t *parent, const char *ns_uri,
  37. const char *name, const char *value);
  38. void xml_node_set_text(struct xml_node_ctx *ctx, xml_node_t *node,
  39. const char *value);
  40. int xml_node_add_attr(struct xml_node_ctx *ctx, xml_node_t *node,
  41. xml_namespace_t *ns, const char *name, const char *value);
  42. char * xml_node_get_attr_value(struct xml_node_ctx *ctx, xml_node_t *node,
  43. char *name);
  44. char * xml_node_get_attr_value_ns(struct xml_node_ctx *ctx, xml_node_t *node,
  45. const char *ns_uri, char *name);
  46. void xml_node_get_attr_value_free(struct xml_node_ctx *ctx, char *val);
  47. xml_node_t * xml_node_first_child(struct xml_node_ctx *ctx,
  48. xml_node_t *parent);
  49. xml_node_t * xml_node_next_sibling(struct xml_node_ctx *ctx,
  50. xml_node_t *node);
  51. int xml_node_is_element(struct xml_node_ctx *ctx, xml_node_t *node);
  52. char * xml_node_get_text(struct xml_node_ctx *ctx, xml_node_t *node);
  53. void xml_node_get_text_free(struct xml_node_ctx *ctx, char *val);
  54. char * xml_node_get_base64_text(struct xml_node_ctx *ctx, xml_node_t *node,
  55. int *ret_len);
  56. xml_node_t * xml_node_copy(struct xml_node_ctx *ctx, xml_node_t *node);
  57. #define xml_node_for_each_child(ctx, child, parent) \
  58. for (child = xml_node_first_child(ctx, parent); \
  59. child; \
  60. child = xml_node_next_sibling(ctx, child))
  61. #define xml_node_for_each_sibling(ctx, node) \
  62. for (; \
  63. node; \
  64. node = xml_node_next_sibling(ctx, node))
  65. #define xml_node_for_each_check(ctx, child) \
  66. if (!xml_node_is_element(ctx, child)) \
  67. continue
  68. struct xml_node_ctx * xml_node_init_ctx(void *upper_ctx,
  69. const void *env);
  70. void xml_node_deinit_ctx(struct xml_node_ctx *ctx);
  71. xml_node_t * get_node_uri(struct xml_node_ctx *ctx, xml_node_t *root,
  72. const char *uri);
  73. xml_node_t * get_node(struct xml_node_ctx *ctx, xml_node_t *root,
  74. const char *path);
  75. xml_node_t * get_child_node(struct xml_node_ctx *ctx, xml_node_t *root,
  76. const char *path);
  77. xml_node_t * node_from_file(struct xml_node_ctx *ctx, const char *name);
  78. int node_to_file(struct xml_node_ctx *ctx, const char *fname, xml_node_t *node);
  79. xml_node_t * mo_to_tnds(struct xml_node_ctx *ctx, xml_node_t *mo,
  80. int use_path, const char *urn, const char *ns_uri);
  81. xml_node_t * tnds_to_mo(struct xml_node_ctx *ctx, xml_node_t *tnds);
  82. xml_node_t * soap_build_envelope(struct xml_node_ctx *ctx, xml_node_t *node);
  83. xml_node_t * soap_get_body(struct xml_node_ctx *ctx, xml_node_t *soap);
  84. #endif /* XML_UTILS_H */