From dfc51f7ba4bf8918eec7d3404246f80004c6aedc Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 29 Jun 2022 09:42:54 +0200 Subject: database: unref date --- src/database.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/database.c b/src/database.c index 0ccd422a..b6497e09 100644 --- a/src/database.c +++ b/src/database.c @@ -301,7 +301,9 @@ _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Ji if (message->timestamp) { date_fmt = g_date_time_format_iso8601(message->timestamp); } else { - date_fmt = g_date_time_format_iso8601(g_date_time_new_now_local()); + GDateTime* dt = g_date_time_new_now_local(); + date_fmt = g_date_time_format_iso8601(dt); + g_date_time_unref(dt); } const char* enc = _get_message_enc_str(message->enc); -- cgit 1.4.1-2-gfad0 From 30faa6c3678a19d182bbc1e62cc9667ea2040892 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 29 Jun 2022 09:44:57 +0200 Subject: chatlog: remove unused variable --- src/chatlog.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/chatlog.c b/src/chatlog.c index da5c7e2b..482e8f38 100644 --- a/src/chatlog.c +++ b/src/chatlog.c @@ -57,7 +57,6 @@ static GHashTable* logs; static GHashTable* groupchat_logs; -static GDateTime* session_started; struct dated_chat_log { @@ -77,7 +76,6 @@ static void _groupchat_log_chat(const gchar* const login, const gchar* const roo void chat_log_init(void) { - session_started = g_date_time_new_now_local(); log_info("Initialising chat logs"); logs = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, free, (GDestroyNotify)_free_chat_log); @@ -422,7 +420,6 @@ chat_log_close(void) { g_hash_table_destroy(logs); g_hash_table_destroy(groupchat_logs); - g_date_time_unref(session_started); } static char* -- cgit 1.4.1-2-gfad0 From 7713223ddb698f798597ee07c6bbdabe698da02d Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 29 Jun 2022 09:47:13 +0200 Subject: build: otr cflags -> CFLAGS --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 96495386..408cdbbd 100644 --- a/configure.ac +++ b/configure.ac @@ -301,7 +301,7 @@ if test "x$enable_otr" != xno; then AM_CONDITIONAL([BUILD_OTR], [true]) PKG_CHECK_MODULES([libotr], [libotr >= 4.0], - [LIBS="$libotr_LIBS $LIBS" CFLAGS="$libotr_CFLAGS $cflags"], + [LIBS="$libotr_LIBS $LIBS" CFLAGS="$libotr_CFLAGS $CFLAGS"], [AM_CONDITIONAL([BUILD_OTR], [false]) AS_IF([test "x$enable_otr" = xyes], [AC_MSG_ERROR([libotr >= 4.0 is required for OTR support])], -- cgit 1.4.1-2-gfad0 From 945ac79364e344c1a9de7a1e7daecfa2165e35d2 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 29 Jun 2022 10:34:59 +0200 Subject: scripts: get rid of read variable --- src/config/scripts.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/config/scripts.c b/src/config/scripts.c index 3f006f77..aca85173 100644 --- a/src/config/scripts.c +++ b/src/config/scripts.c @@ -112,10 +112,9 @@ scripts_read(const char* const script) char* line = NULL; size_t len = 0; - ssize_t read; GSList* result = NULL; - while ((read = getline(&line, &len, scriptfile)) != -1) { + while (getline(&line, &len, scriptfile) != -1) { if (g_str_has_suffix(line, "\n")) { result = g_slist_append(result, g_strndup(line, strlen(line) - 1)); } else { @@ -150,9 +149,8 @@ scripts_exec(const char* const script) char* line = NULL; size_t len = 0; - ssize_t read; - while ((read = getline(&line, &len, scriptfile)) != -1) { + while (getline(&line, &len, scriptfile) != -1) { ProfWin* win = wins_get_current(); cmd_process_input(win, line); session_process_events(); -- cgit 1.4.1-2-gfad0 From 14a2fb6e72db4b1785e37c023ce65f139e126e19 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 29 Jun 2022 12:27:50 +0200 Subject: accounts: deduplicate code via helper function --- src/config/accounts.c | 170 ++++++++++++++++---------------------------------- 1 file changed, 54 insertions(+), 116 deletions(-) diff --git a/src/config/accounts.c b/src/config/accounts.c index d99dd10d..d185b1ad 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -3,6 +3,7 @@ * vim: expandtab:ts=4:sts=4:sw=4 * * Copyright (C) 2012 - 2019 James Booth + * Copyright (C) 2019 - 2022 Michael Vetter * * This file is part of Profanity. * @@ -510,148 +511,127 @@ accounts_set_port(const char* const account_name, const int value) } } -void -accounts_set_resource(const char* const account_name, const char* const value) +static void +_accounts_set_string_option(const char* account_name, const char* const option, const char* const value) { if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "resource", value); + g_key_file_set_string(accounts, account_name, option, value); _save_accounts(); } } -void -accounts_set_password(const char* const account_name, const char* const value) +static void +_accounts_set_int_option(const char* account_name, const char* const option, int value) { if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "password", value); + g_key_file_set_integer(accounts, account_name, option, value); _save_accounts(); } } -void -accounts_set_eval_password(const char* const account_name, const char* const value) +static void +_accounts_clear_string_option(const char* account_name, const char* const option) { if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "eval_password", value); + g_key_file_remove_key(accounts, account_name, option, NULL); _save_accounts(); } } +void +accounts_set_resource(const char* const account_name, const char* const value) +{ + _accounts_set_string_option(account_name, "resource", value); +} + +void +accounts_set_password(const char* const account_name, const char* const value) +{ + _accounts_set_string_option(account_name, "password", value); +} + +void +accounts_set_eval_password(const char* const account_name, const char* const value) +{ + _accounts_set_string_option(account_name, "eval_password", value); +} + void accounts_set_pgp_keyid(const char* const account_name, const char* const value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "pgp.keyid", value); - _save_accounts(); - } + _accounts_set_string_option(account_name, "pgp.keyid", value); } void accounts_set_script_start(const char* const account_name, const char* const value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "script.start", value); - _save_accounts(); - } + _accounts_set_string_option(account_name, "script.start", value); } void accounts_set_theme(const char* const account_name, const char* const value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "theme", value); - _save_accounts(); - } + _accounts_set_string_option(account_name, "theme", value); } void accounts_clear_password(const char* const account_name) { - if (accounts_account_exists(account_name)) { - g_key_file_remove_key(accounts, account_name, "password", NULL); - _save_accounts(); - } + _accounts_clear_string_option(account_name, "password"); } void accounts_clear_eval_password(const char* const account_name) { - if (accounts_account_exists(account_name)) { - g_key_file_remove_key(accounts, account_name, "eval_password", NULL); - _save_accounts(); - } + _accounts_clear_string_option(account_name, "eval_password"); } void accounts_clear_server(const char* const account_name) { - if (accounts_account_exists(account_name)) { - g_key_file_remove_key(accounts, account_name, "server", NULL); - _save_accounts(); - } + _accounts_clear_string_option(account_name, "server"); } void accounts_clear_port(const char* const account_name) { - if (accounts_account_exists(account_name)) { - g_key_file_remove_key(accounts, account_name, "port", NULL); - _save_accounts(); - } + _accounts_clear_string_option(account_name, "port"); } void accounts_clear_pgp_keyid(const char* const account_name) { - if (accounts_account_exists(account_name)) { - g_key_file_remove_key(accounts, account_name, "pgp.keyid", NULL); - _save_accounts(); - } + _accounts_clear_string_option(account_name, "pgp.keyid"); } void accounts_clear_script_start(const char* const account_name) { - if (accounts_account_exists(account_name)) { - g_key_file_remove_key(accounts, account_name, "script.start", NULL); - _save_accounts(); - } + _accounts_clear_string_option(account_name, "script.start"); } void accounts_clear_theme(const char* const account_name) { - if (accounts_account_exists(account_name)) { - g_key_file_remove_key(accounts, account_name, "theme", NULL); - _save_accounts(); - } + _accounts_clear_string_option(account_name, "theme"); } void accounts_clear_muc(const char* const account_name) { - if (accounts_account_exists(account_name)) { - g_key_file_remove_key(accounts, account_name, "muc.service", NULL); - _save_accounts(); - } + _accounts_clear_string_option(account_name, "muc.service"); } void accounts_clear_resource(const char* const account_name) { - if (accounts_account_exists(account_name)) { - g_key_file_remove_key(accounts, account_name, "resource", NULL); - _save_accounts(); - } + _accounts_clear_string_option(account_name, "resource"); } void accounts_clear_otr(const char* const account_name) { - if (accounts_account_exists(account_name)) { - g_key_file_remove_key(accounts, account_name, "otr.policy", NULL); - _save_accounts(); - } + _accounts_clear_string_option(account_name, "otr.policy"); } void @@ -740,100 +720,67 @@ accounts_clear_omemo_state(const char* const account_name, const char* const con void accounts_set_muc_service(const char* const account_name, const char* const value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "muc.service", value); - _save_accounts(); - } + _accounts_set_string_option(account_name, "muc.service", value); } void accounts_set_muc_nick(const char* const account_name, const char* const value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "muc.nick", value); - _save_accounts(); - } + _accounts_set_string_option(account_name, "muc.nick", value); } void accounts_set_otr_policy(const char* const account_name, const char* const value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "otr.policy", value); - _save_accounts(); - } + _accounts_set_string_option(account_name, "otr.policy", value); } void accounts_set_omemo_policy(const char* const account_name, const char* const value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "omemo.policy", value); - _save_accounts(); - } + _accounts_set_string_option(account_name, "omemo.policy", value); } void accounts_set_tls_policy(const char* const account_name, const char* const value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "tls.policy", value); - _save_accounts(); - } + _accounts_set_string_option(account_name, "tls.policy", value); } void accounts_set_auth_policy(const char* const account_name, const char* const value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "auth.policy", value); - _save_accounts(); - } + _accounts_set_string_option(account_name, "auth.policy", value); } void accounts_set_priority_online(const char* const account_name, const gint value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_integer(accounts, account_name, "priority.online", value); - _save_accounts(); - } + _accounts_set_int_option(account_name, "priority.online", value); } void accounts_set_priority_chat(const char* const account_name, const gint value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_integer(accounts, account_name, "priority.chat", value); - _save_accounts(); - } + _accounts_set_int_option(account_name, "priority.chat", value); } void accounts_set_priority_away(const char* const account_name, const gint value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_integer(accounts, account_name, "priority.away", value); - _save_accounts(); - } + _accounts_set_int_option(account_name, "priority.away", value); } void accounts_set_priority_xa(const char* const account_name, const gint value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_integer(accounts, account_name, "priority.xa", value); - _save_accounts(); - } + _accounts_set_int_option(account_name, "priority.xa", value); } void accounts_set_priority_dnd(const char* const account_name, const gint value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_integer(accounts, account_name, "priority.dnd", value); - _save_accounts(); - } + _accounts_set_int_option(account_name, "priority.dnd", value); } void @@ -845,7 +792,6 @@ accounts_set_priority_all(const char* const account_name, const gint value) accounts_set_priority_away(account_name, value); accounts_set_priority_xa(account_name, value); accounts_set_priority_dnd(account_name, value); - _save_accounts(); } } @@ -882,21 +828,13 @@ accounts_get_priority_for_presence_type(const char* const account_name, void accounts_set_last_presence(const char* const account_name, const char* const value) { - if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, "presence.last", value); - _save_accounts(); - } + _accounts_set_string_option(account_name, "presence.last", value); } void accounts_set_last_status(const char* const account_name, const char* const value) { - if (accounts_account_exists(account_name)) { - if (value) { - g_key_file_set_string(accounts, account_name, "presence.laststatus", value); - } - _save_accounts(); - } + _accounts_set_string_option(account_name, "presence.laststatus", value); } void -- cgit 1.4.1-2-gfad0 From b3b76d9f5c36fc96e91cd170f6994215cb4ef146 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 29 Jun 2022 12:31:06 +0200 Subject: stanza: remove strange assignment --- src/xmpp/stanza.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 8dcad982..c6bf19fb 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -2635,7 +2635,7 @@ stanza_create_avatar_data_publish_iq(xmpp_ctx_t* ctx, const char* img_data, gsiz xmpp_stanza_t* stanza_create_avatar_metadata_publish_iq(xmpp_ctx_t* ctx, const char* img_data, gsize len, int height, int width) { - char* id = id = connection_create_stanza_id(); + char* id = connection_create_stanza_id(); xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_SET, id); free(id); xmpp_stanza_set_attribute(iq, STANZA_ATTR_FROM, connection_get_fulljid()); -- cgit 1.4.1-2-gfad0 1'>391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659