示例#1
0
/* Given a 'date', deterimine if it is in the future.
 * 
 * Return:
 *   A non-NULL string date with today's date if the input
 *   date is in the future.
 *
 *   Otherwise return NULL
 */
char *date_in_future (char *date) {
  int intdate1 = 0, intdate2;
  char strdate[10];

  sscanf (date, "%d", &intdate1);
  if (intdate1 == 0)
    return NULL;

  intdate2 = todays_date ();

  if (intdate1 > intdate2) {
    sprintf (strdate, "%d", intdate2);
    return strdup (strdate);
  }

  return NULL;
}
示例#2
0
bool FServerIrcBotPlugin::files(const message& msg)
{
	BUG_COMMAND(msg);
	if(done.load())
	{
		bot.fc_reply_pm_notice(msg, "Declined, server shutting down");
		return true;
	}
	// make zip file
	// ommo-ebooks-YYYY-MM-DD.txt
	str data_dir = bot.get("fserver.data.dir", bot.get_data_folder());
	bug_var(data_dir);
	str fname = data_dir;
	fname += "/" + bot.get("fserver.index.file.prefix", bot.nick + "-files");
	fname += "-" + todays_date();

	if(!have_zip(data_dir, fname))
		return false;

	request_file(msg, fname + ".zip");

	return true;
}
示例#3
0
/* Given a 'date' (ie, YYMMDD) make sure the date is in proper
 * format and syntax.  YY must be >= 1988.  If the date is
 * in the future, change the date to today's date and return 
 * the correct date.  Skip the future check if 'skip_future_check' is set
 * (ie, withdrawn: attr)
 *
 * Return:
 *   NULL if no errors in date and date is not in the future
 *   today's date if no errors in date and date is in the future
 */
char *date_syntax (char *date, parse_info_t *obj, int skip_future_check) {
  char year[5];
  char month[3];
  char day[3];
  char strdate[9];
  char *now;
  int errors;

  /* ensure the date is 6 char's long and all numbers */
  if (regexec(&re[RE_DATE], date, (size_t) 0, NULL, 0)) {
      error_msg_queue (obj, "Malformed date (/^YYYYMMDD$/)", WARN_OVERRIDE_MSG);
      error_msg_queue (obj, "Changing to today's date", WARN_OVERRIDE_MSG);
      sprintf (strdate, "%d", todays_date ());
      return strdup (strdate);

    /*
	error_msg_queue (obj, "Malformed date (/^YYYYMMDD$/)", ERROR_MSG);
	return NULL;
    */
  }

  errors = 0;

  /* check year part */
  strncpy (year, date, 4);
  year[4] = '\0';

  if (strncmp (year, "1988", 4) < 0) {
      error_msg_queue (obj, "Year part of date is too old (YYYYMMDD)", ERROR_MSG);    
      errors++;
  }

  /* check month part */
  strncpy (month, &date[4], 2);
  month[2] = '\0';

  if ((strncmp (month, "01", 2) < 0) ||
      (strncmp (month, "12", 2) > 0)) {
      error_msg_queue (obj, "Syntax error in month part of date (YYYYMMDD)", ERROR_MSG);
      errors++;
  }

  /* check day part */
  strncpy (day, &date[6], 2);
  day[2] = '\0';

  if ((strncmp (day, "01", 2) < 0) ||
      (strncmp (day, "31", 2) > 0)) {
      error_msg_queue (obj, "Syntax error in day part of date (YYMMDD)", ERROR_MSG);
      errors++;
  }

  if (errors || skip_future_check)
    return NULL;

  if ((now = date_in_future (date)) != NULL) {
    /*
    error_msg_queue (obj, "Date is in the future, changed to today's date", WARN_OVERRIDE_MSG);
    */
    return now;
  }

  return NULL;
}