* * HTTP Unpack byte stream according to RFC 2068 and split * into header records and data. * * To build the filter package: * GLOBAL MACLIB FPLGPI FPLOM * HLASM RMHTTP ( OBJECT * LOAD DMSPFP RMHTTP ( MAP RLD * GENMOD RMHTTP (FROM DMSPFP * To load the filter package: * RMHTTP * COPY PGMID RMHTTP MODBEG FREETYPE=NONE,CNOTE=NO DMSPDEFS VECTOR=R9,VECTOR2=YES * * * The raw HTTP byte stream is split into a header and body part. The * header lines can be terminated with x'0a' or x'0d0a' and the header * ends with an empty line. The x'0a' or x'0d0a' are removed from the * lines when they are written to the primary output stream. * After the null record is written to the primary output the primary * input stream is tested to see if there is a record available. If * so, a number is read from that record to indicate the number of * bytes in the body of the message. The bytes that form the body of * the message are written to the secondary output as is, terminated * with a null record. After this the stage resumes reading headers. * When no body size is present on the secondary input the remainder * of the byte stream is written to the secondary output, after * which the stage will terminate (since it cannot find the start * of the next headers). * * Streams used * input.0 raw HTTP data in ASCII (from tcpclient or tcpdata) * input.1 body length * output.0 header lines * output.1 body records * HTTP PROC SAREA=STACK,ENTRY=NO,WORKBASE=R10 HDRS DS F Number of headers produced HTTPHDR PIPBFR 100 Hold the unpacked lines PBEGIN , PIPIBFR HTTPHDR Clear the buffer ZIP R6,R7,R8 ST R6,HDRS Set to 0 as well REPEAT , LTR R7,R7 Do we have data left? IF ZERO LTR R6,R6 Did we peek at something? IF NOTZERO PIPINPUT (,0) Consume it FI , PIPLOCX , Peek at next record LR R6,R1 LTR R7,R0 FI , CONTINUE COND=ZERO Iterate when null record LTR R8,R8 Are we reading the body? IF ZERO No, in headers here LR R4,R6 Point into input buffer LR R5,R7 Remaining length REPEAT , CLI 0(R6),X'0A' Linefeed? UNTIL ZERO,BCT=R7,INCR=R6 SR R5,R7 Subtract remaining length PIPBFRAP HTTPHDR,(,),EXIT=NOTZERO Copy the string to the buffer LTR R7,R7 IF NOTZERO INCR R6,1 Skip linefeed DECR R7,1 PCALL HTTPEND Process header line FI , ELSE , PIPSEL OUTPUT,1 Write body to secondary LR R0,R7 Assume we will output all LRMIN R0,R8 But at most what was specified LR R1,R6 Point into input buffer PIPOUTX , Output the record SR R8,R0 Adjust counter for output COND ZERO,PCALLTR,WRTNULL SR R7,R0 Adjust counter for input COND NOTZERO,AR,R6,R0 Advance pointer input buffer PIPSEL OUTPUT,0 FI , UNTIL , PEXIT RC=(R15) * &MODULE.HT PIPDESC STREAMS=2,BUFFER=HTTPHDR,STOPABLE=YES, * SYNTAX=((!4,LR),?Z222, * DONE) * WRTNULL PROC ENTRY=NO PBEGIN , PIPOUTX (,0) Write a null record PEXIT RC=(R15) PROCEND , End of WrtNull * HTTPEND PROC ENTRY=NO Process end of HDR record PBEGIN , PIPBFRSU HTTPHDR Prepare to output record LTR R2,R0 IF NOTZERO Any more characters in buffer AR R2,R1 Point to previous character DECR R2,1 CLI 0(R2),X'0D' Carriage Return? COND ZERO,DECR,R0 Don't output that FI , LTR R3,R0 Remember length of this record COND ZERO,C,R0,HDRS Null record before headers? COND NOTZERO,PIPOUTX Output the header record LTR R0,R3 IF NOTZERO INCR HDRS,1 Show that we have seen headers ELSE , End of header section L R0,HDRS Are these leading null lines LTR R0,R0 IF NOTZERO PCALL HTTP2ND READ body length from 2nd ZIP R0 ST R0,HDRS FI , FI , PEXIT RC=,REGS=R8 * * Read a number from secondary input HTTP2ND PROC ENTRY=NO PBEGIN , PIPSTRST INPUT,1 Look at the secondary IF NOTZERO PIPMISC SUSPEND And see whether something will PIPSTRST INPUT,1 come up here to read FI , IF ZERO Yes, we have a record PIPSEL INPUT,1,EXIT=NOTZERO PIPLOCX , LR R2,R1 LR R3,R0 PIPDECWD GETWORD=YES,MESSAGE=YES,MINIMUM=0 LR R8,R0 PIPINPUT (,0) PIPSEL INPUT,0 ELSE , L R8,=XL4'7FFFFFFF' FI , PEXIT RC=,REGS=R8 * PROCEND , End of HTTP2nd PROCEND , End of HTTPend * PROCEND , End of HTTP * * ENTRY PIPEPT PIPEPT DS 0D PIPEPT , PIPEPTEN HTTP,RMHTTPHT http PIPEPTED , * MODEND ,