| 58 | #define crReset(state) state = 0; |
| 59 | |
| 60 | SC::Result SC::HttpParser::parse(Span<const char> data, size_t& readBytes, Span<const char>& parsedData) |
| 61 | { |
| 62 | if (state == State::Finished) |
| 63 | { |
| 64 | return SC::Result(false); |
| 65 | } |
| 66 | readBytes = 0; |
| 67 | if (type == Type::Request) |
| 68 | { |
| 69 | if (token == Token::HeadersEnd) |
| 70 | { |
| 71 | if (state == State::Result) |
| 72 | { |
| 73 | state = State::Finished; |
| 74 | return Result(true); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | if (token == Token::Body) |
| 81 | { |
| 82 | if (state == State::Result) |
| 83 | { |
| 84 | state = State::Finished; |
| 85 | return Result(true); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | if (data.sizeInBytes() == 0) |
| 91 | { |
| 92 | return SC::Result(false); |
| 93 | } |
| 94 | |
| 95 | SC_CO_BEGIN(topLevelCoroutine); |
| 96 | if (type == Type::Request) |
| 97 | { |
| 98 | //------------------------ |
| 99 | // Parse Method |
| 100 | //------------------------ |
| 101 | globalStart += globalLength; |
| 102 | tokenStart = globalStart; |
| 103 | tokenLength = 0; |
| 104 | globalLength = 0; |
| 105 | do |
| 106 | { |
| 107 | SC_TRY((process<&HttpParser::parseMethod, Token::Method>(data, readBytes, parsedData))); |
| 108 | SC_CO_RETURN(topLevelCoroutine, Result(true)); |
| 109 | } while (state == State::Parsing); |
| 110 | //------------------------ |
| 111 | // Parse URL |
| 112 | //------------------------ |
| 113 | globalStart += globalLength; |
| 114 | tokenStart = globalStart; |
| 115 | tokenLength = 0; |
| 116 | globalLength = 0; |
| 117 | matchIndex = 0; |
no test coverage detected