Mercurial > pidgin.yaz
annotate src/protocols/msn/servconn.c @ 8569:ee13d1befabe
[gaim-migrate @ 9317]
Patch by Stu Tomlinson to restore MSN error reporting. Thanks!
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sat, 03 Apr 2004 03:17:51 +0000 |
parents | 06f57183e29f |
children | fc27237783ee |
rev | line source |
---|---|
5309 | 1 /** |
2 * @file servconn.c Server connection functions | |
3 * | |
4 * gaim | |
5 * | |
8475
06f57183e29f
[gaim-migrate @ 9208]
Christian Hammond <chipx86@chipx86.com>
parents:
8299
diff
changeset
|
6 * Copyright (C) 2003-2004 Christian Hammond <chipx86@gnupdate.org> |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
6122
diff
changeset
|
7 * |
5309 | 8 * This program is free software; you can redistribute it and/or modify |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 #include "msn.h" | |
23 #include "servconn.h" | |
8569
ee13d1befabe
[gaim-migrate @ 9317]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
24 #include "error.h" |
5309 | 25 |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
26 typedef struct |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
27 { |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
28 char *command; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
29 MsnMessage *msg; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
30 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
31 } MsnQueueEntry; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
32 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
33 static gboolean |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5785
diff
changeset
|
34 process_message(MsnServConn *servconn, MsnMessage *msg) |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
35 { |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
36 MsnServConnMsgCb cb; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
37 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
38 cb = g_hash_table_lookup(servconn->msg_types, |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
39 msn_message_get_content_type(msg)); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
40 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
41 if (cb == NULL) { |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
42 gaim_debug(GAIM_DEBUG_WARNING, "msn", |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
43 "Unhandled content-type '%s': %s\n", |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
44 msn_message_get_content_type(msg), |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
45 msn_message_get_body(msg)); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
46 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
47 return FALSE; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
48 } |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
49 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
50 cb(servconn, msg); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
51 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
52 return TRUE; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
53 } |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
54 |
5309 | 55 static gboolean |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5785
diff
changeset
|
56 process_single_line(MsnServConn *servconn, char *str) |
5309 | 57 { |
5897
e3733414ca08
[gaim-migrate @ 6329]
Christian Hammond <chipx86@chipx86.com>
parents:
5793
diff
changeset
|
58 MsnSession *session = servconn->session; |
5309 | 59 MsnServConnCommandCb cb; |
5897
e3733414ca08
[gaim-migrate @ 6329]
Christian Hammond <chipx86@chipx86.com>
parents:
5793
diff
changeset
|
60 GSList *l, *l_next = NULL; |
5309 | 61 gboolean result; |
62 size_t param_count = 0; | |
63 char *command, *param_start; | |
64 char **params = NULL; | |
65 | |
66 command = str; | |
67 | |
68 /** | |
69 * See how many spaces we have in this. | |
70 */ | |
71 param_start = strchr(command, ' '); | |
72 | |
73 if (param_start != NULL) { | |
74 params = g_strsplit(param_start + 1, " ", 0); | |
75 | |
76 for (param_count = 0; params[param_count] != NULL; param_count++) | |
77 ; | |
78 | |
79 *param_start = '\0'; | |
80 } | |
81 | |
82 cb = g_hash_table_lookup(servconn->commands, command); | |
83 | |
84 if (cb == NULL) { | |
7938
160547821ea2
[gaim-migrate @ 8609]
Christian Hammond <chipx86@chipx86.com>
parents:
7604
diff
changeset
|
85 cb = g_hash_table_lookup(servconn->commands, "_unknown_"); |
5309 | 86 |
87 if (cb == NULL) { | |
8569
ee13d1befabe
[gaim-migrate @ 9317]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
88 if (isdigit(*str)) |
ee13d1befabe
[gaim-migrate @ 9317]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
89 msn_error_handle(session, atoi(str)); |
ee13d1befabe
[gaim-migrate @ 9317]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
90 else |
ee13d1befabe
[gaim-migrate @ 9317]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
91 gaim_debug(GAIM_DEBUG_WARNING, "msn", |
5309 | 92 "Unhandled command '%s'\n", str); |
93 | |
94 if (params != NULL) | |
95 g_strfreev(params); | |
96 | |
97 return TRUE; | |
98 } | |
99 } | |
100 | |
101 result = cb(servconn, command, (const char **)params, param_count); | |
102 | |
103 if (params != NULL) | |
104 g_strfreev(params); | |
105 | |
5898
5baeb89ee2d4
[gaim-migrate @ 6330]
Christian Hammond <chipx86@chipx86.com>
parents:
5897
diff
changeset
|
106 if (g_list_find(session->servconns, servconn) == NULL) |
5897
e3733414ca08
[gaim-migrate @ 6329]
Christian Hammond <chipx86@chipx86.com>
parents:
5793
diff
changeset
|
107 return result; |
e3733414ca08
[gaim-migrate @ 6329]
Christian Hammond <chipx86@chipx86.com>
parents:
5793
diff
changeset
|
108 |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
109 /* Process all queued messages that are waiting on this command. */ |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
110 for (l = servconn->msg_queue; l != NULL; l = l_next) { |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
111 MsnQueueEntry *entry = l->data; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
112 MsnMessage *msg; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
113 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
114 l_next = l->next; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
115 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
116 if (entry->command == NULL || |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
117 !g_ascii_strcasecmp(entry->command, command)) { |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
118 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
119 MsnUser *sender; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
120 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
121 msg = entry->msg; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
122 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
123 msn_message_ref(msg); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
124 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
125 sender = msn_message_get_sender(msg); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
126 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
127 servconn->msg_passport = g_strdup(msn_user_get_passport(sender)); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
128 servconn->msg_friendly = g_strdup(msn_user_get_name(sender)); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
129 |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5785
diff
changeset
|
130 process_message(servconn, msg); |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
131 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
132 g_free(servconn->msg_passport); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
133 g_free(servconn->msg_friendly); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
134 |
6122 | 135 msn_servconn_unqueue_message(servconn, entry->msg); |
136 | |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
137 msn_message_destroy(msg); |
5744
6b87c127fe7b
[gaim-migrate @ 6168]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
138 entry->msg = NULL; |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
139 } |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
140 } |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
141 |
5309 | 142 return result; |
143 } | |
144 | |
145 static gboolean | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5785
diff
changeset
|
146 process_multi_line(MsnServConn *servconn, char *buffer) |
5309 | 147 { |
148 char msg_str[MSN_BUF_LEN]; | |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
149 gboolean result = TRUE; |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
150 |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
151 if (servconn->multiline_type == MSN_MULTILINE_MSG) { |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
152 MsnMessage *msg; |
7604
43803965ef45
[gaim-migrate @ 8227]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
153 size_t header_len; |
5309 | 154 |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
155 g_snprintf(msg_str, sizeof(msg_str), |
7604
43803965ef45
[gaim-migrate @ 8227]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
156 "MSG %s %s %d\r\n", |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
157 servconn->msg_passport, servconn->msg_friendly, |
7604
43803965ef45
[gaim-migrate @ 8227]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
158 servconn->multiline_len); |
43803965ef45
[gaim-migrate @ 8227]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
159 |
43803965ef45
[gaim-migrate @ 8227]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
160 header_len = strlen(msg_str); |
43803965ef45
[gaim-migrate @ 8227]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
161 |
43803965ef45
[gaim-migrate @ 8227]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
162 memcpy(msg_str + header_len, buffer, servconn->multiline_len); |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
163 |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
164 gaim_debug(GAIM_DEBUG_MISC, "msn", |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
165 "Message: {%s}\n", buffer); |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
166 |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
167 msg = msn_message_new_from_str(servconn->session, msg_str); |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
168 |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
169 result = process_message(servconn, msg); |
5309 | 170 |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
171 msn_message_destroy(msg); |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
172 } |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
173 else if (servconn->multiline_type == MSN_MULTILINE_IPG) { |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
174 g_snprintf(msg_str, sizeof(msg_str), |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
175 "IPG %d\r\n%s", |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
176 servconn->multiline_len, buffer); |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5317
diff
changeset
|
177 |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
178 gaim_debug(GAIM_DEBUG_MISC, "msn", |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
179 "Incoming Page: {%s}\n", buffer); |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
180 } |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
181 else if (servconn->multiline_type == MSN_MULTILINE_NOT) { |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
182 g_snprintf(msg_str, sizeof(msg_str), |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
183 "NOT %d\r\n%s", |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
184 servconn->multiline_len, buffer); |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
185 |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
186 gaim_debug(GAIM_DEBUG_MISC, "msn", |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
187 "Notification: {%s}\n", buffer); |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
188 } |
5309 | 189 |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
190 return result; |
5309 | 191 } |
192 | |
193 static void | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5785
diff
changeset
|
194 connect_cb(gpointer data, gint source, GaimInputCondition cond) |
5309 | 195 { |
196 MsnServConn *servconn = data; | |
197 | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
198 gaim_debug_info("msn", "In servconn's connect_cb\n"); |
5309 | 199 if (servconn->connect_cb(data, source, cond)) |
200 servconn->inpa = gaim_input_add(servconn->fd, GAIM_INPUT_READ, | |
201 servconn->login_cb, data); | |
202 } | |
203 | |
204 MsnServConn * | |
205 msn_servconn_new(MsnSession *session) | |
206 { | |
207 MsnServConn *servconn; | |
208 | |
209 g_return_val_if_fail(session != NULL, NULL); | |
210 | |
211 servconn = g_new0(MsnServConn, 1); | |
212 | |
213 servconn->login_cb = msn_servconn_parse_data; | |
214 servconn->session = session; | |
215 | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
216 if (session->http_method) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
217 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
218 servconn->http_data = g_new0(MsnHttpMethodData, 1); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
219 servconn->http_data->virgin = TRUE; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
220 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
221 |
5309 | 222 servconn->commands = g_hash_table_new_full(g_str_hash, g_str_equal, |
223 g_free, NULL); | |
224 | |
225 servconn->msg_types = g_hash_table_new_full(g_str_hash, g_str_equal, | |
226 g_free, NULL); | |
227 | |
5898
5baeb89ee2d4
[gaim-migrate @ 6330]
Christian Hammond <chipx86@chipx86.com>
parents:
5897
diff
changeset
|
228 session->servconns = g_list_append(session->servconns, servconn); |
5baeb89ee2d4
[gaim-migrate @ 6330]
Christian Hammond <chipx86@chipx86.com>
parents:
5897
diff
changeset
|
229 |
5309 | 230 return servconn; |
231 } | |
232 | |
233 gboolean | |
234 msn_servconn_connect(MsnServConn *servconn) | |
235 { | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
236 MsnSession *session; |
5309 | 237 int i; |
238 | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
239 g_return_val_if_fail(servconn != NULL, FALSE); |
5309 | 240 g_return_val_if_fail(servconn->server != NULL, FALSE); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
241 g_return_val_if_fail(!servconn->connected, TRUE); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
242 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
243 session = servconn->session; |
5309 | 244 |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
245 if (session->http_method) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
246 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
247 servconn->http_data->gateway_ip = g_strdup(servconn->server); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
248 |
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
249 g_free(servconn->server); |
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
250 servconn->server = g_strdup("gateway.messenger.hotmail.com"); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
251 servconn->port = 80; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
252 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
253 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
254 i = gaim_proxy_connect(session->account, servconn->server, |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
255 servconn->port, connect_cb, servconn); |
5309 | 256 |
257 if (i == 0) | |
258 servconn->connected = TRUE; | |
259 | |
260 return servconn->connected; | |
261 } | |
262 | |
263 void | |
264 msn_servconn_disconnect(MsnServConn *servconn) | |
265 { | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
266 MsnSession *session; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
267 |
5309 | 268 g_return_if_fail(servconn != NULL); |
269 g_return_if_fail(servconn->connected); | |
270 | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
271 session = servconn->session; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
272 |
5309 | 273 if (servconn->inpa) |
274 gaim_input_remove(servconn->inpa); | |
275 | |
5744
6b87c127fe7b
[gaim-migrate @ 6168]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
276 close(servconn->fd); |
6b87c127fe7b
[gaim-migrate @ 6168]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
277 |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
278 if (servconn->http_data != NULL) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
279 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
280 if (servconn->http_data->session_id != NULL) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
281 g_free(servconn->http_data->session_id); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
282 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
283 if (servconn->http_data->old_gateway_ip != NULL) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
284 g_free(servconn->http_data->old_gateway_ip); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
285 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
286 if (servconn->http_data->gateway_ip != NULL) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
287 g_free(servconn->http_data->gateway_ip); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
288 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
289 if (servconn->http_data->timer) |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
7938
diff
changeset
|
290 gaim_timeout_remove(servconn->http_data->timer); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
291 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
292 g_free(servconn->http_data); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
293 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
294 |
6827
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6826
diff
changeset
|
295 if (servconn->rxqueue != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6826
diff
changeset
|
296 g_free(servconn->rxqueue); |
5309 | 297 |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
298 while (servconn->txqueue != NULL) { |
5309 | 299 g_free(servconn->txqueue->data); |
300 | |
301 servconn->txqueue = g_slist_remove(servconn->txqueue, | |
302 servconn->txqueue->data); | |
303 } | |
304 | |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
305 while (servconn->msg_queue != NULL) { |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
306 MsnQueueEntry *entry = servconn->msg_queue->data; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
307 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
308 msn_servconn_unqueue_message(servconn, entry->msg); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
309 } |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
310 |
5309 | 311 servconn->connected = FALSE; |
312 } | |
313 | |
314 void | |
315 msn_servconn_destroy(MsnServConn *servconn) | |
316 { | |
5898
5baeb89ee2d4
[gaim-migrate @ 6330]
Christian Hammond <chipx86@chipx86.com>
parents:
5897
diff
changeset
|
317 MsnSession *session; |
5baeb89ee2d4
[gaim-migrate @ 6330]
Christian Hammond <chipx86@chipx86.com>
parents:
5897
diff
changeset
|
318 |
5309 | 319 g_return_if_fail(servconn != NULL); |
320 | |
5898
5baeb89ee2d4
[gaim-migrate @ 6330]
Christian Hammond <chipx86@chipx86.com>
parents:
5897
diff
changeset
|
321 session = servconn->session; |
5baeb89ee2d4
[gaim-migrate @ 6330]
Christian Hammond <chipx86@chipx86.com>
parents:
5897
diff
changeset
|
322 |
5baeb89ee2d4
[gaim-migrate @ 6330]
Christian Hammond <chipx86@chipx86.com>
parents:
5897
diff
changeset
|
323 session->servconns = g_list_remove(session->servconns, servconn); |
5baeb89ee2d4
[gaim-migrate @ 6330]
Christian Hammond <chipx86@chipx86.com>
parents:
5897
diff
changeset
|
324 |
5309 | 325 if (servconn->connected) |
326 msn_servconn_disconnect(servconn); | |
327 | |
328 if (servconn->server != NULL) | |
329 g_free(servconn->server); | |
330 | |
331 g_free(servconn); | |
332 } | |
333 | |
334 void | |
335 msn_servconn_set_server(MsnServConn *servconn, const char *server, int port) | |
336 { | |
337 g_return_if_fail(servconn != NULL); | |
338 g_return_if_fail(server != NULL); | |
339 g_return_if_fail(port > 0); | |
340 | |
341 if (servconn->server != NULL) | |
342 g_free(servconn->server); | |
343 | |
344 servconn->server = g_strdup(server); | |
345 servconn->port = port; | |
346 } | |
347 | |
348 const char * | |
349 msn_servconn_get_server(const MsnServConn *servconn) | |
350 { | |
351 g_return_val_if_fail(servconn != NULL, NULL); | |
352 | |
353 return servconn->server; | |
354 } | |
355 | |
356 int | |
357 msn_servconn_get_port(const MsnServConn *servconn) | |
358 { | |
359 g_return_val_if_fail(servconn != NULL, 0); | |
360 | |
361 return servconn->port; | |
362 } | |
363 | |
364 void | |
365 msn_servconn_set_connect_cb(MsnServConn *servconn, | |
366 gboolean (*connect_cb)(gpointer, gint, | |
367 GaimInputCondition)) | |
368 { | |
369 g_return_if_fail(servconn != NULL); | |
370 | |
371 servconn->connect_cb = connect_cb; | |
372 } | |
373 | |
374 void | |
375 msn_servconn_set_failed_read_cb(MsnServConn *servconn, | |
376 void (*failed_read_cb)(gpointer, gint, | |
377 GaimInputCondition)) | |
378 { | |
379 g_return_if_fail(servconn != NULL); | |
380 | |
381 servconn->failed_read_cb = failed_read_cb; | |
382 } | |
383 | |
384 size_t | |
385 msn_servconn_write(MsnServConn *servconn, const char *buf, size_t size) | |
386 { | |
387 g_return_val_if_fail(servconn != NULL, 0); | |
388 | |
389 gaim_debug(GAIM_DEBUG_MISC, "msn", "C: %s%s", buf, | |
390 (*(buf + size - 1) == '\n' ? "" : "\n")); | |
391 | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
392 if (servconn->session->http_method) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
393 return msn_http_servconn_write(servconn, buf, size, |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
394 servconn->http_data->server_type); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
395 else |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
396 return write(servconn->fd, buf, size); |
5309 | 397 } |
398 | |
399 gboolean | |
400 msn_servconn_send_command(MsnServConn *servconn, const char *command, | |
401 const char *params) | |
402 { | |
403 char buf[MSN_BUF_LEN]; | |
404 | |
405 g_return_val_if_fail(servconn != NULL, FALSE); | |
406 g_return_val_if_fail(command != NULL, FALSE); | |
407 | |
408 if (params == NULL) | |
409 g_snprintf(buf, sizeof(buf), "%s %u\r\n", command, | |
410 servconn->session->trId++); | |
411 else | |
412 g_snprintf(buf, sizeof(buf), "%s %u %s\r\n", | |
413 command, servconn->session->trId++, params); | |
414 | |
415 return (msn_servconn_write(servconn, buf, strlen(buf)) > 0); | |
416 } | |
417 | |
418 void | |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
419 msn_servconn_queue_message(MsnServConn *servconn, const char *command, |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
420 MsnMessage *msg) |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
421 { |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
422 MsnQueueEntry *entry; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
423 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
424 g_return_if_fail(servconn != NULL); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
425 g_return_if_fail(msg != NULL); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
426 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
427 entry = g_new0(MsnQueueEntry, 1); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
428 entry->msg = msg; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
429 entry->command = (command == NULL ? NULL : g_strdup(command)); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
430 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
431 servconn->msg_queue = g_slist_append(servconn->msg_queue, entry); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
432 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
433 msn_message_ref(msg); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
434 } |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
435 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
436 void |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
437 msn_servconn_unqueue_message(MsnServConn *servconn, MsnMessage *msg) |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
438 { |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
439 MsnQueueEntry *entry = NULL; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
440 GSList *l; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
441 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
442 g_return_if_fail(servconn != NULL); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
443 g_return_if_fail(msg != NULL); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
444 |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
445 for (l = servconn->msg_queue; l != NULL; l = l->next) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
446 { |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
447 entry = l->data; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
448 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
449 if (entry->msg == msg) |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
450 break; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
451 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
452 entry = NULL; |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
453 } |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
454 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
455 g_return_if_fail(entry != NULL); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
456 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
457 msn_message_unref(msg); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
458 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
459 servconn->msg_queue = g_slist_remove(servconn->msg_queue, entry); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
460 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
461 if (entry->command != NULL) |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
462 g_free(entry->command); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
463 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
464 g_free(entry); |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
465 } |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
466 |
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
467 void |
5309 | 468 msn_servconn_register_command(MsnServConn *servconn, const char *command, |
469 MsnServConnCommandCb cb) | |
470 { | |
471 char *command_up; | |
472 | |
473 g_return_if_fail(servconn != NULL); | |
474 g_return_if_fail(command != NULL); | |
475 g_return_if_fail(cb != NULL); | |
476 | |
477 command_up = g_ascii_strup(command, -1); | |
478 | |
479 g_hash_table_insert(servconn->commands, command_up, cb); | |
480 } | |
481 | |
482 void | |
483 msn_servconn_register_msg_type(MsnServConn *servconn, | |
484 const char *content_type, | |
485 MsnServConnMsgCb cb) | |
486 { | |
487 g_return_if_fail(servconn != NULL); | |
488 g_return_if_fail(content_type != NULL); | |
489 g_return_if_fail(cb != NULL); | |
490 | |
491 g_hash_table_insert(servconn->msg_types, g_strdup(content_type), cb); | |
492 } | |
493 | |
494 void | |
495 msn_servconn_parse_data(gpointer data, gint source, GaimInputCondition cond) | |
496 { | |
497 MsnServConn *servconn = (MsnServConn *)data; | |
5899
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
498 MsnSession *session = servconn->session; |
5309 | 499 char buf[MSN_BUF_LEN]; |
500 gboolean cont = TRUE; | |
501 int len; | |
502 | |
503 len = read(servconn->fd, buf, sizeof(buf)); | |
504 | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
505 if (len <= 0) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
506 { |
5309 | 507 if (servconn->failed_read_cb != NULL) |
508 servconn->failed_read_cb(data, source, cond); | |
509 | |
510 return; | |
511 } | |
512 | |
513 servconn->rxqueue = g_realloc(servconn->rxqueue, len + servconn->rxlen); | |
514 memcpy(servconn->rxqueue + servconn->rxlen, buf, len); | |
515 servconn->rxlen += len; | |
516 | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
517 if (session->http_method) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
518 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
519 char *result_msg = NULL; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
520 size_t result_len = 0; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
521 gboolean error; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
522 char *tmp; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
523 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
524 tmp = g_strndup(servconn->rxqueue, servconn->rxlen); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
525 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
526 if (!msn_http_servconn_parse_data(servconn, tmp, |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
527 servconn->rxlen, &result_msg, |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
528 &result_len, &error)) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
529 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
530 g_free(tmp); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
531 return; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
532 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
533 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
534 g_free(tmp); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
535 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
536 if (error) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
537 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
538 gaim_connection_error( |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
539 gaim_account_get_connection(session->account), |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
540 _("Received HTTP error. Please report this.")); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
541 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
542 return; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
543 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
544 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
545 if (servconn->http_data->session_id != NULL && |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
546 !strcmp(servconn->http_data->session_id, "close")) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
547 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
548 msn_servconn_destroy(servconn); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
549 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
550 return; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
551 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
552 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
553 #if 0 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
554 if (strcmp(servconn->http_data->gateway_ip, |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
555 msn_servconn_get_server(servconn)) != 0) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
556 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
557 int i; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
558 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
559 /* Evil hackery. I promise to remove it, even though I can't. */ |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
560 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
561 servconn->connected = FALSE; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
562 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
563 if (servconn->inpa) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
564 gaim_input_remove(servconn->inpa); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
565 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
566 close(servconn->fd); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
567 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
568 i = gaim_proxy_connect(session->account, servconn->server, |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
569 servconn->port, servconn->login_cb, |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
570 servconn); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
571 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
572 if (i == 0) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
573 servconn->connected = TRUE; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
574 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
575 #endif |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
576 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
577 g_free(servconn->rxqueue); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
578 servconn->rxqueue = result_msg; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
579 servconn->rxlen = result_len; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
580 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
581 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
582 while (cont) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
583 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
584 if (servconn->parsing_multiline) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
585 { |
5309 | 586 char *msg; |
587 | |
588 if (servconn->rxlen == 0) | |
589 break; | |
590 | |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
591 if (servconn->multiline_len > servconn->rxlen) |
5309 | 592 break; |
593 | |
594 msg = servconn->rxqueue; | |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
595 servconn->rxlen -= servconn->multiline_len; |
5309 | 596 |
597 if (servconn->rxlen) { | |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
598 servconn->rxqueue = g_memdup(msg + servconn->multiline_len, |
5309 | 599 servconn->rxlen); |
600 } | |
601 else { | |
602 servconn->rxqueue = NULL; | |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
603 msg = g_realloc(msg, servconn->multiline_len + 1); |
5309 | 604 } |
605 | |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
606 msg[servconn->multiline_len] = '\0'; |
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
607 servconn->parsing_multiline = FALSE; |
5309 | 608 |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5785
diff
changeset
|
609 process_multi_line(servconn, msg); |
5309 | 610 |
5899
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
611 if (g_list_find(session->servconns, servconn) != NULL) { |
5962
115769a4c6fc
[gaim-migrate @ 6409]
Christian Hammond <chipx86@chipx86.com>
parents:
5899
diff
changeset
|
612 servconn->multiline_len = 0; |
5899
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
613 |
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
614 if (servconn->msg_passport != NULL) |
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
615 g_free(servconn->msg_passport); |
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
616 |
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
617 if (servconn->msg_friendly != NULL) |
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
618 g_free(servconn->msg_friendly); |
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
619 } |
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
620 else |
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
621 cont = 0; |
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
622 |
5309 | 623 g_free(msg); |
624 } | |
625 else { | |
626 char *end = servconn->rxqueue; | |
627 char *cmd; | |
628 int cmdlen, i; | |
629 | |
630 if (!servconn->rxlen) | |
631 return; | |
632 | |
633 for (i = 0; i < servconn->rxlen - 1; end++, i++) { | |
634 if (*end == '\r' && end[1] == '\n') | |
635 break; | |
636 } | |
637 | |
638 if (i == servconn->rxlen - 1) | |
639 return; | |
640 | |
641 cmdlen = end - servconn->rxqueue + 2; | |
642 cmd = servconn->rxqueue; | |
643 servconn->rxlen -= cmdlen; | |
644 | |
645 if (servconn->rxlen) | |
646 servconn->rxqueue = g_memdup(cmd + cmdlen, servconn->rxlen); | |
647 else { | |
648 servconn->rxqueue = NULL; | |
649 cmd = g_realloc(cmd, cmdlen + 1); | |
650 } | |
651 | |
652 cmd[cmdlen] = '\0'; | |
653 | |
654 gaim_debug(GAIM_DEBUG_MISC, "msn", "S: %s", cmd); | |
655 | |
656 g_strchomp(cmd); | |
657 | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5785
diff
changeset
|
658 cont = process_single_line(servconn, cmd); |
5309 | 659 |
660 g_free(cmd); | |
661 } | |
662 } | |
663 } |