It is highly likely that a backend needs configuration details. On launch, these parameters need to be declared with PDNS so it knows it should accept them in the configuration file and on the commandline. Furthermore, they will be listed in the output of --help.
Declaring arguments is done by implementing the member function declareArguments()
in the factory class of your
backend. PDNS will call this method after launching the backend.
In the declareArguments()
method, the function declare()
is available. The exact definitions:
This method is called to allow a backend to register configurable parameters. The suffix is the sub-name of this module. There is no need to touch this suffix, just pass it on to the declare method.
The suffix is passed to your method, and can be passed on to declare. param is the name of your parameter. explanation is what will appear in the output of --help. Furthermore, a default value can be supplied in the value parameter.
A sample implementation:
void declareArguments(const string &suffix) { declare(suffix,"dbname","Pdns backend database name to connect to","powerdns"); declare(suffix,"user","Pdns backend user to connect as","powerdns"); declare(suffix,"host","Pdns backend host to connect to",""); declare(suffix,"password","Pdns backend password to connect with",""); }
After the arguments have been declared, they can be accessed from your backend using the mustDo()
,
getArg()
and getArgAsNum()
methods. The are defined as follows in the DNSBackend class:
Must be called before any of the other accessing functions are used. Typical usage is 'setArgPrefix("mybackend"+suffix)
'
in the constructor of a backend.
Returns true if the variable key
is set to anything but 'no'.
Returns the exact value of a parameter.
Returns the numerical value of a parameter. Uses atoi()
internally
Sample usage from the BindBackend, using the bind-example-zones and bind-config parameters.
if(mustDo("example-zones")) { insert(0,"www.example.com","A","1.2.3.4"); /* ... */ } if(!getArg("config").empty()) { BindParser BP; BP.parse(getArg("config")); }