|
|
@@ -10,6 +10,7 @@
|
|
|
#include "cfg.h"
|
|
|
#include "cascade.h"
|
|
|
#include "appweb.h"
|
|
|
+#include "upg.h"
|
|
|
#include "language_common.h"
|
|
|
#include "websocket_handle.h"
|
|
|
|
|
|
@@ -151,6 +152,11 @@ static void *web_thread(void *arg)
|
|
|
|
|
|
#else
|
|
|
|
|
|
+typedef struct {
|
|
|
+ size_t expected; // POST data length, bytes
|
|
|
+ size_t received; // Already received bytes
|
|
|
+ void *fp; // Opened uploaded file
|
|
|
+}upload_stat_t;
|
|
|
static void http_mg_cb(struct mg_connection *c, int ev, void *ev_data)
|
|
|
{
|
|
|
int i,j;
|
|
|
@@ -170,6 +176,10 @@ static void http_mg_cb(struct mg_connection *c, int ev, void *ev_data)
|
|
|
mg_http_serve_dir(c, ev_data, &opts);
|
|
|
}
|
|
|
}
|
|
|
+ else if (ev == MG_EV_HTTP_HDRS) {
|
|
|
+ printf("____ MG_EV_HTTP_HDRS\n");
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
static void *web_thread(void *arg)
|
|
|
{
|
|
|
@@ -217,7 +227,7 @@ static void systemConfiguration(void* conn)
|
|
|
#else
|
|
|
mg_stream_t *s = (mg_stream_t *)conn;
|
|
|
struct mg_http_message *msg = s->ev_data;
|
|
|
- rx_Head_buf = (char *)msg->head.ptr;
|
|
|
+ rx_Head_buf = (char *)msg->head.buf;
|
|
|
#endif
|
|
|
|
|
|
g_token = json_to_Token_info(rx_Head_buf);
|
|
|
@@ -252,7 +262,7 @@ static void changeLanguages(void* conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf = (char*)msg->body.ptr;
|
|
|
+ rx_body_buf = (char*)msg->body.buf;
|
|
|
#endif
|
|
|
json_to_switch_language(rx_body_buf);
|
|
|
dev_update_device_genera_info(__globalDeviceManage.db,__globalDeviceManage._global_device_info);
|
|
|
@@ -274,7 +284,7 @@ static void loginFunc(void* conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf = msg->body.ptr;
|
|
|
+ rx_body_buf = msg->body.buf;
|
|
|
#endif
|
|
|
|
|
|
//用户信息创建-未析构
|
|
|
@@ -356,7 +366,7 @@ static void loginOutFunc(void* conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf = (char*)msg->body.ptr;
|
|
|
+ rx_body_buf = (char*)msg->body.buf;
|
|
|
#endif
|
|
|
|
|
|
//转换json参数
|
|
|
@@ -403,7 +413,7 @@ static void getUserRouters(void* conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_Head_buf = (char*)msg->head.ptr;
|
|
|
+ rx_Head_buf = (char*)msg->head.buf;
|
|
|
#endif
|
|
|
|
|
|
g_token = json_to_Token_info(rx_Head_buf);
|
|
|
@@ -439,7 +449,7 @@ static void overallStatusMonitoring(void* conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf = (char*)msg->body.ptr;
|
|
|
+ rx_body_buf = (char*)msg->body.buf;
|
|
|
#endif
|
|
|
|
|
|
//转换json参数
|
|
|
@@ -865,7 +875,7 @@ static void channelStatusMonitoring(void* conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf=(char*)msg->body.ptr;
|
|
|
+ rx_body_buf=(char*)msg->body.buf;
|
|
|
#endif
|
|
|
|
|
|
//转换json参数
|
|
|
@@ -1379,7 +1389,7 @@ static void sensorStatusMonitoring(void* conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf=(char*)msg->body.ptr;
|
|
|
+ rx_body_buf=(char*)msg->body.buf;
|
|
|
#endif
|
|
|
//转换json参数
|
|
|
cjson = json_to_sensor_manage(rx_body_buf,&_over_all_sensor_request);
|
|
|
@@ -1869,7 +1879,7 @@ static void alarmProtect(void *conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf=(char*)msg->body.ptr;
|
|
|
+ rx_body_buf=(char*)msg->body.buf;
|
|
|
#endif
|
|
|
|
|
|
memset(&_alarm_request_info, 0, sizeof(_alarm_request_info));
|
|
|
@@ -2146,7 +2156,7 @@ static void logInformation(void *conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf=(char*)msg->body.ptr;
|
|
|
+ rx_body_buf=(char*)msg->body.buf;
|
|
|
#endif
|
|
|
|
|
|
memset(&__logInformationRequestInfo,0,sizeof(_LogInformationRequestInfo));
|
|
|
@@ -2341,7 +2351,7 @@ static void communicationManagement(void *conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf=(char*)msg->body.ptr;
|
|
|
+ rx_body_buf=(char*)msg->body.buf;
|
|
|
#endif
|
|
|
|
|
|
//转换json参数
|
|
|
@@ -2429,7 +2439,7 @@ static void serviceManagement(void *conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf = (char*)msg->body.ptr;
|
|
|
+ rx_body_buf = (char*)msg->body.buf;
|
|
|
#endif
|
|
|
|
|
|
//转换json参数
|
|
|
@@ -3157,7 +3167,7 @@ static void systemManagent(void *conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf = (char*)msg->body.ptr;
|
|
|
+ rx_body_buf = (char*)msg->body.buf;
|
|
|
#endif
|
|
|
|
|
|
//转换json参数
|
|
|
@@ -3323,7 +3333,7 @@ static void equipmentMintenance(void *conn)
|
|
|
#else
|
|
|
mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
struct mg_http_message *msg=s->ev_data;
|
|
|
- rx_body_buf = (char*)msg->body.ptr;
|
|
|
+ rx_body_buf = (char*)msg->body.buf;
|
|
|
#endif
|
|
|
|
|
|
//转换json参数
|
|
|
@@ -3415,59 +3425,45 @@ static void equipmentMintenance(void *conn)
|
|
|
http_reply(conn, 200, ack_str);
|
|
|
cJSON_free((void*)ack_str);
|
|
|
}
|
|
|
+static int upload_handle(void *conn, char *upload_path)
|
|
|
+{
|
|
|
+ int r=-1;
|
|
|
+ struct mg_http_part part;
|
|
|
+ mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
+ struct mg_http_message *hm = (struct mg_http_message *)s->ev_data;
|
|
|
+
|
|
|
+ MG_INFO(("New request to: [%.*s], body size: %lu", (int) hm->uri.len,
|
|
|
+ hm->uri.buf, (unsigned long) hm->body.len));
|
|
|
+ size_t pos = 0, total_bytes = 0, num_files = 0;
|
|
|
+ while ((pos = mg_http_next_multipart(hm->body, pos, &part)) > 0) {
|
|
|
+ MG_INFO(("Chunk name: [%.*s] filename: [%.*s] length: %lu bytes",
|
|
|
+ (int) part.name.len, part.name.buf, (int) part.filename.len,
|
|
|
+ part.filename.buf, (unsigned long) part.body.len));
|
|
|
|
|
|
-
|
|
|
-typedef struct {
|
|
|
- size_t expected; // POST data length, bytes
|
|
|
- size_t received; // Already received bytes
|
|
|
- void *fp; // Opened uploaded file
|
|
|
-}upload_stat_t;
|
|
|
+ if (mg_path_is_sane(mg_str(upload_path))) {
|
|
|
+ mg_file_write(&mg_fs_posix, upload_path, part.body.buf, part.body.len);
|
|
|
+ total_bytes += part.body.len;
|
|
|
+ num_files++;
|
|
|
+ r = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return r;
|
|
|
+}
|
|
|
static void equipmentMintenanceUpload(void *conn)
|
|
|
{
|
|
|
- int ret = -1 ;
|
|
|
- char* ack_str = "OK" ;
|
|
|
- int len,tlen=0;
|
|
|
+ int r = -1 ;
|
|
|
|
|
|
#ifdef USE_WEBAPP
|
|
|
HttpStream *s=(HttpStream*)conn;
|
|
|
http_reply(conn, 200, NULL);
|
|
|
#else
|
|
|
-/*
|
|
|
- mg_stream_t *s=(mg_stream_t*)conn;
|
|
|
- upload_stat_t *us = (upload_stat_t *) s->c->data;
|
|
|
- struct mg_fs *fs = &mg_fs_posix;
|
|
|
-
|
|
|
- if (s->ev == MG_EV_HTTP_HDRS) {
|
|
|
- struct mg_http_message *hm = (struct mg_http_message *) s->ev_data;
|
|
|
- char path[MG_PATH_MAX];
|
|
|
- mg_snprintf(path, sizeof(path), "%s/%.*s", "/root/dl", hm->uri.len - 8,
|
|
|
- hm->uri.buf + 8);
|
|
|
- us->expected = hm->body.len; // Store number of bytes we expect
|
|
|
- mg_iobuf_del(&s->c->recv, 0, hm->head.len);
|
|
|
- mg_iobuf_del(&s->c->recv, 0, hm->head.len); // Delete HTTP headers
|
|
|
- s->c->pfn = NULL; // Silence HTTP protocol handler, we'll use MG_EV_READ
|
|
|
- if (mg_path_is_sane(mg_str(path))) {
|
|
|
- fs->rm(path); // Delete file if it exists
|
|
|
- us->fp = fs->op(path, MG_FS_WRITE); // Open file for writing
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Catch uploaded file data for both MG_EV_READ and MG_EV_HTTP_HDRS
|
|
|
- if (us->expected > 0 && s->c->recv.len > 0) {
|
|
|
- us->received += s->c->recv.len;
|
|
|
- if (us->fp) fs->wr(us->fp, s->c->recv.buf, s->c->recv.len); // Write to file
|
|
|
- s->c->recv.len = 0; // Delete received data
|
|
|
- if (us->received >= us->expected) {
|
|
|
- // Uploaded everything. Send response back
|
|
|
- MG_INFO(("Uploaded %lu bytes", us->received));
|
|
|
- mg_http_reply(s->c, 200, NULL, "%lu ok\n", us->received);
|
|
|
- if (us->fp) fs->cl(us->fp); // Close file
|
|
|
- memset(us, 0, sizeof(*us)); // Cleanup upload state
|
|
|
- s->c->is_draining = 1; // Close connection when response gets sent
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- */
|
|
|
+ char path[200];
|
|
|
+ sprintf(path, "%s/%s", DOWN_FOLDER, UPG_PKG_NAME);
|
|
|
+ r = upload_handle(conn, path);
|
|
|
+ if(r==0) {
|
|
|
+ upg_start();
|
|
|
+ }
|
|
|
+ http_reply(conn, 200, "");
|
|
|
#endif
|
|
|
}
|
|
|
|