Fix an incorrect call to soup_message_set_request.
[pidgin-git.git] / libpurple / connection.h
bloba26c1462f42d1f3e3de921097cec8c6cf1b7655b
1 /* purple
3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
5 * source distribution.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #ifndef PURPLE_CONNECTION_H
23 #define PURPLE_CONNECTION_H
24 /**
25 * SECTION:connection
26 * @section_id: libpurple-connection
27 * @short_description: <filename>connection.h</filename>
28 * @title: Connection API
29 * @see_also: <link linkend="chapter-signals-connection">Connection signals</link>
32 #include <glib.h>
34 #define PURPLE_TYPE_CONNECTION purple_connection_get_type()
36 typedef struct _PurpleConnection PurpleConnection;
38 #define PURPLE_TYPE_CONNECTION_UI_OPS (purple_connection_ui_ops_get_type())
40 typedef struct _PurpleConnectionUiOps PurpleConnectionUiOps;
42 #define PURPLE_TYPE_CONNECTION_ERROR_INFO (purple_connection_error_info_get_type())
44 typedef struct _PurpleConnectionErrorInfo PurpleConnectionErrorInfo;
46 /**
47 * PurpleConnectionFlags:
48 * @PURPLE_CONNECTION_FLAG_HTML: Connection sends/receives in 'HTML'
49 * @PURPLE_CONNECTION_FLAG_NO_BGCOLOR: Connection does not send/receive
50 * background colors
51 * @PURPLE_CONNECTION_FLAG_AUTO_RESP: Send auto responses when away
52 * @PURPLE_CONNECTION_FLAG_FORMATTING_WBFO: The text buffer must be formatted
53 * as a whole
54 * @PURPLE_CONNECTION_FLAG_NO_NEWLINES: No new lines are allowed in outgoing
55 * messages
56 * @PURPLE_CONNECTION_FLAG_NO_FONTSIZE: Connection does not send/receive font
57 * sizes
58 * @PURPLE_CONNECTION_FLAG_NO_URLDESC: Connection does not support descriptions
59 * with links
60 * @PURPLE_CONNECTION_FLAG_NO_IMAGES: Connection does not support sending of
61 * images
62 * @PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY: Connection supports sending
63 * and receiving custom smileys
64 * @PURPLE_CONNECTION_FLAG_SUPPORT_MOODS: Connection supports setting moods
65 * @PURPLE_CONNECTION_FLAG_SUPPORT_MOOD_MESSAGES: Connection supports setting
66 * a message on moods
68 * Flags to change behavior of the client for a given connection.
70 typedef enum /*< flags >*/
72 PURPLE_CONNECTION_FLAG_HTML = 0x0001,
73 PURPLE_CONNECTION_FLAG_NO_BGCOLOR = 0x0002,
74 PURPLE_CONNECTION_FLAG_AUTO_RESP = 0x0004,
75 PURPLE_CONNECTION_FLAG_FORMATTING_WBFO = 0x0008,
76 PURPLE_CONNECTION_FLAG_NO_NEWLINES = 0x0010,
77 PURPLE_CONNECTION_FLAG_NO_FONTSIZE = 0x0020,
78 PURPLE_CONNECTION_FLAG_NO_URLDESC = 0x0040,
79 PURPLE_CONNECTION_FLAG_NO_IMAGES = 0x0080,
80 PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY = 0x0100,
81 PURPLE_CONNECTION_FLAG_SUPPORT_MOODS = 0x0200,
82 PURPLE_CONNECTION_FLAG_SUPPORT_MOOD_MESSAGES = 0x0400
83 } PurpleConnectionFlags;
85 /**
86 * PurpleConnectionState:
87 * @PURPLE_CONNECTION_DISCONNECTED: Disconnected.
88 * @PURPLE_CONNECTION_CONNECTED: Connected.
89 * @PURPLE_CONNECTION_CONNECTING: Connecting.
91 typedef enum
93 PURPLE_CONNECTION_DISCONNECTED = 0,
94 PURPLE_CONNECTION_CONNECTED,
95 PURPLE_CONNECTION_CONNECTING
96 } PurpleConnectionState;
98 #define PURPLE_CONNECTION_ERROR purple_connection_error_quark()
101 * purple_connection_error_quark:
103 * Error domain for Purple connection errors. Errors in this domain will be
104 * from the #PurpleConnectionError enum.
106 GQuark purple_connection_error_quark(void);
109 * PurpleConnectionError:
110 * @PURPLE_CONNECTION_ERROR_NETWORK_ERROR: There was an error sending or
111 * receiving on the network socket, or there was some protocol error
112 * (such as the server sending malformed data).
113 * @PURPLE_CONNECTION_ERROR_INVALID_USERNAME: The username supplied was not
114 * valid.
115 * @PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED: The username, password or
116 * some other credential was incorrect. Use
117 * #PURPLE_CONNECTION_ERROR_INVALID_USERNAME instead if the username
118 * is known to be invalid.
119 * @PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE: libpurple doesn't speak
120 * any of the authentication methods the server offered.
121 * @PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT: libpurple was built without SSL
122 * support, and the connection needs SSL.
123 * @PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR: There was an error negotiating
124 * SSL on this connection, or the server does not support encryption
125 * but an account option was set to require it.
126 * @PURPLE_CONNECTION_ERROR_NAME_IN_USE: Someone is already connected to the
127 * server using the name you are trying to connect with.
128 * @PURPLE_CONNECTION_ERROR_INVALID_SETTINGS: The username/server/other
129 * preference for the account isn't valid. For instance, on IRC the
130 * username cannot contain white space. This reason should not be used
131 * for incorrect passwords etc: use
132 * #PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED for that.
133 * @PURPLE_CONNECTION_ERROR_CERT_NOT_PROVIDED: The server did not provide a
134 * SSL certificate.
135 * @PURPLE_CONNECTION_ERROR_CERT_UNTRUSTED: The server's SSL certificate could
136 * not be trusted.
137 * @PURPLE_CONNECTION_ERROR_CERT_EXPIRED: The server's SSL certificate has
138 * expired.
139 * @PURPLE_CONNECTION_ERROR_CERT_NOT_ACTIVATED: The server's SSL certificate is
140 * not yet valid.
141 * @PURPLE_CONNECTION_ERROR_CERT_HOSTNAME_MISMATCH: The server's SSL
142 * certificate did not match its hostname.
143 * @PURPLE_CONNECTION_ERROR_CERT_FINGERPRINT_MISMATCH: The server's SSL
144 * certificate does not have the expected fingerprint.
145 * @PURPLE_CONNECTION_ERROR_CERT_SELF_SIGNED: The server's SSL certificate is
146 * self-signed.
147 * @PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR: There was some other error
148 * validating the server's SSL certificate.
149 * @PURPLE_CONNECTION_ERROR_OTHER_ERROR: Some other error occurred which fits
150 * into none of the other categories.
152 * Possible errors that can cause a connection to be closed.
154 typedef enum
156 PURPLE_CONNECTION_ERROR_NETWORK_ERROR = 0,
157 PURPLE_CONNECTION_ERROR_INVALID_USERNAME = 1,
158 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED = 2,
159 PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE = 3,
160 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT = 4,
161 PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR = 5,
162 PURPLE_CONNECTION_ERROR_NAME_IN_USE = 6,
164 /* TODO This reason really shouldn't be necessary. Usernames and
165 * other account preferences should be validated when the
166 * account is created. */
167 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS = 7,
169 PURPLE_CONNECTION_ERROR_CERT_NOT_PROVIDED = 8,
170 PURPLE_CONNECTION_ERROR_CERT_UNTRUSTED = 9,
171 PURPLE_CONNECTION_ERROR_CERT_EXPIRED = 10,
172 PURPLE_CONNECTION_ERROR_CERT_NOT_ACTIVATED = 11,
173 PURPLE_CONNECTION_ERROR_CERT_HOSTNAME_MISMATCH = 12,
174 PURPLE_CONNECTION_ERROR_CERT_FINGERPRINT_MISMATCH = 13,
175 PURPLE_CONNECTION_ERROR_CERT_SELF_SIGNED = 14,
176 PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR = 15,
178 /* purple_connection_error() in connection.c uses the fact that
179 * this is the last member of the enum when sanity-checking; if other
180 * reasons are added after it, the check must be updated.
182 PURPLE_CONNECTION_ERROR_OTHER_ERROR = 16
183 } PurpleConnectionError;
186 * PurpleConnectionErrorInfo:
187 * @type: The type of error.
188 * @description: A localised, human-readable description of the error.
190 * Holds the type of an error along with its description.
192 struct _PurpleConnectionErrorInfo
194 PurpleConnectionError type;
195 char *description;
198 #include <time.h>
200 #include "account.h"
201 #include "protocol.h"
202 #include "status.h"
203 #include "sslconn.h"
206 * PurpleConnectionUiOps:
207 * @connect_progress: When an account is connecting, this operation is called to
208 * notify the UI of what is happening, as well as which @step
209 * out of @step_count has been reached (which might be
210 * displayed as a progress bar).
211 * <sbr/>See purple_connection_update_progress().
212 * @connected: Called when a connection is established (just before the
213 * <link linkend="connections-signed-on"><literal>"signed-on"</literal></link>
214 * signal).
215 * @disconnected: Called when a connection is ended (between the
216 * <link linkend="connections-signing-off"><literal>"signing-off"</literal></link>
217 * and <link linkend="connections-signed-off"><literal>"signed-off"</literal></link>
218 * signals).
219 * @notice: Used to display connection-specific notices. (Pidgin's Gtk user
220 * interface implements this as a no-op; purple_connection_notice(),
221 * which uses this operation, is not used by any of the protocols
222 * shipped with libpurple.)
223 * @network_connected: Called when libpurple discovers that the computer's
224 * network connection is active. On Linux, this uses
225 * Network Manager if available; on Windows, it uses
226 * Win32's network change notification infrastructure.
227 * @network_disconnected: Called when libpurple discovers that the computer's
228 * network connection has gone away.
229 * @report_disconnect: Called when an error causes a connection to be
230 * disconnected. Called before @disconnected.
231 * <sbr/>See purple_connection_error().
232 * <sbr/>@reason: why the connection ended, if known, or
233 * #PURPLE_CONNECTION_ERROR_OTHER_ERROR, if not.
234 * <sbr/>@text: a localized message describing the
235 * disconnection in more detail to the user.
237 * Connection UI operations. Used to notify the user of changes to
238 * connections, such as being disconnected, and to respond to the
239 * underlying network connection appearing and disappearing. UIs should
240 * call #purple_connections_set_ui_ops() with an instance of this struct.
242 * See <link linkend="chapter-ui-ops">List of <literal>UiOps</literal> Structures</link>
244 struct _PurpleConnectionUiOps
246 void (*connect_progress)(PurpleConnection *gc,
247 const char *text,
248 size_t step,
249 size_t step_count);
251 void (*connected)(PurpleConnection *gc);
252 void (*disconnected)(PurpleConnection *gc);
254 void (*notice)(PurpleConnection *gc, const char *text);
256 void (*network_connected)(void);
257 void (*network_disconnected)(void);
259 void (*report_disconnect)(PurpleConnection *gc,
260 PurpleConnectionError reason,
261 const char *text);
263 /*< private >*/
264 void (*_purple_reserved1)(void);
265 void (*_purple_reserved2)(void);
266 void (*_purple_reserved3)(void);
267 void (*_purple_reserved4)(void);
270 G_BEGIN_DECLS
272 /**************************************************************************/
273 /* Connection API */
274 /**************************************************************************/
277 * purple_connection_get_type:
279 * Returns: The #GType for the Connection object.
281 G_DECLARE_FINAL_TYPE(PurpleConnection, purple_connection, PURPLE, CONNECTION, GObject)
284 * purple_connection_error_info_get_type:
286 * Returns: The #GType for the #PurpleConnectionErrorInfo boxed structure.
288 GType purple_connection_error_info_get_type(void);
291 * purple_connection_set_state:
292 * @gc: The connection.
293 * @state: The connection state.
295 * Sets the connection state. Protocols should call this and pass in
296 * the state #PURPLE_CONNECTION_CONNECTED when the account is completely
297 * signed on. What does it mean to be completely signed on? If
298 * the core can call protocol's set_status, and it successfully changes
299 * your status, then the account is online.
301 void purple_connection_set_state(PurpleConnection *gc, PurpleConnectionState state);
304 * purple_connection_set_flags:
305 * @gc: The connection.
306 * @flags: The flags.
308 * Sets the connection flags.
310 void purple_connection_set_flags(PurpleConnection *gc, PurpleConnectionFlags flags);
313 * purple_connection_set_display_name:
314 * @gc: The connection.
315 * @name: The displayed name.
317 * Sets the connection's displayed name.
319 void purple_connection_set_display_name(PurpleConnection *gc, const char *name);
322 * purple_connection_set_protocol_data:
323 * @connection: The PurpleConnection.
324 * @proto_data: The protocol data to set for the connection.
326 * Sets the protocol data for a connection.
328 void purple_connection_set_protocol_data(PurpleConnection *connection, void *proto_data);
331 * purple_connection_get_state:
332 * @gc: The connection.
334 * Returns the connection state.
336 * Returns: The connection state.
338 PurpleConnectionState purple_connection_get_state(PurpleConnection *gc);
341 * purple_connection_get_flags:
342 * @gc: The connection.
344 * Returns the connection flags.
346 * Returns: The connection flags.
348 PurpleConnectionFlags purple_connection_get_flags(PurpleConnection *gc);
351 * PURPLE_CONNECTION_IS_CONNECTED:
353 * Returns TRUE if the account is connected, otherwise returns FALSE.
355 * Returns: TRUE if the account is connected, otherwise returns FALSE.
357 #define PURPLE_CONNECTION_IS_CONNECTED(gc) \
358 (purple_connection_get_state(gc) == PURPLE_CONNECTION_CONNECTED)
361 * purple_connection_is_disconnecting:
362 * @param gc The connection.
364 * Checks, if connection is in disconnecting state.
366 * Returns: %TRUE, if the account is disconnecting.
368 gboolean
369 purple_connection_is_disconnecting(PurpleConnection *gc);
372 * purple_connection_get_account:
373 * @gc: The connection.
375 * Returns the connection's account.
377 * Returns: (transfer none): The connection's account.
379 PurpleAccount *purple_connection_get_account(PurpleConnection *gc);
382 * purple_connection_get_protocol:
383 * @gc: The connection.
385 * Returns the protocol managing a connection.
387 * Returns: (transfer none): The protocol.
389 PurpleProtocol *purple_connection_get_protocol(PurpleConnection *gc);
392 * purple_connection_get_password:
393 * @gc: The connection.
395 * Returns the connection's password.
397 * Returns: The connection's password.
399 const char *purple_connection_get_password(PurpleConnection *gc);
402 * purple_connection_get_active_chats:
403 * @gc: The connection.
405 * Returns a list of active chat conversations on a connection.
407 * Returns: (element-type PurpleChatConversation) (transfer none): The active
408 * chats on the connection.
410 GSList *purple_connection_get_active_chats(PurpleConnection *gc);
413 * purple_connection_get_display_name:
414 * @gc: The connection.
416 * Returns the connection's displayed name.
418 * Returns: The connection's displayed name.
420 const char *purple_connection_get_display_name(PurpleConnection *gc);
423 * purple_connection_get_protocol_data:
424 * @gc: The PurpleConnection.
426 * Gets the protocol data from a connection.
428 * Returns: The protocol data for the connection.
430 void *purple_connection_get_protocol_data(PurpleConnection *gc);
433 * purple_connection_update_progress:
434 * @gc: The connection.
435 * @text: Information on the current step.
436 * @step: The current step.
437 * @count: The total number of steps.
439 * Updates the connection progress.
441 void purple_connection_update_progress(PurpleConnection *gc, const char *text,
442 size_t step, size_t count);
445 * purple_connection_notice:
446 * @gc: The connection.
447 * @text: The notice text.
449 * Displays a connection-specific notice.
451 void purple_connection_notice(PurpleConnection *gc, const char *text);
454 * purple_connection_error:
455 * @gc: the connection which is closing.
456 * @reason: why the connection is closing.
457 * @description: a localized description of the error (not %NULL ).
459 * Closes a connection with an error and a human-readable description of the
460 * error.
462 void
463 purple_connection_error(PurpleConnection *gc,
464 PurpleConnectionError reason,
465 const char *description);
468 * purple_connection_get_error_info:
469 * @gc: The connection.
471 * Returns the #PurpleConnectionErrorInfo instance of a connection if an
472 * error exists.
474 * Returns: The #PurpleConnectionErrorInfo instance of the connection if an
475 * error exists, %NULL otherwise.
477 PurpleConnectionErrorInfo *
478 purple_connection_get_error_info(PurpleConnection *gc);
481 * purple_connection_ssl_error:
483 * Closes a connection due to an SSL error; this is basically a shortcut to
484 * turning the #PurpleSslErrorType into a #PurpleConnectionError and a
485 * human-readable string and then calling purple_connection_error().
487 void
488 purple_connection_ssl_error (PurpleConnection *gc,
489 PurpleSslErrorType ssl_error);
492 * purple_connection_g_error
493 * @gc: Connection the error is associated with
494 * @error: Error information
496 * Closes a connection similar to purple_connection_error(), but
497 * takes a GError which is then converted to purple error codes.
499 * This function ignores G_IO_ERROR_CANCELLED, returning without
500 * closing the connection. This can be used as a shortcut when
501 * cancelling connections, as this is commonly done when shutting
502 * down a connection. If G_IO_ERROR_CANCELLED needs to be caught,
503 * do so with g_error_matches() prior to calling this function.
505 void
506 purple_connection_g_error(PurpleConnection *pc,
507 const GError *error);
510 * purple_connection_take_error
511 * @gc: Connection the error is associated with
512 * @error: (transfer full): Error information
514 * Closes a connection similar to purple_connection_error(), but
515 * takes a GError which is then converted to purple error codes.
517 * This function is equivalent to purple_connection_g_error(),
518 * except that it takes ownership of the GError.
520 void
521 purple_connection_take_error(PurpleConnection *pc,
522 GError *error);
525 * purple_connection_error_is_fatal:
527 * Reports whether a disconnection reason is fatal (in which case the account
528 * should probably not be automatically reconnected) or transient (so
529 * auto-reconnection is a good idea).
530 * For instance, #PURPLE_CONNECTION_ERROR_NETWORK_ERROR is a temporary error,
531 * which might be caused by losing the network connection, so <literal>
532 * purple_connection_error_is_fatal (PURPLE_CONNECTION_ERROR_NETWORK_ERROR)</literal>
533 * is %FALSE. On the other hand,
534 * #PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED probably indicates a
535 * misconfiguration of the account which needs the user to go fix it up, so
536 * <literal> purple_connection_error_is_fatal
537 * (PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED)</literal> is %TRUE.
539 * Returns: %TRUE if the account should not be automatically reconnected, and
540 * %FALSE otherwise.
542 gboolean
543 purple_connection_error_is_fatal (PurpleConnectionError reason);
546 * purple_connection_update_last_received:
547 * @gc: The connection.
549 * Indicate that a packet was received on the connection.
550 * Set by the protocol to avoid sending unneeded keepalives.
552 void purple_connection_update_last_received(PurpleConnection *gc);
554 /**************************************************************************/
555 /* Connections API */
556 /**************************************************************************/
559 * purple_connections_disconnect_all:
561 * Disconnects from all connections.
563 void purple_connections_disconnect_all(void);
566 * purple_connections_get_all:
568 * Returns a list of all active connections. This does not
569 * include connections that are in the process of connecting.
571 * Returns: (element-type PurpleConnection) (transfer none): A list of all
572 * active connections.
574 GList *purple_connections_get_all(void);
577 * purple_connections_get_connecting:
579 * Returns a list of all connections in the process of connecting.
581 * Returns: (element-type PurpleConnection) (transfer none): A list of
582 * connecting connections.
584 GList *purple_connections_get_connecting(void);
586 /**************************************************************************/
587 /* UI Registration Functions */
588 /**************************************************************************/
591 * purple_connection_ui_ops_get_type:
593 * Returns: The #GType for the #PurpleConnectionUiOps boxed structure.
595 GType purple_connection_ui_ops_get_type(void);
598 * purple_connections_set_ui_ops:
599 * @ops: The UI operations structure.
601 * Sets the UI operations structure to be used for connections.
603 void purple_connections_set_ui_ops(PurpleConnectionUiOps *ops);
606 * purple_connections_get_ui_ops:
608 * Returns the UI operations structure used for connections.
610 * Returns: The UI operations structure in use.
612 PurpleConnectionUiOps *purple_connections_get_ui_ops(void);
614 /**************************************************************************/
615 /* Connections Subsystem */
616 /**************************************************************************/
619 * purple_connections_init:
621 * Initializes the connections subsystem.
623 void purple_connections_init(void);
626 * purple_connections_uninit:
628 * Uninitializes the connections subsystem.
630 void purple_connections_uninit(void);
633 * purple_connections_get_handle:
635 * Returns the handle to the connections subsystem.
637 * Returns: The connections subsystem handle.
639 void *purple_connections_get_handle(void);
642 G_END_DECLS
644 #endif /* PURPLE_CONNECTION_H */