connection.h

Go to the documentation of this file.
00001 
00007 /* purple
00008  *
00009  * Purple is the legal property of its developers, whose names are too numerous
00010  * to list here.  Please refer to the COPYRIGHT file distributed with this
00011  * source distribution.
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
00026  */
00027 #ifndef _PURPLE_CONNECTION_H_
00028 #define _PURPLE_CONNECTION_H_
00029 
00031 typedef struct _PurpleConnection PurpleConnection;
00032 
00036 typedef enum
00037 {
00038     PURPLE_CONNECTION_HTML       = 0x0001, 
00039     PURPLE_CONNECTION_NO_BGCOLOR = 0x0002, 
00041     PURPLE_CONNECTION_AUTO_RESP  = 0x0004,  
00042     PURPLE_CONNECTION_FORMATTING_WBFO = 0x0008, 
00043     PURPLE_CONNECTION_NO_NEWLINES = 0x0010, 
00044     PURPLE_CONNECTION_NO_FONTSIZE = 0x0020, 
00045     PURPLE_CONNECTION_NO_URLDESC = 0x0040,  
00046     PURPLE_CONNECTION_NO_IMAGES = 0x0080,  
00047     PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY = 0x0100, 
00048     PURPLE_CONNECTION_SUPPORT_MOODS = 0x0200, 
00049     PURPLE_CONNECTION_SUPPORT_MOOD_MESSAGES = 0x0400 
00050 } PurpleConnectionFlags;
00051 
00052 typedef enum
00053 {
00054     PURPLE_DISCONNECTED = 0, 
00055     PURPLE_CONNECTED,        
00056     PURPLE_CONNECTING        
00058 } PurpleConnectionState;
00059 
00065 typedef enum
00066 {
00071     PURPLE_CONNECTION_ERROR_NETWORK_ERROR = 0,
00073     PURPLE_CONNECTION_ERROR_INVALID_USERNAME = 1,
00078     PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED = 2,
00082     PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE = 3,
00086     PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT = 4,
00091     PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR = 5,
00095     PURPLE_CONNECTION_ERROR_NAME_IN_USE = 6,
00096 
00106     PURPLE_CONNECTION_ERROR_INVALID_SETTINGS = 7,
00107 
00109     PURPLE_CONNECTION_ERROR_CERT_NOT_PROVIDED = 8,
00111     PURPLE_CONNECTION_ERROR_CERT_UNTRUSTED = 9,
00113     PURPLE_CONNECTION_ERROR_CERT_EXPIRED = 10,
00115     PURPLE_CONNECTION_ERROR_CERT_NOT_ACTIVATED = 11,
00117     PURPLE_CONNECTION_ERROR_CERT_HOSTNAME_MISMATCH = 12,
00121     PURPLE_CONNECTION_ERROR_CERT_FINGERPRINT_MISMATCH = 13,
00123     PURPLE_CONNECTION_ERROR_CERT_SELF_SIGNED = 14,
00126     PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR = 15,
00127 
00131     /* purple_connection_error_reason() in connection.c uses the fact that
00132      * this is the last member of the enum when sanity-checking; if other
00133      * reasons are added after it, the check must be updated.
00134      */
00135     PURPLE_CONNECTION_ERROR_OTHER_ERROR = 16
00136 } PurpleConnectionError;
00137 
00139 typedef struct
00140 {
00142     PurpleConnectionError type;
00144     char *description;
00145 } PurpleConnectionErrorInfo;
00146 
00147 #include <time.h>
00148 
00149 #include "account.h"
00150 #include "plugin.h"
00151 #include "status.h"
00152 #include "sslconn.h"
00153 
00162 typedef struct
00163 {
00171     void (*connect_progress)(PurpleConnection *gc,
00172                              const char *text,
00173                              size_t step,
00174                              size_t step_count);
00175 
00180     void (*connected)(PurpleConnection *gc);
00181 
00186     void (*disconnected)(PurpleConnection *gc);
00187 
00194     void (*notice)(PurpleConnection *gc, const char *text);
00195 
00204     void (*report_disconnect)(PurpleConnection *gc, const char *text);
00205 
00212     void (*network_connected)(void);
00213 
00218     void (*network_disconnected)(void);
00219 
00234     void (*report_disconnect_reason)(PurpleConnection *gc,
00235                                      PurpleConnectionError reason,
00236                                      const char *text);
00237 
00238     void (*_purple_reserved1)(void);
00239     void (*_purple_reserved2)(void);
00240     void (*_purple_reserved3)(void);
00241 } PurpleConnectionUiOps;
00242 
00243 
00244 /* Represents an active connection on an account. */
00245 struct _PurpleConnection
00246 {
00247     PurplePlugin *prpl;            
00248     PurpleConnectionFlags flags;   
00250     PurpleConnectionState state;   
00252     PurpleAccount *account;        
00253     char *password;              
00254     int inpa;                    
00256     GSList *buddy_chats;         
00259     void *proto_data;            
00261     char *display_name;          
00262     guint keepalive;             
00271     gboolean wants_to_die;
00272 
00273     guint disconnect_timeout;    
00274     time_t last_received;        
00276 };
00277 
00278 #ifdef __cplusplus
00279 extern "C" {
00280 #endif
00281 
00282 /**************************************************************************/
00284 /**************************************************************************/
00287 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
00288 
00307 void purple_connection_new(PurpleAccount *account, gboolean regist,
00308                                     const char *password);
00309 #endif
00310 
00311 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
00312 
00326 void purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data);
00327 #endif
00328 
00329 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
00330 
00341 void purple_connection_destroy(PurpleConnection *gc);
00342 #endif
00343 
00354 void purple_connection_set_state(PurpleConnection *gc, PurpleConnectionState state);
00355 
00362 void purple_connection_set_account(PurpleConnection *gc, PurpleAccount *account);
00363 
00370 void purple_connection_set_display_name(PurpleConnection *gc, const char *name);
00371 
00380 void purple_connection_set_protocol_data(PurpleConnection *connection, void *proto_data);
00381 
00389 PurpleConnectionState purple_connection_get_state(const PurpleConnection *gc);
00390 
00396 #define PURPLE_CONNECTION_IS_CONNECTED(gc) \
00397     (purple_connection_get_state(gc) == PURPLE_CONNECTED)
00398 
00406 PurpleAccount *purple_connection_get_account(const PurpleConnection *gc);
00407 
00417 PurplePlugin * purple_connection_get_prpl(const PurpleConnection *gc);
00418 
00426 const char *purple_connection_get_password(const PurpleConnection *gc);
00427 
00435 const char *purple_connection_get_display_name(const PurpleConnection *gc);
00436 
00446 void *purple_connection_get_protocol_data(const PurpleConnection *connection);
00447 
00456 void purple_connection_update_progress(PurpleConnection *gc, const char *text,
00457                                      size_t step, size_t count);
00458 
00465 void purple_connection_notice(PurpleConnection *gc, const char *text);
00466 
00480 void purple_connection_error(PurpleConnection *gc, const char *reason);
00481 
00494 void
00495 purple_connection_error_reason (PurpleConnection *gc,
00496                                 PurpleConnectionError reason,
00497                                 const char *description);
00498 
00506 void
00507 purple_connection_ssl_error (PurpleConnection *gc,
00508                              PurpleSslErrorType ssl_error);
00509 
00530 gboolean
00531 purple_connection_error_is_fatal (PurpleConnectionError reason);
00532 
00535 /**************************************************************************/
00537 /**************************************************************************/
00543 void purple_connections_disconnect_all(void);
00544 
00551 GList *purple_connections_get_all(void);
00552 
00558 GList *purple_connections_get_connecting(void);
00559 
00568 /*
00569  * TODO: Eventually this bad boy will be removed, because it is
00570  *       a gross fix for a crashy problem.
00571  */
00572 #define PURPLE_CONNECTION_IS_VALID(gc) (g_list_find(purple_connections_get_all(), (gc)) != NULL)
00573 
00576 /**************************************************************************/
00578 /**************************************************************************/
00586 void purple_connections_set_ui_ops(PurpleConnectionUiOps *ops);
00587 
00593 PurpleConnectionUiOps *purple_connections_get_ui_ops(void);
00594 
00597 /**************************************************************************/
00599 /**************************************************************************/
00605 void purple_connections_init(void);
00606 
00610 void purple_connections_uninit(void);
00611 
00617 void *purple_connections_get_handle(void);
00618 
00622 #ifdef __cplusplus
00623 }
00624 #endif
00625 
00626 #endif /* _PURPLE_CONNECTION_H_ */