validate all parameters sent to dsp, refs #215

This commit is contained in:
Jakob Ketterl 2021-01-24 22:29:23 +01:00
parent 15940d0a2e
commit 7e60efeae2

View File

@ -4,16 +4,26 @@ from owrx.js8 import Js8Parser
from owrx.aprs import AprsParser from owrx.aprs import AprsParser
from owrx.pocsag import PocsagParser from owrx.pocsag import PocsagParser
from owrx.source import SdrSource, SdrSourceEventClient from owrx.source import SdrSource, SdrSourceEventClient
from owrx.property import PropertyStack, PropertyLayer from owrx.property import PropertyStack, PropertyLayer, PropertyValidator
from owrx.property.validators import OrValidator, RegexValidator, BoolValidator
from owrx.modes import Modes from owrx.modes import Modes
from csdr import csdr from csdr import csdr
import threading import threading
import re
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class ModulationValidator(OrValidator):
"""
This validator only allows alphanumeric characters and numbers, but no spaces or special characters
"""
def __init__(self):
super().__init__(BoolValidator(), RegexValidator(re.compile("^[a-z0-9]+$")))
class DspManager(csdr.output, SdrSourceEventClient): class DspManager(csdr.output, SdrSourceEventClient):
def __init__(self, handler, sdrSource): def __init__(self, handler, sdrSource):
self.handler = handler self.handler = handler
@ -27,19 +37,24 @@ class DspManager(csdr.output, SdrSourceEventClient):
} }
self.props = PropertyStack() self.props = PropertyStack()
# local demodulator properties not forwarded to the sdr # local demodulator properties not forwarded to the sdr
self.localProps = PropertyLayer().filter( # ensure strict validation since these can be set from the client
"output_rate", # and are used to build executable commands
"hd_output_rate", validators = {
"squelch_level", "output_rate": "int",
"secondary_mod", "hd_output_rate": "int",
"low_cut", "squelch_level": "num",
"high_cut", "secondary_mod": ModulationValidator(),
"offset_freq", "low_cut": "num",
"mod", "high_cut": "num",
"secondary_offset_freq", "offset_freq": "int",
"dmr_filter", "mod": ModulationValidator(),
) "secondary_offset_freq": "int",
"dmr_filter": "int",
}
self.localProps = PropertyValidator(PropertyLayer().filter(*validators.keys()), validators)
self.props.addLayer(0, self.localProps) self.props.addLayer(0, self.localProps)
# properties that we inherit from the sdr # properties that we inherit from the sdr
self.props.addLayer(1, self.sdrSource.getProps().filter( self.props.addLayer(1, self.sdrSource.getProps().filter(