Commit b1d88355 authored by vysheng's avatar vysheng

Added send_text query

parent e2cc2ed7
...@@ -35,6 +35,7 @@ char *commands[] = { ...@@ -35,6 +35,7 @@ char *commands[] = {
"dialog_list", "dialog_list",
"send_photo", "send_photo",
"send_video", "send_video",
"send_text",
0 }; 0 };
int commands_flags[] = { int commands_flags[] = {
...@@ -46,6 +47,7 @@ int commands_flags[] = { ...@@ -46,6 +47,7 @@ int commands_flags[] = {
07, 07,
0732, 0732,
0732, 0732,
0732,
}; };
char *a = 0; char *a = 0;
...@@ -255,6 +257,21 @@ void interpreter (char *line UU) { ...@@ -255,6 +257,21 @@ void interpreter (char *line UU) {
Peers[index]->id, strndup (f, len)); 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)) { } else if (!memcmp (line, "history", 7)) {
char *q = line + 7; char *q = line + 7;
int len; int len;
......
...@@ -486,6 +486,26 @@ void do_send_message (union user_chat *U, const char *msg) { ...@@ -486,6 +486,26 @@ void do_send_message (union user_chat *U, const char *msg) {
print_message (M); 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) { int get_history_on_answer (struct query *q UU) {
static struct message *ML[10000]; static struct message *ML[10000];
int i; int i;
......
...@@ -48,6 +48,7 @@ double get_double_time (void); ...@@ -48,6 +48,7 @@ double get_double_time (void);
void do_update_contact_list (void); void do_update_contact_list (void);
union user_chat; union user_chat;
void do_send_message (union user_chat *U, const char *msg); 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_history (union user_chat *U, int limit);
void do_get_dialog_list (void); void do_get_dialog_list (void);
void do_send_photo (int type, int to_id, char *file_name); void do_send_photo (int type, int to_id, char *file_name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment