Пример #1
0
void
gaim_xfer_end(GaimXfer *xfer)
{
	g_return_if_fail(xfer != NULL);

	/* See if we are actually trying to cancel this. */
	if (!xfer->completed) {
		gaim_xfer_cancel_local(xfer);
		return;
	}

	if (xfer->ops.end != NULL)
		xfer->ops.end(xfer);

	if (xfer->watcher != 0) {
		gaim_input_remove(xfer->watcher);
		xfer->watcher = 0;
	}

	if (xfer->fd != 0)
		close(xfer->fd);

	if (xfer->dest_fp != NULL) {
		fclose(xfer->dest_fp);
		xfer->dest_fp = NULL;
	}
}
Пример #2
0
void
gaim_xfer_destroy(GaimXfer *xfer)
{
	GaimXferUiOps *ui_ops;

	g_return_if_fail(xfer != NULL);

	if (!xfer->completed)
		gaim_xfer_cancel_local(xfer);

	ui_ops = gaim_xfer_get_ui_ops(xfer);

	if (ui_ops != NULL && ui_ops->destroy != NULL)
		ui_ops->destroy(xfer);

	g_free(xfer->who);
	g_free(xfer->filename);

	if (xfer->remote_ip != NULL) g_free(xfer->remote_ip);
	if (xfer->local_ip  != NULL) g_free(xfer->local_ip);

	if (xfer->local_filename != NULL)
		g_free(xfer->local_filename);

	g_free(xfer);
}
Пример #3
0
static void
begin_transfer(GaimXfer *xfer, GaimInputCondition cond)
{
	GaimXferUiOps *ui_ops;
	GaimXferType type = gaim_xfer_get_type(xfer);

	ui_ops = gaim_xfer_get_ui_ops(xfer);

	/*
	 * We'll have already tried to open this earlier to make sure we can
	 * read/write here. Should be safe.
	 */
	xfer->dest_fp = fopen(gaim_xfer_get_local_filename(xfer),
						  type == GAIM_XFER_RECEIVE ? "wb" : "rb");

	/* Just in case, though. */
	if (xfer->dest_fp == NULL) {
		gaim_xfer_cancel_local(xfer); /* ? */
		return;
	}

	xfer->watcher = gaim_input_add(xfer->fd, cond, transfer_cb, xfer);

	if (ui_ops != NULL && ui_ops->add_xfer != NULL)
		ui_ops->add_xfer(xfer);

	if (xfer->ops.start != NULL)
		xfer->ops.start(xfer);
}
Пример #4
0
Файл: si.c Проект: VoxOx/VoxOx
static void
jabber_si_xfer_bytestreams_listen_cb(int sock, gpointer data)
{
	GaimXfer *xfer = data;
	JabberSIXfer *jsx;
	JabberIq *iq;
	xmlnode *query, *streamhost;
	char *jid, *port;

	jsx = xfer->data;
	jsx->listen_data = NULL;

	if (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_LOCAL) {
		gaim_xfer_unref(xfer);
		return;
	}

	gaim_xfer_unref(xfer);

	if (sock < 0) {
		gaim_xfer_cancel_local(xfer);
		return;
	}

	iq = jabber_iq_new_query(jsx->js, JABBER_IQ_SET,
			"http://jabber.org/protocol/bytestreams");
	xmlnode_set_attrib(iq->node, "to", xfer->who);
	query = xmlnode_get_child(iq->node, "query");

	xmlnode_set_attrib(query, "sid", jsx->stream_id);

	streamhost = xmlnode_new_child(query, "streamhost");
	jid = g_strdup_printf("%s@%s/%s", jsx->js->user->node,
			jsx->js->user->domain, jsx->js->user->resource);
	xmlnode_set_attrib(streamhost, "jid", jid);
	g_free(jid);

	/* XXX: shouldn't we use the public IP or something? here */
	xmlnode_set_attrib(streamhost, "host",
			gaim_network_get_my_ip(jsx->js->fd));
	xfer->local_port = gaim_network_get_port_from_fd(sock);
	port = g_strdup_printf("%hu", xfer->local_port);
	xmlnode_set_attrib(streamhost, "port", port);
	g_free(port);

	xfer->watcher = gaim_input_add(sock, GAIM_INPUT_READ,
			jabber_si_xfer_bytestreams_send_connected_cb, xfer);

	/* XXX: insert proxies here */

	/* XXX: callback to find out which streamhost they used, or see if they
	 * screwed it up */
	jabber_iq_send(iq);

}
Пример #5
0
static void
irc_dccsend_network_listen_cb(int sock, gpointer data)
{
	GaimXfer *xfer = data;
	struct irc_xfer_send_data *xd;
	GaimConnection *gc;
	struct irc_conn *irc;
	const char *arg[2];
	char *tmp;
	struct in_addr addr;
	unsigned short int port;

	xd = xfer->data;
	xd->listen_data = NULL;

	if (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_LOCAL
			|| gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_REMOTE) {
		gaim_xfer_unref(xfer);
		return;
	}

	xd = xfer->data;
	gc = gaim_account_get_connection(gaim_xfer_get_account(xfer));
	irc = gc->proto_data;

	gaim_xfer_unref(xfer);

	if (sock < 0) {
		gaim_notify_error(gc, NULL, _("File Transfer Failed"),
		                  _("Gaim could not open a listening port."));
		gaim_xfer_cancel_local(xfer);
		return;
	}

	xd->fd = sock;

	port = gaim_network_get_port_from_fd(sock);
	gaim_debug_misc("irc", "port is %hu\n", port);
	/* Monitor the listening socket */
	xfer->watcher = gaim_input_add(sock, GAIM_INPUT_READ,
	                               irc_dccsend_send_connected, xfer);

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

	irc_cmd_privmsg(gc->proto_data, "msg", NULL, arg);
	g_free(tmp);
}
Пример #6
0
Файл: si.c Проект: VoxOx/VoxOx
static void
jabber_si_xfer_bytestreams_send_init(GaimXfer *xfer)
{
	JabberSIXfer *jsx;

	gaim_xfer_ref(xfer);

	jsx = xfer->data;
	jsx->listen_data = gaim_network_listen_range(0, 0, SOCK_STREAM,
				jabber_si_xfer_bytestreams_listen_cb, xfer);
	if (jsx->listen_data == NULL) {
		gaim_xfer_unref(xfer);
		/* XXX: couldn't open a port, we're fscked */
		gaim_xfer_cancel_local(xfer);
		return;
	}

}
Пример #7
0
/*
 * This function is called after the user has selected a file to send.
 */
static void irc_dccsend_send_init(GaimXfer *xfer) {
	GaimConnection *gc = gaim_account_get_connection(gaim_xfer_get_account(xfer));
	struct irc_xfer_send_data *xd = xfer->data;

	xfer->filename = g_path_get_basename(xfer->local_filename);

	gaim_xfer_ref(xfer);

	/* Create a listening socket */
	xd->listen_data = gaim_network_listen_range(0, 0, SOCK_STREAM,
			irc_dccsend_network_listen_cb, xfer);
	if (xd->listen_data == NULL) {
		gaim_xfer_unref(xfer);
		gaim_notify_error(gc, NULL, _("File Transfer Failed"),
		                  _("Gaim could not open a listening port."));
		gaim_xfer_cancel_local(xfer);
	}

}
Пример #8
0
/*
 * This function is called after the user has selected a file to send.
 */
static void gaym_dccsend_send_init(GaimXfer *xfer) {
	struct gaym_xfer_send_data *xd = xfer->data;
	GaimConnection *gc = gaim_account_get_connection(gaim_xfer_get_account(xfer));
	struct gaym_conn *gaym = gc->proto_data;
	int sock;
	const char *arg[2];
	char *tmp;
	struct in_addr addr;
	unsigned short int port;

	xfer->filename = g_path_get_basename(xfer->local_filename);

	/* Create a listening socket */
	sock = gaim_network_listen_range(0, 0);

	if (sock < 0) {
		gaim_notify_error(gc, NULL, _("File Transfer Aborted"),
		                  _("Gaim could not open a listening port."));
		gaim_xfer_cancel_local(xfer);
		return;
	}

	xd->fd = sock;

	port = gaim_network_get_port_from_fd(sock);
	gaim_debug_misc("gaym", "port is %hu\n", port);
	/* Monitor the listening socket */
	xfer->watcher = gaim_input_add(sock, GAIM_INPUT_READ,
	                               gaym_dccsend_send_connected, xfer);

	/* Send the intended recipient the DCC request */
	arg[0] = xfer->who;
	inet_aton(gaim_network_get_my_ip(gaym->fd), &addr);
	arg[1] = tmp = g_strdup_printf("\001DCC SEND \"%s\" %u %hu %zu\001",
	                         xfer->filename, ntohl(addr.s_addr),
	                         port, xfer->size);

	gaym_cmd_privmsg(xfer->account->gc->proto_data, "msg", NULL, arg);
	g_free(tmp);
}
Пример #9
0
static void
stop_button_cb(GtkButton *button, GaimGtkXferDialog *dialog)
{
	gaim_xfer_cancel_local(dialog->selected_xfer);
}
Пример #10
0
Файл: si.c Проект: VoxOx/VoxOx
static void jabber_si_bytestreams_attempt_connect(GaimXfer *xfer)
{
	JabberSIXfer *jsx = xfer->data;
	struct bytestreams_streamhost *streamhost;
	char *dstaddr, *p;
	int i;
	unsigned char hashval[20];
	JabberID *dstjid;

	if(!jsx->streamhosts) {
		JabberIq *iq = jabber_iq_new(jsx->js, JABBER_IQ_ERROR);
		xmlnode *error, *inf;

		if(jsx->iq_id)
			jabber_iq_set_id(iq, jsx->iq_id);

		xmlnode_set_attrib(iq->node, "to", xfer->who);
		error = xmlnode_new_child(iq->node, "error");
		xmlnode_set_attrib(error, "code", "404");
		xmlnode_set_attrib(error, "type", "cancel");
		inf = xmlnode_new_child(error, "item-not-found");
		xmlnode_set_namespace(inf, "urn:ietf:params:xml:ns:xmpp-stanzas");

		jabber_iq_send(iq);

		gaim_xfer_cancel_local(xfer);

		return;
	}

	streamhost = jsx->streamhosts->data;

	dstjid = jabber_id_new(xfer->who);

	if(dstjid != NULL) {
		jsx->gpi = gaim_proxy_info_new();
		gaim_proxy_info_set_type(jsx->gpi, GAIM_PROXY_SOCKS5);
		gaim_proxy_info_set_host(jsx->gpi, streamhost->host);
		gaim_proxy_info_set_port(jsx->gpi, streamhost->port);



		dstaddr = g_strdup_printf("%s%s@%s/%s%s@%s/%s", jsx->stream_id, dstjid->node, dstjid->domain, dstjid->resource, jsx->js->user->node,
				jsx->js->user->domain, jsx->js->user->resource);

		gaim_cipher_digest_region("sha1", (guchar *)dstaddr, strlen(dstaddr),
				sizeof(hashval), hashval, NULL);
		g_free(dstaddr);
		dstaddr = g_malloc(41);
		p = dstaddr;
		for(i=0; i<20; i++, p+=2)
			snprintf(p, 3, "%02x", hashval[i]);

		jsx->connect_data = gaim_proxy_connect_socks5(NULL, jsx->gpi,
				dstaddr, 0,
				jabber_si_bytestreams_connect_cb, xfer);
		g_free(dstaddr);

		jabber_id_free(dstjid);
	}

	if (jsx->connect_data == NULL)
	{
		jsx->streamhosts = g_list_remove(jsx->streamhosts, streamhost);
		g_free(streamhost->jid);
		g_free(streamhost->host);
		g_free(streamhost);
		jabber_si_bytestreams_attempt_connect(xfer);
	}
}