Mercurial > pidgin
comparison libpurple/protocols/bonjour/jabber.c @ 21820:509871e4f61c
Cleanup to prevent unnecessary alloc/free. Also a small fix to remove the possiblity that a message will be sent before the stream is started.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 11 Dec 2007 20:28:09 +0000 |
parents | 41959f031322 |
children | cc0809ec0c85 |
comparison
equal
deleted
inserted
replaced
21819:1162bf342def | 21820:509871e4f61c |
---|---|
75 }; | 75 }; |
76 | 76 |
77 static void | 77 static void |
78 xep_iq_parse(xmlnode *packet, PurpleConnection *connection, PurpleBuddy *pb); | 78 xep_iq_parse(xmlnode *packet, PurpleConnection *connection, PurpleBuddy *pb); |
79 | 79 |
80 #if 0 /* this isn't used anywhere... */ | |
81 static const char * | |
82 _font_size_purple_to_ichat(int size) | |
83 { | |
84 switch (size) { | |
85 case 1: | |
86 return "8"; | |
87 case 2: | |
88 return "10"; | |
89 case 3: | |
90 return "12"; | |
91 case 4: | |
92 return "14"; | |
93 case 5: | |
94 return "17"; | |
95 case 6: | |
96 return "21"; | |
97 case 7: | |
98 return "24"; | |
99 } | |
100 | |
101 return "12"; | |
102 } | |
103 #endif | |
104 | |
105 static BonjourJabberConversation * | 80 static BonjourJabberConversation * |
106 bonjour_jabber_conv_new(PurpleBuddy *pb) { | 81 bonjour_jabber_conv_new(PurpleBuddy *pb) { |
107 | 82 |
108 BonjourJabberConversation *bconv = g_new0(BonjourJabberConversation, 1); | 83 BonjourJabberConversation *bconv = g_new0(BonjourJabberConversation, 1); |
109 bconv->socket = -1; | 84 bconv->socket = -1; |
141 static void | 116 static void |
142 _jabber_parse_and_write_message_to_ui(xmlnode *message_node, PurpleBuddy *pb) | 117 _jabber_parse_and_write_message_to_ui(xmlnode *message_node, PurpleBuddy *pb) |
143 { | 118 { |
144 xmlnode *body_node, *html_node, *events_node; | 119 xmlnode *body_node, *html_node, *events_node; |
145 PurpleConnection *gc = pb->account->gc; | 120 PurpleConnection *gc = pb->account->gc; |
146 char *body, *html_body = NULL; | 121 gchar *body = NULL; |
147 const char *ichat_balloon_color = NULL; | |
148 const char *ichat_text_color = NULL; | |
149 const char *font_face = NULL; | |
150 const char *font_size = NULL; | |
151 const char *font_color = NULL; | |
152 gboolean composing_event = FALSE; | 122 gboolean composing_event = FALSE; |
153 | 123 |
154 body_node = xmlnode_get_child(message_node, "body"); | 124 body_node = xmlnode_get_child(message_node, "body"); |
155 if (body_node == NULL) | |
156 return; | |
157 body = xmlnode_get_data(body_node); | |
158 | |
159 html_node = xmlnode_get_child(message_node, "html"); | 125 html_node = xmlnode_get_child(message_node, "html"); |
160 if (html_node != NULL) | 126 |
161 { | 127 if (body_node == NULL && html_node == NULL) { |
128 purple_debug_error("bonjour", "No body or html node found, discarding message.\n"); | |
129 return; | |
130 } | |
131 | |
132 events_node = xmlnode_get_child_with_namespace(message_node, "x", "jabber:x:event"); | |
133 if (events_node != NULL) { | |
134 if (xmlnode_get_child(events_node, "composing") != NULL) | |
135 composing_event = TRUE; | |
136 if (xmlnode_get_child(events_node, "id") != NULL) { | |
137 /* The user is just typing */ | |
138 /* TODO: Deal with typing notification */ | |
139 return; | |
140 } | |
141 } | |
142 | |
143 if (html_node != NULL) { | |
162 xmlnode *html_body_node; | 144 xmlnode *html_body_node; |
163 | 145 |
164 html_body_node = xmlnode_get_child(html_node, "body"); | 146 html_body_node = xmlnode_get_child(html_node, "body"); |
165 if (html_body_node != NULL) | 147 if (html_body_node != NULL) { |
166 { | |
167 xmlnode *html_body_font_node; | 148 xmlnode *html_body_font_node; |
149 const char *ichat_balloon_color = NULL; | |
150 const char *ichat_text_color = NULL; | |
151 const char *font_face = NULL; | |
152 const char *font_size = NULL; | |
153 const char *font_color = NULL; | |
168 | 154 |
169 ichat_balloon_color = xmlnode_get_attrib(html_body_node, "ichatballooncolor"); | 155 ichat_balloon_color = xmlnode_get_attrib(html_body_node, "ichatballooncolor"); |
170 ichat_text_color = xmlnode_get_attrib(html_body_node, "ichattextcolor"); | 156 ichat_text_color = xmlnode_get_attrib(html_body_node, "ichattextcolor"); |
171 html_body_font_node = xmlnode_get_child(html_body_node, "font"); | 157 html_body_font_node = xmlnode_get_child(html_body_node, "font"); |
172 if (html_body_font_node != NULL) | 158 |
173 { /* Types of messages sent by iChat */ | 159 /* Types of messages sent by iChat */ |
160 if (html_body_font_node != NULL) { | |
161 gchar *html_body; | |
162 | |
174 font_face = xmlnode_get_attrib(html_body_font_node, "face"); | 163 font_face = xmlnode_get_attrib(html_body_font_node, "face"); |
175 /* The absolute iChat font sizes should be converted to 1..7 range */ | 164 /* The absolute iChat font sizes should be converted to 1..7 range */ |
176 font_size = xmlnode_get_attrib(html_body_font_node, "ABSZ"); | 165 font_size = xmlnode_get_attrib(html_body_font_node, "ABSZ"); |
177 if (font_size != NULL) | 166 if (font_size != NULL) |
178 font_size = _font_size_ichat_to_purple(atoi(font_size)); | 167 font_size = _font_size_ichat_to_purple(atoi(font_size)); |
179 font_color = xmlnode_get_attrib(html_body_font_node, "color"); | 168 font_color = xmlnode_get_attrib(html_body_font_node, "color"); |
180 html_body = xmlnode_get_data(html_body_font_node); | 169 html_body = xmlnode_get_data(html_body_font_node); |
170 | |
181 if (html_body == NULL) | 171 if (html_body == NULL) |
182 /* This is the kind of formated messages that Purple creates */ | 172 /* This is the kind of formated messages that Purple creates */ |
183 html_body = xmlnode_to_str(html_body_font_node, NULL); | 173 html_body = xmlnode_to_str(html_body_font_node, NULL); |
174 | |
175 if (html_body != NULL) { | |
176 /* Use some sane defaults */ | |
177 if (font_face == NULL) font_face = "Helvetica"; | |
178 if (font_size == NULL) font_size = "3"; | |
179 if (ichat_text_color == NULL) ichat_text_color = "#000000"; | |
180 if (ichat_balloon_color == NULL) ichat_balloon_color = "#FFFFFF"; | |
181 | |
182 body = g_strdup_printf("<font face='%s' size='%s' color='%s' back='%s'>%s</font>", | |
183 font_face, font_size, ichat_text_color, ichat_balloon_color, | |
184 html_body); | |
185 | |
186 g_free(html_body); | |
187 } | |
184 } | 188 } |
185 } | 189 } |
186 } | 190 } |
187 | 191 |
188 events_node = xmlnode_get_child_with_namespace(message_node, "x", "jabber:x:event"); | |
189 if (events_node != NULL) | |
190 { | |
191 if (xmlnode_get_child(events_node, "composing") != NULL) | |
192 composing_event = TRUE; | |
193 if (xmlnode_get_child(events_node, "id") != NULL) | |
194 { | |
195 /* The user is just typing */ | |
196 /* TODO: Deal with typing notification */ | |
197 g_free(body); | |
198 g_free(html_body); | |
199 return; | |
200 } | |
201 } | |
202 | |
203 /* Compose the message */ | 192 /* Compose the message */ |
204 if (html_body != NULL) | 193 if (body == NULL && body_node != NULL) |
205 { | 194 body = xmlnode_get_data(body_node); |
206 g_free(body); | 195 |
207 | 196 if (body == NULL) { |
208 if (font_face == NULL) font_face = "Helvetica"; | 197 purple_debug_error("bonjour", "No html body or regular body found.\n"); |
209 if (font_size == NULL) font_size = "3"; | 198 return; |
210 if (ichat_text_color == NULL) ichat_text_color = "#000000"; | 199 } |
211 if (ichat_balloon_color == NULL) ichat_balloon_color = "#FFFFFF"; | |
212 body = g_strdup_printf("<font face='%s' size='%s' color='%s' back='%s'>%s</font>", | |
213 font_face, font_size, ichat_text_color, ichat_balloon_color, | |
214 html_body); | |
215 } | |
216 | |
217 /* TODO: Should we do something with "composing_event" here? */ | |
218 | 200 |
219 /* Send the message to the UI */ | 201 /* Send the message to the UI */ |
220 serv_got_im(gc, pb->name, body, 0, time(NULL)); | 202 serv_got_im(gc, pb->name, body, 0, time(NULL)); |
221 | 203 |
222 g_free(body); | 204 g_free(body); |
223 g_free(html_body); | |
224 } | 205 } |
225 | 206 |
226 struct _check_buddy_by_address_t { | 207 struct _check_buddy_by_address_t { |
227 const char *address; | 208 const char *address; |
228 PurpleBuddy **pb; | 209 PurpleBuddy **pb; |
343 return -1; | 324 return -1; |
344 } | 325 } |
345 | 326 |
346 if (ret < len) { | 327 if (ret < len) { |
347 /* Don't interfere with the stream starting */ | 328 /* Don't interfere with the stream starting */ |
348 if (bconv->tx_handler == 0) | 329 if (bconv->sent_stream_start == FULLY_SENT && bconv->recv_stream_start && bconv->tx_handler == 0) |
349 bconv->tx_handler = purple_input_add(bconv->socket, PURPLE_INPUT_WRITE, | 330 bconv->tx_handler = purple_input_add(bconv->socket, PURPLE_INPUT_WRITE, |
350 _send_data_write_cb, pb); | 331 _send_data_write_cb, pb); |
351 purple_circ_buffer_append(bconv->tx_buf, message + ret, len - ret); | 332 purple_circ_buffer_append(bconv->tx_buf, message + ret, len - ret); |
352 } | 333 } |
353 | 334 |