Mercurial > pidgin
comparison libpurple/network.h @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
| author | Elliott Sales de Andrade <qulogic@pidgin.im> |
|---|---|
| date | Sat, 02 Jun 2012 02:30:49 +0000 |
| parents | 98520ee78f12 |
| children |
comparison
equal
deleted
inserted
replaced
| 32818:01ff09d4a463 | 32819:2c6510167895 |
|---|---|
| 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 25 */ | 25 */ |
| 26 #ifndef _PURPLE_NETWORK_H_ | 26 #ifndef _PURPLE_NETWORK_H_ |
| 27 #define _PURPLE_NETWORK_H_ | 27 #define _PURPLE_NETWORK_H_ |
| 28 | 28 |
| 29 #ifdef __cplusplus | 29 #include <glib.h> |
| 30 extern "C" { | 30 |
| 31 #endif | 31 G_BEGIN_DECLS |
| 32 | 32 |
| 33 /**************************************************************************/ | 33 /**************************************************************************/ |
| 34 /** @name Network API */ | 34 /** @name Network API */ |
| 35 /**************************************************************************/ | 35 /**************************************************************************/ |
| 36 /*@{*/ | 36 /*@{*/ |
| 90 /** | 90 /** |
| 91 * Returns all IP addresses of the local system. | 91 * Returns all IP addresses of the local system. |
| 92 * | 92 * |
| 93 * @note The caller must free this list. If libpurple was built with | 93 * @note The caller must free this list. If libpurple was built with |
| 94 * support for it, this function also enumerates IPv6 addresses. | 94 * support for it, this function also enumerates IPv6 addresses. |
| 95 * @since 2.7.0 | |
| 96 * | 95 * |
| 97 * @return A list of local IP addresses. | 96 * @return A list of local IP addresses. |
| 98 */ | 97 */ |
| 99 GList *purple_network_get_all_local_system_ips(void); | 98 GList *purple_network_get_all_local_system_ips(void); |
| 100 | 99 |
| 114 * | 113 * |
| 115 * @param fd The fd to use to help figure out the IP, or -1. | 114 * @param fd The fd to use to help figure out the IP, or -1. |
| 116 * @return The local IP address to be used. | 115 * @return The local IP address to be used. |
| 117 */ | 116 */ |
| 118 const char *purple_network_get_my_ip(int fd); | 117 const char *purple_network_get_my_ip(int fd); |
| 119 | |
| 120 /** | |
| 121 * Should calls to purple_network_listen() and purple_network_listen_range() | |
| 122 * map the port externally using NAT-PMP or UPnP? | |
| 123 * The default value is TRUE | |
| 124 * | |
| 125 * @param map_external Should the open port be mapped externally? | |
| 126 * @deprecated In 3.0.0 a boolean will be added to the functions mentioned | |
| 127 * above to perform the same function. | |
| 128 * @since 2.3.0 | |
| 129 */ | |
| 130 void purple_network_listen_map_external(gboolean map_external); | |
| 131 | 118 |
| 132 /** | 119 /** |
| 133 * Attempts to open a listening port ONLY on the specified port number. | 120 * Attempts to open a listening port ONLY on the specified port number. |
| 134 * You probably want to use purple_network_listen_range() instead of this. | 121 * You probably want to use purple_network_listen_range() instead of this. |
| 135 * This function is useful, for example, if you wanted to write a telnet | 122 * This function is useful, for example, if you wanted to write a telnet |
| 140 * of type PURPLE_INPUT_READ on the fd returned in cb. It will probably call | 127 * of type PURPLE_INPUT_READ on the fd returned in cb. It will probably call |
| 141 * accept in the watcher callback, and then possibly remove the watcher and | 128 * accept in the watcher callback, and then possibly remove the watcher and |
| 142 * close the listening socket, and add a new watcher on the new socket accept | 129 * close the listening socket, and add a new watcher on the new socket accept |
| 143 * returned. | 130 * returned. |
| 144 * | 131 * |
| 145 * @param port The port number to bind to. Must be greater than 0. | |
| 146 * @param socket_type The type of socket to open for listening. | |
| 147 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP. | |
| 148 * @param cb The callback to be invoked when the port to listen on is available. | |
| 149 * The file descriptor of the listening socket will be specified in | |
| 150 * this callback, or -1 if no socket could be established. | |
| 151 * @param cb_data extra data to be returned when cb is called | |
| 152 * | |
| 153 * @return A pointer to a data structure that can be used to cancel | |
| 154 * the pending listener, or NULL if unable to obtain a local | |
| 155 * socket to listen on. | |
| 156 */ | |
| 157 PurpleNetworkListenData *purple_network_listen(unsigned short port, | |
| 158 int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data); | |
| 159 | |
| 160 /** | |
| 161 * \copydoc purple_network_listen | |
| 162 * | |
| 163 * Libpurple does not currently do any port mapping (stateful firewall hole | 132 * Libpurple does not currently do any port mapping (stateful firewall hole |
| 164 * poking) for IPv6-only listeners (if an IPv6 socket supports v4-mapped | 133 * poking) for IPv6-only listeners (if an IPv6 socket supports v4-mapped |
| 165 * addresses, a mapping is done). | 134 * addresses, a mapping is done). |
| 166 * | 135 * |
| 136 * @param port The port number to bind to. Must be greater than 0. | |
| 167 * @param socket_family The protocol family of the socket. This should be | 137 * @param socket_family The protocol family of the socket. This should be |
| 168 * AF_INET for IPv4 or AF_INET6 for IPv6. IPv6 sockets | 138 * AF_INET for IPv4 or AF_INET6 for IPv6. IPv6 sockets |
| 169 * may or may not be able to accept IPv4 connections | 139 * may or may not be able to accept IPv4 connections |
| 170 * based on the system configuration (use | 140 * based on the system configuration (use |
| 171 * purple_socket_speaks_ipv4 to check). If an IPv6 | 141 * purple_socket_speaks_ipv4 to check). If an IPv6 |
| 172 * socket doesn't accept V4-mapped addresses, you will | 142 * socket doesn't accept V4-mapped addresses, you will |
| 173 * need a second listener to support both v4 and v6. | 143 * need a second listener to support both v4 and v6. |
| 174 * @since 2.7.0 | 144 * @param socket_type The type of socket to open for listening. |
| 175 * @deprecated This function will be renamed to purple_network_listen in 3.0.0. | 145 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP. |
| 176 */ | 146 * @param map_external Should the open port be mapped externally using |
| 177 PurpleNetworkListenData *purple_network_listen_family(unsigned short port, | 147 * NAT-PNP or UPnP? (default should be TRUE) |
| 178 int socket_family, int socket_type, PurpleNetworkListenCallback cb, | 148 * @param cb The callback to be invoked when the port to listen on is available. |
| 179 gpointer cb_data); | 149 * The file descriptor of the listening socket will be specified in |
| 150 * this callback, or -1 if no socket could be established. | |
| 151 * @param cb_data extra data to be returned when cb is called | |
| 152 * | |
| 153 * @return A pointer to a data structure that can be used to cancel | |
| 154 * the pending listener, or NULL if unable to obtain a local | |
| 155 * socket to listen on. | |
| 156 */ | |
| 157 PurpleNetworkListenData *purple_network_listen(unsigned short port, | |
| 158 int socket_family, int socket_type, gboolean map_external, | |
| 159 PurpleNetworkListenCallback cb, gpointer cb_data); | |
| 180 | 160 |
| 181 /** | 161 /** |
| 182 * Opens a listening port selected from a range of ports. The range of | 162 * Opens a listening port selected from a range of ports. The range of |
| 183 * ports used is chosen in the following manner: | 163 * ports used is chosen in the following manner: |
| 184 * If a range is specified in preferences, these values are used. | 164 * If a range is specified in preferences, these values are used. |
| 190 * of type PURPLE_INPUT_READ on the fd returned in cb. It will probably call | 170 * of type PURPLE_INPUT_READ on the fd returned in cb. It will probably call |
| 191 * accept in the watcher callback, and then possibly remove the watcher and close | 171 * accept in the watcher callback, and then possibly remove the watcher and close |
| 192 * the listening socket, and add a new watcher on the new socket accept | 172 * the listening socket, and add a new watcher on the new socket accept |
| 193 * returned. | 173 * returned. |
| 194 * | 174 * |
| 175 * Libpurple does not currently do any port mapping (stateful firewall hole | |
| 176 * poking) for IPv6-only listeners (if an IPv6 socket supports v4-mapped | |
| 177 * addresses, a mapping is done). | |
| 178 * | |
| 195 * @param start The port number to bind to, or 0 to pick a random port. | 179 * @param start The port number to bind to, or 0 to pick a random port. |
| 196 * Users are allowed to override this arg in prefs. | 180 * Users are allowed to override this arg in prefs. |
| 197 * @param end The highest possible port in the range of ports to listen on, | 181 * @param end The highest possible port in the range of ports to listen on, |
| 198 * or 0 to pick a random port. Users are allowed to override this | 182 * or 0 to pick a random port. Users are allowed to override this |
| 199 * arg in prefs. | 183 * arg in prefs. |
| 200 * @param socket_type The type of socket to open for listening. | |
| 201 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP. | |
| 202 * @param cb The callback to be invoked when the port to listen on is available. | |
| 203 * The file descriptor of the listening socket will be specified in | |
| 204 * this callback, or -1 if no socket could be established. | |
| 205 * @param cb_data extra data to be returned when cb is called | |
| 206 * | |
| 207 * @return A pointer to a data structure that can be used to cancel | |
| 208 * the pending listener, or NULL if unable to obtain a local | |
| 209 * socket to listen on. | |
| 210 */ | |
| 211 PurpleNetworkListenData *purple_network_listen_range(unsigned short start, | |
| 212 unsigned short end, int socket_type, | |
| 213 PurpleNetworkListenCallback cb, gpointer cb_data); | |
| 214 | |
| 215 /** | |
| 216 * \copydoc purple_network_listen_range | |
| 217 * | |
| 218 * Libpurple does not currently do any port mapping (stateful firewall hole | |
| 219 * poking) for IPv6-only listeners (if an IPv6 socket supports v4-mapped | |
| 220 * addresses, a mapping is done). | |
| 221 * | |
| 222 * @param socket_family The protocol family of the socket. This should be | 184 * @param socket_family The protocol family of the socket. This should be |
| 223 * AF_INET for IPv4 or AF_INET6 for IPv6. IPv6 sockets | 185 * AF_INET for IPv4 or AF_INET6 for IPv6. IPv6 sockets |
| 224 * may or may not be able to accept IPv4 connections | 186 * may or may not be able to accept IPv4 connections |
| 225 * based on the system configuration (use | 187 * based on the system configuration (use |
| 226 * purple_socket_speaks_ipv4 to check). If an IPv6 | 188 * purple_socket_speaks_ipv4 to check). If an IPv6 |
| 227 * socket doesn't accept V4-mapped addresses, you will | 189 * socket doesn't accept V4-mapped addresses, you will |
| 228 * need a second listener to support both v4 and v6. | 190 * need a second listener to support both v4 and v6. |
| 229 * @since 2.7.0 | 191 * @param socket_type The type of socket to open for listening. |
| 230 * @deprecated This function will be renamed to purple_network_listen_range | 192 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP. |
| 231 * in 3.0.0. | 193 * @param map_external Should the open port be mapped externally using |
| 232 */ | 194 * NAT-PNP or UPnP? (default should be TRUE) |
| 233 PurpleNetworkListenData *purple_network_listen_range_family( | 195 * @param cb The callback to be invoked when the port to listen on is available. |
| 196 * The file descriptor of the listening socket will be specified in | |
| 197 * this callback, or -1 if no socket could be established. | |
| 198 * @param cb_data extra data to be returned when cb is called | |
| 199 * | |
| 200 * @return A pointer to a data structure that can be used to cancel | |
| 201 * the pending listener, or NULL if unable to obtain a local | |
| 202 * socket to listen on. | |
| 203 */ | |
| 204 PurpleNetworkListenData *purple_network_listen_range( | |
| 234 unsigned short start, unsigned short end, int socket_family, | 205 unsigned short start, unsigned short end, int socket_family, |
| 235 int socket_type, PurpleNetworkListenCallback cb, gpointer cb_data); | 206 int socket_type, gboolean map_external, |
| 207 PurpleNetworkListenCallback cb, gpointer cb_data); | |
| 236 | 208 |
| 237 /** | 209 /** |
| 238 * This can be used to cancel any in-progress listener connection | 210 * This can be used to cancel any in-progress listener connection |
| 239 * by passing in the return value from either purple_network_listen() | 211 * by passing in the return value from either purple_network_listen() |
| 240 * or purple_network_listen_range(). | 212 * or purple_network_listen_range(). |
| 265 * Makes purple_network_is_available() always return @c TRUE. | 237 * Makes purple_network_is_available() always return @c TRUE. |
| 266 * | 238 * |
| 267 * This is what backs the --force-online command line argument in Pidgin, | 239 * This is what backs the --force-online command line argument in Pidgin, |
| 268 * for example. This is useful for offline testing, especially when | 240 * for example. This is useful for offline testing, especially when |
| 269 * combined with nullprpl. | 241 * combined with nullprpl. |
| 270 * | |
| 271 * @since 2.6.0 | |
| 272 */ | 242 */ |
| 273 void purple_network_force_online(void); | 243 void purple_network_force_online(void); |
| 274 | 244 |
| 275 /** | 245 /** |
| 276 * Get the handle for the network system | 246 * Get the handle for the network system |
| 282 /** | 252 /** |
| 283 * Update the STUN server IP given the host name | 253 * Update the STUN server IP given the host name |
| 284 * Will result in a DNS query being executed asynchronous | 254 * Will result in a DNS query being executed asynchronous |
| 285 * | 255 * |
| 286 * @param stun_server The host name of the STUN server to set | 256 * @param stun_server The host name of the STUN server to set |
| 287 * @since 2.6.0 | |
| 288 */ | 257 */ |
| 289 void purple_network_set_stun_server(const gchar *stun_server); | 258 void purple_network_set_stun_server(const gchar *stun_server); |
| 290 | 259 |
| 291 /** | 260 /** |
| 292 * Get the IP address of the STUN server as a string representation | 261 * Get the IP address of the STUN server as a string representation |
| 293 * | 262 * |
| 294 * @return the IP address | 263 * @return the IP address |
| 295 * @since 2.6.0 | |
| 296 */ | 264 */ |
| 297 const gchar *purple_network_get_stun_ip(void); | 265 const gchar *purple_network_get_stun_ip(void); |
| 298 | 266 |
| 299 /** | 267 /** |
| 300 * Update the TURN server IP given the host name | 268 * Update the TURN server IP given the host name |
| 301 * Will result in a DNS query being executed asynchronous | 269 * Will result in a DNS query being executed asynchronous |
| 302 * | 270 * |
| 303 * @param turn_server The host name of the TURN server to set | 271 * @param turn_server The host name of the TURN server to set |
| 304 * @since 2.6.0 | |
| 305 */ | 272 */ |
| 306 void purple_network_set_turn_server(const gchar *turn_server); | 273 void purple_network_set_turn_server(const gchar *turn_server); |
| 307 | 274 |
| 308 /** | 275 /** |
| 309 * Get the IP address of the TURN server as a string representation | 276 * Get the IP address of the TURN server as a string representation |
| 310 * | 277 * |
| 311 * @return the IP address | 278 * @return the IP address |
| 312 * @since 2.6.0 | |
| 313 */ | 279 */ |
| 314 const gchar *purple_network_get_turn_ip(void); | 280 const gchar *purple_network_get_turn_ip(void); |
| 315 | 281 |
| 316 /** | 282 /** |
| 317 * Remove a port mapping (UPnP or NAT-PMP) associated with listening socket | 283 * Remove a port mapping (UPnP or NAT-PMP) associated with listening socket |
| 318 * | 284 * |
| 319 * @param fd Socket to remove the port mapping for | 285 * @param fd Socket to remove the port mapping for |
| 320 * @since 2.6.0 | |
| 321 */ | 286 */ |
| 322 void purple_network_remove_port_mapping(gint fd); | 287 void purple_network_remove_port_mapping(gint fd); |
| 323 | 288 |
| 324 /** | 289 /** |
| 325 * Convert a UTF-8 domain name to ASCII in accordance with the IDNA | 290 * Convert a UTF-8 domain name to ASCII in accordance with the IDNA |
| 334 * @param in The hostname to be converted. | 299 * @param in The hostname to be converted. |
| 335 * @param out The output buffer where an allocated string will be returned. | 300 * @param out The output buffer where an allocated string will be returned. |
| 336 * The caller is responsible for freeing this. | 301 * The caller is responsible for freeing this. |
| 337 * @returns 0 on success, -1 if the out is NULL, or an error code | 302 * @returns 0 on success, -1 if the out is NULL, or an error code |
| 338 * that currently corresponds to the Idna_rc enum in libidn. | 303 * that currently corresponds to the Idna_rc enum in libidn. |
| 339 * @since 2.6.0 | |
| 340 */ | 304 */ |
| 341 int purple_network_convert_idn_to_ascii(const gchar *in, gchar **out); | 305 int purple_network_convert_idn_to_ascii(const gchar *in, gchar **out); |
| 342 | 306 |
| 343 /** | 307 /** |
| 344 * Initializes the network subsystem. | 308 * Initializes the network subsystem. |
| 350 */ | 314 */ |
| 351 void purple_network_uninit(void); | 315 void purple_network_uninit(void); |
| 352 | 316 |
| 353 /*@}*/ | 317 /*@}*/ |
| 354 | 318 |
| 355 #ifdef __cplusplus | 319 G_END_DECLS |
| 356 } | |
| 357 #endif | |
| 358 | 320 |
| 359 #endif /* _PURPLE_NETWORK_H_ */ | 321 #endif /* _PURPLE_NETWORK_H_ */ |
