Source

quechua / modules / channel / dionaeaHarvester / dionaeaHarvester.h

Full commit
/* 
 * Quechua - the lightweight data mining framework
 *
 * Copyright (C) 2012 Marek Denis <quechua@octogan.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef DNCHAN_H
#define DNCHAN_H

#include "ev++.h"

#include "../../../include/types.h"
#include "../../../include/interface-channel.h"
#include "../../../include/python-interface.h"
#include "../../data/dionaeaconnections.h"
#include "selects.h"

bool exec_query(dbwork_t& w,dbresult_t& r, const char* q,bool commit = false);


class  DionaeaHarvester : public Channel {
    
    struct credentials_s {
        string_t user;
        string_t password;
        string_t hostname;
        string_t database;
    };
    
    struct times_s {
        string_t interval;
        string_t from;
        string_t to;
    };

    enum FETCH {DEFAULT,ALL,RANGE,INTERVAL};

 public:
        DionaeaHarvester();
        virtual ~DionaeaHarvester();

        bool start();
        bool prepare();
        bool stop();

        bool notify();
        bool load_misc_conf(const setting_t& misc);
 protected:
        inline bool check_connection(const dbconnection_t* c);
        inline bool check_and_complain_connection(const dbconnection_t* c);

        bool connect();
        bool disconnect();
 private:
        int interval;
        times_s range;
        const char* select_query;
        FETCH fetch;

        static const int QUERY_LIMIT = 2048;
        char formated_query[QUERY_LIMIT];

        credentials_s credentials;
        dbconnection_t* connection;

        void fetch_data();

        void update_select_query();

        void prepare_select_query(const setting_t& misc);
        void setup_select_query_interval(const setting_t& misc);
        void setup_select_query_range(const setting_t& misc);
        void setup_select_query_all();
        void setup_default_query();
        bool from_to_zeroed(const setting_t& misc);
};

extern "C" Channel* create_channel();

#endif // DNCHAN_H