Mercurial > pidgin.yaz
comparison libpurple/protocols/myspace/message.c @ 17334:af7083a8ada7
Add MSIM_TYPE_STRING to msim_msg_get_binary() (but with reservations).
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Fri, 01 Jun 2007 05:44:50 +0000 |
parents | b9c0a8bb94b9 |
children | d8afaaf24f34 |
comparison
equal
deleted
inserted
replaced
17333:b9c0a8bb94b9 | 17334:af7083a8ada7 |
---|---|
639 } | 639 } |
640 } | 640 } |
641 | 641 |
642 /** Return the data of an element of a given name, as a binary GString. | 642 /** Return the data of an element of a given name, as a binary GString. |
643 * | 643 * |
644 * @return GString * of binary data, or NULL. | 644 * @param binary_data A pointer to a new pointer, which will be filled in with the binary data. CALLER MUST g_free(). |
645 */ | 645 * |
646 GString *msim_msg_get_binary(MsimMessage *msg, gchar *name) | 646 * @param binary_length A pointer to an integer, which will be set to the binary data length. |
647 * | |
648 * @return TRUE if successful, FALSE if not. | |
649 */ | |
650 gboolean msim_msg_get_binary(MsimMessage *msg, gchar *name, gchar **binary_data, guint *binary_length) | |
647 { | 651 { |
648 switch (elem->type) | 652 switch (elem->type) |
649 { | 653 { |
654 case MSIM_TYPE_STRING: | |
655 /* Currently, incoming messages get stored as MSIM_TYPE_STRING. | |
656 * This is fine for integers and strings, since they can easily be | |
657 * converted in msim_get_*, as desirable. However, it may not work | |
658 * well for binary strings. Consider: | |
659 * | |
660 * Incoming base64'd elements get tagged as MSIM_TYPE_STRING. | |
661 * msim_msg_get_binary() sees MSIM_TYPE_STRING, base64 decodes, returns. | |
662 * everything is fine. | |
663 * But then, msim_send() is called on the incoming message, which has | |
664 * a base64'd MSIM_TYPE_STRING that really is encoded binary. The values | |
665 * will be escaped since strings are escaped, and / becomes /2; no good. | |
666 * | |
667 * TODO: Make incoming messages be tagged with MSIM_TYPE_UNKNOWN, and | |
668 * converted appropriately. They can still be "strings", just they won't | |
669 * be tagged as MSIM_TYPE_STRING (as MSIM_TYPE_STRING is intended to be used | |
670 * by msimprpl code for things like instant messages - stuff that should be | |
671 * escaped if needed). DWIM. | |
672 */ | |
673 *binary_data = (guchar *)purple_base64_decode((gchar *)elem->data, binary_length); | |
674 return TRUE; | |
675 | |
650 case MSIM_TYPE_BINARY: | 676 case MSIM_TYPE_BINARY: |
651 return (GString *)elem->data; | 677 { |
678 GString *gs; | |
679 | |
680 gs = (GString *)elem->data; | |
681 | |
682 /* Duplicate data, so caller can g_free() it. */ | |
683 *binary_data = g_new0(char, gs->len); | |
684 memcpy(*binary_data, gs->data, gs->len); | |
685 | |
686 *binary_length = gs->len; | |
687 | |
688 return TRUE; | |
689 } | |
690 | |
691 | |
692 /* Rejected because if it isn't already a GString, have to g_new0 it and | |
693 * then caller has to ALSO free the GString! | |
694 * | |
695 * return (GString *)elem->data; */ | |
652 | 696 |
653 default: | 697 default: |
654 return NULL; | 698 return FALSE; |
655 } | 699 } |
656 } | 700 } |