diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2014-07-24 17:56:02 (GMT) |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2014-07-24 20:55:42 (GMT) |
commit | e0d453a3a2c120264b13c44f004025b0330547a8 (patch) | |
tree | 4517a7e8f3100f1f75b4cecd68486b42d4f7f0df /src/lib.c | |
parent | fae0aa58c19a1918e7b7750b4862e2abcbc55788 (diff) | |
download | soup-transcoding-proxy-e0d453a3a2c120264b13c44f004025b0330547a8.zip soup-transcoding-proxy-e0d453a3a2c120264b13c44f004025b0330547a8.tar.gz |
Implement concurrent RTP-UDP streams, and a REST API for status and auth
When the --token-server=ADDR/MASK argument is passed to the server, the token
verification framework is enabled, and the specified subnet is allowed to access
the REST API to add/revoke/list tokens that allow clients to connect, and to
list/abort streams running on the server.
Details about the REST API are documented in the file "REST-API".
There were also some organisational and name changes in the code.
Diffstat (limited to 'src/lib.c')
-rw-r--r-- | src/lib.c | 85 |
1 files changed, 73 insertions, 12 deletions
@@ -22,26 +22,76 @@ #include "lib.h" -static void stp_disconnect_cleanup_client (TranscodeClientCtx *ctx); +static void stp_disconnect_cleanup_client (STPClientCtx *ctx); gboolean -invoke_g_hash_table_remove (TranscodeServerCtx *ctx) +invoke_g_hash_table_remove (STPServerCtx *ctx) { - g_hash_table_remove (ctx->parent_ctx_table, ctx->path); + g_hash_table_remove (ctx->parent_ctx_table, ctx->sessionid); return G_SOURCE_REMOVE; } gboolean -invoke_g_free_client_context (TranscodeClientCtx *ctx) +invoke_g_free_client_context (STPClientCtx *ctx) { g_free (ctx); return G_SOURCE_REMOVE; } +guint +stp_get_stream_type_from_string (const char *type) +{ + if (type == NULL) + return STP_STREAM_TYPE_ALL; + + if (soup_str_case_equal (type, "http")) + return STP_STREAM_TYPE_HTTP; + + if (soup_str_case_equal (type, "rtp-udp")) + return STP_STREAM_TYPE_RTP_UDP; + + if (soup_str_case_equal (type, "rtp-udp,http") || + soup_str_case_equal (type, "http,rtp-udp")) + return STP_STREAM_TYPE_ALL; + + return STP_STREAM_TYPE_INVALID; +} + +const char* +stp_get_stream_type_string (guint stream_type) +{ + switch (stream_type) { + case STP_STREAM_TYPE_HTTP: + return "http"; + case STP_STREAM_TYPE_RTP_UDP: + return "rtp-udp"; + case STP_STREAM_TYPE_ALL: + return "http,rtp-udp"; + default: + return "invalid"; + } +} + +gboolean +stp_validate_token_server (GInetAddressMask *mask, + SoupClientContext *client) +{ + gboolean ret; + GInetAddress *addr; + + if (!mask) + return TRUE; + + addr = g_inet_address_new_from_string (soup_client_context_get_host (client)); + ret = g_inet_address_mask_matches (mask, addr); + g_object_unref (addr); + return ret; +} + gboolean -stp_on_gst_bus_message (GstBus *bus, - GstMessage *msg, - TranscodeServerCtx *ctx) +stp_on_gst_bus_message (GstBus *bus, + GstMessage *msg, + STPServerCtx *ctx) { GError *error = NULL; char *tmp = NULL; @@ -85,10 +135,13 @@ stp_on_gst_bus_message (GstBus *bus, * which initiates a shutdown for all clients and then * the server itself */ void -stp_cleanup_transcode_server_ctx (TranscodeServerCtx *ctx) +stp_server_ctx_cleanup (STPServerCtx *ctx) { g_debug (">>> Doing server cleanup"); + g_source_remove (ctx->timeout_handler_id); + ctx->timeout_handler_id = 0; + /* Disconnect and free the context for each client */ g_list_foreach (ctx->clients, (GFunc)stp_disconnect_cleanup_client, NULL); g_list_free (ctx->clients); @@ -99,13 +152,14 @@ stp_cleanup_transcode_server_ctx (TranscodeServerCtx *ctx) gst_object_unref (ctx->pipeline); } + g_free (ctx->udp_clients); g_free (ctx); } static GstPadProbeReturn pad_blocked_cleanup_cb (GstPad *srcpad, GstPadProbeInfo *info, - TranscodeClientCtx *ctx) + STPClientCtx *ctx) { GstElement *tee; GstElement *sinkbin = GST_ELEMENT (gst_element_get_parent (ctx->appsink)); @@ -133,10 +187,10 @@ pad_blocked_cleanup_cb (GstPad *srcpad, * branch for the client from the pipeline, and then freeing the * context. */ void -stp_cleanup_transcode_client_ctx (TranscodeClientCtx *ctx) +stp_client_ctx_cleanup (STPClientCtx *ctx) { GstPad *srcpad; - TranscodeServerCtx *server_ctx = ctx->server_ctx; + STPServerCtx *server_ctx = ctx->server_ctx; GstElement *sinkbin = GST_ELEMENT (gst_element_get_parent (ctx->appsink)); stp_print_status (">>> Doing client cleanup."); @@ -157,11 +211,18 @@ stp_cleanup_transcode_client_ctx (TranscodeClientCtx *ctx) stp_print_status ("."); } +void +stp_stream_token_free (STPStreamToken *token) +{ + g_free (token->udp_clients); + g_free (token); +} + /* When shutting down a client due to a server shutdown, * we just need to remove the client timeout handler and * free the context. The rest is owned by the pipeline. */ static void -stp_disconnect_cleanup_client (TranscodeClientCtx *ctx) +stp_disconnect_cleanup_client (STPClientCtx *ctx) { stp_print_status (">>> Disconnecting client on server shutdown\n"); |