if (cb->func == func) {
rec->callbacks =
g_slist_remove(rec->callbacks, cb);
+ g_free(cb);
return rec;
}
}
return pos;
}
-static char *cmd_get_quoted_param(char **data)
+char *cmd_get_quoted_param(char **data)
{
char *pos, quote;
quote = **data; (*data)++;
pos = *data;
- while (**data != '\0' && **data != quote) {
+ while (**data != '\0' && (**data != quote ||
+ ((*data)[1] != ' ' && (*data)[1] != '\0'))) {
if (**data == '\\' && (*data)[1] != '\0')
g_memmove(*data, (*data)+1, strlen(*data));
(*data)++;
}
- if (**data != '\0') *(*data)++ = '\0';
+ if (**data == quote) {
+ *(*data)++ = '\0';
+ if (**data == ' ')
+ (*data)++;
+ }
return pos;
}
}
(*data)++;
- if (**data == '-' && i_isspace((*data)[1])) {
+ if (**data == '-' && (*data)[1] == ' ') {
/* -- option means end of options even
if next word starts with - */
(*data)++;
- while (i_isspace(**data)) (*data)++;
+ while (**data == ' ') (*data)++;
break;
}
if (**data == '\0')
option = "-";
- else if (!i_isspace(**data))
+ else if (**data != ' ')
option = cmd_get_param(data);
else {
option = "-";
*optlist[pos] == '!')
option = NULL;
- while (i_isspace(**data)) (*data)++;
+ while (**data == ' ') (*data)++;
continue;
}
}
option = NULL;
- while (i_isspace(**data)) (*data)++;
+ while (**data == ' ') (*data)++;
}
return 0;
GHashTable *options;
} CMD_TEMP_REC;
-static char *get_optional_channel(WI_ITEM_REC *active_item, char **data,
- int require_name)
+static const char *
+get_optional_channel(WI_ITEM_REC *active_item, char **data, int require_name)
{
CHANNEL_REC *chanrec;
- char *tmp, *origtmp, *channel, *ret;
+ const char *ret;
+ char *tmp, *origtmp, *channel;
if (active_item == NULL) {
/* no active channel in window, channel required */
if (strcmp(channel, "*") == 0 && !require_name) {
/* "*" means active channel */
cmd_get_param(data);
- ret = active_item->name;
+ ret = window_item_get_target(active_item);
} else if (!server_ischannel(active_item->server, channel)) {
/* we don't have channel parameter - use active channel */
- ret = active_item->name;
+ ret = window_item_get_target(active_item);
} else {
/* Find the channel first and use it's name if found.
This allows automatic !channel -> !XXXXXchannel replaces. */
/* optional channel as first parameter */
require_name = (count & PARAM_FLAG_OPTCHAN_NAME) ==
PARAM_FLAG_OPTCHAN_NAME;
- arg = get_optional_channel(item, &datad, require_name);
+ arg = (char *) get_optional_channel(item, &datad, require_name);
str = (char **) va_arg(args, char **);
if (str != NULL) *str = arg;
g_return_if_fail(line != NULL);
- if (*line == '\0') {
- /* empty line, forget it. */
- signal_stop();
- return;
- }
-
- cmdchar = strchr(settings_get_str("cmdchars"), *line);
+ cmdchar = *line == '\0' ? NULL :
+ strchr(settings_get_str("cmdchars"), *line);
if (cmdchar != NULL && line[1] == ' ') {
/* "/ text" = same as sending "text" to active channel. */
line += 2;
parse_command(line, expand_aliases, server, item);
}
+static int eval_recursion_depth=0;
/* SYNTAX: EVAL <command(s)> */
static void cmd_eval(const char *data, SERVER_REC *server, void *item)
{
g_return_if_fail(data != NULL);
+ if (eval_recursion_depth > 100)
+ cmd_return_error(CMDERR_EVAL_MAX_RECURSE);
+
+ eval_recursion_depth++;
eval_special_string(data, "", server, item);
+ eval_recursion_depth--;
}
/* SYNTAX: CD <directory> */