Posted to tcl by marc.ziegenhagen at Tue May 20 13:56:10 GMT 2014view raw
- package require http
- package require tls
-
- ::tls::init -command tls_callback
-
- ::http::register https 443 [list ::tls::socket \
- -require 1 -cadir "/etc/ssl/certs"]
-
- proc bgerror {msg} {
- puts stderr "bgerror: $msg\n$::errorInfo"
- }
-
- proc callback {token} {
- gloabl G
- upvar #0 $token state
-
- puts "Callback: [arra yget $state]"
-
- switch -- $state(status) {
- error {
- puts stderr "Error: $state(error)"
- }
- ok {
- puts "Body: $state(body)"
- }
- default {
- puts "Unknown state: $state(status)"
- }
- }
-
- set G(run) 0
- http::destroy $token
- }
-
- proc tls_callback {option args} {
-
- #puts [concat $option $args]
-
- switch -- $option {
- "error" {
- foreach {chan msg} $args break
-
- puts "TLS/$chan: error: $msg"
- }
- "verify" {
- # poor man's lassign
- foreach {chan depth cert rc err} $args break
-
- array set c $cert
-
- if {$rc != "1"} {
- puts "TLS/$chan: verify/$depth: Bad Cert: $err (rc = $rc)"
- } else {
- puts "TLS/$chan: verify/$depth: $c(subject)"
- }
- return $rc
- }
- "info" {
- # poor man's lassign
- foreach {chan major minor state msg} $args break
-
- if {$msg != ""} {
- append state ": $msg"
- }
- # For tracing
- upvar #0 tls::$chan cb
- set cb($major) $minor
-
- #puts "TLS/$chan: $major/$minor: $state"
- }
- default {
- return -code error "bad option \"$option\":\
- must be one of error, info, or verify"
- }
- }
- }
-
- set url "https://80.254.163.223/ippf/checkapplication"
- set timeout 15000
-
- puts "URL: $url"
-
- if {[catch {::http::geturl $url \
- -timeout $timeout -type multipart/form-data \
- -command [list callback]} token]} {
- puts stderr "Error: $token"
- exit 1
- }
- puts "url runs: $token"
-
- set G(run) 1
- vwait G(run)
- puts "G(run): $G(run)"