2013-12-14 02:27:07 +08:00
|
|
|
/*
|
|
|
|
* ZoneMinder regular expression class implementation, $Date$, $Revision$
|
|
|
|
* Copyright (C) 2001-2008 Philip Coombes
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-12-16 23:49:51 +08:00
|
|
|
#include "zm.h"
|
2013-12-14 02:27:07 +08:00
|
|
|
#include "zm_db.h"
|
|
|
|
|
|
|
|
#include "zm_storage.h"
|
|
|
|
|
2013-12-16 23:49:51 +08:00
|
|
|
#include <string.h>
|
2015-12-15 05:55:26 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-12-14 02:27:07 +08:00
|
|
|
Storage::Storage() {
|
2015-12-16 00:17:32 +08:00
|
|
|
Warning("Instantiating default Storage Object. Should not happen.");
|
|
|
|
id = 0;
|
|
|
|
strcpy(name, "Default");
|
2017-06-14 06:02:28 +08:00
|
|
|
if ( staticConfig.DIR_EVENTS[0] != '/' ) {
|
2016-09-28 19:10:20 +08:00
|
|
|
// not using an absolute path. Make it one by appending ZM_PATH_WEB
|
2017-06-14 06:02:28 +08:00
|
|
|
snprintf( path, sizeof (path), "%s/%s", staticConfig.PATH_WEB.c_str( ), staticConfig.DIR_EVENTS.c_str() );
|
2016-09-28 19:10:20 +08:00
|
|
|
} else {
|
2017-12-13 00:48:12 +08:00
|
|
|
strncpy(path, staticConfig.DIR_EVENTS.c_str(), sizeof(path)-1 );
|
2016-09-28 19:10:20 +08:00
|
|
|
}
|
2018-01-23 22:07:40 +08:00
|
|
|
scheme = MEDIUM;
|
|
|
|
scheme_str = "Medium";
|
2013-12-14 02:27:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Storage::Storage( MYSQL_ROW &dbrow ) {
|
|
|
|
unsigned int index = 0;
|
2015-12-15 05:55:26 +08:00
|
|
|
id = atoi( dbrow[index++] );
|
2017-12-13 00:48:12 +08:00
|
|
|
strncpy( name, dbrow[index++], sizeof(name)-1 );
|
|
|
|
strncpy( path, dbrow[index++], sizeof(path)-1 );
|
2017-12-19 01:52:26 +08:00
|
|
|
type_str = std::string(dbrow[index++]);
|
|
|
|
scheme_str = std::string(dbrow[index++]);
|
|
|
|
if ( scheme_str == "Deep" ) {
|
2017-12-20 00:01:03 +08:00
|
|
|
scheme = DEEP;
|
2017-12-19 01:52:26 +08:00
|
|
|
} else if ( scheme_str == "Medium" ) {
|
2017-12-20 00:01:03 +08:00
|
|
|
scheme = MEDIUM;
|
2017-12-19 01:52:26 +08:00
|
|
|
} else {
|
2017-12-20 00:01:03 +08:00
|
|
|
scheme = SHALLOW;
|
2017-12-19 01:52:26 +08:00
|
|
|
}
|
2013-12-14 02:27:07 +08:00
|
|
|
}
|
|
|
|
|
2015-12-15 22:39:29 +08:00
|
|
|
/* If a zero or invalid p_id is passed, then the old default path will be assumed. */
|
2013-12-16 23:49:51 +08:00
|
|
|
Storage::Storage( unsigned int p_id ) {
|
2015-12-16 00:17:32 +08:00
|
|
|
id = 0;
|
2015-12-15 05:55:26 +08:00
|
|
|
|
2015-12-15 22:39:29 +08:00
|
|
|
if ( p_id ) {
|
|
|
|
char sql[ZM_SQL_SML_BUFSIZ];
|
2017-12-19 01:52:26 +08:00
|
|
|
snprintf( sql, sizeof(sql), "SELECT Id, Name, Path, Type, Scheme from Storage WHERE Id=%d", p_id );
|
2016-09-25 21:31:20 +08:00
|
|
|
Debug(2,"Loading Storage for %d using %s", p_id, sql );
|
2016-04-20 23:56:58 +08:00
|
|
|
zmDbRow dbrow;
|
|
|
|
if ( ! dbrow.fetch( sql ) ) {
|
2015-12-15 22:39:29 +08:00
|
|
|
Error( "Unable to load storage area for id %d: %s", p_id, mysql_error( &dbconn ) );
|
|
|
|
} else {
|
|
|
|
unsigned int index = 0;
|
|
|
|
id = atoi( dbrow[index++] );
|
2017-12-19 01:52:26 +08:00
|
|
|
strncpy( name, dbrow[index++], sizeof(name)-1 );
|
|
|
|
strncpy( path, dbrow[index++], sizeof(path)-1 );
|
|
|
|
type_str = std::string(dbrow[index++]);
|
|
|
|
scheme_str = std::string(dbrow[index++]);
|
|
|
|
if ( scheme_str == "Deep" ) {
|
2017-12-20 00:01:03 +08:00
|
|
|
scheme = DEEP;
|
2017-12-19 01:52:26 +08:00
|
|
|
} else if ( scheme_str == "Medium" ) {
|
2017-12-20 00:01:03 +08:00
|
|
|
scheme = MEDIUM;
|
2017-12-19 01:52:26 +08:00
|
|
|
} else {
|
2017-12-20 00:01:03 +08:00
|
|
|
scheme = SHALLOW;
|
2017-12-19 01:52:26 +08:00
|
|
|
}
|
2016-09-25 21:31:20 +08:00
|
|
|
Debug( 1, "Loaded Storage area %d '%s'", id, this->Name() );
|
2015-12-15 22:39:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( ! id ) {
|
2017-06-14 06:02:28 +08:00
|
|
|
if ( staticConfig.DIR_EVENTS[0] != '/' ) {
|
2016-09-25 21:31:20 +08:00
|
|
|
// not using an absolute path. Make it one by appending ZM_PATH_WEB
|
2017-06-14 06:02:28 +08:00
|
|
|
snprintf( path, sizeof (path), "%s/%s", staticConfig.PATH_WEB.c_str( ), staticConfig.DIR_EVENTS.c_str() );
|
2016-09-25 21:31:20 +08:00
|
|
|
} else {
|
2017-12-13 00:48:12 +08:00
|
|
|
strncpy(path, staticConfig.DIR_EVENTS.c_str(), sizeof(path)-1 );
|
2016-09-25 21:31:20 +08:00
|
|
|
}
|
|
|
|
Debug(1,"No id passed to Storage constructor. Using default path %s instead", path );
|
2015-12-15 22:39:29 +08:00
|
|
|
strcpy(name, "Default");
|
2018-01-23 22:07:40 +08:00
|
|
|
scheme = MEDIUM;
|
|
|
|
scheme_str = "Medium";
|
2015-12-15 22:39:29 +08:00
|
|
|
}
|
2013-12-16 23:49:51 +08:00
|
|
|
}
|
|
|
|
|
2013-12-14 02:27:07 +08:00
|
|
|
Storage::~Storage() {
|
|
|
|
}
|