2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
// ZoneMinder Remote Camera Class Interface, $Date$, $Revision$
|
2006-01-17 18:56:30 +08:00
|
|
|
// Copyright (C) 2003, 2004, 2005, 2006 Philip Coombes
|
2003-03-26 19:57:29 +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.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ZM_REMOTE_CAMERA_H
|
|
|
|
#define ZM_REMOTE_CAMERA_H
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include "zm_camera.h"
|
2004-03-13 22:07:57 +08:00
|
|
|
#include "zm_buffer.h"
|
|
|
|
#include "zm_regexp.h"
|
2003-03-26 19:57:29 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// Class representing 'remote' cameras, i.e. those which are
|
|
|
|
// accessed over a network connection.
|
|
|
|
//
|
|
|
|
class RemoteCamera : public Camera
|
|
|
|
{
|
|
|
|
protected:
|
2004-02-16 03:17:38 +08:00
|
|
|
const char *host;
|
|
|
|
const char *port;
|
|
|
|
const char *path;
|
|
|
|
const char *auth;
|
|
|
|
char auth64[256];
|
2003-03-26 19:57:29 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
char request[1024];
|
|
|
|
struct timeval timeout;
|
|
|
|
struct hostent *hp;
|
|
|
|
struct sockaddr_in sa;
|
|
|
|
int sd;
|
2004-03-13 22:07:57 +08:00
|
|
|
Buffer buffer;
|
2006-01-20 23:20:07 +08:00
|
|
|
enum { SINGLE_IMAGE, MULTI_IMAGE } mode;
|
2006-01-20 23:27:48 +08:00
|
|
|
enum { UNDEF, JPEG, X_RGB, X_RGBZ } format;
|
2005-05-14 22:40:17 +08:00
|
|
|
enum { HEADER, HEADERCONT, SUBHEADER, SUBHEADERCONT, CONTENT } state;
|
2003-03-26 19:57:29 +08:00
|
|
|
|
2004-02-16 03:17:38 +08:00
|
|
|
protected:
|
|
|
|
static void Base64Encode( const char *in_string, char *out_string );
|
2005-06-13 01:06:58 +08:00
|
|
|
inline static char *mempbrk( register const char *s, const char *accept, size_t limit )
|
2005-05-14 22:40:17 +08:00
|
|
|
{
|
2005-06-13 01:06:58 +08:00
|
|
|
if ( limit <= 0 || !s || !accept || !*accept )
|
2005-05-14 22:40:17 +08:00
|
|
|
return( 0 );
|
|
|
|
|
|
|
|
register int i,j;
|
|
|
|
size_t acc_len = strlen( accept );
|
|
|
|
|
|
|
|
for ( i = 0; i < limit; s++, i++ )
|
|
|
|
{
|
|
|
|
for ( j = 0; j < acc_len; j++ )
|
|
|
|
{
|
|
|
|
if ( *s == accept[j] )
|
|
|
|
{
|
|
|
|
return( (char *)s );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( 0 );
|
|
|
|
}
|
2005-06-13 01:06:58 +08:00
|
|
|
inline static char *memstr( register const char *s, const char *n, size_t limit )
|
2005-05-14 22:40:17 +08:00
|
|
|
{
|
2005-06-13 01:06:58 +08:00
|
|
|
if ( limit <= 0 || !s || !n )
|
|
|
|
return( 0 );
|
|
|
|
|
|
|
|
if ( !*n )
|
|
|
|
return( (char *)s );
|
|
|
|
|
|
|
|
register int i,j,k;
|
|
|
|
size_t n_len = strlen( n );
|
|
|
|
|
|
|
|
for ( i = 0; i < limit; i++, s++ )
|
|
|
|
{
|
|
|
|
if ( *s != *n )
|
|
|
|
continue;
|
|
|
|
j = 1;
|
|
|
|
k = 1;
|
|
|
|
while ( true )
|
|
|
|
{
|
|
|
|
if ( k >= n_len )
|
|
|
|
return( (char *)s );
|
|
|
|
if ( s[j++] != n[k++] )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
inline static size_t memspn( register const char *s, const char *accept, size_t limit )
|
|
|
|
{
|
|
|
|
if ( limit <= 0 || !s || !accept || !*accept )
|
2005-05-14 22:40:17 +08:00
|
|
|
return( 0 );
|
|
|
|
|
|
|
|
register int i,j;
|
|
|
|
size_t acc_len = strlen( accept );
|
|
|
|
|
|
|
|
for ( i = 0; i < limit; s++, i++ )
|
|
|
|
{
|
|
|
|
register bool found = false;
|
|
|
|
for ( j = 0; j < acc_len; j++ )
|
|
|
|
{
|
|
|
|
if ( *s == accept[j] )
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( !found )
|
|
|
|
{
|
|
|
|
return( i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( limit );
|
|
|
|
}
|
2005-06-13 01:06:58 +08:00
|
|
|
inline static size_t memcspn( register const char *s, const char *reject, size_t limit )
|
2005-05-14 22:40:17 +08:00
|
|
|
{
|
2005-06-13 01:06:58 +08:00
|
|
|
if ( limit <= 0 || !s || !reject )
|
2005-05-14 22:40:17 +08:00
|
|
|
return( 0 );
|
|
|
|
|
2005-06-13 01:06:58 +08:00
|
|
|
if ( !*reject )
|
|
|
|
return( limit );
|
|
|
|
|
2005-05-14 22:40:17 +08:00
|
|
|
register int i,j;
|
|
|
|
size_t rej_len = strlen( reject );
|
|
|
|
|
|
|
|
for ( i = 0; i < limit; s++, i++ )
|
|
|
|
{
|
|
|
|
for ( j = 0; j < rej_len; j++ )
|
|
|
|
{
|
|
|
|
if ( *s == reject[j] )
|
|
|
|
{
|
|
|
|
return( i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( limit );
|
|
|
|
}
|
2004-02-16 03:17:38 +08:00
|
|
|
|
2003-03-26 19:57:29 +08:00
|
|
|
public:
|
2004-09-26 00:37:41 +08:00
|
|
|
RemoteCamera( const char *p_host, const char *p_port, const char *p_path, int p_width, int p_height, int p_palette, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture=true );
|
2003-03-26 19:57:29 +08:00
|
|
|
~RemoteCamera();
|
|
|
|
|
|
|
|
const char *Host() const { return( host ); }
|
|
|
|
const char *Port() const { return( port ); }
|
|
|
|
const char *Path() const { return( path ); }
|
2004-02-16 03:17:38 +08:00
|
|
|
const char *Auth() const { return( auth ); }
|
2003-03-26 19:57:29 +08:00
|
|
|
|
|
|
|
void Initialise();
|
|
|
|
void Terminate() { Disconnect(); }
|
|
|
|
int Connect();
|
|
|
|
int Disconnect();
|
|
|
|
int SendRequest();
|
2005-05-14 22:40:17 +08:00
|
|
|
int ReadData( Buffer &buffer, int bytes_expected=0 );
|
2004-03-13 22:07:57 +08:00
|
|
|
int GetResponse();
|
2003-03-26 19:57:29 +08:00
|
|
|
int PreCapture();
|
|
|
|
int PostCapture( Image &image );
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ZM_REMOTE_CAMERA_H
|