From 9fc320fbf7c8c689c59854a35be27d905179a181 Mon Sep 17 00:00:00 2001 From: stan Date: Thu, 5 Feb 2004 21:58:44 +0000 Subject: [PATCH] Fixed path problem when streaming. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@814 e3e1d417-86f3-4887-817a-d78f3d33393f --- src/zm_config.h.z | 1 + src/zm_event.cpp | 34 ++++++++++++++++++++++++++++++---- src/zm_event.h | 2 +- src/zms.cpp | 5 +---- web/zm_html_view_event.php | 2 +- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/zm_config.h.z b/src/zm_config.h.z index b405dd72c..6050478f6 100644 --- a/src/zm_config.h.z +++ b/src/zm_config.h.z @@ -27,6 +27,7 @@ #define ZM_DB_PASSA "" // Privileged DB user password #define ZM_DB_USERB "" // Unprivileged DB user name, need just select privilege. #define ZM_DB_PASSB "" // Unprivileged DB user password +#define ZM_PATH_WEB "" // Path to web files #define ZM_MAX_IMAGE_WIDTH 2048 // The largest image we imagine ever handling #define ZM_MAX_IMAGE_HEIGHT 1536 // The largest image we imagine ever handling diff --git a/src/zm_event.cpp b/src/zm_event.cpp index c4fe91fe2..e34f7e845 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -319,11 +319,12 @@ void Event::AddFrame( struct timeval timestamp, const Image *image, unsigned int } } -void Event::StreamEvent( const char *path, int event_id, int rate, int scale, FILE *fd ) +void Event::StreamEvent( int event_id, int rate, int scale, FILE *fd ) { static char sql[BUFSIZ]; + static char eventpath[PATH_MAX]; - sprintf( sql, "select Id, EventId, Delta from Frames where EventId = %d order by Id", event_id ); + sprintf( sql, "select M.Id, M.Name from Events as E inner join Monitors as M on E.MonitorId = M.Id where E.Id = %d", event_id ); if ( mysql_query( &dbconn, sql ) ) { Error(( "Can't run query: %s", mysql_error( &dbconn ) )); @@ -336,6 +337,31 @@ void Event::StreamEvent( const char *path, int event_id, int rate, int scale, FI Error(( "Can't use query result: %s", mysql_error( &dbconn ) )); exit( mysql_errno( &dbconn ) ); } + MYSQL_ROW dbrow = mysql_fetch_row( result ); + + if ( mysql_errno( &dbconn ) ) + { + Error(( "Can't fetch row: %s", mysql_error( &dbconn ) )); + exit( mysql_errno( &dbconn ) ); + } + + sprintf( eventpath, "%s/%s/%s/%d", ZM_PATH_WEB, (const char *)config.Item( ZM_DIR_EVENTS ), dbrow[1], event_id ); + + mysql_free_result( result ); + + sprintf( sql, "select FrameId, EventId, Delta from Frames where EventId = %d order by FrameId", event_id ); + if ( mysql_query( &dbconn, sql ) ) + { + Error(( "Can't run query: %s", mysql_error( &dbconn ) )); + exit( mysql_errno( &dbconn ) ); + } + + result = mysql_store_result( &dbconn ); + if ( !result ) + { + Error(( "Can't use query result: %s", mysql_error( &dbconn ) )); + exit( mysql_errno( &dbconn ) ); + } setbuf( fd, 0 ); @@ -364,7 +390,7 @@ void Event::StreamEvent( const char *path, int event_id, int rate, int scale, FI struct DeltaTimeval delta_time; gettimeofday( &now, &dummy_tz ); - for( int i = 0; MYSQL_ROW dbrow = mysql_fetch_row( result ); i++ ) + for( int i = 0; dbrow = mysql_fetch_row( result ); i++ ) { if ( rate ) { @@ -390,7 +416,7 @@ void Event::StreamEvent( const char *path, int event_id, int rate, int scale, FI gettimeofday( &last_now, &dummy_tz ); } static char filepath[PATH_MAX]; - sprintf( filepath, "%s/%03d-capture.jpg", path, dbrow[0] ); + sprintf( filepath, "%s/%03d-capture.jpg", eventpath, atoi(dbrow[0]) ); fprintf( fd, "Content-type: image/jpg\n\n" ); if ( scale == 1 ) diff --git a/src/zm_event.h b/src/zm_event.h index 056e04987..410a99212 100644 --- a/src/zm_event.h +++ b/src/zm_event.h @@ -83,7 +83,7 @@ public: void AddFrames( int n_frames, struct timeval **timestamps, const Image **images ); void AddFrame( struct timeval timestamp, const Image *image, unsigned int score=0, const Image *alarm_frame=NULL ); - static void StreamEvent( const char *path, int event_id, int rate=1, int scale=1, FILE *fd=stdout ); + static void StreamEvent( int event_id, int rate=1, int scale=1, FILE *fd=stdout ); }; #endif // ZM_EVENT_H diff --git a/src/zms.cpp b/src/zms.cpp index 865ed0347..ffc2c8798 100644 --- a/src/zms.cpp +++ b/src/zms.cpp @@ -29,7 +29,6 @@ int main(void ) unsigned int rate = 1; unsigned int scale = 1; int event = 0; - const char *path = "."; unsigned int ttl = 0; //setbuf( fd, 0 ); @@ -66,8 +65,6 @@ int main(void ) id = atoi( value ); else if ( !strcmp( name, "event" ) ) event = strtoull( value, (char **)NULL, 10 ); - else if ( !strcmp( name, "path" ) ) - path = value; else if ( !strcmp( name, "ttl" ) ) ttl = atoi(value); } @@ -90,7 +87,7 @@ int main(void ) } else { - Event::StreamEvent( path, event, rate, scale, stdout ); + Event::StreamEvent( event, rate, scale, stdout ); } return( 0 ); } diff --git a/web/zm_html_view_event.php b/web/zm_html_view_event.php index 216eba7cf..6ce95179b 100644 --- a/web/zm_html_view_event.php +++ b/web/zm_html_view_event.php @@ -233,7 +233,7 @@ if ( $mode == "still" && $paged && !empty($page) )