blob: da5c7885f65c488c0426e3e868dd9fc9e5bc820f [file] [log] [blame]
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -08001/* 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
David 'Digit' Turnercc330d42013-12-14 23:26:42 +010015#include "android/sockets.h"
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080016
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
25typedef 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 */
33typedef void (*ProxyEventFunc)( void* opaque, int fd, ProxyEvent event );
34
35extern void proxy_set_verbose(int mode);
36
37
38typedef 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
51typedef 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 */
65extern 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 */
74extern 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 */
David 'Digit' Turnerc0052462014-02-25 18:39:29 +010078extern void proxy_manager_select_fill( int *pcount,
79 fd_set* read_fds,
80 fd_set* write_fds,
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080081 fd_set* err_fds);
82
83/* this function is called to act on proxified connection sockets when network events arrive */
David 'Digit' Turnerc0052462014-02-25 18:39:29 +010084extern void proxy_manager_poll( fd_set* read_fds,
85 fd_set* write_fds,
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -080086 fd_set* err_fds );
87
David 'Digit' Turner9b98dbd2010-07-30 15:35:00 -070088/* 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
95extern int proxy_check_connection( const char* proxyname,
96 int proxyname_len,
97 int proxyport,
98 int timeout_ms );
99
The Android Open Source Project8b23a6c2009-03-03 19:30:32 -0800100#endif /* END */