mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2025-01-07 12:25:31 +00:00
sip: origin: register with SIP server
This commit is contained in:
parent
017af5ec8b
commit
4521033127
4 changed files with 78 additions and 10 deletions
|
@ -63,6 +63,8 @@ struct _CallsSipOrigin
|
||||||
|
|
||||||
CallsSipMediaManager *media_manager;
|
CallsSipMediaManager *media_manager;
|
||||||
|
|
||||||
|
gboolean auto_connect;
|
||||||
|
|
||||||
/* Account information */
|
/* Account information */
|
||||||
gchar *user;
|
gchar *user;
|
||||||
gchar *password;
|
gchar *password;
|
||||||
|
@ -93,6 +95,7 @@ enum {
|
||||||
PROP_ACC_PORT,
|
PROP_ACC_PORT,
|
||||||
PROP_ACC_PROTOCOL,
|
PROP_ACC_PROTOCOL,
|
||||||
PROP_ACC_DIRECT,
|
PROP_ACC_DIRECT,
|
||||||
|
PROP_ACC_AUTO_CONNECT,
|
||||||
PROP_SIP_CONTEXT,
|
PROP_SIP_CONTEXT,
|
||||||
PROP_ACC_STATE,
|
PROP_ACC_STATE,
|
||||||
PROP_CALLS,
|
PROP_CALLS,
|
||||||
|
@ -449,6 +452,7 @@ static CallsSipHandles *
|
||||||
setup_sip_handles (CallsSipOrigin *self)
|
setup_sip_handles (CallsSipOrigin *self)
|
||||||
{
|
{
|
||||||
CallsSipHandles *oper;
|
CallsSipHandles *oper;
|
||||||
|
g_autofree gchar *registrar_url = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (CALLS_IS_SIP_ORIGIN (self), NULL);
|
g_return_val_if_fail (CALLS_IS_SIP_ORIGIN (self), NULL);
|
||||||
|
|
||||||
|
@ -457,9 +461,10 @@ setup_sip_handles (CallsSipOrigin *self)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registrar_url = g_strconcat (self->protocol_prefix, ":", self->host, NULL);
|
||||||
oper->context = self->ctx;
|
oper->context = self->ctx;
|
||||||
oper->register_handle = nua_handle (self->nua, self->oper,
|
oper->register_handle = nua_handle (self->nua, self->oper,
|
||||||
NUTAG_REGISTRAR (self->host),
|
NUTAG_REGISTRAR (registrar_url),
|
||||||
TAG_END ());
|
TAG_END ());
|
||||||
oper->call_handle = NULL;
|
oper->call_handle = NULL;
|
||||||
|
|
||||||
|
@ -552,9 +557,14 @@ init_sip_account (CallsSipOrigin *self,
|
||||||
/* In the case of a direct connection we're immediately good to go */
|
/* In the case of a direct connection we're immediately good to go */
|
||||||
if (self->use_direct_connection)
|
if (self->use_direct_connection)
|
||||||
self->state = SIP_ACCOUNT_ONLINE;
|
self->state = SIP_ACCOUNT_ONLINE;
|
||||||
else
|
else {
|
||||||
self->state = SIP_ACCOUNT_OFFLINE;
|
self->state = SIP_ACCOUNT_OFFLINE;
|
||||||
|
|
||||||
|
if (self->auto_connect)
|
||||||
|
/* try to go online */
|
||||||
|
calls_sip_origin_go_online (self, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACC_STATE]);
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACC_STATE]);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -773,6 +783,10 @@ calls_sip_origin_set_property (GObject *object,
|
||||||
g_warning ("Setting the account state does not yet have any effect");
|
g_warning ("Setting the account state does not yet have any effect");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_ACC_AUTO_CONNECT:
|
||||||
|
self->auto_connect = g_value_get_boolean (value);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -817,6 +831,10 @@ calls_sip_origin_get_property (GObject *object,
|
||||||
g_value_set_enum (value, self->state);
|
g_value_set_enum (value, self->state);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_ACC_AUTO_CONNECT:
|
||||||
|
g_value_set_boolean (value, self->auto_connect);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -963,6 +981,14 @@ calls_sip_origin_class_init (CallsSipOriginClass *klass)
|
||||||
G_PARAM_READWRITE);
|
G_PARAM_READWRITE);
|
||||||
g_object_class_install_property (object_class, PROP_ACC_STATE, props[PROP_ACC_STATE]);
|
g_object_class_install_property (object_class, PROP_ACC_STATE, props[PROP_ACC_STATE]);
|
||||||
|
|
||||||
|
props[PROP_ACC_AUTO_CONNECT] =
|
||||||
|
g_param_spec_boolean ("auto-connect",
|
||||||
|
"Auto connect",
|
||||||
|
"Automatically try to connect",
|
||||||
|
FALSE,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
|
||||||
|
g_object_class_install_property (object_class, PROP_ACC_AUTO_CONNECT, props[PROP_ACC_AUTO_CONNECT]);
|
||||||
|
|
||||||
#define IMPLEMENTS(ID, NAME) \
|
#define IMPLEMENTS(ID, NAME) \
|
||||||
g_object_class_override_property (object_class, ID, NAME); \
|
g_object_class_override_property (object_class, ID, NAME); \
|
||||||
props[ID] = g_object_class_find_property(object_class, NAME);
|
props[ID] = g_object_class_find_property(object_class, NAME);
|
||||||
|
@ -1017,7 +1043,6 @@ calls_sip_origin_create_inbound (CallsSipOrigin *self,
|
||||||
add_call (self, address, TRUE, handle);
|
add_call (self, address, TRUE, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CallsSipOrigin *
|
CallsSipOrigin *
|
||||||
calls_sip_origin_new (const gchar *name,
|
calls_sip_origin_new (const gchar *name,
|
||||||
CallsSipContext *sip_context,
|
CallsSipContext *sip_context,
|
||||||
|
@ -1026,7 +1051,8 @@ calls_sip_origin_new (const gchar *name,
|
||||||
const gchar *host,
|
const gchar *host,
|
||||||
gint port,
|
gint port,
|
||||||
const gchar *protocol,
|
const gchar *protocol,
|
||||||
gboolean direct_connection)
|
gboolean direct_connection,
|
||||||
|
gboolean auto_connect)
|
||||||
{
|
{
|
||||||
CallsSipOrigin *origin;
|
CallsSipOrigin *origin;
|
||||||
|
|
||||||
|
@ -1040,9 +1066,34 @@ calls_sip_origin_new (const gchar *name,
|
||||||
"port", port,
|
"port", port,
|
||||||
"protocol", protocol,
|
"protocol", protocol,
|
||||||
"direct-connection", direct_connection,
|
"direct-connection", direct_connection,
|
||||||
|
"auto-connect", auto_connect,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
g_string_assign (origin->name, name);
|
g_string_assign (origin->name, name);
|
||||||
|
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
calls_sip_origin_go_online (CallsSipOrigin *self,
|
||||||
|
gboolean online)
|
||||||
|
{
|
||||||
|
g_return_if_fail (CALLS_IS_SIP_ORIGIN (self));
|
||||||
|
|
||||||
|
if (online) {
|
||||||
|
if (self->state == SIP_ACCOUNT_ONLINE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
nua_register (self->oper->register_handle,
|
||||||
|
NUTAG_M_FEATURES("expires=180"),
|
||||||
|
TAG_END ());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (self->state == SIP_ACCOUNT_OFFLINE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
nua_unregister (self->oper->register_handle,
|
||||||
|
TAG_END ());
|
||||||
|
}
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACC_STATE]);
|
||||||
|
}
|
||||||
|
|
|
@ -42,9 +42,11 @@ CallsSipOrigin *calls_sip_origin_new (const gchar *na
|
||||||
const gchar *host,
|
const gchar *host,
|
||||||
gint port,
|
gint port,
|
||||||
const gchar *protocol,
|
const gchar *protocol,
|
||||||
gboolean direct_connection);
|
gboolean direct_connection,
|
||||||
|
gboolean auto_connect);
|
||||||
void calls_sip_origin_create_inbound (CallsSipOrigin *self,
|
void calls_sip_origin_create_inbound (CallsSipOrigin *self,
|
||||||
const gchar *number,
|
const gchar *number,
|
||||||
nua_handle_t *handle);
|
nua_handle_t *handle);
|
||||||
|
void calls_sip_origin_go_online (CallsSipOrigin *self,
|
||||||
|
gboolean online);
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
@ -113,6 +113,10 @@ calls_sip_provider_load_accounts (CallsSipProvider *self)
|
||||||
gint port = 0;
|
gint port = 0;
|
||||||
gboolean direct_connection =
|
gboolean direct_connection =
|
||||||
g_key_file_get_boolean (key_file, groups[i], "Direct", NULL);
|
g_key_file_get_boolean (key_file, groups[i], "Direct", NULL);
|
||||||
|
gboolean auto_connect = TRUE;
|
||||||
|
|
||||||
|
if (g_key_file_has_key (key_file, groups[i], "AutoConnect", NULL))
|
||||||
|
auto_connect = g_key_file_get_boolean (key_file, groups[i], "AutoConnect", NULL);
|
||||||
|
|
||||||
if (direct_connection)
|
if (direct_connection)
|
||||||
goto skip;
|
goto skip;
|
||||||
|
@ -143,7 +147,15 @@ calls_sip_provider_load_accounts (CallsSipProvider *self)
|
||||||
|
|
||||||
g_debug ("Adding origin for SIP account %s", groups[i]);
|
g_debug ("Adding origin for SIP account %s", groups[i]);
|
||||||
|
|
||||||
calls_sip_provider_add_origin (self, groups[i], user, password, host, port, protocol, direct_connection);
|
calls_sip_provider_add_origin (self,
|
||||||
|
groups[i],
|
||||||
|
user,
|
||||||
|
password,
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
protocol,
|
||||||
|
direct_connection,
|
||||||
|
auto_connect);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (groups);
|
g_strfreev (groups);
|
||||||
|
@ -369,7 +381,8 @@ calls_sip_provider_add_origin (CallsSipProvider *self,
|
||||||
const gchar *host,
|
const gchar *host,
|
||||||
gint port,
|
gint port,
|
||||||
const gchar *protocol,
|
const gchar *protocol,
|
||||||
gboolean direct_connection)
|
gboolean direct_connection,
|
||||||
|
gboolean auto_connect)
|
||||||
{
|
{
|
||||||
g_autoptr (CallsSipOrigin) origin = NULL;
|
g_autoptr (CallsSipOrigin) origin = NULL;
|
||||||
|
|
||||||
|
@ -382,7 +395,8 @@ calls_sip_provider_add_origin (CallsSipProvider *self,
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
protocol,
|
protocol,
|
||||||
direct_connection);
|
direct_connection,
|
||||||
|
auto_connect);
|
||||||
|
|
||||||
if (!origin) {
|
if (!origin) {
|
||||||
g_warning ("Could not create CallsSipOrigin");
|
g_warning ("Could not create CallsSipOrigin");
|
||||||
|
|
|
@ -42,6 +42,7 @@ void calls_sip_provider_add_origin (CallsSipProvider *s
|
||||||
const gchar *host,
|
const gchar *host,
|
||||||
gint port,
|
gint port,
|
||||||
const gchar *protocol,
|
const gchar *protocol,
|
||||||
gboolean direct_connection);
|
gboolean direct_connection,
|
||||||
|
gboolean auto_connect);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
Loading…
Reference in a new issue