Example #1
0
PurpleXfer *silcpurple_ftp_new_xfer(PurpleConnection *gc, const char *name)
{
    SilcPurple sg = gc->proto_data;
    SilcClient client = sg->client;
    SilcClientConnection conn = sg->conn;
    SilcClientEntry *clients;
    SilcUInt32 clients_count;
    SilcPurpleXfer xfer;
    char *nickname;

    g_return_val_if_fail(name != NULL, NULL);

    if (!silc_parse_userfqdn(name, &nickname, NULL))
        return NULL;

    /* Find client entry */
    clients = silc_client_get_clients_local(client, conn, nickname, name,
                                            &clients_count);
    if (!clients) {
        silc_client_get_clients(client, conn, nickname, NULL,
                                silcpurple_ftp_send_file_resolved,
                                strdup(name));
        silc_free(nickname);
        return NULL;
    }

    xfer = silc_calloc(1, sizeof(*xfer));

    g_return_val_if_fail(xfer != NULL, NULL);

    xfer->sg = sg;
    xfer->client_entry = clients[0];
    xfer->xfer = purple_xfer_new(xfer->sg->account, PURPLE_XFER_SEND,
                                 xfer->client_entry->nickname);
    if (!xfer->xfer) {
        silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id);
        g_free(xfer->hostname);
        silc_free(xfer);
        return NULL;
    }
    purple_xfer_set_init_fnc(xfer->xfer, silcpurple_ftp_send);
    purple_xfer_set_request_denied_fnc(xfer->xfer, silcpurple_ftp_request_denied);
    purple_xfer_set_cancel_send_fnc(xfer->xfer, silcpurple_ftp_send_cancel);
    xfer->xfer->data = xfer;

    silc_free(clients);
    silc_free(nickname);

    return xfer->xfer;
}
Example #2
0
File: buddy.c Project: dylex/pidgin
static void
silcpurple_buddy_getkey(PurpleConnection *gc, const char *name)
{
	SilcPurple sg = gc->proto_data;
	SilcClient client = sg->client;
	SilcClientConnection conn = sg->conn;
	SilcClientEntry *clients;
	SilcUInt32 clients_count;
	SilcPurpleBuddyGetkey g;
	char *nickname;

	if (!name)
		return;

	if (!silc_parse_userfqdn(name, &nickname, NULL))
		return;

	/* Find client entry */
	clients = silc_client_get_clients_local(client, conn, nickname, name,
						&clients_count);
	if (!clients) {
		silc_client_get_clients(client, conn, nickname, NULL,
					silcpurple_buddy_getkey_resolved,
					g_strdup(name));
		silc_free(nickname);
		return;
	}

	/* Call GETKEY */
	g = silc_calloc(1, sizeof(*g));
	if (!g)
		return;
	g->client = client;
	g->conn = conn;
	g->client_id = *clients[0]->id;
	silc_client_command_call(client, conn, NULL, "GETKEY",
				 clients[0]->nickname, NULL);
	silc_client_command_pending(conn, SILC_COMMAND_GETKEY,
				    conn->cmd_ident,
				    (SilcCommandCb)silcpurple_buddy_getkey_cb, g);
	silc_free(clients);
	silc_free(nickname);
}
Example #3
0
File: buddy.c Project: dylex/pidgin
static void
silcpurple_buddy_privkey(PurpleConnection *gc, const char *name)
{
	SilcPurple sg = gc->proto_data;
	char *nickname;
	SilcPurplePrivkey p;
	SilcClientEntry *clients;
	SilcUInt32 clients_count;

	if (!name)
		return;
	if (!silc_parse_userfqdn(name, &nickname, NULL))
		return;

	/* Find client entry */
	clients = silc_client_get_clients_local(sg->client, sg->conn,
						nickname, name,
						&clients_count);
	if (!clients) {
		silc_client_get_clients(sg->client, sg->conn, nickname, NULL,
					silcpurple_buddy_privkey_resolved,
					g_strdup(name));
		silc_free(nickname);
		return;
	}

	p = silc_calloc(1, sizeof(*p));
	if (!p)
		return;
	p->client = sg->client;
	p->conn = sg->conn;
	p->client_id = *clients[0]->id;
	purple_request_input(gc, _("IM With Password"), NULL,
	                     _("Set IM Password"), NULL, FALSE, TRUE, NULL,
	                     _("OK"), G_CALLBACK(silcpurple_buddy_privkey_cb),
	                     _("Cancel"), G_CALLBACK(silcpurple_buddy_privkey_cb),
	                     gc->account, NULL, NULL, p);

	silc_free(clients);
	silc_free(nickname);
}
Example #4
0
File: buddy.c Project: dylex/pidgin
static void
silcpurple_buddy_keyagr_do(PurpleConnection *gc, const char *name,
			 gboolean force_local)
{
	SilcPurple sg = gc->proto_data;
	SilcClientEntry *clients;
	SilcUInt32 clients_count;
	char *local_ip = NULL, *remote_ip = NULL;
	gboolean local = TRUE;
	char *nickname;
	SilcPurpleKeyAgr a;

	if (!sg->conn || !name)
		return;

	if (!silc_parse_userfqdn(name, &nickname, NULL))
		return;

	/* Find client entry */
	clients = silc_client_get_clients_local(sg->client, sg->conn, nickname, name,
						&clients_count);
	if (!clients) {
		/* Resolve unknown user */
		SilcPurpleResolve r = silc_calloc(1, sizeof(*r));
		if (!r)
			return;
		r->nick = g_strdup(name);
		r->gc = gc;
		silc_client_get_clients(sg->client, sg->conn, nickname, NULL,
					silcpurple_buddy_keyagr_resolved, r);
		silc_free(nickname);
		return;
	}

	/* Resolve the local IP from the outgoing socket connection.  We resolve
	   it to check whether we have a private range IP address or public IP
	   address.  If we have public then we will assume that we are not behind
	   NAT and will provide automatically the point of connection to the
	   agreement.  If we have private range address we assume that we are
	   behind NAT and we let the responder provide the point of connection.

	   The algorithm also checks the remote IP address of server connection.
	   If it is private range address and we have private range address we
	   assume that we are chatting in LAN and will provide the point of
	   connection.

	   Naturally this algorithm does not always get things right. */

	if (silc_net_check_local_by_sock(sg->conn->sock->sock, NULL, &local_ip)) {
		/* Check if the IP is private */
		if (!force_local && silcpurple_ip_is_private(local_ip)) {
			local = FALSE;

			/* Local IP is private, resolve the remote server IP to see whether
			   we are talking to Internet or just on LAN. */
			if (silc_net_check_host_by_sock(sg->conn->sock->sock, NULL,
							&remote_ip))
				if (silcpurple_ip_is_private(remote_ip))
					/* We assume we are in LAN.  Let's provide
					   the connection point. */
					local = TRUE;
		}
	}

	if (force_local)
		local = TRUE;

	if (local && !local_ip)
		local_ip = silc_net_localip();

	a = silc_calloc(1, sizeof(*a));
	if (!a)
		return;
	a->responder = local;

	/* Send the key agreement request */
	silc_client_send_key_agreement(sg->client, sg->conn, clients[0],
				       local ? local_ip : NULL, NULL, 0, 60,
				       silcpurple_buddy_keyagr_cb, a);

	silc_free(local_ip);
	silc_free(remote_ip);
	silc_free(clients);
}