From: Timo Sirainen Date: Sun, 19 Apr 2020 13:11:47 +0000 (+0300) Subject: global: Replace strncasecmp() with str_begins_icase*() X-Git-Tag: 2.4.0~4232 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a75f7cccd1e5777769ee394e69a9cc66e090ecc5;p=thirdparty%2Fdovecot%2Fcore.git global: Replace strncasecmp() with str_begins_icase*() --- diff --git a/src/auth/mech-oauth2.c b/src/auth/mech-oauth2.c index 4348b10aff..eec1971d88 100644 --- a/src/auth/mech-oauth2.c +++ b/src/auth/mech-oauth2.c @@ -146,9 +146,9 @@ mech_xoauth2_auth_continue(struct auth_request *request, username = value; user_given = TRUE; } else if (str_begins(*ptr, "auth=", &value)) { - if (strncasecmp(value, "bearer ", 7) == 0 && - oauth2_valid_token(value+7)) { - token = value+7; + if (str_begins_icase(value, "bearer ", &value) && + oauth2_valid_token(value)) { + token = value; } else { e_info(request->mech_event, "Invalid continued data"); @@ -246,9 +246,9 @@ mech_oauthbearer_auth_continue(struct auth_request *request, for(ptr = fields; *ptr != NULL; ptr++) { if (str_begins(*ptr, "auth=", &value)) { - if (strncasecmp(value, "bearer ", 7) == 0 && - oauth2_valid_token(value+7)) { - token = value+7; + if (str_begins_icase(value, "bearer ", &value) && + oauth2_valid_token(value)) { + token = value; } else { e_info(request->mech_event, "Invalid continued data"); diff --git a/src/doveadm/doveadm-log.c b/src/doveadm/doveadm-log.c index 2654d9b787..5e0310219d 100644 --- a/src/doveadm/doveadm-log.c +++ b/src/doveadm/doveadm-log.c @@ -130,12 +130,12 @@ cmd_log_find_syslog_files(struct log_find_context *ctx, const char *path) static bool log_type_find(const char *str, enum log_type *type_r) { + const char *suffix; unsigned int i; - size_t len = strlen(str); for (i = 0; i < LAST_LOG_TYPE; i++) { - if (strncasecmp(str, failure_log_type_prefixes[i], len) == 0 && - failure_log_type_prefixes[i][len] == ':') { + if (str_begins_icase(failure_log_type_prefixes[i], str, &suffix) && + suffix[0] == ':') { *type_r = i; return TRUE; } diff --git a/src/doveadm/doveadm-zlib.c b/src/doveadm/doveadm-zlib.c index f7a8f5232c..0987de92e3 100644 --- a/src/doveadm/doveadm-zlib.c +++ b/src/doveadm/doveadm-zlib.c @@ -96,15 +96,17 @@ struct client { static bool client_input_get_compress_algorithm(struct client *client, const char *line) { + const char *algorithm; + /* skip tag */ while (*line != ' ' && *line != '\0') line++; - if (strncasecmp(line, " COMPRESS ", 10) != 0) + if (!str_begins_icase(line, " COMPRESS ", &algorithm)) return FALSE; - if (compression_lookup_handler(t_str_lcase(line+10), + if (compression_lookup_handler(t_str_lcase(algorithm), &client->handler) <= 0) - i_fatal("Unsupported compression mechanism: %s", line+10); + i_fatal("Unsupported compression mechanism: %s", algorithm); return TRUE; } diff --git a/src/imap-login/imap-login-cmd-id.c b/src/imap-login/imap-login-cmd-id.c index a1c6294651..809661ab25 100644 --- a/src/imap-login/imap-login-cmd-id.c +++ b/src/imap-login/imap-login-cmd-id.c @@ -66,8 +66,11 @@ static void cmd_id_x_forward_(struct imap_client *client, const char *key, const char *value) { - i_assert(strncasecmp(key, "x-forward-", 10) == 0); - client_add_forward_field(&client->common, key+10, value); + const char *suffix; + + if (!str_begins_icase(key, "x-forward-", &suffix)) + i_unreached(); + client_add_forward_field(&client->common, suffix, value); } static const struct imap_id_param_handler imap_login_id_params[] = { @@ -86,11 +89,11 @@ static const struct imap_id_param_handler imap_login_id_params[] = { static const struct imap_id_param_handler * imap_id_param_handler_find(const char *key) { - for (unsigned int i = 0; imap_login_id_params[i].key != NULL; i++) { - unsigned int prefix_len = strlen(imap_login_id_params[i].key); + const char *suffix; - if (strncasecmp(imap_login_id_params[i].key, key, prefix_len) == 0 && - (key[prefix_len] == '\0' || + for (unsigned int i = 0; imap_login_id_params[i].key != NULL; i++) { + if (str_begins_icase(key, imap_login_id_params[i].key, &suffix) && + (suffix[0] == '\0' || imap_login_id_params[i].key_is_prefix)) return &imap_login_id_params[i]; } diff --git a/src/imap-login/imap-proxy.c b/src/imap-login/imap-proxy.c index aa38062ebf..61dfff5d8a 100644 --- a/src/imap-login/imap-proxy.c +++ b/src/imap-login/imap-proxy.c @@ -51,11 +51,12 @@ static void proxy_write_id(struct imap_client *client, string_t *str) /* append any forward_ variables to request */ for(const char *const *ptr = client->common.auth_passdb_args; *ptr != NULL; ptr++) { - if (strncasecmp(*ptr, "forward_", 8) == 0) { + const char *suffix; + if (str_begins_icase(*ptr, "forward_", &suffix)) { const char *key = t_strconcat("x-forward-", - t_strcut((*ptr)+8, '='), + t_strcut(suffix, '='), NULL); - const char *val = i_strchr_to_next(*ptr, '='); + const char *val = i_strchr_to_next(suffix, '='); str_append_c(str, ' '); imap_append_string(str, key); str_append_c(str, ' '); @@ -219,12 +220,14 @@ client_send_login_reply(struct imap_client *client, string_t *str, const char *line) { const char *capability; - bool tagged_capability; + bool tagged_capability = FALSE; - capability = client->proxy_backend_capability; - tagged_capability = strncasecmp(line, "[CAPABILITY ", 12) == 0; - if (tagged_capability) - capability = t_strcut(line + 12, ']'); + if (!str_begins_icase(line, "[CAPABILITY ", &capability)) + capability = client->proxy_backend_capability; + else { + capability = t_strcut(capability, ']'); + tagged_capability = TRUE; + } if (client->client_ignores_capability_resp_code && capability != NULL) { /* client has used CAPABILITY command, so it didn't understand @@ -398,8 +401,7 @@ int imap_proxy_parse_line(struct client *client, const char *line) imap_client->proxy_rcvd_state = IMAP_PROXY_RCVD_STATE_LOGIN; const char *log_line = line; - if (strncasecmp(log_line, "NO ", 3) == 0) - log_line += 3; + (void)str_begins_icase(log_line, "NO ", &log_line); enum login_proxy_failure_type failure_type = LOGIN_PROXY_FAILURE_TYPE_AUTH; #define STR_NO_IMAP_RESP_CODE_AUTHFAILED "NO ["IMAP_RESP_CODE_AUTHFAILED"]" @@ -440,9 +442,9 @@ int imap_proxy_parse_line(struct client *client, const char *line) login_proxy_get_event(client->login_proxy), failure_type, log_line); return -1; - } else if (strncasecmp(line, "* CAPABILITY ", 13) == 0) { + } else if (str_begins_icase(line, "* CAPABILITY ", &line)) { i_free(imap_client->proxy_backend_capability); - imap_client->proxy_backend_capability = i_strdup(line + 13); + imap_client->proxy_backend_capability = i_strdup(line); return 0; } else if (str_begins_with(line, "C ")) { /* Reply to CAPABILITY command we sent */ @@ -460,7 +462,7 @@ int imap_proxy_parse_line(struct client *client, const char *line) return 1; } return 0; - } else if (strncasecmp(line, "I ", 2) == 0) { + } else if (str_begins_icase_with(line, "I ")) { /* Reply to ID command we sent, ignore it unless pipelining is disabled, in which case send either STARTTLS or login */ @@ -479,7 +481,7 @@ int imap_proxy_parse_line(struct client *client, const char *line) return 1; } return 0; - } else if (strncasecmp(line, "* ID ", 5) == 0) { + } else if (str_begins_icase_with(line, "* ID ")) { /* Reply to ID command we sent, ignore it */ return 0; } else if (str_begins_with(line, "* BYE ")) { diff --git a/src/imap-urlauth/imap-urlauth-worker.c b/src/imap-urlauth/imap-urlauth-worker.c index 3edf677151..8e5688d50c 100644 --- a/src/imap-urlauth/imap-urlauth-worker.c +++ b/src/imap-urlauth/imap-urlauth-worker.c @@ -795,7 +795,7 @@ client_ctrl_read_fds(struct client *client) static void client_ctrl_input(struct client *client) { const char *const *args; - const char *line; + const char *line, *value; int ret; timeout_reset(client->to_idle); @@ -881,9 +881,9 @@ static void client_ctrl_input(struct client *client) if (strcasecmp(*args, "debug") == 0) { client->debug = TRUE; /* apps=[,flags & NAMESPACE_FLAG_INBOX_USER) != 0 && !str_begins_with(name, "INBOX") && - strncasecmp(name, "INBOX", 5) == 0 && + str_begins_icase_with(name, "INBOX") && (name[5] == '\0' || name[5] == ns_sep)) { /* we'll do only case-sensitive comparisons later, so sanitize INBOX to be uppercase */ diff --git a/src/imap/cmd-store.c b/src/imap/cmd-store.c index 126c042b35..7962261552 100644 --- a/src/imap/cmd-store.c +++ b/src/imap/cmd-store.c @@ -32,11 +32,11 @@ get_modify_type(struct imap_store_context *ctx, const char *type) ctx->modify_type = MODIFY_REPLACE; } - if (strncasecmp(type, "FLAGS", 5) != 0) + if (!str_begins_icase(type, "FLAGS", &type)) return FALSE; - ctx->silent = strcasecmp(type+5, ".SILENT") == 0; - if (!ctx->silent && type[5] != '\0') + ctx->silent = strcasecmp(type, ".SILENT") == 0; + if (!ctx->silent && type[0] != '\0') return FALSE; return TRUE; } diff --git a/src/lib-dcrypt/dcrypt-gnutls.c b/src/lib-dcrypt/dcrypt-gnutls.c index 33a2a231a1..1dd1df3ada 100644 --- a/src/lib-dcrypt/dcrypt-gnutls.c +++ b/src/lib-dcrypt/dcrypt-gnutls.c @@ -316,13 +316,13 @@ dcrypt_gnutls_pbkdf2(const unsigned char *password, size_t password_len, unsigned char buf[result_len]; /* only sha1 or sha256 is supported */ - if (strncasecmp(algorithm, "sha1", 4) == 0) { + if (str_begins_icase_with(algorithm, "sha1")) { pbkdf2_hmac_sha1(password_len, password, rounds, salt_len, salt, result_len, buf); - } else if (strncasecmp(algorithm, "sha256", 6) == 0) { + } else if (str_begins_icase_with(algorithm, "sha256")) { pbkdf2_hmac_sha256(password_len, password, rounds, salt_len, salt, result_len, buf); - } else if (strncasecmp(algorithm, "sha512", 6) == 0) { + } else if (str_begins_icase_with(algorithm, "sha512")) { struct hmac_sha512_ctx ctx; hmac_sha512_set_key(&ctx, password_len, password); diff --git a/src/lib-dcrypt/dcrypt-openssl.c b/src/lib-dcrypt/dcrypt-openssl.c index ffb0a8bf06..63eb7c317d 100644 --- a/src/lib-dcrypt/dcrypt-openssl.c +++ b/src/lib-dcrypt/dcrypt-openssl.c @@ -2291,11 +2291,10 @@ dcrypt_openssl_store_private_key_dovecot(struct dcrypt_private_key *key, } /* see if we want ECDH based or password based encryption */ - if (cipher != NULL && strncasecmp(cipher, "ecdh-", 5) == 0) { + if (cipher != NULL && str_begins_icase(cipher, "ecdh-", &cipher2)) { i_assert(enc_key != NULL); i_assert(password == NULL); enctype = DCRYPT_DOVECOT_KEY_ENCRYPT_PK; - cipher2 = cipher+5; } else if (cipher != NULL) { i_assert(enc_key == NULL); i_assert(password != NULL); diff --git a/src/lib-imap-client/imapc-connection.c b/src/lib-imap-client/imapc-connection.c index 0deefdee58..50912bb1c1 100644 --- a/src/lib-imap-client/imapc-connection.c +++ b/src/lib-imap-client/imapc-connection.c @@ -597,7 +597,7 @@ static bool last_arg_is_fetch_body(const struct imap_arg *args, imap_arg_get_list_full(&args[2], &list, &count) && count >= 2 && list[count].type == IMAP_ARG_LITERAL_SIZE && imap_arg_get_atom(&list[count-1], &name) && - strncasecmp(name, "BODY[", 5) == 0) { + str_begins_icase_with(name, "BODY[")) { *parent_arg_r = &args[2]; *idx_r = count; return TRUE; @@ -950,11 +950,12 @@ imapc_connection_authenticate_cb(const struct imapc_command_reply *reply, static bool imapc_connection_have_auth(struct imapc_connection *conn, const char *mech_name) { + const char *auth; char *const *capa; for (capa = conn->capabilities_list; *capa != NULL; capa++) { - if (strncasecmp(*capa, "AUTH=", 5) == 0 && - strcasecmp((*capa)+5, mech_name) == 0) + if (str_begins_icase(*capa, "AUTH=", &auth) && + strcasecmp(auth, mech_name) == 0) return TRUE; } return FALSE; diff --git a/src/lib-imap-urlauth/imap-urlauth-connection.c b/src/lib-imap-urlauth/imap-urlauth-connection.c index 5fce6f73a6..0a36b217b5 100644 --- a/src/lib-imap-urlauth/imap-urlauth-connection.c +++ b/src/lib-imap-urlauth/imap-urlauth-connection.c @@ -688,7 +688,7 @@ imap_urlauth_connection_read_literal(struct imap_urlauth_connection *conn) static int imap_urlauth_input_pending(struct imap_urlauth_connection *conn) { struct imap_urlauth_request *urlreq; - const char *response, *const *args, *bpstruct = NULL; + const char *value, *response, *const *args, *bpstruct = NULL; uoff_t literal_size; i_assert(conn->targets_head != NULL); @@ -718,10 +718,9 @@ static int imap_urlauth_input_pending(struct imap_urlauth_connection *conn) const char *param = args[1], *error = NULL; if (param != NULL && - strncasecmp(param, "error=", 6) == 0 && - param[6] != '\0') { - error = param+6; - } + str_begins_icase(param, "error=", &value) && + value[0] != '\0') + error = value; conn->state = IMAP_URLAUTH_STATE_REQUEST_WAIT; imap_urlauth_request_fail(conn, conn->targets_head->requests_head, error); @@ -739,9 +738,9 @@ static int imap_urlauth_input_pending(struct imap_urlauth_connection *conn) if (strcasecmp(param, "hasnuls") == 0) { urlreq->binary_has_nuls = TRUE; - } else if (strncasecmp(param, "bpstruct=", 9) == 0 && - param[9] != '\0') { - bpstruct = param+9; + } else if (str_begins_icase(param, "bpstruct=", &value) && + value[0] != '\0') { + bpstruct = value; } } diff --git a/src/lib-imap/imap-url.c b/src/lib-imap/imap-url.c index c3aeae9dfb..bcbed1eddd 100644 --- a/src/lib-imap/imap-url.c +++ b/src/lib-imap/imap-url.c @@ -222,14 +222,14 @@ static int imap_url_parse_iserver(struct imap_url_parser *url_parser) uend = p; if (*p == ';') { - if (strncasecmp(p, ";AUTH=", 6) != 0) { + if (!str_begins_icase(p, ";AUTH=", &p)) { parser->error = t_strdup_printf( "Stray ';' in userinfo `%s'", auth.enc_userinfo); return -1; } - for (p += 6; *p != '\0'; p++) { + for (; *p != '\0'; p++) { if (*p == ';' || *p == ':') { parser->error = t_strdup_printf( "Stray %s in userinfo `%s'", @@ -292,15 +292,15 @@ imap_url_parse_urlauth(struct imap_url_parser *url_parser, const char *urlext) */ /* ";EXPIRE=" date-time */ - if (strncasecmp(urlext, ";EXPIRE=", 8) == 0) { + if (str_begins_icase(urlext, ";EXPIRE=", &urlext)) { if ((url_parser->flags & IMAP_URL_PARSE_ALLOW_URLAUTH) == 0) { parser->error = "`;EXPIRE=' is not allowed in this context"; return -1; } - if ((p = strchr(urlext+8, ';')) != NULL) { - if (!iso8601_date_parse((const unsigned char *)urlext+8, - p-urlext-8, &expire, &tz)) { + if ((p = strchr(urlext, ';')) != NULL) { + if (!iso8601_date_parse((const unsigned char *)urlext, + p-urlext, &expire, &tz)) { parser->error = "invalid date-time for `;EXPIRE='"; return -1; } @@ -309,14 +309,13 @@ imap_url_parse_urlauth(struct imap_url_parser *url_parser, const char *urlext) } /* ";URLAUTH=" access */ - if (strncasecmp(urlext, ";URLAUTH=", 9) != 0) { + if (!str_begins_icase(urlext, ";URLAUTH=", &urlext)) { if (expire != (time_t)-1) { parser->error = "`;EXPIRE=' without `;URLAUTH='"; return -1; } return 0; } - urlext += 9; if (url != NULL) url->uauth_expire = expire; @@ -436,7 +435,7 @@ imap_url_parse_path(struct imap_url_parser *url_parser, { struct uri_parser *parser = &url_parser->parser; struct imap_url *url = url_parser->url; - const char *const *segment; + const char *const *segment, *suffix; string_t *mailbox, *section = NULL; uint32_t uid = 0, uidvalidity = 0; uoff_t partial_offset = 0, partial_size = 0; @@ -560,7 +559,7 @@ imap_url_parse_path(struct imap_url_parser *url_parser, /* Handle ';' */ if (p != NULL) { /* [uidvalidity] */ - if (strncasecmp(p, ";UIDVALIDITY=", 13) == 0) { + if (str_begins_icase(p, ";UIDVALIDITY=", &suffix)) { /* append last bit of mailbox */ if (*segment != p) { if (segment > path || @@ -572,17 +571,17 @@ imap_url_parse_path(struct imap_url_parser *url_parser, } /* ";UIDVALIDITY=" nz-number */ - if (strchr(p+13, ';') != NULL) { + if (strchr(suffix, ';') != NULL) { parser->error = "Encountered stray ';' after UIDVALIDITY"; return -1; } /* nz-number */ - if (p[13] == '\0') { + if (suffix[0] == '\0') { parser->error = "Empty UIDVALIDITY value"; return -1; } - if (imap_url_parse_number(parser, p+13, &uidvalidity) <= 0) + if (imap_url_parse_number(parser, suffix, &uidvalidity) <= 0) return -1; if (uidvalidity == 0) { parser->error = "UIDVALIDITY cannot be zero"; @@ -596,9 +595,9 @@ imap_url_parse_path(struct imap_url_parser *url_parser, } /* iuid */ - if (*segment != NULL && strncasecmp(*segment, ";UID=", 5) == 0) { + if (*segment != NULL && + str_begins_icase(*segment, ";UID=", &value)) { /* ";UID=" nz-number */ - value = (*segment)+5; if ((p = strchr(value,';')) != NULL) { if (segment[1] != NULL ) { /* not the last segment, so it cannot be extension like iurlauth */ @@ -627,11 +626,10 @@ imap_url_parse_path(struct imap_url_parser *url_parser, if (*segment != NULL && uid > 0) { /* [isection] */ if (section != NULL || - strncasecmp(*segment, ";SECTION=", 9) == 0) { + str_begins_icase(*segment, ";SECTION=", &value)) { /* ";SECTION=" enc-section */ if (section == NULL) { section = t_str_new(256); - value = (*segment) + 9; } else { value = *segment; } @@ -682,11 +680,10 @@ imap_url_parse_path(struct imap_url_parser *url_parser, /* [ipartial] */ if (*segment != NULL && - strncasecmp(*segment, ";PARTIAL=", 9) == 0) { + str_begins_icase(*segment, ";PARTIAL=", &value)) { have_partial = TRUE; /* ";PARTIAL=" partial-range */ - value = (*segment) + 9; if ((p = strchr(value,';')) != NULL) { urlext = p; value = t_strdup_until(value, p); diff --git a/src/lib-lua/dlua-compat.c b/src/lib-lua/dlua-compat.c index c676186258..9f0d11e704 100644 --- a/src/lib-lua/dlua-compat.c +++ b/src/lib-lua/dlua-compat.c @@ -103,13 +103,10 @@ lua_Integer lua_tointegerx(lua_State *L, int idx, int *isnum_r) /* convert using str_to_long() */ str = lua_tostring(L, idx); - if (strncasecmp(str, "0x", 2) == 0) { + if (str_begins_icase(str, "0x", &str)) { /* hex */ uintmax_t tmp; - /* skip over leading 0x */ - str += 2; - if (str_to_uintmax_hex(str, &tmp) < 0) break; diff --git a/src/lib-mail/message-parser.c b/src/lib-mail/message-parser.c index 9a9c9a3515..4015cd0e62 100644 --- a/src/lib-mail/message-parser.c +++ b/src/lib-mail/message-parser.c @@ -503,7 +503,7 @@ static void parse_content_type(struct message_parser_ctx *ctx, struct message_header_line *hdr) { struct rfc822_parser_context parser; - const char *const *results; + const char *const *results, *suffix; string_t *content_type; int ret; @@ -519,14 +519,13 @@ static void parse_content_type(struct message_parser_ctx *ctx, if (strcasecmp(str_c(content_type), "message/rfc822") == 0) ctx->part->flags |= MESSAGE_PART_FLAG_MESSAGE_RFC822; - else if (strncasecmp(str_c(content_type), "text", 4) == 0 && - (str_len(content_type) == 4 || - str_data(content_type)[4] == '/')) + else if (str_begins_icase(str_c(content_type), "text", &suffix) && + (suffix[0] == '\0' || suffix[0] == '/')) ctx->part->flags |= MESSAGE_PART_FLAG_TEXT; - else if (strncasecmp(str_c(content_type), "multipart/", 10) == 0) { + else if (str_begins_icase(str_c(content_type), "multipart/", &suffix)) { ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART; - if (strcasecmp(str_c(content_type)+10, "digest") == 0) + if (strcasecmp(suffix, "digest") == 0) ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART_DIGEST; } diff --git a/src/lib-mail/message-part-data.c b/src/lib-mail/message-part-data.c index a5771f87e2..bb5dfb648d 100644 --- a/src/lib-mail/message-part-data.c +++ b/src/lib-mail/message-part-data.c @@ -506,7 +506,7 @@ void message_part_data_parse_from_header(pool_t pool, parent_rfc822 = part->parent != NULL && (part->parent->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) != 0; - if (!parent_rfc822 && strncasecmp(hdr->name, "Content-", 8) != 0) + if (!parent_rfc822 && !str_begins_icase_with(hdr->name, "Content-")) return; if (part->data == NULL) { @@ -515,7 +515,7 @@ void message_part_data_parse_from_header(pool_t pool, } part_data = part->data; - if (strncasecmp(hdr->name, "Content-", 8) == 0) { + if (str_begins_icase_with(hdr->name, "Content-")) { T_BEGIN { parse_content_header(part_data, pool, hdr); } T_END; diff --git a/src/lib-mail/message-search.c b/src/lib-mail/message-search.c index 5f54485339..e4fc9637fb 100644 --- a/src/lib-mail/message-search.c +++ b/src/lib-mail/message-search.c @@ -59,8 +59,8 @@ static void parse_content_type(struct message_search_context *ctx, content_type = t_str_new(64); (void)rfc822_parse_content_type(&parser, content_type); ctx->content_type_text = - strncasecmp(str_c(content_type), "text/", 5) == 0 || - strncasecmp(str_c(content_type), "message/", 8) == 0; + str_begins_icase_with(str_c(content_type), "text/") || + str_begins_icase_with(str_c(content_type), "message/"); rfc822_parser_deinit(&parser); } diff --git a/src/lib-mail/message-snippet.c b/src/lib-mail/message-snippet.c index 2982e2eece..37126fec4f 100644 --- a/src/lib-mail/message-snippet.c +++ b/src/lib-mail/message-snippet.c @@ -187,7 +187,7 @@ int message_snippet_generate(struct istream *input, ctx.plain_output = buffer_create_dynamic(pool, 1024); } - } else if (strncasecmp(ct, "text/", 5) != 0) + } else if (!str_begins_icase_with(ct, "text/")) skip_part = raw_block.part; } else if (!snippet_generate(&ctx, block.data, block.size)) break; diff --git a/src/lib-settings/settings-parser.c b/src/lib-settings/settings-parser.c index eb15b96968..79ed5b2145 100644 --- a/src/lib-settings/settings-parser.c +++ b/src/lib-settings/settings-parser.c @@ -376,19 +376,19 @@ static int settings_get_time_full(const char *str, unsigned int *interval_r, switch (i_toupper(*p)) { case 'S': multiply *= 1; - if (strncasecmp(p, "secs", strlen(p)) == 0 || - strncasecmp(p, "seconds", strlen(p)) == 0) + if (str_begins_icase_with("secs", p) || + str_begins_icase_with("seconds", p)) p = ""; break; case 'M': multiply *= 60; - if (strncasecmp(p, "mins", strlen(p)) == 0 || - strncasecmp(p, "minutes", strlen(p)) == 0) + if (str_begins_icase_with("mins", p) || + str_begins_icase_with("minutes", p)) p = ""; - else if (strncasecmp(p, "msecs", strlen(p)) == 0 || - strncasecmp(p, "mseconds", strlen(p)) == 0 || - strncasecmp(p, "millisecs", strlen(p)) == 0 || - strncasecmp(p, "milliseconds", strlen(p)) == 0) { + else if (str_begins_icase_with("msecs", p) || + str_begins_icase_with("mseconds", p) || + str_begins_icase_with("millisecs", p) || + str_begins_icase_with("milliseconds", p)) { if (milliseconds || (num % 1000) == 0) { if (!milliseconds) { /* allow ms also for seconds, as long @@ -406,17 +406,17 @@ static int settings_get_time_full(const char *str, unsigned int *interval_r, break; case 'H': multiply *= 60*60; - if (strncasecmp(p, "hours", strlen(p)) == 0) + if (str_begins_icase_with("hours", p)) p = ""; break; case 'D': multiply *= 60*60*24; - if (strncasecmp(p, "days", strlen(p)) == 0) + if (str_begins_icase_with("days", p)) p = ""; break; case 'W': multiply *= 60*60*24*7; - if (strncasecmp(p, "weeks", strlen(p)) == 0) + if (str_begins_icase_with("weeks", p)) p = ""; break; } diff --git a/src/lib-smtp/smtp-server-cmd-mail.c b/src/lib-smtp/smtp-server-cmd-mail.c index c0e719ba75..2650a57436 100644 --- a/src/lib-smtp/smtp-server-cmd-mail.c +++ b/src/lib-smtp/smtp-server-cmd-mail.c @@ -93,15 +93,14 @@ void smtp_server_cmd_mail(struct smtp_server_cmd_ctx *cmd, return; /* Reverse-path */ - if (params == NULL || strncasecmp(params, "FROM:", 5) != 0) { + if (params == NULL || !str_begins_icase(params, "FROM:", ¶ms)) { smtp_server_reply(cmd, 501, "5.5.4", "Invalid parameters"); return; } - if (params[5] != ' ' && params[5] != '\t') { - params += 5; + if (params[0] != ' ' && params[0] != '\t') { + /* no whitespace */ } else if ((set->workarounds & SMTP_SERVER_WORKAROUND_WHITESPACE_BEFORE_PATH) != 0) { - params += 5; while (*params == ' ' || *params == '\t') params++; } else { diff --git a/src/lib-smtp/smtp-server-cmd-rcpt.c b/src/lib-smtp/smtp-server-cmd-rcpt.c index b4a496bbb3..9aca87b584 100644 --- a/src/lib-smtp/smtp-server-cmd-rcpt.c +++ b/src/lib-smtp/smtp-server-cmd-rcpt.c @@ -127,16 +127,15 @@ void smtp_server_cmd_rcpt(struct smtp_server_cmd_ctx *cmd, return; /* ( "" / "" / Forward-path ) */ - if (params == NULL || strncasecmp(params, "TO:", 3) != 0) { + if (params == NULL || !str_begins_icase(params, "TO:", ¶ms)) { smtp_server_reply(cmd, 501, "5.5.4", "Invalid parameters"); return; } - if (params[3] != ' ' && params[3] != '\t') { - params += 3; + if (params[0] != ' ' && params[0] != '\t') { + /* no whitespace */ } else if ((set->workarounds & SMTP_SERVER_WORKAROUND_WHITESPACE_BEFORE_PATH) != 0) { - params += 3; while (*params == ' ' || *params == '\t') params++; } else { diff --git a/src/lib-smtp/smtp-server-cmd-xclient.c b/src/lib-smtp/smtp-server-cmd-xclient.c index 00e61c90da..4de426cfee 100644 --- a/src/lib-smtp/smtp-server-cmd-xclient.c +++ b/src/lib-smtp/smtp-server-cmd-xclient.c @@ -141,10 +141,8 @@ void smtp_server_cmd_xclient(struct smtp_server_cmd_ctx *cmd, bool ipv6 = FALSE; if (strcasecmp(param.value, "[UNAVAILABLE]") == 0) continue; - if (strncasecmp(param.value, "IPV6:", 5) == 0) { + if (str_begins_icase(param.value, "IPV6:", ¶m.value)) ipv6 = TRUE; - param.value += 5; - } if (net_addr2ip(param.value, &proxy_data->source_ip) < 0 || (ipv6 && proxy_data->source_ip.family != AF_INET6)) { smtp_server_reply(cmd, 501, "5.5.4", diff --git a/src/lib-sql/driver-cassandra.c b/src/lib-sql/driver-cassandra.c index 1c54e3f076..ea9418ac4d 100644 --- a/src/lib-sql/driver-cassandra.c +++ b/src/lib-sql/driver-cassandra.c @@ -2006,7 +2006,7 @@ driver_cassandra_transaction_commit(struct sql_transaction_context *_ctx, /* just a single query, send it */ const char *query = ctx->query != NULL ? ctx->query : sql_statement_get_query(&ctx->stmt->stmt); - if (strncasecmp(query, "DELETE ", 7) == 0) + if (str_begins_icase_with(query, "DELETE ")) query_type = CASSANDRA_QUERY_TYPE_DELETE; else query_type = CASSANDRA_QUERY_TYPE_WRITE; @@ -2047,7 +2047,7 @@ driver_cassandra_try_commit_s(struct cassandra_transaction_context *ctx) enum cassandra_query_type query_type; /* just a single query, send it */ - if (strncasecmp(ctx->query, "DELETE ", 7) == 0) + if (str_begins_icase_with(ctx->query, "DELETE ")) query_type = CASSANDRA_QUERY_TYPE_DELETE; else query_type = CASSANDRA_QUERY_TYPE_WRITE; diff --git a/src/lib-storage/index/imapc/imapc-search.c b/src/lib-storage/index/imapc/imapc-search.c index e395919f34..ec2e908633 100644 --- a/src/lib-storage/index/imapc/imapc-search.c +++ b/src/lib-storage/index/imapc/imapc-search.c @@ -103,8 +103,8 @@ imapc_build_search_query_arg(struct imapc_mailbox *mbox, size_t pos = str_len(str); if (!mail_search_arg_to_imap(str, arg, &error)) return FALSE; - if (strncasecmp(str_c(str) + pos, "OLDER", 5) == 0 || - strncasecmp(str_c(str) + pos, "YOUNGER", 7) == 0) + if (str_begins_icase_with(str_c(str) + pos, "OLDER") || + str_begins_icase_with(str_c(str) + pos, "YOUNGER")) return FALSE; return TRUE; } diff --git a/src/lib-storage/index/imapc/imapc-settings.c b/src/lib-storage/index/imapc/imapc-settings.c index 6183f8f21d..d3fca47f56 100644 --- a/src/lib-storage/index/imapc/imapc-settings.c +++ b/src/lib-storage/index/imapc/imapc-settings.c @@ -132,7 +132,7 @@ imapc_settings_parse_features(struct imapc_settings *set, { enum imapc_features features = 0; const struct imapc_feature_list *list; - const char *const *str; + const char *const *str, *value; str = t_strsplit_spaces(set->imapc_features, " ,"); for (; *str != NULL; str++) { @@ -143,8 +143,8 @@ imapc_settings_parse_features(struct imapc_settings *set, break; } } - if (strncasecmp(*str, "throttle:", 9) == 0) { - if (imapc_settings_parse_throttle(set, *str + 9, error_r) < 0) + if (str_begins_icase(*str, "throttle:", &value)) { + if (imapc_settings_parse_throttle(set, value, error_r) < 0) return -1; continue; } diff --git a/src/lib-storage/index/index-attachment.c b/src/lib-storage/index/index-attachment.c index 6e51fab161..7307a0fd93 100644 --- a/src/lib-storage/index/index-attachment.c +++ b/src/lib-storage/index/index-attachment.c @@ -55,7 +55,7 @@ static bool index_attachment_want(const struct istream_attachment_header *hdr, /* don't treat text/ parts as attachments */ return hdr->content_type != NULL && - strncasecmp(hdr->content_type, "text/", 5) != 0; + !str_begins_icase_with(hdr->content_type, "text/"); } static int index_attachment_open_temp_fd(void *context) diff --git a/src/lib-storage/index/index-mail-headers.c b/src/lib-storage/index/index-mail-headers.c index ce23e9df04..2348fb1582 100644 --- a/src/lib-storage/index/index-mail-headers.c +++ b/src/lib-storage/index/index-mail-headers.c @@ -184,7 +184,7 @@ static void index_mail_parse_header_register_all_wanted(struct index_mail *mail) mail_cache_register_get_list(_mail->box->cache, pool_datastack_create(), &count); for (i = 0; i < count; i++) { - if (strncasecmp(all_cache_fields[i].name, "hdr.", 4) != 0) + if (!str_begins_icase_with(all_cache_fields[i].name, "hdr.")) continue; if (!mail_cache_field_want_add(_mail->transaction->cache_trans, _mail->seq, i)) diff --git a/src/lib-storage/index/index-storage.c b/src/lib-storage/index/index-storage.c index adfd90445f..1331fd6cbb 100644 --- a/src/lib-storage/index/index-storage.c +++ b/src/lib-storage/index/index-storage.c @@ -49,7 +49,7 @@ static void set_cache_decisions(struct mail_cache *cache, idx = mail_cache_register_lookup(cache, name); if (idx != UINT_MAX) { field = *mail_cache_register_get_field(cache, idx); - } else if (strncasecmp(name, "hdr.", 4) == 0) { + } else if (str_begins_icase_with(name, "hdr.")) { /* Do some sanity checking for the header name. Mainly to make sure there aren't UTF-8 characters that look like their ASCII equivalents or are completely diff --git a/src/lib-storage/index/pop3c/pop3c-client.c b/src/lib-storage/index/pop3c/pop3c-client.c index 44544a350f..fc74b5b0cd 100644 --- a/src/lib-storage/index/pop3c/pop3c-client.c +++ b/src/lib-storage/index/pop3c/pop3c-client.c @@ -452,9 +452,9 @@ pop3c_client_prelogin_input_line(struct pop3c_client *client, const char *line) break; case POP3C_CLIENT_STATE_PASS: if (client->login_callback != NULL) { - reply = strncasecmp(line, "+OK ", 4) == 0 ? line + 4 : - strncasecmp(line, "-ERR ", 5) == 0 ? line + 5 : - line; + if (!str_begins_icase(line, "+OK ", &reply) && + !str_begins_icase(line, "-ERR ", &reply)) + reply = line; client_login_callback(client, success ? POP3C_COMMAND_STATE_OK : POP3C_COMMAND_STATE_ERR, reply); @@ -469,7 +469,7 @@ pop3c_client_prelogin_input_line(struct pop3c_client *client, const char *line) client->state = POP3C_CLIENT_STATE_CAPA; break; case POP3C_CLIENT_STATE_CAPA: - if (strncasecmp(line, "-ERR", 4) == 0) { + if (str_begins_icase_with(line, "-ERR")) { /* CAPA command not supported. some commands still support UIDL though. */ client->capabilities |= POP3C_CAPABILITY_UIDL; @@ -732,13 +732,11 @@ pop3c_client_input_next_reply(struct pop3c_client *client) if (line == NULL) return client->input->eof ? -1 : 0; - if (strncasecmp(line, "+OK", 3) == 0) { - line += 3; + if (str_begins_icase(line, "+OK", &line)) state = POP3C_COMMAND_STATE_OK; - } else if (strncasecmp(line, "-ERR", 4) == 0) { - line += 4; + else if (str_begins_icase(line, "-ERR", &line)) state = POP3C_COMMAND_STATE_ERR; - } else { + else { i_error("pop3c(%s): Server sent unrecognized line: %s", client->set.host, line); state = POP3C_COMMAND_STATE_ERR; diff --git a/src/lib-storage/list/mailbox-list-iter.c b/src/lib-storage/list/mailbox-list-iter.c index ab4736428d..338a8fd7d6 100644 --- a/src/lib-storage/list/mailbox-list-iter.c +++ b/src/lib-storage/list/mailbox-list-iter.c @@ -445,10 +445,11 @@ mailbox_list_ns_prefix_return(struct ns_list_iterate_context *ctx, { struct mailbox *box; enum mailbox_existence existence; + const char *suffix; int ret; - if (strncasecmp(ns->prefix, "INBOX", 5) == 0 && - ns->prefix[5] == mail_namespace_get_sep(ns)) { + if (str_begins_icase(ns->prefix, "INBOX", &suffix) && + suffix[0] == mail_namespace_get_sep(ns)) { /* prefix=INBOX/ (or prefix=INBOX/something/) namespace exists. so we can create children to INBOX. */ ctx->inbox_info.flags &= ENUM_NEGATE(MAILBOX_NOINFERIORS); @@ -570,6 +571,7 @@ mailbox_list_ns_iter_try_next(struct mailbox_list_iterate_context *_ctx, (struct ns_list_iterate_context *)_ctx; struct mail_namespace *ns; const struct mailbox_info *info; + const char *suffix; bool has_children; if (ctx->cur_ns == NULL) { @@ -636,8 +638,8 @@ mailbox_list_ns_iter_try_next(struct mailbox_list_iterate_context *_ctx, MAILBOX_CHILD_SUBSCRIBED)); return FALSE; } - if (strncasecmp(info->vname, "INBOX", 5) == 0 && - info->vname[5] == mail_namespace_get_sep(info->ns)) { + if (str_begins_icase(info->vname, "INBOX", &suffix) && + suffix[0] == mail_namespace_get_sep(info->ns)) { /* we know now that INBOX has children */ ctx->inbox_info.flags |= MAILBOX_CHILDREN; ctx->inbox_info.flags &= ENUM_NEGATE(MAILBOX_NOINFERIORS); diff --git a/src/lib-storage/mail-namespace.c b/src/lib-storage/mail-namespace.c index 9f47b25084..614aac50f0 100644 --- a/src/lib-storage/mail-namespace.c +++ b/src/lib-storage/mail-namespace.c @@ -707,10 +707,11 @@ mail_namespace_find_mask(struct mail_namespace *namespaces, const char *box, struct mail_namespace *ns = namespaces; struct mail_namespace *best = NULL; size_t best_len = 0; + const char *suffix; bool inbox; - inbox = strncasecmp(box, "INBOX", 5) == 0; - if (inbox && box[5] == '\0') { + inbox = str_begins_icase(box, "INBOX", &suffix); + if (inbox && suffix[0] == '\0') { /* find the INBOX namespace */ while (ns != NULL) { if ((ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0 && diff --git a/src/lib-storage/mail-namespace.h b/src/lib-storage/mail-namespace.h index ae54f59bc7..b70da18b6b 100644 --- a/src/lib-storage/mail-namespace.h +++ b/src/lib-storage/mail-namespace.h @@ -212,10 +212,12 @@ mail_namespace_is_inbox_noinferiors(struct mail_namespace *ns) static inline bool mail_namespace_prefix_is_inbox(struct mail_namespace *ns) { + const char *suffix; + return (ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0 && (ns->prefix_len == 6) && - (strncasecmp(ns->prefix, "INBOX", 5) == 0) && - (ns->prefix[5] == mail_namespace_get_sep(ns)); + (str_begins_icase(ns->prefix, "INBOX", &suffix)) && + (suffix[0] == mail_namespace_get_sep(ns)); } #endif diff --git a/src/lib-storage/mail-storage-settings.c b/src/lib-storage/mail-storage-settings.c index 4b802ebc2b..f6535488ce 100644 --- a/src/lib-storage/mail-storage-settings.c +++ b/src/lib-storage/mail-storage-settings.c @@ -417,11 +417,11 @@ static bool mail_cache_fields_parse(const char *key, const char *value, for (arr = t_strsplit_spaces(value, " ,"); *arr != NULL; arr++) { const char *name = *arr; - if (strncasecmp(name, "hdr.", 4) == 0 && - !message_header_name_is_valid(name+4)) { + if (str_begins_icase(name, "hdr.", &name) && + !message_header_name_is_valid(name)) { *error_r = t_strdup_printf( "Invalid %s: %s is not a valid header name", - key, name + 4); + key, name); return FALSE; } } diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 8b4f819402..11b9cca6cc 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -844,19 +844,19 @@ struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *vname, struct mail_storage *storage; struct mailbox *box; enum mail_error open_error = 0; - const char *errstr = NULL; + const char *suffix, *errstr = NULL; i_assert(uni_utf8_str_is_valid(vname)); - if (strncasecmp(vname, "INBOX", 5) == 0 && + if (str_begins_icase(vname, "INBOX", &suffix) && !str_begins_with(vname, "INBOX")) { /* make sure INBOX shows up in uppercase everywhere. do this regardless of whether we're in inbox=yes namespace, because clients expect INBOX to be case insensitive regardless of server's internal configuration. */ - if (vname[5] == '\0') + if (suffix[0] == '\0') vname = "INBOX"; - else if (vname[5] != mail_namespace_get_sep(list->ns)) + else if (suffix[0] != mail_namespace_get_sep(list->ns)) /* not INBOX prefix */ ; else if (strncasecmp(list->ns->prefix, vname, 6) == 0 && !str_begins_with(list->ns->prefix, "INBOX")) { @@ -866,7 +866,7 @@ struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *vname, list->ns->prefix); open_error = MAIL_ERROR_TEMP; } else { - vname = t_strconcat("INBOX", vname + 5, NULL); + vname = t_strconcat("INBOX", suffix, NULL); } } diff --git a/src/lib-storage/mailbox-tree.c b/src/lib-storage/mailbox-tree.c index 9333fb6139..7e292f950c 100644 --- a/src/lib-storage/mailbox-tree.c +++ b/src/lib-storage/mailbox-tree.c @@ -83,7 +83,7 @@ mailbox_tree_traverse(struct mailbox_tree_context *tree, const char *path, bool create, bool *created_r) { struct mailbox_node **node, *parent; - const char *name; + const char *name, *suffix; string_t *str; *created_r = FALSE; @@ -91,9 +91,9 @@ mailbox_tree_traverse(struct mailbox_tree_context *tree, const char *path, if (path == NULL) return tree->nodes; - if (strncasecmp(path, "INBOX", 5) == 0 && - (path[5] == '\0' || path[5] == tree->separator)) - path = t_strdup_printf("INBOX%s", path+5); + if (str_begins_icase(path, "INBOX", &suffix) && + (suffix[0] == '\0' || suffix[0] == tree->separator)) + path = t_strdup_printf("INBOX%s", suffix); parent = NULL; node = &tree->nodes; diff --git a/src/lmtp/lmtp-proxy.c b/src/lmtp/lmtp-proxy.c index f7e062decb..d29e46509b 100644 --- a/src/lmtp/lmtp-proxy.c +++ b/src/lmtp/lmtp-proxy.c @@ -984,7 +984,7 @@ int lmtp_proxy_rcpt(struct client *client, /* Copy forward fields returned from passdb */ fwfields = NULL; for (const char *const *ptr = fields; *ptr != NULL; ptr++) { - if (strncasecmp(*ptr, "forward_", 8) != 0) + if (!str_begins_icase_with(*ptr, "forward_")) continue; if (fwfields == NULL) diff --git a/src/plugins/quota/quota-count.c b/src/plugins/quota/quota-count.c index 00e25e6b6c..eb123a42d3 100644 --- a/src/plugins/quota/quota-count.c +++ b/src/plugins/quota/quota-count.c @@ -153,7 +153,7 @@ quota_mailbox_iter_next(struct quota_mailbox_iter *iter) } if (iter->ns->prefix_len > 0 && (iter->ns->prefix_len != 6 || - strncasecmp(iter->ns->prefix, "INBOX", 5) != 0)) { + !str_begins_icase_with(iter->ns->prefix, "INBOX"))) { /* if the namespace prefix itself exists, count it also */ iter->info.ns = iter->ns; iter->info.vname = t_strndup(iter->ns->prefix, diff --git a/src/pop3-login/client.c b/src/pop3-login/client.c index a4b52fbb27..51df83c297 100644 --- a/src/pop3-login/client.c +++ b/src/pop3-login/client.c @@ -40,7 +40,7 @@ static bool cmd_quit(struct pop3_client *client) static bool cmd_xclient(struct pop3_client *client, const char *args) { - const char *const *tmp; + const char *const *tmp, *value; in_port_t remote_port; bool args_ok = TRUE; @@ -50,30 +50,28 @@ static bool cmd_xclient(struct pop3_client *client, const char *args) return TRUE; } for (tmp = t_strsplit(args, " "); *tmp != NULL; tmp++) { - if (strncasecmp(*tmp, "ADDR=", 5) == 0) { - if (net_addr2ip(*tmp + 5, &client->common.ip) < 0) + if (str_begins_icase(*tmp, "ADDR=", &value)) { + if (net_addr2ip(value, &client->common.ip) < 0) args_ok = FALSE; - } else if (strncasecmp(*tmp, "PORT=", 5) == 0) { - if (net_str2port(*tmp + 5, &remote_port) < 0) + } else if (str_begins_icase(*tmp, "PORT=", &value)) { + if (net_str2port(value, &remote_port) < 0) args_ok = FALSE; else client->common.remote_port = remote_port; - } else if (strncasecmp(*tmp, "SESSION=", 8) == 0) { - const char *value = *tmp + 8; - + } else if (str_begins_icase(*tmp, "SESSION=", &value)) { if (strlen(value) <= LOGIN_MAX_SESSION_ID_LEN) { client->common.session_id = p_strdup(client->common.pool, value); } - } else if (strncasecmp(*tmp, "TTL=", 4) == 0) { - if (str_to_uint(*tmp + 4, &client->common.proxy_ttl) < 0) + } else if (str_begins_icase(*tmp, "TTL=", &value)) { + if (str_to_uint(value, &client->common.proxy_ttl) < 0) args_ok = FALSE; - } else if (strncasecmp(*tmp, "FORWARD=", 8) == 0) { - size_t value_len = strlen((*tmp)+8); + } else if (str_begins_icase(*tmp, "FORWARD=", &value)) { + size_t value_len = strlen(value); client->common.forward_fields = str_new(client->common.preproxy_pool, MAX_BASE64_DECODED_SIZE(value_len)); - if (base64_decode((*tmp)+8, value_len, + if (base64_decode(value, value_len, client->common.forward_fields) < 0) args_ok = FALSE; } diff --git a/src/pop3-login/pop3-proxy.c b/src/pop3-login/pop3-proxy.c index 78c40bfa39..12820bd16c 100644 --- a/src/pop3-login/pop3-proxy.c +++ b/src/pop3-login/pop3-proxy.c @@ -23,7 +23,7 @@ static int proxy_send_login(struct pop3_client *client, struct ostream *output) struct dsasl_client_settings sasl_set; const unsigned char *sasl_output; size_t len; - const char *mech_name, *error; + const char *mech_name, *value, *error; string_t *str = t_str_new(128); i_assert(client->common.proxy_ttl > 1); @@ -31,10 +31,10 @@ static int proxy_send_login(struct pop3_client *client, struct ostream *output) !client->common.proxy_not_trusted) { string_t *fwd = t_str_new(128); for(const char *const *ptr = client->common.auth_passdb_args;*ptr != NULL; ptr++) { - if (strncasecmp(*ptr, "forward_", 8) == 0) { + if (str_begins_icase(*ptr, "forward_", &value)) { if (str_len(fwd) > 0) str_append_c(fwd, '\t'); - str_append_tabescaped(fwd, (*ptr)+8); + str_append_tabescaped(fwd, value); } } diff --git a/src/submission-login/submission-proxy.c b/src/submission-login/submission-proxy.c index 03dae118cf..4965ca4612 100644 --- a/src/submission-login/submission-proxy.c +++ b/src/submission-login/submission-proxy.c @@ -54,7 +54,7 @@ proxy_send_starttls(struct submission_client *client, struct ostream *output) static buffer_t * proxy_compose_xclient_forward(struct submission_client *client) { - const char *const *arg; + const char *const *arg, *value; string_t *str; if (*client->common.auth_passdb_args == NULL) @@ -62,10 +62,10 @@ proxy_compose_xclient_forward(struct submission_client *client) str = t_str_new(128); for (arg = client->common.auth_passdb_args; *arg != NULL; arg++) { - if (strncasecmp(*arg, "forward_", 8) == 0) { + if (str_begins_icase(*arg, "forward_", &value)) { if (str_len(str) > 0) str_append_c(str, '\t'); - str_append_tabescaped(str, (*arg)+8); + str_append_tabescaped(str, value); } } if (str_len(str) == 0) @@ -499,7 +499,7 @@ int submission_proxy_parse_line(struct client *client, const char *line) struct smtp_server_command *command = cmd->cmd; struct ostream *output; bool last_line = FALSE, invalid_line = FALSE; - const char *text = NULL, *enh_code = NULL; + const char *suffix, *text = NULL, *enh_code = NULL; unsigned int status = 0; i_assert(!client->destroyed); @@ -566,17 +566,17 @@ int submission_proxy_parse_line(struct client *client, const char *line) return -1; } - if (strncasecmp(text, "XCLIENT ", 8) == 0) { + if (str_begins_icase(text, "XCLIENT ", &suffix)) { subm_client->proxy_capability |= SMTP_CAPABILITY_XCLIENT; i_free_and_null(subm_client->proxy_xclient); subm_client->proxy_xclient = p_strarray_dup( - default_pool, t_strsplit_spaces(text + 8, " ")); + default_pool, t_strsplit_spaces(suffix, " ")); } else if (strcasecmp(text, "STARTTLS") == 0) { subm_client->proxy_capability |= SMTP_CAPABILITY_STARTTLS; - } else if (strncasecmp(text, "AUTH", 4) == 0 && - text[4] == ' ' && text[5] != '\0') { + } else if (str_begins_icase(text, "AUTH ", &suffix) && + suffix[0] != '\0') { subm_client->proxy_capability |= SMTP_CAPABILITY_AUTH; } else if (strcasecmp(text, "ENHANCEDSTATUSCODES") == 0) {