/* * Handle an event that was generated in Bareos */ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) { bRC retval; plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext; if (!p_ctx) { return bRC_Error; } switch (event->eventType) { case bEventLevel: p_ctx->backup_level = (int64_t)value; retval = bRC_OK; break; case bEventRestoreCommand: /* * Fall-through wanted */ case bEventBackupCommand: /* * Fall-through wanted */ case bEventPluginCommand: retval = parse_plugin_definition(ctx, value); break; case bEventNewPluginOptions: /* * Free any previous value. */ if (p_ctx->plugin_options) { free(p_ctx->plugin_options); p_ctx->plugin_options = NULL; } retval = parse_plugin_definition(ctx, value); /* * Save that we got a plugin override. */ p_ctx->plugin_options = bstrdup((char *)value); break; case bEventEndRestoreJob: retval = end_restore_job(ctx, value); break; default: Jmsg(ctx, M_FATAL, "mssqlvdi-fd: unknown event=%d\n", event->eventType); Dmsg(ctx, dbglvl, "mssqlvdi-fd: unknown event=%d\n", event->eventType); retval = bRC_Error; break; } return retval; }
/* * Handle an event that was generated in Bareos */ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) { bRC retval = bRC_OK; struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; if (!p_ctx) { return bRC_Error; } switch (event->eventType) { case bEventJobStart: Dmsg(ctx, dbglvl, "bpipe-fd: JobStart=%s\n", (char *)value); break; case bEventRestoreCommand: /* * Fall-through wanted */ case bEventBackupCommand: /* * Fall-through wanted */ case bEventEstimateCommand: /* * Fall-through wanted */ case bEventPluginCommand: retval = parse_plugin_definition(ctx, value); break; case bEventNewPluginOptions: /* * Free any previous value. */ if (p_ctx->plugin_options) { free(p_ctx->plugin_options); p_ctx->plugin_options = NULL; } retval = parse_plugin_definition(ctx, value); /* * Save that we got a plugin override. */ p_ctx->plugin_options = bstrdup((char *)value); break; default: Jmsg(ctx, M_FATAL, "bpipe-fd: unknown event=%d\n", event->eventType); Dmsg(ctx, dbglvl, "bpipe-fd: unknown event=%d\n", event->eventType); retval = bRC_Error; break; } return retval; }
/* * Handle an event that was generated in Bareos */ static bRC handlePluginEvent(bpContext *ctx, bsdEvent *event, void *value) { bRC retval = bRC_Error; bool event_dispatched = false; POOL_MEM plugin_options(PM_FNAME); plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext; if (!p_ctx) { goto bail_out; } /* * First handle some events internally before calling python if it * want to do some special handling on the event triggered. */ switch (event->eventType) { case bsdEventNewPluginOptions: event_dispatched = true; retval = parse_plugin_definition(ctx, value, plugin_options); break; default: break; } /* * See if we have been triggered in the previous switch if not we have to * always dispatch the event. If we already processed the event internally * we only do a dispatch to the python entry point when that internal processing * was successfull (e.g. retval == bRC_OK). */ if (!event_dispatched || retval == bRC_OK) { PyEval_AcquireThread(p_ctx->interpreter); /* * Now dispatch the event to Python. * First the calls that need special handling. */ switch (event->eventType) { case bsdEventNewPluginOptions: /* * See if we already loaded the Python modules. */ if (!p_ctx->python_loaded) { retval = PyLoadModule(ctx, plugin_options.c_str()); } /* * Only try to call when the loading succeeded. */ if (retval == bRC_OK) { retval = PyParsePluginDefinition(ctx, plugin_options.c_str()); } break; default: /* * Handle the generic events e.g. the ones which are just passed on. * We only try to call Python when we loaded the right module until * that time we pretend the call succeeded. */ if (p_ctx->python_loaded) { retval = PyHandlePluginEvent(ctx, event, value); } else { retval = bRC_OK; } break; } PyEval_ReleaseThread(p_ctx->interpreter); } bail_out: return retval; }