initial message templates support
[claws.git] / src / socket.h
blobac06ef74b10753bbbf9905cafbc514988f4d0ea6
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef __SOCKET_H__
21 #define __SOCKET_H__
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <glib.h>
28 #include <gdk/gdk.h> /* ugly, just needed for the GdkInputCondition et al. */
30 #if USE_THREADS
31 # include <pthread.h>
32 #endif
34 typedef struct _SockInfo SockInfo;
36 #if USE_SSL
37 # include "ssl.h"
38 #endif
40 typedef enum
42 CONN_READY,
43 CONN_LOOKUPSUCCESS,
44 CONN_ESTABLISHED,
45 CONN_LOOKUPFAILED,
46 CONN_FAILED
47 } ConnectionState;
49 struct _SockInfo
51 #if USE_GIO
52 GIOChannel *channel;
53 gchar *buf;
54 gint buflen;
55 #else
56 gint sock;
57 #endif
58 gchar *hostname;
59 gushort port;
60 ConnectionState state;
61 gpointer data;
62 #if USE_THREADS
63 pthread_t connect_thr;
64 pthread_mutex_t mutex;
65 #endif
66 #if USE_SSL
67 SSL *ssl;
68 #endif
71 gint sock_set_nonblocking_mode (SockInfo *sock, gboolean nonblock);
72 gboolean sock_is_nonblocking_mode (SockInfo *sock);
74 SockInfo *sock_connect_nb (const gchar *hostname, gushort port);
75 SockInfo *sock_connect (const gchar *hostname, gushort port);
78 #if USE_THREADS
79 SockInfo *sock_connect_with_thread (const gchar *hostname, gushort port);
80 #endif
82 gint sock_printf (SockInfo *sock, const gchar *format, ...)
83 G_GNUC_PRINTF(2, 3);
84 gint sock_read (SockInfo *sock, gchar *buf, gint len);
85 gint sock_write (SockInfo *sock, const gchar *buf, gint len);
86 gint sock_gets (SockInfo *sock, gchar *buf, gint len);
87 gchar *sock_getline (SockInfo *sock);
88 gint sock_puts (SockInfo *sock, const gchar *buf);
89 gint sock_close (SockInfo *sock);
91 /* wrapper functions */
92 gint sock_gdk_input_add (SockInfo *sock,
93 GdkInputCondition condition,
94 GdkInputFunction function,
95 gpointer data);
98 /* Functions to directly work on FD. They are needed for pipes */
99 gint fd_connect_unix (const gchar *path);
100 gint fd_open_unix (const gchar *path);
101 gint fd_accept (gint sock);
103 gint fd_read (gint sock, gchar *buf, gint len);
104 gint fd_write (gint sock, const gchar *buf, gint len);
105 gint fd_gets (gint sock, gchar *buf, gint len);
106 gchar *fd_getline (gint sock);
107 gint fd_close (gint sock);
109 #endif /* __SOCKET_H__ */