diff --git a/interface.c b/interface.c index 12d5e42..4ded901 100644 --- a/interface.c +++ b/interface.c @@ -35,6 +35,7 @@ char *commands[] = { "dialog_list", "send_photo", "send_video", + "send_text", 0 }; int commands_flags[] = { @@ -46,6 +47,7 @@ int commands_flags[] = { 07, 0732, 0732, + 0732, }; char *a = 0; @@ -255,6 +257,21 @@ void interpreter (char *line UU) { Peers[index]->id, strndup (f, len)); } } + } else if (!memcmp (line, "send_text", 9)) { + char *q = line + 10; + int len; + char *text = get_token (&q, &len); + int index = 0; + while (index < user_num + chat_num && (!Peers[index]->print_name || strncmp (Peers[index]->print_name, text, len))) { + index ++; + } + if (index < user_num + chat_num) { + int len = 0; + char *f = get_token (&q, &len); + if (len > 0) { + do_send_text (Peers[index], strndup (f, len)); + } + } } else if (!memcmp (line, "history", 7)) { char *q = line + 7; int len; diff --git a/queries.c b/queries.c index bdd45c5..dfc9085 100644 --- a/queries.c +++ b/queries.c @@ -486,6 +486,26 @@ void do_send_message (union user_chat *U, const char *msg) { print_message (M); } +void do_send_text (union user_chat *U, char *file_name) { + int fd = open (file_name, O_RDONLY); + if (fd < 0) { + rprintf ("No such file '%s'\n", file_name); + free (file_name); + return; + } + static char buf[(1 << 20) + 1]; + int x = read (fd, buf, (1 << 20) + 1); + if (x == (1 << 20) + 1) { + rprintf ("Too big file '%s'\n", file_name); + free (file_name); + close (fd); + } else { + do_send_message (U, buf); + free (file_name); + close (fd); + } +} + int get_history_on_answer (struct query *q UU) { static struct message *ML[10000]; int i; diff --git a/queries.h b/queries.h index 477cd9b..bb2f5b3 100644 --- a/queries.h +++ b/queries.h @@ -48,6 +48,7 @@ double get_double_time (void); void do_update_contact_list (void); union user_chat; void do_send_message (union user_chat *U, const char *msg); +void do_send_text (union user_chat *U, char *file); void do_get_history (union user_chat *U, int limit); void do_get_dialog_list (void); void do_send_photo (int type, int to_id, char *file_name);