then this fetch clearly does not make sense, in which case the value returned
will be -1.
+date([<offset>]) : integer
+ Returns the current date as the epoch (number of seconds since 01/01/1970).
+ If an offset value is specified, then it is a number of seconds that is added
+ to the current date before returning the value. This is particularly useful
+ to compute relative dates, as both positive and negative offsets are allowed.
+
env(<name>) : string
Returns a string containing the value of environment variable <name>. As a
reminder, environment variables are per-process and are sampled when the
return 1;
}
+/* retrieve the current local date in epoch time, and applies an optional offset
+ * of args[0] seconds.
+ */
+static int
+smp_fetch_date(struct proxy *px, struct session *s, void *l7, unsigned int opt,
+ const struct arg *args, struct sample *smp)
+{
+ smp->data.uint = date.tv_sec;
+
+ /* add offset */
+ if (args && (args[0].type == ARGT_SINT || args[0].type == ARGT_UINT))
+ smp->data.uint += args[0].data.sint;
+
+ smp->type = SMP_T_UINT;
+ smp->flags |= SMP_F_VOL_TEST | SMP_F_MAY_CHANGE;
+ return 1;
+}
+
/* Note: must not be declared <const> as its list will be overwritten.
* Note: fetches that may return multiple types must be declared as the lowest
* common denominator, the type that can be casted into all other ones. For
{ "always_false", smp_fetch_false, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN },
{ "always_true", smp_fetch_true, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN },
{ "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_CSTR, SMP_USE_INTRN },
+ { "date", smp_fetch_date, ARG1(0,SINT), NULL, SMP_T_UINT, SMP_USE_INTRN },
{ /* END */ },
}};