1 /*****************************************************************************
2 * network.h: interface to communicate with network plug-ins
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: network.h,v 1.7 2004/01/06 23:03:16 fenrir Exp $
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Laurent Aimar <fenrir@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
26 * network_socket_t: structure passed to a network plug-in to define the
27 * kind of socket we want
28 *****************************************************************************/
29 struct network_socket_t
36 char * psz_server_addr;
62 /*****************************************************************************
64 *****************************************************************************
65 * option : if != 0 then path is split at this char
67 * format [protocol://][host[:port]]/path[OPTIONoption]
68 *****************************************************************************/
69 static inline void vlc_UrlParse( vlc_url_t *url, char *psz_url, char option )
71 char *psz_dup = strdup( psz_url );
72 char *psz_parse = psz_dup;
75 url->psz_protocol = NULL;
79 url->psz_option = NULL;
81 if( ( p = strstr( psz_parse, ":/" ) ) )
83 /* we have a protocol */
87 if( p[0] == '/' && p[1] == '/' )
91 url->psz_protocol = strdup( psz_dup );
96 p = strchr( psz_parse, '/' );
97 if( !p || psz_parse < p )
101 /* We have a host[:port] */
102 url->psz_host = strdup( psz_parse );
105 url->psz_host[p - psz_parse] = '\0';
108 p2 = strchr( url->psz_host, ':' );
112 url->i_port = atoi( p2 );
120 /* Now parse psz_path and psz_option */
123 url->psz_path = strdup( psz_parse );
126 p = strchr( url->psz_path, option );
130 url->psz_option = strdup( p );
137 /*****************************************************************************
139 *****************************************************************************
141 *****************************************************************************/
142 static inline void vlc_UrlClean( vlc_url_t *url )
144 if( url->psz_protocol ) free( url->psz_protocol );
145 if( url->psz_host ) free( url->psz_host );
146 if( url->psz_path ) free( url->psz_path );
147 if( url->psz_option ) free( url->psz_option );
149 url->psz_protocol = NULL;
150 url->psz_host = NULL;
152 url->psz_path = NULL;
153 url->psz_option = NULL;
156 #define net_OpenTCP(a, b, c) __net_OpenTCP(VLC_OBJECT(a), b, c)
157 VLC_EXPORT( int, __net_OpenTCP, ( vlc_object_t *p_this, char *psz_host, int i_port ) );
159 VLC_EXPORT( void, net_Close, ( int fd ) );
161 #define net_Read(a,b,c,d,e) __net_Read(VLC_OBJECT(a),b,c,d,e)
162 VLC_EXPORT( int, __net_Read, ( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data, vlc_bool_t b_retry ) );
164 #define net_Write(a,b,c,d) __net_Write(VLC_OBJECT(a),b,c,d)
165 VLC_EXPORT( int, __net_Write, ( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data ) );
167 #define net_Gets(a,b) __net_Gets(VLC_OBJECT(a),b)
168 VLC_EXPORT( char *, __net_Gets, ( vlc_object_t *p_this, int fd ) );
170 VLC_EXPORT( int, net_Printf, ( vlc_object_t *p_this, int fd, char *psz_fmt, ... ) );