Skip to content

Commit

Permalink
Avoid logs flooding using some options of netcam_keepalive and try to…
Browse files Browse the repository at this point in the history
… discard images with weird header Content-Lenght 0.
  • Loading branch information
AngelCarpintero authored and AngelCarpintero committed Jan 4, 2010
1 parent 4bca8c1 commit 51f9a24
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Bugfixes
* V4L2 fourcc GRBG not supported, updated default value for v4l2_palette 17. (Isaac Richter)
http://www.lavrsen.dk/foswiki/bin/view/Motion/BugReport2009x10x29x222753
* Exit when image dimension are not modulo 16. (Angel Carpintero)
* Avoid logs flooding using some options of netcam_keepalive and try to discard images with
weird header Content-Lenght 0. (Angel Carpintero)

3.2.11.1 Sumary of Changes

Expand Down
12 changes: 11 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,17 @@ set-version:
@sed -i 's/.\/commit-version.sh/.\/version.sh/g' configure.in
./configure --with-developer-flags


help:
@echo "--------------------------------------------------------------------------------"
@echo "make Build motion from local copy in your computer"
@echo "make current Build last version of motion from svn"
@echo "make build-commit Build last version of motion and prepare to commit to svn"
@echo "make clean Clean objects"
@echo "make distclean Clean everything"
@echo "make install Install binary , examples , docs and config files"
@echo "make uninstall Uninstall all installed files"
@echo "--------------------------------------------------------------------------------"
@echo

################################################################################
# INSTALL installs all relevant files. #
Expand Down
18 changes: 9 additions & 9 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.64 for motion trunk-r475.
# Generated by GNU Autoconf 2.64 for motion trunk-r476.
#
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software
Expand Down Expand Up @@ -546,8 +546,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='motion'
PACKAGE_TARNAME='motion'
PACKAGE_VERSION='trunk-r475'
PACKAGE_STRING='motion trunk-r475'
PACKAGE_VERSION='trunk-r476'
PACKAGE_STRING='motion trunk-r476'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''

Expand Down Expand Up @@ -1210,7 +1210,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures motion trunk-r475 to adapt to many kinds of systems.
\`configure' configures motion trunk-r476 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1271,7 +1271,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of motion trunk-r475:";;
short | recursive ) echo "Configuration of motion trunk-r476:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1412,7 +1412,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
motion configure trunk-r475
motion configure trunk-r476
generated by GNU Autoconf 2.64
Copyright (C) 2009 Free Software Foundation, Inc.
Expand Down Expand Up @@ -2009,7 +2009,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by motion $as_me trunk-r475, which was
It was created by motion $as_me trunk-r476, which was
generated by GNU Autoconf 2.64. Invocation command line was
$ $0 $@
Expand Down Expand Up @@ -5790,7 +5790,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by motion $as_me trunk-r475, which was
This file was extended by motion $as_me trunk-r476, which was
generated by GNU Autoconf 2.64. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -5850,7 +5850,7 @@ Report bugs to the package provider."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_version="\\
motion config.status trunk-r475
motion config.status trunk-r476
configured by $0, generated by GNU Autoconf 2.64,
with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
Expand Down
64 changes: 53 additions & 11 deletions netcam.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ static int netcam_read_next_header(netcam_context_ptr netcam)
*
*/
netcam->caps.content_length = 0;

/*
* If this is a "streaming" camera, the stream header must be
* preceded by a "boundary" string
Expand All @@ -469,7 +470,7 @@ static int netcam_read_next_header(netcam_context_ptr netcam)
__FUNCTION__, header);
}

free(header);
free(header);
return -1;
}

Expand Down Expand Up @@ -501,12 +502,17 @@ static int netcam_read_next_header(netcam_context_ptr netcam)
}
}

if ((retval = (int) netcam_check_content_length(header)) > 0) {
retval = (int) netcam_check_content_length(header);
free(header);

if (retval > 0) {
netcam->caps.content_length = 1; /* set flag */
netcam->receiving->content_length = (int) retval;
netcam->receiving->content_length = retval;
} else {
netcam->receiving->content_length = 0;
motion_log(LOG_ERR, 0, "%s: Content-Length 0", __FUNCTION__);
return -1;
}

free(header);
}

if (debug_level > CAMERA_INFO)
Expand Down Expand Up @@ -602,7 +608,9 @@ static int netcam_read_first_header(netcam_context_ptr netcam)
/* But we do unset the netcam keepalive flag which was set in netcam_start */
/* This message is logged as Information as it would be useful to know */
/* if your netcam often returns bad HTTP result codes */
netcam->connect_keepalive = 0;
netcam->connect_keepalive = FALSE;
free((void *)netcam->cnt->conf.netcam_keepalive);
netcam->cnt->conf.netcam_keepalive = strdup("off");
motion_log(LOG_INFO, 0, "%s: Removed netcam Keep-Alive flag"
"due to apparent closed HTTP connection.", __FUNCTION__);
}
Expand Down Expand Up @@ -686,8 +694,14 @@ static int netcam_read_first_header(netcam_context_ptr netcam)
if (SETUP)
motion_log(LOG_DEBUG, 0, "%s: Content-length present", __FUNCTION__);

netcam->caps.content_length = 1; /* set flag */
netcam->receiving->content_length = ret;
if (ret > 0) {
netcam->caps.content_length = 1; /* set flag */
netcam->receiving->content_length = ret;
} else {
netcam->receiving->content_length = 0;
motion_log(LOG_ERR, 0, "%s: Content-length 0", __FUNCTION__);
retval = -2;
}
} else if (netcam_check_keepalive(header) == TRUE) {
/* Note that we have received a Keep-Alive header, and thus the socket can be left open */
aliveflag = TRUE;
Expand All @@ -714,6 +728,16 @@ static int netcam_read_first_header(netcam_context_ptr netcam)

if (aliveflag) {
if (closeflag) {
netcam->warning_count++;
if (netcam->warning_count > 3) {
netcam->warning_count = 0;
motion_log(LOG_INFO, 0, "%s: Info: Both 'Connection: Keep-Alive' and "
"'Connection: close' header received. Motion removes keepalive.",
__FUNCTION__);
netcam->connect_keepalive = FALSE;
free((void *)netcam->cnt->conf.netcam_keepalive);
netcam->cnt->conf.netcam_keepalive = strdup("off");
} else
/*
* If not a streaming cam, and keepalive is set, and the flag shows we
* did not see a Keep-Alive field returned from netcam and a Close field.
Expand All @@ -736,6 +760,16 @@ static int netcam_read_first_header(netcam_context_ptr netcam)
}
} else { /* !aliveflag */
if (!closeflag) {
netcam->warning_count++;

if (netcam->warning_count > 3) {
netcam->warning_count = 0;
motion_log(LOG_INFO, 0, "%s: No 'Connection: Keep-Alive' nor 'Connection: close' "
"header received.\n Motion removes keepalive.", __FUNCTION__);
netcam->connect_keepalive = FALSE;
free((void *)netcam->cnt->conf.netcam_keepalive);
netcam->cnt->conf.netcam_keepalive = strdup("off");
} else
/*
* If not a streaming cam, and keepalive is set, and the flag shows we
* did not see a Keep-Alive field returned from netcam nor a Close field.
Expand Down Expand Up @@ -767,6 +801,8 @@ static int netcam_read_first_header(netcam_context_ptr netcam)
*/
if (!netcam->keepalive_thisconn) {
netcam->connect_keepalive = FALSE; /* No further attempts at keep-alive */
free((void *)netcam->cnt->conf.netcam_keepalive);
netcam->cnt->conf.netcam_keepalive = strdup("off");
motion_log(LOG_INFO, 0, "%s: Removed netcam Keep-Alive flag because "
"'Connection: close' header received.\n Netcam does not support "
"Keep-Alive. Motion continues in non-Keep-Alive.", __FUNCTION__);
Expand Down Expand Up @@ -1076,6 +1112,8 @@ static void netcam_check_buffsize(netcam_buff_ptr buff, size_t numbytes)
* 1) If a Content-Length is present, set the variable "remaining"
* to be equal to that value, else set it to a "very large"
* number.
* WARNING !!! Content-Length *must* to be greater than 0, even more
* a jpeg image cannot be less than 300 bytes or so.
* 2) While there is more data available from the camera:
* a) If there is a "boundary string" specified (from the initial
* header):
Expand Down Expand Up @@ -1339,12 +1377,12 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam)
if (netcam->caps.streaming == NCS_UNSUPPORTED) {
if (!netcam->connect_keepalive) {
if (debug_level > CAMERA_INFO)
motion_log(LOG_DEBUG, 0, "%s: netcam_read_html_jpeg disconnecting "
motion_log(LOG_DEBUG, 0, "%s: disconnecting "
"netcam since keep-alive not set.", __FUNCTION__);

netcam_disconnect(netcam);
} else if (debug_level > CAMERA_INFO) {
motion_log(LOG_DEBUG, 0, "%s: netcam_read_html_jpeg leaving netcam connected.",
motion_log(LOG_DEBUG, 0, "%s: leaving netcam connected.",
__FUNCTION__);
}
}
Expand Down Expand Up @@ -2196,7 +2234,11 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url)
ptr = mymalloc(strlen(url->service) + strlen(url->host)
+ strlen(url->path) + 4);
sprintf((char *)ptr, "http://%s%s", url->host, url->path);
netcam->connect_keepalive = 0; /* Disable Keepalive if proxy */

netcam->connect_keepalive = FALSE; /* Disable Keepalive if proxy */
free((void *)netcam->cnt->conf.netcam_keepalive);
netcam->cnt->conf.netcam_keepalive = strdup("off");

if (debug_level > CAMERA_INFO)
motion_log(LOG_DEBUG, 0, "%s: Removed netcam_keepalive flag due to proxy set."
"Proxy is incompatible with Keep-Alive.", __FUNCTION__);
Expand Down
3 changes: 3 additions & 0 deletions netcam.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ typedef struct netcam_context {
int imgcnt_last; /* remember last count to check if a new
image arrived */

int warning_count; /* simple count of number of warnings
since last good frame was received */

int error_count; /* simple count of number of errors since
last good frame was received */

Expand Down

0 comments on commit 51f9a24

Please sign in to comment.