⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpd.lst

📁 ENC28J60 System HTTP
💻 LST
📖 第 1 页 / 共 5 页
字号:
 403:net/httpd.c   **** 			///handle http authentication for everything in /adm/:
 404:net/httpd.c   **** 			//we check this only for the first \r\n\r\n otherwise we get problems
 405:net/httpd.c   **** 			//with the http post stuff. maybe move the second rnrn detection to a seperate
 406:net/httpd.c   **** 			//post substate!
 407:net/httpd.c   **** 			if (!authorized && string_compare_progmem_noeof("adm/", file_name) ){
 408:net/httpd.c   **** 						//authorization required!
 409:net/httpd.c   **** 						#if HTTPD_DEBUG_AUTH
 410:net/httpd.c   **** 						softuart_puts_progmem("HTTPD: auth failed!");
 411:net/httpd.c   **** 						softuart_putnewline();
 412:net/httpd.c   **** 						#endif
 413:net/httpd.c   **** 
 414:net/httpd.c   **** 						//not authorzed, send auth request & failure message
 415:net/httpd.c   **** 						//when this is an http post, this is not correct...
 416:net/httpd.c   **** 						//but simply ignore this, no normal user would be unauthorized & try to upload (he cant see u
 417:net/httpd.c   **** 						//so this should only happens to a hacker ;)
 418:net/httpd.c   **** 						pos = TCP_POS_TXDATA;
 419:net/httpd.c   **** 						pos = httpd_add_progmem_data(HTTPD_RESPONSE_401,NULL, buffer, pos, 0, NIC_BUFFERSIZE-pos);
 420:net/httpd.c   **** 						httpd_conn[socketnum].state = HTTPD_STATE_FINISHED;
 421:net/httpd.c   **** 						*appstate = TCP_APPSTATE_HAS_TXDATA;
 422:net/httpd.c   **** 						return (pos-TCP_POS_TXDATA);
 423:net/httpd.c   **** 			}
 424:net/httpd.c   **** 			
 425:net/httpd.c   **** 			if ((httpd_conn[socketnum].substate & 0x07) == HTTPD_SUBSTATE_RNRN){
 426:net/httpd.c   **** 				//request end, send data !
 427:net/httpd.c   **** 				pos = TCP_POS_TXDATA;
 428:net/httpd.c   **** 
 429:net/httpd.c   **** 				//POST test hack
 430:net/httpd.c   **** 				if (httpd_conn[socketnum].file_id == HTTPD_STATE_FILE_POST){
 431:net/httpd.c   **** 					//wait for filename detection!
 432:net/httpd.c   **** 					if (httpd_conn[socketnum].substate  == HTTPD_SUBSTATE_RNRN)
 433:net/httpd.c   **** 						break; 
 434:net/httpd.c   **** 
 435:net/httpd.c   **** 					if (httpd_conn[socketnum].substate & HTTPD_SUBSTATE_POST_FN_OK){
 436:net/httpd.c   **** 						//filename detected !
 437:net/httpd.c   **** 					}else{
 438:net/httpd.c   **** 						#if HTTPD_DEBUG
 439:net/httpd.c   **** 						softuart_puts_progmem("HTTP: POST (unknown filename)");
 440:net/httpd.c   **** 						softuart_putnewline();
 441:net/httpd.c   **** 						#endif
 442:net/httpd.c   **** 						//open default file
 443:net/httpd.c   **** 						filesystem_open_file_wr("upload","txt");
 444:net/httpd.c   **** 					}
 445:net/httpd.c   **** 
 446:net/httpd.c   **** 					inpos++;
 447:net/httpd.c   **** 					filesystem_write_data(&buffer[inpos], datalen-(inpos-datapos),0);
 448:net/httpd.c   **** 					
 449:net/httpd.c   **** 					httpd_conn[socketnum].state = HTTPD_STATE_POST;
 450:net/httpd.c   **** 					httpd_conn[socketnum].data_position -= datalen-(inpos_old-datapos)-1;
 451:net/httpd.c   **** 
 452:net/httpd.c   **** 					//set appstate & exit here !!
 453:net/httpd.c   **** 					*appstate = TCP_APPSTATE_EMPTYACK;
 454:net/httpd.c   **** 					return (pos-TCP_POS_TXDATA);
 455:net/httpd.c   **** 				}else{
 456:net/httpd.c   **** 					//add ok
 457:net/httpd.c   **** 					pos = httpd_add_progmem_data(HTTPD_RESPONSE_OK,NULL, buffer, pos, 0, NIC_BUFFERSIZE-pos);
 458:net/httpd.c   **** 					
 459:net/httpd.c   **** 					//add content type, detects jpg,png,bmp,gif,html -> default is html!
 460:net/httpd.c   **** 					//we need to check first char only !!
 461:net/httpd.c   **** 					switch(file_ext[0]){
 462:net/httpd.c   **** 						case ('j'): //if (string_compare_progmem_noeof("jpg", file_ext))
 463:net/httpd.c   **** 							pos = httpd_add_progmem_data(HTTPD_CTYPE_JPG,NULL, buffer, pos, 0, NIC_BUFFERSIZE-pos);
 464:net/httpd.c   **** 							break;
 465:net/httpd.c   **** 
 466:net/httpd.c   **** 						case ('p'): //else if (string_compare_progmem_noeof("png", file_ext))
 467:net/httpd.c   **** 							pos = httpd_add_progmem_data(HTTPD_CTYPE_PNG,NULL, buffer, pos, 0, NIC_BUFFERSIZE-pos);
 468:net/httpd.c   **** 							break;
 469:net/httpd.c   **** 
 470:net/httpd.c   **** 						case ('b'): //else if (string_compare_progmem_noeof("bmp", file_ext))
 471:net/httpd.c   **** 							pos = httpd_add_progmem_data(HTTPD_CTYPE_BMP,NULL, buffer, pos, 0, NIC_BUFFERSIZE-pos);
 472:net/httpd.c   **** 							break;
 473:net/httpd.c   **** 
 474:net/httpd.c   **** 						case ('g'): //else if (string_compare_progmem_noeof("gif", file_ext))
 475:net/httpd.c   **** 							pos = httpd_add_progmem_data(HTTPD_CTYPE_GIF,NULL, buffer, pos, 0, NIC_BUFFERSIZE-pos);
 476:net/httpd.c   **** 							break;
 477:net/httpd.c   **** 
 478:net/httpd.c   **** 						default: //htm!
 479:net/httpd.c   **** 							pos = httpd_add_progmem_data(HTTPD_CTYPE_HTML,NULL, buffer, pos, 0, NIC_BUFFERSIZE-pos);
 480:net/httpd.c   **** 							break;
 481:net/httpd.c   **** 					}
 482:net/httpd.c   **** 				
 483:net/httpd.c   **** 					//add \r\n\r\n
 484:net/httpd.c   **** 					pos = httpd_add_progmem_data(HTTPD_RNRN,NULL, buffer, pos, 0, NIC_BUFFERSIZE-pos);
 485:net/httpd.c   **** 					*appstate = TCP_APPSTATE_HAS_TXDATA;
 486:net/httpd.c   **** 
 487:net/httpd.c   **** 					//http conn active now -> send data
 488:net/httpd.c   **** 					httpd_conn[socketnum].state      = HTTPD_STATE_ACTIVE;
 489:net/httpd.c   **** 
 490:net/httpd.c   **** 					//store seq offset!
 491:net/httpd.c   **** 					httpd_conn[socketnum].seq_offset = pos - datapos + 1;
 492:net/httpd.c   **** 
 493:net/httpd.c   **** 					return (pos-TCP_POS_TXDATA);
 494:net/httpd.c   **** 				}
 495:net/httpd.c   **** 			}
 496:net/httpd.c   **** 
 497:net/httpd.c   **** 			*appstate = TCP_APPSTATE_EMPTYACK;
 498:net/httpd.c   **** 			return (0);
 499:net/httpd.c   **** 			break;
 500:net/httpd.c   **** 
 501:net/httpd.c   **** 		case(HTTPD_STATE_ACTIVE):
 502:net/httpd.c   **** 			#if HTTPD_DEBUG2
 503:net/httpd.c   **** 			softuart_put_uint16(httpd_conn[socketnum].seq_offset);
 504:net/httpd.c   **** 			#endif
 505:net/httpd.c   **** 			offset = (tcp_sockets[socketnum].seq - httpd_conn[socketnum].seq_offset);
 506:net/httpd.c   **** 			*appstate = TCP_APPSTATE_HAS_TXDATA;
 507:net/httpd.c   **** 
 508:net/httpd.c   **** 			if (httpd_conn[socketnum].file_id <= 0xFF){
 509:net/httpd.c   **** 				///this file is not stored on dataflash
 510:net/httpd.c   **** 				switch ((httpd_conn[socketnum].file_id)&0xFF){
 511:net/httpd.c   **** 					///index.html
 512:net/httpd.c   **** 					case(HTTPD_STATE_FILE_INDEX):
 513:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML,HTTPD_FILE_SITE_START_HTML,buffer,TCP_POS_
 514:net/httpd.c   **** 						break;
 515:net/httpd.c   **** 
 516:net/httpd.c   **** 					///graph0
 517:net/httpd.c   **** 					case(HTTPD_STATE_FILE_GRAPH0):
 518:net/httpd.c   **** 						ret = plot_generate_bmp(buffer, TCP_POS_TXDATA, NIC_BUFFERSIZE-TCP_POS_TXDATA, offset, PLOT_S
 519:net/httpd.c   **** 						break;
 520:net/httpd.c   **** 
 521:net/httpd.c   **** 					///upload test
 522:net/httpd.c   **** 					case(HTTPD_STATE_FILE_UP):
 523:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML,HTTPD_FILE_SITE_UPLOAD_HTML,buffer,TCP_POS
 524:net/httpd.c   **** 						break;
 525:net/httpd.c   **** 
 526:net/httpd.c   **** 					///list	fs files
 527:net/httpd.c   **** 					case(HTTPD_STATE_FILE_FS_LS):
 528:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML,HTTPD_FILE_SITE_FSLS_HTML,buffer,TCP_POS_T
 529:net/httpd.c   **** 						break;
 530:net/httpd.c   **** 
 531:net/httpd.c   **** 					///upload finished, up ok
 532:net/httpd.c   **** 					case(HTTPD_STATE_FILE_UP_DONE):
 533:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML,HTTPD_FILE_SITE_UPOK_HTML,buffer,TCP_POS_T
 534:net/httpd.c   **** 						break;
 535:net/httpd.c   **** 
 536:net/httpd.c   **** 					///upload finished, up err
 537:net/httpd.c   **** 					case(HTTPD_STATE_FILE_UP_ERR):
 538:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML,HTTPD_FILE_SITE_UPERR_HTML,buffer,TCP_POS_
 539:net/httpd.c   **** 						break;
 540:net/httpd.c   **** 
 541:net/httpd.c   **** 					///removed fs file
 542:net/httpd.c   **** 					case(HTTPD_STATE_FILE_REMOVED):
 543:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML,HTTPD_FILE_SITE_RMOK_HTML,buffer,TCP_POS_T
 544:net/httpd.c   **** 						break;
 545:net/httpd.c   **** 
 546:net/httpd.c   **** 					///format filesystem question
 547:net/httpd.c   **** 					case(HTTPD_STATE_FILE_MKFS):
 548:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML, HTTPD_FILE_SITE_MKFS_HTML,buffer,TCP_POS_
 549:net/httpd.c   **** 						break;
 550:net/httpd.c   **** 
 551:net/httpd.c   **** 					///do format
 552:net/httpd.c   **** 					case(HTTPD_STATE_FILE_MKFS2):
 553:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML, HTTPD_FILE_SITE_MKFS2_HTML,buffer,TCP_POS
 554:net/httpd.c   **** 						break;
 555:net/httpd.c   **** 
 556:net/httpd.c   **** 					///cam/pic (webcam picture)
 557:net/httpd.c   **** 					case(HTTPD_STATE_FILE_CAM_PIC):
 558:net/httpd.c   **** 						ret = mca25_grab_data(&buffer[TCP_POS_TXDATA], NIC_BUFFERSIZE-TCP_POS_TXDATA, offset, socketn
 559:net/httpd.c   **** 						if (ret == 0xFFFE){
 560:net/httpd.c   **** 							//cam is busy -> show busy jpg !
 561:net/httpd.c   **** 							ret = httpd_add_progmem_data_bin(HTTPD_CAM_BUSY_JPG,buffer,TCP_POS_TXDATA, offset, NIC_BUFFE
 562:net/httpd.c   **** 							httpd_conn[socketnum].file_id = 6;
 563:net/httpd.c   **** 						}else if (ret == 0xFFFF){
 564:net/httpd.c   **** 							ret = 1;
 565:net/httpd.c   **** 						}
 566:net/httpd.c   **** 						//add offset
 567:net/httpd.c   **** 						if (ret != 0)
 568:net/httpd.c   **** 							ret = TCP_POS_TXDATA + ret;
 569:net/httpd.c   **** 						
 570:net/httpd.c   **** 						break;
 571:net/httpd.c   **** 
 572:net/httpd.c   **** 					///cam/busy  ->  cam busy jpg
 573:net/httpd.c   **** 					case(HTTPD_STATE_FILE_CAM_BUSY):
 574:net/httpd.c   **** 						ret = httpd_add_progmem_data_bin(HTTPD_CAM_BUSY_JPG,buffer,TCP_POS_TXDATA, offset, NIC_BUFFER
 575:net/httpd.c   **** 						break;
 576:net/httpd.c   **** 
 577:net/httpd.c   **** 					///site/cam  ->  include cam html code
 578:net/httpd.c   **** 					case(HTTPD_STATE_FILE_SITE_CAM):
 579:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML,HTTPD_FILE_SITE_CAM_HTML,buffer,TCP_POS_TX
 580:net/httpd.c   **** 						break;
 581:net/httpd.c   **** 
 582:net/httpd.c   **** 					///site/temp  ->  include templog
 583:net/httpd.c   **** 					case(HTTPD_STATE_FILE_SITE_TEMP):
 584:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML,HTTPD_FILE_SITE_TEMP_HTML,buffer,TCP_POS_T
 585:net/httpd.c   **** 						break;
 586:net/httpd.c   **** 
 587:net/httpd.c   **** 					///site/io  ->  port io site
 588:net/httpd.c   **** 					case(HTTPD_STATE_FILE_SITE_IO):
 589:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML,HTTPD_FILE_SITE_IO_HTML,buffer,TCP_POS_TXD
 590:net/httpd.c   **** 						break;
 591:net/httpd.c   **** 
 592:net/httpd.c   **** 					///set/xx_1 -> show green io pic
 593:net/httpd.c   **** 					case(HTTPD_STATE_FILE_SET_IO_1_PIC):
 594:net/httpd.c   **** 						ret = httpd_add_progmem_data_bin(HTTPD_BUTTON_GREEN,buffer,TCP_POS_TXDATA, offset, NIC_BUFFER
 595:net/httpd.c   **** 						break;
 596:net/httpd.c   **** 
 597:net/httpd.c   **** 					///set/xx_0 -> show red io pic
 598:net/httpd.c   **** 					case(HTTPD_STATE_FILE_SET_IO_0_PIC):
 599:net/httpd.c   **** 						ret = httpd_add_progmem_data_bin(HTTPD_BUTTON_RED,buffer,TCP_POS_TXDATA, offset, NIC_BUFFERSI
 600:net/httpd.c   **** 						break;
 601:net/httpd.c   **** 
 602:net/httpd.c   **** 					///servo moving
 603:net/httpd.c   **** 					case(HTTPD_STATE_FILE_SERVO_OK):
 604:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_INDEX_HTML,HTTPD_FILE_SITE_SERVO_OK,buffer,TCP_POS_TX
 605:net/httpd.c   **** 						break;
 606:net/httpd.c   **** 
 607:net/httpd.c   **** 					///get/set servo pos
 608:net/httpd.c   **** 					case(HTTPD_STATE_FILE_SERVO_POS):
 609:net/httpd.c   **** 						ret = servo_generate_bmp(buffer, TCP_POS_TXDATA, NIC_BUFFERSIZE-TCP_POS_TXDATA, offset, PLOT_
 610:net/httpd.c   **** 						break;
 611:net/httpd.c   **** 
 612:net/httpd.c   **** 					///add file icon gif
 613:net/httpd.c   **** 					case(HTTPD_STATE_FILE_SITE_FILE_ICON_PIC):
 614:net/httpd.c   **** 						ret = httpd_add_progmem_data_bin(HTTPD_FILE_ICON_GIF,buffer,TCP_POS_TXDATA, offset, NIC_BUFFE
 615:net/httpd.c   **** 						break;
 616:net/httpd.c   **** 
 617:net/httpd.c   **** 					///404 - not found !
 618:net/httpd.c   **** 					default:
 619:net/httpd.c   **** 						#if HTTPD_DEBUG
 620:net/httpd.c   **** 						softuart_puts_progmem("HTTP: 404 file not found!");
 621:net/httpd.c   **** 						softuart_putnewline();
 622:net/httpd.c   **** 						#endif
 623:net/httpd.c   **** 						ret = httpd_add_progmem_data(HTTPD_FILE_NOT_FOUND,NULL,buffer,TCP_POS_TXDATA, offset, NIC_BUF
 624:net/httpd.c   **** 						break;
 625:net/httpd.c   **** 				}
 626:net/httpd.c   **** 			}else{
 627:net/httpd.c   **** 				///this file is stored on dataflash!
 628:net/httpd.c   **** 				//-> send data from file x:
 629:net/httpd.c   **** 				if ((httpd_conn[socketnum].data_position != offset) || (offset == 0)){
 630:net/httpd.c   **** 					//we must (re)seek to position offset!
 631:net/httpd.c   **** 					ret = filesystem_get_data(buffer, TCP_POS_TXDATA, NIC_BUFFERSIZE-TCP_POS_TXDATA, offset, (http
 632:net/httpd.c   **** 					//this is wrong if this is the last packet, 
 633:net/httpd.c   **** 					//but it does not matter, after the last packet we do not need datapos any more
 634:net/httpd.c   **** 					httpd_conn[socketnum].data_position = offset + (NIC_BUFFERSIZE-TCP_POS_TXDATA); 
 635:net/httpd.c   **** 				}else{
 636:net/httpd.c   **** 					//data_ptr -> flash page
 637:net/httpd.c   **** 					//data_position % 256 -> position inside page
 638:net/httpd.c   **** 					unsigned char indpos = httpd_conn[socketnum].data_position & 0xFF; // %256; 
 639:net/httpd.c   **** 					ret = filesystem_get_data_startat(buffer, TCP_POS_TXDATA, NIC_BUFFERSIZE-TCP_POS_TXDATA, &http
 640:net/httpd.c   **** 					//this is wrong if this is the last packet, 
 641:net/httpd.c   **** 					//but it does not matter, after the last packet we do not need datapos any more
 642:net/httpd.c   **** 					httpd_conn[socketnum].data_position += (NIC_BUFFERSIZE-TCP_POS_TXDATA);
 643:net/httpd.c   **** 				}
 644:net/httpd.c   **** 				
 645:net/httpd.c   **** 			}
 646:net/httpd.c   **** 
 647:net/httpd.c   **** 			#if HTTPD_DEBUG2
 648:net/httpd.c   **** 			softuart_puts_progmem("\r\nret=");
 649:net/httpd.c   **** 			softuart_put_uint8(ret);
 650:net/httpd.c   **** 			#endif
 651:net/httpd.c   **** 			if (ret != 0){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -