[gssdp] Add msearch-port property to GSSDPClient
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gssdp] Add msearch-port property to GSSDPClient
- Date: Tue, 29 Oct 2013 15:14:31 +0000 (UTC)
commit fe85ede14ad3045665bbb2b863818a57dec033dc
Author: Jens Georg <jensg openismus com>
Date: Mon Oct 28 15:39:31 2013 +0100
Add msearch-port property to GSSDPClient
https://bugzilla.gnome.org/show_bug.cgi?id=711015
libgssdp/gssdp-client.c | 68 +++++++++++++++++++++++++++++++++++++---
libgssdp/gssdp-socket-source.c | 23 ++++++++++++-
libgssdp/gssdp-socket-source.h | 6 ++-
3 files changed, 88 insertions(+), 9 deletions(-)
---
diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c
index baec893..cf0f0cb 100644
--- a/libgssdp/gssdp-client.c
+++ b/libgssdp/gssdp-client.c
@@ -1,10 +1,12 @@
/*
* Copyright (C) 2006, 2007, 2008 OpenedHand Ltd.
* Copyright (C) 2009 Nokia Corporation.
+ * Copyright (C) 2013 Intel Corporation.
*
* Author: Jorn Baayen <jorn openedhand com>
* Zeeshan Ali (Khattak) <zeeshanak gnome org>
* <zeeshan ali nokia com>
+ * Jens Georg <jensg openismus com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -106,6 +108,7 @@ struct _GSSDPClientPrivate {
char *server_id;
guint socket_ttl;
+ guint msearch_port;
GSSDPNetworkDevice device;
GSSDPSocketSource *request_socket;
@@ -125,6 +128,7 @@ enum {
PROP_HOST_IP,
PROP_ACTIVE,
PROP_SOCKET_TTL,
+ PROP_MSEARCH_PORT,
};
enum {
@@ -242,11 +246,16 @@ gssdp_client_initable_init (GInitable *initable,
/* Setup send socket. For security reasons, it is not recommended to
* send M-SEARCH with source port == SSDP_PORT */
- client->priv->search_socket = gssdp_socket_source_new
- (GSSDP_SOCKET_SOURCE_TYPE_SEARCH,
- gssdp_client_get_host_ip (client),
- client->priv->socket_ttl,
- &internal_error);
+ client->priv->search_socket = GSSDP_SOCKET_SOURCE (g_initable_new
+ (GSSDP_TYPE_SOCKET_SOURCE,
+ NULL,
+ &internal_error,
+ "type", GSSDP_SOCKET_SOURCE_TYPE_SEARCH,
+ "host-ip", gssdp_client_get_host_ip (client),
+ "ttl", client->priv->socket_ttl,
+ "port", client->priv->msearch_port,
+ NULL));
+
if (client->priv->search_socket != NULL) {
gssdp_socket_source_set_callback
(client->priv->search_socket,
@@ -331,6 +340,9 @@ gssdp_client_get_property (GObject *object,
case PROP_SOCKET_TTL:
g_value_set_uint (value, client->priv->socket_ttl);
break;
+ case PROP_MSEARCH_PORT:
+ g_value_set_uint (value, client->priv->msearch_port);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -369,6 +381,9 @@ gssdp_client_set_property (GObject *object,
case PROP_SOCKET_TTL:
client->priv->socket_ttl = g_value_get_uint (value);
break;
+ case PROP_MSEARCH_PORT:
+ client->priv->msearch_port = g_value_get_uint (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -571,6 +586,26 @@ gssdp_client_class_init (GSSDPClientClass *klass)
G_PARAM_STATIC_BLURB));
/**
+ * GSSDPClient:msearch-port:
+ *
+ * UDP port to use for sending multicast M-SEARCH requests on the
+ * network. If not set (or set to 0) a random port will be used.
+ * This property can be only set during object construction.
+ */
+ g_object_class_install_property
+ (object_class,
+ PROP_MSEARCH_PORT,
+ g_param_spec_uint
+ ("msearch-port",
+ "M-SEARCH port",
+ "UDP port to use for M-SEARCH requests",
+ 0, G_MAXUINT16,
+ 0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
* GSSDPClient::message-received: (skip)
*
* Internal signal.
@@ -618,6 +653,29 @@ gssdp_client_new (GMainContext *main_context,
NULL);
}
+/**
+ * gssdp_client_new_with_port:
+ * @iface: (allow-none): The name of the network interface, or %NULL for
+ * auto-detection.
+ * @msearch_port: The network port to use for M-SEARCH requests or 0 for
+ * random.
+ * @error: (allow-none): Location to store error, or %NULL.
+ *
+ * Return value: A new #GSSDPClient object.
+ **/
+GSSDPClient *
+gssdp_client_new_with_port (const char *iface,
+ guint16 msearch_port,
+ GError **error)
+{
+ return g_initable_new (GSSDP_TYPE_CLIENT,
+ NULL,
+ error,
+ "interface", iface,
+ "msearch-port", msearch_port,
+ NULL);
+}
+
/*
* gssdp_client_get_main_context: (skip)
* @client: A #GSSDPClient
diff --git a/libgssdp/gssdp-socket-source.c b/libgssdp/gssdp-socket-source.c
index a59fab1..c7e9585 100644
--- a/libgssdp/gssdp-socket-source.c
+++ b/libgssdp/gssdp-socket-source.c
@@ -50,6 +50,7 @@ struct _GSSDPSocketSourcePrivate {
char *host_ip;
guint ttl;
+ guint port;
};
enum {
@@ -57,6 +58,7 @@ enum {
PROP_TYPE,
PROP_HOST_IP,
PROP_TTL,
+ PROP_PORT
};
static void
@@ -114,6 +116,9 @@ gssdp_socket_source_set_property (GObject *object,
case PROP_TTL:
self->priv->ttl = g_value_get_uint (value);
break;
+ case PROP_PORT:
+ self->priv->port = g_value_get_uint (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -256,9 +261,11 @@ gssdp_socket_source_do_init (GInitable *initable,
} else {
guint port = SSDP_PORT;
- /* Chose random port For the socket source used by M-SEARCH */
+ /* Use user-supplied or random port for the socket source used
+ * by M-SEARCH */
if (self->priv->type == GSSDP_SOCKET_SOURCE_TYPE_SEARCH)
- port = 0;
+ port = self->priv->port;
+
bind_address = g_inet_socket_address_new (iface_address,
port);
}
@@ -449,4 +456,16 @@ gssdp_socket_source_class_init (GSSDPSocketSourceClass *klass)
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
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));
}
diff --git a/libgssdp/gssdp-socket-source.h b/libgssdp/gssdp-socket-source.h
index c3bba90..ed9ef42 100644
--- a/libgssdp/gssdp-socket-source.h
+++ b/libgssdp/gssdp-socket-source.h
@@ -30,6 +30,9 @@
G_BEGIN_DECLS
+G_GNUC_INTERNAL GType
+gssdp_socket_source_get_type (void) G_GNUC_CONST;
+
#define GSSDP_TYPE_SOCKET_SOURCE \
(gssdp_socket_source_get_type ())
#define GSSDP_SOCKET_SOURCE(obj) \
@@ -59,8 +62,6 @@ typedef enum {
GSSDP_SOCKET_SOURCE_TYPE_SEARCH
} GSSDPSocketSourceType;
-
-
typedef struct _GSSDPSocketSource {
GObject parent;
@@ -76,6 +77,7 @@ gssdp_socket_source_new (GSSDPSocketSourceType type,
const char *host_ip,
guint ttl,
GError **error);
+
G_GNUC_INTERNAL GSocket*
gssdp_socket_source_get_socket (GSSDPSocketSource *socket_source);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]