From ff71d05d0bd0700a74dfe1500fadd0b81080298e Mon Sep 17 00:00:00 2001 From: Nishi Date: Wed, 2 Oct 2024 07:44:13 +0000 Subject: [PATCH] add flags git-svn-id: file:///raid/svn-personal/koakuma/trunk@19 219d0f9c-2d94-d447-890a-813e76b88fe9 --- Tool/create-project.in | 20 +++++++++++++++++--- Utility/rpc.tcl | 25 +++++++++++++++++-------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Tool/create-project.in b/Tool/create-project.in index d79a79d..6c8c2e5 100644 --- a/Tool/create-project.in +++ b/Tool/create-project.in @@ -4,19 +4,33 @@ package require tdom foreach path [glob "@@PREFIX@@/lib/koakuma/utility/*.tcl"] { source $path } +set dothis "" foreach arg $argv { if { [string range "$arg" 0 0] == "-" } { if { "$arg" == "-h" || "$arg" == "--help" } { - puts "Usage: $argv0" + puts "Usage: $argv0 \[-u username\] \[-p password\] \[-R rpc_url\]" puts "You can set the environment variable `KOAKUMA_RPC' to override default RPC URL." puts "Default: http://127.0.0.1/koakuma/rpc" exit 0 + } elseif { "$arg" == "-u" } { + set dothis "set-username" + } elseif { "$arg" == "-p" } { + set dothis "set-password" + } elseif { "$arg" == "-R" } { + set dothis "set-rpc" } + } else { + if { "$dothis" == "set-username" } { + ::rpc::set-username "$arg" + } elseif { "$dothis" == "set-password" } { + ::rpc::set-password "$arg" + } elseif { "$dothis" == "set-rpc" } { + set RPC_URL "$arg" + } + set dothis "" } } -::rpc::init - dom createNodeCmd -tagName "name" -jsonType NONE elementNode keyName dom createNodeCmd -tagName "description" -jsonType NONE elementNode keyDescription dom createNodeCmd -tagName "vcs" -jsonType NONE elementNode keyVCS diff --git a/Utility/rpc.tcl b/Utility/rpc.tcl index 7080f74..368bb8b 100644 --- a/Utility/rpc.tcl +++ b/Utility/rpc.tcl @@ -67,16 +67,25 @@ namespace eval rpc { return 0 } proc send {path content} { - set headers "" global RPC_URL - if { "$::rpc::username" != "" } { - lappend headers "Authorization" - lappend headers "Basic [::base64::encode -wrapchar "" "$::rpc::username:$::rpc::password"]" + set code "" + set body "" + while 1 { + set headers "" + if { "$::rpc::username" != "" } { + lappend headers "Authorization" + lappend headers "Basic [::base64::encode -wrapchar "" "$::rpc::username:$::rpc::password"]" + } + set tok [::http::geturl "$RPC_URL$path" -headers $headers -type "application/json" -query "$content"] + set code [::http::ncode $tok] + set body "[::http::data $tok]" + ::http::cleanup $tok + if { $code == 401 } { + ::rpc::ask-auth + } else { + break + } } - set tok [::http::geturl "$RPC_URL$path" -headers $headers -type "application/json" -query "$content"] - set code [::http::ncode $tok] - set body "[::http::data $tok]" - ::http::cleanup $tok lappend result "$code" lappend result "$body" return $result -- 2.45.2