From f08041f0eb8512304584b583073508629a934c88 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 26 Oct 2008 20:38:44 +0100 Subject: input_stream: added struct input_plugin Instead of managing a set of method pointers in each input_stream struct, move these into the new input_plugin struct. Each input_stream has only a pointer to the plugin struct. Pointers to all implementations are kept in the array "input_plugins". --- src/input_stream.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/input_stream.c') diff --git a/src/input_stream.c b/src/input_stream.c index db51cbd4c..a5c55fa54 100644 --- a/src/input_stream.c +++ b/src/input_stream.c @@ -27,6 +27,16 @@ #include +static const struct input_plugin *const input_plugins[] = { + &input_plugin_file, +#ifdef HAVE_CURL + &input_plugin_curl, +#endif +}; + +static const unsigned num_input_plugins = + sizeof(input_plugins) / sizeof(input_plugins[0]); + void input_stream_global_init(void) { #ifdef HAVE_CURL @@ -52,26 +62,27 @@ int input_stream_open(struct input_stream *is, char *url) is->meta_name = NULL; is->meta_title = NULL; - if (input_file_open(is, url) == 0) - return 0; + for (unsigned i = 0; i < num_input_plugins; ++i) { + const struct input_plugin *plugin = input_plugins[i]; -#ifdef HAVE_CURL - if (input_curl_open(is, url)) - return 0; -#endif + if (plugin->open(is, url)) { + is->plugin = plugin; + return 0; + } + } return -1; } int input_stream_seek(struct input_stream *is, long offset, int whence) { - return is->seekFunc(is, offset, whence); + return is->plugin->seek(is, offset, whence); } size_t input_stream_read(struct input_stream *is, void *ptr, size_t size) { - return is->readFunc(is, ptr, size); + return is->plugin->read(is, ptr, size); } int input_stream_close(struct input_stream *is) @@ -83,15 +94,15 @@ int input_stream_close(struct input_stream *is) if (is->meta_title) free(is->meta_title); - return is->closeFunc(is); + return is->plugin->close(is); } int input_stream_eof(struct input_stream *is) { - return is->atEOFFunc(is); + return is->plugin->eof(is); } int input_stream_buffer(struct input_stream *is) { - return is->bufferFunc(is); + return is->plugin->buffer(is); } -- cgit v1.2.3