+static bool init_fileset(JCR *jcr)
+{
+ FF_PKT *ff;
+ findFILESET *fileset;
+
+ if (!jcr->ff) {
+ return false;
+ }
+ ff = (FF_PKT *)jcr->ff;
+ if (ff->fileset) {
+ return false;
+ }
+ fileset = (findFILESET *)malloc(sizeof(findFILESET));
+ memset(fileset, 0, sizeof(findFILESET));
+ ff->fileset = fileset;
+ fileset->state = state_none;
+ fileset->include_list.init(1, true);
+ return true;
+}
+
+static findFOPTS *set_options(FF_PKT *ff)
+{
+ int state = ff->fileset->state;
+ findINCEXE *incexe = ff->fileset->incexe;
+
+ if (state != state_options) {
+ ff->fileset->state = state_options;
+ findFOPTS *fo = (findFOPTS *)malloc(sizeof(findFOPTS));
+ memset(fo, 0, sizeof(findFOPTS));
+ fo->regex.init(1, true);
+ fo->wild.init(1, true);
+ fo->base.init(1, true);
+ incexe->current_opts = fo;
+ incexe->opts_list.append(fo);
+ }
+ return incexe->current_opts;
+
+}
+
+
+static void add_fileset(JCR *jcr, const char *item)
+{
+ FF_PKT *ff = (FF_PKT *)jcr->ff;
+ findFILESET *fileset = ff->fileset;
+ int state = fileset->state;
+ findFOPTS *current_opts;
+ int code = item[0];
+ if (item[1] == ' ') { /* If string follows */
+ item += 2; /* point to string */
+ }
+
+ if (state == state_error) {
+ return;
+ }
+ switch (code) {
+ case 'I':
+ /* New include */
+ fileset->incexe = (findINCEXE *)malloc(sizeof(findINCEXE));
+ memset(fileset->incexe, 0, sizeof(findINCEXE));
+ fileset->incexe->opts_list.init(1, true);
+ fileset->incexe->name_list.init(1, true);
+ fileset->include_list.append(fileset->incexe);
+ break;
+ case 'N':
+ state = state_none;
+ break;
+ case 'F':
+ /* File item */
+ state = state_include;
+ fileset->incexe->name_list.append(bstrdup(item));
+ break;
+ case 'R':
+ current_opts = set_options(ff);
+ current_opts->regex.append(bstrdup(item));
+ state = state_options;
+ break;
+ case 'B':
+ current_opts = set_options(ff);
+ current_opts->base.append(bstrdup(item));
+ state = state_options;
+ break;
+ case 'W':
+ current_opts = set_options(ff);
+ current_opts->wild.append(bstrdup(item));
+ state = state_options;
+ break;
+ case 'O':
+ current_opts = set_options(ff);
+ bstrncpy(current_opts->opts, item, MAX_FOPTS);
+ state = state_options;
+ break;
+ default:
+ Jmsg(jcr, M_FATAL, 0, "Invalid FileSet command: %s\n", item);
+ state = state_error;
+ break;
+ }
+ ff->fileset->state = state;
+}
+
+static bool term_fileset(JCR *jcr)
+{
+ FF_PKT *ff = (FF_PKT *)jcr->ff;
+ findFILESET *fileset = ff->fileset;
+ int i, j, k;
+
+ for (i=0; i<fileset->include_list.size(); i++) {
+ findINCEXE *incexe = (findINCEXE *)fileset->include_list.get(i);
+ for (j=0; j<incexe->opts_list.size(); j++) {
+ findFOPTS *fo = (findFOPTS *)incexe->opts_list.get(j);
+ Dmsg1(400, "O %s\n", fo->opts);
+ for (k=0; k<fo->regex.size(); k++) {
+ Dmsg1(400, "R %s\n", (char *)fo->regex.get(k));
+ }
+ for (k=0; k<fo->wild.size(); k++) {
+ Dmsg1(400, "W %s\n", (char *)fo->wild.get(k));
+ }
+ for (k=0; k<fo->base.size(); k++) {
+ Dmsg1(400, "B %s\n", (char *)fo->base.get(k));
+ }
+ }
+ for (j=0; j<incexe->name_list.size(); j++) {
+ Dmsg1(400, "F %s\n", (char *)incexe->name_list.get(j));
+ }
+
+ }
+
+
+ return ff->fileset->state != state_error;
+}
+
+
+
+/*
+ * Director is passing his Fileset
+ */
+static int fileset_cmd(JCR *jcr)