Unify coding style

@sjaeckel integrated clang-format with formal coding style. Run his
script and commit changes.

There are pros and cons of this commit.

Mixed coding style is a "broken window". A good single style simplifies
reading and writing code.

On the other hand, this is a big change which will lead to conflicts.
This commit is contained in:
Dmitry Podgorny
2020-01-03 22:02:22 +02:00
parent eef07cef36
commit 562a06425b
62 changed files with 3972 additions and 3746 deletions

View File

@@ -33,8 +33,7 @@
* TODO Convert handler lists to double-linked lists. Current implementation
* works for O(n).
*/
static void _handler_item_remove(xmpp_handlist_t **head,
xmpp_handlist_t *item)
static void _handler_item_remove(xmpp_handlist_t **head, xmpp_handlist_t *item)
{
xmpp_handlist_t *i = *head;
@@ -56,8 +55,7 @@ static void _handler_item_remove(xmpp_handlist_t **head,
* @param conn a Strophe connection object
* @param stanza a Strophe stanza object
*/
void handler_fire_stanza(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza)
void handler_fire_stanza(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza)
{
xmpp_handlist_t *item, *next, *head, *head_old;
const char *id, *ns, *name, *type;
@@ -75,7 +73,8 @@ void handler_fire_stanza(xmpp_conn_t * const conn,
while (item) {
/* don't fire user handlers until authentication succeeds and
and skip newly added handlers */
if ((item->user_handler && !conn->authenticated) || !item->enabled) {
if ((item->user_handler && !conn->authenticated) ||
!item->enabled) {
item = item->next;
continue;
}
@@ -127,9 +126,12 @@ void handler_fire_stanza(xmpp_conn_t * const conn,
if (!ret) {
/* handler is one-shot, so delete it */
_handler_item_remove(&conn->handlers, item);
if (item->u.ns) xmpp_free(conn->ctx, item->u.ns);
if (item->u.name) xmpp_free(conn->ctx, item->u.name);
if (item->u.type) xmpp_free(conn->ctx, item->u.type);
if (item->u.ns)
xmpp_free(conn->ctx, item->u.ns);
if (item->u.name)
xmpp_free(conn->ctx, item->u.name);
if (item->u.type)
xmpp_free(conn->ctx, item->u.type);
xmpp_free(conn->ctx, item);
}
}
@@ -144,7 +146,7 @@ void handler_fire_stanza(xmpp_conn_t * const conn,
*
* @return the time in milliseconds until the next handler will be ready
*/
uint64_t handler_fire_timed(xmpp_ctx_t * const ctx)
uint64_t handler_fire_timed(xmpp_ctx_t *const ctx)
{
xmpp_connlist_t *connitem;
xmpp_handlist_t *item, *next;
@@ -171,7 +173,8 @@ uint64_t handler_fire_timed(xmpp_ctx_t * const ctx)
while (item) {
/* don't fire user handlers until authentication succeeds and
skip newly added handlers */
if ((item->user_handler && !conn->authenticated) || !item->enabled) {
if ((item->user_handler && !conn->authenticated) ||
!item->enabled) {
item = item->next;
continue;
}
@@ -221,10 +224,10 @@ void handler_reset_timed(xmpp_conn_t *conn, int user_only)
}
}
static void _timed_handler_add(xmpp_conn_t * const conn,
static void _timed_handler_add(xmpp_conn_t *const conn,
xmpp_timed_handler handler,
const unsigned long period,
void * const userdata,
void *const userdata,
const int user_handler)
{
xmpp_handlist_t *item, *tail;
@@ -236,11 +239,13 @@ static void _timed_handler_add(xmpp_conn_t * const conn,
break;
}
}
if (item) return;
if (item)
return;
/* build new item */
item = xmpp_alloc(conn->ctx, sizeof(xmpp_handlist_t));
if (!item) return;
if (!item)
return;
item->user_handler = user_handler;
item->handler = handler;
@@ -269,12 +274,13 @@ static void _timed_handler_add(xmpp_conn_t * const conn,
*
* @ingroup Handlers
*/
void xmpp_timed_handler_delete(xmpp_conn_t * const conn,
void xmpp_timed_handler_delete(xmpp_conn_t *const conn,
xmpp_timed_handler handler)
{
xmpp_handlist_t *item, *prev;
if (!conn->timed_handlers) return;
if (!conn->timed_handlers)
return;
prev = NULL;
item = conn->timed_handlers;
@@ -294,10 +300,11 @@ void xmpp_timed_handler_delete(xmpp_conn_t * const conn,
}
}
static void _id_handler_add(xmpp_conn_t * const conn,
xmpp_handler handler,
const char * const id,
void * const userdata, int user_handler)
static void _id_handler_add(xmpp_conn_t *const conn,
xmpp_handler handler,
const char *const id,
void *const userdata,
int user_handler)
{
xmpp_handlist_t *item, *tail;
@@ -310,11 +317,13 @@ static void _id_handler_add(xmpp_conn_t * const conn,
}
item = item->next;
}
if (item) return;
if (item)
return;
/* build new item */
item = xmpp_alloc(conn->ctx, sizeof(xmpp_handlist_t));
if (!item) return;
if (!item)
return;
item->user_handler = user_handler;
item->handler = handler;
@@ -347,15 +356,16 @@ static void _id_handler_add(xmpp_conn_t * const conn,
*
* @ingroup Handlers
*/
void xmpp_id_handler_delete(xmpp_conn_t * const conn,
void xmpp_id_handler_delete(xmpp_conn_t *const conn,
xmpp_handler handler,
const char * const id)
const char *const id)
{
xmpp_handlist_t *item, *prev, *next;
prev = NULL;
item = (xmpp_handlist_t *)hash_get(conn->id_handlers, id);
if (!item) return;
if (!item)
return;
while (item) {
next = item->next;
@@ -379,12 +389,13 @@ void xmpp_id_handler_delete(xmpp_conn_t * const conn,
}
/* add a stanza handler */
static void _handler_add(xmpp_conn_t * const conn,
static void _handler_add(xmpp_conn_t *const conn,
xmpp_handler handler,
const char * const ns,
const char * const name,
const char * const type,
void * const userdata, int user_handler)
const char *const ns,
const char *const name,
const char *const type,
void *const userdata,
int user_handler)
{
xmpp_handlist_t *item, *tail;
@@ -397,11 +408,13 @@ static void _handler_add(xmpp_conn_t * const conn,
break;
}
}
if (item) return;
if (item)
return;
/* build new item */
item = (xmpp_handlist_t *)xmpp_alloc(conn->ctx, sizeof(xmpp_handlist_t));
if (!item) return;
if (!item)
return;
item->user_handler = user_handler;
item->handler = handler;
@@ -417,20 +430,25 @@ static void _handler_add(xmpp_conn_t * const conn,
}
} else
item->u.ns = NULL;
if (name) {
item->u.name = xmpp_strdup(conn->ctx, name);
if (!item->u.name) {
if (item->u.ns) xmpp_free(conn->ctx, item->u.ns);
if (item->u.ns)
xmpp_free(conn->ctx, item->u.ns);
xmpp_free(conn->ctx, item);
return;
}
} else
item->u.name = NULL;
if (type) {
item->u.type = xmpp_strdup(conn->ctx, type);
if (!item->u.type) {
if (item->u.ns) xmpp_free(conn->ctx, item->u.ns);
if (item->u.name) xmpp_free(conn->ctx, item->u.name);
if (item->u.ns)
xmpp_free(conn->ctx, item->u.ns);
if (item->u.name)
xmpp_free(conn->ctx, item->u.name);
xmpp_free(conn->ctx, item);
}
} else
@@ -454,12 +472,12 @@ static void _handler_add(xmpp_conn_t * const conn,
*
* @ingroup Handlers
*/
void xmpp_handler_delete(xmpp_conn_t * const conn,
xmpp_handler handler)
void xmpp_handler_delete(xmpp_conn_t *const conn, xmpp_handler handler)
{
xmpp_handlist_t *prev, *item;
if (!conn->handlers) return;
if (!conn->handlers)
return;
prev = NULL;
item = conn->handlers;
@@ -470,9 +488,12 @@ void xmpp_handler_delete(xmpp_conn_t * const conn,
else
conn->handlers = item->next;
if (item->u.ns) xmpp_free(conn->ctx, item->u.ns);
if (item->u.name) xmpp_free(conn->ctx, item->u.name);
if (item->u.type) xmpp_free(conn->ctx, item->u.type);
if (item->u.ns)
xmpp_free(conn->ctx, item->u.ns);
if (item->u.name)
xmpp_free(conn->ctx, item->u.name);
if (item->u.type)
xmpp_free(conn->ctx, item->u.type);
xmpp_free(conn->ctx, item);
item = prev ? prev->next : conn->handlers;
} else {
@@ -498,10 +519,10 @@ void xmpp_handler_delete(xmpp_conn_t * const conn,
*
* @ingroup Handlers
*/
void xmpp_timed_handler_add(xmpp_conn_t * const conn,
void xmpp_timed_handler_add(xmpp_conn_t *const conn,
xmpp_timed_handler handler,
const unsigned long period,
void * const userdata)
void *const userdata)
{
_timed_handler_add(conn, handler, period, userdata, 1);
}
@@ -515,10 +536,10 @@ void xmpp_timed_handler_add(xmpp_conn_t * const conn,
* @param period the time in milliseconds between firings
* @param userdata an opaque data pointer that will be passed to the handler
*/
void handler_add_timed(xmpp_conn_t * const conn,
void handler_add_timed(xmpp_conn_t *const conn,
xmpp_timed_handler handler,
const unsigned long period,
void * const userdata)
void *const userdata)
{
_timed_handler_add(conn, handler, period, userdata, 0);
}
@@ -539,10 +560,10 @@ void handler_add_timed(xmpp_conn_t * const conn,
*
* @ingroup Handlers
*/
void xmpp_id_handler_add(xmpp_conn_t * const conn,
void xmpp_id_handler_add(xmpp_conn_t *const conn,
xmpp_handler handler,
const char * const id,
void * const userdata)
const char *const id,
void *const userdata)
{
_id_handler_add(conn, handler, id, userdata, 1);
}
@@ -556,10 +577,10 @@ void xmpp_id_handler_add(xmpp_conn_t * const conn,
* @param id a string with the id
* @param userdata an opaque data pointer that will be passed to the handler
*/
void handler_add_id(xmpp_conn_t * const conn,
void handler_add_id(xmpp_conn_t *const conn,
xmpp_handler handler,
const char * const id,
void * const userdata)
const char *const id,
void *const userdata)
{
_id_handler_add(conn, handler, id, userdata, 0);
}
@@ -586,12 +607,12 @@ void handler_add_id(xmpp_conn_t * const conn,
*
* @ingroup Handlers
*/
void xmpp_handler_add(xmpp_conn_t * const conn,
void xmpp_handler_add(xmpp_conn_t *const conn,
xmpp_handler handler,
const char * const ns,
const char * const name,
const char * const type,
void * const userdata)
const char *const ns,
const char *const name,
const char *const type,
void *const userdata)
{
_handler_add(conn, handler, ns, name, type, userdata, 1);
}
@@ -607,12 +628,12 @@ void xmpp_handler_add(xmpp_conn_t * const conn,
* @param type a string with the 'type' attribute value to match
* @param userdata an opaque data pointer that will be passed to the handler
*/
void handler_add(xmpp_conn_t * const conn,
void handler_add(xmpp_conn_t *const conn,
xmpp_handler handler,
const char * const ns,
const char * const name,
const char * const type,
void * const userdata)
const char *const ns,
const char *const name,
const char *const type,
void *const userdata)
{
_handler_add(conn, handler, ns, name, type, userdata, 0);
}
@@ -636,9 +657,12 @@ void handler_system_delete_all(xmpp_conn_t *conn)
if (!item->user_handler) {
next = item->next;
_handler_item_remove(&conn->handlers, item);
if (item->u.ns) xmpp_free(conn->ctx, item->u.ns);
if (item->u.name) xmpp_free(conn->ctx, item->u.name);
if (item->u.type) xmpp_free(conn->ctx, item->u.type);
if (item->u.ns)
xmpp_free(conn->ctx, item->u.ns);
if (item->u.name)
xmpp_free(conn->ctx, item->u.name);
if (item->u.type)
xmpp_free(conn->ctx, item->u.type);
xmpp_free(conn->ctx, item);
item = next;
} else
@@ -686,5 +710,6 @@ void handler_system_delete_all(xmpp_conn_t *conn)
xmpp_free(conn->ctx, key2);
}
}
if (iter) hash_iter_release(iter);
if (iter)
hash_iter_release(iter);
}