]> git.sesse.net Git - vlc/blob - include/network.h
* include/vlc_keys.h: Fixed a warning in StringToKey().
[vlc] / include / network.h
1 /*****************************************************************************
2  * network.h: interface to communicate with network plug-ins
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: network.h,v 1.5 2003/11/07 17:44:43 fenrir Exp $
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
50
51 typedef struct
52 {
53     char *psz_protocol;
54     char *psz_host;
55     int  i_port;
56
57     char *psz_path;
58
59     char *psz_option;
60 } vlc_url_t;
61
62 /*****************************************************************************
63  * vlc_UrlParse:
64  *****************************************************************************
65  * option : if != 0 then path is split at this char
66  *
67  * format protocol://host[:port]/path[OPTIONoption]
68  *****************************************************************************/
69 static inline void vlc_UrlParse( vlc_url_t *url, char *psz_url, char option )
70 {
71     char *psz_dup = strdup( psz_url );
72     char *psz_parse = psz_dup;
73     char *p;
74
75     url->psz_protocol = NULL;
76     url->psz_host     = NULL;
77     url->i_port       = 0;
78     url->psz_path     = NULL;
79     url->psz_option   = NULL;
80
81     p  = strchr( psz_dup, ':' );
82
83     if( p )
84     {
85         /* we have a protocol */
86
87         /* skip :// */
88         *p++ = '\0';
89         if( p[0] == '/' && p[1] == '/' )
90         {
91             p += 2;
92         }
93         url->psz_protocol = strdup( psz_dup );
94
95         psz_parse = p;
96
97         p = strchr( psz_parse, '/' );
98         if( !p || psz_parse < p )
99         {
100             char *p2;
101
102             /* We have a host[:port] */
103             url->psz_host = strdup( psz_parse );
104             if( p )
105             {
106                 url->psz_host[p - psz_parse] = '\0';
107             }
108
109             p2 = strchr( url->psz_host, ':' );
110             if( p2 )
111             {
112                 *p2++ = '\0';
113                 url->i_port = atoi( p2 );
114             }
115         }
116
117         psz_parse = p;
118     }
119
120     /* Now parse psz_path and psz_option */
121     if( psz_parse )
122     {
123         url->psz_path = strdup( psz_parse );
124         if( option != '\0' )
125         {
126             p = strchr( url->psz_path, option );
127             if( p )
128             {
129                 *p++ = '\0';
130                 url->psz_option = strdup( p );
131             }
132         }
133     }
134     free( psz_dup );
135 }
136
137 /*****************************************************************************
138  * vlc_UrlClean:
139  *****************************************************************************
140  *
141  *****************************************************************************/
142 static inline void vlc_UrlClean( vlc_url_t *url )
143 {
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 );
148
149     url->psz_protocol = NULL;
150     url->psz_host     = NULL;
151     url->i_port       = 0;
152     url->psz_path     = NULL;
153     url->psz_option   = NULL;
154 }
155