aboutsummaryrefslogtreecommitdiff
path: root/ssh/tomsg_clientlib.c
diff options
context:
space:
mode:
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++;