Mercurial > pidgin.yaz
annotate src/protocols/msn/nexus.c @ 13573:0b2e4a5a8e79
[gaim-migrate @ 15952]
Bj??rn pointed out on gaim-i18n that the instructions are not translated.
For users who might not speak English (or whatever language the server
configuration file is in), it seems worthwhile to flag that text as coming
from the server.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 26 Mar 2006 17:45:53 +0000 |
parents | 33bef17125c2 |
children | cf48a70da762 995aea35b05c |
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" |
25 #include "nexus.h" | |
26 #include "notification.h" | |
27 | |
28 /************************************************************************** | |
10481 | 29 * Main |
30 **************************************************************************/ | |
31 | |
32 MsnNexus * | |
33 msn_nexus_new(MsnSession *session) | |
34 { | |
35 MsnNexus *nexus; | |
36 | |
37 nexus = g_new0(MsnNexus, 1); | |
38 nexus->session = session; | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
39 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
|
40 g_str_equal, g_free, g_free); |
10481 | 41 |
42 return nexus; | |
43 } | |
44 | |
45 void | |
46 msn_nexus_destroy(MsnNexus *nexus) | |
47 { | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
48 g_free(nexus->login_host); |
10481 | 49 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
50 g_free(nexus->login_path); |
10481 | 51 |
52 if (nexus->challenge_data != NULL) | |
53 g_hash_table_destroy(nexus->challenge_data); | |
54 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
55 if (nexus->input_handler > 0) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
56 gaim_input_remove(nexus->input_handler); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
57 g_free(nexus->write_buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
58 g_free(nexus->read_buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
59 |
10481 | 60 g_free(nexus); |
61 } | |
62 | |
63 /************************************************************************** | |
8171 | 64 * Util |
65 **************************************************************************/ | |
66 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
67 static gssize |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
68 msn_ssl_read(MsnNexus *nexus) |
8171 | 69 { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
70 gssize len; |
8171 | 71 char temp_buf[4096]; |
72 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
73 if ((len = gaim_ssl_read(nexus->gsc, temp_buf, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
74 sizeof(temp_buf))) > 0) |
8171 | 75 { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
76 nexus->read_buf = g_realloc(nexus->read_buf, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
77 nexus->read_len + len + 1); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
78 strncpy(nexus->read_buf + nexus->read_len, temp_buf, len); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
79 nexus->read_len += len; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
80 nexus->read_buf[nexus->read_len] = '\0'; |
8171 | 81 } |
82 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
83 return len; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
84 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
85 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
86 static void |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
87 nexus_write_cb(gpointer data, gint source, GaimInputCondition cond) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
88 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
89 MsnNexus *nexus = data; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
90 int len, total_len; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
91 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
92 total_len = strlen(nexus->write_buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
93 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
94 len = gaim_ssl_write(nexus->gsc, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
95 nexus->write_buf + nexus->written_len, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
96 total_len - nexus->written_len); |
8171 | 97 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
98 if (len < 0 && errno == EAGAIN) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
99 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
100 else if (len <= 0) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
101 gaim_input_remove(nexus->input_handler); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
102 nexus->input_handler = -1; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
103 /* TODO: notify of the error */ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
104 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
105 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
106 nexus->written_len += len; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
107 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
108 if (nexus->written_len < total_len) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
109 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
110 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
111 gaim_input_remove(nexus->input_handler); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
112 nexus->input_handler = -1; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
113 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
114 g_free(nexus->write_buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
115 nexus->write_buf = NULL; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
116 nexus->written_len = 0; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
117 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
118 nexus->written_cb(nexus, source, 0); |
8171 | 119 } |
120 | |
121 /************************************************************************** | |
122 * Login | |
123 **************************************************************************/ | |
124 | |
125 static void | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
126 login_connect_cb(gpointer data, GaimSslConnection *gsc, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
127 GaimInputCondition cond); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
128 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
129 static void |
8171 | 130 login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data) |
131 { | |
132 MsnNexus *nexus; | |
133 MsnSession *session; | |
134 | |
135 nexus = data; | |
136 g_return_if_fail(nexus != NULL); | |
137 | |
138 session = nexus->session; | |
139 g_return_if_fail(session != NULL); | |
140 | |
10481 | 141 msn_session_set_error(session, MSN_ERROR_AUTH, _("Unable to connect")); |
10568 | 142 /* the above line will result in nexus being destroyed, so we don't want |
143 * to destroy it here, or we'd crash */ | |
8171 | 144 } |
145 | |
146 static void | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
147 nexus_login_written_cb(gpointer data, gint source, GaimInputCondition cond) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
148 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
149 MsnNexus *nexus = data; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
150 MsnSession *session; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
151 int len; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
152 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
153 session = nexus->session; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
154 g_return_if_fail(session != NULL); |
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 if (nexus->input_handler == -1) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
157 nexus->input_handler = gaim_input_add(nexus->gsc->fd, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
158 GAIM_INPUT_READ, nexus_login_written_cb, nexus); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
159 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
160 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
161 len = msn_ssl_read(nexus); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
162 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
163 if (len < 0 && errno == EAGAIN) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
164 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
165 else if (len < 0) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
166 gaim_input_remove(nexus->input_handler); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
167 nexus->input_handler = -1; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
168 g_free(nexus->read_buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
169 nexus->read_buf = NULL; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
170 nexus->read_len = 0; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
171 /* TODO: error handling */ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
172 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
173 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
174 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
175 if (g_strstr_len(nexus->read_buf, nexus->read_len, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
176 "\r\n\r\n") == NULL) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
177 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
178 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
179 gaim_input_remove(nexus->input_handler); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
180 nexus->input_handler = -1; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
181 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
182 gaim_ssl_close(nexus->gsc); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
183 nexus->gsc = NULL; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
184 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
185 gaim_debug_misc("msn", "ssl buffer: {%s}", nexus->read_buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
186 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
187 if (strstr(nexus->read_buf, "HTTP/1.1 302") != NULL) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
188 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
189 /* Redirect. */ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
190 char *location, *c; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
191 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
192 location = strstr(nexus->read_buf, "Location: "); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
193 if (location == NULL) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
194 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
195 g_free(nexus->read_buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
196 nexus->read_buf = NULL; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
197 nexus->read_len = 0; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
198 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
199 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
200 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
201 location = strchr(location, ' ') + 1; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
202 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
203 if ((c = strchr(location, '\r')) != NULL) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
204 *c = '\0'; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
205 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
206 /* Skip the http:// */ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
207 if ((c = strchr(location, '/')) != NULL) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
208 location = c + 2; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
209 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
210 if ((c = strchr(location, '/')) != NULL) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
211 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
212 g_free(nexus->login_path); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
213 nexus->login_path = g_strdup(c); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
214 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
215 *c = '\0'; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
216 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
217 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
218 g_free(nexus->login_host); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
219 nexus->login_host = g_strdup(location); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
220 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
221 gaim_ssl_connect(session->account, nexus->login_host, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
222 GAIM_SSL_DEFAULT_PORT, login_connect_cb, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
223 login_error_cb, nexus); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
224 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
225 else if (strstr(nexus->read_buf, "HTTP/1.1 401 Unauthorized") != NULL) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
226 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
227 const char *error; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
228 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
229 if ((error = strstr(nexus->read_buf, "WWW-Authenticate")) != NULL) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
230 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
231 if ((error = strstr(error, "cbtxt=")) != NULL) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
232 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
233 const char *c; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
234 char *temp; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
235 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
236 error += strlen("cbtxt="); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
237 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
238 if ((c = strchr(error, '\n')) == NULL) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
239 c = error + strlen(error); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
240 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
241 temp = g_strndup(error, c - error); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
242 error = gaim_url_decode(temp); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
243 g_free(temp); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
244 } |
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 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
247 msn_session_set_error(session, MSN_ERROR_AUTH, error); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
248 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
249 else if (strstr(nexus->read_buf, "HTTP/1.1 200 OK")) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
250 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
251 char *base, *c; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
252 char *login_params; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
253 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
254 #if 0 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
255 /* All your base are belong to us. */ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
256 base = buffer; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
257 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
258 /* For great cookie! */ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
259 while ((base = strstr(base, "Set-Cookie: ")) != NULL) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
260 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
261 base += strlen("Set-Cookie: "); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
262 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
263 c = strchr(base, ';'); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
264 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
265 session->login_cookies = |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
266 g_list_append(session->login_cookies, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
267 g_strndup(base, c - base)); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
268 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
269 #endif |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
270 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
271 base = strstr(nexus->read_buf, "Authentication-Info: "); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
272 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
273 g_return_if_fail(base != NULL); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
274 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
275 base = strstr(base, "from-PP='"); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
276 base += strlen("from-PP='"); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
277 c = strchr(base, '\''); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
278 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
279 login_params = g_strndup(base, c - base); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
280 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
281 msn_got_login_params(session, login_params); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
282 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
283 g_free(login_params); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
284 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
285 msn_nexus_destroy(nexus); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
286 session->nexus = NULL; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
287 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
288 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
289 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
290 g_free(nexus->read_buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
291 nexus->read_buf = NULL; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
292 nexus->read_len = 0; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
293 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
294 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
295 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
296 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
297 void |
8171 | 298 login_connect_cb(gpointer data, GaimSslConnection *gsc, |
299 GaimInputCondition cond) | |
300 { | |
301 MsnNexus *nexus; | |
302 MsnSession *session; | |
303 char *username, *password; | |
12457 | 304 char *request_str, *head, *tail; |
8171 | 305 char *buffer = NULL; |
9966 | 306 guint32 ctint; |
8171 | 307 |
308 nexus = data; | |
309 g_return_if_fail(nexus != NULL); | |
310 | |
311 session = nexus->session; | |
312 g_return_if_fail(session != NULL); | |
313 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
314 nexus->gsc = gsc; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
315 |
10519 | 316 msn_session_set_login_step(session, MSN_LOGIN_STEP_GET_COOKIE); |
10481 | 317 |
8171 | 318 username = |
319 g_strdup(gaim_url_encode(gaim_account_get_username(session->account))); | |
320 | |
321 password = | |
10740 | 322 g_strdup(gaim_url_encode(gaim_connection_get_password(session->account->gc))); |
8171 | 323 |
9966 | 324 ctint = strtoul((char *)g_hash_table_lookup(nexus->challenge_data, "ct"), NULL, 10) + 200; |
325 | |
12457 | 326 head = g_strdup_printf( |
8171 | 327 "GET %s HTTP/1.1\r\n" |
12457 | 328 "Authorization: Passport1.4 OrgVerb=GET,OrgURL=%s,sign-in=%s", |
329 nexus->login_path, | |
330 (char *)g_hash_table_lookup(nexus->challenge_data, "ru"), | |
331 username); | |
332 | |
333 tail = g_strdup_printf( | |
9966 | 334 "lc=%s,id=%s,tw=%s,fs=%s,ru=%s,ct=%" G_GUINT32_FORMAT ",kpp=%s,kv=%s,ver=%s,tpf=%s\r\n" |
8171 | 335 "User-Agent: MSMSGS\r\n" |
336 "Host: %s\r\n" | |
337 "Connection: Keep-Alive\r\n" | |
12457 | 338 "Cache-Control: no-cache\r\n", |
8171 | 339 (char *)g_hash_table_lookup(nexus->challenge_data, "lc"), |
340 (char *)g_hash_table_lookup(nexus->challenge_data, "id"), | |
341 (char *)g_hash_table_lookup(nexus->challenge_data, "tw"), | |
342 (char *)g_hash_table_lookup(nexus->challenge_data, "fs"), | |
343 (char *)g_hash_table_lookup(nexus->challenge_data, "ru"), | |
9966 | 344 ctint, |
8171 | 345 (char *)g_hash_table_lookup(nexus->challenge_data, "kpp"), |
346 (char *)g_hash_table_lookup(nexus->challenge_data, "kv"), | |
347 (char *)g_hash_table_lookup(nexus->challenge_data, "ver"), | |
348 (char *)g_hash_table_lookup(nexus->challenge_data, "tpf"), | |
349 nexus->login_host); | |
350 | |
12457 | 351 buffer = g_strdup_printf("%s,pwd=XXXXXXXX,%s\r\n", head, tail); |
352 request_str = g_strdup_printf("%s,pwd=%s,%s\r\n", head, password, tail); | |
8171 | 353 |
12457 | 354 gaim_debug_misc("msn", "Sending: {%s}\n", buffer); |
355 | |
356 g_free(buffer); | |
357 g_free(head); | |
358 g_free(tail); | |
8171 | 359 g_free(username); |
360 g_free(password); | |
361 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
362 nexus->write_buf = request_str; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
363 nexus->written_len = 0; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
364 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
365 nexus->read_len = 0; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
366 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
367 nexus->written_cb = nexus_login_written_cb; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
368 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
369 nexus->input_handler = gaim_input_add(gsc->fd, GAIM_INPUT_WRITE, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
370 nexus_write_cb, nexus); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
371 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
372 nexus_write_cb(nexus, gsc->fd, GAIM_INPUT_WRITE); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
373 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
374 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
375 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
376 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
377 } |
8171 | 378 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
379 static void |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
380 nexus_connect_written_cb(gpointer data, gint source, GaimInputCondition cond) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
381 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
382 MsnNexus *nexus = data; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
383 int len; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
384 char *da_login; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
385 char *base, *c; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
386 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
387 if (nexus->input_handler == -1) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
388 nexus->input_handler = gaim_input_add(nexus->gsc->fd, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
389 GAIM_INPUT_READ, nexus_connect_written_cb, nexus); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
390 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
391 /* Get the PassportURLs line. */ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
392 len = msn_ssl_read(nexus); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
393 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
394 if (len < 0 && errno == EAGAIN) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
395 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
396 else if (len < 0) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
397 gaim_input_remove(nexus->input_handler); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
398 nexus->input_handler = -1; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
399 g_free(nexus->read_buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
400 nexus->read_buf = NULL; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
401 nexus->read_len = 0; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
402 /* TODO: error handling */ |
8171 | 403 return; |
404 } | |
405 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
406 if (g_strstr_len(nexus->read_buf, nexus->read_len, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
407 "\r\n\r\n") == NULL) |
8171 | 408 return; |
409 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
410 gaim_input_remove(nexus->input_handler); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
411 nexus->input_handler = -1; |
8171 | 412 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
413 base = strstr(nexus->read_buf, "PassportURLs"); |
8171 | 414 |
415 if (base == NULL) | |
416 { | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
417 g_free(nexus->read_buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
418 nexus->read_buf = NULL; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
419 nexus->read_len = 0; |
8171 | 420 return; |
421 } | |
422 | |
423 if ((da_login = strstr(base, "DALogin=")) != NULL) | |
424 { | |
425 if ((da_login = strchr(da_login, '=')) != NULL) | |
426 da_login++; | |
427 | |
428 if ((c = strchr(da_login, ',')) != NULL) | |
429 *c = '\0'; | |
430 | |
431 if ((c = strchr(da_login, '/')) != NULL) | |
432 { | |
433 nexus->login_path = g_strdup(c); | |
434 *c = '\0'; | |
435 } | |
436 | |
437 nexus->login_host = g_strdup(da_login); | |
438 } | |
439 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
440 g_free(nexus->read_buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
441 nexus->read_buf = NULL; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
442 nexus->read_len = 0; |
8171 | 443 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
444 gaim_ssl_close(nexus->gsc); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
445 nexus->gsc = NULL; |
8171 | 446 |
447 /* Now begin the connection to the login server. */ | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
448 gaim_ssl_connect(nexus->session->account, nexus->login_host, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
449 GAIM_SSL_DEFAULT_PORT, login_connect_cb, login_error_cb, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
450 nexus); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
451 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
452 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
453 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
454 /************************************************************************** |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
455 * Connect |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
456 **************************************************************************/ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
457 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
458 static void |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
459 nexus_connect_cb(gpointer data, GaimSslConnection *gsc, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
460 GaimInputCondition cond) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
461 { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
462 MsnNexus *nexus; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
463 MsnSession *session; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
464 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
465 nexus = data; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
466 g_return_if_fail(nexus != NULL); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
467 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
468 session = nexus->session; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
469 g_return_if_fail(session != NULL); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
470 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
471 nexus->gsc = gsc; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
472 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
473 msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
474 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
475 nexus->write_buf = g_strdup("GET /rdr/pprdr.asp\r\n\r\n"); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
476 nexus->written_len = 0; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
477 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
478 nexus->read_len = 0; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
479 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
480 nexus->written_cb = nexus_connect_written_cb; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
481 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
482 nexus->input_handler = gaim_input_add(gsc->fd, GAIM_INPUT_WRITE, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
483 nexus_write_cb, nexus); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
484 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
485 nexus_write_cb(nexus, gsc->fd, GAIM_INPUT_WRITE); |
8171 | 486 } |
487 | |
488 void | |
489 msn_nexus_connect(MsnNexus *nexus) | |
490 { | |
491 gaim_ssl_connect(nexus->session->account, "nexus.passport.com", | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
492 GAIM_SSL_DEFAULT_PORT, nexus_connect_cb, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12457
diff
changeset
|
493 login_error_cb, nexus); |
8171 | 494 } |