2015-12-10 12:54:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of matrix-glib-sdk
|
|
|
|
|
*
|
|
|
|
|
* matrix-glib-sdk is free software: you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation, either
|
|
|
|
|
* version 3 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* matrix-glib-sdk is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
|
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
* See the GNU Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with matrix-glib-sdk. If not, see
|
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "matrix-client.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SECTION:matrix-client
|
2016-01-21 15:23:13 +00:00
|
|
|
|
* @short_description: Base interface for communication with a Matrix.org server
|
2015-12-10 12:54:15 +00:00
|
|
|
|
* @title: MatrixClient
|
|
|
|
|
* @stability: Unstable
|
2016-01-21 15:23:13 +00:00
|
|
|
|
* @include: matrix-glib/matrix-client.h
|
2015-12-10 12:54:15 +00:00
|
|
|
|
*
|
2016-01-21 15:23:13 +00:00
|
|
|
|
* This is the base interface for client communication with a
|
|
|
|
|
* Matrix.org server.
|
2015-12-10 12:54:15 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2016-01-21 15:23:13 +00:00
|
|
|
|
* MatrixClientInterface:
|
|
|
|
|
* @login_with_password: virtual function for
|
|
|
|
|
* matrix_client_login_with_password()
|
|
|
|
|
* @register_with_password: virtual function for
|
|
|
|
|
* matrix_client_register_with_password()
|
|
|
|
|
* @logout: virtual function for matrix_client_logout()
|
|
|
|
|
* @refresh_token: virtual function for matrix_client_refresh_token()
|
|
|
|
|
* @begin_polling: virtual function for matrix_client_begin_polling()
|
|
|
|
|
* @stop_polling: virtual function for matrix_client_stop_polling()
|
2015-12-10 12:54:15 +00:00
|
|
|
|
*
|
2016-01-21 15:23:13 +00:00
|
|
|
|
* The interface vtable for #MatrixClient
|
2015-12-10 12:54:15 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2016-01-21 15:23:13 +00:00
|
|
|
|
* MatrixClient:
|
2015-12-10 12:54:15 +00:00
|
|
|
|
*
|
2016-01-21 15:23:13 +00:00
|
|
|
|
* The MatrixClient object’s interface definition.
|
2015-12-10 12:54:15 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2016-01-21 15:23:13 +00:00
|
|
|
|
G_DEFINE_INTERFACE(MatrixClient, matrix_client, G_TYPE_OBJECT);
|
2015-12-10 12:54:15 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2016-01-21 15:23:13 +00:00
|
|
|
|
matrix_client_default_init(MatrixClientInterface *iface)
|
2015-12-10 12:54:15 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-21 15:23:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* matrix_client_login_with_password:
|
|
|
|
|
* @client: a #MatrixClient
|
|
|
|
|
* @username: the username to login with
|
|
|
|
|
* @password: the password to use
|
|
|
|
|
*
|
|
|
|
|
* Authenticate with the Matrix.org server with a username and
|
|
|
|
|
* password.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
matrix_client_login_with_password(MatrixClient *client,
|
|
|
|
|
const gchar *username,
|
|
|
|
|
const gchar *password)
|
2015-12-10 12:54:15 +00:00
|
|
|
|
{
|
2016-01-21 15:23:13 +00:00
|
|
|
|
g_return_if_fail(MATRIX_IS_CLIENT(client));
|
2015-12-10 12:54:15 +00:00
|
|
|
|
|
2016-01-21 15:23:13 +00:00
|
|
|
|
MATRIX_CLIENT_GET_IFACE(client)
|
|
|
|
|
->login_with_password(client, username, password);
|
2015-12-10 12:54:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-21 15:23:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* matrix_client_register_with_password:
|
|
|
|
|
* @client: a #MatrixClient
|
|
|
|
|
* @username: (allow-none): the username to register. If omitted, the
|
|
|
|
|
* server will generate one
|
|
|
|
|
* @password: the password to use with the registration
|
|
|
|
|
*
|
|
|
|
|
* Register @username with the homeserver.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
matrix_client_register_with_password(MatrixClient *client,
|
|
|
|
|
const gchar *username,
|
|
|
|
|
const gchar *password)
|
2015-12-10 12:54:15 +00:00
|
|
|
|
{
|
2016-01-21 15:23:13 +00:00
|
|
|
|
g_return_if_fail(MATRIX_IS_CLIENT(client));
|
2015-12-10 12:54:15 +00:00
|
|
|
|
|
2016-01-21 15:23:13 +00:00
|
|
|
|
MATRIX_CLIENT_GET_IFACE(client)
|
|
|
|
|
->register_with_password(client, username, password);
|
2015-12-10 12:54:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-21 15:23:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* matrix_client_logout:
|
|
|
|
|
* @client: a #MatrixClient
|
|
|
|
|
*
|
|
|
|
|
* Logout from the homeserver. As Matrix.org doesn’t have such an
|
|
|
|
|
* option, this cancels all ongoing requests and clears the
|
|
|
|
|
* authentication data (e.g. tokens).
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
matrix_client_logout(MatrixClient *client)
|
2015-12-10 12:54:15 +00:00
|
|
|
|
{
|
2016-01-21 15:23:13 +00:00
|
|
|
|
g_return_if_fail(MATRIX_IS_CLIENT(client));
|
2015-12-10 12:54:15 +00:00
|
|
|
|
|
2016-01-21 15:23:13 +00:00
|
|
|
|
MATRIX_CLIENT_GET_IFACE(client)
|
|
|
|
|
->logout(client);
|
2015-12-10 12:54:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-21 15:23:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* matrix_client_refresh_token:
|
|
|
|
|
* @client: a #MatrixClient
|
|
|
|
|
*
|
|
|
|
|
* Request a new authentication token from the server.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
matrix_client_refresh_token(MatrixClient *client)
|
2015-12-10 12:54:15 +00:00
|
|
|
|
{
|
2016-01-21 15:23:13 +00:00
|
|
|
|
g_return_if_fail(MATRIX_IS_CLIENT(client));
|
|
|
|
|
|
|
|
|
|
MATRIX_CLIENT_GET_IFACE(client)
|
|
|
|
|
->refresh_token(client);
|
2015-12-10 12:54:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-21 15:23:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* matrix_client_begin_polling:
|
|
|
|
|
* @client: a #MatrixClient
|
|
|
|
|
*
|
2016-01-22 10:34:04 +00:00
|
|
|
|
* Begin polling the event stream.
|
2016-01-21 15:23:13 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
matrix_client_begin_polling(MatrixClient *client)
|
2015-12-10 12:54:15 +00:00
|
|
|
|
{
|
2016-01-21 15:23:13 +00:00
|
|
|
|
g_return_if_fail(MATRIX_IS_CLIENT(client));
|
2015-12-10 12:54:15 +00:00
|
|
|
|
|
2016-01-21 15:23:13 +00:00
|
|
|
|
MATRIX_CLIENT_GET_IFACE(client)
|
|
|
|
|
->begin_polling(client);
|
2015-12-10 12:54:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-01-21 15:23:13 +00:00
|
|
|
|
* matrix_client_stop_polling:
|
|
|
|
|
* @client: a #MatrixClient
|
|
|
|
|
* @cancel_ongoing: if %TRUE, ongoing requests will be cancelled, too
|
2015-12-10 12:54:15 +00:00
|
|
|
|
*
|
2016-01-21 15:23:13 +00:00
|
|
|
|
* Stop polling the event stream. If @cancel_ongoing is %TRUE, ongoing
|
|
|
|
|
* requests will be cancelled, too.
|
2015-12-10 12:54:15 +00:00
|
|
|
|
*/
|
2016-01-21 15:23:13 +00:00
|
|
|
|
void
|
|
|
|
|
matrix_client_stop_polling(MatrixClient *client, gboolean cancel_ongoing)
|
2015-12-10 12:54:15 +00:00
|
|
|
|
{
|
2016-01-21 15:23:13 +00:00
|
|
|
|
g_return_if_fail(MATRIX_IS_CLIENT(client));
|
|
|
|
|
|
|
|
|
|
MATRIX_CLIENT_GET_IFACE(client)
|
|
|
|
|
->stop_polling(client, cancel_ongoing);
|
2015-12-10 12:54:15 +00:00
|
|
|
|
}
|