1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

refine config, add error line log

This commit is contained in:
winlin 2014-07-17 11:28:20 +08:00
parent f3e85a0063
commit 784d7499cf
2 changed files with 62 additions and 61 deletions

View file

@ -154,6 +154,7 @@ int SrsConfDirective::parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDire
while (true) { while (true) {
std::vector<string> args; std::vector<string> args;
ret = read_token(buffer, args); ret = read_token(buffer, args);
/** /**
@ -169,21 +170,21 @@ int SrsConfDirective::parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDire
} }
if (ret == ERROR_SYSTEM_CONFIG_BLOCK_END) { if (ret == ERROR_SYSTEM_CONFIG_BLOCK_END) {
if (type != parse_block) { if (type != parse_block) {
srs_error("line %d: unexpected \"}\"", buffer->line); srs_error("line %d: unexpected \"}\"", buffer->line + 1);
return ret; return ret;
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
if (ret == ERROR_SYSTEM_CONFIG_EOF) { if (ret == ERROR_SYSTEM_CONFIG_EOF) {
if (type == parse_block) { if (type == parse_block) {
srs_error("line %d: unexpected end of file, expecting \"}\"", buffer->line); srs_error("line %d: unexpected end of file, expecting \"}\"", conf_line + 1);
return ret; return ret;
} }
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
if (args.empty()) { if (args.empty()) {
srs_error("line %d: empty directive.", buffer->line); srs_error("line %d: empty directive.", conf_line + 1);
return ret; return ret;
} }
@ -258,7 +259,7 @@ int SrsConfDirective::read_token(_srs_internal::SrsConfigBuffer* buffer, vector<
if (ch == '{') { if (ch == '{') {
return ERROR_SYSTEM_CONFIG_BLOCK_START; return ERROR_SYSTEM_CONFIG_BLOCK_START;
} }
srs_error("line %d: unexpected '%c'", buffer->line, ch); srs_error("line %d: unexpected '%c'", buffer->line + 1, ch);
return ERROR_SYSTEM_CONFIG_INVALID; return ERROR_SYSTEM_CONFIG_INVALID;
} }
@ -271,19 +272,19 @@ int SrsConfDirective::read_token(_srs_internal::SrsConfigBuffer* buffer, vector<
switch (ch) { switch (ch) {
case ';': case ';':
if (args.size() == 0) { if (args.size() == 0) {
srs_error("line %d: unexpected ';'", buffer->line); srs_error("line %d: unexpected ';'", buffer->line + 1);
return ERROR_SYSTEM_CONFIG_INVALID; return ERROR_SYSTEM_CONFIG_INVALID;
} }
return ERROR_SYSTEM_CONFIG_DIRECTIVE; return ERROR_SYSTEM_CONFIG_DIRECTIVE;
case '{': case '{':
if (args.size() == 0) { if (args.size() == 0) {
srs_error("line %d: unexpected '{'", buffer->line); srs_error("line %d: unexpected '{'", buffer->line + 1);
return ERROR_SYSTEM_CONFIG_INVALID; return ERROR_SYSTEM_CONFIG_INVALID;
} }
return ERROR_SYSTEM_CONFIG_BLOCK_START; return ERROR_SYSTEM_CONFIG_BLOCK_START;
case '}': case '}':
if (args.size() != 0) { if (args.size() != 0) {
srs_error("line %d: unexpected '}'", buffer->line); srs_error("line %d: unexpected '}'", buffer->line + 1);
return ERROR_SYSTEM_CONFIG_INVALID; return ERROR_SYSTEM_CONFIG_INVALID;
} }
return ERROR_SYSTEM_CONFIG_BLOCK_END; return ERROR_SYSTEM_CONFIG_BLOCK_END;
@ -1068,59 +1069,6 @@ int SrsConfig::parse_options(int argc, char** argv)
return ret; return ret;
} }
int SrsConfig::parse_file(const char* filename)
{
int ret = ERROR_SUCCESS;
config_file = filename;
if (config_file.empty()) {
return ERROR_SYSTEM_CONFIG_INVALID;
}
_srs_internal::SrsConfigBuffer buffer;
if ((ret = buffer.fullfill(config_file.c_str())) != ERROR_SUCCESS) {
return ret;
}
if ((ret = root->parse(&buffer)) != ERROR_SUCCESS) {
return ret;
}
SrsConfDirective* conf = NULL;
// check rtmp port specified by directive listen.
if ((conf = get_listen()) == NULL || conf->args.size() == 0) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("line %d: conf error, "
"directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret);
return ret;
}
// TODO: check the hls.
// TODO: check forward.
// TODO: check ffmpeg.
// TODO: check http.
// TODO: check pid.
// check log
std::string log_filename = this->get_log_file();
if (get_log_tank_file() && log_filename.empty()) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("must specifies the file to write log to. ret=%d", ret);
return ret;
}
if (get_log_tank_file()) {
srs_trace("write log to file %s", log_filename.c_str());
srs_trace("you can: tailf %s", log_filename.c_str());
srs_trace("@see: %s", SRS_WIKI_URL_LOG);
} else {
srs_trace("write log to console");
}
return ret;
}
int SrsConfig::parse_argv(int& i, char** argv) int SrsConfig::parse_argv(int& i, char** argv)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
@ -1197,6 +1145,59 @@ void SrsConfig::print_help(char** argv)
argv[0], argv[0], argv[0], argv[0]); argv[0], argv[0], argv[0], argv[0]);
} }
int SrsConfig::parse_file(const char* filename)
{
int ret = ERROR_SUCCESS;
config_file = filename;
if (config_file.empty()) {
return ERROR_SYSTEM_CONFIG_INVALID;
}
_srs_internal::SrsConfigBuffer buffer;
if ((ret = buffer.fullfill(config_file.c_str())) != ERROR_SUCCESS) {
return ret;
}
if ((ret = root->parse(&buffer)) != ERROR_SUCCESS) {
return ret;
}
SrsConfDirective* conf = NULL;
// check rtmp port specified by directive listen.
if ((conf = get_listen()) == NULL || conf->args.size() == 0) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("line %d: conf error, "
"directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret);
return ret;
}
// TODO: check the hls.
// TODO: check forward.
// TODO: check ffmpeg.
// TODO: check http.
// TODO: check pid.
// check log
std::string log_filename = this->get_log_file();
if (get_log_tank_file() && log_filename.empty()) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("must specifies the file to write log to. ret=%d", ret);
return ret;
}
if (get_log_tank_file()) {
srs_trace("write log to file %s", log_filename.c_str());
srs_trace("you can: tailf %s", log_filename.c_str());
srs_trace("@see: %s", SRS_WIKI_URL_LOG);
} else {
srs_trace("write log to console");
}
return ret;
}
string SrsConfig::cwd() string SrsConfig::cwd()
{ {
return _cwd; return _cwd;

View file

@ -245,9 +245,9 @@ private:
public: public:
virtual int parse_options(int argc, char** argv); virtual int parse_options(int argc, char** argv);
private: private:
virtual int parse_file(const char* filename);
virtual int parse_argv(int& i, char** argv); virtual int parse_argv(int& i, char** argv);
virtual void print_help(char** argv); virtual void print_help(char** argv);
virtual int parse_file(const char* filename);
public: public:
virtual std::string cwd(); virtual std::string cwd();
virtual std::string argv(); virtual std::string argv();