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

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

#1 fix bug on linux for r28

File size: 2.9 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 aIter->mValue += aValue;
47
48 /* add only new value */
49 for ( /* NO INIT */ ; aNextPosition != std::string::npos
50 ; aPrevPosition = aNextPosition + 1)
51 {
52 aNextPosition = aValue.find (FILTER_DELIMITER, aPrevPosition);
53 aNewValue = aValue.substr (aPrevPosition, aNextPosition - aPrevPosition);
54 if (aIter->mValue.find (aNewValue) == std::string::npos)
55 aIter->mValue += aNewValue + FILTER_DELIMITER;
56 }
57 }
58 else
59 {
60 aNewFilter.mFilterType = aType;
61 aNewFilter.mIsMatched = aIsMatched;
62 aNewFilter.mValue = aValue;
63
64 mRequestFilterList.push_back (aNewFilter);
65 }
66 /*----------------------------------------------------------------*/
67}
68
69void
70CRXFilter::RemoveRequestFilter (const E_CRX_FILTER_REQUEST aType)
71{
72 CRXFilter_t::iterator aIter = mRequestFilterList.begin ();
73
74 /*----------------------------------------------------------------*/
75 for ( ; aIter != mRequestFilterList.end () ; aIter++)
76 {
77 if (aIter->mFilterType == aType)
78 {
79 mRequestFilterList.erase (aIter);
80 break;
81 }
82 }
83 /*----------------------------------------------------------------*/
84}
85
86bool
87CRXFilter::CheckRequestFilter (const E_CRX_FILTER_REQUEST aType,
88 const CRXHttpRequest & aRequest)
89{
90 size_t aPosition = std::string::npos;
91
92 bool aIsMatched = false;
93 bool aIsFound = false;
94
95 CRXFilter_t::iterator aIter = mRequestFilterList.begin ();
96
97 /*----------------------------------------------------------------*/
98 for ( ; aIter != mRequestFilterList.end () ; aIter++)
99 {
100 if (aIter->mFilterType == aType)
101 {
102 aPosition = aIter->mValue.find (aRequest.GetFileExtension ());
103 aIsMatched = aIter->mIsMatched;
104 break;
105 }
106 }
107 /*----------------------------------------------------------------*/
108
109 aIsFound = aPosition == std::string::npos ? false : true;
110
111 return aIsFound && aIsMatched;
112}
Note: See TracBrowser for help on using the repository browser.