1/*
2 This file is part of Mtproto-proxy Library.
3
4 Mtproto-proxy Library is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 Mtproto-proxy Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mtproto-proxy Library. If not, see <http://www.gnu.org/licenses/>.
16
17 Copyright 2013 Vkontakte Ltd
18 2013 Vitaliy Valtman
19 2013 Anton Maydell
20
21 Copyright 2014 Telegram Messenger Inc
22 2014 Vitaly Valtman
23 2014 Anton Maydell
24
25 Copyright 2015-2016 Telegram Messenger Inc
26 2015-2016 Vitaliy Valtman
27*/
28#include <assert.h>
29#include <stdarg.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include <sys/time.h>
34
35//#include "net/net-buffers.h"
36#include "net/net-events.h"
37#include "net/net-msg.h"
38#include "net/net-msg-buffers.h"
39//#include "net/net-rpc-server.h"
40#include "net/net-rpc-targets.h"
41#include "net/net-tcp-connections.h"
42#include "net/net-tcp-rpc-common.h"
43#include "net/net-tcp-rpc-server.h"
44
45#include "common/cpuid.h"
46#include "common/crc32.h"
47#include "common/kprintf.h"
48#include "common/server-functions.h"
49
50#include "vv/vv-io.h"
51
52//#include "TL/constants.h"
53
54#include "engine/engine.h"
55#include "engine/engine-rpc-common.h"
56
57#include "common/tl-parse.h"
58
59
60static int tl_act_nop (job_t job, struct tl_act_extra *extra) {
61 tls_int (extra->tlio_out, TL_TRUE);
62 return 0;
63}
64
65static int tl_act_stat (job_t job, struct tl_act_extra *extra) {
66 tl_engine_store_stats (extra->tlio_out);
67 return 0;
68}
69
70static inline struct tl_act_extra *tl_simple_parse_function (struct tl_in_state *tlio_in, int (*act)(job_t job, struct tl_act_extra *data)) {
71 tl_fetch_int ();
72 tl_fetch_end ();
73 if (tl_fetch_error ()) {
74 return 0;
75 }
76 struct tl_act_extra *extra = calloc (sizeof (*extra), 1);
77 assert (extra);
78 extra->flags = 3;
79 extra->start_rdtsc = rdtsc ();
80 extra->size = sizeof (*extra);
81 extra->act = act;
82 extra->type = QUERY_ALLOW_REPLICA_GET | QUERY_ALLOW_REPLICA_SET | QUERY_ALLOW_UNINIT;
83 return extra;
84}
85
86struct tl_act_extra *tl_default_parse_function (struct tl_in_state *tlio_in, long long actor_id) {
87 if (actor_id) {
88 return 0;
89 }
90 int f = tl_fetch_lookup_int ();
91 if (tl_fetch_error ()) {
92 return 0;
93 }
94
95 switch (f) {
96 case TL_ENGINE_STAT: return tl_simple_parse_function (tlio_in, tl_act_stat);
97 case TL_ENGINE_NOP: return tl_simple_parse_function (tlio_in, tl_act_nop);
98 }
99 return 0;
100}
101