]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/fd_plugins.c
update configure
[bacula/bacula] / bacula / src / filed / fd_plugins.c
index d07341cd81ed895a96cae77bd8dcaf4c132e2bd3..a4cd7c0e497422c349137d614066313647631d35 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2010 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -36,6 +36,9 @@
 
 extern CLIENT *me;
 extern DLL_IMP_EXP char *exepath;
+extern DLL_IMP_EXP char *version;
+extern DLL_IMP_EXP char *dist_name;
+extern DLL_IMP_EXP int beef;
 
 const int dbglvl = 150;
 #ifdef HAVE_WIN32
@@ -87,6 +90,7 @@ static ssize_t my_plugin_bread(BFILE *bfd, void *buf, size_t count);
 static ssize_t my_plugin_bwrite(BFILE *bfd, void *buf, size_t count);
 static boffset_t my_plugin_blseek(BFILE *bfd, boffset_t offset, int whence);
 
+#define for_this_plug(plugin, str, len) (((len) == (plugin)->file_len) && strncmp((plugin)->file, str, len) == 0)
 
 /* Bacula info */
 static bInfo binfo = {
@@ -175,11 +179,18 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value)
    case bEventEndVerifyJob:
       call_if_canceled = true;
       break;
+   case bEventStartRestoreJob:
+      if (jcr->plugin) {
+         jcr->plugin->restoreFileStarted = false;
+         jcr->plugin->createFileCalled = false;
+      }
+      break;
    case bEventEndRestoreJob:
       call_if_canceled = true;
       if (jcr->plugin && jcr->plugin->restoreFileStarted) {
          plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx);
          jcr->plugin->restoreFileStarted = false;
+         jcr->plugin->createFileCalled = false;
       }
       break;
    default:
@@ -195,9 +206,12 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value)
 
    Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId);
 
-   /* Pass event to every plugin (except if name is set) */
+   /*
+    * Pass event to every plugin (except if name is set). If name
+    *   is set, we pass it only to the plugin with that name.
+    */
    foreach_alist(plugin, plugin_list) {
-      if (name && strncmp(plugin->file, name, len) != 0) {
+      if (name && !for_this_plug(plugin, name, len)) {
          i++;
          continue;
       }
@@ -254,7 +268,7 @@ bool plugin_check_file(JCR *jcr, char *fname)
 /* Get the first part of the the plugin command
  *  systemstate:/@SYSTEMSTATE/ 
  * => ret = 11
- * => can use strncmp(plugin_name, cmd, ret);
+ * => can use for_this_plug(plug, cmd, ret);
  *
  * The plugin command can contain only the plugin name
  *  Plugin = alldrives
@@ -327,8 +341,8 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
 
    /* Note, we stop the loop on the first plugin that matches the name */
    foreach_alist(plugin, plugin_list) {
-      Dmsg3(dbglvl, "plugin=%s cmd=%s len=%d\n", plugin->file, cmd, len);
-      if (strncmp(plugin->file, cmd, len) != 0) {
+      Dmsg4(dbglvl, "plugin=%s plen=%d cmd=%s len=%d\n", plugin->file, plugin->file_len, cmd, len);
+      if (!for_this_plug(plugin, cmd, len)) {
          i++;
          continue;
       }
@@ -354,6 +368,7 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
          sp.pkt_size = sizeof(sp);
          sp.pkt_end = sizeof(sp);
          sp.portable = true;
+         sp.flags = 0;
          sp.cmd = cmd;
          Dmsg3(dbglvl, "startBackup st_size=%p st_blocks=%p sp=%p\n", &sp.statp.st_size, &sp.statp.st_blocks,
                 &sp);
@@ -395,6 +410,21 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
             pm_strcpy(link, sp.link);
             ff_pkt->fname = fname.c_str();
             ff_pkt->link = link.c_str();
+            ff_pkt->delta_seq = sp.delta_seq;
+            if (sp.flags & FO_DELTA) {
+               ff_pkt->flags |= FO_DELTA;
+               ff_pkt->delta_seq++;          /* make new delta sequence number */
+            } else {
+               ff_pkt->flags &= ~FO_DELTA;   /* clean delta sequence number */
+               ff_pkt->delta_seq = 0;
+            }
+            if (sp.flags & FO_OFFSETS) {
+               ff_pkt->flags |= FO_OFFSETS;
+            }
+            if (sp.flags & FO_PORTABLE_DATA) {
+               ff_pkt->flags |= FO_PORTABLE_DATA;
+            }
+            ff_pkt->flags |= FO_PLUGIN;       /* data from plugin */
          }
 
          memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp));
@@ -412,9 +442,9 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
             continue;
          }
          goto bail_out;
-      }
+      } /* end while loop */
       goto bail_out;
-   }
+   } /* end loop over all plugins */
    Jmsg1(jcr, M_FATAL, 0, "Command plugin \"%s\" not found.\n", cmd);
 
 bail_out:
@@ -458,7 +488,7 @@ bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start)
       stat = sd->fsend("%ld 1 %d %s%c", index, sp->portable, sp->cmd, 0);
    } else {
       /* Send end of data */
-      stat = sd->fsend("0 0");
+      stat = sd->fsend("%ld 0", jcr->JobFiles);
    }
    if (!stat) {
       Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
@@ -507,6 +537,7 @@ bool plugin_name_stream(JCR *jcr, char *name)
       if (jcr->plugin && jcr->plugin->restoreFileStarted) {
          plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx);
          jcr->plugin->restoreFileStarted = false;
+         jcr->plugin->createFileCalled = false;
       }
       jcr->plugin_ctx = NULL;
       jcr->plugin = NULL;
@@ -529,7 +560,7 @@ bool plugin_name_stream(JCR *jcr, char *name)
    foreach_alist(plugin, plugin_list) {
       bEvent event;
       Dmsg3(dbglvl, "plugin=%s cmd=%s len=%d\n", plugin->file, cmd, len);
-      if (strncmp(plugin->file, cmd, len) != 0) {
+      if (!for_this_plug(plugin, cmd, len)) {
          i++;
          continue;
       }
@@ -544,11 +575,12 @@ bool plugin_name_stream(JCR *jcr, char *name)
             &event, cmd) != bRC_OK) {
          goto bail_out;
       }
-      /* ***FIXME**** check error code */
-      if (plugin->restoreFileStarted) {
-         plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx);
+      if (plugin->restoreFileStarted)
+      {
+         Jmsg0(jcr, M_FATAL, 0, "Unbalanced call to startRestoreFile\n");
+         goto bail_out;
       }
-      plug_func(plugin)->startRestoreFile((bpContext *)jcr->plugin_ctx, cmd);
+      plug_func(plugin)->startRestoreFile(jcr->plugin_ctx, cmd);
       plugin->restoreFileStarted = true;
       goto bail_out;
    }
@@ -582,6 +614,7 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
 
    rp.pkt_size = sizeof(rp);
    rp.pkt_end = sizeof(rp);
+   rp.delta_seq = attr->delta_seq;
    rp.stream = attr->stream;
    rp.data_stream = attr->data_stream;
    rp.type = attr->type;
@@ -601,6 +634,11 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
    if (rp.attrEx) {
       Dmsg1(dbglvl, "attrEx=\"%s\"\n", rp.attrEx);
    }
+   if (!plugin->restoreFileStarted || plugin->createFileCalled)
+   {
+      Jmsg0(jcr, M_FATAL, 0, "Unbalanced call to createFile\n");
+      return CF_ERROR;
+   }
    rc = plug_func(plugin)->createFile(plugin_ctx, &rp);
    if (rc != bRC_OK) {
       Qmsg2(jcr, M_ERROR, 0, _("Plugin createFile call failed. Stat=%d file=%s\n"),
@@ -751,7 +789,10 @@ static bool is_plugin_compatible(Plugin *plugin)
            plugin->file, info->plugin_license);
       return false;
    }
-      
+   if (info->size != sizeof(pInfo)) {
+      Jmsg(NULL, M_ERROR, 0, _("Plugin size mismatch.\n"));
+      return false;
+   }
    return true;
 }
 
@@ -898,8 +939,10 @@ static ssize_t my_plugin_bread(BFILE *bfd, void *buf, size_t count)
    io.count = count;
    io.buf = (char *)buf;
    io.win32 = false;
+   io.offset = 0;
    io.lerror = 0;
    plug_func(plugin)->pluginIO(jcr->plugin_ctx, &io);
+   bfd->offset = io.offset;
    bfd->berrno = io.io_errno;
    if (io.win32) {
       errno = b_errno_win32;
@@ -989,6 +1032,15 @@ static bRC baculaGetValue(bpContext *ctx, bVariable var, void *value)
    case bVarExePath:
       *(char **)value = exepath;
       break;
+   case bVarVersion:
+      *(char **)value = version;
+      break;
+   case bVarDistName:
+      *(char **)value = dist_name;
+      break;
+   case bVarBEEF:
+      *((int *)value) = beef;
+      break;
    default:
       break;
    }
@@ -1063,6 +1115,9 @@ static bRC baculaGetValue(bpContext *ctx, bVariable var, void *value)
    case bVarFDName:             /* get warning with g++ if we missed one */
    case bVarWorkingDir:
    case bVarExePath:
+   case bVarVersion:
+   case bVarDistName:
+   case bVarBEEF:
       break;
    }
    return bRC_OK;
@@ -1331,6 +1386,11 @@ static bRC baculaCheckChanges(bpContext *ctx, struct save_pkt *sp)
       ret = bRC_Seen;
    }
 
+   /* check_changes() can update delta sequence number, return it to the
+    * plugin 
+    */
+   sp->delta_seq = ff_pkt->delta_seq;
+
 bail_out:
    Dmsg1(100, "checkChanges=%i\n", ret);
    return ret;