/* * Store a directory name at specified address. Note, we do * shell expansion except if the string begins with a vertical * bar (i.e. it will likely be passed to the shell later). */ void store_dir(LEX *lc, RES_ITEM *item, int index, int pass) { lex_get_token(lc, T_STRING); if (pass == 1) { if (lc->str[0] != '|') { do_shell_expansion(lc->str, sizeof(lc->str)); } *(item->value) = bstrdup(lc->str); } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); }
/* * Store a directory name at specified address. Note, we do * shell expansion except if the string begins with a vertical * bar (i.e. it will likely be passed to the shell later). */ static void store_dir(LEX *lc, RES_ITEM *item, int index, int pass) { URES *res_all = (URES *)my_config->m_res_all; lex_get_token(lc, T_STRING); if (pass == 1) { /* * If a default was set free it first. */ if (*(item->value)) { free(*(item->value)); } if (lc->str[0] != '|') { do_shell_expansion(lc->str, sizeof_pool_memory(lc->str)); } *(item->value) = bstrdup(lc->str); } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); }
/* * Store a directory name at specified address in an alist. * Note, we do shell expansion except if the string begins * with a vertical bar (i.e. it will likely be passed to the * shell later). */ void store_alist_dir(LEX *lc, RES_ITEM *item, int index, int pass) { alist *list; if (pass == 2) { if (*(item->value) == NULL) { list = New(alist(10, owned_by_alist)); } else { list = (alist *)(*(item->value)); } lex_get_token(lc, T_STRING); /* scan next item */ Dmsg4(900, "Append %s to alist %p size=%d %s\n", lc->str, list, list->size(), item->name); if (lc->str[0] != '|') { do_shell_expansion(lc->str, sizeof(lc->str)); } list->append(bstrdup(lc->str)); *(item->value) = (char *)list; } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); }
/* * Initialize the static structure to zeros, then * apply all the default values. */ static inline void init_resource(CONFIG *config, int type, RES_ITEM *items, int pass) { memset(config->m_res_all, 0, config->m_res_all_size); res_all.hdr.rcode = type; res_all.hdr.refcnt = 1; /* * Set defaults in each item. We only set defaults in pass 1. */ if (pass == 1) { int i; for (i = 0; items[i].name; i++) { Dmsg3(900, "Item=%s def=%s defval=%s\n", items[i].name, (items[i].flags & ITEM_DEFAULT) ? "yes" : "no", (items[i].default_value) ? items[i].default_value : "None"); /* * Sanity check. * * Items with a default value but without the ITEM_DEFAULT flag set * are most of the time an indication of a programmers error. */ if (items[i].default_value != NULL && !(items[i].flags & ITEM_DEFAULT)) { Pmsg1(000, _("Found config item %s which has default value but no ITEM_DEFAULT flag set\n"), items[i].name); items[i].flags |= ITEM_DEFAULT; } if (items[i].flags & ITEM_DEFAULT && items[i].default_value != NULL) { /* * First try to handle the generic types. */ if (items[i].handler == store_bit) { if (bstrcasecmp(items[i].default_value, "on")) { *(uint32_t *)(items[i].value) |= items[i].code; } else if (bstrcasecmp(items[i].default_value, "off")) { *(uint32_t *)(items[i].value) &= ~(items[i].code); } } else if (items[i].handler == store_bool) { if (bstrcasecmp(items[i].default_value, "yes") || bstrcasecmp(items[i].default_value, "true")) { *(bool *)(items[i].value) = true; } else if (bstrcasecmp(items[i].default_value, "no") || bstrcasecmp(items[i].default_value, "false")) { *(bool *)(items[i].value) = false; } } else if (items[i].handler == store_pint32 || items[i].handler == store_int32 || items[i].handler == store_size32) { *(uint32_t *)(items[i].value) = str_to_int32(items[i].default_value); } else if (items[i].handler == store_int64) { *(int64_t *)(items[i].value) = str_to_int64(items[i].default_value); } else if (items[i].handler == store_size64) { *(uint64_t *)(items[i].value) = str_to_uint64(items[i].default_value); } else if (items[i].handler == store_speed) { *(uint64_t *)(items[i].value) = str_to_uint64(items[i].default_value); } else if (items[i].handler == store_time) { *(utime_t *)(items[i].value) = str_to_int64(items[i].default_value); } else if (items[i].handler == store_strname || items[i].handler == store_str) { *items[i].value = bstrdup(items[i].default_value); } else if (items[i].handler == store_dir) { char pathname[MAXSTRING]; bstrncpy(pathname, items[i].default_value, sizeof(pathname)); if (pathname[0] != '|') { do_shell_expansion(pathname, sizeof(pathname)); } *items[i].value = bstrdup(pathname); } else if (items[i].handler == store_addresses) { init_default_addresses((dlist **)items[i].value, items[i].default_value); } else { /* * None of the generic types fired if there is a registered callback call that now. */ if (config->m_init_res) { config->m_init_res(&items[i]); } } } /* * If this triggers, take a look at lib/parse_conf.h */ if (i >= MAX_RES_ITEMS) { Emsg1(M_ERROR_TERM, 0, _("Too many items in %s resource\n"), resources[type - r_first]); } } } }
/* * Initialize the static structure to zeros, then apply all the default values. */ void CONFIG::init_resource(int type, RES_ITEM *items, int pass) { URES *res_all; memset(m_res_all, 0, m_res_all_size); res_all = ((URES *)m_res_all); res_all->hdr.rcode = type; res_all->hdr.refcnt = 1; /* * See what pass of the config parsing this is. */ switch (pass) { case 1: { /* * Set all defaults for types that are filled in pass 1 of the config parser. */ int i; for (i = 0; items[i].name; i++) { Dmsg3(900, "Item=%s def=%s defval=%s\n", items[i].name, (items[i].flags & CFG_ITEM_DEFAULT) ? "yes" : "no", (items[i].default_value) ? items[i].default_value : "None"); /* * Sanity check. * * Items with a default value but without the CFG_ITEM_DEFAULT flag set * are most of the time an indication of a programmers error. */ if (items[i].default_value != NULL && !(items[i].flags & CFG_ITEM_DEFAULT)) { Pmsg1(000, _("Found config item %s which has default value but no CFG_ITEM_DEFAULT flag set\n"), items[i].name); items[i].flags |= CFG_ITEM_DEFAULT; } /* * See if the CFG_ITEM_DEFAULT flag is set and a default value is available. */ if (items[i].flags & CFG_ITEM_DEFAULT && items[i].default_value != NULL) { /* * First try to handle the generic types. */ switch (items[i].type) { case CFG_TYPE_BIT: if (bstrcasecmp(items[i].default_value, "on")) { set_bit(items[i].code, items[i].bitvalue); } else if (bstrcasecmp(items[i].default_value, "off")) { clear_bit(items[i].code, items[i].bitvalue); } break; case CFG_TYPE_BOOL: if (bstrcasecmp(items[i].default_value, "yes") || bstrcasecmp(items[i].default_value, "true")) { *(items[i].boolvalue) = true; } else if (bstrcasecmp(items[i].default_value, "no") || bstrcasecmp(items[i].default_value, "false")) { *(items[i].boolvalue) = false; } break; case CFG_TYPE_PINT32: case CFG_TYPE_INT32: case CFG_TYPE_SIZE32: *(items[i].ui32value) = str_to_int32(items[i].default_value); break; case CFG_TYPE_INT64: *(items[i].i64value) = str_to_int64(items[i].default_value); break; case CFG_TYPE_SIZE64: *(items[i].ui64value) = str_to_uint64(items[i].default_value); break; case CFG_TYPE_SPEED: *(items[i].ui64value) = str_to_uint64(items[i].default_value); break; case CFG_TYPE_TIME: *(items[i].utimevalue) = str_to_int64(items[i].default_value); break; case CFG_TYPE_STRNAME: case CFG_TYPE_STR: *(items[i].value) = bstrdup(items[i].default_value); break; case CFG_TYPE_DIR: { POOL_MEM pathname(PM_FNAME); pm_strcpy(pathname, items[i].default_value); if (*pathname.c_str() != '|') { int size; /* * Make sure we have enough room */ size = pathname.size() + 1024; pathname.check_size(size); do_shell_expansion(pathname.c_str(), pathname.size()); } *items[i].value = bstrdup(pathname.c_str()); break; } case CFG_TYPE_ADDRESSES: init_default_addresses(items[i].dlistvalue, items[i].default_value); break; default: /* * None of the generic types fired if there is a registered callback call that now. */ if (m_init_res) { m_init_res(&items[i], pass); } break; } if (!m_omit_defaults) { set_bit(i, res_all->hdr.inherit_content); } } /* * If this triggers, take a look at lib/parse_conf.h */ if (i >= MAX_RES_ITEMS) { Emsg1(M_ERROR_TERM, 0, _("Too many items in %s resource\n"), m_resources[type - m_r_first]); } } break; } case 2: { /* * Set all defaults for types that are filled in pass 2 of the config parser. */ int i; for (i = 0; items[i].name; i++) { Dmsg3(900, "Item=%s def=%s defval=%s\n", items[i].name, (items[i].flags & CFG_ITEM_DEFAULT) ? "yes" : "no", (items[i].default_value) ? items[i].default_value : "None"); /* * See if the CFG_ITEM_DEFAULT flag is set and a default value is available. */ if (items[i].flags & CFG_ITEM_DEFAULT && items[i].default_value != NULL) { /* * First try to handle the generic types. */ switch (items[i].type) { case CFG_TYPE_ALIST_STR: if (!*items[i].alistvalue) { *(items[i].alistvalue) = New(alist(10, owned_by_alist)); } (*(items[i].alistvalue))->append(bstrdup(items[i].default_value)); break; case CFG_TYPE_ALIST_DIR: { POOL_MEM pathname(PM_FNAME); if (!*items[i].alistvalue) { *(items[i].alistvalue) = New(alist(10, owned_by_alist)); } pm_strcpy(pathname, items[i].default_value); if (*items[i].default_value != '|') { int size; /* * Make sure we have enough room */ size = pathname.size() + 1024; pathname.check_size(size); do_shell_expansion(pathname.c_str(), pathname.size()); } (*(items[i].alistvalue))->append(bstrdup(pathname.c_str())); break; } default: /* * None of the generic types fired if there is a registered callback call that now. */ if (m_init_res) { m_init_res(&items[i], pass); } break; } if (!m_omit_defaults) { set_bit(i, res_all->hdr.inherit_content); } } /* * If this triggers, take a look at lib/parse_conf.h */ if (i >= MAX_RES_ITEMS) { Emsg1(M_ERROR_TERM, 0, _("Too many items in %s resource\n"), m_resources[type - m_r_first]); } } break; } default: break; } }