Implement ffserver.c:report_config_error() and a macro for logging

error messages / updating the error count.

Originally committed as revision 22960 to svn://svn.ffmpeg.org/ffmpeg/trunk
release/0.6
Stefano Sabatini 15 years ago
parent 6675a5bf73
commit 472e12f510
  1. 139
      ffserver.c

@ -3951,6 +3951,17 @@ static AVOutputFormat *ffserver_guess_format(const char *short_name, const char
return fmt; return fmt;
} }
static void report_config_error(const char *filename, int line_num, int *errors, const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
fprintf(stderr, "%s:%d: ", filename, line_num);
vfprintf(stderr, fmt, vl);
va_end(vl);
(*errors)++;
}
static int parse_ffconfig(const char *filename) static int parse_ffconfig(const char *filename)
{ {
FILE *f; FILE *f;
@ -3981,6 +3992,8 @@ static int parse_ffconfig(const char *filename)
redirect = NULL; redirect = NULL;
audio_id = CODEC_ID_NONE; audio_id = CODEC_ID_NONE;
video_id = CODEC_ID_NONE; video_id = CODEC_ID_NONE;
#define ERROR(...) report_config_error(filename, line_num, &errors, __VA_ARGS__)
for(;;) { for(;;) {
if (fgets(line, sizeof(line), f) == NULL) if (fgets(line, sizeof(line), f) == NULL)
break; break;
@ -3997,17 +4010,13 @@ static int parse_ffconfig(const char *filename)
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
val = atoi(arg); val = atoi(arg);
if (val < 1 || val > 65536) { if (val < 1 || val > 65536) {
fprintf(stderr, "%s:%d: Invalid port: %s\n", ERROR("Invalid_port: %s\n", arg);
filename, line_num, arg);
errors++;
} }
my_http_addr.sin_port = htons(val); my_http_addr.sin_port = htons(val);
} else if (!strcasecmp(cmd, "BindAddress")) { } else if (!strcasecmp(cmd, "BindAddress")) {
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
if (resolve_host(&my_http_addr.sin_addr, arg) != 0) { if (resolve_host(&my_http_addr.sin_addr, arg) != 0) {
fprintf(stderr, "%s:%d: Invalid host/IP address: %s\n", ERROR("%s:%d: Invalid host/IP address: %s\n", arg);
filename, line_num, arg);
errors++;
} }
} else if (!strcasecmp(cmd, "NoDaemon")) { } else if (!strcasecmp(cmd, "NoDaemon")) {
ffserver_daemon = 0; ffserver_daemon = 0;
@ -4015,34 +4024,26 @@ static int parse_ffconfig(const char *filename)
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
val = atoi(arg); val = atoi(arg);
if (val < 1 || val > 65536) { if (val < 1 || val > 65536) {
fprintf(stderr, "%s:%d: Invalid port: %s\n", ERROR("%s:%d: Invalid port: %s\n", arg);
filename, line_num, arg);
errors++;
} }
my_rtsp_addr.sin_port = htons(atoi(arg)); my_rtsp_addr.sin_port = htons(atoi(arg));
} else if (!strcasecmp(cmd, "RTSPBindAddress")) { } else if (!strcasecmp(cmd, "RTSPBindAddress")) {
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
if (resolve_host(&my_rtsp_addr.sin_addr, arg) != 0) { if (resolve_host(&my_rtsp_addr.sin_addr, arg) != 0) {
fprintf(stderr, "%s:%d: Invalid host/IP address: %s\n", ERROR("Invalid host/IP address: %s\n", arg);
filename, line_num, arg);
errors++;
} }
} else if (!strcasecmp(cmd, "MaxHTTPConnections")) { } else if (!strcasecmp(cmd, "MaxHTTPConnections")) {
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
val = atoi(arg); val = atoi(arg);
if (val < 1 || val > 65536) { if (val < 1 || val > 65536) {
fprintf(stderr, "%s:%d: Invalid MaxHTTPConnections: %s\n", ERROR("Invalid MaxHTTPConnections: %s\n", arg);
filename, line_num, arg);
errors++;
} }
nb_max_http_connections = val; nb_max_http_connections = val;
} else if (!strcasecmp(cmd, "MaxClients")) { } else if (!strcasecmp(cmd, "MaxClients")) {
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
val = atoi(arg); val = atoi(arg);
if (val < 1 || val > nb_max_http_connections) { if (val < 1 || val > nb_max_http_connections) {
fprintf(stderr, "%s:%d: Invalid MaxClients: %s\n", ERROR("Invalid MaxClients: %s\n", arg);
filename, line_num, arg);
errors++;
} else { } else {
nb_max_connections = val; nb_max_connections = val;
} }
@ -4051,9 +4052,7 @@ static int parse_ffconfig(const char *filename)
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
llval = atoll(arg); llval = atoll(arg);
if (llval < 10 || llval > 10000000) { if (llval < 10 || llval > 10000000) {
fprintf(stderr, "%s:%d: Invalid MaxBandwidth: %s\n", ERROR("Invalid MaxBandwidth: %s\n", arg);
filename, line_num, arg);
errors++;
} else } else
max_bandwidth = llval; max_bandwidth = llval;
} else if (!strcasecmp(cmd, "CustomLog")) { } else if (!strcasecmp(cmd, "CustomLog")) {
@ -4064,8 +4063,7 @@ static int parse_ffconfig(const char *filename)
/* Feed related options */ /* Feed related options */
char *q; char *q;
if (stream || feed) { if (stream || feed) {
fprintf(stderr, "%s:%d: Already in a tag\n", ERROR("Already in a tag\n");
filename, line_num);
} else { } else {
feed = av_mallocz(sizeof(FFStream)); feed = av_mallocz(sizeof(FFStream));
get_arg(feed->filename, sizeof(feed->filename), &p); get_arg(feed->filename, sizeof(feed->filename), &p);
@ -4075,9 +4073,7 @@ static int parse_ffconfig(const char *filename)
for (s = first_feed; s; s = s->next) { for (s = first_feed; s; s = s->next) {
if (!strcmp(feed->filename, s->filename)) { if (!strcmp(feed->filename, s->filename)) {
fprintf(stderr, "%s:%d: Feed '%s' already registered\n", ERROR("Feed '%s' already registered\n", s->filename);
filename, line_num, s->filename);
errors++;
} }
} }
@ -4156,16 +4152,12 @@ static int parse_ffconfig(const char *filename)
} }
feed->feed_max_size = (int64_t)fsize; feed->feed_max_size = (int64_t)fsize;
if (feed->feed_max_size < FFM_PACKET_SIZE*4) { if (feed->feed_max_size < FFM_PACKET_SIZE*4) {
fprintf(stderr, "%s:%d: Feed max file size is too small, " ERROR("Feed max file size is too small, must be at least %d\n", FFM_PACKET_SIZE*4);
"must be at least %d\n", filename, line_num, FFM_PACKET_SIZE*4);
errors++;
} }
} }
} else if (!strcasecmp(cmd, "</Feed>")) { } else if (!strcasecmp(cmd, "</Feed>")) {
if (!feed) { if (!feed) {
fprintf(stderr, "%s:%d: No corresponding <Feed> for </Feed>\n", ERROR("No corresponding <Feed> for </Feed>\n");
filename, line_num);
errors++;
} }
feed = NULL; feed = NULL;
} else if (!strcasecmp(cmd, "<Stream")) { } else if (!strcasecmp(cmd, "<Stream")) {
@ -4173,8 +4165,7 @@ static int parse_ffconfig(const char *filename)
/* Stream related options */ /* Stream related options */
char *q; char *q;
if (stream || feed) { if (stream || feed) {
fprintf(stderr, "%s:%d: Already in a tag\n", ERROR("Already in a tag\n");
filename, line_num);
} else { } else {
FFStream *s; FFStream *s;
stream = av_mallocz(sizeof(FFStream)); stream = av_mallocz(sizeof(FFStream));
@ -4185,9 +4176,7 @@ static int parse_ffconfig(const char *filename)
for (s = first_stream; s; s = s->next) { for (s = first_stream; s; s = s->next) {
if (!strcmp(stream->filename, s->filename)) { if (!strcmp(stream->filename, s->filename)) {
fprintf(stderr, "%s:%d: Stream '%s' already registered\n", ERROR("Stream '%s' already registered\n", s->filename);
filename, line_num, s->filename);
errors++;
} }
} }
@ -4216,8 +4205,7 @@ static int parse_ffconfig(const char *filename)
sfeed = sfeed->next_feed; sfeed = sfeed->next_feed;
} }
if (!sfeed) if (!sfeed)
fprintf(stderr, "%s:%d: feed '%s' not defined\n", ERROR("feed '%s' not defined\n", arg);
filename, line_num, arg);
else else
stream->feed = sfeed; stream->feed = sfeed;
} }
@ -4234,9 +4222,7 @@ static int parse_ffconfig(const char *filename)
strcpy(arg, "mjpeg"); strcpy(arg, "mjpeg");
stream->fmt = ffserver_guess_format(arg, NULL, NULL); stream->fmt = ffserver_guess_format(arg, NULL, NULL);
if (!stream->fmt) { if (!stream->fmt) {
fprintf(stderr, "%s:%d: Unknown Format: %s\n", ERROR("Unknown Format: %s\n", arg);
filename, line_num, arg);
errors++;
} }
} }
if (stream->fmt) { if (stream->fmt) {
@ -4249,17 +4235,14 @@ static int parse_ffconfig(const char *filename)
if (stream) { if (stream) {
stream->ifmt = av_find_input_format(arg); stream->ifmt = av_find_input_format(arg);
if (!stream->ifmt) { if (!stream->ifmt) {
fprintf(stderr, "%s:%d: Unknown input format: %s\n", ERROR("Unknown input format: %s\n", arg);
filename, line_num, arg);
} }
} }
} else if (!strcasecmp(cmd, "FaviconURL")) { } else if (!strcasecmp(cmd, "FaviconURL")) {
if (stream && stream->stream_type == STREAM_TYPE_STATUS) { if (stream && stream->stream_type == STREAM_TYPE_STATUS) {
get_arg(stream->feed_filename, sizeof(stream->feed_filename), &p); get_arg(stream->feed_filename, sizeof(stream->feed_filename), &p);
} else { } else {
fprintf(stderr, "%s:%d: FaviconURL only permitted for status streams\n", ERROR("FaviconURL only permitted for status streams\n");
filename, line_num);
errors++;
} }
} else if (!strcasecmp(cmd, "Author")) { } else if (!strcasecmp(cmd, "Author")) {
if (stream) if (stream)
@ -4284,17 +4267,13 @@ static int parse_ffconfig(const char *filename)
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
audio_id = opt_audio_codec(arg); audio_id = opt_audio_codec(arg);
if (audio_id == CODEC_ID_NONE) { if (audio_id == CODEC_ID_NONE) {
fprintf(stderr, "%s:%d: Unknown AudioCodec: %s\n", ERROR("Unknown AudioCodec: %s\n", arg);
filename, line_num, arg);
errors++;
} }
} else if (!strcasecmp(cmd, "VideoCodec")) { } else if (!strcasecmp(cmd, "VideoCodec")) {
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
video_id = opt_video_codec(arg); video_id = opt_video_codec(arg);
if (video_id == CODEC_ID_NONE) { if (video_id == CODEC_ID_NONE) {
fprintf(stderr, "%s:%d: Unknown VideoCodec: %s\n", ERROR("Unknown VideoCodec: %s\n", arg);
filename, line_num, arg);
errors++;
} }
} else if (!strcasecmp(cmd, "MaxTime")) { } else if (!strcasecmp(cmd, "MaxTime")) {
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
@ -4327,9 +4306,7 @@ static int parse_ffconfig(const char *filename)
video_enc.rc_min_rate = minrate * 1000; video_enc.rc_min_rate = minrate * 1000;
video_enc.rc_max_rate = maxrate * 1000; video_enc.rc_max_rate = maxrate * 1000;
} else { } else {
fprintf(stderr, "%s:%d: Incorrect format for VideoBitRateRange -- should be <min>-<max>: %s\n", ERROR("Incorrect format for VideoBitRateRange -- should be <min>-<max>: %s\n", arg);
filename, line_num, arg);
errors++;
} }
} }
} else if (!strcasecmp(cmd, "Debug")) { } else if (!strcasecmp(cmd, "Debug")) {
@ -4363,9 +4340,7 @@ static int parse_ffconfig(const char *filename)
av_parse_video_frame_size(&video_enc.width, &video_enc.height, arg); av_parse_video_frame_size(&video_enc.width, &video_enc.height, arg);
if ((video_enc.width % 16) != 0 || if ((video_enc.width % 16) != 0 ||
(video_enc.height % 16) != 0) { (video_enc.height % 16) != 0) {
fprintf(stderr, "%s:%d: Image size must be a multiple of 16\n", ERROR("Image size must be a multiple of 16\n");
filename, line_num);
errors++;
} }
} }
} else if (!strcasecmp(cmd, "VideoFrameRate")) { } else if (!strcasecmp(cmd, "VideoFrameRate")) {
@ -4373,8 +4348,7 @@ static int parse_ffconfig(const char *filename)
if (stream) { if (stream) {
AVRational frame_rate; AVRational frame_rate;
if (av_parse_video_frame_rate(&frame_rate, arg) < 0) { if (av_parse_video_frame_rate(&frame_rate, arg) < 0) {
fprintf(stderr, "Incorrect frame rate\n"); ERROR("Incorrect frame rate: %s\n", arg);
errors++;
} else { } else {
video_enc.time_base.num = frame_rate.den; video_enc.time_base.num = frame_rate.den;
video_enc.time_base.den = frame_rate.num; video_enc.time_base.den = frame_rate.num;
@ -4410,8 +4384,7 @@ static int parse_ffconfig(const char *filename)
type = AV_OPT_FLAG_AUDIO_PARAM; type = AV_OPT_FLAG_AUDIO_PARAM;
} }
if (ffserver_opt_default(arg, arg2, avctx, type|AV_OPT_FLAG_ENCODING_PARAM)) { if (ffserver_opt_default(arg, arg2, avctx, type|AV_OPT_FLAG_ENCODING_PARAM)) {
fprintf(stderr, "AVOption error: %s %s\n", arg, arg2); ERROR("AVOption error: %s %s\n", arg, arg2);
errors++;
} }
} else if (!strcasecmp(cmd, "VideoTag")) { } else if (!strcasecmp(cmd, "VideoTag")) {
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
@ -4437,9 +4410,7 @@ static int parse_ffconfig(const char *filename)
if (stream) { if (stream) {
video_enc.max_qdiff = atoi(arg); video_enc.max_qdiff = atoi(arg);
if (video_enc.max_qdiff < 1 || video_enc.max_qdiff > 31) { if (video_enc.max_qdiff < 1 || video_enc.max_qdiff > 31) {
fprintf(stderr, "%s:%d: VideoQDiff out of range\n", ERROR("VideoQDiff out of range\n");
filename, line_num);
errors++;
} }
} }
} else if (!strcasecmp(cmd, "VideoQMax")) { } else if (!strcasecmp(cmd, "VideoQMax")) {
@ -4447,9 +4418,7 @@ static int parse_ffconfig(const char *filename)
if (stream) { if (stream) {
video_enc.qmax = atoi(arg); video_enc.qmax = atoi(arg);
if (video_enc.qmax < 1 || video_enc.qmax > 31) { if (video_enc.qmax < 1 || video_enc.qmax > 31) {
fprintf(stderr, "%s:%d: VideoQMax out of range\n", ERROR("VideoQMax out of range\n");
filename, line_num);
errors++;
} }
} }
} else if (!strcasecmp(cmd, "VideoQMin")) { } else if (!strcasecmp(cmd, "VideoQMin")) {
@ -4457,9 +4426,7 @@ static int parse_ffconfig(const char *filename)
if (stream) { if (stream) {
video_enc.qmin = atoi(arg); video_enc.qmin = atoi(arg);
if (video_enc.qmin < 1 || video_enc.qmin > 31) { if (video_enc.qmin < 1 || video_enc.qmin > 31) {
fprintf(stderr, "%s:%d: VideoQMin out of range\n", ERROR("VideoQMin out of range\n");
filename, line_num);
errors++;
} }
} }
} else if (!strcasecmp(cmd, "LumaElim")) { } else if (!strcasecmp(cmd, "LumaElim")) {
@ -4498,9 +4465,7 @@ static int parse_ffconfig(const char *filename)
get_arg(arg, sizeof(arg), &p); get_arg(arg, sizeof(arg), &p);
if (stream) { if (stream) {
if (resolve_host(&stream->multicast_ip, arg) != 0) { if (resolve_host(&stream->multicast_ip, arg) != 0) {
fprintf(stderr, "%s:%d: Invalid host/IP address: %s\n", ERROR("Invalid host/IP address: %s\n", arg);
filename, line_num, arg);
errors++;
} }
stream->is_multicast = 1; stream->is_multicast = 1;
stream->loop = 1; /* default is looping */ stream->loop = 1; /* default is looping */
@ -4518,9 +4483,7 @@ static int parse_ffconfig(const char *filename)
stream->loop = 0; stream->loop = 0;
} else if (!strcasecmp(cmd, "</Stream>")) { } else if (!strcasecmp(cmd, "</Stream>")) {
if (!stream) { if (!stream) {
fprintf(stderr, "%s:%d: No corresponding <Stream> for </Stream>\n", ERROR("No corresponding <Stream> for </Stream>\n");
filename, line_num);
errors++;
} else { } else {
if (stream->feed && stream->fmt && strcmp(stream->fmt->name, "ffm") != 0) { if (stream->feed && stream->fmt && strcmp(stream->fmt->name, "ffm") != 0) {
if (audio_id != CODEC_ID_NONE) { if (audio_id != CODEC_ID_NONE) {
@ -4540,9 +4503,7 @@ static int parse_ffconfig(const char *filename)
/*********************************************/ /*********************************************/
char *q; char *q;
if (stream || feed || redirect) { if (stream || feed || redirect) {
fprintf(stderr, "%s:%d: Already in a tag\n", ERROR("Already in a tag\n");
filename, line_num);
errors++;
} else { } else {
redirect = av_mallocz(sizeof(FFStream)); redirect = av_mallocz(sizeof(FFStream));
*last_stream = redirect; *last_stream = redirect;
@ -4559,14 +4520,10 @@ static int parse_ffconfig(const char *filename)
get_arg(redirect->feed_filename, sizeof(redirect->feed_filename), &p); get_arg(redirect->feed_filename, sizeof(redirect->feed_filename), &p);
} else if (!strcasecmp(cmd, "</Redirect>")) { } else if (!strcasecmp(cmd, "</Redirect>")) {
if (!redirect) { if (!redirect) {
fprintf(stderr, "%s:%d: No corresponding <Redirect> for </Redirect>\n", ERROR("No corresponding <Redirect> for </Redirect>\n");
filename, line_num);
errors++;
} else { } else {
if (!redirect->feed_filename[0]) { if (!redirect->feed_filename[0]) {
fprintf(stderr, "%s:%d: No URL found for <Redirect>\n", ERROR("No URL found for <Redirect>\n");
filename, line_num);
errors++;
} }
redirect = NULL; redirect = NULL;
} }
@ -4575,15 +4532,13 @@ static int parse_ffconfig(const char *filename)
#if HAVE_DLOPEN #if HAVE_DLOPEN
load_module(arg); load_module(arg);
#else #else
fprintf(stderr, "%s:%d: Module support not compiled into this version: '%s'\n", ERROR("Module support not compiled into this version: '%s'\n", arg);
filename, line_num, arg);
errors++;
#endif #endif
} else { } else {
fprintf(stderr, "%s:%d: Incorrect keyword: '%s'\n", ERROR("Incorrect keyword: '%s'\n", cmd);
filename, line_num, cmd);
} }
} }
#undef ERROR
fclose(f); fclose(f);
if (errors) if (errors)

Loading…
Cancel
Save