2002-09-24 06:08:50 +08:00
|
|
|
//
|
2002-12-10 21:21:41 +08:00
|
|
|
// ZoneMinder Streaming Server, $Date$, $Revision$
|
2003-01-12 02:22:27 +08:00
|
|
|
// Copyright (C) 2003 Philip Coombes
|
2002-09-24 06:08:50 +08:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
//
|
|
|
|
|
2002-09-16 17:19:24 +08:00
|
|
|
#include "zm.h"
|
|
|
|
|
2002-10-28 22:33:57 +08:00
|
|
|
int main( int argc, const char *argv[] )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
|
|
|
int id = 1;
|
|
|
|
unsigned long idle = 5000;
|
|
|
|
unsigned long refresh = 50;
|
|
|
|
int event = 0;
|
|
|
|
char *path = ".";
|
|
|
|
|
|
|
|
const char *query = getenv( "QUERY_STRING" );
|
|
|
|
if ( query )
|
|
|
|
{
|
|
|
|
char temp_query[256];
|
|
|
|
strcpy( temp_query, query );
|
|
|
|
char *q_ptr = temp_query;
|
|
|
|
char *parms[8]; // Shouldn't be more than this
|
|
|
|
int parm_no = 0;
|
|
|
|
while( parms[parm_no] = strtok( q_ptr, "&" ) )
|
|
|
|
{
|
|
|
|
parm_no++;
|
|
|
|
q_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( int p = 0; p < parm_no; p++ )
|
|
|
|
{
|
|
|
|
char *name = strtok( parms[p], "=" );
|
|
|
|
char *value = strtok( NULL, "=" );
|
|
|
|
if ( !strcmp( name, "refresh" ) )
|
|
|
|
refresh = atol( value );
|
|
|
|
else if ( !strcmp( name, "idle" ) )
|
|
|
|
idle = atol( value );
|
|
|
|
else if ( !strcmp( name, "monitor" ) )
|
|
|
|
id = atoi( value );
|
|
|
|
else if ( !strcmp( name, "event" ) )
|
|
|
|
event = atoi( value );
|
|
|
|
else if ( !strcmp( name, "path" ) )
|
|
|
|
path = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dbg_name = "zms";
|
|
|
|
|
|
|
|
DbgInit();
|
|
|
|
|
|
|
|
if ( !mysql_init( &dbconn ) )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Can't initialise structure: %s\n", mysql_error( &dbconn ) );
|
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
2003-01-11 01:03:03 +08:00
|
|
|
if ( !mysql_connect( &dbconn, ZM_DB_SERVER, ZM_DB_USERB, ZM_DB_PASSB ) )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
|
|
|
fprintf( stderr, "Can't connect to server: %s\n", mysql_error( &dbconn ) );
|
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
2003-01-11 01:03:03 +08:00
|
|
|
if ( mysql_select_db( &dbconn, ZM_DB_NAME ) )
|
2002-09-16 17:19:24 +08:00
|
|
|
{
|
|
|
|
fprintf( stderr, "Can't select database: %s\n", mysql_error( &dbconn ) );
|
|
|
|
exit( mysql_errno( &dbconn ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !event )
|
|
|
|
{
|
|
|
|
Monitor *monitor = Monitor::Load( id );
|
|
|
|
|
|
|
|
if ( monitor )
|
|
|
|
monitor->StreamImages( idle, refresh, stdout );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Event::StreamEvent( path, event, refresh, stdout );
|
|
|
|
}
|
2002-10-28 22:33:57 +08:00
|
|
|
return( 0 );
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|