Ejemplo n.º 1
0
static void
set_account(GtkListStore *store, GtkTreeIter *iter, PurpleAccount *account)
{
  GdkPixbuf *pixbuf;
  GdkPixbuf *scale;

  scale = NULL;

  pixbuf = pidgin_create_prpl_icon(account, 0.5);

  if (pixbuf != NULL)
  {
    scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, GDK_INTERP_BILINEAR);

    if (purple_account_is_disconnected(account))
      gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE);
  }

  gtk_list_store_set(store, iter,
    COLUMN_ICON, scale,
    COLUMN_SCREENNAME, purple_account_get_username(account),
    COLUMN_ENABLED, ap_account_has_profile_enabled(account),
    COLUMN_PROTOCOL, purple_account_get_protocol_name(account),
    COLUMN_DATA, account,
    -1);

  if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf));
  if (scale  != NULL) g_object_unref(G_OBJECT(scale));
}
Ejemplo n.º 2
0
static void
purple_protocol_finalize(GObject *object)
{
	PurpleProtocol *protocol = PURPLE_PROTOCOL(object);
	GList *accounts, *l;

	accounts = purple_accounts_get_all_active();
	for (l = accounts; l != NULL; l = l->next) {
		PurpleAccount *account = PURPLE_ACCOUNT(l->data);
		if (purple_account_is_disconnected(account))
			continue;

		if (purple_strequal(protocol->id,
				purple_account_get_protocol_id(account)))
			purple_account_disconnect(account);
	}

	g_list_free(accounts);

	purple_request_close_with_handle(protocol);
	purple_notify_close_with_handle(protocol);

	purple_signals_disconnect_by_handle(protocol);
	purple_signals_unregister_by_instance(protocol);

	purple_prefs_disconnect_by_handle(protocol);

	user_splits_free(protocol);
	account_options_free(protocol);
	icon_spec_free(protocol);

	PURPLE_DBUS_UNREGISTER_POINTER(protocol);

	parent_class->finalize(object);
}
Ejemplo n.º 3
0
static void
pb_fetch_url(PushBulletAccount *pba, const gchar *url, const gchar *postdata, PushBulletProxyCallbackFunc callback, gpointer user_data)
{
	PurpleAccount *account;
	GString *headers;
    gchar *host = NULL, *path = NULL, *user = NULL, *password = NULL;
    int port;
	PushBulletProxyConnection *conn;
	
	account = pba->account;
	if (purple_account_is_disconnected(account)) return;
	
	conn = g_new0(PushBulletProxyConnection, 1);
	conn->pba = pba;
	conn->callback = callback;
	conn->user_data = user_data;
    
    purple_url_parse(url, &host, &port, &path, &user, &password);
	purple_debug_info("pushbullet", "Fetching url %s\n", url);
	
	headers = g_string_new(NULL);
	
	//Use the full 'url' until libpurple can handle path's longer than 256 chars
	g_string_append_printf(headers, "%s /%s HTTP/1.0\r\n", (postdata ? "POST" : "GET"), path);
	//g_string_append_printf(headers, "%s %s HTTP/1.0\r\n", (postdata ? "POST" : "GET"), url);
    g_string_append_printf(headers, "Connection: close\r\n");
    g_string_append_printf(headers, "Host: %s\r\n", host);
    g_string_append_printf(headers, "Accept: */*\r\n");
	g_string_append_printf(headers, "User-Agent: Pidgin\r\n");
    
    if(pba->access_token && *(pba->access_token)) {
        g_string_append_printf(headers, "Authorization: Bearer %s\r\n", pba->access_token);
    }
    
    if(postdata) {
		purple_debug_info("mightytext", "With postdata %s\n", postdata);
		
		if (postdata[0] == '{') {
			g_string_append(headers, "Content-Type: application/json\r\n");
		} else {
			g_string_append(headers, "Content-Type: application/x-www-form-urlencoded\r\n");
		}
        g_string_append_printf(headers, "Content-Length: %d\r\n", strlen(postdata));
        g_string_append(headers, "\r\n");
        
        g_string_append(headers, postdata);
    } else {
        g_string_append(headers, "\r\n");
    }
    
    g_free(host);
    g_free(path);
    g_free(user);
    g_free(password);
    
    purple_util_fetch_url_request_len_with_account(pba->account, url, FALSE, "Pidgin", TRUE, headers->str, FALSE, 6553500, pb_response_callback, conn);
	
	g_string_free(headers, TRUE);
}
Ejemplo n.º 4
0
static void
do_prpl_change_account_status(PurpleAccount *account,
								PurpleStatus *old_status, PurpleStatus *new_status)
{
	PurplePlugin *prpl;
	PurplePluginProtocolInfo *prpl_info;

	if (purple_status_is_online(new_status) &&
		purple_account_is_disconnected(account) &&
		purple_network_is_available())
	{
		purple_account_connect(account);
		return;
	}

	if (!purple_status_is_online(new_status))
	{
		if (!purple_account_is_disconnected(account))
			purple_account_disconnect(account);
		/* Clear out the unsaved password if we're already disconnected and we switch to offline status */
		else if (!purple_account_get_remember_password(account))
			purple_account_set_password(account, NULL);
		return;
	}

	if (purple_account_is_connecting(account))
		/*
		 * We don't need to call the set_status PRPL function because
		 * the PRPL will take care of setting its status during the
		 * connection process.
		 */
		return;

	prpl = purple_find_prpl(purple_account_get_protocol_id(account));

	if (prpl == NULL)
		return;

	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

	if (!purple_account_is_disconnected(account) && prpl_info->set_status != NULL)
	{
		prpl_info->set_status(account, new_status);
	}
}
Ejemplo n.º 5
0
void
_purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data)
{
	/* Lots of copy/pasted code to avoid API changes. You might want to integrate that into the previous function when posssible. */
	PurpleConnection *gc;
	PurplePlugin *prpl;
	PurplePluginProtocolInfo *prpl_info;

	g_return_if_fail(account != NULL);

	prpl = purple_find_prpl(purple_account_get_protocol_id(account));

	if (prpl != NULL)
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
	else {
		gchar *message;

		message = g_strdup_printf(_("Missing protocol plugin for %s"),
								  purple_account_get_username(account));
		purple_notify_error(NULL, _("Unregistration Error"), message, NULL);
		g_free(message);
		return;
	}

	if (!purple_account_is_disconnected(account)) {
		prpl_info->unregister_user(account, cb, user_data);
		return;
	}

	if (((password == NULL) || (*password == '\0')) &&
		!(prpl_info->options & OPT_PROTO_NO_PASSWORD) &&
		!(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL))
	{
		purple_debug_error("connection", "Cannot connect to account %s without "
						   "a password.\n", purple_account_get_username(account));
		return;
	}

	gc = g_new0(PurpleConnection, 1);
	PURPLE_DBUS_REGISTER_POINTER(gc, PurpleConnection);

	gc->prpl = prpl;
	if ((password != NULL) && (*password != '\0'))
		gc->password = g_strdup(password);
	purple_connection_set_account(gc, account);
	purple_connection_set_state(gc, PURPLE_CONNECTING);
	connections = g_list_append(connections, gc);
	purple_account_set_connection(account, gc);

	purple_signal_emit(purple_connections_get_handle(), "signing-on", gc);

	purple_debug_info("connection", "Unregistering.  gc = %p\n", gc);

	prpl_info->unregister_user(account, cb, user_data);
}
Ejemplo n.º 6
0
void client_enable_account(PurpleAccount *account) {

	if ((account) && !purple_account_get_enabled(account, UI_ID)) {
		LM_DBG("account %s disabled, enabling...\n", account->username);
		purple_account_set_enabled(account, UI_ID, TRUE);
	}

	if ((account) && purple_account_is_disconnected(account)) {
		LM_DBG("account %s disconnected, reconnecting...\n", account->username);
		purple_account_connect(account);
		LM_DBG("account %s connection called\n", account->username);
	}
}
Ejemplo n.º 7
0
void jidgin_worker_cb_signon(PurpleConnection *gc, gpointer signal)
{
  PurpleAccount *account = purple_connection_get_account(gc);

  if (purple_account_is_disconnected(account)) {
    jidgin_log(LOG_ERR, "[purple_account_is_disconnected]%s %d\n",
        purple_account_get_username(account), retry_count);
    jidgin_worker_cb_retry(account);
  } else {
    jidgin_worker_get_uptime_str();
    jidgin_log(LOG_INFO, "[purple_account_is_connected]%s\n",
        purple_account_get_username(account));
  }
}
Ejemplo n.º 8
0
static void pidgin_connection_network_connected (void)
{
	GList *list, *l;
	PidginBuddyList *gtkblist = pidgin_blist_get_default_gtk_blist();

	if(gtkblist)
		pidgin_status_box_set_network_available(PIDGIN_STATUS_BOX(gtkblist->statusbox), TRUE);

	l = list = purple_accounts_get_all_active();
	while (l) {
		PurpleAccount *account = (PurpleAccount*)l->data;
		g_hash_table_remove(auto_reconns, account);
		if (purple_account_is_disconnected(account))
			do_signon(account);
		l = l->next;
	}
	g_list_free(list);
}
Ejemplo n.º 9
0
static void pipe_handle_message(struct purple_message *message) {
	LM_DBG("handling message cmd\n");
	PurpleAccount *account = NULL;
	extern_account_t *accounts = NULL;
	extern_user_t *users = NULL;
	int naccounts = 0, nusers = 0;
	int i, j;

	PurpleConversation *conv = NULL;
	LM_DBG("calling find_accounts(\"%s\", &naccounts)\n", message->from);
	accounts = find_accounts(message->from, &naccounts);
	LM_DBG("found %d extra account(s) for <%s>", naccounts, message->from);

	LM_DBG("calling find_users(\"%s\", &nusers)\n", message->to);
	users = find_users(message->to, &nusers);
	LM_DBG("found %d extra user(s) for <%s>", nusers, message->to);

	for (i = 0; i < naccounts; i++) {
		LM_DBG("calling client_find_account(\"%s\")\n", accounts[i].username);
		account = client_find_account(&accounts[i]);
		if ((account) && purple_account_is_connected(account)) {
			//enable_account(account);
			for (j = 0; j < nusers; j++) {
				if (!strcmp(accounts[i].protocol, users[j].protocol)) {
					LM_DBG("mathing protocol found: %s\n", accounts[i].protocol);
					conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, users[j].username, account);
					if (conv == NULL)
						conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, users[j].username);
					purple_conv_im_send(purple_conversation_get_im_data(conv), message->body);
					break;
				}
			}
		}
		else if (account == NULL)
			LM_DBG("not account found neither created\n");
		else if (purple_account_is_disconnected(account))
			LM_DBG("account is disconnected cannot send message\n");
	}
	if (accounts)
		extern_account_free(accounts, naccounts);
	if (users)
		extern_user_free(users, nusers);

}
Ejemplo n.º 10
0
static void pidgin_connection_network_disconnected (void)
{
	GList *list, *l;
	PidginBuddyList *gtkblist = pidgin_blist_get_default_gtk_blist();

	if(gtkblist)
		pidgin_status_box_set_network_available(PIDGIN_STATUS_BOX(gtkblist->statusbox), FALSE);

	l = list = purple_accounts_get_all_active();
	while (l) {
		PurpleAccount *a = (PurpleAccount*)l->data;
		if (!purple_account_is_disconnected(a)) {
			char *password = g_strdup(purple_account_get_password(a));
			purple_account_disconnect(a);
			purple_account_set_password(a, password);
			g_free(password);
		}
		l = l->next;
	}
	g_list_free(list);
}
Ejemplo n.º 11
0
gboolean jidgin_worker_send_im(PurpleAccount *account, PurpleConversation *conv, pJidginMsg pmsg) {
  PurpleBuddy *buddy;
  char *reply;
  pJidginSetting setting = jidgin_core_get_purple_settings();

  if (!account) {
    account = jidgin_core_get_primary_account();
  }

  if (purple_account_is_disconnected(account)) {
    jidgin_log(LOG_INFO, "[jidgin_worker_send_im]%s disconnected\n",
        purple_account_get_username(account));
    jidgin_worker_cb_retry(account);
    return FALSE;
  }

  if (!conv) {
    buddy = purple_find_buddy(account, pmsg->from);
    if (!buddy) {
      if (setting && setting->is_force_mt)
        buddy = purple_buddy_new(account, pmsg->from, pmsg->from);
      else
        return FALSE;
    }
    conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, buddy->account, pmsg->from);
  }

  jidgin_log(LOG_INFO, "[jidgin_worker_send_im]%s %s\n",
      purple_account_get_username(account), pmsg->from);

  if (jidgin_intercept_postrouting(pmsg->msg, &reply)) {
    g_free(pmsg->msg);
    pmsg->msg = reply;
  }
  purple_conv_im_send(PURPLE_CONV_IM(conv), pmsg->msg);

  return TRUE;
}
Ejemplo n.º 12
0
void
_purple_connection_new(PurpleAccount *account, gboolean regist, const char *password)
{
	PurpleConnection *gc;
	PurplePlugin *prpl;
	PurplePluginProtocolInfo *prpl_info;

	g_return_if_fail(account != NULL);

	if (!purple_account_is_disconnected(account))
		return;

	prpl = purple_find_prpl(purple_account_get_protocol_id(account));

	if (prpl != NULL)
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
	else {
		gchar *message;

		message = g_strdup_printf(_("Missing protocol plugin for %s"),
			purple_account_get_username(account));
		purple_notify_error(NULL, regist ? _("Registration Error") :
						  _("Connection Error"), message, NULL);
		g_free(message);
		return;
	}

	if (regist)
	{
		if (prpl_info->register_user == NULL)
			return;
	}
	else
	{
		if (((password == NULL) || (*password == '\0')) &&
			!(prpl_info->options & OPT_PROTO_NO_PASSWORD) &&
			!(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL))
		{
			purple_debug_error("connection", "Cannot connect to account %s without "
							 "a password.\n", purple_account_get_username(account));
			return;
		}
	}

	gc = g_new0(PurpleConnection, 1);
	PURPLE_DBUS_REGISTER_POINTER(gc, PurpleConnection);

	gc->prpl = prpl;
	if ((password != NULL) && (*password != '\0'))
		gc->password = g_strdup(password);
	purple_connection_set_account(gc, account);
	purple_connection_set_state(gc, PURPLE_CONNECTING);
	connections = g_list_append(connections, gc);
	purple_account_set_connection(account, gc);

	purple_signal_emit(purple_connections_get_handle(), "signing-on", gc);

	if (regist)
	{
		purple_debug_info("connection", "Registering.  gc = %p\n", gc);

		/* set this so we don't auto-reconnect after registering */
		gc->wants_to_die = TRUE;

		prpl_info->register_user(account);
	}
	else
	{
		purple_debug_info("connection", "Connecting. gc = %p\n", gc);

		purple_signal_emit(purple_accounts_get_handle(), "account-connecting", account);
		prpl_info->login(account);
	}
}