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>
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));
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));
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);
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 "
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;
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;
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 "
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);
}
} 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)
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;
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);
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);
}
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;
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;
}
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;
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)) {
}
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)) {
{
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,
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;
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);
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,
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,
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;
"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);
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) {
} 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",
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) {
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";
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) {
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;
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');
{
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;
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);
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;
"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 */
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;
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) {
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: "
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) ?
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);
}
if (ctx->old->auth_section == 1) {
- if (strncmp(key, "auth_", 5) != 0)
+ if (!str_begins(key, "auth_"))
key = t_strconcat("auth_", key, NULL);
}
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)
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);
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);
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;
}
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.. */
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) {
/* 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;
}
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 {
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 {
{
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;
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;
}
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 = {
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 */
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;
{
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) {
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;
}
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");
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;
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 &&
continue;
line++;
- if (strncmp(line, "OK Begin compression", 20) == 0 ||
+ if (str_begins(line, "OK Begin compression") ||
strcasecmp(line, "COMPRESS DEFLATE") == 0)
break;
}
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)) {
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;
}
}
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)));
}
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;
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",
}
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;
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;
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));
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);
} 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;
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;
}
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,
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;
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;
/* 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,
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;
}
/* 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;
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;
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 "
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)
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";
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);
/* 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);
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);
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;
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);
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);
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) {
}
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 {
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;
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) {
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);
/* 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);
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;
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] != ']')
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);
{
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;
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++;
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;
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;
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;
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;
}
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 "
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);
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;
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;
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++;
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);
}
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);
}
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;
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) {
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;
}
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");
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;
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, ' ');
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;
}
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;
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;
}
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. */
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);
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 {
}
}
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 {
}
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;
*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;
/* 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;
}
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
const char *value;
name = t_str_lcase(name);
- if (strncmp(name, "/flags/", 7) != 0)
+ if (!str_begins(name, "/flags/"))
return 0;
name += 7;
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);
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) {
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 {
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 {
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);
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
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",
*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);
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);
int ret, fd;
/* tcp:host:port */
- if (strncmp(path, "tcp:", 4) != 0)
+ if (!str_begins(path, "tcp:"))
return 0;
path += 4;
{
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);
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++) {
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
(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 */
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);
}
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)
} 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);
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);
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);
/* 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;
*/
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;
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);
}
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);
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 = "";
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;
}
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;
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;
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);
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;
}
first = FALSE;
- if (strncmp(line, "--", 2) == 0) {
+ if (str_begins(line, "--")) {
skip_body = FALSE;
mime_header = TRUE;
}
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;
}
/* 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();
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;
}
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;
}
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,
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;
}
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;
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;
}
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)));
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) {
}
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)));
}
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)));
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 */
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,
}
return 0;
}
- if (strncmp(line, "+OK", 3) != 0)
+ if (!str_begins(line, "+OK"))
break;
/* Login successful. Send this line to client. */
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 {
}
if (client->set->auth_verbose) {
- if (strncmp(line, "-ERR ", 5) == 0)
+ if (str_begins(line, "-ERR "))
line += 5;
client_proxy_log_failure(client, line);
}
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);