conf: rework local directive to have default stratum
Allow the local directive to be specified without the stratum field. It's an option now, with default value 10. Also, move the parsing code to cmdparse.c to make it available to the client.
This commit is contained in:
parent
eb75ce7d07
commit
981f897c96
3 changed files with 31 additions and 6 deletions
26
cmdparse.c
26
cmdparse.c
|
@ -223,6 +223,32 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src)
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
int
|
||||||
|
CPS_ParseLocal(char *line, int *stratum)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
char *cmd;
|
||||||
|
|
||||||
|
*stratum = 10;
|
||||||
|
|
||||||
|
while (*line) {
|
||||||
|
cmd = line;
|
||||||
|
line = CPS_SplitWord(line);
|
||||||
|
|
||||||
|
if (!strcasecmp(cmd, "stratum")) {
|
||||||
|
if (sscanf(line, "%d%n", stratum, &n) != 1)
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
line += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
CPS_StatusToString(CPS_Status status, char *dest, int len)
|
CPS_StatusToString(CPS_Status status, char *dest, int len)
|
||||||
{
|
{
|
||||||
|
|
|
@ -59,6 +59,9 @@ typedef struct {
|
||||||
/* Parse a command to add an NTP server or peer */
|
/* Parse a command to add an NTP server or peer */
|
||||||
extern CPS_Status CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
|
extern CPS_Status CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src);
|
||||||
|
|
||||||
|
/* Parse a command to enable local reference */
|
||||||
|
extern int CPS_ParseLocal(char *line, int *stratum);
|
||||||
|
|
||||||
/* Get a string describing error status */
|
/* Get a string describing error status */
|
||||||
extern void CPS_StatusToString(CPS_Status status, char *dest, int len);
|
extern void CPS_StatusToString(CPS_Status status, char *dest, int len);
|
||||||
|
|
||||||
|
|
8
conf.c
8
conf.c
|
@ -817,13 +817,9 @@ parse_log(char *line)
|
||||||
static void
|
static void
|
||||||
parse_local(char *line)
|
parse_local(char *line)
|
||||||
{
|
{
|
||||||
int stratum;
|
if (!CPS_ParseLocal(line, &local_stratum))
|
||||||
if (sscanf(line, "stratum%d", &stratum) == 1) {
|
|
||||||
local_stratum = stratum;
|
|
||||||
enable_local = 1;
|
|
||||||
} else {
|
|
||||||
command_parse_error();
|
command_parse_error();
|
||||||
}
|
enable_local = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
Loading…
Reference in a new issue