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

Code before:
            }
            
            srs_freep(err);
            return srs_success;
        }
        if (srs_error_code(err) == ERROR_SYSTEM_CONFIG_EOF) {
            if (type == parse_block) {
                return srs_error_wrap(err, "line %d: unexpected end of file, expecting \"}\"", conf_line);
            }
            
            srs_freep(err);
            return srs_success;
        }
        
        if (args.empty()) {
            return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: empty directive", conf_line);
        }
        
        // build directive tree.
        if (args[0] == "include") {
            if (args.size() < 2) {
                return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: include is empty directive", buffer->line);
            }

            std::string file = args[1];
            if (!srs_string_contains(file, "*", "?", "[")) {
                srs_trace("config parse include %s", file.c_str());
                srs_freep(err);
                if ((err = conf->parse_include_file(file.c_str())) != srs_success) {
                    return srs_error_wrap(err, "parse file");
                }
            } else {
                unsigned long i = 0;
                glob_t glob_buf;

                if (glob((char *) file.c_str(), 0, NULL, &glob_buf) != 0) {
                    return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: parse include %s failed", buffer->line, file.c_str());
                }

                while(i < glob_buf.gl_pathc) {
                    srs_trace("include %s", *(glob_buf.gl_pathv+i));
                    srs_freep(err);
                    if ((err = conf->parse_include_file(*(glob_buf.gl_pathv+i))) != srs_success) {
                        return srs_error_wrap(err, "parse file");
                    }
                    i ++;
                }
            }
        } else {
            SrsConfDirective* directive = new SrsConfDirective();


Review comment (suggestion):
Files that do not support special characters can return an error if there are any special characters.

This is relatively simple and doesn't have much impact.

`TRANS_BY_GPT3`

Code after:
            SrsConfDirective* directive = new SrsConfDirective();

            directive->conf_line = line_start;
            directive->name = args[0];
            args.erase(args.begin());
            directive->args.swap(args);

            directives.push_back(directive);

            if (state == SrsDirectiveStateBlockStart) {
                if ((err = directive->parse_conf(buffer, SrsDirectiveContextBlock, conf)) != srs_success) {
                    return srs_error_wrap(err, "parse dir");
                }
            }
            continue;
        }

        // Parse including, allow multiple files.
        vector<string> files(args.begin() + 1, args.end());
        if (files.empty()) {
            return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: include is empty directive", buffer->line);
        }
        if (!conf) {
            return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: no config", buffer->line);
        }

        for (int i = 0; i < (int)files.size(); i++) {
            std::string file = files.at(i);
            srs_assert(!file.empty());
            srs_trace("config parse include %s", file.c_str());

            SrsConfigBuffer* include_file_buffer = NULL;
            SrsAutoFree(SrsConfigBuffer, include_file_buffer);
            if ((err = conf->build_buffer(file, &include_file_buffer)) != srs_success) {
                return srs_error_wrap(err, "buffer fullfill %s", file.c_str());
            }

            if ((err = parse_conf(include_file_buffer, SrsDirectiveContextFile, conf)) != srs_success) {
                return srs_error_wrap(err, "parse include buffer");
            }
        }
    }
    
    return err;
}

// see: ngx_conf_read_token
srs_error_t SrsConfDirective::read_token(SrsConfigBuffer* buffer, vector<string>& args, int& line_start, SrsDirectiveState& state)
{
    srs_error_t err = srs_success;