Skip to content

Commit d482fb4

Browse files
authored
Merge pull request #129 from vvd170501/telegram-plugin-fixes
Telegram plugin fixes
2 parents 6242d18 + ec40b84 commit d482fb4

File tree

9 files changed

+44
-25
lines changed

9 files changed

+44
-25
lines changed

bin/ej-jobs.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,31 +1922,37 @@ void *__attribute__((unused))
19221922
job_server_force_link_2[] =
19231923
{
19241924
base64u_decode,
1925-
xml_parse_full_cookie,
1926-
xml_err_elem_undefined_s,
1925+
cJSON_Delete,
1926+
cJSON_GetArrayItem,
1927+
cJSON_GetArraySize,
1928+
cJSON_GetObjectItem,
1929+
cJSON_Parse,
19271930
ej_uuid_parse,
1928-
userprob_plugin_get,
19291931
task_New,
1932+
userprob_plugin_get,
1933+
xml_err_elem_undefined_s,
1934+
xml_parse_full_cookie,
1935+
xml_parse_int,
1936+
xml_parse_ip,
1937+
xml_parse_ipv6_2,
1938+
xml_unparse_full_cookie,
1939+
xml_unparse_ip,
1940+
xml_unparse_ipv6,
19301941
};
19311942

19321943
#if HAVE_LIBMONGOC - 0 > 0
19331944
void *
19341945
job_server_force_link[] =
19351946
{
1936-
cJSON_Delete,
19371947
ej_bson_parse_string_new,
1938-
xml_parse_int,
19391948
};
1940-
#endif
19411949

1942-
#if HAVE_LIBMONGO_CLIENT - 0 == 1
1950+
#elif HAVE_LIBMONGO_CLIENT - 0 == 1
19431951

19441952
void *
19451953
job_server_force_link[] =
19461954
{
1947-
cJSON_Delete,
19481955
ej_bson_parse_string,
1949-
xml_parse_int,
19501956
};
19511957

19521958
#endif

plugins/telegram/mongo_conn.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#endif
3030

3131
#include <stdio.h>
32+
#include <string.h>
3233

3334
#define MONGO_RETRY_TIMEOUT 60
3435

plugins/telegram/mysql_conn.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "ejudge/xalloc.h"
2828
#include "ejudge/errlog.h"
2929

30+
#include <stdio.h>
31+
3032
static struct generic_conn *
3133
free_func(struct generic_conn *gc)
3234
{
@@ -526,10 +528,9 @@ token_remove_expired_func(
526528

527529
mi->lock(md);
528530
cmd_f = open_memstream(&cmd_s, &cmd_z);
529-
fprintf(cmd_f, "DELETE FROM %stelegram_tokens WHERE expiry_time = '",
531+
fprintf(cmd_f, "DELETE FROM %stelegram_tokens WHERE expiry_time = ",
530532
md->table_prefix);
531533
mi->write_timestamp(md, cmd_f, NULL, current_time);
532-
fprintf(cmd_f, "'");
533534
fclose(cmd_f); cmd_f = NULL;
534535
if (mi->simple_query(md, cmd_s, cmd_z) < 0)
535536
db_error_fail(md);
@@ -963,7 +964,7 @@ subscription_fetch_func(
963964
return ts;
964965
}
965966

966-
ts = telegram_subscription_create(bot_id, contest_id, user_id);
967+
ts = telegram_subscription_create(bot_id, user_id, contest_id);
967968
mi->unlock(md);
968969
gc->vt->subscription_save(gc, ts);
969970
return ts;

plugins/telegram/telegram.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
#include <curl/curl.h>
4141
#endif
4242

43-
#include <pthread.h>
44-
#include <string.h>
4543
#include <ctype.h>
4644
#include <signal.h>
45+
#include <stdio.h>
46+
#include <string.h>
47+
#include <pthread.h>
4748

4849
static struct common_plugin_data *
4950
init_func(void);
@@ -780,7 +781,7 @@ packet_handler_telegram_reviewed(int uid, int argc, char **argv, void *user)
780781
goto cleanup;
781782
}
782783

783-
sub = state->conn->vt->subscription_fetch(state->conn, argv[1], contest_id, user_id);
784+
sub = state->conn->vt->subscription_fetch(state->conn, argv[1], user_id, contest_id);
784785
if (!sub) goto cleanup;
785786
if (!sub->review_flag) goto cleanup;
786787
if (!sub->chat_id) {
@@ -860,7 +861,7 @@ packet_handler_telegram_replied(int uid, int argc, char **argv, void *user)
860861
goto cleanup;
861862
}
862863

863-
sub = state->conn->vt->subscription_fetch(state->conn, argv[1], contest_id, user_id);
864+
sub = state->conn->vt->subscription_fetch(state->conn, argv[1], user_id, contest_id);
864865
if (!sub) goto cleanup;
865866
if (!sub->reply_flag) goto cleanup;
866867
if (!sub->chat_id) {
@@ -1444,11 +1445,11 @@ handle_incoming_message(
14441445
} else if (!r) {
14451446
send_result = send_message(state, bs, mc, "Token expired. Operation failed.", NULL, NULL);
14461447
} else {
1447-
sub = state->conn->vt->subscription_fetch(state->conn, bs->bot_id, token->contest_id, token->user_id);
1448+
sub = state->conn->vt->subscription_fetch(state->conn, bs->bot_id, token->user_id, token->contest_id);
14481449
if (!sub && !strcmp(tcs->command, "/unsubscribe")) {
14491450
send_result = send_message(state, bs, mc, "You have no subscriptions. Nothing to unsubscribe.", NULL, "{ \"hide_keyboard\": true}");
14501451
} else {
1451-
if (!sub) sub = telegram_subscription_create(bs->bot_id, token->contest_id, token->user_id);
1452+
if (!sub) sub = telegram_subscription_create(bs->bot_id, token->user_id, token->contest_id);
14521453
if (!strcmp(tcs->command, "/subscribe")) {
14531454
if (tcs->review_flag) sub->review_flag = 1;
14541455
if (tcs->reply_flag) sub->reply_flag = 1;

plugins/telegram/telegram_chat.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
* GNU General Public License for more details.
1515
*/
1616

17+
#include "telegram_chat.h"
18+
1719
#include "ejudge/bson_utils.h"
20+
1821
#include "ejudge/xalloc.h"
1922
#include "ejudge/errlog.h"
2023
#include "ejudge/osdeps.h"
2124

22-
#include "telegram_chat.h"
2325
#include "mongo_conn.h"
2426

2527
#if HAVE_LIBMONGOC - 0 > 1
@@ -31,6 +33,7 @@
3133
#endif
3234

3335
#include <errno.h>
36+
#include <string.h>
3437

3538
#if HAVE_LIBMONGOC - 0 > 0
3639
struct _bson_t;

plugins/telegram/telegram_chat_state.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
* GNU General Public License for more details.
1515
*/
1616

17+
#include "telegram_chat_state.h"
18+
1719
#include "ejudge/bson_utils.h"
20+
1821
#include "ejudge/xalloc.h"
1922
#include "ejudge/errlog.h"
2023
#include "ejudge/osdeps.h"
2124

22-
#include "telegram_chat_state.h"
2325
#include "mongo_conn.h"
2426

2527
#if HAVE_LIBMONGOC - 0 > 1
@@ -31,6 +33,7 @@
3133
#endif
3234

3335
#include <errno.h>
36+
#include <string.h>
3437

3538
#if HAVE_LIBMONGOC - 0 > 0
3639
struct _bson_t;

plugins/telegram/telegram_subscription.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#endif
3232

3333
#include <errno.h>
34+
#include <stdio.h>
3435
#include <string.h>
3536

3637
#if HAVE_LIBMONGOC - 0 > 0
@@ -61,7 +62,7 @@ telegram_subscription_free(struct telegram_subscription *sub)
6162
}
6263

6364
struct telegram_subscription *
64-
telegram_subscription_create(const unsigned char *bot_id, int contest_id, int user_id)
65+
telegram_subscription_create(const unsigned char *bot_id, int user_id, int contest_id)
6566
{
6667
struct telegram_subscription *sub = NULL;
6768
unsigned char buf[1024];
@@ -72,8 +73,8 @@ telegram_subscription_create(const unsigned char *bot_id, int contest_id, int us
7273
XCALLOC(sub, 1);
7374
sub->_id = xstrdup(buf);
7475
sub->bot_id = xstrdup(bot_id);
75-
sub->contest_id = contest_id;
7676
sub->user_id = user_id;
77+
sub->contest_id = contest_id;
7778
return sub;
7879
}
7980

@@ -207,7 +208,7 @@ telegram_subscription_unparse_bson(const struct telegram_subscription *sub)
207208
}
208209

209210
struct telegram_subscription *
210-
telegram_subscription_fetch(struct mongo_conn *conn, const unsigned char *bot_id, int contest_id, int user_id)
211+
telegram_subscription_fetch(struct mongo_conn *conn, const unsigned char *bot_id, int user_id, int contest_id)
211212
{
212213
#if HAVE_LIBMONGOC - 0 > 0
213214
if (!conn->b.vt->open(&conn->b)) return NULL;

plugins/telegram/telegram_subscription.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ struct telegram_subscription
3636
struct telegram_subscription *
3737
telegram_subscription_free(struct telegram_subscription *subscription);
3838
struct telegram_subscription *
39-
telegram_subscription_create(const unsigned char *bot_id, int contest_id, int user_id);
39+
telegram_subscription_create(const unsigned char *bot_id, int user_id, int contest_id);
4040

4141
#endif

plugins/telegram/telegram_user.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
* GNU General Public License for more details.
1515
*/
1616

17+
#include "telegram_user.h"
18+
1719
#include "ejudge/bson_utils.h"
20+
1821
#include "ejudge/xalloc.h"
1922
#include "ejudge/errlog.h"
2023
#include "ejudge/osdeps.h"
2124

22-
#include "telegram_user.h"
2325
#include "mongo_conn.h"
2426

2527
#if HAVE_LIBMONGOC - 0 > 1
@@ -31,6 +33,7 @@
3133
#endif
3234

3335
#include <errno.h>
36+
#include <string.h>
3437

3538
#if HAVE_LIBMONGOC - 0 > 0
3639
struct _bson_t;

0 commit comments

Comments
 (0)