More mailmap fixes
[vlc.git] / modules / access / tcp.c
blobbed738df358a7fb20ad7a85fcd9113f8d6e2a41d
1 /*****************************************************************************
2 * tcp.c: TCP input module
3 *****************************************************************************
4 * Copyright (C) 2003-2004 the VideoLAN team
5 * $Id$
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
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 General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_access.h>
36 #include <vlc_network.h>
38 /*****************************************************************************
39 * Module descriptor
40 *****************************************************************************/
41 static int Open ( vlc_object_t * );
42 static void Close( vlc_object_t * );
44 vlc_module_begin ()
45 set_shortname( N_("TCP") )
46 set_description( N_("TCP input") )
47 set_category( CAT_INPUT )
48 set_subcategory( SUBCAT_INPUT_ACCESS )
50 set_capability( "access", 0 )
51 add_shortcut( "tcp" )
52 set_callbacks( Open, Close )
53 vlc_module_end ()
55 /*****************************************************************************
56 * Local prototypes
57 *****************************************************************************/
58 struct access_sys_t
60 int fd;
64 static ssize_t Read( access_t *, uint8_t *, size_t );
65 static int Control( access_t *, int, va_list );
67 /*****************************************************************************
68 * Open: open the socket
69 *****************************************************************************/
70 static int Open( vlc_object_t *p_this )
72 access_t *p_access = (access_t *)p_this;
73 access_sys_t *p_sys;
75 char *psz_dup = strdup(p_access->psz_location);
76 char *psz_parser = psz_dup;
78 /* Parse server:port */
79 if( *psz_parser == '[' )
81 psz_parser = strchr( psz_parser, ']' );
82 if( psz_parser == NULL )
83 psz_parser = psz_dup;
85 psz_parser = strchr( psz_parser, ':' );
87 if( psz_parser == NULL )
89 msg_Err( p_access, "missing port number : %s", psz_dup );
90 free( psz_dup );
91 return VLC_EGENERIC;
94 *psz_parser++ = '\0';
96 /* Init p_access */
97 access_InitFields( p_access );
98 ACCESS_SET_CALLBACKS( Read, NULL, Control, NULL );
99 p_sys = p_access->p_sys = calloc( 1, sizeof( access_sys_t ) );
100 if( !p_sys )
102 free( psz_dup );
103 return VLC_ENOMEM;
106 p_sys->fd = net_ConnectTCP( p_access, psz_dup, atoi( psz_parser ) );
107 free( psz_dup );
109 if( p_sys->fd < 0 )
111 free( p_sys );
112 return VLC_EGENERIC;
115 return VLC_SUCCESS;
118 /*****************************************************************************
119 * Close: free unused data structures
120 *****************************************************************************/
121 static void Close( vlc_object_t *p_this )
123 access_t *p_access = (access_t *)p_this;
124 access_sys_t *p_sys = p_access->p_sys;
126 net_Close( p_sys->fd );
127 free( p_sys );
130 /*****************************************************************************
131 * Read: read on a file descriptor
132 *****************************************************************************/
133 static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
135 access_sys_t *p_sys = p_access->p_sys;
136 int i_read;
138 if( p_access->info.b_eof )
139 return 0;
141 i_read = net_Read( p_access, p_sys->fd, NULL, p_buffer, i_len,
142 false );
143 if( i_read == 0 )
144 p_access->info.b_eof = true;
145 else if( i_read > 0 )
146 p_access->info.i_pos += i_read;
148 return i_read;
151 /*****************************************************************************
152 * Control:
153 *****************************************************************************/
154 static int Control( access_t *p_access, int i_query, va_list args )
156 bool *pb_bool;
157 int64_t *pi_64;
159 switch( i_query )
161 /* */
162 case ACCESS_CAN_SEEK:
163 case ACCESS_CAN_FASTSEEK:
164 pb_bool = (bool*)va_arg( args, bool* );
165 *pb_bool = false;
166 break;
167 case ACCESS_CAN_PAUSE:
168 pb_bool = (bool*)va_arg( args, bool* );
169 *pb_bool = true; /* FIXME */
170 break;
171 case ACCESS_CAN_CONTROL_PACE:
172 pb_bool = (bool*)va_arg( args, bool* );
173 *pb_bool = true; /* FIXME */
174 break;
176 case ACCESS_GET_PTS_DELAY:
177 pi_64 = (int64_t*)va_arg( args, int64_t * );
178 *pi_64 = INT64_C(1000)
179 * var_InheritInteger( p_access, "network-caching" );
180 break;
182 /* */
183 case ACCESS_SET_PAUSE_STATE:
184 /* Nothing to do */
185 break;
187 case ACCESS_GET_TITLE_INFO:
188 case ACCESS_SET_TITLE:
189 case ACCESS_SET_SEEKPOINT:
190 case ACCESS_SET_PRIVATE_ID_STATE:
191 case ACCESS_GET_CONTENT_TYPE:
192 return VLC_EGENERIC;
194 default:
195 msg_Warn( p_access, "unimplemented query in control" );
196 return VLC_EGENERIC;
199 return VLC_SUCCESS;