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