if (!rspamd_cl_obj_todouble_safe (obj, target)) {
g_set_error (err, CFG_RCL_ERROR, EINVAL, "cannot convert param to double");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+gboolean
+rspamd_rcl_parse_struct_time (struct config_file *cfg, rspamd_cl_object_t *obj,
+ gpointer ud, struct rspamd_rcl_section *section, GError **err)
+{
+ struct rspamd_rcl_struct_parser *pd = ud;
+ union {
+ gint *psec;
+ gdouble *pdv;
+ struct timeval *ptv;
+ struct timespec *pts;
+ } target;
+ gdouble val;
+
+ if (!rspamd_cl_obj_todouble_safe (obj, &val)) {
+ g_set_error (err, CFG_RCL_ERROR, EINVAL, "cannot convert param to double");
+ return FALSE;
+ }
+
+ if (pd->flags == RSPAMD_CL_FLAG_TIME_TIMEVAL) {
+ target.ptv = (struct timeval *)(((gchar *)pd->user_struct) + pd->offset);
+ target.ptv->tv_sec = (glong)val;
+ target.ptv->tv_usec = (val - (glong)val) * 1000000;
+ }
+ else if (pd->flags == RSPAMD_CL_FLAG_TIME_TIMESPEC) {
+ target.pts = (struct timespec *)(((gchar *)pd->user_struct) + pd->offset);
+ target.pts->tv_sec = (glong)val;
+ target.pts->tv_nsec = (val - (glong)val) * 1000000000000LL;
+ }
+ else if (pd->flags == RSPAMD_CL_FLAG_TIME_FLOAT) {
+ target.pdv = (double *)(((gchar *)pd->user_struct) + pd->offset);
+ *target.pdv = val;
+ }
+ else if (pd->flags == RSPAMD_CL_FLAG_TIME_INTEGER) {
+ target.psec = (gint *)(((gchar *)pd->user_struct) + pd->offset);
+ *target.psec = val;
+ }
+ else {
+ g_set_error (err, CFG_RCL_ERROR, EINVAL, "invalid flags to parse time value");
+ return FALSE;
}
return TRUE;
gpointer user_struct;
goffset offset;
gsize size;
-#define RSPAMD_CL_FLAG_TIME_FLOAT 0x1 << 0
-#define RSPAMD_CL_FLAG_TIME_TIMEVAL 0x1 << 1
-#define RSPAMD_CL_FLAG_TIME_TIMESPEC 0x1 << 2
-#define RSPAMD_CL_FLAG_TIME_INTEGER 0x1 << 3
- gint flags;
+ enum {
+ RSPAMD_CL_FLAG_TIME_FLOAT = 0x1 << 0,
+ RSPAMD_CL_FLAG_TIME_TIMEVAL = 0x1 << 1,
+ RSPAMD_CL_FLAG_TIME_TIMESPEC = 0x1 << 2,
+ RSPAMD_CL_FLAG_TIME_INTEGER = 0x1 << 3
+ } flags;
};
/**
gboolean rspamd_rcl_parse_struct_double (struct config_file *cfg, rspamd_cl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
+/**
+ * Parse a time field of a structure
+ * @param cfg config pointer
+ * @param obj object to parse
+ * @param ud struct_parser structure (flags mean the exact structure used)
+ * @param section the current section
+ * @param err error pointer
+ * @return TRUE if a value has been successfully parsed
+ */
+gboolean rspamd_rcl_parse_struct_time (struct config_file *cfg, rspamd_cl_object_t *obj,
+ gpointer ud, struct rspamd_rcl_section *section, GError **err);
+
#endif /* CFG_RCL_H_ */