mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2025-01-06 03: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;
|
||||
|
||||
gboolean auto_connect;
|
||||
|
||||
/* Account information */
|
||||
gchar *user;
|
||||
gchar *password;
|
||||
|
@ -93,6 +95,7 @@ enum {
|
|||
PROP_ACC_PORT,
|
||||
PROP_ACC_PROTOCOL,
|
||||
PROP_ACC_DIRECT,
|
||||
PROP_ACC_AUTO_CONNECT,
|
||||
PROP_SIP_CONTEXT,
|
||||
PROP_ACC_STATE,
|
||||
PROP_CALLS,
|
||||
|
@ -449,6 +452,7 @@ static CallsSipHandles *
|
|||
setup_sip_handles (CallsSipOrigin *self)
|
||||
{
|
||||
CallsSipHandles *oper;
|
||||
g_autofree gchar *registrar_url = NULL;
|
||||
|
||||
g_return_val_if_fail (CALLS_IS_SIP_ORIGIN (self), NULL);
|
||||
|
||||
|
@ -457,9 +461,10 @@ setup_sip_handles (CallsSipOrigin *self)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
registrar_url = g_strconcat (self->protocol_prefix, ":", self->host, NULL);
|
||||
oper->context = self->ctx;
|
||||
oper->register_handle = nua_handle (self->nua, self->oper,
|
||||
NUTAG_REGISTRAR (self->host),
|
||||
NUTAG_REGISTRAR (registrar_url),
|
||||
TAG_END ());
|
||||
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 */
|
||||
if (self->use_direct_connection)
|
||||
self->state = SIP_ACCOUNT_ONLINE;
|
||||
else
|
||||
else {
|
||||
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]);
|
||||
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");
|
||||
break;
|
||||
|
||||
case PROP_ACC_AUTO_CONNECT:
|
||||
self->auto_connect = g_value_get_boolean (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
|
@ -817,6 +831,10 @@ calls_sip_origin_get_property (GObject *object,
|
|||
g_value_set_enum (value, self->state);
|
||||
break;
|
||||
|
||||
case PROP_ACC_AUTO_CONNECT:
|
||||
g_value_set_boolean (value, self->auto_connect);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
|
@ -963,6 +981,14 @@ calls_sip_origin_class_init (CallsSipOriginClass *klass)
|
|||
G_PARAM_READWRITE);
|
||||
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) \
|
||||
g_object_class_override_property (object_class, ID, 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);
|
||||
}
|
||||
|
||||
|
||||
CallsSipOrigin *
|
||||
calls_sip_origin_new (const gchar *name,
|
||||
CallsSipContext *sip_context,
|
||||
|
@ -1026,7 +1051,8 @@ calls_sip_origin_new (const gchar *name,
|
|||
const gchar *host,
|
||||
gint port,
|
||||
const gchar *protocol,
|
||||
gboolean direct_connection)
|
||||
gboolean direct_connection,
|
||||
gboolean auto_connect)
|
||||
{
|
||||
CallsSipOrigin *origin;
|
||||
|
||||
|
@ -1040,9 +1066,34 @@ calls_sip_origin_new (const gchar *name,
|
|||
"port", port,
|
||||
"protocol", protocol,
|
||||
"direct-connection", direct_connection,
|
||||
"auto-connect", auto_connect,
|
||||
NULL);
|
||||
|
||||
g_string_assign (origin->name, name);
|
||||
|
||||
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,
|
||||
gint port,
|
||||
const gchar *protocol,
|
||||
gboolean direct_connection);
|
||||
gboolean direct_connection,
|
||||
gboolean auto_connect);
|
||||
void calls_sip_origin_create_inbound (CallsSipOrigin *self,
|
||||
const gchar *number,
|
||||
nua_handle_t *handle);
|
||||
|
||||
void calls_sip_origin_go_online (CallsSipOrigin *self,
|
||||
gboolean online);
|
||||
G_END_DECLS
|
||||
|
|
|
@ -113,6 +113,10 @@ calls_sip_provider_load_accounts (CallsSipProvider *self)
|
|||
gint port = 0;
|
||||
gboolean direct_connection =
|
||||
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)
|
||||
goto skip;
|
||||
|
@ -143,7 +147,15 @@ calls_sip_provider_load_accounts (CallsSipProvider *self)
|
|||
|
||||
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);
|
||||
|
@ -369,7 +381,8 @@ calls_sip_provider_add_origin (CallsSipProvider *self,
|
|||
const gchar *host,
|
||||
gint port,
|
||||
const gchar *protocol,
|
||||
gboolean direct_connection)
|
||||
gboolean direct_connection,
|
||||
gboolean auto_connect)
|
||||
{
|
||||
g_autoptr (CallsSipOrigin) origin = NULL;
|
||||
|
||||
|
@ -382,7 +395,8 @@ calls_sip_provider_add_origin (CallsSipProvider *self,
|
|||
host,
|
||||
port,
|
||||
protocol,
|
||||
direct_connection);
|
||||
direct_connection,
|
||||
auto_connect);
|
||||
|
||||
if (!origin) {
|
||||
g_warning ("Could not create CallsSipOrigin");
|
||||
|
|
|
@ -42,6 +42,7 @@ void calls_sip_provider_add_origin (CallsSipProvider *s
|
|||
const gchar *host,
|
||||
gint port,
|
||||
const gchar *protocol,
|
||||
gboolean direct_connection);
|
||||
gboolean direct_connection,
|
||||
gboolean auto_connect);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
Loading…
Reference in a new issue