"
(C) 2010 by Holger Hans Peter Freyther
All Rights Reserved
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"
CStruct subclass: Vty_app_info [
]
CStruct subclass: Vty_vector [
"the index is wrong but we do not need to access it"
]
CStruct subclass: Vty_cmd_element [
]
CStruct subclass: Vty_cmd_node [
]
Object subclass: NodeType [
NodeType class >> AUTH_NODE [
^ 0
]
NodeType class >> VIEW_NODE [
^ 1
]
NodeType class >> AUTH_ENABLE_NODE [
^ 2
]
NodeType class >> ENABLE_NODE [
^ 3
]
NodeType class >> CONFIG_NODE [
^ 4
]
NodeType class >> SERVICE_NODE [
^ 5
]
NodeType class >> DEBUG_NODE [
^ 6
]
NodeType class >> VTY_NODE [
^ 7
]
]
Object subclass: OSMOVTY [
OSMOVTY class >> initialize [
DLD addLibrary: 'libosmovty.so.0'
]
OSMOVTY class >> vty_init: app_info [
]
OSMOVTY class >> vty_read_config_file: file_name priv: priv [
]
OSMOVTY class >> telnet_init: tall_context priv: priv port: aPort [
]
OSMOVTY class >> install_node: aNode func: aFunc [
]
OSMOVTY class >> install_default: aNode [
]
OSMOVTY class >> install_element: aNode cmd: aCmd [
]
OSMOVTY class >> install_element_ve: aCmd [
]
OSMOVTY class >> vty_out: aVty msg: aMsg [
]
OSMOVTY class >> vty_out_newline: aVty [
]
OSMOVTY class >> initWith: aName version: aVersion license: aLicense port: aPort [
| app_info |
app_info := Vty_app_info new.
app_info name value: aName.
app_info version value: aVersion.
app_info copyright value: aLicense.
app_info tall_ctx value: 0.
app_info go_parent_cb value: 0.
app_info is_config_node value: 0.
OSMOVTY vty_init: app_info.
OSMOVTY telnet_init: nil priv: nil port: 4444.
]
OSMOVTY class >> commands [
^ Smalltalk at: #VTY_Commands ifAbsent: [
| array |
array := OrderedCollection new.
Smalltalk at: #VTY_Commands put: array.
array.
]
]
]
Object subclass: VTYCommand [
| command callback handler |
VTYCommand class >> initWith: aCommand help: aHelp handler: aBlock[
"Create a new command. The memory is allocated permamently"
| command |
command := Vty_cmd_element gcNew.
command name value: aCommand.
command doc value: aHelp.
^ (self new)
command: command;
handler: aBlock;
yourself.
]
handleCommand: aCmd vty: aVty argc: aArgc argv: aArgv [
| str strings |
str := aArgv castTo: CStringType.
strings := OrderedCollection new.
0 to: (aArgc - 1) do: [ :each |
strings add: (str at: each).
].
^ handler value: aVty value: strings.
]
handler: aBlock [
handler := aBlock.
]
command: aCommand [
"We need to know when we are removed as we will segfault soon"
self addToBeFinalized.
command := aCommand.
callback := CCallbackDescriptor
for: [ :cmd :vty :argc :argv |
self handleCommand: cmd vty: vty argc: argc argv: argv.
]
returning: #int
withArgs: #(#cObject #cObject #int #cObject).
command func value: callback.
]
command [
^ command
]
finalize [
self error: 'The command can not be removed. A crash will happen soon.'
]
install_ve [
OSMOVTY commands add: self.
OSMOVTY install_element_ve: command.
]
install: aNode [
OSMOVTY commands add: self.
OSMOVTY install_element: aNode cmd: command.
]
]
Eval [
OSMOVTY initialize.
]