[vlc-devel] [PATCH] access: add gopher input submodule to tcp.c
Rémi Denis-Courmont
remi at remlab.net
Wed Jan 8 15:00:13 CET 2020
Not OK for me. This belongs as a separate source and binary.
Le 7 janvier 2020 19:17:18 GMT+09:00, Vincenzo Nicosia <katolaz at freaknet.org> a écrit :
>On Tue, Jan 07, 2020 at 09:10:09AM +0100, Steve Lhomme wrote:
>
>[cut]
>
>> > However, I understand that it makes sense to have a consistent
>coding
>> > style in the same file. I will adapt the patch to match the style
>used
>> > in tcp.c then.
>>
>> That's the idea, we usually try to follow the style of the existing
>file for
>> additions. For new code, especially modules, it depends on the
>author. But
>> in general we use a space before the { of a if().
>>
>
>Hi Steve,
>
>I used the same style found in tcp.c ({ on a lonely line, aligned with
>'if', no space before '(' and ')', uncuddled 'else'), and replaced
>msg_Info with msg_Warn. Amended patch below.
>
>Thanks for your review.
>
>---
> modules/access/tcp.c | 86 ++++++++++++++++++++++++++++++++++++++++++++
> src/input/item.c | 1 +
> 2 files changed, 87 insertions(+)
>
>diff --git a/modules/access/tcp.c b/modules/access/tcp.c
>index 214a5853be..b3599a0472 100644
>--- a/modules/access/tcp.c
>+++ b/modules/access/tcp.c
>@@ -2,8 +2,10 @@
> * tcp.c: TCP input module
>*****************************************************************************
> * Copyright (C) 2003-2004 VLC authors and VideoLAN
>+ * Copyright (C) 2020 Vincenzo "KatolaZ" Nicosia
> *
> * Authors: Laurent Aimar <fenrir at via.ecp.fr>
>+ * Vincenzo "KatolaZ" Nicosia <katolaz at freaknet.org> (gopher
>sub-module)
> *
>* 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
>@@ -29,9 +31,13 @@
> #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>
>+
> static ssize_t Read(stream_t *access, void *buf, size_t len)
> {
> return vlc_tls_Read(access->p_sys, buf, len, false);
>@@ -106,6 +112,76 @@ static void Close( vlc_object_t *p_this )
> vlc_tls_SessionDelete(access->p_sys);
> }
>
>+static int GopherOpen(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;
>+ }
>+
>+ if (url.psz_path == NULL || strlen(url.psz_path) <= 3)
>+ {
>+ /* If no resource type is specified, look for the root
>resource */
>+ if (asprintf(&psz_path, "\r\n") == -1)
>+ {
>+ vlc_UrlClean(&url);
>+ vlc_tls_SessionDelete(sock);
>+ return VLC_EGENERIC;
>+ }
>+ msg_Warn(access, "path set to root resource");
>+ }
>+ else { /* strip resource type from URL */
>+ if(asprintf(&psz_path, "%s\r\n", url.psz_path+2) == -1)
>+ {
>+ vlc_UrlClean(&url);
>+ vlc_tls_SessionDelete(sock);
>+ return VLC_EGENERIC;
>+ }
>+ msg_Warn(access, "stripped resource type from path");
>+ }
>+ vlc_UrlClean(&url);
>+
>+ access->p_sys = sock;
>+ access->pf_read = Read;
>+ access->pf_block = NULL;
>+ access->pf_control = Control;
>+ access->pf_seek = NULL;
>+
>+ msg_Warn(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;
>+}
>+
>+
>+
>/*****************************************************************************
> * Module descriptor
>*****************************************************************************/
>@@ -118,4 +194,14 @@ vlc_module_begin ()
> set_capability( "access", 0 )
> add_shortcut( "tcp" )
> set_callbacks( Open, Close )
>+
>+/* Gopher submodule */
>+ add_submodule ()
>+ set_description( N_("Gopher input") )
>+ set_capability( "access", 0 )
>+ set_shortname( "gopher" )
>+ set_category( CAT_INPUT )
>+ set_subcategory( SUBCAT_INPUT_ACCESS )
>+ add_shortcut( "gopher" )
>+ set_callbacks( GopherOpen, Close )
> vlc_module_end ()
>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
--
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200108/e05c4c2a/attachment.html>
More information about the vlc-devel
mailing list