From 9c7ddb4ac71e7b4bd298e20500ef66f58db6d329 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 28 Jul 2020 20:06:57 +0200 Subject: clientlib: Update to protocol version 2 with replies --- ssh/tomsg_clientlib.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'ssh/tomsg_clientlib.c') diff --git a/ssh/tomsg_clientlib.c b/ssh/tomsg_clientlib.c index c14d5c5..05ee09d 100644 --- a/ssh/tomsg_clientlib.c +++ b/ssh/tomsg_clientlib.c @@ -178,7 +178,7 @@ const char* tomsg_strerror(enum tomsg_retval code) { static enum tomsg_retval version_negotiation(struct tomsg_client *client) { if (!client->conn) return TOMSG_ERR_CLOSED; - const enum sshnc_retval retssh = sshnc_send(client->conn, "ver version 1\n", 14); + const enum sshnc_retval retssh = sshnc_send(client->conn, "ver version 2\n", 14); if (retssh == SSHNC_EOF) return TOMSG_ERR_CLOSED; if (retssh != SSHNC_OK) return TOMSG_ERR_TRANSPORT; @@ -691,6 +691,7 @@ static enum tomsg_retval handle_line( PARSE_WORD(push_message.message.username); PARSE_I64(push_message.message.timestamp); PARSE_I64(push_message.message.msgid); + PARSE_I64(push_message.message.replyid); PARSE_RESTSTRING(push_message.message.message); return TOMSG_OK; } else if (sv_equals(command, "online")) { @@ -822,11 +823,12 @@ static enum tomsg_retval handle_line( // (and everywhere): the messages buffer has been allocated with // calloc(), so tomsg_event_nullify() will cleanup up precisely // everything that we haven't filled in yet. - struct history_message *msg = &inflight.event.history.messages[index];; + struct history_message *msg = &inflight.event.history.messages[index]; if (!sv_equals(sv_tokenise_word(&line), inflight.event.history.room_name)) CLEANUP_RETURN(TOMSG_ERR_PARSE); if (!sv_copy(sv_tokenise_word(&line), &msg->username)) CLEANUP_RETURN(TOMSG_ERR_PARSE); if (!sv_parse_i64(sv_tokenise_word(&line), &msg->timestamp)) CLEANUP_RETURN(TOMSG_ERR_PARSE); if (!sv_parse_i64(sv_tokenise_word(&line), &msg->msgid)) CLEANUP_RETURN(TOMSG_ERR_PARSE); + if (!sv_parse_i64(sv_tokenise_word(&line), &msg->replyid)) CLEANUP_RETURN(TOMSG_ERR_PARSE); if (!sv_copy(line, &msg->message)) CLEANUP_RETURN(TOMSG_ERR_PARSE); // If there are more history_message events coming, re-add the tag for them @@ -1018,13 +1020,15 @@ enum tomsg_retval tomsg_invite( enum tomsg_retval tomsg_send( struct tomsg_client *client, const char *room_name, const char *message, + int64_t replyid, int64_t *tagp //output ) { if (!client->conn) return TOMSG_ERR_CLOSED; if (hasspacelf(room_name)) return TOMSG_ERR_SPACE; if (haslf(message)) return TOMSG_ERR_SPACE; const int64_t tag = client->next_tag++; - SEND_FMT(client, tag, "send %s %s", room_name, message); + if (replyid < 0) replyid = -1; + SEND_FMT(client, tag, "send %s %" PRIi64 " %s", room_name, replyid, message); const struct tomsg_event event = (struct tomsg_event){ .type = TOMSG_EV_SEND, .send.tag = tag, -- cgit v1.2.3-54-g00ecf