source: cheroxy/trunk/src/CRXFilter.cpp@ 42

Last change on this file since 42 was 42, checked in by cheese, 11 years ago

#1 remove debugging code from CRXFilter

File size: 2.8 KB
Line 
1/**
2 * CRXFilter.cpp
3 */
4
5#include "CRXFilter.h"
6
7CRXFilter::CRXFilter (void)
8{
9 /*----------------------------------------------------------------*/
10 /*----------------------------------------------------------------*/
11}
12
13CRXFilter::~CRXFilter (void)
14{
15 /*----------------------------------------------------------------*/
16 /*----------------------------------------------------------------*/
17}
18
19void
20CRXFilter::SetRequestFilter (const E_CRX_FILTER_REQUEST aType,
21 const bool aIsMatched,
22 const std::string aValue)
23{
24 bool aIsExistType = false;
25 S_CRX_FILTER aNewFilter;
26
27 size_t aPrevPosition = 0;
28 size_t aNextPosition = 0;
29 std::string aNewValue;
30
31 CRXFilter_t::iterator aIter = mRequestFilterList.begin ();
32
33 /*----------------------------------------------------------------*/
34 for ( ; aIter != mRequestFilterList.end () ; aIter++)
35 {
36 if (aIter->mFilterType == aType)
37 {
38 aIsExistType = true;
39 break;
40 }
41 }
42
43 if (aIsExistType)
44 {
45 aIter->mIsMatched = aIsMatched;
46
47 /* add only new value */
48 for ( /* NO INIT */ ; aNextPosition != std::string::npos
49 ; aPrevPosition = aNextPosition + 1)
50 {
51 aNextPosition = aValue.find (FILTER_DELIMITER, aPrevPosition);
52 aNewValue = aValue.substr (aPrevPosition, aNextPosition - aPrevPosition);
53 if (aIter->mValue.find (aNewValue) == std::string::npos)
54 aIter->mValue += aNewValue + FILTER_DELIMITER;
55 }
56 }
57 else
58 {
59 aNewFilter.mFilterType = aType;
60 aNewFilter.mIsMatched = aIsMatched;
61 aNewFilter.mValue = aValue;
62
63 mRequestFilterList.push_back (aNewFilter);
64 }
65 /*----------------------------------------------------------------*/
66}
67
68void
69CRXFilter::RemoveRequestFilter (const E_CRX_FILTER_REQUEST aType)
70{
71 CRXFilter_t::iterator aIter = mRequestFilterList.begin ();
72
73 /*----------------------------------------------------------------*/
74 for ( ; aIter != mRequestFilterList.end () ; aIter++)
75 {
76 if (aIter->mFilterType == aType)
77 {
78 mRequestFilterList.erase (aIter);
79 break;
80 }
81 }
82 /*----------------------------------------------------------------*/
83}
84
85bool
86CRXFilter::CheckRequestFilter (const E_CRX_FILTER_REQUEST aType,
87 const CRXHttpRequest & aRequest)
88{
89 size_t aPosition = std::string::npos;
90
91 bool aIsMatched = false;
92 bool aIsFound = false;
93
94 CRXFilter_t::iterator aIter = mRequestFilterList.begin ();
95
96 /*----------------------------------------------------------------*/
97 for ( ; aIter != mRequestFilterList.end () ; aIter++)
98 {
99 if (aIter->mFilterType == aType)
100 {
101 aPosition = aIter->mValue.find (aRequest.GetFileExtension ());
102 aIsMatched = aIter->mIsMatched;
103 break;
104 }
105 }
106 /*----------------------------------------------------------------*/
107
108 aIsFound = aPosition == std::string::npos ? false : true;
109
110 return aIsFound && aIsMatched;
111}
Note: See TracBrowser for help on using the repository browser.