Frameworks/libpurple.framework/Versions/0.6.2/Headers/network.h
changeset 2592 e8d15275025e
parent 2571 75fb8ee8f2e6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Frameworks/libpurple.framework/Versions/0.6.2/Headers/network.h	Fri Aug 21 13:25:11 2009 -0700
     1.3 @@ -0,0 +1,305 @@
     1.4 +/**
     1.5 + * @file network.h Network API
     1.6 + * @ingroup core
     1.7 + */
     1.8 +
     1.9 +/* purple
    1.10 + *
    1.11 + * Purple is the legal property of its developers, whose names are too numerous
    1.12 + * to list here.  Please refer to the COPYRIGHT file distributed with this
    1.13 + * source distribution.
    1.14 + *
    1.15 + * This program is free software; you can redistribute it and/or modify
    1.16 + * it under the terms of the GNU General Public License as published by
    1.17 + * the Free Software Foundation; either version 2 of the License, or
    1.18 + * (at your option) any later version.
    1.19 + *
    1.20 + * This program is distributed in the hope that it will be useful,
    1.21 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.22 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.23 + * GNU General Public License for more details.
    1.24 + *
    1.25 + * You should have received a copy of the GNU General Public License
    1.26 + * along with this program; if not, write to the Free Software
    1.27 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
    1.28 + */
    1.29 +#ifndef _PURPLE_NETWORK_H_
    1.30 +#define _PURPLE_NETWORK_H_
    1.31 +
    1.32 +#ifdef __cplusplus
    1.33 +extern "C" {
    1.34 +#endif
    1.35 +
    1.36 +/**************************************************************************/
    1.37 +/** @name Network API                                                     */
    1.38 +/**************************************************************************/
    1.39 +/*@{*/
    1.40 +
    1.41 +typedef struct _PurpleNetworkListenData PurpleNetworkListenData;
    1.42 +
    1.43 +typedef void (*PurpleNetworkListenCallback) (int listenfd, gpointer data);
    1.44 +
    1.45 +/**
    1.46 + * Converts a dot-decimal IP address to an array of unsigned
    1.47 + * chars.  For example, converts 192.168.0.1 to a 4 byte
    1.48 + * array containing 192, 168, 0 and 1.
    1.49 + *
    1.50 + * @param ip An IP address in dot-decimal notiation.
    1.51 + * @return An array of 4 bytes containing an IP addresses
    1.52 + *         equivalent to the given parameter, or NULL if
    1.53 + *         the given IP address is invalid.  This value
    1.54 + *         is statically allocated and should not be
    1.55 + *         freed.
    1.56 + */
    1.57 +const unsigned char *purple_network_ip_atoi(const char *ip);
    1.58 +
    1.59 +/**
    1.60 + * Sets the IP address of the local system in preferences.  This
    1.61 + * is the IP address that should be used for incoming connections
    1.62 + * (file transfer, direct IM, etc.) and should therefore be
    1.63 + * publicly accessible.
    1.64 + *
    1.65 + * @param ip The local IP address.
    1.66 + */
    1.67 +void purple_network_set_public_ip(const char *ip);
    1.68 +
    1.69 +/**
    1.70 + * Returns the IP address of the local system set in preferences.
    1.71 + *
    1.72 + * This returns the value set via purple_network_set_public_ip().
    1.73 + * You probably want to use purple_network_get_my_ip() instead.
    1.74 + *
    1.75 + * @return The local IP address set in preferences.
    1.76 + */
    1.77 +const char *purple_network_get_public_ip(void);
    1.78 +
    1.79 +/**
    1.80 + * Returns the IP address of the local system.
    1.81 + *
    1.82 + * You probably want to use purple_network_get_my_ip() instead.
    1.83 + *
    1.84 + * @note The returned string is a pointer to a static buffer. If this
    1.85 + *       function is called twice, it may be important to make a copy
    1.86 + *       of the returned string.
    1.87 + *
    1.88 + * @param fd The fd to use to help figure out the IP, or else -1.
    1.89 + * @return The local IP address.
    1.90 + */
    1.91 +const char *purple_network_get_local_system_ip(int fd);
    1.92 +
    1.93 +/**
    1.94 + * Returns the IP address that should be used anywhere a
    1.95 + * public IP addresses is needed (listening for an incoming
    1.96 + * file transfer, etc).
    1.97 + *
    1.98 + * If the user has manually specified an IP address via
    1.99 + * preferences, then this IP is returned.  Otherwise the
   1.100 + * IP address returned by purple_network_get_local_system_ip()
   1.101 + * is returned.
   1.102 + *
   1.103 + * @note The returned string is a pointer to a static buffer. If this
   1.104 + *       function is called twice, it may be important to make a copy
   1.105 + *       of the returned string.
   1.106 + *
   1.107 + * @param fd The fd to use to help figure out the IP, or -1.
   1.108 + * @return The local IP address to be used.
   1.109 + */
   1.110 +const char *purple_network_get_my_ip(int fd);
   1.111 +
   1.112 +/**
   1.113 + * Should calls to purple_network_listen() and purple_network_listen_range()
   1.114 + * map the port externally using NAT-PMP or UPnP?
   1.115 + * The default value is TRUE
   1.116 + *
   1.117 + * @param map_external Should the open port be mapped externally?
   1.118 + * @deprecated In 3.0.0 a boolean will be added to the above functions to
   1.119 + *             perform the same function.
   1.120 + * @since 2.3.0
   1.121 + */
   1.122 +void purple_network_listen_map_external(gboolean map_external);
   1.123 +
   1.124 +/**
   1.125 + * Attempts to open a listening port ONLY on the specified port number.
   1.126 + * You probably want to use purple_network_listen_range() instead of this.
   1.127 + * This function is useful, for example, if you wanted to write a telnet
   1.128 + * server as a Purple plugin, and you HAD to listen on port 23.  Why anyone
   1.129 + * would want to do that is beyond me.
   1.130 + *
   1.131 + * This opens a listening port. The caller will want to set up a watcher
   1.132 + * of type PURPLE_INPUT_READ on the fd returned in cb. It will probably call
   1.133 + * accept in the watcher callback, and then possibly remove the watcher and close
   1.134 + * the listening socket, and add a new watcher on the new socket accept
   1.135 + * returned.
   1.136 + *
   1.137 + * @param port The port number to bind to.  Must be greater than 0.
   1.138 + * @param socket_type The type of socket to open for listening.
   1.139 + *   This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP.
   1.140 + * @param cb The callback to be invoked when the port to listen on is available.
   1.141 + *           The file descriptor of the listening socket will be specified in
   1.142 + *           this callback, or -1 if no socket could be established.
   1.143 + * @param cb_data extra data to be returned when cb is called
   1.144 + *
   1.145 + * @return A pointer to a data structure that can be used to cancel
   1.146 + *         the pending listener, or NULL if unable to obtain a local
   1.147 + *         socket to listen on.
   1.148 + */
   1.149 +PurpleNetworkListenData *purple_network_listen(unsigned short port,
   1.150 +		int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data);
   1.151 +
   1.152 +/**
   1.153 + * Opens a listening port selected from a range of ports.  The range of
   1.154 + * ports used is chosen in the following manner:
   1.155 + * If a range is specified in preferences, these values are used.
   1.156 + * If a non-0 values are passed to the function as parameters, these
   1.157 + * values are used.
   1.158 + * Otherwise a port is chosen at random by the operating system.
   1.159 + *
   1.160 + * This opens a listening port. The caller will want to set up a watcher
   1.161 + * of type PURPLE_INPUT_READ on the fd returned in cb. It will probably call
   1.162 + * accept in the watcher callback, and then possibly remove the watcher and close
   1.163 + * the listening socket, and add a new watcher on the new socket accept
   1.164 + * returned.
   1.165 + *
   1.166 + * @param start The port number to bind to, or 0 to pick a random port.
   1.167 + *              Users are allowed to override this arg in prefs.
   1.168 + * @param end The highest possible port in the range of ports to listen on,
   1.169 + *            or 0 to pick a random port.  Users are allowed to override this
   1.170 + *            arg in prefs.
   1.171 + * @param socket_type The type of socket to open for listening.
   1.172 + *   This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP.
   1.173 + * @param cb The callback to be invoked when the port to listen on is available.
   1.174 + *           The file descriptor of the listening socket will be specified in
   1.175 + *           this callback, or -1 if no socket could be established.
   1.176 + * @param cb_data extra data to be returned when cb is called
   1.177 + *
   1.178 + * @return A pointer to a data structure that can be used to cancel
   1.179 + *         the pending listener, or NULL if unable to obtain a local
   1.180 + *         socket to listen on.
   1.181 + */
   1.182 +PurpleNetworkListenData *purple_network_listen_range(unsigned short start,
   1.183 +		unsigned short end, int socket_type,
   1.184 +		PurpleNetworkListenCallback cb, gpointer cb_data);
   1.185 +
   1.186 +/**
   1.187 + * This can be used to cancel any in-progress listener connection
   1.188 + * by passing in the return value from either purple_network_listen()
   1.189 + * or purple_network_listen_range().
   1.190 + *
   1.191 + * @param listen_data This listener attempt will be canceled and
   1.192 + *        the struct will be freed.
   1.193 + */
   1.194 +void purple_network_listen_cancel(PurpleNetworkListenData *listen_data);
   1.195 +
   1.196 +/**
   1.197 + * Gets a port number from a file descriptor.
   1.198 + *
   1.199 + * @param fd The file descriptor. This should be a tcp socket. The current
   1.200 + *           implementation probably dies on anything but IPv4. Perhaps this
   1.201 + *           possible bug will inspire new and valuable contributors to Purple.
   1.202 + * @return The port number, in host byte order.
   1.203 + */
   1.204 +unsigned short purple_network_get_port_from_fd(int fd);
   1.205 +
   1.206 +/**
   1.207 + * Detects if there is an available network connection.
   1.208 + *
   1.209 + * @return TRUE if the network is available
   1.210 + */
   1.211 +gboolean purple_network_is_available(void);
   1.212 +
   1.213 +/**
   1.214 + * Makes purple_network_is_available() always return @c TRUE.
   1.215 + *
   1.216 + * This is what backs the --force-online command line argument in Pidgin,
   1.217 + * for example.  This is useful for offline testing, especially when
   1.218 + * combined with nullprpl.
   1.219 + *
   1.220 + * @since 2.6.0
   1.221 + */
   1.222 +void purple_network_force_online(void);
   1.223 +
   1.224 +/**
   1.225 + * Get the handle for the network system
   1.226 + *
   1.227 + * @return the handle to the network system
   1.228 + */
   1.229 +void *purple_network_get_handle(void);
   1.230 +
   1.231 +/**	
   1.232 + * Update the STUN server IP given the host name
   1.233 + * Will result in a DNS query being executed asynchronous
   1.234 + * 
   1.235 + * @param stun_server The host name of the STUN server to set
   1.236 + * @since 2.6.0
   1.237 + */
   1.238 +void purple_network_set_stun_server(const gchar *stun_server);
   1.239 +	
   1.240 +/**
   1.241 + * Get the IP address of the STUN server as a string representation
   1.242 + *
   1.243 + * @return the IP address
   1.244 + * @since 2.6.0
   1.245 + */
   1.246 +const gchar *purple_network_get_stun_ip(void);
   1.247 +	
   1.248 +/**	
   1.249 + * Update the TURN server IP given the host name
   1.250 + * Will result in a DNS query being executed asynchronous
   1.251 + * 
   1.252 + * @param turn_server The host name of the TURN server to set
   1.253 + * @since 2.6.0
   1.254 + */
   1.255 +void purple_network_set_turn_server(const gchar *turn_server);
   1.256 +	
   1.257 +/**
   1.258 + * Get the IP address of the STUN server as a string representation
   1.259 + *
   1.260 + * @return the IP address
   1.261 + * @since 2.6.0
   1.262 + */
   1.263 +const gchar *purple_network_get_turn_ip(void);
   1.264 +		
   1.265 +/**
   1.266 + * Remove a port mapping (UPnP or NAT-PMP) associated with listening socket
   1.267 + *
   1.268 + * @param fd Socket to remove the port mapping for
   1.269 + * @since 2.6.0
   1.270 + */
   1.271 +void purple_network_remove_port_mapping(gint fd);	
   1.272 +
   1.273 +/**
   1.274 + * Convert a UTF-8 domain name to ASCII in accordance with the IDNA
   1.275 + * specification. If libpurple is compiled without IDN support, this function
   1.276 + * copies the input into the output buffer.
   1.277 + *
   1.278 + * Because this function is used by DNS resolver child/threads, it uses no
   1.279 + * other libpurple API and is threadsafe.
   1.280 + *
   1.281 + * In general, a buffer of about 512 bytes is the appropriate size to use.
   1.282 + *
   1.283 + * @param in      The hostname to be converted.
   1.284 + * @param out     The output buffer where an allocated string will be returned.
   1.285 + *                The caller is responsible for freeing this.
   1.286 + * @returns       0 on success, -1 if the out is NULL, or an error code
   1.287 + *                that currently corresponds to the Idna_rc enum in libidn.
   1.288 + * @since 2.6.0
   1.289 + */
   1.290 +int purple_network_convert_idn_to_ascii(const gchar *in, gchar **out);
   1.291 +
   1.292 +/**
   1.293 + * Initializes the network subsystem.
   1.294 + */
   1.295 +void purple_network_init(void);
   1.296 +
   1.297 +/**
   1.298 + * Shuts down the network subsystem.
   1.299 + */
   1.300 +void purple_network_uninit(void);
   1.301 +
   1.302 +/*@}*/
   1.303 +
   1.304 +#ifdef __cplusplus
   1.305 +}
   1.306 +#endif
   1.307 +
   1.308 +#endif /* _PURPLE_NETWORK_H_ */