Diff
Not logged in

Differences From Artifact [1f3f84a892]:

To Artifact [e26961fb7d]:


32
33
34
35
36
37
38










39
40
41
42
43
44
45
46
47
48
49
50

51
52

53
54
55













56
57
58
59
60
61
62

63
64

65


66
67
68
69
70
71
72
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

60
61

62
63
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

84
85
86
87

88
89
90
91
92
93
94
95
96







+
+
+
+
+
+
+
+
+
+











-
+

-
+


-
+
+
+
+
+
+
+
+
+
+
+
+
+






-
+


+
-
+
+







    #
    variable clientDirectory

    if {![info exists clientDirectory]} then {
      set clientDirectory [file dirname $script]
    }

    #
    # NOTE: This is the HTTP(S) login cookie to use when downloading files
    #       from the package file server.
    #
    variable loginCookie; # DEFAULT: NONE

    if {![info exists loginCookie]} then {
      set loginCookie [list]
    }

    #
    # NOTE: Prevent progress messages from being displayed while downloading
    #       from the repository, etc?  By default, this is enabled.
    #
    variable quiet; # DEFAULT: true

    if {![info exists quiet]} then {
      set quiet true
    }

    #
    # NOTE: The base URI for the package distribution web site.
    # NOTE: The base URI used to build the URIs for the package file server.
    #
    variable baseUri; # DEFAULT: https://urn.to/r/pkgd
    variable baseUri; # DEFAULT: https://urn.to/r

    if {![info exists baseUri]} then {
      set baseUri https://urn.to/r/pkgd
      set baseUri https://urn.to/r
    }

    #
    # NOTE: The URI where a login request may be sent.  This should return a
    #       payload containing the necessary HTTP(S) cookie information.
    #
    variable loginUri; # DEFAULT: ${baseUri}/pkgd_login?...

    if {![info exists loginUri]} then {
      set loginUri [string trim {
        ${baseUri}/pkgd_login?name=${userName}&password=${password}
      }]
    }

    #
    # NOTE: The URI where a single package file may be found.  This file will
    #       belong to a specific version of one package.
    #
    variable downloadUri; # DEFAULT: ${baseUri}?...&filename=${fileName}
    variable downloadUri; # DEFAULT: ${baseUri}/pkgd_file?...

    if {![info exists downloadUri]} then {
      set downloadUri [string trim {
      set downloadUri {${baseUri}?download&ci=trunk&filename=${fileName}}
        ${baseUri}/pkgd_file?download&ci=trunk&filename=${fileName}
      }]
    }

    #
    # NOTE: The root directory where any persistent packages will be saved.
    #
    variable persistentRootDirectory; # DEFAULT: [getPersistentRootDirectory]

124
125
126
127
128
129
130

131
132
133
134
135
136
137
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162







+








  #
  # NOTE: This procedure returns non-zero if the specified file seems to be
  #       a Harpy script certificate file.  The fileName argument is the name
  #       of the file to check, which may or may not exist.  The nameOnly
  #       argument should be non-zero to ignore the contents of the file.
  #
  # <notUsed>
  proc isHarpyCertificateFileName { fileName nameOnly } {
    if {[string length $fileName] == 0} then {
      return false
    }

    set extension [file extension $fileName]

228
229
230
231
232
233
234







































































































235
236
237
238
239
240
241
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








      set isClient true
    } else {
      error "unsupported language"
    }
  }

  #
  # NOTE: This procedure issues a request to an HTTP(S) server.  It returns
  #       the raw response data verbatim.  It may raise a script error.  It
  #       will always use the currently configured HTTP(S) login cookie, if
  #       any; therefore, it should really only be used for requests to the
  #       package file server.  The uri argument is the fully qualified URI
  #       to request.
  #
  proc getPackageFile { uri } {
    variable loginCookie
    variable quiet

    if {[isEagle]} then {
      if {![object invoke Eagle._Tests.Default \
          TestHasScriptNewWebClientCallback ""]} then {
        set error null

        set code [object invoke Eagle._Tests.Default \
            TestSetScriptNewWebClientCallback "" true true error]

        if {$code ne "Ok"} then {
          error [getStringFromObjectHandle $error]
        }
      }

      if {[info exists loginCookie] && [llength $loginCookie] == 2} then {
        set script [object create String {
          if {[methodName ToString] eq "GetWebRequest"} then {
            webRequest Headers.Add Cookie [join $loginCookie =]
          }
        }]

        return [uri download -inline -webclientdata $script -- $uri]
      } else {
        return [uri download -inline -- $uri]
      }
    } else {
      set options [list -binary true]

      if {[info exists loginCookie] && [llength $loginCookie] == 2} then {
        lappend options -headers [list Cookie [join $loginCookie =]]
      }

      return [eval ::PackageRepository::getFileViaHttp \
          [list $uri] [list 20] [list stdout] [list $quiet] $options]
    }
  }

  #
  # NOTE: This procedure resets the currently configured login cookie, if
  #       any, and then attempts to login using the specified user name and
  #       password.  Upon success, it will set the login cookie to the one
  #       from the raw response data.  Upon failure, a script error will be
  #       raised.  The userName argument must be the name of a package file
  #       server user with at least Fossil Check-Out (o) permissions on the
  #       package file server.  The password argument must be the plaintext
  #       password that is associated with the specified user name.
  #
  # <public>
  proc resetCookieAndLogin { userName password } {
    variable baseUri
    variable loginCookie
    variable loginUri

    #
    # NOTE: Build the full URI for the login request.
    #
    set uri [subst $loginUri]

    #
    # NOTE: Reset the old login cookie, if any.  Then, issue a new login
    #       request, capturing the raw response data.
    #
    set loginCookie [list]; set data [getPackageFile $uri]

    #
    # NOTE: Attempt to extract the necessary values from the raw response
    #       data.
    #
    set pattern(1) {"authToken":"(.*?)"}; # TODO: *HACK* Keep updated.

    if {![regexp -- $pattern(1) $data dummy authToken]} then {
      error "login response missing \"authToken\""
    }

    set pattern(2) {"loginCookieName":"(.*?)"}; # TODO: *HACK* Keep updated.

    if {![regexp -- $pattern(2) $data dummy loginCookieName]} then {
      error "login response missing \"loginCookieName\""
    }

    #
    # NOTE: Set the login cookie to the one freshly extracted from the raw
    #       response data.
    #
    set loginCookie [list $loginCookieName $authToken]

    #
    # NOTE: Always return an empty string (i.e. and not the login data).
    #
    return ""
  }

  #
  # NOTE: This procedure checks if there is a higher version available of the
  #       specified package on the package file server.  The language argument
  #       must be one of the literal strings "eagle", "tcl", or "client".  The
  #       version argument must be one of the literal strings "8.4", "8.5", or
  #       "8.6" when the language is "tcl" -OR- the literal string "1.0" when
  #       the language is either "eagle" or "client".  The packageName argument
274
275
276
277
278
279
280



281



282
283
284
285
286
287
288
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416
417
418
419
420
421







+
+
+
-
+
+
+








    set localFileName [file join $persistentDirectory $fileName]

    set compare [package vcompare \
        [string trim [readFile $downloadFileName]] \
        [string trim [readFile $localFileName]]]

    if {[isEagle]} then {
      file delete -recursive -- $temporaryDirectory
    } else {
    file delete -force -- $temporaryDirectory
      file delete -force -- $temporaryDirectory
    }

    return [expr {$compare > 0}]
  }

  #
  # NOTE: This procedure downloads a single file from the package file server,
  #       writing its contents to the specified local file name.  It can also
  #       verify the OpenPGP signatures.  When an OpenPGP signature file is
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

322
323
324
325
326
327
328
329
330
431
432
433
434
435
436
437

438
439
440
441
442
443
444
445
446
447
448
449




450


451
452
453
454
455
456
457







-












-
-
-
-
+
-
-







  #       where the downloaded file should be written.  The usePgp argument
  #       should be non-zero when an OpenPGP signature file needs to be
  #       downloaded and verified for the downloaded file.
  #
  proc downloadOneFile { language version fileName localFileName usePgp } {
    variable baseUri
    variable downloadUri
    variable quiet

    #
    # NOTE: First, build the full relative file name to download from
    #       the remote package repository.
    #
    set fileName [file join $language $version $fileName]
    set uri [subst $downloadUri]

    #
    # NOTE: Then, in one step, download the file from the package file
    #       server and write it to the specified local file.
    #
    if {[isEagle]} then {
      writeFile $localFileName [interp readorgetscriptfile -- "" $uri]
    } else {
      writeFile $localFileName [::PackageRepository::getFileViaHttp \
    writeFile $localFileName [getPackageFile $uri]
          $uri 20 stdout $quiet -binary true]
    }

    #
    # NOTE: Is use of OpenPGP for signature verification enabled?  Also,
    #       did we just download an OpenPGP signature file?
    #
    if {$usePgp && [isPgpSignatureFileName $localFileName true]} then {
      #
457
458
459
460
461
462
463



464


465
466
467
468
469
470
471
584
585
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601
602







+
+
+
-
+
+







    if {$useAutoPath} then {
      foreach downloadDirectory $downloadDirectories {
        addToAutoPath $language $downloadDirectory
      }
    }

    if {$persistent} then {
      if {[isEagle]} then {
        file delete -recursive -- $temporaryDirectory
      } else {
      file delete -force -- $temporaryDirectory
        file delete -force -- $temporaryDirectory
      }
    }

    return $downloadDirectories
  }

  #
  # NOTE: This package requires the package repository client package.