Repository: ossrs/srs
File: trunk/src/app/srs_app_config.cpp (C++)

Code before:
    }
    
    SrsConfigBuffer buffer;
    
    if ((err = buffer.fullfill(config_file.c_str())) != srs_success) {
        return srs_error_wrap(err, "buffer fullfil");
    }
    
    if ((err = parse_buffer(&buffer)) != srs_success) {
        return srs_error_wrap(err, "parse buffer");
    }
    
    return err;
}

srs_error_t SrsConfig::parse_include_file(const char *filename)
{
    srs_error_t err = srs_success;

    std::string file = filename;

    if (file.empty()) {
        return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "empty include config");
    }

    SrsConfigBuffer buffer;

    if ((err = buffer.fullfill(file.c_str())) != srs_success) {
        return srs_error_wrap(err, "buffer fullfil");
    }

    // Parse root tree from buffer.
    if ((err = root->parse(&buffer, this)) != srs_success) {
        return srs_error_wrap(err, "parse include buffer");
    }

    return err;
}

SrsConfigBuffer* SrsConfig::get_buffer_from_include_file(const char* filename)
{
    srs_error_t err = srs_success;

    SrsConfigBuffer* buffer = new SrsConfigBuffer();

    if ((err = buffer->fullfill(filename)) != srs_success) {
        srs_freep(buffer);

        return NULL;
    }


Review comment (suggestion):
This place also needs to create `SrsConfigBuffer`, and `get_buffer_from_include_file` also needs to create `SrsConfigBuffer`. Essentially, both require creation, so why split them into two functions? This part can actually be improved.

Or, to put it another way, `parse_include_file` is for use by `root`, while `get_buffer_from_include_file` is for use by `conf`. Actually, there is no difference between the two, they are both `SrsDirective`. There is no need to specifically prepare a logic for `root`. Just think about it.

Is it possible to just call one logic: `parse_conf(config_buffer, parse_file, root)`, instead of specifically preparing a logic for `root`? It seems unnecessary to do so.

`TRANS_BY_GPT3`

Code after:

    if ((err = buffer->fullfill(src.c_str())) != srs_success) {
        srs_freep(buffer);
        return srs_error_wrap(err, "read from src %s", src.c_str());
    }

    *pbuffer = buffer;
    return err;
}
// LCOV_EXCL_STOP

srs_error_t SrsConfig::check_config()
{
    srs_error_t err = srs_success;
    
    if ((err = check_normal_config()) != srs_success) {
        return srs_error_wrap(err, "check normal");
    }
    
    if ((err = check_number_connections()) != srs_success) {
        return srs_error_wrap(err, "check connections");
    }

    // If use the full.conf, fail.
    if (is_full_config()) {
        return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID,
            "never use full.conf(%s)", config_file.c_str());
    }
    
    return err;
}

srs_error_t SrsConfig::check_normal_config()
{
    srs_error_t err = srs_success;
    
    srs_trace("srs checking config...");
    
    ////////////////////////////////////////////////////////////////////////
    // check empty
    ////////////////////////////////////////////////////////////////////////
    if (root->directives.size() == 0) {
        return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "conf is empty");
    }
    
    ////////////////////////////////////////////////////////////////////////
    // check root directives.
    ////////////////////////////////////////////////////////////////////////
    for (int i = 0; i < (int)root->directives.size(); i++) {
        SrsConfDirective* conf = root->at(i);
        std::string n = conf->name;