1 /*****************************************************************************
2 * tcp.c: TCP input module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 VLC authors and VideoLAN
5 * $Id: 947ee49b061fa5d59eb48c7f068b52bce6f79766 $
6 *
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <errno.h>
29
30 #include <vlc_common.h>
31 #include <vlc_plugin.h>
32 #include <vlc_access.h>
33 #include <vlc_url.h>
34 #include <vlc_tls.h>
35
Read(stream_t * access,void * buf,size_t len)36 static ssize_t Read(stream_t *access, void *buf, size_t len)
37 {
38 return vlc_tls_Read(access->p_sys, buf, len, false);
39 }
40
Control(stream_t * p_access,int i_query,va_list args)41 static int Control( stream_t *p_access, int i_query, va_list args )
42 {
43 bool *pb_bool;
44 int64_t *pi_64;
45
46 switch( i_query )
47 {
48 case STREAM_CAN_SEEK:
49 case STREAM_CAN_FASTSEEK:
50 pb_bool = va_arg( args, bool * );
51 *pb_bool = false;
52 break;
53 case STREAM_CAN_PAUSE:
54 pb_bool = va_arg( args, bool * );
55 *pb_bool = true; /* FIXME */
56 break;
57 case STREAM_CAN_CONTROL_PACE:
58 pb_bool = va_arg( args, bool * );
59 *pb_bool = true; /* FIXME */
60 break;
61
62 case STREAM_GET_PTS_DELAY:
63 pi_64 = va_arg( args, int64_t * );
64 *pi_64 = INT64_C(1000)
65 * var_InheritInteger( p_access, "network-caching" );
66 break;
67
68 case STREAM_SET_PAUSE_STATE:
69 /* Nothing to do */
70 break;
71
72 default:
73 return VLC_EGENERIC;
74 }
75 return VLC_SUCCESS;
76 }
77
Open(vlc_object_t * obj)78 static int Open(vlc_object_t *obj)
79 {
80 stream_t *access = (stream_t *)obj;
81 vlc_tls_t *sock;
82 vlc_url_t url;
83
84 if (vlc_UrlParse(&url, access->psz_url)
85 || url.psz_host == NULL || url.i_port == 0)
86 {
87 msg_Err(access, "invalid location: %s", access->psz_location);
88 vlc_UrlClean(&url);
89 return VLC_EGENERIC;
90 }
91
92 sock = vlc_tls_SocketOpenTCP(obj, url.psz_host, url.i_port);
93 vlc_UrlClean(&url);
94 if (sock == NULL)
95 return VLC_EGENERIC;
96
97 access->p_sys = sock;
98 access->pf_read = Read;
99 access->pf_block = NULL;
100 access->pf_control = Control;
101 access->pf_seek = NULL;
102 return VLC_SUCCESS;
103 }
104
Close(vlc_object_t * p_this)105 static void Close( vlc_object_t *p_this )
106 {
107 stream_t *access = (stream_t *)p_this;
108
109 vlc_tls_SessionDelete(access->p_sys);
110 }
111
112 /*****************************************************************************
113 * Module descriptor
114 *****************************************************************************/
115 vlc_module_begin ()
116 set_shortname( N_("TCP") )
117 set_description( N_("TCP input") )
118 set_category( CAT_INPUT )
119 set_subcategory( SUBCAT_INPUT_ACCESS )
120
121 set_capability( "access", 0 )
122 add_shortcut( "tcp" )
123 set_callbacks( Open, Close )
124 vlc_module_end ()
125