[vlc-devel] [PATCH] access: add gopher input module

Thomas Guillem thomas at gllm.fr
Mon Jan 6 16:50:47 CET 2020


Hello,

Thanks for the commit, I was about to merge it, but I have a question before, for everyone. Should this module be a submodule of the tcp module instead ? (cf. add_submodule(), only the Open function will differ).

That way, we don't increase the number of .so/.dll.

On Thu, Jan 2, 2020, at 09:17, Vincenzo Nicosia wrote:
> On Wed, Jan 01, 2020 at 01:16:32PM +0200, Rémi Denis-Courmont wrote:
> > Le keskiviikkona 1. tammikuuta 2020, 12.50.26 EET Vincenzo Nicosia a écrit :
> 
> [cut]
> 
> Dear Remi,
> 
> thanks a lot for the quick review. I implemented all your comments,
> but I would still prefer to keep the module descriptor at the top if
> possible, so the prototypes for Open and Close remained there. Amended
> patch below.
> 
> Thanks
> 
> ---
>  modules/access/Makefile.am |   5 ++
>  modules/access/gopher.c    | 165 +++++++++++++++++++++++++++++++++++++
>  src/input/item.c           |   1 +
>  3 files changed, 171 insertions(+)
>  create mode 100644 modules/access/gopher.c
> 
> diff --git a/modules/access/Makefile.am b/modules/access/Makefile.am
> index 756ca5cf59..9e5353b94c 100644
> --- a/modules/access/Makefile.am
> +++ b/modules/access/Makefile.am
> @@ -326,6 +326,11 @@ libhttp_plugin_la_SOURCES = access/http.c
>  libhttp_plugin_la_LIBADD = $(SOCKET_LIBS)
>  access_LTLIBRARIES += libhttp_plugin.la
>  
> +libgopher_plugin_la_SOURCES = access/gopher.c
> +libgopher_plugin_la_LIBADD = $(SOCKET_LIBS)
> +access_LTLIBRARIES += libgopher_plugin.la
> +
> +
>  liblive555_plugin_la_SOURCES = access/live555.cpp access/mms/asf.c 
> access/mms/buffer.c \
>                                 access/live555_dtsgen.h
>  liblive555_plugin_la_CXXFLAGS = $(AM_CXXFLAGS) $(CXXFLAGS_live555)
> diff --git a/modules/access/gopher.c b/modules/access/gopher.c
> new file mode 100644
> index 0000000000..62a28cc499
> --- /dev/null
> +++ b/modules/access/gopher.c
> @@ -0,0 +1,165 @@
> +/*****************************************************************************
> + * gopher.c: gopher input module
> + 
> *****************************************************************************
> + * Copyright (C) 2019 Vincenzo "KatolaZ" Nicosia
> + *
> + * Authors: Vincenzo "KatolaZ" Nicosia <katolaz at freaknet.org>
> + *
> + * This module was adapted from tcp.c
> + *
> + * This program is free software; you can redistribute it and/or 
> modify it
> + * under the terms of the GNU Lesser General Public License as 
> published by
> + * the Free Software Foundation; either version 2.1 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that 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 Street, Fifth Floor, Boston MA 02110-1301, USA.
> + 
> *****************************************************************************/
> +
> +#ifdef HAVE_CONFIG_H
> +# include "config.h"
> +#endif
> +
> +#include <vlc_common.h>
> +#include <vlc_plugin.h>
> +#include <vlc_access.h>
> +#include <vlc_messages.h>
> +#include <vlc_url.h>
> +#include <vlc_tls.h>
> +
> +#include <stdlib.h>
> +#include <string.h>
> +
> +/* Forward declarations */
> +static int Open(vlc_object_t *);
> +static void Close(vlc_object_t *);
> +
> +/* Module descriptor */
> +vlc_module_begin ()
> +    set_description( N_("Gopher input") )
> +    set_capability( "access", 0 )
> +    set_shortname( N_( "gopher" ) )
> +    set_category( CAT_INPUT )
> +    set_subcategory( SUBCAT_INPUT_ACCESS )
> +    add_shortcut( "gopher")
> +    set_callbacks( Open, Close )
> +vlc_module_end ()
> +
> +
> +static ssize_t Read(stream_t *access, void *buf, size_t len)
> +{
> +    return vlc_tls_Read(access->p_sys, buf, len, false);
> +}
> +
> +static int Control( stream_t *p_access, int i_query, va_list args )
> +{
> +    bool    *pb_bool;
> +
> +    switch( i_query )
> +    {
> +        case STREAM_CAN_SEEK:
> +        case STREAM_CAN_FASTSEEK:
> +            pb_bool = va_arg( args, bool * );
> +            *pb_bool = false;
> +            break;
> +        case STREAM_CAN_PAUSE:
> +            pb_bool = va_arg( args, bool * );
> +            *pb_bool = true;    /* FIXME */
> +            break;
> +        case STREAM_CAN_CONTROL_PACE:
> +            pb_bool = va_arg( args, bool * );
> +            *pb_bool = true;    /* FIXME */
> +            break;
> +
> +        case STREAM_GET_PTS_DELAY:
> +            *va_arg( args, vlc_tick_t * ) =
> +                VLC_TICK_FROM_MS(var_InheritInteger( p_access, 
> "network-caching" ));
> +            break;
> +
> +        case STREAM_SET_PAUSE_STATE:
> +            /* Nothing to do */
> +            break;
> +
> +        default:
> +            return VLC_EGENERIC;
> +    }
> +    return VLC_SUCCESS;
> +}
> +
> +
> +
> +static int Open(vlc_object_t *obj)
> +{
> +    char *psz_path = NULL;
> +    stream_t *access = (stream_t *)obj;
> +    vlc_tls_t *sock;
> +    vlc_url_t url;
> +
> +
> +    if (vlc_UrlParse(&url, access->psz_url) || url.psz_host == NULL){
> +        msg_Err(access, "invalid location: %s", access->psz_location);
> +        vlc_UrlClean(&url);
> +        return VLC_EGENERIC;
> +    }
> +
> +    if (url.i_port <= 0){
> +        url.i_port = 70;
> +    }
> +    sock = vlc_tls_SocketOpenTCP(obj, url.psz_host, url.i_port);
> +
> +    if (unlikely(sock == NULL)){
> +        msg_Err(access, "cannot connect to %s:%d", url.psz_host, 
> url.i_port);
> +        vlc_UrlClean(&url);
> +        return VLC_EGENERIC;
> +    }
> +
> +    /* strip resource type from URL */
> +    if (strlen(url.psz_path) > 3){
> +        if(asprintf(&psz_path, "%s\r\n", url.psz_path+2) == -1){
> +            vlc_UrlClean(&url);
> +            vlc_tls_SessionDelete(sock);
> +            return VLC_EGENERIC;
> +        }
> +        msg_Info(access, "stripped resource type from path");
> +    }
> +    else { /* if no resource type is specified, then look for the root 
> resource */
> +        if (asprintf(&psz_path, "/\r\n") == -1){
> +            vlc_UrlClean(&url);
> +            vlc_tls_SessionDelete(sock);
> +            return VLC_EGENERIC;
> +        }
> +        msg_Info(access, "path set to root resource");
> +    }
> +    vlc_UrlClean(&url);
> +
> +    access->p_sys = sock;
> +    access->pf_read = Read;
> +    access->pf_block = NULL;
> +    access->pf_control = Control;
> +    access->pf_seek = NULL;
> +
> +    msg_Info(access, "requesting resource: %s", psz_path);
> +    if (vlc_tls_Write(access->p_sys, psz_path, strlen(psz_path)) < 0){
> +        vlc_tls_SessionDelete(access->p_sys);
> +        free(psz_path);
> +        return VLC_EGENERIC;
> +    }
> +
> +    free(psz_path);
> +    return VLC_SUCCESS;
> +}
> +
> +static void Close( vlc_object_t *p_this )
> +{
> +    stream_t *access = (stream_t *)p_this;
> +
> +    vlc_tls_SessionDelete(access->p_sys);
> +}
> +
> +
> diff --git a/src/input/item.c b/src/input/item.c
> index 9c3442d5c7..1a8a2bdb3f 100644
> --- a/src/input/item.c
> +++ b/src/input/item.c
> @@ -1187,6 +1187,7 @@ static enum input_item_type_e GuessType( const 
> input_item_t *p_item, bool *p_net
>          { "fd",     ITEM_TYPE_UNKNOWN, false },
>          { "file",   ITEM_TYPE_FILE, false },
>          { "ftp",    ITEM_TYPE_FILE, true },
> +        { "gopher", ITEM_TYPE_STREAM, true },
>          { "http",   ITEM_TYPE_FILE, true },
>          { "icyx",   ITEM_TYPE_STREAM, true },
>          { "imem",   ITEM_TYPE_UNKNOWN, false },
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list