fr_value_box_memdup_shallow(dst, dst->enumv, buf, len, a->tainted | b->tainted);
break;
+ case T_SUB:
+ /*
+ * The inverse of add!
+ */
+ if (a->vb_length < b->vb_length) {
+ fr_strerror_const("Suffix to remove is longer than input string");
+ return -1;
+ }
+
+ if (memcmp(a->vb_octets + a->vb_length - b->vb_length, b->vb_strvalue, b->vb_length) != 0) {
+ fr_strerror_const("Right side is not a suffix of the input string");
+ return -1;
+ }
+
+ len = a->vb_length - b->vb_length;
+ buf = talloc_array(ctx, uint8_t, len);
+ if (!buf) goto oom;
+
+ memcpy(buf, a->vb_strvalue, len);
+ buf[len] = '\0';
+
+ fr_value_box_clear_value(dst);
+ fr_value_box_memdup_shallow(dst, dst->enumv, buf, len, a->tainted | b->tainted);
+ break;
+
default:
return ERR_INVALID; /* invalid operator */
}
fr_value_box_strdup_shallow(dst, dst->enumv, buf, a->tainted | b->tainted);
break;
+ case T_SUB:
+ /*
+ * The inverse of add!
+ */
+ if (a->vb_length < b->vb_length) {
+ fr_strerror_const("Suffix to remove is longer than input string");
+ return -1;
+ }
+
+ if (memcmp(a->vb_strvalue + a->vb_length - b->vb_length, b->vb_strvalue, b->vb_length) != 0) {
+ fr_strerror_const("Right side is not a suffix of the input string");
+ return -1;
+ }
+
+ len = a->vb_length - b->vb_length;
+ buf = talloc_array(ctx, char, len + 1);
+ if (!buf) goto oom;
+
+ memcpy(buf, a->vb_strvalue, len);
+ buf[len] = '\0';
+
+ fr_value_box_clear_value(dst);
+ fr_value_box_strdup_shallow(dst, dst->enumv, buf, a->tainted | b->tainted);
+ break;
+
default:
return ERR_INVALID; /* invalid operator */
}
calc string "a" . string "b" -> string
match ab
-# string prepend
-calc string "a" ^ string "b" -> string
-match ba
+# string subtraction is the inverse of addition!
+calc string "ab" - string "b" -> string
+match a
+
+# octets prepend
+calc octets "a" ^ octets "b" -> octets
+match 0x6261
+
+# octets append
+calc octets "a" . octets "b" -> octets
+match 0x6162
+
+# octets subtraction is the inverse of addition!
+calc octets "ab" - octets "b" -> octets
+match 0x61
+
# time deltas
calc time_delta 1 + time_delta 2 -> time_delta
match 2test
count
-match 42
+match 48