2 * @file connection.h Connection API
4 * @see @ref connection-signals
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;
34 * Flags to change behavior of the client for a given connection.
38 PURPLE_CONNECTION_HTML = 0x0001, /**< Connection sends/receives in 'HTML'. */
39 PURPLE_CONNECTION_NO_BGCOLOR = 0x0002, /**< Connection does not send/receive
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 */
49 } PurpleConnectionFlags;
53 PURPLE_DISCONNECTED = 0, /**< Disconnected. */
54 PURPLE_CONNECTED, /**< Connected. */
55 PURPLE_CONNECTING /**< Connecting. */
57 } PurpleConnectionState;
60 * Possible errors that can cause a connection to be closed.
66 /** There was an error sending or receiving on the network socket, or
67 * there was some protocol error (such as the server sending malformed
70 PURPLE_CONNECTION_ERROR_NETWORK_ERROR = 0,
71 /** The username supplied was not valid. */
72 PURPLE_CONNECTION_ERROR_INVALID_USERNAME = 1,
73 /** The username, password or some other credential was incorrect. Use
74 * #PURPLE_CONNECTION_ERROR_INVALID_USERNAME instead if the username
75 * is known to be invalid.
77 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED = 2,
78 /** libpurple doesn't speak any of the authentication methods the
81 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE = 3,
82 /** libpurple was built without SSL support, and the connection needs
85 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT = 4,
86 /** There was an error negotiating SSL on this connection, or the
87 * server does not support encryption but an account option was set to
90 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR = 5,
91 /** Someone is already connected to the server using the name you are
92 * trying to connect with.
94 PURPLE_CONNECTION_ERROR_NAME_IN_USE = 6,
96 /** The username/server/other preference for the account isn't valid.
97 * For instance, on IRC the username cannot contain white space.
98 * This reason should not be used for incorrect passwords etc: use
99 * #PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED for that.
101 * @todo This reason really shouldn't be necessary. Usernames and
102 * other account preferences should be validated when the
103 * account is created.
105 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS = 7,
107 /** The server did not provide a SSL certificate. */
108 PURPLE_CONNECTION_ERROR_CERT_NOT_PROVIDED = 8,
109 /** The server's SSL certificate could not be trusted. */
110 PURPLE_CONNECTION_ERROR_CERT_UNTRUSTED = 9,
111 /** The server's SSL certificate has expired. */
112 PURPLE_CONNECTION_ERROR_CERT_EXPIRED = 10,
113 /** The server's SSL certificate is not yet valid. */
114 PURPLE_CONNECTION_ERROR_CERT_NOT_ACTIVATED = 11,
115 /** The server's SSL certificate did not match its hostname. */
116 PURPLE_CONNECTION_ERROR_CERT_HOSTNAME_MISMATCH = 12,
117 /** The server's SSL certificate does not have the expected
120 PURPLE_CONNECTION_ERROR_CERT_FINGERPRINT_MISMATCH = 13,
121 /** The server's SSL certificate is self-signed. */
122 PURPLE_CONNECTION_ERROR_CERT_SELF_SIGNED = 14,
123 /** There was some other error validating the server's SSL certificate.
125 PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR = 15,
127 /** Some other error occurred which fits into none of the other
130 /* purple_connection_error_reason() in connection.c uses the fact that
131 * this is the last member of the enum when sanity-checking; if other
132 * reasons are added after it, the check must be updated.
134 PURPLE_CONNECTION_ERROR_OTHER_ERROR = 16
135 } PurpleConnectionError;
137 /** Holds the type of an error along with its description. */
140 /** The type of error. */
141 PurpleConnectionError type;
142 /** A localised, human-readable description of the error. */
144 } PurpleConnectionErrorInfo;
154 * Connection UI operations. Used to notify the user of changes to
155 * connections, such as being disconnected, and to respond to the
156 * underlying network connection appearing and disappearing. UIs should
157 * call #purple_connections_set_ui_ops() with an instance of this struct.
164 * When an account is connecting, this operation is called to notify
165 * the UI of what is happening, as well as which @a step out of @a
166 * step_count has been reached (which might be displayed as a progress
168 * @see #purple_connection_update_progress
170 void (*connect_progress)(PurpleConnection *gc,
176 * Called when a connection is established (just before the
177 * @ref signed-on signal).
179 void (*connected)(PurpleConnection *gc);
182 * Called when a connection is ended (between the @ref signing-off
183 * and @ref signed-off signals).
185 void (*disconnected)(PurpleConnection *gc);
188 * Used to display connection-specific notices. (Pidgin's Gtk user
189 * interface implements this as a no-op; #purple_connection_notice(),
190 * which uses this operation, is not used by any of the protocols
191 * shipped with libpurple.)
193 void (*notice)(PurpleConnection *gc, const char *text);
196 * Called when an error causes a connection to be disconnected.
197 * Called before #disconnected.
198 * @param text a localized error message.
199 * @see #purple_connection_error
200 * @deprecated in favour of
201 * #PurpleConnectionUiOps.report_disconnect_reason.
203 void (*report_disconnect)(PurpleConnection *gc, const char *text);
206 * Called when libpurple discovers that the computer's network
207 * connection is active. On Linux, this uses Network Manager if
208 * available; on Windows, it uses Win32's network change notification
211 void (*network_connected)(void);
214 * Called when libpurple discovers that the computer's network
215 * connection has gone away.
217 void (*network_disconnected)(void);
220 * Called when an error causes a connection to be disconnected.
221 * Called before #disconnected. This op is intended to replace
222 * #report_disconnect. If both are implemented, this will be called
223 * first; however, there's no real reason to implement both.
225 * @param reason why the connection ended, if known, or
226 * #PURPLE_CONNECTION_ERROR_OTHER_ERROR, if not.
227 * @param text a localized message describing the disconnection
228 * in more detail to the user.
229 * @see #purple_connection_error_reason
233 void (*report_disconnect_reason)(PurpleConnection *gc,
234 PurpleConnectionError reason,
237 void (*_purple_reserved1)(void);
238 void (*_purple_reserved2)(void);
239 void (*_purple_reserved3)(void);
240 } PurpleConnectionUiOps;
243 /* Represents an active connection on an account. */
244 struct _PurpleConnection
246 PurplePlugin *prpl; /**< The protocol plugin. */
247 PurpleConnectionFlags flags; /**< Connection flags. */
249 PurpleConnectionState state; /**< The connection state. */
251 PurpleAccount *account; /**< The account being connected to. */
252 char *password; /**< The password used. */
253 int inpa; /**< The input watcher. */
255 GSList *buddy_chats; /**< A list of active chats
256 (#PurpleConversation structs of type
257 #PURPLE_CONV_TYPE_CHAT). */
258 void *proto_data; /**< Protocol-specific data. */
260 char *display_name; /**< How you appear to other people. */
261 guint keepalive; /**< Keep-alive. */
263 /** Wants to Die state. This is set when the user chooses to log out, or
264 * when the protocol is disconnected and should not be automatically
265 * reconnected (incorrect password, etc.). prpls should rely on
266 * purple_connection_error_reason() to set this for them rather than
267 * setting it themselves.
268 * @see purple_connection_error_is_fatal
270 gboolean wants_to_die;
272 guint disconnect_timeout; /**< Timer used for nasty stack tricks */
273 time_t last_received; /**< When we last received a packet. Set by the
274 prpl to avoid sending unneeded keepalives */
281 /**************************************************************************/
282 /** @name Connection API */
283 /**************************************************************************/
286 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
288 * This function should only be called by purple_account_connect()
289 * in account.c. If you're trying to sign on an account, use that
292 * Creates a connection to the specified account and either connects
293 * or attempts to register a new account. If you are logging in,
294 * the connection uses the current active status for this account.
295 * So if you want to sign on as "away," for example, you need to
296 * have called purple_account_set_status(account, "away").
297 * (And this will call purple_account_connect() automatically).
299 * @param account The account the connection should be connecting to.
300 * @param regist Whether we are registering a new account or just
301 * trying to do a normal signon.
302 * @param password The password to use.
304 * @deprecated As this is internal, we should make it private in 3.0.0.
306 void purple_connection_new(PurpleAccount *account, gboolean regist,
307 const char *password);
310 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
312 * This function should only be called by purple_account_unregister()
315 * Tries to unregister the account on the server. If the account is not
316 * connected, also creates a new connection.
318 * @param account The account to unregister
319 * @param password The password to use.
320 * @param cb Optional callback to be called when unregistration is complete
321 * @param user_data user data to pass to the callback
323 * @deprecated As this is internal, we should make it private in 3.0.0.
325 void purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data);
328 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
330 * Disconnects and destroys a PurpleConnection.
332 * This function should only be called by purple_account_disconnect()
333 * in account.c. If you're trying to sign off an account, use that
336 * @param gc The purple connection to destroy.
338 * @deprecated As this is internal, we should make it private in 3.0.0.
340 void purple_connection_destroy(PurpleConnection *gc);
344 * Sets the connection state. PRPLs should call this and pass in
345 * the state #PURPLE_CONNECTED when the account is completely
346 * signed on. What does it mean to be completely signed on? If
347 * the core can call prpl->set_status, and it successfully changes
348 * your status, then the account is online.
350 * @param gc The connection.
351 * @param state The connection state.
353 void purple_connection_set_state(PurpleConnection *gc, PurpleConnectionState state);
356 * Sets the connection's account.
358 * @param gc The connection.
359 * @param account The account.
361 void purple_connection_set_account(PurpleConnection *gc, PurpleAccount *account);
364 * Sets the connection's displayed name.
366 * @param gc The connection.
367 * @param name The displayed name.
369 void purple_connection_set_display_name(PurpleConnection *gc, const char *name);
372 * Sets the protocol data for a connection.
374 * @param connection The PurpleConnection.
375 * @param proto_data The protocol data to set for the connection.
379 void purple_connection_set_protocol_data(PurpleConnection *connection, void *proto_data);
382 * Returns the connection state.
384 * @param gc The connection.
386 * @return The connection state.
388 PurpleConnectionState purple_connection_get_state(const PurpleConnection *gc);
391 * Returns TRUE if the account is connected, otherwise returns FALSE.
393 * @return TRUE if the account is connected, otherwise returns FALSE.
395 #define PURPLE_CONNECTION_IS_CONNECTED(gc) \
396 (purple_connection_get_state(gc) == PURPLE_CONNECTED)
399 * Returns the connection's account.
401 * @param gc The connection.
403 * @return The connection's account.
405 PurpleAccount *purple_connection_get_account(const PurpleConnection *gc);
408 * Returns the protocol plugin managing a connection.
410 * @param gc The connection.
412 * @return The protocol plugin.
416 PurplePlugin * purple_connection_get_prpl(const PurpleConnection *gc);
419 * Returns the connection's password.
421 * @param gc The connection.
423 * @return The connection's password.
425 const char *purple_connection_get_password(const PurpleConnection *gc);
428 * Returns the connection's displayed name.
430 * @param gc The connection.
432 * @return The connection's displayed name.
434 const char *purple_connection_get_display_name(const PurpleConnection *gc);
437 * Gets the protocol data from a connection.
439 * @param connection The PurpleConnection.
441 * @return The protocol data for the connection.
445 void *purple_connection_get_protocol_data(const PurpleConnection *connection);
448 * Updates the connection progress.
450 * @param gc The connection.
451 * @param text Information on the current step.
452 * @param step The current step.
453 * @param count The total number of steps.
455 void purple_connection_update_progress(PurpleConnection *gc, const char *text,
456 size_t step, size_t count);
459 * Displays a connection-specific notice.
461 * @param gc The connection.
462 * @param text The notice text.
464 void purple_connection_notice(PurpleConnection *gc, const char *text);
467 * Closes a connection with an error.
469 * @param gc The connection.
470 * @param reason The error text, which may not be @c NULL.
471 * @deprecated in favour of #purple_connection_error_reason. Calling
472 * @c purple_connection_error(gc, text) is equivalent to calling
473 * @c purple_connection_error_reason(gc, reason, text) where @c reason is
474 * #PURPLE_CONNECTION_ERROR_OTHER_ERROR if @c gc->wants_to_die is @c TRUE, and
475 * #PURPLE_CONNECTION_ERROR_NETWORK_ERROR if not. (This is to keep
476 * auto-reconnection behaviour the same when using old prpls which don't use
479 void purple_connection_error(PurpleConnection *gc, const char *reason);
482 * Closes a connection with an error and a human-readable description of the
483 * error. It also sets @c gc->wants_to_die to the value of
484 * #purple_connection_error_is_fatal(@a reason), mainly for
485 * backwards-compatibility.
487 * @param gc the connection which is closing.
488 * @param reason why the connection is closing.
489 * @param description a non-@c NULL localized description of the error.
494 purple_connection_error_reason (PurpleConnection *gc,
495 PurpleConnectionError reason,
496 const char *description);
499 * Closes a connection due to an SSL error; this is basically a shortcut to
500 * turning the #PurpleSslErrorType into a #PurpleConnectionError and a
501 * human-readable string and then calling purple_connection_error_reason().
506 purple_connection_ssl_error (PurpleConnection *gc,
507 PurpleSslErrorType ssl_error);
510 * Reports whether a disconnection reason is fatal (in which case the account
511 * should probably not be automatically reconnected) or transient (so
512 * auto-reconnection is a good idea).
513 * For instance, #PURPLE_CONNECTION_ERROR_NETWORK_ERROR is a temporary error,
514 * which might be caused by losing the network connection, so <tt>
515 * purple_connection_error_is_fatal (PURPLE_CONNECTION_ERROR_NETWORK_ERROR)</tt>
516 * is @c FALSE. On the other hand,
517 * #PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED probably indicates a
518 * misconfiguration of the account which needs the user to go fix it up, so
519 * <tt> purple_connection_error_is_fatal
520 * (PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED)</tt> is @c TRUE.
522 * (This function is meant to replace checking PurpleConnection.wants_to_die.)
524 * @return @c TRUE if the account should not be automatically reconnected, and
525 * @c FALSE otherwise.
530 purple_connection_error_is_fatal (PurpleConnectionError reason);
534 /**************************************************************************/
535 /** @name Connections API */
536 /**************************************************************************/
540 * Disconnects from all connections.
542 void purple_connections_disconnect_all(void);
545 * Returns a list of all active connections. This does not
546 * include connections that are in the process of connecting.
548 * @constreturn A list of all active connections.
550 GList *purple_connections_get_all(void);
553 * Returns a list of all connections in the process of connecting.
555 * @constreturn A list of connecting connections.
557 GList *purple_connections_get_connecting(void);
560 * Checks if gc is still a valid pointer to a gc.
562 * @return @c TRUE if gc is valid.
564 * @deprecated Do not use this. Instead, cancel your asynchronous request
565 * when the PurpleConnection is destroyed.
568 * TODO: Eventually this bad boy will be removed, because it is
569 * a gross fix for a crashy problem.
571 #define PURPLE_CONNECTION_IS_VALID(gc) (g_list_find(purple_connections_get_all(), (gc)) != NULL)
575 /**************************************************************************/
576 /** @name UI Registration Functions */
577 /**************************************************************************/
581 * Sets the UI operations structure to be used for connections.
583 * @param ops The UI operations structure.
585 void purple_connections_set_ui_ops(PurpleConnectionUiOps *ops);
588 * Returns the UI operations structure used for connections.
590 * @return The UI operations structure in use.
592 PurpleConnectionUiOps *purple_connections_get_ui_ops(void);
596 /**************************************************************************/
597 /** @name Connections Subsystem */
598 /**************************************************************************/
602 * Initializes the connections subsystem.
604 void purple_connections_init(void);
607 * Uninitializes the connections subsystem.
609 void purple_connections_uninit(void);
612 * Returns the handle to the connections subsystem.
614 * @return The connections subsystem handle.
616 void *purple_connections_get_handle(void);
625 #endif /* _PURPLE_CONNECTION_H_ */