LCOV - code coverage report
Current view: top level - extra/webserver/webserver/filter - SPWebInputFilter.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 4 100.0 %
Date: 2024-05-12 00:16:13 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2024 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef EXTRA_WEBSERVER_WEBSERVER_FILTER_SPWEBINPUTFILTER_H_
      24             : #define EXTRA_WEBSERVER_WEBSERVER_FILTER_SPWEBINPUTFILTER_H_
      25             : 
      26             : #include "SPWebRequest.h"
      27             : 
      28             : namespace STAPPLER_VERSIONIZED stappler::web {
      29             : 
      30             : class InputParser : public AllocBase {
      31             : public:
      32             :         InputParser(const db::InputConfig &, size_t);
      33             : 
      34             :         SP_COVERAGE_TRIVIAL
      35             :         virtual ~InputParser() { }
      36             : 
      37             :         virtual bool run(BytesView) = 0;
      38             :         virtual void finalize() = 0;
      39             :         virtual void cleanup();
      40             : 
      41         650 :         virtual Value &getData() {
      42         650 :                 return root;
      43             :         }
      44             : 
      45         650 :         virtual Vector<db::InputFile> &getFiles() {
      46         650 :                 return files;
      47             :         }
      48             : 
      49             :         const db::InputConfig &getConfig() const;
      50             : 
      51             : protected:
      52             :         db::InputConfig config;
      53             :         size_t length;
      54             :         Value root;
      55             :         //UrlencodeParser basicParser;
      56             :         Vector<db::InputFile> files;
      57             : };
      58             : 
      59             : class InputFilter : public AllocBase {
      60             : public:
      61             :         using FilterFunc = Function<void(InputFilter *filter)>;
      62             :         using Accept = InputFilterAccept;
      63             : 
      64             :         enum class Exception {
      65             :                 None,
      66             :                 TooLarge,
      67             :                 Unrecognized,
      68             :         };
      69             : 
      70             :         static Status getStatusForException(Exception);
      71             : 
      72             :         static Exception insert(const Request &);
      73             : 
      74             :         /* file index can be coded as ordered index or negative id
      75             :          * negative_id = - index - 1
      76             :          *
      77             :          * return nullptr if there is no such file */
      78             :         static db::InputFile *getFileFromContext(int64_t);
      79             : 
      80             :         InputFilter(const Request &, Accept a);
      81             : 
      82             :         Status init();
      83             : 
      84             :         bool step(BytesView);
      85             :         void finalize();
      86             : 
      87             :         StringView getContentType() const;
      88             : 
      89             :         size_t getContentLength() const;
      90             :         size_t getBytesRead() const;
      91             :         size_t getBytesReadSinceUpdate() const;
      92             : 
      93             :         Time getStartTime() const;
      94             :         TimeInterval getElapsedTime() const;
      95             :         TimeInterval getElapsedTimeSinceUpdate() const;
      96             : 
      97             :         size_t getFileBufferSize() const;
      98             :         void setFileBufferSize(size_t size);
      99             : 
     100             :         bool isFileUploadAllowed() const;
     101             :         bool isDataParsingAllowed() const;
     102             :         bool isBodySavingAllowed() const;
     103             : 
     104             :         bool isCompleted() const;
     105             : 
     106             :         const StringStream & getBody() const;
     107             :         Value & getData();
     108             :         Vector<db::InputFile> &getFiles();
     109             : 
     110             :         db::InputFile * getInputFile(int64_t) const;
     111             : 
     112             :         const db::InputConfig & getConfig() const;
     113             : 
     114             :         Request getRequest() const;
     115             :         memory::pool_t *getPool() const;
     116             : 
     117             : protected:
     118             :         Accept _accept = Accept::None;
     119             : 
     120             :         Time _time;
     121             :         Time _startTime;
     122             :         TimeInterval _timer;
     123             : 
     124             :         size_t _unupdated = 0;
     125             :         size_t _read = 0;
     126             :         size_t _contentLength = 0;
     127             : 
     128             :         StringStream _body;
     129             : 
     130             :         InputParser *_parser = nullptr;
     131             :         Request _request;
     132             : 
     133             :         bool _eos = false, _isCompleted = false, _isStarted = false;
     134             : };
     135             : 
     136             : }
     137             : 
     138             : #endif /* EXTRA_WEBSERVER_WEBSERVER_FILTER_SPWEBINPUTFILTER_H_ */

Generated by: LCOV version 1.14