Mercurial > pidgin.yaz
comparison libpurple/protocols/msn/slpmsg_part.c @ 31285:74c4aa38adfc
Add support to ref/unref SlpMessageParts.
author | masca@cpw.pidgin.im |
---|---|
date | Tue, 06 Jul 2010 19:00:21 +0000 |
parents | 98cd0ea847ec |
children | e358e16e527f |
comparison
equal
deleted
inserted
replaced
31284:e0c374ad8fd3 | 31285:74c4aa38adfc |
---|---|
15 part->footer = g_memdup(footer, P2P_PACKET_FOOTER_SIZE); | 15 part->footer = g_memdup(footer, P2P_PACKET_FOOTER_SIZE); |
16 | 16 |
17 part->ack_cb = msn_slpmsgpart_ack; | 17 part->ack_cb = msn_slpmsgpart_ack; |
18 part->nak_cb = msn_slpmsgpart_nak; | 18 part->nak_cb = msn_slpmsgpart_nak; |
19 | 19 |
20 return part; | 20 return msn_slpmsgpart_ref(part); |
21 } | 21 } |
22 | 22 |
23 MsnSlpMessagePart *msn_slpmsgpart_new_from_data(const char *data, size_t data_len) | 23 MsnSlpMessagePart *msn_slpmsgpart_new_from_data(const char *data, size_t data_len) |
24 { | 24 { |
25 MsnSlpMessagePart *part; | 25 MsnSlpMessagePart *part; |
59 void msn_slpmsgpart_destroy(MsnSlpMessagePart *part) | 59 void msn_slpmsgpart_destroy(MsnSlpMessagePart *part) |
60 { | 60 { |
61 if (!part) | 61 if (!part) |
62 return; | 62 return; |
63 | 63 |
64 if (part->ref_count > 0) { | |
65 msn_slpmsgpart_unref(part); | |
66 | |
67 return; | |
68 } | |
69 | |
64 g_free(part->header); | 70 g_free(part->header); |
65 g_free(part->footer); | 71 g_free(part->footer); |
66 | 72 |
67 g_free(part); | 73 g_free(part); |
68 | 74 |
75 } | |
76 | |
77 MsnSlpMessagePart *msn_slpmsgpart_ref(MsnSlpMessagePart *part) | |
78 { | |
79 g_return_val_if_fail(part != NULL, NULL); | |
80 part->ref_count ++; | |
81 | |
82 return part; | |
83 } | |
84 | |
85 MsnSlpMessagePart *msn_slpmsgpart_unref(MsnSlpMessagePart *part) | |
86 { | |
87 g_return_val_if_fail(part != NULL, NULL); | |
88 g_return_val_if_fail(part->ref_count > 0, NULL); | |
89 | |
90 part->ref_count--; | |
91 | |
92 if (part->ref_count == 0) { | |
93 msn_slpmsgpart_destroy(part); | |
94 | |
95 return NULL; | |
96 } | |
97 | |
98 return part; | |
69 } | 99 } |
70 | 100 |
71 void msn_slpmsgpart_set_bin_data(MsnSlpMessagePart *part, const void *data, size_t len) | 101 void msn_slpmsgpart_set_bin_data(MsnSlpMessagePart *part, const void *data, size_t len) |
72 { | 102 { |
73 g_return_if_fail(part != NULL); | 103 g_return_if_fail(part != NULL); |