Mercurial > pidgin.yaz
comparison src/protocols/msn/servconn.c @ 9092:9e5a709c30a8
[gaim-migrate @ 9869]
More patches by shx. These prevent disconnects with message lengths that
are past the allowed MSN message length, fixes pager messages, and provides
a better error dialog stuff for MSN errors. I hope I got that all right. :)
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 27 May 2004 08:19:29 +0000 |
parents | 9883e3398e37 |
children | 6dd02df922b4 |
comparison
equal
deleted
inserted
replaced
9091:97a1fb329cd2 | 9092:9e5a709c30a8 |
---|---|
24 #include "error.h" | 24 #include "error.h" |
25 | 25 |
26 static void read_cb(gpointer data, gint source, GaimInputCondition cond); | 26 static void read_cb(gpointer data, gint source, GaimInputCondition cond); |
27 | 27 |
28 static void | 28 static void |
29 connect_cb(gpointer data, gint source, GaimInputCondition cond) | |
30 { | |
31 MsnServConn *servconn = data; | |
32 | |
33 gaim_debug_info("msn", "In servconn's connect_cb\n"); | |
34 | |
35 servconn->fd = source; | |
36 | |
37 if (source > 0) | |
38 { | |
39 /* Someone wants to know we connected. */ | |
40 servconn->connect_cb(servconn); | |
41 servconn->inpa = gaim_input_add(servconn->fd, GAIM_INPUT_READ, | |
42 read_cb, data); | |
43 } | |
44 else | |
45 { | |
46 GaimConnection *gc = servconn->session->account->gc; | |
47 gaim_connection_error(gc, _("Unable to connect.")); | |
48 } | |
49 } | |
50 | |
51 MsnServConn * | |
52 msn_servconn_new(MsnSession *session, MsnServerType type) | |
53 { | |
54 MsnServConn *servconn; | |
55 | |
56 g_return_val_if_fail(session != NULL, NULL); | |
57 | |
58 servconn = g_new0(MsnServConn, 1); | |
59 | |
60 servconn->type = type; | |
61 | |
62 servconn->session = session; | |
63 servconn->cmdproc = msn_cmdproc_new(session); | |
64 servconn->cmdproc->servconn = servconn; | |
65 | |
66 if (session->http_method) | |
67 { | |
68 servconn->http_data = g_new0(MsnHttpMethodData, 1); | |
69 servconn->http_data->virgin = TRUE; | |
70 } | |
71 | |
72 servconn->num = session->servconns_count++; | |
73 session->servconns = g_list_append(session->servconns, servconn); | |
74 | |
75 return servconn; | |
76 } | |
77 | |
78 gboolean | |
79 msn_servconn_connect(MsnServConn *servconn, const char *host, int port) | |
80 { | |
81 MsnSession *session; | |
82 int i; | |
83 | |
84 g_return_val_if_fail(servconn != NULL, FALSE); | |
85 g_return_val_if_fail(host != NULL, FALSE); | |
86 g_return_val_if_fail(port > 0, FALSE); | |
87 | |
88 session = servconn->session; | |
89 | |
90 if (servconn->connected) | |
91 msn_servconn_disconnect(servconn); | |
92 | |
93 if (session->http_method) | |
94 { | |
95 servconn->http_data->gateway_ip = g_strdup(host); | |
96 } | |
97 | |
98 i = gaim_proxy_connect(session->account, host, port, connect_cb, | |
99 servconn); | |
100 | |
101 if (i == 0) | |
102 servconn->connected = TRUE; | |
103 | |
104 return servconn->connected; | |
105 } | |
106 | |
107 void | |
108 msn_servconn_disconnect(MsnServConn *servconn) | |
109 { | |
110 MsnSession *session; | |
111 | |
112 g_return_if_fail(servconn != NULL); | |
113 g_return_if_fail(servconn->connected); | |
114 | |
115 session = servconn->session; | |
116 | |
117 if (servconn->inpa > 0) | |
118 { | |
119 gaim_input_remove(servconn->inpa); | |
120 servconn->inpa = 0; | |
121 } | |
122 | |
123 close(servconn->fd); | |
124 | |
125 if (servconn->http_data != NULL) | |
126 { | |
127 if (servconn->http_data->session_id != NULL) | |
128 g_free(servconn->http_data->session_id); | |
129 | |
130 if (servconn->http_data->old_gateway_ip != NULL) | |
131 g_free(servconn->http_data->old_gateway_ip); | |
132 | |
133 if (servconn->http_data->gateway_ip != NULL) | |
134 g_free(servconn->http_data->gateway_ip); | |
135 | |
136 if (servconn->http_data->timer) | |
137 gaim_timeout_remove(servconn->http_data->timer); | |
138 | |
139 g_free(servconn->http_data); | |
140 } | |
141 | |
142 servconn->rx_len = 0; | |
143 servconn->payload_len = 0; | |
144 | |
145 if (servconn->disconnect_cb != NULL) | |
146 servconn->disconnect_cb(servconn); | |
147 | |
148 servconn->connected = FALSE; | |
149 } | |
150 | |
151 void | |
152 msn_servconn_destroy(MsnServConn *servconn) | |
153 { | |
154 MsnSession *session; | |
155 | |
156 g_return_if_fail(servconn != NULL); | |
157 | |
158 if (servconn->processing) | |
159 { | |
160 servconn->wasted = TRUE; | |
161 return; | |
162 } | |
163 | |
164 session = servconn->session; | |
165 | |
166 session->servconns = g_list_remove(session->servconns, servconn); | |
167 | |
168 if (servconn->connected) | |
169 msn_servconn_disconnect(servconn); | |
170 | |
171 msn_cmdproc_destroy(servconn->cmdproc); | |
172 g_free(servconn); | |
173 } | |
174 | |
175 void | |
176 msn_servconn_set_connect_cb(MsnServConn *servconn, | |
177 gboolean (*connect_cb)(MsnServConn *servconn)) | |
178 { | |
179 g_return_if_fail(servconn != NULL); | |
180 | |
181 servconn->connect_cb = connect_cb; | |
182 } | |
183 | |
184 void | |
185 msn_servconn_set_disconnect_cb(MsnServConn *servconn, | |
186 void (*disconnect_cb)(MsnServConn | |
187 *servconn)) | |
188 { | |
189 g_return_if_fail(servconn != NULL); | |
190 | |
191 servconn->disconnect_cb = disconnect_cb; | |
192 } | |
193 | |
194 static void | |
195 show_error(MsnServConn *servconn) | 29 show_error(MsnServConn *servconn) |
196 { | 30 { |
197 GaimConnection *gc; | 31 GaimConnection *gc; |
198 char *tmp; | 32 char *tmp; |
199 char *cmd; | 33 char *cmd; |
200 | 34 |
201 const char *names[] = { "Notification", "Switchboard" }; | 35 const char *names[] = { "Notification", "Switchboard" }; |
202 const char *name; | 36 const char *name; |
203 | 37 |
204 gc = gaim_account_get_connection(servconn->session->account); | 38 gc = gaim_account_get_connection(servconn->session->account); |
205 name = names[servconn->type]; | 39 name = names[servconn->type]; |
206 | 40 |
207 switch (servconn->cmdproc->error) | 41 switch (servconn->cmdproc->error) |
208 { | 42 { |
213 case MSN_ERROR_WRITE: | 47 case MSN_ERROR_WRITE: |
214 tmp = g_strdup_printf(_("Error writing to %s server"), name); | 48 tmp = g_strdup_printf(_("Error writing to %s server"), name); |
215 break; | 49 break; |
216 case MSN_ERROR_READ: | 50 case MSN_ERROR_READ: |
217 cmd = servconn->cmdproc->last_trans; | 51 cmd = servconn->cmdproc->last_trans; |
218 tmp = g_strdup_printf(_("Error reading from %s server. Last" | 52 tmp = g_strdup_printf(_("Error reading from %s server"), name); |
219 "command was:\n %s"), name, cmd); | 53 gaim_debug_info("msn", "Last command was: %s\n", cmd); |
220 break; | 54 break; |
221 default: | 55 default: |
222 tmp = g_strdup_printf(_("Unknown error from %s server"), name); | 56 tmp = g_strdup_printf(_("Unknown error from %s server"), name); |
223 break; | 57 break; |
224 } | 58 } |
225 | 59 |
226 if (servconn->type != MSN_SERVER_SB) | 60 gaim_connection_error(gc, tmp); |
227 gaim_connection_error(gc, tmp); | 61 |
62 g_free(tmp); | |
63 } | |
64 | |
65 static void | |
66 connect_cb(gpointer data, gint source, GaimInputCondition cond) | |
67 { | |
68 MsnServConn *servconn = data; | |
69 | |
70 gaim_debug_info("msn", "In servconn's connect_cb\n"); | |
71 | |
72 servconn->fd = source; | |
73 | |
74 if (source > 0) | |
75 { | |
76 /* Someone wants to know we connected. */ | |
77 servconn->connect_cb(servconn); | |
78 servconn->inpa = gaim_input_add(servconn->fd, GAIM_INPUT_READ, | |
79 read_cb, data); | |
80 } | |
228 else | 81 else |
229 gaim_notify_error(gc, NULL, tmp, NULL); | 82 { |
230 | 83 servconn->cmdproc->error = MSN_ERROR_CONNECT; |
231 g_free(tmp); | 84 show_error(servconn); |
85 } | |
86 } | |
87 | |
88 MsnServConn * | |
89 msn_servconn_new(MsnSession *session, MsnServerType type) | |
90 { | |
91 MsnServConn *servconn; | |
92 | |
93 g_return_val_if_fail(session != NULL, NULL); | |
94 | |
95 servconn = g_new0(MsnServConn, 1); | |
96 | |
97 servconn->type = type; | |
98 | |
99 servconn->session = session; | |
100 servconn->cmdproc = msn_cmdproc_new(session); | |
101 servconn->cmdproc->servconn = servconn; | |
102 | |
103 if (session->http_method) | |
104 { | |
105 servconn->http_data = g_new0(MsnHttpMethodData, 1); | |
106 servconn->http_data->virgin = TRUE; | |
107 } | |
108 | |
109 servconn->num = session->servconns_count++; | |
110 session->servconns = g_list_append(session->servconns, servconn); | |
111 | |
112 return servconn; | |
113 } | |
114 | |
115 gboolean | |
116 msn_servconn_connect(MsnServConn *servconn, const char *host, int port) | |
117 { | |
118 MsnSession *session; | |
119 int i; | |
120 | |
121 g_return_val_if_fail(servconn != NULL, FALSE); | |
122 g_return_val_if_fail(host != NULL, FALSE); | |
123 g_return_val_if_fail(port > 0, FALSE); | |
124 | |
125 session = servconn->session; | |
126 | |
127 if (servconn->connected) | |
128 msn_servconn_disconnect(servconn); | |
129 | |
130 if (session->http_method) | |
131 { | |
132 servconn->http_data->gateway_ip = g_strdup(host); | |
133 } | |
134 | |
135 i = gaim_proxy_connect(session->account, host, port, connect_cb, | |
136 servconn); | |
137 | |
138 if (i == 0) | |
139 servconn->connected = TRUE; | |
140 | |
141 return servconn->connected; | |
142 } | |
143 | |
144 void | |
145 msn_servconn_disconnect(MsnServConn *servconn) | |
146 { | |
147 MsnSession *session; | |
148 | |
149 g_return_if_fail(servconn != NULL); | |
150 g_return_if_fail(servconn->connected); | |
151 | |
152 session = servconn->session; | |
153 | |
154 if (servconn->inpa > 0) | |
155 { | |
156 gaim_input_remove(servconn->inpa); | |
157 servconn->inpa = 0; | |
158 } | |
159 | |
160 close(servconn->fd); | |
161 | |
162 if (servconn->http_data != NULL) | |
163 { | |
164 if (servconn->http_data->session_id != NULL) | |
165 g_free(servconn->http_data->session_id); | |
166 | |
167 if (servconn->http_data->old_gateway_ip != NULL) | |
168 g_free(servconn->http_data->old_gateway_ip); | |
169 | |
170 if (servconn->http_data->gateway_ip != NULL) | |
171 g_free(servconn->http_data->gateway_ip); | |
172 | |
173 if (servconn->http_data->timer) | |
174 gaim_timeout_remove(servconn->http_data->timer); | |
175 | |
176 g_free(servconn->http_data); | |
177 } | |
178 | |
179 servconn->rx_len = 0; | |
180 servconn->payload_len = 0; | |
181 | |
182 if (servconn->disconnect_cb != NULL) | |
183 servconn->disconnect_cb(servconn); | |
184 | |
185 servconn->connected = FALSE; | |
186 } | |
187 | |
188 void | |
189 msn_servconn_destroy(MsnServConn *servconn) | |
190 { | |
191 MsnSession *session; | |
192 | |
193 g_return_if_fail(servconn != NULL); | |
194 | |
195 if (servconn->processing) | |
196 { | |
197 servconn->wasted = TRUE; | |
198 return; | |
199 } | |
200 | |
201 session = servconn->session; | |
202 | |
203 session->servconns = g_list_remove(session->servconns, servconn); | |
204 | |
205 if (servconn->connected) | |
206 msn_servconn_disconnect(servconn); | |
207 | |
208 msn_cmdproc_destroy(servconn->cmdproc); | |
209 g_free(servconn); | |
210 } | |
211 | |
212 void | |
213 msn_servconn_set_connect_cb(MsnServConn *servconn, | |
214 gboolean (*connect_cb)(MsnServConn *servconn)) | |
215 { | |
216 g_return_if_fail(servconn != NULL); | |
217 | |
218 servconn->connect_cb = connect_cb; | |
219 } | |
220 | |
221 void | |
222 msn_servconn_set_disconnect_cb(MsnServConn *servconn, | |
223 void (*disconnect_cb)(MsnServConn | |
224 *servconn)) | |
225 { | |
226 g_return_if_fail(servconn != NULL); | |
227 | |
228 servconn->disconnect_cb = disconnect_cb; | |
232 } | 229 } |
233 | 230 |
234 static void | 231 static void |
235 failed_io(MsnServConn *servconn) | 232 failed_io(MsnServConn *servconn) |
236 { | 233 { |