Frameworks/libpurple.framework/Versions/0.6.2/Headers/proxy.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 2490 Frameworks/libpurple.framework/Versions/0.6.0/Headers/proxy.h@3ea385a6b702
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
     1 /**
     2  * @file proxy.h Proxy API
     3  * @ingroup core
     4  */
     5 
     6 /* purple
     7  *
     8  * Purple is the legal property of its developers, whose names are too numerous
     9  * to list here.  Please refer to the COPYRIGHT file distributed with this
    10  * source distribution.
    11  *
    12  * This program is free software; you can redistribute it and/or modify
    13  * it under the terms of the GNU General Public License as published by
    14  * the Free Software Foundation; either version 2 of the License, or
    15  * (at your option) any later version.
    16  *
    17  * This program is distributed in the hope that it will be useful,
    18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20  * GNU General Public License for more details.
    21  *
    22  * You should have received a copy of the GNU General Public License
    23  * along with this program; if not, write to the Free Software
    24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
    25  */
    26 #ifndef _PURPLE_PROXY_H_
    27 #define _PURPLE_PROXY_H_
    28 
    29 #include <glib.h>
    30 #include "eventloop.h"
    31 
    32 /**
    33  * A type of proxy connection.
    34  */
    35 typedef enum
    36 {
    37 	PURPLE_PROXY_USE_GLOBAL = -1,  /**< Use the global proxy information. */
    38 	PURPLE_PROXY_NONE = 0,         /**< No proxy.                         */
    39 	PURPLE_PROXY_HTTP,             /**< HTTP proxy.                       */
    40 	PURPLE_PROXY_SOCKS4,           /**< SOCKS 4 proxy.                    */
    41 	PURPLE_PROXY_SOCKS5,           /**< SOCKS 5 proxy.                    */
    42 	PURPLE_PROXY_USE_ENVVAR        /**< Use environmental settings.       */
    43 
    44 } PurpleProxyType;
    45 
    46 /**
    47  * Information on proxy settings.
    48  */
    49 typedef struct
    50 {
    51 	PurpleProxyType type;   /**< The proxy type.  */
    52 
    53 	char *host;           /**< The host.        */
    54 	int   port;           /**< The port number. */
    55 	char *username;       /**< The username.    */
    56 	char *password;       /**< The password.    */
    57 
    58 } PurpleProxyInfo;
    59 
    60 typedef struct _PurpleProxyConnectData PurpleProxyConnectData;
    61 
    62 typedef void (*PurpleProxyConnectFunction)(gpointer data, gint source, const gchar *error_message);
    63 
    64 
    65 #include "account.h"
    66 
    67 #ifdef __cplusplus
    68 extern "C" {
    69 #endif
    70 
    71 /**************************************************************************/
    72 /** @name Proxy structure API                                             */
    73 /**************************************************************************/
    74 /*@{*/
    75 
    76 /**
    77  * Creates a proxy information structure.
    78  *
    79  * @return The proxy information structure.
    80  */
    81 PurpleProxyInfo *purple_proxy_info_new(void);
    82 
    83 /**
    84  * Destroys a proxy information structure.
    85  *
    86  * @param info The proxy information structure to destroy.
    87  */
    88 void purple_proxy_info_destroy(PurpleProxyInfo *info);
    89 
    90 /**
    91  * Sets the type of proxy.
    92  *
    93  * @param info The proxy information.
    94  * @param type The proxy type.
    95  */
    96 void purple_proxy_info_set_type(PurpleProxyInfo *info, PurpleProxyType type);
    97 
    98 /**
    99  * Sets the proxy host.
   100  *
   101  * @param info The proxy information.
   102  * @param host The host.
   103  */
   104 void purple_proxy_info_set_host(PurpleProxyInfo *info, const char *host);
   105 
   106 /**
   107  * Sets the proxy port.
   108  *
   109  * @param info The proxy information.
   110  * @param port The port.
   111  */
   112 void purple_proxy_info_set_port(PurpleProxyInfo *info, int port);
   113 
   114 /**
   115  * Sets the proxy username.
   116  *
   117  * @param info     The proxy information.
   118  * @param username The username.
   119  */
   120 void purple_proxy_info_set_username(PurpleProxyInfo *info, const char *username);
   121 
   122 /**
   123  * Sets the proxy password.
   124  *
   125  * @param info     The proxy information.
   126  * @param password The password.
   127  */
   128 void purple_proxy_info_set_password(PurpleProxyInfo *info, const char *password);
   129 
   130 /**
   131  * Returns the proxy's type.
   132  *
   133  * @param info The proxy information.
   134  *
   135  * @return The type.
   136  */
   137 PurpleProxyType purple_proxy_info_get_type(const PurpleProxyInfo *info);
   138 
   139 /**
   140  * Returns the proxy's host.
   141  *
   142  * @param info The proxy information.
   143  *
   144  * @return The host.
   145  */
   146 const char *purple_proxy_info_get_host(const PurpleProxyInfo *info);
   147 
   148 /**
   149  * Returns the proxy's port.
   150  *
   151  * @param info The proxy information.
   152  *
   153  * @return The port.
   154  */
   155 int purple_proxy_info_get_port(const PurpleProxyInfo *info);
   156 
   157 /**
   158  * Returns the proxy's username.
   159  *
   160  * @param info The proxy information.
   161  *
   162  * @return The username.
   163  */
   164 const char *purple_proxy_info_get_username(const PurpleProxyInfo *info);
   165 
   166 /**
   167  * Returns the proxy's password.
   168  *
   169  * @param info The proxy information.
   170  *
   171  * @return The password.
   172  */
   173 const char *purple_proxy_info_get_password(const PurpleProxyInfo *info);
   174 
   175 /*@}*/
   176 
   177 /**************************************************************************/
   178 /** @name Global Proxy API                                                */
   179 /**************************************************************************/
   180 /*@{*/
   181 
   182 /**
   183  * Returns purple's global proxy information.
   184  *
   185  * @return The global proxy information.
   186  */
   187 PurpleProxyInfo *purple_global_proxy_get_info(void);
   188 
   189 /**
   190  * Set purple's global proxy information.
   191  *
   192  * @param info     The proxy information.
   193  * @since 2.6.0
   194  */
   195 void purple_global_proxy_set_info(PurpleProxyInfo *info);
   196 
   197 /*@}*/
   198 
   199 /**************************************************************************/
   200 /** @name Proxy API                                                       */
   201 /**************************************************************************/
   202 /*@{*/
   203 
   204 /**
   205  * Returns the proxy subsystem handle.
   206  *
   207  * @return The proxy subsystem handle.
   208  */
   209 void *purple_proxy_get_handle(void);
   210 
   211 /**
   212  * Initializes the proxy subsystem.
   213  */
   214 void purple_proxy_init(void);
   215 
   216 /**
   217  * Uninitializes the proxy subsystem.
   218  */
   219 void purple_proxy_uninit(void);
   220 
   221 /**
   222  * Returns configuration of a proxy.
   223  *
   224  * @param account The account for which the configuration is needed.
   225  *
   226  * @return The configuration of a proxy.
   227  */
   228 PurpleProxyInfo *purple_proxy_get_setup(PurpleAccount *account);
   229 
   230 /**
   231  * Makes a connection to the specified host and port.  Note that this
   232  * function name can be misleading--although it is called "proxy
   233  * connect," it is used for establishing any outgoing TCP connection,
   234  * whether through a proxy or not.
   235  *
   236  * @param handle     A handle that should be associated with this
   237  *                   connection attempt.  The handle can be used
   238  *                   to cancel the connection attempt using the
   239  *                   purple_proxy_connect_cancel_with_handle()
   240  *                   function.
   241  * @param account    The account making the connection.
   242  * @param host       The destination host.
   243  * @param port       The destination port.
   244  * @param connect_cb The function to call when the connection is
   245  *                   established.  If the connection failed then
   246  *                   fd will be -1 and error message will be set
   247  *                   to something descriptive (hopefully).
   248  * @param data       User-defined data.
   249  *
   250  * @return NULL if there was an error, or a reference to an
   251  *         opaque data structure that can be used to cancel
   252  *         the pending connection, if needed.
   253  */
   254 PurpleProxyConnectData *purple_proxy_connect(void *handle,
   255 			PurpleAccount *account,
   256 			const char *host, int port,
   257 			PurpleProxyConnectFunction connect_cb, gpointer data);
   258 
   259 /**
   260  * Makes a connection to the specified host and port.  Note that this
   261  * function name can be misleading--although it is called "proxy
   262  * connect," it is used for establishing any outgoing UDP connection,
   263  * whether through a proxy or not.
   264  *
   265  * @param handle     A handle that should be associated with this
   266  *                   connection attempt.  The handle can be used
   267  *                   to cancel the connection attempt using the
   268  *                   purple_proxy_connect_cancel_with_handle()
   269  *                   function.
   270  * @param account    The account making the connection.
   271  * @param host       The destination host.
   272  * @param port       The destination port.
   273  * @param connect_cb The function to call when the connection is
   274  *                   established.  If the connection failed then
   275  *                   fd will be -1 and error message will be set
   276  *                   to something descriptive (hopefully).
   277  * @param data       User-defined data.
   278  *
   279  * @return NULL if there was an error, or a reference to an
   280  *         opaque data structure that can be used to cancel
   281  *         the pending connection, if needed.
   282  */
   283 PurpleProxyConnectData *purple_proxy_connect_udp(void *handle,
   284 			PurpleAccount *account,
   285 			const char *host, int port,
   286 			PurpleProxyConnectFunction connect_cb, gpointer data);
   287 
   288 /**
   289  * Makes a connection through a SOCKS5 proxy.
   290  *
   291  * @param handle     A handle that should be associated with this
   292  *                   connection attempt.  The handle can be used
   293  *                   to cancel the connection attempt using the
   294  *                   purple_proxy_connect_cancel_with_handle()
   295  *                   function.
   296  * @param gpi        The PurpleProxyInfo specifying the proxy settings
   297  * @param host       The destination host.
   298  * @param port       The destination port.
   299  * @param connect_cb The function to call when the connection is
   300  *                   established.  If the connection failed then
   301  *                   fd will be -1 and error message will be set
   302  *                   to something descriptive (hopefully).
   303  * @param data       User-defined data.
   304  *
   305  * @return NULL if there was an error, or a reference to an
   306  *         opaque data structure that can be used to cancel
   307  *         the pending connection, if needed.
   308  */
   309 PurpleProxyConnectData *purple_proxy_connect_socks5(void *handle,
   310 			PurpleProxyInfo *gpi,
   311 			const char *host, int port,
   312 			PurpleProxyConnectFunction connect_cb, gpointer data);
   313 
   314 /**
   315  * Cancel an in-progress connection attempt.  This should be called
   316  * by the PRPL if the user disables an account while it is still
   317  * performing the initial sign on.  Or when establishing a file
   318  * transfer, if we attempt to connect to a remote user but they
   319  * are behind a firewall then the PRPL can cancel the connection
   320  * attempt early rather than just letting the OS's TCP/IP stack
   321  * time-out the connection.
   322  */
   323 void purple_proxy_connect_cancel(PurpleProxyConnectData *connect_data);
   324 
   325 /*
   326  * Closes all proxy connections registered with the specified handle.
   327  *
   328  * @param handle The handle.
   329  */
   330 void purple_proxy_connect_cancel_with_handle(void *handle);
   331 
   332 /*@}*/
   333 
   334 #ifdef __cplusplus
   335 }
   336 #endif
   337 
   338 #endif /* _PURPLE_PROXY_H_ */