Модуль ns_captionkey для AOL Server

Описание модуля приведено в комментарии в коде.


# Copyright 2009, Mobile Business Group
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.

package require json

# простой интерфейс для управления заголовками
# проверки аргументов убраны, т.к. это лишний оверхед, а функции вызываются очень часто
proc ns_captionkey {action args} {
if {$action eq {exists}} {
return [nsv_exists captionkeys[lindex $args 0] [lindex $args 1]]
} elseif {$action eq {names}} {
return [nsv_array names captionkeys[lindex $args 0]]
} elseif {$action eq {get_escape}} {
return [::json::string_escape [ns_captionkey get {*}$args]]
} elseif {$action eq {get}} {
# можно указывать список юнитов, поиск ведется последовательно
if {[lindex $args 0] eq {}} {
if {[nsv_exists captionkeys[lindex $args 0] [lindex $args 1]] == 1} {
return [nsv_get captionkeys[lindex $args 0] [lindex $args 1]]
}
}
foreach name [lindex $args 0] {
if {[nsv_exists captionkeys$name [lindex $args 1]] == 1} {
return [nsv_get captionkeys$name [lindex $args 1]]
}
}
# ключ не найден, возвращаем имя ключа
return [lindex $args 1]
} elseif {$action eq {set}} {
nsv_set captionkeys[lindex $args 0] [lindex $args 1] [lindex $args 2]
return [lindex $args 2]
} elseif {$action eq {lappend}} {
# append data to list
nsv_lappend captionkeys[lindex $args 0] [lindex $args 1] [lindex $args 2]
return [nsv_get captionkeys[lindex $args 0] [lindex $args 1]]
} elseif {$action eq {aset}} {
nsv_array set captionkeys[lindex $args 0] [lindex $args 1]
} elseif {$action eq {aget}} {
return [nsv_array get captionkeys[lindex $args 0]]
}
}

Comments

Popular posts from this blog

Открытый софт для научных расчетов

Счетчики в SQLite

Модем Huawei E1550 в debian