• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2007-2008 The Android Open Source Project
2 **
3 ** This software is licensed under the terms of the GNU General Public
4 ** License version 2, as published by the Free Software Foundation, and
5 ** may be copied, distributed, and modified under those terms.
6 **
7 ** This program is distributed in the hope that it will be useful,
8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 ** GNU General Public License for more details.
11 */
12 #ifndef _PROXY_COMMON_H_
13 #define _PROXY_COMMON_H_
14 
15 #include "android/sockets.h"
16 
17 #ifdef _WIN32
18 #include <winsock2.h>
19 #else
20 #include <sys/select.h>
21 #endif
22 
23 /* types and definitions used by all proxy connections */
24 
25 typedef enum {
26     PROXY_EVENT_NONE,
27     PROXY_EVENT_CONNECTED,
28     PROXY_EVENT_CONNECTION_REFUSED,
29     PROXY_EVENT_SERVER_ERROR
30 } ProxyEvent;
31 
32 /* event can't be NONE when this callback is called */
33 typedef void (*ProxyEventFunc)( void*  opaque, int  fd, ProxyEvent  event );
34 
35 extern void  proxy_set_verbose(int  mode);
36 
37 
38 typedef enum {
39     PROXY_OPTION_AUTH_USERNAME = 1,
40     PROXY_OPTION_AUTH_PASSWORD,
41 
42     PROXY_OPTION_HTTP_NOCACHE = 100,
43     PROXY_OPTION_HTTP_KEEPALIVE,
44     PROXY_OPTION_HTTP_USER_AGENT,
45 
46     PROXY_OPTION_MAX
47 
48 } ProxyOptionType;
49 
50 
51 typedef struct {
52     ProxyOptionType  type;
53     const char*      string;
54     int              string_len;
55 } ProxyOption;
56 
57 
58 /* add a new proxified socket connection to the manager's list. the event function
59  * will be called when the connection is established or refused.
60  *
61  * only IPv4 is supported at the moment, since our slirp code cannot handle IPv6
62  *
63  * returns 0 on success, or -1 if there is no proxy service for this type of connection
64  */
65 extern int   proxy_manager_add( SockAddress*         address,
66                                 SocketType           sock_type,
67                                 ProxyEventFunc       ev_func,
68                                 void*                ev_opaque );
69 
70 /* remove an on-going proxified socket connection from the manager's list.
71  * this is only necessary when the socket connection must be canceled before
72  * the connection accept/refusal occured
73  */
74 extern void  proxy_manager_del( void*  ev_opaque );
75 
76 /* this function is called to update the select file descriptor sets
77  * with those of the proxified connection sockets that are currently managed */
78 extern void  proxy_manager_select_fill( int     *pcount,
79                                         fd_set*  read_fds,
80                                         fd_set*  write_fds,
81                                         fd_set*  err_fds);
82 
83 /* this function is called to act on proxified connection sockets when network events arrive */
84 extern void  proxy_manager_poll( fd_set*  read_fds,
85                                  fd_set*  write_fds,
86                                  fd_set*  err_fds );
87 
88 /* this function checks that one can connect to a given proxy. It will simply try to connect()
89  * to it, for a specified timeout, in milliseconds, then close the connection.
90  *
91  * returns 0 in case of success, and -1 in case of error. errno will be set to ETIMEDOUT in
92  * case of timeout, or ECONNREFUSED if the connection is refused.
93  */
94 
95 extern int   proxy_check_connection( const char* proxyname,
96                                      int         proxyname_len,
97                                      int         proxyport,
98                                      int         timeout_ms );
99 
100 #endif /* END */
101