These changes are reuired to make the Windows installer build.
[pidgin-git.git] / libpurple / connection.h
blob1eb7c15173b5b449189fee0e7824a84f1c22407b
1 /**
2 * @file connection.h Connection API
3 * @ingroup core
4 * @see @ref connection-signals
5 */
7 /* purple
9 * Purple is the legal property of its developers, whose names are too numerous
10 * to list here. Please refer to the COPYRIGHT file distributed with this
11 * source distribution.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #ifndef _PURPLE_CONNECTION_H_
28 #define _PURPLE_CONNECTION_H_
30 /** @copydoc _PurpleConnection */
31 typedef struct _PurpleConnection PurpleConnection;
33 /**
34 * Flags to change behavior of the client for a given connection.
36 typedef enum
38 PURPLE_CONNECTION_HTML = 0x0001, /**< Connection sends/receives in 'HTML'. */
39 PURPLE_CONNECTION_NO_BGCOLOR = 0x0002, /**< Connection does not send/receive
40 background colors. */
41 PURPLE_CONNECTION_AUTO_RESP = 0x0004, /**< Send auto responses when away. */
42 PURPLE_CONNECTION_FORMATTING_WBFO = 0x0008, /**< The text buffer must be formatted as a whole */
43 PURPLE_CONNECTION_NO_NEWLINES = 0x0010, /**< No new lines are allowed in outgoing messages */
44 PURPLE_CONNECTION_NO_FONTSIZE = 0x0020, /**< Connection does not send/receive font sizes */
45 PURPLE_CONNECTION_NO_URLDESC = 0x0040, /**< Connection does not support descriptions with links */
46 PURPLE_CONNECTION_NO_IMAGES = 0x0080, /**< Connection does not support sending of images */
47 PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY = 0x0100, /**< Connection supports sending and receiving custom smileys */
48 PURPLE_CONNECTION_SUPPORT_MOODS = 0x0200, /**< Connection supports setting moods */
49 PURPLE_CONNECTION_SUPPORT_MOOD_MESSAGES = 0x0400 /**< Connection supports setting a message on moods */
50 } PurpleConnectionFlags;
52 typedef enum
54 PURPLE_DISCONNECTED = 0, /**< Disconnected. */
55 PURPLE_CONNECTED, /**< Connected. */
56 PURPLE_CONNECTING /**< Connecting. */
58 } PurpleConnectionState;
60 /**
61 * Possible errors that can cause a connection to be closed.
63 * @since 2.3.0
65 typedef enum
67 /** There was an error sending or receiving on the network socket, or
68 * there was some protocol error (such as the server sending malformed
69 * data).
71 PURPLE_CONNECTION_ERROR_NETWORK_ERROR = 0,
72 /** The username supplied was not valid. */
73 PURPLE_CONNECTION_ERROR_INVALID_USERNAME = 1,
74 /** The username, password or some other credential was incorrect. Use
75 * #PURPLE_CONNECTION_ERROR_INVALID_USERNAME instead if the username
76 * is known to be invalid.
78 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED = 2,
79 /** libpurple doesn't speak any of the authentication methods the
80 * server offered.
82 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE = 3,
83 /** libpurple was built without SSL support, and the connection needs
84 * SSL.
86 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT = 4,
87 /** There was an error negotiating SSL on this connection, or the
88 * server does not support encryption but an account option was set to
89 * require it.
91 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR = 5,
92 /** Someone is already connected to the server using the name you are
93 * trying to connect with.
95 PURPLE_CONNECTION_ERROR_NAME_IN_USE = 6,
97 /** The username/server/other preference for the account isn't valid.
98 * For instance, on IRC the username cannot contain white space.
99 * This reason should not be used for incorrect passwords etc: use
100 * #PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED for that.
102 * @todo This reason really shouldn't be necessary. Usernames and
103 * other account preferences should be validated when the
104 * account is created.
106 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS = 7,
108 /** The server did not provide a SSL certificate. */
109 PURPLE_CONNECTION_ERROR_CERT_NOT_PROVIDED = 8,
110 /** The server's SSL certificate could not be trusted. */
111 PURPLE_CONNECTION_ERROR_CERT_UNTRUSTED = 9,
112 /** The server's SSL certificate has expired. */
113 PURPLE_CONNECTION_ERROR_CERT_EXPIRED = 10,
114 /** The server's SSL certificate is not yet valid. */
115 PURPLE_CONNECTION_ERROR_CERT_NOT_ACTIVATED = 11,
116 /** The server's SSL certificate did not match its hostname. */
117 PURPLE_CONNECTION_ERROR_CERT_HOSTNAME_MISMATCH = 12,
118 /** The server's SSL certificate does not have the expected
119 * fingerprint.
121 PURPLE_CONNECTION_ERROR_CERT_FINGERPRINT_MISMATCH = 13,
122 /** The server's SSL certificate is self-signed. */
123 PURPLE_CONNECTION_ERROR_CERT_SELF_SIGNED = 14,
124 /** There was some other error validating the server's SSL certificate.
126 PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR = 15,
128 /** Some other error occurred which fits into none of the other
129 * categories.
131 /* purple_connection_error_reason() in connection.c uses the fact that
132 * this is the last member of the enum when sanity-checking; if other
133 * reasons are added after it, the check must be updated.
135 PURPLE_CONNECTION_ERROR_OTHER_ERROR = 16
136 } PurpleConnectionError;
138 /** Holds the type of an error along with its description. */
139 typedef struct
141 /** The type of error. */
142 PurpleConnectionError type;
143 /** A localised, human-readable description of the error. */
144 char *description;
145 } PurpleConnectionErrorInfo;
147 #include <time.h>
149 #include "account.h"
150 #include "plugin.h"
151 #include "status.h"
152 #include "sslconn.h"
155 * Connection UI operations. Used to notify the user of changes to
156 * connections, such as being disconnected, and to respond to the
157 * underlying network connection appearing and disappearing. UIs should
158 * call #purple_connections_set_ui_ops() with an instance of this struct.
160 * @see @ref ui-ops
162 typedef struct
165 * When an account is connecting, this operation is called to notify
166 * the UI of what is happening, as well as which @a step out of @a
167 * step_count has been reached (which might be displayed as a progress
168 * bar).
169 * @see #purple_connection_update_progress
171 void (*connect_progress)(PurpleConnection *gc,
172 const char *text,
173 size_t step,
174 size_t step_count);
177 * Called when a connection is established (just before the
178 * @ref signed-on signal).
180 void (*connected)(PurpleConnection *gc);
183 * Called when a connection is ended (between the @ref signing-off
184 * and @ref signed-off signals).
186 void (*disconnected)(PurpleConnection *gc);
189 * Used to display connection-specific notices. (Pidgin's Gtk user
190 * interface implements this as a no-op; #purple_connection_notice(),
191 * which uses this operation, is not used by any of the protocols
192 * shipped with libpurple.)
194 void (*notice)(PurpleConnection *gc, const char *text);
197 * Called when an error causes a connection to be disconnected.
198 * Called before #disconnected.
199 * @param text a localized error message.
200 * @see #purple_connection_error
201 * @deprecated in favour of
202 * #PurpleConnectionUiOps.report_disconnect_reason.
204 void (*report_disconnect)(PurpleConnection *gc, const char *text);
207 * Called when libpurple discovers that the computer's network
208 * connection is active. On Linux, this uses Network Manager if
209 * available; on Windows, it uses Win32's network change notification
210 * infrastructure.
212 void (*network_connected)(void);
215 * Called when libpurple discovers that the computer's network
216 * connection has gone away.
218 void (*network_disconnected)(void);
221 * Called when an error causes a connection to be disconnected.
222 * Called before #disconnected. This op is intended to replace
223 * #report_disconnect. If both are implemented, this will be called
224 * first; however, there's no real reason to implement both.
226 * @param reason why the connection ended, if known, or
227 * #PURPLE_CONNECTION_ERROR_OTHER_ERROR, if not.
228 * @param text a localized message describing the disconnection
229 * in more detail to the user.
230 * @see #purple_connection_error_reason
232 * @since 2.3.0
234 void (*report_disconnect_reason)(PurpleConnection *gc,
235 PurpleConnectionError reason,
236 const char *text);
238 void (*_purple_reserved1)(void);
239 void (*_purple_reserved2)(void);
240 void (*_purple_reserved3)(void);
241 } PurpleConnectionUiOps;
244 /* Represents an active connection on an account. */
245 struct _PurpleConnection
247 PurplePlugin *prpl; /**< The protocol plugin. */
248 PurpleConnectionFlags flags; /**< Connection flags. */
250 PurpleConnectionState state; /**< The connection state. */
252 PurpleAccount *account; /**< The account being connected to. */
253 char *password; /**< The password used. */
254 int inpa; /**< The input watcher. */
256 GSList *buddy_chats; /**< A list of active chats
257 (#PurpleConversation structs of type
258 #PURPLE_CONV_TYPE_CHAT). */
259 void *proto_data; /**< Protocol-specific data. */
261 char *display_name; /**< How you appear to other people. */
262 guint keepalive; /**< Keep-alive. */
264 /** Wants to Die state. This is set when the user chooses to log out, or
265 * when the protocol is disconnected and should not be automatically
266 * reconnected (incorrect password, etc.). prpls should rely on
267 * purple_connection_error_reason() to set this for them rather than
268 * setting it themselves.
269 * @see purple_connection_error_is_fatal
271 gboolean wants_to_die;
273 guint disconnect_timeout; /**< Timer used for nasty stack tricks */
274 time_t last_received; /**< When we last received a packet. Set by the
275 prpl to avoid sending unneeded keepalives */
278 #ifdef __cplusplus
279 extern "C" {
280 #endif
282 /**************************************************************************/
283 /** @name Connection API */
284 /**************************************************************************/
285 /*@{*/
287 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
289 * This function should only be called by purple_account_connect()
290 * in account.c. If you're trying to sign on an account, use that
291 * function instead.
293 * Creates a connection to the specified account and either connects
294 * or attempts to register a new account. If you are logging in,
295 * the connection uses the current active status for this account.
296 * So if you want to sign on as "away," for example, you need to
297 * have called purple_account_set_status(account, "away").
298 * (And this will call purple_account_connect() automatically).
300 * @param account The account the connection should be connecting to.
301 * @param regist Whether we are registering a new account or just
302 * trying to do a normal signon.
303 * @param password The password to use.
305 * @deprecated As this is internal, we should make it private in 3.0.0.
307 void purple_connection_new(PurpleAccount *account, gboolean regist,
308 const char *password);
309 #endif
311 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
313 * This function should only be called by purple_account_unregister()
314 * in account.c.
316 * Tries to unregister the account on the server. If the account is not
317 * connected, also creates a new connection.
319 * @param account The account to unregister
320 * @param password The password to use.
321 * @param cb Optional callback to be called when unregistration is complete
322 * @param user_data user data to pass to the callback
324 * @deprecated As this is internal, we should make it private in 3.0.0.
326 void purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data);
327 #endif
329 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
331 * Disconnects and destroys a PurpleConnection.
333 * This function should only be called by purple_account_disconnect()
334 * in account.c. If you're trying to sign off an account, use that
335 * function instead.
337 * @param gc The purple connection to destroy.
339 * @deprecated As this is internal, we should make it private in 3.0.0.
341 void purple_connection_destroy(PurpleConnection *gc);
342 #endif
345 * Sets the connection state. PRPLs should call this and pass in
346 * the state #PURPLE_CONNECTED when the account is completely
347 * signed on. What does it mean to be completely signed on? If
348 * the core can call prpl->set_status, and it successfully changes
349 * your status, then the account is online.
351 * @param gc The connection.
352 * @param state The connection state.
354 void purple_connection_set_state(PurpleConnection *gc, PurpleConnectionState state);
357 * Sets the connection's account.
359 * @param gc The connection.
360 * @param account The account.
362 void purple_connection_set_account(PurpleConnection *gc, PurpleAccount *account);
365 * Sets the connection's displayed name.
367 * @param gc The connection.
368 * @param name The displayed name.
370 void purple_connection_set_display_name(PurpleConnection *gc, const char *name);
373 * Sets the protocol data for a connection.
375 * @param connection The PurpleConnection.
376 * @param proto_data The protocol data to set for the connection.
378 * @since 2.6.0
380 void purple_connection_set_protocol_data(PurpleConnection *connection, void *proto_data);
383 * Returns the connection state.
385 * @param gc The connection.
387 * @return The connection state.
389 PurpleConnectionState purple_connection_get_state(const PurpleConnection *gc);
392 * Returns TRUE if the account is connected, otherwise returns FALSE.
394 * @return TRUE if the account is connected, otherwise returns FALSE.
396 #define PURPLE_CONNECTION_IS_CONNECTED(gc) \
397 (purple_connection_get_state(gc) == PURPLE_CONNECTED)
400 * Returns the connection's account.
402 * @param gc The connection.
404 * @return The connection's account.
406 PurpleAccount *purple_connection_get_account(const PurpleConnection *gc);
409 * Returns the protocol plugin managing a connection.
411 * @param gc The connection.
413 * @return The protocol plugin.
415 * @since 2.4.0
417 PurplePlugin * purple_connection_get_prpl(const PurpleConnection *gc);
420 * Returns the connection's password.
422 * @param gc The connection.
424 * @return The connection's password.
426 const char *purple_connection_get_password(const PurpleConnection *gc);
429 * Returns the connection's displayed name.
431 * @param gc The connection.
433 * @return The connection's displayed name.
435 const char *purple_connection_get_display_name(const PurpleConnection *gc);
438 * Gets the protocol data from a connection.
440 * @param connection The PurpleConnection.
442 * @return The protocol data for the connection.
444 * @since 2.6.0
446 void *purple_connection_get_protocol_data(const PurpleConnection *connection);
449 * Updates the connection progress.
451 * @param gc The connection.
452 * @param text Information on the current step.
453 * @param step The current step.
454 * @param count The total number of steps.
456 void purple_connection_update_progress(PurpleConnection *gc, const char *text,
457 size_t step, size_t count);
460 * Displays a connection-specific notice.
462 * @param gc The connection.
463 * @param text The notice text.
465 void purple_connection_notice(PurpleConnection *gc, const char *text);
468 * Closes a connection with an error.
470 * @param gc The connection.
471 * @param reason The error text, which may not be @c NULL.
472 * @deprecated in favour of #purple_connection_error_reason. Calling
473 * @c purple_connection_error(gc, text) is equivalent to calling
474 * @c purple_connection_error_reason(gc, reason, text) where @c reason is
475 * #PURPLE_CONNECTION_ERROR_OTHER_ERROR if @c gc->wants_to_die is @c TRUE, and
476 * #PURPLE_CONNECTION_ERROR_NETWORK_ERROR if not. (This is to keep
477 * auto-reconnection behaviour the same when using old prpls which don't use
478 * reasons yet.)
480 void purple_connection_error(PurpleConnection *gc, const char *reason);
483 * Closes a connection with an error and a human-readable description of the
484 * error. It also sets @c gc->wants_to_die to the value of
485 * #purple_connection_error_is_fatal(@a reason), mainly for
486 * backwards-compatibility.
488 * @param gc the connection which is closing.
489 * @param reason why the connection is closing.
490 * @param description a non-@c NULL localized description of the error.
492 * @since 2.3.0
494 void
495 purple_connection_error_reason (PurpleConnection *gc,
496 PurpleConnectionError reason,
497 const char *description);
500 * Closes a connection due to an SSL error; this is basically a shortcut to
501 * turning the #PurpleSslErrorType into a #PurpleConnectionError and a
502 * human-readable string and then calling purple_connection_error_reason().
504 * @since 2.3.0
506 void
507 purple_connection_ssl_error (PurpleConnection *gc,
508 PurpleSslErrorType ssl_error);
511 * Reports whether a disconnection reason is fatal (in which case the account
512 * should probably not be automatically reconnected) or transient (so
513 * auto-reconnection is a good idea).
514 * For instance, #PURPLE_CONNECTION_ERROR_NETWORK_ERROR is a temporary error,
515 * which might be caused by losing the network connection, so <tt>
516 * purple_connection_error_is_fatal (PURPLE_CONNECTION_ERROR_NETWORK_ERROR)</tt>
517 * is @c FALSE. On the other hand,
518 * #PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED probably indicates a
519 * misconfiguration of the account which needs the user to go fix it up, so
520 * <tt> purple_connection_error_is_fatal
521 * (PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED)</tt> is @c TRUE.
523 * (This function is meant to replace checking PurpleConnection.wants_to_die.)
525 * @return @c TRUE if the account should not be automatically reconnected, and
526 * @c FALSE otherwise.
528 * @since 2.3.0
530 gboolean
531 purple_connection_error_is_fatal (PurpleConnectionError reason);
533 /*@}*/
535 /**************************************************************************/
536 /** @name Connections API */
537 /**************************************************************************/
538 /*@{*/
541 * Disconnects from all connections.
543 void purple_connections_disconnect_all(void);
546 * Returns a list of all active connections. This does not
547 * include connections that are in the process of connecting.
549 * @constreturn A list of all active connections.
551 GList *purple_connections_get_all(void);
554 * Returns a list of all connections in the process of connecting.
556 * @constreturn A list of connecting connections.
558 GList *purple_connections_get_connecting(void);
561 * Checks if gc is still a valid pointer to a gc.
563 * @return @c TRUE if gc is valid.
565 * @deprecated Do not use this. Instead, cancel your asynchronous request
566 * when the PurpleConnection is destroyed.
569 * TODO: Eventually this bad boy will be removed, because it is
570 * a gross fix for a crashy problem.
572 #define PURPLE_CONNECTION_IS_VALID(gc) (g_list_find(purple_connections_get_all(), (gc)) != NULL)
574 /*@}*/
576 /**************************************************************************/
577 /** @name UI Registration Functions */
578 /**************************************************************************/
579 /*@{*/
582 * Sets the UI operations structure to be used for connections.
584 * @param ops The UI operations structure.
586 void purple_connections_set_ui_ops(PurpleConnectionUiOps *ops);
589 * Returns the UI operations structure used for connections.
591 * @return The UI operations structure in use.
593 PurpleConnectionUiOps *purple_connections_get_ui_ops(void);
595 /*@}*/
597 /**************************************************************************/
598 /** @name Connections Subsystem */
599 /**************************************************************************/
600 /*@{*/
603 * Initializes the connections subsystem.
605 void purple_connections_init(void);
608 * Uninitializes the connections subsystem.
610 void purple_connections_uninit(void);
613 * Returns the handle to the connections subsystem.
615 * @return The connections subsystem handle.
617 void *purple_connections_get_handle(void);
619 /*@}*/
622 #ifdef __cplusplus
624 #endif
626 #endif /* _PURPLE_CONNECTION_H_ */