| | 360 | | | | static int dcc_send_one_file(int queue, const char *target, const char *fname, | | | 361 | | | | IRC_SERVER_REC *server, CHAT_DCC_REC *chat, | | | 362 | | | | int passive) | | | 363 | | | | { | | | 364 | | | | struct stat st; | | | 365 | | | | char *str; | | | 366 | | | | char host[MAX_IP_LEN];
| | | 367 | | | | int hfile, port = 0; | | | 368 | | | | SEND_DCC_REC *dcc; | | | 369 | | | | IPADDR own_ip; | | | 370 | | | | GIOChannel *handle; | | | 371 | | | | | | | 372 | | | | if (dcc_find_request(DCC_SEND_TYPE, target, fname)) {
| | | 373 | | | | signal_emit("dcc error send exists", 2, target, fname); | | | 374 | | | | return FALSE;
| | | 375 | | | | } | | | 376 | | | | | | | 377 | | | | str = dcc_send_get_file(fname); | | | 378 | | | | hfile = open(str, O_RDONLY);
| | | 379 | | | | g_free(str); | | | 380 | | | | | | | 381 | | | | if (hfile == -1) { | | | 382 | | | | signal_emit("dcc error file open", 3, target, fname, | | | 383 | | | | GINT_TO_POINTER(errno));
| | | 384 | | | | return FALSE;
| | | 385 | | | | } | | | 386 | | | | | | | 387 | | | | if (fstat(hfile, &st) < 0) { | | | 388 | | | | g_warning("fstat() failed: %s", strerror(errno));
| | | 389 | | | | close(hfile); | | | 390 | | | | return FALSE;
| | | 391 | | | | } | | | 392 | | | | | | | 393 | | | | | | | 394 | | | | | | | 395 | | | | if (passive == FALSE) {
| | | 396 | | | | handle = dcc_listen(chat != NULL ? chat->handle :
| | | 397 | | | | net_sendbuffer_handle(server->handle), | | | 398 | | | | &own_ip, &port); | | | 399 | | | | if (handle == NULL) {
| | | 400 | | | | close(hfile); | | | 401 | | | | g_warning("dcc_listen() failed: %s", strerror(errno));
| | | 402 | | | | return FALSE;
| | | 403 | | | | } | | | 404 | | | | } else { | | | 405 | | | | handle = NULL;
| | | 406 | | | | } | | | 407 | | | | | | | 408 | | | | fname = g_basename(fname); | | | 409 | | | | | | | 410 | | | | | | | 411 | | | | | | | 412 | | | | if (!settings_get_bool("dcc_send_replace_space_with_underscore")) | | | 413 | | | | str = NULL;
| | | 414 | | | | else { | | | 415 | | | | str = g_strdup(fname); | | | 416 | | | | g_strdelimit(str, " ", '_'); | | | 417 | | | | fname = str; | | | 418 | | | | } | | | 419 | | | | | | | 420 | | | | dcc = dcc_send_create(server, chat, target, fname); | | | 421 | | | | g_free(str); | | | 422 | | | | | | | 423 | | | | dcc->handle = handle; | | | 424 | | | | dcc->port = port; | | | 425 | | | | dcc->size = st.st_size; | | | 426 | | | | dcc->fhandle = hfile; | | | 427 | | | | dcc->queue = queue; | | | 428 | | | | dcc->file_quoted = strchr(fname, ' ') != NULL;
| | | 429 | | | | if (!passive) { | | | 430 | | | | dcc->tagconn = g_input_add(handle, G_INPUT_READ,
| | | 431 | | | | (GInputFunction) dcc_send_connected, | | | 432 | | | | dcc); | | | 433 | | | | } | | | 434 | | | | | | | 435 | | | | | | | 436 | | | | if (passive) { | | | 437 | | | | dcc->pasv_id = rand() % 64; | | | 438 | | | | } | | | 439 | | | | | | | 440 | | | | | | | 441 | | | | signal_emit("dcc request send", 1, dcc); | | | 442 | | | | | | | 443 | | | | | | | 444 | | | | dcc_ip2str(&own_ip, host); | | | 445 | | | | if (passive == FALSE) {
| | | 446 | | | | str = g_strdup_printf(dcc->file_quoted ? | | | 447 | | | | "DCC SEND \"%s\" %s %d %"PRIuUOFF_T :
| | | 448 | | | | "DCC SEND %s %s %d %"PRIuUOFF_T,
| | | 449 | | | | dcc->arg, host, port, dcc->size); | | | 450 | | | | } else { | | | 451 | | | | str = g_strdup_printf(dcc->file_quoted ? | | | 452 | | | | "DCC SEND \"%s\" 16843009 0 %"PRIuUOFF_T" %d" :
| | | 453 | | | | "DCC SEND %s 16843009 0 %"PRIuUOFF_T" %d",
| | | 454 | | | | dcc->arg, dcc->size, dcc->pasv_id); | | | 455 | | | | } |
|