handler: avoid unnamed union

Unnamed unions appeared only in C11 standard. Don't use them to
increase portability.
This commit is contained in:
Dmitry Podgorny
2020-01-10 01:22:53 +02:00
parent 212df6d036
commit 0326e5c5e2
3 changed files with 43 additions and 43 deletions

View File

@@ -130,7 +130,7 @@ struct _xmpp_handlist_t {
char *name; char *name;
char *type; char *type;
}; };
}; } u;
}; };
#define MAX_DOMAIN_LEN 256 #define MAX_DOMAIN_LEN 256

View File

@@ -305,7 +305,7 @@ int xmpp_conn_release(xmpp_conn_t * const conn)
while (hlitem) { while (hlitem) {
thli = hlitem; thli = hlitem;
hlitem = hlitem->next; hlitem = hlitem->next;
xmpp_free(conn->ctx, thli->id); xmpp_free(conn->ctx, thli->u.id);
xmpp_free(conn->ctx, thli); xmpp_free(conn->ctx, thli);
} }
} }
@@ -317,9 +317,9 @@ int xmpp_conn_release(xmpp_conn_t * const conn)
thli = hlitem; thli = hlitem;
hlitem = hlitem->next; hlitem = hlitem->next;
if (thli->ns) xmpp_free(ctx, thli->ns); if (thli->u.ns) xmpp_free(ctx, thli->u.ns);
if (thli->name) xmpp_free(ctx, thli->name); if (thli->u.name) xmpp_free(ctx, thli->u.name);
if (thli->type) xmpp_free(ctx, thli->type); if (thli->u.type) xmpp_free(ctx, thli->u.type);
xmpp_free(ctx, thli); xmpp_free(ctx, thli);
} }

View File

@@ -90,7 +90,7 @@ void handler_fire_stanza(xmpp_conn_t * const conn,
/* replace old value */ /* replace old value */
hash_add(conn->id_handlers, id, head); hash_add(conn->id_handlers, id, head);
} }
xmpp_free(conn->ctx, item->id); xmpp_free(conn->ctx, item->u.id);
xmpp_free(conn->ctx, item); xmpp_free(conn->ctx, item);
} }
item = next; item = next;
@@ -116,10 +116,10 @@ void handler_fire_stanza(xmpp_conn_t * const conn,
} }
next = item->next; next = item->next;
if ((!item->ns || (ns && strcmp(ns, item->ns) == 0) || if ((!item->u.ns || (ns && strcmp(ns, item->u.ns) == 0) ||
xmpp_stanza_get_child_by_ns(stanza, item->ns)) && xmpp_stanza_get_child_by_ns(stanza, item->u.ns)) &&
(!item->name || (name && strcmp(name, item->name) == 0)) && (!item->u.name || (name && strcmp(name, item->u.name) == 0)) &&
(!item->type || (type && strcmp(type, item->type) == 0))) { (!item->u.type || (type && strcmp(type, item->u.type) == 0))) {
ret = ((xmpp_handler)(item->handler))(conn, stanza, item->userdata); ret = ((xmpp_handler)(item->handler))(conn, stanza, item->userdata);
/* list may be changed during execution of a handler */ /* list may be changed during execution of a handler */
@@ -127,9 +127,9 @@ void handler_fire_stanza(xmpp_conn_t * const conn,
if (!ret) { if (!ret) {
/* handler is one-shot, so delete it */ /* handler is one-shot, so delete it */
_handler_item_remove(&conn->handlers, item); _handler_item_remove(&conn->handlers, item);
if (item->ns) xmpp_free(conn->ctx, item->ns); if (item->u.ns) xmpp_free(conn->ctx, item->u.ns);
if (item->name) xmpp_free(conn->ctx, item->name); if (item->u.name) xmpp_free(conn->ctx, item->u.name);
if (item->type) xmpp_free(conn->ctx, item->type); if (item->u.type) xmpp_free(conn->ctx, item->u.type);
xmpp_free(conn->ctx, item); xmpp_free(conn->ctx, item);
} }
} }
@@ -178,10 +178,10 @@ uint64_t handler_fire_timed(xmpp_ctx_t * const ctx)
next = item->next; next = item->next;
timestamp = time_stamp(); timestamp = time_stamp();
elapsed = time_elapsed(item->last_stamp, timestamp); elapsed = time_elapsed(item->u.last_stamp, timestamp);
if (elapsed >= item->period) { if (elapsed >= item->u.period) {
/* fire! */ /* fire! */
item->last_stamp = timestamp; item->u.last_stamp = timestamp;
ret = ((xmpp_timed_handler)item->handler)(conn, item->userdata); ret = ((xmpp_timed_handler)item->handler)(conn, item->userdata);
/* list may be changed during execution of a handler */ /* list may be changed during execution of a handler */
next = item->next; next = item->next;
@@ -190,8 +190,8 @@ uint64_t handler_fire_timed(xmpp_ctx_t * const ctx)
_handler_item_remove(&conn->timed_handlers, item); _handler_item_remove(&conn->timed_handlers, item);
xmpp_free(conn->ctx, item); xmpp_free(conn->ctx, item);
} }
} else if (min > (item->period - elapsed)) } else if (min > (item->u.period - elapsed))
min = item->period - elapsed; min = item->u.period - elapsed;
item = next; item = next;
} }
@@ -215,7 +215,7 @@ void handler_reset_timed(xmpp_conn_t *conn, int user_only)
handitem = conn->timed_handlers; handitem = conn->timed_handlers;
while (handitem) { while (handitem) {
if ((user_only && handitem->user_handler) || !user_only) if ((user_only && handitem->user_handler) || !user_only)
handitem->last_stamp = time_stamp(); handitem->u.last_stamp = time_stamp();
handitem = handitem->next; handitem = handitem->next;
} }
@@ -248,8 +248,8 @@ static void _timed_handler_add(xmpp_conn_t * const conn,
item->enabled = 0; item->enabled = 0;
item->next = NULL; item->next = NULL;
item->period = period; item->u.period = period;
item->last_stamp = time_stamp(); item->u.last_stamp = time_stamp();
/* append item to list */ /* append item to list */
if (!conn->timed_handlers) if (!conn->timed_handlers)
@@ -322,8 +322,8 @@ static void _id_handler_add(xmpp_conn_t * const conn,
item->enabled = 0; item->enabled = 0;
item->next = NULL; item->next = NULL;
item->id = xmpp_strdup(conn->ctx, id); item->u.id = xmpp_strdup(conn->ctx, id);
if (!item->id) { if (!item->u.id) {
xmpp_free(conn->ctx, item); xmpp_free(conn->ctx, item);
return; return;
} }
@@ -368,7 +368,7 @@ void xmpp_id_handler_delete(xmpp_conn_t * const conn,
hash_add(conn->id_handlers, id, next); hash_add(conn->id_handlers, id, next);
} }
xmpp_free(conn->ctx, item->id); xmpp_free(conn->ctx, item->u.id);
xmpp_free(conn->ctx, item); xmpp_free(conn->ctx, item);
item = next; item = next;
} else { } else {
@@ -410,31 +410,31 @@ static void _handler_add(xmpp_conn_t * const conn,
item->next = NULL; item->next = NULL;
if (ns) { if (ns) {
item->ns = xmpp_strdup(conn->ctx, ns); item->u.ns = xmpp_strdup(conn->ctx, ns);
if (!item->ns) { if (!item->u.ns) {
xmpp_free(conn->ctx, item); xmpp_free(conn->ctx, item);
return; return;
} }
} else } else
item->ns = NULL; item->u.ns = NULL;
if (name) { if (name) {
item->name = xmpp_strdup(conn->ctx, name); item->u.name = xmpp_strdup(conn->ctx, name);
if (!item->name) { if (!item->u.name) {
if (item->ns) xmpp_free(conn->ctx, item->ns); if (item->u.ns) xmpp_free(conn->ctx, item->u.ns);
xmpp_free(conn->ctx, item); xmpp_free(conn->ctx, item);
return; return;
} }
} else } else
item->name = NULL; item->u.name = NULL;
if (type) { if (type) {
item->type = xmpp_strdup(conn->ctx, type); item->u.type = xmpp_strdup(conn->ctx, type);
if (!item->type) { if (!item->u.type) {
if (item->ns) xmpp_free(conn->ctx, item->ns); if (item->u.ns) xmpp_free(conn->ctx, item->u.ns);
if (item->name) xmpp_free(conn->ctx, item->name); if (item->u.name) xmpp_free(conn->ctx, item->u.name);
xmpp_free(conn->ctx, item); xmpp_free(conn->ctx, item);
} }
} else } else
item->type = NULL; item->u.type = NULL;
/* append to list */ /* append to list */
if (!conn->handlers) if (!conn->handlers)
@@ -470,9 +470,9 @@ void xmpp_handler_delete(xmpp_conn_t * const conn,
else else
conn->handlers = item->next; conn->handlers = item->next;
if (item->ns) xmpp_free(conn->ctx, item->ns); if (item->u.ns) xmpp_free(conn->ctx, item->u.ns);
if (item->name) xmpp_free(conn->ctx, item->name); if (item->u.name) xmpp_free(conn->ctx, item->u.name);
if (item->type) xmpp_free(conn->ctx, item->type); if (item->u.type) xmpp_free(conn->ctx, item->u.type);
xmpp_free(conn->ctx, item); xmpp_free(conn->ctx, item);
item = prev ? prev->next : conn->handlers; item = prev ? prev->next : conn->handlers;
} else { } else {
@@ -636,9 +636,9 @@ void handler_system_delete_all(xmpp_conn_t *conn)
if (!item->user_handler) { if (!item->user_handler) {
next = item->next; next = item->next;
_handler_item_remove(&conn->handlers, item); _handler_item_remove(&conn->handlers, item);
if (item->ns) xmpp_free(conn->ctx, item->ns); if (item->u.ns) xmpp_free(conn->ctx, item->u.ns);
if (item->name) xmpp_free(conn->ctx, item->name); if (item->u.name) xmpp_free(conn->ctx, item->u.name);
if (item->type) xmpp_free(conn->ctx, item->type); if (item->u.type) xmpp_free(conn->ctx, item->u.type);
xmpp_free(conn->ctx, item); xmpp_free(conn->ctx, item);
item = next; item = next;
} else } else
@@ -665,7 +665,7 @@ void handler_system_delete_all(xmpp_conn_t *conn)
if (!item->user_handler) { if (!item->user_handler) {
next = item->next; next = item->next;
_handler_item_remove(&head, item); _handler_item_remove(&head, item);
xmpp_free(conn->ctx, item->id); xmpp_free(conn->ctx, item->u.id);
xmpp_free(conn->ctx, item); xmpp_free(conn->ctx, item);
item = next; item = next;
} else } else