lusa 5 lat temu
rodzic
commit
36cfce03bf

+ 94 - 94
app/goahead-3.6.5/src/goahead.c

@@ -235,113 +235,113 @@ 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;
+// 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;
+// }
 
 
 
 static void uploadTest(Webs *wp)
 {
-    // WebsKey         *s;
-    // WebsUpload      *up;
-    // char            *upfile;
-    filestruct fileitem;
+    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    *bufStr, *md5, *filename;
+    // bufStr = websGetVar(wp, "bufStr", NULL);
+    // md5 = websGetVar(wp, "md5", NULL);
+    // filename = websGetVar(wp, "filename", NULL);
 
-    char* jsonString=wp->input.servp;
+    // 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");
-
-
-    // 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);
-    //     // }
+    // 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);
+        }
+    }
 
 
 

+ 5 - 16
app/goahead-3.6.5/src/http.c

@@ -788,8 +788,7 @@ static void readEvent(Webs *wp)
         return;
     }
     websNoteRequestActivity(wp);
-    rxbuf = &wp->rxbuf; //存储的是请求包中的所有数据 18432 //缓冲区的数据结构
-    printf("%d>>>>>>>>0000>>>>%d>>>\n",rxbuf->buflen, bufRoom(rxbuf));
+    rxbuf = &wp->rxbuf; //存储的是请求包中的所有数据  //缓冲区的数据结构
     if (bufRoom(rxbuf) < (ME_GOAHEAD_LIMIT_BUFFER+1)) { //缓冲区不够了增加缓冲区的大小
         if (!bufGrow(rxbuf, (ME_GOAHEAD_LIMIT_BUFFER+1))) {
             websError(wp, HTTP_CODE_INTERNAL_SERVER_ERROR, "Cannot grow rxbuf");
@@ -799,30 +798,21 @@ static void readEvent(Webs *wp)
     }
 
 
-    printf("%s>>>>>>>>rxbuf->endp>>>>>>>\n",rxbuf->endp);
     // ME_GOAHEAD_LIMIT_BUFFER
-    if ((nbytes = websRead(wp, (char*) rxbuf->endp, ME_GOAHEAD_LIMIT_BUFFER*10)) > 0) {//调用socketRead,读HTTP请求.rxbuf->endp是上一次的数据尾,每次读之后接上
-        printf("%d>>>>>>>>2222>>>>>>>\n",nbytes);//一次读了多少字节
+    if ((nbytes = websRead(wp, (char*) rxbuf->endp, ME_GOAHEAD_LIMIT_BUFFER)) > 0) {//调用socketRead,读HTTP请求.rxbuf->endp是上一次的数据尾,每次读之后接上
+        //一次读了多少字节
         wp->lastRead = nbytes;//读了多少字节,数据的尾指针就加多少字节
-
-         printf("%d>>>>>>>>bp->buflen>>>>>>>\n",rxbuf->buflen);
         bufAdjustEnd(rxbuf, nbytes);//写字符串结束符
         bufAddNull(rxbuf);
     }
-    printf("%d>>>>>>>>56565656>>>>>>>\n",nbytes);
     if (nbytes > 0 || wp->state > WEBS_BEGIN) { //读到数据了,进来处理
-        printf("%d>>>>>>>>2222>>>>>>>\n",nbytes);
         websPump(wp);
     }
     //到这一步nbytes值是-1  为什么??
-    printf("%d>>>>>>>>>nbytes>>>>>>>>>>>\n",nbytes);
-
-    printf("%d>>>>>>>>>wp->sid>>>>>>>>>>>\n",wp->sid);
     if (wp->flags & WEBS_CLOSED) {
         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 +836,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 +846,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 +1110,7 @@ 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);
+            // 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 +1320,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;
     }

+ 6 - 8
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;
@@ -156,7 +157,6 @@ PUBLIC bool websProcessUploadData(Webs *wp)
             break;
         }
     }
-    printf(">>>>>>66666666>>>>>>>>>>>>>\n");
     bufCompact(&wp->input);
     return canProceed;
 }
@@ -207,7 +207,7 @@ static void processUploadHeader(Webs *wp, char *line)
             File data
             ---boundary
          */
-        printf(">>>>>>>>>>>>>>>>>2222>>>>>lllLLL>>>>>>>\n");
+        // printf(">>>>>>>>>>>>>>>>>2222>>>>>lllLLL>>>>>>>\n");
         key = rest;
         wfree(wp->uploadVar);
         wfree(wp->clientFilename);
@@ -243,7 +243,7 @@ static void processUploadHeader(Webs *wp, char *line)
                     Create the file to hold the uploaded data /var/tmp
                  */
                 wfree(wp->uploadTmp);
-                 printf(">>>>>>>>>>>>>>>>>0000>>>>>%s>>>>>>>\n", uploadDir);
+                 // printf(">>>>>>>>>>>>>>>>>0000>>>>>%s>>>>>>>\n", uploadDir);
                 // if ((wp->uploadTmp = websTempFile(uploadDir, "tmp")) == 0) {
                 if ((wp->uploadTmp = websTempFile("/var/tmp", "tmp")) == 0) {
 
@@ -251,7 +251,7 @@ static void processUploadHeader(Webs *wp, char *line)
                         "Cannot create upload temp file %s. Check upload temp dir %s", wp->uploadTmp, uploadDir);
                     return;
                 }
-                printf("File upload of: %s stored as %s\n", wp->clientFilename, wp->uploadTmp);
+                // printf("File upload of: %s stored as %s\n", wp->clientFilename, wp->uploadTmp);
                     //  1 
                 // printf(">>>>>%d>>>>>>%d>>>>>>%d>>>>>%d>>>>>>>\n", O_WRONLY , O_CREAT , O_TRUNC , O_BINARY);
                 if ((wp->upfd = open(wp->uploadTmp, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0600)) < 0) {
@@ -306,7 +306,8 @@ static int writeToFile(Webs *wp, char *data, ssize len)
 
     file = wp->currentFile;
 
-    if ((file->size + len) > ME_GOAHEAD_LIMIT_UPLOAD) {
+    printf("%d>>>>%d>>>>>writeToFile>>>>>>%d\n",file->size, len,  ME_GOAHEAD_LIMIT_UPLOAD);
+    if ((file->size + len) > ME_GOAHEAD_LIMIT_UPLOAD*8) {
         websError(wp, HTTP_CODE_REQUEST_TOO_LARGE, "Uploaded file exceeds maximum %d", (int) ME_GOAHEAD_LIMIT_UPLOAD);
         return -1;
     }
@@ -336,14 +337,11 @@ static bool processContentData(Webs *wp)
     file = wp->currentFile;
    
     size = bufLen(content);
-    printf("%d>>>>>>>>>>>>>>>:%d\n", size,  wp->boundaryLen);
     if (size < wp->boundaryLen) {
-        printf("come here >>>>>>>>>>>>>>>>>>>>>\n");
         /*  Incomplete boundary. Return and get more data */
         return 0;
     }
 
-    printf("**************>>>>>>>>>>>>>>>>>>>>>\n");
     if ((bp = getBoundary(wp, content->servp, size)) == 0) {
         trace(7, "uploadFilter: Got boundary filename %x", wp->clientFilename);
         if (wp->clientFilename) {