Misc. Scamper bug fixes
Tim Olson
tim at jumpnet.com
Fri Jan 22 15:57:25 UTC 1999
Hi, all:
While using Scamper to browse the CNN web site, I dropped into the
debugger on two occasions. Here are the fixes to address these two bugs:
----
'From Squeak 2.3 of January 14, 1999 on 22 January 1999 at 8:52:57 am'!
"Change Set: Scamper Fixes
Date: 22 January 1999
Author: Tim Olson
Fixes for 2 bugs discovered when browsing various web pages with Scamper
PluggableListMorph>>selectionIndex:
This fix prevents an out-of-bounds error when a ListMorph with a non-zero
default index is initialized without initializing the list at the same
time.
HTTPSocket class>>httpGetDocument:args:accept:request:
Added missing parenthesis around (self argString:args) when concatenating
to the page string.
"!
!HTTPSocket class methodsFor: 'get the page' stamp: 'tao 1/22/1999 08:46'!
httpGetDocument: url args: args accept: mimeType request: requestString
"Return the exact contents of a web object. Asks for the given MIME
type. If mimeType is nil, use 'text/html'. An extra requestString may be
submitted and must end with crlf. The parsed header is saved. Use a
proxy server if one has been registered. tk 7/23/97 17:12"
"Note: To fetch raw data, you can use the MIME type
'application/octet-stream'."
| serverName serverAddr port sock header length bare page list firstData
aStream index connectToHost connectToPort type newUrl |
Socket initializeNetwork.
bare _ (url asLowercase beginsWith: 'http://')
ifTrue: [url copyFrom: 8 to: url size]
ifFalse: [url].
bare _ bare copyUpTo: $#. "remove fragment, if specified"
serverName _ bare copyUpTo: $/.
page _ bare copyFrom: serverName size + 1 to: bare size.
(serverName includes: $:)
ifTrue: [ index _ serverName indexOf: $:.
port _ (serverName copyFrom: index+1 to: serverName size) asNumber.
serverName _ serverName copyFrom: 1 to: index-1. ]
ifFalse: [ port _ self defaultPort ].
page size = 0 ifTrue: [page _ '/'].
"add arguments"
args ifNotNil: [page _ page, (self argString: args) ].
HTTPProxyServer isNil
ifTrue: [
connectToHost _ serverName.
connectToPort _ port ]
ifFalse: [
page _ 'http://', serverName, ':', port printString, page. "put back
together"
connectToHost _ HTTPProxyServer.
connectToPort _ HTTPProxyPort].
self flag: #XXX. "this doesn't make sense if a user isn't available for
questioning... -ls"
self retry: [serverAddr _ NetNameResolver addressForName: connectToHost
timeout: 20.
serverAddr ~~ nil]
asking: 'Trouble resolving server name. Keep trying?'
ifGiveUp: [Socket deadServer: connectToHost.
^ 'Could not resolve the server named: ', connectToHost].
3 timesRepeat: [
sock _ HTTPSocket new.
sock connectTo: serverAddr port: connectToPort.
(sock waitForConnectionUntil: (self deadlineSecs: 30)) ifFalse: [
Socket deadServer: connectToHost. sock destroy.
^ 'Server ',connectToHost,' is not responding'].
Transcript cr; cr; show: url.
sock sendCommand: 'GET ', page, ' HTTP/1.0', CrLf,
(mimeType ifNotNil: ['ACCEPT: ', mimeType, CrLf] ifNil: ['']),
'ACCEPT: text/html', CrLf, "Always accept plain text"
HTTPBlabEmail, "may be empty"
requestString, "extra user request. Authorization"
'User-Agent: Squeak 1.31', CrLf,
'Host: ', serverName, ':', port printString, CrLf. "blank line
automatically added"
list _ sock getResponseUpTo: CrLf, CrLf. "list = header, CrLf, CrLf,
beginningOfData"
header _ list at: 1.
"Transcript show: page; cr; show: header; cr."
firstData _ list at: 3.
header isEmpty
ifTrue: [aStream _ 'server aborted early']
ifFalse: [
"dig out some headers"
sock header: header.
length _ sock getHeader: 'content-length'.
length ifNotNil: [ length _ length asNumber ].
type _ sock getHeader: 'content-type'.
sock responseCode first = $3 ifTrue: [
newUrl _ sock getHeader: 'location'.
newUrl ifNotNil: [
Transcript show: 'redirecting to ', newUrl; cr.
sock destroy.
^self httpGetDocument: newUrl args: args accept: mimeType ] ].
aStream _ sock getRestOfBuffer: firstData totalLength: length.
sock responseCode = '401' ifTrue: [^ header, aStream contents].
].
sock destroy. "Always OK to destroy!!"
aStream class ~~ String ifTrue: [
^ MIMEDocument contentType: type content: aStream contents url: url].
aStream = 'server aborted early' ifFalse: [
]
].! !
!PluggableListMorph methodsFor: 'selection' stamp: 'tao 1/17/1999 09:56'!
selectionIndex: index
"Called internally to select the index-th item."
| theMorph range |
(index isNil or: [index > scroller submorphs size]) ifTrue: [^ self].
(theMorph _ index = 0 ifTrue: [nil] ifFalse: [scroller submorphs at:
index])
ifNotNil:
[((theMorph bounds top - scroller offset y) >= 0
and: [(theMorph bounds bottom - scroller offset y) <= bounds height])
ifFalse:
["Scroll into view -- should be elsewhere"
range _ self totalScrollRange.
scrollBar value: (range > 0
ifTrue: [((index-1 * theMorph height) / self totalScrollRange)
truncateTo: scrollBar scrollDelta]
ifFalse: [0]).
scroller offset: -3 @ (range * scrollBar value)]].
self selectedMorph: theMorph! !
More information about the Squeak-dev
mailing list
|