diff options
Diffstat (limited to 'ssh')
-rw-r--r-- | ssh/client.c | 16 | ||||
-rw-r--r-- | ssh/tomsg_clientlib.c | 26 | ||||
-rw-r--r-- | ssh/tomsg_clientlib.h | 8 |
3 files changed, 50 insertions, 0 deletions
diff --git a/ssh/client.c b/ssh/client.c index ad0f107..a262d6f 100644 --- a/ssh/client.c +++ b/ssh/client.c @@ -285,6 +285,14 @@ static bool handle_line( ret = tomsg_history(client, args[0], count, msgid); } + } else if (sv_equals(command, "get") || + sv_equals(command, "get_message")) { + int64_t msgid; + if (parse_args(line, args, num_args = 1, false) && + parse_i64(args[0], &msgid)) { + ret = tomsg_get_message(client, msgid); + } + } else if (sv_equals(command, "on") || sv_equals(command, "is_online")) { if (parse_args(line, args, num_args = 1, false)) { @@ -326,6 +334,7 @@ static bool handle_line( " ping\n" " hist/history <room> <count>\n" " histb/history_before <room> <count> <before_msgid>\n" + " get/get_message <msgid>\n" " on/is_online <user>\n" " act/user_active <y/n>\n" " help\n" @@ -361,6 +370,7 @@ static const char* event_type_descr(enum tomsg_event_type type) { case TOMSG_EV_INVITE: return "invite"; case TOMSG_EV_SEND: return "send"; case TOMSG_EV_HISTORY: return "history"; + case TOMSG_EV_GET_MESSAGE: return "get_message"; case TOMSG_EV_PING: return "ping"; case TOMSG_EV_IS_ONLINE: return "is_online"; case TOMSG_EV_USER_ACTIVE: return "user_active"; @@ -451,6 +461,12 @@ static void handle_event(struct state *state, const struct tomsg_event event) { } break; + case TOMSG_EV_GET_MESSAGE: + printf(" %" PRIi64 " is in room %s:\n ", + event.get_message.message.msgid, event.get_message.room_name); + print_history_message(event.get_message.message); + break; + case TOMSG_EV_PING: printf(" Pong\n"); break; 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++; diff --git a/ssh/tomsg_clientlib.h b/ssh/tomsg_clientlib.h index b164eb3..8a4aae4 100644 --- a/ssh/tomsg_clientlib.h +++ b/ssh/tomsg_clientlib.h @@ -126,6 +126,7 @@ enum tomsg_event_type { TOMSG_EV_INVITE, // join TOMSG_EV_SEND, // send TOMSG_EV_HISTORY, // history + TOMSG_EV_GET_MESSAGE, // get_message TOMSG_EV_PING, // - TOMSG_EV_IS_ONLINE, // is_online TOMSG_EV_USER_ACTIVE, // user_active @@ -181,6 +182,10 @@ struct tomsg_event { struct history_message *messages; } history; struct { + char *room_name; + struct history_message message; + } get_message; + struct { char *username; int64_t online_count; } is_online; @@ -262,6 +267,9 @@ enum tomsg_retval tomsg_history( struct tomsg_client *client, const char *room_name, int64_t count, int64_t before_msgid); +// Send a get_message command to the server. +enum tomsg_retval tomsg_get_message(struct tomsg_client *client, int64_t msgid); + // Send a ping command to the server. enum tomsg_retval tomsg_ping(struct tomsg_client *client); |