Frameworks/libpurple.framework/Versions/0.6.2/Headers/servconn.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 2571 Frameworks/libpurple.framework/Versions/0.6.0/Headers/servconn.h@75fb8ee8f2e6
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
     1 /**
     2  * @file servconn.h Server connection functions
     3  *
     4  * purple
     5  *
     6  * Purple is the legal property of its developers, whose names are too numerous
     7  * to list here.  Please refer to the COPYRIGHT file distributed with this
     8  * source distribution.
     9  *
    10  * This program is free software; you can redistribute it and/or modify
    11  * it under the terms of the GNU General Public License as published by
    12  * the Free Software Foundation; either version 2 of the License, or
    13  * (at your option) any later version.
    14  *
    15  * This program is distributed in the hope that it will be useful,
    16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18  * GNU General Public License for more details.
    19  *
    20  * You should have received a copy of the GNU General Public License
    21  * along with this program; if not, write to the Free Software
    22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
    23  */
    24 #ifndef _MSN_SERVCONN_H_
    25 #define _MSN_SERVCONN_H_
    26 
    27 typedef struct _MsnServConn MsnServConn;
    28 
    29 #include "session.h"
    30 #include "cmdproc.h"
    31 
    32 #include "proxy.h"
    33 #include "httpconn.h"
    34 
    35 /**
    36  * Connection error types.
    37  */
    38 typedef enum
    39 {
    40 	MSN_SERVCONN_ERROR_NONE,
    41 	MSN_SERVCONN_ERROR_CONNECT,
    42 	MSN_SERVCONN_ERROR_WRITE,
    43 	MSN_SERVCONN_ERROR_READ
    44 
    45 } MsnServConnError;
    46 
    47 /**
    48  * Connection types.
    49  */
    50 typedef enum
    51 {
    52 	MSN_SERVCONN_NS,
    53 	MSN_SERVCONN_SB
    54 
    55 } MsnServConnType;
    56 
    57 /**
    58  * A Connection.
    59  */
    60 struct _MsnServConn
    61 {
    62 	MsnServConnType type; /**< The type of this connection. */
    63 	MsnSession *session;  /**< The MSN session of this connection. */
    64 	MsnCmdProc *cmdproc;  /**< The command processor of this connection. */
    65 
    66 	PurpleProxyConnectData *connect_data;
    67 
    68 	gboolean connected;   /**< A flag that states if it's connected. */
    69 	gboolean processing;  /**< A flag that states if something is working
    70 							with this connection. */
    71 	gboolean wasted;      /**< A flag that states if it should be destroyed. */
    72 
    73 	char *host; /**< The host this connection is connected or should be
    74 				  connected to. */
    75 	int num; /**< A number id of this connection. */
    76 
    77 	MsnHttpConn *httpconn; /**< The HTTP connection this connection should use. */
    78 
    79 	int fd; /**< The connection's file descriptor. */
    80 	int inpa; /**< The connection's input handler. */
    81 
    82 	char *rx_buf; /**< The receive buffer. */
    83 	int rx_len; /**< The receive buffer lenght. */
    84 
    85 	size_t payload_len; /**< The length of the payload.
    86 						  It's only set when we've received a command that
    87 						  has a payload. */
    88 
    89 	PurpleCircBuffer *tx_buf;
    90 	guint tx_handler;
    91 	guint timeout_sec;
    92 	guint timeout_handle;
    93 
    94 	void (*connect_cb)(MsnServConn *); /**< The callback to call when connecting. */
    95 	void (*disconnect_cb)(MsnServConn *); /**< The callback to call when disconnecting. */
    96 	void (*destroy_cb)(MsnServConn *); /**< The callback to call when destroying. */
    97 };
    98 
    99 /**
   100  * Creates a new connection object.
   101  *
   102  * @param session The session.
   103  * @param type The type of the connection.
   104  */
   105 MsnServConn *msn_servconn_new(MsnSession *session, MsnServConnType type);
   106 
   107 /**
   108  * Destroys a connection object.
   109  *
   110  * @param servconn The connection.
   111  */
   112 void msn_servconn_destroy(MsnServConn *servconn);
   113 
   114 /**
   115  * Connects to a host.
   116  *
   117  * @param servconn The connection.
   118  * @param host The host.
   119  * @param port The port.
   120  * @param force Force this servconn to connect to a new server.
   121  */
   122 gboolean msn_servconn_connect(MsnServConn *servconn, const char *host, int port,
   123                               gboolean force);
   124 
   125 /**
   126  * Disconnects.
   127  *
   128  * @param servconn The connection.
   129  */
   130 void msn_servconn_disconnect(MsnServConn *servconn);
   131 
   132 /**
   133  * Sets the connect callback.
   134  *
   135  * @param servconn The servconn.
   136  * @param connect_cb The connect callback.
   137  */
   138 void msn_servconn_set_connect_cb(MsnServConn *servconn,
   139 								 void (*connect_cb)(MsnServConn *));
   140 /**
   141  * Sets the disconnect callback.
   142  *
   143  * @param servconn The servconn.
   144  * @param disconnect_cb The disconnect callback.
   145  */
   146 void msn_servconn_set_disconnect_cb(MsnServConn *servconn,
   147 									void (*disconnect_cb)(MsnServConn *));
   148 /**
   149  * Sets the destroy callback.
   150  *
   151  * @param servconn The servconn that's being destroyed.
   152  * @param destroy_cb The destroy callback.
   153  */
   154 void msn_servconn_set_destroy_cb(MsnServConn *servconn,
   155 								 void (*destroy_cb)(MsnServConn *));
   156 
   157 /**
   158  * Writes a chunck of data to the servconn.
   159  *
   160  * @param servconn The servconn.
   161  * @param buf The data to write.
   162  * @param size The size of the data.
   163  */
   164 gssize msn_servconn_write(MsnServConn *servconn, const char *buf,
   165 						  size_t size);
   166 
   167 /**
   168  * Function to call whenever an error related to a switchboard occurs.
   169  *
   170  * @param servconn The servconn.
   171  * @param error The error that happened.
   172  */
   173 void msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error,
   174                             const char *reason);
   175 
   176 /**
   177  * Process the data in servconn->rx_buf.  This is called after reading
   178  * data from the socket.
   179  *
   180  * @param servconn The servconn.
   181  */
   182 void msn_servconn_process_data(MsnServConn *servconn);
   183 
   184 /**
   185  * Set a idle timeout fot this servconn
   186  *
   187  * @param servconn The servconn
   188  * @param seconds The idle timeout in seconds
   189  */
   190 void msn_servconn_set_idle_timeout(MsnServConn *servconn, guint seconds);
   191 
   192 #endif /* _MSN_SERVCONN_H_ */