You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
4.2 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __CORE_MODULES_ASSEMBLY_
  2. #define __CORE_MODULES_ASSEMBLY_
  3. //#define _REENTRANT
  4. #define _ENABLE_LOG_MESSAGES_
  5. #include <stdlib.h>
  6. #include <iostream>
  7. #include <vector>
  8. #include <map>
  9. #include <stdio.h>
  10. #include <errno.h>
  11. #include <string.h>
  12. #include <strings.h>
  13. #include <unistd.h>
  14. #include <netdb.h>
  15. #include <fcntl.h>
  16. #include <signal.h>
  17. #include <netinet/in.h>
  18. #include <arpa/inet.h>
  19. //#include <linux/tcp.h>
  20. #include <netinet/tcp.h>
  21. #include <netdb.h>
  22. #include <pthread.h>
  23. #include <ncurses.h>
  24. #include <stddef.h>
  25. #include <assert.h>
  26. #include <locale.h>
  27. #include <getopt.h>
  28. #include <sys/types.h>
  29. #include <sys/stat.h>
  30. #include <sys/ipc.h>
  31. #include <sys/sem.h>
  32. #include <sys/types.h>
  33. #include <sys/ioctl.h>
  34. #include <sys/syscall.h>
  35. #include <sys/socket.h>
  36. #include <sys/time.h>
  37. #include <mysql/mysql.h>
  38. #include <time.h>
  39. #include <math.h>
  40. #include <stdlib.h>
  41. #include <stdio.h>
  42. #include <string.h>
  43. #include <time.h>
  44. #include <dirent.h>
  45. #include <sys/types.h>
  46. #include <ifaddrs.h>
  47. #include <sys/statvfs.h>
  48. //#include <curl/curl.h>
  49. // Default Data Types
  50. using namespace std;
  51. typedef unsigned short U16;
  52. typedef unsigned int U32;
  53. typedef unsigned char U8;
  54. typedef unsigned long long U64;
  55. typedef char * CSTR;
  56. //typedef map < char *, char * > Assoc;
  57. typedef map < string, string > Assoc;
  58. typedef vector < Assoc * > AAssoc;
  59. typedef vector < string * > SArray;
  60. typedef vector < CSTR > CArray;
  61. typedef vector < char * > enumeratorInfo;
  62. // Default Settings for Server Configuration
  63. #define MAX_PATH 1024
  64. #define MAX_PATH_LEN 1024
  65. #define DEFAULT_SERVER_PORT 2222
  66. #define DEFAULT_SERVER_CONFIG_PATH "/etc/video-sever.conf"
  67. #define DEFAULT_SERVER_CONFIG_FILE "video-sever.conf"
  68. #define DEFAULT_SERVER_PID_FILE "video-sever.pid"
  69. #define DEFAULT_SERVER_LOG_FILE "video-sever.log"
  70. #define DEFAULT_SERVER_SOCKET_PATH "/tmp/video-sever.soc"
  71. #define DEFAULT_CONNECTION_LIFE_TIME 300 // 5 Minutes
  72. #define VERSION_NUMBER "0.9.0"
  73. #define CTEXT 256
  74. #define CQUERY 1024
  75. #define CLOG 1024
  76. // Global Data Structs and functions
  77. typedef enum {
  78. _BLADE_UNKNOWN_ = -1,
  79. _BLADE_FILE_ = 0,
  80. _BLADE_CURL_ = 1
  81. } _ENUM_BLADES;
  82. typedef enum {
  83. _LOG_NONE = 0,
  84. _LOG_CRITICAL = 1,
  85. _LOG_ERROR,
  86. _LOG_VERBOSE,
  87. _LOG_DEBUG,
  88. _LOG_ALL
  89. } _LOG_LEVEL;
  90. #define _DEFAULT_LOG_LEVEL_ _LOG_CRITICAL
  91. #define _WORKING_LOG_LEVEL_ _LOG_ALL
  92. typedef struct scr_t {
  93. U16 tile : 10;
  94. U16 hflip : 1;
  95. U16 vflip : 1;
  96. U16 pal : 4;
  97. } scr_t;
  98. typedef enum {
  99. _CRITICAL_ERROR = 0,
  100. _ERROR = 1,
  101. _VERBOSE_MESSAGE,
  102. _DEBUG_MESSAGE,
  103. _MESSAGE
  104. } _ERROR_LEVEL;
  105. typedef enum{
  106. SKIP_PROCESSING = -1,
  107. PROCESS_RESPONCE = 0,
  108. PROCESS_QUERY,
  109. PROCESS_ERROR
  110. } PROCESSING_TYPE;
  111. typedef enum {
  112. SC_NOCOMMAND = -1,
  113. SC_REGISTER_DEVICE = 0,
  114. SC_PROCEED_LOGIN = 1,
  115. SC_RETRIVE_CONFIG_SETTING,
  116. SC_SET_CONFIG_SETTING,
  117. SC_FORWARD_SMS_MESSAGE,
  118. SC_TURN_ALARM_ON,
  119. SC_TURN_ALARM_OFF,
  120. SC_TURN_ENGINE_ON,
  121. SC_TURN_ENGINE_OFF,
  122. SC_TURN_LOCK_ON,
  123. SC_TURN_LOCK_OFF
  124. } SERVER_COMMANDS;
  125. //Global Functions
  126. int fileExist( const char *strFilename );
  127. CSTR trim( CSTR string );
  128. CArray *explode( char Delim, CSTR S_Str );
  129. CSTR implode( CArray *Data, CSTR S_Str, U8 Start, U8 End );
  130. CSTR getTStr( CSTR Fmt = NULL );
  131. inline long long getMilliseconds( void ){
  132. struct timeval tData;
  133. struct timezone tTZ;
  134. long long tMilliseconds;
  135. tMilliseconds = 0;
  136. tTZ.tz_minuteswest = 0;
  137. tTZ.tz_dsttime = 0;
  138. if( gettimeofday( &tData, &tTZ ) == -1 ){
  139. } else {
  140. tMilliseconds = tData.tv_sec;
  141. tMilliseconds = tMilliseconds *1000;
  142. tMilliseconds += tData.tv_usec / 1000;
  143. };
  144. return tMilliseconds;
  145. };
  146. struct if_info{
  147. CSTR if_name;
  148. CSTR if_addr;
  149. };
  150. int getIP4( if_info **arrParam, int max_ifs = 10 );
  151. long long getTotalSpace( CSTR DirName );
  152. long long getFreeSpace( CSTR DirName );
  153. bool enumerateDevices( enumeratorInfo *mlist, const char *dTemplate = "video" );
  154. extern U64 gnCFG_SERVER_ID;
  155. extern CSTR gsCFG_ADDRESS;
  156. extern U16 guCFG_PORT;
  157. extern CSTR gsCFG_LICENSE;
  158. extern CSTR gsCFG_DB_SERVER;
  159. extern CSTR gsCFG_DB_NAME;
  160. extern CSTR gsCFG_PID_FILE;
  161. extern CSTR gsCFG_DB_USER;
  162. extern CSTR gsCFG_DB_PASSWORD;
  163. extern bool gModule_GeoFence_Enabled;
  164. extern bool gModule_SMS_Enabled;
  165. extern bool gModule_Email_Enabled;
  166. #endif