Ejemplo n.º 1
0
/*------------------------------------------------------------------------
 * Initialise a new file transfer.
 *
 *  @param xfer			The file transfer object
 */
static void mxit_xfer_init( PurpleXfer* xfer )
{
	struct mxitxfer*	mx	= (struct mxitxfer*) xfer->data;

	purple_debug_info( MXIT_PLUGIN_ID, "mxit_xfer_init\n" );

	if ( purple_xfer_get_type( xfer ) == PURPLE_XFER_SEND ) {
		/* we are trying to send a file to MXit */

		if ( purple_xfer_get_size( xfer ) > CP_MAX_FILESIZE ) {
			/* the file is too big */
			purple_xfer_error( xfer->type, xfer->account, xfer->who, _( "The file you are trying to send is too large!" ) );
			purple_xfer_cancel_local( xfer );
			return;
		}

		/* start the file transfer */
		purple_xfer_start( xfer, -1, NULL, 0 );
	}
	else {
		/*
		 * we have just accepted a file transfer request from MXit.  send a confirmation
		 * to the MXit server so that can send us the file
		 */
		mxit_send_file_accept( mx->session, mx->fileid, purple_xfer_get_size( xfer ), 0 );
	}
}
Ejemplo n.º 2
0
static gssize yahoo_xfer_write(const guchar *buffer, size_t size, PurpleXfer *xfer)
{
	gssize len;
	struct yahoo_xfer_data *xd = xfer->data;

	if (!xd)
		return -1;

	if (purple_xfer_get_type(xfer) != PURPLE_XFER_SEND) {
		return -1;
	}

	len = write(xfer->fd, buffer, size);

	if (len == -1) {
		if (purple_xfer_get_bytes_sent(xfer) >= purple_xfer_get_size(xfer))
			purple_xfer_set_completed(xfer, TRUE);
		if ((errno != EAGAIN) && (errno != EINTR))
			return -1;
		return 0;
	}

	if ((purple_xfer_get_bytes_sent(xfer) + len) >= purple_xfer_get_size(xfer))
		purple_xfer_set_completed(xfer, TRUE);

	return len;
}
Ejemplo n.º 3
0
std::string FiletransferRepeater::requestFT() {
// 	purple_xfer_request_accepted(xfer, std::string(filename).c_str());
	std::string filename(purple_xfer_get_filename(m_xfer));
	m_sid = m_main->ft->requestFT(m_to, filename, purple_xfer_get_size(m_xfer), EmptyString, EmptyString, EmptyString, EmptyString, SIProfileFT::FTTypeAll, m_from);
	m_main->ftManager->m_info[m_sid].filename = filename;
	m_main->ftManager->m_info[m_sid].size = purple_xfer_get_size(m_xfer);
	m_main->ftManager->m_info[m_sid].straight = true;
	return m_sid;
}
Ejemplo n.º 4
0
static void _qq_update_send_progess(PurpleConnection *gc, guint32 fragment_index)
{
	guint32 mask;
	guint8 *buffer;
	gint readbytes;
	qq_data *qd = (qq_data *) gc->proto_data;
	PurpleXfer *xfer = qd->xfer;
	ft_info *info = (ft_info *) xfer->data;

	purple_debug_info("QQ",
			"receiving %dth fragment ack, slide window status %o, max_fragment_index %d\n",
			fragment_index, info->window, info->max_fragment_index);
	if (fragment_index < info->max_fragment_index ||
			fragment_index >= info->max_fragment_index + sizeof(info->window)) {
		purple_debug_info("QQ", "duplicate %dth fragment, drop it!\n", fragment_index+1);
		return;
	}
	mask = 0x1 << (fragment_index % sizeof(info->window));
	if ((info->window & mask) == 0)
	{
		info->window |= mask;
		if (fragment_index + 1 != info->fragment_num) {
			xfer->bytes_sent += info->fragment_len;
		} else {
			xfer->bytes_sent += purple_xfer_get_size(xfer) % info->fragment_len;
		}
		xfer->bytes_remaining = purple_xfer_get_size(xfer) - purple_xfer_get_bytes_sent(xfer);
		purple_xfer_update_progress(xfer);
		if (purple_xfer_get_bytes_remaining(xfer) <= 0) {
			/* We have finished sending the file */
			purple_xfer_set_completed(xfer, TRUE);
			return;
		}
		mask = 0x1 << (info->max_fragment_index % sizeof(info->window));
		while (info->window & mask)
		{
			/* move the slide window */
			info->window &= ~mask;

			buffer = g_newa(guint8, info->fragment_len);
			readbytes = _qq_xfer_read_file(buffer, info->max_fragment_index + sizeof(info->window),
					info->fragment_len, xfer);
			if (readbytes > 0)
				_qq_send_file_data_packet(gc, QQ_FILE_CMD_FILE_OP, QQ_FILE_DATA_INFO,
						info->max_fragment_index + sizeof(info->window) + 1, 0, buffer, readbytes);

			info->max_fragment_index ++;
			if (mask & 0x8000) mask = 0x0001;
			else mask = mask << 1;
		}
	}
	purple_debug_info("QQ",
			"procceed %dth fragment ack, slide window status %o, max_fragment_index %d\n",
			fragment_index, info->window, info->max_fragment_index);
}
Ejemplo n.º 5
0
double
purple_xfer_get_progress(const PurpleXfer *xfer)
{
	g_return_val_if_fail(xfer != NULL, 0.0);

	if (purple_xfer_get_size(xfer) == 0)
		return 0.0;

	return ((double)purple_xfer_get_bytes_sent(xfer) /
			(double)purple_xfer_get_size(xfer));
}
Ejemplo n.º 6
0
static void yahoo_xfer_start(PurpleXfer *xfer)
{
	PurpleHttpRequest *req;
	struct yahoo_xfer_data *xd;

	xd = purple_xfer_get_protocol_data(xfer);

	req = yahoo_ft_new_req(xd);
	purple_http_request_set_timeout(req, -1);
	if (purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_RECEIVE) {
		purple_http_request_set_max_len(req, -1);
		purple_http_request_set_response_writer(req,
			yahoo_process_filetrans_15_writer, xfer);
		xd->hc = purple_http_request(xd->gc, req,
			yahoo_process_filetrans_15_downloaded, xfer);
	} else {
		purple_http_request_set_method(req, "POST");
		/* YHttpServer quirk: it sets content-length, but doesn't sends
		 * any data. */
		purple_http_request_set_max_len(req, 0);
		purple_http_request_set_contents_reader(req,
			yahoo_process_filetrans_15_reader,
			purple_xfer_get_size(xfer), xfer);
		xd->hc = purple_http_request(xd->gc, req,
			yahoo_process_filetrans_15_sent, xfer);
	}

	purple_http_conn_set_progress_watcher(xd->hc,
		yahoo_process_filetrans_15_watcher, xfer, -1);
	purple_http_request_unref(req);
}
Ejemplo n.º 7
0
static void
skypeweb_xfer_send_connect_cb(gpointer user_data, PurpleSslConnection *ssl_connection, PurpleInputCondition cond)
{
	SkypeWebFileTransfer *swft = user_data;
	SkypeWebAccount *sa = swft->sa;
	PurpleXfer *xfer = swft->xfer;
	gchar *headers;
	
	headers = g_strdup_printf("PUT /v1/objects/%s/content/original HTTP/1.0\r\n"
			"Connection: close\r\n"
			"Authorization: skype_token %s\r\n" //slightly different to normal!
			"Host: " SKYPEWEB_XFER_HOST "\r\n"
			"Content-Length: %d\r\n"
			"Content-Type: application/json\r\n"
			"\r\n\r\n",
			purple_url_encode(swft->id),
			sa->skype_token, 
			purple_xfer_get_size(xfer));
	
	purple_ssl_write(ssl_connection, headers, strlen(headers));
	
	swft->conn = ssl_connection;
	purple_xfer_ref(xfer);
	purple_xfer_start(xfer, ssl_connection->fd, NULL, 0);
	
	//TODO add input watcher that calls this repeatedly
	purple_xfer_prpl_ready(xfer);
	//purple_ssl_input_add(
			
	g_free(headers);
}
Ejemplo n.º 8
0
static void ggp_edisc_xfer_send_reader(PurpleHttpConnection *hc,
	gchar *buffer, size_t offset, size_t length, gpointer _xfer,
	PurpleHttpContentReaderCb cb)
{
	PurpleXfer *xfer = _xfer;
	ggp_edisc_xfer *edisc_xfer;
	int stored;
	gboolean success, eof = FALSE;

	g_return_if_fail(xfer != NULL);
	edisc_xfer = purple_xfer_get_protocol_data(xfer);
	g_return_if_fail(edisc_xfer != NULL);

	if (edisc_xfer->already_read != offset) {
		purple_debug_error("gg", "ggp_edisc_xfer_send_reader: "
			"Invalid offset (%" G_GSIZE_FORMAT " != %" G_GSIZE_FORMAT ")\n",
			edisc_xfer->already_read, offset);
		ggp_edisc_xfer_error(xfer, _("Error while reading a file"));
		return;
	}

	stored = purple_xfer_read_file(xfer, (guchar *)buffer, length);

	if (stored < 0)
		success = FALSE;
	else {
		success = TRUE;
		edisc_xfer->already_read += stored;
		eof = ((goffset)edisc_xfer->already_read >= purple_xfer_get_size(xfer));
	}

	cb(hc, success, eof, stored);
}
Ejemplo n.º 9
0
static void
send_file_cb(MsnSlpCall *slpcall)
{
	MsnSlpMessage *slpmsg;
	PurpleXfer *xfer;

	xfer = (PurpleXfer *)slpcall->xfer;
	if (purple_xfer_get_status(xfer) >= PURPLE_XFER_STATUS_STARTED)
		return;

	purple_xfer_ref(xfer);
	purple_xfer_start(xfer, -1, NULL, 0);
	if (purple_xfer_get_status(xfer) != PURPLE_XFER_STATUS_STARTED) {
		purple_xfer_unref(xfer);
		return;
	}
	purple_xfer_unref(xfer);

	slpmsg = msn_slpmsg_new(slpcall->slplink);
	slpmsg->slpcall = slpcall;
	slpmsg->flags = 0x1000030;
	slpmsg->info = "SLP FILE";
	slpmsg->size = purple_xfer_get_size(xfer);

	msn_slplink_send_slpmsg(slpcall->slplink, slpmsg);
}
Ejemplo n.º 10
0
static void tgprpl_xfer_send_on_finished (struct tgl_state *TLS, void *_data, int success, struct tgl_message *M) {
  debug ("tgprpl_xfer_on_finished()");
  struct tgp_xfer_send_data *data = _data;

  if (success) {
    if (! purple_xfer_is_canceled (data->xfer)) {
      debug ("purple_xfer_set_completed");
      purple_xfer_set_bytes_sent (data->xfer, purple_xfer_get_size (data->xfer));
      purple_xfer_set_completed (data->xfer, TRUE);
      purple_xfer_end (data->xfer);
    }
    write_secret_chat_file (TLS);
  } else {
    tgp_notify_on_error_gw (TLS, NULL, success);
    if (! purple_xfer_is_canceled (data->xfer)) {
      purple_xfer_cancel_remote (data->xfer);
    }
    failure ("send xfer failed");
  }

  data->loading = FALSE;

  data->xfer->data = NULL;
  purple_xfer_unref (data->xfer);
  tgprpl_xfer_free_data (data);
}
Ejemplo n.º 11
0
static void tgprpl_xfer_recv_on_finished (struct tgl_state *TLS, void *_data, int success, const char *filename) {
  debug ("tgprpl_xfer_recv_on_finished()");
  struct tgp_xfer_send_data *data = _data;
  char *selected = g_strdup (purple_xfer_get_local_filename (data->xfer));

  if (success) {
    debug ("purple_xfer_set_completed");

    // always completed the file transfer to avoid a warning dialogue when closing (Adium)
    purple_xfer_set_bytes_sent (data->xfer, purple_xfer_get_size (data->xfer));
    purple_xfer_set_completed (data->xfer, TRUE);

    if (! purple_xfer_is_canceled (data->xfer)) {
      purple_xfer_end (data->xfer);
    }
  } else {
    tgp_notify_on_error_gw (TLS, NULL, success);
    if (! purple_xfer_is_canceled (data->xfer)) {
      purple_xfer_cancel_remote (data->xfer);
    }
    failure ("recv xfer failed");
  }

  data->loading = FALSE;

  data->xfer->data = NULL;
  purple_xfer_unref (data->xfer);
  tgprpl_xfer_free_data (data);

  debug ("moving transferred file from tgl directory %s to selected target %s", selected, filename);
  g_unlink (selected);
  g_rename (filename, selected);
  g_free (selected);
}
Ejemplo n.º 12
0
static void
ft_outgoing_init(PurpleXfer *xfer)
{
	sipe_core_ft_outgoing_init(PURPLE_XFER_TO_SIPE_FILE_TRANSFER,
				   purple_xfer_get_filename(xfer),
				   purple_xfer_get_size(xfer),
				   xfer->who);
}
Ejemplo n.º 13
0
void
purple_xfer_set_bytes_sent(PurpleXfer *xfer, size_t bytes_sent)
{
	g_return_if_fail(xfer != NULL);

	xfer->bytes_sent = bytes_sent;
	xfer->bytes_remaining = purple_xfer_get_size(xfer) - bytes_sent;
}
Ejemplo n.º 14
0
static void
yahoo_xfer_init_15(PurpleXfer *xfer)
{
	struct yahoo_xfer_data *xfer_data;
	PurpleConnection *gc;
	PurpleAccount *account;
	YahooData *yd;
	struct yahoo_packet *pkt;

	xfer_data = purple_xfer_get_protocol_data(xfer);
	gc = xfer_data->gc;
	yd = purple_connection_get_protocol_data(gc);
	account = purple_connection_get_account(gc);

	if (purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_SEND)	{
		gchar *filename;
		filename = g_path_get_basename(purple_xfer_get_local_filename(xfer));
		pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15,
							   YAHOO_STATUS_AVAILABLE,
							   yd->session_id);
		yahoo_packet_hash(pkt, "sssiiiisiii",
			1, purple_normalize(account, purple_account_get_username(account)),
			5, purple_xfer_get_remote_user(xfer),
			265, xfer_data->xfer_peer_idstring,
			222, 1,
			266, 1,
			302, 268,
			300, 268,
			27,  filename,
			28,  (int)purple_xfer_get_size(xfer),
			301, 268,
			303, 268);
		g_free(filename);
	} else {
		if(xfer_data->firstoflist == TRUE) {
			pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15,
				YAHOO_STATUS_AVAILABLE, yd->session_id);

			yahoo_packet_hash(pkt, "sssi",
				1, purple_normalize(account, purple_account_get_username(account)),
				5, purple_xfer_get_remote_user(xfer),
				265, xfer_data->xfer_peer_idstring,
				222, 3);
		} else {
			pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_ACC_15,
				YAHOO_STATUS_AVAILABLE, yd->session_id);

			yahoo_packet_hash(pkt, "sssi",
				1, purple_normalize(account, purple_account_get_username(account)),
				5, purple_xfer_get_remote_user(xfer),
				265, xfer_data->xfer_peer_idstring,
				271, 1);
		}
	}
	yahoo_packet_send_and_free(pkt, yd);
}
Ejemplo n.º 15
0
static int _qq_xfer_open_file(const gchar *filename, const gchar *method, PurpleXfer *xfer)
{
	ft_info *info = xfer->data;
	int fd;
	if (method[0] == 'r') {
		fd = open(purple_xfer_get_local_filename(xfer), O_RDONLY);
		info->buffer = mmap(0, purple_xfer_get_size(xfer), PROT_READ, MAP_PRIVATE, fd, 0);
	}
	else
	{
		fd = open(purple_xfer_get_local_filename(xfer), O_RDWR|O_CREAT, 0644);
		info->buffer = mmap(0, purple_xfer_get_size(xfer), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FILE, fd, 0);
	}

	if (info->buffer == NULL) {
		return - 1;
	}
	return 0;
}
Ejemplo n.º 16
0
static gint _qq_xfer_read_file(guint8 *buffer, guint index, guint len, PurpleXfer *xfer)
{
	ft_info *info = xfer->data;
	gint readbytes;

	buffer = info->buffer + len * index;
	readbytes = purple_xfer_get_size(xfer) - (buffer - info->buffer);
	if (readbytes > info->fragment_len) readbytes = info->fragment_len;
	return readbytes;
}
Ejemplo n.º 17
0
static void
update_title_progress(PidginXferDialog *dialog)
{
	gboolean valid;
	GtkTreeIter iter;
	int num_active_xfers = 0;
	guint64 total_bytes_xferred = 0;
	guint64 total_file_size = 0;

	if (dialog->window == NULL)
		return;

	valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dialog->model), &iter);

	/* Find all active transfers */
	while (valid) {
		GValue val;
		PurpleXfer *xfer = NULL;

		val.g_type = 0;
		gtk_tree_model_get_value(GTK_TREE_MODEL(dialog->model),
				&iter, COLUMN_DATA, &val);

		xfer = g_value_get_pointer(&val);
		if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_STARTED) {
			num_active_xfers++;
			total_bytes_xferred += purple_xfer_get_bytes_sent(xfer);
			total_file_size += purple_xfer_get_size(xfer);
		}

		valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(dialog->model), &iter);
	}

	/* Update the title */
	if (num_active_xfers > 0)
	{
		gchar *title;
		int total_pct = 0;

		if (total_file_size > 0) {
			total_pct = 100 * total_bytes_xferred / total_file_size;
		}

		title = g_strdup_printf(ngettext("File Transfers - %d%% of %d file",
						 "File Transfers - %d%% of %d files",
						 num_active_xfers),
					total_pct, num_active_xfers);
		gtk_window_set_title(GTK_WINDOW(dialog->window), title);
		g_free(title);
	} else {
		gtk_window_set_title(GTK_WINDOW(dialog->window), _("File Transfers"));
	}
}
Ejemplo n.º 18
0
static void
irc_dccsend_network_listen_cb(int sock, gpointer data)
{
    PurpleXfer *xfer = data;
    struct irc_xfer_send_data *xd;
    PurpleConnection *gc;
    struct irc_conn *irc;
    const char *arg[2];
    char *tmp;
    struct in_addr addr;
    unsigned short int port;

    xd = purple_xfer_get_protocol_data(xfer);
    xd->listen_data = NULL;

    if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL
            || purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_REMOTE) {
        g_object_unref(xfer);
        return;
    }

    xd = purple_xfer_get_protocol_data(xfer);
    gc = purple_account_get_connection(purple_xfer_get_account(xfer));
    irc = purple_connection_get_protocol_data(gc);

    g_object_unref(xfer);

    if (sock < 0) {
        purple_notify_error(gc, NULL, _("File Transfer Failed"),
                            _("Unable to open a listening port."),
                            purple_request_cpar_from_connection(gc));
        purple_xfer_cancel_local(xfer);
        return;
    }

    xd->fd = sock;

    port = purple_network_get_port_from_fd(sock);
    purple_debug_misc("irc", "port is %hu\n", port);
    /* Monitor the listening socket */
    purple_xfer_set_watcher(xfer, purple_input_add(sock, PURPLE_INPUT_READ,
                            irc_dccsend_send_connected, xfer));

    /* Send the intended recipient the DCC request */
    arg[0] = purple_xfer_get_remote_user(xfer);
    inet_aton(purple_network_get_my_ip(irc->fd), &addr);
    arg[1] = tmp = g_strdup_printf("\001DCC SEND \"%s\" %u %hu %" G_GOFFSET_FORMAT "\001",
                                   purple_xfer_get_filename(xfer), ntohl(addr.s_addr),
                                   port, purple_xfer_get_size(xfer));

    irc_cmd_privmsg(purple_connection_get_protocol_data(gc), "msg", NULL, arg);
    g_free(tmp);
}
Ejemplo n.º 19
0
/* just in case you were wondering, this is why DCC is gay */
static void irc_dccsend_send_read(gpointer data, int source, PurpleInputCondition cond)
{
    PurpleXfer *xfer = data;
    struct irc_xfer_send_data *xd = purple_xfer_get_protocol_data(xfer);
    char buffer[64];
    int len;

    len = read(source, buffer, sizeof(buffer));

    if (len < 0 && errno == EAGAIN)
        return;
    else if (len <= 0) {
        /* XXX: Shouldn't this be canceling the transfer? */
        purple_input_remove(xd->inpa);
        xd->inpa = 0;
        return;
    }

    xd->rxqueue = g_realloc(xd->rxqueue, len + xd->rxlen);
    memcpy(xd->rxqueue + xd->rxlen, buffer, len);
    xd->rxlen += len;

    while (1) {
        gint32 val;
        size_t acked;

        if (xd->rxlen < 4)
            break;

        memcpy(&val, xd->rxqueue, sizeof(val));
        acked = ntohl(val);

        xd->rxlen -= 4;
        if (xd->rxlen) {
            unsigned char *tmp = g_memdup(xd->rxqueue + 4, xd->rxlen);
            g_free(xd->rxqueue);
            xd->rxqueue = tmp;
        } else {
            g_free(xd->rxqueue);
            xd->rxqueue = NULL;
        }

        if ((goffset)acked >= purple_xfer_get_size(xfer)) {
            purple_input_remove(xd->inpa);
            xd->inpa = 0;
            purple_xfer_set_completed(xfer, TRUE);
            purple_xfer_end(xfer);
            return;
        }
    }
}
Ejemplo n.º 20
0
static void
purple_xfer_ask_recv(PurpleXfer *xfer)
{
	char *buf, *size_buf;
	size_t size;
	gconstpointer thumb;
	gsize thumb_size;

	/* If we have already accepted the request, ask the destination file
	   name directly */
	if (purple_xfer_get_status(xfer) != PURPLE_XFER_STATUS_ACCEPTED) {
		PurpleBuddy *buddy = purple_find_buddy(xfer->account, xfer->who);

		if (purple_xfer_get_filename(xfer) != NULL)
		{
			size = purple_xfer_get_size(xfer);
			size_buf = purple_str_size_to_units(size);
			buf = g_strdup_printf(_("%s wants to send you %s (%s)"),
						  buddy ? purple_buddy_get_alias(buddy) : xfer->who,
						  purple_xfer_get_filename(xfer), size_buf);
			g_free(size_buf);
		}
		else
		{
			buf = g_strdup_printf(_("%s wants to send you a file"),
						buddy ? purple_buddy_get_alias(buddy) : xfer->who);
		}

		if (xfer->message != NULL)
			serv_got_im(purple_account_get_connection(xfer->account),
								 xfer->who, xfer->message, 0, time(NULL));

		if ((thumb = purple_xfer_get_thumbnail(xfer, &thumb_size))) {
			purple_request_accept_cancel_with_icon(xfer, NULL, buf, NULL,
				PURPLE_DEFAULT_ACTION_NONE, xfer->account, xfer->who, NULL,
				thumb, thumb_size, xfer,
				G_CALLBACK(purple_xfer_choose_file),
				G_CALLBACK(cancel_recv_cb));
		} else {
			purple_request_accept_cancel(xfer, NULL, buf, NULL,
				PURPLE_DEFAULT_ACTION_NONE, xfer->account, xfer->who, NULL,
				xfer, G_CALLBACK(purple_xfer_choose_file),
				G_CALLBACK(cancel_recv_cb));
		}
			
		g_free(buf);
	} else
		purple_xfer_choose_file(xfer);
}
Ejemplo n.º 21
0
void waprpl_xfer_init(PurpleXfer * xfer)
{
	purple_debug_info(WHATSAPP_ID, "File xfer init...\n");
	wa_file_upload *xinfo = (wa_file_upload *) xfer->data;
	whatsapp_connection *wconn = xinfo->wconn;

	size_t fs = purple_xfer_get_size(xfer);
	const char *fn = purple_xfer_get_filename(xfer);
	const char *fp = purple_xfer_get_local_filename(xfer);

	wa_file_upload *xfer_info = (wa_file_upload *) xfer->data;
	purple_xfer_set_size(xfer, fs);

	xfer_info->ref_id = waAPI_sendimage(wconn->waAPI, xinfo->to, 100, 100, fs, fp);
	purple_debug_info(WHATSAPP_ID, "Transfer file %s at %s with size %zu (given ref %d)\n", fn, fp, fs, xfer_info->ref_id);

	waprpl_check_output(xinfo->gc);
}
Ejemplo n.º 22
0
static void tgprpl_xfer_on_finished (struct tgl_state *TLS, void *_data, int success, struct tgl_message *M) {
  debug ("tgprpl_xfer_on_finished()");
  struct tgp_xfer_send_data *data = _data;
  
  if (success) {
    if (!data->done) {
      debug ("purple_xfer_set_completed");
      purple_xfer_set_bytes_sent (data->xfer, purple_xfer_get_size (data->xfer));
      purple_xfer_set_completed (data->xfer, TRUE);
      purple_xfer_end(data->xfer);
    }
  } else {
    failure ("ERROR xfer failed");
  }
  
  data->xfer->data = NULL;
  tgprpl_xfer_free_data (data);
}
Ejemplo n.º 23
0
static void ggp_edisc_xfer_send_init_authenticated(PurpleConnection *gc,
	gboolean success, gpointer _xfer)
{
	ggp_edisc_session_data *sdata = ggp_edisc_get_sdata(gc);
	PurpleHttpRequest *req;
	PurpleXfer *xfer = _xfer;
	ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer);
	gchar *data;

	if (purple_xfer_is_cancelled(xfer))
		return;

	if (!success) {
		ggp_edisc_xfer_error(xfer, _("Authentication failed"));
		return;
	}

	g_return_if_fail(sdata != NULL);

	req = purple_http_request_new("https://drive.mpa.gg.pl/send_ticket");
	purple_http_request_set_method(req, "PUT");

	ggp_edisc_set_defaults(req);
	purple_http_request_set_cookie_jar(req, sdata->cookies);

	purple_http_request_header_set(req, "X-gged-security-token",
		sdata->security_token);

	data = g_strdup_printf("{\"send_ticket\":{"
		"\"recipient\":\"%s\","
		"\"file_name\":\"%s\","
		"\"file_size\":\"%u\""
		"}}",
		purple_xfer_get_remote_user(xfer),
		edisc_xfer->filename,
		(int)purple_xfer_get_size(xfer));
	purple_http_request_set_contents(req, data, -1);
	g_free(data);

	edisc_xfer->hc = purple_http_request(gc, req,
		ggp_edisc_xfer_send_init_ticket_created, xfer);
	purple_http_request_unref(req);
}
Ejemplo n.º 24
0
static void ggp_edisc_xfer_send_start(PurpleXfer *xfer)
{
	ggp_edisc_session_data *sdata;
	ggp_edisc_xfer *edisc_xfer;
	gchar *upload_url, *filename_e;
	PurpleHttpRequest *req;

	g_return_if_fail(xfer != NULL);
	edisc_xfer = purple_xfer_get_protocol_data(xfer);
	g_return_if_fail(edisc_xfer != NULL);
	sdata = ggp_edisc_get_sdata(edisc_xfer->gc);
	g_return_if_fail(sdata != NULL);

	filename_e = purple_strreplace(edisc_xfer->filename, " ", "%20");
	upload_url = g_strdup_printf("https://drive.mpa.gg.pl/me/file/outbox/"
		"%s%%2C%s", edisc_xfer->ticket_id, filename_e);
	g_free(filename_e);
	req = purple_http_request_new(upload_url);
	g_free(upload_url);

	purple_http_request_set_method(req, "PUT");
	purple_http_request_set_timeout(req, -1);

	ggp_edisc_set_defaults(req);
	purple_http_request_set_cookie_jar(req, sdata->cookies);

	purple_http_request_header_set(req, "X-gged-local-revision", "0");
	purple_http_request_header_set(req, "X-gged-security-token",
		sdata->security_token);
	purple_http_request_header_set(req, "X-gged-metadata",
		"{\"node_type\": \"file\"}");

	purple_http_request_set_contents_reader(req, ggp_edisc_xfer_send_reader,
		purple_xfer_get_size(xfer), xfer);

	edisc_xfer->hc = purple_http_request(edisc_xfer->gc, req,
		ggp_edisc_xfer_send_done, xfer);
	purple_http_request_unref(req);

	purple_http_conn_set_progress_watcher(edisc_xfer->hc,
		ggp_edisc_xfer_progress_watcher, xfer, 250000);
}
Ejemplo n.º 25
0
void
finch_xfer_dialog_add_xfer(PurpleXfer *xfer)
{
	PurpleGntXferUiData *data;
	PurpleXferType type;
	char *size_str, *remaining_str;
	char *lfilename, *utf8;

	g_return_if_fail(xfer_dialog != NULL);
	g_return_if_fail(xfer != NULL);

	purple_xfer_ref(xfer);

	data = FINCHXFER(xfer);
	data->in_list = TRUE;

	finch_xfer_dialog_show();

	data->last_updated_time = 0;

	type = purple_xfer_get_type(xfer);

	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));

	lfilename = g_path_get_basename(purple_xfer_get_local_filename(xfer));
	utf8 = g_filename_to_utf8(lfilename, -1, NULL, NULL, NULL);
	g_free(lfilename);
	lfilename = utf8;
	gnt_tree_add_row_last(GNT_TREE(xfer_dialog->tree), xfer,
		gnt_tree_create_row(GNT_TREE(xfer_dialog->tree),
			"0.0", (type == PURPLE_XFER_RECEIVE) ? purple_xfer_get_filename(xfer) : lfilename,
			size_str, "0.0", "",_("Waiting for transfer to begin")), NULL);
	g_free(lfilename);

	g_free(size_str);
	g_free(remaining_str);

	xfer_dialog->num_transfers++;

	update_title_progress();
}
Ejemplo n.º 26
0
static void
update_title_progress(void)
{
	GList *list;
	int num_active_xfers = 0;
	guint64 total_bytes_xferred = 0;
	guint64 total_file_size = 0;

	if (xfer_dialog == NULL || xfer_dialog->window == NULL)
		return;

	/* Find all active transfers */
	for (list = gnt_tree_get_rows(GNT_TREE(xfer_dialog->tree)); list; list = list->next) {
		PurpleXfer *xfer = (PurpleXfer *)list->data;

		if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_STARTED) {
			num_active_xfers++;
			total_bytes_xferred += purple_xfer_get_bytes_sent(xfer);
			total_file_size += purple_xfer_get_size(xfer);
		}
	}

	/* Update the title */
	if (num_active_xfers > 0) {
		gchar *title;
		int total_pct = 0;

		if (total_file_size > 0) {
			total_pct = 100 * total_bytes_xferred / total_file_size;
		}

		title = g_strdup_printf(ngettext("File Transfers - %d%% of %d file",
						 "File Transfers - %d%% of %d files",
						 num_active_xfers),
				total_pct, num_active_xfers);
		gnt_screen_rename_widget((xfer_dialog->window), title);
		g_free(title);
	} else {
		gnt_screen_rename_widget((xfer_dialog->window), _("File Transfers"));
	}
}
Ejemplo n.º 27
0
static void
send_file_cb(MsnSlpCall *slpcall)
{
	MsnSlpMessage *slpmsg;
	PurpleXfer *xfer;

	xfer = (PurpleXfer *)slpcall->xfer;
	if (purple_xfer_get_status(xfer) >= PURPLE_XFER_STATUS_STARTED)
		return;

	g_object_ref(xfer);
	purple_xfer_start(xfer, -1, NULL, 0);
	if (purple_xfer_get_status(xfer) != PURPLE_XFER_STATUS_STARTED) {
		g_object_unref(xfer);
		return;
	}
	g_object_unref(xfer);

	slpmsg = msn_slpmsg_file_new(slpcall, purple_xfer_get_size(xfer));

	msn_slplink_send_slpmsg(slpcall->slplink, slpmsg);
}
Ejemplo n.º 28
0
static void tgprpl_xfer_recv_on_finished (struct tgl_state *TLS, void *_data, int success, const char *filename) {
  debug ("tgprpl_xfer_recv_on_finished()");
  struct tgp_xfer_send_data *data = _data;

  if (success) {
    if (!data->done) {
      debug ("purple_xfer_set_completed");
      purple_xfer_set_bytes_sent (data->xfer, purple_xfer_get_size (data->xfer));
      purple_xfer_set_completed (data->xfer, TRUE);
      purple_xfer_end (data->xfer);
    }
    
    g_unlink (purple_xfer_get_local_filename (data->xfer));
    g_rename (filename, purple_xfer_get_local_filename (data->xfer));

  } else {
    failure ("ERROR xfer failed");
  }

  data->xfer->data = NULL;
  tgprpl_xfer_free_data (data);
}
Ejemplo n.º 29
0
/* Checks if the WA protocol has data to output and schedules a write handler */
void waprpl_check_ssl_output(PurpleConnection * gc)
{
	whatsapp_connection *wconn = purple_connection_get_protocol_data(gc);
	if (wconn->sslfd < 0)
		return;

	int r = waAPI_sslhasoutdata(wconn->waAPI);
	if (r > 0) {
		/* Need to watch for output data (if we are not doing it already) */
		if (wconn->sslwh == 0)
			wconn->sslwh = purple_input_add(wconn->sslfd, PURPLE_INPUT_WRITE, waprpl_ssl_output_cb, gc);
	} else if (r < 0) {
		waprpl_ssl_cerr_cb(0, 0, gc);	/* Finished the connection! */
	} else {
		if (wconn->sslwh != 0)
			purple_input_remove(wconn->sslwh);

		wconn->sslwh = 0;
	}

	/* Update transfer status */
	int rid, bytes_sent;
	if (waAPI_fileuploadprogress(wconn->waAPI, &rid, &bytes_sent)) {
		GList *xfers = purple_xfers_get_all();
		while (xfers) {
			PurpleXfer *xfer = xfers->data;
			wa_file_upload *xinfo = (wa_file_upload *) xfer->data;
			if (xinfo->ref_id == rid) {
				purple_debug_info("waprpl", "Upload progress %d bytes done\n", bytes_sent);
				purple_xfer_set_bytes_sent(xfer, bytes_sent);
				purple_xfer_update_progress(xfer);
				if (bytes_sent >= (signed)purple_xfer_get_size(xfer))
					purple_xfer_set_completed(xfer, TRUE);
				break;
			}
			xfers = g_list_next(xfers);
		}
	}
}
Ejemplo n.º 30
0
gssize
purple_xfer_read(PurpleXfer *xfer, guchar **buffer)
{
	gssize s, r;

	g_return_val_if_fail(xfer   != NULL, 0);
	g_return_val_if_fail(buffer != NULL, 0);

	if (purple_xfer_get_size(xfer) == 0)
		s = xfer->current_buffer_size;
	else
		s = MIN(purple_xfer_get_bytes_remaining(xfer), xfer->current_buffer_size);

	if (xfer->ops.read != NULL)	{
		r = (xfer->ops.read)(buffer, xfer);
	}
	else {
		*buffer = g_malloc0(s);

		r = read(xfer->fd, *buffer, s);
		if (r < 0 && errno == EAGAIN)
			r = 0;
		else if (r < 0)
			r = -1;
		else if (r == 0)
			r = -1;
	}

	if (r == xfer->current_buffer_size)
		/*
		 * We managed to read the entire buffer.  This means our this
		 * network is fast and our buffer is too small, so make it
		 * bigger.
		 */
		purple_xfer_increase_buffer_size(xfer);

	return r;
}