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 
00062 typedef enum
00063 {
00068     PURPLE_CONNECTION_ERROR_NETWORK_ERROR = 0,
00070     PURPLE_CONNECTION_ERROR_INVALID_USERNAME = 1,
00075     PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED = 2,
00079     PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE = 3,
00083     PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT = 4,
00088     PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR = 5,
00092     PURPLE_CONNECTION_ERROR_NAME_IN_USE = 6,
00093 
00103     PURPLE_CONNECTION_ERROR_INVALID_SETTINGS = 7,
00104 
00106     PURPLE_CONNECTION_ERROR_CERT_NOT_PROVIDED = 8,
00108     PURPLE_CONNECTION_ERROR_CERT_UNTRUSTED = 9,
00110     PURPLE_CONNECTION_ERROR_CERT_EXPIRED = 10,
00112     PURPLE_CONNECTION_ERROR_CERT_NOT_ACTIVATED = 11,
00114     PURPLE_CONNECTION_ERROR_CERT_HOSTNAME_MISMATCH = 12,
00118     PURPLE_CONNECTION_ERROR_CERT_FINGERPRINT_MISMATCH = 13,
00120     PURPLE_CONNECTION_ERROR_CERT_SELF_SIGNED = 14,
00123     PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR = 15,
00124 
00128     /* purple_connection_error_reason() in connection.c uses the fact that
00129      * this is the last member of the enum when sanity-checking; if other
00130      * reasons are added after it, the check must be updated.
00131      */
00132     PURPLE_CONNECTION_ERROR_OTHER_ERROR = 16
00133 } PurpleConnectionError;
00134 
00136 typedef struct
00137 {
00139     PurpleConnectionError type;
00141     char *description;
00142 } PurpleConnectionErrorInfo;
00143 
00144 #include <time.h>
00145 
00146 #include "account.h"
00147 #include "plugin.h"
00148 #include "status.h"
00149 #include "sslconn.h"
00150 
00158 typedef struct
00159 {
00166     void (*connect_progress)(PurpleConnection *gc,
00167                              const char *text,
00168                              size_t step,
00169                              size_t step_count);
00170 
00174     void (*connected)(PurpleConnection *gc);
00178     void (*disconnected)(PurpleConnection *gc);
00179 
00185     void (*notice)(PurpleConnection *gc, const char *text);
00186 
00194     void (*report_disconnect)(PurpleConnection *gc, const char *text);
00195 
00201     void (*network_connected)(void);
00205     void (*network_disconnected)(void);
00206 
00218     void (*report_disconnect_reason)(PurpleConnection *gc,
00219                                      PurpleConnectionError reason,
00220                                      const char *text);
00221 
00222     void (*_purple_reserved1)(void);
00223     void (*_purple_reserved2)(void);
00224     void (*_purple_reserved3)(void);
00225 } PurpleConnectionUiOps;
00226 
00227 
00228 /* Represents an active connection on an account. */
00229 struct _PurpleConnection
00230 {
00231     PurplePlugin *prpl;            
00232     PurpleConnectionFlags flags;   
00234     PurpleConnectionState state;   
00236     PurpleAccount *account;        
00237     char *password;              
00238     int inpa;                    
00240     GSList *buddy_chats;         
00243     void *proto_data;            
00245     char *display_name;          
00246     guint keepalive;             
00255     gboolean wants_to_die;
00256 
00257     guint disconnect_timeout;    
00258     time_t last_received;        
00260 };
00261 
00262 #ifdef __cplusplus
00263 extern "C" {
00264 #endif
00265 
00266 /**************************************************************************/
00268 /**************************************************************************/
00271 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
00272 
00291 void purple_connection_new(PurpleAccount *account, gboolean regist,
00292                                     const char *password);
00293 #endif
00294 
00295 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
00296 
00310 void purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data);
00311 #endif
00312 
00313 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_CONNECTION_C_)
00314 
00325 void purple_connection_destroy(PurpleConnection *gc);
00326 #endif
00327 
00338 void purple_connection_set_state(PurpleConnection *gc, PurpleConnectionState state);
00339 
00346 void purple_connection_set_account(PurpleConnection *gc, PurpleAccount *account);
00347 
00354 void purple_connection_set_display_name(PurpleConnection *gc, const char *name);
00355 
00363 PurpleConnectionState purple_connection_get_state(const PurpleConnection *gc);
00364 
00370 #define PURPLE_CONNECTION_IS_CONNECTED(gc) \
00371     (purple_connection_get_state(gc) == PURPLE_CONNECTED)
00372 
00380 PurpleAccount *purple_connection_get_account(const PurpleConnection *gc);
00381 
00390 PurplePlugin * purple_connection_get_prpl(const PurpleConnection *gc);
00391 
00399 const char *purple_connection_get_password(const PurpleConnection *gc);
00400 
00408 const char *purple_connection_get_display_name(const PurpleConnection *gc);
00409 
00418 void purple_connection_update_progress(PurpleConnection *gc, const char *text,
00419                                      size_t step, size_t count);
00420 
00427 void purple_connection_notice(PurpleConnection *gc, const char *text);
00428 
00442 void purple_connection_error(PurpleConnection *gc, const char *reason);
00443 
00455 void
00456 purple_connection_error_reason (PurpleConnection *gc,
00457                                 PurpleConnectionError reason,
00458                                 const char *description);
00459 
00466 void
00467 purple_connection_ssl_error (PurpleConnection *gc,
00468                              PurpleSslErrorType ssl_error);
00469 
00489 gboolean
00490 purple_connection_error_is_fatal (PurpleConnectionError reason);
00491 
00494 /**************************************************************************/
00496 /**************************************************************************/
00502 void purple_connections_disconnect_all(void);
00503 
00510 GList *purple_connections_get_all(void);
00511 
00517 GList *purple_connections_get_connecting(void);
00518 
00524 /*
00525  * TODO: Eventually this bad boy will be removed, because it is
00526  *       a gross fix for a crashy problem.
00527  */
00528 #define PURPLE_CONNECTION_IS_VALID(gc) (g_list_find(purple_connections_get_all(), (gc)) != NULL)
00529 
00532 /**************************************************************************/
00534 /**************************************************************************/
00542 void purple_connections_set_ui_ops(PurpleConnectionUiOps *ops);
00543 
00549 PurpleConnectionUiOps *purple_connections_get_ui_ops(void);
00550 
00553 /**************************************************************************/
00555 /**************************************************************************/
00561 void purple_connections_init(void);
00562 
00566 void purple_connections_uninit(void);
00567 
00573 void *purple_connections_get_handle(void);
00574 
00578 #ifdef __cplusplus
00579 }
00580 #endif
00581 
00582 #endif /* _PURPLE_CONNECTION_H_ */