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

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

#1 fix bug on filter string bug

File size: 2.9 KB
Line 
1/**
2 * CRXFilter.cpp
3 */
4
5#include "CRXFilter.h"
6
7#include <stdio.h>
8
9CRXFilter::CRXFilter (void)
10{
11 /*----------------------------------------------------------------*/
12 /*----------------------------------------------------------------*/
13}
14
15CRXFilter::~CRXFilter (void)
16{
17 /*----------------------------------------------------------------*/
18 /*----------------------------------------------------------------*/
19}
20
21void
22CRXFilter::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
72void
73CRXFilter::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
89bool
90CRXFilter::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}
Note: See TracBrowser for help on using the repository browser.