socket.h (2820B)
1 /* 2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client 3 * Copyright (C) 1999-2017 Hiroyuki Yamamoto and the Claws Mail team 4 * 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 3 of the License, or 8 * (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 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef __SOCKET_H__ 20 #define __SOCKET_H__ 21 22 #include <glib.h> 23 #include <netdb.h> 24 25 typedef struct _SockInfo SockInfo; 26 27 #include "ssl.h" 28 29 typedef enum 30 { 31 CONN_READY, 32 CONN_LOOKUPSUCCESS, 33 CONN_ESTABLISHED, 34 CONN_LOOKUPFAILED, 35 CONN_FAILED, 36 CONN_DISCONNECTED 37 } ConnectionState; 38 39 typedef gint (*SockConnectFunc) (SockInfo *sock, 40 gpointer data); 41 typedef gboolean (*SockFunc) (SockInfo *sock, 42 GIOCondition condition, 43 gpointer data); 44 45 struct _SockInfo 46 { 47 gint sock; 48 gnutls_session_t ssl; 49 gnutls_certificate_credentials_t xcred; 50 gnutls_pcert_st client_crt; 51 gnutls_privkey_t client_key; 52 gchar *gnutls_priority; 53 guint g_source; 54 GIOChannel *sock_ch; 55 56 gchar *hostname; 57 gushort port; 58 ConnectionState state; 59 gpointer data; 60 61 SockFunc callback; 62 GIOCondition condition; 63 gchar *canonical_name; 64 65 const void *account; 66 gboolean is_smtp; 67 gboolean ssl_cert_auto_accept; 68 gboolean use_tls_sni; 69 }; 70 71 gint sock_set_io_timeout (guint sec); 72 73 gint sock_set_nonblocking_mode (SockInfo *sock, gboolean nonblock); 74 gboolean sock_is_nonblocking_mode (SockInfo *sock); 75 76 guint sock_add_watch (SockInfo *sock, GIOCondition condition, 77 SockFunc func, gpointer data); 78 79 SockInfo *sock_connect (const gchar *hostname, gushort port); 80 gint sock_connect_async (const gchar *hostname, gushort port, 81 SockConnectFunc func, gpointer data); 82 gint sock_connect_async_cancel (gint id); 83 84 /* Basic I/O functions */ 85 gint sock_read (SockInfo *sock, gchar *buf, gint len); 86 gint sock_write (SockInfo *sock, const gchar *buf, gint len); 87 gint sock_write_all (SockInfo *sock, const gchar *buf, gint len); 88 gint sock_close (SockInfo *sock, gboolean close_fd); 89 90 /* Functions to directly work on FD. They are needed for pipes */ 91 gint fd_connect_unix (const gchar *path); 92 gint fd_open_unix (const gchar *path); 93 gint fd_accept (gint sock); 94 95 gint fd_write (gint sock, const gchar *buf, gint len); 96 gint fd_write_all (gint sock, const gchar *buf, gint len); 97 gint fd_gets (gint sock, gchar *buf, gint len); 98 99 #endif /* __SOCKET_H__ */