Mercurial > pidgin
comparison src/proxy.c @ 14108:7a205b430d19
[gaim-migrate @ 16742]
Removing the "error_cb" parameter for gaim_proxy_connect(), changing it
back to how it was. As I started making changes to oscar to support
canceling connection attempts, I realized that having a separate callback
for errors would result in more code duplication than was needed.
Originally I thought the separate callback would make things cleaner.
Anyway, sorry for the noise.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Mon, 14 Aug 2006 04:43:38 +0000 |
| parents | eec0c7fd8529 |
| children | c3167a1dd817 |
comparison
equal
deleted
inserted
replaced
| 14107:c0ee28af3ca2 | 14108:7a205b430d19 |
|---|---|
| 38 #include "proxy.h" | 38 #include "proxy.h" |
| 39 #include "util.h" | 39 #include "util.h" |
| 40 | 40 |
| 41 struct _GaimProxyConnectInfo { | 41 struct _GaimProxyConnectInfo { |
| 42 GaimProxyConnectFunction connect_cb; | 42 GaimProxyConnectFunction connect_cb; |
| 43 GaimProxyErrorFunction error_cb; | |
| 44 gpointer data; | 43 gpointer data; |
| 45 char *host; | 44 char *host; |
| 46 int port; | 45 int port; |
| 47 int fd; | 46 int fd; |
| 48 guint inpa; | 47 guint inpa; |
| 322 } | 321 } |
| 323 | 322 |
| 324 static void | 323 static void |
| 325 gaim_proxy_connect_info_connected(GaimProxyConnectInfo *connect_info) | 324 gaim_proxy_connect_info_connected(GaimProxyConnectInfo *connect_info) |
| 326 { | 325 { |
| 327 connect_info->connect_cb(connect_info->data, connect_info->fd); | 326 connect_info->connect_cb(connect_info->data, connect_info->fd, NULL); |
| 328 | 327 |
| 329 /* | 328 /* |
| 330 * We've passed the file descriptor to the protocol, so it's no longer | 329 * We've passed the file descriptor to the protocol, so it's no longer |
| 331 * our responsibility, and we should be careful not to free it when | 330 * our responsibility, and we should be careful not to free it when |
| 332 * we destroy the connect_info. | 331 * we destroy the connect_info. |
| 346 * good error_message. | 345 * good error_message. |
| 347 */ | 346 */ |
| 348 static void | 347 static void |
| 349 gaim_proxy_connect_info_error(GaimProxyConnectInfo *connect_info, const gchar *error_message) | 348 gaim_proxy_connect_info_error(GaimProxyConnectInfo *connect_info, const gchar *error_message) |
| 350 { | 349 { |
| 351 if (connect_info->error_cb == NULL) | 350 connect_info->connect_cb(connect_info->data, -1, error_message); |
| 352 { | |
| 353 /* | |
| 354 * TODO | |
| 355 * While we're transitioning to the new gaim_proxy_connect() | |
| 356 * code, not all callers supply an error_cb. If this is the | |
| 357 * case then they're expecting connect_cb to be called with | |
| 358 * an fd of -1 in the case of an error. Once all callers have | |
| 359 * been changed this whole if statement should be removed. | |
| 360 */ | |
| 361 connect_info->connect_cb(connect_info->data, -1); | |
| 362 gaim_proxy_connect_info_destroy(connect_info); | |
| 363 return; | |
| 364 } | |
| 365 | |
| 366 connect_info->error_cb(connect_info->data, error_message); | |
| 367 gaim_proxy_connect_info_destroy(connect_info); | 351 gaim_proxy_connect_info_destroy(connect_info); |
| 368 } | 352 } |
| 369 | 353 |
| 370 #if defined(__unix__) || defined(__APPLE__) | 354 #if defined(__unix__) || defined(__APPLE__) |
| 371 | 355 |
| 2337 return gpi; | 2321 return gpi; |
| 2338 } | 2322 } |
| 2339 | 2323 |
| 2340 GaimProxyConnectInfo * | 2324 GaimProxyConnectInfo * |
| 2341 gaim_proxy_connect(GaimAccount *account, const char *host, int port, | 2325 gaim_proxy_connect(GaimAccount *account, const char *host, int port, |
| 2342 GaimProxyConnectFunction connect_cb, | 2326 GaimProxyConnectFunction connect_cb, gpointer data) |
| 2343 GaimProxyErrorFunction error_cb, gpointer data) | |
| 2344 { | 2327 { |
| 2345 const char *connecthost = host; | 2328 const char *connecthost = host; |
| 2346 int connectport = port; | 2329 int connectport = port; |
| 2347 GaimProxyConnectInfo *connect_info; | 2330 GaimProxyConnectInfo *connect_info; |
| 2348 | 2331 |
| 2349 g_return_val_if_fail(host != NULL, NULL); | 2332 g_return_val_if_fail(host != NULL, NULL); |
| 2350 g_return_val_if_fail(port > 0, NULL); | 2333 g_return_val_if_fail(port > 0, NULL); |
| 2351 g_return_val_if_fail(connect_cb != NULL, NULL); | 2334 g_return_val_if_fail(connect_cb != NULL, NULL); |
| 2352 /* g_return_val_if_fail(error_cb != NULL, NULL); *//* TODO: Soon! */ | |
| 2353 | 2335 |
| 2354 connect_info = g_new0(GaimProxyConnectInfo, 1); | 2336 connect_info = g_new0(GaimProxyConnectInfo, 1); |
| 2355 connect_info->fd = -1; | 2337 connect_info->fd = -1; |
| 2356 connect_info->connect_cb = connect_cb; | 2338 connect_info->connect_cb = connect_cb; |
| 2357 connect_info->error_cb = error_cb; | |
| 2358 connect_info->data = data; | 2339 connect_info->data = data; |
| 2359 connect_info->host = g_strdup(host); | 2340 connect_info->host = g_strdup(host); |
| 2360 connect_info->port = port; | 2341 connect_info->port = port; |
| 2361 connect_info->gpi = gaim_proxy_get_setup(account); | 2342 connect_info->gpi = gaim_proxy_get_setup(account); |
| 2362 | 2343 |
| 2402 /* | 2383 /* |
| 2403 * Combine some of this code with gaim_proxy_connect() | 2384 * Combine some of this code with gaim_proxy_connect() |
| 2404 */ | 2385 */ |
| 2405 GaimProxyConnectInfo * | 2386 GaimProxyConnectInfo * |
| 2406 gaim_proxy_connect_socks5(GaimProxyInfo *gpi, const char *host, int port, | 2387 gaim_proxy_connect_socks5(GaimProxyInfo *gpi, const char *host, int port, |
| 2407 GaimProxyConnectFunction connect_cb, | 2388 GaimProxyConnectFunction connect_cb, gpointer data) |
| 2408 GaimProxyErrorFunction error_cb, gpointer data) | |
| 2409 { | 2389 { |
| 2410 GaimProxyConnectInfo *connect_info; | 2390 GaimProxyConnectInfo *connect_info; |
| 2411 | 2391 |
| 2412 g_return_val_if_fail(host != NULL, NULL); | 2392 g_return_val_if_fail(host != NULL, NULL); |
| 2413 g_return_val_if_fail(port > 0, NULL); | 2393 g_return_val_if_fail(port > 0, NULL); |
| 2414 g_return_val_if_fail(connect_cb != NULL, NULL); | 2394 g_return_val_if_fail(connect_cb != NULL, NULL); |
| 2415 /* g_return_val_if_fail(error_cb != NULL, NULL); *//* TODO: Soon! */ | |
| 2416 | 2395 |
| 2417 connect_info = g_new0(GaimProxyConnectInfo, 1); | 2396 connect_info = g_new0(GaimProxyConnectInfo, 1); |
| 2418 connect_info->fd = -1; | 2397 connect_info->fd = -1; |
| 2419 connect_info->connect_cb = connect_cb; | 2398 connect_info->connect_cb = connect_cb; |
| 2420 connect_info->error_cb = error_cb; | |
| 2421 connect_info->data = data; | 2399 connect_info->data = data; |
| 2422 connect_info->host = g_strdup(host); | 2400 connect_info->host = g_strdup(host); |
| 2423 connect_info->port = port; | 2401 connect_info->port = port; |
| 2424 connect_info->gpi = gpi; | 2402 connect_info->gpi = gpi; |
| 2425 | 2403 |
