comparison src/protocols/jabber/jabber.c @ 12508:5cfc53ead482

[gaim-migrate @ 14820] patch from Simon Wilkinson to add Cyrus SASL support for jabber Give him credit if it works flawlessly. Blame me if it doesn't, as the patch was against 1.3.1 (yeah, I've been sitting on it for that long), and I had to merge it to HEAD, and clean up a bunch of warnings committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 17 Dec 2005 02:24:05 +0000
parents 51898e3031e6
children 9d9030dfd689
comparison
equal deleted inserted replaced
12507:5bf6c0c908b2 12508:5cfc53ead482
201 /* because printing a tab to debug every minute gets old */ 201 /* because printing a tab to debug every minute gets old */
202 if(strcmp(data, "\t")) 202 if(strcmp(data, "\t"))
203 gaim_debug(GAIM_DEBUG_MISC, "jabber", "Sending%s: %s\n", 203 gaim_debug(GAIM_DEBUG_MISC, "jabber", "Sending%s: %s\n",
204 js->gsc ? " (ssl)" : "", data); 204 js->gsc ? " (ssl)" : "", data);
205 205
206 /* If we've got a security layer, we need to encode the data,
207 * splitting it on the maximum buffer length negotiated */
208
209 #ifdef HAVE_CYRUS_SASL
210 if (js->sasl_maxbuf>0) {
211 int pos;
212
213 if (!js->gsc && js->fd<0)
214 return;
215 pos = 0;
216 if (len == -1)
217 len = strlen(data);
218 while (pos < len) {
219 int towrite;
220 const char *out;
221 unsigned olen;
222
223 if ((len - pos) < js->sasl_maxbuf)
224 towrite = len - pos;
225 else
226 towrite = js->sasl_maxbuf;
227
228 sasl_encode(js->sasl, &data[pos], towrite, &out, &olen);
229 pos += towrite;
230
231 if (js->gsc)
232 ret = gaim_ssl_write(js->gsc, out, olen);
233 else
234 ret = write(js->fd, out, olen);
235 if (ret < 0)
236 gaim_connection_error(js->gc, _("Write error"));
237 }
238 return;
239 }
240 #endif
241
206 if(js->gsc) { 242 if(js->gsc) {
207 ret = gaim_ssl_write(js->gsc, data, len == -1 ? strlen(data) : len); 243 ret = gaim_ssl_write(js->gsc, data, len == -1 ? strlen(data) : len);
208 } else { 244 } else {
209 if(js->fd < 0) 245 if(js->fd < 0)
210 return; 246 return;
264 300
265 if(!g_list_find(gaim_connections_get_all(), gc)) 301 if(!g_list_find(gaim_connections_get_all(), gc))
266 return; 302 return;
267 303
268 if((len = read(js->fd, buf, sizeof(buf) - 1)) > 0) { 304 if((len = read(js->fd, buf, sizeof(buf) - 1)) > 0) {
305 #ifdef HAVE_CYRUS_SASL
306 if (js->sasl_maxbuf>0) {
307 const char *out;
308 int olen;
309 sasl_decode(js->sasl, buf, len, &out, &olen);
310 if (olen>0) {
311 gaim_debug(GAIM_DEBUG_INFO, "jabber", "RecvSASL (%d): %s\n", olen, out);
312 jabber_parser_process(js,out,olen);
313 }
314 return;
315 }
316 #endif
269 buf[len] = '\0'; 317 buf[len] = '\0';
270 gaim_debug(GAIM_DEBUG_INFO, "jabber", "Recv (%d): %s\n", len, buf); 318 gaim_debug(GAIM_DEBUG_INFO, "jabber", "Recv (%d): %s\n", len, buf);
271 jabber_parser_process(js, buf, len); 319 jabber_parser_process(js, buf, len);
272 } else { 320 } else {
273 gaim_connection_error(gc, _("Read Error")); 321 gaim_connection_error(gc, _("Read Error"));
817 g_free(js->stream_id); 865 g_free(js->stream_id);
818 if(js->user) 866 if(js->user)
819 jabber_id_free(js->user); 867 jabber_id_free(js->user);
820 if(js->avatar_hash) 868 if(js->avatar_hash)
821 g_free(js->avatar_hash); 869 g_free(js->avatar_hash);
870 #ifdef HAVE_CYRUS_SASL
871 if(js->sasl)
872 sasl_dispose(&js->sasl);
873 if(js->sasl_mechs)
874 g_string_free(js->sasl_mechs, TRUE);
875 if(js->sasl_cb)
876 g_free(js->sasl_cb);
877 #endif
822 g_free(js); 878 g_free(js);
823 879
824 gc->proto_data = NULL; 880 gc->proto_data = NULL;
825 } 881 }
826 882
1606 NULL); 1662 NULL);
1607 } 1663 }
1608 1664
1609 static GaimPluginProtocolInfo prpl_info = 1665 static GaimPluginProtocolInfo prpl_info =
1610 { 1666 {
1611 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME, 1667 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME |
1668 OPT_PROTO_PASSWORD_OPTIONAL,
1612 NULL, /* user_splits */ 1669 NULL, /* user_splits */
1613 NULL, /* protocol_options */ 1670 NULL, /* protocol_options */
1614 {"jpeg,gif,png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */ 1671 {"jpeg,gif,png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */
1615 jabber_list_icon, /* list_icon */ 1672 jabber_list_icon, /* list_icon */
1616 jabber_list_emblems, /* list_emblems */ 1673 jabber_list_emblems, /* list_emblems */
1741 1798
1742 my_protocol = plugin; 1799 my_protocol = plugin;
1743 1800
1744 gaim_prefs_remove("/plugins/prpl/jabber"); 1801 gaim_prefs_remove("/plugins/prpl/jabber");
1745 1802
1803 /* XXX - If any other plugin wants SASL this won't be good ... */
1804 #ifdef HAVE_CYRUS_SASL
1805 sasl_client_init(NULL);
1806 #endif
1746 jabber_register_commands(); 1807 jabber_register_commands();
1747 } 1808 }
1748 1809
1749 GAIM_INIT_PLUGIN(jabber, init_plugin, info); 1810 GAIM_INIT_PLUGIN(jabber, init_plugin, info);