diff --git a/src/format.c b/src/format.c index cd775d46..6f40bea2 100644 --- a/src/format.c +++ b/src/format.c @@ -71,6 +71,8 @@ format_type_t format_get_type (const char *contenttype) return FORMAT_TYPE_EBML; else if(strcmp(contenttype, "video/x-matroska-3d") == 0) return FORMAT_TYPE_EBML; + else if(strcmp(contenttype, "text/plain") == 0) + return FORMAT_TYPE_TEXT; else /* We default to the Generic format handler, which can handle many more formats than just mp3. @@ -90,6 +92,9 @@ int format_get_plugin(format_type_t type, source_t *source) case FORMAT_TYPE_EBML: ret = format_ebml_get_plugin(source); break; + case FORMAT_TYPE_TEXT: + ret = format_text_get_plugin(source); + break; case FORMAT_TYPE_GENERIC: ret = format_mp3_get_plugin(source); break; diff --git a/src/format.h b/src/format.h index 5ddae298..67c938f6 100644 --- a/src/format.h +++ b/src/format.h @@ -32,6 +32,7 @@ typedef enum _format_type_tag FORMAT_ERROR, /* No format, source not processable */ FORMAT_TYPE_OGG, FORMAT_TYPE_EBML, + FORMAT_TYPE_TEXT, FORMAT_TYPE_GENERIC } format_type_t; diff --git a/src/format_text.c b/src/format_text.c index c83e7015..41804bec 100644 --- a/src/format_text.c +++ b/src/format_text.c @@ -12,9 +12,63 @@ #include #endif +#include + +#include "source.h" +#include "format.h" #include "format_text.h" #define CATMODULE "format-text" #include "logging.h" +static void text_free_plugin(format_plugin_t *plugin) +{ + free(plugin); +} + +static refbuf_t *text_get_buffer(source_t *source) +{ + format_plugin_t *format = source->format; + refbuf_t *refbuf = refbuf_new(1024); + ssize_t bytes; + + bytes = client_body_read(source->client, refbuf->data, refbuf->len); + if (bytes < 0) { + /* Why do we do this here (not source.c)? -- ph3-der-loewe, 2018-04-17 */ + if (client_body_eof(source->client)) { + refbuf_release (refbuf); + } + return NULL; + } + refbuf->len = bytes; + refbuf->sync_point = 1; + format->read_bytes += bytes; + + ICECAST_LOG_DDEBUG("Got buffer for source %p with %zi bytes", source, bytes); + + return refbuf; +} + +int format_text_get_plugin(source_t *source) +{ + format_plugin_t *plugin = calloc(1, sizeof(format_plugin_t)); + + ICECAST_LOG_DEBUG("Opening text format for source %p", source); + + plugin->get_buffer = text_get_buffer; + plugin->write_buf_to_client = format_generic_write_to_client; + plugin->create_client_data = NULL; + plugin->free_plugin = text_free_plugin; + plugin->write_buf_to_file = NULL; + plugin->set_tag = NULL; + plugin->apply_settings = NULL; + + plugin->contenttype = httpp_getvar(source->parser, "content-type"); + + plugin->_state = NULL; + vorbis_comment_init(&plugin->vc); + source->format = plugin; + + return 0; +}