Be explicit with checks

pull/1/head
Michael Santos 9 years ago
parent d0792db2f8
commit fc09ca4ff1

@ -168,7 +168,7 @@ main(int argc, char **argv)
}
}
if (!jid)
if (jid == NULL)
usage(state);
if (state->bufsz < 3 || state->bufsz >= 0xffff
@ -180,10 +180,10 @@ main(int argc, char **argv)
state->server = xmppipe_servername(jid);
if (!state->room)
if (state->room == NULL)
state->room = xmppipe_roomname("stdout");
if (!state->resource)
if (state->resource == NULL)
state->resource = xmppipe_strdup("xmppipe");
if (strchr(state->room, '@')) {
@ -199,11 +199,11 @@ main(int argc, char **argv)
log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG);
state->ctx = xmpp_ctx_new(NULL, (state->verbose > 1 ? log : NULL));
if (!state->ctx)
if (state->ctx == NULL)
errx(EXIT_FAILURE, "could not allocate context");
state->conn = xmpp_conn_new(state->ctx);
if (!state->conn)
if (state->conn == NULL)
errx(EXIT_FAILURE, "could not allocate connection");
xmpp_conn_set_jid(state->conn, jid);
@ -303,7 +303,7 @@ xmppipe_muc_init(xmppipe_state_t *state)
xmpp_id_handler_add(state->conn, handle_ping_reply, "c2s1", state);
/* Discover the MUC service */
if (!state->out) {
if (state->out == NULL) {
xmpp_handler_add(state->conn, handle_disco_items,
"http://jabber.org/protocol/disco#items", "iq", "result",
state);
@ -525,7 +525,7 @@ handle_null(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
char *name = NULL;
name = xmpp_stanza_get_name(stanza);
if (!name)
if (name == NULL)
return 1;
if (XMPPIPE_STREQ(name, "iq")
@ -581,7 +581,7 @@ handle_sm_ack(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
h = xmpp_stanza_get_attribute(stanza, "h");
if (!h)
if (h == NULL)
return 1;
ack = (u_int32_t)atoi(h); /* XXX */
@ -626,7 +626,7 @@ handle_disco_items(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
query = xmpp_stanza_get_child_by_name(stanza, "query");
if (!query)
if (query == NULL)
return 1;
for (item = xmpp_stanza_get_children(query); item != NULL;
@ -636,14 +636,14 @@ handle_disco_items(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
char *name = NULL;
name = xmpp_stanza_get_name(item);
if (!name)
if (name == NULL)
continue;
if (XMPPIPE_STRNEQ(name, "item"))
continue;
jid = xmpp_stanza_get_attribute(item, "jid");
if (!jid)
if (jid == NULL)
continue;
iq = xmppipe_stanza_new(ctx);
@ -674,12 +674,12 @@ handle_disco_info(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
from = xmpp_stanza_get_attribute(stanza, "from");
if (!from)
if (from == NULL)
return 1;
query = xmpp_stanza_get_child_by_name(stanza, "query");
if (!query)
if (query == NULL)
return 1;
for (child = xmpp_stanza_get_children(query); child != NULL;
@ -688,14 +688,14 @@ handle_disco_info(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
char *var = NULL;
feature = xmpp_stanza_get_name(child);
if (!feature)
if (feature == NULL)
continue;
if (XMPPIPE_STRNEQ(feature, "feature"))
continue;
var = xmpp_stanza_get_attribute(child, "var");
if (!var)
if (var == NULL)
continue;
if (XMPPIPE_STRNEQ(var, "http://jabber.org/protocol/muc"))
@ -737,13 +737,13 @@ handle_version(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
xmppipe_stanza_set_type(reply, "result");
id = xmpp_stanza_get_attribute(stanza, "from");
if (!id)
if (id == NULL)
return 1;
xmppipe_stanza_set_id(reply, id);
from = xmpp_stanza_get_attribute(stanza, "from");
if (!from)
if (from == NULL)
return 1;
xmppipe_stanza_set_attribute(reply, "to", from);
@ -752,7 +752,7 @@ handle_version(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
xmppipe_stanza_set_name(query, "query");
child = xmpp_stanza_get_children(stanza);
if (!child) {
if (child == NULL) {
(void)xmpp_stanza_release(query);
return 1;
}
@ -807,7 +807,7 @@ handle_presence(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
from = xmpp_stanza_get_attribute(stanza, "from");
to = xmpp_stanza_get_attribute(stanza, "to");
if (!from || !to)
if (from == NULL || to == NULL)
return 1;
x = xmpp_stanza_get_child_by_name(stanza, "x");
@ -836,10 +836,10 @@ handle_presence(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
type = xmpp_stanza_get_attribute(stanza, "type");
if (!type)
if (type == NULL)
type = "available";
if (!me && XMPPIPE_STREQ(type, "available")) {
if (me != 0 && XMPPIPE_STREQ(type, "available")) {
state->occupants++;
}
else if (XMPPIPE_STREQ(type, "unavailable") && (state->occupants > 0)) {
@ -882,7 +882,7 @@ handle_presence_error(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
from = xmpp_stanza_get_attribute(stanza, "from");
to = xmpp_stanza_get_attribute(stanza, "to");
if (!from || !to)
if (from == NULL || to == NULL)
return 1;
/* Check error is to our JID (user@example.org/binding) */
@ -894,7 +894,7 @@ handle_presence_error(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
return 1;
error = xmpp_stanza_get_child_by_name(stanza, "error");
if (!error)
if (error == NULL)
return 1;
code = xmpp_stanza_get_attribute(error, "code");
@ -928,30 +928,27 @@ handle_message(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
return 1;
from = xmpp_stanza_get_attribute(stanza, "from");
if (!from)
if (from == NULL)
return 1;
to = xmpp_stanza_get_attribute(stanza, "to");
if (!to)
if (to == NULL)
return 1;
type = xmpp_stanza_get_type(stanza);
if (!type)
if (type == NULL)
return 1;
/* Check if the message is from us */
if (XMPPIPE_STREQ(type, "groupchat") && XMPPIPE_STREQ(from, state->mucjid))
return 1;
if (!xmpp_stanza_get_child_by_name(stanza, "body"))
return 1;
child = xmpp_stanza_get_child_by_name(stanza, "body");
if (!child)
if (child == NULL)
return 1;
message = xmpp_stanza_get_text(child);
if (!message)
if (message == NULL)
return 1;
if (state->encode) {
@ -1140,7 +1137,7 @@ xmppipe_send(xmppipe_state_t *state, xmpp_stanza_t *const stanza)
xmpp_send(state->conn, stanza);
if (!state->sm_enabled)
if (state->sm_enabled == 0)
return;
if (state->sm_request % state->sm_request_interval != 0)

@ -23,8 +23,8 @@
#define XMPPIPE_VERSION "0.7.1"
#define XMPPIPE_STREQ(a,b) !strcmp((a),(b))
#define XMPPIPE_STRNEQ(a,b) strcmp((a),(b))
#define XMPPIPE_STREQ(a,b) (strcmp((a),(b)) == 0)
#define XMPPIPE_STRNEQ(a,b) (strcmp((a),(b)) != 0)
#define BASE64_LENGTH(n) ((((n) + 2) / 3) * 4)

@ -36,7 +36,7 @@ xmppipe_getenv(const char *s)
{
char *p = getenv(s);
if (!p)
if (p == NULL)
return NULL;
return xmppipe_strdup(p);
@ -47,11 +47,11 @@ xmppipe_strdup(const char *s)
{
char *buf = NULL;
if (!s)
if (s == NULL)
errx(2, "invalid string");
buf = strdup(s);
if (!buf)
if (buf == NULL)
err(3, "allocation failure");
return buf;
@ -66,7 +66,7 @@ xmppipe_malloc(size_t size)
errx(2, "invalid size: %zd", size);
buf = malloc(size);
if (!buf)
if (buf == NULL)
err(3, "allocation failure");
return buf;
@ -77,9 +77,8 @@ xmppipe_calloc(size_t nmemb, size_t size)
{
char *buf = NULL;
/* XXX overflow */
buf = calloc(nmemb, size);
if (!buf)
if (buf == NULL)
err(3, "allocation failure");
return buf;
@ -90,7 +89,7 @@ xmppipe_stanza_new(xmpp_ctx_t *ctx)
{
xmpp_stanza_t *s = xmpp_stanza_new(ctx);
if (!s)
if (s == NULL)
err(3, "allocation failure");
return s;
@ -161,7 +160,7 @@ xmppipe_servername(char *jid)
char *p = strchr(buf, '@');
char *q;
if (!p) {
if (p == NULL) {
free(buf);
return NULL;
}

Loading…
Cancel
Save