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