aboutsummaryrefslogtreecommitdiff
path: root/ssh/tomsg_clientlib.c
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-07-29 10:33:53 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-07-29 10:33:53 +0200
commit2ec25e126f54ba1e12c5b98a7d345f18fc52e898 (patch)
tree18fc7f967d27668dbbae3ed68f094f79a382a75c /ssh/tomsg_clientlib.c
parent9c7ddb4ac71e7b4bd298e20500ef66f58db6d329 (diff)
clientlib: Support get_message
Diffstat (limited to 'ssh/tomsg_clientlib.c')
-rw-r--r--ssh/tomsg_clientlib.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/ssh/tomsg_clientlib.c b/ssh/tomsg_clientlib.c
index 05ee09d..adcb4ee 100644
--- a/ssh/tomsg_clientlib.c
+++ b/ssh/tomsg_clientlib.c
@@ -635,6 +635,11 @@ void tomsg_event_nullify(struct tomsg_event event) {
free(event.history.messages);
break;
+ case TOMSG_EV_GET_MESSAGE:
+ free(event.get_message.room_name);
+ history_message_nullify(event.get_message.message);
+ break;
+
case TOMSG_EV_PUSH_MESSAGE:
free(event.push_message.room_name);
history_message_nullify(event.push_message.message);
@@ -843,6 +848,16 @@ static enum tomsg_retval handle_line(
CLEANUP_RETURN(TOMSG_ERR_PARSE);
}
+ case TOMSG_EV_GET_MESSAGE:
+ if (!sv_equals(command, "message")) CLEANUP_RETURN(TOMSG_ERR_PARSE);
+ if (!sv_copy(sv_tokenise_word(&line), &inflight.event.get_message.room_name)) CLEANUP_RETURN(TOMSG_ERR_PARSE);
+ if (!sv_copy(sv_tokenise_word(&line), &inflight.event.get_message.message.username)) CLEANUP_RETURN(TOMSG_ERR_PARSE);
+ if (!sv_parse_i64(sv_tokenise_word(&line), &inflight.event.get_message.message.timestamp)) CLEANUP_RETURN(TOMSG_ERR_PARSE);
+ if (!sv_parse_i64(sv_tokenise_word(&line), &inflight.event.get_message.message.msgid)) CLEANUP_RETURN(TOMSG_ERR_PARSE);
+ if (!sv_parse_i64(sv_tokenise_word(&line), &inflight.event.get_message.message.replyid)) CLEANUP_RETURN(TOMSG_ERR_PARSE);
+ if (!sv_copy(line, &inflight.event.get_message.message.message)) CLEANUP_RETURN(TOMSG_ERR_PARSE);
+ SUCCESS_RETURN();
+
case TOMSG_EV_PING:
if (!sv_equals(command, "pong")) CLEANUP_RETURN(TOMSG_ERR_PARSE);
if (!sv_is_empty(line)) CLEANUP_RETURN(TOMSG_ERR_PARSE);
@@ -1059,6 +1074,17 @@ enum tomsg_retval tomsg_history(
return add_inflight(client, tag, event);
}
+enum tomsg_retval tomsg_get_message(struct tomsg_client *client, int64_t msgid) {
+ if (!client->conn) return TOMSG_ERR_CLOSED;
+ if (msgid < -1) msgid = -1;
+ const int64_t tag = client->next_tag++;
+ const struct tomsg_event event = (struct tomsg_event){
+ .type = TOMSG_EV_GET_MESSAGE,
+ };
+ SEND_FMT(client, tag, "get_message %" PRIi64, msgid);
+ return add_inflight(client, tag, event);
+}
+
enum tomsg_retval tomsg_ping(struct tomsg_client *client) {
if (!client->conn) return TOMSG_ERR_CLOSED;
const int64_t tag = client->next_tag++;