return 0;
}
+static int cmd_timestamp(struct dict_connection_cmd *cmd, const char *line)
+{
+ struct dict_connection_transaction *trans;
+ const char *const *args;
+ long long tv_sec;
+ unsigned int tv_nsec;
+
+ /* <id> <secs> <nsecs> */
+ args = t_strsplit_tabescaped(line);
+ if (str_array_length(args) != 3 ||
+ str_to_llong(args[1], &tv_sec) < 0 ||
+ str_to_uint(args[2], &tv_nsec) < 0) {
+ i_error("dict client: ATOMIC_INC: broken input");
+ return -1;
+ }
+
+ if (dict_connection_transaction_lookup_parse(cmd->conn, args[0], &trans) < 0)
+ return -1;
+
+ struct timespec ts = {
+ .tv_sec = tv_sec,
+ .tv_nsec = tv_nsec
+ };
+ dict_transaction_set_timestamp(trans->ctx, &ts);
+ return 0;
+}
+
static const struct dict_cmd_func cmds[] = {
{ DICT_PROTOCOL_CMD_LOOKUP, cmd_lookup },
{ DICT_PROTOCOL_CMD_ITERATE, cmd_iterate },
{ DICT_PROTOCOL_CMD_SET, cmd_set },
{ DICT_PROTOCOL_CMD_UNSET, cmd_unset },
{ DICT_PROTOCOL_CMD_ATOMIC_INC, cmd_atomic_inc },
+ { DICT_PROTOCOL_CMD_TIMESTAMP, cmd_timestamp },
{ 0, NULL }
};
client_dict_send_transaction_query(ctx, query);
}
+static void client_dict_set_timestamp(struct dict_transaction_context *_ctx,
+ const struct timespec *ts)
+{
+ struct client_dict_transaction_context *ctx =
+ (struct client_dict_transaction_context *)_ctx;
+ const char *query;
+
+ query = t_strdup_printf("%c%u\t%s\t%u",
+ DICT_PROTOCOL_CMD_TIMESTAMP,
+ ctx->id, dec2str(ts->tv_sec),
+ (unsigned int)ts->tv_nsec);
+ client_dict_send_transaction_query(ctx, query);
+}
+
struct dict dict_driver_client = {
.name = "proxy",
.unset = client_dict_unset,
.atomic_inc = client_dict_atomic_inc,
.lookup_async = client_dict_lookup_async,
- .switch_ioloop = client_dict_switch_ioloop
+ .switch_ioloop = client_dict_switch_ioloop,
+ .set_timestamp = client_dict_set_timestamp,
}
};
DICT_PROTOCOL_CMD_SET = 'S', /* <id> <key> <value> */
DICT_PROTOCOL_CMD_UNSET = 'U', /* <id> <key> */
- DICT_PROTOCOL_CMD_ATOMIC_INC = 'A' /* <id> <key> <diff> */
+ DICT_PROTOCOL_CMD_ATOMIC_INC = 'A', /* <id> <key> <diff> */
+ DICT_PROTOCOL_CMD_TIMESTAMP = 'T', /* <id> <secs> <nsecs> */
};
enum dict_protocol_reply {