NCBI C++ ToolKit
cgi_entry_reader.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CGI_IMPL___CGI_ENTRY_READER__HPP
2 #define CGI_IMPL___CGI_ENTRY_READER__HPP
3 
4 /* $Id: cgi_entry_reader.hpp 81838 2018-04-09 17:42:02Z grichenk $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Aaron Ucko
30  *
31  */
32 
33 /// @file cgi_entry_reader.hpp
34 /// Support classes for on-demand CGI input parsing.
35 
36 
37 #include <cgi/ncbicgi.hpp>
38 
39 
40 /** @addtogroup CGIReqRes
41  *
42  * @{
43  */
44 
45 
47 
48 
49 class CCgiEntryReader : public IReader
50 {
51 public:
53 
54  ERW_Result Read(void* buf, size_t count, size_t* bytes_read);
55  ERW_Result PendingCount(size_t* count);
56 
57 private:
58  enum EState {
59  fUnread = 0x1,
60  fHitCR = 0x2,
61  fHitLF = 0x4,
63  fHitBoundary = 0x8
64  };
65  typedef int TState;
66 
68  : m_Context(context), m_State(fUnread | fHitCRLF)
69  { }
71 
72  void x_FillBuffer(SIZE_TYPE count);
73  void x_Flush(void) { x_FillBuffer(NPOS); }
74  void x_HitBoundary(bool final);
75 
77  string m_Buffer;
79 
80  friend class CCgiEntryReaderContext;
81 };
82 
83 
85 {
86 public:
88  const string& content_type,
89  size_t content_length
91  string* content_log = NULL);
93 
95 
96  void IncludePreparsedEntries(void);
97 
98 private:
101  eCT_Null, // at end of input
104  };
110  };
111 
112  void x_FlushCurrentEntry(void);
114  void x_ReadURLEncodedEntry(string& name, string& value);
115  void x_ReadMultipartHeaders(string& name, string& filename,
116  string& content_type);
117 
125  string m_Boundary;
126  string* m_ContentLog;
127  unsigned int m_Position;
131 
132  friend class CCgiEntryReader;
133 };
134 
135 
137 
138 
139 /* @} */
140 
141 #endif /* CGI_IMPL___CGI_ENTRY_READER__HPP */
A very basic data-read interface.
char value[7]
Definition: config.c:431
std::ofstream out("events_result.xml")
main entry point for tests
void x_ReadMultipartHeaders(string &name, string &filename, string &content_type)
EReadTerminator x_DelimitedRead(string &s, SIZE_TYPE n=NPOS)
TCgiEntries::iterator TCgiEntriesI
Definition: ncbicgi.hpp:639
CCgiEntryReaderContext(CNcbiIstream &in, TCgiEntries &out, const string &content_type, size_t content_length=CCgiRequest::kContentLengthUnknown, string *content_log=NULL)
void x_HitBoundary(bool final)
ERW_Result PendingCount(size_t *count)
Via parameter "count" (which is guaranteed to be supplied non-NULL) return the number of bytes that a...
TCgiEntriesI GetNextEntry(void)
void x_ReadURLEncodedEntry(string &name, string &value)
CCgiEntryReader(TContext &context)
ERW_Result Read(void *buf, size_t count, size_t *bytes_read)
Read as many as "count" bytes into a buffer pointed to by the "buf" argument.
static const size_t kContentLengthUnknown
Get content length using value of the property 'eCgi_ContentLength'.
Definition: ncbicgi.hpp:781
CCgiEntryReaderContext TContext
void x_FillBuffer(SIZE_TYPE count)
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
ERW_Result
Result codes for I/O operations.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
#define NPOS
Definition: ncbistr.hpp:133
char * buf
yy_size_t n
std::istream & in(std::istream &in_, double &x_)
Modified on Sun Mar 03 03:13:07 2024 by modify_doxy.py rev. 669887