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.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/ssh/tomsg_clientlib.c b/ssh/tomsg_clientlib.c
index e6d3684..df22a1e 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 2\n", 14);
+ const enum sshnc_retval retssh = sshnc_send(client->conn, "ver version 3\n", 14);
if (retssh == SSHNC_EOF) return TOMSG_ERR_CLOSED;
if (retssh != SSHNC_OK) return TOMSG_ERR_TRANSPORT;
@@ -607,6 +607,10 @@ void tomsg_event_nullify(struct tomsg_event event) {
free(event.create_room.room_name);
break;
+ case TOMSG_EV_LEAVE_ROOM:
+ free(event.leave_room.room_name);
+ break;
+
case TOMSG_EV_LIST_ROOMS:
if (event.list_rooms.rooms != NULL) {
for (int64_t i = 0; i < event.list_rooms.count; i++) {
@@ -649,6 +653,11 @@ void tomsg_event_nullify(struct tomsg_event event) {
free(event.push_invite.room_name);
free(event.push_invite.inviter);
break;
+
+ case TOMSG_EV_PUSH_LEAVE:
+ free(event.push_leave.room_name);
+ free(event.push_leave.username);
+ break;
}
}
@@ -717,6 +726,12 @@ static enum tomsg_retval handle_line(
PARSE_WORD(join.username);
EXPECT_FINISH();
return TOMSG_OK;
+ } else if (sv_equals(command, "leave")) {
+ eventp->type = TOMSG_EV_PUSH_LEAVE;
+ PARSE_WORD(push_leave.room_name);
+ PARSE_WORD(push_leave.username);
+ EXPECT_FINISH();
+ return TOMSG_OK;
} else {
// Unknown command, let's just ignore
return TOMSG_ERR_AGAIN;
@@ -757,6 +772,7 @@ static enum tomsg_retval handle_line(
case TOMSG_EV_LOGIN:
case TOMSG_EV_LOGOUT:
case TOMSG_EV_INVITE:
+ case TOMSG_EV_LEAVE_ROOM:
if (!sv_equals(command, "ok")) CLEANUP_RETURN(TOMSG_ERR_PARSE);
SUCCESS_RETURN();
@@ -883,6 +899,7 @@ static enum tomsg_retval handle_line(
case TOMSG_EV_PUSH_MESSAGE:
case TOMSG_EV_PUSH_INVITE:
case TOMSG_EV_PUSH_JOIN:
+ case TOMSG_EV_PUSH_LEAVE:
// What? Why did we put a push event in the inflight list? That's a bug.
assert(false);
}
@@ -1023,6 +1040,19 @@ enum tomsg_retval tomsg_create_room(struct tomsg_client *client) {
return add_inflight(client, tag, event);
}
+enum tomsg_retval tomsg_leave_room(
+ struct tomsg_client *client, const char *room_name) {
+ if (!client->conn) return TOMSG_ERR_CLOSED;
+ if (hasspacelf(room_name)) return TOMSG_ERR_SPACE;
+ const int64_t tag = client->next_tag++;
+ SEND_FMT(client, tag, "leave_room %s", room_name);
+ const struct tomsg_event event = (struct tomsg_event){
+ .type = TOMSG_EV_LEAVE_ROOM,
+ .leave_room.room_name = strdup(room_name),
+ };
+ return add_inflight(client, tag, event);
+}
+
enum tomsg_retval tomsg_invite(
struct tomsg_client *client, const char *room_name, const char *username) {
if (!client->conn) return TOMSG_ERR_CLOSED;