| 1 |
/* |
| 2 |
* Copyright (c) 2014 Alexander Golovko <[email protected]> |
| 3 |
* All rights reserved. |
| 4 |
* Portions (c) 2015 Matthias Bethke <[email protected]> |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions are met: |
| 8 |
* |
| 9 |
* 1. Redistributions of source code must retain the above copyright notice, |
| 10 |
* this list of conditions and the following disclaimer. |
| 11 |
* |
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 |
* this list of conditions and the following disclaimer in the documentation |
| 14 |
* and/or other materials provided with the distribution. |
| 15 |
* |
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 20 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 |
* POSSIBILITY OF SUCH DAMAGE. |
| 27 |
*/ |
| 28 |
|
| 29 |
#ifndef __NSCANG_CLIENT_H |
| 30 |
#define __NSCANG_CLIENT_H |
| 31 |
|
| 32 |
#include <openssl/ssl.h> |
| 33 |
#include <openssl/err.h> |
| 34 |
|
| 35 |
#include "uthash.h" |
| 36 |
|
| 37 |
typedef enum { NSCANG_STATE_NONE=0, NSCANG_STATE_NEW, NSCANG_STATE_MOIN } nscang_state_t; |
| 38 |
typedef enum { NSCANG_RESP_MOIN=1, NSCANG_RESP_OKAY } nscang_response_t; |
| 39 |
typedef enum { |
| 40 |
NSCANG_ERROR_MALLOC=1, |
| 41 |
NSCANG_ERROR_TIMEOUT, |
| 42 |
NSCANG_ERROR_TOO_LONG_RESPONSE, |
| 43 |
NSCANG_ERROR_BAD_PROTO_VERSION, |
| 44 |
NSCANG_ERROR_PROTOCOL_MISMATCH, |
| 45 |
NSCANG_ERROR_UNKNOWN_RESPONSE, |
| 46 |
NSCANG_ERROR_BAIL, |
| 47 |
NSCANG_ERROR_FAIL, |
| 48 |
NSCANG_ERROR_BAD_STATE, |
| 49 |
NSCANG_ERROR_SSL_CTX_CREATE=101, |
| 50 |
NSCANG_ERROR_SSL_CIPHERS, |
| 51 |
NSCANG_ERROR_SSL_BIO_CREATE, |
| 52 |
NSCANG_ERROR_SSL_CREATE, |
| 53 |
NSCANG_ERROR_SSL |
| 54 |
} nscang_error_t; |
| 55 |
|
| 56 |
typedef struct { |
| 57 |
SSL_CTX *ssl_ctx; |
| 58 |
BIO *bio; |
| 59 |
SSL *ssl; |
| 60 |
nscang_state_t state; |
| 61 |
|
| 62 |
char *identity; |
| 63 |
char *psk; |
| 64 |
|
| 65 |
nscang_error_t _errno; |
| 66 |
char errstr[1024]; |
| 67 |
|
| 68 |
UT_hash_handle hh; |
| 69 |
} nscang_client_t; |
| 70 |
|
| 71 |
int nscang_client_init(nscang_client_t *c, char *host, int port, |
| 72 |
char *ciphers, char *identity, char *psk); |
| 73 |
void nscang_client_free(nscang_client_t *c); |
| 74 |
void nscang_client_disconnect(nscang_client_t *c); |
| 75 |
int nscang_client_send_moin(nscang_client_t *c, int timeout); |
| 76 |
int nscang_client_send_command(nscang_client_t *c, const char *command, int timeout); |
| 77 |
int nscang_client_send_push(nscang_client_t *c, char *host, char *service, |
| 78 |
int status, char *message, int timeout); |
| 79 |
int nscang_client_send_quit(nscang_client_t *c); |
| 80 |
char *nscang_client_errstr(nscang_client_t *c, char *buf, int buf_size); |
| 81 |
|
| 82 |
#endif /* __NSCANG_CLIENT_H */ |