Input Validation
All ClearOS libraries should maintain their own validation routines for consistency. For example, dnsmasq→validate_gateway() should be created and used instead of making the developer poke around for the network_utils→validate_ip. Why? Consistency. Every application may have slightly different needs. For example, 192.168.3.3 is certainly a valid IP but it's not a valid DHCP gateway address for a 10.0.0.0 network. Instead of making a developer guess how to pre-validate a dnsmasq→set_gateway method, they can count on seeing an dnsmasq→validate_gateway method.
The validation methods can certainly call generic routines, e.g. dnsmasq→validate_gateway uses network_utils→validate_ip. That is to be encouraged of course!
Validation 101
- Check the date type
- Check the length
- Match an appropriate regular expression
- Escape the data if necessary