loudmouth/inc/loudmouth/lm-connection.h
changeset 10 59927b2d3b75
parent 0 d0f3a028347a
equal deleted inserted replaced
0:d0f3a028347a 10:59927b2d3b75
     1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
       
     2 /*
       
     3  * Copyright (C) 2003 Imendio AB
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU Lesser General Public License as
       
     7  * published by the Free Software Foundation; either version 2 of the
       
     8  * License, or (at your option) any later version.
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13  * Lesser General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU Lesser General Public
       
    16  * License along with this program; if not, write to the
       
    17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    18  * Boston, MA 02111-1307, USA.
       
    19  */
       
    20 
       
    21 #ifndef __LM_CONNECTION_H__
       
    22 #define __LM_CONNECTION_H__
       
    23 
       
    24 #if !defined (LM_INSIDE_LOUDMOUTH_H) && !defined (LM_COMPILATION)
       
    25 #error "Only <loudmouth/loudmouth.h> can be included directly, this file may disappear or change contents."
       
    26 #endif
       
    27 
       
    28 #include "loudmouth/lm-message.h"
       
    29 #include "loudmouth/lm-proxy.h"
       
    30 #include "loudmouth/lm-ssl.h"
       
    31 
       
    32 G_BEGIN_DECLS
       
    33 
       
    34 #define LM_CONNECTION(o) (LmConnection *) o;
       
    35 
       
    36 #define LM_CONNECTION_DEFAULT_PORT     5222
       
    37 #define LM_CONNECTION_DEFAULT_PORT_SSL 5223
       
    38 
       
    39 typedef struct _LmConnection LmConnection;
       
    40 
       
    41 typedef struct LmMessageHandler LmMessageHandler;
       
    42 
       
    43 typedef enum {
       
    44 	LM_HANDLER_RESULT_REMOVE_MESSAGE,
       
    45 	LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS
       
    46 } LmHandlerResult;
       
    47  
       
    48 typedef enum {
       
    49 	LM_HANDLER_PRIORITY_LAST   = 1,
       
    50 	LM_HANDLER_PRIORITY_NORMAL = 2,
       
    51 	LM_HANDLER_PRIORITY_FIRST  = 3
       
    52 } LmHandlerPriority;
       
    53 
       
    54 typedef enum {
       
    55 	LM_DISCONNECT_REASON_OK,
       
    56 	LM_DISCONNECT_REASON_PING_TIME_OUT,
       
    57 	LM_DISCONNECT_REASON_HUP,
       
    58 	LM_DISCONNECT_REASON_ERROR,
       
    59 	LM_DISCONNECT_REASON_RESOURCE_CONFLICT,
       
    60 	LM_DISCONNECT_REASON_INVALID_XML,
       
    61 	LM_DISCONNECT_REASON_UNKNOWN
       
    62 } LmDisconnectReason;
       
    63 
       
    64 typedef enum {
       
    65 	LM_CONNECTION_STATE_CLOSED,
       
    66 	LM_CONNECTION_STATE_OPENING,
       
    67 	LM_CONNECTION_STATE_OPEN,
       
    68 	LM_CONNECTION_STATE_AUTHENTICATING,
       
    69 	LM_CONNECTION_STATE_AUTHENTICATED
       
    70 } LmConnectionState;
       
    71 
       
    72 typedef void          (* LmResultFunction)     (LmConnection       *connection,
       
    73 						gboolean            success,
       
    74 						gpointer            user_data);
       
    75 
       
    76 typedef void          (* LmDisconnectFunction) (LmConnection       *connection,
       
    77 						LmDisconnectReason  reason,
       
    78 						gpointer            user_data);
       
    79 
       
    80 IMPORT_C LmConnection *lm_connection_new               (const gchar        *server);
       
    81 IMPORT_C LmConnection *lm_connection_new_with_context  (const gchar        *server,
       
    82 					       GMainContext       *context);
       
    83 IMPORT_C gboolean      lm_connection_open              (LmConnection       *connection,
       
    84 					       LmResultFunction    function,
       
    85 					       gpointer            user_data,
       
    86 					       GDestroyNotify      notify,
       
    87 					       GError            **error);
       
    88 
       
    89 IMPORT_C gboolean      lm_connection_open_and_block    (LmConnection       *connection,
       
    90 					       GError            **error);
       
    91 
       
    92 IMPORT_C void          lm_connection_cancel_open       (LmConnection      *connection);
       
    93 IMPORT_C gboolean      lm_connection_close             (LmConnection       *connection,
       
    94 					       GError            **error);
       
    95 IMPORT_C gboolean      lm_connection_authenticate      (LmConnection       *connection,
       
    96 					       const gchar        *username,
       
    97 					       const gchar        *password,
       
    98 					       const gchar        *resource,
       
    99 					       LmResultFunction    function,
       
   100 					       gpointer            user_data,
       
   101 					       GDestroyNotify      notify,
       
   102 					       GError            **error);
       
   103 IMPORT_C gboolean
       
   104 lm_connection_authenticate_and_block          (LmConnection       *connection,
       
   105 					       const gchar        *username,
       
   106 					       const gchar        *password,
       
   107 					       const gchar        *resource,
       
   108 					       GError            **error);
       
   109 IMPORT_C guint         lm_connection_get_keep_alive_rate (LmConnection     *connection);
       
   110 IMPORT_C void        lm_connection_set_keep_alive_rate (LmConnection       *connection,
       
   111 					       guint               rate);
       
   112 
       
   113 IMPORT_C gboolean    lm_connection_is_open           (LmConnection       *connection);
       
   114 IMPORT_C gboolean    lm_connection_is_authenticated  (LmConnection       *connection);
       
   115 
       
   116 IMPORT_C const gchar * lm_connection_get_server        (LmConnection       *connection);
       
   117 IMPORT_C void          lm_connection_set_server        (LmConnection       *connection,
       
   118 					       const gchar        *server);
       
   119 IMPORT_C void          lm_connection_set_jid           (LmConnection       *connection,
       
   120 					       const gchar        *jid);
       
   121 IMPORT_C const gchar * lm_connection_get_jid           (LmConnection       *connection);
       
   122 IMPORT_C gchar *       lm_connection_get_full_jid      (LmConnection       *connection);
       
   123 
       
   124 IMPORT_C guint         lm_connection_get_port          (LmConnection       *connection);
       
   125 IMPORT_C void          lm_connection_set_port          (LmConnection       *connection,
       
   126 					       guint               port);
       
   127 
       
   128 IMPORT_C LmSSL *       lm_connection_get_ssl           (LmConnection       *connection);
       
   129 IMPORT_C void          lm_connection_set_ssl           (LmConnection       *connection,
       
   130 					       LmSSL              *ssl);
       
   131 IMPORT_C LmProxy *     lm_connection_get_proxy         (LmConnection       *connection);
       
   132 IMPORT_C void          lm_connection_set_proxy         (LmConnection       *connection,
       
   133 					       LmProxy            *proxy);
       
   134 IMPORT_C gboolean      lm_connection_send              (LmConnection       *connection,
       
   135 					       LmMessage          *message,
       
   136 					       GError            **error);
       
   137 IMPORT_C gboolean      lm_connection_send_with_reply   (LmConnection       *connection,
       
   138 					       LmMessage          *message,
       
   139 					       LmMessageHandler   *handler,
       
   140 					       GError            **error);
       
   141 IMPORT_C LmMessage *   
       
   142 lm_connection_send_with_reply_and_block       (LmConnection       *connection,
       
   143 					       LmMessage          *message,
       
   144 					       GError            **error);
       
   145 IMPORT_C void
       
   146 lm_connection_register_message_handler        (LmConnection       *connection,
       
   147 					       LmMessageHandler   *handler,
       
   148 					       LmMessageType       type,
       
   149 					       LmHandlerPriority   priority);
       
   150 IMPORT_C void
       
   151 lm_connection_unregister_message_handler      (LmConnection       *connection,
       
   152 					       LmMessageHandler   *handler,
       
   153 					       LmMessageType       type);
       
   154 IMPORT_C void 
       
   155 lm_connection_set_disconnect_function         (LmConnection       *connection,
       
   156 					       LmDisconnectFunction function,
       
   157 					       gpointer             user_data,
       
   158 					       GDestroyNotify       notify);
       
   159 					       
       
   160 IMPORT_C gboolean      lm_connection_send_raw          (LmConnection       *connection,
       
   161 					       const gchar        *str,
       
   162 					       GError            **error);
       
   163 IMPORT_C LmConnectionState lm_connection_get_state     (LmConnection       *connection);
       
   164 IMPORT_C gchar *       lm_connection_get_local_host    (LmConnection       *connection);
       
   165 IMPORT_C LmConnection* lm_connection_ref               (LmConnection       *connection);
       
   166 IMPORT_C void          lm_connection_unref             (LmConnection       *connection);
       
   167 
       
   168 gboolean
       
   169 _lm_connection_old_auth (LmConnection *connection, const gchar *username,
       
   170 			 const gchar *password, const gchar *resource,
       
   171 			 GError **errror);
       
   172 
       
   173 G_END_DECLS
       
   174 
       
   175 #endif /* __LM_CONNECTION_H__ */