Older/MediaServer/Http/HttpRequestSplitter.h

140 lines
4.4 KiB
C
Raw Normal View History

2024-09-28 23:55:00 +08:00
/*
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
*
* Use of this source code is governed by MIT-like license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#ifndef ZLMEDIAKIT_HTTPREQUESTSPLITTER_H
#define ZLMEDIAKIT_HTTPREQUESTSPLITTER_H
#include <string>
#include "Network/Buffer.h"
namespace mediakit {
class HttpRequestSplitter {
public:
HttpRequestSplitter();
virtual ~HttpRequestSplitter() = default;
/**
*
* @param data
* @param len
* @warning len + 1, 使 strstr , , @p len + 1 '\0' .
* Add data
* @param data Data to be added
* @param len Data length
* @warning Actual memory must be no less than len + 1. strstr is used internally for searching. To prevent out-of-bounds search, a '\0' terminator is set at the @p len + 1 position.
* [AUTO-TRANSLATED:3bbfc2ab]
*/
virtual void input(const char *data, size_t len);
/**
*
* Restore initial settings
* [AUTO-TRANSLATED:f797ec5a]
*/
void reset();
/**
*
* Remaining data size
* [AUTO-TRANSLATED:808a9399]
*/
size_t remainDataSize();
/**
*
* Get remaining data pointer
* [AUTO-TRANSLATED:e419f28a]
*/
const char *remainData() const;
/**
*
* Set maximum cache size
* [AUTO-TRANSLATED:19333c32]
*/
void setMaxCacheSize(size_t max_cache_size);
protected:
/**
*
* @param data
* @param len
*
* @return content长度,
* <0 : contentcontent将分段通过onRecvContent函数回调出去
* 0 : ,
* >0 : content,content并等到所有content接收完毕一次性通过onRecvContent函数回调出去
* Receive request header
* @param data Request header data
* @param len Request header length
*
* @return Content length after request header,
* <0 : Represents that all subsequent data is content, in which case the subsequent content will be called back in segments through the onRecvContent function
* 0 : Represents that the subsequent data is still the request header,
* >0 : Represents that the subsequent data is fixed-length content, in which case the content will be cached and called back through the onRecvContent function once all content is received
* [AUTO-TRANSLATED:f185e6c5]
*/
virtual ssize_t onRecvHeader(const char *data,size_t len) = 0;
/**
* content分片或全部数据
* onRecvHeader函数返回>0,
* @param data content分片或全部数据
* @param len
* Receive content fragments or all data
* onRecvHeader function returns >0, then it is all data
* @param data Content fragments or all data
* @param len Data length
* [AUTO-TRANSLATED:2ef280fb]
*/
virtual void onRecvContent(const char *data,size_t len) {};
/**
*
* @param data
* @param len
* @return nullptr代表未找到包位
* Determine if there is a packet tail in the data
* @param data Data pointer
* @param len Data length
* @return nullptr represents that the packet position is not found, otherwise returns the packet tail pointer
* [AUTO-TRANSLATED:f7190dec]
*/
virtual const char *onSearchPacketTail(const char *data, size_t len);
/**
* content len
* Set content len
* [AUTO-TRANSLATED:6dce48f8]
*/
void setContentLen(ssize_t content_len);
private:
ssize_t _content_len = 0;
size_t _max_cache_size = 0;
size_t _remain_data_size = 0;
toolkit::BufferLikeString _remain_data;
};
} /* namespace mediakit */
#endif //ZLMEDIAKIT_HTTPREQUESTSPLITTER_H