1 /* 2 * (C) Copyright 2008-2010 Wojtek Kaniewski <wojtekka@irc.pl> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License Version 6 * 2.1 as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU Lesser General Public License for more details. 12 * 13 * You should have received a copy of the GNU Lesser General Public 14 * License along with this program; if not, write to the Free Software 15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 16 * USA. 17 */ 18 19 #ifndef LIBGADU_SESSION_H 20 #define LIBGADU_SESSION_H 21 22 #ifdef GG_CONFIG_HAVE_GNUTLS 23 # include <gnutls/gnutls.h> 24 #endif 25 26 #define GG_SESSION_CHECK(gs, result) \ 27 do { \ 28 if ((gs) == NULL) { \ 29 errno = EINVAL; \ 30 return (result); \ 31 } \ 32 } while (0) 33 34 #define GG_SESSION_CHECK_CONNECTED(gs, result) \ 35 do { \ 36 GG_SESSION_CHECK(gs, result); \ 37 \ 38 if (!GG_SESSION_IS_CONNECTED(gs)) { \ 39 errno = ENOTCONN; \ 40 return (result); \ 41 } \ 42 } while (0) 43 44 #define GG_SESSION_IS_IDLE(gs) ((gs)->state == GG_STATE_IDLE) 45 #define GG_SESSION_IS_CONNECTING(gs) ((gs)->state != GG_STATE_IDLE && (gs)->state != GG_STATE_CONNECTED) 46 #define GG_SESSION_IS_CONNECTED(gs) ((gs)->state == GG_STATE_CONNECTED) 47 48 #ifdef GG_CONFIG_HAVE_GNUTLS 49 50 typedef struct { 51 int global_init_called; 52 gnutls_session_t session; 53 int session_ready; 54 gnutls_certificate_credentials_t xcred; 55 int xcred_ready; 56 } gg_session_gnutls_t; 57 58 #define GG_SESSION_GNUTLS(gs) ((gg_session_gnutls_t*) (gs)->ssl)->session 59 60 #endif /* GG_CONFIG_HAVE_GNUTLS */ 61 62 #ifdef GG_CONFIG_HAVE_OPENSSL 63 64 #define GG_SESSION_OPENSSL(gs) ((SSL*) (gs)->ssl) 65 66 #endif /* GG_CONFIG_HAVE_OPENSSL */ 67 68 int gg_session_handle_packet(struct gg_session *gs, uint32_t type, const char *ptr, size_t len, struct gg_event *ge); 69 70 #endif /* LIBGADU_SESSION_H */ 71