int parc, char *parv[])
{
struct MaskItem *conf = NULL;
- int tkline_time = 0;
+ time_t tkline_time = 0;
char *kuser, *khost, *kreason;
if (parc != 6 || EmptyString(parv[5]))
if (match(parv[1], me.name))
return;
- tkline_time = valid_tkline(parv[2], TK_SECONDS);
+ valid_tkline(parv[2], TK_SECONDS, &tkline_time);
kuser = parv[3];
khost = parv[4];
kreason = parv[5];
*
* inputs - pointer to ascii string to check
* - whether the specified time is in seconds or minutes
- * output - -1 not enough parameters
- * - 0 if not an integer number, else the number
+ * - pointer to the parsed value in seconds
+ * output - true if the data passed is a valid time, otherwise false
* side effects - none
* Originally written by Dianora (Diane, db@db.net)
*/
-time_t
-valid_tkline(const char *data, const int minutes)
+bool
+valid_tkline(const char *data, const int minutes, time_t *out)
{
const unsigned char *p = (const unsigned char *)data;
unsigned char tmpch = '\0';
while ((tmpch = *p++))
{
if (!IsDigit(tmpch))
- return 0;
+ return false;
result *= 10;
result += (tmpch & 0xF);
}
- /*
- * In the degenerate case where oper does a /quote kline 0 user@host :reason
- * i.e. they specifically use 0, I am going to return 1 instead
- * as a return value of non-zero is used to flag it as a temporary kline
- */
- if (result == 0)
- result = 1;
-
- /*
- * If the incoming time is in seconds convert it to minutes for the purpose
- * of this calculation
- */
- if (!minutes)
- result = result / 60;
+ // Convert to seconds
+ if (minutes)
+ result *= 60;
- if (result > MAX_TDKLINE_TIME)
- result = MAX_TDKLINE_TIME;
+ // MAX_TDKLINE_TIME is in minutes, so convert to seconds
+ if (result > MAX_TDKLINE_TIME * 60)
+ result = MAX_TDKLINE_TIME * 60;
- result = result * 60; /* turn it into seconds */
-
- return result;
+ *out = result;
+ return true;
}
/* valid_wild_card_simple()
int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
char **target_server, char **reason)
{
- int found_tkline_time=0;
+ time_t parsed_tkline_time;
static char def_reason[] = CONF_NOREASON;
static char user[USERLEN*4+1];
static char host[HOSTLEN*4+1];
parv++;
parc--;
- found_tkline_time = valid_tkline(*parv, TK_MINUTES);
-
- if (found_tkline_time != 0)
+ if (valid_tkline(*parv, TK_MINUTES, &parsed_tkline_time))
{
parv++;
parc--;
if (tkline_time != NULL)
- *tkline_time = found_tkline_time;
+ *tkline_time = parsed_tkline_time;
else
{
sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",