void gui_entry_downcase_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_tolower(entry->text[pos]); pos++; } gui_entry_redraw_from(entry, entry->pos); entry->pos = pos; gui_entry_fix_cursor(entry); gui_entry_draw(entry); }
static GList *completion_nicks_nonstrict(CHANNEL_REC *channel, const char *nick, const char *suffix) { GSList *nicks, *tmp; GList *list; char *tnick, *str, *in, *out; int len, str_len, tmplen; g_return_val_if_fail(channel != NULL, NULL); list = NULL; /* get all nicks from current channel, strip non alnum chars, compare again and add to completion list on matching */ len = strlen(nick); nicks = nicklist_getnicks(channel); str_len = 80; str = g_malloc(str_len+1); for (tmp = nicks; tmp != NULL; tmp = tmp->next) { NICK_REC *rec = tmp->data; tmplen = strlen(rec->nick); if (tmplen > str_len) { str_len = tmplen*2; str = g_realloc(str, str_len+1); } /* remove non alnum chars from nick */ in = rec->nick; out = str; while (*in != '\0') { if (i_isalnum(*in)) *out++ = *in; in++; } *out = '\0'; /* add to list if 'cleaned' nick matches */ if (g_strncasecmp(str, nick, len) == 0) { tnick = g_strconcat(rec->nick, suffix, NULL); if (completion_lowercase) g_strdown(tnick); if (glist_find_icase_string(list, tnick) == NULL) list = g_list_append(list, tnick); else g_free(tnick); } } g_free(str); g_slist_free(nicks); return list; }
void gui_entry_transpose_words(GUI_ENTRY_REC *entry) { int spos1, epos1, spos2, epos2; /* find last position */ epos2 = entry->pos; while (epos2 < entry->text_len && !i_isalnum(entry->text[epos2])) epos2++; while (epos2 < entry->text_len && i_isalnum(entry->text[epos2])) epos2++; /* find other position */ spos2 = epos2; while (spos2 > 0 && !i_isalnum(entry->text[spos2-1])) spos2--; while (spos2 > 0 && i_isalnum(entry->text[spos2-1])) spos2--; epos1 = spos2; while (epos1 > 0 && !i_isalnum(entry->text[epos1-1])) epos1--; spos1 = epos1; while (spos1 > 0 && i_isalnum(entry->text[spos1-1])) spos1--; /* do wordswap if any found */ if (spos1 < epos1 && epos1 < spos2 && spos2 < epos2) { unichar *first, *sep, *second; int i; first = (unichar *) g_malloc( (epos1 - spos1) * sizeof(unichar) ); sep = (unichar *) g_malloc( (spos2 - epos1) * sizeof(unichar) ); second = (unichar *) g_malloc( (epos2 - spos2) * sizeof(unichar) ); for (i = spos1; i < epos1; i++) first[i-spos1] = entry->text[i]; for (i = epos1; i < spos2; i++) sep[i-epos1] = entry->text[i]; for (i = spos2; i < epos2; i++) second[i-spos2] = entry->text[i]; entry->pos = spos1; for (i = 0; i < epos2-spos2; i++) entry->text[entry->pos++] = second[i]; for (i = 0; i < spos2-epos1; i++) entry->text[entry->pos++] = sep[i]; for (i = 0; i < epos1-spos1; i++) entry->text[entry->pos++] = first[i]; g_free(first); g_free(sep); g_free(second); } gui_entry_redraw_from(entry, spos1); gui_entry_fix_cursor(entry); gui_entry_draw(entry); }
static void gui_entry_move_words_right(GUI_ENTRY_REC *entry, int count, int to_space) { int pos; pos = entry->pos; while (count > 0 && pos < entry->text_len) { if (to_space) { while (pos < entry->text_len && entry->text[pos] == ' ') pos++; while (pos < entry->text_len && entry->text[pos] != ' ') pos++; } else { while (pos < entry->text_len && !i_isalnum(entry->text[pos])) pos++; while (pos < entry->text_len && i_isalnum(entry->text[pos])) pos++; } count--; } entry->pos = pos; }
static void gui_entry_move_words_left(GUI_ENTRY_REC *entry, int count, int to_space) { int pos; pos = entry->pos; while (count > 0 && pos > 0) { if (to_space) { while (pos > 0 && entry->text[pos-1] == ' ') pos--; while (pos > 0 && entry->text[pos-1] != ' ') pos--; } else { while (pos > 0 && !i_isalnum(entry->text[pos-1])) pos--; while (pos > 0 && i_isalnum(entry->text[pos-1])) pos--; } count--; } entry->pos = pos; }
/* Modify the script name so that all non-alphanumeric characters are translated to '_' */ void script_fix_name(char *name) { char *p; p = strrchr(name, '.'); if (p != NULL) *p = '\0'; while (*name != '\0') { if (*name != '_' && !i_isalnum(*name)) *name = '_'; name++; } }
/* Remove all "extra" characters from `nick'. Like _nick_ -> nick */ char *irc_nick_strip(const char *nick) { char *stripped, *spos; g_return_val_if_fail(nick != NULL, NULL); spos = stripped = g_strdup(nick); while (isnickchar(*nick)) { if (i_isalnum(*nick)) *spos++ = *nick; nick++; } if ((unsigned char) *nick >= 128) *spos++ = *nick; /* just add it so that nicks won't match.. */ *spos = '\0'; return stripped; }
static bool mirror_get_remote_cmd(struct dsync_cmd_context *ctx, const char *user, const char *const **cmd_args_r) { const char *p, *host, *const *argv = ctx->ctx.args; if (argv[1] != NULL) { /* more than one parameter, so it contains a full command (e.g. ssh host dsync) */ mirror_get_remote_cmd_line(argv, cmd_args_r); return TRUE; } /* if it begins with /[a-z0-9]+:/, it's a mail location (e.g. mdbox:~/mail) */ for (p = argv[0]; *p != '\0'; p++) { if (!i_isalnum(*p)) { if (*p == ':') return FALSE; break; } } if (strchr(argv[0], ' ') != NULL || strchr(argv[0], '/') != NULL) { /* a) the whole command is in one string. this is mainly for backwards compatibility. b) script/path */ mirror_get_remote_cmd_line(t_strsplit(argv[0], " "), cmd_args_r); return TRUE; } /* [user@]host */ host = strchr(argv[0], '@'); if (host != NULL) user = t_strdup_until(argv[0], host++); else host = argv[0]; /* we'll assume virtual users, so in user@host it really means not to give ssh a username, but to give dsync -u user parameter. */ *cmd_args_r = get_ssh_cmd_args(host, "", user); return TRUE; }
bool sieve_variable_identifier_is_valid(const char *identifier) { const char *p = identifier; size_t plen = strlen(identifier); const char *pend; if ( plen == 0 || plen >= EXT_VARIABLES_MAX_VARIABLE_NAME_LEN ) return FALSE; pend = PTR_OFFSET(identifier, plen); if ( *p == '_' || i_isalpha(*p) ) { p++; while ( p < pend && (*p == '_' || i_isalnum(*p)) ) { p++; } } return ( p == pend ); }
static const char *ext_enotify_uri_scheme_parse(const char **uri_p) { string_t *scheme = t_str_new(EXT_ENOTIFY_MAX_SCHEME_LEN); const char *p = *uri_p; unsigned int len = 0; /* RFC 3968: * * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) * * FIXME: we do not allow '%' in schemes. Is this correct? */ if ( !i_isalpha(*p) ) return NULL; str_append_c(scheme, *p); p++; while ( *p != '\0' && len < EXT_ENOTIFY_MAX_SCHEME_LEN ) { if ( !i_isalnum(*p) && *p != '+' && *p != '-' && *p != '.' ) break; str_append_c(scheme, *p); p++; len++; } if ( *p != ':' ) return NULL; p++; *uri_p = p; return str_c(scheme); }
static bool arg_testsuite_string_validate (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, struct sieve_command *cmd) { enum { ST_NONE, ST_OPEN, ST_SUBSTITUTION, ST_PARAM, ST_CLOSE } state = ST_NONE; pool_t pool = sieve_ast_pool((*arg)->ast); struct sieve_arg_catenated_string *catstr = NULL; string_t *str = sieve_ast_argument_str(*arg); const char *p, *strstart, *substart = NULL; const char *strval = (const char *) str_data(str); const char *strend = strval + str_len(str); bool result = TRUE; string_t *subs_name = t_str_new(256); string_t *subs_param = t_str_new(256); T_BEGIN { /* Initialize substitution structure */ p = strval; strstart = p; while ( result && p < strend ) { switch ( state ) { /* Nothing found yet */ case ST_NONE: if ( *p == '%' ) { substart = p; state = ST_OPEN; str_truncate(subs_name, 0); str_truncate(subs_param, 0); } p++; break; /* Got '%' */ case ST_OPEN: if ( *p == '{' ) { state = ST_SUBSTITUTION; p++; } else state = ST_NONE; break; /* Got '%{' */ case ST_SUBSTITUTION: state = ST_PARAM; while ( *p != '}' && *p != ':' ) { if ( !i_isalnum(*p) ) { state = ST_NONE; break; } str_append_c(subs_name, *p); p++; } break; /* Got '%{name' */ case ST_PARAM: if ( *p == ':' ) { p++; while ( *p != '}' ) { str_append_c(subs_param, *p); p++; } } state = ST_CLOSE; break; /* Finished parsing param, expecting '}' */ case ST_CLOSE: if ( *p == '}' ) { struct sieve_ast_argument *strarg; /* We now know that the substitution is valid */ if ( catstr == NULL ) { catstr = sieve_arg_catenated_string_create(*arg); } /* Add the substring that is before the substitution to the * variable-string AST. */ if ( substart > strstart ) { string_t *newstr = str_new(pool, substart - strstart); str_append_n(newstr, strstart, substart - strstart); strarg = sieve_ast_argument_string_create_raw ((*arg)->ast, newstr, (*arg)->source_line); sieve_arg_catenated_string_add_element(catstr, strarg); /* Give other substitution extensions a chance to do their work */ if ( !sieve_validator_argument_activate_super (valdtr, cmd, strarg, FALSE) ) { result = FALSE; break; } } strarg = testsuite_substitution_argument_create (valdtr, (*arg)->ast, (*arg)->source_line, str_c(subs_name), str_c(subs_param)); if ( strarg != NULL ) sieve_arg_catenated_string_add_element(catstr, strarg); else { sieve_argument_validate_error(valdtr, *arg, "unknown testsuite substitution type '%s'", str_c(subs_name)); } strstart = p + 1; substart = strstart; p++; } /* Finished, reset for the next substitution */ state = ST_NONE; } } } T_END; /* Bail out early if substitution is invalid */ if ( !result ) return FALSE; /* Check whether any substitutions were found */ if ( catstr == NULL ) { /* No substitutions in this string, pass it on to any other substution * extension. */ return sieve_validator_argument_activate_super(valdtr, cmd, *arg, TRUE); } /* Add the final substring that comes after the last substitution to the * variable-string AST. */ if ( strend > strstart ) { struct sieve_ast_argument *strarg; string_t *newstr = str_new(pool, strend - strstart); str_append_n(newstr, strstart, strend - strstart); strarg = sieve_ast_argument_string_create_raw ((*arg)->ast, newstr, (*arg)->source_line); sieve_arg_catenated_string_add_element(catstr, strarg); /* Give other substitution extensions a chance to do their work */ if ( !sieve_validator_argument_activate_super (valdtr, cmd, strarg, FALSE) ) return FALSE; } return TRUE; }
/* 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; } }
/* Expand key code - returns TRUE if successful. */ static int expand_key(const char *key, GSList **out, int *limit) { GSList *tmp; const char *start; int last_hyphen; if ((*limit)-- < 0) { return FALSE; } /* meta-^W^Gf -> ^[-^W-^G-f */ start = NULL; last_hyphen = TRUE; for (; *key != '\0'; key++) { if (start != NULL) { if (i_isalnum(*key) || *key == '_') { /* key combo continues */ continue; } if (!expand_combo(start, key-1, out, limit)) return FALSE; expand_out_char(*out, '-'); start = NULL; } if (*key == '-') { if (last_hyphen) { expand_out_char(*out, '-'); expand_out_char(*out, '-'); } last_hyphen = !last_hyphen; } else if (*key == '^') { expand_out_char(*out, '^'); /* ctrl-code */ if (key[1] != '\0' && key[1] != '-') { key++; expand_out_char(*out, *key); } else { /* escaped syntax for ^, see gui-readline.c */ expand_out_char(*out, '-'); } expand_out_char(*out, '-'); last_hyphen = FALSE; /* optional */ } else if (last_hyphen && i_isalpha(*key)) { /* possibly beginning of keycombo */ start = key; last_hyphen = FALSE; } else if (g_utf8_validate(key, -1, NULL)) { /* Assume we are looking at the start of a * multibyte sequence we will receive as-is, * so add it to the list as-is. */ const char *p, *end = g_utf8_next_char(key); for (p = key; p != end; p++) expand_out_char(*out, *p); expand_out_char(*out, '-'); /* The for loop skips past the remaining character. * Nasty, I know... */ key = end - 1; last_hyphen = FALSE; } else { expand_out_char(*out, *key); expand_out_char(*out, '-'); last_hyphen = FALSE; /* optional */ } } if (start != NULL) return expand_combo(start, key-1, out, limit); for (tmp = *out; tmp != NULL; tmp = tmp->next) { GString *str = tmp->data; g_string_truncate(str, str->len-1); } return TRUE; }
static bool ext_enotify_option_parse (struct sieve_enotify_env *nenv, const char *option, bool name_only, const char **opt_name_r, const char **opt_value_r) { const char *p = option; /* "<optionname>=<value>". * * l-d = ALPHA / DIGIT * l-d-p = l-d / "." / "-" / "_" * optionname = l-d *l-d-p * value = *(%x01-09 / %x0B-0C / %x0E-FF) */ /* * Parse option name * * optionname = l-d *l-d-p */ /* Explicitly report empty option as such */ if ( *p == '\0' ) { sieve_enotify_error(nenv, "empty option specified"); return FALSE; } /* l-d = ALPHA / DIGIT */ if ( i_isalnum(*p) ) { p++; /* l-d-p = l-d / "." / "-" / "_" */ while ( i_isalnum(*p) || *p == '.' || *p == '-' || *p == '_' ) p++; } /* Parsing must end at '=' and we must parse at least one character */ if ( *p != '=' || p == option ) { sieve_enotify_error(nenv, "invalid option name specified in option '%s'", str_sanitize(option, 80)); return FALSE; } /* Assign option name */ if ( opt_name_r != NULL ) *opt_name_r = t_strdup_until(option, p); /* Skip '=' */ p++; /* Exit now if only the option name is of interest */ if ( name_only ) return TRUE; /* * Parse option value */ /* value = *(%x01-09 / %x0B-0C / %x0E-FF) */ while ( *p != '\0' && *p != 0x0A && *p != 0x0D ) p++; /* Parse must end at end of string */ if ( *p != '\0' ) { sieve_enotify_error(nenv, "notify command: invalid option value specified in option '%s'", str_sanitize(option, 80)); return FALSE; } /* Assign option value */ if ( opt_value_r != NULL ) *opt_value_r = p; return TRUE; }
static int smtp_parse_ehlo_line(struct smtp_parser *parser, const char **key_r, const char *const **params_r) { const unsigned char *pbegin = parser->cur; ARRAY_TYPE(const_string) params = ARRAY_INIT; const char *param; /* ehlo-line = ehlo-keyword *( SP ehlo-param ) ehlo-keyword = (ALPHA / DIGIT) *(ALPHA / DIGIT / "-") ; additional syntax of ehlo-params depends on ; ehlo-keyword ehlo-param = 1*(%d33-126) ; any CHAR excluding <SP> and all ; control characters (US-ASCII 0-31 and 127 ; inclusive) */ if (parser->cur >= parser->end || !i_isalnum(*parser->cur)) { parser->error = "Unexpected character in EHLO keyword"; return -1; } parser->cur++; while (parser->cur < parser->end && (i_isalnum(*parser->cur) || *parser->cur == '-')) parser->cur++; if (key_r != NULL) *key_r = p_strdup_until(parser->pool, pbegin, parser->cur); if (parser->cur >= parser->end) { if (params_r != NULL) *params_r = p_new(parser->pool, const char *, 1); return 1; } if (*parser->cur != ' ') { parser->error = "Unexpected character in EHLO keyword"; return -1; } parser->cur++; pbegin = parser->cur; if (params_r != NULL) p_array_init(¶ms, parser->pool, 32); while (parser->cur < parser->end) { if (*parser->cur == ' ') { if (parser->cur+1 >= parser->end || *(parser->cur+1) == ' ') { parser->error = "Missing EHLO parameter after ' '"; return -1; } if (params_r != NULL) { param = p_strdup_until(parser->pool, pbegin, parser->cur); array_append(¶ms, ¶m, 1); } pbegin = parser->cur + 1; } else if (!smtp_char_is_ehlo_param(*parser->cur)) { parser->error = "Unexpected character in EHLO parameter"; return -1; } parser->cur++; } if (params_r != NULL) { array_append_zero(¶ms); *params_r = array_idx(¶ms, 0); } return 1; }