/* * Store a resource pointer in an alist. default_value indicates how many * times this routine can be called -- i.e. how many alists * there are. * * If we are in pass 2, do a lookup of the resource. */ static void store_alist_res(LEX *lc, RES_ITEM *item, int index, int pass) { RES *res; int i = 0; alist *list; URES *res_all = (URES *)my_config->m_res_all; int count = str_to_int32(item->default_value); if (pass == 2) { if (count == 0) { /* always store in item->value */ i = 0; if ((item->value)[i] == NULL) { list = New(alist(10, not_owned_by_alist)); } else { list = (alist *)(item->value)[i]; } } else { /* * Find empty place to store this directive */ while ((item->value)[i] != NULL && i++ < count) { } if (i >= count) { scan_err4(lc, _("Too many %s directives. Max. is %d. line %d: %s\n"), lc->str, count, lc->line_no, lc->line); return; } list = New(alist(10, not_owned_by_alist)); } for (;;) { lex_get_token(lc, T_NAME); /* scan next item */ res = GetResWithName(item->code, lc->str); if (res == NULL) { scan_err3(lc, _("Could not find config Resource \"%s\" referenced on line %d : %s\n"), item->name, lc->line_no, lc->line); return; } Dmsg5(900, "Append %p to alist %p size=%d i=%d %s\n", res, list, list->size(), i, item->name); list->append(res); (item->value)[i] = (char *)list; if (lc->ch != ',') { /* if no other item follows */ break; /* get out */ } lex_get_token(lc, T_ALL); /* eat comma */ } } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); }
/* Store a bool in a bit field */ void store_bool(LEX *lc, RES_ITEM *item, int index, int pass) { lex_get_token(lc, T_NAME); if (strcasecmp(lc->str, "yes") == 0 || strcasecmp(lc->str, "true") == 0) { *(bool *)(item->value) = true; } else if (strcasecmp(lc->str, "no") == 0 || strcasecmp(lc->str, "false") == 0) { *(bool *)(item->value) = false; } else { scan_err2(lc, _("Expect %s, got: %s"), "YES, NO, TRUE, or FALSE", lc->str); /* YES and NO must not be translated */ return; } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); }
/* * Store a string at specified address */ void store_str(LEX *lc, RES_ITEM *item, int index, int pass) { lex_get_token(lc, T_STRING); if (pass == 1) { /* * If a default was set free it first. */ if (*(item->value)) { free(*(item->value)); } *(item->value) = bstrdup(lc->str); } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); }
/* * Store a bool in a bit field */ static void store_bool(LEX *lc, RES_ITEM *item, int index, int pass) { URES *res_all = (URES *)my_config->m_res_all; lex_get_token(lc, T_NAME); if (bstrcasecmp(lc->str, "yes") || bstrcasecmp(lc->str, "true")) { *item->boolvalue = true; } else if (bstrcasecmp(lc->str, "no") || bstrcasecmp(lc->str, "false")) { *(item->boolvalue) = false; } else { scan_err2(lc, _("Expect %s, got: %s"), "YES, NO, TRUE, or FALSE", lc->str); /* YES and NO must not be translated */ return; } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); }
/* * Store default values for Resource from xxxDefs * If we are in pass 2, do a lookup of the * resource and store everything not explicitly set * in main resource. * * Note, here item points to the main resource (e.g. Job, not * the jobdefs, which we look up). */ void store_defs(LEX *lc, RES_ITEM *item, int index, int pass) { RES *res; lex_get_token(lc, T_NAME); if (pass == 2) { Dmsg2(900, "Code=%d name=%s\n", item->code, lc->str); res = GetResWithName(item->code, lc->str); if (res == NULL) { scan_err3(lc, _("Missing config Resource \"%s\" referenced on line %d : %s\n"), lc->str, lc->line_no, lc->line); return; } } scan_to_eol(lc); }
/* ---------------------------------------------------------------- * Handle data type. Import/Export * ---------------------------------------------------------------- */ bool ini_store_str(LEX *lc, ConfigFile *inifile, ini_items *item) { if (!lc) { Mmsg(inifile->edit, "%s", item->val.strval); return true; } if (lex_get_token(lc, T_STRING) == T_ERROR) { return false; } /* If already allocated, free first */ if (item->found && item->val.strval) { free(item->val.strval); } item->val.strval = bstrdup(lc->str); scan_to_eol(lc); return true; }
static BSR *store_slot(LEX *lc, BSR *bsr) { int token; token = lex_get_token(lc, T_PINT32); if (token == T_ERROR) { return NULL; } if (!bsr->volume) { Emsg1(M_ERROR,0, _("Slot %d in bsr at inappropriate place.\n"), lc->pint32_val); return bsr; } bsr->volume->Slot = lc->pint32_val; scan_to_eol(lc); return bsr; }
/* Store regex info */ static void store_regex(LEX *lc, RES_ITEM *item, int index, int pass) { int token, rc; regex_t preg; char prbuf[500]; const char *type; int newsize; token = lex_get_token(lc, T_SKIP_EOL); if (pass == 1) { /* Pickup regex string */ switch (token) { case T_IDENTIFIER: case T_UNQUOTED_STRING: case T_QUOTED_STRING: rc = regcomp(&preg, lc->str, REG_EXTENDED); if (rc != 0) { regerror(rc, &preg, prbuf, sizeof(prbuf)); regfree(&preg); scan_err1(lc, _("Regex compile error. ERR=%s\n"), prbuf); break; } regfree(&preg); if (item->code == 1) { type = "regexdir"; res_incexe.current_opts->regexdir.append(bstrdup(lc->str)); newsize = res_incexe.current_opts->regexdir.size(); } else if (item->code == 2) { type = "regexfile"; res_incexe.current_opts->regexfile.append(bstrdup(lc->str)); newsize = res_incexe.current_opts->regexfile.size(); } else { type = "regex"; res_incexe.current_opts->regex.append(bstrdup(lc->str)); newsize = res_incexe.current_opts->regex.size(); } Dmsg4(900, "set %s %p size=%d %s\n", type, res_incexe.current_opts, newsize, lc->str); break; default: scan_err1(lc, _("Expected a regex string, got: %s\n"), lc->str); } } scan_to_eol(lc); }
/* * Store a password at specified address in MD5 coding */ static void store_clearpassword(LEX *lc, RES_ITEM *item, int index, int pass) { s_password *pwd; URES *res_all = (URES *)my_config->m_res_all; lex_get_token(lc, T_STRING); if (pass == 1) { pwd = item->pwdvalue; if (pwd->value) { free(pwd->value); } pwd->encoding = p_encoding_clear; pwd->value = bstrdup(lc->str); } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); }
/* Store Wild-card info */ static void store_wild(LEX *lc, RES_ITEM *item, int index, int pass) { int token; const char *type; int newsize; token = lex_get_token(lc, T_SKIP_EOL); if (pass == 1) { /* * Pickup Wild-card string */ switch (token) { case T_IDENTIFIER: case T_UNQUOTED_STRING: case T_QUOTED_STRING: if (item->code == 1) { type = "wilddir"; res_incexe.current_opts->wilddir.append(bstrdup(lc->str)); newsize = res_incexe.current_opts->wilddir.size(); } else if (item->code == 2) { if (strpbrk(lc->str, "/\\") != NULL) { type = "wildfile"; res_incexe.current_opts->wildfile.append(bstrdup(lc->str)); newsize = res_incexe.current_opts->wildfile.size(); } else { type = "wildbase"; res_incexe.current_opts->wildbase.append(bstrdup(lc->str)); newsize = res_incexe.current_opts->wildbase.size(); } } else { type = "wild"; res_incexe.current_opts->wild.append(bstrdup(lc->str)); newsize = res_incexe.current_opts->wild.size(); } Dmsg4(9, "set %s %p size=%d %s\n", type, res_incexe.current_opts, newsize, lc->str); break; default: scan_err1(lc, _("Expected a wild-card string, got: %s\n"), lc->str); } } scan_to_eol(lc); }
/* * This routine is ONLY for resource names * Store a name at specified address. */ void store_name(LEX *lc, RES_ITEM *item, int index, int pass) { POOLMEM *msg = get_pool_memory(PM_EMSG); lex_get_token(lc, T_NAME); if (!is_name_valid(lc->str, &msg)) { scan_err1(lc, "%s\n", msg); return; } free_pool_memory(msg); /* Store the name both pass 1 and pass 2 */ if (*(item->value)) { scan_err2(lc, _("Attempt to redefine name \"%s\" to \"%s\"."), *(item->value), lc->str); return; } *(item->value) = bstrdup(lc->str); scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); }
/* * Store a time period in seconds */ static void store_time(LEX *lc, RES_ITEM *item, int index, int pass) { int token; utime_t utime; char period[500]; URES *res_all = (URES *)my_config->m_res_all; token = lex_get_token(lc, T_SKIP_EOL); errno = 0; switch (token) { case T_NUMBER: case T_IDENTIFIER: case T_UNQUOTED_STRING: bstrncpy(period, lc->str, sizeof(period)); /* get first part */ /* * If terminated by space, scan and get modifier */ while (lc->ch == ' ') { token = lex_get_token(lc, T_ALL); switch (token) { case T_NUMBER: case T_IDENTIFIER: case T_UNQUOTED_STRING: bstrncat(period, lc->str, sizeof(period)); break; } } if (!duration_to_utime(period, &utime)) { scan_err1(lc, _("expected a time period, got: %s"), period); return; } *(item->utimevalue) = utime; break; default: scan_err1(lc, _("expected a time period, got: %s"), lc->str); return; } if (token != T_EOL) { scan_to_eol(lc); } set_bit(index, res_all->hdr.item_present); }
/* * Store a name string at specified address * A name string is limited to MAX_RES_NAME_LENGTH */ static void store_strname(LEX *lc, RES_ITEM *item, int index, int pass) { URES *res_all = (URES *)my_config->m_res_all; /* * Store the name */ lex_get_token(lc, T_NAME); if (pass == 1) { /* * If a default was set free it first. */ if (*(item->value)) { free(*(item->value)); } *(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 Tape Label Type (Bacula, ANSI, IBM) * */ void store_label(LEX *lc, RES_ITEM *item, int index, int pass) { int token, i; token = lex_get_token(lc, T_NAME); /* Store the label pass 2 so that type is defined */ for (i=0; tapelabels[i].name; i++) { if (strcasecmp(lc->str, tapelabels[i].name) == 0) { *(uint32_t *)(item->value) = tapelabels[i].token; i = 0; break; } } if (i != 0) { scan_err1(lc, _("Expected a Tape Label keyword, got: %s"), lc->str); return; } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); }
/* * Store a string in an alist. */ void store_alist_str(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); list->append(bstrdup(lc->str)); *(item->value) = (char *)list; } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); }
/* Store a size in bytes */ void store_size(LEX *lc, RES_ITEM *item, int index, int pass) { int token; uint64_t uvalue; char bsize[500]; Dmsg0(900, "Enter store_size\n"); token = lex_get_token(lc, T_SKIP_EOL); errno = 0; switch (token) { case T_NUMBER: case T_IDENTIFIER: case T_UNQUOTED_STRING: bstrncpy(bsize, lc->str, sizeof(bsize)); /* save first part */ /* if terminated by space, scan and get modifier */ while (lc->ch == ' ') { token = lex_get_token(lc, T_ALL); switch (token) { case T_NUMBER: case T_IDENTIFIER: case T_UNQUOTED_STRING: bstrncat(bsize, lc->str, sizeof(bsize)); break; } } if (!size_to_uint64(bsize, strlen(bsize), &uvalue)) { scan_err1(lc, _("expected a size number, got: %s"), lc->str); return; } *(uint64_t *)(item->value) = uvalue; break; default: scan_err1(lc, _("expected a size, got: %s"), lc->str); return; } if (token != T_EOL) { scan_to_eol(lc); } set_bit(index, res_all.hdr.item_present); Dmsg0(900, "Leave store_size\n"); }
bool ini_store_bool(LEX *lc, ConfigFile *inifile, ini_items *item) { if (!lc) { Mmsg(inifile->edit, "%s", item->val.boolval?"yes":"no"); return true; } if (lex_get_token(lc, T_NAME) == T_ERROR) { return false; } if (strcasecmp(lc->str, "yes") == 0 || strcasecmp(lc->str, "true") == 0) { item->val.boolval = true; } else if (strcasecmp(lc->str, "no") == 0 || strcasecmp(lc->str, "false") == 0) { item->val.boolval = false; } else { /* YES and NO must not be translated */ scan_err2(lc, _("Expect %s, got: %s"), "YES, NO, TRUE, or FALSE", lc->str); return false; } scan_to_eol(lc); return true; }
static void store_meta(LEX *lc, RES_ITEM *item, int index, int pass) { int token; token = lex_get_token(lc, T_SKIP_EOL); if (pass == 1) { /* Pickup fstype string */ switch (token) { case T_IDENTIFIER: case T_UNQUOTED_STRING: case T_QUOTED_STRING: res_incexe.current_opts->meta.append(bstrdup(lc->str)); Dmsg3(900, "set meta %p size=%d %s\n", res_incexe.current_opts, res_incexe.current_opts->meta.size(), lc->str); break; default: scan_err1(lc, _("Expected a meta string, got: %s\n"), lc->str); } } scan_to_eol(lc); }
/* Store a password specified address in MD5 coding */ void store_password(LEX *lc, RES_ITEM *item, int index, int pass) { unsigned int i, j; struct MD5Context md5c; unsigned char digest[CRYPTO_DIGEST_MD5_SIZE]; char sig[100]; lex_get_token(lc, T_STRING); if (pass == 1) { MD5Init(&md5c); MD5Update(&md5c, (unsigned char *) (lc->str), lc->str_len); MD5Final(digest, &md5c); for (i = j = 0; i < sizeof(digest); i++) { sprintf(&sig[j], "%02x", digest[i]); j += 2; } *(item->value) = bstrdup(sig); } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); }
/* * Store a password at specified address in MD5 coding */ static void store_md5password(LEX *lc, RES_ITEM *item, int index, int pass) { s_password *pwd; URES *res_all = (URES *)my_config->m_res_all; lex_get_token(lc, T_STRING); if (pass == 1) { pwd = item->pwdvalue; if (pwd->value) { free(pwd->value); } /* * See if we are parsing an MD5 encoded password already. */ if (bstrncmp(lc->str, "[md5]", 5)) { pwd->encoding = p_encoding_md5; pwd->value = bstrdup(lc->str + 5); } else { unsigned int i, j; struct MD5Context md5c; unsigned char digest[CRYPTO_DIGEST_MD5_SIZE]; char sig[100]; MD5Init(&md5c); MD5Update(&md5c, (unsigned char *) (lc->str), lc->str_len); MD5Final(digest, &md5c); for (i = j = 0; i < sizeof(digest); i++) { sprintf(&sig[j], "%02x", digest[i]); j += 2; } pwd->encoding = p_encoding_md5; pwd->value = bstrdup(sig); } } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); }
/* Store a resource at specified address. * If we are in pass 2, do a lookup of the * resource. */ void store_res(LEX *lc, RES_ITEM *item, int index, int pass) { RES *res; lex_get_token(lc, T_NAME); if (pass == 2) { res = GetResWithName(item->code, lc->str); if (res == NULL) { scan_err3(lc, _("Could not find config Resource %s referenced on line %d : %s\n"), lc->str, lc->line_no, lc->line); return; } if (*(item->value)) { scan_err3(lc, _("Attempt to redefine resource \"%s\" referenced on line %d : %s\n"), item->name, lc->line_no, lc->line); return; } *(item->value) = (char *)res; } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); }
/* * Store Filename info. Note, for minor efficiency reasons, we * always increase the name buffer by 10 items because we expect * to add more entries. */ static void store_plugin_name(LEX *lc, RES_ITEM2 *item, int index, int pass, bool exclude) { int token; INCEXE *incexe; if (exclude) { scan_err0(lc, _("Plugin directive not permitted in Exclude\n")); /* NOT REACHED */ } token = lex_get_token(lc, T_SKIP_EOL); if (pass == 1) { /* Pickup Filename string */ switch (token) { case T_IDENTIFIER: case T_UNQUOTED_STRING: if (strchr(lc->str, '\\')) { scan_err1(lc, _("Backslash found. Use forward slashes or quote the string.: %s\n"), lc->str); /* NOT REACHED */ } case T_QUOTED_STRING: if (res_all.res_fs.have_MD5) { MD5Update(&res_all.res_fs.md5c, (unsigned char *)lc->str, lc->str_len); } incexe = &res_incexe; if (incexe->plugin_list.size() == 0) { incexe->plugin_list.init(10, true); } incexe->plugin_list.append(bstrdup(lc->str)); Dmsg1(900, "Add to plugin_list %s\n", lc->str); break; default: scan_err1(lc, _("Expected a filename, got: %s"), lc->str); /* NOT REACHED */ } } scan_to_eol(lc); }
/* * Store Tape Label Type (BAREOS, ANSI, IBM) */ static void store_label(LEX *lc, RES_ITEM *item, int index, int pass) { int i; URES *res_all = (URES *)my_config->m_res_all; lex_get_token(lc, T_NAME); /* * Store the label pass 2 so that type is defined */ for (i = 0; tapelabels[i].name; i++) { if (bstrcasecmp(lc->str, tapelabels[i].name)) { *(item->ui32value) = tapelabels[i].token; i = 0; break; } } if (i != 0) { scan_err1(lc, _("Expected a Tape Label keyword, got: %s"), lc->str); return; } 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). */ static void store_alist_dir(LEX *lc, RES_ITEM *item, int index, int pass) { alist *list; URES *res_all = (URES *)my_config->m_res_all; 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_pool_memory(lc->str)); } list->append(bstrdup(lc->str)); *(item->value) = (char *)list; } scan_to_eol(lc); set_bit(index, res_all->hdr.item_present); }
static BSR *store_exclude(LEX *lc, BSR *bsr) { scan_to_eol(lc); return bsr; }
/* * Store new style FileSet Include/Exclude info * * Note, when this routine is called, we are inside a FileSet * resource. We treat the Include/Execlude like a sort of * mini-resource within the FileSet resource. */ static void store_newinc(LEX *lc, RES_ITEM *item, int index, int pass) { int token, i; INCEXE *incexe; bool options; if (!res_all.res_fs.have_MD5) { MD5Init(&res_all.res_fs.md5c); res_all.res_fs.have_MD5 = true; } memset(&res_incexe, 0, sizeof(INCEXE)); res_all.res_fs.new_include = true; while ((token = lex_get_token(lc, T_SKIP_EOL)) != T_EOF) { if (token == T_EOB) { break; } if (token != T_IDENTIFIER) { scan_err1(lc, _("Expecting keyword, got: %s\n"), lc->str); } for (i=0; newinc_items[i].name; i++) { options = bstrcasecmp(lc->str, "options"); if (bstrcasecmp(newinc_items[i].name, lc->str)) { if (!options) { token = lex_get_token(lc, T_SKIP_EOL); if (token != T_EQUALS) { scan_err1(lc, _("expected an equals, got: %s"), lc->str); } } /* Call item handler */ newinc_items[i].handler(lc, &newinc_items[i], i, pass, item->code); i = -1; break; } } if (i >=0) { scan_err1(lc, _("Keyword %s not permitted in this resource"), lc->str); } } if (pass == 1) { incexe = (INCEXE *)malloc(sizeof(INCEXE)); memcpy(incexe, &res_incexe, sizeof(INCEXE)); memset(&res_incexe, 0, sizeof(INCEXE)); if (item->code == 0) { /* include */ if (res_all.res_fs.num_includes == 0) { res_all.res_fs.include_items = (INCEXE **)malloc(sizeof(INCEXE *)); } else { res_all.res_fs.include_items = (INCEXE **)realloc(res_all.res_fs.include_items, sizeof(INCEXE *) * (res_all.res_fs.num_includes + 1)); } res_all.res_fs.include_items[res_all.res_fs.num_includes++] = incexe; Dmsg1(900, "num_includes=%d\n", res_all.res_fs.num_includes); } else { /* exclude */ if (res_all.res_fs.num_excludes == 0) { res_all.res_fs.exclude_items = (INCEXE **)malloc(sizeof(INCEXE *)); } else { res_all.res_fs.exclude_items = (INCEXE **)realloc(res_all.res_fs.exclude_items, sizeof(INCEXE *) * (res_all.res_fs.num_excludes + 1)); } res_all.res_fs.exclude_items[res_all.res_fs.num_excludes++] = incexe; Dmsg1(900, "num_excludes=%d\n", res_all.res_fs.num_excludes); } } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); }
/* * Store a size in bytes */ static void store_int_unit(LEX *lc, RES_ITEM *item, int index, int pass, bool size32, enum store_unit_type type) { int token; uint64_t uvalue; char bsize[500]; Dmsg0(900, "Enter store_unit\n"); token = lex_get_token(lc, T_SKIP_EOL); errno = 0; switch (token) { case T_NUMBER: case T_IDENTIFIER: case T_UNQUOTED_STRING: bstrncpy(bsize, lc->str, sizeof(bsize)); /* save first part */ /* * If terminated by space, scan and get modifier */ while (lc->ch == ' ') { token = lex_get_token(lc, T_ALL); switch (token) { case T_NUMBER: case T_IDENTIFIER: case T_UNQUOTED_STRING: bstrncat(bsize, lc->str, sizeof(bsize)); break; } } switch (type) { case STORE_SIZE: if (!size_to_uint64(bsize, &uvalue)) { scan_err1(lc, _("expected a size number, got: %s"), lc->str); return; } break; case STORE_SPEED: if (!speed_to_uint64(bsize, &uvalue)) { scan_err1(lc, _("expected a speed number, got: %s"), lc->str); return; } break; default: scan_err0(lc, _("unknown unit type encountered")); return; } if (size32) { *(uint32_t *)(item->value) = (uint32_t)uvalue; } else { *(uint64_t *)(item->value) = uvalue; } break; default: scan_err2(lc, _("expected a %s, got: %s"), (type == STORE_SIZE)?_("size"):_("speed"), lc->str); return; } if (token != T_EOL) { scan_to_eol(lc); } set_bit(index, res_all.hdr.item_present); Dmsg0(900, "Leave store_unit\n"); }
/* * Analyse the content of a ini file to build the item list * It uses special syntax for datatype. Used by Director on Restore object * * OptPrompt = "Variable1" * OptRequired * OptDefault = 100 * Variable1 = @PINT32@ * ... */ bool ConfigFile::unserialize(const char *fname) { int token, i, nb = 0; bool ret = false; const char **assign; /* * At this time, we allow only 32 different items */ int s = MAX_INI_ITEMS * sizeof (struct ini_items); items = (struct ini_items *) malloc (s); memset(items, 0, s); items_allocated = true; /* * Parse the file and generate the items structure on the fly */ if ((lc = lex_open_file(lc, fname, s_err, s_warn)) == NULL) { berrno be; Emsg2(M_ERROR, 0, _("Cannot open config file %s: %s\n"), fname, be.bstrerror()); return false; } lc->options |= LOPT_NO_EXTERN; lc->caller_ctx = (void *)this; while ((token=lex_get_token(lc, T_ALL)) != T_EOF) { Dmsg1(dbglevel, "parse got token=%s\n", lex_tok_to_str(token)); if (token == T_EOL) { continue; } ret = false; assign = NULL; if (nb >= MAX_INI_ITEMS) { break; } if (bstrcasecmp("optprompt", lc->str)) { assign = &(items[nb].comment); } else if (bstrcasecmp("optdefault", lc->str)) { assign = &(items[nb].default_value); } else if (bstrcasecmp("optrequired", lc->str)) { items[nb].required = true; /* Don't use argument */ scan_to_eol(lc); continue; } else { items[nb].name = bstrdup(lc->str); } token = lex_get_token(lc, T_ALL); Dmsg1(dbglevel, "in T_IDENT got token=%s\n", lex_tok_to_str(token)); if (token != T_EQUALS) { scan_err1(lc, "expected an equals, got: %s", lc->str); break; } /* * We may allow blank variable */ if (lex_get_token(lc, T_STRING) == T_ERROR) { break; } if (assign) { *assign = bstrdup(lc->str); } else { if ((items[nb].type = ini_get_store_type(lc->str)) == 0) { scan_err1(lc, "expected a data type, got: %s", lc->str); break; } nb++; } scan_to_eol(lc); ret = true; } if (!ret) { for (i = 0; i < nb; i++) { bfree_and_null_const(items[i].name); bfree_and_null_const(items[i].comment); bfree_and_null_const(items[i].default_value); items[i].type = 0; items[i].required = false; } } lc = lex_close_file(lc); return ret; }
/* Store Messages Destination information */ void store_msgs(LEX *lc, RES_ITEM *item, int index, int pass) { int token; char *cmd; POOLMEM *dest; int dest_len; Dmsg2(900, "store_msgs pass=%d code=%d\n", pass, item->code); if (pass == 1) { switch (item->code) { case MD_STDOUT: case MD_STDERR: case MD_SYSLOG: /* syslog */ case MD_CONSOLE: case MD_CATALOG: scan_types(lc, (MSGS *)(item->value), item->code, NULL, NULL); break; case MD_OPERATOR: /* send to operator */ case MD_DIRECTOR: /* send to Director */ case MD_MAIL: /* mail */ case MD_MAIL_ON_ERROR: /* mail if Job errors */ case MD_MAIL_ON_SUCCESS: /* mail if Job succeeds */ if (item->code == MD_OPERATOR) { cmd = res_all.res_msgs.operator_cmd; } else { cmd = res_all.res_msgs.mail_cmd; } dest = get_pool_memory(PM_MESSAGE); dest[0] = 0; dest_len = 0; /* Pick up comma separated list of destinations */ for ( ;; ) { token = lex_get_token(lc, T_NAME); /* scan destination */ dest = check_pool_memory_size(dest, dest_len + lc->str_len + 2); if (dest[0] != 0) { pm_strcat(dest, " "); /* separate multiple destinations with space */ dest_len++; } pm_strcat(dest, lc->str); dest_len += lc->str_len; Dmsg2(900, "store_msgs newdest=%s: dest=%s:\n", lc->str, NPRT(dest)); token = lex_get_token(lc, T_SKIP_EOL); if (token == T_COMMA) { continue; /* get another destination */ } if (token != T_EQUALS) { scan_err1(lc, _("expected an =, got: %s"), lc->str); return; } break; } Dmsg1(900, "mail_cmd=%s\n", NPRT(cmd)); scan_types(lc, (MSGS *)(item->value), item->code, dest, cmd); free_pool_memory(dest); Dmsg0(900, "done with dest codes\n"); break; case MD_FILE: /* file */ case MD_APPEND: /* append */ dest = get_pool_memory(PM_MESSAGE); /* Pick up a single destination */ token = lex_get_token(lc, T_NAME); /* scan destination */ pm_strcpy(dest, lc->str); dest_len = lc->str_len; token = lex_get_token(lc, T_SKIP_EOL); Dmsg1(900, "store_msgs dest=%s:\n", NPRT(dest)); if (token != T_EQUALS) { scan_err1(lc, _("expected an =, got: %s"), lc->str); return; } scan_types(lc, (MSGS *)(item->value), item->code, dest, NULL); free_pool_memory(dest); Dmsg0(900, "done with dest codes\n"); break; default: scan_err1(lc, _("Unknown item code: %d\n"), item->code); return; } } scan_to_eol(lc); set_bit(index, res_all.hdr.item_present); Dmsg0(900, "Done store_msgs\n"); }