summaryrefslogtreecommitdiff
path: root/libgssdp
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2022-08-05 18:42:53 +0200
committerJens Georg <mail@jensge.org>2022-08-05 18:42:53 +0200
commitc8a54cd0b86f43c16ec8c6e4cd8f6da4066b5fdd (patch)
tree345190fb6f6711fd4b4041a2325b2680f1cbe63c /libgssdp
parentf6fd0d2ff1607fd9920f292d5a5f8f672152931d (diff)
downloadgssdp-c8a54cd0b86f43c16ec8c6e4cd8f6da4066b5fdd.tar.gz
Client: Add new convenience constructors
Diffstat (limited to 'libgssdp')
-rw-r--r--libgssdp/gssdp-client.c83
-rw-r--r--libgssdp/gssdp-client.h15
-rw-r--r--libgssdp/gssdp-net-posix.c10
3 files changed, 96 insertions, 12 deletions
diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c
index 02f81c8..60aeb06 100644
--- a/libgssdp/gssdp-client.c
+++ b/libgssdp/gssdp-client.c
@@ -659,7 +659,7 @@ gssdp_client_class_init (GSSDPClientClass *klass)
* used to determine the proper address.
*
* If not specified, will contain the currrent address family after
- * the call to [method@GLib.Initable.init]. Use %G_SOCKET_FAMILY_INVALID
+ * the call to [method@Glib.Initable.init]. Use %G_SOCKET_FAMILY_INVALID
* to specifiy using the default socket family (legacy IP)
*
* Since: 1.2.0
@@ -762,13 +762,17 @@ gssdp_client_class_init (GSSDPClientClass *klass)
/**
* gssdp_client_new:
- * @iface: (nullable): The name of the network interface, or %NULL for auto-detection.
+ * @iface: (nullable): The name of the network interface, or %NULL for
+ * auto-detection.
* @error: (nullable): Location to store error, or %NULL
*
* Creates a GSSDP client on @iface. GSSDPClient will pick the address it finds
* suitable for using.
*
- * Using this utility function, the created client will be using UDA 1.0 and IPv4 only.
+ * Using this utility function, the created client will be using UDA 1.0 and
+ * IPv4 only.
+ *
+ * Deprecated: 1.6. Use [ctor@GSSDP.Client.new_for_address] instead.
*
* Return value: (nullable): A new #GSSDPClient object.
**/
@@ -795,6 +799,8 @@ gssdp_client_new (const char *iface, GError **error)
*
* Using this utility function, the created client will be using UDA 1.0 and IPv4 only.
*
+ * Deprecated: 1.6. Use [ctor@GSSDP.Client.new_for_address] instead.
+ *
* Return value: (nullable): A new #GSSDPClient object or %NULL on error.
*/
GSSDPClient *
@@ -805,12 +811,79 @@ gssdp_client_new_with_port (const char *iface,
return g_initable_new (GSSDP_TYPE_CLIENT,
NULL,
error,
- "interface", iface,
- "msearch-port", msearch_port,
+ "interface",
+ iface,
+ "port",
+ msearch_port,
NULL);
}
/**
+ * gssdp_client_new_full:
+ * @iface: (nullable): the name of a network interface
+ * @addr: (nullable): an IP address or %NULL for auto-detection. If you do not
+ * care about the address, but want to specify an address family, use
+ * [ctor@Glib.InetAddress.new_any] with the appropriate family instead.
+ * @port: The network port to use for M-SEARCH requests or 0 for
+ * random.
+ * @uda_version: The UDA version this client will adhere to
+ * @error: (allow-none): Location to store error, or %NULL.
+ *
+ * Creates a GSSDP client with address @addr. If none is specified, GSSDP
+ * will chose the address it deems most suitable.
+ *
+ * Since: 1.6.
+ *
+ * Return value: (nullable): A new #GSSDPClient object or %NULL on error.
+ */
+GSSDPClient *
+gssdp_client_new_full (const char *iface,
+ GInetAddress *addr,
+ guint16 port,
+ GSSDPUDAVersion uda_version,
+ GError **error)
+{
+ return g_initable_new (GSSDP_TYPE_CLIENT,
+ NULL,
+ error,
+ "interface",
+ iface,
+ "address",
+ addr,
+ "port",
+ port,
+ "uda-version",
+ uda_version,
+ NULL);
+}
+
+/**
+ * gssdp_client_new_for_address
+ * @addr: (nullable): an IP address or %NULL for auto-detection. If you do not
+ * care about the address, but want to specify an address family, use
+ * [ctor@Glib.InetAddress.new_any] with the appropriate family instead.
+ * @port: The network port to use for M-SEARCH requests or 0 for
+ * random.
+ * @uda_version: The UDA version this client will adhere to
+ * @error: (allow-none): Location to store error, or %NULL.
+ *
+ * Creates a GSSDP client with address @addr. If none is specified, GSSDP
+ * will chose the address it deems most suitable.
+ *
+ * Since: 1.6.
+ *
+ * Return value: (nullable): A new #GSSDPClient object or %NULL on error.
+ */
+GSSDPClient *
+gssdp_client_new_for_address (GInetAddress *addr,
+ guint16 port,
+ GSSDPUDAVersion uda_version,
+ GError **error)
+{
+ return gssdp_client_new_full (NULL, addr, port, uda_version, error);
+}
+
+/**
* gssdp_client_set_server_id:(attributes org.gtk.Method.set_property=server-id):
* @client: A #GSSDPClient
* @server_id: The server ID
diff --git a/libgssdp/gssdp-client.h b/libgssdp/gssdp-client.h
index 9b2fb8c..0514b6d 100644
--- a/libgssdp/gssdp-client.h
+++ b/libgssdp/gssdp-client.h
@@ -47,15 +47,30 @@ struct _GSSDPClientClass {
void (* _gssdp_reserved4) (void);
};
+G_DEPRECATED_FOR(gssdp_client_new_for_address)
GSSDPClient *
gssdp_client_new (const char *iface,
GError **error);
+G_DEPRECATED_FOR(gssdp_client_new_for_address)
GSSDPClient *
gssdp_client_new_with_port (const char *iface,
guint16 msearch_port,
GError **error);
+GSSDPClient *
+gssdp_client_new_for_address (GInetAddress *addr,
+ guint16 port,
+ GSSDPUDAVersion uda_version,
+ GError **error);
+
+GSSDPClient *
+gssdp_client_new_full (const char *iface,
+ GInetAddress *addr,
+ guint16 port,
+ GSSDPUDAVersion uda_version,
+ GError **error);
+
void
gssdp_client_set_server_id (GSSDPClient *client,
const char *server_id);
diff --git a/libgssdp/gssdp-net-posix.c b/libgssdp/gssdp-net-posix.c
index cd46014..be5a343 100644
--- a/libgssdp/gssdp-net-posix.c
+++ b/libgssdp/gssdp-net-posix.c
@@ -468,6 +468,9 @@ gssdp_net_get_host_ip (GSSDPNetworkDevice *device, GError **error)
*/
if (device->host_addr) {
family = g_inet_address_get_family (device->host_addr);
+ // Address was solely added to select the address family
+ if (g_inet_address_get_is_any (device->host_addr))
+ g_clear_object (&device->host_addr);
}
for (ifaceptr = up_ifaces;
@@ -491,15 +494,8 @@ gssdp_net_get_host_ip (GSSDPNetworkDevice *device, GError **error)
if (device->host_addr == NULL) {
switch (ifa->ifa_addr->sa_family) {
case AF_INET:
- /* legacy IP: Easy, just take the first
- * address we can find */
- device->host_addr = g_object_ref (device_addr);
- break;
case AF_INET6:
- /* IP: Bit more complicated. We have to select a
- * link-local or ULA address */
device->host_addr = g_object_ref (device_addr);
- break;
default:
/* We filtered this out in the list before */
g_assert_not_reached ();