]> git.stg.codes - stg.git/blob - stargazer/plugins/capture/cap_nf/cap_nf.h
Public interfaces: part 1
[stg.git] / stargazer / plugins / capture / cap_nf / cap_nf.h
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18 Date: 16.05.2008
19 */
20
21 /*
22 * Author : Maxim Mamontov <faust@stg.dp.ua>
23 */
24
25 /*
26 $Revision: 1.5 $
27 $Date: 2009/12/13 12:56:07 $
28 $Author: faust $
29 */
30 #pragma once
31
32 #include "stg/plugin.h"
33 #include "stg/module_settings.h"
34 #include "stg/logger.h"
35
36 #include <string>
37 #include <cstdint>
38
39 #include <pthread.h>
40 #include <unistd.h> // close
41
42 #define VERSION "cap_nf v. 0.4"
43 #define START_POS 40
44 #define STOP_POS 40
45
46 namespace STG
47 {
48
49 struct Users;
50 struct Tariffs;
51 struct Admins;
52 struct TraffCounter;
53 struct Store;
54 struct Settings;
55
56 }
57
58 class NF_CAP : public STG::Plugin {
59 public:
60     NF_CAP();
61
62     void            SetTraffcounter(STG::TraffCounter * tc) override { traffCnt = tc; }
63     void            SetSettings(const STG::ModuleSettings & s) override { settings = s; }
64     int             ParseSettings() override;
65
66     int             Start() override;
67     int             Stop() override;
68     int             Reload(const STG::ModuleSettings & /*ms*/) override { return 0; }
69
70     bool            IsRunning() override { return runningTCP || runningUDP; }
71     const std::string & GetStrError() const override { return errorStr; }
72     std::string     GetVersion() const override { return VERSION; }
73     uint16_t        GetStartPosition() const override { return START_POS; }
74     uint16_t        GetStopPosition() const override { return STOP_POS; }
75
76 private:
77     NF_CAP(const NF_CAP & rvalue);
78     NF_CAP & operator=(const NF_CAP & rvalue);
79
80     STG::TraffCounter * traffCnt;
81     STG::ModuleSettings settings;
82     pthread_t tidTCP;
83     pthread_t tidUDP;
84     bool runningTCP;
85     bool runningUDP;
86     bool stoppedTCP;
87     bool stoppedUDP;
88     uint16_t portT;
89     uint16_t portU;
90     int sockTCP;
91     int sockUDP;
92     mutable std::string errorStr;
93     STG::PluginLogger logger;
94
95     static void * RunUDP(void *);
96     static void * RunTCP(void *);
97     void ParseBuffer(uint8_t * buf, ssize_t size);
98
99     bool OpenTCP();
100     bool OpenUDP();
101     void CloseTCP() { close(sockTCP); }
102     void CloseUDP() { close(sockUDP); }
103 };