示例#1
0
文件: dcc_send.c 项目: VoxOx/VoxOx
/**
 * Gaim calls this function when the user selects Send File from the
 * buddy menu
 * It sets up the GaimXfer struct and tells Gaim to go ahead
 */
void irc_dccsend_send_file(GaimConnection *gc, const char *who, const char *file) {
	GaimXfer *xfer = irc_dccsend_new_xfer(gc, who);

	/* Perform the request */
	if (file)
		gaim_xfer_request_accepted(xfer, file);
	else
		gaim_xfer_request(xfer);
}
示例#2
0
文件: si.c 项目: VoxOx/VoxOx
void jabber_si_xfer_send(GaimConnection *gc, const char *who, const char *file)
{
	JabberStream *js;

	GaimXfer *xfer;

	js = gc->proto_data;

	if(!gaim_find_buddy(gc->account, who) || !jabber_buddy_find(js, who, FALSE))
		return;

	xfer = jabber_si_new_xfer(gc, who);

	if (file)
		gaim_xfer_request_accepted(xfer, file);
	else
		gaim_xfer_request(xfer);
}
示例#3
0
/**
 * Gaim calls this function when the user selects Send File from the
 * buddy menu
 * It sets up the GaimXfer struct and tells Gaim to go ahead
 */
void gaym_dccsend_send_file(GaimConnection *gc, const char *who, const char *file) {
	GaimXfer *xfer;
	struct gaym_xfer_send_data *xd;

	/* Build the file transfer handle */
	xfer = gaim_xfer_new(gaim_connection_get_account(gc), GAIM_XFER_SEND, who);


	xd = g_new0(struct gaym_xfer_send_data, 1);
	xd->fd = -1;
	xfer->data = xd;

	 /* Setup our I/O op functions */
	gaim_xfer_set_init_fnc(xfer, gaym_dccsend_send_init);
	gaim_xfer_set_write_fnc(xfer, gaym_dccsend_send_write);
	gaim_xfer_set_end_fnc(xfer, gaym_dccsend_send_destroy);
	gaim_xfer_set_request_denied_fnc(xfer, gaym_dccsend_send_destroy);
	gaim_xfer_set_cancel_send_fnc(xfer, gaym_dccsend_send_destroy);
	/* Now perform the request */
	if (file)
		gaim_xfer_request_accepted(xfer, file);
	else
		gaim_xfer_request(xfer);
}
示例#4
0
文件: dcc_send.c 项目: VoxOx/VoxOx
/* This function makes the necessary arrangements for receiving files */
void irc_dccsend_recv(struct irc_conn *irc, const char *from, const char *msg) {
	GaimXfer *xfer;
	struct irc_xfer_rx_data *xd;
	gchar **token;
	struct in_addr addr;
	GString *filename;
	int i = 0;
	guint32 nip;

	token = g_strsplit(msg, " ", 0);
	if (!token[0] || !token[1] || !token[2]) {
		g_strfreev(token);
		return;
	}

	filename = g_string_new("");
	if (token[0][0] == '"') {
		if (!strchr(&(token[0][1]), '"')) {
			g_string_append(filename, &(token[0][1]));
			for (i = 1; token[i]; i++)
				if (!strchr(token[i], '"')) {
					g_string_append_printf(filename, " %s", token[i]);
				} else {
					g_string_append_len(filename, token[i], strlen(token[i]) - 1);
					break;
				}
		} else {
			g_string_append_len(filename, &(token[0][1]), strlen(&(token[0][1])) - 1);
		}
	} else {
		g_string_append(filename, token[0]);
	}

	if (!token[i] || !token[i+1] || !token[i+2]) {
		g_strfreev(token);
		g_string_free(filename, TRUE);
		return;
	}
	i++;

	xfer = gaim_xfer_new(irc->account, GAIM_XFER_RECEIVE, from);
	if (xfer)
	{
		xd = g_new0(struct irc_xfer_rx_data, 1);
		xfer->data = xd;

		gaim_xfer_set_filename(xfer, filename->str);
		xfer->remote_port = atoi(token[i+1]);

		nip = strtoul(token[i], NULL, 10);
		if (nip) {
			addr.s_addr = htonl(nip);
			xd->ip = g_strdup(inet_ntoa(addr));
		} else {
			xd->ip = g_strdup(token[i]);
		}
		gaim_debug(GAIM_DEBUG_INFO, "irc", "Receiving file from %s\n",
				   xd->ip);
		gaim_xfer_set_size(xfer, token[i+2] ? atoi(token[i+2]) : 0);
		
		gaim_xfer_set_init_fnc(xfer, irc_dccsend_recv_init);
		gaim_xfer_set_ack_fnc(xfer, irc_dccsend_recv_ack);
		
		gaim_xfer_set_end_fnc(xfer, irc_dccsend_recv_destroy);
		gaim_xfer_set_request_denied_fnc(xfer, irc_dccsend_recv_destroy);
		gaim_xfer_set_cancel_send_fnc(xfer, irc_dccsend_recv_destroy);
		
		gaim_xfer_request(xfer);
	}
	g_strfreev(token);
	g_string_free(filename, TRUE);
}
示例#5
0
文件: si.c 项目: VoxOx/VoxOx
void jabber_si_parse(JabberStream *js, xmlnode *packet)
{
	JabberSIXfer *jsx;
	GaimXfer *xfer;
	xmlnode *si, *file, *feature, *x, *field, *option, *value;
	const char *stream_id, *filename, *filesize_c, *profile, *from;
	size_t filesize = 0;

	if(!(si = xmlnode_get_child(packet, "si")))
		return;

	if(!(profile = xmlnode_get_attrib(si, "profile")) ||
			strcmp(profile, "http://jabber.org/protocol/si/profile/file-transfer"))
		return;

	if(!(stream_id = xmlnode_get_attrib(si, "id")))
		return;

	if(!(file = xmlnode_get_child(si, "file")))
		return;

	if(!(filename = xmlnode_get_attrib(file, "name")))
		return;

	if((filesize_c = xmlnode_get_attrib(file, "size")))
		filesize = atoi(filesize_c);

	if(!(feature = xmlnode_get_child(si, "feature")))
		return;

	if(!(x = xmlnode_get_child_with_namespace(feature, "x", "jabber:x:data")))
		return;

	if(!(from = xmlnode_get_attrib(packet, "from")))
		return;

	/* if they've already sent us this file transfer with the same damn id
	 * then we're gonna ignore it, until I think of something better to do
	 * with it */
	if((xfer = jabber_si_xfer_find(js, stream_id, from)))
		return;

	jsx = g_new0(JabberSIXfer, 1);

	for(field = xmlnode_get_child(x, "field"); field; field = xmlnode_get_next_twin(field)) {
		const char *var = xmlnode_get_attrib(field, "var");
		if(var && !strcmp(var, "stream-method")) {
			for(option = xmlnode_get_child(field, "option"); option;
					option = xmlnode_get_next_twin(option)) {
				if((value = xmlnode_get_child(option, "value"))) {
					char *val;
					if((val = xmlnode_get_data(value))) {
						if(!strcmp(val, "http://jabber.org/protocol/bytestreams")) {
							jsx->stream_method |= STREAM_METHOD_BYTESTREAMS;
							/*
						} else if(!strcmp(val, "http://jabber.org/protocol/ibb")) {
							jsx->stream_method |= STREAM_METHOD_IBB;
							*/
						}
						g_free(val);
					}
				}
			}
		}
	}

	if(jsx->stream_method == STREAM_METHOD_UNKNOWN) {
		g_free(jsx);
		return;
	}

	jsx->js = js;
	jsx->stream_id = g_strdup(stream_id);
	jsx->iq_id = g_strdup(xmlnode_get_attrib(packet, "id"));

	xfer = gaim_xfer_new(js->gc->account, GAIM_XFER_RECEIVE, from);
	if (xfer)
	{
		xfer->data = jsx;

		gaim_xfer_set_filename(xfer, filename);
		if(filesize > 0)
			gaim_xfer_set_size(xfer, filesize);

		gaim_xfer_set_init_fnc(xfer, jabber_si_xfer_init);
		gaim_xfer_set_request_denied_fnc(xfer, jabber_si_xfer_request_denied);
		gaim_xfer_set_cancel_recv_fnc(xfer, jabber_si_xfer_cancel_recv);
		gaim_xfer_set_end_fnc(xfer, jabber_si_xfer_end);

		js->file_transfers = g_list_append(js->file_transfers, xfer);

		gaim_xfer_request(xfer);
	}
}