]> Git repositories of Nishi - koakuma.git/commitdiff
add flags
authorNishi <nishi@nishi.boats>
Wed, 2 Oct 2024 07:44:13 +0000 (07:44 +0000)
committerNishi <nishi@nishi.boats>
Wed, 2 Oct 2024 07:44:13 +0000 (07:44 +0000)
git-svn-id: file:///raid/svn-personal/koakuma/trunk@19 219d0f9c-2d94-d447-890a-813e76b88fe9

Tool/create-project.in
Utility/rpc.tcl

index d79a79daa395e28ba4bf0173246137ff1b348507..6c8c2e559bba7adae813f91a4f711477fd44b5fe 100644 (file)
@@ -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
index 7080f74593ebfc37a7da9c4c23a086e9009f4687..368bb8b8e64b6b853ec231b4a16d5a8fe306d5ae 100644 (file)
@@ -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