]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Replace strncasecmp() with str_begins_icase*()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Sun, 19 Apr 2020 13:11:47 +0000 (16:11 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 23 Mar 2022 10:25:06 +0000 (10:25 +0000)
40 files changed:
src/auth/mech-oauth2.c
src/doveadm/doveadm-log.c
src/doveadm/doveadm-zlib.c
src/imap-login/imap-login-cmd-id.c
src/imap-login/imap-proxy.c
src/imap-urlauth/imap-urlauth-worker.c
src/imap/cmd-notify.c
src/imap/cmd-store.c
src/lib-dcrypt/dcrypt-gnutls.c
src/lib-dcrypt/dcrypt-openssl.c
src/lib-imap-client/imapc-connection.c
src/lib-imap-urlauth/imap-urlauth-connection.c
src/lib-imap/imap-url.c
src/lib-lua/dlua-compat.c
src/lib-mail/message-parser.c
src/lib-mail/message-part-data.c
src/lib-mail/message-search.c
src/lib-mail/message-snippet.c
src/lib-settings/settings-parser.c
src/lib-smtp/smtp-server-cmd-mail.c
src/lib-smtp/smtp-server-cmd-rcpt.c
src/lib-smtp/smtp-server-cmd-xclient.c
src/lib-sql/driver-cassandra.c
src/lib-storage/index/imapc/imapc-search.c
src/lib-storage/index/imapc/imapc-settings.c
src/lib-storage/index/index-attachment.c
src/lib-storage/index/index-mail-headers.c
src/lib-storage/index/index-storage.c
src/lib-storage/index/pop3c/pop3c-client.c
src/lib-storage/list/mailbox-list-iter.c
src/lib-storage/mail-namespace.c
src/lib-storage/mail-namespace.h
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage.c
src/lib-storage/mailbox-tree.c
src/lmtp/lmtp-proxy.c
src/plugins/quota/quota-count.c
src/pop3-login/client.c
src/pop3-login/pop3-proxy.c
src/submission-login/submission-proxy.c

index 4348b10afff7c72ef7814b4b279c72e694c99ac8..eec1971d8871d0ea9895cf2c111b9218f631992b 100644 (file)
@@ -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");
index 2654d9b787b8414d63ed8f672212d1ba66f72b38..5e0310219dbf97f30a9afcb92ccfed3e4f53dbe6 100644 (file)
@@ -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;
                }
index f7a8f5232cb5285096711131fd1c35e71c0e38d9..0987de92e37e831182617fe745e16a4118fcc52e 100644 (file)
@@ -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;
 }
 
index a1c629465150b88428af5547982e05f30304d533..809661ab25804c34eebb92f8809eafd3fad8f6df 100644 (file)
@@ -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];
        }
index aa38062ebf024eb506998b38074f606972cf7ebd..61dfff5d8a8357ef27760dca5c7b88b158dbf89d 100644 (file)
@@ -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 ")) {
index 3edf6771511c6fddf6c01c77ac1b4e2254f06703..8e5688d50c5dd1fd3f1a04c24faa474432412820 100644 (file)
@@ -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=<access-application>[,<access-application,...] */
-               } else if (strncasecmp(*args, "apps=", 5) == 0 &&
-                          (*args)[5] != '\0') {
-                       const char *const *apps = t_strsplit(*args+5, ",");
+               } else if (str_begins_icase(*args, "apps=", &value) &&
+                          value[0] != '\0') {
+                       const char *const *apps = t_strsplit(value, ",");
 
                        while (*apps != NULL) {
                                char *app = i_strdup(*apps);
index cdb6dc961f62417470832ae8a554cc0a45a81c2f..25d613deae9c747945101f616e0a0fde32178a47 100644 (file)
@@ -162,7 +162,7 @@ cmd_notify_add_mailbox(struct imap_notify_context *ctx,
 
        if ((ns->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 */
index 126c042b35cff393d19bf03fb14fefdfdf4b6299..796226155217e3b69e78d0e975147acd392fb7b1 100644 (file)
@@ -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;
 }
index 33a2a231a11dbcf4c2e796fc2a38b8a89dab9376..1dd1df3ada1d97f7e5fdd65dea9d55391c853aa3 100644 (file)
@@ -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);
index ffb0a8bf065c883484419e50319ddf38e139ea39..63eb7c317d7fcae6a0517c7e209ff6982322535d 100644 (file)
@@ -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);
index 0deefdee585bc428a00f0102fcbc7b67c5219c72..50912bb1c1f2fb5d2546f07df8bf507bcdb44fb0 100644 (file)
@@ -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;
index 5fce6f73a6a1d0abf39c6e71ff3485dbd514af96..0a36b217b50f8d50c9e25fd4645fd75922ece503 100644 (file)
@@ -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;
                }
        }
 
index c3aeae9dfb8ed53d1101867540e3919cd4c5e01c..bcbed1eddd423cebb14d7d6258422c2dad4ddfb4 100644 (file)
@@ -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);
index c676186258434b57c099223834540ac38a1d4f0e..9f0d11e7040c6834918464bb251e1e3d6152efa9 100644 (file)
@@ -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;
 
index 9a9c9a3515f70a30c075f70cc2472f3133a175c0..4015cd0e624c760e79d229b16596b87e731f63c6 100644 (file)
@@ -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;
        }
 
index a5771f87e2e9e2203aac0f1144fe2117a04a1df4..bb5dfb648dcc2e1c2cf8cf5364dd47059541d519 100644 (file)
@@ -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;
index 5f54485339af07385ab8845eb0d464addfc10cee..e4fc9637fbf84ba4ae7116e86a8cd55450980103 100644 (file)
@@ -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);
 }
 
index 2982e2eece499ac20e870f445b9cbe53502c8c1b..37126fec4faa35cdc97c30c87631dd4f5f7c68ef 100644 (file)
@@ -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;
index eb15b969687224a94f428f5f3617b1d8925b6ab2..79ed5b21450fb2d2cf66bc6207783488f1f979e6 100644 (file)
@@ -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;
        }
index c0e719ba753680a6b16e3a37c05f10a9b3c2a606..2650a5743608728ded151c61a936af259d01ac75 100644 (file)
@@ -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:", &params)) {
                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 {
index b4a496bbb37ee94fbe9275d88ed6490cde42f2ff..9aca87b58426cbe8630170f6910ddf4d77b33edd 100644 (file)
@@ -127,16 +127,15 @@ void smtp_server_cmd_rcpt(struct smtp_server_cmd_ctx *cmd,
                return;
 
        /* ( "<Postmaster@" Domain ">" / "<Postmaster>" / Forward-path ) */
-       if (params == NULL || strncasecmp(params, "TO:", 3) != 0) {
+       if (params == NULL || !str_begins_icase(params, "TO:", &params)) {
                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 {
index 00e61c90dacd8341a5131ec85807d01db46d032c..4de426cfee40b3c0eee5c598108efecf6a32b260 100644 (file)
@@ -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:", &param.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",
index 1c54e3f07654b78ac73654ffd50cc8a3541d1fd0..ea9418ac4d0cfdcadf2d058c84274f1508f8d1d9 100644 (file)
@@ -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;
index e395919f3429d70accc65eacca55ac3aa6f167c9..ec2e9086336f72ed888cc856713eba016cb0bbc4 100644 (file)
@@ -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;
                }
index 6183f8f21d835d5eca658d6932bab9320d0b06fe..d3fca47f564f6d1ce7c3d2ff2c92b577dd7159ea 100644 (file)
@@ -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;
                }
index 6e51fab161d3dee721ddc8628497f7d8ab7f9b39..7307a0fd93c9c136ce073fd26b62eba15363d607 100644 (file)
@@ -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)
index ce23e9df04ab5e0992992fb6c27fae10168bd211..2348fb15827862cadf2de6f732e976dccaf10c5a 100644 (file)
@@ -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))
index adfd90445f6e9b02cf6530f71283c228b094c8a9..1331fd6cbbb4769242206292a8e031ec29ed4c37 100644 (file)
@@ -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
index 44544a350f5e1d4aabf6b20b96692b6407a484f8..fc74b5b0cd3b64459a0585dfd3f9dafe10b0aa35 100644 (file)
@@ -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;
index ab4736428de2a75028e2ef55fa2a40513e29efd9..338a8fd7d6620c208e35fc44e9669910fbe43d37 100644 (file)
@@ -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);
index 9f47b25084a30dea6669b78eba1a83bae3bb682c..614aac50f0e04bededd2b3018718cb682b43cfe5 100644 (file)
@@ -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 &&
index ae54f59bc75824b806e2910577971aa6e8d30bbc..b70da18b6b94eece8b3e3b5c3b21106fd81fd08e 100644 (file)
@@ -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
index 4b802ebc2b5fe9193503a80ade1d292a1306cdbf..f6535488ceff81c9433906baefeee0df6d370241 100644 (file)
@@ -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;
                }
        }
index 8b4f81940235e5a515e71e900a29b4cf44f5b9c9..11b9cca6cc22994f0e7bebb6ce6e8cfdcc07cf1d 100644 (file)
@@ -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);
                }
        }
 
index 9333fb61399a669e602a7f878d8f2d31c89ccef4..7e292f950ca7d4280130497efab616dcf9e3a94d 100644 (file)
@@ -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;
index f7e062decbdf2ab6bf4f068143a4b1e303af331a..d29e46509be3b149bfb16bfc2777c77cc4cf6b65 100644 (file)
@@ -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)
index 00e25e6b6cd77cbb6fe57146d00b44d4e86fe177..eb123a42d3ae934e6f3505b6e677d6b7fb668797 100644 (file)
@@ -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,
index a4b52fbb275de9b23a492dd068d1be68cf609693..51df83c297239bf1b4107577a82841710520a1bc 100644 (file)
@@ -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;
                }
index 78c40bfa39adaf9141582d7adfdec225562cd260..12820bd16ce60992b77b92101b10d8891fe65c54 100644 (file)
@@ -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);
                         }
                }
 
index 03dae118cf72f68d42f5f6da9b2b9903b41250bb..4965ca461295c91cd1319f562aed1a92b5d99906 100644 (file)
@@ -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) {