|
@@ -105,7 +105,7 @@ MAIN(goahead, int argc, char **argv, char **envp)
|
|
|
logSetPath(argv[++argind]);
|
|
|
|
|
|
} else if (smatch(argp, "--verbose") || smatch(argp, "-v")) {
|
|
|
- logSetPath("stdout:2");
|
|
|
+ logSetPath("stdout:2"); //2
|
|
|
|
|
|
} else if (smatch(argp, "--route") || smatch(argp, "-r")) {
|
|
|
route = argv[++argind];
|
|
@@ -130,7 +130,7 @@ MAIN(goahead, int argc, char **argv, char **envp)
|
|
|
printf("---> initPlatform\n");
|
|
|
initPlatform();
|
|
|
printf("---> websOpen\n");
|
|
|
- printf(">>>>>>>>>>>>>>>>>>>>>>>>>>2>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
|
|
+// printf(">>>>>>>>>>>>>>>>>>>>>>>>>>2>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
|
|
if (websOpen(documents, route) < 0) {
|
|
|
error("Cannot initialize server. Exiting.");
|
|
|
return -1;
|
|
@@ -267,106 +267,107 @@ int StringToHex(char *str, unsigned char *out, unsigned int *outlen)
|
|
|
|
|
|
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;
|
|
|
+ WebsKey *s;
|
|
|
+ WebsUpload *up;
|
|
|
+ char *upfile;
|
|
|
+
|
|
|
+ printf("---> Enter uploadTest\n");
|
|
|
+ // filestruct fileitem;
|
|
|
+ // 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;
|
|
|
+ // 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.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");
|
|
|
+ // 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);
|
|
|
+ // // 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);
|
|
|
- // // }
|
|
|
- // }
|
|
|
+ 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("---> uploadTest, upfile: %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);
|
|
|
+ // 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);
|
|
|
+ // 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);
|
|
|
+ // 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);
|
|
|
}
|