comparison libpurple/xmlnode.c @ 18684:5c1ed6296b56

propagate from branch 'im.pidgin.pidgin' (head b195e262642015df66e36d33e9dd16ecae5df9d5) to branch 'im.pidgin.soc.2007.xmpp' (head 06f9dbd73b69e26dc9f56873a9ce106146bb1b18)
author Andreas Monitzer <pidgin@monitzer.com>
date Wed, 11 Jul 2007 22:27:44 +0000
parents 9d02fefaa589 6050348614ab
children 472bcd9d502e
comparison
equal deleted inserted replaced
17907:8d2ea5072f6f 18684:5c1ed6296b56
266 { 266 {
267 xmlnode *x, *y; 267 xmlnode *x, *y;
268 268
269 g_return_if_fail(node != NULL); 269 g_return_if_fail(node != NULL);
270 270
271 /* if we're part of a tree, remove ourselves from the tree first */
272 if(NULL != node->parent) {
273 if(node->parent->child == node) {
274 node->parent->child = node->next;
275 } else {
276 xmlnode *prev = node->parent->child;
277 while(prev && prev->next != node) {
278 prev = prev->next;
279 }
280 if(prev) {
281 prev->next = node->next;
282 }
283 }
284 }
285
286 /* now free our children */
271 x = node->child; 287 x = node->child;
272 while(x) { 288 while(x) {
273 y = x->next; 289 y = x->next;
274 xmlnode_free(x); 290 xmlnode_free(x);
275 x = y; 291 x = y;
276 } 292 }
277 293
294 /* now dispose of ourselves */
278 g_free(node->name); 295 g_free(node->name);
279 g_free(node->data); 296 g_free(node->data);
280 g_free(node->xmlns); 297 g_free(node->xmlns);
281 298
282 PURPLE_DBUS_UNREGISTER_POINTER(node); 299 PURPLE_DBUS_UNREGISTER_POINTER(node);
331 g_return_val_if_fail(node != NULL, NULL); 348 g_return_val_if_fail(node != NULL, NULL);
332 349
333 for(c = node->child; c; c = c->next) { 350 for(c = node->child; c; c = c->next) {
334 if(c->type == XMLNODE_TYPE_DATA) { 351 if(c->type == XMLNODE_TYPE_DATA) {
335 if(!str) 352 if(!str)
336 str = g_string_new(""); 353 str = g_string_new_len(c->data, c->data_sz);
337 str = g_string_append_len(str, c->data, c->data_sz); 354 else
355 str = g_string_append_len(str, c->data, c->data_sz);
338 } 356 }
339 } 357 }
340 358
341 if (str == NULL) 359 if (str == NULL)
342 return NULL; 360 return NULL;
343 361
344 return g_string_free(str, FALSE); 362 return g_string_free(str, FALSE);
363 }
364
365 char *
366 xmlnode_get_data_unescaped(xmlnode *node)
367 {
368 char *escaped = xmlnode_get_data(node);
369
370 char *unescaped = escaped ? purple_unescape_html(escaped) : NULL;
371
372 g_free(escaped);
373
374 return unescaped;
345 } 375 }
346 376
347 static char * 377 static char *
348 xmlnode_to_str_helper(xmlnode *node, int *len, gboolean formatting, int depth) 378 xmlnode_to_str_helper(xmlnode *node, int *len, gboolean formatting, int depth)
349 { 379 {
517 struct _xmlnode_parser_data *xpd = user_data; 547 struct _xmlnode_parser_data *xpd = user_data;
518 xpd->error = TRUE; 548 xpd->error = TRUE;
519 } 549 }
520 550
521 static xmlSAXHandler xmlnode_parser_libxml = { 551 static xmlSAXHandler xmlnode_parser_libxml = {
522 .internalSubset = NULL, 552 NULL, /* internalSubset */
523 .isStandalone = NULL, 553 NULL, /* isStandalone */
524 .hasInternalSubset = NULL, 554 NULL, /* hasInternalSubset */
525 .hasExternalSubset = NULL, 555 NULL, /* hasExternalSubset */
526 .resolveEntity = NULL, 556 NULL, /* resolveEntity */
527 .getEntity = NULL, 557 NULL, /* getEntity */
528 .entityDecl = NULL, 558 NULL, /* entityDecl */
529 .notationDecl = NULL, 559 NULL, /* notationDecl */
530 .attributeDecl = NULL, 560 NULL, /* attributeDecl */
531 .elementDecl = NULL, 561 NULL, /* elementDecl */
532 .unparsedEntityDecl = NULL, 562 NULL, /* unparsedEntityDecl */
533 .setDocumentLocator = NULL, 563 NULL, /* setDocumentLocator */
534 .startDocument = NULL, 564 NULL, /* startDocument */
535 .endDocument = NULL, 565 NULL, /* endDocument */
536 .startElement = NULL, 566 NULL, /* startElement */
537 .endElement = NULL, 567 NULL, /* endElement */
538 .reference = NULL, 568 NULL, /* reference */
539 .characters = xmlnode_parser_element_text_libxml, 569 xmlnode_parser_element_text_libxml, /* characters */
540 .ignorableWhitespace = NULL, 570 NULL, /* ignorableWhitespace */
541 .processingInstruction = NULL, 571 NULL, /* processingInstruction */
542 .comment = NULL, 572 NULL, /* comment */
543 .warning = NULL, 573 NULL, /* warning */
544 .error = xmlnode_parser_error_libxml, 574 xmlnode_parser_error_libxml, /* error */
545 .fatalError = NULL, 575 NULL, /* fatalError */
546 .getParameterEntity = NULL, 576 NULL, /* getParameterEntity */
547 .cdataBlock = NULL, 577 NULL, /* cdataBlock */
548 .externalSubset = NULL, 578 NULL, /* externalSubset */
549 .initialized = XML_SAX2_MAGIC, 579 XML_SAX2_MAGIC, /* initialized */
550 ._private = NULL, 580 NULL, /* _private */
551 .startElementNs = xmlnode_parser_element_start_libxml, 581 xmlnode_parser_element_start_libxml, /* startElementNs */
552 .endElementNs = xmlnode_parser_element_end_libxml, 582 xmlnode_parser_element_end_libxml, /* endElementNs */
553 .serror = NULL 583 NULL, /* serror */
554 }; 584 };
555 585
556 xmlnode * 586 xmlnode *
557 xmlnode_from_str(const char *str, gssize size) 587 xmlnode_from_str(const char *str, gssize size)
558 { 588 {