C++ IP API  9.5.8
TCP & UDP for virtual user scripts
Extractor.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2024 Eggplant Ltd
3 // All Rights Reserved
4 
5 #pragma once
6 #pragma warning (disable : 4251)
7 #pragma warning (disable : 4635)
8 
9 #include <string>
10 #include <vector>
11 using namespace std;
12 
13 #include "fc.h"
14 #include "Action.h"
15 #include "ExtractionCursor.h"
16 #include "RegExpMatch.h"
17 #include "CharacterEncoding.h"
18 #include "VirtualUserInterface.h"
19 
20 using namespace Facilita;
21 
22 namespace Facilita {
23 
27  class FC_API Extractor: public CharacterEncoding
28  {
29  public:
30  Extractor();
31  Extractor(const string& data);
32  Extractor(const string& path, int dummy);
33  Extractor(const Extractor& other);
34  virtual ~Extractor();
35  Extractor& operator=( const Extractor& other);
36  Extractor& operator=( const string& data);
46  bool find(ExtractionCursor &cursor, const string& text, bool caseSensitive = true);
56  bool rfind(ExtractionCursor &cursor, const string& text, bool caseSensitive = true);
68  string extract(ExtractionCursor &cursor, const string& before, const string& after, const string& defaultValue, bool caseSensitive = true);
69 
70  string extractFromEnd(ExtractionCursor &cursor, const string& after, const string& before, const string& defaultValue, bool caseSensitive = true);
71 
83  string extract(ExtractionCursor &cursor, const StringVector& before, const string& after, const string& defaultValue, bool caseSensitive = true);
84 
85  string extractFromEnd(ExtractionCursor &cursor, const StringVector& after, const string& before, const string& defaultValue, bool caseSensitive = true);
86 
87 
98  string extract(ExtractionCursor &cursor, const StringVector& before, const string& after, bool caseSensitive = true);
99 
100 
101  string extractFromEnd(ExtractionCursor &cursor, const StringVector& after, const string& before, bool caseSensitive = true);
102 
103 
114  string extract(ExtractionCursor &cursor, const string& before, const string& after, bool caseSensitive = true);
115 
116  string extractFromEnd(ExtractionCursor &cursor, const string& after, const string& before, bool caseSensitive = true);
117 
128  RegExpMatchList extractRegExp(ExtractionCursor &cursor, const string& regExp, bool caseSensitive = true);
129 
130  string extractRegExp(ExtractionCursor &cursor, const string& beforeRegExp, const string& afterRegExp, bool caseSensitive = true);
131  string extractRegExpFromEnd(ExtractionCursor &cursor, const string& afterRegExp, const string& beforeRegExp, bool caseSensitive = true);
132 
139  bool verifyContains(const string &text, bool caseSensitive = true); // check if content contains the pattern
140 
141  virtual StringVector extractList(const string& before, const string& after, bool caseSensitive = true, int maxItems = -1);
142  virtual StringVector extractList(ExtractionCursor &cursor, const string& before, const string& after, const string& endAt = "", bool caseSensitive = true, int maxItems = -1);
143 
147  const string path() const { return _path;}
151  const string& data() const { return _data;}
152 
154 #ifndef SWIG
155  int getCurrentPosition() const { return _currentPosition;}
156  int& getCurrentPositionRef(){ return _currentPosition;}
157  void setCurrentPosition(int position) {_currentPosition = position;}
158  void incrementCurrentPosition(int inc=1) {_currentPosition += inc;}
159 
160  void rewind() {_currentPosition = _rewindPosition;}
161  void advanceRewind() {_rewindPosition = _currentPosition;}
162  void setEndSearch() {_endSearchPosition = _currentPosition;}
163 
164  string stringAtCurrentPosition(int len) const;
165  const char* getContentPtr(void) { return _data.data();}
166  int findString(int startPos, const string& str, bool caseSensitive = true);
167  int rfindString(int startPos, const string& str, bool caseSensitive = true);
168  bool findPtr(int startPos, const StringVector& before, const char* pAfterString, bool casesensitive, char** pMatchedString, int& matchedStringPos, int& matchedStringlength);
169 
170  bool rfindPtr(int startPos, const StringVector& after, const char* pBeforeString, bool casesensitive, char** pMatchedString, int& matchedStringPos, int& matchedStringlength);
171 
172  int findString(int startPos, const char* pBeforeString, bool casesensitive);
173  int rfindString(int startPos, const char* str);
174  int rfindStringIc(int startPos, const char* str);
175  const char* getKeywordValue(const char* keyword, int& valueLen, bool bRemoveQuotes);
176  int findStringCheckIc(int startPos, const char* string, const char checkChar, bool skipQuotes, int endPos=0);
177  int findStringCheck(int startPos, const char* str, const char checkChar);
178  void skipToStringIc(const char* pTag);
179  virtual void setCharEncoding(const string& charEncoding);
180  virtual string getCharEncoding();
181 #endif // SWIG
182  private:
183  #pragma warning (disable : 4251)
184  string _data;
185  string _path;
186  string _charEncoding;
187  #pragma warning(default:4251)
188  int _currentPosition; // used when parsing
189  int _rewindPosition;
190  int _endSearchPosition;
191  };
192 
194  class FC_API ExtractorWithActionsInterface: public CharacterEncoding
195  {
196  public:
197  virtual ~ExtractorWithActionsInterface() {}
198  virtual bool find(ExtractionCursor &cursor, const string& text, bool caseSensitive)= 0;
199  virtual bool rfind(ExtractionCursor &cursor, const string& text, bool caseSensitive)= 0;
200 
201  virtual string extract(ExtractionCursor &cursor, const string& before, const string& after, const string& defaultValue, bool caseSensitive)= 0;
202  virtual string extractFromEnd(ExtractionCursor &cursor, const string& after, const string& before, const string& defaultValue, bool caseSensitive) = 0;
203 
204  virtual string extract(ExtractionCursor &cursor, const StringVector& before, const string& after, const string& defaultValue, bool caseSensitive)= 0;
205  virtual string extractFromEnd(ExtractionCursor &cursor, const StringVector& after, const string& before, const string& defaultValue, bool caseSensitive) = 0;
206 
207  virtual string extract(ExtractionCursor &cursor, const StringVector& before, const string& after, bool caseSensitive)= 0;
208  virtual string extractFromEnd(ExtractionCursor &cursor, const StringVector& after, const string& before, bool caseSensitive) = 0;
209 
210  virtual string extract(ExtractionCursor &cursor, const string& before, const string& after, bool caseSensitive)= 0;
211  virtual string extractFromEnd(ExtractionCursor &cursor, const string& after, const string& before, bool caseSensitive) = 0;
212 
213  virtual RegExpMatchList extractRegExp(ExtractionCursor &cursor, const string& regExp, bool caseSensitive)= 0;
214  virtual string extractRegExp(ExtractionCursor &cursor, const string& beforeRegExp, const string& afterRegExp, bool caseSensitive = true) = 0;
215  virtual string extractRegExpFromEnd(ExtractionCursor &cursor, const string& afterRegExp, const string& beforeRegExp, bool caseSensitive = true) = 0;
216  virtual bool verifyContains(const string &text, bool caseSensitive) = 0; // check if content contains the pattern
217  virtual bool find(ExtractionCursor &cursor, const string& text, ActionType failAction, bool caseSensitive) = 0;
218  virtual bool rfind(ExtractionCursor &cursor, const string& text, ActionType failAction, bool caseSensitive) = 0;
219 
220 
221  virtual string extract(ExtractionCursor &cursor, const string& before, const string& after, ActionType failAction, bool caseSensitive) = 0;
222  virtual string extractFromEnd(ExtractionCursor &cursor, const string& after, const string& before, ActionType failAction, bool caseSensitive) = 0;
223 
224  virtual string extract(ExtractionCursor &cursor, const StringVector& before, const string& after, ActionType failAction, bool caseSensitive) = 0;
225  virtual string extractFromEnd(ExtractionCursor &cursor, const StringVector& after, const string& before, ActionType failAction, bool caseSensitive) = 0;
226 
227  virtual string extractRegExp(ExtractionCursor &cursor, const string& beforeRegExp, const string& afterRegExp, ActionType failAction, bool caseSensitive = true) = 0;
228  virtual string extractRegExpFromEnd(ExtractionCursor &cursor, const string& afterRegExp, const string& beforeRegExp, ActionType failAction, bool caseSensitive = true) = 0;
229  virtual bool verifyContains(const string &text, ActionType failAction, bool caseSensitive) = 0;
230  };
232 
236  class FC_API ExtractorWithActions: public Extractor
237  {
238  public:
240  ExtractorWithActions(VirtualUserInterface& vu, const string& data);
241  ExtractorWithActions(VirtualUserInterface& vu, const string& path, int dummy);
243  virtual ~ExtractorWithActions();
244  ExtractorWithActions& operator=( const ExtractorWithActions& other);
247  bool find(ExtractionCursor& cursor, const string& text, bool caseSensitive = true);
249  bool rfind(ExtractionCursor &cursor, const string& text, bool caseSensitive = true);
251  string extract(ExtractionCursor &cursor, const string& before, const string& after, const string& defaultValue, bool caseSensitive = true);
252 
253  string extractFromEnd(ExtractionCursor &cursor, const string& after, const string& before, const string& defaultValue, bool caseSensitive = true);
254 
256  string extract(ExtractionCursor &cursor, const StringVector& before, const string& after, const string& defaultValue, bool caseSensitive = true);
257 
258  string extractFromEnd(ExtractionCursor &cursor, const StringVector& after, const string& before, const string& defaultValue, bool caseSensitive = true);
259 
262  string extract(ExtractionCursor &cursor, const StringVector& before, const string& after, bool caseSensitive = true);
263 
264  string extractFromEnd(ExtractionCursor &cursor, const StringVector& after, const string& before, bool caseSensitive = true);
265 
268  string extract(ExtractionCursor &cursor, const string& before, const string& after, bool caseSensitive = true);
269 
270  string extractFromEnd(ExtractionCursor &cursor, const string& after, const string& before, bool caseSensitive = true);
271 
272 
274  RegExpMatchList extractRegExp(ExtractionCursor &cursor, const string& regExp, bool caseSensitive = true);
275  string extractRegExp(ExtractionCursor &cursor, const string& beforeRegExp, const string& afterRegExp, bool caseSensitive = true);
276  string extractRegExpFromEnd(ExtractionCursor &cursor, const string& afterRegExp, const string& beforeRegExp, bool caseSensitive = true);
286  bool verifyContains(const string &text, bool caseSensitive = true);
287 
288  bool find(ExtractionCursor &cursor, const string& text, ActionType failAction, bool caseSensitive = true);
289  bool rfind(ExtractionCursor &cursor, const string& text, ActionType failAction, bool caseSensitive = true);
303  string extract(ExtractionCursor &cursor, const string& before, const string& after, ActionType failAction, bool caseSensitive = true);
304 
305  string extractFromEnd(ExtractionCursor &cursor, const string& after, const string& before, ActionType failAction, bool caseSensitive = true);
306 
320  string extract(ExtractionCursor &cursor, const StringVector& before, const string& after, ActionType failAction, bool caseSensitive = true);
321 
322  string extractFromEnd(ExtractionCursor &cursor, const StringVector& after, const string& before, ActionType failAction, bool caseSensitive = true);
323 
324  string extractRegExp(ExtractionCursor &cursor, const string& beforeRegExp, const string& afterRegExp, ActionType failAction, bool caseSensitive = true);
325  string extractRegExpFromEnd(ExtractionCursor &cursor, const string& afterRegExp, const string& beforeRegExp, ActionType failAction, bool caseSensitive = true);
326  bool verifyContains(const string &text, ActionType failAction, bool caseSensitive);
327 
328  VirtualUserInterface* getVU() { return _vu;}
329 
330  private:
331  VirtualUserInterface* _vu;
332  };
333 }
334 
const string & data() const
Definition: Extractor.h:151
void setEndSearch()
Definition: Extractor.h:162
int & getCurrentPositionRef()
Definition: Extractor.h:156
A means to search and extract information from a string.
Definition: Extractor.h:27
A means to search and extract information from a string.
Definition: Extractor.h:236
const string path() const
Definition: Extractor.h:147
void setCurrentPosition(int position)
Definition: Extractor.h:157
vector< RegExpMatch > RegExpMatchList
Definition: RegExpMatch.h:41
STL namespace.
This class maintains information over a sequence of textual searches.
Definition: ExtractionCursor.h:16
VirtualUserInterface * getVU()
Definition: Extractor.h:328
void incrementCurrentPosition(int inc=1)
Definition: Extractor.h:158
int getCurrentPosition() const
Definition: Extractor.h:155
void rewind()
Definition: Extractor.h:160
Definition: IpEndPoint.h:9
const char * getContentPtr(void)
Definition: Extractor.h:165
void advanceRewind()
Definition: Extractor.h:161