Updated to use fixed buffer sizes rather than relying on o/s defined.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@3189 e3e1d417-86f3-4887-817a-d78f3d33393f
pull/27/merge
stan 2010-11-11 12:22:35 +00:00
parent ca4358bfd6
commit 46d777398e
12 changed files with 44 additions and 38 deletions

View File

@ -236,9 +236,9 @@ Config::~Config()
void Config::Load()
{
static char sql[BUFSIZ];
strncpy( sql, "select Name, Value, Type from Config order by Id", sizeof(sql) );
static char sql[ZM_SQL_SML_BUFSIZ];
strncpy( sql, "select Name, Value, Type from Config order by Id", sizeof(sql) );
if ( mysql_query( &dbconn, sql ) )
{
Error( "Can't run query: %s", mysql_error( &dbconn ) );

View File

@ -34,6 +34,12 @@
#define ZM_SCALE_BASE 100 // The factor by which we bump up 'scale' to simulate FP
#define ZM_RATE_BASE 100 // The factor by which we bump up 'rate' to simulate FP
#define ZM_SQL_SML_BUFSIZ 256 // Size of SQL buffer
#define ZM_SQL_MED_BUFSIZ 1024 // Size of SQL buffer
#define ZM_SQL_LGE_BUFSIZ 8192 // Size of SQL buffer
#define ZM_NETWORK_BUFSIZ 32768 // Size of network buffer
#define ZM_MAX_FPS 30 // The maximum frame rate we expect to handle
#define ZM_SAMPLE_RATE int(1000000/ZM_MAX_FPS) // A general nyquist sample frequency for delays etc
#define ZM_SUSPENDED_RATE int(1000000/4) // A slower rate for when disabled etc

View File

@ -67,7 +67,7 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
gettimeofday( &start_time, 0 );
}
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
struct tm *stime = localtime( &start_time.tv_sec );
snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, Name, StartTime, Width, Height, Cause, Notes ) values ( %d, 'New Event', from_unixtime( %ld ), %d, %d, '%s', '%s' )", monitor->Id(), start_time.tv_sec, monitor->Width(), monitor->Height(), cause.c_str(), notes.c_str() );
@ -167,7 +167,7 @@ Event::~Event()
DELTA_TIMEVAL( delta_time, end_time, start_time, DT_PREC_2 );
Debug( 1, "Adding closing frame %d to DB", frames );
static char sql[BUFSIZ];
static char sql[ZM_SQL_SML_BUFSIZ];
snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, TimeStamp, Delta ) values ( %d, %d, from_unixtime( %ld ), %s%ld.%02ld )", id, frames, end_time.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec );
if ( mysql_query( &dbconn, sql ) )
{
@ -176,7 +176,7 @@ Event::~Event()
}
}
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
struct DeltaTimeval delta_time;
DELTA_TIMEVAL( delta_time, end_time, start_time, DT_PREC_2 );
@ -418,11 +418,11 @@ void Event::updateNotes( const StringSetMap &newNoteSetMap )
createNotes( notes );
Debug( 2, "Updating notes for event %d, '%s'", id, notes.c_str() );
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
#if USE_PREPARED_SQL
static MYSQL_STMT *stmt = 0;
char notesStr[BUFSIZ] = "";
char notesStr[ZM_SQL_MED_BUFSIZ] = "";
unsigned long notesLen = 0;
if ( !stmt )
@ -471,7 +471,7 @@ void Event::updateNotes( const StringSetMap &newNoteSetMap )
Fatal( "Unable to execute sql '%s': %s", sql, mysql_stmt_error(stmt) );
}
#else
static char escapedNotes[BUFSIZ];
static char escapedNotes[ZM_SQL_MED_BUFSIZ];
mysql_real_escape_string( &dbconn, escapedNotes, notes.c_str(), notes.length() );
@ -486,8 +486,8 @@ void Event::updateNotes( const StringSetMap &newNoteSetMap )
void Event::AddFrames( int n_frames, Image **images, struct timeval **timestamps )
{
static char sql[BUFSIZ];
strncpy( sql, "insert into Frames ( EventId, FrameId, TimeStamp, Delta ) values ", BUFSIZ );
static char sql[ZM_SQL_LGE_BUFSIZ];
strncpy( sql, "insert into Frames ( EventId, FrameId, TimeStamp, Delta ) values ", sizeof(sql) );
int frameCount = 0;
for ( int i = 0; i < n_frames; i++ )
{
@ -557,7 +557,7 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image *
const char *frame_type = score>0?"Alarm":(score<0?"Bulk":"Normal");
Debug( 1, "Adding frame %d to DB", frames );
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
snprintf( sql, sizeof(sql), "insert into Frames ( EventId, FrameId, Type, TimeStamp, Delta, Score ) values ( %d, %d, '%s', from_unixtime( %ld ), %s%ld.%02ld, %d )", id, frames, frame_type, timestamp.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, score );
if ( mysql_query( &dbconn, sql ) )
{
@ -641,7 +641,7 @@ void Event::AddFrame( Image *image, struct timeval timestamp, int score, Image *
bool EventStream::loadInitialEventData( int monitor_id, time_t event_time )
{
static char sql[BUFSIZ];
static char sql[ZM_SQL_SML_BUFSIZ];
snprintf( sql, sizeof(sql), "select Id from Events where MonitorId = %d and unix_timestamp( EndTime ) > %ld order by Id asc limit 1", monitor_id, event_time );
@ -713,7 +713,7 @@ bool EventStream::loadInitialEventData( int init_event_id, int init_frame_id )
bool EventStream::loadEventData( int event_id )
{
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
snprintf( sql, sizeof(sql), "select M.Id, M.Name, E.Frames, unix_timestamp( StartTime ) as StartTimestamp, max(F.Delta)-min(F.Delta) as Duration from Events as E inner join Monitors as M on E.MonitorId = M.Id inner join Frames as F on E.Id = F.EventId where E.Id = %d group by E.Id", event_id );
@ -1106,7 +1106,7 @@ void EventStream::processCommand( const CmdMsg *msg )
void EventStream::checkEventLoaded()
{
bool reload_event = false;
static char sql[BUFSIZ];
static char sql[ZM_SQL_SML_BUFSIZ];
if ( curr_frame_id <= 0 )
{

View File

@ -719,7 +719,7 @@ void Monitor::actionEnable()
{
shared_data->action |= RELOAD;
static char sql[BUFSIZ];
static char sql[ZM_SQL_SML_BUFSIZ];
snprintf( sql, sizeof(sql), "update Monitors set Enabled = 1 where Id = '%d'", id );
if ( mysql_query( &dbconn, sql ) )
{
@ -732,7 +732,7 @@ void Monitor::actionDisable()
{
shared_data->action |= RELOAD;
static char sql[BUFSIZ];
static char sql[ZM_SQL_SML_BUFSIZ];
snprintf( sql, sizeof(sql), "update Monitors set Enabled = 0 where Id = '%d'", id );
if ( mysql_query( &dbconn, sql ) )
{
@ -1545,7 +1545,7 @@ void Monitor::Reload()
closeEvent();
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
snprintf( sql, sizeof(sql), "select Function+0, Enabled, LinkedMonitors, EventPrefix, LabelFormat, LabelX, LabelY, WarmupCount, PreEventCount, PostEventCount, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion, SignalCheckColour from Monitors where Id = '%d'", id );
if ( mysql_query( &dbconn, sql ) )
{
@ -1693,9 +1693,9 @@ void Monitor::ReloadLinkedMonitors( const char *p_linked_monitors )
linked_monitors = new MonitorLink *[n_linked_monitors];
for ( int i = 0; i < n_linked_monitors; i++ )
{
static char sql[BUFSIZ];
Debug( 1, "Checking linked monitor %d", link_ids[i] );
static char sql[ZM_SQL_SML_BUFSIZ];
snprintf( sql, sizeof(sql), "select Id, Name from Monitors where Id = %d and Function != 'None' and Function != 'Monitor' and Enabled = 1", link_ids[i] );
if ( mysql_query( &dbconn, sql ) )
{
@ -1728,7 +1728,7 @@ void Monitor::ReloadLinkedMonitors( const char *p_linked_monitors )
int Monitor::LoadLocalMonitors( const char *device, Monitor **&monitors, Purpose purpose )
{
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
if ( !device[0] )
{
strncpy( sql, "select Id, Name, Function+0, Enabled, LinkedMonitors, Device, Channel, Format, Method, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion, SignalCheckColour from Monitors where Function != 'None' and Type = 'Local' order by Device, Channel", sizeof(sql) );
@ -1867,7 +1867,7 @@ int Monitor::LoadLocalMonitors( const char *device, Monitor **&monitors, Purpose
int Monitor::LoadRemoteMonitors( const char *protocol, const char *host, const char *port, const char *path, Monitor **&monitors, Purpose purpose )
{
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
if ( !protocol )
{
strncpy( sql, "select Id, Name, Function+0, Enabled, LinkedMonitors, Protocol, Method, Host, Port, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'Remote'", sizeof(sql) );
@ -2029,7 +2029,7 @@ int Monitor::LoadRemoteMonitors( const char *protocol, const char *host, const c
int Monitor::LoadFileMonitors( const char *file, Monitor **&monitors, Purpose purpose )
{
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
if ( !file[0] )
{
strncpy( sql, "select Id, Name, Function+0, Enabled, LinkedMonitors, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'File'", sizeof(sql) );
@ -2157,7 +2157,7 @@ int Monitor::LoadFileMonitors( const char *file, Monitor **&monitors, Purpose pu
#if HAVE_LIBAVFORMAT
int Monitor::LoadFfmpegMonitors( const char *file, Monitor **&monitors, Purpose purpose )
{
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
if ( !file[0] )
{
strncpy( sql, "select Id, Name, Function+0, Enabled, LinkedMonitors, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion from Monitors where Function != 'None' and Type = 'File'", sizeof(sql) );
@ -2285,7 +2285,7 @@ int Monitor::LoadFfmpegMonitors( const char *file, Monitor **&monitors, Purpose
Monitor *Monitor::Load( int id, bool load_zones, Purpose purpose )
{
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
snprintf( sql, sizeof(sql), "select Id, Name, Type, Function+0, Enabled, LinkedMonitors, Device, Channel, Format, Protocol, Method, Host, Port, Path, Width, Height, Palette, Orientation+0, Brightness, Contrast, Hue, Colour, EventPrefix, LabelFormat, LabelX, LabelY, ImageBufferCount, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, SectionLength, FrameSkip, MaxFPS, AlarmMaxFPS, FPSReportInterval, RefBlendPerc, TrackMotion, SignalCheckColour from Monitors where Id = %d", id );
if ( mysql_query( &dbconn, sql ) )
{

View File

@ -176,7 +176,7 @@ int RemoteCameraHttp::ReadData( Buffer &buffer, int bytes_expected )
int total_bytes_read = 0;
do
{
static unsigned char temp_buffer[5*BUFSIZ];
static unsigned char temp_buffer[ZM_NETWORK_BUFSIZ];
int bytes_to_read = total_bytes_to_read>sizeof(temp_buffer)?sizeof(temp_buffer):total_bytes_to_read;
int bytes_read = read( sd, temp_buffer, bytes_to_read );

View File

@ -291,7 +291,7 @@ int RtpCtrlThread::run()
Select select( 10 );
select.addReader( &rtpCtrlServer );
unsigned char buffer[BUFSIZ];
unsigned char buffer[ZM_NETWORK_BUFSIZ];
while ( !mStop && select.wait() >= 0 )
{
if ( mStop )

View File

@ -78,7 +78,7 @@ int RtpDataThread::run()
Select select( 3 );
select.addReader( &rtpDataSocket );
unsigned char buffer[BUFSIZ];
unsigned char buffer[ZM_NETWORK_BUFSIZ];
while ( !mStop && select.wait() >= 0 )
{
if ( mStop )

View File

@ -72,7 +72,7 @@ bool RtspThread::recvResponse( std::string &response )
Debug( 2, "Received RTSP response: %s (%zd bytes)", response.c_str(), response.size() );
float respVer = 0;
int respCode = -1;
char respText[BUFSIZ];
char respText[ZM_NETWORK_BUFSIZ];
if ( sscanf( response.c_str(), "RTSP/%f %3d %[^\r\n]\r\n", &respVer, &respCode, respText ) != 3 )
{
if ( isalnum(response[0]) )
@ -99,7 +99,7 @@ int RtspThread::requestPorts()
{
if ( !smMinDataPort )
{
char sql[BUFSIZ];
char sql[ZM_SQL_SML_BUFSIZ];
strncpy( sql, "select Id from Monitors where Function != 'None' and Type = 'Remote' and Protocol = 'rtsp' and Method = 'rtpUni' order by Id asc", sizeof(sql) );
if ( mysql_query( &dbconn, sql ) )
{
@ -202,7 +202,7 @@ int RtspThread::run()
std::string message;
std::string response;
response.reserve( BUFSIZ );
response.reserve( ZM_NETWORK_BUFSIZ );
if ( !mRtspSocket.connect( mHost.c_str(), strtol( mPort.c_str(), NULL, 10 ) ) )
Fatal( "Unable to connect RTSP socket" );
@ -550,7 +550,7 @@ int RtspThread::run()
Select select( double(config.http_timeout)/1000.0 );
select.addReader( &mRtspSocket );
Buffer buffer( 10*BUFSIZ );
Buffer buffer( ZM_NETWORK_BUFSIZ );
time_t lastKeepalive = time(NULL);
std::string keepaliveMessage = "OPTIONS * RTSP/1.0\r\n";
std::string keepaliveResponse = "RTSP/1.0 200 OK\r\n";
@ -563,7 +563,7 @@ int RtspThread::run()
break;
}
static char tempBuffer[10*BUFSIZ];
static char tempBuffer[ZM_NETWORK_BUFSIZ];
ssize_t nBytes = mRtspSocket.recv( tempBuffer, sizeof(tempBuffer) );
buffer.append( tempBuffer, nBytes );
Debug( 4, "Read %zd bytes on sd %d, %d total", nBytes, mRtspSocket.getReadDesc(), buffer.size() );

View File

@ -103,7 +103,7 @@ bool User::canAccess( int monitor_id )
// Function to load a user from username and password
User *zmLoadUser( const char *username, const char *password )
{
char sql[BUFSIZ] = "";
char sql[ZM_SQL_SML_BUFSIZ] = "";
if ( password )
{
@ -170,7 +170,7 @@ User *zmLoadAuthUser( const char *auth, bool use_remote_addr )
}
Debug( 1, "Attempting to authenticate user from auth string '%s'", auth );
char sql[BUFSIZ] = "";
char sql[ZM_SQL_SML_BUFSIZ] = "";
snprintf( sql, sizeof(sql), "select Username, Password, Enabled, Stream+0, Events+0, Control+0, Monitors+0, System+0, MonitorIds from Users where Enabled = 1" );
if ( mysql_query( &dbconn, sql ) )

View File

@ -104,7 +104,7 @@ Zone::~Zone()
void Zone::RecordStats( const Event *event )
{
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
snprintf( sql, sizeof(sql), "insert into Stats set MonitorId=%d, ZoneId=%d, EventId=%d, FrameId=%d, PixelDiff=%d, AlarmPixels=%d, FilterPixels=%d, BlobPixels=%d, Blobs=%d, MinBlobSize=%d, MaxBlobSize=%d, MinX=%d, MinY=%d, MaxX=%d, MaxY=%d, Score=%d", monitor->Id(), id, event->Id(), event->Frames()+1, pixel_diff, alarm_pixels, alarm_filter_pixels, alarm_blob_pixels, alarm_blobs, min_blob_size, max_blob_size, alarm_box.LoX(), alarm_box.LoY(), alarm_box.HiX(), alarm_box.HiY(), score );
if ( mysql_query( &dbconn, sql ) )
{
@ -874,7 +874,7 @@ bool Zone::ParseZoneString( const char *zone_string, int &zone_id, int &colour,
int Zone::Load( Monitor *monitor, Zone **&zones )
{
static char sql[BUFSIZ];
static char sql[ZM_SQL_MED_BUFSIZ];
snprintf( sql, sizeof(sql), "select Id,Name,Type+0,Units,NumCoords,Coords,AlarmRGB,CheckMethod+0,MinPixelThreshold,MaxPixelThreshold,MinAlarmPixels,MaxAlarmPixels,FilterX,FilterY,MinFilterPixels,MaxFilterPixels,MinBlobPixels,MaxBlobPixels,MinBlobs,MaxBlobs,OverloadFrames from Zones where MonitorId = %d order by Type, Id", monitor->Id() );
if ( mysql_query( &dbconn, sql ) )
{

View File

@ -137,7 +137,7 @@ int main( int argc, char *argv[] )
zmLoadConfig();
// Only do registered devices
static char sql[BUFSIZ];
static char sql[ZM_SQL_SML_BUFSIZ];
snprintf( sql, sizeof(sql), "select distinct Device from Monitors where not isnull(Device) and Type = 'Local'" );
if ( mysql_query( &dbconn, sql ) )
{

View File

@ -666,7 +666,7 @@ int main( int argc, char *argv[] )
if ( function & ZMU_LIST )
{
char sql[BUFSIZ];
char sql[ZM_SQL_SML_BUFSIZ];
strncpy( sql, "select Id, Function+0 from Monitors", sizeof(sql) );
if ( !verbose )
{