Skip to content

Commit

Permalink
fixed some nagelfar tcl linter syntax warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jens-maus committed Oct 26, 2023
1 parent 805fb55 commit 7ca4031
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 32 deletions.
22 changes: 4 additions & 18 deletions xmlapi/common.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ loadOnce tclrpc.so

proc decr {x {cnt 1}} {
upvar $x xx
set xx [expr $xx - $cnt]
set xx [expr { $xx - $cnt }]
}
proc max {x y} { expr { $x > $y ? $x : $y } }
proc min {x y} { expr { $x > $y ? $y : $x } }

proc cgi_cgi {args} {return $args}

proc in {list element} {expr [lsearch -exact $list $element] >= 0}
proc in {list element} {expr { [lsearch -exact $list $element] >= 0 } }

proc array_clear {name} {
upvar $name arr
Expand All @@ -30,13 +30,6 @@ proc array_clear {name} {
}
}

proc array_copy {src_name dst_name} {

global $src_name $dst_name
array_clear $dst_name
array set $dst_name [array get $src_name]
}

#Liest eine Datei ein mit dem Format
#Key=Value
#Key=Value
Expand Down Expand Up @@ -118,13 +111,6 @@ proc eval_script {script} {
return $ret
}

proc BitsSet {b_testee b_set} {

if {$b_testee == "" || $b_set == "" || $b_testee == 0 || $b_set == 0} then { return 0 }

return [expr [expr $b_set & $b_testee] == $b_testee]
}

proc putimage {img_path} {

set in [open $img_path]
Expand Down Expand Up @@ -161,7 +147,7 @@ array set interface_descriptions ""
proc read_interfaces {} {
global interfaces interface_descriptions INTERFACES_FILE env
set retval 1
if { [ info exist env(BIDCOS_SERVICE) ] } {
if { [ info exists env(BIDCOS_SERVICE) ] } {
set interfaces(default) "$env(BIDCOS_SERVICE)"
set interface_descriptions(default) "Default BidCoS Interface"
} else {
Expand All @@ -171,7 +157,7 @@ proc read_interfaces {} {
set contents [read $fd]
while { [regexp -indices {</ipc[^>]*>} $contents range] } {
set section [string range $contents 0 [lindex $range 1]]
set contents [string range $contents [expr [lindex $range 1] + 1] end]
set contents [string range $contents [expr { [lindex $range 1] + 1 }] end]
if {
[regexp {<name[^>]*>([^<]+)</name} $section dummy name] &&
[regexp {<url[^>]*>([^<]+)</url} $section dummy url] &&
Expand Down
2 changes: 1 addition & 1 deletion xmlapi/devicelist.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ if {[info exists sid] && [check_session $sid]} {
Write("</device>");
}
}
}]
}]

if { $res(STDOUT) != "" } {
puts -nonewline $res(STDOUT)
Expand Down
5 changes: 4 additions & 1 deletion xmlapi/exec.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ if {[info exists sid] && [check_session $sid]} {
set first 1
set result "\{\n"
foreach name [array names script_result] {
if { 1 != $first } { append result ",\n" } { set first 0 }
if { 1 != $first } {
append result ",\n"
}
set first 0
set value $script_result($name)
append result " [toString $name]: [toString $value]"
}
Expand Down
2 changes: 1 addition & 1 deletion xmlapi/scripterrors.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if {[info exists sid] && [check_session $sid]} {

set Datei [open "|/usr/bin/tail -n 10 /var/log/messages" r]
while {[gets $Datei Zeile] >= 0} {
if [regexp Error.*near $Zeile] {
if { [regexp Error.*near $Zeile] } {
regexp {([a-zA-Z]+ [0-9]+ [0-9\:]+) .+ local0.err ReGaHss: ERROR: SyntaxError\: Error ([0-9]+) at row ([0-9]+) col ([0-9]+)} $Zeile line time code row col
puts -nonewline "<error "
puts -nonewline "timestamp='$time' "
Expand Down
18 changes: 9 additions & 9 deletions xmlapi/session.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ proc save_tokens tokenlist {
}
}

proc register_token desc {
proc register_token descr {
# get tokens
array set tokens [get_tokens]

Expand All @@ -45,21 +45,21 @@ proc register_token desc {
set newToken [subst [string repeat {[format %c [expr {int(rand() * 26) + (rand() > .5 ? 97 : 65)}]]} 16]]

# add token to array
set tokens($newToken) $desc
set tokens($newToken) $descr

# save tokens
save_tokens [array get tokens]

return $newToken
}

proc revoke_token token {
proc revoke_token tid {
# get tokens
array set tokens [get_tokens]

if {[info exists tokens($token)]} {
if {[info exists tokens($tid)]} {
# remove token from array
unset tokens($token)
unset tokens($tid)

# write out new token list
save_tokens [array get tokens]
Expand All @@ -69,19 +69,19 @@ proc revoke_token token {
return 0
}

proc check_session sid {
proc check_session session_id {
global raddr
# check for api tokens first and then check
# for webui session ids as well as a fallback
if {[regexp {^([0-9a-zA-Z]{16})$} $sid all sidnr]} {
if {[regexp {^([0-9a-zA-Z]{16})$} $session_id all sidnr]} {
# get tokens
array set tokens [get_tokens]

# check if sid exists in token array
if {[info exists tokens($sid)]} {
if {[info exists tokens($session_id)]} {
return 1
}
} elseif {[regexp {^@([0-9a-zA-Z]{10})@$} $sid all sidnr]} {
} elseif {[regexp {^@([0-9a-zA-Z]{10})@$} $session_id all sidnr]} {
set res [lindex [rega_script "Write(system.GetSessionVarStr('$sidnr'));"] 1]
if {$res != ""} {
return 1
Expand Down
2 changes: 1 addition & 1 deletion xmlapi/statechange.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if {[info exists sid] && [check_session $sid]} {
regsub -all {%21} $new_value {!} new_value
regsub -all {%23} $new_value {#} new_value
regsub -all {%25} $new_value {%} new_value
regsub -all {%2A} $new_value {*} new_value
regsub -all {%2A} $new_value * new_value
regsub -all {%2F} $new_value {/} new_value
regsub -all {%3C} $new_value {<} new_value
regsub -all {%3E} $new_value {>} new_value
Expand Down
2 changes: 1 addition & 1 deletion xmlapi/statelist.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if {[info exists sid] && [check_session $sid]} {
Write(" timestamp='");WriteXML(oDP.Timestamp().ToInteger());Write("'");
Write(" />");
}
}
}

} else {

Expand Down

0 comments on commit 7ca4031

Please sign in to comment.