mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
minor changes
* fix typo * less code duplication * less `GString` usage * more `auto_gchar` usage * document connecting to servers supporting SASL ANONYMOUS * ignore valgrind output Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
parent
b1b6c6f62d
commit
e9aaba938b
3
.gitignore
vendored
3
.gitignore
vendored
@ -55,6 +55,9 @@ tests/unittests/unittests.log
|
|||||||
tests/unittests/unittests.trs
|
tests/unittests/unittests.trs
|
||||||
test-suite.log
|
test-suite.log
|
||||||
|
|
||||||
|
# valgrind output
|
||||||
|
profval*
|
||||||
|
|
||||||
# local scripts
|
# local scripts
|
||||||
clean-test.sh
|
clean-test.sh
|
||||||
gen_docs.sh
|
gen_docs.sh
|
||||||
|
@ -170,15 +170,18 @@ static struct cmd_t command_defs[] = {
|
|||||||
CMD_TAG_CONNECTION)
|
CMD_TAG_CONNECTION)
|
||||||
CMD_SYN(
|
CMD_SYN(
|
||||||
"/connect [<account>]",
|
"/connect [<account>]",
|
||||||
"/connect <account> [server <server>] [port <port>] [tls force|allow|trust|legacy|disable] [auth default|legacy]")
|
"/connect <account> [server <server>] [port <port>] [tls force|allow|trust|legacy|disable] [auth default|legacy]",
|
||||||
|
"/connect <server>")
|
||||||
CMD_DESC(
|
CMD_DESC(
|
||||||
"Login to a chat service. "
|
"Login to a chat service. "
|
||||||
"If no account is specified, the default is used if one is configured. "
|
"If no account is specified, the default is used if one is configured. "
|
||||||
"A local account is created with the JID as it's name if it doesn't already exist.")
|
"A local account is created with the JID as it's name if it doesn't already exist. "
|
||||||
|
"In case you want to connect to a server via SASL ANONYMOUS (c.f. XEP-0175) you can also do that.")
|
||||||
CMD_ARGS(
|
CMD_ARGS(
|
||||||
{ "<account>", "The local account you wish to connect with, or a JID if connecting for the first time." },
|
{ "<account>", "The local account you wish to connect with, or a JID if connecting for the first time." },
|
||||||
{ "server <server>", "Supply a server if it is different to the domain part of your JID." },
|
{ "server <server>", "Supply a server if it is different to the domain part of your JID." },
|
||||||
{ "port <port>", "The port to use if different to the default (5222, or 5223 for SSL)." },
|
{ "port <port>", "The port to use if different to the default (5222, or 5223 for SSL)." },
|
||||||
|
{ "<server>", "Connect to said server in an anonymous way. (Be aware: There aren't many servers that support this.)" },
|
||||||
{ "tls force", "Force TLS connection, and fail if one cannot be established, this is default behaviour." },
|
{ "tls force", "Force TLS connection, and fail if one cannot be established, this is default behaviour." },
|
||||||
{ "tls allow", "Use TLS for the connection if it is available." },
|
{ "tls allow", "Use TLS for the connection if it is available." },
|
||||||
{ "tls trust", "Force TLS connection and trust server's certificate." },
|
{ "tls trust", "Force TLS connection and trust server's certificate." },
|
||||||
@ -192,7 +195,8 @@ static struct cmd_t command_defs[] = {
|
|||||||
"/connect odin@valhalla.edda server talk.google.com",
|
"/connect odin@valhalla.edda server talk.google.com",
|
||||||
"/connect freyr@vanaheimr.edda port 5678",
|
"/connect freyr@vanaheimr.edda port 5678",
|
||||||
"/connect me@localhost.test.org server 127.0.0.1 tls disable",
|
"/connect me@localhost.test.org server 127.0.0.1 tls disable",
|
||||||
"/connect me@chatty server chatty.com port 5443")
|
"/connect me@chatty server chatty.com port 5443",
|
||||||
|
"/connect server.supporting.sasl.anonymous.example")
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "/tls",
|
{ "/tls",
|
||||||
@ -2013,7 +2017,7 @@ static struct cmd_t command_defs[] = {
|
|||||||
{ "rotate on|off", "Rotate log, default on. Does not take effect if you specified a filename yourself when starting Profanity." },
|
{ "rotate on|off", "Rotate log, default on. Does not take effect if you specified a filename yourself when starting Profanity." },
|
||||||
{ "maxsize <bytes>", "With rotate enabled, specifies the max log size, defaults to 10485760 (10MB)." },
|
{ "maxsize <bytes>", "With rotate enabled, specifies the max log size, defaults to 10485760 (10MB)." },
|
||||||
{ "shared on|off", "Share logs between all instances, default: on. When off, the process id will be included in the log filename. Does not take effect if you specified a filename yourself when starting Profanity." },
|
{ "shared on|off", "Share logs between all instances, default: on. When off, the process id will be included in the log filename. Does not take effect if you specified a filename yourself when starting Profanity." },
|
||||||
{"level INFO|DEBUG|WARN|EFFOR", "Set the log level. Default is INFO. Only works with default log file, not with user provided log file during startup via -f." })
|
{"level INFO|DEBUG|WARN|ERROR", "Set the log level. Default is INFO. Only works with default log file, not with user provided log file during startup via -f." })
|
||||||
CMD_NOEXAMPLES
|
CMD_NOEXAMPLES
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -120,8 +120,8 @@
|
|||||||
|
|
||||||
static void _update_presence(const resource_presence_t presence,
|
static void _update_presence(const resource_presence_t presence,
|
||||||
const char* const show, gchar** args);
|
const char* const show, gchar** args);
|
||||||
static void _cmd_set_boolean_preference(gchar* arg, const char* const command,
|
static gboolean _cmd_set_boolean_preference(gchar* arg, const char* const command,
|
||||||
const char* const display, preference_t pref);
|
const char* const display, preference_t pref);
|
||||||
static void _who_room(ProfWin* window, const char* const command, gchar** args);
|
static void _who_room(ProfWin* window, const char* const command, gchar** args);
|
||||||
static void _who_roster(ProfWin* window, const char* const command, gchar** args);
|
static void _who_roster(ProfWin* window, const char* const command, gchar** args);
|
||||||
static gboolean _cmd_execute(ProfWin* window, const char* const command, const char* const inp);
|
static gboolean _cmd_execute(ProfWin* window, const char* const command, const char* const inp);
|
||||||
@ -6517,9 +6517,8 @@ cmd_log(ProfWin* window, const char* const command, gchar** args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(subcmd, "level") == 0) {
|
if (strcmp(subcmd, "level") == 0) {
|
||||||
if (g_strcmp0(value, "INFO") == 0 || g_strcmp0(value, "DEBUG") == 0 || g_strcmp0(value, "WARN") == 0 || g_strcmp0(value, "ERROR") == 0) {
|
log_level_t prof_log_level;
|
||||||
|
if (log_level_from_string(value, &prof_log_level) == 0) {
|
||||||
log_level_t prof_log_level = log_level_from_string(value);
|
|
||||||
log_close();
|
log_close();
|
||||||
log_init(prof_log_level, NULL);
|
log_init(prof_log_level, NULL);
|
||||||
|
|
||||||
@ -8580,31 +8579,24 @@ _update_presence(const resource_presence_t resource_presence,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// helper function for boolean preference commands
|
// helper function for boolean preference commands
|
||||||
static void
|
static gboolean
|
||||||
_cmd_set_boolean_preference(gchar* arg, const char* const command,
|
_cmd_set_boolean_preference(gchar* arg, const char* const command,
|
||||||
const char* const display, preference_t pref)
|
const char* const display, preference_t pref)
|
||||||
{
|
{
|
||||||
if (arg == NULL) {
|
if (arg == NULL) {
|
||||||
cons_bad_cmd_usage(command);
|
cons_bad_cmd_usage(command);
|
||||||
} else if (strcmp(arg, "on") == 0) {
|
return FALSE;
|
||||||
GString* enabled = g_string_new(display);
|
} else if (g_strcmp0(arg, "on") == 0) {
|
||||||
g_string_append(enabled, " enabled.");
|
cons_show("%s enabled.", display);
|
||||||
|
|
||||||
cons_show(enabled->str);
|
|
||||||
prefs_set_boolean(pref, TRUE);
|
prefs_set_boolean(pref, TRUE);
|
||||||
|
} else if (g_strcmp0(arg, "off") == 0) {
|
||||||
g_string_free(enabled, TRUE);
|
cons_show("%s disabled.", display);
|
||||||
} else if (strcmp(arg, "off") == 0) {
|
|
||||||
GString* disabled = g_string_new(display);
|
|
||||||
g_string_append(disabled, " disabled.");
|
|
||||||
|
|
||||||
cons_show(disabled->str);
|
|
||||||
prefs_set_boolean(pref, FALSE);
|
prefs_set_boolean(pref, FALSE);
|
||||||
|
|
||||||
g_string_free(disabled, TRUE);
|
|
||||||
} else {
|
} else {
|
||||||
cons_bad_cmd_usage(command);
|
cons_bad_cmd_usage(command);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
18
src/log.c
18
src/log.c
@ -233,21 +233,25 @@ log_msg(log_level_t level, const char* const area, const char* const msg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log_level_t
|
int
|
||||||
log_level_from_string(char* log_level)
|
log_level_from_string(char* log_level, log_level_t* level)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
assert(log_level != NULL);
|
assert(log_level != NULL);
|
||||||
|
assert(level != NULL);
|
||||||
if (strcmp(log_level, "DEBUG") == 0) {
|
if (strcmp(log_level, "DEBUG") == 0) {
|
||||||
return PROF_LEVEL_DEBUG;
|
*level = PROF_LEVEL_DEBUG;
|
||||||
} else if (strcmp(log_level, "INFO") == 0) {
|
} else if (strcmp(log_level, "INFO") == 0) {
|
||||||
return PROF_LEVEL_INFO;
|
*level = PROF_LEVEL_INFO;
|
||||||
} else if (strcmp(log_level, "WARN") == 0) {
|
} else if (strcmp(log_level, "WARN") == 0) {
|
||||||
return PROF_LEVEL_WARN;
|
*level = PROF_LEVEL_WARN;
|
||||||
} else if (strcmp(log_level, "ERROR") == 0) {
|
} else if (strcmp(log_level, "ERROR") == 0) {
|
||||||
return PROF_LEVEL_ERROR;
|
*level = PROF_LEVEL_ERROR;
|
||||||
} else { // default logging is warn
|
} else { // default logging is warn
|
||||||
return PROF_LEVEL_WARN;
|
*level = PROF_LEVEL_WARN;
|
||||||
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
|
@ -55,7 +55,7 @@ void log_info(const char* const msg, ...);
|
|||||||
void log_warning(const char* const msg, ...);
|
void log_warning(const char* const msg, ...);
|
||||||
void log_error(const char* const msg, ...);
|
void log_error(const char* const msg, ...);
|
||||||
void log_msg(log_level_t level, const char* const area, const char* const msg);
|
void log_msg(log_level_t level, const char* const area, const char* const msg);
|
||||||
log_level_t log_level_from_string(char* log_level);
|
int log_level_from_string(char* log_level, log_level_t* level);
|
||||||
const char* log_string_from_level(log_level_t level);
|
const char* log_string_from_level(log_level_t level);
|
||||||
|
|
||||||
void log_stderr_init(log_level_t level);
|
void log_stderr_init(log_level_t level);
|
||||||
|
@ -175,7 +175,8 @@ _init(char* log_level, char* config_file, char* log_file, char* theme_name)
|
|||||||
|
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
files_create_directories();
|
files_create_directories();
|
||||||
log_level_t prof_log_level = log_level_from_string(log_level);
|
log_level_t prof_log_level;
|
||||||
|
log_level_from_string(log_level, &prof_log_level);
|
||||||
prefs_load(config_file);
|
prefs_load(config_file);
|
||||||
log_init(prof_log_level, log_file);
|
log_init(prof_log_level, log_file);
|
||||||
log_stderr_init(PROF_LEVEL_ERROR);
|
log_stderr_init(PROF_LEVEL_ERROR);
|
||||||
|
@ -367,34 +367,20 @@ char*
|
|||||||
autocomplete_param_no_with_func(const char* const input, char* command, int arg_number, autocomplete_func func, gboolean previous, void* context)
|
autocomplete_param_no_with_func(const char* const input, char* command, int arg_number, autocomplete_func func, gboolean previous, void* context)
|
||||||
{
|
{
|
||||||
if (strncmp(input, command, strlen(command)) == 0) {
|
if (strncmp(input, command, strlen(command)) == 0) {
|
||||||
GString* result_str = NULL;
|
|
||||||
|
|
||||||
// count tokens properly
|
// count tokens properly
|
||||||
int num_tokens = count_tokens(input);
|
int num_tokens = count_tokens(input);
|
||||||
|
|
||||||
// if correct number of tokens, then candidate for autocompletion of last param
|
// if correct number of tokens, then candidate for autocompletion of last param
|
||||||
if (num_tokens == arg_number) {
|
if (num_tokens == arg_number) {
|
||||||
gchar* start_str = get_start(input, arg_number);
|
auto_gchar gchar* start_str = get_start(input, arg_number);
|
||||||
gchar* comp_str = g_strdup(&input[strlen(start_str)]);
|
auto_gchar gchar* comp_str = g_strdup(&input[strlen(start_str)]);
|
||||||
|
|
||||||
// autocomplete param
|
// autocomplete param
|
||||||
if (comp_str) {
|
if (comp_str) {
|
||||||
char* found = func(comp_str, previous, context);
|
auto_gchar gchar* found = func(comp_str, previous, context);
|
||||||
if (found) {
|
if (found) {
|
||||||
result_str = g_string_new("");
|
return g_strdup_printf("%s%s", start_str, found);
|
||||||
g_string_append(result_str, start_str);
|
|
||||||
g_string_append(result_str, found);
|
|
||||||
|
|
||||||
free(start_str);
|
|
||||||
free(comp_str);
|
|
||||||
|
|
||||||
char* result = result_str->str;
|
|
||||||
g_string_free(result_str, FALSE);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
free(start_str);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -418,14 +404,12 @@ autocomplete_remove_older_than_max_reverse(Autocomplete ac, int maxsize)
|
|||||||
static gchar*
|
static gchar*
|
||||||
_search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction)
|
_search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction)
|
||||||
{
|
{
|
||||||
gchar* search_str_ascii = g_str_to_ascii(ac->search_str, NULL);
|
auto_gchar gchar* search_str_ascii = g_str_to_ascii(ac->search_str, NULL);
|
||||||
gchar* search_str_lower = g_ascii_strdown(search_str_ascii, -1);
|
auto_gchar gchar* search_str_lower = g_ascii_strdown(search_str_ascii, -1);
|
||||||
g_free(search_str_ascii);
|
|
||||||
|
|
||||||
while (curr) {
|
while (curr) {
|
||||||
gchar* curr_ascii = g_str_to_ascii(curr->data, NULL);
|
auto_gchar gchar* curr_ascii = g_str_to_ascii(curr->data, NULL);
|
||||||
gchar* curr_lower = g_ascii_strdown(curr_ascii, -1);
|
auto_gchar gchar* curr_lower = g_ascii_strdown(curr_ascii, -1);
|
||||||
g_free(curr_ascii);
|
|
||||||
|
|
||||||
// match found
|
// match found
|
||||||
if (strncmp(curr_lower, search_str_lower, strlen(search_str_lower)) == 0) {
|
if (strncmp(curr_lower, search_str_lower, strlen(search_str_lower)) == 0) {
|
||||||
@ -435,27 +419,13 @@ _search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction
|
|||||||
|
|
||||||
// if contains space, quote before returning
|
// if contains space, quote before returning
|
||||||
if (quote && g_strrstr(curr->data, " ")) {
|
if (quote && g_strrstr(curr->data, " ")) {
|
||||||
GString* quoted = g_string_new("\"");
|
return g_strdup_printf("\"%s\"", (gchar*)curr->data);
|
||||||
g_string_append(quoted, curr->data);
|
|
||||||
g_string_append(quoted, "\"");
|
|
||||||
|
|
||||||
gchar* result = quoted->str;
|
|
||||||
g_string_free(quoted, FALSE);
|
|
||||||
|
|
||||||
g_free(search_str_lower);
|
|
||||||
g_free(curr_lower);
|
|
||||||
return result;
|
|
||||||
|
|
||||||
// otherwise just return the string
|
// otherwise just return the string
|
||||||
} else {
|
} else {
|
||||||
g_free(search_str_lower);
|
|
||||||
g_free(curr_lower);
|
|
||||||
return strdup(curr->data);
|
return strdup(curr->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(curr_lower);
|
|
||||||
|
|
||||||
if (direction == PREVIOUS) {
|
if (direction == PREVIOUS) {
|
||||||
curr = g_list_previous(curr);
|
curr = g_list_previous(curr);
|
||||||
} else {
|
} else {
|
||||||
@ -463,6 +433,5 @@ _search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(search_str_lower);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -67,10 +67,10 @@ get_log_file_location(void)
|
|||||||
return mock_ptr_type(char*);
|
return mock_ptr_type(char*);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_level_t
|
int
|
||||||
log_level_from_string(char* log_level)
|
log_level_from_string(char* log_level, log_level_t* level)
|
||||||
{
|
{
|
||||||
return mock_type(log_level_t);
|
return mock_type(int);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user