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 
00049 } PurpleConnectionFlags;
00050 
00051 typedef enum
00052 {
00053     PURPLE_DISCONNECTED = 0, 
00054     PURPLE_CONNECTED,        
00055     PURPLE_CONNECTING        
00057 } PurpleConnectionState;
00058 
00064 typedef enum
00065 {
00070     PURPLE_CONNECTION_ERROR_NETWORK_ERROR = 0,
00072     PURPLE_CONNECTION_ERROR_INVALID_USERNAME = 1,
00077     PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED = 2,
00081     PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE = 3,
00085     PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT = 4,
00090     PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR = 5,
00094     PURPLE_CONNECTION_ERROR_NAME_IN_USE = 6,
00095 
00105     PURPLE_CONNECTION_ERROR_INVALID_SETTINGS = 7,
00106 
00108     PURPLE_CONNECTION_ERROR_CERT_NOT_PROVIDED = 8,
00110     PURPLE_CONNECTION_ERROR_CERT_UNTRUSTED = 9,
00112     PURPLE_CONNECTION_ERROR_CERT_EXPIRED = 10,
00114     PURPLE_CONNECTION_ERROR_CERT_NOT_ACTIVATED = 11,
00116     PURPLE_CONNECTION_ERROR_CERT_HOSTNAME_MISMATCH = 12,
00120     PURPLE_CONNECTION_ERROR_CERT_FINGERPRINT_MISMATCH = 13,
00122     PURPLE_CONNECTION_ERROR_CERT_SELF_SIGNED = 14,
00125     PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR = 15,
00126 
00130     /* purple_connection_error_reason() in connection.c uses the fact that
00131      * this is the last member of the enum when sanity-checking; if other
00132      * reasons are added after it, the check must be updated.
00133      */
00134     PURPLE_CONNECTION_ERROR_OTHER_ERROR = 16
00135 } PurpleConnectionError;
00136 
00138 typedef struct
00139 {
00141     PurpleConnectionError type;
00143     char *description;
00144 } PurpleConnectionErrorInfo;
00145 
00146 #include <time.h>
00147 
00148 #include "account.h"
00149 #include "plugin.h"
00150 #include "status.h"
00151 #include "sslconn.h"
00152 
00161 typedef struct
00162 {
00170     void (*connect_progress)(PurpleConnection *gc,
00171                              const char *text,
00172                              size_t step,
00173                              size_t step_count);
00174 
00179     void (*connected)(PurpleConnection *gc);
00180 
00185     void (*disconnected)(PurpleConnection *gc);
00186 
00193     void (*notice)(PurpleConnection *gc, const char *text);
00194 
00203     void (*report_disconnect)(PurpleConnection *gc, const char *text);
00204 
00211     void (*network_connected)(void);
00212 
00217     void (*network_disconnected)(void);
00218 
00233     void (*report_disconnect_reason)(PurpleConnection *gc,
00234                                      PurpleConnectionError reason,
00235                                      const char *text);
00236 
00237     void (*_purple_reserved1)(void);
00238     void (*_purple_reserved2)(void);
00239     void (*_purple_reserved3)(void);
00240 } PurpleConnectionUiOps;
00241 
00242 
00243 /* Represents an active connection on an account. */
00244 struct _PurpleConnection
00245 {
00246     PurplePlugin *prpl;            
00247     PurpleConnectionFlags flags;   
00249     PurpleConnectionState state;   
00251     PurpleAccount *account;        
00252     char *password;              
00253     int inpa;                    
00255     GSList *buddy_chats;         
00258     void *proto_data;            
00260     char *display_name;          
00261     guint keepalive;             
00270     gboolean wants_to_die;
00271 
00272     guint disconnect_timeout;    
00273     time_t last_received;        
00275 };
00276 
00277 #ifdef __cplusplus
00278 extern "C" {
00279 #endif
00280 
00281 /**************************************************************************/
00283 /**************************************************************************/
00286 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
00287 
00306 void purple_connection_new(PurpleAccount *account, gboolean regist,
00307                                     const char *password);
00308 #endif
00309 
00310 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
00311 
00325 void purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data);
00326 #endif
00327 
00328 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
00329 
00340 void purple_connection_destroy(PurpleConnection *gc);
00341 #endif
00342 
00353 void purple_connection_set_state(PurpleConnection *gc, PurpleConnectionState state);
00354 
00361 void purple_connection_set_account(PurpleConnection *gc, PurpleAccount *account);
00362 
00369 void purple_connection_set_display_name(PurpleConnection *gc, const char *name);
00370 
00379 void purple_connection_set_protocol_data(PurpleConnection *connection, void *proto_data);
00380 
00388 PurpleConnectionState purple_connection_get_state(const PurpleConnection *gc);
00389 
00395 #define PURPLE_CONNECTION_IS_CONNECTED(gc) \
00396     (purple_connection_get_state(gc) == PURPLE_CONNECTED)
00397 
00405 PurpleAccount *purple_connection_get_account(const PurpleConnection *gc);
00406 
00416 PurplePlugin * purple_connection_get_prpl(const PurpleConnection *gc);
00417 
00425 const char *purple_connection_get_password(const PurpleConnection *gc);
00426 
00434 const char *purple_connection_get_display_name(const PurpleConnection *gc);
00435 
00445 void *purple_connection_get_protocol_data(const PurpleConnection *connection);
00446 
00455 void purple_connection_update_progress(PurpleConnection *gc, const char *text,
00456                                      size_t step, size_t count);
00457 
00464 void purple_connection_notice(PurpleConnection *gc, const char *text);
00465 
00479 void purple_connection_error(PurpleConnection *gc, const char *reason);
00480 
00493 void
00494 purple_connection_error_reason (PurpleConnection *gc,
00495                                 PurpleConnectionError reason,
00496                                 const char *description);
00497 
00505 void
00506 purple_connection_ssl_error (PurpleConnection *gc,
00507                              PurpleSslErrorType ssl_error);
00508 
00529 gboolean
00530 purple_connection_error_is_fatal (PurpleConnectionError reason);
00531 
00534 /**************************************************************************/
00536 /**************************************************************************/
00542 void purple_connections_disconnect_all(void);
00543 
00550 GList *purple_connections_get_all(void);
00551 
00557 GList *purple_connections_get_connecting(void);
00558 
00567 /*
00568  * TODO: Eventually this bad boy will be removed, because it is
00569  *       a gross fix for a crashy problem.
00570  */
00571 #define PURPLE_CONNECTION_IS_VALID(gc) (g_list_find(purple_connections_get_all(), (gc)) != NULL)
00572 
00575 /**************************************************************************/
00577 /**************************************************************************/
00585 void purple_connections_set_ui_ops(PurpleConnectionUiOps *ops);
00586 
00592 PurpleConnectionUiOps *purple_connections_get_ui_ops(void);
00593 
00596 /**************************************************************************/
00598 /**************************************************************************/
00604 void purple_connections_init(void);
00605 
00609 void purple_connections_uninit(void);
00610 
00616 void *purple_connections_get_handle(void);
00617 
00621 #ifdef __cplusplus
00622 }
00623 #endif
00624 
00625 #endif /* _PURPLE_CONNECTION_H_ */