Example #1
0
static bool pattern_is_inboxcase(const char *pattern, char separator)
{
	const char *p = pattern, *inboxp = inbox;

	/* skip over exact matches */
	while (*inboxp == i_toupper(*p) && *p != '\0') {
		inboxp++; p++;
	}
	if (*p != '%') {
		return *p == '*' || *p == separator ||
			(*inboxp == '\0' && *p == '\0');
	}

	/* handle 'I%B%X' style checks */
	for (; *p != '\0' && *p != '*' && *p != separator; p++) {
		if (*p != '%') {
			inboxp = strchr(inboxp, i_toupper(*p));
			if (inboxp == NULL)
				return FALSE;

			if (*++inboxp == '\0') {
				/* now check that it doesn't end with
				   any invalid chars */
				if (*++p == '%') p++;
				if (*p != '\0' && *p != '*' &&
				    *p != separator)
					return FALSE;
				break;
			}
		}
	}
	return TRUE;
}
Example #2
0
const char *rfc2822_header_field_name_sanitize(const char *name)
{
	char *result = t_strdup_noconst(name);
	char *p;

	/* Make the whole name lower case ... */
	result = str_lcase(result);

	/* ... except for the first letter and those that follow '-' */
	p = result;
	*p = i_toupper(*p);
	while ( *p != '\0' ) {
		if ( *p == '-' ) {
			p++;

			if ( *p != '\0' )
				*p = i_toupper(*p);

			continue;
		}

		p++;
	}

	return result;
}
Example #3
0
int i_my_strcasecmp(const char *s1, const char *s2)
{
	while (*s1 != '\0' && i_toupper(*s1) == i_toupper(*s2)) {
		s1++; s2++;
	}

        return i_toupper(*s1) - i_toupper(*s2);
}
Example #4
0
int config_get_bool(CONFIG_REC *rec, const char *section, const char *key, int def)
{
	char *str;

	str = config_get_str(rec, section, key, NULL);
	if (str == NULL) return def;

        return i_toupper(*str) == 'T' || i_toupper(*str) == 'Y';
}
Example #5
0
int i_my_strncasecmp(const char *s1, const char *s2, size_t max_chars)
{
	while (max_chars > 1 && *s1 != '\0' &&
	       i_toupper(*s1) == i_toupper(*s2)) {
		s1++; s2++; max_chars--;
	}

        return i_toupper(*s1) - i_toupper(*s2);
}
Example #6
0
int config_node_get_bool(CONFIG_NODE *parent, const char *key, int def)
{
	char *str;

	str = config_node_get_str(parent, key, NULL);
	if (str == NULL) return def;

	return i_toupper(*str) == 'T' || i_toupper(*str) == 'Y' ||
		(i_toupper(*str) == 'O' && i_toupper(str[1]) == 'N');
}
Example #7
0
static void check_oldcrap(void)
{
        FILE *f;
	char *path, str[256];
        int found;

        /* check that default.theme is up-to-date */
	path = g_strdup_printf("%s/default.theme", get_irssi_dir());
	f = fopen(path, "r+");
	if (f == NULL) {
		g_free(path);
                return;
	}
        found = FALSE;
	while (!found && fgets(str, sizeof(str), f) != NULL)
                found = strstr(str, "abstracts = ") != NULL;
	fclose(f);

	if (found) {
		g_free(path);
		return;
	}

	printf("\nYou seem to have old default.theme in "IRSSI_DIR_SHORT"/ directory.\n");
        printf("Themeing system has changed a bit since last irssi release,\n");
        printf("you should either delete your old default.theme or manually\n");
        printf("merge it with the new default.theme.\n\n");
	printf("Do you want to delete the old theme now? (Y/n)\n");

	str[0] = '\0';
	fgets(str, sizeof(str), stdin);
	if (i_toupper(str[0]) == 'Y' || str[0] == '\n' || str[0] == '\0')
                remove(path);
	g_free(path);
}
Example #8
0
int i_memcasecmp(const void *p1, const void *p2, size_t size)
{
	const unsigned char *s1 = p1;
	const unsigned char *s2 = p2;
	int ret;

	while (size > 0) {
		ret = i_toupper(*s1) - i_toupper(*s2);
		if (ret != 0)
			return ret;

		s1++; s2++; size--;
	}

        return 0;
}
Example #9
0
char *str_ucase(char *str)
{
	char *p;

	for (p = str; *p != '\0'; p++)
		*p = i_toupper(*p);
        return str;
}
Example #10
0
File: bans.c Project: irssi/irssi
static int parse_custom_ban(const char *type)
{
	char **list;
	int n, ban_type;

        ban_type = 0;
	list = g_strsplit(type, " ", -1);
	for (n = 0; list[n] != NULL; n++) {
		if (i_toupper(list[n][0]) == 'N')
			ban_type |= IRC_MASK_NICK;
		else if (i_toupper(list[n][0]) == 'U')
			ban_type |= IRC_MASK_USER;
		else if (i_toupper(list[n][0]) == 'H')
			ban_type |= IRC_MASK_HOST | IRC_MASK_DOMAIN;
		else if (i_toupper(list[n][0]) == 'D')
			ban_type |= IRC_MASK_DOMAIN;
	}
	g_strfreev(list);

        return ban_type;
}
bool mod_upperfirst_modify(string_t *in, string_t **result)
{
	char *content;

	*result = t_str_new(str_len(in));
	str_append_str(*result, in);

	content = str_c_modifiable(*result);
	content[0] = i_toupper(content[0]);

	return TRUE;
}
Example #12
0
File: bans.c Project: irssi/irssi
static int parse_ban_type(const char *type)
{
	const char *pos;

	g_return_val_if_fail(type != NULL, 0);

	if (i_toupper(type[0]) == 'N')
		return BAN_TYPE_NORMAL;
	if (i_toupper(type[0]) == 'U')
		return BAN_TYPE_USER;
	if (i_toupper(type[0]) == 'H')
		return BAN_TYPE_HOST;
	if (i_toupper(type[0]) == 'D')
		return BAN_TYPE_DOMAIN;
	if (i_toupper(type[0]) == 'C') {
		pos = strchr(type, ' ');
                if (pos != NULL)
			return parse_custom_ban(pos+1);
	}

        return 0;
}
Example #13
0
/* SYNTAX: MIRCDCC ON|OFF */
static void cmd_mircdcc(const char *data, SERVER_REC *server,
			QUERY_REC *item)
{
	CHAT_DCC_REC *dcc;

	g_return_if_fail(data != NULL);

	dcc = item_get_dcc((WI_ITEM_REC *) item);
	if (dcc == NULL) return;

	dcc->mirc_ctcp = i_toupper(*data) != 'N' &&
		g_ascii_strncasecmp(data, "OF", 2) != 0;
}
Example #14
0
static unsigned char *
t_unicode_str(const char *src, bool ucase, size_t *size)
{
    buffer_t *wstr;

    wstr = buffer_create_dynamic(unsafe_data_stack_pool, 32);
    for ( ; *src; src++) {
        buffer_append_c(wstr, ucase ? i_toupper(*src) : *src);
        buffer_append_c(wstr, '\0');
    }

    *size = buffer_get_used_size(wstr);
    return buffer_free_without_data(&wstr);
}
Example #15
0
static int redirect_args_match(const char *event_args,
			       const char *arg, int pos)
{
	const char *start;

	if (pos == -1)
		return TRUE;

        /* skip to the start of the wanted argument */
	while (pos > 0 && *event_args != '\0') {
                while (*event_args != ' ' && *event_args != '\0') event_args++;
		while (*event_args == ' ') event_args++;
                pos--;
	}

	/* now compare the arguments */
	start = event_args;
	while (*arg != '\0') {
		while (*arg != '\0' && *arg != ' ' && *event_args != '\0') {
			if (i_toupper(*arg) != i_toupper(*event_args))
				break;
			arg++; event_args++;
		}

		if ((*arg == '\0' || *arg == ' ') &&
		    (*event_args == '\0' || *event_args == ' '))
			return TRUE;

                /* compare the next argument */
		while (*arg != ' ' && *arg != '\0') arg++;
                while (*arg == ' ') arg++;

		event_args = start;
	}

        return FALSE;
}
Example #16
0
void gui_entry_upcase_word(GUI_ENTRY_REC *entry)
{
	int pos = entry->pos;
	while (pos < entry->text_len && !i_isalnum(entry->text[pos]))
		pos++;

	while (pos < entry->text_len && i_isalnum(entry->text[pos])) {
		entry->text[pos] = i_toupper(entry->text[pos]);
		pos++;
	}

	gui_entry_redraw_from(entry, entry->pos);
	entry->pos = pos;
	gui_entry_fix_cursor(entry);
	gui_entry_draw(entry);
}
Example #17
0
const unsigned char *
lm_hash(const char *passwd, unsigned char hash[LM_HASH_SIZE])
{
    static const unsigned char lm_magic[8] = "KGS!@#$%";
    unsigned char buffer[14];
    unsigned int i;

    strncpy((char *)buffer, passwd, sizeof(buffer));

    for (i = 0; i < sizeof(buffer); i++)
        buffer[i] = i_toupper(buffer[i]);

    deshash(hash, buffer, lm_magic);
    deshash(hash + 8, buffer + 7, lm_magic);

    safe_memset(buffer, 0, sizeof(buffer));

    return hash;
}
Example #18
0
/* SYNTAX: WINDOW STICK [<ref#>] [ON|OFF] */
static void cmd_window_stick(const char *data)
{
        MAIN_WINDOW_REC *mainwin;
        WINDOW_REC *win;

        mainwin = active_mainwin;
        win = active_mainwin->active;

	if (is_numeric(data, ' ')) {
		/* ref# specified */
		win = window_find_refnum(atoi(data));
		if (win == NULL) {
			printformat_window(active_win, MSGLEVEL_CLIENTERROR,
					   TXT_REFNUM_NOT_FOUND, data);
			return;
		}

		while (*data != ' ' && *data != '\0') data++;
		while (*data == ' ') data++;
	}

	if (g_strncasecmp(data, "OF", 2) == 0 || i_toupper(*data) == 'N') {
		/* unset sticky */
		if (!WINDOW_GUI(win)->sticky) {
			printformat_window(win, MSGLEVEL_CLIENTERROR,
					   TXT_WINDOW_NOT_STICKY);
		} else {
                        gui_window_set_unsticky(win);
			printformat_window(win, MSGLEVEL_CLIENTNOTICE,
					   TXT_WINDOW_UNSET_STICKY);
		}
	} else {
		/* set sticky */
		window_reparent(win, mainwin);
                gui_window_set_sticky(win);

		printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
				   TXT_WINDOW_SET_STICKY);
	}
}
Example #19
0
File: nicklist.c Project: GPF/irssi
/* Check is `msg' is meant for `nick'. */
int nick_match_msg(CHANNEL_REC *channel, const char *msg, const char *nick)
{
	const char *msgstart, *orignick;
	int len, fullmatch;

	g_return_val_if_fail(nick != NULL, FALSE);
	g_return_val_if_fail(msg != NULL, FALSE);

	if (channel != NULL && channel->server->nick_match_msg != NULL)
		return channel->server->nick_match_msg(msg, nick);

	/* first check for identical match */
	len = strlen(nick);
	if (g_ascii_strncasecmp(msg, nick, len) == 0 &&
	    !isalnumhigh((int) msg[len]))
		return TRUE;

	orignick = nick;
	for (;;) {
		nick = orignick;
		msgstart = msg;
                fullmatch = TRUE;

		/* check if it matches for alphanumeric parts of nick */
		while (*nick != '\0' && *msg != '\0') {
			if (i_toupper(*nick) == i_toupper(*msg)) {
				/* total match */
				msg++;
			} else if (i_isalnum(*msg) && !i_isalnum(*nick)) {
				/* some strange char in your nick, pass it */
                                fullmatch = FALSE;
			} else
				break;

			nick++;
		}

		if (msg != msgstart && !isalnumhigh(*msg)) {
			/* at least some of the chars in line matched the
			   nick, and msg continue with non-alphanum character,
			   this might be for us.. */
			if (*nick != '\0') {
				/* remove the rest of the non-alphanum chars
				   from nick and check if it then matches. */
                                fullmatch = FALSE;
				while (*nick != '\0' && !i_isalnum(*nick))
					nick++;
			}

			if (*nick == '\0') {
				/* yes, match! */
                                break;
			}
		}

		/* no match. check if this is a message to multiple people
		   (like nick1,nick2: text) */
		while (*msg != '\0' && *msg != ' ' && *msg != ',') msg++;

		if (*msg != ',') {
                        nick = orignick;
			break;
		}

                msg++;
	}

	if (*nick != '\0')
		return FALSE; /* didn't match */

	if (fullmatch)
		return TRUE; /* matched without fuzzyness */

	if (channel != NULL) {
		/* matched with some fuzzyness .. check if there's an exact match
		   for some other nick in the same channel. */
		return nick_nfind(channel, msgstart, (int) (msg-msgstart)) == NULL;
	} else {
		return TRUE;
	}
}
Example #20
0
static int wildcard_match_int(const char *data, const char *mask, bool icase)
{
  const char *ma = mask, *na = data, *lsm = NULL, *lsn = NULL;
  int match = 1;
  int sofar = 0;

  if (na[0] == '\0') {
	  /* empty string can match only "*" wildcard(s) */
	  while (ma[0] == '*') ma++;
	  return ma[0] == '\0' ? MATCH : NOMATCH;
  }
  /* find the end of each string */
  while (*(mask++) != '\0');
  mask-=2;
  while (*(data++) != '\0');
  data-=2;

  while (data >= na) {
    /* If the mask runs out of chars before the string, fall back on
     * a wildcard or fail. */
    if (mask < ma) {
      if (lsm != NULL) {
        data = --lsn;
        mask = lsm;
        if (data < na)
          lsm = NULL;
        sofar = 0;
      }
      else
        return NOMATCH;
    }

    switch (*mask) {
    case WILDS:                /* Matches anything */
      do
        mask--;                    /* Zap redundant wilds */
      while ((mask >= ma) && (*mask == WILDS));
      lsm = mask;
      lsn = data;
      match += sofar;
      sofar = 0;                /* Update fallback pos */
      if (mask < ma)
        return MATCH;
      continue;                 /* Next char, please */
    case WILDQ:
      mask--;
      data--;
      continue;                 /* '?' always matches */
    }
    if (icase ? (i_toupper(*mask) == i_toupper(*data)) :
	(*mask == *data)) {     /* If matching char */
      mask--;
      data--;
      sofar++;                  /* Tally the match */
      continue;                 /* Next char, please */
    }
    if (lsm != NULL) {          /* To to fallback on '*' */
      data = --lsn;
      mask = lsm;
      if (data < na)
        lsm = NULL;                /* Rewind to saved pos */
      sofar = 0;
      continue;                 /* Next char, please */
    }
    return NOMATCH;             /* No fallback=No match */
  }
  while ((mask >= ma) && (*mask == WILDS))
    mask--;                        /* Zap leftover %s & *s */
  return (mask >= ma) ? NOMATCH : MATCH;   /* Start of both = match */
}
Example #21
0
static int parse_timezone(const unsigned char *str, size_t len)
{
	int offset;
	char chr;

	if (len == 5 && (*str == '+' || *str == '-')) {
		/* numeric offset */
		if (!i_isdigit(str[1]) || !i_isdigit(str[2]) ||
		    !i_isdigit(str[3]) || !i_isdigit(str[4]))
			return FALSE;

		offset = ((str[1]-'0') * 10 + (str[2]-'0')) * 60  +
			(str[3]-'0') * 10 + (str[4]-'0');
		return *str == '+' ? offset : -offset;
	}

	if (len == 1) {
		/* military zone - handle them the correct way, not as
		   RFC822 says. RFC2822 though suggests that they'd be
		   considered as unspecified.. */
		chr = i_toupper(*str);
		if (chr < 'J')
			return (*str-'A'+1) * 60;
		if (chr == 'J')
			return 0;
		if (chr <= 'M')
			return (*str-'A') * 60;
		if (chr < 'Z')
			return ('M'-*str) * 60;
		return 0;
	}

	if (len == 2 && i_toupper(str[0]) == 'U' && i_toupper(str[1]) == 'T') {
		/* UT - Universal Time */
		return 0;
	}

	if (len == 3) {
		/* GMT | [ECMP][DS]T */
		if (str[2] != 'T')
			return 0;

		switch (i_toupper(*str)) {
		case 'E':
			offset = -5 * 60;
			break;
		case 'C':
			offset = -6 * 60;
			break;
		case 'M':
			offset = -7 * 60;
			break;
		case 'P':
			offset = -8 * 60;
			break;
		default:
			/* GMT and others */
			return 0;
		}

		if (i_toupper(str[1]) == 'D')
			return offset + 60;
		if (i_toupper(str[1]) == 'S')
			return offset;
	}

	return 0;
}
Example #22
0
static void settings_save_confirm(const char *line, char *fname)
{
	if (i_toupper(line[0]) == 'Y')
		settings_save_fe(fname);
	g_free(fname);
}
Example #23
0
static void settings_clean_confirm(const char *line)
{
	if (i_toupper(line[0]) == 'Y')
                settings_clean_invalid();
}