Esempio n. 1
0
static void purple_login( account_t *acc )
{
	struct im_connection *ic = imcb_new( acc );
	PurpleAccount *pa;
	
	if( ( local_bee != NULL && local_bee != acc->bee ) ||
	    ( global.conf->runmode == RUNMODE_DAEMON && !getenv( "BITLBEE_DEBUG" ) ) )
	{
		imcb_error( ic,  "Daemon mode detected. Do *not* try to use libpurple in daemon mode! "
		                 "Please use inetd or ForkDaemon mode instead." );
		imc_logout( ic, FALSE );
		return;
	}
	local_bee = acc->bee;
	
	/* For now this is needed in the _connected() handlers if using
	   GLib event handling, to make sure we're not handling events
	   on dead connections. */
	purple_connections = g_slist_prepend( purple_connections, ic );
	
	ic->proto_data = pa = purple_account_new( acc->user, (char*) acc->prpl->data );
	purple_account_set_password( pa, acc->pass );
	purple_sync_settings( acc, pa );
	
	purple_account_set_enabled( pa, "BitlBee", TRUE );
}
Esempio n. 2
0
static void msn_login( account_t *acc )
{
	struct im_connection *ic = imcb_new( acc );
	struct msn_data *md = g_new0( struct msn_data, 1 );
	
	ic->proto_data = md;
	ic->flags |= OPT_PONGS | OPT_PONGED;
	
	if( strchr( acc->user, '@' ) == NULL )
	{
		imcb_error( ic, "Invalid account name" );
		imc_logout( ic, FALSE );
		return;
	}
	
	md->ic = ic;
	md->away_state = msn_away_state_list;
	md->domaintree = g_tree_new( msn_domaintree_cmp );
	md->ns->fd = -1;
	
	msn_connections = g_slist_prepend( msn_connections, ic );
	
	imcb_log( ic, "Connecting" );
	msn_ns_connect( ic, md->ns, MSN_NS_HOST, MSN_NS_PORT );
}
Esempio n. 3
0
static void purple_login(account_t *acc)
{
	struct im_connection *ic = imcb_new(acc);
	struct purple_data *pd;

	if ((local_bee != NULL && local_bee != acc->bee) ||
	    (global.conf->runmode == RUNMODE_DAEMON && !getenv("BITLBEE_DEBUG"))) {
		imcb_error(ic,  "Daemon mode detected. Do *not* try to use libpurple in daemon mode! "
		           "Please use inetd or ForkDaemon mode instead.");
		imc_logout(ic, FALSE);
		return;
	}
	local_bee = acc->bee;

	/* For now this is needed in the _connected() handlers if using
	   GLib event handling, to make sure we're not handling events
	   on dead connections. */
	purple_connections = g_slist_prepend(purple_connections, ic);

	ic->proto_data = pd = g_new0(struct purple_data, 1);
	pd->account = purple_account_new(acc->user, (char *) acc->prpl->data);
	pd->input_requests = g_hash_table_new_full(g_direct_hash, g_direct_equal,
	                                           NULL, g_free);
	pd->next_request_id = 0;
	purple_account_set_password(pd->account, acc->pass);
	purple_sync_settings(acc, pd->account);

	purple_account_set_enabled(pd->account, "BitlBee", TRUE);

	if (set_getbool(&acc->set, "mail_notifications") && set_getstr(&acc->set, "mail_notifications_handle")) {
		imcb_add_buddy(ic, set_getstr(&acc->set, "mail_notifications_handle"), NULL);
	}
}
Esempio n. 4
0
void
Skype_login (account_t* account)
{
    im_connection* connection = imcb_new(account);
    SkypeData*     skype      = g_new0(struct SkypeData, 1);

    connection->proto_data = skype;

    imcb_log(connection, "Connecting");

    skype->ssl = ssl_connect(
        set_getstr(&account->set, "server"),
        set_getint(&account->set, "port"),
        Skype_connected,
        connection
    );

    skype->fd         = skype->ssl ? ssl_getfd(skype->ssl) : -1;
    skype->username   = g_strdup(account->user);
    skype->connection = connection;

    if (set_getbool(&account->set, "skypeconsole")) {
        imcb_add_buddy(connection, "skypeconsole", NULL);
    }
}
Esempio n. 5
0
static void discord_login(account_t *acc)
{
  struct im_connection *ic = imcb_new(acc);

  discord_data *dd = g_new0(discord_data, 1);
  dd->keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL;
  ic->proto_data = dd;

  discord_http_login(acc);
}
Esempio n. 6
0
/**
 * Creates a new #SteamData with an #account_t. The returned #SteamData
 * should be freed with #steam_data_free() when no longer needed.
 *
 * @param acc The #account_t.
 *
 * @return The #SteamData or NULL on error.
 **/
SteamData *steam_data_new(account_t *acc)
{
    SteamData *sata;

    g_return_val_if_fail(acc != NULL, NULL);

    sata = g_new0(SteamData, 1);
    sata->api = steam_api_new();
    sata->ic  = imcb_new(acc);
    sata->ic->proto_data = sata;

    sata->api->umqid  = g_strdup(set_getstr(&acc->set, "umqid"));
    sata->api->token  = g_strdup(set_getstr(&acc->set, "token"));
    sata->api->sessid = g_strdup(set_getstr(&acc->set, "sessid"));
    sata->game_status = set_getbool(&acc->set, "game_status");

    steam_api_rehash(sata->api);

    return sata;
}
Esempio n. 7
0
File: jabber.c Progetto: AlD/bitlbee
static void jabber_login( account_t *acc )
{
	struct im_connection *ic = imcb_new( acc );
	struct jabber_data *jd = g_new0( struct jabber_data, 1 );
	char *s;
	
	/* For now this is needed in the _connected() handlers if using
	   GLib event handling, to make sure we're not handling events
	   on dead connections. */
	jabber_connections = g_slist_prepend( jabber_connections, ic );
	
	jd->ic = ic;
	ic->proto_data = jd;
	
	jabber_set_me( ic, acc->user );
	
	jd->fd = jd->r_inpa = jd->w_inpa = -1;
	
	if( jd->server == NULL )
	{
		imcb_error( ic, "Incomplete account name (format it like <*****@*****.**>)" );
		imc_logout( ic, FALSE );
		return;
	}
	
	if( ( s = strchr( jd->server, '/' ) ) )
	{
		*s = 0;
		set_setstr( &acc->set, "resource", s + 1 );
		
		/* Also remove the /resource from the original variable so we
		   won't have to do this again every time. */
		s = strchr( acc->user, '/' );
		*s = 0;
	}
	
	jd->node_cache = g_hash_table_new_full( g_str_hash, g_str_equal, NULL, jabber_cache_entry_free );
	jd->buddies = g_hash_table_new( g_str_hash, g_str_equal );
	
	if( set_getbool( &acc->set, "oauth" ) )
	{
		GSList *p_in = NULL;
		const char *tok;
		
		jd->fd = jd->r_inpa = jd->w_inpa = -1;
		
		if( strstr( jd->server, ".live.com" ) )
			jd->oauth2_service = &oauth2_service_mslive;
		else if( strstr( jd->server, ".facebook.com" ) )
			jd->oauth2_service = &oauth2_service_facebook;
		else
			jd->oauth2_service = &oauth2_service_google;
		
		oauth_params_parse( &p_in, ic->acc->pass );
		
		/* First see if we have a refresh token, in which case any
		   access token we *might* have has probably expired already
		   anyway. */
		if( ( tok = oauth_params_get( &p_in, "refresh_token" ) ) )
		{
			sasl_oauth2_refresh( ic, tok );
		}
		/* If we don't have a refresh token, let's hope the access
		   token is still usable. */
		else if( ( tok = oauth_params_get( &p_in, "access_token" ) ) )
		{
			jd->oauth2_access_token = g_strdup( tok );
			jabber_connect( ic );
		}
		/* If we don't have any, start the OAuth process now. Don't
		   even open an XMPP connection yet. */
		else
		{
			sasl_oauth2_init( ic );
			ic->flags |= OPT_SLOW_LOGIN;
		}
		
		oauth_params_free( &p_in );
	}
	else
		jabber_connect( ic );
}
Esempio n. 8
0
/**
 * Login method. Since the twitter API works with separate HTTP request we
 * only save the user and pass to the twitter_data object.
 */
static void twitter_login(account_t * acc)
{
	struct im_connection *ic = imcb_new(acc);
	struct twitter_data *td;
	char name[strlen(acc->user) + 9];
	url_t url;
	char *s;
	
	if (!url_set(&url, set_getstr(&ic->acc->set, "base_url")) ||
	    (url.proto != PROTO_HTTP && url.proto != PROTO_HTTPS)) {
		imcb_error(ic, "Incorrect API base URL: %s", set_getstr(&ic->acc->set, "base_url"));
		imc_logout(ic, FALSE);
		return;
	}

	if (!strstr(url.host, "twitter.com") &&
	    set_getbool(&ic->acc->set, "stream")) {
		imcb_error(ic, "Warning: The streaming API is only supported by Twitter, "
		               "and you seem to be connecting to a different service.");
	}

	imcb_log(ic, "Connecting");

	twitter_connections = g_slist_append(twitter_connections, ic);
	td = g_new0(struct twitter_data, 1);
	ic->proto_data = td;
	td->user = g_strdup(acc->user);

	td->url_ssl = url.proto == PROTO_HTTPS;
	td->url_port = url.port;
	td->url_host = g_strdup(url.host);
	if (strcmp(url.file, "/") != 0)
		td->url_path = g_strdup(url.file);
	else {
		td->url_path = g_strdup("");
		if (g_str_has_suffix(url.host, "twitter.com"))
			/* May fire for people who turned on HTTPS. */
			imcb_error(ic, "Warning: Twitter requires a version number in API calls "
			               "now. Try resetting the base_url account setting.");
	}
	
	/* Hacky string mangling: Turn identi.ca into identi.ca and api.twitter.com
	   into twitter, and try to be sensible if we get anything else. */
	td->prefix = g_strdup(url.host);
	if (g_str_has_suffix(td->prefix, ".com"))
		td->prefix[strlen(url.host) - 4] = '\0';
	if ((s = strrchr(td->prefix, '.')) && strlen(s) > 4) {
		/* If we have at least 3 chars after the last dot, cut off the rest.
		   (mostly a www/api prefix or sth) */
		s = g_strdup(s + 1);
		g_free(td->prefix);
		td->prefix = s;
	}
	
	if (strstr(acc->pass, "oauth_token="))
		td->oauth_info = oauth_from_string(acc->pass, get_oauth_service(ic));

	sprintf(name, "%s_%s", td->prefix, acc->user);
	imcb_add_buddy(ic, name, NULL);
	imcb_buddy_status(ic, name, OPT_LOGGED_IN, NULL, NULL);

	td->log = g_new0(struct twitter_log_data, TWITTER_LOG_LENGTH);
	td->log_id = -1;
	
	s = set_getstr(&ic->acc->set, "mode");
	if (g_strcasecmp(s, "one") == 0)
		td->flags |= TWITTER_MODE_ONE;
	else if (g_strcasecmp(s, "many") == 0)
		td->flags |= TWITTER_MODE_MANY;
	else
		td->flags |= TWITTER_MODE_CHAT;

	twitter_login_finish(ic);
}