diff options
author | Jens Georg <mail@jensge.org> | 2022-11-20 19:06:46 +0100 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2022-11-20 19:11:17 +0100 |
commit | f41f01b3387bcdd6fe6ec09b839d74d160ecd18e (patch) | |
tree | 0e11bca02a70f96b6767d746926e5ba142a88029 | |
parent | 3d24d57bdbdabaf6fe623194c65c47de75278ccf (diff) | |
download | gssdp-f41f01b3387bcdd6fe6ec09b839d74d160ecd18e.tar.gz |
client,socket-source: Propagate random port
If the client is configured to use a random port, store the one that is
generated in the port property. That causes the GUPnP context later on
to create the Soup server on that port as well
Fixes part of GUPnP/81
-rw-r--r-- | libgssdp/gssdp-client.c | 8 | ||||
-rw-r--r-- | libgssdp/gssdp-socket-source.c | 46 |
2 files changed, 43 insertions, 11 deletions
diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c index e68f86a..a64515e 100644 --- a/libgssdp/gssdp-client.c +++ b/libgssdp/gssdp-client.c @@ -270,6 +270,13 @@ gssdp_client_initable_init (GInitable *initable, NULL)); if (priv->search_socket != NULL) { + if (priv->msearch_port == 0) { + g_object_get (priv->search_socket, + "port", + &priv->msearch_port, + NULL); + } + gssdp_socket_source_set_callback (priv->search_socket, (GSourceFunc) search_socket_source_cb, @@ -2056,6 +2063,7 @@ init_network_info (GSSDPClient *client, GError **error) g_debug ("Created SSDP client %p", client); g_debug (" iface_name : %s", priv->device.iface_name); g_debug (" host_ip : %s", gssdp_client_get_host_ip (client)); + g_debug (" port : %u", gssdp_client_get_port (client)); g_debug (" server_id : %s", priv->server_id); g_debug (" network : %s", priv->device.network); g_debug (" index : %d", priv->device.index); diff --git a/libgssdp/gssdp-socket-source.c b/libgssdp/gssdp-socket-source.c index b3c8b70..6be3267 100644 --- a/libgssdp/gssdp-socket-source.c +++ b/libgssdp/gssdp-socket-source.c @@ -89,8 +89,17 @@ gssdp_socket_source_get_property (GObject *object, G_GNUC_UNUSED GValue *value, GParamSpec *pspec) { + GSSDPSocketSource *self; + GSSDPSocketSourcePrivate *priv; + + self = GSSDP_SOCKET_SOURCE (object); + priv = gssdp_socket_source_get_instance_private (self); + /* All properties are construct-only, write-only */ switch (property_id) { + case PROP_PORT: + g_value_set_uint (value, priv->port); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -319,6 +328,21 @@ gssdp_socket_source_do_init (GInitable *initable, goto error; } + if (priv->type == GSSDP_SOCKET_SOURCE_TYPE_SEARCH && priv->port == 0) { + GSocketAddress *addr = + g_socket_get_local_address (priv->socket, &inner_error); + + if (inner_error != NULL) { + g_propagate_prefixed_error ( + error, + inner_error, + "Failed to get port from socket"); + } + + priv->port = g_inet_socket_address_get_port ( + G_INET_SOCKET_ADDRESS (addr)); + } + if (priv->type == GSSDP_SOCKET_SOURCE_TYPE_MULTICAST) { /* The 4th argument 'iface_name' can't be NULL even though Glib API doc says you * can. 'NULL' will fail the test. @@ -499,17 +523,17 @@ gssdp_socket_source_class_init (GSSDPSocketSourceClass *klass) G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - g_object_class_install_property - (object_class, - PROP_PORT, - g_param_spec_uint - ("port", - "UDP port", - "UDP port to use for TYPE_SEARCH sockets", - 0, G_MAXUINT16, - 0, - G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + g_object_class_install_property ( + object_class, + PROP_PORT, + g_param_spec_uint ("port", + "UDP port", + "UDP port to use for TYPE_SEARCH sockets", + 0, + G_MAXUINT16, + 0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); g_object_class_install_property (object_class, |