+static bool is_ctx_good(bpContext *ctx, JCR *&jcr, bacula_ctx *&bctx)
+{
+ if (!ctx) {
+ return false;
+ }
+ bctx = (bacula_ctx *)ctx->bContext;
+ if (!bctx) {
+ return false;
+ }
+ jcr = bctx->jcr;
+ if (!jcr) {
+ return false;
+ }
+ return true;
+}
+
+/**
+ * Let the plugin define files/directories to be excluded
+ * from the main backup.
+ */
+static bRC baculaAddExclude(bpContext *ctx, const char *file)
+{
+ JCR *jcr;
+ bacula_ctx *bctx;
+ if (!is_ctx_good(ctx, jcr, bctx)) {
+ return bRC_Error;
+ }
+ if (!file) {
+ return bRC_Error;
+ }
+ if (!bctx->exclude) {
+ bctx->exclude = new_exclude(jcr);
+ new_options(jcr, bctx->exclude);
+ }
+ set_incexe(jcr, bctx->exclude);
+ add_file_to_fileset(jcr, file, true);
+ Dmsg1(100, "Add exclude file=%s\n", file);
+ return bRC_OK;
+}
+
+/**
+ * Let the plugin define files/directories to be excluded
+ * from the main backup.
+ */
+static bRC baculaAddInclude(bpContext *ctx, const char *file)
+{
+ JCR *jcr;
+ bacula_ctx *bctx;
+ if (!is_ctx_good(ctx, jcr, bctx)) {
+ return bRC_Error;
+ }
+ if (!file) {
+ return bRC_Error;
+ }
+ if (!bctx->include) {
+ bctx->include = new_preinclude(jcr);
+ new_options(jcr, bctx->include);
+ }
+ set_incexe(jcr, bctx->include);
+ add_file_to_fileset(jcr, file, true);
+ Dmsg1(100, "Add include file=%s\n", file);
+ return bRC_OK;
+}
+
+static bRC baculaAddOptions(bpContext *ctx, const char *opts)
+{
+ JCR *jcr;
+ bacula_ctx *bctx;
+ if (!is_ctx_good(ctx, jcr, bctx)) {
+ return bRC_Error;
+ }
+ if (!opts) {
+ return bRC_Error;
+ }
+ add_options_to_fileset(jcr, opts);
+ Dmsg1(1000, "Add options=%s\n", opts);
+ return bRC_OK;
+}
+
+static bRC baculaAddRegex(bpContext *ctx, const char *item, int type)
+{
+ JCR *jcr;
+ bacula_ctx *bctx;
+ if (!is_ctx_good(ctx, jcr, bctx)) {
+ return bRC_Error;
+ }
+ if (!item) {
+ return bRC_Error;
+ }
+ add_regex_to_fileset(jcr, item, type);
+ Dmsg1(100, "Add regex=%s\n", item);
+ return bRC_OK;
+}
+
+static bRC baculaAddWild(bpContext *ctx, const char *item, int type)
+{
+ JCR *jcr;
+ bacula_ctx *bctx;
+ if (!is_ctx_good(ctx, jcr, bctx)) {
+ return bRC_Error;
+ }
+ if (!item) {
+ return bRC_Error;
+ }
+ add_wild_to_fileset(jcr, item, type);
+ Dmsg1(100, "Add wild=%s\n", item);
+ return bRC_OK;
+}
+
+static bRC baculaNewOptions(bpContext *ctx)
+{
+ JCR *jcr;
+ bacula_ctx *bctx;
+ if (!is_ctx_good(ctx, jcr, bctx)) {
+ return bRC_Error;
+ }
+ (void)new_options(jcr, NULL);
+ return bRC_OK;
+}
+
+static bRC baculaNewInclude(bpContext *ctx)
+{
+ JCR *jcr;
+ bacula_ctx *bctx;
+ if (!is_ctx_good(ctx, jcr, bctx)) {
+ return bRC_Error;
+ }
+ (void)new_include(jcr);
+ return bRC_OK;
+}
+
+
+/*
+ * Check if a file have to be backuped using Accurate code
+ */
+static bRC baculaCheckChanges(bpContext *ctx, struct save_pkt *sp)
+{
+ JCR *jcr;
+ bacula_ctx *bctx;
+ FF_PKT *ff_pkt;
+ bRC ret = bRC_Error;
+
+ if (!is_ctx_good(ctx, jcr, bctx)) {
+ goto bail_out;
+ }
+ if (!sp) {
+ goto bail_out;
+ }
+
+ ff_pkt = jcr->ff;
+ /*
+ * Copy fname and link because save_file() zaps them. This
+ * avoids zaping the plugin's strings.
+ */
+ ff_pkt->type = sp->type;
+ if (!sp->fname) {
+ Jmsg0(jcr, M_FATAL, 0, _("Command plugin: no fname in baculaCheckChanges packet.\n"));
+ goto bail_out;
+ }
+
+ ff_pkt->fname = sp->fname;
+ ff_pkt->link = sp->link;
+ memcpy(&ff_pkt->statp, &sp->statp, sizeof(ff_pkt->statp));
+
+ if (check_changes(jcr, ff_pkt)) {
+ ret = bRC_OK;
+ } else {
+ ret = bRC_Seen;
+ }
+
+bail_out:
+ Dmsg1(100, "checkChanges=%i\n", ret);
+ return ret;
+}