zhangbo пре 5 година
родитељ
комит
bdc4e279c8

+ 27 - 76
app/goahead-3.6.5/src/goahead.c

@@ -242,33 +242,33 @@ websDefineAction("resetBmc", resetBmc);
     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;
+// 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;
-}
+//     if(outlen != NULL) *outlen = tmplen / 2 + tmplen % 2;
+//     return tmplen / 2 + tmplen % 2;
+// }
 
 
 
@@ -277,55 +277,6 @@ static void uploadTest(Webs *wp)
     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;
-
-    // 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");
@@ -339,7 +290,7 @@ static void uploadTest(Webs *wp)
             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);
+            printf("<<<<<<<<<<<%s>>>>>>>>>>\n", upfile);
             if (rename(up->filename, upfile) < 0) {
                 error("Cannot rename uploaded file: %s to %s, errno %d", up->filename, upfile, errno);
             }

+ 2 - 4
app/goahead-3.6.5/src/http.c

@@ -788,6 +788,7 @@ static void readEvent(Webs *wp)
         return;
     }
     websNoteRequestActivity(wp);
+
     rxbuf = &wp->rxbuf; //存储的是请求包中的所有数据 18432 //缓冲区的数据结构
 //    printf("%d>>>>>>>>0000>>>>%d>>>\n",rxbuf->buflen, bufRoom(rxbuf));
     if (bufRoom(rxbuf) < (ME_GOAHEAD_LIMIT_BUFFER+1)) { //缓冲区不够了增加缓冲区的大小
@@ -822,7 +823,6 @@ static void readEvent(Webs *wp)
         return;//通过websPump处理完请求,需要关闭连接,return返回readEvent.数据结构依然保留。
     } else if (nbytes < 0 && socketEof(wp->sid)) {
         /* EOF or error. Allow running requests to continue. */
-        // printf("%d>>>>>>>>>state>>>>>>>>>>>\n", wp->state);
         //state 值是1
         if (wp->state < WEBS_READY) {//ready 2
             if (wp->state > WEBS_BEGIN) {//begin 0
@@ -846,6 +846,7 @@ PUBLIC void websPump(Webs *wp)
     bool    canProceed;
 
     for (canProceed = 1; canProceed; ) {
+        printf("wp->state = %d\n",wp->state);
         switch (wp->state) {
         case WEBS_BEGIN:
             canProceed = parseIncoming(wp);
@@ -855,7 +856,6 @@ PUBLIC void websPump(Webs *wp)
             break;
         case WEBS_READY:
             if (!websRunRequest(wp)) {
-                // printf("%d<<<<<<<<<<<<>>>>>>>>>*******\n", WEBS_READY);
                 /* Reroute if the handler re-wrote the request */
                 websRouteRequest(wp);
                 wp->state = WEBS_READY;
@@ -1120,7 +1120,6 @@ static void parseHeaders(Webs *wp)
         } else if (strcmp(key, "content-type") == 0) {
             wfree(wp->contentType);
             wp->contentType = sclone(value);
-//            printf("%s>>>>>>>>>>>>>>>wp->contentType>>>>>\n", wp->contentType);
             if (strstr(value, "application/x-www-form-urlencoded")) {
                 wp->flags |= WEBS_FORM;
             } else if (strstr(value, "application/json")) {
@@ -1330,7 +1329,6 @@ static bool filterChunkData(Webs *wp)
             nbytes = min(bufRoom(&wp->input), len);
 //            printf("---> bufPutBlk2 len = %d\n", len);
             if (len > 0 && (nbytes = bufPutBlk(&wp->input, rxbuf->servp, nbytes)) == 0) {
-                printf("<<<<<<<<<<<<<<>>42222>>>>>>>>>>>>\n" );
                 websError(wp, HTTP_CODE_REQUEST_TOO_LARGE | WEBS_CLOSE, "Too big");
                 return 1;
             }

+ 0 - 1
app/goahead-3.6.5/src/socket.c

@@ -811,7 +811,6 @@ PUBLIC ssize socketRead(int sid, void *buf, ssize bufsize)
 
     assert(buf);
     assert(bufsize > 0);
-
     if ((sp = socketPtr(sid)) == NULL) {
         return -1;
     }

+ 4 - 1
app/goahead-3.6.5/src/upload.c

@@ -132,6 +132,7 @@ PUBLIC bool websProcessUploadData(Webs *wp)
             }
         }
         switch (wp->uploadState) {
+            printf("wp->uploadState = %d\n",wp->uploadState);
         case 0:
             initUpload(wp);
             break;
@@ -206,6 +207,7 @@ static void processUploadHeader(Webs *wp, char *line)
             File data
             ---boundary
          */
+
         key = rest;
         wfree(wp->uploadVar);
         wfree(wp->clientFilename);
@@ -241,11 +243,13 @@ static void processUploadHeader(Webs *wp, char *line)
                     Create the file to hold the uploaded data
                  */
                 wfree(wp->uploadTmp);
+
                 if ((wp->uploadTmp = websTempFile(uploadDir, "tmp")) == 0) {
                     websError(wp, HTTP_CODE_INTERNAL_SERVER_ERROR,
                         "Cannot create upload temp file %s. Check upload temp dir %s", wp->uploadTmp, uploadDir);
                     return;
                 }
+
                 trace(5, "File upload of: %s stored as %s", wp->clientFilename, wp->uploadTmp);
 
                 if ((wp->upfd = open(wp->uploadTmp, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0600)) < 0) {
@@ -299,7 +303,6 @@ static int writeToFile(Webs *wp, char *data, ssize len)
     ssize           rc;
 
     file = wp->currentFile;
-
     //printf("===file->size %d >>>len %d >> ME_GOAHEAD_LIMIT_UPLOAD %d ====\n", file->size, len, ME_GOAHEAD_LIMIT_UPLOAD);
     printf("- %d\n", file->size);
     if ((file->size + len) > ME_GOAHEAD_LIMIT_UPLOAD) {