Index: conf.c =================================================================== --- conf.c (revisión: 433) +++ conf.c (copia de trabajo) @@ -115,7 +115,7 @@ on_event_end: NULL, mask_file: NULL, smart_mask_speed: 0, -#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) +#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) sql_log_image: 1, sql_log_snapshot: 1, sql_log_movie: 0, @@ -124,10 +124,13 @@ database_type: NULL, database_dbname: NULL, database_host: "localhost", - database_user: NULL, + database_user: NULL, database_password: NULL, database_port: 0, +#ifdef HAVE_SQLITE3 + sqlite3_db: NULL, #endif +#endif /* defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || define(HAVE_SQLITE3) */ on_picture_save: NULL, on_motion_detected: NULL, on_area_detected: NULL, @@ -1270,12 +1273,12 @@ print_string }, -#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) +#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) { "sql_log_picture", "\n############################################################\n" - "# Common Options For MySQL and PostgreSQL database features.\n" - "# Options require the MySQL/PostgreSQL options to be active also.\n" + "# Common Options for database features.\n" + "# Options require the database options to be active also.\n" "############################################################\n\n" "# Log to the database when creating motion triggered image file (default: on)", 0, @@ -1326,7 +1329,7 @@ "\n############################################################\n" "# Database Options \n" "############################################################\n\n" - "# database type : mysql, postgresql (default : not defined)", + "# database type : mysql, postgresql, sqlite3 (default : not defined)", 0, CONF_OFFSET(database_type), copy_string, @@ -1373,8 +1376,22 @@ copy_int, print_int }, -#endif /* defined(HAVE_MYSQL) || defined(HAVE_PGSQL) */ +#ifdef HAVE_SQLITE3 { + "sqlite3_db", + "\n############################################################\n" + "# Database Options For SQLite3\n" + "############################################################\n\n" + "# SQLite3 database to log to (default: not defined)", + 0, + CONF_OFFSET(sqlite3_db), + copy_string, + print_string + }, +#endif /* HAVE_SQLITE3 */ + +#endif /* defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) */ + { "video_pipe", "\n############################################################\n" "# Video Loopback Device (vloopback project)\n" Index: conf.h =================================================================== --- conf.h (revisión: 433) +++ conf.h (copia de trabajo) @@ -100,6 +100,7 @@ const char *database_host; const char *database_user; const char *database_password; + const char *sqlite3_db; int database_port; char *on_picture_save; char *on_area_detected; Index: configure.in =================================================================== --- configure.in (revisión: 433) +++ configure.in (copia de trabajo) @@ -446,6 +446,26 @@ # +# Check SQLITE3 +# + +SQLITE3_SUPPORT="no" +saved_CFLAGS=$CFLAGS +saved_LIBS=$LIBS + +AC_CHECK_LIB(sqlite3, sqlite3_open, +[ +TEMP_LIBS="$TEMP_LIBS -lsqlite3" +SQLITE3_SUPPORT="yes" +AC_DEFINE([HAVE_SQLITE3],1,[Define to 1 if you have SQLITE3 support]) +] +) + +CFLAGS=$saved_CFLAGS +LIBS=$saved_LIBS + + +# # Check Mysql # @@ -1168,6 +1188,12 @@ echo "FFmpeg Support: No" fi +if test "${SQLITE3_SUPPORT}" = "yes"; then + echo "SQLite3 Support: Yes" +else + echo "SQLite3 Support: No" +fi + if test "${MYSQL_SUPPORT}" = "yes"; then echo "MYSQL Support: Yes" else @@ -1181,10 +1207,12 @@ fi echo + echo "CFLAGS: $CFLAGS" echo "LIBS: $LIBS" echo "LDFLAGS: $LDFLAGS" + echo echo "Install prefix: $prefix" echo Index: motion.c =================================================================== --- motion.c (revisión: 433) +++ motion.c (copia de trabajo) @@ -768,9 +768,25 @@ #endif /* BSD */ #endif /*WITHOUT_V4L*/ -#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) +#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) if (cnt->conf.database_type) { + motion_log(LOG_INFO, 0, "%s: Database backend %s", __FUNCTION__, + cnt->conf.database_type); + +#ifdef HAVE_SQLITE3 + if ((!strcmp(cnt->conf.database_type, "sqlite3")) && cnt->conf.sqlite3_db) { + motion_log(LOG_INFO, 0, "%s: DB %s", __FUNCTION__, + cnt->conf.sqlite3_db); + if (sqlite3_open(cnt->conf.sqlite3_db, &cnt->database_sqlite3) != SQLITE_OK) { + motion_log(LOG_ERR, 0, "%s: Can't open database %s : %s\n", __FUNCTION__, + cnt->conf.sqlite3_db, sqlite3_errmsg(cnt->database_sqlite3)); + sqlite3_close(cnt->database_sqlite3); + exit(1); + } + } +#endif /* HAVE_SQLITE3 */ + #ifdef HAVE_MYSQL if ((!strcmp(cnt->conf.database_type, "mysql")) && (cnt->conf.database_dbname)) { cnt->database = (MYSQL *) mymalloc(sizeof(MYSQL)); @@ -824,7 +840,7 @@ cnt->conf.sql_log_timelapse * FTYPE_MPEG_TIMELAPSE; } -#endif /* defined(HAVE_MYSQL) || defined(HAVE_PGSQL) */ +#endif /* defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) */ /* Load the mask file if any */ if (cnt->conf.mask_file) { @@ -991,6 +1007,12 @@ free(cnt->eventtime_tm); cnt->eventtime_tm = NULL; } + +#ifdef HAVE_SQLITE3 + /* Close the SQLite database */ + if (cnt->conf.sqlite3_db) + sqlite3_close(cnt->database_sqlite3); +#endif /* HAVE_SQLITE3 */ } /** @@ -1982,7 +2004,8 @@ smartmask_ratio = 5 * cnt->lastrate * (11 - cnt->smartmask_speed); } -#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) +#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) + /* Set the sql mask file according to the SQL config options * We update it for every frame in case the config was updated * via remote control. @@ -1991,7 +2014,7 @@ cnt->conf.sql_log_snapshot * FTYPE_IMAGE_SNAPSHOT + cnt->conf.sql_log_movie * (FTYPE_MPEG + FTYPE_MPEG_MOTION) + cnt->conf.sql_log_timelapse * FTYPE_MPEG_TIMELAPSE; -#endif /* defined(HAVE_MYSQL) || defined(HAVE_PGSQL) */ +#endif /* defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) */ } Index: motion.h =================================================================== --- motion.h (revisión: 433) +++ motion.h (copia de trabajo) @@ -17,6 +17,11 @@ #include #endif +#ifdef HAVE_SQLITE3 +#include +#endif + + #include #include #define __USE_GNU @@ -371,10 +376,14 @@ struct stream stream; int stream_count; -#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) +#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) int sql_mask; #endif +#ifdef HAVE_SQLITE3 + sqlite3 *database_sqlite3; +#endif + #ifdef HAVE_MYSQL MYSQL *database; #endif Index: motion-dist.conf.in =================================================================== --- motion-dist.conf.in (revisión: 433) +++ motion-dist.conf.in (copia de trabajo) @@ -585,10 +585,10 @@ # Some hangs the motion thread. Some even hangs the PC! (default: none) ; on_camera_lost value -############################################################ -# Common Options For MySQL and PostgreSQL database features. -# Options require the MySQL/PostgreSQL options to be active also. -############################################################ +##################################################################### +# Common Options for database features. +# Options require database options to be active also. +##################################################################### # Log to the database when creating motion triggered picture file (default: on) ; sql_log_picture on @@ -616,7 +616,7 @@ # Database Options ############################################################ -# database type : mysql, postgresql (default : not defined) +# database type : mysql, postgresql, sqlite3 (default : not defined) ; database_type value # database to log to (default: not defined) @@ -635,7 +635,15 @@ # mysql 3306 , postgresql 5432 (default: not defined) ; database_port value +############################################################ +# Database Options For SQLite3 +############################################################ + +# SQLite3 database (file path) (default: not defined) +; sqlite3_db value + + ############################################################ # Video Loopback Device (vloopback project) ############################################################ Index: config.h.in =================================================================== --- config.h.in (revisión: 433) +++ config.h.in (copia de trabajo) @@ -18,6 +18,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have SQLITE3 support */ +#undef HAVE_SQLITE3 + /* Define to 1 if you have MySQL support */ #undef HAVE_MYSQL Index: event.c =================================================================== --- event.c (revisión: 433) +++ event.c (copia de trabajo) @@ -106,7 +106,7 @@ exec_command(cnt, cnt->conf.on_motion_detected, NULL, 0); } -#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) +#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED, unsigned char *dummy ATTRIBUTE_UNUSED, @@ -166,10 +166,22 @@ } } #endif /* HAVE_PGSQL */ + +#ifdef HAVE_SQLITE3 + if ((!strcmp(cnt->conf.database_type, "sqlite3")) && (cnt->conf.sqlite3_db)) { + int res; + char *errmsg = 0; + res = sqlite3_exec(cnt->database_sqlite3, sqlquery, NULL, 0, &errmsg); + if( res != SQLITE_OK ) { + motion_log(LOG_ERR, 0, "%s: SQLite error was %s", __FUNCTION__, errmsg); + sqlite3_free(errmsg); + } + } +#endif /* HAVE_SQLITE3 */ } } -#endif /* defined HAVE_MYSQL || defined HAVE_PGSQL */ +#endif /* defined HAVE_MYSQL || defined HAVE_PGSQL || defined(HAVE_SQLITE3) */ static void on_area_command(struct context *cnt, int type ATTRIBUTE_UNUSED, unsigned char *dummy1 ATTRIBUTE_UNUSED, @@ -710,7 +722,7 @@ }; struct event_handlers event_handlers[] = { -#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) +#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) { EVENT_FILECREATE, event_sqlnewfile