Mon, 08 Mar 2004 06:16:46 +0000
[gaim-migrate @ 9137]
Some general cleanups I wanted to make to gtkconv.c before I begin my conv
rewrite tree. There will be much more of them, I assure you, but they'll
probably happen with the conv rewrite patch. I want to standardize on a
coding style in there.
| 8231 | 1 | /** |
| 2 | * @file network.h Network API | |
| 3 | * @ingroup core | |
| 4 | * | |
| 5 | * gaim | |
| 6 | * | |
| 7 | * Gaim is the legal property of its developers, whose names are too numerous | |
| 8 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 9 | * source distribution. | |
| 10 | * | |
| 11 | * This program is free software; you can redistribute it and/or modify | |
| 12 | * it under the terms of the GNU General Public License as published by | |
| 13 | * the Free Software Foundation; either version 2 of the License, or | |
| 14 | * (at your option) any later version. | |
| 15 | * | |
| 16 | * This program is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with this program; if not, write to the Free Software | |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 24 | */ | |
| 25 | #ifndef _GAIM_NETWORK_H_ | |
| 26 | #define _GAIM_NETWORK_H_ | |
| 27 | ||
| 28 | #ifdef __cplusplus | |
| 29 | extern "C" { | |
| 30 | #endif | |
| 31 | ||
| 32 | /**************************************************************************/ | |
| 33 | /** @name Network API */ | |
| 34 | /**************************************************************************/ | |
| 35 | /*@{*/ | |
| 36 | ||
| 37 | /** | |
| 38 | * Sets the IP address of the local system in preferences. | |
| 39 | * | |
| 40 | * @param ip The local IP address. | |
| 41 | */ | |
| 42 | void gaim_network_set_local_ip(const char *ip); | |
| 43 | ||
| 44 | /** | |
| 45 | * Returns the IP address of the local system set in preferences. | |
| 46 | * | |
| 47 | * This returns the value set via gaim_network_set_local_ip(). | |
| 48 | * You probably want to use gaim_network_get_ip_for_account() instead. | |
| 49 | * | |
| 50 | * @return The local IP address set in preferences. | |
| 51 | */ | |
| 52 | const char *gaim_network_get_local_ip(void); | |
| 53 | ||
| 54 | /** | |
| 55 | * Returns the IP address of the local system. | |
| 56 | * | |
| 57 | * You probably want to use gaim_network_get_ip_for_account() instead. | |
| 58 | * | |
| 59 | * @note The returned string is a pointer to a static buffer. If this | |
| 60 | * function is called twice, it may be important to make a copy | |
| 61 | * of the returned string. | |
| 62 | * | |
| 63 | * @param fd The fd to use to help figure out the IP, or else -1. | |
| 64 | * @return The local IP address. | |
| 65 | */ | |
| 66 | const char *gaim_network_get_local_system_ip(int fd); | |
| 67 | ||
| 68 | /** | |
| 69 | * Returns the IP address that should be used for the specified account. | |
| 70 | * | |
| 71 | * First, if @a account is not @c NULL, the IP associated with @a account | |
| 72 | * is tried, via a call to gaim_account_get_local_ip(). | |
| 73 | * | |
| 74 | * If that IP is not set, the IP set in preferences is tried. | |
| 75 | * | |
| 76 | * If that IP is not set, the system's local IP is tried, via a call to | |
| 77 | * gaim_network_get_local_ip(). | |
| 78 | * | |
| 79 | * @note The returned string is a pointer to a static buffer. If this | |
| 80 | * function is called twice, it may be important to make a copy | |
| 81 | * of the returned string. | |
| 82 | * | |
| 83 | * @param account The account to use. This may be @c NULL, and if so | |
| 84 | * the first step listed above is skipped. | |
| 85 | * @param fd The fd to use to help figure out the IP, or -1. | |
| 86 | * @return The local IP address to be used. | |
| 87 | */ | |
| 88 | const char *gaim_network_get_ip_for_account(const GaimAccount *account, int fd); | |
| 89 | ||
| 90 | /** | |
|
8250
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
91 | * Attempts to open a listening port ONLY on the specified port number. |
|
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
92 | * You probably want to use gaim_network_listen_range() instead of this. |
|
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
93 | * This function is useful, for example, if you wanted to write a telnet |
|
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
94 | * server as a Gaim plugin, and you HAD to listen on port 23. Why anyone |
|
8248
47da4fbe1a17
[gaim-migrate @ 8971]
Mark Doliner <markdoliner@pidgin.im>
parents:
8246
diff
changeset
|
95 | * would want to do that is beyond me. |
| 8231 | 96 | * |
| 97 | * This opens a listening port. The caller will want to set up a watcher | |
| 98 | * of type GAIM_INPUT_READ on the returned fd. It will probably call | |
| 99 | * accept in the callback, and then possibly remove the watcher and close | |
| 100 | * the listening socket, and add a new watcher on the new socket accept | |
| 101 | * returned. | |
| 102 | * | |
|
8250
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
103 | * @param port The port number to bind to. Must be greater than 0. |
|
8246
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
104 | * |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
105 | * @return The file descriptor of the listening socket, or -1 if |
|
8240
2e5f97ed575d
[gaim-migrate @ 8963]
Mark Doliner <markdoliner@pidgin.im>
parents:
8239
diff
changeset
|
106 | * no socket could be established. |
| 8231 | 107 | */ |
|
8250
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
108 | int gaim_network_listen(unsigned short port); |
|
8246
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
109 | |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
110 | /** |
|
8250
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
111 | * Opens a listening port selected from a range of ports. The range of |
|
8248
47da4fbe1a17
[gaim-migrate @ 8971]
Mark Doliner <markdoliner@pidgin.im>
parents:
8246
diff
changeset
|
112 | * ports used is chosen in the following manner: |
|
47da4fbe1a17
[gaim-migrate @ 8971]
Mark Doliner <markdoliner@pidgin.im>
parents:
8246
diff
changeset
|
113 | * If a range is specified in preferences, these values are used. |
|
8250
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
114 | * If a non-0 values are passed to the function as parameters, these |
|
8248
47da4fbe1a17
[gaim-migrate @ 8971]
Mark Doliner <markdoliner@pidgin.im>
parents:
8246
diff
changeset
|
115 | * values are used. |
|
47da4fbe1a17
[gaim-migrate @ 8971]
Mark Doliner <markdoliner@pidgin.im>
parents:
8246
diff
changeset
|
116 | * Otherwise a port is chosen at random by the kernel. |
|
8246
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
117 | * |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
118 | * This opens a listening port. The caller will want to set up a watcher |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
119 | * of type GAIM_INPUT_READ on the returned fd. It will probably call |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
120 | * accept in the callback, and then possibly remove the watcher and close |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
121 | * the listening socket, and add a new watcher on the new socket accept |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
122 | * returned. |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
123 | * |
|
8248
47da4fbe1a17
[gaim-migrate @ 8971]
Mark Doliner <markdoliner@pidgin.im>
parents:
8246
diff
changeset
|
124 | * @param start The port number to bind to, or 0 to pick a random port. |
|
8246
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
125 | * Users are allowed to override this arg in prefs. |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
126 | * @param end The highest possible port in the range of ports to listen on, |
|
8248
47da4fbe1a17
[gaim-migrate @ 8971]
Mark Doliner <markdoliner@pidgin.im>
parents:
8246
diff
changeset
|
127 | * or 0 to pick a random port. Users are allowed to override this |
|
8246
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
128 | * arg in prefs. |
|
8250
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
129 | * |
|
8246
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
130 | * @return The file descriptor of the listening socket, or -1 if |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
131 | * no socket could be established. |
|
c83c0421149a
[gaim-migrate @ 8969]
Mark Doliner <markdoliner@pidgin.im>
parents:
8240
diff
changeset
|
132 | */ |
|
8250
e855dcce1fa0
[gaim-migrate @ 8973]
Mark Doliner <markdoliner@pidgin.im>
parents:
8248
diff
changeset
|
133 | int gaim_network_listen_range(unsigned short start, unsigned short end); |
| 8231 | 134 | |
| 135 | /** | |
| 136 | * Gets a port number from a file descriptor. | |
| 137 | * | |
| 138 | * @param fd The file descriptor. This should be a tcp socket. The current | |
| 139 | * implementation probably dies on anything but IPv4. Perhaps this | |
| 140 | * possible bug will inspire new and valuable contributors to Gaim. | |
| 141 | * @return The port number, in host byte order. | |
| 142 | */ | |
| 143 | short gaim_network_get_port_from_fd(int fd); | |
| 144 | ||
| 145 | /** | |
| 146 | * Initializes the network subsystem. | |
| 147 | */ | |
| 148 | void gaim_network_init(void); | |
| 149 | ||
| 150 | /*@}*/ | |
| 151 | ||
| 152 | #ifdef __cplusplus | |
| 153 | } | |
| 154 | #endif | |
| 155 | ||
| 156 | #endif /* _GAIM_NETWORK_H_ */ |