Mercurial > pidgin
comparison libpurple/protocols/jabber/auth.c @ 28697:de8565bc63fe
jabber: Use accessors instead of directly accessing gc->account (and similar)
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sat, 07 Nov 2009 06:41:33 +0000 |
parents | 8ada06fb65ed |
children | f27ed49948b7 |
comparison
equal
deleted
inserted
replaced
28696:8ada06fb65ed | 28697:de8565bc63fe |
---|---|
46 xmlnode *packet, gpointer data); | 46 xmlnode *packet, gpointer data); |
47 | 47 |
48 gboolean | 48 gboolean |
49 jabber_process_starttls(JabberStream *js, xmlnode *packet) | 49 jabber_process_starttls(JabberStream *js, xmlnode *packet) |
50 { | 50 { |
51 PurpleAccount *account; | |
51 xmlnode *starttls; | 52 xmlnode *starttls; |
53 | |
54 account = purple_connection_get_account(js->gc); | |
52 | 55 |
53 if((starttls = xmlnode_get_child(packet, "starttls"))) { | 56 if((starttls = xmlnode_get_child(packet, "starttls"))) { |
54 if(purple_ssl_is_supported()) { | 57 if(purple_ssl_is_supported()) { |
55 jabber_send_raw(js, | 58 jabber_send_raw(js, |
56 "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>", -1); | 59 "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>", -1); |
58 } else if(xmlnode_get_child(starttls, "required")) { | 61 } else if(xmlnode_get_child(starttls, "required")) { |
59 purple_connection_error_reason(js->gc, | 62 purple_connection_error_reason(js->gc, |
60 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, | 63 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, |
61 _("Server requires TLS/SSL, but no TLS/SSL support was found.")); | 64 _("Server requires TLS/SSL, but no TLS/SSL support was found.")); |
62 return TRUE; | 65 return TRUE; |
63 } else if(purple_account_get_bool(js->gc->account, "require_tls", JABBER_DEFAULT_REQUIRE_TLS)) { | 66 } else if(purple_account_get_bool(account, "require_tls", JABBER_DEFAULT_REQUIRE_TLS)) { |
64 purple_connection_error_reason(js->gc, | 67 purple_connection_error_reason(js->gc, |
65 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, | 68 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, |
66 _("You require encryption, but no TLS/SSL support was found.")); | 69 _("You require encryption, but no TLS/SSL support was found.")); |
67 return TRUE; | 70 return TRUE; |
68 } | 71 } |
88 jabber_iq_send(iq); | 91 jabber_iq_send(iq); |
89 } | 92 } |
90 | 93 |
91 static void allow_plaintext_auth(PurpleAccount *account) | 94 static void allow_plaintext_auth(PurpleAccount *account) |
92 { | 95 { |
96 PurpleConnection *gc; | |
97 JabberStream *js; | |
98 | |
93 purple_account_set_bool(account, "auth_plain_in_clear", TRUE); | 99 purple_account_set_bool(account, "auth_plain_in_clear", TRUE); |
94 | 100 |
95 finish_plaintext_authentication(account->gc->proto_data); | 101 gc = purple_account_get_connection(account); |
102 js = purple_connection_get_protocol_data(gc); | |
103 | |
104 finish_plaintext_authentication(js); | |
96 } | 105 } |
97 | 106 |
98 static void disallow_plaintext_auth(PurpleAccount *account) | 107 static void disallow_plaintext_auth(PurpleAccount *account) |
99 { | 108 { |
100 purple_connection_error_reason(account->gc, | 109 purple_connection_error_reason(purple_account_get_connection(account), |
101 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, | 110 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, |
102 _("Server requires plaintext authentication over an unencrypted stream")); | 111 _("Server requires plaintext authentication over an unencrypted stream")); |
103 } | 112 } |
104 | 113 |
105 static void | 114 static void |
134 /* Restart our connection */ | 143 /* Restart our connection */ |
135 jabber_auth_start_old(js); | 144 jabber_auth_start_old(js); |
136 } | 145 } |
137 | 146 |
138 static void | 147 static void |
139 auth_no_pass_cb(PurpleConnection *conn, PurpleRequestFields *fields) | 148 auth_no_pass_cb(PurpleConnection *gc, PurpleRequestFields *fields) |
140 { | 149 { |
141 JabberStream *js; | |
142 | |
143 /* The password prompt dialog doesn't get disposed if the account disconnects */ | 150 /* The password prompt dialog doesn't get disposed if the account disconnects */ |
144 if (!PURPLE_CONNECTION_IS_VALID(conn)) | 151 if (!PURPLE_CONNECTION_IS_VALID(gc)) |
145 return; | 152 return; |
146 | |
147 js = conn->proto_data; | |
148 | 153 |
149 /* Disable the account as the user has canceled connecting */ | 154 /* Disable the account as the user has canceled connecting */ |
150 purple_account_set_enabled(conn->account, purple_core_get_ui(), FALSE); | 155 purple_account_set_enabled(purple_connection_get_account(gc), purple_core_get_ui(), FALSE); |
151 } | 156 } |
152 | 157 |
153 void | 158 void |
154 jabber_auth_start(JabberStream *js, xmlnode *packet) | 159 jabber_auth_start(JabberStream *js, xmlnode *packet) |
155 { | 160 { |
220 { | 225 { |
221 if (type == JABBER_IQ_RESULT) { | 226 if (type == JABBER_IQ_RESULT) { |
222 jabber_stream_set_state(js, JABBER_STREAM_POST_AUTH); | 227 jabber_stream_set_state(js, JABBER_STREAM_POST_AUTH); |
223 jabber_disco_items_server(js); | 228 jabber_disco_items_server(js); |
224 } else { | 229 } else { |
230 PurpleAccount *account; | |
225 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; | 231 PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; |
226 char *msg = jabber_parse_error(js, packet, &reason); | 232 char *msg = jabber_parse_error(js, packet, &reason); |
227 xmlnode *error; | 233 xmlnode *error; |
228 const char *err_code; | 234 const char *err_code; |
235 | |
236 account = purple_connectoion_get_account(js->gc); | |
229 | 237 |
230 /* FIXME: Why is this not in jabber_parse_error? */ | 238 /* FIXME: Why is this not in jabber_parse_error? */ |
231 if((error = xmlnode_get_child(packet, "error")) && | 239 if((error = xmlnode_get_child(packet, "error")) && |
232 (err_code = xmlnode_get_attrib(error, "code")) && | 240 (err_code = xmlnode_get_attrib(error, "code")) && |
233 g_str_equal(err_code, "401")) { | 241 g_str_equal(err_code, "401")) { |
234 reason = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED; | 242 reason = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED; |
235 /* Clear the pasword if it isn't being saved */ | 243 /* Clear the pasword if it isn't being saved */ |
236 if (!purple_account_get_remember_password(js->gc->account)) | 244 if (!purple_account_get_remember_password(account)) |
237 purple_account_set_password(js->gc->account, NULL); | 245 purple_account_set_password(account, NULL); |
238 } | 246 } |
239 | 247 |
240 purple_connection_error_reason(js->gc, reason, msg); | 248 purple_connection_error_reason(js->gc, reason, msg); |
241 g_free(msg); | 249 g_free(msg); |
242 } | 250 } |
305 | 313 |
306 jabber_iq_set_callback(iq, auth_old_result_cb, NULL); | 314 jabber_iq_set_callback(iq, auth_old_result_cb, NULL); |
307 jabber_iq_send(iq); | 315 jabber_iq_send(iq); |
308 | 316 |
309 } else if(xmlnode_get_child(query, "password")) { | 317 } else if(xmlnode_get_child(query, "password")) { |
310 if(!jabber_stream_is_ssl(js) && !purple_account_get_bool(js->gc->account, | 318 PurpleAccount *account = purple_connection_get_account(js->gc); |
319 if(!jabber_stream_is_ssl(js) && !purple_account_get_bool(account, | |
311 "auth_plain_in_clear", FALSE)) { | 320 "auth_plain_in_clear", FALSE)) { |
312 char *msg = g_strdup_printf(_("%s requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"), | 321 char *msg = g_strdup_printf(_("%s requires plaintext authentication over an unencrypted connection. Allow this and continue authentication?"), |
313 js->gc->account->username); | 322 purple_account_get_username(account)); |
314 purple_request_yes_no(js->gc, _("Plaintext Authentication"), | 323 purple_request_yes_no(js->gc, _("Plaintext Authentication"), |
315 _("Plaintext Authentication"), | 324 _("Plaintext Authentication"), |
316 msg, | 325 msg, |
317 1, | 326 1, |
318 purple_connection_get_account(js->gc), NULL, NULL, | 327 account, NULL, NULL, |
319 purple_connection_get_account(js->gc), allow_plaintext_auth, | 328 account, allow_plaintext_auth, |
320 disallow_plaintext_auth); | 329 disallow_plaintext_auth); |
321 g_free(msg); | 330 g_free(msg); |
322 return; | 331 return; |
323 } | 332 } |
324 finish_plaintext_authentication(js); | 333 finish_plaintext_authentication(js); |
331 } | 340 } |
332 } | 341 } |
333 | 342 |
334 void jabber_auth_start_old(JabberStream *js) | 343 void jabber_auth_start_old(JabberStream *js) |
335 { | 344 { |
345 PurpleAccount *account; | |
336 JabberIq *iq; | 346 JabberIq *iq; |
337 xmlnode *query, *username; | 347 xmlnode *query, *username; |
348 | |
349 account = purple_connection_get_account(js->gc); | |
338 | 350 |
339 /* | 351 /* |
340 * We can end up here without encryption if the server doesn't support | 352 * We can end up here without encryption if the server doesn't support |
341 * <stream:features/> and we're not using old-style SSL. If the user | 353 * <stream:features/> and we're not using old-style SSL. If the user |
342 * is requiring SSL/TLS, we need to enforce it. | 354 * is requiring SSL/TLS, we need to enforce it. |
343 */ | 355 */ |
344 if (!jabber_stream_is_ssl(js) && | 356 if (!jabber_stream_is_ssl(js) && |
345 purple_account_get_bool(purple_connection_get_account(js->gc), "require_tls", JABBER_DEFAULT_REQUIRE_TLS)) { | 357 purple_account_get_bool(account, "require_tls", JABBER_DEFAULT_REQUIRE_TLS)) { |
346 purple_connection_error_reason(js->gc, | 358 purple_connection_error_reason(js->gc, |
347 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, | 359 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, |
348 _("You require encryption, but it is not available on this server.")); | 360 _("You require encryption, but it is not available on this server.")); |
349 return; | 361 return; |
350 } | 362 } |
368 /* If we have Cyrus SASL, then passwords will have been set | 380 /* If we have Cyrus SASL, then passwords will have been set |
369 * to OPTIONAL for this protocol. So, we need to do our own | 381 * to OPTIONAL for this protocol. So, we need to do our own |
370 * password prompting here | 382 * password prompting here |
371 */ | 383 */ |
372 | 384 |
373 if (!purple_account_get_password(js->gc->account)) { | 385 if (!purple_account_get_password(account)) { |
374 purple_account_request_password(js->gc->account, G_CALLBACK(auth_old_pass_cb), G_CALLBACK(auth_no_pass_cb), js->gc); | 386 purple_account_request_password(account, G_CALLBACK(auth_old_pass_cb), G_CALLBACK(auth_no_pass_cb), js->gc); |
375 return; | 387 return; |
376 } | 388 } |
377 #endif | 389 #endif |
378 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:auth"); | 390 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:auth"); |
379 | 391 |