int state_setaux(st_tree_t *root, const char *var, const char *auxs) { st_tree_t *sttmp; int aux; /* find the tree node for var */ sttmp = state_tree_find(root, var); if (!sttmp) { upslogx(LOG_ERR, "state_addenum: base variable (%s) " "does not exist", var); return -1; /* failed */ } aux = strtol(auxs, (char **) NULL, 10); /* silently ignore matches */ if (sttmp->aux == aux) { return 0; } sttmp->aux = aux; return 1; }
int state_delrange(st_tree_t *root, const char *var, const int min, const int max) { st_tree_t *sttmp; /* find the tree node for var */ sttmp = state_tree_find(root, var); if (!sttmp) { return 0; } return st_tree_del_range(&sttmp->range_list, min, max); }
int state_delenum(st_tree_t *root, const char *var, const char *val) { st_tree_t *sttmp; /* find the tree node for var */ sttmp = state_tree_find(root, var); if (!sttmp) { return 0; } return st_tree_del_enum(&sttmp->enum_list, val); }
const range_t *state_getrangelist(st_tree_t *root, const char *var) { st_tree_t *sttmp; /* find the tree node for var */ sttmp = state_tree_find(root, var); if (!sttmp) { return NULL; } return sttmp->range_list; }
int state_getaux(st_tree_t *root, const char *var) { st_tree_t *sttmp; /* find the tree node for var */ sttmp = state_tree_find(root, var); if (!sttmp) { return -1; } return sttmp->aux; }
const char *state_getinfo(st_tree_t *root, const char *var) { st_tree_t *sttmp; /* find the tree node for var */ sttmp = state_tree_find(root, var); if (!sttmp) { return NULL; } return sttmp->val; }
int state_addenum(st_tree_t *root, const char *var, const char *val) { st_tree_t *sttmp; char enc[ST_MAX_VALUE_LEN]; /* find the tree node for var */ sttmp = state_tree_find(root, var); if (!sttmp) { upslogx(LOG_ERR, "state_addenum: base variable (%s) " "does not exist", var); return 0; /* failed */ } /* smooth over any oddities in the enum value */ pconf_encode(val, enc, sizeof(enc)); return st_tree_enum_add(&sttmp->enum_list, enc); }
void dstate_setaux(const char *var, int aux) { st_tree_t *sttmp; /* find the dtree node for var */ sttmp = state_tree_find(dtree_root, var); if (!sttmp) { upslogx(LOG_ERR, "dstate_setaux: base variable (%s) does not exist", var); return; } if (sttmp->aux == aux) { return; /* no change */ } sttmp->aux = aux; /* update listeners */ send_to_all("SETAUX %s %d\n", var, aux); }
int state_addrange(st_tree_t *root, const char *var, const int min, const int max) { st_tree_t *sttmp; /* sanity check */ if (min > max) { upslogx(LOG_ERR, "state_addrange: min is superior to max! (%i, %i)", min, max); return 0; } /* find the tree node for var */ sttmp = state_tree_find(root, var); if (!sttmp) { upslogx(LOG_ERR, "state_addrange: base variable (%s) " "does not exist", var); return 0; /* failed */ } return st_tree_range_add(&sttmp->range_list, min, max); }
void dstate_setflags(const char *var, int flags) { st_tree_t *sttmp; char flist[SMALLBUF]; /* find the dtree node for var */ sttmp = state_tree_find(dtree_root, var); if (!sttmp) { upslogx(LOG_ERR, "%s: base variable (%s) does not exist", __func__, var); return; } if (sttmp->flags & ST_FLAG_IMMUTABLE) { upslogx(LOG_WARNING, "%s: base variable (%s) is immutable", __func__, var); return; } if (sttmp->flags == flags) { return; /* no change */ } sttmp->flags = flags; /* build the list */ snprintf(flist, sizeof(flist), "%s", var); if (flags & ST_FLAG_RW) { snprintfcat(flist, sizeof(flist), " RW"); } if (flags & ST_FLAG_STRING) { snprintfcat(flist, sizeof(flist), " STRING"); } /* update listeners */ send_to_all("SETFLAGS %s\n", flist); }
void state_setflags(st_tree_t *root, const char *var, int numflags, char **flag) { int i; st_tree_t *sttmp; /* find the tree node for var */ sttmp = state_tree_find(root, var); if (!sttmp) { upslogx(LOG_ERR, "state_setflags: base variable (%s) " "does not exist", var); return; } sttmp->flags = 0; for (i = 0; i < numflags; i++) { if (!strcasecmp(flag[i], "RW")) { sttmp->flags |= ST_FLAG_RW; continue; } if (!strcasecmp(flag[i], "STRING")) { sttmp->flags |= ST_FLAG_STRING; continue; } if (!strcasecmp(flag[i], "NUMBER")) { sttmp->flags |= ST_FLAG_NUMBER; continue; } upsdebugx(2, "Unrecognized flag [%s]", flag[i]); } }