| 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 gnutls_session_t session; |
|
| 52 gnutls_certificate_credentials_t xcred; |
|
| 53 } gg_session_gnutls_t; |
|
| 54 |
|
| 55 #define GG_SESSION_GNUTLS(gs) ((gg_session_gnutls_t*) (gs)->ssl)->session |
|
| 56 |
|
| 57 #endif /* GG_CONFIG_HAVE_GNUTLS */ |
|
| 58 |
|
| 59 #ifdef GG_CONFIG_HAVE_OPENSSL |
|
| 60 |
|
| 61 #define GG_SESSION_OPENSSL(gs) ((SSL*) (gs)->ssl) |
|
| 62 |
|
| 63 #endif /* GG_CONFIG_HAVE_OPENSSL */ |
|
| 64 |
|
| 65 int gg_session_handle_packet(struct gg_session *gs, uint32_t type, const char *ptr, size_t len, struct gg_event *ge); |
|
| 66 |
|
| 67 #endif /* LIBGADU_SESSION_H */ |
|