]> git.sesse.net Git - vlc/blob - include/network.h
* modules/misc/rtsp.c, src/misc/vlm.c: VOD RTSP support is beginning to work.
[vlc] / include / network.h
1 /*****************************************************************************
2  * network.h: interface to communicate with network plug-ins
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *          Laurent Aimar <fenrir@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
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
30 {
31     unsigned int i_type;
32
33     char * psz_bind_addr;
34     int i_bind_port;
35
36     char * psz_server_addr;
37     int i_server_port;
38
39     int i_ttl;
40
41     /* Return values */
42     int i_handle;
43     size_t i_mtu;
44 };
45
46 /* Socket types */
47 #define NETWORK_UDP 1
48 #define NETWORK_TCP 2
49 #define NETWORK_TCP_PASSIVE 3
50
51
52 typedef struct
53 {
54     char *psz_protocol;
55     char *psz_host;
56     int  i_port;
57
58     char *psz_path;
59
60     char *psz_option;
61 } vlc_url_t;
62
63 /*****************************************************************************
64  * vlc_UrlParse:
65  *****************************************************************************
66  * option : if != 0 then path is split at this char
67  *
68  * format [protocol://][host[:port]]/path[OPTIONoption]
69  *****************************************************************************/
70 static inline void vlc_UrlParse( vlc_url_t *url, char *psz_url, char option )
71 {
72     char *psz_dup = psz_url ? strdup( psz_url ) : 0;
73     char *psz_parse = psz_dup;
74     char *p;
75
76     url->psz_protocol = NULL;
77     url->psz_host     = NULL;
78     url->i_port       = 0;
79     url->psz_path     = NULL;
80     url->psz_option   = NULL;
81
82     if( !psz_url ) return;
83
84     if( ( p  = strstr( psz_parse, ":/" ) ) )
85     {
86         /* we have a protocol */
87
88         /* skip :// */
89         *p++ = '\0';
90         if( p[0] == '/' && p[1] == '/' )
91         {
92             p += 2;
93         }
94         url->psz_protocol = strdup( psz_dup );
95
96         psz_parse = p;
97     }
98
99     p = strchr( psz_parse, '/' );
100     if( !p || psz_parse < p )
101     {
102         char *p2;
103
104         /* We have a host[:port] */
105         url->psz_host = strdup( psz_parse );
106         if( p )
107         {
108             url->psz_host[p - psz_parse] = '\0';
109         }
110
111         if( *url->psz_host == '[' )
112         {
113             /* Ipv6 address */
114             p2 = strchr( url->psz_host, ']' );
115             if( p2 )
116             {
117                 p2 = strchr( p2, ':' );
118             }
119         }
120         else
121         {
122             p2 = strchr( url->psz_host, ':' );
123         }
124         if( p2 )
125         {
126             *p2++ = '\0';
127             url->i_port = atoi( p2 );
128         }
129     }
130     psz_parse = p;
131
132     /* Now parse psz_path and psz_option */
133     if( psz_parse )
134     {
135         url->psz_path = strdup( psz_parse );
136         if( option != '\0' )
137         {
138             p = strchr( url->psz_path, option );
139             if( p )
140             {
141                 *p++ = '\0';
142                 url->psz_option = strdup( p );
143             }
144         }
145     }
146     free( psz_dup );
147 }
148
149 /*****************************************************************************
150  * vlc_UrlClean:
151  *****************************************************************************
152  *
153  *****************************************************************************/
154 static inline void vlc_UrlClean( vlc_url_t *url )
155 {
156     if( url->psz_protocol ) free( url->psz_protocol );
157     if( url->psz_host )     free( url->psz_host );
158     if( url->psz_path )     free( url->psz_path );
159     if( url->psz_option )   free( url->psz_option );
160
161     url->psz_protocol = NULL;
162     url->psz_host     = NULL;
163     url->i_port       = 0;
164     url->psz_path     = NULL;
165     url->psz_option   = NULL;
166 }
167
168 #define net_OpenTCP(a, b, c) __net_OpenTCP(VLC_OBJECT(a), b, c)
169 VLC_EXPORT( int, __net_OpenTCP, ( vlc_object_t *p_this, char *psz_host, int i_port ) );
170
171 #define net_ListenTCP(a, b, c) __net_ListenTCP(VLC_OBJECT(a), b, c)
172 VLC_EXPORT( int, __net_ListenTCP, ( vlc_object_t *p_this, char *psz_localaddr, int i_port ) );
173
174 #define net_Accept(a, b, c) __net_Accept(VLC_OBJECT(a), b, c)
175 VLC_EXPORT( int, __net_Accept, ( vlc_object_t *p_this, int fd_listen, mtime_t i_wait ) );
176
177 #define net_OpenUDP(a, b, c, d, e ) __net_OpenUDP(VLC_OBJECT(a), b, c, d, e)
178 VLC_EXPORT( int, __net_OpenUDP, ( vlc_object_t *p_this, char *psz_bind, int i_bind, char *psz_server, int i_server ) );
179
180 VLC_EXPORT( void, net_Close, ( int fd ) );
181
182 #define net_Read(a,b,c,d,e) __net_Read(VLC_OBJECT(a),b,c,d,e)
183 VLC_EXPORT( int, __net_Read, ( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data, vlc_bool_t b_retry ) );
184
185 #define net_ReadNonBlock(a,b,c,d,e) __net_ReadNonBlock(VLC_OBJECT(a),b,c,d,e)
186 VLC_EXPORT( int, __net_ReadNonBlock, ( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data, mtime_t i_wait ) );
187
188 #define net_Write(a,b,c,d) __net_Write(VLC_OBJECT(a),b,c,d)
189 VLC_EXPORT( int, __net_Write, ( vlc_object_t *p_this, int fd, uint8_t *p_data, int i_data ) );
190
191 #define net_Gets(a,b) __net_Gets(VLC_OBJECT(a),b)
192 VLC_EXPORT( char *, __net_Gets, ( vlc_object_t *p_this, int fd ) );
193
194 VLC_EXPORT( int, net_Printf, ( vlc_object_t *p_this, int fd, const char *psz_fmt, ... ) );
195
196 #define net_vaPrintf(a,b,c,d) __net_vaPrintf(VLC_OBJECT(a),b,c,d)
197 VLC_EXPORT( int, __net_vaPrintf, ( vlc_object_t *p_this, int fd, const char *psz_fmt, va_list args ) );