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

📄 httpserv.s

📁 单片机C语言程序设计实训100例--基于AVR+PROTEUS仿真
💻 S
📖 第 1 页 / 共 5 页
字号:
	.module httpserv.c
	.area text(rom, con, rel)
	.dbfile C:\ethernut-4.9.7\nutapp_13h\httpd\httpserv.c
	.area data(ram, con, rel)
	.dbfile C:\ethernut-4.9.7\nutapp_13h\httpd\httpserv.c
_html_mt:
	.blkw 1
	.area idata
	.word L2
	.area data(ram, con, rel)
	.dbfile C:\ethernut-4.9.7\nutapp_13h\httpd\httpserv.c
	.dbsym s html_mt _html_mt pc
	.area text(rom, con, rel)
	.dbfile C:\ethernut-4.9.7\nutapp_13h\httpd\httpserv.c
	.dbfunc s ASPCallback _ASPCallback fI
	.dbstruct 0 0 __iobuf
	.dbend
;         stream -> R10,R11
;   pASPFunction -> R12,R13
	.even
_ASPCallback:
	xcall push_xgset003C
	movw R10,R18
	movw R12,R16
	.dbline -1
	.dbline 263
; /*
;  * Copyright (C) 2001-2004 by egnite Software GmbH. All rights reserved.
;  *
;  * Redistribution and use in source and binary forms, with or without
;  * modification, are permitted provided that the following conditions
;  * are met:
;  *
;  * 1. Redistributions of source code must retain the above copyright
;  *    notice, this list of conditions and the following disclaimer.
;  * 2. Redistributions in binary form must reproduce the above copyright
;  *    notice, this list of conditions and the following disclaimer in the
;  *    documentation and/or other materials provided with the distribution.
;  * 3. Neither the name of the copyright holders nor the names of
;  *    contributors may be used to endorse or promote products derived
;  *    from this software without specific prior written permission.
;  *
;  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
;  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
;  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
;  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
;  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
;  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
;  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
;  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
;  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
;  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
;  * SUCH DAMAGE.
;  *
;  * For additional information see http://www.ethernut.de/
;  *
;  */
; 
; /*!
;  * $Log$
;  * Revision 1.21  2009/02/18 12:18:58  olereinhardt
;  * 2009-02-18  Ole Reinhardt <ole.reinhardt@thermotemp.de>
;  *
;  *           Fixed compilier warnings. Especialy signedness of char buffers
;  *           as well as unused code on arm platform and main functions without
;  *           return value
;  *
;  * Revision 1.20  2009/02/06 15:37:40  haraldkipp
;  * Added stack space multiplier and addend. Adjusted stack space.
;  *
;  * Revision 1.19  2008/07/25 10:20:12  olereinhardt
;  * Fixed compiler bug for AVR-ICC and added missing PSTR macro around
;  * prog_char strings
;  *
;  * Revision 1.18  2008/07/17 11:56:20  olereinhardt
;  * Updated the webserver demo to show new webserver functions (different cgi
;  * pathes with seperate authentication, $QUERY_STRING parameter for ssi
;  * included CGIs)
;  *
;  * Revision 1.17  2008/05/13 19:31:34  thiagocorrea
;  * NutHttpSendHeaderBot is marked as deprecated, use NutHttpSendHeaderBottom instead.
;  *
;  * Revision 1.16  2007/07/17 18:29:30  haraldkipp
;  * Server thread names not unique on SAM7X. Fixed by Marti Raudsepp.
;  *
;  * Revision 1.15  2006/09/07 09:01:36  haraldkipp
;  * Discovery registration added.
;  * Re-arranged network interface setup to exclude DHCP code from ICCAVR
;  * builds and make it work with the demo compiler. Unfinished.
;  * Added PHAT file system support. Untested.
;  *
;  * Revision 1.14  2006/03/02 19:44:03  haraldkipp
;  * MMC and PHAT enabled.
;  *
;  * Revision 1.13  2006/01/11 08:32:57  hwmaier
;  * Added explicit type casts to silence a few avr-gcc 3.4.3 warning messages
;  *
;  * Revision 1.12  2005/11/22 09:14:13  haraldkipp
;  * Replaced specific device names by generalized macros.
;  *
;  * Revision 1.11  2005/10/16 23:22:20  hwmaier
;  * Removed unreferenced nutconfig.h include statement
;  *
;  * Revision 1.10  2005/08/05 11:32:50  olereinhardt
;  * Added SSI and ASP sample
;  *
;  * Revision 1.9  2005/04/05 18:04:17  haraldkipp
;  * Support for ARM7 Wolf Board added.
;  *
;  * Revision 1.8  2005/02/23 04:39:26  hwmaier
;  * no message
;  *
;  * Revision 1.7  2005/02/22 02:44:34  hwmaier
;  * Changes to compile as well for AT90CAN128 device.
;  *
;  * Revision 1.6  2004/12/16 10:17:18  haraldkipp
;  * Added Mikael Adolfsson's excellent parameter parsing routines.
;  *
;  * Revision 1.5  2004/03/16 16:48:26  haraldkipp
;  * Added Jan Dubiec's H8/300 port.
;  *
;  * Revision 1.4  2003/11/04 17:46:52  haraldkipp
;  * Adapted to Ethernut 2
;  *
;  * Revision 1.3  2003/09/29 16:33:12  haraldkipp
;  * Using portable strtok and strtok_r
;  *
;  * Revision 1.2  2003/08/07 08:27:58  haraldkipp
;  * Bugfix, remote not displayed in socket list
;  *
;  * Revision 1.1  2003/07/20 15:56:14  haraldkipp
;  * *** empty log message ***
;  *
;  */
; 
; /*!
;  * \example httpd/httpserv.c
;  *
;  * Simple multithreaded HTTP daemon.
;  */
; 
; /* 
;  * Unique MAC address of the Ethernut Board. 
;  *
;  * Ignored if EEPROM contains a valid configuration.
;  */
; #define MY_MAC  "\x00\x06\x98\x30\x00\x35"
; 
; /* 
;  * Unique IP address of the Ethernut Board. 
;  *
;  * Ignored if DHCP is used. 
;  */
; #define MY_IPADDR "192.168.192.35"
; 
; /* 
;  * IP network mask of the Ethernut Board.
;  *
;  * Ignored if DHCP is used. 
;  */
; #define MY_IPMASK "255.255.255.0"
; 
; /* 
;  * Gateway IP address for the Ethernut Board.
;  *
;  * Ignored if DHCP is used. 
;  */
; #define MY_IPGATE "192.168.192.1"
; 
; /* ICCAVR Demo is limited. Try to use the bare minimum. */
; #if !defined(__IMAGECRAFT__)
; 
; /* Wether we should use DHCP. */
; #define USE_DHCP
; /* Wether we should run a discovery responder. */
; #define USE_DISCOVERY
; /* Wether to use PHAT file system. */
; //#define USE_PHAT
; 
; #endif /* __IMAGECRAFT__ */
; 
; 
; #ifdef USE_PHAT
; 
; #if defined(ETHERNUT3)
; 
; /* Ethernut 3 file system. */
; #define MY_FSDEV       devPhat0
; #define MY_FSDEV_NAME  "PHAT0" 
; 
; /* Ethernut 3 block device interface. */
; #define MY_BLKDEV      devNplMmc0
; #define MY_BLKDEV_NAME "MMC0"
; 
; #elif defined(AT91SAM7X_EK)
; 
; /* SAM7X-EK file system. */
; #define MY_FSDEV       devPhat0
; #define MY_FSDEV_NAME  "PHAT0" 
; 
; /* SAM7X-EK block device interface. */
; #define MY_BLKDEV      devAt91SpiMmc0
; #define MY_BLKDEV_NAME "MMC0"
; 
; #elif defined(AT91SAM9260_EK)
; 
; /* SAM9260-EK file system. */
; #define MY_FSDEV       devPhat0
; #define MY_FSDEV_NAME  "PHAT0" 
; 
; /* SAM9260-EK block device interface. */
; #define MY_BLKDEV      devAt91Mci0
; #define MY_BLKDEV_NAME "MCI0"
; 
; #endif
; #endif /* USE_PHAT */
; 
; #ifndef MY_FSDEV
; #define MY_FSDEV        devUrom
; #endif
; 
; #ifdef MY_FSDEV_NAME
; #define MY_HTTPROOT     MY_FSDEV_NAME ":/" 
; #endif
; 
; 
; #include <cfg/os.h>
; 
; #include <string.h>
; #include <io.h>
; #include <fcntl.h>
; #include <time.h>
; 
; #include <dev/board.h>
; #include <dev/urom.h>
; #include <dev/nplmmc.h>
; #include <dev/sbimmc.h>
; #include <fs/phatfs.h>
; 
; #include <sys/version.h>
; #include <sys/thread.h>
; #include <sys/timer.h>
; #include <sys/heap.h>
; #include <sys/confnet.h>
; #include <sys/socket.h>
; 
; #include <arpa/inet.h>
; #include <net/route.h>
; 
; #include <pro/httpd.h>
; #include <pro/dhcp.h>
; #include <pro/ssi.h>
; #include <pro/asp.h>
; #include <pro/discover.h>
; 
; #ifdef NUTDEBUG
; #include <sys/osdebug.h>
; #include <net/netdebug.h>
; #endif
; 
; /* Server thread stack size. */
; #ifndef HTTPD_SERVICE_STACK
; #if defined(__AVR__)
; #define HTTPD_SERVICE_STACK ((580 * NUT_THREAD_STACK_MULT) + NUT_THREAD_STACK_ADD)
; #elif defined(__arm__)
; #define HTTPD_SERVICE_STACK ((1024 * NUT_THREAD_STACK_MULT) + NUT_THREAD_STACK_ADD)
; #else
; #define HTTPD_SERVICE_STACK  ((2048 * NUT_THREAD_STACK_MULT) + NUT_THREAD_STACK_ADD)
; #endif
; #endif
; 
; static char *html_mt = "text/html";
; 
; 
; /**************************************************************/
; /*  ASPCallback                                               */
; /*                                                            */
; /* This routine must have been registered by                  */
; /* NutRegisterAspCallback() and is automatically called by    */
; /* NutHttpProcessFileRequest() when the server process a page */
; /* with an asp function.                                      */
; /*                                                            */
; /* Return 0 on success, -1 otherwise.                         */
; /**************************************************************/
; 
; 
; static int ASPCallback (char *pASPFunction, FILE *stream)
; {
	.dbline 264
;     if (strcmp(pASPFunction, "usr_date") == 0) {
	ldi R18,<L6
	ldi R19,>L6
	movw R16,R12
	xcall _strcmp
	cpi R16,0
	cpc R16,R17
	brne L4
X0:
	.dbline 264
	.dbline 265
;         fprintf(stream, "Dummy example: 01.01.2005");
	ldi R18,<L7
	ldi R19,>L7
	movw R16,R10
	xcall _fprintf
	.dbline 266
;         return(0);
	clr R16
	clr R17
	xjmp L3
L4:
	.dbline 269
;     }
; 
;     if (strcmp(pASPFunction, "usr_time") == 0) {
	ldi R18,<L10
	ldi R19,>L10
	movw R16,R12
	xcall _strcmp
	cpi R16,0
	cpc R16,R17
	brne L8
X1:
	.dbline 269
	.dbline 270
;         fprintf(stream, "Dummy example: 12:15:02");
	ldi R18,<L11
	ldi R19,>L11
	movw R16,R10
	xcall _fprintf
	.dbline 271
;         return(0);
	clr R16
	clr R17
	xjmp L3
L8:
	.dbline 274
;     }
; 
;     return (-1);
	ldi R16,-1
	ldi R17,-1
	.dbline -2
L3:
	.dbline 0 ; func end
	xjmp pop_xgset003C
	.dbsym r stream 10 pS[__iobuf]
	.dbsym r pASPFunction 12 pc
	.dbend
	.area lit(rom, con, rel)
L13:
	.byte 60,'H,'T,'M,'L,62,60,'H,'E,'A,'D,62,60,'T,'I,'T
	.byte 'L,'E,62,'P,'a,'r,'a,'m,'e,'t,'e,'r,'s,60,47,'T
	.byte 'I,'T,'L,'E,62,60,47,'H,'E,'A,'D,62,60,'B,'O,'D
	.byte 'Y,62,60,'H,49,62,'P,'a,'r,'a,'m,'e,'t,'e,'r,'s
	.byte 60,47,'H,49,62,0
L14:
	.byte 60,47,'B,'O,'D,'Y,62,60,47,'H,'T,'M,'L,62,0
L15:
	.byte 'M,'e,'t,'h,'o,'d,58,32,37,'s,60,'B,'R,62,13,10
	.byte 'V,'e,'r,'s,'i,'o,'n,58,32,'H,'T,'T,'P,47,37,'d
	.byte 46,37,'d,60,'B,'R,62,13,10,'C,'o,'n,'t,'e,'n,'t
	.byte 32,'l,'e,'n,'g,'t,'h,58,32,37,'l,'d,60,'B,'R,62
	.byte 13,10,0
L16:
	.byte 'U,'R,'L,58,32,37,'s,60,'B,'R,62,13,10,0
L17:
	.byte 'A,'r,'g,'u,'m,'e,'n,'t,58,32,37,'s,60,'B,'R,62
	.byte 13,10,0
L18:
	.byte 'C,'o,'n,'t,'e,'n,'t,32,'t,'y,'p,'e,58,32,37,'s
	.byte 60,'B,'R,62,13,10,0
L19:
	.byte 'C,'o,'o,'k,'i,'e,58,32,37,'s,60,'B,'R,62,13,10
	.byte 0
L20:
	.byte 'A,'u,'t,'h,32,'i,'n,'f,'o,58,32,37,'s,60,'B,'R
	.byte 62,13,10,0
L21:
	.byte 'U,'s,'e,'r,32,'a,'g,'e,'n,'t,58,32,37,'s,60,'B
	.byte 'R,62,13,10,0
	.area text(rom, con, rel)
	.dbfile C:\ethernut-4.9.7\nutapp_13h\httpd\httpserv.c
	.dbfunc s ShowQuery _ShowQuery fI
	.dbstruct 0 34 _REQUEST
	.dbfield 0 req_method I
	.dbfield 2 req_version I
	.dbfield 4 req_length L
	.dbfield 8 req_url pc
	.dbfield 10 req_query pc
	.dbfield 12 req_type pc
	.dbfield 14 req_cookie pc
	.dbfield 16 req_auth pc
	.dbfield 18 req_agent pc
	.dbfield 20 req_qptrs ppc
	.dbfield 22 req_numqptrs I
	.dbfield 24 req_ims L
	.dbfield 28 req_referer pc
	.dbfield 30 req_host pc
	.dbfield 32 req_connection I
	.dbend
	.dbsym s agent_fmt L21 A[21:21]kc
	.dbsym s auth_fmt L20 A[20:20]kc
	.dbsym s cookie_fmt L19 A[17:17]kc
	.dbsym s type_fmt L18 A[23:23]kc
	.dbsym s query_fmt L17 A[19:19]kc
	.dbsym s url_fmt L16 A[14:14]kc
	.dbsym s req_fmt L15 A[67:67]kc
	.dbsym s foot L14 A[15:15]kc
	.dbsym s head L13 A[70:70]kc
;             cp -> R22,R23
;            req -> R20,R21
;         stream -> R10,R11
	.even
_ShowQuery:
	xcall push_xgsetF00C
	movw R20,R18
	movw R10,R16
	sbiw R28,10
	.dbline -1
	.dbline 287
; }
; 
; /*
;  * CGI Sample: Show request parameters.
;  *
;  * See httpd.h for REQUEST structure.
;  *
;  * This routine must have been registered by NutRegisterCgi() and is
;  * automatically called by NutHttpProcessRequest() when the client
;  * request the URL 'cgi-bin/test.cgi'.
;  */
; static int ShowQuery(FILE * stream, REQUEST * req)
; {
	.dbline 306
;     char *cp;
;     /*
;      * This may look a little bit weird if you are not used to C programming
;      * for flash microcontrollers. The special type 'prog_char' forces the
;      * string literals to be placed in flash ROM. This saves us a lot of
;      * precious RAM.
;      */
;     static prog_char head[] = "<HTML><HEAD><TITLE>Parameters</TITLE></HEAD><BODY><H1>Parameters</H1>";
;     static prog_char foot[] = "</BODY></HTML>";
;     static prog_char req_fmt[] = "Method: %s<BR>\r\nVersion: HTTP/%d.%d<BR>\r\nContent length: %ld<BR>\r\n";
;     static prog_char url_fmt[] = "URL: %s<BR>\r\n";
;     static prog_char query_fmt[] = "Argument: %s<BR>\r\n";
;     static prog_char type_fmt[] = "Content type: %s<BR>\r\n";
;     static prog_char cookie_fmt[] = "Cookie: %s<BR>\r\n";
;     static prog_char auth_fmt[] = "Auth info: %s<BR>\r\n";
;     static prog_char agent_fmt[] = "User agent: %s<BR>\r\n";
; 
;     /* These useful API calls create a HTTP response for us. */
;     NutHttpSendHeaderTop(stream, req, 200, "Ok");
	ldi R24,<L22
	ldi R25,>L22
	std y+3,R25
	std y+2,R24
	ldi R24,200
	ldi R25,0
	std y+1,R25
	std y+0,R24
	movw R18,R20
	movw R16,R10
	xcall _NutHttpSendHeaderTop
	.dbline 307
;     NutHttpSendHeaderBottom(stream, req, html_mt, -1);
	ldi R24,255
	ldi R25,255
	ldi R26,255
	ldi R27,255
	std y+2,R24
	std y+3,R25
	std y+4,R26
	std y+5,R27
	lds R2,_html_mt
	lds R3,_html_mt+1
	std y+1,R3
	std y+0,R2
	movw R18,R20
	movw R16,R10
	xcall _NutHttpSendHeaderBottom
	.dbline 310
; 
;     /* Send HTML header. */
;     fputs_P(head, stream);
	movw R18,R10
	ldi R16,<L13
	ldi R17,>L13
	xcall _fputs_P
	.dbline 315
; 
;     /*
;      * Send request parameters.
;      */
;     switch (req->req_method) {
	movw R30,R20
	ldd R22,z+0
	ldd R23,z+1
	cpi R22,1
	ldi R30,0
	cpc R23,R30
	breq L26
X2:
	cpi R22,2
	ldi R30,0
	cpc R23,R30
	breq L28
X3:
	cpi R22,3
	ldi R30,0
	cpc R23,R30
	breq L30
X4:
	xjmp L23
L26:
	.dbline 317
;     case METHOD_GET:
;         cp = "GET";
	ldi R22,<L27
	ldi R23,>L27
	.dbline 318
;         break;
	xjmp L24
L28:
	.dbline 320
;     case METHOD_POST:
;         cp = "POST";
	ldi R22,<L29
	ldi R23,>L29
	.dbline 321
;         break;
	xjmp L24
L30:
	.dbline 323
;     case METHOD_HEAD:
;         cp = "HEAD";
	ldi R22,<L31
	ldi R23,>L31
	.dbline 324
;         break;
	xjmp L24
L23:
	.dbline 326
;     default:
;         cp = "UNKNOWN";
	ldi R22,<L32
	ldi R23,>L32
	.dbline 327
;         break;
L24:
	.dbline 329
;     }
;     fprintf_P(stream, req_fmt, cp, req->req_version / 10, req->req_version % 10, req->req_length);
	movw R30,R20
	ldd R2,z+4
	ldd R3,z+5
	ldd R4,z+6
	ldd R5,z+7
	std y+6,R2
	std y+7,R3
	std y+8,R4
	std y+9,R5
	ldd R2,z+2
	ldd R3,z+3
	ldi R18,10
	ldi R19,0
	movw R16,R2
	xcall mod16s
	std y+5,R17
	std y+4,R16
	ldi R18,10
	ldi R19,0
	movw R16,R2
	xcall div16s
	std y+3,R17
	std y+2,R16
	std y+1,R23
	std y+0,R22
	ldi R18,<L15
	ldi R19,>L15

⌨️ 快捷键说明

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