summaryrefslogtreecommitdiff
path: root/src/rexmpp_xml.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rexmpp_xml.c')
-rw-r--r--src/rexmpp_xml.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/rexmpp_xml.c b/src/rexmpp_xml.c
index 7e428e2..e77bf78 100644
--- a/src/rexmpp_xml.c
+++ b/src/rexmpp_xml.c
@@ -256,6 +256,14 @@ rexmpp_xml_t *rexmpp_xml_new_text (const char *str) {
return node;
}
+rexmpp_xml_t *rexmpp_xml_new_text_len (const char *str, size_t len) {
+ rexmpp_xml_t *node = malloc(sizeof(rexmpp_xml_t));
+ node->type = REXMPP_XML_TEXT;
+ node->alt.text = strndup(str, len);
+ node->next = NULL;
+ return node;
+}
+
void rexmpp_xml_add_child (rexmpp_xml_t *node,
rexmpp_xml_t *child)
{
@@ -277,6 +285,18 @@ int rexmpp_xml_add_text (rexmpp_xml_t *node,
return -1;
}
+int rexmpp_xml_add_text_len (rexmpp_xml_t *node,
+ const char *str,
+ size_t len)
+{
+ rexmpp_xml_t *text_node = rexmpp_xml_new_text_len(str, len);
+ if (text_node != NULL) {
+ rexmpp_xml_add_child(node, text_node);
+ return 0;
+ }
+ return -1;
+}
+
rexmpp_xml_t *rexmpp_xml_new_elem (const char *name,
const char *namespace)
{
@@ -787,4 +807,27 @@ char *rexmpp_xml_text (rexmpp_xml_t *node) {
char *rexmpp_xml_text_child (rexmpp_xml_t *node) {
return rexmpp_xml_text(rexmpp_xml_children(node));
}
+
+rexmpp_xml_t *rexmpp_xml_reverse (rexmpp_xml_t *node) {
+ rexmpp_xml_t *next, *prev = NULL;
+ while (node != NULL) {
+ next = node->next;
+ node->next = prev;
+ prev = node;
+ node = next;
+ }
+ return prev;
+}
+
+rexmpp_xml_t *rexmpp_xml_reverse_all (rexmpp_xml_t *node) {
+ node = rexmpp_xml_reverse(node);
+ rexmpp_xml_t *cur;
+ for (cur = node; cur != NULL; cur = cur->next) {
+ if (cur->type == REXMPP_XML_ELEMENT) {
+ cur->alt.elem.children = rexmpp_xml_reverse_all(cur->alt.elem.children);
+ }
+ }
+ return node;
+}
+
#endif