Reindent server/core/users.c
This commit is contained in:
@ -45,7 +45,7 @@
|
|||||||
USERS *
|
USERS *
|
||||||
users_alloc()
|
users_alloc()
|
||||||
{
|
{
|
||||||
USERS *rval;
|
USERS *rval;
|
||||||
|
|
||||||
if ((rval = calloc(1, sizeof(USERS))) == NULL)
|
if ((rval = calloc(1, sizeof(USERS))) == NULL)
|
||||||
{
|
{
|
||||||
@ -60,7 +60,11 @@ USERS *rval;
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hashtable_memory_fns(rval->data, (HASHMEMORYFN)strdup, (HASHMEMORYFN)strdup, (HASHMEMORYFN)free, (HASHMEMORYFN)free);
|
hashtable_memory_fns(rval->data,
|
||||||
|
(HASHMEMORYFN)strdup,
|
||||||
|
(HASHMEMORYFN)strdup,
|
||||||
|
(HASHMEMORYFN)free,
|
||||||
|
(HASHMEMORYFN)free);
|
||||||
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
@ -73,14 +77,16 @@ USERS *rval;
|
|||||||
void
|
void
|
||||||
users_free(USERS *users)
|
users_free(USERS *users)
|
||||||
{
|
{
|
||||||
if(users == NULL)
|
if (users == NULL)
|
||||||
{
|
{
|
||||||
MXS_ERROR("[%s:%d]: NULL parameter.", __FUNCTION__, __LINE__);
|
MXS_ERROR("[%s:%d]: NULL parameter.", __FUNCTION__, __LINE__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(users->data)
|
if (users->data)
|
||||||
|
{
|
||||||
hashtable_free(users->data);
|
hashtable_free(users->data);
|
||||||
|
}
|
||||||
free(users);
|
free(users);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +101,7 @@ users_free(USERS *users)
|
|||||||
int
|
int
|
||||||
users_add(USERS *users, char *user, char *auth)
|
users_add(USERS *users, char *user, char *auth)
|
||||||
{
|
{
|
||||||
int add;
|
int add;
|
||||||
|
|
||||||
atomic_add(&users->stats.n_adds, 1);
|
atomic_add(&users->stats.n_adds, 1);
|
||||||
add = hashtable_add(users->data, user, auth);
|
add = hashtable_add(users->data, user, auth);
|
||||||
@ -115,9 +121,10 @@ int add;
|
|||||||
int
|
int
|
||||||
users_delete(USERS *users, char *user)
|
users_delete(USERS *users, char *user)
|
||||||
{
|
{
|
||||||
int del;
|
int del;
|
||||||
|
|
||||||
if (users->stats.n_entries == 1) {
|
if (users->stats.n_entries == 1)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
atomic_add(&users->stats.n_deletes, 1);
|
atomic_add(&users->stats.n_deletes, 1);
|
||||||
@ -153,7 +160,9 @@ int
|
|||||||
users_update(USERS *users, char *user, char *auth)
|
users_update(USERS *users, char *user, char *auth)
|
||||||
{
|
{
|
||||||
if (hashtable_delete(users->data, user) == 0)
|
if (hashtable_delete(users->data, user) == 0)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return hashtable_add(users->data, user, auth);
|
return hashtable_add(users->data, user, auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,9 +187,9 @@ usersPrint(USERS *users)
|
|||||||
void
|
void
|
||||||
dcb_usersPrint(DCB *dcb, USERS *users)
|
dcb_usersPrint(DCB *dcb, USERS *users)
|
||||||
{
|
{
|
||||||
HASHITERATOR *iter;
|
HASHITERATOR *iter;
|
||||||
char *sep;
|
char *sep;
|
||||||
void *user;
|
void *user;
|
||||||
|
|
||||||
dcb_printf(dcb, "Users table data\n");
|
dcb_printf(dcb, "Users table data\n");
|
||||||
|
|
||||||
@ -197,18 +206,22 @@ void *user;
|
|||||||
dcb_printf(dcb, "User names: ");
|
dcb_printf(dcb, "User names: ");
|
||||||
sep = "";
|
sep = "";
|
||||||
|
|
||||||
if (users->usersCustomUserFormat != NULL) {
|
if (users->usersCustomUserFormat != NULL)
|
||||||
|
{
|
||||||
while ((user = hashtable_next(iter)) != NULL)
|
while ((user = hashtable_next(iter)) != NULL)
|
||||||
{
|
{
|
||||||
char *custom_user;
|
char *custom_user;
|
||||||
custom_user = users->usersCustomUserFormat(user);
|
custom_user = users->usersCustomUserFormat(user);
|
||||||
if (custom_user) {
|
if (custom_user)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "%s%s", sep, custom_user);
|
dcb_printf(dcb, "%s%s", sep, custom_user);
|
||||||
free(custom_user);
|
free(custom_user);
|
||||||
sep = ", ";
|
sep = ", ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
while ((user = hashtable_next(iter)) != NULL)
|
while ((user = hashtable_next(iter)) != NULL)
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "%s%s", sep, (char *)user);
|
dcb_printf(dcb, "%s%s", sep, (char *)user);
|
||||||
|
@ -42,7 +42,8 @@
|
|||||||
/**
|
/**
|
||||||
* The users table statistics structure
|
* The users table statistics structure
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
int n_entries; /**< The number of entries */
|
int n_entries; /**< The number of entries */
|
||||||
int n_adds; /**< The number of inserts */
|
int n_adds; /**< The number of inserts */
|
||||||
int n_deletes; /**< The number of deletes */
|
int n_deletes; /**< The number of deletes */
|
||||||
@ -53,12 +54,12 @@ typedef struct {
|
|||||||
* The user table, this contains the username and authentication data required
|
* The user table, this contains the username and authentication data required
|
||||||
* for the authentication implementation within the gateway.
|
* for the authentication implementation within the gateway.
|
||||||
*/
|
*/
|
||||||
typedef struct users {
|
typedef struct users
|
||||||
|
{
|
||||||
HASHTABLE *data; /**< The hashtable containing the actual data */
|
HASHTABLE *data; /**< The hashtable containing the actual data */
|
||||||
char *(*usersCustomUserFormat)(void *); /**< Optional username format routine */
|
char *(*usersCustomUserFormat)(void *); /**< Optional username format routine */
|
||||||
USERS_STATS stats; /**< The statistics for the users table */
|
USERS_STATS stats; /**< The statistics for the users table */
|
||||||
unsigned char
|
unsigned char cksum[SHA_DIGEST_LENGTH]; /**< The users' table ckecksum */
|
||||||
cksum[SHA_DIGEST_LENGTH]; /**< The users' table ckecksum */
|
|
||||||
} USERS;
|
} USERS;
|
||||||
|
|
||||||
extern USERS *users_alloc(); /**< Allocate a users table */
|
extern USERS *users_alloc(); /**< Allocate a users table */
|
||||||
@ -66,7 +67,9 @@ extern void users_free(USERS *); /**< Free a users table */
|
|||||||
extern int users_add(USERS *, char *, char *); /**< Add a user to the users table */
|
extern int users_add(USERS *, char *, char *); /**< Add a user to the users table */
|
||||||
extern int users_delete(USERS *, char *); /**< Delete a user from the users table */
|
extern int users_delete(USERS *, char *); /**< Delete a user from the users table */
|
||||||
extern char *users_fetch(USERS *, char *); /**< Fetch the authentication data for a user */
|
extern char *users_fetch(USERS *, char *); /**< Fetch the authentication data for a user */
|
||||||
extern int users_update(USERS *, char *, char *); /**< Change the password data for a user in the users table */
|
extern int users_update(USERS *, char *, char *); /**< Change the password data for a user in
|
||||||
|
the users table */
|
||||||
extern void usersPrint(USERS *); /**< Print data about the users loaded */
|
extern void usersPrint(USERS *); /**< Print data about the users loaded */
|
||||||
extern void dcb_usersPrint(DCB *, USERS *); /**< Print data about the users loaded */
|
extern void dcb_usersPrint(DCB *, USERS *); /**< Print data about the users loaded */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user