diff options
Diffstat (limited to 'src/lib.c')
-rw-r--r-- | src/lib.c | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -88,6 +88,55 @@ stp_validate_token_server (GInetAddressMask *mask, return ret; } +gboolean stp_clients_is_subset (char *superset, + char *subset) +{ + gsize i, n; + gboolean ret; + char **supersetv, **subsetv; + GHashTable *superset_table = NULL; + + if (!subset) + return TRUE; + + if (!superset) + return FALSE; + + /* Simplest case */ + if (g_strcmp0 (superset, subset) == 0) + return TRUE; + + subsetv = g_strsplit (subset, ",", 0); + supersetv = g_strsplit (superset, ",", 0); + + if (sizeof(supersetv)/sizeof(supersetv[0]) <= 1 || + sizeof(subsetv)/sizeof(subsetv[0]) < 1) + /* If there's one client in the superset, and the subset didn't match, + * it won't match. Same if there's less than one client in either list. */ + goto fail; + + /* Easiest way to check. Add superset clients to a table, and then check + * whether every subset client is in that table. */ + superset_table = g_hash_table_new (g_str_hash, g_str_equal); + for (i = 0, n = sizeof(supersetv)/sizeof(supersetv[0]); i < n; i++) + g_hash_table_add (superset_table, supersetv[i]); + + for (i = 0, n = sizeof(subsetv)/sizeof(subsetv[0]); i < n; i++) + if (!g_hash_table_contains (superset_table, subsetv[i])) + goto fail; + + ret = TRUE; +out: + if (superset_table) + g_hash_table_destroy (superset_table); + g_strfreev (supersetv); + g_strfreev (subsetv); + return ret; +fail: + ret = FALSE; + goto out; +} + gboolean stp_on_gst_bus_message (GstBus *bus, GstMessage *msg, |