return instance->driver_parameter;
}
-char *
-RCL_GetDriverOption(RCL_Instance instance, char *name)
+static char *
+get_next_driver_option(RCL_Instance instance, char *option)
{
- char *s, *e;
- int n;
+ if (option == NULL)
+ option = instance->driver_parameter;
- s = instance->driver_parameter;
- e = s + instance->driver_parameter_length;
- n = strlen(name);
+ option += strlen(option) + 1;
- while (1) {
- s += strlen(s) + 1;
- if (s >= e)
- break;
- if (!strncmp(name, s, n)) {
- if (s[n] == '=')
- return s + n + 1;
- if (s[n] == '\0')
- return s + n;
+ if (option >= instance->driver_parameter + instance->driver_parameter_length)
+ return NULL;
+
+ return option;
+}
+
+void
+RCL_CheckDriverOptions(RCL_Instance instance, const char **options)
+{
+ char *option;
+ int i, len;
+
+ for (option = get_next_driver_option(instance, NULL);
+ option;
+ option = get_next_driver_option(instance, option)) {
+ for (i = 0; options && options[i]; i++) {
+ len = strlen(options[i]);
+ if (!strncmp(options[i], option, strlen(options[i])) &&
+ (option[len] == '=' || option[len] == '\0'))
+ break;
+ }
+
+ if (!options || !options[i])
+ LOG_FATAL("Invalid refclock driver option %s", option);
+ }
+}
+
+char *
+RCL_GetDriverOption(RCL_Instance instance, char *name)
+{
+ char *option;
+ int len;
+
+ len = strlen(name);
+
+ for (option = get_next_driver_option(instance, NULL);
+ option;
+ option = get_next_driver_option(instance, option)) {
+ if (!strncmp(name, option, len)) {
+ if (option[len] == '=')
+ return option + len + 1;
+ if (option[len] == '\0')
+ return option + len;
}
}
extern void RCL_SetDriverData(RCL_Instance instance, void *data);
extern void *RCL_GetDriverData(RCL_Instance instance);
extern char *RCL_GetDriverParameter(RCL_Instance instance);
+extern void RCL_CheckDriverOptions(RCL_Instance instance, const char **options);
extern char *RCL_GetDriverOption(RCL_Instance instance, char *name);
extern int RCL_AddSample(RCL_Instance instance, struct timespec *sample_time, double offset, int leap);
extern int RCL_AddPulse(RCL_Instance instance, struct timespec *pulse_time, double second);
static int phc_initialise(RCL_Instance instance)
{
+ const char *options[] = {"nocrossts", "extpps", "pin", "channel", "clear", NULL};
struct phc_instance *phc;
int phc_fd, rising_edge;
char *path, *s;
+ RCL_CheckDriverOptions(instance, options);
+
path = RCL_GetDriverParameter(instance);
phc_fd = SYS_Linux_OpenPHC(path, 0);
};
static int pps_initialise(RCL_Instance instance) {
+ const char *options[] = {"clear", NULL};
pps_handle_t handle;
pps_params_t params;
struct pps_instance *pps;
int fd, edge_clear, mode;
char *path;
+ RCL_CheckDriverOptions(instance, options);
+
path = RCL_GetDriverParameter(instance);
edge_clear = RCL_GetDriverOption(instance, "clear") ? 1 : 0;
};
static int shm_initialise(RCL_Instance instance) {
+ const char *options[] = {"perm", NULL};
int id, param, perm;
char *s;
struct shmTime *shm;
+ RCL_CheckDriverOptions(instance, options);
+
param = atoi(RCL_GetDriverParameter(instance));
s = RCL_GetDriverOption(instance, "perm");
perm = s ? strtol(s, NULL, 8) & 0777 : 0600;
int sockfd;
char *path;
+ RCL_CheckDriverOptions(instance, NULL);
+
path = RCL_GetDriverParameter(instance);
s.sun_family = AF_UNIX;