Commit 811df367 authored by vysheng's avatar vysheng

Updates

parent 35f100b9
......@@ -14,21 +14,29 @@ HEADERS= ${srcdir}/constants.h ${srcdir}/include.h ${srcdir}/interface.h ${sr
INCLUDE=-I. -I${srcdir}
CC=@CC@
OBJECTS=main.o loop.o interface.o net.o mtproto-common.o mtproto-client.o queries.o structures.o binlog.o tools.o lua-tg.o
TLC_OBJECTS=tlc.o tl-parser.o tools.o crc32.o
GENERATE_OBJECTS=generate.o tools.o
.SUFFIXES:
.SUFFIXES: .c .h .o
all: telegram
all: telegram tlc generate
${OBJECTS}: ${HEADERS}
${OBJECTS} ${TLC_OBJECTS}: ${HEADERS}
telegram: ${OBJECTS}
${CC} ${OBJECTS} ${LINK_FLAGS} -o $@
tlc: ${TLC_OBJECTS}
${CC} ${TLC_OBJECTS} ${LINK_FLAGS} -o $@
.c.o :
${CC} ${COMPILE_FLAGS} ${INCLUDE} -c $< -o $@
tlc: ${GENERATE_OBJECTS}
${CC} ${GENERATE_OBJECTS} ${LINK_FLAGS} -o $@
clean:
rm -rf *.o telegram config.log config.status > /dev/null || echo "all clean"
......
int skip_double (void) {
if (in_ptr + 2 <= in_end) {
in_ptr += 2;
return 0;
} else {
return -1;
}
}
int skip_long (void) {
if (in_ptr + 2 <= in_end) {
in_ptr += 2;
return 0;
} else {
return -1;
}
}
int skip_int (void) {
if (in_ptr + 1 <= in_end) {
in_ptr += 1;
return 0;
} else {
return -1;
}
}
int skip_string (void) {
if (in_ptr == in_end) { return -1; }
unsigned len = *(unsigned char *)in_ptr;
if (len == 0xff) { return -1; }
if (len < 0xfe) {
int size = len + 1;
size += (-size) & 3;
if (in_ptr + (size / 4) <= in_end) {
in_ptr += (size / 4);
return 0;
} else {
return -1;
}
} else {
len = (*in_ptr) >> 8;
int size = len + 4;
size += (-size) & 3;
if (in_ptr + (size / 4) <= in_end) {
in_ptr += (size / 4);
return 0;
} else {
return -1;
}
}
}
#ifndef __AUTO_H__
#define __AUTO_H__
struct tl_type {
unsigned name;
char *id;
};
struct paramed_type {
struct tl_type *type;
struct paramed_type **params;
};
#define NAME_ARRAY 0x89932ad9
#define TYPE_TO_PARAM(NAME) (&(struct paramed_type) {.type = &tl_type_## NAME, .params=0})
#define ODDP(x) (((long)(x)) & 1)
#define EVENP(x) (!ODDP(x))
#define INT2PTR(x) (void *)(long)(((long)x) * 2 + 1)
#define PTR2INT(x) ((((long)x) - 1) / 2)
#include "auto-header.h"
#endif
This diff is collapsed.
#ifndef __GENERATE_H__
#define __GENERATE_H__
struct tl_combinator;
struct tl_type {
// struct tl_type_methods *methods;
char *id;
unsigned name;
int arity;
int flags;
int constructors_num;
struct tl_combinator **constructors;
long long params_types;
int extra;
};
#define NODE_TYPE_TYPE 1
#define NODE_TYPE_NAT_CONST 2
#define NODE_TYPE_VAR_TYPE 3
#define NODE_TYPE_VAR_NUM 4
#define NODE_TYPE_ARRAY 5
#define MAX_COMBINATOR_VARS 64
#define NAME_VAR_NUM 0x70659eff
#define NAME_VAR_TYPE 0x2cecf817
#define NAME_INT 0xa8509bda
#define NAME_LONG 0x22076cba
#define NAME_DOUBLE 0x2210c154
#define NAME_STRING 0xb5286e24
#define NAME_VECTOR 0x1cb5c415
#define NAME_MAYBE_TRUE 0x3f9c8ef8
#define NAME_MAYBE_FALSE 0x27930a7b
#define NAME_BOOL_FALSE 0xbc799737
#define NAME_BOOL_TRUE 0x997275b5
#define FLAG_OPT_VAR (1 << 17)
#define FLAG_EXCL (1 << 18)
#define FLAG_OPT_FIELD (1 << 20)
#define FLAG_NOVAR (1 << 21)
#define FLAG_BARE 1
#define FLAGS_MASK ((1 << 16) - 1)
#define FLAG_DEFAULT_CONSTRUCTOR (1 << 25)
#define FLAG_NOCONS (1 << 1)
extern struct tl_tree_methods tl_nat_const_methods;
extern struct tl_tree_methods tl_nat_const_full_methods;
extern struct tl_tree_methods tl_pnat_const_full_methods;
extern struct tl_tree_methods tl_array_methods;
extern struct tl_tree_methods tl_type_methods;
extern struct tl_tree_methods tl_parray_methods;
extern struct tl_tree_methods tl_ptype_methods;
extern struct tl_tree_methods tl_var_num_methods;
extern struct tl_tree_methods tl_var_type_methods;
extern struct tl_tree_methods tl_pvar_num_methods;
extern struct tl_tree_methods tl_pvar_type_methods;
#define TL_IS_NAT_VAR(x) (((long)x) & 1)
#define TL_TREE_METHODS(x) (TL_IS_NAT_VAR (x) ? &tl_nat_const_methods : ((struct tl_tree *)(x))->methods)
#define DEC_REF(x) (TL_TREE_METHODS(x)->dec_ref ((void *)x))
#define INC_REF(x) (TL_TREE_METHODS(x)->inc_ref ((void *)x))
#define TYPE(x) (TL_TREE_METHODS(x)->type ((void *)x))
typedef unsigned long long tl_tree_hash_t;
struct tl_tree;
struct tl_tree_methods {
int (*type)(struct tl_tree *T);
int (*eq)(struct tl_tree *T, struct tl_tree *U);
void (*inc_ref)(struct tl_tree *T);
void (*dec_ref)(struct tl_tree *T);
};
struct tl_tree {
int ref_cnt;
int flags;
//tl_tree_hash_t hash;
struct tl_tree_methods *methods;
};
/*
struct tl_tree_nat_const {
struct tl_tree self;
int value;
};*/
struct tl_tree_type {
struct tl_tree self;
struct tl_type *type;
int children_num;
struct tl_tree **children;
};
struct tl_tree_array {
struct tl_tree self;
struct tl_tree *multiplicity;
int args_num;
struct arg **args;
};
struct tl_tree_var_type {
struct tl_tree self;
int var_num;
};
struct tl_tree_var_num {
struct tl_tree self;
int var_num;
int dif;
};
struct tl_tree_nat_const {
struct tl_tree self;
long long value;
};
struct arg {
char *id;
int var_num;
int flags;
int exist_var_num;
int exist_var_bit;
struct tl_tree *type;
};
struct tl_combinator {
//struct tl_combinator_methods *methods;
char *id;
unsigned name;
int is_fun;
int var_num;
int args_num;
struct arg **args;
struct tl_tree *result;
void **IP;
void **fIP;
int IP_len;
int fIP_len;
};
#endif
......@@ -53,6 +53,8 @@
#include "binlog.h"
#include "lua-tg.h"
#include "auto.h"
extern char *default_username;
extern char *auth_token;
extern int test_dc;
......
......@@ -53,6 +53,7 @@
#include "interface.h"
#include "structures.h"
#include "binlog.h"
#include "auto.h"
#if defined(__FreeBSD__)
#define __builtin_bswap32(x) bswap32(x)
......@@ -1407,6 +1408,10 @@ void work_update_short (struct connection *c, long long msg_id) {
}
void work_updates (struct connection *c, long long msg_id) {
int *save = in_ptr;
assert (!skip_type_any (&(struct paramed_type) {.type = &tl_type_Updates, .params=0}));
int *save_end = in_ptr;
in_ptr = save;
assert (fetch_int () == CODE_updates);
assert (fetch_int () == CODE_vector);
int n = fetch_int ();
......@@ -1426,6 +1431,7 @@ void work_updates (struct connection *c, long long msg_id) {
}
bl_do_set_date (fetch_int ());
bl_do_set_seq (fetch_int ());
assert (save_end == in_ptr);
}
void work_update_short_message (struct connection *c UU, long long msg_id UU) {
......
......@@ -53,6 +53,7 @@
#include "no-preview.h"
#include "binlog.h"
#include "auto.h"
#define sha1 SHA1
......@@ -242,6 +243,16 @@ void query_result (long long id UU) {
}
queries_tree = tree_delete_query (queries_tree, q);
if (q->methods && q->methods->on_answer) {
if (q->methods->type) {
int *save = in_ptr;
if (skip_type_any (q->methods->type) < 0) {
logprintf ("Skipped %ld int out of %ld (type %s)\n", in_ptr - save, in_end - save, q->methods->type->type->id);
assert (0);
}
assert (in_ptr == in_end);
in_ptr = save;
}
q->methods->on_answer (q);
assert (in_ptr == in_end);
}
......@@ -376,7 +387,8 @@ int help_get_config_on_answer (struct query *q UU) {
}
struct query_methods help_get_config_methods = {
.on_answer = help_get_config_on_answer
.on_answer = help_get_config_on_answer,
.type = TYPE_TO_PARAM(Config)
};
void do_help_get_config (void) {
......@@ -421,7 +433,8 @@ int send_code_on_error (struct query *q UU, int error_code, int l, char *error)
struct query_methods send_code_methods = {
.on_answer = send_code_on_answer,
.on_error = send_code_on_error
.on_error = send_code_on_error,
.type = TYPE_TO_PARAM(auth_SentCode)
};
int code_is_sent (void) {
......@@ -490,7 +503,8 @@ int phone_call_on_error (struct query *q UU, int error_code, int l, char *error)
struct query_methods phone_call_methods = {
.on_answer = phone_call_on_answer,
.on_error = phone_call_on_error
.on_error = phone_call_on_error,
.type = TYPE_TO_PARAM(Bool)
};
void do_phone_call (const char *user) {
......@@ -554,7 +568,8 @@ int check_phone_on_error (struct query *q UU, int error_code, int l, char *error
struct query_methods check_phone_methods = {
.on_answer = check_phone_on_answer,
.on_error = check_phone_on_error
.on_error = check_phone_on_error,
.type = TYPE_TO_PARAM(auth_CheckedPhone)
};
int do_auth_check_phone (const char *user) {
......@@ -598,7 +613,8 @@ int fail_on_error (struct query *q UU, int error_code UU, int l UU, char *error
struct query_methods nearest_dc_methods = {
.on_answer = nearest_dc_on_answer,
.on_error = fail_on_error
.on_error = fail_on_error,
.type = TYPE_TO_PARAM(NearestDc)
};
int do_get_nearest_dc (void) {
......@@ -649,7 +665,8 @@ int sign_in_on_error (struct query *q UU, int error_code, int l, char *error) {
struct query_methods sign_in_methods = {
.on_answer = sign_in_on_answer,
.on_error = sign_in_on_error
.on_error = sign_in_on_error,
.type = TYPE_TO_PARAM(auth_Authorization)
};
int do_send_code_result (const char *code) {
......@@ -684,6 +701,7 @@ extern char *user_list[];
int get_contacts_on_answer (struct query *q UU) {
int i;
assert (fetch_int () == (int)CODE_contacts_contacts);
assert (fetch_int () == CODE_vector);
int n = fetch_int ();
......@@ -728,6 +746,7 @@ int get_contacts_on_answer (struct query *q UU) {
struct query_methods get_contacts_methods = {
.on_answer = get_contacts_on_answer,
.type = TYPE_TO_PARAM(contacts_Contacts)
};
......@@ -893,11 +912,13 @@ int msg_send_on_error (struct query *q, int error_code, int error_len, char *err
struct query_methods msg_send_methods = {
.on_answer = msg_send_on_answer,
.on_error = msg_send_on_error
.on_error = msg_send_on_error,
.type = TYPE_TO_PARAM(messages_SentMessage)
};
struct query_methods msg_send_encr_methods = {
.on_answer = msg_send_encr_on_answer
.on_answer = msg_send_encr_on_answer,
.type = TYPE_TO_PARAM(messages_SentEncryptedMessage)
};
int out_message_num;
......@@ -1001,11 +1022,13 @@ int mark_read_encr_on_receive (struct query *q UU) {
}
struct query_methods mark_read_methods = {
.on_answer = mark_read_on_receive
.on_answer = mark_read_on_receive,
.type = TYPE_TO_PARAM(messages_AffectedHistory)
};
struct query_methods mark_read_encr_methods = {
.on_answer = mark_read_encr_on_receive
.on_answer = mark_read_encr_on_receive,
.type = TYPE_TO_PARAM(Bool)
};
void do_messages_mark_read (peer_id_t id, int max_id) {
......@@ -1093,6 +1116,7 @@ int get_history_on_answer (struct query *q UU) {
struct query_methods get_history_methods = {
.on_answer = get_history_on_answer,
.type = TYPE_TO_PARAM(messages_Messages)
};
void do_get_local_history (peer_id_t id, int limit) {
......@@ -1196,6 +1220,7 @@ int get_dialogs_on_answer (struct query *q UU) {
struct query_methods get_dialogs_methods = {
.on_answer = get_dialogs_on_answer,
.type = TYPE_TO_PARAM(messages_Dialogs)
};
......@@ -2085,7 +2110,7 @@ int import_auth_on_answer (struct query *q UU) {
assert (fetch_int () == (int)CODE_auth_authorization);
fetch_int (); // expires
fetch_alloc_user ();
tfree_str (export_auth_str);
tfree (export_auth_str, export_auth_str_len);
export_auth_str = 0;
return 0;
}
......
......@@ -20,6 +20,7 @@
#ifndef __QUERIES_H__
#define __QUERIES_H__
#include "structures.h"
#include "auto.h"
#define QUERY_ACK_RECEIVED 1
......@@ -28,6 +29,7 @@ struct query_methods {
int (*on_answer)(struct query *q);
int (*on_error)(struct query *q, int error_code, int len, char *error);
int (*on_timeout)(struct query *q);
struct paramed_type *type;
};
struct event_timer {
......
This diff is collapsed.
......@@ -405,6 +405,9 @@ notifyAll#74d07c60 = NotifyPeer;
updateUserBlocked#80ece81a user_id:int blocked:Bool = Update;
updateNotifySettings#bec268ef peer:NotifyPeer notify_settings:PeerNotifySettings = Update;
za int = Z 0;
zb {n:#} int %(Vector int) = Z (n + 1);
---functions---
invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X;
......
......@@ -272,14 +272,22 @@ char *parse_lex (void) {
if (curch == '#') {
parse.lex.flags |= 2;
int i;
int ok = 1;
for (i = 0; i < 8; i++) {
if (!is_hexdigit (nextch())) {
parse_error ("Hex digit expected");
parse.lex.type = lex_error;
return (parse.lex.ptr = (void *)-1);
if (curch == ' ' && i >= 5) {
ok = 2;
break;
} else {
parse_error ("Hex digit expected");
parse.lex.type = lex_error;
return (parse.lex.ptr = (void *)-1);
}
}
}
nextch ();
if (ok == 1) {
nextch ();
}
}
parse.lex.len = parse.text + parse.pos - p;
parse.lex.type = lex_lc_ident;
......@@ -1117,9 +1125,9 @@ struct tl_constructor *tl_add_constructor (struct tl_type *a, const char *_id, i
unsigned magic = 0;
if (x < len) {
assert (len - x == 9);
assert (len - x >= 6 && len - x <= 9);
int i;
for (i = 1; i <= 8; i++) {
for (i = 1; i < len - x; i++) {
magic = (magic << 4) + (_id[x + i] <= '9' ? _id[x + i] - '0' : _id[x + i] - 'a' + 10);
}
assert (magic && magic != (unsigned)-1);
......@@ -1178,9 +1186,9 @@ struct tl_constructor *tl_add_function (struct tl_type *a, const char *_id, int
unsigned magic = 0;
if (x < len) {
assert (len - x == 9);
assert (len - x >= 6 && len - x <= 9);
int i;
for (i = 1; i <= 8; i++) {
for (i = 1; i < len - x; i++) {
magic = (magic << 4) + (_id[x + i] <= '9' ? _id[x + i] - '0' : _id[x + i] - 'a' + 10);
}
assert (magic && magic != (unsigned)-1);
......
......@@ -129,6 +129,7 @@ int main (int argc, char **argv) {
usage ();
}
struct parse *P = tl_init_parse_file (argv[optind]);
if (!P) {
return 0;
......
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