]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/breg.c
Change copyright as per agreement with FSFE
[bacula/bacula] / bacula / src / lib / breg.c
index 27b2b7030e63e8ab140edd40b50cda2f239250b3..8034c2c321aeedbf6120f0667220dbfeeb565fd8 100644 (file)
@@ -1,38 +1,27 @@
+/*
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2016 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
+*/
 /*
  * Manipulation routines for BREGEXP list
  *
  *  Eric Bollengier, March 2007
  *
- *  Version $Id$
- *
  */
-/*
-   Bacula\81Â\81® - The Network Backup Solution
-
-   Copyright (C) 2006-2006 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 and included
-   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\81Â\81® is a registered trademark of John Walker.
-   The licensor of Bacula is the Free Software Foundation Europe
-   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Z\81Ã\81¼rich,
-   Switzerland, email:ftf@fsfeurope.org.
-*/
 
 
 #include "bacula.h"
@@ -45,7 +34,7 @@ BREGEXP *new_bregexp(const char *motif)
    Dmsg0(500, "bregexp: creating new bregexp object\n");
    BREGEXP *self = (BREGEXP *)bmalloc(sizeof(BREGEXP));
    memset(self, 0, sizeof(BREGEXP));
-   
+
    if (!self->extract_regexp(motif)) {
       Dmsg0(100, "bregexp: extract_regexp error\n");
       free_bregexp(self);
@@ -106,7 +95,7 @@ bool apply_bregexps(const char *fname, alist *bregexps, char **result)
    return ok;
 }
 
-/* return an alist of BREGEXP or return NULL if it's not a 
+/* return an alist of BREGEXP or return NULL if it's not a
  * where=!tmp!opt!ig,!temp!opt!i
  */
 alist *get_bregexps(const char *where)
@@ -124,7 +113,7 @@ alist *get_bregexps(const char *where)
    }
 
    if (list->size()) {
-      return list;      
+      return list;
    } else {
       delete list;
       return NULL;
@@ -136,20 +125,21 @@ bool BREGEXP::extract_regexp(const char *motif)
    if ( !motif ) {
       return false;
    }
-   
+
    char sep = motif[0];
 
-   if (!(sep == '!' || 
-         sep == ':' || 
-         sep == ';' || 
-         sep == '|' || 
-         sep == ',' || 
-         sep == '&' || 
-         sep == '%' || 
-         sep == '=' || 
+   if (!(sep == '!' ||
+         sep == ':' ||
+         sep == ';' ||
+         sep == '|' ||
+         sep == ',' ||
+         sep == '&' ||
+         sep == '%' ||
+         sep == '=' ||
          sep == '~' ||
          sep == '/' ||
-         sep == '#'   )) 
+         sep == '<' ||
+         sep == '#'   ))
    {
       return false;
    }
@@ -163,7 +153,7 @@ bool BREGEXP::extract_regexp(const char *motif)
 
    while (*search && !ok) {
       if (search[0] == '\\' && search[1] == sep) {
-         *dest++ = *++search;       /* we skip separator */ 
+         *dest++ = *++search;       /* we skip separator */
 
       } else if (search[0] == '\\' && search[1] == '\\') {
          *dest++ = *++search;       /* we skip the second \ */
@@ -175,7 +165,7 @@ bool BREGEXP::extract_regexp(const char *motif)
             ok = true;
 
          } else {
-            *dest++ = *++search; /* we skip separator */ 
+            *dest++ = *++search; /* we skip separator */
             subst = dest;        /* get replaced string */
          }
 
@@ -184,7 +174,7 @@ bool BREGEXP::extract_regexp(const char *motif)
       }
    }
    *dest = '\0';                /* in case of */
-   
+
    if (!ok || !subst) {
       /* bad regexp */
       return false;
@@ -247,7 +237,7 @@ char *BREGEXP::replace(const char *fname)
    }
 
    return result;
-} 
+}
 
 char *BREGEXP::return_fname(const char *fname, int len)
 {
@@ -256,19 +246,19 @@ char *BREGEXP::return_fname(const char *fname, int len)
    return result;
 }
 
-int BREGEXP::compute_dest_len(const char *fname, regmatch_t regs[])
+int BREGEXP::compute_dest_len(const char *fname, regmatch_t breg[])
 {
    int len=0;
    char *p;
    char *psubst = subst;
    int no;
 
-   if (!fname || !regs) {
+   if (!fname || !breg) {
       return 0;
    }
 
    /* match failed ? */
-   if (regs[0].rm_so < 0) {
+   if (breg[0].rm_so < 0) {
       return 0;
    }
 
@@ -280,23 +270,23 @@ int BREGEXP::compute_dest_len(const char *fname, regmatch_t regs[])
          /* we check if the back reference exists */
          /* references can not match if we are using (..)? */
 
-         if (regs[no].rm_so >= 0 && regs[no].rm_eo >= 0) { 
-            len += regs[no].rm_eo - regs[no].rm_so;
+         if (breg[no].rm_so >= 0 && breg[no].rm_eo >= 0) {
+            len += breg[no].rm_eo - breg[no].rm_so;
          }
-         
+
       } else {
          len++;
       }
    }
 
    /* $0 is replaced by subst */
-   len -= regs[0].rm_eo - regs[0].rm_so;
+   len -= breg[0].rm_eo - breg[0].rm_so;
    len += strlen(fname) + 1;
 
    return len;
 }
 
-char *BREGEXP::edit_subst(const char *fname, regmatch_t regs[])
+char *BREGEXP::edit_subst(const char *fname, regmatch_t breg[])
 {
    int i;
    char *p;
@@ -305,10 +295,10 @@ char *BREGEXP::edit_subst(const char *fname, regmatch_t regs[])
    int len;
 
    /* il faut recopier fname dans dest
-    *  on recopie le debut fname -> regs->start[0]
+    *  on recopie le debut fname -> breg->start[0]
     */
-   
-   for (i = 0; i < regs[0].rm_so ; i++) {
+
+   for (i = 0; i < breg[0].rm_so ; i++) {
       result[i] = fname[i];
    }
 
@@ -320,9 +310,9 @@ char *BREGEXP::edit_subst(const char *fname, regmatch_t regs[])
          no = *psubst++ - '0';
 
          /* have a back reference ? */
-         if (regs[no].rm_so >= 0 && regs[no].rm_eo >= 0) {
-            len = regs[no].rm_eo - regs[no].rm_so;
-            bstrncpy(result + i, fname + regs[no].rm_so, len + 1);
+         if (breg[no].rm_so >= 0 && breg[no].rm_eo >= 0) {
+            len = breg[no].rm_eo - breg[no].rm_so;
+            bstrncpy(result + i, fname + breg[no].rm_so, len + 1);
             i += len ;
          }
 
@@ -332,7 +322,7 @@ char *BREGEXP::edit_subst(const char *fname, regmatch_t regs[])
    }
 
    /* we copy what is out of the match */
-   strcpy(result + i, fname + regs[0].rm_eo);
+   strcpy(result + i, fname + breg[0].rm_eo);
 
    return result;
 }
@@ -340,7 +330,7 @@ char *BREGEXP::edit_subst(const char *fname, regmatch_t regs[])
 /* escape sep char and \
  * dest must be long enough (src*2+1)
  * return end of the string */
-char *bregexp_escape_string(char *dest, char *src, char sep)
+char *bregexp_escape_string(char *dest, const char *src, const char sep)
 {
    char *ret = dest;
    while (*src)
@@ -354,20 +344,20 @@ char *bregexp_escape_string(char *dest, char *src, char sep)
    }
    *dest = '\0';
 
-   return ret; 
+   return ret;
 }
 
-static char regexp_sep = '!';
-static char *str_strip_prefix = "!%s!!i";
-static char *str_add_prefix   = "!^!%s!";
-static char *str_add_suffix   = "!([^/])$!$1%s!";
+static const char regexp_sep = '!';
+static const char *str_strip_prefix = "!%s!!i";
+static const char *str_add_prefix   = "!^!%s!";
+static const char *str_add_suffix   = "!([^/])$!$1%s!";
 
-int bregexp_get_build_where_size(char *strip_prefix, 
-                                 char *add_prefix, 
+int bregexp_get_build_where_size(char *strip_prefix,
+                                 char *add_prefix,
                                  char *add_suffix)
 {
    int str_size = ((strip_prefix?strlen(strip_prefix)+strlen(str_strip_prefix):0) +
-                   (add_prefix?strlen(add_prefix)+strlen(str_add_prefix)      :0) +  
+                   (add_prefix?strlen(add_prefix)+strlen(str_add_prefix)      :0) +
                    (add_suffix?strlen(add_suffix)+strlen(str_add_suffix)      :0) )
          /* escape + 3*, + \0 */
             * 2    + 3   + 1;
@@ -378,16 +368,16 @@ int bregexp_get_build_where_size(char *strip_prefix,
 
 /* build a regexp string with user arguments
  * Usage :
- * 
+ *
  * int len = bregexp_get_build_where_size(a,b,c) ;
  * char *dest = (char *) bmalloc (len * sizeof(char));
  * bregexp_build_where(dest, len, a, b, c);
  * bfree(dest);
- * 
+ *
  */
 char *bregexp_build_where(char *dest, int str_size,
-                          char *strip_prefix, 
-                          char *add_prefix, 
+                          char *strip_prefix,
+                          char *add_prefix,
                           char *add_suffix)
 {
    int len=0;
@@ -395,7 +385,7 @@ char *bregexp_build_where(char *dest, int str_size,
    POOLMEM *str_tmp = get_memory(str_size);
 
    *str_tmp = *dest = '\0';
-   
+
    if (strip_prefix) {
       len += bsnprintf(dest, str_size - len, str_strip_prefix,
                        bregexp_escape_string(str_tmp, strip_prefix, regexp_sep));
@@ -411,7 +401,7 @@ char *bregexp_build_where(char *dest, int str_size,
    if (add_prefix) {
       if (len) dest[len++] = ',';
 
-      len += bsnprintf(dest + len, str_size - len, str_add_prefix, 
+      len += bsnprintf(dest + len, str_size - len, str_add_prefix,
                        bregexp_escape_string(str_tmp, add_prefix, regexp_sep));
    }