1 |
// Copyright (C) 2003 Stephane Thiell |
2 |
// |
3 |
// This file is part of pxyscand (from pxys) |
4 |
// |
5 |
// This program is free software; you can redistribute it and/or |
6 |
// modify it under the terms of the GNU General Public License |
7 |
// as published by the Free Software Foundation; either version 2 |
8 |
// of the License, or (at your option) any later version. |
9 |
// |
10 |
// This program is distributed in the hope that it will be useful, |
11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
// GNU General Public License for more details. |
14 |
// |
15 |
// You should have received a copy of the GNU General Public License |
16 |
// along with this program; if not, write to the Free Software |
17 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
// |
19 |
// $Id: PXScanManager.h,v 1.1.1.1 2003/12/30 17:09:01 mbuna Exp $ |
20 |
// |
21 |
#ifndef INCLUDED_PXSCANMANAGER_H_ |
22 |
#define INCLUDED_PXSCANMANAGER_H_ |
23 |
|
24 |
#include <deque> |
25 |
#include <queue> |
26 |
#include <vector> |
27 |
#include <fstream> |
28 |
#include <cstdlib> |
29 |
|
30 |
#include "PXConfig.h" |
31 |
#include "PXMutex.h" |
32 |
#include "PXRepeater.h" |
33 |
|
34 |
#include <peak/peak.h> |
35 |
|
36 |
using std::queue; |
37 |
using std::deque; |
38 |
using std::ofstream; |
39 |
using std::vector; |
40 |
|
41 |
class PXConfig; |
42 |
class PXScan; |
43 |
|
44 |
typedef PXScan * PXScanPtr; |
45 |
|
46 |
struct PXModuleInfo |
47 |
{ |
48 |
PXModuleInfo(const char *inShortName, uint16_t inPort, |
49 |
uint32_t *inConnCountPtr, uint32_t *inProxyCountPtr) |
50 |
{ |
51 |
shortName = peak_strdup(inShortName); |
52 |
port = inPort; |
53 |
connCountPtr = inConnCountPtr; |
54 |
proxyCountPtr = inProxyCountPtr; |
55 |
} |
56 |
~PXModuleInfo() { peak_deallocate(shortName); } |
57 |
|
58 |
char *shortName; |
59 |
uint16_t port; |
60 |
uint32_t *connCountPtr; |
61 |
uint32_t *proxyCountPtr; |
62 |
}; |
63 |
|
64 |
class PXScanManager : public PXRepeater |
65 |
{ |
66 |
public: |
67 |
PXScanManager(PXConfig *inConfig); |
68 |
virtual ~PXScanManager(); |
69 |
|
70 |
void Rehash(); |
71 |
size_t GetModuleInfoCount() const { return mMInfo.size(); } |
72 |
void UseModule(PXModuleInfo *inNewMInfo) { mMInfo.push_back(inNewMInfo); } |
73 |
const PXModuleInfo *GetMInfo(int idx) const { return mMInfo[idx]; } |
74 |
|
75 |
bool AddScan(PXScan *inScan); |
76 |
void ScanCompleted(PXScan *inScan); |
77 |
|
78 |
in_addr GetTargetAddress() const { return mScanTarget.address; } |
79 |
uint16_t GetTargetPort() const { return (uint16_t)mScanTarget.port; } |
80 |
time_t GetLastTargetCheck() const { return mLastTargetCheck; } |
81 |
|
82 |
ofstream& GetFAgent() { return mFAgent; } |
83 |
|
84 |
// Status readers (not sync): |
85 |
|
86 |
// Current number of IPs being scanned. |
87 |
int GetIPScanCount() const { return mIPScanCount; } |
88 |
// Max simultaneous scannable IPs |
89 |
int GetIPScanMax() const { return sNeededFDs ? mRunScanMax/sNeededFDs : 0; } |
90 |
// Current "allocated" socket scans (overestimation). |
91 |
int GetRunScanCount() const { return mRunScanCount; } |
92 |
// Max socket scans (from config) |
93 |
int GetRunScanMax() const { return mRunScanMax; } |
94 |
|
95 |
size_t GetScanQSize() const { return mScanQ.size(); } |
96 |
|
97 |
PXConfig *mConfig; |
98 |
|
99 |
protected: |
100 |
void TargetCheck(); |
101 |
void TargetCheckNext(); |
102 |
void RepeaterFire(); |
103 |
void TCEvent(peak_stream s, int type); |
104 |
|
105 |
static void TCEventCallback(peak_stream s, int type, void *context); |
106 |
|
107 |
ofstream mFAgent; |
108 |
vector<PXConfigScannerTarget> mScanTargets; |
109 |
vector<PXConfigScannerTarget>::const_iterator mScanTargetIterator; |
110 |
PXConfigScannerTarget mScanTarget; |
111 |
time_t mLastTargetCheck; |
112 |
int mIPScanCount, mRunScanMax, mRunScanCount; |
113 |
queue<PXScanPtr> mScanQ; |
114 |
PXMutex mMutex; |
115 |
vector<PXModuleInfo*> mMInfo; |
116 |
static int sNeededFDs; |
117 |
}; |
118 |
|
119 |
#endif // INCLUDED_PXSCANMANAGER_H_ |