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

Vincenzo Nicosia katolaz at freaknet.org
Wed Jan 1 11:50:26 CET 2020


Hi All,

I am new here. I have written a gopher input module for VLC. It's
based on the existing tcp.c module, with little stuff around to cater
for gopher. I have gone through the checklist, and I am now ready to
receive comments.

Happy New Year

---
From: Vincenzo "KatolaZ" Nicosia <katolaz at freaknet.org>
Date: Tue, 31 Dec 2019 10:04:50 +0000
Subject: [PATCH] access: add gopher input module

---
 modules/access/Makefile.am |   5 ++
 modules/access/gopher.c    | 156 +++++++++++++++++++++++++++++++++++++
 src/input/item.c           |   1 +
 3 files changed, 162 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..eb9509debf
--- /dev/null
+++ b/modules/access/gopher.c
@@ -0,0 +1,156 @@
+/*****************************************************************************
+ * 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_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 *);
+static int Control(stream_t *p_access, int i_query, va_list args);
+static ssize_t Read(stream_t *access, void *buf, size_t len);
+
+/* 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 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);
+
+    psz_path = malloc((strlen(url.psz_path) + 6) * sizeof(char));
+    if (unlikely(sock == NULL) || unlikely(psz_path == NULL)){
+        vlc_UrlClean(&url);
+        if (sock == NULL){
+            return VLC_EGENERIC;
+        }
+        else {
+            return VLC_ENOMEM;
+        }
+    }
+    /* strip resource type from URL */
+    if (strlen(url.psz_path) > 3){
+        sprintf(psz_path, "%s\r\n", url.psz_path+2);
+    }
+    else { /* if no resource type is specified, then look for the root resource */
+        sprintf(psz_path, "/\r\n");
+    }
+    vlc_UrlClean(&url);
+    fprintf(stderr, "[module:input:gopher] resource path is: %s\n", psz_path);
+
+    access->p_sys = sock;
+    access->pf_read = Read;
+    access->pf_block = NULL;
+    access->pf_control = Control;
+    access->pf_seek = NULL;
+
+    if (vlc_tls_Write(access->p_sys, psz_path, strlen(psz_path)) < 0){
+        vlc_tls_SessionDelete(access->p_sys);
+        return VLC_EGENERIC;
+    }
+    fprintf(stderr, "[module:input:gopher] request sent\n");
+    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);
+}
+
+
+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;
+}
+
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200101/124bfb39/attachment.sig>


More information about the vlc-devel mailing list