Ejemplo n.º 1
0
static void auth_old_result_cb(JabberStream *js, const char *from,
                               JabberIqType type, const char *id,
                               PurpleXmlNode *packet, gpointer data)
{
	if (type == JABBER_IQ_RESULT) {
		jabber_stream_set_state(js, JABBER_STREAM_POST_AUTH);
		jabber_disco_items_server(js);
	} else {
		PurpleAccount *account;
		PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
		char *msg = jabber_parse_error(js, packet, &reason);
		PurpleXmlNode *error;
		const char *err_code;

		account = purple_connection_get_account(js->gc);

		/* FIXME: Why is this not in jabber_parse_error? */
		if((error = purple_xmlnode_get_child(packet, "error")) &&
					(err_code = purple_xmlnode_get_attrib(error, "code")) &&
					g_str_equal(err_code, "401")) {
			reason = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
			/* Clear the pasword if it isn't being saved */
			if (!purple_account_get_remember_password(account))
				purple_account_set_password(account, NULL, NULL, NULL);
		}

		purple_connection_error(js->gc, reason, msg);
		g_free(msg);
	}
}
Ejemplo n.º 2
0
AccountWindow::BoolOption::BoolOption(PurpleAccount *account_,
    Type type_)
: account(account_), option(NULL), type(type_)
{
  g_assert(account);

  if (type == TYPE_REMEMBER_PASSWORD) {
    setText(_("Remember password"));
    setChecked(purple_account_get_remember_password(account));
  }
  else if (type == TYPE_ENABLE_ACCOUNT) {
    setText(_("Account enabled"));
    setChecked(purple_account_get_enabled(account, PACKAGE_NAME));
  }

  signal_toggle.connect(sigc::mem_fun(this, &BoolOption::onToggle));
}
Ejemplo n.º 3
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.º 4
0
void QuetzalAccount::save()
{
	if (m_isLoading)
		return;
	// Test it
	else
		return;
	Config cfg = config();
	cfg.beginGroup(QLatin1String("general"));
	cfg.setValue(QLatin1String("alias"), purple_account_get_alias(m_account));
	cfg.setValue(QLatin1String("userInfo"), purple_account_get_user_info(m_account));
	if (purple_account_get_remember_password(m_account))
		cfg.setValue(QLatin1String("passwd"), purple_account_get_password(m_account), Config::Crypted);
	else
		cfg.remove(QLatin1String("passwd"));
	QVariantMap settings;
	g_hash_table_foreach(m_account->settings, (GHFunc)quetzal_serialize_node, &settings);
	cfg.setValue(QLatin1String("quetzal_settings"), settings);
}
Ejemplo n.º 5
0
void
msn_session_set_error(MsnSession *session, MsnErrorType error,
					  const char *info)
{
	PurpleConnection *gc;
	PurpleConnectionError reason;
	char *msg;

	if (session->destroying)
		return;

	gc = purple_account_get_connection(session->account);

	switch (error)
	{
		case MSN_ERROR_SERVCONN:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(info);
			break;
		case MSN_ERROR_UNSUPPORTED_PROTOCOL:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(_("Our protocol is not supported by the "
							 "server"));
			break;
		case MSN_ERROR_HTTP_MALFORMED:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(_("Error parsing HTTP"));
			break;
		case MSN_ERROR_SIGN_OTHER:
			reason = PURPLE_CONNECTION_ERROR_NAME_IN_USE;
			msg = g_strdup(_("You have signed on from another location"));
			if (!purple_account_get_remember_password(session->account))
				purple_account_set_password(session->account, NULL, NULL, NULL);
			break;
		case MSN_ERROR_SERV_UNAVAILABLE:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(_("The MSN servers are temporarily "
							 "unavailable. Please wait and try "
							 "again."));
			break;
		case MSN_ERROR_SERV_DOWN:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(_("The MSN servers are going down "
							 "temporarily"));
			break;
		case MSN_ERROR_AUTH:
			reason = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
			msg = g_strdup_printf(_("Unable to authenticate: %s"),
								  (info == NULL ) ?
								  _("Unknown error") : info);
			/* Clear the password if it isn't being saved */
			if (!purple_account_get_remember_password(session->account))
				purple_account_set_password(session->account, NULL, NULL, NULL);
			break;
		case MSN_ERROR_BAD_BLIST:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup_printf(_("Your MSN buddy list is temporarily "
			                        "unavailable: %s"),
			                      (info == NULL) ? _("Unknown error") : info);
			break;
		default:
			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
			msg = g_strdup(_("Unknown error"));
			break;
	}

	msn_session_disconnect(session);

	purple_connection_error(gc, reason, msg);

	g_free(msg);
}
Ejemplo n.º 6
0
/**
 * This function parses the given response from a clientLogin request
 * and extracts the useful information.
 *
 * @param gc           The PurpleConnection.  If the response data does
 *                     not indicate then purple_connection_error_reason()
 *                     will be called to close this connection.
 * @param response     The response data from the clientLogin request.
 * @param response_len The length of the above response, or -1 if
 *                     @response is NUL terminated.
 * @param token        If parsing was successful then this will be set to
 *                     a newly allocated string containing the token.  The
 *                     caller should g_free this string when it is finished
 *                     with it.  On failure this value will be untouched.
 * @param secret       If parsing was successful then this will be set to
 *                     a newly allocated string containing the secret.  The
 *                     caller should g_free this string when it is finished
 *                     with it.  On failure this value will be untouched.
 * @param hosttime     If parsing was successful then this will be set to
 *                     the time on the OpenAuth Server in seconds since the
 *                     Unix epoch.  On failure this value will be untouched.
 *
 * @return TRUE if the request was successful and we were able to
 *         extract all info we need.  Otherwise FALSE.
 */
static gboolean parse_client_login_response(PurpleConnection *gc, const gchar *response, gsize response_len, char **token, char **secret, time_t *hosttime)
{
    xmlnode *response_node, *tmp_node, *data_node;
    xmlnode *secret_node = NULL, *hosttime_node = NULL, *token_node = NULL, *tokena_node = NULL;
    char *tmp;

    /* Parse the response as XML */
    response_node = xmlnode_from_str(response, response_len);
    if (response_node == NULL)
    {
        char *msg;
        purple_debug_error("oscar", "clientLogin could not parse "
                           "response as XML: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        return FALSE;
    }

    /* Grab the necessary XML nodes */
    tmp_node = xmlnode_get_child(response_node, "statusCode");
    data_node = xmlnode_get_child(response_node, "data");
    if (data_node != NULL) {
        secret_node = xmlnode_get_child(data_node, "sessionSecret");
        hosttime_node = xmlnode_get_child(data_node, "hostTime");
        token_node = xmlnode_get_child(data_node, "token");
        if (token_node != NULL)
            tokena_node = xmlnode_get_child(token_node, "a");
    }

    /* Make sure we have a status code */
    if (tmp_node == NULL || (tmp = xmlnode_get_data_unescaped(tmp_node)) == NULL) {
        char *msg;
        purple_debug_error("oscar", "clientLogin response was "
                           "missing statusCode: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        xmlnode_free(response_node);
        return FALSE;
    }

    /* Make sure the status code was 200 */
    if (strcmp(tmp, "200") != 0)
    {
        int status_code, status_detail_code = 0;

        status_code = atoi(tmp);
        g_free(tmp);
        tmp_node = xmlnode_get_child(response_node, "statusDetailCode");
        if (tmp_node != NULL && (tmp = xmlnode_get_data_unescaped(tmp_node)) != NULL) {
            status_detail_code = atoi(tmp);
            g_free(tmp);
        }

        purple_debug_error("oscar", "clientLogin response statusCode "
                           "was %d (%d): %s\n", status_code, status_detail_code, response);

        if (status_code == 330 && status_detail_code == 3011) {
            PurpleAccount *account = purple_connection_get_account(gc);
            if (!purple_account_get_remember_password(account))
                purple_account_set_password(account, NULL);
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
                                           _("Incorrect password"));
        } else if (status_code == 330 && status_detail_code == 3015) {
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
                                           _("Server requested that you fill out a CAPTCHA in order to "
                                             "sign in, but this client does not currently support CAPTCHAs."));
        } else if (status_code == 401 && status_detail_code == 3019) {
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_OTHER_ERROR,
                                           _("AOL does not allow your screen name to authenticate here"));
        } else {
            char *msg;
            msg = generate_error_message(response_node,
                                         URL_CLIENT_LOGIN);
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_OTHER_ERROR, msg);
            g_free(msg);
        }

        xmlnode_free(response_node);
        return FALSE;
    }
    g_free(tmp);

    /* Make sure we have everything else */
    if (data_node == NULL || secret_node == NULL ||
            token_node == NULL || tokena_node == NULL)
    {
        char *msg;
        purple_debug_error("oscar", "clientLogin response was missing "
                           "something: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        xmlnode_free(response_node);
        return FALSE;
    }

    /* Extract data from the XML */
    *token = xmlnode_get_data_unescaped(tokena_node);
    *secret = xmlnode_get_data_unescaped(secret_node);
    tmp = xmlnode_get_data_unescaped(hosttime_node);
    if (*token == NULL || **token == '\0' || *secret == NULL || **secret == '\0' || tmp == NULL || *tmp == '\0')
    {
        char *msg;
        purple_debug_error("oscar", "clientLogin response was missing "
                           "something: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        g_free(*token);
        g_free(*secret);
        g_free(tmp);
        xmlnode_free(response_node);
        return FALSE;
    }

    *hosttime = strtol(tmp, NULL, 10);
    g_free(tmp);

    xmlnode_free(response_node);

    return TRUE;
}
Ejemplo n.º 7
0
static gboolean
flap_connection_destroy_cb(gpointer data)
{
	FlapConnection *conn;
	OscarData *od;
	PurpleAccount *account;
	aim_rxcallback_t userfunc;

	conn = data;
	/* Explicitly added for debugging #5927.  Don't re-order this, only
	 * consider removing it.
	 */
	purple_debug_info("oscar", "Destroying FLAP connection %p\n", conn);

	od = conn->od;
	account = purple_connection_get_account(od->gc);

	purple_debug_info("oscar", "Destroying oscar connection (%p) of "
			"type 0x%04hx.  Disconnect reason is %d\n", conn,
			conn->type, conn->disconnect_reason);

	od->oscar_connections = g_slist_remove(od->oscar_connections, conn);

	if ((userfunc = aim_callhandler(od, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR)))
		userfunc(od, conn, NULL, conn->disconnect_code, conn->error_message);

	/*
	 * TODO: If we don't have a SNAC_FAMILY_LOCATE connection then
	 * we should try to request one instead of disconnecting.
	 */
	if (!account->disconnecting && ((od->oscar_connections == NULL)
			|| (!flap_connection_getbytype(od, SNAC_FAMILY_LOCATE))))
	{
		/* No more FLAP connections!  Sign off this PurpleConnection! */
		gchar *tmp;
		PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;

		if (conn->disconnect_code == 0x0001) {
			reason = PURPLE_CONNECTION_ERROR_NAME_IN_USE;
			tmp = g_strdup(_("You have signed on from another location"));
			if (!purple_account_get_remember_password(account))
				purple_account_set_password(account, NULL);
		} else if (conn->disconnect_reason == OSCAR_DISCONNECT_REMOTE_CLOSED)
			tmp = g_strdup(_("Server closed the connection"));
		else if (conn->disconnect_reason == OSCAR_DISCONNECT_LOST_CONNECTION)
			tmp = g_strdup_printf(_("Lost connection with server: %s"),
					conn->error_message);
		else if (conn->disconnect_reason == OSCAR_DISCONNECT_INVALID_DATA)
			tmp = g_strdup(_("Received invalid data on connection with server"));
		else if (conn->disconnect_reason == OSCAR_DISCONNECT_COULD_NOT_CONNECT)
			tmp = g_strdup_printf(_("Unable to connect: %s"),
					conn->error_message);
		else
			/*
			 * We shouldn't print a message for some disconnect_reasons.
			 * Like OSCAR_DISCONNECT_LOCAL_CLOSED.
			 */
			tmp = NULL;

		if (tmp != NULL)
		{
			purple_connection_error_reason(od->gc, reason, tmp);
			g_free(tmp);
		}
	}

	flap_connection_close(od, conn);

	g_free(conn->error_message);
	g_free(conn->cookie);

	/*
	 * Free conn->internal, if necessary
	 */
	if (conn->type == SNAC_FAMILY_CHAT)
		flap_connection_destroy_chat(od, conn);

	g_slist_free(conn->groups);
	while (conn->rateclasses != NULL)
	{
		g_free(conn->rateclasses->data);
		conn->rateclasses = g_slist_delete_link(conn->rateclasses, conn->rateclasses);
	}

	g_hash_table_destroy(conn->rateclass_members);

	if (conn->queued_snacs) {
		while (!g_queue_is_empty(conn->queued_snacs))
		{
			QueuedSnac *queued_snac;
			queued_snac = g_queue_pop_head(conn->queued_snacs);
			flap_frame_destroy(queued_snac->frame);
			g_free(queued_snac);
		}
		g_queue_free(conn->queued_snacs);
	}

	if (conn->queued_lowpriority_snacs) {
		while (!g_queue_is_empty(conn->queued_lowpriority_snacs))
		{
			QueuedSnac *queued_snac;
			queued_snac = g_queue_pop_head(conn->queued_lowpriority_snacs);
			flap_frame_destroy(queued_snac->frame);
			g_free(queued_snac);
		}
		g_queue_free(conn->queued_lowpriority_snacs);
	}

	if (conn->queued_timeout > 0)
		purple_timeout_remove(conn->queued_timeout);

	g_free(conn);

	return FALSE;
}