Mercurial > pidgin
annotate src/protocols/msn/nexus.c @ 19813:6bc69cd68d3c
[gaim-migrate @ 16955]
fix the authentication string fs 's bug
comitted by Ma Yuan<mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
author | Ma Yuan <mayuan2006@gmail.com> |
---|---|
date | Mon, 21 Aug 2006 17:40:07 +0000 |
parents | d928bccffe4c |
children | bffd1b96207c |
rev | line source |
---|---|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
1 /** |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
2 * @file nexus.c MSN Nexus functions |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
3 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
4 * gaim |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
5 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
9 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
10 * This program is free software; you can redistribute it and/or modify |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
13 * (at your option) any later version. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
14 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
15 * This program is distributed in the hope that it will be useful, |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
18 * GNU General Public License for more details. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
19 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
20 * You should have received a copy of the GNU General Public License |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
21 * along with this program; if not, write to the Free Software |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
23 */ |
8171 | 24 #include "msn.h" |
19784 | 25 #include "soap.h" |
8171 | 26 #include "nexus.h" |
27 #include "notification.h" | |
28 | |
19789 | 29 /*Local Function Prototype*/ |
30 static void nexus_login_connect_cb(gpointer data, GaimSslConnection *gsc,GaimInputCondition cond); | |
31 | |
8171 | 32 /************************************************************************** |
10481 | 33 * Main |
34 **************************************************************************/ | |
35 | |
36 MsnNexus * | |
37 msn_nexus_new(MsnSession *session) | |
38 { | |
39 MsnNexus *nexus; | |
40 | |
41 nexus = g_new0(MsnNexus, 1); | |
42 nexus->session = session; | |
19784 | 43 /*we must use SSL connection to do Windows Live ID authentication*/ |
19785 | 44 nexus->soapconn = msn_soap_new(session,nexus,1); |
45 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
46 nexus->challenge_data = g_hash_table_new_full(g_str_hash, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
47 g_str_equal, g_free, g_free); |
10481 | 48 |
49 return nexus; | |
50 } | |
51 | |
52 void | |
53 msn_nexus_destroy(MsnNexus *nexus) | |
54 { | |
55 if (nexus->challenge_data != NULL) | |
56 g_hash_table_destroy(nexus->challenge_data); | |
57 | |
19784 | 58 msn_soap_destroy(nexus->soapconn); |
10481 | 59 g_free(nexus); |
60 } | |
61 | |
62 /************************************************************************** | |
8171 | 63 * Login |
64 **************************************************************************/ | |
65 static void | |
19789 | 66 nexus_login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data) |
8171 | 67 { |
19784 | 68 MsnSoapConn * soapconn = data; |
8171 | 69 MsnSession *session; |
70 | |
19784 | 71 session = soapconn->session; |
8171 | 72 g_return_if_fail(session != NULL); |
73 | |
19784 | 74 msn_session_set_error(session, MSN_ERROR_AUTH, _("Windows Live ID authentication:Unable to connect")); |
10568 | 75 /* the above line will result in nexus being destroyed, so we don't want |
76 * to destroy it here, or we'd crash */ | |
8171 | 77 } |
78 | |
19789 | 79 /*process the SOAP reply, get the Authentication Info*/ |
8171 | 80 static void |
19784 | 81 nexus_login_read_cb(gpointer data, gint source, GaimInputCondition cond) |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
82 { |
19784 | 83 MsnSoapConn * soapconn = data; |
84 MsnNexus *nexus; | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
85 MsnSession *session; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
86 |
19789 | 87 char *base, *c; |
88 char *msn_twn_t,*msn_twn_p; | |
89 char *login_params; | |
90 char **elems, **cur, **tokens; | |
91 char * cert_str; | |
92 | |
19784 | 93 nexus = soapconn->parent; |
94 g_return_if_fail(nexus != NULL); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
95 session = nexus->session; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
96 g_return_if_fail(session != NULL); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
97 |
19786 | 98 // gaim_debug_misc("msn", "TWN Server Reply: {%s}\n", soapconn->read_buf); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
99 |
19789 | 100 /*reply OK, we should process the SOAP body*/ |
101 gaim_debug_info("MaYuan","Windows Live ID Reply OK!\n"); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
102 |
19789 | 103 //TODO: we should parse it using XML |
104 base = g_strstr_len(soapconn->read_buf, soapconn->read_len, TWN_START_TOKEN); | |
105 base += strlen(TWN_START_TOKEN); | |
106 c = g_strstr_len(soapconn->read_buf, soapconn->read_len, TWN_END_TOKEN); | |
107 login_params = g_strndup(base, c - base); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
108 |
19789 | 109 // gaim_debug_info("msn", "TWN Cert: {%s}\n", login_params); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
110 |
19789 | 111 /* Parse the challenge data. */ |
112 elems = g_strsplit(login_params, "&", 0); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
113 |
19789 | 114 for (cur = elems; *cur != NULL; cur++){ |
115 tokens = g_strsplit(*cur, "=", 2); | |
116 g_hash_table_insert(nexus->challenge_data, tokens[0], tokens[1]); | |
117 /* Don't free each of the tokens, only the array. */ | |
118 g_free(tokens); | |
119 } | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
120 |
19789 | 121 g_strfreev(elems); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
122 |
19789 | 123 msn_twn_t = (char *)g_hash_table_lookup(nexus->challenge_data, "t"); |
124 msn_twn_p = (char *)g_hash_table_lookup(nexus->challenge_data, "p"); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
125 |
19789 | 126 /*setup the t and p parameter for session*/ |
127 if (session->passport_info.t != NULL){ | |
128 g_free(session->passport_info.t); | |
129 } | |
130 session->passport_info.t = g_strdup(msn_twn_t); | |
19783 | 131 |
19789 | 132 if (session->passport_info.p != NULL) |
133 g_free(session->passport_info.p); | |
134 session->passport_info.p = g_strdup(msn_twn_p); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
135 |
19789 | 136 cert_str = g_strdup_printf("t=%s&p=%s",msn_twn_t,msn_twn_p); |
137 msn_got_login_params(session, cert_str); | |
19784 | 138 |
19789 | 139 gaim_debug_info("MaYuan","close nexus connection! \n"); |
140 g_free(cert_str); | |
141 g_free(login_params); | |
142 msn_nexus_destroy(nexus); | |
143 session->nexus = NULL; | |
19784 | 144 |
19789 | 145 return; |
19784 | 146 } |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
147 |
19784 | 148 static void |
149 nexus_login_written_cb(gpointer data, gint source, GaimInputCondition cond) | |
150 { | |
151 MsnSoapConn * soapconn = data; | |
152 | |
153 soapconn->read_cb = nexus_login_read_cb; | |
19810 | 154 // msn_soap_read_cb(data,source,cond); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
155 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
156 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
157 |
19789 | 158 /*when connect, do the SOAP Style windows Live ID authentication */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
159 void |
19789 | 160 nexus_login_connect_cb(gpointer data, GaimSslConnection *gsc, |
8171 | 161 GaimInputCondition cond) |
162 { | |
19784 | 163 MsnSoapConn *soapconn; |
164 MsnNexus * nexus; | |
8171 | 165 MsnSession *session; |
19812 | 166 char *ru,*lc,*id,*tw,*ct,*kpp,*kv,*ver,*rn,*tpf,*fs; |
8171 | 167 char *username, *password; |
19783 | 168 char *request_str, *head, *tail,*challenge_str; |
8171 | 169 |
19783 | 170 gaim_debug_info("MaYuan","starting Windows Live ID authentication\n"); |
19784 | 171 |
172 soapconn = data; | |
173 g_return_if_fail(soapconn != NULL); | |
174 | |
175 nexus = soapconn->parent; | |
8171 | 176 g_return_if_fail(nexus != NULL); |
177 | |
19784 | 178 session = soapconn->session; |
8171 | 179 g_return_if_fail(session != NULL); |
180 | |
10519 | 181 msn_session_set_login_step(session, MSN_LOGIN_STEP_GET_COOKIE); |
10481 | 182 |
19784 | 183 /*prepare the Windows Live ID authentication token*/ |
19783 | 184 username = g_strdup(gaim_account_get_username(session->account)); |
185 password = g_strdup(gaim_connection_get_password(session->account->gc)); | |
12457 | 186 |
19808 | 187 lc = (char *)g_hash_table_lookup(nexus->challenge_data, "lc"); |
188 id = (char *)g_hash_table_lookup(nexus->challenge_data, "id"); | |
189 tw = (char *)g_hash_table_lookup(nexus->challenge_data, "tw"); | |
19812 | 190 fs = (char *)g_hash_table_lookup(nexus->challenge_data, "fs"); |
19808 | 191 ru = (char *)g_hash_table_lookup(nexus->challenge_data, "ru"); |
192 ct = (char *)g_hash_table_lookup(nexus->challenge_data, "ct"); | |
193 kpp= (char *)g_hash_table_lookup(nexus->challenge_data, "kpp"); | |
194 kv = (char *)g_hash_table_lookup(nexus->challenge_data, "kv"); | |
195 ver= (char *)g_hash_table_lookup(nexus->challenge_data, "ver"); | |
196 rn = (char *)g_hash_table_lookup(nexus->challenge_data, "rn"); | |
197 tpf= (char *)g_hash_table_lookup(nexus->challenge_data, "tpf"); | |
198 | |
199 if(!(lc && id && tw && ru && ct && kpp && kv && ver && tpf)){ | |
200 gaim_debug_error("MaYuan","WLM Authenticate Key Error!\n"); | |
201 msn_session_set_error(session, MSN_ERROR_AUTH, _("Windows Live ID authentication Failed")); | |
202 g_free(username); | |
203 g_free(password); | |
204 gaim_ssl_close(gsc); | |
205 msn_nexus_destroy(nexus); | |
206 session->nexus = NULL; | |
207 return; | |
208 } | |
209 | |
19812 | 210 if(!fs){ |
19813 | 211 fs =g_strdup("1"); |
19812 | 212 } |
19783 | 213 challenge_str = g_strdup_printf( |
19812 | 214 "lc=%s&id=%s&tw=%s&fs=%s&ru=%s&ct=%s&kpp=%s&kv=%s&ver=%s&rn=%s&tpf=%s\r\n", |
215 lc,id,tw,fs,ru,ct,kpp,kv,ver,rn,tpf | |
19783 | 216 ); |
19813 | 217 if(!fs){ |
218 g_free(fs); | |
219 } | |
19783 | 220 |
221 /*build the SOAP windows Live ID XML body */ | |
222 tail = g_strdup_printf(TWN_ENVELOP_TEMPLATE,username,password,challenge_str ); | |
8171 | 223 |
19784 | 224 soapconn->login_path = g_strdup(TWN_POST_URL); |
19783 | 225 head = g_strdup_printf( |
226 "POST %s HTTP/1.1\r\n" | |
227 "Accept: text/*\r\n" | |
228 "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n" | |
229 "Host: %s\r\n" | |
230 "Content-Length: %d\r\n" | |
231 "Connection: Keep-Alive\r\n" | |
232 "Cache-Control: no-cache\r\n\r\n", | |
19784 | 233 soapconn->login_path,soapconn->login_host,strlen(tail)); |
8171 | 234 |
19783 | 235 request_str = g_strdup_printf("%s%s", head,tail); |
19786 | 236 // gaim_debug_misc("msn", "TWN Sending: {%s}\n", request_str); |
12457 | 237 |
238 g_free(head); | |
239 g_free(tail); | |
8171 | 240 g_free(username); |
241 g_free(password); | |
242 | |
19784 | 243 /*prepare to send the SOAP request*/ |
244 msn_soap_write(soapconn,request_str,nexus_login_written_cb); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
245 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
246 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
247 } |
8171 | 248 |
19783 | 249 /************************************************************************** |
250 * Connect | |
251 **************************************************************************/ | |
252 void | |
253 msn_nexus_connect(MsnNexus *nexus) | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
254 { |
19783 | 255 /* Authenticate via Windows Live ID. */ |
256 gaim_debug_info("MaYuan","msn_nexus_connect...\n"); | |
19789 | 257 msn_soap_init(nexus->soapconn,MSN_TWN_SERVER,1,nexus_login_connect_cb,nexus_login_error_cb); |
19806 | 258 msn_soap_connect(nexus->soapconn); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
259 } |
19784 | 260 |