static bRC createFile(bpContext *ctx, struct restore_pkt *rp);
static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp);
+static char *apply_rp_codes(struct plugin_ctx * p_ctx);
/* Pointers to Bacula functions */
static bFuncs *bfuncs = NULL;
return bRC_OK;
}
-/*
- * Apply codes in writer command:
- * %w -> "where"
- * %r -> "replace"
- *
- * Replace:
- * 'always' => 'a', chr(97)
- * 'ifnewer' => 'w', chr(119)
- * 'ifolder' => 'o', chr(111)
- * 'never' => 'n', chr(110)
- *
- * This function will allocate the required amount of memory with malloc.
- * Need to be free()d manually.
- * Inspired by edit_job_codes in lib/util.c
- */
-
-char *apply_rp_codes(struct plugin_ctx * p_ctx)
-{
- char *p, *q;
- const char *str;
- char add[10];
- int w_count = 0, r_count = 0;
- char *omsg;
-
- char *imsg = p_ctx->writer;
-
- if (!imsg) {
- return NULL;
- }
-
- if ((p = imsg)) {
- while ((q = strstr(p, "%w"))) {
- w_count++;
- p=q+1;
- }
-
- p = imsg;
- while ((q = strstr(p, "%r"))) {
- r_count++;
- p=q+1;
- }
- }
-
- /* Required mem:
- * len(imsg)
- * + number of "where" codes * (len(where)-2)
- * - number of "replace" codes
- */
- omsg = (char*)malloc(strlen(imsg) + (w_count * (strlen(p_ctx->where)-2)) - r_count + 1);
- if (!omsg) {
- fprintf(stderr, "Out of memory.");
- exit(1);
- }
-
- *omsg = 0;
- //printf("apply_rp_codes: %s\n", imsg);
- for (p=imsg; *p; p++) {
- if (*p == '%') {
- switch (*++p) {
- case '%':
- str = "%";
- break;
- case 'w':
- str = p_ctx->where;
- break;
- case 'r':
- snprintf(add, 2, "%c", p_ctx->replace);
- str = add;
- break;
- default:
- add[0] = '%';
- add[1] = *p;
- add[2] = 0;
- str = add;
- break;
- }
- } else {
- add[0] = *p;
- add[1] = 0;
- str = add;
- }
- //printf("add_str %s\n", str);
- strcat(omsg, str);
- //printf("omsg=%s\n", omsg);
- }
- return omsg;
-}
/*
* Bacula is calling us to do the actual I/O
return bRC_OK;
}
+/*************************************************************************
+ * Apply codes in writer command:
+ * %w -> "where"
+ * %r -> "replace"
+ *
+ * Replace:
+ * 'always' => 'a', chr(97)
+ * 'ifnewer' => 'w', chr(119)
+ * 'ifolder' => 'o', chr(111)
+ * 'never' => 'n', chr(110)
+ *
+ * This function will allocate the required amount of memory with malloc.
+ * Need to be free()d manually.
+ * Inspired by edit_job_codes in lib/util.c
+ */
+
+static char *apply_rp_codes(struct plugin_ctx * p_ctx)
+{
+ char *p, *q;
+ const char *str;
+ char add[10];
+ int w_count = 0, r_count = 0;
+ char *omsg;
+
+ char *imsg = p_ctx->writer;
+
+ if (!imsg) {
+ return NULL;
+ }
+
+ if ((p = imsg)) {
+ while ((q = strstr(p, "%w"))) {
+ w_count++;
+ p=q+1;
+ }
+
+ p = imsg;
+ while ((q = strstr(p, "%r"))) {
+ r_count++;
+ p=q+1;
+ }
+ }
+
+ /* Required mem:
+ * len(imsg)
+ * + number of "where" codes * (len(where)-2)
+ * - number of "replace" codes
+ */
+ omsg = (char*)malloc(strlen(imsg) + (w_count * (strlen(p_ctx->where)-2)) - r_count + 1);
+ if (!omsg) {
+ fprintf(stderr, "Out of memory.");
+ exit(1);
+ }
+
+ *omsg = 0;
+ //printf("apply_rp_codes: %s\n", imsg);
+ for (p=imsg; *p; p++) {
+ if (*p == '%') {
+ switch (*++p) {
+ case '%':
+ str = "%";
+ break;
+ case 'w':
+ str = p_ctx->where;
+ break;
+ case 'r':
+ snprintf(add, 2, "%c", p_ctx->replace);
+ str = add;
+ break;
+ default:
+ add[0] = '%';
+ add[1] = *p;
+ add[2] = 0;
+ str = add;
+ break;
+ }
+ } else {
+ add[0] = *p;
+ add[1] = 0;
+ str = add;
+ }
+ //printf("add_str %s\n", str);
+ strcat(omsg, str);
+ //printf("omsg=%s\n", omsg);
+ }
+ return omsg;
+}
+
#ifdef __cplusplus
}
/*
- Bacula® - The Network Backup Solution
-
- Copyright (C) 2007-2008 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.
- This program is Free Software; you can redistribute it and/or
- modify it under the terms of version two of the GNU General Public
- License as published by the Free Software Foundation, which is
- listed in the file LICENSE.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Bacula® is a registered trademark of Kern Sibbald.
- The licensor of Bacula is the Free Software Foundation Europe
- (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
- Switzerland, email:ftf@fsfeurope.org.
+
+ Copyright (C) 2007-2008 Kern Sibbald
+
+ You may freely use this code to create your own plugin provided
+ it is to write a plugin for Bacula licensed under GPLv2
+ (as Bacula is), and in that case, you may also remove
+ the above Copyright and this notice as well as modify
+ the code in any way.
+
*/
-/*
- * Sample Plugin program
- *
- * Kern Sibbald, October 2007
- *
- */
#include <stdio.h>
#include "fd_plugins.h"
#endif
#define PLUGIN_LICENSE "GPL"
-#define PLUGIN_AUTHOR "Kern Sibbald"
+#define PLUGIN_AUTHOR "Your name"
#define PLUGIN_DATE "January 2008"
#define PLUGIN_VERSION "1"
#define PLUGIN_DESCRIPTION "Test File Daemon Plugin"