|
@@ -28,6 +28,8 @@
|
|
|
#include "fw_update.h"
|
|
|
#include "config.h"
|
|
|
#include "user.h"
|
|
|
+#include <stdio.h>
|
|
|
+#include <string.h>
|
|
|
|
|
|
/********************************* Defines ************************************/
|
|
|
|
|
@@ -35,6 +37,7 @@ static int finished = 0;
|
|
|
|
|
|
UserInfo_T UserInfoTbl[MAX_USER_NUM];
|
|
|
|
|
|
+
|
|
|
/********************************* Forwards ***********************************/
|
|
|
|
|
|
static void initPlatform();
|
|
@@ -50,7 +53,7 @@ static LRESULT CALLBACK websWindProc(HWND hwnd, UINT msg, UINT wp, LPARAM lp);
|
|
|
#if ME_UNIX_LIKE
|
|
|
static void sigHandler(int signo);
|
|
|
#endif
|
|
|
-
|
|
|
+static void uploadTest(Webs *wp);
|
|
|
/*********************************** Code *************************************/
|
|
|
|
|
|
MAIN(goahead, int argc, char **argv, char **envp)
|
|
@@ -197,7 +200,7 @@ websDefineAction("getAllUserInfo", getAllUserInfo);
|
|
|
websDefineAction("setUserPassword", setUserPassword);
|
|
|
websDefineAction("addUser", addUser);
|
|
|
websDefineAction("delUser", delUser);
|
|
|
-
|
|
|
+ websDefineAction("uploadTest", uploadTest);
|
|
|
|
|
|
|
|
|
|
|
@@ -232,6 +235,141 @@ websDefineAction("delUser", delUser);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+typedef struct{
|
|
|
+ char buf[1024*1000];
|
|
|
+ char filename[32];
|
|
|
+ int fileSize;
|
|
|
+} filestruct;
|
|
|
+
|
|
|
+//这个函数是把16进制字符串转换成16进制
|
|
|
+
|
|
|
+int StringToHex(char *str, unsigned char *out, unsigned int *outlen)
|
|
|
+{
|
|
|
+ char *p = str;
|
|
|
+ char high = 0, low = 0;
|
|
|
+ int tmplen = strlen(p), cnt = 0;
|
|
|
+ tmplen = strlen(p);
|
|
|
+ while(cnt < (tmplen / 2))
|
|
|
+ {
|
|
|
+ high = ((*p > '9') && ((*p <= 'F') || (*p <= 'f'))) ? *p - 48 - 7 : *p - 48;
|
|
|
+ low = (*(++ p) > '9' && ((*p <= 'F') || (*p <= 'f'))) ? *(p) - 48 - 7 : *(p) - 48;
|
|
|
+ out[cnt] = ((high & 0x0f) << 4 | (low & 0x0f));
|
|
|
+ p ++;
|
|
|
+ cnt ++;
|
|
|
+ }
|
|
|
+ if(tmplen % 2 != 0) out[cnt] = ((*p > '9') && ((*p <= 'F') || (*p <= 'f'))) ? *p - 48 - 7 : *p - 48;
|
|
|
+
|
|
|
+ if(outlen != NULL) *outlen = tmplen / 2 + tmplen % 2;
|
|
|
+ return tmplen / 2 + tmplen % 2;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+static void uploadTest(Webs *wp)
|
|
|
+{
|
|
|
+ // WebsKey *s;
|
|
|
+ // WebsUpload *up;
|
|
|
+ // char *upfile;
|
|
|
+ filestruct fileitem;
|
|
|
+ printf("<<<<<<<<come in >>>>>>>>>>>>>>>>>>\n");
|
|
|
+ char *bufStr, *md5, *filename;
|
|
|
+ bufStr = websGetVar(wp, "bufStr", NULL);
|
|
|
+ md5 = websGetVar(wp, "md5", NULL);
|
|
|
+ filename = websGetVar(wp, "filename", NULL);
|
|
|
+
|
|
|
+ char* jsonString=wp->input.servp;
|
|
|
+
|
|
|
+
|
|
|
+ cJSON *root1 = cJSON_Parse(jsonString);
|
|
|
+ cJSON *bufItem=cJSON_GetObjectItem(root1,"bufStr");
|
|
|
+ cJSON *filenameItem=cJSON_GetObjectItem(root1,"filename");
|
|
|
+ cJSON *fileSizeItem=cJSON_GetObjectItem(root1,"fileSize");
|
|
|
+ fileitem.fileSize = fileSizeItem->valueint;
|
|
|
+
|
|
|
+ memcpy(fileitem.buf, bufItem->valuestring, fileitem.fileSize);
|
|
|
+
|
|
|
+ memcpy(fileitem.filename, filenameItem->valuestring,strlen(filenameItem->valuestring));
|
|
|
+ int outlen = 0;
|
|
|
+ unsigned char hexStr[fileitem.fileSize];
|
|
|
+ StringToHex(fileitem.buf, hexStr, &outlen);
|
|
|
+ printf("<<<<<<<<come jsonString 1>>>>>>>>%s>>>>>>>>>>\n", hexStr);
|
|
|
+ printf("<<<<<<<<come jsonString >2>>>>>>>%s>>>>>>>>>>\n", jsonString);
|
|
|
+ printf("<<<<<<<<come jsonString >3>>>>>>>%s>>>>>>>>>>\n", fileitem.buf);
|
|
|
+ printf("<<<<<<<<come infilename >>4>>>>>>%s>>>>>>>>>>\n", fileitem.filename);
|
|
|
+ // printf("<<<<<<<<come md5 >>>>>>>>%s>>>>>>>>>>\n", md5);
|
|
|
+ // printf("<<<<<<<<come bufStr >>>>>>>>%s>>>>>>>>>>\n", bufStr);
|
|
|
+
|
|
|
+ int i;
|
|
|
+ printf("---> buf: ");
|
|
|
+ for (i = 0; i < fileitem.fileSize; ++i)
|
|
|
+ {
|
|
|
+ printf("%#x ", fileitem.buf[i]);
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+
|
|
|
+
|
|
|
+ // zheli
|
|
|
+ // char buf[] = "hello jimbo"; //把这个换成你的buf, 试试 应该不行
|
|
|
+ FILE *fp;
|
|
|
+ char pathStr[100] = {0};
|
|
|
+ sprintf(pathStr, "/var/www/goahead/%s", fileitem.filename);
|
|
|
+ fp = fopen(pathStr , "wb+");//wb+是什么?二进制写,没有文件就创建,有就覆盖
|
|
|
+ fwrite ( hexStr, sizeof(char), fileitem.fileSize, fp);
|
|
|
+ fclose(fp);
|
|
|
+
|
|
|
+
|
|
|
+ // websSetStatus(wp, 200);
|
|
|
+ // websWriteHeaders(wp, -1, 0);
|
|
|
+ // websWriteHeader(wp, "Content-Type", "text/plain");
|
|
|
+ // websWriteEndHeaders(wp);
|
|
|
+ // if (scaselessmatch(wp->method, "POST")) {
|
|
|
+ // for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) {
|
|
|
+ // up = s->content.value.symbol;
|
|
|
+ // websWrite(wp, "FILE: %s\r\n", s->name.value.string);
|
|
|
+ // websWrite(wp, "FILENAME=%s\r\n", up->filename);
|
|
|
+ // websWrite(wp, "CLIENT=%s\r\n", up->clientFilename);
|
|
|
+ // websWrite(wp, "TYPE=%s\r\n", up->contentType);
|
|
|
+ // websWrite(wp, "SIZE=%d\r\n", up->size);
|
|
|
+ // upfile = sfmt("%s/tmp/%s", websGetDocuments(), up->clientFilename);
|
|
|
+ // printf("<<<<<<<<<<<%s>>>>>>>>>>\n", upfile);
|
|
|
+ // if (rename(up->filename, upfile) < 0) {
|
|
|
+ // error("Cannot rename uploaded file: %s to %s, errno %d", up->filename, upfile, errno);
|
|
|
+ // }
|
|
|
+ // wfree(upfile);
|
|
|
+ // }
|
|
|
+ // // websWrite(wp, "\r\nVARS:\r\n");
|
|
|
+ // // for (s = hashFirst(wp->vars); s; s = hashNext(wp->vars, s)) {
|
|
|
+ // // websWrite(wp, "%s=%s\r\n", s->name.value.string, s->content.value.string);
|
|
|
+ // // }
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ char *pStr;
|
|
|
+ cJSON * root = cJSON_CreateObject();
|
|
|
+ cJSON * data = cJSON_CreateObject();
|
|
|
+ cJSON_AddItemToObject(root, "data", data);//根节点下添加
|
|
|
+ cJSON_AddStringToObject(root, "msg", "");
|
|
|
+ cJSON_AddNumberToObject(root, "code", 200);
|
|
|
+
|
|
|
+
|
|
|
+ pStr = cJSON_PrintUnformatted(root);
|
|
|
+
|
|
|
+ printf("---> cJSON Str:\n%s\n", pStr);
|
|
|
+ websSetStatus(wp, 200);
|
|
|
+ websWriteHeaders(wp, -1, 0);
|
|
|
+ websWriteEndHeaders(wp);
|
|
|
+ websWrite(wp,"%s", pStr);
|
|
|
+ websFlush(wp, 0);
|
|
|
+ // websDone(wp);
|
|
|
+
|
|
|
+ if(pStr)
|
|
|
+ wfree(pStr);
|
|
|
+ if(root)
|
|
|
+ cJSON_Delete(root);
|
|
|
+
|
|
|
+ websDone(wp);
|
|
|
+}
|
|
|
|
|
|
static void logHeader()
|
|
|
{
|