return r;
}
+static int td_source_check_data_sources(td_source* self) {
+ for (const td_rrd_ds* ds = self->impl->rrd_dss; ds->field; ds++) {
+ // Check if the field name is empty
+ if (!ds->field || !*ds->field) {
+ ERROR(self->ctx, "Empty DS field in %s\n", td_source_name(self));
+ return -EINVAL;
+ }
+
+ // Check field name length
+ size_t length = strlen(ds->field);
+
+ // Fail if it is too long
+ if (length > 19) {
+ ERROR(self->ctx, "DS field name is too long: %s. "
+ "Must be <= 19 characters, but is %ld.\n", ds->field, length);
+ return -EINVAL;
+ }
+
+ // Check for invalid characters
+ for (const char* p = ds->field; *p; p++) {
+ // A-Z/a-z are allowed
+ if (isalpha(*p))
+ continue;
+
+ // Digits are allowed
+ if (isdigit(*p))
+ continue;
+
+ // Special characters
+ switch (*p) {
+ case '-':
+ case '_':
+ continue;
+
+ default:
+ ERROR(self->ctx, "DS field name contains invalid characters: %s\n", ds->field);
+ return -EINVAL;
+ }
+ }
+ }
+
+ return 0;
+}
+
static int td_source_check(td_source* self) {
// Check if name is set
if (!self->impl->name) {
return -EINVAL;
}
- return 0;
+ // Check data sources
+ return td_source_check_data_sources(self);
}
static void td_source_free(td_source* self) {