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