blob: 227aef923aab42ad3d235337f438aaa7d14634f5 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#ifndef ZTE_WEB_HTTPSHARE_H
2#define ZTE_WEB_HTTPSHARE_H
3
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include <errno.h>
9#include <string.h>
10#include <dirent.h>
11#include <sys/statvfs.h>
12
13#include <sys/stat.h>
14#include <sys/types.h>
15#include <fcntl.h>
16#include <utime.h>
17
18#include <linux/stat.h>
19
20#include "zte_web_interface.h"
21
22
23#ifndef uint16
24#define uint16 unsigned short
25#endif
26
27#ifndef uint32
28#define uint32 unsigned long
29#endif
30
31#ifndef boolean
32#define boolean unsigned char
33#endif
34
35#ifndef TRUE
36#define TRUE 1
37#endif
38
39#ifndef FALSE
40#define FALSE 0
41#endif
42
43#ifndef NULL
44#define NULL 0
45#endif
46
47#ifndef WEBS_SOCKET_BUFSIZ
48#define WEBS_SOCKET_BUFSIZ 4096 /* Bytes read from socket */
49#endif
50
51#define ZTE_HTTPSHARE_PATH_NAME_MAX_LEN 4096
52#define ZTE_HTTPSHARE_FILE_NAME_MAX_LEN 1024
53#define ZTE_HTTPSHARE_DEFAULT_LEN 100
54#define ZTE_HTTPSHARE_MAX_NUM_SHOW_RECORD 10
55#define ZTE_IP_ADDRESS_LENGTH 40
56#define FILE_BUFFER_LEN 65536
57
58#define ZTE_HTTPSHARE_LEN_50 50
59#define ZTE_HTTPSHARE_LEN_64 64
60#define ZTE_HTTPSHARE_LEN_100 100
61#define ZTE_HTTPSHARE_LEN_12 12
62#define ZTE_HTTPSHARE_MAC_ADDR_MAX_LEN 18
63
64//#define ZTE_HTTPSHARE_TIMEOUT 600
65#define ZTE_PARSE_CGI_TAIL_LEN 100
66#define MAX_LEN_FOR_SQL 1024
67
68#define HTTPSHARE_BUF_NORMAL_LEN_MAX 255
69#define DECCHK( c ) ((c) >= '0' && (c) <= '9')
70
71
72#define ZTE_FOLDER_STR "document"
73#define ZTE_FILE_STR "file"
74#define SD_CARD_USB_MOUNT_PATH "/tmp/sd"
75#define ZTE_CREATE_TABLE_DOWNLOAD_SQL "CREATE TABLE IF NOT EXISTS download(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,path TEXT)"
76
77#define SD_CARD_PATH "/etc_rw/config/mmc2" // "/mmc2"
78#define SD_CARD_PATH_PR "/etc_rw/config"
79#define ZTE_HTTPSHARE_DB_DIR "/etc_rw/config/httpshare_db" //usr/httpshare_db
80#define ZTE_HTTPSHARE_DB_PATH "/etc_rw/config/httpshare_db/httpshare.db" //"/usr/httpshare_db/httpshare.db"
81#define TCARD_UPLOAD_FILE "/etc_rw/config/upload.data"
82
83#define SD_CARD_PATH_NAN "/mmc2/mmc2/mmc2"
84#define SD_CARD_SOFT_LINK "/usr/zte_web/web/mmc2"
85#define USB_DEV_SDCARD_PATH "/dev/mmcblk0p1"
86#define USB_DEV_SDCARD_PATH_BACK "/dev/mmcblk0"
87#define SDCARD_EXIST_FLAGE_FILE "/sys/class/android_usb/android0/tcard"
88#define NO_SDCARD "no_sdcad"
89#define ZTE_HTTPSHARE_TIME "path_SD_CARD_time_unix"
90
91#define SET_MODE_SHELL "./etc/init.d/mmchost"
92#define SET_MODE_USB "usb"
93#define SET_MODE_HTTP_SHARE "httpshare"
94
95#define USB_MODE "usb_mode"
96#define HTTP_SHARE_MODE "http_share_mode"
97#define ZTE_HTTPSHARE_DB_NAME "httpshare"
98
99#define TCARD_SIZE_FILE "/proc/proc_sd/size"
100
101//httpshare password
102#define HTTPSHARE_LOGIN_SUCCESS "0" // "share_login_ok"
103#define HTTPSHARE_LOGIN_FAIL "1" //"share_login_failure"
104#define HTTPSHARE_LOGIN_CHECK_FAIL "2" //"share_login_check_fail"
105#define HTTPSHARE_LOGIN_BAD_PASSWORD "3" // "share_login_bad_password"
106#define HTTPSHARE_LOGIN_ALREADY_LOGIN "4" //"share_login_already"
107#define HTTPSHARE_LOGIN_LOGIN_BEFORE "5" //"share_login_before"
108
109
110#define HTTPSHARE_LOGIN_TIMEOK "6" // "share_timeok"
111#define HTTPSHARE_LOGIN_TIMEOUT "7" //"share_timeout"
112#define HTTPSHARE_LOGIN_TIMEFAIL "8" //"share_timefail"
113
114
115#define ZTE_CREATE_TABLE_HTTPSHARE_SQL "CREATE TABLE IF NOT EXISTS httpshare(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,ip TEXT,path TEXT)"
116
117#define HTTPSHARE_PATH_INLEGAL "/mmc2/.." // user document path
118
119typedef enum {
120 ZTE_HTTPSHARE_DB_OK = 0,
121 ZTE_HTTPSHARE_DB_ERROR_INVAILD_PTR = 100,
122 ZTE_HTTPSHARE_DB_ERROR_NOT_OPEN_DB,
123 ZTE_HTTPSHARE_DB_ERROR_FULL,
124 ZTE_HTTPSHARE_DB_ERROR = -1
125} zte_httpshare_db_result_e_type;
126
127
128typedef enum {
129 ZTE_HTTPSHARE_FAILURE = -1,
130 ZTE_HTTPSHARE_SUCCESS = 0,
131 ZTE_HTTPSHARE_NOT_SUPPORT = 1,
132 ZTE_HTTPSHARE_MAX
133} zte_httpshare_return_e_type;
134
135
136typedef enum {
137 ZTE_CGI_PARSE_FILE_HEAD_BEGIN = 0,
138 ZTE_CGI_PARSE_FINDE_HEAD_FIRST = 1, //13
139 ZTE_CGI_PARSE_FINDE_HEAD_SEC = 2, //10
140 ZTE_CGI_PARSE_FINDE_HEAD_THIRD = 3, //13
141 ZTE_CGI_PARSE_FINDE_HEAD_FOUTH = 4, //10
142 ZTE_CGI_PARSE_FINDE_FILE_HEAD = 5, //10
143} zte_cgi_parse_file_head_type_e;
144
145
146typedef enum {
147 ZTE_CGI_PARSE_FILE_TAIL_ADD_BEGIN = 0,
148 ZTE_CGI_PARSE_FINDE_TAIL_ADD_FIRST = 1, //13
149 ZTE_CGI_PARSE_FINDE_TAIL_ADD_SEC = 2, //10
150 ZTE_CGI_PARSE_FINDE_TAIL_ADD_THIRD = 3, //13
151 ZTE_CGI_PARSE_FINDE_TAIL_ADD_FOUTH = 4, //10
152 ZTE_CGI_PARSE_FINDE_FILE_TAIL_ADD = 5, //10
153} zte_cgi_parse_file_tail_addres_type_e;
154
155
156
157
158typedef enum {
159 ZTE_CGI_PARSE_FILE_TAIL_BEGIN = 0,
160 ZTE_CGI_PARSE_FINDE_TAIL_IN_FILE = 1,
161 ZTE_CGI_PARSE_FINDE_TAIL_IN_POOL = 2,
162 ZTE_CGI_PARSE_FINDE_TAIL_PROCESS = 3,
163
164
165} zte_cgi_parse_file_tail_type_e;
166
167
168typedef enum {
169 ZTE_CGI_WRITE_THE_FIRST_DATA = 0,
170 ZTE_CGI_WRITE_THE_SEC_DATA = 1,
171} zte_cgi_write_e;
172
173
174struct user_upload_infor {
175 char file_tail_pool[ZTE_PARSE_CGI_TAIL_LEN];
176 int file_tail_pool_len;
177 int file_tail_len;
178 int file_head_len;
179 uint32 file_raw_size;
180 zte_cgi_parse_file_head_type_e file_head;
181 zte_cgi_parse_file_tail_type_e file_tail;
182 zte_cgi_parse_file_tail_addres_type_e file_tail_addres;
183 zte_cgi_write_e data_no;
184};
185
186typedef struct user_upload_infor USER_UPLOAD_INFOR;
187
188typedef struct user_common_infor_type {
189 char address[ZTE_IP_ADDRESS_LENGTH]; /* current user ip address of user */
190 char file_name[ZTE_HTTPSHARE_FILE_NAME_MAX_LEN]; /* curretn user user name for specific if it is the same user else reset infor. */
191 char path[ZTE_HTTPSHARE_FILE_NAME_MAX_LEN];
192 USER_UPLOAD_INFOR infor;
193 int requst_sid;
194 int card_full;
195 int cnt;
196 //int unixTime;
197 char UnixYMDTime[ZTE_IP_ADDRESS_LENGTH];
198 //struct user_common_infor_type *next;
199} USER_COMMON_INFOR;
200
201
202typedef struct {
203 int id;
204 char fileName[ZTE_HTTPSHARE_PATH_NAME_MAX_LEN + 1];
205 char attribute[ZTE_HTTPSHARE_DEFAULT_LEN];
206 uint32 size;
207 char lastUpdateTime[ZTE_HTTPSHARE_DEFAULT_LEN];
208
209} zte_file_record_s_type;
210
211
212typedef enum {
213 ZTE_ERROR_MODE = -1,
214 ZTE_HTTPSHARE_USB = 0,
215 ZTE_HTTPSHARE_HTTPSHARE = 1,
216 ZTE_RESERVE_MODE
217} zte_httpshare_current_mode_type;
218
219typedef struct {
220 char *dev_path;
221} httpshare_usb_mmc_dev;
222
223typedef enum {
224 ZTE_CHANGE_MODE_ERROR = 0,
225 ZTE_CHANGE_MODE_OK
226} zte_httpshare_change_mode_type;
227
228
229/*Óû§Ä£Ê½Ï³öUSB start*/
230
231#define ZTE_GET_USB_INFO_DEV "/dev/usbNVDev"
232#define ZTE_AT_PROXY4_DEV "/dev/ctrm_atproxy4"
233
234static int g_get_usb_info_fd = -1;
235static int g_at_proxy4_fd = -1;
236
237#define USBNV_IOCTL_W_CFGCDROMCHARGER 0x16
238
239typedef struct _T_REF_NV_USB_CFG {
240 UINT16 pid;
241 UINT16 vid;
242 UINT8 f_Tcard;
243 UINT8 f_Cdrom;
244 UINT8 f_AtExt;
245 UINT8 f_AtExt2;
246 CHAR Sn[64];
247} T_REF_NV_USB_CFG;
248
249/*Óû§Ä£Ê½Ï³öUSB end*/
250
251USER_COMMON_INFOR* zte_process_user_auth(webs_t wp);
252
253//record a defined count file record to show user
254extern zte_file_record_s_type httpshare_file_record[ZTE_HTTPSHARE_MAX_NUM_SHOW_RECORD];
255extern int zte_httpshare_change_current_mode(zte_httpshare_current_mode_type curr_mode);
256//extern void zte_httpshare_call_system(char * cmd);
257
258int save_upload_info_to_file(const char *file, char *name);
259int read_upload_info_from_file(const char *file, char *name);
260#endif