예제 #1
0
static GDateTime *parse_datetime(const char *str)
{
	if(str == NULL) return NULL;

	GDateTime *ret = NULL;
	char **bits = g_strsplit(str, " ", -1);
	int num_bits = g_strv_length(bits);
	if(num_bits < 6) {
		g_debug("num_bits for `%s' isn't valid; format unknown", str);
		goto fail;
	}

	/* #0 is day-of-week in english. that's skipped. */
	int month = parse_month(bits[1]);
	if(month <= 0) goto fail;
	int day = atoi(bits[2]);
	if(day == 0) goto fail;
	int hour, min, sec;
	if(sscanf(bits[3], "%d:%d:%d", &hour, &min, &sec) != 3) goto fail;
	int year = atoi(bits[5]);
	if(year < 0) goto fail;
	GTimeZone *tz = g_time_zone_new(bits[4]);
	if(tz == NULL) goto fail;

	ret = g_date_time_new(tz, year, month, day, hour, min, sec);
	g_time_zone_unref(tz);
	if(ret == NULL) {
		g_debug("couldn't make a new timestamp");
	}

fail:
	g_strfreev(bits);
	return ret;
}
예제 #2
0
static gboolean
parse_textual_date (SoupDate *date, const char *date_string)
{
	/* If it starts with a word, it must be a weekday, which we skip */
	if (g_ascii_isalpha (*date_string)) {
		while (g_ascii_isalpha (*date_string))
			date_string++;
		if (*date_string == ',')
			date_string++;
		while (g_ascii_isspace (*date_string))
			date_string++;
	}

	/* If there's now another word, this must be an asctime-date */
	if (g_ascii_isalpha (*date_string)) {
		/* (Sun) Nov  6 08:49:37 1994 */
		if (!parse_month (date, &date_string) ||
		    !parse_day (date, &date_string) ||
		    !parse_time (date, &date_string) ||
		    !parse_year (date, &date_string))
			return FALSE;

		/* There shouldn't be a timezone, but check anyway */
		parse_timezone (date, &date_string);
	} else {
		/* Non-asctime date, so some variation of
		 * (Sun,) 06 Nov 1994 08:49:37 GMT
		 */
		if (!parse_day (date, &date_string) ||
		    !parse_month (date, &date_string) ||
		    !parse_year (date, &date_string) ||
		    !parse_time (date, &date_string))
			return FALSE;

		/* This time there *should* be a timezone, but we
		 * survive if there isn't.
		 */
		parse_timezone (date, &date_string);
	}
	return TRUE;
}
예제 #3
0
static int parse_line(
    const char *linebuf,
    int *year,
    int *month,
    int *day,
    double *delta
) {
	char s[0x100]; // for substrings

	long tmp;

	substr(s, linebuf, 1, 4); // year
	if (!parse_long(s, &tmp)) {
		fprintf(stderr, "cannot parse year: \"%s\"\n", s);
		return 0;
	}
	*year = (int) tmp;

	substr(s, linebuf, 6, 3); // month name abbr
	if (!parse_month(s, &tmp)) {
		fprintf(stderr, "cannot parse month: \"%s\"\n", s);
		return 0;
	}
	*month = (int) tmp;

	substr(s, linebuf, 10, 2); // day
	if (!parse_long(s, &tmp)) {
		fprintf(stderr, "cannot parse day: \"%s\"\n", s);
		return 0;
	}
	*day = (int) tmp;

	substr(s, linebuf, 36, 13); // tai-utc delta
	if (!parse_double(s, delta)) {
		fprintf(stderr, "cannot parse delta: %s\n", s);
		return 0;
	}
	return 1;

//         1         2         3         4         5         6         7         8
//12345678901234567890123456789012345678901234567890123456789012345678901234567890
//                                    1234567890123
// 2012 JUL  1 =JD 2456109.5  TAI-UTC=  35.0       S + (MJD - 41317.) X 0.0      S
}
예제 #4
0
static void
parse_rule_line                 (ParsingData    *data)
{
  GArray *rule_array;
  RuleData rule;
  char *name;
  TimeCode time_code;

  /* All 10 fields must be present. */
  if (data->num_fields != 10) {
        fprintf (stderr, "%s:%i: Invalid Rule line - %i fields.\n%s\n",
                 data->filename, data->line_number, data->num_fields,
                 data->line);
        exit (1);
  }

  name = data->fields[RULE_NAME];

  /* Create the GArray and add it to the hash table if it doesn't already
     exist. */
  rule_array = g_hash_table_lookup (data->rule_data, name);
  if (!rule_array) {
    rule_array = g_array_new (FALSE, FALSE, sizeof (RuleData));
    g_hash_table_insert (data->rule_data, g_strdup (name), rule_array);
  }

  rule.from_year = parse_year (data, data->fields[RULE_FROM], FALSE, 0);
  if (rule.from_year == YEAR_MAXIMUM) {
    fprintf (stderr, "%s:%i: Invalid Rule FROM value: '%s'\n",
             data->filename, data->line_number, data->fields[RULE_FROM]);
    exit (1);
  }

  rule.to_year = parse_year (data, data->fields[RULE_TO], TRUE,
                             rule.from_year);
  if (rule.to_year == YEAR_MINIMUM) {
    fprintf (stderr, "%s:%i: Invalid Rule TO value: %s\n",
             data->filename, data->line_number, data->fields[RULE_TO]);
    exit (1);
  }

  /* We also want to know the maximum year used in any TO/FROM value, so we
     know where to expand all the infinite Rule data to. */
  if (rule.to_year != YEAR_MAXIMUM)
    data->max_until_year = MAX (data->max_until_year, rule.to_year);
  else if (rule.from_year != YEAR_MINIMUM)
    data->max_until_year = MAX (data->max_until_year, rule.from_year);

  if (!strcmp (data->fields[RULE_TYPE], "-"))
    rule.type = NULL;
  else {
    printf ("Type: %s\n", data->fields[RULE_TYPE]);
    rule.type = g_strdup (data->fields[RULE_TYPE]);
  }

  rule.in_month = parse_month (data, data->fields[RULE_IN]);
  rule.on_day_code = parse_day (data, data->fields[RULE_ON],
                                &rule.on_day_number, &rule.on_day_weekday);
  rule.at_time_seconds = parse_time (data, data->fields[RULE_AT],
                                     &rule.at_time_code);
  rule.save_seconds = parse_time (data, data->fields[RULE_SAVE], &time_code);

  if (!strcmp (data->fields[RULE_LETTER_S], "-")) {
    rule.letter_s = NULL;
  } else {
    rule.letter_s = g_strdup (data->fields[RULE_LETTER_S]);
  }

  rule.is_shallow_copy = FALSE;

  g_array_append_val (rule_array, rule);
}
예제 #5
0
static gboolean
parse_zone_common               (ParsingData    *data,
                                 int             offset)
{
  ZoneData *zone;
  ZoneLineData zone_line;
  TimeCode time_code;

  zone_line.stdoff_seconds = parse_time (data,
                                         data->fields[ZONE_GMTOFF + offset],
                                         &time_code);
  zone_line.save_seconds = parse_rules_save (data,
                                             data->fields[ZONE_RULES_SAVE + offset],
                                             &zone_line.rules);

  if (!VzicPureOutput) {
    /* We round the UTC offsets to the nearest minute, to be compatible with
       Outlook. This also works with -ve numbers, I think.
       -56 % 60 = -59. -61 % 60 = -1. */
    if (zone_line.stdoff_seconds >= 0)
      zone_line.stdoff_seconds += 30;
    else
      zone_line.stdoff_seconds -= 29;
    zone_line.stdoff_seconds -= zone_line.stdoff_seconds % 60;

    if (zone_line.save_seconds >= 0)
      zone_line.save_seconds += 30;
    else
      zone_line.save_seconds -= 29;
    zone_line.save_seconds -= zone_line.save_seconds % 60;
  }

  zone_line.format = g_strdup (data->fields[ZONE_FORMAT + offset]);

  if (data->num_fields - offset >= 6) {
    zone_line.until_set = TRUE;
    zone_line.until_year = parse_year (data,
                                       data->fields[ZONE_UNTIL_YEAR + offset],
                                       FALSE, 0);
    zone_line.until_month = parse_month (data,
                                         data->fields[ZONE_UNTIL_MONTH + offset]);
    zone_line.until_day_code = parse_day (data,
                                          data->fields[ZONE_UNTIL_DAY + offset],
                                          &zone_line.until_day_number,
                                          &zone_line.until_day_weekday);
    zone_line.until_time_seconds = parse_time (data,
                                               data->fields[ZONE_UNTIL_TIME + offset],
                                               &zone_line.until_time_code);

    /* We also want to know the maximum year used in any UNTIL value, so we
       know where to expand all the infinite Rule data to. */
    if (zone_line.until_year != YEAR_MAXIMUM
        && zone_line.until_year != YEAR_MINIMUM)
      data->max_until_year = MAX (data->max_until_year, zone_line.until_year);

  } else {
    zone_line.until_set = FALSE;
  }

  /* Append it to the last Zone, since that is the one we are currently
     reading. */
  zone = &g_array_index (data->zone_data, ZoneData, data->zone_data->len - 1);
  g_array_append_val (zone->zone_line_data, zone_line);

  return zone_line.until_set;
}
예제 #6
0
파일: cookie.cpp 프로젝트: Donny2g/hprose
 std::time_t parse_rfc_datetime(std::string value)
 {
     boost::replace_all(value, " -", " #");
     std::replace(value.begin(), value.end(), '-', ' ');
     boost::replace_all(value, " #", " -");
     std::tm t;
     memset(&t, 0, sizeof(std::tm));
     int x, zone = 0;
     std::string s;
     std::string::size_type pos;
     while (!value.empty())
     {
         pos = value.find(' ');
         if (pos != std::string::npos)
         {
             s = value.substr(0, pos);
             value.erase(0, pos + 1);
         }
         else
         {
             s = value;
             value.clear();
         }
         std::transform(s.begin(), s.end(), s.begin(), toupper);
         if (parse_timezone(s, zone)) continue;
         if ((x = atoi(s.c_str())) > 0)
         {
             if ((x < 32) && (!t.tm_mday))
             {
                 t.tm_mday = x;
                 continue;
             }
             else
             {
                 if ((!t.tm_year) && (t.tm_mon || (x > 12)))
                 {
                     if (x < 32)
                     {
                         t.tm_year = x + 100;
                     }
                     else if (x < 1000)
                     {
                         t.tm_year = x;
                     }
                     else
                     {
                         t.tm_year = x - 1900;
                     }
                     continue;
                 }
             }
         }
         std::string::size_type first, last;
         if ((first = s.find_first_of(':')) < (last = s.find_last_of(':')))
         {
             t.tm_hour = atoi(s.substr(0, first).c_str());
             t.tm_min = atoi(s.substr(first + 1, last).c_str());
             t.tm_sec = atoi(s.substr(last + 1).c_str());
             continue;
         }
         if (s == "DST")
         {
             t.tm_isdst = true;
             continue;
         }
         if (parse_month(s, x) && (!t.tm_mon))
         {
             t.tm_mon = x;
         }
     }
     if (!t.tm_year)
     {
         t.tm_year = 80;
     }
     if (t.tm_mon > 11)
     {
         t.tm_mon = 11;
     }
     if (!t.tm_mday)
     {
         t.tm_mday = 1;
     }
     t.tm_sec -= (zone + ctime::timezone());
     return mktime(&t);
 }
예제 #7
0
/**
 * tracker_date_guess:
 * @date_string: the date in a string pointer
 *
 * This function uses a number of methods to try and guess the date
 * held in @date_string. The @date_string must be at least 5
 * characters in length or longer for any guessing to be attempted.
 * Some of the string formats guessed include:
 *
 * <itemizedlist>
 *  <listitem><para>"YYYY-MM-DD" (Simple format)</para></listitem>
 *  <listitem><para>"20050315113224-08'00'" (PDF format)</para></listitem>
 *  <listitem><para>"20050216111533Z" (PDF format)</para></listitem>
 *  <listitem><para>"Mon Feb  9 10:10:00 2004" (Microsoft Office format)</para></listitem>
 *  <listitem><para>"2005:04:29 14:56:54" (Exif format)</para></listitem>
 *  <listitem><para>"YYYY-MM-DDThh:mm:ss.ff+zz:zz</para></listitem>
 * </itemizedlist>
 *
 * Returns: a newly-allocated string with the time represented in
 * ISO8601 date format which should be freed with g_free() when
 * finished with, otherwise %NULL.
 *
 * Since: 0.8
 **/
gchar *
tracker_date_guess (const gchar *date_string)
{
	gchar buf[30];
	gint  len;
	GError *error = NULL;

	if (!date_string) {
		return NULL;
	}

	len = strlen (date_string);

	/* We cannot format a date without at least a four digit
	 * year.
	 */
	if (len < 4) {
		return NULL;
	}

	/* Check for year only dates (EG ID3 music tags might have
	 * Audio.ReleaseDate as 4 digit year)
	 */
	if (len == 4) {
		if (is_int (date_string)) {
			buf[0] = date_string[0];
			buf[1] = date_string[1];
			buf[2] = date_string[2];
			buf[3] = date_string[3];
			buf[4] = '-';
			buf[5] = '0';
			buf[6] = '1';
			buf[7] = '-';
			buf[8] = '0';
			buf[9] = '1';
			buf[10] = 'T';
			buf[11] = '0';
			buf[12] = '0';
			buf[13] = ':';
			buf[14] = '0';
			buf[15] = '0';
			buf[16] = ':';
			buf[17] = '0';
			buf[18] = '0';
			buf[19] = 'Z';
			buf[20] = '\0';

			tracker_string_to_date (buf, NULL, &error);

			if (error != NULL) {
				g_error_free (error);
				return NULL;
			}

			return g_strdup (buf);
		} else {
			return NULL;
		}
	} else if (len == 10)  {
		/* Check for date part only YYYY-MM-DD */
		buf[0] = date_string[0];
		buf[1] = date_string[1];
		buf[2] = date_string[2];
		buf[3] = date_string[3];
		buf[4] = '-';
		buf[5] = date_string[5];
		buf[6] = date_string[6];
		buf[7] = '-';
		buf[8] = date_string[8];
		buf[9] = date_string[9];
		buf[10] = 'T';
		buf[11] = '0';
		buf[12] = '0';
		buf[13] = ':';
		buf[14] = '0';
		buf[15] = '0';
		buf[16] = ':';
		buf[17] = '0';
		buf[18] = '0';
		buf[19] = '\0';

		tracker_string_to_date (buf, NULL, &error);

		if (error != NULL) {
			g_error_free (error);
			return NULL;
		}

		return g_strdup (buf);
	} else if (len == 14) {
		/* Check for pdf format EG 20050315113224-08'00' or
		 * 20050216111533Z
		 */
		buf[0] = date_string[0];
		buf[1] = date_string[1];
		buf[2] = date_string[2];
		buf[3] = date_string[3];
		buf[4] = '-';
		buf[5] = date_string[4];
		buf[6] = date_string[5];
		buf[7] = '-';
		buf[8] = date_string[6];
		buf[9] = date_string[7];
		buf[10] = 'T';
		buf[11] = date_string[8];
		buf[12] = date_string[9];
		buf[13] = ':';
		buf[14] = date_string[10];
		buf[15] = date_string[11];
		buf[16] = ':';
		buf[17] = date_string[12];
		buf[18] = date_string[13];
		buf[19] = '\0';

		tracker_string_to_date (buf, NULL, &error);

		if (error != NULL) {
			g_error_free (error);
			return NULL;
		}

		return g_strdup (buf);
	} else if (len == 15 && date_string[14] == 'Z') {
		buf[0] = date_string[0];
		buf[1] = date_string[1];
		buf[2] = date_string[2];
		buf[3] = date_string[3];
		buf[4] = '-';
		buf[5] = date_string[4];
		buf[6] = date_string[5];
		buf[7] = '-';
		buf[8] = date_string[6];
		buf[9] = date_string[7];
		buf[10] = 'T';
		buf[11] = date_string[8];
		buf[12] = date_string[9];
		buf[13] = ':';
		buf[14] = date_string[10];
		buf[15] = date_string[11];
		buf[16] = ':';
		buf[17] = date_string[12];
		buf[18] = date_string[13];
		buf[19] = 'Z';
		buf[20] = '\0';

		tracker_string_to_date (buf, NULL, &error);

		if (error != NULL) {
			g_error_free (error);
			return NULL;
		}

		return g_strdup (buf);
	} else if (len == 21 && (date_string[14] == '-' || date_string[14] == '+' )) {
		buf[0] = date_string[0];
		buf[1] = date_string[1];
		buf[2] = date_string[2];
		buf[3] = date_string[3];
		buf[4] = '-';
		buf[5] = date_string[4];
		buf[6] = date_string[5];
		buf[7] = '-';
		buf[8] = date_string[6];
		buf[9] = date_string[7];
		buf[10] = 'T';
		buf[11] = date_string[8];
		buf[12] = date_string[9];
		buf[13] = ':';
		buf[14] = date_string[10];
		buf[15] = date_string[11];
		buf[16] = ':';
		buf[17] = date_string[12];
		buf[18] = date_string[13];
		buf[19] = date_string[14];
		buf[20] = date_string[15];
		buf[21] = date_string[16];
		buf[22] =  ':';
		buf[23] = date_string[18];
		buf[24] = date_string[19];
		buf[25] = '\0';

		tracker_string_to_date (buf, NULL, &error);

		if (error != NULL) {
			g_error_free (error);
			return NULL;
		}

		return g_strdup (buf);
	} else if ((len == 24) && (date_string[3] == ' ')) {
		/* Check for msoffice date format "Mon Feb  9 10:10:00 2004" */
		gint  num_month;
		gchar mon1;
		gchar day1;

		num_month = parse_month (date_string + 4);

		if (num_month < 0) {
			return NULL;
		}

		mon1 = imonths[num_month];

		if (date_string[8] == ' ') {
			day1 = '0';
		} else {
			day1 = date_string[8];
		}

		buf[0] = date_string[20];
		buf[1] = date_string[21];
		buf[2] = date_string[22];
		buf[3] = date_string[23];
		buf[4] = '-';

		if (num_month < 10) {
			buf[5] = '0';
			buf[6] = mon1;
		} else {
			buf[5] = '1';
			buf[6] = mon1;
		}

		buf[7] = '-';
		buf[8] = day1;
		buf[9] = date_string[9];
		buf[10] = 'T';
		buf[11] = date_string[11];
		buf[12] = date_string[12];
		buf[13] = ':';
		buf[14] = date_string[14];
		buf[15] = date_string[15];
		buf[16] = ':';
		buf[17] = date_string[17];
		buf[18] = date_string[18];
		buf[19] = '\0';

		tracker_string_to_date (buf, NULL, &error);

		if (error != NULL) {
			g_error_free (error);
			return NULL;
		}

		return g_strdup (buf);
	} else if ((len == 19) && (date_string[4] == ':') && (date_string[7] == ':')) {
		/* Check for Exif date format "2005:04:29 14:56:54" */
		buf[0] = date_string[0];
		buf[1] = date_string[1];
		buf[2] = date_string[2];
		buf[3] = date_string[3];
		buf[4] = '-';
		buf[5] = date_string[5];
		buf[6] = date_string[6];
		buf[7] = '-';
		buf[8] = date_string[8];
		buf[9] = date_string[9];
		buf[10] = 'T';
		buf[11] = date_string[11];
		buf[12] = date_string[12];
		buf[13] = ':';
		buf[14] = date_string[14];
		buf[15] = date_string[15];
		buf[16] = ':';
		buf[17] = date_string[17];
		buf[18] = date_string[18];
		buf[19] = '\0';

		tracker_string_to_date (buf, NULL, &error);

		if (error != NULL) {
			g_error_free (error);
			return NULL;
		}

		return g_strdup (buf);
	} 

	tracker_string_to_date (date_string, NULL, &error);

	if (error != NULL) {
		g_error_free (error);
		return NULL;
	}

	return g_strdup (date_string);
}
예제 #8
0
파일: parse.c 프로젝트: rkd77/elinks-tv
static struct ftp_file_info *
parse_ftp_unix_response(struct ftp_file_info *info, unsigned char *src, int len)
{
	unsigned char *end = src + len;
	unsigned char *pos;
	struct tm mtime;
	enum ftp_unix fact;

	/* Decide the file type. */
	{
		int type = (int)*src++;

		switch (type) {
		case FTP_FILE_PLAINFILE:
		case FTP_FILE_DIRECTORY:
		case FTP_FILE_SYMLINK:
			info->type = type;
			break;

		default:
			info->type = FTP_FILE_UNKNOWN;
		}
	}

	memset(&mtime, 0, sizeof(mtime));
	mtime.tm_isdst = -1;

	/* Following is only needed to handle NetWare listings which are not
	 * (yet) handled. So disabled for now. --Zas */
	/* skip_space_end(src, end); */

	fact = FTP_UNIX_PERMISSIONS;

	for (pos = src; src < end; src = pos) {
		skip_nonspace_end(pos, end);

		switch (fact) {
		case FTP_UNIX_PERMISSIONS:
			/* We wanna know permissions as well! And I decided to
			 * completely ignore the NetWare perms, they are very
			 * rare and of some nonstandart format.  If you want
			 * them, though, I'll accept patch enabling them.
			 * --pasky */
			if (pos - src == 9)	/* 9 is length of "rwxrwxrwx". */
				info->permissions = parse_ftp_unix_permissions(src, 9);
			fact = FTP_UNIX_SIZE;
			break;

		case FTP_UNIX_SIZE:
			/* Search for the size and month name combo: */
			if (info->size != FTP_SIZE_UNKNOWN
			    && pos - src == 3) {
				int month = parse_month((const unsigned char **) &src, pos);

				if (month != -1) {
					fact = FTP_UNIX_DAY;
					mtime.tm_mon = month;
					break;
				}
			}

			if (!isdigit(*src)) {
				info->size = FTP_SIZE_UNKNOWN;
				break;
			}

			info->size = parse_ftp_number(&src, pos, 0, OFFT_MAX);
			break;

		case FTP_UNIX_DAY:
			mtime.tm_mday = parse_day((const unsigned char **) &src, pos);
			fact = FTP_UNIX_TIME;
			break;

		case FTP_UNIX_TIME:
			/* This ought to be either the time, or the
			 * year. Let's be flexible! */
			fact = FTP_UNIX_NAME;

			/* We must deal with digits.  */
			if (!isdigit (*src))
				break;

			/* If we have a number x, it's a year. If we have x:y,
			 * it's hours and minutes. */
			if (!memchr(src, ':', pos - src)) {
				mtime.tm_year = parse_year((const unsigned char **) &src, pos);
				break;
			}

			if (!parse_time((const unsigned char **) &src, &mtime, pos)) {
				mtime.tm_hour = mtime.tm_min = mtime.tm_sec = 0;
			}
			break;

		case FTP_UNIX_NAME:
			/* Since the file name may contain spaces use @end as the
			 * token ending and not @pos. */

			info->name.source = src;
			info->name.length = end - src;

			/* Some FTP sites choose to have ls -F as their default
			 * LIST output, which marks the symlinks with a trailing
			 * `@', directory names with a trailing `/' and
			 * executables with a trailing `*'. This is no problem
			 * unless encountering a symbolic link ending with `@',
			 * or an executable ending with `*' on a server without
			 * default -F output. I believe these cases are very
			 * rare. */

#define check_trailing_char(string, trailchar) \
	((string)->length > 0 \
	 && (string)->source[(string)->length - 1] == (trailchar))

			switch (info->type) {
			case FTP_FILE_DIRECTORY:
				/* Check for trailing `/' */
				if (check_trailing_char(&info->name, '/'))
					info->name.length--;
				break;

			case FTP_FILE_SYMLINK:
				/* If the file is a symbolic link, it should
				 * have a ` -> ' somewhere. */
				while (pos && pos + 3 < end) {
					if (!memcmp(pos, " -> ", 4)) {
						info->symlink.source = pos + 4;
						info->symlink.length = end - pos - 4;
						info->name.length = pos - src;
						break;
					}

					pos = (unsigned char *)memchr(pos + 1, ' ', end - pos);
				}

				if (!info->symlink.source)
					return NULL;

				/* Check for trailing `@' on link and trailing
				 * `/' on the link target if it's a directory */
				if (check_trailing_char(&info->name, '@'))
					info->name.length--;

				if (check_trailing_char(&info->symlink, '/'))
					info->symlink.length--;
				break;

			case FTP_FILE_PLAINFILE:
				/* Check for trailing `*' on files which are
				 * executable. */
				if ((info->permissions & 0111)
				    && check_trailing_char(&info->name, '*'))
					info->name.length--;

			default:
				break;
			}

			if (mtime.tm_year == 0) {
				/* Get the current time.  */
				time_t timenow = time(NULL);
				struct tm *now = localtime(&timenow);

				mtime.tm_year = now->tm_year;

				/* Some listings will not specify the year if it
				 * is "obvious" that the file was from the
				 * previous year. E.g. if today is 97-01-12, and
				 * you see a file of Dec 15th, its year is 1996,
				 * not 1997. Thanks to Vladimir Volovich for
				 * mentioning this! */
				if (mtime.tm_mon > now->tm_mon)
					mtime.tm_year--;
			}

			info->mtime = mktime(&mtime); /* store the time-stamp */
			info->local_time_zone = 1;

			return info;
		}

		skip_space_end(pos, end);
	}

	return NULL;
}
예제 #9
0
파일: Twitter.cpp 프로젝트: 0x27/mrw-code
long
Twitter::parse_date(char *date)
{
  tmElements_t tm;
  char *cp;
  char *end;

  memset(&tm, 0, sizeof(tm));

  /* We could use sscanf to parse the date string but it adds 26 bytes
     to our SRAM consumption so let's use this adhoc parser. */

  for (cp = date; *cp && *cp != ','; cp++)
    ;

  if (*cp != ',')
    return 0;

  tm.Day = strtol(++cp, &end, 10);

  if (end == cp)
    return 0;

  cp = end;

  for (; *cp && *cp == ' '; cp++)
    ;
  if (!*cp)
    return 0;

  tm.Month = parse_month(cp, &end);
  if (tm.Month <= 0)
    return 0;

  cp = end + 1;

  tm.Year = strtol(cp, &end, 10) - 1970;

  if (end == cp)
    return 0;

  cp = end + 1;

  tm.Hour = strtol(cp, &end, 10);

  if (end == cp)
    return 0;

  cp = end + 1;

  tm.Minute = strtol(cp, &end, 10);

  if (end == cp)
    return 0;

  cp = end + 1;

  tm.Second = strtol(cp, &end, 10);

  if (end == cp)
    return 0;

  return makeTime(tm);
}
예제 #10
0
struct ftp_file_info *parse_ftp_file_info( struct ftp_file_info *info, unsigned char *src, int len )
{
  int eax;
  int ecx;
  int edx;
  int dh;
  if ( assert_failed == 0 )
  {
    if ( src[0] && info && len >= 1 )
    {
      assert_failed = 0;
      if ( src[0] < 'd' )
        len = len;
        if ( src[0] == 'p' || src[0] == 's' || src[0] == 'l' )
        {
          if ( src[0] == 'd' || src[0] == 'l' || src[0] == '-' )
            info[0].type = src[0];
          else
            info[0].type = FTP_FILE_UNKNOWN;
          memset( ebp_76, 0, 44 );
          if ( src[1] < src[ len ] )
          {
            while ( src[ len ] <= edi + 1 )
            {
              switch ( 0 )
              {
              case 0:
                if ( ebx - eax == 9 )
                {
                  if ( eax != '-' )
                  {
                    if ( ecx != 'r' )
                    {
                      info->permissions = edx;
                      while ( ebx < esi )
                      {
                        if ( ebx != ' ' )
                        {
                          break;
                        }
                        else
                        {
                        }
                      }
                      break;
                    }
                  }
                  else
                  {
                  }
                  if ( src[1] != '-' )
                  {
                    if ( src[1] == 'w' )
                    {
                    }
                  }
                  if ( src[2] != 's' )
                  {
                    if ( ccdep1 < ccdep2 )
                    {
                      if ( info->name.length/*.1_1of4*/ != 'x' )
                        continue;
                    }
                    else
                    if ( src[2] != '-' )
                    {
                      if ( src[2] == 'S' )
                      {
                        if ( src[3] != '-' )
                        {
                          if ( src[3] == 'r' )
                          {
                          }
                        }
                        if ( src[4] != '-' )
                        {
                          if ( src[4] == 'w' )
                          {
                          }
                        }
                        if ( src[5] != 's' )
                        {
                          if ( ccdep1 < ccdep2 )
                          {
                            if ( info->name.length/*.1_1of4*/ == 'x' )
                            {
                            }
                          }
                          else
                          if ( src[5] != '-' )
                          {
                            if ( src[5] == 'S' )
                            {
                              if ( src[6] != '-' )
                              {
                                if ( src[6] == 'r' )
                                {
                                }
                              }
                              if ( src[7] != '-' )
                              {
                                if ( src[7] == 'w' )
                                {
                                }
                              }
                              if ( src[8] != 'l' )
                              {
                                if ( ccdep1 < ccdep2 )
                                {
                                  if ( info->name.length/*.1_1of4*/ != 't' )
                                  {
                                    if ( info->name.length/*.1_1of4*/ != 'x' )
                                      continue;
                                  }
                                  else
                                  {
                                  }
                                  edx |= 1;
                                }
                                else
                                if ( src[8] != 'L' )
                                {
                                  if ( src[8] != 'T' )
                                  {
                                    if ( src[8] == '-' )
                                    {
                                    }
                                  }
                                  else
                                  {
                                  }
                                }
                              }
                              edx &= -9;
                            }
                          }
                        }
                        else
                        {
                        }
                      }
                    }
                  }
                  else
                  {
                  }
                }
                break;
              case 1:
                if ( ( (unsigned int)(info->size << 32) & (unsigned int)(info->size & 0xFFFFFFFF) ) != -1 && ebx - eax == 3 && parse_month( ebp_28, (unsigned char*)info ) != -1 )
                {
                }
                else
                {
                  if ( *ebp_28 - 48 < 9 )
                  {
                    info->size = (long long)-1;
                  }
                  else
                  {
                    if ( ecx < ebx )
                    {
                      do
                      {
                      }
                      while ( ecx + 1 < edi && ecx - 48 >= 9 );
                      ebp_136 = ebp_136;
                      if ( ebp_132 < 0 )
                      {
                      }
                    }
                    else
                    {
                    }
                    info->size = (long long)0;
                  }
                }
                break;
              case 2:
                break;
              case 3:
                if ( eax - 48 >= 9 )
                {
                  if ( eax == 0 )
                  {
                  }
                  else
                  {
                    if ( eax == 0 )
                    {
                    }
                  }
                }
                break;
              case 4:
                info->name.source = (unsigned char*)eax;
                info->name.length = esi - ebp_28;
                if ( info[0].type == 100 )
                {
                  if ( esi >= 1 && *(char*)(( esi + eax ) - 1) == '/' )
                    info->name.length = esi - 1;
                }
                else
                if ( info[0].type != 108 )
                {
                  if ( info[0].type == 45 && ( ( info->permissions/*.1_1of4*/ & 73 ) & 255 ) && len - src >= 1 && *(char*)(( ( len - src ) + info->name.source ) - 1) == '*' )
                    info->name.length = len - src - 1;
                }
                else
                {
                  if ( ebx )
                  {
                    if ( ebx + 3 < edx )
                    {
                      ebx = ebx;
                      do
                      {
                        strcmp( " -&gt; ", (char*)eax );
                        if ( 1 )
                        {
                          info->symlink.source = eax + 4;
                          info->symlink.length = ebx - 4 - eax;
                          info->name.length = eax - ebp_28;
                          if ( eax == 0 )
                            break;
                          if ( info->name.length >= 1 && *(char*)(( info->name.length + *(int*)(info + 4) ) - 1) == '@' )
                            info->name.length = parse_month( ebp_28, (unsigned char*)info ) - 1;
                          if ( info->symlink.length >= 1 && *(char*)(( info->symlink.length + *(int*)(info + 12) ) - 1) == '/' )
                            info->symlink.length--;
                        }
                        else
                        {
                          if ( eax == 0 )
                            goto B223;
                          else
                        }
                      }
                      while ( ebx <= eax + 3 );
                    }
                    info->symlink.source = info->symlink.source;
                  }
B223:                  info->symlink.source = info->symlink.source;
                }
                if ( !ebp_56 && *(int*)(localtime( ebp_32 ) + 16) < ebp_60 )
                {
                }
                info->bits_at_32/*.1_1of4*/ |= 1;
                info->mtime = mktime( ebp_76 );
                return info;
                break;
              default:
                break;
              }
            }
            do
            {
            }
            while ( edi != ' ' && edi + 1 < ebp_104 );
            switch ( 0 )
            {
            case 0:
              break;
            case 1:
              break;
            case 2:
              break;
            case 3:
              break;
            case 4:
              break;
            default:
              break;
            }
          }
          else
          {
            info = 0;
            return info;
          }
        }
예제 #11
0
int parse_time(const char *buf, int offset, int len, time_t * time_return)
{
	struct tm tm;
	time_t t;
	int i = offset;

	i = skip_word(buf, i, len);
	if (i < 0)
		return -1;
	i = skip_separator(buf, i, len);
	if (i < 0)
		return -1;

	if (i >= len)
		return -1;

	if (d2i(buf[i]) >= 0) {
		i = parse_int(buf, i, len, &tm.tm_mday);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_month(buf, i, len, &tm.tm_mon);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_year);
		if (i < 0)
			return -1;
		if (tm.tm_year < 100)
			tm.tm_year += 1900;
		if (tm.tm_year < 1937)
			tm.tm_year += 100;
		if (tm.tm_year < 1937)
			return -1;

		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_hour);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_min);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_sec);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = skip_word(buf, i, len);
		if (i < 0)
			return -1;
	} else {		
		i = parse_month(buf, i, len, &tm.tm_mon);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_mday);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_hour);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_min);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_sec);
		if (i < 0)
			return -1;
		i = skip_separator(buf, i, len);
		if (i < 0)
			return -1;
		i = parse_int(buf, i, len, &tm.tm_year);
		if (i < 0)
			return -1;
		if (tm.tm_year < 100)
			tm.tm_year += 1900;
		if (tm.tm_year < 1937)
			tm.tm_year += 100;
		if (tm.tm_year < 1937 || tm.tm_year > 2040)
			return -1;
	}

	if (tm.tm_year < 2038) {
		tm.tm_year -= 1900;
		tm.tm_isdst = -1;
		t = mktime_gmt(&tm);
		if (t == -1)
			return -1;
	} else {
		t = time_t_max;
	}

	*time_return = t;
	return i;
}