Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
static int ffserver_parse_config_redirect(FFServerConfig *config, const char *cmd, const char **p,
int line_num, FFServerStream **predirect)
{
FFServerStream *redirect;
av_assert0(predirect);
redirect = *predirect;
if (!av_strcasecmp(cmd, "<Redirect")) {
char *q;
redirect = av_mallocz(sizeof(FFServerStream));
if (!redirect)
return AVERROR(ENOMEM);
ffserver_get_arg(redirect->filename, sizeof(redirect->filename), p);
q = strrchr(redirect->filename, '>');
if (*q)
*q = '\0';
redirect->stream_type = STREAM_TYPE_REDIRECT;
*predirect = redirect;
return 0;
}
av_assert0(redirect);
if (!av_strcasecmp(cmd, "URL")) {
ffserver_get_arg(redirect->feed_filename, sizeof(redirect->feed_filename), p);
} else if (!av_strcasecmp(cmd, "</Redirect>")) {
if (!redirect->feed_filename[0])
ERROR("No URL found for <Redirect>\n");
*predirect = NULL;
} else {
ERROR("Invalid entry '%s' inside <Redirect></Redirect>\n", cmd);
}
return 0;
}
int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config)
{
FILE *f;
char line[1024];
char cmd[64];
const char *p;
int line_num = 0;
FFServerStream **last_stream, *stream = NULL, *redirect = NULL;
FFServerStream **last_feed, *feed = NULL;
int ret = 0;
av_assert0(config);
f = fopen(filename, "r");
if (!f) {
ret = AVERROR(errno);
av_log(NULL, AV_LOG_ERROR, "Could not open the configuration file '%s'\n", filename);
return ret;
}
config->first_stream = NULL;
last_stream = &config->first_stream;
config->first_feed = NULL;
last_feed = &config->first_feed;
config->errors = config->warnings = 0;
for(;;) {
if (fgets(line, sizeof(line), f) == NULL)
break;
line_num++;
p = line;
while (av_isspace(*p))
p++;
if (*p == '\0' || *p == '#')
continue;
ffserver_get_arg(cmd, sizeof(cmd), &p);
if (feed || !av_strcasecmp(cmd, "<Feed")) {
int opening = !av_strcasecmp(cmd, "<Feed");
if (opening && (stream || feed || redirect)) {
ERROR("Already in a tag\n");
} else {
if ((ret = ffserver_parse_config_feed(config, cmd, &p, line_num, &feed)) < 0)
if (opening) {
/* add in stream list */
*last_stream = feed;
last_stream = &feed->next;
/* add in feed list */
*last_feed = feed;
last_feed = &feed->next_feed;
} else if (stream || !av_strcasecmp(cmd, "<Stream")) {
int opening = !av_strcasecmp(cmd, "<Stream");
if (opening && (stream || feed || redirect)) {
ERROR("Already in a tag\n");
} else {
if ((ret = ffserver_parse_config_stream(config, cmd, &p, line_num, &stream)) < 0)
break;
if (opening) {
/* add in stream list */
*last_stream = stream;
last_stream = &stream->next;
} else if (redirect || !av_strcasecmp(cmd, "<Redirect")) {
int opening = !av_strcasecmp(cmd, "<Redirect");
if (opening && (stream || feed || redirect))
ERROR("Already in a tag\n");
else {
if ((ret = ffserver_parse_config_redirect(config, cmd, &p, line_num, &redirect)) < 0)
break;
if (opening) {
/* add in stream list */
*last_stream = redirect;
last_stream = &redirect->next;
}
}
} else {
ffserver_parse_config_global(config, cmd, &p, line_num);
}
}
fclose(f);
if (ret < 0)
return ret;
if (config->errors)
return AVERROR(EINVAL);
else
return 0;
}
#undef ERROR
#undef WARNING