[gupnp-tools] network-light: Add --interface and --port option



commit 8e640cfd3089d234dac8c3ed3d91bdceb81f3209
Author: Jens Georg <mail jensge org>
Date:   Sun Oct 20 13:10:13 2013 +0200

    network-light: Add --interface and --port option

 src/network-light/main.c |   31 ++++++++++++++++++++++++++++---
 src/network-light/upnp.c |   12 ++++++++++--
 src/network-light/upnp.h |    2 +-
 3 files changed, 39 insertions(+), 6 deletions(-)
---
diff --git a/src/network-light/main.c b/src/network-light/main.c
index 401efc8..43d6baa 100644
--- a/src/network-light/main.c
+++ b/src/network-light/main.c
@@ -1,9 +1,11 @@
 /*
  * Copyright (C) 2007 Zeeshan Ali.
  * Copyright (C) 2007 OpenedHand Ltd.
+ * Copyright (C) 2013 Jens Georg <mail jensge org>
  *
- * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
- * Author: Jorn Baayen <jorn openedhand com>
+ * Authors: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *          Jorn Baayen <jorn openedhand com>
+ *          Jens Georg <mail jensge org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -36,6 +38,16 @@
 static gboolean light_status;
 static gint     light_load_level;
 
+static int      upnp_port = 0;
+static char   **interfaces = NULL;
+
+static GOptionEntry entries[] =
+{
+        { "port", 'p', 0, G_OPTION_ARG_INT, &upnp_port, N_("Network PORT to use for UPnP"), "PORT" },
+        { "interface", 'i', 0, G_OPTION_ARG_STRING_ARRAY, &interfaces, N_("Network interfaces to use for 
UPnP communication"), "INTERFACE" },
+        { NULL }
+};
+
 void
 set_status (gboolean status)
 {
@@ -73,6 +85,9 @@ get_load_level (void)
 int
 main (int argc, char **argv)
 {
+        GError *error = NULL;
+        GOptionContext *context = NULL;
+
         /* Light is off in the beginning */
         light_status = FALSE;
         light_load_level = 100;
@@ -82,11 +97,21 @@ main (int argc, char **argv)
         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
         textdomain (GETTEXT_PACKAGE);
 
+        context = g_option_context_new (_("- UPnP AV control point"));
+        g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+        g_option_context_add_group (context, gtk_get_option_group (TRUE));
+
+        if (!g_option_context_parse (context, &argc, &argv, &error)) {
+                g_print (_("Could not parse options: %s\n"), error->message);
+
+                return -4;
+        }
+
         if (!init_ui (&argc, &argv)) {
                 return -1;
         }
 
-        if (!init_upnp ()) {
+        if (!init_upnp (interfaces, upnp_port)) {
                 return -2;
         }
 
diff --git a/src/network-light/upnp.c b/src/network-light/upnp.c
index c3af7e8..0e6a74b 100644
--- a/src/network-light/upnp.c
+++ b/src/network-light/upnp.c
@@ -669,9 +669,10 @@ context_equal (GUPnPContext *context1, GUPnPContext *context2)
 }
 
 gboolean
-init_upnp (void)
+init_upnp (gchar **interfaces, guint port)
 {
         GError *error = NULL;
+        GUPnPWhiteList *white_list;
 
         switch_proxies = NULL;
         dimming_proxies = NULL;
@@ -685,9 +686,16 @@ init_upnp (void)
                 return FALSE;
         }
 
-        context_manager = gupnp_context_manager_new (NULL, 0);
+        context_manager = gupnp_context_manager_new (NULL, port);
         g_assert (context_manager != NULL);
 
+        if (interfaces != NULL) {
+                white_list = gupnp_context_manager_get_white_list
+                                            (context_manager);
+                gupnp_white_list_add_entryv (white_list, interfaces);
+                gupnp_white_list_set_enabled (white_list, TRUE);
+        }
+
         g_signal_connect (context_manager,
                           "context-available",
                           G_CALLBACK (on_context_available),
diff --git a/src/network-light/upnp.h b/src/network-light/upnp.h
index efb9712..0f05f9e 100644
--- a/src/network-light/upnp.h
+++ b/src/network-light/upnp.h
@@ -30,7 +30,7 @@ void
 notify_load_level_change        (gint           load_level);
 
 gboolean
-init_upnp                       (void);
+init_upnp                       (gchar **interfaces, guint port);
 
 void
 deinit_upnp                     (void);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]