Subversion Repositories Koakuma

Rev

Rev 17 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 19
Line 1... Line 1...
1
# $Id: rpc.tcl 17 2024-10-02 07:31:01Z nishi $
1
# $Id: rpc.tcl 19 2024-10-02 07:44:13Z nishi $
2
package require http
2
package require http
3
package require base64
3
package require base64
4
package require term::ansi::ctrl::unix
4
package require term::ansi::ctrl::unix
5
 
5
 
6
catch {
6
catch {
Line 65... Line 65...
65
			return 1
65
			return 1
66
		}
66
		}
67
		return 0
67
		return 0
68
	}
68
	}
69
	proc send {path content} {
69
	proc send {path content} {
70
		set headers ""
-
 
71
		global RPC_URL
70
		global RPC_URL
-
 
71
		set code ""
-
 
72
		set body ""
-
 
73
		while 1 {
-
 
74
			set headers ""
72
		if { "$::rpc::username" != "" } {
75
			if { "$::rpc::username" != "" } {
73
			lappend headers "Authorization"
76
				lappend headers "Authorization"
74
			lappend headers "Basic [::base64::encode -wrapchar "" "$::rpc::username:$::rpc::password"]"
77
				lappend headers "Basic [::base64::encode -wrapchar "" "$::rpc::username:$::rpc::password"]"
-
 
78
			}
-
 
79
			set tok [::http::geturl "$RPC_URL$path" -headers $headers -type "application/json" -query "$content"]
-
 
80
			set code [::http::ncode $tok]
-
 
81
			set body "[::http::data $tok]"
-
 
82
			::http::cleanup $tok
-
 
83
			if { $code == 401 } {
-
 
84
				::rpc::ask-auth
-
 
85
			} else {
-
 
86
				break
-
 
87
			}
75
		}
88
		}
76
		set tok [::http::geturl "$RPC_URL$path" -headers $headers -type "application/json" -query "$content"]
-
 
77
		set code [::http::ncode $tok]
-
 
78
		set body "[::http::data $tok]"
-
 
79
		::http::cleanup $tok
-
 
80
		lappend result "$code"
89
		lappend result "$code"
81
		lappend result "$body"
90
		lappend result "$body"
82
		return $result
91
		return $result
83
	}
92
	}
84
	proc init {} {
93
	proc init {} {