Code with Finding: |
class SSIFrame { /** * Does a first-time parse and sets the segment list attribute * accordingly. */ private void parseFirstTime() { if (debug) System.out.println("@@@ parseFirstTime"); cacheReplies = true; byte[] unparsed = null ; try { unparsed = readUnparsed() ; } catch(IOException ex) { setValue(ATTR_SEGMENTS,null) ; return ; }
// The parsing code was adapted from phttpd int byteIdx = 0, startInc, endInc, startParam, endParam, paramIdx,i ; byte ch, quote ; int max ,length = 0; boolean valueFound ; int unparsedSize = 0 ; // For maintaining the segment list Vector buildSegments = new Vector(20) ;
StringBuffer cmdBuf = null ; String cmdName = null ; Vector /*<String>*/ parNames = null ; Vector /*<String>*/ parValues = null ; String name = null , value = null ; // To store where the last segment ended int lastSegEnd = 0;
do { byteIdx += 4; while(byteIdx < unparsed.length) { if( (ch = unparsed[byteIdx]) == (byte) '#' ) if(byteArrayNEquals(unparsed, byteIdx-4, startPat, 0, 4)) { break; }
// This is an ugly work-around to the // absence of unsigned bytes in Java. byteIdx += startIncrements[ch>=0 ? ch : 0]; }
if(++byteIdx >= unparsed.length) break; // Nothing found // Record the start of the command name and parameter list startInc = (startParam = paramIdx = byteIdx) - 5 ; // Add the previous segment of unparsed text // (Unless empty) if(startInc > lastSegEnd) { buildSegments.addElement(new Segment(lastSegEnd, startInc)); unparsedSize += startInc - lastSegEnd ; lastSegEnd = startInc ; }
// Now find the end of the comment byteIdx += 2; while(byteIdx < unparsed.length) { if( (ch = unparsed[byteIdx]) == (byte) '>') if(unparsed[byteIdx-2] == (byte) '-' && unparsed[byteIdx-1] == (byte) '-') break;
// This is an ugly work-around to the absence of // unsigned bytes in Java: byteIdx += endIncrements[ch>=0 ? ch : 0] ; } if(++byteIdx >= unparsed.length) break; // No end found
// The end of the parameter list is 3 bytes earlier endParam = byteIdx - 3 ; // Record the nominal end of the command segment endInc = byteIdx ;
// Skip white space before command while(paramIdx < endParam && isSpace(unparsed[paramIdx]) ) paramIdx++; if( paramIdx >= endParam ) continue; // No command name
max = endParam - paramIdx ;
cmdName = parseCmdName(unparsed,paramIdx,max) ;
// If not found, take this one as unparsed and // search for the next include. if(cmdName == null) { buildSegments.addElement(new Segment(startInc, endInc)); unparsedSize += endInc - startInc ; lastSegEnd = endInc ; continue; }
parNames = new Vector(5) ; parValues = new Vector(5) ;
parseCmdParams(unparsed, paramIdx+cmdName.length(), endParam, parNames,parValues) ;
buildSegments.addElement( new Segment(this, cmdName, new ArrayDictionary(parNames, parValues), lastSegEnd, endInc)) ; lastSegEnd = endInc ; } while(byteIdx < unparsed.length) ; // Add the last chunk of unparsed text as a segment buildSegments.addElement(new Segment(lastSegEnd, unparsed.length)); unparsedSize += unparsed.length - lastSegEnd ;
setUnparsedSize(unparsedSize) ; Segment[] segs = new Segment[buildSegments.size()] ; buildSegments.copyInto(segs) ; setValue(ATTR_SEGMENTS,segs) ; }
}
|