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