#include "irc_user.h"
#include "log.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
// XXX: prototype of function from irc_net
void irc_net_remove_user (struct irc_net *net, struct irc_user *user);
err_t irc_user_create (struct irc_user **user_ptr, struct irc_net *net, const char *nickname)
{
struct irc_user *user;
(void) net;
// allocate
if ((user = calloc(1, sizeof(*user))) == NULL)
return ERR_CALLOC;
// init
if ((user->nickname = strdup(nickname)) == NULL)
return ERR_STRDUP;
user->refcount = 0;
// ok
*user_ptr = user;
return SUCCESS;
}
err_t irc_user_rename (struct irc_user *user, const char *new_nickname)
{
// release old name
free(user->nickname);
// copy new one
if ((user->nickname = strdup(new_nickname)) == NULL)
return ERR_STRDUP;
// ok
return SUCCESS;
}
void irc_user_destroy (struct irc_user *user)
{
if (user->refcount > 0)
log_warn("refcount=%zu", user->refcount);
free(user->nickname);
free(user);
}