summaryrefslogtreecommitdiff
path: root/libdleyna/core/white-list.c
blob: 03a6b4183381d8756cb9f5364232984d05ff66d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * dLeyna
 *
 * Copyright (C) 2012-2017 Intel Corporation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Ludovic Ferrandis <ludovic.ferrandis@intel.com>
 *
 */

#include <string.h>

#include "white-list.h"
#include "log.h"

struct dleyna_white_list_t_ {
	GUPnPWhiteList *gupnp_wl;
};

#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_DEBUG
static void prv_dump_wl_entries(GUPnPWhiteList *wl)
{
	GList *l;

	l = gupnp_white_list_get_entries(wl);

	DLEYNA_LOG_DEBUG_NL();
	DLEYNA_LOG_DEBUG("White List entries:");

	if (l != NULL) {
		while (l != NULL) {
			DLEYNA_LOG_DEBUG("     Entry: [%s].", (char *)l->data);
			l = l->next;
		}
	} else {
		DLEYNA_LOG_DEBUG("     White List Empty.");
	}

	DLEYNA_LOG_DEBUG_NL();
}
#endif

dleyna_white_list_t *dleyna_white_list_new(GUPnPWhiteList *gupnp_wl)
{
	dleyna_white_list_t *wl;

	if (gupnp_wl != NULL) {
		wl =  g_new0(dleyna_white_list_t, 1);

		wl->gupnp_wl = gupnp_wl;
	} else {
		wl = NULL;
		DLEYNA_LOG_DEBUG("Parameter must not be NULL");
	}


	return wl;
}

void dleyna_white_list_delete(dleyna_white_list_t *wl)
{
	g_free(wl);
}

void dleyna_white_list_enable(dleyna_white_list_t *wl,
			      gboolean enabled)
{
	if (wl->gupnp_wl != NULL) {
		gupnp_white_list_set_enabled(wl->gupnp_wl, enabled);

		DLEYNA_LOG_DEBUG("White List enabled: %d", enabled);
	}
}

void dleyna_white_list_add_entries(dleyna_white_list_t *wl,
				   GVariant *entries)
{
	GVariantIter viter;
	gchar *entry;

	DLEYNA_LOG_DEBUG("Enter");

	if ((entries != NULL) && (wl->gupnp_wl != NULL)) {
		(void) g_variant_iter_init(&viter, entries);

		while (g_variant_iter_next(&viter, "&s", &entry))
			(void) gupnp_white_list_add_entry(wl->gupnp_wl, entry);

#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_DEBUG
		prv_dump_wl_entries(wl->gupnp_wl);
#endif
	}

	DLEYNA_LOG_DEBUG("Exit");
}

void dleyna_white_list_remove_entries(dleyna_white_list_t *wl,
				      GVariant *entries)
{
	GVariantIter viter;
	gchar *entry;

	if ((entries != NULL) && (wl->gupnp_wl != NULL)) {
		(void) g_variant_iter_init(&viter, entries);

		while (g_variant_iter_next(&viter, "&s", &entry))
			(void) gupnp_white_list_remove_entry(wl->gupnp_wl,
							     entry);

#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_DEBUG
		prv_dump_wl_entries(wl->gupnp_wl);
#endif
	}
}

void dleyna_white_list_clear(dleyna_white_list_t *wl)
{
	if (wl->gupnp_wl != NULL) {
		DLEYNA_LOG_DEBUG("Clear white list");
		gupnp_white_list_clear(wl->gupnp_wl);

#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_DEBUG
		prv_dump_wl_entries(wl->gupnp_wl);
#endif
	}
}