Merge pull request #81 from pasis/priority

introduce priority support
This commit is contained in:
James Booth
2012-11-13 14:40:24 -08:00
8 changed files with 157 additions and 15 deletions

View File

@@ -22,6 +22,8 @@
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <glib.h>
@@ -79,6 +81,8 @@ static void _notify_autocomplete(char *input, int *size);
static void _parameter_autocomplete(char *input, int *size, char *command,
autocomplete_func func);
static int _strtoi(char *str, int *saveptr, int min, int max);
// command prototypes
static gboolean _cmd_quit(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_help(const char * const inp, struct cmd_help_t help);
@@ -95,6 +99,7 @@ static gboolean _cmd_join(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_beep(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_notify(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_log(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_priority(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_intype(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_flash(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_set_showsplash(const char * const inp, struct cmd_help_t help);
@@ -433,6 +438,16 @@ static struct cmd_t setting_commands[] =
"",
"Config file section : [log]",
"Config file value : maxsize=bytes",
NULL } } },
{ "/priority",
_cmd_set_priority,
{ "/priority <value>", "Set priority for connection.",
{ "/priority <value>",
"--------------------",
"value : Number between -128 and 127. Default value is 0.",
"",
"Config file section : [jabber]",
NULL } } }
};
@@ -1432,13 +1447,43 @@ _cmd_set_log(const char * const inp, struct cmd_help_t help)
value = strtok(NULL, " ");
if (subcmd == NULL || value == NULL) {
cons_show("Usage: %s", help.usage);
} else {
if (strcmp(subcmd, "maxsize") == 0) {
intval = atoi(value);
return TRUE;
}
if (strcmp(subcmd, "maxsize") == 0) {
if (_strtoi(value, &intval, PREFS_MIN_LOG_SIZE, INT_MAX) == 0) {
prefs_set_max_log_size(intval);
cons_show("Log maxinum size set to %d bytes", intval);
}
/* TODO: make 'level' subcommand for debug level */
}
/* TODO: make 'level' subcommand for debug level */
return TRUE;
}
static gboolean
_cmd_set_priority(const char * const inp, struct cmd_help_t help)
{
char *value;
char inp_cpy[strlen(inp) + 1];
int intval;
strcpy(inp_cpy, inp);
strtok(inp_cpy, " ");
value = strtok(NULL, " ");
if (value == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
if (_strtoi(value, &intval, -128, 127) == 0) {
char *status = jabber_get_status();
prefs_set_priority((int)intval);
// update presence with new priority
jabber_update_presence(jabber_get_presence(), status);
if (status != NULL)
free(status);
cons_show("Priority set to %d.", intval);
}
return TRUE;
}
@@ -1705,3 +1750,24 @@ _notify_autocomplete(char *input, int *size)
}
}
}
static int
_strtoi(char *str, int *saveptr, int min, int max)
{
char *ptr;
int val;
errno = 0;
val = (int)strtol(str, &ptr, 0);
if (*str == '\0' || *ptr != '\0') {
cons_show("Illegal character. Must be a number.");
return -1;
} else if (errno == ERANGE || val < min || val > max) {
cons_show("Value out of range. Must be in %d..%d.", min, max);
return -1;
}
*saveptr = val;
return 0;
}