| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "inicfg_internals.h" |
| 4 | |
| 5 | /* |
| 6 | * @Input: |
| 7 | * Connector / instance to add to an internal structure |
| 8 | * @Return |
| 9 | * The current head of the linked list of connector_instance |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | _CONNECTOR_INSTANCE *add_connector_instance(struct config_section *connector, struct config_section *instance) |
| 14 | { |
| 15 | static struct _connector_instance *global_connector_instance = NULL; |
| 16 | struct _connector_instance *local_ci, *local_ci_tmp; |
| 17 | |
| 18 | if (unlikely(!connector)) { |
| 19 | if (unlikely(!instance)) |
| 20 | return global_connector_instance; |
| 21 | |
| 22 | local_ci = global_connector_instance; |
| 23 | while (local_ci) { |
| 24 | local_ci_tmp = local_ci->next; |
| 25 | freez(local_ci); |
| 26 | local_ci = local_ci_tmp; |
| 27 | } |
| 28 | global_connector_instance = NULL; |
| 29 | return NULL; |
| 30 | } |
| 31 | |
| 32 | local_ci = callocz(1, sizeof(struct _connector_instance)); |
| 33 | local_ci->instance = instance; |
| 34 | local_ci->connector = connector; |
| 35 | strncpyz(local_ci->instance_name, string2str(instance->name), CONFIG_MAX_NAME); |
| 36 | strncpyz(local_ci->connector_name, string2str(connector->name), CONFIG_MAX_NAME); |
| 37 | local_ci->next = global_connector_instance; |
| 38 | global_connector_instance = local_ci; |
| 39 | |
| 40 | return global_connector_instance; |
| 41 | } |
| 42 | |
| 43 | int is_valid_connector(char *type, int check_reserved) { |
| 44 | int rc = 1; |
| 45 | |
| 46 | if (unlikely(!type)) |
| 47 | return 0; |
| 48 | |
| 49 | if (!check_reserved) { |
| 50 | if (unlikely(is_valid_connector(type,1))) { |
| 51 | return 0; |
| 52 | } |
| 53 | //if (unlikely(*type == ':') |
| 54 | // return 0; |
| 55 | char *separator = strrchr(type, ':'); |
| 56 | if (likely(separator)) { |
| 57 | *separator = '\0'; |
| 58 | rc = (int)(separator - type); |
| 59 | } else |
| 60 | return 0; |
| 61 | } |
| 62 | // else { |
| 63 | // if (unlikely(is_valid_connector(type,1))) { |
| 64 | // netdata_log_error("Section %s invalid -- reserved name", type); |
| 65 | // return 0; |
| 66 | // } |
| 67 | // } |
| 68 | |
| 69 | if (!strcmp(type, "graphite") || !strcmp(type, "graphite:plaintext")) { |
| 70 | return rc; |
| 71 | } else if (!strcmp(type, "graphite:http") || !strcmp(type, "graphite:https")) { |
| 72 | return rc; |
| 73 | } else if (!strcmp(type, "json") || !strcmp(type, "json:plaintext")) { |
| 74 | return rc; |
| 75 | } else if (!strcmp(type, "json:http") || !strcmp(type, "json:https")) { |
| 76 | return rc; |
| 77 | } else if (!strcmp(type, "opentsdb") || !strcmp(type, "opentsdb:telnet")) { |
| 78 | return rc; |
| 79 | } else if (!strcmp(type, "opentsdb:http") || !strcmp(type, "opentsdb:https")) { |
| 80 | return rc; |
| 81 | } else if (!strcmp(type, "prometheus_remote_write")) { |
| 82 | return rc; |
| 83 | } else if (!strcmp(type, "prometheus_remote_write:http") || !strcmp(type, "prometheus_remote_write:https")) { |
| 84 | return rc; |
| 85 | } else if (!strcmp(type, "kinesis") || !strcmp(type, "kinesis:plaintext")) { |
| 86 | return rc; |
| 87 | } else if (!strcmp(type, "pubsub") || !strcmp(type, "pubsub:plaintext")) { |
| 88 | return rc; |
| 89 | } else if (!strcmp(type, "mongodb") || !strcmp(type, "mongodb:plaintext")) { |
| 90 | return rc; |
| 91 | } |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 |