113
|
1 |
"{ Package: 'stx:goodies/monticello' }"
|
|
2 |
|
|
3 |
MCFileBasedRepository subclass:#MCHttpRepository
|
|
4 |
instanceVariableNames:'location user password readerCache'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Monticello-Repositories'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
192
|
11 |
!MCHttpRepository class methodsFor:'initialization'!
|
|
12 |
|
|
13 |
clearPasswords
|
|
14 |
self allSubInstancesDo: [:ea | ea password: ''].
|
|
15 |
|
|
16 |
! !
|
|
17 |
|
113
|
18 |
!MCHttpRepository class methodsFor:'as yet unclassified'!
|
|
19 |
|
|
20 |
creationTemplate
|
192
|
21 |
^self creationTemplateLocation: 'http://www.squeaksource.com/'
|
113
|
22 |
user: 'squeak'
|
|
23 |
password: 'squeak'
|
192
|
24 |
|
113
|
25 |
!
|
|
26 |
|
|
27 |
creationTemplateLocation: location user: user password: password
|
192
|
28 |
^
|
113
|
29 |
'MCHttpRepository
|
192
|
30 |
location: %1
|
|
31 |
user: %2
|
|
32 |
password: %3'
|
|
33 |
bindWith: location storeString
|
|
34 |
with: user storeString
|
|
35 |
with: password storeString
|
|
36 |
|
|
37 |
"Modified: / 16-09-2010 / 14:34:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
113
|
38 |
!
|
|
39 |
|
|
40 |
description
|
|
41 |
^ 'HTTP'
|
|
42 |
!
|
|
43 |
|
|
44 |
location: location user: user password: password
|
|
45 |
^ self new
|
|
46 |
location: location;
|
|
47 |
user: user;
|
|
48 |
password: password
|
|
49 |
! !
|
|
50 |
|
|
51 |
!MCHttpRepository methodsFor:'as yet unclassified'!
|
|
52 |
|
|
53 |
asCreationTemplate
|
|
54 |
^self class creationTemplateLocation: location user: user password: password
|
|
55 |
!
|
|
56 |
|
|
57 |
location: aUrlString
|
192
|
58 |
location := aUrlString
|
113
|
59 |
!
|
|
60 |
|
|
61 |
locationWithTrailingSlash
|
|
62 |
^ (location endsWith: '/')
|
|
63 |
ifTrue: [location]
|
|
64 |
ifFalse: [location, '/']
|
|
65 |
!
|
|
66 |
|
|
67 |
parseFileNamesFromStream: aStream
|
|
68 |
| names fullName |
|
192
|
69 |
names := OrderedCollection new.
|
113
|
70 |
[aStream atEnd] whileFalse:
|
|
71 |
[[aStream upTo: $<. {$a. $A. nil} includes: aStream next] whileFalse.
|
|
72 |
aStream upTo: $".
|
|
73 |
aStream atEnd ifFalse: [
|
192
|
74 |
fullName := aStream upTo: $".
|
113
|
75 |
names add: fullName unescapePercents]].
|
|
76 |
^ names
|
|
77 |
!
|
|
78 |
|
|
79 |
password
|
|
80 |
self userAndPasswordFromSettingsDo: [:usr :pwd | ^pwd].
|
|
81 |
|
|
82 |
self user isEmpty ifTrue: [^password].
|
|
83 |
|
|
84 |
[password isEmpty] whileTrue: [
|
|
85 |
| answer |
|
|
86 |
"Give the user a chance to change the login"
|
192
|
87 |
answer := UIManager default request: 'User name for ' translated, String cr, location
|
113
|
88 |
initialAnswer: self user.
|
|
89 |
answer isEmpty
|
|
90 |
ifTrue: [^password]
|
|
91 |
ifFalse: [self user: answer].
|
|
92 |
|
192
|
93 |
password := UIManager default requestPassword: 'Password for' translated, ' "', self user, '" ', 'at ' translated, String cr, location.
|
113
|
94 |
].
|
|
95 |
|
|
96 |
^ password
|
|
97 |
!
|
|
98 |
|
|
99 |
password: passwordString
|
192
|
100 |
password := passwordString
|
113
|
101 |
!
|
|
102 |
|
|
103 |
urlForFileNamed: aString
|
192
|
104 |
^ self locationWithTrailingSlash, aString utf8Encoded
|
|
105 |
|
|
106 |
"Modified: / 14-09-2010 / 19:32:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
113
|
107 |
!
|
|
108 |
|
|
109 |
user
|
|
110 |
self userAndPasswordFromSettingsDo: [:usr :pwd | ^usr].
|
|
111 |
"not in settings"
|
|
112 |
^user
|
|
113 |
!
|
|
114 |
|
|
115 |
user: userString
|
192
|
116 |
user := userString
|
113
|
117 |
!
|
|
118 |
|
|
119 |
userAndPasswordFromSettingsDo: aBlock
|
|
120 |
"The mcSettings file in ExternalSettings preferenceDirectory should contain entries for each account:
|
|
121 |
|
|
122 |
account1: *myhost.mydomain* user:password
|
|
123 |
account2: *otherhost.mydomain/somerep* dXNlcjpwYXNzd29yZA==
|
|
124 |
|
|
125 |
That is it must start with 'account', followed by anything to distinguish accounts, and a colon. Then comes a match expression for the repository url, and after a space the user:password string.
|
|
126 |
|
|
127 |
To not have the clear text password on your disc, you can base64 encode it:
|
|
128 |
(Base64MimeConverter mimeEncode: 'user:password' readStream) contents
|
|
129 |
"
|
|
130 |
|
|
131 |
| entry userAndPassword |
|
|
132 |
Settings ifNotNil: [
|
|
133 |
Settings keysAndValuesDo: [:key :value |
|
|
134 |
(key asLowercase beginsWith: 'account') ifTrue: [
|
192
|
135 |
entry := value findTokens: ' '.
|
113
|
136 |
(entry first match: location) ifTrue: [
|
|
137 |
userAndPassword := entry second.
|
|
138 |
(userAndPassword includes: $:) ifFalse: [
|
|
139 |
userAndPassword := (Base64MimeConverter mimeDecodeToChars: userAndPassword readStream) contents].
|
|
140 |
userAndPassword := userAndPassword findTokens: $:.
|
|
141 |
^aBlock value: userAndPassword first
|
|
142 |
value: userAndPassword second
|
|
143 |
]
|
|
144 |
]
|
|
145 |
]
|
|
146 |
].
|
|
147 |
^nil
|
|
148 |
!
|
|
149 |
|
|
150 |
versionReaderForFileNamed: aString
|
192
|
151 |
readerCache ifNil: [readerCache := Dictionary new].
|
113
|
152 |
^ readerCache at: aString ifAbsent:
|
|
153 |
[self resizeCache: readerCache.
|
|
154 |
super versionReaderForFileNamed: aString do:
|
|
155 |
[:r |
|
|
156 |
r ifNotNil: [readerCache at: aString put: r]]]
|
|
157 |
|
|
158 |
!
|
|
159 |
|
|
160 |
versionReaderForFileNamed: aString do: aBlock
|
192
|
161 |
|
|
162 |
| r |
|
|
163 |
|
|
164 |
^(r := self versionReaderForFileNamed: aString) ifNotNil: [aBlock value: r]
|
|
165 |
|
|
166 |
"Modified: / 14-09-2010 / 19:39:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
167 |
! !
|
|
168 |
|
|
169 |
!MCHttpRepository methodsFor:'displaying'!
|
|
170 |
|
|
171 |
displayString
|
|
172 |
|
|
173 |
^location
|
|
174 |
|
|
175 |
"Created: / 14-09-2010 / 23:20:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
113
|
176 |
! !
|
|
177 |
|
|
178 |
!MCHttpRepository methodsFor:'required'!
|
|
179 |
|
|
180 |
allFileNames
|
192
|
181 |
| response |
|
|
182 |
response := HTTPInterface get: self locationWithTrailingSlash, '?C=M;O=D' userName: self user password: self password.
|
|
183 |
response responseCode ~= 200
|
|
184 |
ifTrue: [self error: 'Could not access ', location].
|
|
185 |
^ self parseFileNamesFromStream: response data readStream
|
|
186 |
|
|
187 |
"Modified: / 14-09-2010 / 19:16:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
113
|
188 |
!
|
|
189 |
|
|
190 |
description
|
|
191 |
^ location
|
|
192 |
!
|
|
193 |
|
192
|
194 |
flushCache
|
|
195 |
super flushCache.
|
|
196 |
readerCache := nil.
|
|
197 |
!
|
|
198 |
|
113
|
199 |
readStreamForFileNamed: aString do: aBlock
|
192
|
200 |
|
|
201 |
| response |
|
|
202 |
response := HTTPInterface get: (self urlForFileNamed: aString) userName: self user password: self password.
|
|
203 |
^response responseCode == 200
|
|
204 |
ifTrue: [aBlock value: response data readStream].
|
|
205 |
|
|
206 |
"Modified: / 14-09-2010 / 19:38:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
113
|
207 |
!
|
|
208 |
|
|
209 |
writeStreamForFileNamed: aString replace: ignoreBoolean do: aBlock
|
|
210 |
| stream response |
|
192
|
211 |
stream := RWBinaryOrTextStream on: String new.
|
113
|
212 |
aBlock value: stream.
|
192
|
213 |
response := HTTPSocket
|
113
|
214 |
httpPut: stream contents
|
|
215 |
to: (self urlForFileNamed: aString)
|
|
216 |
user: self user
|
|
217 |
passwd: self password.
|
|
218 |
|
|
219 |
(#( 'HTTP/1.1 201 ' 'HTTP/1.1 200 ' 'HTTP/1.0 201 ' 'HTTP/1.0 200 ')
|
|
220 |
anySatisfy: [:code | response beginsWith: code ])
|
|
221 |
ifFalse: [self error: response].
|
|
222 |
! !
|
|
223 |
|
|
224 |
!MCHttpRepository class methodsFor:'documentation'!
|
|
225 |
|
192
|
226 |
version_CVS
|
|
227 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCHttpRepository.st,v 1.2 2011-08-20 11:41:22 cg Exp $'
|
|
228 |
!
|
|
229 |
|
|
230 |
version_SVN
|
|
231 |
^ '§Id: MCHttpRepository.st 13 2010-09-16 14:56:21Z vranyj1 §'
|
113
|
232 |
! !
|