C/C++ API: header file libipsng.h



    // ipset-ng client library: lightweight apache,nginx,MTA,php,perl,etc IPSet access server
    // - very simple API to use
    // - use JSON protocol
    // by @IpsNg
    //   

    #ifndef IPSET_NG_LIBIPSNG_H
    #define IPSET_NG_LIBIPSNG_H

    #if !defined(IPSET_NG_OPENSSL)
        typedef char SSL;
        typedef char SSL_CTX;
    #else
        #include <openssl/ssl.h>
    #endif

    #include <netinet/in.h>

    enum tbltype {
        TBL_LST_BLACK       = 1,
        TBL_LST_WHITE       = 2,
        TBL_LST_ADD         = 3,
        TBL_LST_DEL         = 4,
        TBL_LST_TABLE       = 5,
        TBL_LST_ERROR       = -1
    };
    enum ipsetype {
        IPSET_CMD_CREATE    = 2,
        IPSET_CMD_DESTROY   = 3,
        IPSET_CMD_FLUSH     = 4,
        IPSET_CMD_ADD       = 9,
        IPSET_CMD_DEL       = 10,
        IPSET_CMD_TEST      = 11,
        IPSET_OPT_TIMEOUT   = 10,
        IPSET_OPT_FAMILY    = 3,
        IPSET_OPT_HASHSIZE  = 12,
        IPSET_OPT_MAXELEM   = 13
    };
    enum netftype {
        NFPROTO_IPV4        = 2,
        NFPROTO_IPV6        = 10,
        NFPROTO_HEX     = 33
    };
    enum cmdtype {
        SEND_IN_BLOCK       = 404,
        SEND_NO_BLOCK       = 200,
        SEND_ERROR      = 500,
        SEND_INCOR      = 403,
        SEND_FATAL      = -1
    };

    typedef struct {
        unsigned char state[4][4];
        int kcol;
        unsigned long rounds;
        unsigned long keysched[0];
    } AESCRYPT_t;

    typedef struct _ipsngssl {
        int port;
        int sessid;
        int crl_check_sec;
        long int crl_check_time;
        long scache;
        bool is_ssl_secure;
        bool is_ssl_cache;
        bool is_ssl_chkhost;
        bool is_ssl_crl;
        bool is_show_cert;
        bool is_show_stat;
        bool is_show_info;
        char *sni;
        char *host;
        char *certs[4];
        char *cipher;
        SSL_CTX *ctx;
        struct sockaddr_in addr;
    } IPSNGSSL_t;

    typedef struct _ipsngnet {
        int port;
        char *host;
        bool is_crypt;
        AESCRYPT_t *aes;
        struct sockaddr_in addr;
    } IPSNGNET_t;

    #define ipsng_net_send(ngnet,cmd,type,ipv,dnsbl,ip,net,tbl) \
                ipsng_send(NULL,ngnet,cmd,type,ipv,dnsbl,ip,net,tbl)
    #define ipsng_ssl_send(ngssl,cmd,type,ipv,dnsbl,ip,net,tbl) \
                ipsng_send(ngssl,NULL,cmd,type,ipv,dnsbl,ip,net,tbl)

    #define ipsng_set_check(tbl) \
                ipsng_set_packet(IPSET_CMD_TEST,TBL_LST_BLACK,NFPROTO_IPV4,1,0,tbl)
    #define ipsng_set_add(tbl) \
                ipsng_set_packet(IPSET_CMD_ADD,TBL_LST_ADD,NFPROTO_IPV4,0,0,tbl)
    #define ipsng_set_del(tbl) \
                ipsng_set_packet(IPSET_CMD_DEL,TBL_LST_DEL,NFPROTO_IPV4,0,0,tbl)

    #define ipsng_net_chkip(ngnet,ip,tbl) \
                ipsng_send(NULL,ngnet,IPSET_CMD_TEST,TBL_LST_BLACK,0,0,0,ip,NULL,tbl)
    #define ipsng_ssl_chkip(ngssl,ip,tbl) \
                ipsng_send(ngssl,NULL,IPSET_CMD_TEST,TBL_LST_BLACK,0,0,0,ip,NULL,tbl)

    #define ipsng_net_ip_preset(ngnet,ip) \
                ipsng_send(NULL,ngnet,0,0,0,0,0,ip,NULL,NULL)
    #define ipsng_ssl_ip_preset(ngssl,ip) \
                ipsng_send(ngssl,NULL,0,0,0,0,0,ip,NULL,NULL)

    #define ipsng_net_addnet(ngnet,net,tbl) \
                ipsng_send(NULL,ngnet,IPSET_CMD_ADD,TBL_LST_ADD,0,0,0,NULL,net,tbl)
    #define ipsng_ssl_addnet(ngssl,net,tbl) \
                ipsng_send(ngssl,NULL,IPSET_CMD_ADD,TBL_LST_ADD,0,0,0,NULL,net,tbl)

    IPSNGNET_t *ipsng_net_init(
        int,            //  UDP server port
        const char *,       //  UDP server host
        const char *        //  password - crypt AES connection
        );
    IPSNGSSL_t *ipsng_ssl_init(
        int,            //  SSL server port
        int,            //  SSL cache: num session, 0 disable
        const char *,       //  SSL server host
        const char *,       //  SSL client certificate + ca + key
        const char *,       //  SSL cipher string
        const char *,       //  check SSL SNI - server host name
        bool,           //  use SSL secure protocol
        bool,           //  show SSL info
        bool,           //  show SSL session statistic
        bool            //  print other message
        );
    int ipsng_send(
        IPSNGSSL_t *,       //  ngssl structure
        IPSNGNET_t *,       //  ngnet structure
        int,            //  ipset cmd, see ENUM ipsetype
        int,            //  table type, see ENUM tbltype
        int,            //  ipv protocol, see ENUM netftype
        int,            //  enable/disable check in dnsbl, 0/1
        int,            //  timeouts IP address (live time) if add ip to ipset tables
        const char *,       //  single ip address 1.2.3.4
        const char *,       //  net ip addresses 1.2.3.0/24
        const char *        //  ipset table name
        );
    void ipsng_set_packet(
        int,            //  ipset cmd, see ENUM ipsetype
        int,            //  table type, see ENUM tbltype
        int,            //  ipv protocol, see ENUM netftype
        int,            //  enable/disable check in dnsbl, 0/1
        int,            //  timeouts IP address (live time) if add ip to ipset tables
        const char *        //  ipset table name
        );
    void ipsng_net_close(IPSNGNET_t *);
    void ipsng_ssl_close(IPSNGSSL_t *);

    #endif



  Meta Tags: Header file libipsng.h C/C++ API