static void purple_xfer_show_file_error(PurpleXfer *xfer, const char *filename) { int err = errno; gchar *msg = NULL, *utf8; PurpleXferType xfer_type = purple_xfer_get_type(xfer); PurpleAccount *account = purple_xfer_get_account(xfer); utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); switch(xfer_type) { case PURPLE_XFER_SEND: msg = g_strdup_printf(_("Error reading %s: \n%s.\n"), utf8, g_strerror(err)); break; case PURPLE_XFER_RECEIVE: msg = g_strdup_printf(_("Error writing %s: \n%s.\n"), utf8, g_strerror(err)); break; default: msg = g_strdup_printf(_("Error accessing %s: \n%s.\n"), utf8, g_strerror(err)); break; } g_free(utf8); purple_xfer_conversation_write(xfer, msg, TRUE); purple_xfer_error(xfer_type, account, xfer->who, msg); g_free(msg); }
void purple_xfer_cancel_local(PurpleXfer *xfer) { PurpleXferUiOps *ui_ops; char *msg = NULL; g_return_if_fail(xfer != NULL); purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_LOCAL); xfer->end_time = time(NULL); if (purple_xfer_get_filename(xfer) != NULL) { msg = g_strdup_printf(_("You cancelled the transfer of %s"), purple_xfer_get_filename(xfer)); } else { msg = g_strdup(_("File transfer cancelled")); } purple_xfer_conversation_write(xfer, msg, FALSE); g_free(msg); if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) { if (xfer->ops.cancel_send != NULL) xfer->ops.cancel_send(xfer); } else { if (xfer->ops.cancel_recv != NULL) xfer->ops.cancel_recv(xfer); } if (xfer->watcher != 0) { purple_input_remove(xfer->watcher); xfer->watcher = 0; } if (xfer->fd != -1) close(xfer->fd); if (xfer->dest_fp != NULL) { fclose(xfer->dest_fp); xfer->dest_fp = NULL; } ui_ops = purple_xfer_get_ui_ops(xfer); if (ui_ops != NULL && ui_ops->cancel_local != NULL) ui_ops->cancel_local(xfer); xfer->bytes_remaining = 0; purple_xfer_unref(xfer); }
static void ggp_edisc_xfer_error(PurpleXfer *xfer, const gchar *msg) { if (purple_xfer_is_cancelled(xfer)) g_return_if_reached(); purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_REMOTE); purple_xfer_conversation_write(xfer, msg, TRUE); purple_xfer_error( purple_xfer_get_xfer_type(xfer), purple_xfer_get_account(xfer), purple_xfer_get_remote_user(xfer), msg); ggp_edisc_xfer_free(xfer); purple_xfer_end(xfer); }
void purple_xfer_request(PurpleXfer *xfer) { g_return_if_fail(xfer != NULL); g_return_if_fail(xfer->ops.init != NULL); purple_xfer_ref(xfer); if (purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) { purple_signal_emit(purple_xfers_get_handle(), "file-recv-request", xfer); if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL) { /* The file-transfer was cancelled by a plugin */ purple_xfer_cancel_local(xfer); } else if (purple_xfer_get_filename(xfer) || purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_ACCEPTED) { gchar* message = NULL; PurpleBuddy *buddy = purple_find_buddy(xfer->account, xfer->who); message = g_strdup_printf(_("%s is offering to send file %s"), buddy ? purple_buddy_get_alias(buddy) : xfer->who, purple_xfer_get_filename(xfer)); purple_xfer_conversation_write(xfer, message, FALSE); g_free(message); /* Ask for a filename to save to if it's not already given by a plugin */ if (xfer->local_filename == NULL) purple_xfer_ask_recv(xfer); } else { purple_xfer_ask_accept(xfer); } } else { purple_xfer_choose_file(xfer); } }
void purple_xfer_request_accepted(PurpleXfer *xfer, const char *filename) { PurpleXferType type; struct stat st; char *msg, *utf8, *base; PurpleAccount *account; PurpleBuddy *buddy; if (xfer == NULL) return; type = purple_xfer_get_type(xfer); account = purple_xfer_get_account(xfer); purple_debug_misc("xfer", "request accepted for %p\n", xfer); if (!filename && type == PURPLE_XFER_RECEIVE) { xfer->status = PURPLE_XFER_STATUS_ACCEPTED; xfer->ops.init(xfer); return; } buddy = purple_find_buddy(account, xfer->who); if (type == PURPLE_XFER_SEND) { /* Sending a file */ /* Check the filename. */ PurpleXferUiOps *ui_ops; ui_ops = purple_xfer_get_ui_ops(xfer); #ifdef _WIN32 if (g_strrstr(filename, "../") || g_strrstr(filename, "..\\")) #else if (g_strrstr(filename, "../")) #endif { utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); msg = g_strdup_printf(_("%s is not a valid filename.\n"), utf8); purple_xfer_error(type, account, xfer->who, msg); g_free(utf8); g_free(msg); purple_xfer_unref(xfer); return; } if (ui_ops == NULL || (ui_ops->ui_read == NULL && ui_ops->ui_write == NULL)) { if (g_stat(filename, &st) == -1) { purple_xfer_show_file_error(xfer, filename); purple_xfer_unref(xfer); return; } purple_xfer_set_local_filename(xfer, filename); purple_xfer_set_size(xfer, st.st_size); } else { utf8 = g_strdup(filename); purple_xfer_set_local_filename(xfer, filename); } base = g_path_get_basename(filename); utf8 = g_filename_to_utf8(base, -1, NULL, NULL, NULL); g_free(base); purple_xfer_set_filename(xfer, utf8); msg = g_strdup_printf(_("Offering to send %s to %s"), utf8, buddy ? purple_buddy_get_alias(buddy) : xfer->who); g_free(utf8); purple_xfer_conversation_write(xfer, msg, FALSE); g_free(msg); } else { /* Receiving a file */ xfer->status = PURPLE_XFER_STATUS_ACCEPTED; purple_xfer_set_local_filename(xfer, filename); msg = g_strdup_printf(_("Starting transfer of %s from %s"), xfer->filename, buddy ? purple_buddy_get_alias(buddy) : xfer->who); purple_xfer_conversation_write(xfer, msg, FALSE); g_free(msg); } purple_xfer_add(xfer); xfer->ops.init(xfer); }
void purple_xfer_cancel_remote(PurpleXfer *xfer) { PurpleXferUiOps *ui_ops; gchar *msg; PurpleAccount *account; PurpleBuddy *buddy; g_return_if_fail(xfer != NULL); purple_request_close_with_handle(xfer); purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_REMOTE); xfer->end_time = time(NULL); account = purple_xfer_get_account(xfer); buddy = purple_find_buddy(account, xfer->who); if (purple_xfer_get_filename(xfer) != NULL) { msg = g_strdup_printf(_("%s cancelled the transfer of %s"), buddy ? purple_buddy_get_alias(buddy) : xfer->who, purple_xfer_get_filename(xfer)); } else { msg = g_strdup_printf(_("%s cancelled the file transfer"), buddy ? purple_buddy_get_alias(buddy) : xfer->who); } purple_xfer_conversation_write(xfer, msg, TRUE); purple_xfer_error(purple_xfer_get_type(xfer), account, xfer->who, msg); g_free(msg); if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) { if (xfer->ops.cancel_send != NULL) xfer->ops.cancel_send(xfer); } else { if (xfer->ops.cancel_recv != NULL) xfer->ops.cancel_recv(xfer); } if (xfer->watcher != 0) { purple_input_remove(xfer->watcher); xfer->watcher = 0; } if (xfer->fd != -1) close(xfer->fd); if (xfer->dest_fp != NULL) { fclose(xfer->dest_fp); xfer->dest_fp = NULL; } ui_ops = purple_xfer_get_ui_ops(xfer); if (ui_ops != NULL && ui_ops->cancel_remote != NULL) ui_ops->cancel_remote(xfer); xfer->bytes_remaining = 0; purple_xfer_unref(xfer); }
void yahoo_process_filetrans_15(PurpleConnection *gc, struct yahoo_packet *pkt) { char *from = NULL; char *imv = NULL; long val_222 = 0L; PurpleXfer *xfer; YahooData *yd; struct yahoo_xfer_data *xfer_data; char *service = NULL; char *filename = NULL; char *xfer_peer_idstring = NULL; char *utf8_filename; GSList *l; GSList *filename_list = NULL; GSList *size_list = NULL; int nooffiles = 0; yd = purple_connection_get_protocol_data(gc); for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 4: if (g_utf8_validate(pair->value, -1, NULL)) { from = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 5: /* to */ break; case 265: if (g_utf8_validate(pair->value, -1, NULL)) { xfer_peer_idstring = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 27: filename_list = g_slist_prepend(filename_list, g_strdup(pair->value)); nooffiles++; break; case 28: if (g_utf8_validate(pair->value, -1, NULL)) { size_list = g_slist_prepend(size_list, g_strdup(pair->value)); } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 222: val_222 = atol(pair->value); /* 1=send, 2=cancel, 3=accept, 4=reject */ break; /* check for p2p and imviron .... not sure it comes by this service packet. Since it was bundled with filexfer in old ymsg version, still keeping it. */ case 49: if (g_utf8_validate(pair->value, -1, NULL)) { service = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 63: if (g_utf8_validate(pair->value, -1, NULL)) { imv = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; /* end check */ } } if(!xfer_peer_idstring) return; if(val_222 == 2 || val_222 == 4) { xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map, xfer_peer_idstring); if(!xfer) return; purple_xfer_cancel_remote(xfer); return; } if(val_222 == 3) { PurpleAccount *account; struct yahoo_xfer_data *xd; xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map, xfer_peer_idstring); if(!xfer) return; xd = purple_xfer_get_protocol_data(xfer); /* * In the file trans info packet that we must reply with, we are * supposed to mention the ip address... * purple connect does not give me a way of finding the ip address... * so, purple dnsquery is used... but retries, trying with next ip * address etc. is not implemented..TODO */ /* To send through p2p */ if( g_hash_table_lookup(yd->peers, from) ) { /* send p2p file transfer information */ purple_debug_error("yahoo", "p2p file transfers are not supported yet\n"); /*xd->is_relay = FALSE;*/ } xd->is_relay = TRUE; account = purple_connection_get_account(gc); if (yd->jp) { purple_dnsquery_a(account, YAHOOJP_XFER_RELAY_HOST, YAHOOJP_XFER_RELAY_PORT, yahoo_xfer_dns_connected_15, xfer); } else { purple_dnsquery_a(account, YAHOO_XFER_RELAY_HOST, YAHOO_XFER_RELAY_PORT, yahoo_xfer_dns_connected_15, xfer); } return; } /* processing for p2p and imviron .... not sure it comes by this service packet. Since it was bundled with filexfer in old ymsg version, still keeping it. */ /* * The remote user has changed their IMVironment. We * record it for later use. */ if (from && imv && service && (strcmp("IMVIRONMENT", service) == 0)) { g_hash_table_replace(yd->imvironments, g_strdup(from), g_strdup(imv)); return; } if (pkt->service == YAHOO_SERVICE_P2PFILEXFER) { if (service && (strcmp("FILEXFER", service) != 0)) { purple_debug_misc("yahoo", "unhandled service 0x%02x\n", pkt->service); return; } } /* end processing */ if(!filename_list) return; /* have to change list into order in which client at other end sends */ filename_list = g_slist_reverse(filename_list); size_list = g_slist_reverse(size_list); filename = filename_list->data; if(!from) return; xfer_data = g_new0(struct yahoo_xfer_data, 1); xfer_data->firstoflist = TRUE; xfer_data->gc = gc; xfer_data->xfer_peer_idstring = g_strdup(xfer_peer_idstring); xfer_data->filename_list = filename_list; xfer_data->size_list = size_list; /* Build the file transfer handle. */ xfer = yahoo_ft_new_xfer_struct(gc, PURPLE_XFER_TYPE_RECEIVE, from); /* Set the info about the incoming file. */ utf8_filename = yahoo_string_decode(gc, filename, TRUE); purple_xfer_set_filename(xfer, utf8_filename); g_free(utf8_filename); purple_xfer_set_protocol_data(xfer, xfer_data); g_hash_table_insert(yd->xfer_peer_idstring_map, xfer_data->xfer_peer_idstring, xfer); if(nooffiles > 1) { gchar* message; message = g_strdup_printf(_("%s is trying to send you a group of %d files.\n"), purple_xfer_get_remote_user(xfer), nooffiles); purple_xfer_conversation_write(xfer, message, FALSE); g_free(message); } /* Now perform the request */ purple_xfer_request(xfer); }
void finch_xfer_dialog_update_xfer(PurpleXfer *xfer) { PurpleGntXferUiData *data; char *size_str, *remaining_str; time_t current_time; char prog_str[5]; double kb_sent; double kbps = 0.0; time_t elapsed, now; char *kbsec; gboolean send; if ((now = purple_xfer_get_end_time(xfer)) == 0) now = time(NULL); kb_sent = purple_xfer_get_bytes_sent(xfer) / 1024.0; elapsed = (purple_xfer_get_start_time(xfer) > 0 ? now - purple_xfer_get_start_time(xfer) : 0); kbps = (elapsed > 0 ? (kb_sent / elapsed) : 0); g_return_if_fail(xfer_dialog != NULL); g_return_if_fail(xfer != NULL); if ((data = FINCHXFER(xfer)) == NULL) return; if (data->in_list == FALSE || data->notified) return; current_time = time(NULL); if (((current_time - data->last_updated_time) == 0) && (!purple_xfer_is_completed(xfer))) { /* Don't update the window more than once per second */ return; } data->last_updated_time = current_time; send = (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND); size_str = purple_str_size_to_units(purple_xfer_get_size(xfer)); remaining_str = purple_str_size_to_units(purple_xfer_get_bytes_remaining(xfer)); kbsec = g_strdup_printf(_("%.2f KiB/s"), kbps); gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_PROGRESS, g_ascii_dtostr(prog_str, sizeof(prog_str), purple_xfer_get_progress(xfer) * 100.)); gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_SIZE, size_str); gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_REMAINING, remaining_str); gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_SPEED, kbsec); g_free(size_str); g_free(remaining_str); g_free(kbsec); if (purple_xfer_is_completed(xfer)) { gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_STATUS, send ? _("Sent") : _("Received")); gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_REMAINING, _("Finished")); if (!send) { char *msg = g_strdup_printf(_("The file was saved as %s."), purple_xfer_get_local_filename(xfer)); purple_xfer_conversation_write(xfer, msg, FALSE); g_free(msg); } data->notified = TRUE; } else { gnt_tree_change_text(GNT_TREE(xfer_dialog->tree), xfer, COLUMN_STATUS, send ? _("Sending") : _("Receiving")); } update_title_progress(); if (purple_xfer_is_completed(xfer) && xfer_dialog->auto_clear) finch_xfer_dialog_remove_xfer(xfer); }