mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Merge branch 'master' into plugins
This commit is contained in:
commit
ff663f5f9c
@ -40,6 +40,7 @@ core_sources = \
|
||||
src/tools/p_sha1.h src/tools/p_sha1.c \
|
||||
src/tools/autocomplete.c src/tools/autocomplete.h \
|
||||
src/tools/tinyurl.c src/tools/tinyurl.h \
|
||||
src/config/files.c src/config/files.h \
|
||||
src/config/conflists.c src/config/conflists.h \
|
||||
src/config/accounts.c src/config/accounts.h \
|
||||
src/config/tlscerts.c src/config/tlscerts.h \
|
||||
@ -78,6 +79,7 @@ unittest_sources = \
|
||||
src/tools/tinyurl.c src/tools/tinyurl.h \
|
||||
src/config/accounts.h \
|
||||
src/config/account.c src/config/account.h \
|
||||
src/config/files.c src/config/files.h \
|
||||
src/config/tlscerts.c src/config/tlscerts.h \
|
||||
src/config/preferences.c src/config/preferences.h \
|
||||
src/config/theme.c src/config/theme.h \
|
||||
|
182
src/common.c
182
src/common.c
@ -285,7 +285,7 @@ utf8_display_len(const char *const str)
|
||||
}
|
||||
|
||||
char*
|
||||
prof_getline(FILE *stream)
|
||||
file_getline(FILE *stream)
|
||||
{
|
||||
char *buf;
|
||||
char *result;
|
||||
@ -380,113 +380,6 @@ release_is_new(char *found_version)
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
valid_resource_presence_string(const char *const str)
|
||||
{
|
||||
assert(str != NULL);
|
||||
if ((strcmp(str, "online") == 0) || (strcmp(str, "chat") == 0) ||
|
||||
(strcmp(str, "away") == 0) || (strcmp(str, "xa") == 0) ||
|
||||
(strcmp(str, "dnd") == 0)) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
string_from_resource_presence(resource_presence_t presence)
|
||||
{
|
||||
switch(presence)
|
||||
{
|
||||
case RESOURCE_CHAT:
|
||||
return "chat";
|
||||
case RESOURCE_AWAY:
|
||||
return "away";
|
||||
case RESOURCE_XA:
|
||||
return "xa";
|
||||
case RESOURCE_DND:
|
||||
return "dnd";
|
||||
default:
|
||||
return "online";
|
||||
}
|
||||
}
|
||||
|
||||
resource_presence_t
|
||||
resource_presence_from_string(const char *const str)
|
||||
{
|
||||
if (str == NULL) {
|
||||
return RESOURCE_ONLINE;
|
||||
} else if (strcmp(str, "online") == 0) {
|
||||
return RESOURCE_ONLINE;
|
||||
} else if (strcmp(str, "chat") == 0) {
|
||||
return RESOURCE_CHAT;
|
||||
} else if (strcmp(str, "away") == 0) {
|
||||
return RESOURCE_AWAY;
|
||||
} else if (strcmp(str, "xa") == 0) {
|
||||
return RESOURCE_XA;
|
||||
} else if (strcmp(str, "dnd") == 0) {
|
||||
return RESOURCE_DND;
|
||||
} else {
|
||||
return RESOURCE_ONLINE;
|
||||
}
|
||||
}
|
||||
|
||||
contact_presence_t
|
||||
contact_presence_from_resource_presence(resource_presence_t resource_presence)
|
||||
{
|
||||
switch(resource_presence)
|
||||
{
|
||||
case RESOURCE_CHAT:
|
||||
return CONTACT_CHAT;
|
||||
case RESOURCE_AWAY:
|
||||
return CONTACT_AWAY;
|
||||
case RESOURCE_XA:
|
||||
return CONTACT_XA;
|
||||
case RESOURCE_DND:
|
||||
return CONTACT_DND;
|
||||
default:
|
||||
return CONTACT_ONLINE;
|
||||
}
|
||||
}
|
||||
|
||||
gchar*
|
||||
xdg_get_config_home(void)
|
||||
{
|
||||
gchar *xdg_config_home = getenv("XDG_CONFIG_HOME");
|
||||
if (xdg_config_home)
|
||||
g_strstrip(xdg_config_home);
|
||||
|
||||
if (xdg_config_home && (strcmp(xdg_config_home, "") != 0)) {
|
||||
return strdup(xdg_config_home);
|
||||
} else {
|
||||
GString *default_path = g_string_new(getenv("HOME"));
|
||||
g_string_append(default_path, "/.config");
|
||||
gchar *result = strdup(default_path->str);
|
||||
g_string_free(default_path, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
gchar*
|
||||
xdg_get_data_home(void)
|
||||
{
|
||||
gchar *xdg_data_home = getenv("XDG_DATA_HOME");
|
||||
if (xdg_data_home)
|
||||
g_strstrip(xdg_data_home);
|
||||
|
||||
if (xdg_data_home && (strcmp(xdg_data_home, "") != 0)) {
|
||||
return strdup(xdg_data_home);
|
||||
} else {
|
||||
GString *default_path = g_string_new(getenv("HOME"));
|
||||
g_string_append(default_path, "/.local/share");
|
||||
gchar *result = strdup(default_path->str);
|
||||
g_string_free(default_path, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
char*
|
||||
create_unique_id(char *prefix)
|
||||
{
|
||||
@ -527,79 +420,6 @@ p_sha1_hash(char *str)
|
||||
return g_base64_encode(digest, sizeof(digest));
|
||||
}
|
||||
|
||||
int
|
||||
cmp_win_num(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
int real_a = GPOINTER_TO_INT(a);
|
||||
int real_b = GPOINTER_TO_INT(b);
|
||||
|
||||
if (real_a == 0) {
|
||||
real_a = 10;
|
||||
}
|
||||
|
||||
if (real_b == 0) {
|
||||
real_b = 10;
|
||||
}
|
||||
|
||||
if (real_a < real_b) {
|
||||
return -1;
|
||||
} else if (real_a == real_b) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
get_next_available_win_num(GList *used)
|
||||
{
|
||||
// only console used
|
||||
if (g_list_length(used) == 1) {
|
||||
return 2;
|
||||
} else {
|
||||
GList *sorted = NULL;
|
||||
GList *curr = used;
|
||||
while (curr) {
|
||||
sorted = g_list_insert_sorted(sorted, curr->data, cmp_win_num);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
int last_num = 1;
|
||||
curr = sorted;
|
||||
// skip console
|
||||
curr = g_list_next(curr);
|
||||
while (curr) {
|
||||
int curr_num = GPOINTER_TO_INT(curr->data);
|
||||
|
||||
if (((last_num != 9) && ((last_num + 1) != curr_num)) ||
|
||||
((last_num == 9) && (curr_num != 0))) {
|
||||
result = last_num + 1;
|
||||
if (result == 10) {
|
||||
result = 0;
|
||||
}
|
||||
g_list_free(sorted);
|
||||
return (result);
|
||||
|
||||
} else {
|
||||
last_num = curr_num;
|
||||
if (last_num == 0) {
|
||||
last_num = 10;
|
||||
}
|
||||
}
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
result = last_num + 1;
|
||||
if (result == 10) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
g_list_free(sorted);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static size_t
|
||||
_data_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
{
|
||||
|
13
src/common.h
13
src/common.h
@ -107,24 +107,15 @@ char* str_replace(const char *string, const char *substr, const char *replacemen
|
||||
int str_contains(const char str[], int size, char ch);
|
||||
gboolean strtoi_range(char *str, int *saveptr, int min, int max, char **err_msg);
|
||||
int utf8_display_len(const char *const str);
|
||||
char* prof_getline(FILE *stream);
|
||||
char* file_getline(FILE *stream);
|
||||
|
||||
char* release_get_latest(void);
|
||||
gboolean release_is_new(char *found_version);
|
||||
gchar* xdg_get_config_home(void);
|
||||
gchar* xdg_get_data_home(void);
|
||||
|
||||
gboolean valid_resource_presence_string(const char *const str);
|
||||
const char* string_from_resource_presence(resource_presence_t presence);
|
||||
resource_presence_t resource_presence_from_string(const char *const str);
|
||||
contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence);
|
||||
|
||||
char* p_sha1_hash(char *str);
|
||||
char* create_unique_id(char *prefix);
|
||||
void reset_unique_id(void);
|
||||
|
||||
int cmp_win_num(gconstpointer a, gconstpointer b);
|
||||
int get_next_available_win_num(GList *used);
|
||||
|
||||
char* get_file_or_linked(char *loc, char *basedir);
|
||||
char* strip_arg_quotes(const char *const input);
|
||||
gboolean is_notify_enabled(void);
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "log.h"
|
||||
#include "config/account.h"
|
||||
#include "xmpp/jid.h"
|
||||
#include "xmpp/resource.h"
|
||||
|
||||
ProfAccount*
|
||||
account_new(const gchar *const name, const gchar *const jid,
|
||||
|
@ -42,20 +42,20 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
#include "config/files.h"
|
||||
#include "config/account.h"
|
||||
#include "config/conflists.h"
|
||||
#include "tools/autocomplete.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "xmpp/jid.h"
|
||||
|
||||
static gchar *accounts_loc;
|
||||
static char *accounts_loc;
|
||||
static GKeyFile *accounts;
|
||||
|
||||
static Autocomplete all_ac;
|
||||
static Autocomplete enabled_ac;
|
||||
|
||||
static void _save_accounts(void);
|
||||
static gchar* _get_accounts_file(void);
|
||||
|
||||
void
|
||||
accounts_load(void)
|
||||
@ -63,7 +63,7 @@ accounts_load(void)
|
||||
log_info("Loading accounts");
|
||||
all_ac = autocomplete_new();
|
||||
enabled_ac = autocomplete_new();
|
||||
accounts_loc = _get_accounts_file();
|
||||
accounts_loc = files_get_data_path(FILE_ACCOUNTS);
|
||||
|
||||
if (g_file_test(accounts_loc, G_FILE_TEST_EXISTS)) {
|
||||
g_chmod(accounts_loc, S_IRUSR | S_IWUSR);
|
||||
@ -857,27 +857,13 @@ _save_accounts(void)
|
||||
{
|
||||
gsize g_data_size;
|
||||
gchar *g_accounts_data = g_key_file_to_data(accounts, &g_data_size, NULL);
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
GString *base_str = g_string_new(xdg_data);
|
||||
g_string_append(base_str, "/profanity/");
|
||||
gchar *true_loc = get_file_or_linked(accounts_loc, base_str->str);
|
||||
|
||||
gchar *base = g_path_get_basename(accounts_loc);
|
||||
gchar *true_loc = get_file_or_linked(accounts_loc, base);
|
||||
g_file_set_contents(true_loc, g_accounts_data, g_data_size, NULL);
|
||||
g_chmod(accounts_loc, S_IRUSR | S_IWUSR);
|
||||
g_free(xdg_data);
|
||||
|
||||
g_free(base);
|
||||
free(true_loc);
|
||||
g_free(g_accounts_data);
|
||||
g_string_free(base_str, TRUE);
|
||||
}
|
||||
|
||||
static gchar*
|
||||
_get_accounts_file(void)
|
||||
{
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
GString *logfile = g_string_new(xdg_data);
|
||||
g_string_append(logfile, "/profanity/accounts");
|
||||
gchar *result = strdup(logfile->str);
|
||||
g_free(xdg_data);
|
||||
g_string_free(logfile, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
194
src/config/files.c
Normal file
194
src/config/files.c
Normal file
@ -0,0 +1,194 @@
|
||||
/*
|
||||
* files.c
|
||||
*
|
||||
* Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* This file is part of Profanity.
|
||||
*
|
||||
* Profanity is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Profanity is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link the code of portions of this program with the OpenSSL library under
|
||||
* certain conditions as described in each individual source file, and
|
||||
* distribute linked combinations including the two.
|
||||
*
|
||||
* You must obey the GNU General Public License in all respects for all of the
|
||||
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
||||
* may extend this exception to your version of the file(s), but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version. If you delete this exception statement from all
|
||||
* source files in the program, then also delete it here.
|
||||
*
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
#include "config/files.h"
|
||||
#include "config/preferences.h"
|
||||
|
||||
static char* _files_get_xdg_config_home(void);
|
||||
static char* _files_get_xdg_data_home(void);
|
||||
|
||||
void
|
||||
files_create_directories(void)
|
||||
{
|
||||
gchar *xdg_config = _files_get_xdg_config_home();
|
||||
gchar *xdg_data = _files_get_xdg_data_home();
|
||||
|
||||
GString *themes_dir = g_string_new(xdg_config);
|
||||
g_string_append(themes_dir, "/profanity/themes");
|
||||
GString *icons_dir = g_string_new(xdg_config);
|
||||
g_string_append(icons_dir, "/profanity/icons");
|
||||
GString *chatlogs_dir = g_string_new(xdg_data);
|
||||
g_string_append(chatlogs_dir, "/profanity/chatlogs");
|
||||
GString *logs_dir = g_string_new(xdg_data);
|
||||
g_string_append(logs_dir, "/profanity/logs");
|
||||
GString *plugins_dir = g_string_new(xdg_data);
|
||||
g_string_append(plugins_dir, "/profanity/plugins");
|
||||
|
||||
if (!mkdir_recursive(themes_dir->str)) {
|
||||
log_error("Error while creating directory %s", themes_dir->str);
|
||||
}
|
||||
if (!mkdir_recursive(icons_dir->str)) {
|
||||
log_error("Error while creating directory %s", icons_dir->str);
|
||||
}
|
||||
if (!mkdir_recursive(chatlogs_dir->str)) {
|
||||
log_error("Error while creating directory %s", chatlogs_dir->str);
|
||||
}
|
||||
if (!mkdir_recursive(logs_dir->str)) {
|
||||
log_error("Error while creating directory %s", logs_dir->str);
|
||||
}
|
||||
if (!mkdir_recursive(plugins_dir->str)) {
|
||||
log_error("Error while creating directory %s", plugins_dir->str);
|
||||
}
|
||||
|
||||
g_string_free(themes_dir, TRUE);
|
||||
g_string_free(icons_dir, TRUE);
|
||||
g_string_free(chatlogs_dir, TRUE);
|
||||
g_string_free(logs_dir, TRUE);
|
||||
g_string_free(plugins_dir, TRUE);
|
||||
|
||||
g_free(xdg_config);
|
||||
g_free(xdg_data);
|
||||
}
|
||||
|
||||
char*
|
||||
files_get_inputrc_file(void)
|
||||
{
|
||||
gchar *xdg_config = _files_get_xdg_config_home();
|
||||
GString *inputrc_file = g_string_new(xdg_config);
|
||||
g_free(xdg_config);
|
||||
|
||||
g_string_append(inputrc_file, "/profanity/inputrc");
|
||||
|
||||
if (g_file_test(inputrc_file->str, G_FILE_TEST_IS_REGULAR)) {
|
||||
char *result = strdup(inputrc_file->str);
|
||||
g_string_free(inputrc_file, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
g_string_free(inputrc_file, TRUE);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char*
|
||||
files_get_log_file(void)
|
||||
{
|
||||
gchar *xdg_data = _files_get_xdg_data_home();
|
||||
GString *logfile = g_string_new(xdg_data);
|
||||
g_string_append(logfile, "/profanity/logs/profanity");
|
||||
if (!prefs_get_boolean(PREF_LOG_SHARED)) {
|
||||
g_string_append_printf(logfile, "%d", getpid());
|
||||
}
|
||||
g_string_append(logfile, ".log");
|
||||
char *result = strdup(logfile->str);
|
||||
free(xdg_data);
|
||||
g_string_free(logfile, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
char*
|
||||
files_get_config_path(char *config_base)
|
||||
{
|
||||
gchar *xdg_config = _files_get_xdg_config_home();
|
||||
GString *file_str = g_string_new(xdg_config);
|
||||
g_string_append(file_str, "/profanity/");
|
||||
g_string_append(file_str, config_base);
|
||||
char *result = strdup(file_str->str);
|
||||
g_free(xdg_config);
|
||||
g_string_free(file_str, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
char*
|
||||
files_get_data_path(char *data_base)
|
||||
{
|
||||
gchar *xdg_data = _files_get_xdg_data_home();
|
||||
GString *file_str = g_string_new(xdg_data);
|
||||
g_string_append(file_str, "/profanity/");
|
||||
g_string_append(file_str, data_base);
|
||||
char *result = strdup(file_str->str);
|
||||
g_free(xdg_data);
|
||||
g_string_free(file_str, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static char*
|
||||
_files_get_xdg_config_home(void)
|
||||
{
|
||||
gchar *xdg_config_home = getenv("XDG_CONFIG_HOME");
|
||||
if (xdg_config_home)
|
||||
g_strstrip(xdg_config_home);
|
||||
|
||||
if (xdg_config_home && (strcmp(xdg_config_home, "") != 0)) {
|
||||
return strdup(xdg_config_home);
|
||||
} else {
|
||||
GString *default_path = g_string_new(getenv("HOME"));
|
||||
g_string_append(default_path, "/.config");
|
||||
char *result = strdup(default_path->str);
|
||||
g_string_free(default_path, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
static char*
|
||||
_files_get_xdg_data_home(void)
|
||||
{
|
||||
gchar *xdg_data_home = getenv("XDG_DATA_HOME");
|
||||
if (xdg_data_home)
|
||||
g_strstrip(xdg_data_home);
|
||||
|
||||
if (xdg_data_home && (strcmp(xdg_data_home, "") != 0)) {
|
||||
return strdup(xdg_data_home);
|
||||
} else {
|
||||
GString *default_path = g_string_new(getenv("HOME"));
|
||||
g_string_append(default_path, "/.local/share");
|
||||
gchar *result = strdup(default_path->str);
|
||||
g_string_free(default_path, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
63
src/config/files.h
Normal file
63
src/config/files.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* files.h
|
||||
*
|
||||
* Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* This file is part of Profanity.
|
||||
*
|
||||
* Profanity is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Profanity is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link the code of portions of this program with the OpenSSL library under
|
||||
* certain conditions as described in each individual source file, and
|
||||
* distribute linked combinations including the two.
|
||||
*
|
||||
* You must obey the GNU General Public License in all respects for all of the
|
||||
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
||||
* may extend this exception to your version of the file(s), but you are not
|
||||
* obligated to do so. If you do not wish to do so, delete this exception
|
||||
* statement from your version. If you delete this exception statement from all
|
||||
* source files in the program, then also delete it here.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_FILES_H
|
||||
#define CONFIG_FILES_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#define FILE_PROFRC "profrc"
|
||||
#define FILE_ACCOUNTS "accounts"
|
||||
#define FILE_TLSCERTS "tlscerts"
|
||||
#define FILE_PLUGIN_SETTINGS "plugin_settings"
|
||||
#define FILE_PLUGIN_THEMES "plugin_themes"
|
||||
#define FILE_CAPSCACHE "capscache"
|
||||
|
||||
#define DIR_THEMES "themes"
|
||||
#define DIR_ICONS "icons"
|
||||
#define DIR_SCRIPTS "scripts"
|
||||
#define DIR_CHATLOGS "chatlogs"
|
||||
#define DIR_OTR "otr"
|
||||
#define DIR_PGP "pgp"
|
||||
#define DIR_PLUGINS "plugins"
|
||||
|
||||
void files_create_directories(void);
|
||||
|
||||
char* files_get_config_path(char *config_base);
|
||||
char* files_get_data_path(char *data_base);
|
||||
|
||||
char* files_get_log_file(void);
|
||||
char* files_get_inputrc_file(void);
|
||||
|
||||
#endif
|
@ -45,6 +45,7 @@
|
||||
#include "log.h"
|
||||
#include "preferences.h"
|
||||
#include "tools/autocomplete.h"
|
||||
#include "config/files.h"
|
||||
#include "config/conflists.h"
|
||||
|
||||
// preference groups refer to the sections in .profrc, for example [ui]
|
||||
@ -61,7 +62,7 @@
|
||||
|
||||
#define INPBLOCK_DEFAULT 1000
|
||||
|
||||
static gchar *prefs_loc;
|
||||
static char *prefs_loc;
|
||||
static GKeyFile *prefs;
|
||||
gint log_maxsize = 0;
|
||||
|
||||
@ -69,7 +70,6 @@ static Autocomplete boolean_choice_ac;
|
||||
static Autocomplete room_trigger_ac;
|
||||
|
||||
static void _save_prefs(void);
|
||||
static gchar* _get_preferences_file(void);
|
||||
static const char* _get_group(preference_t pref);
|
||||
static const char* _get_key(preference_t pref);
|
||||
static gboolean _get_default_boolean(preference_t pref);
|
||||
@ -79,7 +79,7 @@ void
|
||||
prefs_load(void)
|
||||
{
|
||||
GError *err;
|
||||
prefs_loc = _get_preferences_file();
|
||||
prefs_loc = files_get_config_path(FILE_PROFRC);
|
||||
|
||||
if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
|
||||
g_chmod(prefs_loc, S_IRUSR | S_IWUSR);
|
||||
@ -1120,27 +1120,6 @@ prefs_get_aliases(void)
|
||||
}
|
||||
}
|
||||
|
||||
gchar*
|
||||
prefs_get_inputrc(void)
|
||||
{
|
||||
gchar *xdg_config = xdg_get_config_home();
|
||||
GString *inputrc_file = g_string_new(xdg_config);
|
||||
g_free(xdg_config);
|
||||
|
||||
g_string_append(inputrc_file, "/profanity/inputrc");
|
||||
|
||||
if (g_file_test(inputrc_file->str, G_FILE_TEST_IS_REGULAR)) {
|
||||
gchar *result = strdup(inputrc_file->str);
|
||||
g_string_free(inputrc_file, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
g_string_free(inputrc_file, TRUE);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
_free_alias(ProfAlias *alias)
|
||||
{
|
||||
@ -1160,29 +1139,15 @@ _save_prefs(void)
|
||||
{
|
||||
gsize g_data_size;
|
||||
gchar *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL);
|
||||
gchar *xdg_config = xdg_get_config_home();
|
||||
GString *base_str = g_string_new(xdg_config);
|
||||
g_string_append(base_str, "/profanity/");
|
||||
gchar *true_loc = get_file_or_linked(prefs_loc, base_str->str);
|
||||
gchar *base = g_path_get_basename(prefs_loc);
|
||||
gchar *true_loc = get_file_or_linked(prefs_loc, base);
|
||||
|
||||
g_file_set_contents(true_loc, g_prefs_data, g_data_size, NULL);
|
||||
g_chmod(prefs_loc, S_IRUSR | S_IWUSR);
|
||||
g_free(xdg_config);
|
||||
|
||||
g_free(base);
|
||||
free(true_loc);
|
||||
g_free(g_prefs_data);
|
||||
g_string_free(base_str, TRUE);
|
||||
}
|
||||
|
||||
static gchar*
|
||||
_get_preferences_file(void)
|
||||
{
|
||||
gchar *xdg_config = xdg_get_config_home();
|
||||
GString *prefs_file = g_string_new(xdg_config);
|
||||
g_string_append(prefs_file, "/profanity/profrc");
|
||||
gchar *result = strdup(prefs_file->str);
|
||||
g_free(xdg_config);
|
||||
g_string_free(prefs_file, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// get the preference group for a specific preference
|
||||
|
@ -42,6 +42,7 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
#include "config/files.h"
|
||||
#include "command/cmd_defs.h"
|
||||
#include "ui/ui.h"
|
||||
#include "ui/window_list.h"
|
||||
@ -50,38 +51,31 @@
|
||||
void
|
||||
scripts_init(void)
|
||||
{
|
||||
gchar *data_home = xdg_get_data_home();
|
||||
GString *scriptsdir = g_string_new(data_home);
|
||||
free(data_home);
|
||||
|
||||
g_string_append(scriptsdir, "/profanity/scripts");
|
||||
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
|
||||
|
||||
// mkdir if doesn't exist
|
||||
errno = 0;
|
||||
int res = g_mkdir_with_parents(scriptsdir->str, S_IRWXU);
|
||||
int res = g_mkdir_with_parents(scriptsdir, S_IRWXU);
|
||||
if (res == -1) {
|
||||
char *errmsg = strerror(errno);
|
||||
if (errmsg) {
|
||||
log_error("Error creating directory: %s, %s", scriptsdir->str, errmsg);
|
||||
log_error("Error creating directory: %s, %s", scriptsdir, errmsg);
|
||||
} else {
|
||||
log_error("Error creating directory: %s", scriptsdir->str);
|
||||
log_error("Error creating directory: %s", scriptsdir);
|
||||
}
|
||||
}
|
||||
|
||||
g_string_free(scriptsdir, TRUE);
|
||||
free(scriptsdir);
|
||||
}
|
||||
|
||||
GSList*
|
||||
scripts_list(void)
|
||||
{
|
||||
gchar *data_home = xdg_get_data_home();
|
||||
GString *scriptsdir = g_string_new(data_home);
|
||||
free(data_home);
|
||||
g_string_append(scriptsdir, "/profanity/scripts");
|
||||
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
|
||||
|
||||
GSList *result = NULL;
|
||||
GDir *scripts = g_dir_open(scriptsdir->str, 0, NULL);
|
||||
g_string_free(scriptsdir, TRUE);
|
||||
GDir *scripts = g_dir_open(scriptsdir, 0, NULL);
|
||||
free(scriptsdir);
|
||||
|
||||
if (scripts) {
|
||||
const gchar *script = g_dir_read_name(scripts);
|
||||
@ -98,11 +92,10 @@ scripts_list(void)
|
||||
GSList*
|
||||
scripts_read(const char *const script)
|
||||
{
|
||||
gchar *data_home = xdg_get_data_home();
|
||||
GString *scriptpath = g_string_new(data_home);
|
||||
free(data_home);
|
||||
|
||||
g_string_append(scriptpath, "/profanity/scripts/");
|
||||
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
|
||||
GString *scriptpath = g_string_new(scriptsdir);
|
||||
free(scriptsdir);
|
||||
g_string_append(scriptpath, "/");
|
||||
g_string_append(scriptpath, script);
|
||||
|
||||
FILE *scriptfile = g_fopen(scriptpath->str, "r");
|
||||
@ -136,11 +129,10 @@ scripts_read(const char *const script)
|
||||
gboolean
|
||||
scripts_exec(const char *const script)
|
||||
{
|
||||
gchar *data_home = xdg_get_data_home();
|
||||
GString *scriptpath = g_string_new(data_home);
|
||||
free(data_home);
|
||||
|
||||
g_string_append(scriptpath, "/profanity/scripts/");
|
||||
char *scriptsdir = files_get_data_path(DIR_SCRIPTS);
|
||||
GString *scriptpath = g_string_new(scriptsdir);
|
||||
free(scriptsdir);
|
||||
g_string_append(scriptpath, "/");
|
||||
g_string_append(scriptpath, script);
|
||||
|
||||
FILE *scriptfile = g_fopen(scriptpath->str, "r");
|
||||
|
@ -47,8 +47,9 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
#include "theme.h"
|
||||
#include "preferences.h"
|
||||
#include "config/files.h"
|
||||
#include "config/theme.h"
|
||||
#include "config/preferences.h"
|
||||
|
||||
static GString *theme_loc;
|
||||
static GKeyFile *theme;
|
||||
@ -62,7 +63,6 @@ struct colour_string_t {
|
||||
};
|
||||
|
||||
static void _load_preferences(void);
|
||||
static gchar* _get_themes_dir(void);
|
||||
void _theme_list_dir(const gchar *const dir, GSList **result);
|
||||
static GString* _theme_find(const char *const theme_name);
|
||||
static gboolean _theme_load_file(const char *const theme_name);
|
||||
@ -217,7 +217,7 @@ GSList*
|
||||
theme_list(void)
|
||||
{
|
||||
GSList *result = NULL;
|
||||
char *themes_dir = _get_themes_dir();
|
||||
char *themes_dir = files_get_config_path(DIR_THEMES);
|
||||
_theme_list_dir(themes_dir, &result);
|
||||
free(themes_dir);
|
||||
#ifdef THEMES_PATH
|
||||
@ -531,16 +531,6 @@ _load_preferences(void)
|
||||
}
|
||||
}
|
||||
|
||||
static gchar*
|
||||
_get_themes_dir(void)
|
||||
{
|
||||
gchar *xdg_config = xdg_get_config_home();
|
||||
GString *themes_dir = g_string_new(xdg_config);
|
||||
g_free(xdg_config);
|
||||
g_string_append(themes_dir, "/profanity/themes");
|
||||
return g_string_free(themes_dir, FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
_theme_list_dir(const gchar *const dir, GSList **result)
|
||||
{
|
||||
@ -559,11 +549,11 @@ static GString*
|
||||
_theme_find(const char *const theme_name)
|
||||
{
|
||||
GString *path = NULL;
|
||||
gchar *themes_dir = _get_themes_dir();
|
||||
char *themes_dir = files_get_config_path(DIR_THEMES);
|
||||
|
||||
if (themes_dir) {
|
||||
path = g_string_new(themes_dir);
|
||||
g_free(themes_dir);
|
||||
free(themes_dir);
|
||||
g_string_append(path, "/");
|
||||
g_string_append(path, theme_name);
|
||||
if (!g_file_test(path->str, G_FILE_TEST_EXISTS)) {
|
||||
|
@ -40,13 +40,13 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "common.h"
|
||||
#include "config/files.h"
|
||||
#include "config/tlscerts.h"
|
||||
#include "tools/autocomplete.h"
|
||||
|
||||
static gchar *tlscerts_loc;
|
||||
static char *tlscerts_loc;
|
||||
static GKeyFile *tlscerts;
|
||||
|
||||
static gchar* _get_tlscerts_file(void);
|
||||
static void _save_tlscerts(void);
|
||||
|
||||
static Autocomplete certs_ac;
|
||||
@ -57,7 +57,7 @@ void
|
||||
tlscerts_init(void)
|
||||
{
|
||||
log_info("Loading TLS certificates");
|
||||
tlscerts_loc = _get_tlscerts_file();
|
||||
tlscerts_loc = files_get_data_path(FILE_TLSCERTS);
|
||||
|
||||
if (g_file_test(tlscerts_loc, G_FILE_TEST_EXISTS)) {
|
||||
g_chmod(tlscerts_loc, S_IRUSR | S_IWUSR);
|
||||
@ -428,19 +428,6 @@ tlscerts_close(void)
|
||||
autocomplete_free(certs_ac);
|
||||
}
|
||||
|
||||
static gchar*
|
||||
_get_tlscerts_file(void)
|
||||
{
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
GString *tlscerts_file = g_string_new(xdg_data);
|
||||
g_string_append(tlscerts_file, "/profanity/tlscerts");
|
||||
gchar *result = strdup(tlscerts_file->str);
|
||||
g_free(xdg_data);
|
||||
g_string_free(tlscerts_file, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
_save_tlscerts(void)
|
||||
{
|
||||
|
45
src/log.c
45
src/log.c
@ -45,6 +45,7 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "common.h"
|
||||
#include "config/files.h"
|
||||
#include "config/preferences.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
|
||||
@ -84,8 +85,6 @@ static gboolean _key_equals(void *key1, void *key2);
|
||||
static char* _get_log_filename(const char *const other, const char *const login, GDateTime *dt, gboolean create);
|
||||
static char* _get_groupchat_log_filename(const char *const room, const char *const login, GDateTime *dt,
|
||||
gboolean create);
|
||||
static gchar* _get_chatlog_dir(void);
|
||||
static gchar* _get_main_log_file(void);
|
||||
static void _rotate_log_file(void);
|
||||
static char* _log_string_from_level(log_level_t level);
|
||||
static void _chat_log_chat(const char *const login, const char *const other, const gchar *const msg,
|
||||
@ -144,7 +143,7 @@ log_init(log_level_t filter)
|
||||
{
|
||||
level_filter = filter;
|
||||
tz = g_time_zone_new_local();
|
||||
gchar *log_file = _get_main_log_file();
|
||||
char *log_file = files_get_log_file();
|
||||
logp = fopen(log_file, "a");
|
||||
g_chmod(log_file, S_IRUSR | S_IWUSR);
|
||||
mainlogfile = g_string_new(log_file);
|
||||
@ -225,7 +224,7 @@ log_level_from_string(char *log_level)
|
||||
static void
|
||||
_rotate_log_file(void)
|
||||
{
|
||||
gchar *log_file = _get_main_log_file();
|
||||
char *log_file = files_get_log_file();
|
||||
size_t len = strlen(log_file);
|
||||
char *log_file_new = malloc(len + 3);
|
||||
|
||||
@ -471,7 +470,7 @@ chat_log_get_previous(const gchar *const login, const gchar *const recipient)
|
||||
g_string_free(header, FALSE);
|
||||
|
||||
char *line;
|
||||
while ((line = prof_getline(logp)) != NULL) {
|
||||
while ((line = file_getline(logp)) != NULL) {
|
||||
history = g_slist_append(history, line);
|
||||
}
|
||||
|
||||
@ -571,7 +570,7 @@ gboolean _key_equals(void *key1, void *key2)
|
||||
static char*
|
||||
_get_log_filename(const char *const other, const char *const login, GDateTime *dt, gboolean create)
|
||||
{
|
||||
gchar *chatlogs_dir = _get_chatlog_dir();
|
||||
char *chatlogs_dir = files_get_data_path(DIR_CHATLOGS);
|
||||
GString *log_file = g_string_new(chatlogs_dir);
|
||||
free(chatlogs_dir);
|
||||
|
||||
@ -602,9 +601,9 @@ _get_log_filename(const char *const other, const char *const login, GDateTime *d
|
||||
static char*
|
||||
_get_groupchat_log_filename(const char *const room, const char *const login, GDateTime *dt, gboolean create)
|
||||
{
|
||||
gchar *chatlogs_dir = _get_chatlog_dir();
|
||||
char *chatlogs_dir = files_get_data_path(DIR_CHATLOGS);
|
||||
GString *log_file = g_string_new(chatlogs_dir);
|
||||
g_free(chatlogs_dir);
|
||||
free(chatlogs_dir);
|
||||
|
||||
gchar *login_dir = str_replace(login, "@", "_at_");
|
||||
g_string_append_printf(log_file, "/%s", login_dir);
|
||||
@ -635,36 +634,6 @@ _get_groupchat_log_filename(const char *const room, const char *const login, GDa
|
||||
return result;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
_get_chatlog_dir(void)
|
||||
{
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
GString *chatlogs_dir = g_string_new(xdg_data);
|
||||
g_string_append(chatlogs_dir, "/profanity/chatlogs");
|
||||
gchar *result = strdup(chatlogs_dir->str);
|
||||
free(xdg_data);
|
||||
g_string_free(chatlogs_dir, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
_get_main_log_file(void)
|
||||
{
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
GString *logfile = g_string_new(xdg_data);
|
||||
g_string_append(logfile, "/profanity/logs/profanity");
|
||||
if (!prefs_get_boolean(PREF_LOG_SHARED)) {
|
||||
g_string_append_printf(logfile, "%d", getpid());
|
||||
}
|
||||
g_string_append(logfile, ".log");
|
||||
gchar *result = strdup(logfile->str);
|
||||
free(xdg_data);
|
||||
g_string_free(logfile, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static char*
|
||||
_log_string_from_level(log_level_t level)
|
||||
{
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "config/preferences.h"
|
||||
#include "config/files.h"
|
||||
#include "otr/otr.h"
|
||||
#include "otr/otrlib.h"
|
||||
#include "ui/ui.h"
|
||||
@ -125,12 +126,11 @@ cb_write_fingerprints(void *opdata)
|
||||
{
|
||||
gcry_error_t err = 0;
|
||||
|
||||
gchar *data_home = xdg_get_data_home();
|
||||
GString *basedir = g_string_new(data_home);
|
||||
free(data_home);
|
||||
|
||||
char *otrdir = files_get_data_path(DIR_OTR);
|
||||
GString *basedir = g_string_new(otrdir);
|
||||
free(otrdir);
|
||||
gchar *account_dir = str_replace(jid, "@", "_at_");
|
||||
g_string_append(basedir, "/profanity/otr/");
|
||||
g_string_append(basedir, "/");
|
||||
g_string_append(basedir, account_dir);
|
||||
g_string_append(basedir, "/");
|
||||
free(account_dir);
|
||||
@ -214,12 +214,11 @@ otr_on_connect(ProfAccount *account)
|
||||
jid = strdup(account->jid);
|
||||
log_info("Loading OTR key for %s", jid);
|
||||
|
||||
gchar *data_home = xdg_get_data_home();
|
||||
GString *basedir = g_string_new(data_home);
|
||||
free(data_home);
|
||||
|
||||
char *otrdir = files_get_data_path(DIR_OTR);
|
||||
GString *basedir = g_string_new(otrdir);
|
||||
free(otrdir);
|
||||
gchar *account_dir = str_replace(jid, "@", "_at_");
|
||||
g_string_append(basedir, "/profanity/otr/");
|
||||
g_string_append(basedir, "/");
|
||||
g_string_append(basedir, account_dir);
|
||||
g_string_append(basedir, "/");
|
||||
free(account_dir);
|
||||
@ -392,12 +391,11 @@ otr_keygen(ProfAccount *account)
|
||||
jid = strdup(account->jid);
|
||||
log_info("Generating OTR key for %s", jid);
|
||||
|
||||
gchar *data_home = xdg_get_data_home();
|
||||
GString *basedir = g_string_new(data_home);
|
||||
free(data_home);
|
||||
|
||||
char *otrdir = files_get_data_path(DIR_OTR);
|
||||
GString *basedir = g_string_new(otrdir);
|
||||
free(otrdir);
|
||||
gchar *account_dir = str_replace(jid, "@", "_at_");
|
||||
g_string_append(basedir, "/profanity/otr/");
|
||||
g_string_append(basedir, "/");
|
||||
g_string_append(basedir, account_dir);
|
||||
g_string_append(basedir, "/");
|
||||
free(account_dir);
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "log.h"
|
||||
#include "common.h"
|
||||
#include "pgp/gpg.h"
|
||||
#include "config/files.h"
|
||||
#include "tools/autocomplete.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
@ -156,12 +157,10 @@ p_gpg_close(void)
|
||||
void
|
||||
p_gpg_on_connect(const char *const barejid)
|
||||
{
|
||||
gchar *data_home = xdg_get_data_home();
|
||||
GString *pubsfile = g_string_new(data_home);
|
||||
free(data_home);
|
||||
|
||||
char *pgpdir = files_get_data_path(DIR_PGP);
|
||||
GString *pubsfile = g_string_new(pgpdir);
|
||||
gchar *account_dir = str_replace(barejid, "@", "_at_");
|
||||
g_string_append(pubsfile, "/profanity/pgp/");
|
||||
g_string_append(pubsfile, "/");
|
||||
g_string_append(pubsfile, account_dir);
|
||||
free(account_dir);
|
||||
|
||||
|
@ -218,7 +218,6 @@ static void
|
||||
c_api_win_create(const char *filename, char *tag, void(*callback)(char *tag, char *line))
|
||||
{
|
||||
char *plugin_name = _c_plugin_name(filename);
|
||||
log_debug("Win create %s for %s", tag, plugin_name);
|
||||
|
||||
WindowWrapper *wrapper = malloc(sizeof(WindowWrapper));
|
||||
wrapper->func = callback;
|
||||
|
@ -41,6 +41,7 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "config/preferences.h"
|
||||
#include "config/files.h"
|
||||
#include "plugins/api.h"
|
||||
#include "plugins/callbacks.h"
|
||||
#include "plugins/plugins.h"
|
||||
@ -60,9 +61,9 @@ c_plugin_create(const char *const filename)
|
||||
ProfPlugin *plugin;
|
||||
void *handle = NULL;
|
||||
|
||||
gchar *plugins_dir = plugins_get_dir();
|
||||
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
|
||||
GString *path = g_string_new(plugins_dir);
|
||||
g_free(plugins_dir);
|
||||
free(plugins_dir);
|
||||
g_string_append(path, "/");
|
||||
g_string_append(path, filename);
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "log.h"
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
#include "config/files.h"
|
||||
#include "config/preferences.h"
|
||||
#include "plugins/callbacks.h"
|
||||
#include "plugins/autocompleters.h"
|
||||
@ -164,7 +165,7 @@ plugins_init(void)
|
||||
gboolean
|
||||
plugins_install(const char *const plugin_name, const char *const filename)
|
||||
{
|
||||
char *plugins_dir = plugins_get_dir();
|
||||
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
|
||||
GString *target_path = g_string_new(plugins_dir);
|
||||
free(plugins_dir);
|
||||
g_string_append(target_path, "/");
|
||||
@ -299,7 +300,7 @@ GSList*
|
||||
plugins_unloaded_list(void)
|
||||
{
|
||||
GSList *result = NULL;
|
||||
char *plugins_dir = plugins_get_dir();
|
||||
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
|
||||
_plugins_unloaded_list_dir(plugins_dir, &result);
|
||||
free(plugins_dir);
|
||||
|
||||
@ -879,16 +880,3 @@ plugins_shutdown(void)
|
||||
callbacks_close();
|
||||
disco_close();
|
||||
}
|
||||
|
||||
char*
|
||||
plugins_get_dir(void)
|
||||
{
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
GString *plugins_dir = g_string_new(xdg_data);
|
||||
g_string_append(plugins_dir, "/profanity/plugins");
|
||||
char *result = strdup(plugins_dir->str);
|
||||
g_free(xdg_data);
|
||||
g_string_free(plugins_dir, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -540,7 +540,6 @@ python_api_win_create(PyObject *self, PyObject *args)
|
||||
char *tag_str = python_str_or_unicode_to_string(tag);
|
||||
|
||||
char *plugin_name = _python_plugin_name();
|
||||
log_debug("Win create %s for %s", tag_str, plugin_name);
|
||||
|
||||
if (p_callback && PyCallable_Check(p_callback)) {
|
||||
allow_python_threads();
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "config/preferences.h"
|
||||
#include "config/files.h"
|
||||
#include "plugins/api.h"
|
||||
#include "plugins/callbacks.h"
|
||||
#include "plugins/plugins.h"
|
||||
@ -77,7 +78,7 @@ python_env_init(void)
|
||||
|
||||
python_init_prof();
|
||||
|
||||
gchar *plugins_dir = plugins_get_dir();
|
||||
char *plugins_dir = files_get_data_path(DIR_PLUGINS);
|
||||
GString *path = g_string_new("import sys\n");
|
||||
g_string_append(path, "sys.path.append(\"");
|
||||
g_string_append(path, plugins_dir);
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "config/theme.h"
|
||||
#include "config/files.h"
|
||||
|
||||
static GKeyFile *settings;
|
||||
|
||||
@ -48,24 +49,21 @@ static void _save_settings(void);
|
||||
void
|
||||
plugin_settings_init(void)
|
||||
{
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
GString *fileloc = g_string_new(xdg_data);
|
||||
g_string_append(fileloc, "/profanity/plugin_settings");
|
||||
g_free(xdg_data);
|
||||
char *settings_file = files_get_data_path(FILE_PLUGIN_SETTINGS);
|
||||
|
||||
if (g_file_test(fileloc->str, G_FILE_TEST_EXISTS)) {
|
||||
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
|
||||
if (g_file_test(settings_file, G_FILE_TEST_EXISTS)) {
|
||||
g_chmod(settings_file, S_IRUSR | S_IWUSR);
|
||||
}
|
||||
|
||||
settings = g_key_file_new();
|
||||
g_key_file_load_from_file(settings, fileloc->str, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
||||
g_key_file_load_from_file(settings, settings_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
||||
|
||||
gsize g_data_size;
|
||||
gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL);
|
||||
g_file_set_contents(fileloc->str, g_data, g_data_size, NULL);
|
||||
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
|
||||
g_file_set_contents(settings_file, g_data, g_data_size, NULL);
|
||||
g_chmod(settings_file, S_IRUSR | S_IWUSR);
|
||||
g_free(g_data);
|
||||
g_string_free(fileloc, TRUE);
|
||||
free(settings_file);
|
||||
}
|
||||
|
||||
void
|
||||
@ -134,19 +132,13 @@ _save_settings(void)
|
||||
gsize g_data_size;
|
||||
gchar *g_data = g_key_file_to_data(settings, &g_data_size, NULL);
|
||||
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
GString *fileloc = g_string_new(xdg_data);
|
||||
g_free(xdg_data);
|
||||
|
||||
g_string_append(fileloc, "/profanity/");
|
||||
char *base = strdup(fileloc->str);
|
||||
g_string_append(fileloc, "plugin_settings");
|
||||
|
||||
gchar *true_loc = get_file_or_linked(fileloc->str, base);
|
||||
free(base);
|
||||
char *fileloc = files_get_data_path(FILE_PLUGIN_SETTINGS);
|
||||
gchar *base = g_path_get_basename(fileloc);
|
||||
gchar *true_loc = get_file_or_linked(fileloc, base);
|
||||
g_free(base);
|
||||
g_file_set_contents(true_loc, g_data, g_data_size, NULL);
|
||||
free(true_loc);
|
||||
g_free(g_data);
|
||||
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
|
||||
g_string_free(fileloc, TRUE);
|
||||
g_chmod(fileloc, S_IRUSR | S_IWUSR);
|
||||
free(fileloc);
|
||||
}
|
||||
|
@ -32,35 +32,35 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "config/theme.h"
|
||||
#include "config/files.h"
|
||||
|
||||
static GKeyFile *themes;
|
||||
|
||||
void
|
||||
plugin_themes_init(void)
|
||||
{
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
GString *fileloc = g_string_new(xdg_data);
|
||||
g_string_append(fileloc, "/profanity/plugin_themes");
|
||||
g_free(xdg_data);
|
||||
char *themes_file = files_get_data_path(FILE_PLUGIN_THEMES);
|
||||
|
||||
if (g_file_test(fileloc->str, G_FILE_TEST_EXISTS)) {
|
||||
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
|
||||
if (g_file_test(themes_file, G_FILE_TEST_EXISTS)) {
|
||||
g_chmod(themes_file, S_IRUSR | S_IWUSR);
|
||||
}
|
||||
|
||||
themes = g_key_file_new();
|
||||
g_key_file_load_from_file(themes, fileloc->str, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
||||
g_key_file_load_from_file(themes, themes_file, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
||||
|
||||
gsize g_data_size;
|
||||
gchar *g_data = g_key_file_to_data(themes, &g_data_size, NULL);
|
||||
g_file_set_contents(fileloc->str, g_data, g_data_size, NULL);
|
||||
g_chmod(fileloc->str, S_IRUSR | S_IWUSR);
|
||||
g_file_set_contents(themes_file, g_data, g_data_size, NULL);
|
||||
g_chmod(themes_file, S_IRUSR | S_IWUSR);
|
||||
g_free(g_data);
|
||||
g_string_free(fileloc, TRUE);
|
||||
free(themes_file);
|
||||
}
|
||||
|
||||
void
|
||||
|
189
src/profanity.c
189
src/profanity.c
@ -51,6 +51,7 @@
|
||||
#include "profanity.h"
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
#include "config/files.h"
|
||||
#include "config/tlscerts.h"
|
||||
#include "config/accounts.h"
|
||||
#include "config/preferences.h"
|
||||
@ -63,6 +64,7 @@
|
||||
#include "ui/ui.h"
|
||||
#include "ui/window_list.h"
|
||||
#include "xmpp/resource.h"
|
||||
#include "xmpp/session.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "xmpp/muc.h"
|
||||
#include "xmpp/chat_session.h"
|
||||
@ -78,24 +80,10 @@
|
||||
#include "pgp/gpg.h"
|
||||
#endif
|
||||
|
||||
|
||||
static void _check_autoaway(void);
|
||||
static void _init(char *log_level);
|
||||
static void _shutdown(void);
|
||||
static void _create_directories(void);
|
||||
static void _connect_default(const char * const account);
|
||||
|
||||
typedef enum {
|
||||
ACTIVITY_ST_ACTIVE,
|
||||
ACTIVITY_ST_IDLE,
|
||||
ACTIVITY_ST_AWAY,
|
||||
ACTIVITY_ST_XA,
|
||||
} activity_state_t;
|
||||
|
||||
activity_state_t activity_state;
|
||||
resource_presence_t saved_presence;
|
||||
char *saved_status;
|
||||
|
||||
static gboolean cont = TRUE;
|
||||
static gboolean force_quit = FALSE;
|
||||
|
||||
@ -110,13 +98,12 @@ prof_run(char *log_level, char *account_name)
|
||||
|
||||
log_info("Starting main event loop");
|
||||
|
||||
activity_state = ACTIVITY_ST_ACTIVE;
|
||||
saved_status = NULL;
|
||||
session_init_activity();
|
||||
|
||||
char *line = NULL;
|
||||
while(cont && !force_quit) {
|
||||
log_stderr_handler();
|
||||
_check_autoaway();
|
||||
session_check_autoaway();
|
||||
|
||||
line = inp_readline();
|
||||
if (line) {
|
||||
@ -163,126 +150,6 @@ _connect_default(const char *const account)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_check_autoaway(void)
|
||||
{
|
||||
jabber_conn_status_t conn_status = connection_get_status();
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *mode = prefs_get_string(PREF_AUTOAWAY_MODE);
|
||||
gboolean check = prefs_get_boolean(PREF_AUTOAWAY_CHECK);
|
||||
gint away_time = prefs_get_autoaway_time();
|
||||
gint xa_time = prefs_get_autoxa_time();
|
||||
int away_time_ms = away_time * 60000;
|
||||
int xa_time_ms = xa_time * 60000;
|
||||
|
||||
char *account = session_get_account_name();
|
||||
resource_presence_t curr_presence = accounts_get_last_presence(account);
|
||||
char *curr_status = accounts_get_last_status(account);
|
||||
|
||||
unsigned long idle_ms = ui_get_idle_time();
|
||||
|
||||
switch (activity_state) {
|
||||
case ACTIVITY_ST_ACTIVE:
|
||||
if (idle_ms >= away_time_ms) {
|
||||
if (g_strcmp0(mode, "away") == 0) {
|
||||
if ((curr_presence == RESOURCE_ONLINE) || (curr_presence == RESOURCE_CHAT) || (curr_presence == RESOURCE_DND)) {
|
||||
activity_state = ACTIVITY_ST_AWAY;
|
||||
|
||||
// save current presence
|
||||
saved_presence = curr_presence;
|
||||
if (saved_status) {
|
||||
free(saved_status);
|
||||
}
|
||||
saved_status = curr_status;
|
||||
|
||||
// send away presence with last activity
|
||||
char *message = prefs_get_string(PREF_AUTOAWAY_MESSAGE);
|
||||
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
|
||||
cl_ev_presence_send(RESOURCE_AWAY, message, idle_ms / 1000);
|
||||
} else {
|
||||
cl_ev_presence_send(RESOURCE_AWAY, message, 0);
|
||||
}
|
||||
|
||||
int pri = accounts_get_priority_for_presence_type(account, RESOURCE_AWAY);
|
||||
if (message) {
|
||||
cons_show("Idle for %d minutes, status set to away (priority %d), \"%s\".", away_time, pri, message);
|
||||
} else {
|
||||
cons_show("Idle for %d minutes, status set to away (priority %d).", away_time, pri);
|
||||
}
|
||||
prefs_free_string(message);
|
||||
|
||||
title_bar_set_presence(CONTACT_AWAY);
|
||||
}
|
||||
} else if (g_strcmp0(mode, "idle") == 0) {
|
||||
activity_state = ACTIVITY_ST_IDLE;
|
||||
|
||||
// send current presence with last activity
|
||||
cl_ev_presence_send(curr_presence, curr_status, idle_ms / 1000);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ACTIVITY_ST_IDLE:
|
||||
if (check && (idle_ms < away_time_ms)) {
|
||||
activity_state = ACTIVITY_ST_ACTIVE;
|
||||
|
||||
cons_show("No longer idle.");
|
||||
|
||||
// send current presence without last activity
|
||||
cl_ev_presence_send(curr_presence, curr_status, 0);
|
||||
}
|
||||
break;
|
||||
case ACTIVITY_ST_AWAY:
|
||||
if (xa_time_ms > 0 && (idle_ms >= xa_time_ms)) {
|
||||
activity_state = ACTIVITY_ST_XA;
|
||||
|
||||
// send extended away presence with last activity
|
||||
char *message = prefs_get_string(PREF_AUTOXA_MESSAGE);
|
||||
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
|
||||
cl_ev_presence_send(RESOURCE_XA, message, idle_ms / 1000);
|
||||
} else {
|
||||
cl_ev_presence_send(RESOURCE_XA, message, 0);
|
||||
}
|
||||
|
||||
int pri = accounts_get_priority_for_presence_type(account, RESOURCE_XA);
|
||||
if (message) {
|
||||
cons_show("Idle for %d minutes, status set to xa (priority %d), \"%s\".", xa_time, pri, message);
|
||||
} else {
|
||||
cons_show("Idle for %d minutes, status set to xa (priority %d).", xa_time, pri);
|
||||
}
|
||||
prefs_free_string(message);
|
||||
|
||||
title_bar_set_presence(CONTACT_XA);
|
||||
} else if (check && (idle_ms < away_time_ms)) {
|
||||
activity_state = ACTIVITY_ST_ACTIVE;
|
||||
|
||||
cons_show("No longer idle.");
|
||||
|
||||
// send saved presence without last activity
|
||||
cl_ev_presence_send(saved_presence, saved_status, 0);
|
||||
contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence);
|
||||
title_bar_set_presence(contact_pres);
|
||||
}
|
||||
break;
|
||||
case ACTIVITY_ST_XA:
|
||||
if (check && (idle_ms < away_time_ms)) {
|
||||
activity_state = ACTIVITY_ST_ACTIVE;
|
||||
|
||||
cons_show("No longer idle.");
|
||||
|
||||
// send saved presence without last activity
|
||||
cl_ev_presence_send(saved_presence, saved_status, 0);
|
||||
contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence);
|
||||
title_bar_set_presence(contact_pres);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
prefs_free_string(mode);
|
||||
}
|
||||
|
||||
static void
|
||||
_init(char *log_level)
|
||||
{
|
||||
@ -297,7 +164,7 @@ _init(char *log_level)
|
||||
exit(1);
|
||||
}
|
||||
pthread_mutex_lock(&lock);
|
||||
_create_directories();
|
||||
files_create_directories();
|
||||
log_level_t prof_log_level = log_level_from_string(log_level);
|
||||
prefs_load();
|
||||
log_init(prof_log_level);
|
||||
@ -376,50 +243,4 @@ _shutdown(void)
|
||||
cmd_uninit();
|
||||
ui_close();
|
||||
prefs_close();
|
||||
if (saved_status) {
|
||||
free(saved_status);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_create_directories(void)
|
||||
{
|
||||
gchar *xdg_config = xdg_get_config_home();
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
|
||||
GString *themes_dir = g_string_new(xdg_config);
|
||||
g_string_append(themes_dir, "/profanity/themes");
|
||||
GString *icons_dir = g_string_new(xdg_config);
|
||||
g_string_append(icons_dir, "/profanity/icons");
|
||||
GString *chatlogs_dir = g_string_new(xdg_data);
|
||||
g_string_append(chatlogs_dir, "/profanity/chatlogs");
|
||||
GString *logs_dir = g_string_new(xdg_data);
|
||||
g_string_append(logs_dir, "/profanity/logs");
|
||||
GString *plugins_dir = g_string_new(xdg_data);
|
||||
g_string_append(plugins_dir, "/profanity/plugins");
|
||||
|
||||
if (!mkdir_recursive(themes_dir->str)) {
|
||||
log_error("Error while creating directory %s", themes_dir->str);
|
||||
}
|
||||
if (!mkdir_recursive(icons_dir->str)) {
|
||||
log_error("Error while creating directory %s", icons_dir->str);
|
||||
}
|
||||
if (!mkdir_recursive(chatlogs_dir->str)) {
|
||||
log_error("Error while creating directory %s", chatlogs_dir->str);
|
||||
}
|
||||
if (!mkdir_recursive(logs_dir->str)) {
|
||||
log_error("Error while creating directory %s", logs_dir->str);
|
||||
}
|
||||
if (!mkdir_recursive(plugins_dir->str)) {
|
||||
log_error("Error while creating directory %s", plugins_dir->str);
|
||||
}
|
||||
|
||||
g_string_free(themes_dir, TRUE);
|
||||
g_string_free(icons_dir, TRUE);
|
||||
g_string_free(chatlogs_dir, TRUE);
|
||||
g_string_free(logs_dir, TRUE);
|
||||
g_string_free(plugins_dir, TRUE);
|
||||
|
||||
g_free(xdg_config);
|
||||
g_free(xdg_data);
|
||||
}
|
||||
|
@ -57,6 +57,7 @@
|
||||
#include "log.h"
|
||||
#include "common.h"
|
||||
#include "command/cmd_ac.h"
|
||||
#include "config/files.h"
|
||||
#include "config/accounts.h"
|
||||
#include "config/preferences.h"
|
||||
#include "config/theme.h"
|
||||
@ -427,7 +428,7 @@ _inp_rl_startup_hook(void)
|
||||
rl_variable_bind("disable-completion", "on");
|
||||
|
||||
// check for and load ~/.config/profanity/inputrc
|
||||
char *inputrc = prefs_get_inputrc();
|
||||
char *inputrc = files_get_inputrc_file();
|
||||
if (inputrc) {
|
||||
rl_read_init_file(inputrc);
|
||||
free(inputrc);
|
||||
|
@ -41,6 +41,7 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "config/preferences.h"
|
||||
#include "config/files.h"
|
||||
#include "ui/tray.h"
|
||||
#include "ui/window_list.h"
|
||||
|
||||
@ -78,10 +79,8 @@ _get_icons(void)
|
||||
|
||||
#endif /* ICONS_PATH */
|
||||
|
||||
gchar *xdg_config = xdg_get_config_home();
|
||||
icons_dir = g_string_new(xdg_config);
|
||||
g_free(xdg_config);
|
||||
g_string_append(icons_dir, "/profanity/icons");
|
||||
char *icons_dir_s = files_get_config_path(DIR_ICONS);
|
||||
icons_dir = g_string_new(icons_dir_s);
|
||||
GError *err = NULL;
|
||||
if (!g_file_test(icons_dir->str, G_FILE_TEST_IS_DIR)) {
|
||||
return;
|
||||
|
@ -55,6 +55,9 @@ static int current;
|
||||
static Autocomplete wins_ac;
|
||||
static Autocomplete wins_close_ac;
|
||||
|
||||
static int _wins_cmp_num(gconstpointer a, gconstpointer b);
|
||||
static int _wins_get_next_available_num(GList *used);
|
||||
|
||||
void
|
||||
wins_init(void)
|
||||
{
|
||||
@ -424,7 +427,7 @@ wins_get_next(void)
|
||||
{
|
||||
// get and sort win nums
|
||||
GList *keys = g_hash_table_get_keys(windows);
|
||||
keys = g_list_sort(keys, cmp_win_num);
|
||||
keys = g_list_sort(keys, _wins_cmp_num);
|
||||
GList *curr = keys;
|
||||
|
||||
// find our place in the list
|
||||
@ -453,7 +456,7 @@ wins_get_previous(void)
|
||||
{
|
||||
// get and sort win nums
|
||||
GList *keys = g_hash_table_get_keys(windows);
|
||||
keys = g_list_sort(keys, cmp_win_num);
|
||||
keys = g_list_sort(keys, _wins_cmp_num);
|
||||
GList *curr = keys;
|
||||
|
||||
// find our place in the list
|
||||
@ -612,7 +615,7 @@ ProfWin*
|
||||
wins_new_xmlconsole(void)
|
||||
{
|
||||
GList *keys = g_hash_table_get_keys(windows);
|
||||
int result = get_next_available_win_num(keys);
|
||||
int result = _wins_get_next_available_num(keys);
|
||||
g_list_free(keys);
|
||||
ProfWin *newwin = win_create_xmlconsole();
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
@ -625,7 +628,7 @@ ProfWin*
|
||||
wins_new_chat(const char *const barejid)
|
||||
{
|
||||
GList *keys = g_hash_table_get_keys(windows);
|
||||
int result = get_next_available_win_num(keys);
|
||||
int result = _wins_get_next_available_num(keys);
|
||||
g_list_free(keys);
|
||||
ProfWin *newwin = win_create_chat(barejid);
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
@ -648,7 +651,7 @@ ProfWin*
|
||||
wins_new_muc(const char *const roomjid)
|
||||
{
|
||||
GList *keys = g_hash_table_get_keys(windows);
|
||||
int result = get_next_available_win_num(keys);
|
||||
int result = _wins_get_next_available_num(keys);
|
||||
g_list_free(keys);
|
||||
ProfWin *newwin = win_create_muc(roomjid);
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
@ -661,7 +664,7 @@ ProfWin*
|
||||
wins_new_muc_config(const char *const roomjid, DataForm *form)
|
||||
{
|
||||
GList *keys = g_hash_table_get_keys(windows);
|
||||
int result = get_next_available_win_num(keys);
|
||||
int result = _wins_get_next_available_num(keys);
|
||||
g_list_free(keys);
|
||||
ProfWin *newwin = win_create_muc_config(roomjid, form);
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
@ -672,7 +675,7 @@ ProfWin*
|
||||
wins_new_private(const char *const fulljid)
|
||||
{
|
||||
GList *keys = g_hash_table_get_keys(windows);
|
||||
int result = get_next_available_win_num(keys);
|
||||
int result = _wins_get_next_available_num(keys);
|
||||
g_list_free(keys);
|
||||
ProfWin *newwin = win_create_private(fulljid);
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
@ -685,7 +688,7 @@ ProfWin *
|
||||
wins_new_plugin(const char *const plugin_name, const char * const tag)
|
||||
{
|
||||
GList *keys = g_hash_table_get_keys(windows);
|
||||
int result = get_next_available_win_num(keys);
|
||||
int result = _wins_get_next_available_num(keys);
|
||||
g_list_free(keys);
|
||||
ProfWin *newwin = win_create_plugin(plugin_name, tag);
|
||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||
@ -896,23 +899,95 @@ wins_swap(int source_win, int target_win)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
_wins_cmp_num(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
int real_a = GPOINTER_TO_INT(a);
|
||||
int real_b = GPOINTER_TO_INT(b);
|
||||
|
||||
if (real_a == 0) {
|
||||
real_a = 10;
|
||||
}
|
||||
|
||||
if (real_b == 0) {
|
||||
real_b = 10;
|
||||
}
|
||||
|
||||
if (real_a < real_b) {
|
||||
return -1;
|
||||
} else if (real_a == real_b) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
_wins_get_next_available_num(GList *used)
|
||||
{
|
||||
// only console used
|
||||
if (g_list_length(used) == 1) {
|
||||
return 2;
|
||||
} else {
|
||||
GList *sorted = NULL;
|
||||
GList *curr = used;
|
||||
while (curr) {
|
||||
sorted = g_list_insert_sorted(sorted, curr->data, _wins_cmp_num);
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
int last_num = 1;
|
||||
curr = sorted;
|
||||
// skip console
|
||||
curr = g_list_next(curr);
|
||||
while (curr) {
|
||||
int curr_num = GPOINTER_TO_INT(curr->data);
|
||||
|
||||
if (((last_num != 9) && ((last_num + 1) != curr_num)) ||
|
||||
((last_num == 9) && (curr_num != 0))) {
|
||||
result = last_num + 1;
|
||||
if (result == 10) {
|
||||
result = 0;
|
||||
}
|
||||
g_list_free(sorted);
|
||||
return (result);
|
||||
|
||||
} else {
|
||||
last_num = curr_num;
|
||||
if (last_num == 0) {
|
||||
last_num = 10;
|
||||
}
|
||||
}
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
result = last_num + 1;
|
||||
if (result == 10) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
g_list_free(sorted);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
wins_tidy(void)
|
||||
{
|
||||
gboolean tidy_required = FALSE;
|
||||
// check for gaps
|
||||
GList *keys = g_hash_table_get_keys(windows);
|
||||
keys = g_list_sort(keys, cmp_win_num);
|
||||
keys = g_list_sort(keys, _wins_cmp_num);
|
||||
|
||||
// get last used
|
||||
GList *last = g_list_last(keys);
|
||||
int last_num = GPOINTER_TO_INT(last->data);
|
||||
|
||||
// find first free num TODO - Will sort again
|
||||
int next_available = get_next_available_win_num(keys);
|
||||
int next_available = _wins_get_next_available_num(keys);
|
||||
|
||||
// found gap (next available before last window)
|
||||
if (cmp_win_num(GINT_TO_POINTER(next_available), GINT_TO_POINTER(last_num)) < 0) {
|
||||
if (_wins_cmp_num(GINT_TO_POINTER(next_available), GINT_TO_POINTER(last_num)) < 0) {
|
||||
tidy_required = TRUE;
|
||||
}
|
||||
|
||||
@ -966,7 +1041,7 @@ wins_create_summary(gboolean unread)
|
||||
GSList *result = NULL;
|
||||
|
||||
GList *keys = g_hash_table_get_keys(windows);
|
||||
keys = g_list_sort(keys, cmp_win_num);
|
||||
keys = g_list_sort(keys, _wins_cmp_num);
|
||||
GList *curr = keys;
|
||||
|
||||
while (curr) {
|
||||
|
@ -55,12 +55,13 @@
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
#include "plugins/plugins.h"
|
||||
#include "config/files.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
#include "xmpp/stanza.h"
|
||||
#include "xmpp/form.h"
|
||||
#include "xmpp/capabilities.h"
|
||||
|
||||
static gchar *cache_loc;
|
||||
static char *cache_loc;
|
||||
static GKeyFile *cache;
|
||||
|
||||
static GHashTable *jid_to_ver;
|
||||
@ -68,7 +69,6 @@ static GHashTable *jid_to_caps;
|
||||
|
||||
static char *my_sha1;
|
||||
|
||||
static gchar* _get_cache_file(void);
|
||||
static void _save_cache(void);
|
||||
static Capabilities* _caps_by_ver(const char *const ver);
|
||||
static Capabilities* _caps_by_jid(const char *const jid);
|
||||
@ -78,15 +78,14 @@ void
|
||||
caps_init(void)
|
||||
{
|
||||
log_info("Loading capabilities cache");
|
||||
cache_loc = _get_cache_file();
|
||||
cache_loc = files_get_data_path(FILE_CAPSCACHE);
|
||||
|
||||
if (g_file_test(cache_loc, G_FILE_TEST_EXISTS)) {
|
||||
g_chmod(cache_loc, S_IRUSR | S_IWUSR);
|
||||
}
|
||||
|
||||
cache = g_key_file_new();
|
||||
g_key_file_load_from_file(cache, cache_loc, G_KEY_FILE_KEEP_COMMENTS,
|
||||
NULL);
|
||||
g_key_file_load_from_file(cache, cache_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
||||
|
||||
jid_to_ver = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
|
||||
jid_to_caps = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)caps_destroy);
|
||||
@ -677,6 +676,8 @@ caps_close(void)
|
||||
cache = NULL;
|
||||
g_hash_table_destroy(jid_to_ver);
|
||||
g_hash_table_destroy(jid_to_caps);
|
||||
free(cache_loc);
|
||||
cache_loc = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
@ -697,19 +698,6 @@ caps_destroy(Capabilities *caps)
|
||||
}
|
||||
}
|
||||
|
||||
static gchar*
|
||||
_get_cache_file(void)
|
||||
{
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
GString *cache_file = g_string_new(xdg_data);
|
||||
g_string_append(cache_file, "/profanity/capscache");
|
||||
gchar *result = strdup(cache_file->str);
|
||||
g_free(xdg_data);
|
||||
g_string_free(cache_file, TRUE);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
_save_cache(void)
|
||||
{
|
||||
|
@ -95,3 +95,72 @@ resource_destroy(Resource *resource)
|
||||
free(resource);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
valid_resource_presence_string(const char *const str)
|
||||
{
|
||||
assert(str != NULL);
|
||||
if ((strcmp(str, "online") == 0) || (strcmp(str, "chat") == 0) ||
|
||||
(strcmp(str, "away") == 0) || (strcmp(str, "xa") == 0) ||
|
||||
(strcmp(str, "dnd") == 0)) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
string_from_resource_presence(resource_presence_t presence)
|
||||
{
|
||||
switch(presence)
|
||||
{
|
||||
case RESOURCE_CHAT:
|
||||
return "chat";
|
||||
case RESOURCE_AWAY:
|
||||
return "away";
|
||||
case RESOURCE_XA:
|
||||
return "xa";
|
||||
case RESOURCE_DND:
|
||||
return "dnd";
|
||||
default:
|
||||
return "online";
|
||||
}
|
||||
}
|
||||
|
||||
resource_presence_t
|
||||
resource_presence_from_string(const char *const str)
|
||||
{
|
||||
if (str == NULL) {
|
||||
return RESOURCE_ONLINE;
|
||||
} else if (strcmp(str, "online") == 0) {
|
||||
return RESOURCE_ONLINE;
|
||||
} else if (strcmp(str, "chat") == 0) {
|
||||
return RESOURCE_CHAT;
|
||||
} else if (strcmp(str, "away") == 0) {
|
||||
return RESOURCE_AWAY;
|
||||
} else if (strcmp(str, "xa") == 0) {
|
||||
return RESOURCE_XA;
|
||||
} else if (strcmp(str, "dnd") == 0) {
|
||||
return RESOURCE_DND;
|
||||
} else {
|
||||
return RESOURCE_ONLINE;
|
||||
}
|
||||
}
|
||||
|
||||
contact_presence_t
|
||||
contact_presence_from_resource_presence(resource_presence_t resource_presence)
|
||||
{
|
||||
switch(resource_presence)
|
||||
{
|
||||
case RESOURCE_CHAT:
|
||||
return CONTACT_CHAT;
|
||||
case RESOURCE_AWAY:
|
||||
return CONTACT_AWAY;
|
||||
case RESOURCE_XA:
|
||||
return CONTACT_XA;
|
||||
case RESOURCE_DND:
|
||||
return CONTACT_DND;
|
||||
default:
|
||||
return CONTACT_ONLINE;
|
||||
}
|
||||
}
|
||||
|
@ -49,4 +49,9 @@ Resource* resource_new(const char *const name, resource_presence_t presence, con
|
||||
void resource_destroy(Resource *resource);
|
||||
int resource_compare_availability(Resource *first, Resource *second);
|
||||
|
||||
gboolean valid_resource_presence_string(const char *const str);
|
||||
const char* string_from_resource_presence(resource_presence_t presence);
|
||||
resource_presence_t resource_presence_from_string(const char *const str);
|
||||
contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence);
|
||||
|
||||
#endif
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "config/preferences.h"
|
||||
#include "plugins/plugins.h"
|
||||
#include "event/server_events.h"
|
||||
#include "event/client_events.h"
|
||||
#include "xmpp/bookmark.h"
|
||||
#include "xmpp/blocking.h"
|
||||
#include "xmpp/connection.h"
|
||||
@ -74,7 +75,17 @@ static struct {
|
||||
char *tls_policy;
|
||||
} saved_details;
|
||||
|
||||
typedef enum {
|
||||
ACTIVITY_ST_ACTIVE,
|
||||
ACTIVITY_ST_IDLE,
|
||||
ACTIVITY_ST_AWAY,
|
||||
ACTIVITY_ST_XA,
|
||||
} activity_state_t;
|
||||
|
||||
static GTimer *reconnect_timer;
|
||||
static activity_state_t activity_state;
|
||||
static resource_presence_t saved_presence;
|
||||
static char *saved_status;
|
||||
|
||||
static void _session_reconnect(void);
|
||||
|
||||
@ -225,6 +236,9 @@ session_shutdown(void)
|
||||
presence_clear_sub_requests();
|
||||
|
||||
connection_shutdown();
|
||||
if (saved_status) {
|
||||
free(saved_status);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -343,6 +357,133 @@ session_lost_connection(void)
|
||||
presence_clear_sub_requests();
|
||||
}
|
||||
|
||||
void
|
||||
session_init_activity(void)
|
||||
{
|
||||
activity_state = ACTIVITY_ST_ACTIVE;
|
||||
saved_status = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
session_check_autoaway(void)
|
||||
{
|
||||
jabber_conn_status_t conn_status = connection_get_status();
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *mode = prefs_get_string(PREF_AUTOAWAY_MODE);
|
||||
gboolean check = prefs_get_boolean(PREF_AUTOAWAY_CHECK);
|
||||
gint away_time = prefs_get_autoaway_time();
|
||||
gint xa_time = prefs_get_autoxa_time();
|
||||
int away_time_ms = away_time * 60000;
|
||||
int xa_time_ms = xa_time * 60000;
|
||||
|
||||
char *account = session_get_account_name();
|
||||
resource_presence_t curr_presence = accounts_get_last_presence(account);
|
||||
char *curr_status = accounts_get_last_status(account);
|
||||
|
||||
unsigned long idle_ms = ui_get_idle_time();
|
||||
|
||||
switch (activity_state) {
|
||||
case ACTIVITY_ST_ACTIVE:
|
||||
if (idle_ms >= away_time_ms) {
|
||||
if (g_strcmp0(mode, "away") == 0) {
|
||||
if ((curr_presence == RESOURCE_ONLINE) || (curr_presence == RESOURCE_CHAT) || (curr_presence == RESOURCE_DND)) {
|
||||
activity_state = ACTIVITY_ST_AWAY;
|
||||
|
||||
// save current presence
|
||||
saved_presence = curr_presence;
|
||||
if (saved_status) {
|
||||
free(saved_status);
|
||||
}
|
||||
saved_status = curr_status;
|
||||
|
||||
// send away presence with last activity
|
||||
char *message = prefs_get_string(PREF_AUTOAWAY_MESSAGE);
|
||||
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
|
||||
cl_ev_presence_send(RESOURCE_AWAY, message, idle_ms / 1000);
|
||||
} else {
|
||||
cl_ev_presence_send(RESOURCE_AWAY, message, 0);
|
||||
}
|
||||
|
||||
int pri = accounts_get_priority_for_presence_type(account, RESOURCE_AWAY);
|
||||
if (message) {
|
||||
cons_show("Idle for %d minutes, status set to away (priority %d), \"%s\".", away_time, pri, message);
|
||||
} else {
|
||||
cons_show("Idle for %d minutes, status set to away (priority %d).", away_time, pri);
|
||||
}
|
||||
prefs_free_string(message);
|
||||
|
||||
title_bar_set_presence(CONTACT_AWAY);
|
||||
}
|
||||
} else if (g_strcmp0(mode, "idle") == 0) {
|
||||
activity_state = ACTIVITY_ST_IDLE;
|
||||
|
||||
// send current presence with last activity
|
||||
cl_ev_presence_send(curr_presence, curr_status, idle_ms / 1000);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ACTIVITY_ST_IDLE:
|
||||
if (check && (idle_ms < away_time_ms)) {
|
||||
activity_state = ACTIVITY_ST_ACTIVE;
|
||||
|
||||
cons_show("No longer idle.");
|
||||
|
||||
// send current presence without last activity
|
||||
cl_ev_presence_send(curr_presence, curr_status, 0);
|
||||
}
|
||||
break;
|
||||
case ACTIVITY_ST_AWAY:
|
||||
if (xa_time_ms > 0 && (idle_ms >= xa_time_ms)) {
|
||||
activity_state = ACTIVITY_ST_XA;
|
||||
|
||||
// send extended away presence with last activity
|
||||
char *message = prefs_get_string(PREF_AUTOXA_MESSAGE);
|
||||
if (prefs_get_boolean(PREF_LASTACTIVITY)) {
|
||||
cl_ev_presence_send(RESOURCE_XA, message, idle_ms / 1000);
|
||||
} else {
|
||||
cl_ev_presence_send(RESOURCE_XA, message, 0);
|
||||
}
|
||||
|
||||
int pri = accounts_get_priority_for_presence_type(account, RESOURCE_XA);
|
||||
if (message) {
|
||||
cons_show("Idle for %d minutes, status set to xa (priority %d), \"%s\".", xa_time, pri, message);
|
||||
} else {
|
||||
cons_show("Idle for %d minutes, status set to xa (priority %d).", xa_time, pri);
|
||||
}
|
||||
prefs_free_string(message);
|
||||
|
||||
title_bar_set_presence(CONTACT_XA);
|
||||
} else if (check && (idle_ms < away_time_ms)) {
|
||||
activity_state = ACTIVITY_ST_ACTIVE;
|
||||
|
||||
cons_show("No longer idle.");
|
||||
|
||||
// send saved presence without last activity
|
||||
cl_ev_presence_send(saved_presence, saved_status, 0);
|
||||
contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence);
|
||||
title_bar_set_presence(contact_pres);
|
||||
}
|
||||
break;
|
||||
case ACTIVITY_ST_XA:
|
||||
if (check && (idle_ms < away_time_ms)) {
|
||||
activity_state = ACTIVITY_ST_ACTIVE;
|
||||
|
||||
cons_show("No longer idle.");
|
||||
|
||||
// send saved presence without last activity
|
||||
cl_ev_presence_send(saved_presence, saved_status, 0);
|
||||
contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence);
|
||||
title_bar_set_presence(contact_pres);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
prefs_free_string(mode);
|
||||
}
|
||||
|
||||
static void
|
||||
_session_reconnect(void)
|
||||
{
|
||||
|
@ -42,4 +42,7 @@ void session_login_failed(void);
|
||||
void session_lost_connection(void);
|
||||
void session_autoping_fail(void);
|
||||
|
||||
void session_init_activity(void);
|
||||
void session_check_autoaway(void);
|
||||
|
||||
#endif
|
||||
|
@ -15,17 +15,9 @@
|
||||
void create_config_dir(void **state)
|
||||
{
|
||||
setenv("XDG_CONFIG_HOME", "./tests/files/xdg_config_home", 1);
|
||||
gchar *xdg_config = xdg_get_config_home();
|
||||
|
||||
GString *profanity_dir = g_string_new(xdg_config);
|
||||
g_string_append(profanity_dir, "/profanity");
|
||||
|
||||
if (!mkdir_recursive(profanity_dir->str)) {
|
||||
if (!mkdir_recursive("./tests/files/xdg_config_home/profanity")) {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
|
||||
g_free(xdg_config);
|
||||
g_string_free(profanity_dir, TRUE);
|
||||
}
|
||||
|
||||
void remove_config_dir(void **state)
|
||||
@ -37,17 +29,9 @@ void remove_config_dir(void **state)
|
||||
void create_data_dir(void **state)
|
||||
{
|
||||
setenv("XDG_DATA_HOME", "./tests/files/xdg_data_home", 1);
|
||||
gchar *xdg_data = xdg_get_data_home();
|
||||
|
||||
GString *profanity_dir = g_string_new(xdg_data);
|
||||
g_string_append(profanity_dir, "/profanity");
|
||||
|
||||
if (!mkdir_recursive(profanity_dir->str)) {
|
||||
if (!mkdir_recursive("./tests/files/xdg_data_home/profanity")) {
|
||||
assert_true(FALSE);
|
||||
}
|
||||
|
||||
g_free(xdg_data);
|
||||
g_string_free(profanity_dir, TRUE);
|
||||
}
|
||||
|
||||
void remove_data_dir(void **state)
|
||||
|
@ -172,283 +172,6 @@ void replace_when_new_null(void **state)
|
||||
free(result);
|
||||
}
|
||||
|
||||
void compare_win_nums_less(void **state)
|
||||
{
|
||||
gconstpointer a = GINT_TO_POINTER(2);
|
||||
gconstpointer b = GINT_TO_POINTER(3);
|
||||
|
||||
int result = cmp_win_num(a, b);
|
||||
|
||||
assert_true(result < 0);
|
||||
}
|
||||
|
||||
void compare_win_nums_equal(void **state)
|
||||
{
|
||||
gconstpointer a = GINT_TO_POINTER(5);
|
||||
gconstpointer b = GINT_TO_POINTER(5);
|
||||
|
||||
int result = cmp_win_num(a, b);
|
||||
|
||||
assert_true(result == 0);
|
||||
}
|
||||
|
||||
void compare_win_nums_greater(void **state)
|
||||
{
|
||||
gconstpointer a = GINT_TO_POINTER(7);
|
||||
gconstpointer b = GINT_TO_POINTER(6);
|
||||
|
||||
int result = cmp_win_num(a, b);
|
||||
|
||||
assert_true(result > 0);
|
||||
}
|
||||
|
||||
void compare_0s_equal(void **state)
|
||||
{
|
||||
gconstpointer a = GINT_TO_POINTER(0);
|
||||
gconstpointer b = GINT_TO_POINTER(0);
|
||||
|
||||
int result = cmp_win_num(a, b);
|
||||
|
||||
assert_true(result == 0);
|
||||
}
|
||||
|
||||
void compare_0_greater_than_1(void **state)
|
||||
{
|
||||
gconstpointer a = GINT_TO_POINTER(0);
|
||||
gconstpointer b = GINT_TO_POINTER(1);
|
||||
|
||||
int result = cmp_win_num(a, b);
|
||||
|
||||
assert_true(result > 0);
|
||||
}
|
||||
|
||||
void compare_1_less_than_0(void **state)
|
||||
{
|
||||
gconstpointer a = GINT_TO_POINTER(1);
|
||||
gconstpointer b = GINT_TO_POINTER(0);
|
||||
|
||||
int result = cmp_win_num(a, b);
|
||||
|
||||
assert_true(result < 0);
|
||||
}
|
||||
|
||||
void compare_0_less_than_11(void **state)
|
||||
{
|
||||
gconstpointer a = GINT_TO_POINTER(0);
|
||||
gconstpointer b = GINT_TO_POINTER(11);
|
||||
|
||||
int result = cmp_win_num(a, b);
|
||||
|
||||
assert_true(result < 0);
|
||||
}
|
||||
|
||||
void compare_11_greater_than_0(void **state)
|
||||
{
|
||||
gconstpointer a = GINT_TO_POINTER(11);
|
||||
gconstpointer b = GINT_TO_POINTER(0);
|
||||
|
||||
int result = cmp_win_num(a, b);
|
||||
|
||||
assert_true(result > 0);
|
||||
}
|
||||
|
||||
void compare_0_greater_than_9(void **state)
|
||||
{
|
||||
gconstpointer a = GINT_TO_POINTER(0);
|
||||
gconstpointer b = GINT_TO_POINTER(9);
|
||||
|
||||
int result = cmp_win_num(a, b);
|
||||
|
||||
assert_true(result > 0);
|
||||
}
|
||||
|
||||
void compare_9_less_than_0(void **state)
|
||||
{
|
||||
gconstpointer a = GINT_TO_POINTER(9);
|
||||
gconstpointer b = GINT_TO_POINTER(0);
|
||||
|
||||
int result = cmp_win_num(a, b);
|
||||
|
||||
assert_true(result < 0);
|
||||
}
|
||||
|
||||
void next_available_when_only_console(void **state)
|
||||
{
|
||||
GList *used = NULL;
|
||||
used = g_list_append(used, GINT_TO_POINTER(1));
|
||||
|
||||
int result = get_next_available_win_num(used);
|
||||
|
||||
assert_int_equal(2, result);
|
||||
}
|
||||
|
||||
void next_available_3_at_end(void **state)
|
||||
{
|
||||
GList *used = NULL;
|
||||
used = g_list_append(used, GINT_TO_POINTER(1));
|
||||
used = g_list_append(used, GINT_TO_POINTER(2));
|
||||
|
||||
int result = get_next_available_win_num(used);
|
||||
|
||||
assert_int_equal(3, result);
|
||||
}
|
||||
|
||||
void next_available_9_at_end(void **state)
|
||||
{
|
||||
GList *used = NULL;
|
||||
used = g_list_append(used, GINT_TO_POINTER(1));
|
||||
used = g_list_append(used, GINT_TO_POINTER(2));
|
||||
used = g_list_append(used, GINT_TO_POINTER(3));
|
||||
used = g_list_append(used, GINT_TO_POINTER(4));
|
||||
used = g_list_append(used, GINT_TO_POINTER(5));
|
||||
used = g_list_append(used, GINT_TO_POINTER(6));
|
||||
used = g_list_append(used, GINT_TO_POINTER(7));
|
||||
used = g_list_append(used, GINT_TO_POINTER(8));
|
||||
|
||||
int result = get_next_available_win_num(used);
|
||||
|
||||
assert_int_equal(9, result);
|
||||
}
|
||||
|
||||
void next_available_0_at_end(void **state)
|
||||
{
|
||||
GList *used = NULL;
|
||||
used = g_list_append(used, GINT_TO_POINTER(1));
|
||||
used = g_list_append(used, GINT_TO_POINTER(2));
|
||||
used = g_list_append(used, GINT_TO_POINTER(3));
|
||||
used = g_list_append(used, GINT_TO_POINTER(4));
|
||||
used = g_list_append(used, GINT_TO_POINTER(5));
|
||||
used = g_list_append(used, GINT_TO_POINTER(6));
|
||||
used = g_list_append(used, GINT_TO_POINTER(7));
|
||||
used = g_list_append(used, GINT_TO_POINTER(8));
|
||||
used = g_list_append(used, GINT_TO_POINTER(9));
|
||||
|
||||
int result = get_next_available_win_num(used);
|
||||
|
||||
assert_int_equal(0, result);
|
||||
}
|
||||
|
||||
void next_available_2_in_first_gap(void **state)
|
||||
{
|
||||
GList *used = NULL;
|
||||
used = g_list_append(used, GINT_TO_POINTER(1));
|
||||
used = g_list_append(used, GINT_TO_POINTER(3));
|
||||
used = g_list_append(used, GINT_TO_POINTER(4));
|
||||
used = g_list_append(used, GINT_TO_POINTER(5));
|
||||
used = g_list_append(used, GINT_TO_POINTER(9));
|
||||
used = g_list_append(used, GINT_TO_POINTER(0));
|
||||
|
||||
int result = get_next_available_win_num(used);
|
||||
|
||||
assert_int_equal(2, result);
|
||||
}
|
||||
|
||||
void next_available_9_in_first_gap(void **state)
|
||||
{
|
||||
GList *used = NULL;
|
||||
used = g_list_append(used, GINT_TO_POINTER(1));
|
||||
used = g_list_append(used, GINT_TO_POINTER(2));
|
||||
used = g_list_append(used, GINT_TO_POINTER(3));
|
||||
used = g_list_append(used, GINT_TO_POINTER(4));
|
||||
used = g_list_append(used, GINT_TO_POINTER(5));
|
||||
used = g_list_append(used, GINT_TO_POINTER(6));
|
||||
used = g_list_append(used, GINT_TO_POINTER(7));
|
||||
used = g_list_append(used, GINT_TO_POINTER(8));
|
||||
used = g_list_append(used, GINT_TO_POINTER(0));
|
||||
used = g_list_append(used, GINT_TO_POINTER(11));
|
||||
used = g_list_append(used, GINT_TO_POINTER(12));
|
||||
used = g_list_append(used, GINT_TO_POINTER(13));
|
||||
used = g_list_append(used, GINT_TO_POINTER(20));
|
||||
|
||||
int result = get_next_available_win_num(used);
|
||||
|
||||
assert_int_equal(9, result);
|
||||
}
|
||||
|
||||
void next_available_0_in_first_gap(void **state)
|
||||
{
|
||||
GList *used = NULL;
|
||||
used = g_list_append(used, GINT_TO_POINTER(1));
|
||||
used = g_list_append(used, GINT_TO_POINTER(2));
|
||||
used = g_list_append(used, GINT_TO_POINTER(3));
|
||||
used = g_list_append(used, GINT_TO_POINTER(4));
|
||||
used = g_list_append(used, GINT_TO_POINTER(5));
|
||||
used = g_list_append(used, GINT_TO_POINTER(6));
|
||||
used = g_list_append(used, GINT_TO_POINTER(7));
|
||||
used = g_list_append(used, GINT_TO_POINTER(8));
|
||||
used = g_list_append(used, GINT_TO_POINTER(9));
|
||||
used = g_list_append(used, GINT_TO_POINTER(11));
|
||||
used = g_list_append(used, GINT_TO_POINTER(12));
|
||||
used = g_list_append(used, GINT_TO_POINTER(13));
|
||||
used = g_list_append(used, GINT_TO_POINTER(20));
|
||||
|
||||
int result = get_next_available_win_num(used);
|
||||
|
||||
assert_int_equal(0, result);
|
||||
}
|
||||
|
||||
void next_available_11_in_first_gap(void **state)
|
||||
{
|
||||
GList *used = NULL;
|
||||
used = g_list_append(used, GINT_TO_POINTER(1));
|
||||
used = g_list_append(used, GINT_TO_POINTER(2));
|
||||
used = g_list_append(used, GINT_TO_POINTER(3));
|
||||
used = g_list_append(used, GINT_TO_POINTER(4));
|
||||
used = g_list_append(used, GINT_TO_POINTER(5));
|
||||
used = g_list_append(used, GINT_TO_POINTER(6));
|
||||
used = g_list_append(used, GINT_TO_POINTER(7));
|
||||
used = g_list_append(used, GINT_TO_POINTER(8));
|
||||
used = g_list_append(used, GINT_TO_POINTER(9));
|
||||
used = g_list_append(used, GINT_TO_POINTER(0));
|
||||
used = g_list_append(used, GINT_TO_POINTER(12));
|
||||
used = g_list_append(used, GINT_TO_POINTER(13));
|
||||
used = g_list_append(used, GINT_TO_POINTER(20));
|
||||
|
||||
int result = get_next_available_win_num(used);
|
||||
|
||||
assert_int_equal(11, result);
|
||||
}
|
||||
|
||||
void next_available_24_first_big_gap(void **state)
|
||||
{
|
||||
GList *used = NULL;
|
||||
used = g_list_append(used, GINT_TO_POINTER(1));
|
||||
used = g_list_append(used, GINT_TO_POINTER(2));
|
||||
used = g_list_append(used, GINT_TO_POINTER(3));
|
||||
used = g_list_append(used, GINT_TO_POINTER(4));
|
||||
used = g_list_append(used, GINT_TO_POINTER(5));
|
||||
used = g_list_append(used, GINT_TO_POINTER(6));
|
||||
used = g_list_append(used, GINT_TO_POINTER(7));
|
||||
used = g_list_append(used, GINT_TO_POINTER(8));
|
||||
used = g_list_append(used, GINT_TO_POINTER(9));
|
||||
used = g_list_append(used, GINT_TO_POINTER(0));
|
||||
used = g_list_append(used, GINT_TO_POINTER(11));
|
||||
used = g_list_append(used, GINT_TO_POINTER(12));
|
||||
used = g_list_append(used, GINT_TO_POINTER(13));
|
||||
used = g_list_append(used, GINT_TO_POINTER(14));
|
||||
used = g_list_append(used, GINT_TO_POINTER(15));
|
||||
used = g_list_append(used, GINT_TO_POINTER(16));
|
||||
used = g_list_append(used, GINT_TO_POINTER(17));
|
||||
used = g_list_append(used, GINT_TO_POINTER(18));
|
||||
used = g_list_append(used, GINT_TO_POINTER(19));
|
||||
used = g_list_append(used, GINT_TO_POINTER(20));
|
||||
used = g_list_append(used, GINT_TO_POINTER(21));
|
||||
used = g_list_append(used, GINT_TO_POINTER(22));
|
||||
used = g_list_append(used, GINT_TO_POINTER(23));
|
||||
used = g_list_append(used, GINT_TO_POINTER(51));
|
||||
used = g_list_append(used, GINT_TO_POINTER(52));
|
||||
used = g_list_append(used, GINT_TO_POINTER(53));
|
||||
used = g_list_append(used, GINT_TO_POINTER(89));
|
||||
used = g_list_append(used, GINT_TO_POINTER(90));
|
||||
used = g_list_append(used, GINT_TO_POINTER(100));
|
||||
used = g_list_append(used, GINT_TO_POINTER(101));
|
||||
used = g_list_append(used, GINT_TO_POINTER(102));
|
||||
|
||||
int result = get_next_available_win_num(used);
|
||||
|
||||
assert_int_equal(24, result);
|
||||
}
|
||||
|
||||
void test_online_is_valid_resource_presence_string(void **state)
|
||||
{
|
||||
assert_true(valid_resource_presence_string("online"));
|
||||
|
@ -11,25 +11,6 @@ void replace_when_sub_empty(void **state);
|
||||
void replace_when_sub_null(void **state);
|
||||
void replace_when_new_empty(void **state);
|
||||
void replace_when_new_null(void **state);
|
||||
void compare_win_nums_less(void **state);
|
||||
void compare_win_nums_equal(void **state);
|
||||
void compare_win_nums_greater(void **state);
|
||||
void compare_0s_equal(void **state);
|
||||
void compare_0_greater_than_1(void **state);
|
||||
void compare_1_less_than_0(void **state);
|
||||
void compare_0_less_than_11(void **state);
|
||||
void compare_11_greater_than_0(void **state);
|
||||
void compare_0_greater_than_9(void **state);
|
||||
void compare_9_less_than_0(void **state);
|
||||
void next_available_when_only_console(void **state);
|
||||
void next_available_3_at_end(void **state);
|
||||
void next_available_9_at_end(void **state);
|
||||
void next_available_0_at_end(void **state);
|
||||
void next_available_2_in_first_gap(void **state);
|
||||
void next_available_9_in_first_gap(void **state);
|
||||
void next_available_0_in_first_gap(void **state);
|
||||
void next_available_11_in_first_gap(void **state);
|
||||
void next_available_24_first_big_gap(void **state);
|
||||
void test_online_is_valid_resource_presence_string(void **state);
|
||||
void test_chat_is_valid_resource_presence_string(void **state);
|
||||
void test_away_is_valid_resource_presence_string(void **state);
|
||||
|
@ -51,25 +51,6 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(replace_when_sub_null),
|
||||
unit_test(replace_when_new_empty),
|
||||
unit_test(replace_when_new_null),
|
||||
unit_test(compare_win_nums_less),
|
||||
unit_test(compare_win_nums_equal),
|
||||
unit_test(compare_win_nums_greater),
|
||||
unit_test(compare_0s_equal),
|
||||
unit_test(compare_0_greater_than_1),
|
||||
unit_test(compare_1_less_than_0),
|
||||
unit_test(compare_0_less_than_11),
|
||||
unit_test(compare_11_greater_than_0),
|
||||
unit_test(compare_0_greater_than_9),
|
||||
unit_test(compare_9_less_than_0),
|
||||
unit_test(next_available_when_only_console),
|
||||
unit_test(next_available_3_at_end),
|
||||
unit_test(next_available_9_at_end),
|
||||
unit_test(next_available_0_at_end),
|
||||
unit_test(next_available_2_in_first_gap),
|
||||
unit_test(next_available_9_in_first_gap),
|
||||
unit_test(next_available_0_in_first_gap),
|
||||
unit_test(next_available_11_in_first_gap),
|
||||
unit_test(next_available_24_first_big_gap),
|
||||
unit_test(test_online_is_valid_resource_presence_string),
|
||||
unit_test(test_chat_is_valid_resource_presence_string),
|
||||
unit_test(test_away_is_valid_resource_presence_string),
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
// connection functions
|
||||
void session_init(void) {}
|
||||
void session_init_activity(void) {}
|
||||
void session_check_autoaway(void) {}
|
||||
|
||||
jabber_conn_status_t session_connect_with_details(const char * const jid,
|
||||
const char * const passwd, const char * const altdomain, const int port, const char *const tls_policy)
|
||||
|
Loading…
Reference in New Issue
Block a user