OSDN Git Service

add tstools.
[rec10/rec10-git.git] / tstools / DtsEdit / src / gpac / network.h
1 /*\r
2  *                      GPAC - Multimedia Framework C SDK\r
3  *\r
4  *                      Copyright (c) Jean Le Feuvre 2000-2005 \r
5  *                                      All rights reserved\r
6  *\r
7  *  This file is part of GPAC / common tools sub-project\r
8  *\r
9  *  GPAC is free software; you can redistribute it and/or modify\r
10  *  it under the terms of the GNU Lesser General Public License as published by\r
11  *  the Free Software Foundation; either version 2, or (at your option)\r
12  *  any later version.\r
13  *   \r
14  *  GPAC is distributed in the hope that it will be useful,\r
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  *  GNU Lesser General Public License for more details.\r
18  *   \r
19  *  You should have received a copy of the GNU Lesser General Public\r
20  *  License along with this library; see the file COPYING.  If not, write to\r
21  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. \r
22  *\r
23  */\r
24 \r
25 #ifndef _GF_NET_H_\r
26 #define _GF_NET_H_\r
27 \r
28 #ifdef __cplusplus\r
29 extern "C" {\r
30 #endif\r
31 \r
32 /*!\r
33  *      \file <gpac/network.h>\r
34  *      \brief IP network functions.\r
35  */\r
36 \r
37  /*!\r
38  *      \addtogroup net_grp network\r
39  *      \ingroup utils_grp\r
40  *      \brief IP Network Functions\r
41  *\r
42  *This section documents the IP network functions of the GPAC framework.\r
43  *      @{\r
44  */\r
45 \r
46 #include <gpac/tools.h>\r
47 \r
48 \r
49 /*!\r
50  *\brief URL local test\r
51  *\r
52  *Tests whether a URL describes a local file or not\r
53  *\param url the url to analyze\r
54  *\return 1 if the URL describes a local file, 0 otherwise\r
55  */\r
56 Bool gf_url_is_local(const char *url);\r
57 \r
58 /*!\r
59  *\brief gets absolute file path\r
60  *\r
61  *Gets the absolute file path from a relative path and its parent absolute one. This can only be used with file paths.\r
62  *\param pathName the relative path name of a file\r
63  *\param parentPath the absolute parent path name \r
64  *\return absolute path name of the file, or NULL if bad paths are provided.\r
65  \note the returned string must be freed by user\r
66  */\r
67 char *gf_url_get_absolute_path(const char *pathName, const char *parentPath);\r
68 /*concatenates URL and gets back full URL - returned string must be freed by user*/\r
69 /*!\r
70  *\brief URL concatenation\r
71  *\r
72  *Concatenates a relative URL with its parent URL\r
73  *\param parentName URL of the parent service\r
74  *\param pathName URL of the service\r
75  *\return absolute path name of the service, or NULL if bad paths are provided or if the service path is already an absolute one.\r
76  \note the returned string must be freed by user\r
77  */\r
78 char *gf_url_concatenate(const char *parentName, const char *pathName);\r
79 \r
80 \r
81 /*!\r
82  *\brief URL to file system\r
83  *\r
84  *Converts a local URL to a file system value. Removes all white spaces and similar\r
85  *\param url url to convert\r
86  */\r
87 void gf_url_to_fs_path(char *url);\r
88 \r
89 /*!\r
90  *\brief gets UTC time \r
91  *\r
92  *Gets UTC time since midnight Jan 1970\r
93  *\param sec number of seconds\r
94  *\param msec number of milliseconds\r
95  */\r
96 void gf_utc_time_since_1970(u32 *sec, u32 *msec);\r
97 \r
98 \r
99 /*!\r
100  *      \brief NTP seconds from 1900 to 1970\r
101  *      \hideinitializer\r
102  *\r
103  *      Macro giving the number of seconds from from 1900 to 1970\r
104 */\r
105 #define GF_NTP_SEC_1900_TO_1970 2208988800ul\r
106 \r
107 /*!\r
108  *\brief gets NTP time \r
109  *\r
110  *Gets NTP (Network Time Protocol) in seconds and fractional side\r
111  \param sec NTP time in seconds\r
112  \param frac fractional NTP time expressed in 1 / (1<<32 - 1) seconds units\r
113  */\r
114 void gf_net_get_ntp(u32 *sec, u32 *frac);\r
115 \r
116 /*!\r
117  * Socket options\r
118  *      \hideinitializer\r
119  */\r
120 enum\r
121 {\r
122         /*!Reuses port.*/\r
123         GF_SOCK_REUSE_PORT = 1,\r
124         /*!Forces IPV6 if available.*/\r
125         GF_SOCK_FORCE_IPV6 = 1<<1\r
126 };\r
127 \r
128 /*!\r
129  *\brief abstracted socket object\r
130  *\r
131  *The abstracted socket object allows you to build client and server applications very simply\r
132  *with support for unicast and multicast (no IPv6 yet)\r
133 */\r
134 typedef struct __tag_socket GF_Socket;\r
135 \r
136 /*!Buffer size to pass for IP address retrieval*/\r
137 #define GF_MAX_IP_NAME_LEN      516\r
138 \r
139 /*!socket is a TCP socket*/\r
140 #define GF_SOCK_TYPE_TCP                0x01\r
141 /*!socket is a UDP socket*/\r
142 #define GF_SOCK_TYPE_UDP                0x02\r
143 \r
144 /*!\r
145  *\brief socket constructor\r
146  *\r
147  *Constructs a socket object\r
148  *\param SocketType the socket type to create, either UDP or TCP\r
149  *\return the socket object or NULL if network initialization failure\r
150  */\r
151 GF_Socket *gf_sk_new(u32 SocketType);\r
152 /*!\r
153  *\brief socket destructor\r
154  *\r
155  *Deletes a socket object\r
156  *\param sock the socket object\r
157  */\r
158 void gf_sk_del(GF_Socket *sock);\r
159 \r
160 /*!\r
161  *\brief reset internal buffer\r
162  *\r
163  *Forces the internal socket buffer to be reseted (discarded)\r
164  *\param sock the socket object\r
165  */\r
166 void gf_sk_reset(GF_Socket *sock);\r
167 /*!\r
168  *\brief socket buffer size control\r
169  *\r
170  *Sets the size of the internal buffer of the socket. The socket MUST be bound or connected before.\r
171  *\param sock the socket object\r
172  *\param send_buffer if 0, sets the size of the reception buffer, otherwise sets the size of the emission buffer\r
173  *\param new_size new size of the buffer in bytes.\r
174  *\warning This operation may fail depending on the provider, hardware...\r
175  */\r
176 GF_Err gf_sk_set_buffer_size(GF_Socket *sock, Bool send_buffer, u32 new_size);\r
177 \r
178 /*!\r
179  *\brief blocking mode control\r
180  *\r
181  *Sets the blocking mode of a socket on or off. A blocking socket will wait for the net operation to be possible \r
182  *while a non-blocking one would return an error. By default, sockets are created in blocking mode\r
183  *\param sock the socket object\r
184  *\param NonBlockingOn set to 1 to use on-blocking sockets, 0 otherwise\r
185  */\r
186 GF_Err gf_sk_set_block_mode(GF_Socket *sock, Bool NonBlockingOn);\r
187 /*!\r
188  *\brief socket binding\r
189  *\r
190  *Binds the given socket to the specified port.\r
191  *\param local_ip the local interface IP address if desired. If NULL, the default interface will be used.\r
192  *\param sock the socket object\r
193  *\param port port number to bind this socket to\r
194  *\param peer_name the remote server address\r
195  *\param peer_port remote port number to connect the socket to\r
196  *\param options list of option for the bind operation.\r
197  */\r
198 GF_Err gf_sk_bind(GF_Socket *sock, char *local_ip, u16 port, char *peer_name, u16 peer_port, u32 options);\r
199 /*!\r
200  *\brief connects a socket \r
201  *\r
202  *Connects a socket to a remote peer on a given port \r
203  *\param sock the socket object\r
204  *\param peer_name the remote server address (IP or DNS)\r
205  *\param port remote port number to connect the socket to\r
206  *\param local_ip the local (client) address (IP or DNS) if any, NULL otherwise.\r
207  */\r
208 GF_Err gf_sk_connect(GF_Socket *sock, char *peer_name, u16 port, char *local_ip);\r
209 /*!\r
210  *\brief data emission\r
211  *\r
212  *Sends a buffer on the socket. The socket must be in a bound or connected mode\r
213  *\param sock the socket object\r
214  *\param buffer the data buffer to send\r
215  *\param length the data length to send\r
216  */\r
217 GF_Err gf_sk_send(GF_Socket *sock, char *buffer, u32 length);\r
218 /*!\r
219  *\brief data reception\r
220  * \r
221  *Fetches data on a socket. The socket must be in a bound or connected state\r
222  *\param sock the socket object\r
223  *\param buffer the recpetion buffer where data is written\r
224  *\param length the allocated size of the reception buffer\r
225  *\param start_from the offset in the reception buffer where to start writing\r
226  *\param read the actual number of bytes received\r
227  */\r
228 GF_Err gf_sk_receive(GF_Socket *sock, char *buffer, u32 length, u32 start_from, u32 *read);\r
229 /*!\r
230  *\brief socket listening\r
231  *\r
232  *Sets the socket in a listening state. This socket must have been bound to a port before \r
233  *\param sock the socket object\r
234  *\param max_conn the maximum number of simultaneous connection this socket will accept\r
235  */\r
236 GF_Err gf_sk_listen(GF_Socket *sock, u32 max_conn);\r
237 /*!\r
238  *\brief socket accept\r
239  *\r
240  *Accepts an incomming connection on a listening socket\r
241  *\param sock the socket object\r
242  *\param new_conn the resulting connection socket object\r
243  */\r
244 GF_Err gf_sk_accept(GF_Socket *sock, GF_Socket **new_conn);\r
245 \r
246 /*!\r
247  *\brief server socket mode \r
248  *\r
249  *Disable the Nable algo (e.g. set TCP_NODELAY) and set the KEEPALIVE on \r
250  *\param sock the socket object\r
251  *\param server_on sets server mode on or off\r
252 */\r
253 GF_Err gf_sk_server_mode(GF_Socket *sock, Bool server_on);\r
254 \r
255 /*!\r
256  *\brief get local host name\r
257  *\r
258  *Retrieves local host name.\r
259  *\param buffer destination buffer for name. Buffer must be GF_MAX_IP_NAME_LEN long\r
260  */\r
261 GF_Err gf_sk_get_host_name(char *buffer);\r
262 \r
263 /*!\r
264  *\brief get local IP\r
265  *\r
266  *Gets local IP address of a connected socket, typically used for server after an ACCEPT\r
267  *\param sock the socket object\r
268  *\param buffer destination buffer for IP address. Buffer must be GF_MAX_IP_NAME_LEN long\r
269  */\r
270 GF_Err gf_sk_get_local_ip(GF_Socket *sock, char *buffer);\r
271 /*!\r
272  *\brief get local info\r
273  *\r
274  *Gets local socket info of a socket\r
275  *\param sock the socket object\r
276  *\param port local port number of the socket\r
277  *\param sock_type socket type (UDP or TCP)\r
278  */\r
279 GF_Err gf_sk_get_local_info(GF_Socket *sock, u16 *port, u32 *sock_type);\r
280 \r
281 /*!\r
282  *\brief get remote address\r
283  *\r
284  *Gets the remote address of a peer. The socket MUST be connected.\r
285  *\param sock the socket object\r
286  *\param buffer destination buffer for IP address. Buffer must be GF_MAX_IP_NAME_LEN long\r
287  */\r
288 GF_Err gf_sk_get_remote_address(GF_Socket *sock, char *buffer);\r
289 \r
290 /*!\r
291  *\brief set remote address\r
292  *\r
293  *Sets the remote address of a socket. This is used by connectionless sockets using SendTo and ReceiveFrom\r
294  *\param sock the socket object\r
295  *\param address the remote peer address\r
296  *\param port the remote peer port\r
297  */\r
298 GF_Err gf_sk_set_remote(GF_Socket *sock, char *address, u16 port);\r
299 \r
300 \r
301 /*!\r
302  *\brief multicast setup\r
303  *\r
304  *Performs multicast setup (BIND and JOIN) for the socket object\r
305  *\param sock the socket object\r
306  *\param multi_ip_add the multicast IP address\r
307  *\param multi_port the multicast port number\r
308  *\param TTL the multicast TTL (Time-To-Live)\r
309  *\param no_bind if sets, only join the multicast\r
310  *\param local_interface_ip the local interface IP address if desired. If NULL, the default interface will be used.\r
311  */\r
312 GF_Err gf_sk_setup_multicast(GF_Socket *sock, char *multi_ip_add, u16 multi_port, u32 TTL, Bool no_bind, char *local_interface_ip);\r
313 /*!\r
314  *brief multicast address test\r
315  *\r
316  *tests whether an IP address is a multicast one or not\r
317  *\param multi_ip_add the multicast IP address to test\r
318  *\return 1 if the address is a multicast one, 0 otherwise\r
319  */\r
320 u32 gf_sk_is_multicast_address(char *multi_ip_add);\r
321 \r
322 /*!\r
323  *\brief send data with wait delay\r
324  *\r
325  *Sends data with a max wait delay. This is used for http / ftp sockets mainly. The socket must be connected.\r
326  *\param sock the socket object\r
327  *\param buffer the data buffer to send\r
328  *\param length the data length to send\r
329  *\param delay_sec the maximum delay in second to wait before aborting\r
330  *\return If the operation timeed out, the function will return a GF_IP_SOCK_WOULD_BLOCK error.\r
331  */\r
332 GF_Err gf_sk_send_wait(GF_Socket *sock, char *buffer, u32 length, u32 delay_sec);\r
333 /* receive data with a max wait delay of Second - used for http / ftp sockets mainly*/\r
334 /*!\r
335  *\brief receive data with wait delay\r
336  *\r
337  *Fetches data with a max wait delay. This is used for http / ftp sockets mainly. The socket must be connected.\r
338  *\param sock the socket object\r
339  *\param buffer the recpetion buffer where data is written\r
340  *\param length the allocated size of the reception buffer\r
341  *\param start_from the offset in the reception buffer where to start writing\r
342  *\param read the actual number of bytes received\r
343  *\param delay_sec the maximum delay in second to wait before aborting\r
344  *\return If the operation timeed out, the function will return a GF_IP_SOCK_WOULD_BLOCK error.\r
345  */\r
346 GF_Err gf_sk_receive_wait(GF_Socket *sock, char *buffer, u32 length, u32 start_from, u32 *read, u32 delay_sec);\r
347 \r
348 /*!\r
349  *\brief gets socket handle\r
350  *\r
351  *Gets the socket low-level handle as used by OpenSSL.\r
352  *\param sock the socket object\r
353  *\return the socket handle\r
354  */\r
355 s32 gf_sk_get_handle(GF_Socket *sock);\r
356 \r
357 \r
358 /*!\r
359  *\brief gets ipv6 support\r
360  *\r
361  *Returns IPV6 support information.\r
362  *\return 2 if the machine has IPV6 support, 1 if the library was compiled with IPV6 support, 0 otherwise\r
363  */\r
364 u32 gf_net_has_ipv6();\r
365 \r
366 \r
367 /*!\r
368  *\brief checks address type\r
369  *\r
370  *Checks if an address is an IPV6 or IPV4 one.\r
371  *\return true 1 if address is IPV6 one, 0 otherwise\r
372  */\r
373 Bool gf_net_is_ipv6(char *address);\r
374 \r
375 \r
376 /*!\r
377  *      \brief MobileIP Callback\r
378  *\r
379  * The gf_net_mobileip_ctrl_cbk type is the type for the callback of the \ref gf_net_set_mobileip_callback function. By default no mobileip is used\r
380  *      \param cbck Opaque user data.\r
381  *      \param start boolean indicating wether the MobileIP subsystem should be started or stoped.\r
382  *      \return Error code if needed.\r
383  *\r
384  */\r
385 typedef GF_Err (*gf_net_mobileip_ctrl_cbk)(Bool start);\r
386 \r
387 /*!\r
388  *\brief Assigns MobileIP callback\r
389  *\r
390  *Assigns the MobileIP control callback.\r
391  *\param _mobip_cbk MobileIP control callback\r
392  */\r
393 void gf_net_mobileip_set_callback(gf_net_mobileip_ctrl_cbk _mobip_cbk, const char *MobileIP);\r
394 \r
395 /*! @} */\r
396 \r
397 #ifdef __cplusplus\r
398 }\r
399 #endif\r
400 \r
401 \r
402 #endif          /*_GF_NET_H_*/\r
403 \r