Commit db8a7a77 authored by vysheng's avatar vysheng

Some fixes

parent b1d88355
......@@ -223,7 +223,7 @@ void interpreter (char *line UU) {
}
while (*q && (*q == ' ' || *q == '\t')) { q ++; }
if (*q && index < user_num + chat_num) {
do_send_message (Peers[index], q);
do_send_message (Peers[index], q, strlen (q));
}
} else if (!memcmp (line, "send_photo", 10)) {
char *q = line + 10;
......
......@@ -21,6 +21,7 @@ void logprintf (const char *format, ...) __attribute__ ((format (printf, 1, 2)))
void hexdump (int *in_ptr, int *in_end);
struct message;
union user_chat;
void print_message (struct message *M);
void print_chat_name (int id, union user_chat *C);
void print_user_name (int id, union user_chat *U);
......
......@@ -107,6 +107,8 @@ void query_error (long long id) {
queries_tree = tree_delete_query (queries_tree, q);
if (q->methods && q->methods->on_error) {
q->methods->on_error (q, error_code, error_len, error);
} else {
logprintf ( "error for query #%lld: #%d :%.*s\n", id, error_code, error_len, error);
}
free (q->data);
free (q);
......@@ -451,7 +453,7 @@ struct query_methods msg_send_methods = {
int out_message_num;
int our_id;
void do_send_message (union user_chat *U, const char *msg) {
void do_send_message (union user_chat *U, const char *msg, int len) {
if (!out_message_num) {
out_message_num = -lrand48 ();
}
......@@ -475,12 +477,15 @@ void do_send_message (union user_chat *U, const char *msg) {
out_int (U->id);
}
}
M->message = strdup (msg);
M->message = malloc (len + 1);
memcpy (M->message, msg, len);
M->message[len] = 0;
M->message_len = len;
M->out = 1;
M->media.type = CODE_message_media_empty;
M->id = out_message_num;
M->date = time (0);
out_string (msg);
out_cstring (msg, len);
out_long ((--out_message_num) - (1ll << 32));
send_query (DC_working, packet_ptr - packet_buffer, packet_buffer, &msg_send_methods, M);
print_message (M);
......@@ -495,12 +500,14 @@ void do_send_text (union user_chat *U, char *file_name) {
}
static char buf[(1 << 20) + 1];
int x = read (fd, buf, (1 << 20) + 1);
assert (x >= 0);
if (x == (1 << 20) + 1) {
rprintf ("Too big file '%s'\n", file_name);
free (file_name);
close (fd);
} else {
do_send_message (U, buf);
buf[x] = 0;
do_send_message (U, buf, x);
free (file_name);
close (fd);
}
......@@ -738,7 +745,7 @@ void do_send_photo (int type, int to_id, char *file_name) {
f->size = size;
f->offset = 0;
f->part_num = 0;
f->part_size = (size / 1000 + 0x3ff) & ~0x3ff;
f->part_size = ((size + 999) / 1000 + 0x3ff) & ~0x3ff;
f->id = lrand48 () * (1ll << 32) + lrand48 ();
f->to_id = to_id;
f->media_type = type;
......
......@@ -47,7 +47,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_message (union user_chat *U, const char *msg, int len);
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);
......
......@@ -136,6 +136,7 @@ struct message {
struct message_action action;
struct {
char *message;
int message_len;
struct message_media media;
};
};
......
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