mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Support include directive for config file (#2878)
* Support include import configuration * Remove support for regular rules * Remove support for regular rules * Fix configuration file parsing bug * Added utest tests for include functionality * Added utest tests for include functionality * Modify the UTest function * optimized code * Config: Refine parse error with state * Config: Reorder functions * Config: Rename parsing type to context * Config: Refine args for include * Config: Add utests for include * Config: Refine code, parsing recursively. * Config: Change the mock from file to buffer * Config: Mock buffer in config * Config: Refine code * Add utests for include * Added utest for include Co-authored-by: pengfei.ma <pengfei.ma@ngaa.com.cn> Co-authored-by: winlin <winlin@vip.126.com>
This commit is contained in:
parent
5e78c1fe88
commit
fde44885d9
5 changed files with 389 additions and 74 deletions
|
@ -210,7 +210,7 @@ public:
|
|||
// Parse utilities
|
||||
public:
|
||||
// Parse config directive from file buffer.
|
||||
virtual srs_error_t parse(srs_internal::SrsConfigBuffer* buffer);
|
||||
virtual srs_error_t parse(srs_internal::SrsConfigBuffer* buffer, SrsConfig* conf = NULL);
|
||||
// Marshal the directive to writer.
|
||||
// @param level, the root is level0, all its directives are level1, and so on.
|
||||
virtual srs_error_t persistence(SrsFileWriter* writer, int level);
|
||||
|
@ -223,24 +223,36 @@ public:
|
|||
virtual SrsJsonAny* dumps_arg0_to_boolean();
|
||||
// private parse.
|
||||
private:
|
||||
// The directive parsing type.
|
||||
enum SrsDirectiveType {
|
||||
// The directive parsing context.
|
||||
enum SrsDirectiveContext {
|
||||
// The root directives, parsing file.
|
||||
parse_file,
|
||||
// For each direcitve, parsing text block.
|
||||
parse_block
|
||||
SrsDirectiveContextFile,
|
||||
// For each directive, parsing text block.
|
||||
SrsDirectiveContextBlock,
|
||||
};
|
||||
enum SrsDirectiveState {
|
||||
// Init state
|
||||
SrsDirectiveStateInit,
|
||||
// The directive terminated by ';' found
|
||||
SrsDirectiveStateEntire,
|
||||
// The token terminated by '{' found
|
||||
SrsDirectiveStateBlockStart,
|
||||
// The '}' found
|
||||
SrsDirectiveStateBlockEnd,
|
||||
// The config file is done
|
||||
SrsDirectiveStateEOF,
|
||||
};
|
||||
// Parse the conf from buffer. the work flow:
|
||||
// 1. read a token(directive args and a ret flag),
|
||||
// 2. initialize the directive by args, args[0] is name, args[1-N] is args of directive,
|
||||
// 3. if ret flag indicates there are child-directives, read_conf(directive, block) recursively.
|
||||
virtual srs_error_t parse_conf(srs_internal::SrsConfigBuffer* buffer, SrsDirectiveType type);
|
||||
virtual srs_error_t parse_conf(srs_internal::SrsConfigBuffer* buffer, SrsDirectiveContext ctx, SrsConfig* conf);
|
||||
// Read a token from buffer.
|
||||
// A token, is the directive args and a flag indicates whether has child-directives.
|
||||
// @param args, the output directive args, the first is the directive name, left is the args.
|
||||
// @param line_start, the actual start line of directive.
|
||||
// @return, an error code indicates error or has child-directives.
|
||||
virtual srs_error_t read_token(srs_internal::SrsConfigBuffer* buffer, std::vector<std::string>& args, int& line_start);
|
||||
virtual srs_error_t read_token(srs_internal::SrsConfigBuffer* buffer, std::vector<std::string>& args, int& line_start, SrsDirectiveState& state);
|
||||
};
|
||||
|
||||
// The config service provider.
|
||||
|
@ -250,6 +262,7 @@ private:
|
|||
// You could keep it before st-thread switch, or simply never keep it.
|
||||
class SrsConfig
|
||||
{
|
||||
friend class SrsConfDirective;
|
||||
// user command
|
||||
private:
|
||||
// Whether srs is run in dolphin mode.
|
||||
|
@ -356,6 +369,10 @@ private:
|
|||
public:
|
||||
// Parse the config file, which is specified by cli.
|
||||
virtual srs_error_t parse_file(const char* filename);
|
||||
private:
|
||||
// Build a buffer from a src, which is string content or filename.
|
||||
virtual srs_error_t build_buffer(std::string src, srs_internal::SrsConfigBuffer** pbuffer);
|
||||
public:
|
||||
// Check the parsed config.
|
||||
virtual srs_error_t check_config();
|
||||
protected:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue