]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global - migrate strncmp literals to str_begins
authorPhil Carmody <phil@dovecot.fi>
Thu, 11 Jan 2018 13:03:36 +0000 (15:03 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 8 Jun 2018 08:38:45 +0000 (11:38 +0300)
Simplify a bunch of strncmp(,,number) calls.

git ls-files \*.[ch] | xargs perl -p -i -e 's/strncmp\((.*?), ?(\".*?\"), ?(\d+)\) == 0/str_begins($1, $2)/g'
git ls-files \*.[ch] | xargs perl -p -i -e 's/strncmp\((.*?), ?(\".*?\"), ?(\d+)\) != 0/!str_begins($1, $2)/g'

I ran a longer script to verify that all of the string literals and
the length matched. They didn't:

$ git grep strncmp | perl -ne 'print if(m/strncmp\([^,]*,\s*"(.*?)",\s*(\d+)/ and ($s=$1,$t=$2,$s=~s/\\[tn]/#/g,length($s)) != $t)'
src/auth/db-oauth2.c:               if (strncmp(field, "oauth2:", 8) == 0 &&

With the new functions, that kind of typo is impossible.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
112 files changed:
src/auth/auth-client-connection.c
src/auth/auth-master-connection.c
src/auth/auth-request.c
src/auth/auth-worker-server.c
src/auth/db-ldap.c
src/auth/db-oauth2.c
src/auth/main.c
src/auth/mech-oauth2.c
src/auth/mech-otp.c
src/auth/passdb-blocking.c
src/auth/passdb-bsdauth.c
src/auth/passdb-checkpassword.c
src/auth/passdb-lua.c
src/auth/passdb-pam.c
src/auth/passdb-vpopmail.c
src/auth/password-scheme-crypt.c
src/auth/password-scheme.c
src/auth/userdb-blocking.c
src/auth/userdb-checkpassword.c
src/auth/userdb-lua.c
src/auth/userdb-passwd-file.c
src/auth/userdb-vpopmail.c
src/config/config-connection.c
src/config/old-set-parser.c
src/config/sysinfo-get.c
src/director/login-connection.c
src/dns/dns-client.c
src/doveadm/client-connection-tcp.c
src/doveadm/doveadm-auth-server.c
src/doveadm/doveadm-auth.c
src/doveadm/doveadm-dsync.c
src/doveadm/doveadm-dump-dbox.c
src/doveadm/doveadm-mail-fetch.c
src/doveadm/doveadm-mail-mailbox-metadata.c
src/doveadm/doveadm-mail-server.c
src/doveadm/doveadm-oldstats.c
src/doveadm/doveadm-proxy.c
src/doveadm/doveadm-util.c
src/doveadm/doveadm-zlib.c
src/doveadm/server-connection.c
src/imap-hibernate/imap-client.c
src/imap-login/imap-proxy.c
src/imap-urlauth/imap-urlauth.c
src/imap/cmd-notify.c
src/imap/imap-fetch-body.c
src/imap/imap-sync.c
src/lib-auth/auth-client-request.c
src/lib-auth/auth-master.c
src/lib-auth/auth-server-connection.c
src/lib-dcrypt/dcrypt-openssl.c
src/lib-dict-backend/dict-sql-settings.c
src/lib-dict/dict-client.c
src/lib-dict/dict-memcached-ascii.c
src/lib-dict/dict-memcached.c
src/lib-dict/dict-redis.c
src/lib-dns/dns-lookup.c
src/lib-fs/fs-posix.c
src/lib-imap-storage/imap-msgpart.c
src/lib-imap/imap-base-subject.c
src/lib-index/mail-index.c
src/lib-mail/test-message-header-encode.c
src/lib-master/master-login-auth.c
src/lib-master/master-login.c
src/lib-master/master-service-settings-cache.c
src/lib-master/master-service-settings.c
src/lib-master/master-service.c
src/lib-program-client/program-client.c
src/lib-settings/settings-parser.c
src/lib-smtp/test-smtp-client-errors.c
src/lib-sql/driver-pgsql.c
src/lib-storage/index/imapc/imapc-mail-fetch.c
src/lib-storage/index/index-status.c
src/lib-storage/index/index-storage.c
src/lib-storage/index/maildir/maildir-sync-index.c
src/lib-storage/index/mbox/mbox-save.c
src/lib-storage/index/pop3c/pop3c-mail.c
src/lib-storage/index/pop3c/pop3c-storage.c
src/lib-storage/list/mailbox-list-fs-flags.c
src/lib-storage/list/mailbox-list-maildir-iter.c
src/lib-storage/mail-namespace.c
src/lib-storage/mail-search-register-imap.c
src/lib-storage/mail-storage-hooks.c
src/lib-storage/mail-storage-service.c
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage.c
src/lib-storage/mailbox-list.c
src/lib-storage/test-mail-storage.c
src/lib/iostream-rawlog.c
src/lib/module-dir.c
src/lib/test-str-sanitize.c
src/lib/unlink-directory.c
src/log/log-connection.c
src/login-common/client-common-auth.c
src/login-common/sasl-server.c
src/master/main.c
src/old-stats/client-export.c
src/old-stats/mail-session.c
src/plugins/acl/acl-backend-vfile.c
src/plugins/acl/acl-backend.c
src/plugins/fs-compress/fs-compress.c
src/plugins/fts-lucene/fts-lucene-plugin.c
src/plugins/fts-solr/fts-solr-plugin.c
src/plugins/fts-squat/fts-backend-squat.c
src/plugins/fts-squat/squat-test.c
src/plugins/fts/fts-build-mail.c
src/plugins/fts/fts-indexer.c
src/plugins/old-stats/mail-stats-fill.c
src/plugins/quota/quota-status.c
src/plugins/quota/quota-util.c
src/plugins/quota/quota.c
src/pop3-login/pop3-proxy.c
src/util/script.c

index 78293fd6b2b7f4b7ae95b1d6d28ee75e49d31b66..0bcc8bc2ebaeb2e9269b496c9d2f6a56d5fe20c1 100644 (file)
@@ -215,7 +215,7 @@ auth_client_cancel(struct auth_client_connection *conn, const char *line)
 static bool
 auth_client_handle_line(struct auth_client_connection *conn, const char *line)
 {
-       if (strncmp(line, "AUTH\t", 5) == 0) {
+       if (str_begins(line, "AUTH\t")) {
                if (conn->auth->set->debug) {
                        i_debug("client in: %s",
                                auth_line_hide_pass(conn, line));
@@ -223,7 +223,7 @@ auth_client_handle_line(struct auth_client_connection *conn, const char *line)
                return auth_request_handler_auth_begin(conn->request_handler,
                                                       line + 5);
        }
-       if (strncmp(line, "CONT\t", 5) == 0) {
+       if (str_begins(line, "CONT\t")) {
                if (conn->auth->set->debug) {
                        i_debug("client in: %s",
                                cont_line_hide_pass(conn, line));
@@ -231,7 +231,7 @@ auth_client_handle_line(struct auth_client_connection *conn, const char *line)
                return auth_request_handler_auth_continue(conn->request_handler,
                                                          line + 5);
        }
-       if (strncmp(line, "CANCEL\t", 7) == 0) {
+       if (str_begins(line, "CANCEL\t")) {
                if (conn->auth->set->debug)
                        i_debug("client in: %s", line);
                return auth_client_cancel(conn, line + 7);
@@ -273,7 +273,7 @@ static void auth_client_input(struct auth_client_connection *conn)
                        const char *p;
 
                        /* split the version line */
-                       if (strncmp(line, "VERSION\t", 8) != 0 ||
+                       if (!str_begins(line, "VERSION\t") ||
                            str_parse_uint(line + 8, &vmajor, &p) < 0 ||
                            *(p++) != '\t' || str_to_uint(p, &vminor) < 0) {
                                i_error("Authentication client "
@@ -294,7 +294,7 @@ static void auth_client_input(struct auth_client_connection *conn)
                        continue;
                }
 
-               if (strncmp(line, "CPID\t", 5) == 0) {
+               if (str_begins(line, "CPID\t")) {
                        if (!auth_client_input_cpid(conn, line + 5)) {
                                auth_client_connection_destroy(&conn);
                                return;
index a694b9dde447d1dba4219e1e72b65b9e63c51240..368c78bb61f327c5db0f6c46e2ec12a2dc90b49a 100644 (file)
@@ -610,20 +610,20 @@ auth_master_input_line(struct auth_master_connection *conn, const char *line)
        if (conn->auth->set->debug)
                i_debug("master in: %s", line);
 
-       if (strncmp(line, "USER\t", 5) == 0)
+       if (str_begins(line, "USER\t"))
                return master_input_user(conn, line + 5);
-       if (strncmp(line, "LIST\t", 5) == 0)
+       if (str_begins(line, "LIST\t"))
                return master_input_list(conn, line + 5);
-       if (strncmp(line, "PASS\t", 5) == 0)
+       if (str_begins(line, "PASS\t"))
                return master_input_pass(conn, line + 5);
 
        if (!conn->userdb_only) {
                i_assert(conn->userdb_restricted_uid == 0);
-               if (strncmp(line, "REQUEST\t", 8) == 0)
+               if (str_begins(line, "REQUEST\t"))
                        return master_input_request(conn, line + 8);
-               if (strncmp(line, "CACHE-FLUSH\t", 12) == 0)
+               if (str_begins(line, "CACHE-FLUSH\t"))
                        return master_input_cache_flush(conn, line + 12);
-               if (strncmp(line, "CPID\t", 5) == 0) {
+               if (str_begins(line, "CPID\t")) {
                        i_error("Authentication client trying to connect to "
                                "master socket");
                        return FALSE;
@@ -662,7 +662,7 @@ static void master_input(struct auth_master_connection *conn)
                        return;
 
                /* make sure the major version matches */
-               if (strncmp(line, "VERSION\t", 8) != 0 ||
+               if (!str_begins(line, "VERSION\t") ||
                    !str_uint_equals(t_strcut(line + 8, '\t'),
                                     AUTH_MASTER_PROTOCOL_MAJOR_VERSION)) {
                        i_error("Master not compatible with this server "
index 8aaa4f99bf65c0deba59a26c3c1111769bd370e6..5bfe122d7892c4a3b2aa72329662a87c82843d84 100644 (file)
@@ -513,9 +513,9 @@ bool auth_request_import(struct auth_request *request,
                request->delayed_credentials_size = 1;
        } else if (strcmp(key, "mech") == 0)
                request->mech_name = p_strdup(request->pool, value);
-       else if (strncmp(key, "passdb_", 7) == 0)
+       else if (str_begins(key, "passdb_"))
                auth_fields_add(request->extra_fields, key+7, value, 0);
-       else if (strncmp(key, "userdb_", 7) == 0) {
+       else if (str_begins(key, "userdb_")) {
                if (request->userdb_reply == NULL)
                        request->userdb_reply = auth_fields_init(request->pool);
                auth_fields_add(request->userdb_reply, key+7, value, 0);
@@ -1962,7 +1962,7 @@ void auth_request_set_field(struct auth_request *request,
                }
        } else if (strcmp(name, "allow_real_nets") == 0) {
                auth_request_validate_networks(request, name, value, &request->real_remote_ip);
-       } else if (strncmp(name, "userdb_", 7) == 0) {
+       } else if (str_begins(name, "userdb_")) {
                /* for prefetch userdb */
                request->userdb_prefetch_set = TRUE;
                if (request->userdb_reply == NULL)
@@ -2017,7 +2017,7 @@ void auth_request_set_field(struct auth_request *request,
 
 void auth_request_set_null_field(struct auth_request *request, const char *name)
 {
-       if (strncmp(name, "userdb_", 7) == 0) {
+       if (str_begins(name, "userdb_")) {
                /* make sure userdb prefetch is used even if all the fields
                   were returned as NULL. */
                request->userdb_prefetch_set = TRUE;
index 65bf5f05c016d78de70d61bea2d3cd2811ed6fdc..a0b16d76578ce4f7a2a1e4d5541ea9be1c9a9422 100644 (file)
@@ -277,7 +277,7 @@ static bool auth_worker_request_handle(struct auth_worker_connection *conn,
                                       struct auth_worker_request *request,
                                       const char *line)
 {
-       if (strncmp(line, "*\t", 2) == 0) {
+       if (str_begins(line, "*\t")) {
                /* multi-line reply, not finished yet */
                if (conn->resuming)
                        timeout_reset(conn->to);
index b9c59cf48c7c647527f5b0b5959c9eaf2c5b77bd..f62512d871274edfd88df1bdb55d57d917526c08 100644 (file)
@@ -1246,7 +1246,7 @@ int db_ldap_connect(struct ldap_connection *conn)
                if (ret != LDAP_SUCCESS) {
                        if (ret == LDAP_OPERATIONS_ERROR &&
                            conn->set.uris != NULL &&
-                           strncmp(conn->set.uris, "ldaps:", 6) == 0) {
+                           str_begins(conn->set.uris, "ldaps:")) {
                                i_fatal("LDAP %s: Don't use both tls=yes "
                                        "and ldaps URI", conn->config_path);
                        }
index eb95a8b756a93a07dd642859e76aa10bd03ea016..69f76177e328361d08748a5fb85ed66be47bedb6 100644 (file)
@@ -291,7 +291,7 @@ db_oauth2_have_all_fields(struct db_oauth2_request *req)
                                var_get_key_range(ptr, &idx, &size);
                                ptr = ptr+idx;
                                field = t_strndup(ptr,size);
-                               if (strncmp(field, "oauth2:", 8) == 0 &&
+                               if (str_begins(field, "oauth2:") &&
                                    !auth_fields_exists(req->fields, ptr+8))
                                        return FALSE;
                                ptr = ptr+size;
index 7221e5e1e4db2cc365d42d817e5f2b745542ebaa..b38c963668976be25acdcd92457464d16edc4ea2 100644 (file)
@@ -160,8 +160,8 @@ static void listeners_init(void)
 
 static bool auth_module_filter(const char *name, void *context ATTR_UNUSED)
 {
-       if (strncmp(name, "authdb_", 7) == 0 ||
-           strncmp(name, "mech_", 5) == 0) {
+       if (str_begins(name, "authdb_") ||
+           str_begins(name, "mech_")) {
                /* this is lazily loaded */
                return FALSE;
        }
index 0f1740a89ccbe60d51f56d47d85eeab4dd74334d..b5e9be52cad589cc1c329296a88eb4e64e48cb08 100644 (file)
@@ -104,7 +104,7 @@ mech_xoauth2_auth_continue(struct auth_request *request,
        const char *const *fields =
                t_strsplit(t_strndup(data, data_size), "\x01");
        for(ptr = fields; *ptr != NULL; ptr++) {
-               if (strncmp(*ptr,"user=", 5) == 0) {
+               if (str_begins(*ptr, "user=")) {
                        /* xoauth2 does not require unescaping because the data
                           format does not contain anything to escape */
                        const char *username = (*ptr)+5;
@@ -115,7 +115,7 @@ mech_xoauth2_auth_continue(struct auth_request *request,
                                return;
                        }
                        user_given = TRUE;
-               } else if (strncmp(*ptr,"auth=", 5) == 0) {
+               } else if (str_begins(*ptr, "auth=")) {
                        const char *value = (*ptr)+5;
                        if (strncasecmp(value, "bearer ", 7) == 0 &&
                            oauth2_valid_token(value+7)) {
@@ -212,7 +212,7 @@ mech_oauthbearer_auth_continue(struct auth_request *request,
        }
 
        for(ptr = fields; *ptr != NULL; ptr++) {
-               if (strncmp(*ptr,"auth=", 5) == 0) {
+               if (str_begins(*ptr, "auth=")) {
                        const char *value = (*ptr)+5;
                        if (strncasecmp(value, "bearer ", 7) == 0 &&
                            oauth2_valid_token(value+7)) {
index 14952de00ba18302a3b8cc71f9527349c28f1cc8..5666e99f36a24a19d3a9e174dfc44f8cc4fbcf73 100644 (file)
@@ -203,13 +203,13 @@ mech_otp_auth_phase2(struct auth_request *auth_request,
 {
        const char *str = t_strndup(data, data_size);
 
-       if (strncmp(str, "hex:", 4) == 0) {
+       if (str_begins(str, "hex:")) {
                mech_otp_verify(auth_request, str + 4, TRUE);
-       } else if (strncmp(str, "word:", 5) == 0) {
+       } else if (str_begins(str, "word:")) {
                mech_otp_verify(auth_request, str + 5, FALSE);
-       } else if (strncmp(str, "init-hex:", 9) == 0) {
+       } else if (str_begins(str, "init-hex:")) {
                mech_otp_verify_init(auth_request, str + 9, TRUE);
-       } else if (strncmp(str, "init-word:", 10) == 0) {
+       } else if (str_begins(str, "init-word:")) {
                mech_otp_verify_init(auth_request, str + 10, FALSE);
        } else {
                auth_request_log_error(auth_request, AUTH_SUBSYS_MECH,
index 7f72934e2a0b770869520af1b7d3dce8ad558150..76f7e821e7f2e8a9dd20bf4b4bd51f34d59d9588 100644 (file)
@@ -146,7 +146,7 @@ set_credentials_callback(const char *reply, void *context)
        struct auth_request *request = context;
        bool success;
 
-       success = strcmp(reply, "OK") == 0 || strncmp(reply, "OK\t", 3) == 0;
+       success = strcmp(reply, "OK") == 0 || str_begins(reply, "OK\t");
        request->private_callback.set_credentials(success, request);
        auth_request_unref(&request);
        return TRUE;
index d2a237c2003f82312eb9246ee7b6ff7bcc505854..c67a7d0bf8d142f3379ef42342c88ea04dad51a0 100644 (file)
@@ -66,7 +66,7 @@ bsdauth_preinit(pool_t pool, const char *args)
 
        if (strcmp(args, "blocking=no") == 0)
                module->blocking = FALSE;
-       else if (strncmp(args, "cache_key=", 10) == 0)
+       else if (str_begins(args, "cache_key="))
                module->default_cache_key = auth_cache_parse_key(pool, args + 10);
        else if (*args != '\0')
                i_fatal("passdb bsdauth: Unknown setting: %s", args);
index d5302deed3542877eab0d6be2f68d806c56e3ec5..dd6cc3c38f25909fc6ac83fe8b2217c8ce66b3f8 100644 (file)
@@ -33,7 +33,7 @@ auth_checkpassword_callback(struct auth_request *request,
                break;
        }
        for (i = 0; extra_fields[i] != NULL; i++) {
-               if (strncmp(extra_fields[i], "password=", 9) == 0)
+               if (str_begins(extra_fields[i], "password="))
                        crypted_pass = extra_fields[i]+9;
                else if (extra_fields[i][0] != '\0') {
                        auth_request_set_field_keyvalue(request,
@@ -86,7 +86,7 @@ credentials_checkpassword_callback(struct auth_request *request,
                break;
        }
        for (i = 0; extra_fields[i] != NULL; i++) {
-               if (strncmp(extra_fields[i], "password=", 9) == 0)
+               if (str_begins(extra_fields[i], "password="))
                        crypted_pass = extra_fields[i]+9;
                else if (extra_fields[i][0] != '\0') {
                        auth_request_set_field_keyvalue(request,
index 55f252bd31f2358f1a97547ab7a7300948bf56ba..02dd15f0292c68dbad89d3e60654683ae2ef0266 100644 (file)
@@ -111,9 +111,9 @@ passdb_lua_preinit(pool_t pool, const char *args)
        module = p_new(pool, struct dlua_passdb_module, 1);
        const char *const *fields = t_strsplit_spaces(args, " ");
        while(*fields != NULL) {
-               if (strncmp(*fields, "file=", 5) == 0) {
+               if (str_begins(*fields, "file=")) {
                         module->file = p_strdup(pool, (*fields)+5);
-               } else if (strncmp(*fields, "blocking=", 9) == 0) {
+               } else if (str_begins(*fields, "blocking=")) {
                        const char *value = (*fields)+9;
                        if (strcmp(value, "yes") == 0) {
                                blocking = TRUE;
@@ -124,12 +124,12 @@ passdb_lua_preinit(pool_t pool, const char *args)
                                        "Field blocking must be yes or no",
                                        value);
                        }
-                } else if (strncmp(*fields, "cache_key=", 10) == 0) {
+                } else if (str_begins(*fields, "cache_key=")) {
                         if (*((*fields)+10) != '\0')
                                 cache_key = (*fields)+10;
                         else /* explicitly disable auth caching for lua */
                                 cache_key = NULL;
-               } else if (strncmp(*fields, "scheme=", 7) == 0) {
+               } else if (str_begins(*fields, "scheme=")) {
                        scheme = p_strdup(pool, (*fields)+7);
                } else {
                        i_fatal("Unsupported parameter %s", *fields);
index fe402082f2290449b53df7c2309a2f65f103cefe..6828f194e2a575ab261a13bf84101aec9db9a693 100644 (file)
@@ -358,7 +358,7 @@ pam_preinit(pool_t pool, const char *args)
                        module->pam_session = TRUE;
                else if (strcmp(t_args[i], "setcred=yes") == 0)
                        module->pam_setcred = TRUE;
-               else if (strncmp(t_args[i], "cache_key=", 10) == 0) {
+               else if (str_begins(t_args[i], "cache_key=")) {
                        module->module.default_cache_key =
                                auth_cache_parse_key(pool, t_args[i] + 10);
                } else if (strcmp(t_args[i], "blocking=yes") == 0) {
@@ -368,7 +368,7 @@ pam_preinit(pool_t pool, const char *args)
                } else if (strcmp(t_args[i], "*") == 0) {
                        /* for backwards compatibility */
                        module->service_name = "%Ls";
-               } else if (strncmp(t_args[i], "max_requests=", 13) == 0) {
+               } else if (str_begins(t_args[i], "max_requests=")) {
                        if (str_to_uint(t_args[i] + 13,
                                        &module->requests_left) < 0) {
                                i_error("pam: Invalid requests_left value: %s",
index 34b351cab88d4f27e05ee568cc689687c834406f..733a12655eb29c8de2dd12be34e07c8b1d82a2d1 100644 (file)
@@ -186,10 +186,10 @@ vpopmail_preinit(pool_t pool, const char *args)
 
        tmp = t_strsplit_spaces(args, " ");
        for (; *tmp != NULL; tmp++) {
-               if (strncmp(*tmp, "cache_key=", 10) == 0) {
+               if (str_begins(*tmp, "cache_key=")) {
                        module->module.default_cache_key =
                                auth_cache_parse_key(pool, *tmp + 10);
-               } else if (strncmp(*tmp, "webmail=", 8) == 0) {
+               } else if (str_begins(*tmp, "webmail=")) {
                        if (net_addr2ip(*tmp + 8, &module->webmail_ip) < 0)
                                i_fatal("vpopmail: Invalid webmail IP address");
                } else if (strcmp(*tmp, "blocking=no") == 0) {
index db9b50c90ccca268ec185504e1c3b9f0f15f48cf..34febad8845a98260ddc14f5e901c81834a014dc 100644 (file)
@@ -78,7 +78,7 @@ crypt_verify_blowfish(const char *plaintext, const struct password_generate_para
        password = t_strndup(raw_password, size);
 
        if (size < CRYPT_BLF_PREFIX_LEN ||
-           strncmp(password, "$2", 2) != 0 ||
+           !str_begins(password, "$2") ||
            password[2] < 'a' || password[2] > 'z' ||
            password[3] != '$') {
                *error_r = "Password is not blowfish password";
index dc684e59395ced8491c69476d90e80a3d04cc451..0b84c125b17cfb9dd4b684d459d5df7364cb31df 100644 (file)
@@ -103,7 +103,7 @@ const char *password_get_scheme(const char **password)
        if (*password == NULL)
                return NULL;
 
-       if (strncmp(*password, "$1$", 3) == 0) {
+       if (str_begins(*password, "$1$")) {
                /* $1$<salt>$<password>[$<ignored>] */
                p = strchr(*password + 3, '$');
                if (p != NULL) {
@@ -342,7 +342,7 @@ md5_verify(const char *plaintext, const struct password_generate_params *params,
        size_t md5_size;
 
        password = t_strndup(raw_password, size);
-       if (strncmp(password, "$1$", 3) == 0) {
+       if (str_begins(password, "$1$")) {
                /* MD5-CRYPT */
                str = password_generate_md5_crypt(plaintext, password);
                return strcmp(str, password) == 0 ? 1 : 0;
index 7b134c876da017b8b2ded3b0f53c130f2b01b1aa..fd337434b1676b741180f082c42521fa04c1a2f7 100644 (file)
@@ -20,13 +20,13 @@ static bool user_callback(const char *reply, void *context)
        enum userdb_result result;
        const char *username, *args;
 
-       if (strncmp(reply, "FAIL\t", 5) == 0) {
+       if (str_begins(reply, "FAIL\t")) {
                result = USERDB_RESULT_INTERNAL_FAILURE;
                args = reply + 5;
-       } else if (strncmp(reply, "NOTFOUND\t", 9) == 0) {
+       } else if (str_begins(reply, "NOTFOUND\t")) {
                result = USERDB_RESULT_USER_UNKNOWN;
                args = reply + 9;
-       } else if (strncmp(reply, "OK\t", 3) == 0) {
+       } else if (str_begins(reply, "OK\t")) {
                result = USERDB_RESULT_OK;
                username = reply + 3;
                args = strchr(username, '\t');
@@ -70,7 +70,7 @@ static bool iter_callback(const char *reply, void *context)
 {
        struct blocking_userdb_iterate_context *ctx = context;
 
-       if (strncmp(reply, "*\t", 2) == 0) {
+       if (str_begins(reply, "*\t")) {
                if (ctx->destroyed)
                        return TRUE;
                ctx->next = FALSE;
index 55d029b4d92b3ba5753742caf8a5bc176eb4c0d4..aa6455e9a9d30dbdfcef4a614439e3eeb01f8938 100644 (file)
@@ -29,7 +29,7 @@ userdb_checkpassword_callback(struct auth_request *request,
                break;
        case DB_CHECKPASSWORD_STATUS_OK:
                for (i = 0; extra_fields[i] != NULL; i++) {
-                       if (strncmp(extra_fields[i], "userdb_", 7) != 0)
+                       if (!str_begins(extra_fields[i], "userdb_"))
                                continue;
                        auth_request_set_field_keyvalue(request,
                                                        extra_fields[i], NULL);
index c460dc435c678ef53812a2213316162cade56a80..d15451e3fc285437c3d61ea68650df697f8669f9 100644 (file)
@@ -39,9 +39,9 @@ userdb_lua_preinit(pool_t pool, const char *args)
        module = p_new(pool, struct dlua_userdb_module, 1);
        const char *const *fields = t_strsplit_spaces(args, " ");
        while(*fields != NULL) {
-               if (strncmp(*fields, "file=", 5) == 0) {
+               if (str_begins(*fields, "file=")) {
                         module->file = p_strdup(pool, (*fields)+5);
-               } else if (strncmp(*fields, "blocking=", 9) == 0) {
+               } else if (str_begins(*fields, "blocking=")) {
                        const char *value = (*fields)+9;
                        if (strcmp(value, "yes") == 0) {
                                blocking = TRUE;
@@ -52,7 +52,7 @@ userdb_lua_preinit(pool_t pool, const char *args)
                                        "Field blocking must be yes or no",
                                        value);
                        }
-               } else if (strncmp(*fields, "cache_key=", 10) == 0) {
+               } else if (str_begins(*fields, "cache_key=")) {
                        if (*((*fields)+10) != '\0')
                                cache_key = (*fields)+10;
                        else /* explicitly disable auth caching for lua */
index 190ed045d5d83cd94efb40e4c3e49e1e8986cf57..d90bcab9287f796ea4b49f5a205c18443e7f5c93 100644 (file)
@@ -38,7 +38,7 @@ passwd_file_add_extra_fields(struct auth_request *request, char *const *fields)
        table = auth_request_get_var_expand_table(request, NULL);
 
        for (i = 0; fields[i] != NULL; i++) {
-               if (strncmp(fields[i], "userdb_", 7) != 0)
+               if (!str_begins(fields[i], "userdb_"))
                        continue;
 
                key = fields[i] + 7;
@@ -186,7 +186,7 @@ passwd_file_preinit(pool_t pool, const char *args)
        const char *format = PASSWD_FILE_DEFAULT_USERNAME_FORMAT;
        const char *p;
 
-       if (strncmp(args, "username_format=", 16) == 0) {
+       if (str_begins(args, "username_format=")) {
                args += 16;
                p = strchr(args, ' ');
                if (p == NULL) {
index c6e18577532b22e48931b68545ead5e893d2bb73..4291a1049c3ded79249c993a60c463af40af3a33 100644 (file)
@@ -162,10 +162,10 @@ vpopmail_preinit(pool_t pool, const char *args)
        module->module.blocking = TRUE;
 
        for (tmp = t_strsplit(args, " "); *tmp != NULL; tmp++) {
-               if (strncmp(*tmp, "cache_key=", 10) == 0)
+               if (str_begins(*tmp, "cache_key="))
                        module->module.default_cache_key =
                                p_strdup(pool, *tmp + 10);
-               else if (strncmp(*tmp, "quota_template=", 15) == 0) {
+               else if (str_begins(*tmp, "quota_template=")) {
                        p = strchr(*tmp + 15, '=');
                        if (p == NULL) {
                                i_fatal("vpopmail userdb: "
index f3803e6fc91811e9e5da1571d81cd938d409b728..f3522f1060918fcf15e73dec4018d7f8a0f4ac91 100644 (file)
@@ -78,22 +78,22 @@ static int config_connection_request(struct config_connection *conn,
        t_array_init(&modules, 4);
        i_zero(&filter);
        for (; *args != NULL; args++) {
-               if (strncmp(*args, "service=", 8) == 0)
+               if (str_begins(*args, "service="))
                        filter.service = *args + 8;
-               else if (strncmp(*args, "module=", 7) == 0) {
+               else if (str_begins(*args, "module=")) {
                        module = *args + 7;
                        if (strcmp(module, "master") == 0)
                                is_master = TRUE;
                        array_append(&modules, &module, 1);
-               } else if (strncmp(*args, "lname=", 6) == 0)
+               } else if (str_begins(*args, "lname="))
                        filter.local_name = *args + 6;
-               else if (strncmp(*args, "lip=", 4) == 0) {
+               else if (str_begins(*args, "lip=")) {
                        if (net_addr2ip(*args + 4, &filter.local_net) == 0) {
                                filter.local_bits =
                                        IPADDR_IS_V4(&filter.local_net) ?
                                        32 : 128;
                        }
-               } else if (strncmp(*args, "rip=", 4) == 0) {
+               } else if (str_begins(*args, "rip=")) {
                        if (net_addr2ip(*args + 4, &filter.remote_net) == 0) {
                                filter.remote_bits =
                                        IPADDR_IS_V4(&filter.remote_net) ?
index 5a7ba4cb14f6538ba436799814bd2569b7e8658c..93d78c8d3bfc2f3e75a552f89d5d304352d5cf6e 100644 (file)
@@ -350,7 +350,7 @@ old_settings_handle_root(struct config_parser_context *ctx,
                return TRUE;
        }
        if (ctx->old->auth_section == 1) {
-               if (strncmp(key, "auth_", 5) != 0)
+               if (!str_begins(key, "auth_"))
                        key = t_strconcat("auth_", key, NULL);
                config_parser_apply_line(ctx, CONFIG_LINE_TYPE_KEYVALUE,
                                         key, value);
@@ -561,7 +561,7 @@ old_settings_handle_proto(struct config_parser_context *ctx,
        }
 
        if (ctx->old->auth_section == 1) {
-               if (strncmp(key, "auth_", 5) != 0)
+               if (!str_begins(key, "auth_"))
                        key = t_strconcat("auth_", key, NULL);
        }
 
index a2397b538a1f98938d4073b3d94aae230072b43e..dffebe6e2c25a54aa169c4cc53081e7eafa2779c 100644 (file)
@@ -37,7 +37,7 @@ static bool lsb_distro_get(const char *path, const char **name_r)
                return FALSE;
 
        for (p = t_strsplit(data, "\n"); *p != NULL; p++) {
-               if (strncmp(*p, "DISTRIB_DESCRIPTION=", 20) == 0)
+               if (str_begins(*p, "DISTRIB_DESCRIPTION="))
                        break;
        }
        if (*p == NULL)
index 02052a441b4644b6cbbd648776919bcdf5bed780..0cc5b1b5466ed2e999be4051dfefce13431efc46 100644 (file)
@@ -143,9 +143,9 @@ login_host_callback(const struct mail_host *host, const char *hostname,
        unsigned int secs;
 
        if (host == NULL) {
-               if (strncmp(request->line, "OK\t", 3) == 0)
+               if (str_begins(request->line, "OK\t"))
                        line_params = request->line + 3;
-               else if (strncmp(request->line, "PASS\t", 5) == 0)
+               else if (str_begins(request->line, "PASS\t"))
                        line_params = request->line + 5;
                else
                        i_panic("BUG: Unexpected line: %s", request->line);
@@ -196,10 +196,10 @@ static void auth_input_line(const char *line, void *context)
                return;
        }
        if (conn->type != LOGIN_CONNECTION_TYPE_USERDB &&
-           strncmp(line, "OK\t", 3) == 0)
+           str_begins(line, "OK\t"))
                line_params = line + 3;
        else if (conn->type == LOGIN_CONNECTION_TYPE_USERDB &&
-                strncmp(line, "PASS\t", 5) == 0)
+                str_begins(line, "PASS\t"))
                line_params = line + 5;
        else {
                login_connection_send_line(conn, line);
@@ -216,28 +216,28 @@ static void auth_input_line(const char *line, void *context)
 
        i_zero(&temp_request);
        for (; *args != NULL; args++) {
-               if (strncmp(*args, "proxy", 5) == 0 &&
+               if (str_begins(*args, "proxy") &&
                    ((*args)[5] == '=' || (*args)[5] == '\0'))
                        proxy = TRUE;
-               else if (strncmp(*args, "host=", 5) == 0)
+               else if (str_begins(*args, "host="))
                        host = TRUE;
-               else if (strncmp(*args, "lip=", 4) == 0) {
+               else if (str_begins(*args, "lip=")) {
                        if (net_addr2ip((*args) + 4, &temp_request.local_ip) < 0)
                                i_error("auth sent invalid lip field: %s", (*args) + 6);
-               } else if (strncmp(*args, "lport=", 6) == 0) {
+               } else if (str_begins(*args, "lport=")) {
                        if (net_str2port((*args) + 6, &temp_request.local_port) < 0)
                                i_error("auth sent invalid lport field: %s", (*args) + 6);
-               } else if (strncmp(*args, "port=", 5) == 0) {
+               } else if (str_begins(*args, "port=")) {
                        if (net_str2port((*args) + 5, &temp_request.dest_port) < 0)
                                i_error("auth sent invalid port field: %s", (*args) + 6);
-               } else if (strncmp(*args, "destuser=", 9) == 0)
+               } else if (str_begins(*args, "destuser="))
                        username = *args + 9;
-               else if (strncmp(*args, "director_tag=", 13) == 0)
+               else if (str_begins(*args, "director_tag="))
                        tag = *args + 13;
-               else if (strncmp(*args, "director_proxy_maybe", 20) == 0 &&
+               else if (str_begins(*args, "director_proxy_maybe") &&
                         ((*args)[20] == '=' || (*args)[20] == '\0'))
                        temp_request.director_proxy_maybe = TRUE;
-               else if (strncmp(*args, "user=", 5) == 0) {
+               else if (str_begins(*args, "user=")) {
                        if (username == NULL)
                                username = *args + 5;
                }
index 6d685676db3d4b4d759fbd95955cf69326568cd6..53a41be7ff02623e9e901e68340aa8499fad81de 100644 (file)
@@ -31,7 +31,7 @@ static int dns_client_input_line(struct dns_client *client, const char *line)
        unsigned int i, ips_count;
        int ret;
 
-       if (strncmp(line, "IP\t", 3) == 0) {
+       if (str_begins(line, "IP\t")) {
                ret = net_gethostbyname(line + 3, &ips, &ips_count);
                if (ret == 0 && ips_count == 0) {
                        /* shouldn't happen, but fix it anyway.. */
@@ -48,7 +48,7 @@ static int dns_client_input_line(struct dns_client *client, const char *line)
                                        net_ip2addr(&ips[i]), "\n", NULL));
                        }
                }
-       } else if (strncmp(line, "NAME\t", 5) == 0) {
+       } else if (str_begins(line, "NAME\t")) {
                if (net_addr2ip(line+5, &ip) < 0)
                        o_stream_nsend_str(client->output, "-1\n");
                else if ((ret = net_gethostbyaddr(&ip, &name)) != 0) {
index 0f84525abe4cf060e818ab7d2abdba5586f8c2d9..40e582a19aa8be21b03c9391d1204a17942af994 100644 (file)
@@ -446,7 +446,7 @@ client_connection_tcp_authenticate(struct client_connection_tcp *conn)
 
        /* FIXME: some day we should probably let auth process do this and
           support all kinds of authentication */
-       if (strncmp(line, "PLAIN\t", 6) != 0) {
+       if (!str_begins(line, "PLAIN\t")) {
                i_error("doveadm client attempted non-PLAIN authentication: %s", line);
                return -1;
        }
index e8da5d0a336fe97893b938ef60d99e70e4a7faf8..44278e467e78c7c782fd99eff914dc52046600bf 100644 (file)
@@ -142,18 +142,18 @@ cmd_user_input(struct auth_master_connection *conn,
 
 static void auth_user_info_parse(struct auth_user_info *info, const char *arg)
 {
-       if (strncmp(arg, "service=", 8) == 0)
+       if (str_begins(arg, "service="))
                info->service = arg + 8;
-       else if (strncmp(arg, "lip=", 4) == 0) {
+       else if (str_begins(arg, "lip=")) {
                if (net_addr2ip(arg + 4, &info->local_ip) < 0)
                        i_fatal("lip: Invalid ip");
-       } else if (strncmp(arg, "rip=", 4) == 0) {
+       } else if (str_begins(arg, "rip=")) {
                if (net_addr2ip(arg + 4, &info->remote_ip) < 0)
                        i_fatal("rip: Invalid ip");
-       } else if (strncmp(arg, "lport=", 6) == 0) {
+       } else if (str_begins(arg, "lport=")) {
                if (net_str2port(arg + 6, &info->local_port) < 0)
                        i_fatal("lport: Invalid port number");
-       } else if (strncmp(arg, "rport=", 6) == 0) {
+       } else if (str_begins(arg, "rport=")) {
                if (net_str2port(arg + 6, &info->remote_port) < 0)
                        i_fatal("rport: Invalid port number");
        } else {
index d35b3487a5b76dac41a7557ba357bd07844c25b2..d5a5edafa733d374569b3a96a1591600eb118611 100644 (file)
@@ -216,18 +216,18 @@ cmd_auth_input(const char *auth_socket_path, struct authtest_input *input)
 
 static void auth_user_info_parse(struct auth_user_info *info, const char *arg)
 {
-       if (strncmp(arg, "service=", 8) == 0)
+       if (str_begins(arg, "service="))
                info->service = arg + 8;
-       else if (strncmp(arg, "lip=", 4) == 0) {
+       else if (str_begins(arg, "lip=")) {
                if (net_addr2ip(arg + 4, &info->local_ip) < 0)
                        i_fatal("lip: Invalid ip");
-       } else if (strncmp(arg, "rip=", 4) == 0) {
+       } else if (str_begins(arg, "rip=")) {
                if (net_addr2ip(arg + 4, &info->remote_ip) < 0)
                        i_fatal("rip: Invalid ip");
-       } else if (strncmp(arg, "lport=", 6) == 0) {
+       } else if (str_begins(arg, "lport=")) {
                if (net_str2port(arg + 6, &info->local_port) < 0)
                        i_fatal("lport: Invalid port number");
-       } else if (strncmp(arg, "rport=", 6) == 0) {
+       } else if (str_begins(arg, "rport=")) {
                if (net_str2port(arg + 6, &info->remote_port) < 0)
                        i_fatal("rport: Invalid port number");
        } else {
index 25dce789bfda28f54630265d3f246968633720db..d60b1305643c3322843aee6c86b70120cc36103a 100644 (file)
@@ -891,23 +891,23 @@ parse_location(struct dsync_cmd_context *ctx,
 {
        struct doveadm_cmd_context *cctx = ctx->ctx.cctx;
 
-       if (strncmp(location, "tcp:", 4) == 0) {
+       if (str_begins(location, "tcp:")) {
                /* TCP connection to remote dsync */
                ctx->remote_name = location+4;
                return dsync_connect_tcp(ctx, mail_set, ctx->remote_name,
                                         FALSE, error_r);
        }
-       if (strncmp(location, "tcps:", 5) == 0) {
+       if (str_begins(location, "tcps:")) {
                /* TCP+SSL connection to remote dsync */
                ctx->remote_name = location+5;
                return dsync_connect_tcp(ctx, mail_set, ctx->remote_name,
                                         TRUE, error_r);
        }
 
-       if (strncmp(location, "remote:", 7) == 0) {
+       if (str_begins(location, "remote:")) {
                /* this is a remote (ssh) command */
                ctx->remote_name = location+7;
-       } else if (strncmp(location, "remoteprefix:", 13) == 0) {
+       } else if (str_begins(location, "remoteprefix:")) {
                /* this is a remote (ssh) command with a "user\n"
                   prefix sent before dsync actually starts */
                ctx->remote_name = location+13;
@@ -1380,7 +1380,7 @@ void doveadm_dsync_main(int *_argc, char **_argv[])
                i_fatal("Invalid parameter: %s", argv[src]);
        src++; dest++;
 
-       if (src < argc && strncmp(argv[src], "-E", 2) == 0) {
+       if (src < argc && str_begins(argv[src], "-E")) {
                /* we're re-executing dsync due to doveconf */
                return;
        }
index 7a4b7ebb0bdb02eec50ae5757e9f39e4fad34ea7..fd67e1a6ac5a2f03de29a3937888ce6dd485bc51 100644 (file)
@@ -221,7 +221,7 @@ static bool test_dump_dbox(const char *path)
                p = path;
        else
                p++;
-       return strncmp(p, "m.", 2) == 0 || strncmp(p, "u.", 2) == 0;
+       return str_begins(p, "m.") || str_begins(p, "u.");
 }
 
 struct doveadm_cmd_dump doveadm_cmd_dump_dbox = {
index 4fd4816dc2c160622dae4be33523a4596aaefe85..71ba2ec5066b8a5730269540099d646b36cdd833 100644 (file)
@@ -206,7 +206,7 @@ static int fetch_body_field(struct fetch_cmd_context *ctx)
        bool binary;
        int ret;
 
-       binary = strncmp(name, "binary.", 7) == 0;
+       binary = str_begins(name, "binary.");
        name += binary ? 7 : 5;
        if (imap_msgpart_parse(name, &msgpart) < 0)
                i_unreached(); /* we already verified this was ok */
@@ -549,15 +549,15 @@ static void parse_fetch_fields(struct fetch_cmd_context *ctx, const char *str)
                if ((field = fetch_field_find(name)) != NULL) {
                        ctx->wanted_fields |= field->wanted_fields;
                        array_append(&ctx->fields, field, 1);
-               } else if (strncmp(name, "hdr.", 4) == 0) {
+               } else if (str_begins(name, "hdr.")) {
                        name += 4;
                        hdr_field.name = name;
                        array_append(&ctx->fields, &hdr_field, 1);
                        name = t_strcut(name, '.');
                        array_append(&ctx->header_fields, &name, 1);
-               } else if (strncmp(name, "body.", 5) == 0 ||
-                          strncmp(name, "binary.", 7) == 0) {
-                       bool binary = strncmp(name, "binary.", 7) == 0;
+               } else if (str_begins(name, "body.") ||
+                          str_begins(name, "binary.")) {
+                       bool binary = str_begins(name, "binary.");
                        body_field.name = t_strarray_join(t_strsplit(name, ","), " ");
 
                        name += binary ? 7 : 5;
index 1583c07739f20f9280bc8f4ebf873786be38addc..40da3266f83075ce7af02eaaa8308403027acb6e 100644 (file)
@@ -104,10 +104,10 @@ cmd_mailbox_metadata_parse_key(const char *arg,
 {
        arg = t_str_lcase(arg);
 
-       if (strncmp(arg, "/private/", 9) == 0) {
+       if (str_begins(arg, "/private/")) {
                *type_r = MAIL_ATTRIBUTE_TYPE_PRIVATE;
                *key_r = arg + 9;
-       } else if (strncmp(arg, "/shared/", 8) == 0) {
+       } else if (str_begins(arg, "/shared/")) {
                *type_r = MAIL_ATTRIBUTE_TYPE_SHARED;
                *key_r = arg + 8;
        } else if (strcmp(arg, "/private") == 0) {
index d4f8b307351e3b1211f319b97fb2750c46e88626..d0215844583c74032c9d1111154e5397077dd448 100644 (file)
@@ -224,18 +224,18 @@ doveadm_mail_server_user_get_host(struct doveadm_mail_cmd_context *ctx,
                proxy_host = NULL; proxy_hostip = NULL; proxying = FALSE;
                proxy_port = ctx->set->doveadm_port;
                for (i = 0; fields[i] != NULL; i++) {
-                       if (strncmp(fields[i], "proxy", 5) == 0 &&
+                       if (str_begins(fields[i], "proxy") &&
                            (fields[i][5] == '\0' || fields[i][5] == '='))
                                proxying = TRUE;
-                       else if (strncmp(fields[i], "host=", 5) == 0)
+                       else if (str_begins(fields[i], "host="))
                                proxy_host = fields[i]+5;
-                       else if (strncmp(fields[i], "hostip=", 7) == 0)
+                       else if (str_begins(fields[i], "hostip="))
                                proxy_hostip = fields[i]+7;
-                       else if (strncmp(fields[i], "user=", 5) == 0)
+                       else if (str_begins(fields[i], "user="))
                                *user_r = t_strdup(fields[i]+5);
-                       else if (strncmp(fields[i], "destuser=", 9) == 0)
+                       else if (str_begins(fields[i], "destuser="))
                                *user_r = t_strdup(fields[i]+9);
-                       else if (strncmp(fields[i], "port=", 5) == 0) {
+                       else if (str_begins(fields[i], "port=")) {
                                if (net_str2port(fields[i]+5, &proxy_port) < 0)
                                        proxy_port = 0;
                        }
index f3fea81dc17243b472545a197a2579c905840526..04c45d967739fc6cb5f768731c2cde6b350078f7 100644 (file)
@@ -529,7 +529,7 @@ static void stats_reset(const char *path, const char **items ATTR_UNUSED)
 
        if (line == NULL) {
                i_error("read(%s) failed: %s", path, i_stream_get_error(input));
-       } else if (strncmp(line, "OK", 2) != 0) {
+       } else if (!str_begins(line, "OK")) {
                i_error("%s",line);
        } else {
                i_info("Stats reset");
index e1e83e7404f26b6c587009c70f14ac26d31c73c0..d2e76c0d692fc18cfc8bd9ab8027750530379bdd 100644 (file)
@@ -62,7 +62,7 @@ static void cmd_proxy_list_header(const char *const *args)
                const char *arg = args[i];
 
                if (strcmp(arg, "username") == 0 ||
-                   strncmp(arg, "user_", 5) == 0) {
+                   str_begins(arg, "user_")) {
                        doveadm_print_header(arg, arg,
                                             DOVEADM_PRINT_HEADER_FLAG_EXPAND);
                        continue;
index b8d90ae2e70042db0f00d8c6e49a82698ebe968d..a65ef7f723c5b0743926b5d2e37864826cf45068 100644 (file)
@@ -64,7 +64,7 @@ bool doveadm_has_unloaded_plugin(const char *name)
 
        while ((d = readdir(dir)) != NULL) {
                plugin_name = module_file_get_name(d->d_name);
-               if (strncmp(plugin_name, "doveadm_", 8) == 0)
+               if (str_begins(plugin_name, "doveadm_"))
                        plugin_name += 8;
 
                if (strncmp(plugin_name, name, name_len) == 0 &&
index a2144d6921173b8465874710ae98592cdfe2bb94..e82dc19fece87906772db9af37368c72a5f8fbe9 100644 (file)
@@ -61,7 +61,7 @@ static void cmd_dump_imapzlib(int argc ATTR_UNUSED, char *argv[])
                        continue;
                line++;
 
-               if (strncmp(line, "OK Begin compression", 20) == 0 ||
+               if (str_begins(line, "OK Begin compression") ||
                    strcasecmp(line, "COMPRESS DEFLATE") == 0)
                        break;
        }
index e5b9930f538c1e96fc9676e0cfe0bfd9051bdf62..fa83187c0a2c809bf5da4d20341c5df0ec2280df 100644 (file)
@@ -366,7 +366,7 @@ static void server_connection_input(struct server_connection *conn)
                   because v2.2.33 sent the version after and newer
                   versions send before. */
                if (!conn->version_received &&
-                   strncmp(line, "VERSION\t", 8) == 0) {
+                   str_begins(line, "VERSION\t")) {
                        if (!version_string_verify_full(line, "doveadm-client",
                                                        DOVEADM_SERVER_PROTOCOL_VERSION_MAJOR,
                                                        &conn->minor)) {
index 0db3fc0eabb94a6384724234505af9a6de721b2c..f336bdb4768f80a50b9950dffd95f52f07ae5f2b 100644 (file)
@@ -112,7 +112,7 @@ imap_client_parse_userdb_fields(struct imap_client *client,
 
        field = t_strsplit_tabescaped(client->state.userdb_fields);
        for (i = 0; field[i] != NULL; i++) {
-               if (strncmp(field[i], "auth_user=", 10) == 0)
+               if (str_begins(field[i], "auth_user="))
                        *auth_user_r = field[i] + 10;
        }
 }
index 6900d77e9c8a5fda75d8d09f2005f60f1162710a..768426644df45ca72cdab7a08eabfc9b69901126 100644 (file)
@@ -174,7 +174,7 @@ static int proxy_input_banner(struct imap_client *client,
        string_t *str;
        int ret;
 
-       if (strncmp(line, "* OK ", 5) != 0) {
+       if (!str_begins(line, "* OK ")) {
                client_log_err(&client->common, t_strdup_printf(
                        "proxy: Remote returned invalid banner: %s",
                        str_sanitize(line, 160)));
@@ -182,7 +182,7 @@ static int proxy_input_banner(struct imap_client *client,
        }
 
        str = t_str_new(128);
-       if (strncmp(line + 5, "[CAPABILITY ", 12) == 0) {
+       if (str_begins(line + 5, "[CAPABILITY ")) {
                capabilities = t_strsplit(t_strcut(line + 5 + 12, ']'), " ");
                if (str_array_icase_find(capabilities, "SASL-IR"))
                        client->proxy_sasl_ir = TRUE;
@@ -310,11 +310,11 @@ int imap_proxy_parse_line(struct client *client, const char *line)
                imap_client->proxy_sent_state |= IMAP_PROXY_SENT_STATE_AUTH_CONTINUE;
                o_stream_nsend(output, str_data(str), str_len(str));
                return 0;
-       } else if (strncmp(line, "S ", 2) == 0) {
+       } else if (str_begins(line, "S ")) {
                imap_client->proxy_sent_state &= ~IMAP_PROXY_SENT_STATE_STARTTLS;
                imap_client->proxy_rcvd_state = IMAP_PROXY_RCVD_STATE_STARTTLS;
 
-               if (strncmp(line, "S OK ", 5) != 0) {
+               if (!str_begins(line, "S OK ")) {
                        /* STARTTLS failed */
                        client_log_err(client, t_strdup_printf(
                                "proxy: Remote STARTTLS failed: %s",
@@ -336,7 +336,7 @@ int imap_proxy_parse_line(struct client *client, const char *line)
                }
                o_stream_nsend(output, str_data(str), str_len(str));
                return 1;
-       } else if (strncmp(line, "L OK ", 5) == 0) {
+       } else if (str_begins(line, "L OK ")) {
                /* Login successful. Send this line to client. */
                imap_client->proxy_sent_state &= ~IMAP_PROXY_SENT_STATE_LOGIN;
                imap_client->proxy_rcvd_state = IMAP_PROXY_RCVD_STATE_LOGIN;
@@ -346,7 +346,7 @@ int imap_proxy_parse_line(struct client *client, const char *line)
 
                client_proxy_finish_destroy_client(client);
                return 1;
-       } else if (strncmp(line, "L ", 2) == 0) {
+       } else if (str_begins(line, "L ")) {
                imap_client->proxy_sent_state &= ~IMAP_PROXY_SENT_STATE_LOGIN;
                imap_client->proxy_rcvd_state = IMAP_PROXY_RCVD_STATE_LOGIN;
 
@@ -369,7 +369,7 @@ int imap_proxy_parse_line(struct client *client, const char *line)
                        client_send_reply_code(client, IMAP_CMD_REPLY_NO,
                                               IMAP_RESP_CODE_AUTHFAILED,
                                               AUTH_FAILED_MSG);
-               } else if (strncmp(line, "NO [", 4) == 0) {
+               } else if (str_begins(line, "NO [")) {
                        /* remote sent some other resp-code. forward it. */
                        client_send_raw(client, t_strconcat(
                                imap_client->cmd_tag, " ", line, "\r\n", NULL));
@@ -393,11 +393,11 @@ int imap_proxy_parse_line(struct client *client, const char *line)
                i_free(imap_client->proxy_backend_capability);
                imap_client->proxy_backend_capability = i_strdup(line + 13);
                return 0;
-       } else if (strncmp(line, "C ", 2) == 0) {
+       } else if (str_begins(line, "C ")) {
                /* Reply to CAPABILITY command we sent */
                imap_client->proxy_sent_state &= ~IMAP_PROXY_SENT_STATE_CAPABILITY;
                imap_client->proxy_rcvd_state = IMAP_PROXY_RCVD_STATE_CAPABILITY;
-               if (strncmp(line, "C OK ", 5) == 0 &&
+               if (str_begins(line, "C OK ") &&
                    client->proxy_password != NULL) {
                        /* pipelining was disabled, send the login now. */
                        str = t_str_new(128);
@@ -429,7 +429,7 @@ int imap_proxy_parse_line(struct client *client, const char *line)
        } else if (strncasecmp(line, "* ID ", 5) == 0) {
                /* Reply to ID command we sent, ignore it */
                return 0;
-       } else if (strncmp(line, "* ", 2) == 0) {
+       } else if (str_begins(line, "* ")) {
                /* untagged reply. just forward it. */
                client_send_raw(client, t_strconcat(line, "\r\n", NULL));
                return 0;
index 9f9d12b6922df43b80b352c1d831277d0f6f1741..70bc67a2c7e060ba21809573e119a7c02210de34 100644 (file)
@@ -156,7 +156,7 @@ login_client_connected(const struct master_login_client *client,
 
        fields = array_get(&reply.extra_fields, &count);
        for (i = 0; i < count; i++) {
-               if (strncmp(fields[i], "client_service=", 15) == 0) {
+               if (str_begins(fields[i], "client_service=")) {
                        service = fields[i] + 15;
                        break;
                }
index 494139e1dd9cd6e25725b2f9e9c87f030590c076..bc74122c969b3ebb8b2cd2c1ea94c0f271d5782c 100644 (file)
@@ -157,7 +157,7 @@ cmd_notify_add_mailbox(struct imap_notify_context *ctx,
        char ns_sep = mail_namespace_get_sep(ns);
 
        if ((ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0 &&
-           strncmp(name, "INBOX", 5) != 0 &&
+           !str_begins(name, "INBOX") &&
            strncasecmp(name, "INBOX", 5) == 0 &&
            (name[5] == '\0' || name[5] == ns_sep)) {
                /* we'll do only case-sensitive comparisons later,
index cdb967075dc6dce7b4db8ba2c6cf1b1bed58cbfb..4714371cf2cad1e4ff730b0d2c23148047d8d612 100644 (file)
@@ -315,12 +315,12 @@ bool imap_fetch_body_section_init(struct imap_fetch_init_context *ctx)
        unsigned int list_count;
        const char *str, *p, *error;
 
-       i_assert(strncmp(ctx->name, "BODY", 4) == 0);
+       i_assert(str_begins(ctx->name, "BODY"));
        p = ctx->name + 4;
 
        body = p_new(ctx->pool, struct imap_fetch_body_data, 1);
 
-       if (strncmp(p, ".PEEK", 5) == 0)
+       if (str_begins(p, ".PEEK"))
                p += 5;
        else
                ctx->fetch_ctx->flags_update_seen = TRUE;
@@ -380,17 +380,17 @@ bool imap_fetch_binary_init(struct imap_fetch_init_context *ctx)
        unsigned int list_count;
        const char *str, *p, *error;
 
-       i_assert(strncmp(ctx->name, "BINARY", 6) == 0);
+       i_assert(str_begins(ctx->name, "BINARY"));
        p = ctx->name + 6;
 
        body = p_new(ctx->pool, struct imap_fetch_body_data, 1);
        body->binary = TRUE;
 
-       if (strncmp(p, ".SIZE", 5) == 0) {
+       if (str_begins(p, ".SIZE")) {
                /* fetch decoded size of the section */
                p += 5;
                body->binary_size = TRUE;
-       } else if (strncmp(p, ".PEEK", 5) == 0) {
+       } else if (str_begins(p, ".PEEK")) {
                p += 5;
        } else {
                ctx->fetch_ctx->flags_update_seen = TRUE;
index dbaacdfd0f679a8ceaf6364b3dea1d659a4e63e0..ad5d471f6a3f0cefac9d08a076b40eff2be7ad65 100644 (file)
@@ -237,7 +237,7 @@ imap_sync_send_highestmodseq(struct imap_sync_context *ctx,
                /* no sending */
        } else if (sync_cmd->sync != NULL && /* IDLE doesn't have ->sync */
                   sync_cmd->sync->tagline != NULL && /* NOTIFY doesn't have tagline */
-                  strncmp(sync_cmd->sync->tagline, "OK ", 3) == 0 &&
+                  str_begins(sync_cmd->sync->tagline, "OK ") &&
                   sync_cmd->sync->tagline[3] != '[') {
                /* modify the tagged reply directly */
                sync_cmd->sync->tagline = p_strdup_printf(sync_cmd->pool,
index f6d0290a13bb2330246c7906f1f5dd6db8c852f2..d06befba741339f9b7718d6533f31001bd7505db 100644 (file)
@@ -231,7 +231,7 @@ void auth_client_request_server_input(struct auth_client_request *request,
        switch (status) {
        case AUTH_REQUEST_STATUS_OK:
                for (tmp = args; *tmp != NULL; tmp++) {
-                       if (strncmp(*tmp, "resp=", 5) == 0) {
+                       if (str_begins(*tmp, "resp=")) {
                                base64_data = *tmp + 5;
                                break;
                        }
index c3763196a2d35d559519a15a5a98e9fca898a491..e92c40c52bd06cbd7909d9af32a308b0f51d101b 100644 (file)
@@ -209,7 +209,7 @@ static bool auth_lookup_reply_callback(const char *cmd, const char *const *args,
                /* put the reason string into first field */
                ctx->fields = p_new(ctx->pool, const char *, 2);
                for (i = 0; i < len; i++) {
-                       if (strncmp(args[i], "reason=", 7) == 0) {
+                       if (str_begins(args[i], "reason=")) {
                                ctx->fields[0] =
                                        p_strdup(ctx->pool, args[i] + 7);
                                break;
@@ -526,15 +526,15 @@ void auth_user_fields_parse(const char *const *fields, pool_t pool,
        p_array_init(&reply_r->extra_fields, pool, 64);
 
        for (; *fields != NULL; fields++) {
-               if (strncmp(*fields, "uid=", 4) == 0) {
+               if (str_begins(*fields, "uid=")) {
                        if (str_to_uid(*fields + 4, &reply_r->uid) < 0)
                                i_error("Invalid uid in reply");
-               } else if (strncmp(*fields, "gid=", 4) == 0) {
+               } else if (str_begins(*fields, "gid=")) {
                        if (str_to_gid(*fields + 4, &reply_r->gid) < 0)
                                i_error("Invalid gid in reply");
-               } else if (strncmp(*fields, "home=", 5) == 0)
+               } else if (str_begins(*fields, "home="))
                        reply_r->home = p_strdup(pool, *fields + 5);
-               else if (strncmp(*fields, "chroot=", 7) == 0)
+               else if (str_begins(*fields, "chroot="))
                        reply_r->chroot = p_strdup(pool, *fields + 7);
                else if (strcmp(*fields, "anonymous") == 0)
                        reply_r->anonymous = TRUE;
index 7eea061cad618a3725d841a7699d4e5e9c0bee88..63f02b9fac083a91870255ef9378186e25feaf19 100644 (file)
@@ -262,7 +262,7 @@ static void auth_server_connection_input(struct auth_server_connection *conn)
                        return;
 
                /* make sure the major version matches */
-               if (strncmp(line, "VERSION\t", 8) != 0 ||
+               if (!str_begins(line, "VERSION\t") ||
                    !str_uint_equals(t_strcut(line + 8, '\t'),
                                     AUTH_CLIENT_PROTOCOL_MAJOR_VERSION)) {
                        i_error("Authentication server not compatible with "
index 28a72cf1a8fdcc94bc6187e1702b7bdc86395d01..c2dbd301e544be2ab8fb57c401c9a423400f12f1 100644 (file)
@@ -2046,24 +2046,24 @@ dcrypt_openssl_key_string_get_info(
        i_assert(key_data != NULL);
 
        /* is it PEM key */
-       if (strncmp(key_data, "-----BEGIN ", 11) == 0) {
+       if (str_begins(key_data, "-----BEGIN ")) {
                format = DCRYPT_FORMAT_PEM;
                version = DCRYPT_KEY_VERSION_NA;
                key_data += 11;
-               if (strncmp(key_data, "RSA ", 4) == 0) {
+               if (str_begins(key_data, "RSA ")) {
                        if (error_r != NULL)
                                *error_r = "RSA private key format not "
                                        "supported, convert it to PKEY format "
                                        "with openssl pkey";
                        return FALSE;
                }
-               if (strncmp(key_data, "ENCRYPTED ", 10) == 0) {
+               if (str_begins(key_data, "ENCRYPTED ")) {
                        encryption_type = DCRYPT_KEY_ENCRYPTION_TYPE_PASSWORD;
                        key_data += 10;
                }
-               if (strncmp(key_data, "PRIVATE KEY-----", 16) == 0)
+               if (str_begins(key_data, "PRIVATE KEY-----"))
                        kind = DCRYPT_KEY_KIND_PRIVATE;
-               else if (strncmp(key_data, "PUBLIC KEY-----", 15) == 0)
+               else if (str_begins(key_data, "PUBLIC KEY-----"))
                        kind = DCRYPT_KEY_KIND_PUBLIC;
                else {
                        if (error_r != NULL)
@@ -2071,12 +2071,12 @@ dcrypt_openssl_key_string_get_info(
                        return FALSE;
                }
        } else {
-               if (strncmp(key_data, "1:", 2) == 0) {
+               if (str_begins(key_data, "1:")) {
                        if (error_r != NULL)
                                *error_r = "Dovecot v1 key format "
                                        "uses tab to separate fields";
                        return FALSE;
-               } else if (strncmp(key_data, "2\t", 2) == 0) {
+               } else if (str_begins(key_data, "2\t")) {
                        if (error_r != NULL)
                                *error_r = "Dovecot v2 key format uses "
                                        "colon to separate fields";
index 957b6463d581da93b8bad73ca02670cfab1dc3a1..c80bd85a6cda57f70887a27a5dc66ec21e64fc73 100644 (file)
@@ -223,17 +223,17 @@ parse_setting(const char *key, const char *value,
                field = array_append_space(&ctx->cur_fields);
                field->sql_field.name = p_strdup(ctx->pool, key);
                value_len = strlen(value);
-               if (strncmp(value, "${hexblob:", 10) == 0 &&
+               if (str_begins(value, "${hexblob:") &&
                    value[value_len-1] == '}') {
                        field->variable = p_strndup(ctx->pool, value + 10,
                                                    value_len-10-1);
                        field->sql_field.value_type = DICT_SQL_TYPE_HEXBLOB;
-               } else if (strncmp(value, "${int:", 6) == 0 &&
+               } else if (str_begins(value, "${int:") &&
                           value[value_len-1] == '}') {
                        field->variable = p_strndup(ctx->pool, value + 6,
                                                    value_len-6-1);
                        field->sql_field.value_type = DICT_SQL_TYPE_INT;
-               } else if (strncmp(value, "${uint:", 7) == 0 &&
+               } else if (str_begins(value, "${uint:") &&
                           value[value_len-1] == '}') {
                        field->variable = p_strndup(ctx->pool, value + 7,
                                                    value_len-7-1);
index cc945c573a844e5f274797e4b72efea819adb1ee..f4d6d84b871b357c01d0f754a8bb550e3291d1fd 100644 (file)
@@ -721,7 +721,7 @@ client_dict_init(struct dict *driver, const char *uri,
 
        /* uri = [idle_msecs=<n>:] [warn_slow_msecs=<n>:] [<path>] ":" <uri> */
        for (;;) {
-               if (strncmp(uri, "idle_msecs=", 11) == 0) {
+               if (str_begins(uri, "idle_msecs=")) {
                        p = strchr(uri+11, ':');
                        if (p == NULL) {
                                *error_r = t_strdup_printf("Invalid URI: %s", uri);
@@ -732,7 +732,7 @@ client_dict_init(struct dict *driver, const char *uri,
                                return -1;
                        }
                        uri = p+1;
-               } else if (strncmp(uri, "warn_slow_msecs=", 16) == 0) {
+               } else if (str_begins(uri, "warn_slow_msecs=")) {
                        p = strchr(uri+11, ':');
                        if (p == NULL) {
                                *error_r = t_strdup_printf("Invalid URI: %s", uri);
index 4fd540020f320c9e78bc0ec9c523a97ed336cca9..30e4f531da22977ce3bf97dd71def34b471f67ac 100644 (file)
@@ -168,7 +168,7 @@ static int memcached_ascii_input_reply_read(struct memcached_ascii_dict *dict,
        case MEMCACHED_INPUT_STATE_GET:
                /* VALUE <key> <flags> <bytes>
                   END */
-               if (strncmp(line, "VALUE ", 6) == 0) {
+               if (str_begins(line, "VALUE ")) {
                        p = strrchr(line, ' ');
                        if (str_to_uint(p+1, &conn->reply_bytes_left) < 0)
                                break;
@@ -398,22 +398,22 @@ memcached_ascii_dict_init(struct dict *driver, const char *uri,
 
        args = t_strsplit(uri, ":");
        for (; *args != NULL; args++) {
-               if (strncmp(*args, "host=", 5) == 0) {
+               if (str_begins(*args, "host=")) {
                        if (net_addr2ip(*args+5, &dict->ip) < 0) {
                                *error_r = t_strdup_printf("Invalid IP: %s",
                                                           *args+5);
                                ret = -1;
                        }
-               } else if (strncmp(*args, "port=", 5) == 0) {
+               } else if (str_begins(*args, "port=")) {
                        if (net_str2port(*args+5, &dict->port) < 0) {
                                *error_r = t_strdup_printf("Invalid port: %s",
                                                           *args+5);
                                ret = -1;
                        }
-               } else if (strncmp(*args, "prefix=", 7) == 0) {
+               } else if (str_begins(*args, "prefix=")) {
                        i_free(dict->key_prefix);
                        dict->key_prefix = i_strdup(*args + 7);
-               } else if (strncmp(*args, "timeout_msecs=", 14) == 0) {
+               } else if (str_begins(*args, "timeout_msecs=")) {
                        if (str_to_uint(*args+14, &dict->timeout_msecs) < 0) {
                                *error_r = t_strdup_printf(
                                        "Invalid timeout_msecs: %s", *args+14);
index e7a27f4058e48bc8e084a128604a85ac71a04026..cea4a33b6916e16da1490701f9f24291944cca4b 100644 (file)
@@ -191,22 +191,22 @@ memcached_dict_init(struct dict *driver, const char *uri,
 
        args = t_strsplit(uri, ":");
        for (; *args != NULL; args++) {
-               if (strncmp(*args, "host=", 5) == 0) {
+               if (str_begins(*args, "host=")) {
                        if (net_addr2ip(*args+5, &dict->ip) < 0) {
                                *error_r = t_strdup_printf("Invalid IP: %s",
                                                           *args+5);
                                ret = -1;
                        }
-               } else if (strncmp(*args, "port=", 5) == 0) {
+               } else if (str_begins(*args, "port=")) {
                        if (net_str2port(*args+5, &dict->port) < 0) {
                                *error_r = t_strdup_printf("Invalid port: %s",
                                                           *args+5);
                                ret = -1;
                        }
-               } else if (strncmp(*args, "prefix=", 7) == 0) {
+               } else if (str_begins(*args, "prefix=")) {
                        i_free(dict->key_prefix);
                        dict->key_prefix = i_strdup(*args + 7);
-               } else if (strncmp(*args, "timeout_msecs=", 14) == 0) {
+               } else if (str_begins(*args, "timeout_msecs=")) {
                        if (str_to_uint(*args+14, &dict->timeout_msecs) < 0) {
                                *error_r = t_strdup_printf(
                                        "Invalid timeout_msecs: %s", *args+14);
index 14b4db0c48fcbb53b555aa64581f5aa5b024526f..97dc40e65a049d4c718d52f7deff35f920e58069 100644 (file)
@@ -376,30 +376,30 @@ redis_dict_init(struct dict *driver, const char *uri,
 
        args = t_strsplit(uri, ":");
        for (; *args != NULL; args++) {
-               if (strncmp(*args, "path=", 5) == 0) {
+               if (str_begins(*args, "path=")) {
                        unix_path = *args + 5;
-               } else if (strncmp(*args, "host=", 5) == 0) {
+               } else if (str_begins(*args, "host=")) {
                        if (net_addr2ip(*args+5, &ip) < 0) {
                                *error_r = t_strdup_printf("Invalid IP: %s",
                                                           *args+5);
                                ret = -1;
                        }
-               } else if (strncmp(*args, "port=", 5) == 0) {
+               } else if (str_begins(*args, "port=")) {
                        if (net_str2port(*args+5, &port) < 0) {
                                *error_r = t_strdup_printf("Invalid port: %s",
                                                           *args+5);
                                ret = -1;
                        }
-               } else if (strncmp(*args, "prefix=", 7) == 0) {
+               } else if (str_begins(*args, "prefix=")) {
                        i_free(dict->key_prefix);
                        dict->key_prefix = i_strdup(*args + 7);
-               } else if (strncmp(*args, "db=", 3) == 0) {
+               } else if (str_begins(*args, "db=")) {
                        if (str_to_uint(*args+3, &dict->db_id) < 0) {
                                *error_r = t_strdup_printf(
                                        "Invalid db number: %s", *args+3);
                                ret = -1;
                        }
-               } else if (strncmp(*args, "expire_secs=", 12) == 0) {
+               } else if (str_begins(*args, "expire_secs=")) {
                        const char *value = *args + 12;
 
                        if (str_to_uint(value, &secs) < 0 || secs == 0) {
@@ -409,13 +409,13 @@ redis_dict_init(struct dict *driver, const char *uri,
                        }
                        i_free(dict->expire_value);
                        dict->expire_value = i_strdup(value);
-               } else if (strncmp(*args, "timeout_msecs=", 14) == 0) {
+               } else if (str_begins(*args, "timeout_msecs=")) {
                        if (str_to_uint(*args+14, &dict->timeout_msecs) < 0) {
                                *error_r = t_strdup_printf(
                                        "Invalid timeout_msecs: %s", *args+14);
                                ret = -1;
                        }
-               } else if (strncmp(*args, "password=", 9) == 0) {
+               } else if (str_begins(*args, "password=")) {
                        i_free(dict->password);
                        dict->password = i_strdup(*args + 9);
                } else {
index 4f444a80b4caeb42479aaab4fe00d4709d9b9e41..c8c71d1da7fc328b0c67164f594d13180a188bd7 100644 (file)
@@ -87,7 +87,7 @@ static int dns_lookup_input_line(struct dns_lookup *lookup, const char *line)
        if (result->ips_count == 0) {
                if (lookup->ptr_lookup) {
                        /* <ret> [<name>] */
-                       if (strncmp(line, "0 ", 2) == 0) {
+                       if (str_begins(line, "0 ")) {
                                result->name = lookup->name =
                                        i_strdup(line + 2);
                                result->ret = 0;
index 167c1c3d729672291b93c2f9d2a7cf39e07b4d5c..34488f9afa53efce3746325d980328d3e25e7ed7 100644 (file)
@@ -98,7 +98,7 @@ fs_posix_init(struct fs *_fs, const char *args, const struct fs_settings *set)
                        fs->lock_method = FS_POSIX_LOCK_METHOD_FLOCK;
                else if (strcmp(arg, "lock=dotlock") == 0)
                        fs->lock_method = FS_POSIX_LOCK_METHOD_DOTLOCK;
-               else if (strncmp(arg, "prefix=", 7) == 0) {
+               else if (str_begins(arg, "prefix=")) {
                        i_free(fs->path_prefix);
                        fs->path_prefix = i_strdup(arg + 7);
                } else if (strcmp(arg, "mode=auto") == 0) {
@@ -107,9 +107,9 @@ fs_posix_init(struct fs *_fs, const char *args, const struct fs_settings *set)
                        fs->have_dirs = TRUE;
                } else if (strcmp(arg, "no-fsync") == 0) {
                        fs->disable_fsync = TRUE;
-               } else if (strcmp(arg, "accurate-mtime") == 0) {
+               } else if (str_begins(arg, "accurate-mtime") == 0) {
                        fs->accurate_mtime = TRUE;
-               } else if (strncmp(arg, "mode=", 5) == 0) {
+               } else if (str_begins(arg, "mode=")) {
                        unsigned int mode;
                        if (str_to_uint_oct(arg+5, &mode) < 0) {
                                fs_set_error(_fs, "Invalid mode value: %s", arg+5);
index b6d3c31dfae57d922f6d4d491c24e0fd406758b9..a69aa991181b0e09437f0a1862bfd0a8244905ec 100644 (file)
@@ -264,16 +264,16 @@ int imap_msgpart_parse(const char *section, struct imap_msgpart **msgpart_r)
                /* body (for root or for message/rfc822) */
                msgpart->fetch_type = FETCH_BODY;
                msgpart->wanted_fields |= MAIL_FETCH_STREAM_BODY;
-       } else if (strncmp(section, "HEADER", 6) == 0) {
+       } else if (str_begins(section, "HEADER")) {
                /* header (for root or for message/rfc822) */
                if (section[6] == '\0') {
                        msgpart->fetch_type = FETCH_HEADER;
                        ret = 0;
-               } else if (strncmp(section, "HEADER.FIELDS.NOT", 17) == 0) {
+               } else if (str_begins(section, "HEADER.FIELDS.NOT")) {
                        msgpart->fetch_type = FETCH_HEADER_FIELDS_NOT;
                        ret = imap_msgpart_parse_header_fields(msgpart,
                                                               section+17);
-               } else if (strncmp(section, "HEADER.FIELDS", 13) == 0) {
+               } else if (str_begins(section, "HEADER.FIELDS")) {
                        msgpart->fetch_type = FETCH_HEADER_FIELDS;
                        ret = imap_msgpart_parse_header_fields(msgpart,
                                                               section+13);
index 062cbe186455a6208917eb208f1036843f7f0733..02469d3ddacef64e953607a6df261f6259af498f 100644 (file)
@@ -129,11 +129,11 @@ static bool remove_subj_leader(buffer_t *buf, size_t *start_pos,
                        return ret;
        }
 
-       if (strncmp(data, "RE", 2) == 0)
+       if (str_begins(data, "RE"))
                data += 2;
-       else if (strncmp(data, "FWD", 3) == 0)
+       else if (str_begins(data, "FWD"))
                data += 3;
-       else if (strncmp(data, "FW", 2) == 0)
+       else if (str_begins(data, "FW"))
                data += 2;
        else
                return ret;
@@ -178,7 +178,7 @@ static bool remove_subj_fwd_hdr(buffer_t *buf, size_t *start_pos,
           subj-fwd-hdr    = "[fwd:"
           subj-fwd-trl    = "]" */
 
-       if (strncmp(data + *start_pos, "[FWD:", 5) != 0)
+       if (!str_begins(data + *start_pos, "[FWD:"))
                return FALSE;
 
        if (data[size-2] != ']')
index bde6fb1b867896c4e6757ca8ade76a46084420b6..ef5c93ed853ff66e4fd658f74f116ab9731fe3f7 100644 (file)
@@ -1067,7 +1067,7 @@ void mail_index_file_set_syscall_error(struct mail_index *index,
        if (errno == EACCES) {
                function = t_strcut(function, '(');
                if (strcmp(function, "creat") == 0 ||
-                   strncmp(function, "file_dotlock_", 13) == 0)
+                   str_begins(function, "file_dotlock_"))
                        errstr = eacces_error_get_creating(function, filepath);
                else
                        errstr = eacces_error_get(function, filepath);
index 69a4cb22f78d1b0e184c9b2ca0835d5b70b98b17..ebcfedd1e169d9ac5187a9efd01702c1b73b039d 100644 (file)
@@ -11,13 +11,13 @@ static bool verify_q(const char *str, unsigned int i, bool starts_with_a)
 {
        unsigned int line_start = i, char_count = 0;
 
-       if (strncmp(str+i, "\n\t", 2) == 0) {
+       if (str_begins(str+i, "\n\t")) {
                i += 2;
                line_start = i - 1;
        }
 
        for (;;) {
-               if (strncmp(str+i, "=?utf-8?q?", 10) != 0)
+               if (!str_begins(str+i, "=?utf-8?q?"))
                        return FALSE;
                i += 10;
 
@@ -27,8 +27,8 @@ static bool verify_q(const char *str, unsigned int i, bool starts_with_a)
                        starts_with_a = FALSE;
                        i++;
                }
-               while (strncmp(str+i, "?=", 2) != 0) {
-                       if (strncmp(str+i, "=C3=A4", 6) != 0)
+               while (!str_begins(str+i, "?=")) {
+                       if (!str_begins(str+i, "=C3=A4"))
                                return FALSE;
                        i += 6;
                        char_count++;
@@ -39,7 +39,7 @@ static bool verify_q(const char *str, unsigned int i, bool starts_with_a)
 
                if (str[i] == '\0')
                        break;
-               if (strncmp(str+i, "\n\t", 2) != 0)
+               if (!str_begins(str+i, "\n\t"))
                        return FALSE;
                i += 2;
                line_start = i - 1;
@@ -82,13 +82,13 @@ static bool verify_b(const char *str, unsigned int i, bool starts_with_a)
        buffer_t buf;
 
        buffer_create_from_data(&buf, bufdata, sizeof(bufdata));
-       if (strncmp(str+i, "\n\t", 2) == 0) {
+       if (str_begins(str+i, "\n\t")) {
                i += 2;
                line_start = i - 1;
        }
 
        for (;;) {
-               if (strncmp(str+i, "=?utf-8?b?", 10) != 0)
+               if (!str_begins(str+i, "=?utf-8?b?"))
                        return FALSE;
                i += 10;
 
@@ -126,7 +126,7 @@ static bool verify_b(const char *str, unsigned int i, bool starts_with_a)
 
                if (str[i] == '\0')
                        break;
-               if (strncmp(str+i, "\n\t", 2) != 0)
+               if (!str_begins(str+i, "\n\t"))
                        return FALSE;
                i += 2;
                line_start = i - 1;
index de0315ca680ff16f9bc52a19d0833393c4f413d6..f448332fee812b4f0bebec0bd6f8852ed742214b 100644 (file)
@@ -281,7 +281,7 @@ master_login_auth_input_fail(struct master_login_auth *auth,
                return FALSE;
        }
        for (i = 1; args[i] != NULL; i++) {
-               if (strncmp(args[i], "reason=", 7) == 0)
+               if (str_begins(args[i], "reason="))
                        error = args[i] + 7;
        }
 
@@ -329,7 +329,7 @@ static void master_login_auth_input(struct master_login_auth *auth)
                        return;
 
                /* make sure the major version matches */
-               if (strncmp(line, "VERSION\t", 8) != 0 ||
+               if (!str_begins(line, "VERSION\t") ||
                    !str_uint_equals(t_strcut(line + 8, '\t'),
                                     AUTH_MASTER_PROTOCOL_MAJOR_VERSION)) {
                        i_error("Authentication server not compatible with "
@@ -344,7 +344,7 @@ static void master_login_auth_input(struct master_login_auth *auth)
                if (line == NULL)
                        return;
 
-               if (strncmp(line, "SPID\t", 5) != 0 ||
+               if (!str_begins(line, "SPID\t") ||
                    str_to_pid(line + 5, &auth->auth_server_pid) < 0) {
                        i_error("Authentication server didn't "
                                "send valid SPID as expected: %s", line);
@@ -357,11 +357,11 @@ static void master_login_auth_input(struct master_login_auth *auth)
 
        auth->refcount++;
        while ((line = i_stream_next_line(auth->input)) != NULL) {
-               if (strncmp(line, "USER\t", 5) == 0)
+               if (str_begins(line, "USER\t"))
                        ret = master_login_auth_input_user(auth, line + 5);
-               else if (strncmp(line, "NOTFOUND\t", 9) == 0)
+               else if (str_begins(line, "NOTFOUND\t"))
                        ret = master_login_auth_input_notfound(auth, line + 9);
-               else if (strncmp(line, "FAIL\t", 5) == 0)
+               else if (str_begins(line, "FAIL\t"))
                        ret = master_login_auth_input_fail(auth, line + 5);
                else
                        ret = TRUE;
index 370bc52bdebf3c51ae07591abdc1c12807f5d5d5..15c53e0b0c61f338329ac5001d7266540604dfa6 100644 (file)
@@ -346,7 +346,7 @@ static const char *
 auth_args_find_postlogin_socket(const char *const *auth_args)
 {
        for (unsigned int i = 0; auth_args[i] != NULL; i++) {
-               if (strncmp(auth_args[i], "postlogin=", 10) == 0)
+               if (str_begins(auth_args[i], "postlogin="))
                        return auth_args[i]+10;
        }
        return NULL;
index 0e52b8dc492c10ca01a5e2f1cbc62b7e0e832315..3126f1127d65e71332ed8331aa18e430e7502407 100644 (file)
@@ -101,13 +101,13 @@ int master_service_settings_cache_init_filter(struct master_service_settings_cac
                struct config_filter *filter =
                        p_new(cache->pool, struct config_filter, 1);
                while(*keys != NULL) {
-                       if (strncmp(*keys, "local-net=", 10) == 0) {
+                       if (str_begins(*keys, "local-net=")) {
                                (void)net_parse_range((*keys)+10,
                                        &filter->local_ip, &filter->local_bits);
-                       } else if (strncmp(*keys, "remote-net=", 11) == 0) {
+                       } else if (str_begins(*keys, "remote-net=")) {
                                (void)net_parse_range((*keys)+11,
                                        &filter->remote_ip, &filter->remote_bits);
-                       } else if (strncmp(*keys, "local-name=", 11) == 0) {
+                       } else if (str_begins(*keys, "local-name=")) {
                                filter->local_name = p_strdup(cache->pool, (*keys)+11);
                        }
                        keys++;
index 6feac9d2f7d975a62a49f7759a77a48bebc0a963..14ee16197d26a18047a2183705f4522ce70c902a 100644 (file)
@@ -444,7 +444,7 @@ config_read_reply_header(struct istream *istream, const char *path, pool_t pool,
                                output_r->used_local = TRUE;
                        else if (strcmp(*arg, "used-remote") == 0)
                                output_r->used_remote = TRUE;
-                       else if (strncmp(*arg, "service=", 8) == 0) {
+                       else if (str_begins(*arg, "service=")) {
                                const char *name = p_strdup(pool, *arg + 8);
                                array_append(&services, &name, 1);
                         }
@@ -515,7 +515,7 @@ int master_service_settings_get_filters(struct master_service *service,
                while((line = i_stream_read_next_line(is)) != NULL) {
                        if (*line == '\0')
                                break;
-                       if (strncmp(line, "FILTER\t", 7) == 0) {
+                       if (str_begins(line, "FILTER\t")) {
                                line = t_strdup(line+7);
                                array_append(&filters_tmp, &line, 1);
                        }
index 7cc91427219a3bc7410c8e38ada4c7e670cc2405..225c90b936393f833c05b03648a310f928496650 100644 (file)
@@ -1248,7 +1248,7 @@ bool version_string_verify_full(const char *line, const char *service_name,
        size_t service_name_len = strlen(service_name);
        bool ret;
 
-       if (strncmp(line, "VERSION\t", 8) != 0)
+       if (!str_begins(line, "VERSION\t"))
                return FALSE;
        line += 8;
 
index 8762a67086c3a07e2394afa941bbc62bb7e5356c..5c2f30bcb5277b9b24f4e403846075e78b8f8a91 100644 (file)
@@ -614,19 +614,19 @@ int program_client_create(const char *uri, const char *const *args,
                          bool noreply, struct program_client **pc_r,
                          const char **error_r)
 {
-       if (strncmp(uri, "exec:", 5) == 0) {
+       if (str_begins(uri, "exec:") == 0) {
                *pc_r = program_client_local_create(
                        uri+5,
                        args,
                        set);
                return 0;
-       } else if (strncmp(uri, "unix:", 5) == 0) {
+       } else if (str_begins(uri, "unix:") == 0) {
                *pc_r = program_client_unix_create(
                        uri+5,
                        args,
                        set, noreply);
                return 0;
-       } else if (strncmp(uri, "tcp:", 4) == 0) {
+       } else if (str_begins(uri, "tcp:")) {
                const char *host;
                in_port_t port;
                if (net_str2hostport(uri+4, 0, &host, &port) < 0 || port == 0) {
index 1538ab64021b99470831fe73e441b861dc002353..9980e223df9b28e2d11a77ff373b5c23bd2237bb 100644 (file)
@@ -982,7 +982,7 @@ int settings_parse_stream(struct setting_parser_context *ctx,
                        return 0;
                }
                ctx->linenum++;
-               if (ctx->linenum == 1 && strncmp(line, "ERROR ", 6) == 0) {
+               if (ctx->linenum == 1 && str_begins(line, "ERROR ")) {
                        ctx->error = p_strdup(ctx->parser_pool, line + 6);
                        return -1;
                }
index 7e999062f085053be075a71a088a3dbf878ca62a..19912477ce832fc3fb807bd2c81b66ae6715a9e1 100644 (file)
@@ -2647,7 +2647,7 @@ server_connection_input(struct connection *_conn)
                        conn->state = SERVER_CONNECTION_STATE_MAIL_FROM;
                        return;
                case SERVER_CONNECTION_STATE_MAIL_FROM:
-                       if (strncmp(line, "AUTH ", 5) == 0) {
+                       if (str_begins(line, "AUTH ")) {
                                o_stream_send_str(conn->conn.output,
                                        "235 2.7.0 "
                                        "Authentication successful\r\n");
index 1e99208e23d55eb934ef2c3a4a3879b14a804ba6..86400d38afa4cff25fe1d1ee2a1b88bf4cbce3af 100644 (file)
@@ -284,7 +284,7 @@ static struct sql_db *driver_pgsql_init_v(const char *connect_string)
                const char *const *arg = t_strsplit(connect_string, " ");
 
                for (; *arg != NULL; arg++) {
-                       if (strncmp(*arg, "host=", 5) == 0)
+                       if (str_begins(*arg, "host="))
                                db->host = i_strdup(*arg + 5);
                }
        } T_END;
index 16af70933e9fb4432952d7242f9d4c667a850547..a71497d70094aaddf0c6bd05d9c10093b30cb132 100644 (file)
@@ -147,8 +147,8 @@ imapc_mail_try_merge_fetch(struct imapc_mailbox *mbox, string_t *str)
        const char *s2 = str_c(mbox->pending_fetch_cmd);
        const char *p1, *p2;
 
-       i_assert(strncmp(s1, "UID FETCH ", 10) == 0);
-       i_assert(strncmp(s2, "UID FETCH ", 10) == 0);
+       i_assert(str_begins(s1, "UID FETCH "));
+       i_assert(str_begins(s2, "UID FETCH "));
 
        /* skip over UID range */
        p1 = strchr(s1+10, ' ');
index e7b9906176985e3439dd7890a22c359a2ff1ec9b..89edf5cb4d1e1ab5a7ace8a30f341f82f4256ec6 100644 (file)
@@ -234,7 +234,7 @@ static void get_metadata_precache_fields(struct mailbox *box,
        for (i = 0; i < count; i++) {
                const char *name = fields[i].name;
 
-               if (strncmp(name, "hdr.", 4) == 0 ||
+               if (str_begins(name, "hdr.") ||
                    strcmp(name, "date.sent") == 0 ||
                    strcmp(name, "imap.envelope") == 0)
                        cache |= MAIL_FETCH_STREAM_HEADER;
index d6d364cf8f26160ee1604b1ade569a159b197915..71103cb40e6797da10ea9364804230168792fc05 100644 (file)
@@ -478,7 +478,7 @@ index_storage_mailbox_update_cache(struct mailbox *box,
                }
                if (j != old_count) {
                        field = old_fields[j];
-               } else if (strncmp(updates[i].name, "hdr.", 4) == 0) {
+               } else if (str_begins(updates[i].name, "hdr.")) {
                        /* new header */
                        i_zero(&field);
                        field.name = updates[i].name;
index eda8447666b6ad1f392d215e38de5dbc6994bd46..928d6b1044d818c2434142b24118da1a5a4014b9 100644 (file)
@@ -204,7 +204,7 @@ static int maildir_handle_uid_insertion(struct maildir_index_sync_context *ctx,
 
        i_warning("Maildir %s: Expunged message reappeared, giving a new UID "
                  "(old uid=%u, file=%s)%s", mailbox_get_path(&ctx->mbox->box),
-                 uid, filename, strncmp(filename, "msg.", 4) != 0 ? "" :
+                 uid, filename, !str_begins(filename, "msg.") ? "" :
                  " (Your MDA is saving MH files into Maildir?)");
        return 0;
 }
index 5117309df48287003642ee66d405ac3f4d709539..a6835445254ab3b4f180824860158db85ce2a58f 100644 (file)
@@ -328,7 +328,7 @@ save_header_callback(struct header_filter_istream *input ATTR_UNUSED,
                     bool *matched, struct mbox_save_context *ctx)
 {
        if (hdr != NULL) {
-               if (strncmp(hdr->name, "From ", 5) == 0) {
+               if (str_begins(hdr->name, "From ")) {
                        /* we can't allow From_-lines in headers. there's no
                           legitimate reason for allowing them in any case,
                           so just drop them. */
index 19e42f7d1a843637758a462b52dc7f562158fc3c..8e845eaa7d7c09ad66fc5c144eef573c638b10f6 100644 (file)
@@ -193,9 +193,9 @@ pop3c_mail_get_stream(struct mail *_mail, bool get_body,
 
        if (get_body && mail->data.stream != NULL) {
                name = i_stream_get_name(mail->data.stream);
-               if (strncmp(name, "RETR", 4) == 0) {
+               if (str_begins(name, "RETR")) {
                        /* we've fetched the body */
-               } else if (strncmp(name, "TOP", 3) == 0) {
+               } else if (str_begins(name, "TOP")) {
                        /* we've fetched the header, but we need the body
                           now too */
                        index_mail_close_streams(mail);
index 60c0816b3dbcfddd6c0aa926b2f1e62724c86fa2..e6a57951ca315837fa1e1561bac241a4918248b5 100644 (file)
@@ -141,7 +141,7 @@ static void pop3c_login_callback(enum pop3c_command_state state,
                mbox->logged_in = TRUE;
                break;
        case POP3C_COMMAND_STATE_ERR:
-               if (strncmp(reply, "[IN-USE] ", 9) == 0) {
+               if (str_begins(reply, "[IN-USE] ")) {
                        mail_storage_set_error(mbox->box.storage,
                                               MAIL_ERROR_INUSE, reply + 9);
                } else {
index 45c0c127ac8721d673e06e429429411dd42907c5..3f3bd94eeaa4c10d458a02829d82d3783988687e 100644 (file)
@@ -47,7 +47,7 @@ list_is_maildir_mailbox(struct mailbox_list *list, const char *dir,
                }
        }
        if (!S_ISDIR(st.st_mode)) {
-               if (strncmp(fname, ".nfs", 4) == 0) {
+               if (str_begins(fname, ".nfs")) {
                        /* temporary NFS file */
                        *flags_r |= MAILBOX_NONEXISTENT;
                } else {
@@ -186,7 +186,7 @@ int fs_list_get_mailbox_flags(struct mailbox_list *list,
        }
 
        if (!S_ISDIR(st.st_mode)) {
-               if (strncmp(fname, ".nfs", 4) == 0) {
+               if (str_begins(fname, ".nfs")) {
                        /* temporary NFS file */
                        *flags_r |= MAILBOX_NONEXISTENT;
                        return 0;
index 923101a56c32bef95822cace34e060af603a2224..28dafd7510894bd94e132414df794fd74734db5e 100644 (file)
@@ -177,7 +177,7 @@ maildir_get_type(const char *dir, const char *fname,
                *type_r = MAILBOX_LIST_FILE_TYPE_DIR;
                return TRUE;
        } else {
-               if (strncmp(fname, ".nfs", 4) == 0)
+               if (str_begins(fname, ".nfs"))
                        *flags |= MAILBOX_NONEXISTENT;
                else
                        *flags |= MAILBOX_NOSELECT;
@@ -202,7 +202,7 @@ int maildir_list_get_mailbox_flags(struct mailbox_list *list,
                /* need to check with stat() to be sure */
                if (!list->mail_set->maildir_stat_dirs && *fname != '\0' &&
                    strcmp(list->name, MAILBOX_LIST_NAME_MAILDIRPLUSPLUS) == 0 &&
-                   strncmp(fname, ".nfs", 4) != 0) {
+                   !str_begins(fname, ".nfs")) {
                        /* just assume it's a valid mailbox */
                        return 1;
                }
index 5bbeecccc582d8bb66f26d708c302a64f766953b..1ea4ec78f142cdc001e4cdecf47751e10f6fabab 100644 (file)
@@ -688,7 +688,7 @@ static bool mail_namespace_is_usable_prefix(struct mail_namespace *ns,
                return TRUE;
        }
 
-       if (inbox && strncmp(ns->prefix, "INBOX", 5) == 0 &&
+       if (inbox && str_begins(ns->prefix, "INBOX") &&
            strncmp(ns->prefix+5, mailbox+5, ns->prefix_len-5) == 0) {
                /* we already checked that mailbox begins with case-insensitive
                   INBOX. this namespace also begins with INBOX and the rest
index 5d29466ed1dfc528259e4d00bee2f757386d83ac..b64fb5f1356214857534bf2cfcc0803c201d3b10 100644 (file)
@@ -355,7 +355,7 @@ arg_modseq_set_ext(struct mail_search_build_context *ctx,
        const char *value;
 
        name = t_str_lcase(name);
-       if (strncmp(name, "/flags/", 7) != 0)
+       if (!str_begins(name, "/flags/"))
                return 0;
        name += 7;
 
index 4856c6f390bbb6bf4642370326bb11271a969c3f..1e2d31b018037c06f7870f5ff34dab827676300b 100644 (file)
@@ -118,9 +118,9 @@ mail_storage_module_hooks_cmp(const struct mail_storage_module_hooks *h1,
        p = strrchr(s2, '/');
        if (p != NULL) s2 = p+1;
 
-       if (strncmp(s1, "lib", 3) == 0)
+       if (str_begins(s1, "lib"))
                s1 += 3;
-       if (strncmp(s2, "lib", 3) == 0)
+       if (str_begins(s2, "lib"))
                s2 += 3;
 
        return strcmp(s1, s2);
index 0a27b745b90165321c1da1e97647ebc86d9a0dec..38eab63b60bfe64c7e2c7b190696a0a8010f8d4c 100644 (file)
@@ -277,12 +277,12 @@ user_reply_handle(struct mail_storage_service_ctx *ctx,
        str = array_get(&reply->extra_fields, &count);
        for (i = 0; i < count; i++) {
                line = str[i];
-               if (strncmp(line, "system_groups_user=", 19) == 0) {
+               if (str_begins(line, "system_groups_user=")) {
                        user->system_groups_user =
                                p_strdup(user->pool, line + 19);
-               } else if (strncmp(line, "chdir=", 6) == 0) {
+               } else if (str_begins(line, "chdir=")) {
                        user->chdir_path = p_strdup(user->pool, line+6);
-               } else if (strncmp(line, "nice=", 5) == 0) {
+               } else if (str_begins(line, "nice=")) {
 #ifdef HAVE_SETPRIORITY
                        int n;
                        if (str_to_int(line + 5, &n) < 0) {
@@ -293,11 +293,11 @@ user_reply_handle(struct mail_storage_service_ctx *ctx,
                                        i_error("setpriority(%d) failed: %m", n);
                        }
 #endif
-               } else if (strncmp(line, "auth_token=", 11) == 0) {
+               } else if (str_begins(line, "auth_token=")) {
                        user->auth_token = p_strdup(user->pool, line+11);
-               } else if (strncmp(line, "auth_user=", 10) == 0) {
+               } else if (str_begins(line, "auth_user=")) {
                        user->auth_user = p_strdup(user->pool, line+10);
-               } else if (strncmp(line, "admin=", 6) == 0) {
+               } else if (str_begins(line, "admin=")) {
                        user->admin = line[6] == 'y' || line[6] == 'Y' ||
                                line[6] == '1';
                } else T_BEGIN {
index 66121a8570c1691a7c94770f80c727f96316e0d3..f846556b3c65ee023b7d8ea76b2830fadc903911 100644 (file)
@@ -540,7 +540,7 @@ static bool mail_storage_settings_check(void *_set, pool_t pool,
                                set->parsed_mail_attachment_detection_add_flags_on_save = TRUE;
                        } else if (strcmp(opt, "exclude-inlined") == 0) {
                                set->parsed_mail_attachment_exclude_inlined = TRUE;
-                       } else if (strncmp(opt, "content-type=", 13) == 0) {
+                       } else if (str_begins(opt, "content-type=")) {
                                const char *value = p_strdup(pool, opt+13);
                                array_append(&content_types, &value, 1);
                        } else {
index 930d1d14afa3ea5a2e99eb5b45ffd1c0ed3b4c5d..b17ff61049b6927c560bae92fdaee0ae8be7fc9f 100644 (file)
@@ -225,7 +225,7 @@ mail_storage_get_class(struct mail_namespace *ns, const char *driver,
        if (ns->set->location == NULL || *ns->set->location == '\0') {
                *error_r = t_strdup_printf(
                        "Mail storage autodetection failed with home=%s", home);
-       } else if (strncmp(ns->set->location, "auto:", 5) == 0) {
+       } else if (str_begins(ns->set->location, "auto:")) {
                *error_r = t_strdup_printf(
                        "Autodetection failed for %s (home=%s)",
                        ns->set->location, home);
@@ -816,7 +816,7 @@ struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *vname,
        i_assert(uni_utf8_str_is_valid(vname));
 
        if (strncasecmp(vname, "INBOX", 5) == 0 &&
-           strncmp(vname, "INBOX", 5) != 0) {
+           !str_begins(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
@@ -826,7 +826,7 @@ struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *vname,
                else if (vname[5] != mail_namespace_get_sep(list->ns))
                        /* not INBOX prefix */ ;
                else if (strncasecmp(list->ns->prefix, vname, 6) == 0 &&
-                        strncmp(list->ns->prefix, "INBOX", 5) != 0) {
+                        !str_begins(list->ns->prefix, "INBOX")) {
                        mailbox_list_set_critical(list,
                                "Invalid server configuration: "
                                "Namespace prefix=%s must be uppercase INBOX",
index 45086f8a749873a345dc8344910bebc9a9525d06..e395f9077828add17b76289ad19797bd5b27a77b 100644 (file)
@@ -307,7 +307,7 @@ mailbox_list_settings_parse_full(struct mail_user *user, const char *data,
                *error_r = t_strconcat(error, "mail root dir in: ", data, NULL);
                return -1;
        }
-       if (strncmp(set_r->root_dir, "INBOX=", 6) == 0) {
+       if (str_begins(set_r->root_dir, "INBOX=")) {
                /* probably mbox user trying to avoid root_dir */
                *error_r = t_strconcat("Mail root directory not given: ",
                                       data, NULL);
index 5eb8520dbcb6c7eb2ffe5465ca149db1e5149887..73169d0e6f6172d28a22b87dd4283bcdc90ce75b 100644 (file)
@@ -104,7 +104,7 @@ static void test_mail_storage_errors(void)
        test_assert(strstr(mail_storage_get_last_error(&storage, &mail_error), MAIL_ERRSTR_CRITICAL_MSG) != NULL);
        test_assert(mail_error == MAIL_ERROR_TEMP);
        errstr = mail_storage_get_last_internal_error(&storage, &mail_error);
-       test_assert(strncmp(errstr, "critical3: ", 11) == 0);
+       test_assert(str_begins(errstr, "critical3: "));
        test_assert(strstr(errstr+11, MAIL_ERRSTR_CRITICAL_MSG) != NULL);
        test_assert(mail_error == MAIL_ERROR_TEMP);
        test_assert(storage.last_error_is_internal);
index 9ded6b4bc93e18f868f17f1dde0dec24e555d502..fcde45d5c9fbe787fd215f84773fad846eae9387 100644 (file)
@@ -170,7 +170,7 @@ iostream_rawlog_try_create_tcp(const char *path,
        int ret, fd;
 
        /* tcp:host:port */
-       if (strncmp(path, "tcp:", 4) != 0)
+       if (!str_begins(path, "tcp:"))
                return 0;
        path += 4;
 
index d55340c5f02e3b5bab2ce4befaa0ebf755294184..e26025971c3a9760df508fd59e97de31e14ea1b4 100644 (file)
@@ -279,9 +279,9 @@ static int module_name_cmp(const char *const *n1, const char *const *n2)
 {
        const char *s1 = *n1, *s2 = *n2;
 
-       if (strncmp(s1, "lib", 3) == 0)
+       if (str_begins(s1, "lib"))
                s1 += 3;
-       if (strncmp(s2, "lib", 3) == 0)
+       if (str_begins(s2, "lib"))
                s2 += 3;
 
        return strcmp(s1, s2);
@@ -662,7 +662,7 @@ const char *module_file_get_name(const char *fname)
        const char *p;
 
        /* [lib][nn_]name(.so) */
-       if (strncmp(fname, "lib", 3) == 0)
+       if (str_begins(fname, "lib"))
                fname += 3;
 
        for (p = fname; *p != '\0'; p++) {
index c2642e857668ccd4765b2957e283a36cd8947d9e..d3c9716887b6beb3397becd50561c01f46b165b6 100644 (file)
@@ -56,7 +56,7 @@ static void test_str_sanitize_max_bytes(void)
                str_append(str2, "1234567890");
                str_sanitize_append(str2, tests[i].str, tests[i].max_len);
 
-               test_assert_idx(strncmp(str_c(str2), "1234567890", 10) == 0, i);
+               test_assert_idx(str_begins(str_c(str2), "1234567890"), i);
                if (tests[i].sanitized != NULL)
                        test_assert_idx(strcmp(str_c(str2)+10, tests[i].sanitized) == 0, i);
                else
index 8c4f015f69aca8bd7af02f6fe4d46b39ef047118..98fddd1ab6e2fab02491e11ded16e2da530f18a0 100644 (file)
@@ -201,7 +201,7 @@ unlink_directory_r(const char *dir, enum unlink_directory_flags flags,
                                   (flags & UNLINK_DIRECTORY_FLAG_FILES_ONLY) != 0) {
                                /* skip directory */
                        } else if (old_errno == EBUSY &&
-                                  strncmp(d->d_name, ".nfs", 4) == 0) {
+                                  str_begins(d->d_name, ".nfs")) {
                                /* can't delete NFS files that are still
                                   in use. let the caller decide if this error
                                   is worth logging about */
index e117c2b184225ab31390467b38d3eeabc9388991..f9866f272473bf53359c0f4479a8555380a87bbc 100644 (file)
@@ -110,9 +110,9 @@ static void log_parse_option(struct log_connection *log,
        struct log_client *client;
 
        client = log_client_get(log, failure->pid);
-       if (strncmp(failure->text, "ip=", 3) == 0)
+       if (str_begins(failure->text, "ip="))
                (void)net_addr2ip(failure->text + 3, &client->ip);
-       else if (strncmp(failure->text, "prefix=", 7) == 0) {
+       else if (str_begins(failure->text, "prefix=")) {
                i_free(client->prefix);
                client->prefix = i_strdup(failure->text + 7);
        }
@@ -219,9 +219,9 @@ log_parse_master_line(const char *line, const struct timeval *log_time,
                        return;
                }
                log_client_free(log, client, pid);
-       } else if (strncmp(cmd, "FATAL ", 6) == 0) {
+       } else if (str_begins(cmd, "FATAL ")) {
                client_log_fatal(log, client, cmd + 6, log_time, tm);
-       } else if (strncmp(cmd, "DEFAULT-FATAL ", 14) == 0) {
+       } else if (str_begins(cmd, "DEFAULT-FATAL ")) {
                /* If the client has logged a fatal/panic, don't log this
                   message. */
                if (client == NULL || !client->fatal_logged)
index 76cd407a2673a86d1feca2a5c028e3f4e157346d..071ee11022d7dbeaee288c96f4c5dc70411440e0 100644 (file)
@@ -209,12 +209,12 @@ static void client_auth_parse_args(struct client *client, bool success,
                } else if (strcmp(key, "user") == 0 ||
                           strcmp(key, "postlogin_socket") == 0) {
                        /* already handled in sasl-server.c */
-               } else if (strncmp(key, "user_", 5) == 0) {
+               } else if (str_begins(key, "user_")) {
                        if (success) {
                                alt_username_set(&alt_usernames, client->pool,
                                                 key, value);
                        }
-               } else if (strncmp(key, "forward_", 8) == 0) {
+               } else if (str_begins(key, "forward_")) {
                        /* these are passed to upstream */
                } else if (client->set->auth_debug)
                        i_debug("Ignoring unknown passdb extra field: %s", key);
index c8c2f5107eb633c19be4cb3a77323d4f5ab9b18b..dedfb5b8f9278fa2c699bbbd7c1f5adde970797b 100644 (file)
@@ -269,26 +269,26 @@ authenticate_callback(struct auth_client_request *request,
 
                nologin = FALSE;
                for (i = 0; args[i] != NULL; i++) {
-                       if (strncmp(args[i], "user=", 5) == 0) {
+                       if (str_begins(args[i], "user=")) {
                                i_free(client->virtual_user);
                                i_free_and_null(client->virtual_user_orig);
                                i_free_and_null(client->virtual_auth_user);
                                client->virtual_user = i_strdup(args[i] + 5);
-                       } else if (strncmp(args[i], "original_user=", 14) == 0) {
+                       } else if (str_begins(args[i], "original_user=")) {
                                i_free(client->virtual_user_orig);
                                client->virtual_user_orig = i_strdup(args[i] + 14);
-                       } else if (strncmp(args[i], "auth_user=", 10) == 0) {
+                       } else if (str_begins(args[i], "auth_user=")) {
                                i_free(client->virtual_auth_user);
                                client->virtual_auth_user =
                                        i_strdup(args[i] + 10);
-                       } else if (strncmp(args[i], "postlogin_socket=", 17) == 0) {
+                       } else if (str_begins(args[i], "postlogin_socket=")) {
                                client->postlogin_socket_path =
                                        p_strdup(client->pool, args[i] + 17);
                        } else if (strcmp(args[i], "nologin") == 0 ||
                                   strcmp(args[i], "proxy") == 0) {
                                /* user can't login */
                                nologin = TRUE;
-                       } else if (strncmp(args[i], "resp=", 5) == 0 &&
+                       } else if (str_begins(args[i], "resp=") &&
                                   login_binary->sasl_support_final_reply) {
                                client->sasl_final_resp =
                                        p_strdup(client->pool, args[i] + 5);
@@ -313,17 +313,17 @@ authenticate_callback(struct auth_client_request *request,
                if (args != NULL) {
                        /* parse our username if it's there */
                        for (i = 0; args[i] != NULL; i++) {
-                               if (strncmp(args[i], "user=", 5) == 0) {
+                               if (str_begins(args[i], "user=")) {
                                        i_free(client->virtual_user);
                                        i_free_and_null(client->virtual_user_orig);
                                        i_free_and_null(client->virtual_auth_user);
                                        client->virtual_user =
                                                i_strdup(args[i] + 5);
-                               } else if (strncmp(args[i], "original_user=", 14) == 0) {
+                               } else if (str_begins(args[i], "original_user=")) {
                                        i_free(client->virtual_user_orig);
                                        client->virtual_user_orig =
                                                i_strdup(args[i] + 14);
-                               } else if (strncmp(args[i], "auth_user=", 10) == 0) {
+                               } else if (str_begins(args[i], "auth_user=")) {
                                        i_free(client->virtual_auth_user);
                                        client->virtual_auth_user =
                                                i_strdup(args[i] + 10);
index a29926fdf8cda6123257cb995a8a4dfe5df5baa5..4c04c7efacf4da54413eb6faa9f2e291f615aa27 100644 (file)
@@ -755,7 +755,7 @@ int main(int argc, char *argv[])
        /* drop -- prefix from all --args. ugly, but the only way that it
           works with standard getopt() in all OSes.. */
        for (i = 1; i < argc; i++) {
-               if (strncmp(argv[i], "--", 2) == 0) {
+               if (str_begins(argv[i], "--")) {
                        if (argv[i][2] == '\0')
                                break;
                        argv[i] += 2;
index e8478ec97180476ee7027f9d59769267cd771d09..e020d134faf9401a64f1206c2f3cd11c99583a3a 100644 (file)
@@ -72,19 +72,19 @@ mail_export_parse_filter(const char *const *args, pool_t pool,
        */
        i_zero(filter_r);
        for (; *args != NULL; args++) {
-               if (strncmp(*args, "user=", 5) == 0)
+               if (str_begins(*args, "user="))
                        filter_r->user = p_strdup(pool, *args + 5);
-               else if (strncmp(*args, "domain=", 7) == 0)
+               else if (str_begins(*args, "domain="))
                        filter_r->domain = p_strdup(pool, *args + 7);
-               else if (strncmp(*args, "session=", 8) == 0)
+               else if (str_begins(*args, "session="))
                        filter_r->session = p_strdup(pool, *args + 8);
-               else if (strncmp(*args, "ip=", 3) == 0) {
+               else if (str_begins(*args, "ip=")) {
                        if (net_parse_range(*args + 3, &filter_r->ip,
                                            &filter_r->ip_bits) < 0) {
                                *error_r = "Invalid ip filter";
                                return -1;
                        }
-               } else if (strncmp(*args, "since=", 6) == 0) {
+               } else if (str_begins(*args, "since=")) {
                        if (str_to_ulong(*args + 6, &l) < 0) {
                                *error_r = "Invalid since filter";
                                return -1;
index 86f0944c3813312f41efd948e85d443f3052cc38..db202b305a6a0887113384f9d96773ec3c314da3 100644 (file)
@@ -112,7 +112,7 @@ int mail_session_connect_parse(const char *const *args, const char **error_r)
        mail_domain_login(session->user->domain);
 
        for (i = 3; args[i] != NULL; i++) {
-               if (strncmp(args[i], "rip=", 4) == 0 &&
+               if (str_begins(args[i], "rip=") &&
                    net_addr2ip(args[i] + 4, &ip) == 0)
                        session->ip = mail_ip_login(&ip);
        }
index aeb4961cb2d9e364207cb3ef008e98ecfac5060a..c1fe2b6078c67810686af225978304f4ab4e08d4 100644 (file)
@@ -43,7 +43,7 @@ acl_backend_vfile_init(struct acl_backend *_backend, const char *data)
        if (*tmp != NULL)
                tmp++;
        for (; *tmp != NULL; tmp++) {
-               if (strncmp(*tmp, "cache_secs=", 11) == 0) {
+               if (str_begins(*tmp, "cache_secs=")) {
                        if (str_to_uint(*tmp + 11, &backend->cache_secs) < 0) {
                                i_error("acl vfile: Invalid cache_secs value: %s",
                                        *tmp + 11);
index a07d79791901bc706a3316828e99a1e57004ea6f..026aef59c5df7307b5ef289a2bab51a1a438ecf6 100644 (file)
@@ -48,7 +48,7 @@ acl_backend_init(const char *data, struct mailbox_list *list,
 
        group_count = str_array_length(groups);
 
-       if (strncmp(data, "vfile:", 6) == 0)
+       if (str_begins(data, "vfile:"))
                data += 6;
        else if (strcmp(data, "vfile") == 0)
                data = "";
index 5540cfa582fa9e2cb6da5addb3cea5e617a4cd87..ff8445783c8a4ab7d554fdf34a8a4d2f342e31be 100644 (file)
@@ -48,7 +48,7 @@ fs_compress_init(struct fs *_fs, const char *args, const
        const char *parent_name, *parent_args;
 
        /* get compression handler name */
-       if (strncmp(args, "maybe-", 6) == 0) {
+       if (str_begins(args, "maybe-")) {
                fs->try_plain = TRUE;
                args += 6;
        }
index d00c674cf8184d182231b54a9b16ead5c2ab86d9..9a8647f95eac163703515854ec776e98b9a77e75 100644 (file)
@@ -20,14 +20,14 @@ fts_lucene_plugin_init_settings(struct mail_user *user,
        const char *const *tmp;
 
        for (tmp = t_strsplit_spaces(str, " "); *tmp != NULL; tmp++) {
-               if (strncmp(*tmp, "default_language=", 17) == 0) {
+               if (str_begins(*tmp, "default_language=")) {
                        set->default_language =
                                p_strdup(user->pool, *tmp + 17);
-               } else if (strncmp(*tmp, "textcat_conf=", 13) == 0) {
+               } else if (str_begins(*tmp, "textcat_conf=")) {
                        set->textcat_conf = p_strdup(user->pool, *tmp + 13);
-               } else if (strncmp(*tmp, "textcat_dir=", 12) == 0) {
+               } else if (str_begins(*tmp, "textcat_dir=")) {
                        set->textcat_dir = p_strdup(user->pool, *tmp + 12);
-               } else if (strncmp(*tmp, "whitespace_chars=", 17) == 0) {
+               } else if (str_begins(*tmp, "whitespace_chars=")) {
                        set->whitespace_chars = p_strdup(user->pool, *tmp + 17);
                } else if (strcmp(*tmp, "normalize") == 0) {
                        set->normalize = TRUE;
index 16f6af005fd95c781c4db94399637b75d7bdf992..19b89b1906504b32e5317339cff99a74f3fe20bd 100644 (file)
@@ -26,7 +26,7 @@ fts_solr_plugin_init_settings(struct mail_user *user,
                str = "";
 
        for (tmp = t_strsplit_spaces(str, " "); *tmp != NULL; tmp++) {
-               if (strncmp(*tmp, "url=", 4) == 0) {
+               if (str_begins(*tmp, "url=")) {
                        set->url = p_strdup(user->pool, *tmp + 4);
                } else if (strcmp(*tmp, "debug") == 0) {
                        set->debug = TRUE;
index 19f09fccec9a316e8f549e611626dceaae4b519f..cd82400ef219be8ff048f66e2e6177f3b18badf1 100644 (file)
@@ -57,14 +57,14 @@ fts_backend_squat_init(struct fts_backend *_backend, const char **error_r)
                return 0;
 
        for (tmp = t_strsplit_spaces(env, " "); *tmp != NULL; tmp++) {
-               if (strncmp(*tmp, "partial=", 8) == 0) {
+               if (str_begins(*tmp, "partial=")) {
                        if (str_to_uint(*tmp + 8, &len) < 0 || len == 0) {
                                *error_r = t_strdup_printf(
                                        "Invalid partial length: %s", *tmp + 8);
                                return -1;
                        }
                        backend->partial_len = len;
-               } else if (strncmp(*tmp, "full=", 5) == 0) {
+               } else if (str_begins(*tmp, "full=")) {
                        if (str_to_uint(*tmp + 5, &len) < 0 || len == 0) {
                                *error_r = t_strdup_printf(
                                        "Invalid full length: %s", *tmp + 5);
index f7f23c4a16352a46b3939de5437ee782a00d54e4..e2c5a9c3551a5a38f137f706d43e7b8fae8491ca 100644 (file)
@@ -78,7 +78,7 @@ int main(int argc ATTR_UNUSED, char *argv[])
                        fflush(stderr);
                        last = input->v_offset/(1024*100);
                }
-               if (strncmp(line, "From ", 5) == 0) {
+               if (str_begins(line, "From ")) {
                        if (!first)
                                seq++;
                        data_header = TRUE;
@@ -88,7 +88,7 @@ int main(int argc ATTR_UNUSED, char *argv[])
                }
                first = FALSE;
 
-               if (strncmp(line, "--", 2) == 0) {
+               if (str_begins(line, "--")) {
                        skip_body = FALSE;
                        mime_header = TRUE;
                }
index 0d2518b88b1bb2df422046295c2f6d7a1f01bed2..3125f6c2e5604a23da8f0c9a17d4b05f0fb6cad4 100644 (file)
@@ -230,7 +230,7 @@ fts_build_body_begin(struct fts_mail_build_context *ctx,
        i_zero(&parser_context);
        parser_context.content_type = ctx->content_type != NULL ?
                ctx->content_type : "text/plain";
-       if (strncmp(parser_context.content_type, "multipart/", 10) == 0) {
+       if (str_begins(parser_context.content_type, "multipart/")) {
                /* multiparts are never indexed, only their contents */
                return FALSE;
        }
@@ -243,8 +243,8 @@ fts_build_body_begin(struct fts_mail_build_context *ctx,
                /* extract text using the the returned parser */
                *binary_body_r = TRUE;
                key.type = FTS_BACKEND_BUILD_KEY_BODY_PART;
-       } else if (strncmp(parser_context.content_type, "text/", 5) == 0 ||
-                  strncmp(parser_context.content_type, "message/", 8) == 0) {
+       } else if (str_begins(parser_context.content_type, "text/") ||
+                  str_begins(parser_context.content_type, "message/")) {
                /* text body parts */
                key.type = FTS_BACKEND_BUILD_KEY_BODY_PART;
                ctx->body_parser = fts_parser_text_init();
index bda0551037db86051865d19fe10864236dd23006..0fd7a8f260dec823d6e0c3e55c1734c2e04e0ee3 100644 (file)
@@ -169,7 +169,7 @@ static int fts_indexer_input(struct fts_indexer_context *ctx)
        while ((line = i_stream_read_next_line(ctx->input)) != NULL) {
                /* initial reply: <tag> \t OK
                   following: <tag> \t <percentage> */
-               if (strncmp(line, "1\t", 2) != 0) {
+               if (!str_begins(line, "1\t")) {
                        i_error("indexer sent invalid reply: %s", line);
                        return -1;
                }
index c8fc244dcf8e5b49eefea9cb19d6bf40b5cd5291..64771902994c5ccaf2673b98a47696f65eae37b0 100644 (file)
@@ -19,16 +19,16 @@ process_io_buffer_parse(const char *buf, struct mail_stats *stats)
 
        tmp = t_strsplit(buf, "\n");
        for (; *tmp != NULL; tmp++) {
-               if (strncmp(*tmp, "rchar: ", 7) == 0) {
+               if (str_begins(*tmp, "rchar: ")) {
                        if (str_to_uint64(*tmp + 7, &stats->read_bytes) < 0)
                                return -1;
-               } else if (strncmp(*tmp, "wchar: ", 7) == 0) {
+               } else if (str_begins(*tmp, "wchar: ")) {
                        if (str_to_uint64(*tmp + 7, &stats->write_bytes) < 0)
                                return -1;
-               } else if (strncmp(*tmp, "syscr: ", 7) == 0) {
+               } else if (str_begins(*tmp, "syscr: ")) {
                        if (str_to_uint32(*tmp + 7, &stats->read_count) < 0)
                                return -1;
-               } else if (strncmp(*tmp, "syscw: ", 7) == 0) {
+               } else if (str_begins(*tmp, "syscw: ")) {
                        if (str_to_uint32(*tmp + 7, &stats->write_count) < 0)
                                return -1;
                }
index 0b58c1764503e61a3e85ee093fd1fa92199ddabf..330272381b889643847e6a8c18ffb2f484703d96 100644 (file)
@@ -163,7 +163,7 @@ static int client_input_line(struct connection *conn, const char *line)
                return 1;
        }
        if (client->recipient == NULL &&
-           strncmp(line, "recipient=", 10) == 0) {
+           str_begins(line, "recipient=")) {
                if (smtp_address_parse_path(default_pool, line + 10,
                        SMTP_ADDRESS_PARSE_FLAG_ALLOW_LOCALPART |
                        SMTP_ADDRESS_PARSE_FLAG_BRACKETS_OPTIONAL,
@@ -173,7 +173,7 @@ static int client_input_line(struct connection *conn, const char *line)
                                error);
                        return 0;
                }
-       } else if (strncmp(line, "size=", 5) == 0) {
+       } else if (str_begins(line, "size=")) {
                if (str_to_uoff(line+5, &client->size) < 0)
                        client->size = 0;
        }
index 95c49695d7288dcd235d0c4325c0216f12acd5f8..224916d5a0aa87bb0f84f3d8bdca6c8f1306b260 100644 (file)
@@ -262,7 +262,7 @@ int quota_root_add_rule(struct quota_root_settings *root_set,
                return 0;
        }
 
-       if (strncmp(p, "backend=", 8) == 0) {
+       if (str_begins(p, "backend=")) {
                if (root_set->backend->v.parse_rule == NULL) {
                        *error_r = "backend rule not supported";
                        ret = -1;
index 4d2ef1755602a4be0cef89e8492390dc45c3306b..7fbdc1be93b4d3660b27542183f9fa297e46f725 100644 (file)
@@ -184,7 +184,7 @@ quota_root_parse_set(struct mail_user *user, const char *root_name,
        if (value == NULL)
                return 0;
 
-       if (strncmp(value, "dict:", 5) != 0) {
+       if (!str_begins(value, "dict:")) {
                *error_r = t_strdup_printf("%s supports only dict backend", name);
                return -1;
        }
index 5554097da3646503c2cdfceca16ea0230a4735f5..817d40145a6237db931cf1d824d29c58ff7a8e5b 100644 (file)
@@ -154,7 +154,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
        switch (pop3_client->proxy_state) {
        case POP3_PROXY_BANNER:
                /* this is a banner */
-               if (strncmp(line, "+OK", 3) != 0) {
+               if (!str_begins(line, "+OK")) {
                        client_log_err(client, t_strdup_printf(
                                "proxy: Remote returned invalid banner: %s",
                                str_sanitize(line, 160)));
@@ -162,7 +162,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
                        return -1;
                }
                pop3_client->proxy_xclient =
-                       strncmp(line+3, " [XCLIENT]", 10) == 0;
+                       str_begins(line+3, " [XCLIENT]");
 
                ssl_flags = login_proxy_get_ssl_flags(client->login_proxy);
                if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) == 0) {
@@ -176,7 +176,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
                }
                return 0;
        case POP3_PROXY_STARTTLS:
-               if (strncmp(line, "+OK", 3) != 0) {
+               if (!str_begins(line, "+OK")) {
                        client_log_err(client, t_strdup_printf(
                                "proxy: Remote STLS failed: %s",
                                str_sanitize(line, 160)));
@@ -195,7 +195,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
                }
                return 1;
        case POP3_PROXY_XCLIENT:
-               if (strncmp(line, "+OK", 3) != 0) {
+               if (!str_begins(line, "+OK")) {
                        client_log_err(client, t_strdup_printf(
                                "proxy: Remote XCLIENT failed: %s",
                                str_sanitize(line, 160)));
@@ -207,7 +207,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
                return 0;
        case POP3_PROXY_LOGIN1:
                i_assert(client->proxy_sasl_client == NULL);
-               if (strncmp(line, "+OK", 3) != 0)
+               if (!str_begins(line, "+OK"))
                        break;
 
                /* USER successful, send PASS */
@@ -217,7 +217,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
                pop3_client->proxy_state = POP3_PROXY_LOGIN2;
                return 0;
        case POP3_PROXY_LOGIN2:
-               if (strncmp(line, "+ ", 2) == 0 &&
+               if (str_begins(line, "+ ") &&
                    client->proxy_sasl_client != NULL) {
                        /* continue SASL authentication */
                        if (pop3_proxy_continue_sasl_auth(client, output,
@@ -227,7 +227,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
                        }
                        return 0;
                }
-               if (strncmp(line, "+OK", 3) != 0)
+               if (!str_begins(line, "+OK"))
                        break;
 
                /* Login successful. Send this line to client. */
@@ -255,7 +255,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
           So for now we'll just forward the error message. This
           shouldn't be a real problem since of course everyone will
           be using only Dovecot as their backend :) */
-       if (strncmp(line, "-ERR ", 5) != 0) {
+       if (!str_begins(line, "-ERR ")) {
                client_send_reply(client, POP3_CMD_REPLY_ERROR,
                                  AUTH_FAILED_MSG);
        } else {
@@ -263,7 +263,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
        }
 
        if (client->set->auth_verbose) {
-               if (strncmp(line, "-ERR ", 5) == 0)
+               if (str_begins(line, "-ERR "))
                        line += 5;
                client_proxy_log_failure(client, line);
        }
index 5f88cc9075cab77a00b921d294264fa073ae5edb..ee16dbd13340f9d032bb5c81357c7333c6129dfc 100644 (file)
@@ -156,14 +156,14 @@ static bool client_exec_script(struct master_service_connection *conn)
        if (*args != NULL) {
                const char *p;
 
-               if (strncmp(*args, "alarm=", 6) == 0) {
+               if (str_begins(*args, "alarm=")) {
                        unsigned int seconds;
                        if (str_to_uint(*args + 6, &seconds) < 0)
                                i_fatal("invalid alarm option");
                        alarm(seconds);
                        args++;
                }
-               while (strncmp(*args, "env_", 4) == 0) {
+               while (str_begins(*args, "env_")) {
                        const char *envname, *env;
 
                        env = t_str_tabunescape(*args+4);