home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFPRC1
/
DOPUT.SRF
< prev
next >
Wrap
Text File
|
1997-06-30
|
8KB
|
219 lines
/*------------------------------------*/
/* Do the "put" or "delete" method (place the body of a request into the
file designated by the url -- but only if PUT (or DELETE) is one of the
permissions in the ACCESS_FILE.
*/
/*------------------------------------*/
sref_do_put:
parse arg which,ddir,action,enmadd,transaction,accopts,tempfile,homedir, ,
servername,host_nickname,accept_range,do_htaccess,htaccess_file
os2e='os2environment'
if which="DELETE" then signal dodelete
/* is there a PUT option associated with this url (typically, as specified
by a wildcarded entry */
if wordpos('PUT',upper(accopts))=0 then do
dog=response1('notallowed', 'you can not PUT to this URL:'||action)
dog
return 'put not allowed '
end
file=strip(sref_do_virtual(ddir,action,enmadd,0,transaction,homedir,host_Nickname))
if file=0 then do
dog=response1('badreq', 'could not process PUT request')
dog
return 'could not process '
end
if do_htaccess=1 then do
tmp1=sref_htaccess(action,file,htaccess_file,,,,,ddir,,TEMPFILE,0)
if tmp1=-1 then return 'PUT: Access denied '
end
ndo=0
'read body var awords' /* get the incoming data */
filen=length(awords)
ranges=reqfield('range:')
if ranges<>"" then do
if accept_range<>1 then do
dog=response1('notimplemented','server does not accept range requests')
dog
return 'unallowed ranges'
end
parse var ranges atype '=' vlist
if upper(strip(atype))<>"BYTES" then do
dog=response1('notimplemented','server does not accept non-byte range requests')
dog
return 'not supported range type:' atype
end
do until vlist=""
parse var vlist aterm ',' vlist
parse var aterm t1 '-' t2
if t1<>"" then
if datatype(t1)<>'NUM' then iterate
if t2<>"" then
if datatype(t2)<>'NUM' then iterate
if t1="" & t2="" then iterate
if t2="" then t2=filen
if t1="" then do
t1=filen-t2
t2=filen
end
if t1<0 then t1=0
if t2>(filen-1) then t2=filen-1
if t2<t1 then iterate /* bad request */
ndo=ndo+1
r1.ndo=t1 ; r2.ndo=t2
end
if ndo=0 then do
dog=response1('badreq',' No acceptable ranges ')
dog
return 'no acceptable ranges'
end
end
/* can file be open ? */
a=upper(stream(file,'c','open write'))
if abbrev(a,'READY')=0 then do
dog=response1('badreq', 'PUT request to an inaccessible file ')
dog
return 'could not access file '
end
if ndo=0 then do
doit=awords
totdo=length(awords)
end
else do
doit="" ; totdo=0
do mm=1 to ndo
t1=r1.mm ; t2=r2.mm
nget=(1+t2)-t1 ; totdo=totdo+nget
bobo=substr(awords,t1+1,nget)
doit=doit||bobo
end
end
foo=charout(file,doit,1)
if foo>0 then do
dog=response1('badreq', 'PUT request failed to write all bytes ')
dog
return 'could not write all bytes '
end
foo=stream(file,'c','close')
call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
call lineout tempfile, "<html><head><title>PUT request success</title></head>"
call lineout tempfile, "<body><h2>PUT request success ...</h2>"
call lineout tempfile, "<p>PUT of the URL was successful: " action
call lineout tempfile,' <br> Bytes written: ' totdo
call lineout tempfile, "</body></html>"
call lineout tempfile /* close */
'FILE ERASE TYPE text/html NAME' tempfile
return ' success (bytes= ' totdo
/* Jump here if DELETE method */
dodelete:
/*------------------------------------*/
/* Do the "delete" verb (delete a file represented by the url from the server)
-- but only if DELETE is one of the accopts.
*/
/*------------------------------------*/
/* is there a DELETE option associated with this url (typically, as specified
by a wildcarded entry */
if wordpos('DELETE',upper(accopts))=0 then do
dog=response1('notallowed', 'you can not DELETE URL:'||action)
dog
return 'put not allowed '
end
file=strip(sref_do_virtual(ddir,action,enmadd,0,transaction,homedir,host_nickname))
if file=0 then do
dog=response1('badreq', 'could not process DELETE request')
dog
return 'could not process '
end
if do_htaccess=1 then do
tmp1=sref_htaccess(action,file,htaccess_file,,,,,ddir,,TEMPFILE,0)
if tmp1=-1 then return 'DELETE: Access denied '
end
/* can file be open ? */
a=stream(file,'c','query exists')
if a="" then do
dog=response1('badreq', 'DELETED non-existent file ')
dog
return 'file does not exist '
end
a=sysfiledelete(file)
if a<>0 then do
dog=response1('badreq', 'Could not delete file ')
dog
return 'problem deleting file: ' a
end
call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
call lineout tempfile, "<html><head><title>DELETE request success</title></head>"
call lineout tempfile, "<body><h2>DELETE request success ...</h2>"
call lineout tempfile, "<p>DELETE of the URL was successful: " action
call lineout tempfile, "</body></html>"
call lineout tempfile /* close */
'FILE ERASE TYPE text/html NAME' tempfile
return ' success '
/* ----------------------------------------------------------------------- */
/* RESPONSE1: Standard [mostly error] responses. */
/* ----------------------------------------------------------------------- */
/* This routine should stay in the main filter program. */
/* Arguments are: response type and extended message information. */
/* It returns the GoServe command to handle the result file. */
response1: procedure expose tempfile servername
parse arg request, message
select
when request='badreq' then use='400 Bad request syntax'
when request='notfound' then use='404 Not found'
when request='forbid' then use='403 Forbidden'
when request='unauth' then use='401 Unauthorized'
when request='notallowed' then use='405 Method not allowed'
when request='notimplemented' then use='501 Not implemented'
otherwise do
use='406 Not acceptable'
call pmprintf_sref('weird response '|| request||' '|| message)
end
end /* Add others to this list as needed */
/* Now set the response and build the response file */
'RESPONSE HTTP/1.0' use /* Set HTTP response line */
parse var use code text
if request='notallowed' then do
'HEADER ADD Allow:HEAD '
end
call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
call lineout tempfile, "<html><head><title>"text"</title></head>"
call lineout tempfile, "<body><h2>Sorry...</h2>"
call lineout tempfile, "<p>The request from your Web client: " message"."
call lineout tempfile, "<hr><em>HTTP response code:</em>" code '['text']'
call lineout tempfile, "<br><em>From server at:</em>" servername
call lineout tempfile, "<br><em>Running:</em>" server()
call lineout tempfile, "</body></html>"
call lineout tempfile /* close */
return 'FILE ERASE TYPE text/html NAME' tempfile