clean up some code duplication when checking nicks for validity

This commit is contained in:
William Pitcock 2015-12-12 08:41:09 -06:00
parent 7233e364cc
commit 72dee03d50
3 changed files with 24 additions and 44 deletions

View file

@ -74,7 +74,6 @@ static void hurt_destroy(void *hurt);
static int heal_nick(struct Client *, struct Client *); static int heal_nick(struct Client *, struct Client *);
static int nick_is_valid(const char *);
/* }}} */ /* }}} */
/* {{{ State containers */ /* {{{ State containers */
@ -312,7 +311,7 @@ mo_heal(struct Client *client_p, struct Client *source_p,
return 0; return 0;
} }
if (nick_is_valid(parv[1])) if (is_valid_nick(parv[1]))
{ {
target_p = find_named_person(parv[1]); target_p = find_named_person(parv[1]);
if (target_p == NULL) if (target_p == NULL)
@ -364,7 +363,7 @@ me_heal(struct Client *client_p, struct Client *source_p,
if (parc < 2) if (parc < 2)
return 0; return 0;
if (nick_is_valid(parv[1])) if (is_valid_nick(parv[1]))
{ {
target_p = find_person(parv[1]); target_p = find_person(parv[1]);
if (target_p != NULL && MyConnect(target_p)) if (target_p != NULL && MyConnect(target_p))
@ -638,25 +637,6 @@ heal_nick(struct Client *source_p, struct Client *target_p)
} }
/* }}} */ /* }}} */
/*
* Anything else...
*/
/* {{{ static int nick_is_valid() */
static int
nick_is_valid(const char *nick)
{
const char *s = nick;
for (; *s != '\0'; s++) {
if (!IsNickChar(*s))
return 0;
}
return 1;
}
/* }}} */
/* /*
* vim: ts=8 sw=8 noet fdm=marker tw=80 * vim: ts=8 sw=8 noet fdm=marker tw=80
*/ */

View file

@ -616,4 +616,25 @@ extern char *generate_uid(void);
void allocate_away(struct Client *); void allocate_away(struct Client *);
void free_away(struct Client *); void free_away(struct Client *);
static inline int
is_valid_nick(const char *nick)
{
int len = 0;
if(EmptyString(nick) || *nick == '-' || IsDigit(*nick))
return 0;
for(; *nick; nick++)
{
len++;
if(!IsNickChar(*nick))
return 0;
}
if(len >= NICKLEN)
return 0;
return 1;
}
#endif /* INCLUDED_client_h */ #endif /* INCLUDED_client_h */

View file

@ -154,27 +154,6 @@ me_login(struct Client *client_p, struct Client *source_p,
return 0; return 0;
} }
static int
clean_nick(const char *nick)
{
int len = 0;
if(EmptyString(nick) || *nick == '-' || IsDigit(*nick))
return 0;
for(; *nick; nick++)
{
len++;
if(!IsNickChar(*nick))
return 0;
}
if(len >= NICKLEN)
return 0;
return 1;
}
static int static int
me_rsfnc(struct Client *client_p, struct Client *source_p, me_rsfnc(struct Client *client_p, struct Client *source_p,
int parc, const char *parv[]) int parc, const char *parv[])
@ -197,7 +176,7 @@ me_rsfnc(struct Client *client_p, struct Client *source_p,
if(!MyClient(target_p)) if(!MyClient(target_p))
return 0; return 0;
if(!clean_nick(parv[2])) if(!is_valid_nick(parv[2]))
return 0; return 0;
curts = atol(parv[4]); curts = atol(parv[4]);