示例#1
0
void
ft_connection_open_cb (LmConnection *conn, gboolean success, gpointer u)
{
        ft_state *state = (ft_state *)u;
        if (success) {
                do_set_conn_status (FT_CONN);
                PRINTF ("%s",_("Connected."));
        }
        else {
                do_set_conn_status (FT_DEAD);
                PRINTF ("%s",_("Could not connect."));
                return;
        }

        PRINTF ("%s",_("Authenticating ..."));
        fflush(stdout);

        lm_connection_authenticate (conn, state->jid.node, state->password,
                                    state->jid.resource, ft_authenticate_cb,
                                    NULL, g_free, NULL);
}
bool XMPPAccountHandler::authenticate()
{
	UT_DEBUGMSG(("XMPPAccountHandler::authenticate()\n"));

	UT_return_val_if_fail(m_pConnection, false);

	// try to request a frame here; note that this might return 0, for example on application startup
	XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame();
	
	const std::string server = getProperty("server");
	const std::string username = getProperty("username");
	const std::string password = getProperty("password");
	const std::string resource = getProperty("resource");
	
	GError* error = NULL;
	if (!lm_connection_authenticate(m_pConnection, username.c_str(), password.c_str(),
				resource.c_str(), lm_connection_authenticate_async_cb, this, NULL, &error))
	{
		UT_DEBUGMSG(("connect() - couldn't authenticate with '%s' '%s':\n%s\n", 
				username.c_str(), password.c_str(), (error ? error->message : "")));
				
		lm_connection_close(m_pConnection, NULL);
		lm_connection_unref(m_pConnection);
		m_pConnection = NULL;
		
		if (pFrame)
		{
			// inform the user of the authentication failure
			// TODO: this shouldn't be here, the caller should handle this
			UT_UTF8String msg;
			// TODO: make this localizable
			UT_UTF8String_sprintf(msg, "Error while connecting to %s: %s\n", server.c_str(), (error ? error->message : "")); 
			pFrame->showMessageBox(msg.utf8_str(), XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK);
		}

		return  false;
	}

	return true;
}	
示例#3
0
void
LM::Account::on_connection_opened (bool result)
{
  if (result) {

    xmlChar* user = xmlGetProp (node, BAD_CAST "user");
    xmlChar* password = xmlGetProp (node, BAD_CAST "password");
    xmlChar* resource = xmlGetProp (node, BAD_CAST "resource");
    status = _("authenticating");
    lm_connection_authenticate (connection, (const char*)user,
				(const char*)password, (const char*)resource,
				(LmResultFunction)on_authenticate_c, this, NULL, NULL);
    xmlFree (password);
    xmlFree (resource);
    updated ();
  } else {

    /* FIXME: can't we report better? */
    status = _("error connecting");
    updated ();
  }
}
示例#4
0
文件: harmony.c 项目: KDE/amarok
void open_connection_callback(LmConnection* connection, gboolean success, gpointer void_harmony) {
    GError *err = NULL;
    MP3tunesHarmony* harmony = MP3TUNES_HARMONY(void_harmony);
    LmMessage *message;

    if (!success) {
        error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Failed to open connection", err);
        return;
    }

    message = lm_message_new_with_sub_type(NULL,
                                           LM_MESSAGE_TYPE_PRESENCE,
                                           LM_MESSAGE_SUB_TYPE_AVAILABLE);
    lm_connection_send(connection, message, &err);
    lm_message_unref(message);
    if (err != NULL) {
        error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Sending presence message failed", err);
        return;
    }

    /* Authenticate, known */
    if (harmony->device_email != NULL && harmony->device_pin != NULL) {
        if (!lm_connection_authenticate(connection,
                                        harmony->device_formatted_email,
                                        g_strdup_printf("PIN-%s", harmony->device_pin),
                                        harmony->device_pin,
                                        (LmResultFunction) authenticate_known_callback,
                                        harmony,
                                        NULL,
                                        &err)) {
            if (err != NULL) {
                error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Sending authentication failed", err);
            }
            return;
        }
        return;
    }

    /* Authenticate, unknown */
    if (harmony->device_identifier != NULL && 
        harmony->device_pin        != NULL && 
        strncmp(harmony->device_pin, "NULL", 4) != 0) {
        if (!lm_connection_authenticate(connection,
                                        harmony->device_identifier,
                                        MP3TUNES_HARMONY_DEFAULT_PASSWORD,
                                        harmony->device_pin,
                                        (LmResultFunction) authenticate_unknown_callback,
                                        harmony,
                                        NULL,
                                        &err)) {
            if (err != NULL) {
                error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Sending authentication failed", err);
            }
            return;
        }
        return;
    }

    /* Authenticate, new */
    if (harmony->device_identifier != NULL) {
        if (!lm_connection_authenticate(connection,
                                        harmony->device_identifier,
                                        MP3TUNES_HARMONY_DEFAULT_PASSWORD,
                                        harmony->device_pin,
                                        (LmResultFunction) authenticate_new_callback,
                                        harmony,
                                        NULL,
                                        &err)) {
            if (err != NULL) {
                error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Sending authentication failed", err);
            }
            return;
        }
        return;
    }

    error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "A device identifier is required to authenticate", NULL);
    return;
}