VxWorksMipsHttpd

From ProjectWiki
Jump to: navigation, search

What is this?

This is a HTTP daemon for the VxWorks operating system written entirely in Assembly language with conventional VxWorks/gcc calling conventions so it interfaces with other C programs and the built in debugger seemlessly. It features both POST, GET, parses mime types and will upload files. ^^

Source Code

#this function is just to demonstrate the executable webpage option, not necessary
webExecDemo:
		addiu	$sp,-0x20
		sw	$ra,0x1c($sp)
		sw	$s0,0x18($sp)
		move	$s0,$a0
		sw	$s1,0x14($sp)
		move	$s1,$a1
		sw	$s2,0x10($sp)
		sw	$s3,0x0c($sp)
		sw	$s4,0x08($sp)
		move	$s4,$a2
		jal	taskIdSelf
		nop
		move	$s2,$v0
		move	$a0,$v0
		jal	ioTaskStdGet
		li	$a1,1		#get current task so we can reset output
		move	$s3,$v0
		move	$a0,$s2
		li	$a1,1
		jal	ioTaskStdSet
		move	$a2,$s0		#redirect console output to www
		
		la	$a0,aWebExecDemoTxt
		move	$a1,$s1
		jal	printf
		move	$a2,$s0

		jal	webInfo
		move	$a0,$s4

		jal	envShow
		move	$a0,$0

		la	$a0,webExecDemo
		jal	l
		li	$a1,29

		move	$a0,$s2
		li	$a1,1
		jal	ioTaskStdSet
		move	$a2,$s3		#redirect console output back to whatever

		lw	$s4,0x8($sp)
		lw	$s3,0xc($sp)
		lw	$s2,0x10($sp)				
		lw	$s1,0x14($sp)
		lw	$s0,0x18($sp)		
		lw	$ra,0x1c($sp)
		jr	$ra
		addiu	$sp,0x20

#webShowEnSyms(webhandle) lists all symbols allowed to be NV pairs
webShowEnSyms:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		move	$s0,$a0
		la	$a0,awebShowNvsHdr
		jal	printf
		lw	$a1,0x20($s0)
		lw	$s0,0x4($s0)
showwnvp:
		la	$a0,aslfcr
		jal	printf		#show us what u got line by line
		lw	$a1,0x0($s0)
		lw	$v0,0x4($s0)	#check the next one for a blank
		bnez	$v0,showwnvp	#should work since there is allways 1 at least!!
		addiu	$s0,0x4
		lw	$ra,0x2c($sp)
		lw	$s0,0x28($sp)	
		jr	$ra
		addiu	$sp,0x30

#webShowPages(handle) lists all web pages in current table
webShowPages:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		move	$s0,$a0
		la	$a0,ashowWebHeader
		jal	printf
		lw	$a1,0x20($s0)
		lw	$s0,0($s0)
showwpfb:
		la	$a0,a02x06x0x08xs
		lw	$a1,0x8($s0)
		lw	$a2,0xc($s0)
		lw	$a3,0x0($s0)
		sw	$a3,0x10($sp)
		jal	printf		#show us what u got line by line
		lw	$a3,0x4($s0)		
		lw	$v0,0x10($s0)	#check the next one for a blank
		bnez	$v0,showwpfb	#should work since there is allways 1 at least!!
		addiu	$s0,0x10
		lw	$ra,0x2c($sp)
		lw	$s0,0x28($sp)	
		jr	$ra
		addiu	$sp,0x30

#webShowTypes(handle) will show known file extention types and their content-type
webShowTypes:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		nop
		move	$s0,$a0
		la	$a0,awebShowTypesHdr
		jal	printf
		lw	$a1,0x20($s0)
		lw	$s0,0x8($s0)
showtyp:
		la	$a0,a10ss
		lw	$a1,0x0($s0)
		jal	printf		#show us what u got line by line
		lw	$a2,0x4($s0)
		lw	$v0,0x8($s0)	#check the next one for a blank
		bnez	$v0,showtyp	#should work since there is allways 1 at least!!
		addiu	$s0,0x8
		lw	$ra,0x2c($sp)
		lw	$s0,0x28($sp)	
		jr	$ra
		addiu	$sp,0x30

#webFindType(handle, int Fd, str * filename)  Searchs for file known file extentions, if found it sends out a header
webFindType:
		addiu	$sp,-0x230
		sw	$ra,0x22c($sp)
		sw	$s0,0x228($sp)
		sw	$s1,0x224($sp)
		sw	$s2,0x220($sp)
		move	$s2,$a0		#handle
		move	$s0,$a1
		move	$s1,$a2
		move	$a0,$s1		#extract extention
		jal	strchr
		li	$a1,0x2e		#look for "."
		beqz	$v0,wFTexit	#cant find it then leave!
		addiu	$s1,$v0,1		#move one step beyond it and we have the extention
		lw	$s2,0x8($s2)
addwct:
		jal	strlen
		lw	$a0,0($s2)	#Check if extentions match
		move	$a2,$v0		#only match so many bits
		move	$a0,$s1		
		jal	memcmp
		lw	$a1,0($s2)	#Check if extentions match
		beqz	$v0,wFTFound	#found it then break loop
		lw	$v0,0x8($s2)	#check the next one for a blank
		bnez	$v0,addwct	#should work since there is allways 1 at least!!
		addiu	$s2,0x8
		j	wFTexit		#guess its not in the table
		nop
wFTFound:
		addiu	$a0,$sp,0x20	#Use the stack to store the sprintf result of the header
		la	$a1,ahttphdr	#Get Generic http header
		jal	sprintf		#for now print it	
		lw	$a2,4($s2)	#get content type
		addiu	$a1,$sp,0x20	
		jal		WriteSock
		move	$a0,$s0		#write it out now
wFTexit:
		lw	$s2,0x220($sp)
		lw	$s1,0x224($sp)
		lw	$s0,0x228($sp)
		lw	$ra,0x22c($sp)	#ok, have added whatever u told u to add
		jr	$ra
		addiu	$sp,0x230

#webCopy(uint srcwebHandle,uint destwebHandle) 
webCopy:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		sw	$s1,0x24($sp)
		sw	$s2,0x20($sp)
		move	$s0,$a0
		move	$s1,$a1
 #copy web pages
		lw	$s2,0($s0)
webcpyloop1:
		move	$a0,$s1
		lw	$a1,0($s2)
		beqz	$a1,weblp1done
		lw	$a2,0x8($s2)
		lw	$a3,0xc($s2)
		lw	$v0,0x4($s2)
		jal	webAddPage
		sw	$v0,0x10($sp)
		lw	$v0,0x10($s2)
		bnez	$v0,webcpyloop1
		addiu	$s2,0x10
 #copy web enSyms
weblp1done:
		lw	$s2,0x4($s0)
webcpyloop2:
		move	$a0,$s1
		lw	$a1,0($s2)
		beqz	$a1,weblp2done
		nop
		jal	webEnableSym
		move	$a0,$s1
		lw	$v0,0x4($s2)
		bnez	$v0,webcpyloop2
		addiu	$s2,0x4
 #copy web types
weblp2done:
		lw	$s2,0x8($s0)
webcpyloop3:
		lw	$a1,0($s2)
		beqz	$a1,weblp3done
		lw	$a2,0x4($s2)
		jal	webAddType
		move	$a0,$s1
		lw	$v0,0x8($s2)
		bnez	$v0,webcpyloop3
		addiu	$s2,0x8
weblp3done:	
		lw	$s2,0x20($sp)
		lw	$s0,0x28($sp)
		lw	$s1,0x24($sp)		
		lw	$ra,0x2c($sp)
		jr	$ra
		addiu	$sp,0x30

#webAddPage(uint handle, str * name, char type, integer length, char * content)	
webAddPage:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		sw	$s1,0x24($sp)
		sw	$s2,0x20($sp)
		sw	$s3,0x1c($sp)
		sw	$s4,0x18($sp)
		lw	$s4,0x40($sp)	#pop this off the stack we hope
		move	$s1,$a1
		move	$s2,$a2
		move	$s3,$a3
		jal	webDeletePage	#first delete old page with same name if it exists
		lw	$s0,0($a0)
addwpfb:
		lw	$v0,0x0($s0)	#check the next one for a blank
		bnez	$v0,addwpfb	#should work since there is allways 1 at least!!
		addiu	$s0,0x10
		sw	$s1,-0x10($s0)
		sw	$s2,0xfff8($s0)
		sw	$s3,0xfffc($s0)
		sw	$s4,0xfff4($s0)	#ok, have added whatever u told u to add
		lw	$s4,0x18($sp)
		lw	$s3,0x1c($sp)
		lw	$s2,0x20($sp)
		lw	$s1,0x24($sp)
		lw	$s0,0x28($sp)
		lw	$ra,0x2c($sp)
		jr	$ra
		addiu	$sp,0x30

#webDeleteSym(handle, str* sym)
webDeleteSym:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		sw	$s1,0x24($sp)
		move	$s1,$a1
		lw	$s0,0x4($a0)
webDSL1:
		lw	$a0,0($s0)
		beqz	$a0,webDSNF
		addiu	$s0,4
		jal	strcmp
		move	$a1,$s1
		bnez	$v0,webDSL1
webDSL2:
		lw	$a0,0x0($s0)
		sw	$a0,0xfffc($s0)
		bnez	$a0,webDSL2
		addiu	$s0,4
webDSNF:		
		lw	$s1,0x24($sp)
		lw	$s0,0x28($sp)
		lw	$ra,0x2c($sp)
		jr	$ra
		addiu	$sp,0x30

#webDeleteType(handle, str* extention)
webDeleteType:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		sw	$s1,0x24($sp)
		move	$s1,$a1
		lw	$s0,0x8($a0)
webDTL1:
		lw	$a0,0($s0)
		beqz	$a0,webDTNF
		addiu	$s0,0x8
		jal	strcmp
		move	$a1,$s1
		bnez	$v0,webDTL1
webDTL2:
		lw	$a0,0x4($s0)
		sw	$a0,0xfffc($s0)
		lw	$a0,0x0($s0)
		sw	$a0,0xfff8($s0)
		bnez	$a0,webDTL2
		addiu	$s0,8
webDTNF:		
		lw	$s1,0x24($sp)
		lw	$s0,0x28($sp)
		lw	$ra,0x2c($sp)
		jr	$ra
		addiu	$sp,0x30


#webDeletePage(handle, str* name)
webDeletePage:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		sw	$s1,0x24($sp)
		move	$s1,$a1
		lw	$s0,0($a0)
webDPL:
		lw	$a0,0($s0)
		beqz	$a0,webDPNF
		addiu	$s0,0x10
		jal	strcmp
		move	$a1,$s1
		bnez	$v0,webDPL
webDPL2:
		lw	$a0,0x4($s0)	
		sw	$a0,0xfff4($s0)	
		lw	$a0,0x8($s0)
		sw	$a0,0xfff8($s0)
		lw	$a0,0xc($s0)
		sw	$a0,0xfffc($s0)
		lw	$a0,0x0($s0)	
		sw	$a0,0xfff0($s0)				
		bnez	$a0,webDPL2
		addiu	$s0,0x10
webDPNF:
		lw	$s1,0x24($sp)
		lw	$s0,0x28($sp)
		lw	$ra,0x2c($sp)
		jr	$ra
		addiu	$sp,0x30



#webAddType(handle, str * fileextention, str * ctype) Assume fileextention="txt" 
#and ctype="text/plain" then all files with ".txt" will use "text/Plain" in the header
webAddType:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		sw	$s1,0x24($sp)
		sw	$s2,0x20($sp)
		lw	$s0,0x8($a0)
		move	$s1,$a1
		jal	webDeleteType	#first delete type of same name if it exists
		move	$s2,$a2
addwnvpz:
		lw	$v0,0x0($s0)	#check the next one for a blank
		bnez	$v0,addwnvpz	#should work since there is allways 1 at least!!
		addiu	$s0,0x8
		sw	$s1,-0x8($s0)
		sw	$s2,-0x4($s0)
		lw	$s2,0x20($sp)
		lw	$s1,0x24($sp)
		lw	$s0,0x28($sp)
		lw	$ra,0x2c($sp)	#ok, have added whatever u told u to add
		jr	$ra
		addiu	$sp,0x30

#webEnableSym(handle, str * symname) enables name to be used as a name=value pair in present in the URL
#Note the above webAddType uses the function so dont mod without considering
webEnableSym:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		sw	$s1,0x24($sp)
		lw	$s0,0x4($a0)
		jal	webDeleteSym	#first delete symbol of same name 
		move	$s1,$a1
addwnvp:
		lw	$v0,0x0($s0)	#check the next one for a blank
		bnez	$v0,addwnvp	#should work since there is allways 1 at least!!
		addiu	$s0,0x4
		sw	$s1,-0x4($s0)	#store it at -4 of it
		lw	$s1,0x24($sp)
		lw	$s0,0x28($sp)
		lw	$ra,0x2c($sp)	#ok, have added whatever u told u to add
		jr	$ra
		addiu	$sp,0x30

#webInfo(uint webhandle) Prints verbose version of header info
webInfo:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		sw	$s1,0x24($sp)
		move	$s0,$a0
		la	$a0,awebinfodata1
		lw	$a1,0x20($s0)
		lw	$a2,0x0($s0)
		jal	printf
		lw	$a3,0x4($s0)
		la	$a0,awebinfodata2
		lw	$a1,0x8($s0)
		lw	$a2,0xc($s0)
		jal	printf
		lw	$a3,0x1c($s0)

		la	$a0,awebinfodata3
		lw	$a1,0x10($s0)
		lw	$a2,0x14($s0)
		jal	printf
		lw	$a3,0x18($s0)
		jal	inet_ntoa
		lw	$a0,0x28($s0)
		move	$a1,$v0
		move	$s1,$v0
		la	$a0,awebinfodata4
		lw	$a3,0x2c($s0)
		jal	printf
		lw	$a2,0x24($s0)
		jal	free
		move	$a0,$s1
		lw	$s1,0x24($sp)
		lw	$s0,0x28($sp)
		lw	$ra,0x2c($sp)
		jr	$ra
		addiu	$sp,0x30

#webDestroy(uint webhandle)  closes listening socket, kills webTask, frees used memory, etc.
#Note all requests in progress will continue, we just hope the free'd memory isnt instantly reused hehe
webDestroy:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		move	$s0,$a0
		jal	close		#close listening socket
		lw	$a0,0x18($s0)
		jal	td		#kill task
		lw	$a0,0x1c($s0)
		jal	free		#free used mem
		lw	$a0,0x0($s0)	#for now assume webpage table will be start of our malloc'd mem
		lw	$s0,0x28($sp)
		lw	$ra,0x2c($sp)
		jr	$ra
		addiu	$sp,0x30

#webflagflip(str *) converts str to a value and does a FlagFlip on it
webflagflip:
		addiu	$sp,-0x20
		sw	$ra,0x1c($sp)
		la	$a1,a2x
		jal	sscanf
		addiu	$a2,$sp,0x18	#convert arg to 
		jal	FlagFlip
		lw	$a0,0x18($sp)	#there flipped !!
		lw	$ra,0x1c($sp)
		jr	$ra
		addiu	$sp,0x20		

#uint webHandle=webInit(char * bindaddress, uint bindport)
webInit:
		addiu	$sp,-0x100
		sw	$ra,0x9c($sp)
		sw	$s0,0x98($sp)
		sw	$s1,0x94($sp)
		sw	$s2,0x90($sp)
		sw	$s3,0x8c($sp)
		sw	$s4,0x88($sp)
		sw	$s5,0x84($sp)
		jal	inet_addr	#convert address
		move	$s3,$a1
		move	$s4,$v0		#store needed values before initalizing tables

		jal	malloc		#allocate enuff mem for everything including
		li	$a0,0x840	#webpagestable+webensyms+pagestypes+webhandle
		move	$s0,$v0
		move	$a0,$v0
		jal	bzero
		li	$a1,0x840	#zero it	

		addiu	$s5,$s0,0x800	#store handle table pointer
		sw	$s0,0x00($s5)	#store webpagestableptr
		addiu	$a0,$s0,0x400
		sw	$a0,0x04($s5)	#store webensymstableptr
		addiu	$a0,$s0,0x600
		sw	$a0,0x08($s5)	#store webpagetypesptr
		la	$a0,webSocketTask
		sw	$a0,0x0c($s5)	#store webSockTask for hook
		li	$a0,0x8		#max of 8 tasks
		sw	$a0,0x10($s5)	#store webMaxbabies
		sw	$0,0x14($s5)	#zero count (should allready be zero, but just in case)
		sw	$s3,0x24($s5)	#store bind Port
		sw	$s4,0x28($s5)	#store bind Address
		la	$a0,aNotfound 	#"pagenotfound.html"
		sw	$a0,0x2c($s5)	#string to use if page not found
# word 0 = port?		
		jal	malloc
		li	$a0,0x10		#create sockaddr struct
		move	$s1,$v0
		move	$a0,$s1
		jal	bzero
		li	$a1,0x10		#init struct
#no sh instruction either!
#		sh	$s3,0x2($s1)	#store listen port
#		li	$s3,2		
#		sh	$s3,0x0($s1)
		sw	$s3,0x0($s1)
		li	$s3,2
		sb	$s3,0x1($s1)
		sw	$s4,0x4($s1)	#store listen addr
#init values now plz

		li	$a0,2		#IPv4 protocol
		li	$a1,1		#????0 = stream, 1=dgram, 2=raw
		jal	socket
		move	$a2,$0		#0=ip 1=icmp
		move	$s0,$v0		#store listening socket handle
		sw	$s0,0x18($s5)	#store listening socket handle into webHandleStruct

		li	$v0,1
		sw	$v0,0x80($sp)	#store for later
		move	$a0,$s0
		li	$a1,0xffff
		li	$t0,0x4
		sw	$t0,0x10($sp)
		li	$a2,4
		jal	setsockopt
		addiu	$a3,$sp,0x80
		move	$a0,$s0		#sock handle
		move	$a1,$s1		#sockaddr struct
		jal	bind
		li	$a2,0x10		#length of sockaddr struct

		move	$a0,$s0
		jal	listen
		li	$a1,0x5		#max num of backlog'd connections
		
		la	$a2,webTaskCount
		lw	$a3,0($a2)
		addiu	$a3,1
		sw	$a3,0($a2)
		sw	$a3,0x20($s5)	#store this server's count to webhandle
		la	$a1,asd		#"%s%d"
		la	$a2,aHTTPD	
		jal	sprintf
		addiu	$a0,$sp,0x60

		jal	WebDefault
		move	$a0,$s5		#pass handle Pointer

		sw	$s5,0x14($sp)	#task arg0
		sw	$s0,0x18($sp)	#task arg1
		sw	$s1,0x1c($sp)	#task arg2
	
		la	$a0,webTask
		sw	$a0,0x10($sp)	#
		li	$v0,0x10
		sw	$v0,0x20($sp)	#task arg3
		addiu	$a0,$sp,0x24
		jal	bzero
		li	$a1,0x34		#zero out all stack values for safty
		addiu	$a0,$sp,0x60
		li	$a1,0xc8
		move	$a2,$0
		jal	taskSpawn
		ori	$a3,$0,0xf00	#this is prolly way too big!!
		sw	$v0,0x1c($s5)	#store task ID of httpd to webhandle
		la	$a0,awebstarted
		jal	printf
		nop
		la	$a0,awebstarted
		jal	mylog
		nop
		move	$v0,$s5		#return handle
		lw	$s0,0x98($sp)
		lw	$s1,0x94($sp)
		lw	$s2,0x90($sp)
		lw	$s3,0x8c($sp)
		lw	$s4,0x88($sp)
		lw	$s5,0x84($sp)
		lw	$ra,0x9c($sp)
		jr	$ra
		addiu	$sp,0x100

#Opens a socket and waits for web requests in a loop over and over and over and over
#webTask(int handle, int s, struct sockaddr *addr, int addrlen)
webTask:
		addiu	$sp,-0x160
		sw	$ra,0x15c($sp)
		sw	$s0,0x158($sp)
		sw	$s1,0x154($sp)
		sw	$s2,0x150($sp)
		sw	$s3,0x14c($sp)
		sw	$s4,0x148($sp)
		sw	$s5,0x144($sp)
		move	$s5,$a0
		move	$s0,$a1		#
		move	$s1,$a2
		sw	$a3,0x140($sp)
		.if webdbg=true
		la	$a0,awebtaskspawned
		jal	printf
		move 	$a1,$s0
		la	$a0,awebtaskdbg3
		move	$a1,$s0		#sockhandle  
		jal	printf
		move	$a2,$s5		#sockaddrstruct
		.endif
waitfornextreq:
		move	$a0,$s0		#sockhandle  MABY U SHOULD USE A COPY OF THE SOCKADDR
		move	$a1,$s1		#sockaddrstruct
		jal	accept
		addiu	$a2,$sp,0x140	#get ptr to file sockaddr length
		move	$s4,$v0		#FileDesc
		addiu	$a0,$0,-1
		beq	$v0,$a0,wlgcnerr
		nop
#Here is where u need to thread
		sw	$s5,0x14($sp)	#task arg0
		sw	$s4,0x18($sp)	#task arg1
		sw	$s1,0x1c($sp)	#task arg2
		lw	$a0,0x140($sp)	#load sockaddrlength
		sw	$a0,0x20($sp)	#task arg3
GiveBirth:
		lw	$a0,0x10($s5)	#get max child count
		lw	$a3,0x14($s5)	#get curr child cnt
		beq	$a0,$a3,AbortFetus
		addiu	$a3,1		#increment cnt
		j	MammaNeedsMoreWelfare
		sw	$a3,0x14($s5)	#store cnt		
AbortFetus:
		j	GiveBirth
MammaNeedsMoreWelfare:
		lw	$a2,0x20($s5)
		la	$a1,atSHttpd	#tH%dSock%d
		jal	sprintf
		addiu	$a0,$sp,0x60
		la	$a0,webSocketHook
		sw	$a0,0x10($sp)	#store task address
		addiu	$a0,$sp,0x60
		lw	$a1,0x14($s5)
		addiu	$a1,0xc9		#priority 1 more than webTask (so its less priority)
		li	$a2,0x0080	#Give Us a Private Enviroment
		jal	taskSpawn
		li	$a3,0x6ff0	#this is prolly way too big!!
		j	waitfornextreq	#this dont look right, i feel i should leave open the accept or something i dunno
		nop
wlgcnerr:
		lw	$ra,0x15c($sp)
		lw	$s0,0x158($sp)
		lw	$s1,0x154($sp)
		lw	$s2,0x150($sp)
		lw	$s3,0x14c($sp)
		lw	$s4,0x148($sp)
		lw	$s5,0x144($sp)
		jr	$ra
		addiu	$sp,0x160

#webSocketHook(int handle, int socket, struct sockaddr *addr, int addrlen) Calls the specified webSoket task and does cleanup)
webSocketHook:
		addiu	$sp,-0x20
		sw	$ra,0x1c($sp)
		sw	$s0,0x18($sp)
		sw	$s1,0x14($sp)
		move	$s0,$a0
		move	$s1,$a1
		lw	$v0,0xc($a0)
		jalr	$v0		#call the specified websockettask
		nop
		jal	close
		move	$a0,$s1		#close the socket just in case
		.if webdbg=true
		jal	errnoget
		move	$a0,$0
		la	$a0,awebSockHkDbg
		lw	$a1,0x20($s0)
		move	$a3,$v0
		jal	printf
		move	$a2,$s1
		.endif
		lw	$a0,0x14($s0)	#get count
		addiu	$a0,-1
		sw	$a0,0x14($s0)	#store task count
		lw	$s1,0x14($sp)
		lw	$s0,0x18($sp)
		lw	$ra,0x1c($sp)
		jr	$ra
		addiu	$sp,0x20

#webSocketTask(int handle, int socket, struct sockaddr *addr, int addrlen)
webSocketTask:
		addiu	$sp,-0x2030
		sw	$ra,0x202c($sp)
		sw	$s0,0x2028($sp)
		sw	$s1,0x2024($sp)
		sw	$s2,0x2020($sp)
		sw	$s3,0x201c($sp)
		sw	$s4,0x2018($sp)
		sw	$s5,0x2014($sp)
		move	$s0,$a0
		move	$s1,$a1
		move	$s2,$a2
		move	$s3,$a3
		.if webdbg=true
		la	$a0,awebTaskDbg
		lw	$a1,0x14($s0)	#Get web task count
		move 	$a3,$s0
		jal	printf
		move	$a2,$s1
		.endif
		move	$a0,$s1		#rememer to use fd for accecpted port
		addiu	$a1,$sp,0x20
		jal	webLineGet
		li	$a2,0x0fc0
		addiu	$a0,$0,-1
		beq	$v0,$a0,wlgdone
		addiu	$a0,$sp,0x20
		jal	strchr
		li	$a1,0x2f
		beqz	$v0,wlgdone	#not a / on the first line then ur phucked
		li	$t0,0x3d	#replace / with = for env trick
		sb	$t0,0($v0)
		addiu	$a0,$sp,0x1000	
		jal	strcpy
		addiu	$a1,$v0,1	#store URL untill later
		addiu	$a0,$sp,0x1000
		jal	strchr
		li	$a1,0x20		
		beqz	$v0,wlgdone	#not a " " on the first line after the "/" then forget it too
		nop
		sb	$0,0($v0)	#Remove " HTTP" whatever
#store POST or GET line as envvar
		jal	putenv		#store url as post= or get= whatever
		addiu	$a0,$sp,0x20	#see if its post
		sw	$v0,0x2000($sp)	#store here for l8tr
wlgnxtline:
		move	$a0,$s1		#rememer to use fd for accecpted port
		addiu	$a1,$sp,0x20
		jal	webLineGet
		li	$a2,0x0fc0
		lb	$a0,0x20($sp)
		beqz	$a0,wlgnxtlinedone	#check for a blank line
#Parse out crap to taskenviroment
		addiu	$a0,$sp,0x20
		jal	strchr
		li	$a1,0x3a		#search for : to indicate a name/value pair here
		beqz	$v0,wlgnxtline	#if not found then get the next line
		li	$t0,0x3d
		sb	$t0,0($v0)	#store '=' in place of :
		jal	putenv
		addiu	$a0,$sp,0x20
		nop
		j wlgnxtline		
wlgnxtlinedone:
		.if webdbg=true
		la	$a0,awebTaskDb2
		lw	$a1,0x14($s0)	#Get web task count
		jal	printf
		addiu	$a2,$sp,0x1000
		.endif
#If its post get the post line here... Considering using filesystem for this.... maby... possibly have webpath variable?
#nah, just handle post with type of application/x-www-form-urlencoded, in such cases the next line should be the POST data, which we
#handle like a url, multipart/form-data will be handled by whatever webpage specified..
		la	$a0,aPOST
		jal	getenv
		nop
		beqz	$v0,itsnotpost	#see if it was post
		la	$a0, aContentType
		jal	getenv
		nop
		beqz	$v0,itsnotpost
		la	$a1,axwwwformurlencoded
		jal	strstr
		move	$a0,$v0		#see if this is out content type...
		beqz	$v0,itsnotpost	#if its not www-form-urlencoded then forget getting post data
		move	$a0,$s1		#Get one more line should contain post data if www-form-urlencoded
		addiu	$a1,$sp,0x20
		jal	read
		li	$a2,0x0fc0
		addu	$t0,$v0,$sp
		sb	$0,0x20($t0)	#store 0 at last byte location
		addiu	$a1,$sp,0x20	#process name=value pairs now
		move	$a0,$s0		#handle
		jal	urlparse
		move	$a2,$s1		#send sock

itsnotpost:
		move	$a0,$s0
		move	$a1,$s1
		jal	webHandleUrl
		addiu	$a2,$sp,0x1000
wlgdone:
#DONT YET CLOSE ME!
#		jal	close	
#		move	$a0,$s1
#endwebsocktask
		lw	$ra,0x202c($sp)
		lw	$s0,0x2028($sp)
		lw	$s1,0x2024($sp)
		lw	$s2,0x2020($sp)
		lw	$s3,0x201c($sp)
		lw	$s4,0x2018($sp)
		lw	$s5,0x2014($sp)
		jr	$ra
		addiu	$sp,0x2030

		
#webLineGet(int Fd, char * buffer, int length) #aug 17 2005 changed to 0xd 0xa termination?!
webLineGet:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)
		sw	$s0,0x28($sp)
		sw	$s1,0x24($sp)
		sw	$s2,0x20($sp)
		sw	$s3,0x1c($sp)
		move	$s0,$a0
		move	$s1,$a1
		move	$s2,$a2
		move	$s3,$s1
linegetloop:
		move	$a0,$s0
		addiu	$a1,$sp,0x14		
		jal	read
		li	$a2,1		#read one byte at a time plz	
		addiu	$t0,$0,-1
		beq	$t0,$v0,wlgerr
		lbu	$a1,0x14($sp)	#get me outta here if its blank please
		li	$a2,0xd
		beq	$a1,$a2,linegetloop
		li	$a2,0xa
		beq	$a1,$a2,wlgcr
		sb	$a1,0($s1)
		addiu	$s2,-1
		bnez	$s2,linegetloop
		addiu	$s1,1
wlgcr:
		sb	$0,0($s1)		#zero last byte
		subu	$v0,$s1,$s3		#should be length
wlgerr:
		lw	$ra,0x2c($sp)
		lw	$s0,0x28($sp)
		lw	$s1,0x24($sp)
		lw	$s2,0x20($sp)
		lw	$s3,0x1c($sp)
		jr	$ra
		addiu	$sp,0x30
	

#webSetSocketHook(handle, newhookaddress)
webSetSocketHook:
		jr	$ra
		sw	$a1,0xc($a0)

#webSetMaxThreads(handle, int maxthreads)
webSetMaxThreads:
		jr	$ra
		sw	$a1,0x10($a0)

#webDefault(handle) will add defaults pages, types, and enabled syms to table
webDefault:
		addiu	$sp,0x20
		sw	$ra,0x1c($sp)
		sw	$s0,0x18($sp)
		sw	$s1,0x14($sp)
		move	$s0,$a0
		la	$a0,webDefSigmaPageTable
		li	$a2,0x4		#only copy the first few
		jal	wcopy
		lw	$a1,0x0($s0)	#webpagestablestart

		la	$a0,wDefTypes
		li	$a2,0x10		#only copy the first few
		jal	wcopy
		lw	$a1,0x8($s0)	#webpagestypeptr
#THIS HAS OR HAD SOME BIZZARE ERROR!!!!!
		.if webdbg=true
		jal	webShowPages
		move	$a0,$s0
		jal	webShowEnSyms
		move	$a0,$s0
#		jal	webShowTypes
#		move	$a0,$s0
		.endif
		lw	$ra,0x1c($sp)
		lw	$s0,0x18($sp)
		lw	$s1,0x14($sp)
		jr	$ra
		addiu	$sp,-0x20		

#webHandleUrl(handle, int fd, char * URL)
webHandleUrl:
		addiu	$sp,-0x50
		sw	$ra, 0x4c($sp)
		sw	$a0, 0x48($sp)
		sw	$a1, 0x44($sp)
		sw	$a2, 0x40($sp)
		sw	$s5, 0x3c($sp)
		sw	$s0, 0x38($sp)
		sw	$s1, 0x34($sp)
		sw	$s2, 0x30($sp)
		sw	$s3, 0x2c($sp)
		sw	$s4, 0x28($sp)
		move	$s4,$a0		#s4=handle
		move	$s0,$a1		#s0=sock
		move	$s1,$a2		#s1=url
		jal	strlen
		move	$a0,$s1
		jal	malloc
		addiu	$a0,$v0,0x10	#Reserve some space to save the decoded url
		move	$s2,$v0		#s2=temp url
		move	$s5,$v0		#this is just here to keep it from loosing the stupid malloc, this needs to be reworked and rethought and stuff because its lame, yes lame
		move	$a0,$v0	
		jal	strcpy
		move	$a1,$s1		#copy the decoded url for possible use by exec pages
ForceDefaultPage0:		
		move	$a0,$s2
		jal	strchr
		li	$a1,0x3f		#find the ?
		beqz	$v0,TryNextWebPage
		lw	$s3,0($s4)	#Find Address of Webpage Table
		sb	$0,0($v0)		#erase the ?
		move	$a0,$s4		#handle
		move	$a2,$s0		#send sock
		jal	urlparse
		addiu	$a1,$v0,1	#move past the ? and process the name=value pairs

TryNextWebPage:
		lw	$a1,0($s3)	#get next page name from table
		beqz	$a1,webPageNotInTable
		nop
		jal	strcmp		#Check the url
		move	$a0,$s2
		bnez	$v0,TryNextWebPage
		addiu	$s3,0x10
		addiu	$s3,-0x10
		move	$a0,$s4
		move	$a2,$s2		#send decoded url?
		jal	webFindType		#try sending a header for every known extention??
		move	$a1,$s0		#send fd

		lw	$a1,0x8($s3)	#get type
		bnez	$a1,wwwtypenot0
		li	$v0,1		#must be type 0 server parsed html text

		lw	$a1, 0x4($s3)	#show MYYYYYY webpage, its not urs its mine!
		jal	webSendHtml
		move	$a0,$s0
		j	wwwdoneclose
		nop
webPageNotInTable:
		j	ForceDefaultPage0
		lw	$s2,0x2c($s4)	#retrieve default page to use's string
wwwtypenot0:	
		bne	$a1,$v0,wwwtypenot1
		li	$v0,2
		move	$a0,$s0
		lw	$a1, 0x4($s3)	#show MYYYYYY webcontent, its not urs its mine!
		jal	write		#write raw data to socket
		lw	$a2, 0xc($s3)	#size of gif
		j	wwwdoneclose
		nop
wwwtypenot1:
		bne	$a1,$v0,webtypenotfound
		li	$v0,3
		move	$a0,$s0
		move	$a2,$s4		#for gawds sake pass the web handle
		lw	$v0,0x4($s3)	#get address of what to execute
		move	$a3,$s1		#arg3 = original URL untouched!! i think
		jalr	$v0
		move	$a1,$s2
wwwdoneclose:
#		jal	taskDelay
#		li	$a0,0x20
#Dont Close This YET! One Place ONLY 
#		jal	close
		move	$a0,$s0
		sb	$0,0($s1)		#erase page name
webtypenotfound:
		jal	free
		move	$a0,$s5
		lw	$a0, 0x48($sp)
		lw	$a1, 0x44($sp)
		lw	$a2, 0x40($sp)
		lw	$s5, 0x3c($sp)
		lw	$s0, 0x38($sp)
		lw	$s1, 0x34($sp)
		lw	$s2, 0x30($sp)
		lw	$s3, 0x2c($sp)
		lw	$ra, 0x4c($sp)
		lw	$s4, 0x28($sp)
		jr	$ra
		addiu	$sp,0x50

#This deals with everything past the ? in the url
#urlparse(handle, urlpast?, sock)
urlparse:
		addiu	$sp,-0x30
		sw	$ra,0x2c($sp)		#
		sw	$s0,0x28($sp)
		move	$s0,$a0
		sw	$a2,0x18($sp)	#i know will need sock handle later
		sw	$a1,8($sp)		#store where we start
urlplp1:
		lw	$a0,8($sp)
		jal	strchr
		li	$a1,0x26	#look for &
		bnez	$v0,urltoend
		nop
		jal	strlen
		lw	$a0,8($sp)
		lw	$a0,8($sp)
		addu	$v0,$v0,$a0
urltoend:
		lb	$a0,0($v0)
		sb	$a0,0xc($sp)	#remember what char was originally at the end of this piece
		sb	$0,0($v0)		#set the & to 0 (or the end to 0)
		move	$a0,$s0
		lw	$a1,8($sp)	#get start of string
		sw	$v0,8($sp)	#Set new start of string since we are about to process this piece
		jal	webHandleNv		#Process the nv pair
		lw	$a2,0x18($sp)	#pass sockhandle just incase!		
		lw	$a0,8($sp)	#get start of string
		lb	$v0,0xc($sp)	#get old char
		sb	$v0,0($a0)	#put old char back
		addiu	$a0,1
		bnez	$v0,urlplp1	#if it is not zero then get the next piece
		sw	$a0,8($sp)
urlparsedone:
		lw	$s0,0x28($sp)
		lw	$ra,0x2c($sp)
		jr	$ra
		addiu	$sp,0x30

aHTTPD:
		.asciiz	"tHttpd"
atSHTTPD:
		.asciiz	"tH%dSock%d"
awebstarted:
		.asciiz	"Sigma webserver started!\l\n"
awebflashshowcol:
		.includehtml	webflashrow.txt
		nop
		.if webdbg=true
awebSockHkDbg:
		.asciiz	"webSocketTask%d: Closed WebSocket FD-%d errno-%d\l\n"
awebtaskspawned:
		.asciiz	"Spawned new Web Task! Listening Socket - %d\n\l"
awebTaskDbg:
		.asciiz	"webSocketTask%d: Accepted connection! Fd-%d  hWeb-0x%08x\n\l"
awebTaskDb2:
		.asciiz	"webSocketTask%d: Requested URL - %s\n\l"
awebtaskdbg3:
		.asciiz 	"webTask: Listening socket FD-%d hWeb-0x%08x\n\l"
awebinfodata1:
		.asciiz	"tHttpd%d: SigmaHTTPD v1.20 Beta\n\l0x%08x webPagesTable\n\l0x%08x webEnabledSymbolsTable\n\l"
awebinfodata2:
		.asciiz	"0x%08x webPageTypesTable\n\l0x%08x webSockTask\n\l0x%08x webTaskID\n\l"
awebinfodata3:
		.asciiz	"webMaxThreads  - %04d \n\lwebThreadCount - %04d\n\lwebSocketFD    - %04d\n\l"
awebinfodata4:
		.asciiz	"Bind Address - %s\n\lBind Port - %d\n\lNot Found Page - %s\n\"
ashowWebHeader:
		.asciiz	"tHttpd%d: Installed WebPages\n\lType Length Location   Name\n\l"
awebShowNvsHdr:
		.asciiz	"tHttpd%d: Symbols allowed as name=value pairs in URL\n\l"
speplwww:	
		nop		
webTaskCount:
		nop		#Web Task Count
hWebDef:
		nop
SigmaVer:
		nop
awebGif0:
		.asciiz "<img border='0' src='0.gif' width='18' height='19'>"
awebGif1:
		.asciiz	"<img border='0' src='1.gif' width='18' height='19'>"
		
webmintable:
		.word	webMinPageTable
		.word	defminNVTable
		.word	wDefTypes

webDefTable:
		.word	webSigmaPageTable
		.word	defwebNVTable
		.word	wDefTypes

#Table of filename extentions vs content type
wDefTypes:
		.word	ahtml
		.word	atexthtml
		.word	ahtm
		.word	atexthtml
		.word	atxt
		.word	atextplain
		.word	agif
		.word	aimagegif
		.word	ajpg
		.word	aimagejpeg
		.word	ajpeg
		.word	aimagejpeg
		.word	apng
		.word	aimagepng
		.word	abin
		.word	aappoct
		nop
		nop
agif:
		.asciiz	"gif"
chksumvalue:
	.if tools.left(sigmakey,4)=705f #If Flash is Toshiba
		.word ToshiChksm
	.else
		.word IntelChksm
	.endif
aimagegif:
		.asciiz	"image/gif"
ajpg:
		.asciiz	"jpg"
ajpeg:
		.asciiz	"jpeg"
aimagejpeg:
		.asciiz	"image/jpeg"
atxt:
		.asciiz	"txt"
atextplain:
		.asciiz	"text/plain"
ahtm:
		.asciiz	"htm"
ahtml:
		.asciiz	"html"
atexthtml:
		.asciiz	"text/html"
apng:
		.asciiz	"png"
aimagepng:
		.asciiz	"image/png"
abin:
		.asciiz	 "bin"
aappoct:
		.asciiz	"application/octet-stream"	#use .bin for raw data
adothtml:
		.asciiz	".html"
adotbin:
		.asciiz	".bin"
areboot:
		.asciiz	"buttonCMCIUp"

#Sigma Defualt accptable name value pairs
#Two words, first is str * to name
defwebNVTable:
		.word	aexec
		.word	areboot
		.word	0		#LAST 2 WILL ALLWAYS BE 00
		.word	0

defminNvTable:
		.word	aDLImageName
		.word	aDLImageIp
		.word	agetimg
		.word	0
		.word	0

asetdeflog__Fv:
		.asciiz	"setdeflog__Fv"

Personal tools
irssi scripts
eggdrop scripts