comparison src/protocols/jabber/auth.c @ 7514:43a214a385d1

[gaim-migrate @ 8127] this is what I accomplished on the ride to atlanta. pathetic, eh? committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 15 Nov 2003 07:09:20 +0000
parents 85cd2e71bff7
children 6cd392e0d6ea
comparison
equal deleted inserted replaced
7513:e804d727867f 7514:43a214a385d1
125 static void auth_old_cb(JabberStream *js, xmlnode *packet, gpointer data) 125 static void auth_old_cb(JabberStream *js, xmlnode *packet, gpointer data)
126 { 126 {
127 JabberIq *iq; 127 JabberIq *iq;
128 xmlnode *query, *x; 128 xmlnode *query, *x;
129 gboolean digest = FALSE; 129 gboolean digest = FALSE;
130 const char *type = xmlnode_get_attrib(packet, "type");
130 const char *pw = gaim_account_get_password(js->gc->account); 131 const char *pw = gaim_account_get_password(js->gc->account);
131 132
132 /* XXX: check for an <iq type='error' /> */ 133 if(!type) {
133
134 query = xmlnode_get_child(packet, "query");
135 if(js->stream_id && xmlnode_get_child(query, "digest")) {
136 digest = TRUE;
137 } else if(!xmlnode_get_child(query, "password")) {
138 gaim_connection_error(js->gc,
139 _("Server does not use any supported authentication method"));
140 return; 134 return;
141 } 135 } else if(strcmp(type, "error")) {
142 136 /* XXX: handle error */
143 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:auth"); 137 } else if(strcmp(type, "result")) {
144 query = xmlnode_get_child(iq->node, "query"); 138 query = xmlnode_get_child(packet, "query");
145 x = xmlnode_new_child(query, "username"); 139 if(js->stream_id && xmlnode_get_child(query, "digest")) {
146 xmlnode_insert_data(x, js->user->node, -1); 140 digest = TRUE;
147 x = xmlnode_new_child(query, "resource"); 141 } else if(!xmlnode_get_child(query, "password")) {
148 xmlnode_insert_data(x, js->user->resource, -1); 142 gaim_connection_error(js->gc,
149 143 _("Server does not use any supported authentication method"));
150 if(digest) { 144 return;
151 unsigned char hashval[20]; 145 }
152 char *s, h[41], *p; 146
153 int i; 147 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:auth");
154 148 query = xmlnode_get_child(iq->node, "query");
155 x = xmlnode_new_child(query, "digest"); 149 x = xmlnode_new_child(query, "username");
156 s = g_strdup_printf("%s%s", js->stream_id, pw); 150 xmlnode_insert_data(x, js->user->node, -1);
157 shaBlock((unsigned char *)s, strlen(s), hashval); 151 x = xmlnode_new_child(query, "resource");
158 p = h; 152 xmlnode_insert_data(x, js->user->resource, -1);
159 for(i=0; i<20; i++, p+=2) 153
160 snprintf(p, 3, "%02x", hashval[i]); 154 if(digest) {
161 xmlnode_insert_data(x, h, -1); 155 unsigned char hashval[20];
162 g_free(s); 156 char *s, h[41], *p;
163 } else { 157 int i;
164 x = xmlnode_new_child(query, "password"); 158
165 xmlnode_insert_data(x, pw, -1); 159 x = xmlnode_new_child(query, "digest");
166 } 160 s = g_strdup_printf("%s%s", js->stream_id, pw);
167 161 shaBlock((unsigned char *)s, strlen(s), hashval);
168 jabber_iq_set_callback(iq, auth_old_result_cb, NULL); 162 p = h;
169 163 for(i=0; i<20; i++, p+=2)
170 jabber_iq_send(iq); 164 snprintf(p, 3, "%02x", hashval[i]);
165 xmlnode_insert_data(x, h, -1);
166 g_free(s);
167 } else {
168 x = xmlnode_new_child(query, "password");
169 xmlnode_insert_data(x, pw, -1);
170 }
171
172 jabber_iq_set_callback(iq, auth_old_result_cb, NULL);
173
174 jabber_iq_send(iq);
175 }
171 } 176 }
172 177
173 void jabber_auth_start_old(JabberStream *js) 178 void jabber_auth_start_old(JabberStream *js)
174 { 179 {
175 JabberIq *iq; 180 JabberIq *iq;