libnavajo
web server for static and dynamic pages developement in C++
Parser.h
1 // This file is distributed under GPLv3 licence
2 // Author: Gorelov Grigory (gorelov@grigory.info)
3 //
4 // Contacts and other info are on the WEB page: grigory.info/MPFDParser
5 
6 
7 
8 #ifndef _PARSER_H
9 #define _PARSER_H
10 
11 #include <iostream>
12 #include <string>
13 #include <map>
14 #include <vector>
15 #include "Exception.h"
16 #include "Field.h"
17 #include <string.h>
18 #include <stdlib.h>
19 
20 namespace MPFD {
21 
22  class Parser {
23  public:
24  static const int StoreUploadedFilesInFilesystem = 1, StoreUploadedFilesInMemory = 2;
25 
26 
27  Parser();
28  ~Parser();
29 
30  void SetContentType(const std::string type);
31 
32  void AcceptSomeData(const char *data, const long length);
33 
34 
35 
36  void SetMaxCollectedDataLength(long max);
37  void SetTempDirForFileUpload(std::string dir);
38  inline std::string GetTempDirForFileUpload() { return TempDirForFileUpload; };
39  void SetUploadedFilesStorage(int where);
40 
41  std::map<std::string, Field *> GetFieldsMap();
42  Field * GetField(std::string Name);
43 
44  private:
45  int WhereToStoreUploadedFiles;
46 
47  std::map<std::string, Field *> Fields;
48 
49  std::string TempDirForFileUpload;
50  int CurrentStatus;
51 
52  // Work statuses
53  static int const Status_LookingForStartingBoundary = 1;
54  static int const Status_ProcessingHeaders = 2;
55  static int const Status_ProcessingContentOfTheField = 3;
56 
57  std::string Boundary;
58  std::string ProcessingFieldName;
59  bool _HeadersOfTheFieldAreProcessed;
60  std::vector<char> DataCollector;
61  long MaxDataCollectorLength;
62  bool FindStartingBoundaryAndTruncData();
63  void _ProcessData();
64  void _ParseHeaders(std::string headers);
65  bool WaitForHeadersEndAndParseThem();
66  void TruncateDataCollectorFromTheBeginning(long n);
67  long BoundaryPositionInDataCollector();
68  bool ProcessContentOfTheField();
69  };
70 }
71 
72 #endif /* _PARSER_H */
73 
Definition: Parser.h:22
Definition: Field.h:20
Definition: Exception.h:15