/[svn]/vendor/pxys2-2.1.0/pxyscand/src/PXScan.h
ViewVC logotype

Contents of /vendor/pxys2-2.1.0/pxyscand/src/PXScan.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3253 - (show annotations)
Wed Apr 2 20:46:18 2014 UTC (6 years, 11 months ago) by michael
File MIME type: text/x-csrc
File size: 3482 byte(s)
- Imported pxys2-2.1.0

1 // Copyright (C) 2003, 2004 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: PXScan.h,v 1.2 2004/01/10 14:32:29 mbuna Exp $
20 //
21 #ifndef INCLUDED_PXSCAN_H_
22 #define INCLUDED_PXSCAN_H_
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31
32 #include <list>
33 #include <vector>
34
35 #include <opas/opas.h>
36 #include <peak/peak.h>
37
38 #include "PXMutex.h"
39
40 using std::list;
41 using std::vector;
42
43 class PXSession;
44 class PXScanManager;
45 class PXScanModule;
46
47 class PXScan
48 {
49 friend class PXScanManager;
50 friend class PXScanModule;
51
52 struct PXScanQuery
53 {
54 opas_msg_query query;
55 PXSession *session;
56 };
57
58 // Internal status
59 enum { PXSCAN_QUEUED=1, PXSCAN_SCANNING, PXSCAN_PROXY_FOUND, PXSCAN_ERROR };
60
61 public:
62 PXScan(const opas_msg_query &inQuery, PXSession *inSession,
63 PXScanManager *inScanManager);
64
65 int GetMaxNeededFDs() const { return mModules.size(); }
66
67 void AppendQuery(const opas_msg_query &inQuery, PXSession *inSession);
68 bool IsSessionReferenced(const PXSession *inSession);
69 void Schedule();
70
71 // Called from the wrapper in PXScanModule
72 void Completed(PXScanModule *inCompletedModule);
73
74 void ProxyFound(uint16_t inTypeOfProxy, uint16_t inPort,
75 const char *inDescr);
76 void Error(int error);
77
78 bool ScanFlagIsSet(int inFlag) { return mScanFlags & inFlag; }
79 void ScanFlagSet(int inFlag) { mScanFlags |= inFlag; }
80 void ScanFlagClear(int inFlag) { mScanFlags &= ~inFlag; }
81 void ScanFlagReset() { mScanFlags = 0; }
82
83 in_addr GetAddress() const { return mScanQueryList.begin()->query.addr; }
84
85 protected:
86 virtual ~PXScan();
87 void InitModules();
88 void RegisterModule(PXScanModule *inScanModule);
89 void SneakModule(const char *inShortName, uint16_t inPort,
90 uint32_t *inConnCountPtr, uint32_t *inProxyCountPtr) const;
91
92 // Real start of the scanning process, called by PXScanManager only.
93 void Start();
94
95 void Launch();
96 void Done();
97 void ProxyNotFound();
98
99 void Lock() { mMutex.Lock(); }
100 void Unlock() { mMutex.Unlock(); }
101
102 void TimerStop();
103 static void TimerCallback(peak_timer ti, void *context);
104
105 list<PXScanQuery> mScanQueryList;
106 PXScanManager *mScanManager;
107 int mStatus;
108 int mScanFlags; // custom flags, reserved for the scan modules
109
110 peak_timer mScanTimer;
111
112 // Modules
113 vector<PXScanModule*> mModules;
114 vector<PXScanModule*>::const_iterator mModuleIterator;
115 // Number of modules completed, for terminaison detection
116 int mCompletedCount;
117 int mCompletedMax;
118 int mLaunched;
119
120 // Mutex to control concurrent access on this class members
121 PXMutex mMutex;
122
123 static bool sInitialized;
124 };
125
126 #endif // INCLUDED_PXSCAN_H_

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28