for (i = 0; i < cfg_size (cfg, "realm"); i++)
{
- struct rs_realm *r = rs_calloc (ctx, 1, sizeof(*r));
+ struct rs_realm *r = NULL;
const char *typestr;
- if (!r)
+ r = rs_calloc (ctx, 1, sizeof(*r));
+ if (r == NULL)
return rs_err_ctx_push_fl (ctx, RSE_NOMEM, __FILE__, __LINE__, NULL);
- if (config->realms)
+ if (config->realms != NULL)
{
r->next = config->realms->next;
config->realms->next = r;
}
else
+ {
config->realms = r;
+ }
cfg_realm = cfg_getnsec (cfg, "realm", i);
- /* We use a copy of return value of cfg_title since it's a
- const. */
+ /* We use a copy of the return value of cfg_title() since it's const. */
s = cfg_title (cfg_realm);
if (s == NULL)
return rs_err_ctx_push_fl (ctx, RSE_CONFIG, __FILE__, __LINE__,
"missing realm name");
- r->name = strdup (s); /* FIXME: Don't strdup. */
- if (!r->name)
+ r->name = strdup (s);
+ if (r->name == NULL)
return rs_err_ctx_push_fl (ctx, RSE_NOMEM, __FILE__, __LINE__, NULL);
typestr = cfg_getstr (cfg_realm, "type");
- if (!strcmp (typestr, "UDP"))
+ if (strcmp (typestr, "UDP") == 0)
r->type = RS_CONN_TYPE_UDP;
- else if (!strcmp (typestr, "TCP"))
+ else if (strcmp (typestr, "TCP") == 0)
r->type = RS_CONN_TYPE_TCP;
- else if (!strcmp (typestr, "TLS"))
+ else if (strcmp (typestr, "TLS") == 0)
r->type = RS_CONN_TYPE_TLS;
- else if (!strcmp (typestr, "DTLS"))
+ else if (strcmp (typestr, "DTLS") == 0)
r->type = RS_CONN_TYPE_DTLS;
else
return rs_err_ctx_push_fl (ctx, RSE_CONFIG, __FILE__, __LINE__,
for (j = 0; j < cfg_size (cfg_realm, "server"); j++)
{
struct rs_peer *p = peer_create (ctx, &r->peers);
- if (!p)
+ if (p == NULL)
return rs_err_ctx_push_fl (ctx, RSE_NOMEM, __FILE__, __LINE__,
NULL);
p->realm = r;
}
}
- /* Save config object in context, for freeing in
- rs_context_destroy(). */
- ctx->config->cfg = cfg;
+ /* Save config object in context, for freeing in rs_context_destroy(). */
+ ctx->config->cfg = cfg;
+
return RSE_OK;
}
struct rs_realm *r;
for (r = ctx->config->realms; r; r = r->next)
- if (!strcmp (r->name, name))
+ if (strcmp (r->name, name) == 0)
return r;
+
return NULL;
}