Changes in lib/proxy.c [71abe93:5ebff60]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/proxy.c
r71abe93 r5ebff60 63 63 static int proxy_connect_none(const char *host, unsigned short port_, struct PHB *phb); 64 64 65 static gboolean phb_close(struct PHB *phb) 66 { 67 close(phb->fd); 68 phb->func(phb->data, -1, B_EV_IO_READ); 69 g_free(phb->host); 70 g_free(phb); 71 return FALSE; 72 } 73 74 static gboolean proxy_connected(gpointer data, gint source, b_input_condition cond) 65 static gboolean gaim_io_connected(gpointer data, gint source, b_input_condition cond) 75 66 { 76 67 struct PHB *phb = data; … … 89 80 dup2(new_fd, source); 90 81 closesocket(new_fd); 91 phb->inpa = b_input_add(source, B_EV_IO_WRITE, proxy_connected, phb);82 phb->inpa = b_input_add(source, B_EV_IO_WRITE, gaim_io_connected, phb); 92 83 return FALSE; 93 84 } 94 85 } 86 freeaddrinfo(phb->gai); 95 87 closesocket(source); 96 source = -1; 97 /* socket is dead, but continue to clean up */ 98 } else { 99 sock_make_blocking(source); 100 } 101 88 b_event_remove(phb->inpa); 89 phb->inpa = 0; 90 if (phb->proxy_func) { 91 phb->proxy_func(phb->proxy_data, -1, B_EV_IO_READ); 92 } else { 93 phb->func(phb->data, -1, B_EV_IO_READ); 94 g_free(phb); 95 } 96 return FALSE; 97 } 102 98 freeaddrinfo(phb->gai); 99 sock_make_blocking(source); 103 100 b_event_remove(phb->inpa); 104 101 phb->inpa = 0; … … 163 160 continue; 164 161 } else { 165 phb->inpa = b_input_add(fd, B_EV_IO_WRITE, proxy_connected, phb);162 phb->inpa = b_input_add(fd, B_EV_IO_WRITE, gaim_io_connected, phb); 166 163 phb->fd = fd; 167 164 … … 209 206 } 210 207 211 return phb_close(phb); 208 close(source); 209 phb->func(phb->data, -1, B_EV_IO_READ); 210 g_free(phb->host); 211 g_free(phb); 212 213 return FALSE; 212 214 } 213 215 … … 224 226 len = sizeof(error); 225 227 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 226 return phb_close(phb); 228 close(source); 229 phb->func(phb->data, -1, B_EV_IO_READ); 230 g_free(phb->host); 231 g_free(phb); 232 return FALSE; 227 233 } 228 234 sock_make_blocking(source); … … 231 237 phb->host, phb->port); 232 238 if (send(source, cmd, strlen(cmd), 0) < 0) { 233 return phb_close(phb); 239 close(source); 240 phb->func(phb->data, -1, B_EV_IO_READ); 241 g_free(phb->host); 242 g_free(phb); 243 return FALSE; 234 244 } 235 245 … … 242 252 g_free(t2); 243 253 if (send(source, cmd, strlen(cmd), 0) < 0) { 244 return phb_close(phb); 254 close(source); 255 phb->func(phb->data, -1, B_EV_IO_READ); 256 g_free(phb->host); 257 g_free(phb); 258 return FALSE; 245 259 } 246 260 } … … 248 262 g_snprintf(cmd, sizeof(cmd), "\r\n"); 249 263 if (send(source, cmd, strlen(cmd), 0) < 0) { 250 return phb_close(phb); 264 close(source); 265 phb->func(phb->data, -1, B_EV_IO_READ); 266 g_free(phb->host); 267 g_free(phb); 268 return FALSE; 251 269 } 252 270 … … 284 302 } 285 303 286 return phb_close(phb); 304 close(source); 305 phb->func(phb->data, -1, B_EV_IO_READ); 306 g_free(phb->host); 307 g_free(phb); 308 309 return FALSE; 287 310 } 288 311 … … 300 323 len = sizeof(error); 301 324 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 302 return phb_close(phb); 325 close(source); 326 phb->func(phb->data, -1, B_EV_IO_READ); 327 g_free(phb->host); 328 g_free(phb); 329 return FALSE; 303 330 } 304 331 sock_make_blocking(source); … … 306 333 /* XXX does socks4 not support host name lookups by the proxy? */ 307 334 if (!(hp = gethostbyname(phb->host))) { 308 return phb_close(phb); 335 close(source); 336 phb->func(phb->data, -1, B_EV_IO_READ); 337 g_free(phb->host); 338 g_free(phb); 339 return FALSE; 309 340 } 310 341 … … 319 350 packet[8] = 0; 320 351 if (write(source, packet, 9) != 9) { 321 return phb_close(phb); 352 close(source); 353 phb->func(phb->data, -1, B_EV_IO_READ); 354 g_free(phb->host); 355 g_free(phb); 356 return FALSE; 322 357 } 323 358 … … 348 383 349 384 if (read(source, buf, 10) < 10) { 350 return phb_close(phb); 385 close(source); 386 phb->func(phb->data, -1, B_EV_IO_READ); 387 g_free(phb->host); 388 g_free(phb); 389 return FALSE; 351 390 } 352 391 if ((buf[0] != 0x05) || (buf[1] != 0x00)) { 353 return phb_close(phb); 392 close(source); 393 phb->func(phb->data, -1, B_EV_IO_READ); 394 g_free(phb->host); 395 g_free(phb); 396 return FALSE; 354 397 } 355 398 … … 377 420 378 421 if (write(source, buf, (5 + strlen(phb->host) + 2)) < (5 + strlen(phb->host) + 2)) { 379 phb_close(phb); 422 close(source); 423 phb->func(phb->data, -1, B_EV_IO_READ); 424 g_free(phb->host); 425 g_free(phb); 380 426 return; 381 427 } … … 392 438 393 439 if (read(source, buf, 2) < 2) { 394 return phb_close(phb); 440 close(source); 441 phb->func(phb->data, -1, B_EV_IO_READ); 442 g_free(phb->host); 443 g_free(phb); 444 return FALSE; 395 445 } 396 446 397 447 if ((buf[0] != 0x01) || (buf[1] != 0x00)) { 398 return phb_close(phb); 448 close(source); 449 phb->func(phb->data, -1, B_EV_IO_READ); 450 g_free(phb->host); 451 g_free(phb); 452 return FALSE; 399 453 } 400 454 … … 412 466 413 467 if (read(source, buf, 2) < 2) { 414 return phb_close(phb); 468 close(source); 469 phb->func(phb->data, -1, B_EV_IO_READ); 470 g_free(phb->host); 471 g_free(phb); 472 return FALSE; 415 473 } 416 474 417 475 if ((buf[0] != 0x05) || (buf[1] == 0xff)) { 418 return phb_close(phb); 476 close(source); 477 phb->func(phb->data, -1, B_EV_IO_READ); 478 g_free(phb->host); 479 g_free(phb); 480 return FALSE; 419 481 } 420 482 … … 427 489 memcpy(buf + 2 + i + 1, proxypass, j); 428 490 if (write(source, buf, 3 + i + j) < 3 + i + j) { 429 return phb_close(phb); 491 close(source); 492 phb->func(phb->data, -1, B_EV_IO_READ); 493 g_free(phb->host); 494 g_free(phb); 495 return FALSE; 430 496 } 431 497 … … 451 517 len = sizeof(error); 452 518 if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 453 return phb_close(phb); 519 close(source); 520 phb->func(phb->data, -1, B_EV_IO_READ); 521 g_free(phb->host); 522 g_free(phb); 523 return FALSE; 454 524 } 455 525 sock_make_blocking(source); … … 469 539 470 540 if (write(source, buf, i) < i) { 471 return phb_close(phb); 541 close(source); 542 phb->func(phb->data, -1, B_EV_IO_READ); 543 g_free(phb->host); 544 g_free(phb); 545 return FALSE; 472 546 } 473 547
Note: See TracChangeset
for help on using the changeset viewer.