summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2022-08-05 08:59:38 +0200
committerJens Georg <mail@jensge.org>2022-08-05 09:31:54 +0200
commit669f99208000089d3c1705d160091f8ea025eac9 (patch)
tree6730c938e5e82767f62d790c730a2eef05d7f6f7
parent5ef7a31a1b10349eee6f2a9b8b52e13a9e8f1ac7 (diff)
downloadgssdp-669f99208000089d3c1705d160091f8ea025eac9.tar.gz
Client: Fix host-ip handling
Make host-ip construct-only (anything else does not make any sense anyway) and only fill host-addr from it after creation, in init
-rw-r--r--libgssdp/gssdp-client.c71
1 files changed, 50 insertions, 21 deletions
diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c
index 3bd6008..e9bd4e9 100644
--- a/libgssdp/gssdp-client.c
+++ b/libgssdp/gssdp-client.c
@@ -382,14 +382,8 @@ gssdp_client_set_property (GObject *object,
priv->device.network = g_value_dup_string (value);
break;
case PROP_HOST_IP:
- {
- const char *addr = g_value_get_string (value);
- if (addr != NULL) {
- priv->device.host_addr =
- g_inet_address_new_from_string (addr);
- }
- break;
- }
+ priv->device.host_ip = g_value_dup_string (value);
+ break;
case PROP_HOST_ADDR:
priv->device.host_addr = g_value_dup_object (value);
break;
@@ -533,19 +527,17 @@ gssdp_client_class_init (GSSDPClientClass *klass)
*
* Deprecated: 1.6. Use [property@GSSDP.Client:address] instead.
**/
- g_object_class_install_property
- (object_class,
- PROP_HOST_IP,
- g_param_spec_string ("host-ip",
- "Host IP",
- "The IP address of the associated"
- "network interface",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_NICK |
- G_PARAM_STATIC_BLURB));
+ g_object_class_install_property (
+ object_class,
+ PROP_HOST_IP,
+ g_param_spec_string ("host-ip",
+ "Host IP",
+ "The IP address of the associated"
+ "network interface",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
/**
* GSSDPClient:address:(attributes org.gtk.Property.get=gssdp_client_get_address):
@@ -1895,6 +1887,43 @@ init_network_info (GSSDPClient *client, GError **error)
GSSDPClientPrivate *priv = gssdp_client_get_instance_private (client);
gboolean ret = TRUE;
+ /* If we were constructed with a host_ip, try to parse a host_addr from that.
+ * Further code will only work with host_addr */
+ if (priv->device.host_ip != NULL) {
+ GInetAddress *addr =
+ g_inet_address_new_from_string (priv->device.host_ip);
+ if (addr == NULL) {
+ g_set_error (error,
+ GSSDP_ERROR,
+ GSSDP_ERROR_FAILED,
+ "Unparseable host_ip %s",
+ priv->device.host_ip);
+
+ return FALSE;
+ }
+
+ // If there was also a host address passed (why?!) make sure
+ // they match up, otherwise exit with error as well
+ if (priv->device.host_addr != NULL) {
+ gboolean equal =
+ g_inet_address_equal (priv->device.host_addr,
+ addr);
+ g_object_unref (addr);
+ if (!equal) {
+ g_set_error_literal (
+ error,
+ GSSDP_ERROR,
+ GSSDP_ERROR_FAILED,
+ "host_ip and host_addr do not match");
+ return FALSE;
+ }
+
+ } else {
+ priv->device.host_addr = addr;
+ }
+
+ }
+
/* Either interface name or host_ip wasn't given during construction.
* If one is given, try to find the other, otherwise just pick an
* interface.