Repository navigation
Replies: 1 comment 9 replies
|
Im Prinzip ist der Vorschlag eine "Domain Specific Language (DSL)" für die Validierung der "special types" (z.B [IP4]) zu erschaffen. |
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Updated: 2Nov26 18:30
Implementation of a common .cfg file parser/validator
Coding reliable and safe user input parsers is from my view one of the hardest tasks for every programmer.
Because of this challenge I'd like to ask for help from the community to implement this for TinyC.
Requirements:
Validation:
https://github.com/lensboard/Validate-IPv4-address-in-C/blob/main/validate-ip.c#L10C1-L15C54
https://www.rfc-editor.org/info/rfc2640/#section-3
https://ipparse.com/fqdn-validator
https://github.com/lensboard/How-to-validate-an-email-address-in-C
At least some of these requirements can be implemented using regex expressions
i.e. https://stackoverflow.com/questions/11809631/fully-qualified-domain-name-validation
Note: my C programming skills are very limited! Hence I'm not sure if this is feasible in TinyC!
function:
getCfg
function interface:
Open questions:
Implementation:
Reference parameter https://gemu2015.github.io/Sonoff-Tasmota/reference/?h=filelog#reference-parameters-since-143
Dual-context worker VM https://gemu2015.github.io/Sonoff-Tasmota/reference/?h=dual+context+worker+vm#concurrency-model-one-vm-per-slot
Example:
cfg file: ftp.cfg
// /ftp.cfg for FTP-Backup (TinyC). Lines with // are comments.
// FRITZ!Box: its IP, not fritz.box because over IPv6 the box refuses passive mode!
HOST[IP4]=192.168.178.1
// user login on target
USER[FTP-USER]=logger
//password for login
PWD=secret
// folder for the backups, it must exist!
DIR=/
Using rhw proposed function:
Note: this is not TinyC code, not tried to compile!
cfgKeys[]={"HOST","USER","PWD","DIR"}
struct cfgValues {
byte host[40];
byte user[40];
byte pwd[40];
byte dir[128];
}
// get specified key from config file
err = getCfg("ftp.cfg",cfgKeys,cfgValues)
// use output from getCfg
connection = connectToFtpServer(host, user, pwd)
err = moveFileToFtpServer(connection,sourceFile,dir,targetFile)
All reactions