Ejemplo n.º 1
0
void CDateTime::set(unsigned year, unsigned month, unsigned day, unsigned hour, unsigned minute, unsigned second, unsigned nano, bool local)
{
    if(local)
    {
        struct tm local;
        local.tm_year = year - 1900;
        local.tm_mon = month - 1;
        local.tm_mday = day;
        local.tm_hour = hour;
        local.tm_min = minute;
        local.tm_sec = second;
        local.tm_isdst = -1;
        local.tm_wday = 0;
        local.tm_yday = 0;
        time_t simple = timelocal(&local);
        set(simple);
    }
    else
    {
        utc_year = year - 1900;
        utc_mon = month - 1;
        utc_mday = day;
        utc_hour = hour;
        utc_min = minute;
        utc_sec = second;
    }
    nanosec = nano;
}
Ejemplo n.º 2
0
Archivo: time.c Proyecto: DeadZen/qse
int qse_timelocal (const qse_btime_t* bt, qse_ntime_t* nt)
{
	/* TODO: qse_timelocal - remove dependency on timelocal */
	struct tm tm;

	QSE_MEMSET (&tm, 0, QSE_SIZEOF(tm));
	tm.tm_sec = bt->sec;
	tm.tm_min = bt->min;
	tm.tm_hour = bt->hour;
	tm.tm_mday = bt->mday;
	tm.tm_mon = bt->mon;
	tm.tm_year = bt->year;
	tm.tm_wday = bt->wday;
	tm.tm_yday = bt->yday;
	tm.tm_isdst = bt->isdst;

#if defined(HAVE_TIMELOCAL)
	nt->sec = timelocal (&tm);
#else
	nt->sec = mktime (&tm);
#endif

	nt->nsec = 0;
	return 0;
}
Ejemplo n.º 3
0
/******************************************************************************
  * version:    1.0
  * author:     link
  * date:       2015.11.10
  * brief:      设置系统时间
******************************************************************************/
int LINUX_RTC::set_rtc(rtc_time rtc_tm)
{
    int 				ret;
    int  				rtc_fd;
    time_t 				t1;

    rtc_tm.tm_year -= 1900;                     //年从1900开始
    rtc_tm.tm_mon -= 1;                         //月从0开始

    rtc_fd = open("/dev/rtc0", O_RDWR, 0);      //打开RTC
    if (rtc_fd == -1){
        printf("/dev/rtc0 open error\n");
        return -1;
    }

    t1 = timelocal((tm*)&rtc_tm);             //设置系统时间
    stime(&t1);

    ret = ioctl(rtc_fd, RTC_SET_TIME, &rtc_tm); //设置RTC时间
    if (ret == -1){
        printf("rtc ioctl RTC_SET_TIME error\r\n");
        return -1;
    }

    close(rtc_fd);                              //关闭RTC

    return 0;
}
Ejemplo n.º 4
0
int CDateTime::queryUtcToLocalDelta() const
{
    struct tm ts;
    getToUtcTm(ts);
    time_t correct = timegm(&ts);
    time_t shifted = timelocal(&ts);
    return ((int)(correct - shifted))/60;
}
Ejemplo n.º 5
0
END_TEST

START_TEST(mosecs_does_not_change_struct_tm_pointer_content)
{
	struct tm *stm;
	time_t current;

	current = time(NULL);
	stm = localtime(&current);

	defaultcfg();
	ck_assert_int_eq(cfg.monthrotate, 1);
	ck_assert_int_eq(current, timelocal(stm));
	ck_assert_int_ne(mosecs(1, 2), 0);
	ck_assert_int_ne(mosecs(1, 2), 1);
	ck_assert_int_eq(current, timelocal(stm));
}
Ejemplo n.º 6
0
unsigned long long
mas_strtime2long( const char *s, int *pr )
{
  int rpr = 0;
  time_t t = 0;
  char *p = NULL;
  struct tm tm;

  {
    if ( !p )
    {
      memset( &tm, 0, sizeof( tm ) );
      p = strptime( s, "%Y-%m-%d %H:%M:%S", &tm );
    }
    if ( !p )
    {
      memset( &tm, 0, sizeof( tm ) );
      p = strptime( s, "%Y-%m-%d", &tm );
    }
    if ( !p )
    {
      memset( &tm, 0, sizeof( tm ) );
      p = strptime( s, "%Y%m%d.%H%M%S", &tm );
    }
    if ( !p )
    {
      memset( &tm, 0, sizeof( tm ) );
      p = strptime( s, "%Y%m%d.%H%M", &tm );
    }
    if ( !p )
    {
      memset( &tm, 0, sizeof( tm ) );
      p = strptime( s, "%Y%m%d.%H", &tm );
    }
    if ( !p )
    {
      memset( &tm, 0, sizeof( tm ) );
      p = strptime( s, "%Y%m%d", &tm );
    }
    tm.tm_zone = tzname[daylight];
    tm.tm_isdst = daylight;
    if ( p )
      t = timelocal( &tm );
    else
      rpr = -1;
  }
  if ( pr )
    *pr = rpr;
  return ( unsigned long long ) t;
}
Ejemplo n.º 7
0
static inline int ldap_gentime2db_datetime(time_t* dst, str* src)
{
	struct tm time;

	if (src->len < 12) return -1;

	/* It is necessary to zero tm structure first */
	memset(&time, '\0', sizeof(struct tm));
	/* YYYYMMDDHHMMSS[.sss][ 'Z' | ( {'+'|'-'} ZZZZ) ] */
	strptime(src->s, "%Y%m%d%H%M%S", &time);  /* Note: frac of seconds are lost in time_t representation */
	
	if (src->s[src->len-1] == 'Z' || src->s[src->len-5] == '-' || src->s[src->len-5] == '+') {
		/* GMT or specified TZ, no daylight saving time */
		#ifdef HAVE_TIMEGM
		*dst = timegm(&time);
		#else
		*dst = _timegm(&time);
		#endif /* HAVE_TIMEGM */

		if (src->s[src->len-1] != 'Z') {
			/* timezone is specified */
			memset(&time, '\0', sizeof(struct tm));
			strptime(src->s + src->len - 4, "%H%M", &time);
			switch (src->s[src->len-5]) {
				case '-':
					*dst -= time.tm_hour*3600+time.tm_min*60;
					break;
				case '+':
					*dst += time.tm_hour*3600+time.tm_min*60;
					break;
				default:
					;
			}
		}
	}
	else {
		/* it's local time */

		/* Daylight saving information got lost in the database
		 * so let timegm to guess it. This eliminates the bug when
		 * contacts reloaded from the database have different time
		 * of expiration by one hour when daylight saving is used
		 */
		time.tm_isdst = -1;
		*dst = timelocal(&time);
	}
	
	return 0;
}
Ejemplo n.º 8
0
BOOL
_putBlueDot(
        const MyClip *mp,
        char         *errorString,
        PARAM_PBM    *args
    )
{
    PARAM_BD        *param = (PARAM_BD *)(args->args);
    DELICIOUS_ENTRY entry;
    time_t          t;
    struct tm       tm, *tt;
    BOOL            ret = FALSE;

    errorString[0] = NUL;

    if ( mp->url[0] == NUL )
        return ( ret ); // 正常終了扱い

    any2sjisEx( entry.description, mp->title );
    any2sjisEx( entry.extended,    mp->comment );
    any2sjisEx( entry.tag,         mp->tags );

    strcpy( entry.url, mp->url );

    // Blue Dot の時間は PST(PDT)
    //  -- GMT → PDT 変換
    tm.tm_year = mp->yyyy - 1900;
    tm.tm_mon  = mp->mm - 1;
    tm.tm_mday = mp->dd;
    tm.tm_hour = mp->HH;
    tm.tm_min  = mp->MM;
    tm.tm_sec  = mp->SS;

    t = timelocal( &tm );
    t += 7 * 60 * 60;   /* GMT との時差 */
    tt = gmtime( &t );

    sprintf( entry.dateTime,
             "%04d-%02d-%02dT%02d:%02d:%02dZ",
             tt->tm_year + 1900, tt->tm_mon + 1, tt->tm_mday,
             tt->tm_hour, tt->tm_min, tt->tm_sec );

    entry.shared = (mp->publication == PUB_PRIVATE) ? FALSE : TRUE;

    ret = postEntryOnBlueDot( param->userName, param->password, &entry );

    return ( ret );
}
Ejemplo n.º 9
0
/*
 * get the difference in seconds between this time zone and UTC (GMT)
 */
JSInt32
PRMJ_LocalGMTDifference()
{
#if defined(XP_UNIX) || defined(XP_WIN) || defined(XP_OS2) || defined(XP_BEOS)
    struct tm ltime;

    /* get the difference between this time zone and GMT */
    memset((char *)&ltime,0,sizeof(ltime));
    ltime.tm_mday = 2;
    ltime.tm_year = 70;
#ifdef SUNOS4
    ltime.tm_zone = 0;
    ltime.tm_gmtoff = 0;
    return timelocal(&ltime) - (24 * 3600);
#else
    return mktime(&ltime) - (24L * 3600L);
#endif
#endif
#if defined(XP_MAC)
    static JSInt32   zone = -1L;
    MachineLocation  machineLocation;
    JSInt32 	     gmtOffsetSeconds;

    /* difference has been set no need to recalculate */
    if (zone != -1)
        return zone;

    /* Get the information about the local machine, including
     * its GMT offset and its daylight savings time info.
     * Convert each into wides that we can add to
     * startupTimeMicroSeconds.
     */

    MyReadLocation(&machineLocation);

    /* Mask off top eight bits of gmtDelta, sign extend lower three. */
    gmtOffsetSeconds = (machineLocation.u.gmtDelta << 8);
    gmtOffsetSeconds >>= 8;

    /* Backout OS adjustment for DST, to give consistent GMT offset. */
    if (machineLocation.u.dlsDelta != 0)
        gmtOffsetSeconds -= PRMJ_HOUR_SECONDS;
    return (zone = -gmtOffsetSeconds);
#endif
}
Ejemplo n.º 10
0
/*
 * get the difference in seconds between this time zone and UTC (GMT)
 */
JSInt32
PRMJ_LocalGMTDifference()
{
#if defined(XP_UNIX) || defined(XP_WIN) || defined(XP_OS2) || defined(XP_BEOS)
    struct tm ltime;

    /* get the difference between this time zone and GMT */
    memset((char *)&ltime,0,sizeof(ltime));
    ltime.tm_mday = 2;
    ltime.tm_year = 70;
#ifdef SUNOS4
    ltime.tm_zone = 0;
    ltime.tm_gmtoff = 0;
    return timelocal(&ltime) - (24 * 3600);
#else
    return mktime(&ltime) - (24L * 3600L);
#endif
#endif
}
Ejemplo n.º 11
0
const char *
mfn_convtime(MFUNARGS)
{
	struct tm otm;
	int mo, dy, yr, hr, mn, sc;

	yr = 70;
	mo = dy = 1;
	hr = mn = sc = 0;
	if (sscanf(argv[0], "%d:%d:%d %d/%d/%d", &hr, &mn, &sc, &mo, &dy, &yr) != 6)
		ABORT_MPI("CONVTIME", "Needs HH:MM:SS MO/DY/YR time string format.");
	if (hr < 0 || hr > 23)
		ABORT_MPI("CONVTIME", "Bad Hour");
	if (mn < 0 || mn > 59)
		ABORT_MPI("CONVTIME", "Bad Minute");
	if (sc < 0 || sc > 59)
		ABORT_MPI("CONVTIME", "Bad Second");
	if (yr < 0 || yr > 99)
		ABORT_MPI("CONVTIME", "Bad Year");
	if (mo < 1 || mo > 12)
		ABORT_MPI("CONVTIME", "Bad Month");
	if (dy < 1 || dy > 31)
		ABORT_MPI("CONVTIME", "Bad Day");
	otm.tm_mon = mo - 1;
	otm.tm_mday = dy;
	otm.tm_hour = hr;
	otm.tm_min = mn;
	otm.tm_sec = sc;
	otm.tm_year = (yr >= 70) ? yr : (yr + 100);
#ifdef SUNOS
	snprintf(buf, BUFFER_LEN, "%ld", timelocal(&otm));
#else
	snprintf(buf, BUFFER_LEN, "%ld", mktime(&otm));
#endif
	return buf;
}
Ejemplo n.º 12
0
/*
 * get the difference in seconds between this time zone and UTC (GMT)
 */
PR_IMPLEMENT(time_t) PRMJ_LocalGMTDifference()
{
#if defined(XP_UNIX) || defined(XP_PC)
    struct tm ltime;
    /* get the difference between this time zone and GMT */
    memset((char *)&ltime,0,sizeof(ltime));
    ltime.tm_mday = 2;
    ltime.tm_year = 70;
#ifdef SUNOS4
    ltime.tm_zone = 0;
    ltime.tm_gmtoff = 0;
    return timelocal(&ltime) - (24 * 3600);
#else
    return mktime(&ltime) - (24L * 3600L);
#endif
#endif
#if defined(XP_MAC)
    static time_t    zone = -1L;
    MachineLocation  machineLocation;
    PRUint64	     gmtOffsetSeconds;
    PRUint64	     gmtDelta;
    PRUint64	     dlsOffset;
    PRInt32	     offset;

    /* difference has been set no need to recalculate */
    if(zone != -1)
	return zone;

    /* Get the information about the local machine, including
     * its GMT offset and its daylight savings time info.
     * Convert each into wides that we can add to
     * startupTimeMicroSeconds.
     */

    MyReadLocation(&machineLocation);

    /* Mask off top eight bits of gmtDelta, sign extend lower three. */

    if ((machineLocation.u.gmtDelta & 0x00800000) != 0) {
	gmtOffsetSeconds.lo = (machineLocation.u.gmtDelta & 0x00FFFFFF) | 0xFF000000;
	gmtOffsetSeconds.hi = 0xFFFFFFFF;
	LL_UI2L(gmtDelta,0);
    }
    else {

	gmtOffsetSeconds.lo = (machineLocation.u.gmtDelta & 0x00FFFFFF);
	gmtOffsetSeconds.hi = 0;
	LL_UI2L(gmtDelta,PRMJ_DAY_SECONDS);
    }
    /* normalize time to be positive if you are behind GMT. gmtDelta will always
     * be positive.
     */
    LL_SUB(gmtDelta,gmtDelta,gmtOffsetSeconds);

    /* Is Daylight Savings On?  If so, we need to add an hour to the offset. */
    if (machineLocation.u.dlsDelta != 0) {
	LL_UI2L(dlsOffset, PRMJ_HOUR_SECONDS);
    }
    else
	LL_I2L(dlsOffset, 0);

    LL_ADD(gmtDelta,gmtDelta, dlsOffset);
    LL_L2I(offset,gmtDelta);

    zone = offset;
    return (time_t)offset;
#endif
}
Ejemplo n.º 13
0
/** Parses the buffer to extract the attribute-value pairs
 *
 * @param rh a handle to parsed configuration.
 * @param buffer the buffer to be parsed.
 * @param first_pair an allocated array of values.
 * @return 0 on successful parse of attribute-value pair, or -1 on syntax (or other) error detected.
 */
int rc_avpair_parse (rc_handle const *rh, char const *buffer, VALUE_PAIR **first_pair)
{
	int             mode;
	char            attrstr[AUTH_ID_LEN];
	char            valstr[AUTH_STRING_LEN + 1], *p;
	DICT_ATTR      *attr = NULL;
	DICT_VALUE     *dval;
	VALUE_PAIR     *pair;
	VALUE_PAIR     *link;
	struct tm      *tm;
	time_t          timeval;

	mode = PARSE_MODE_NAME;
	while (*buffer != '\n' && *buffer != '\0')
	{
		if (*buffer == ' ' || *buffer == '\t')
		{
			buffer++;
			continue;
		}

		switch (mode)
		{
		    case PARSE_MODE_NAME:		/* Attribute Name */
			rc_fieldcpy (attrstr, &buffer, " \t\n=,", sizeof(attrstr));
			if ((attr =
				rc_dict_findattr (rh, attrstr)) == NULL)
			{
				rc_log(LOG_ERR, "rc_avpair_parse: unknown attribute");
				if (*first_pair) {
					rc_avpair_free(*first_pair);
					*first_pair = NULL;
				}
				return -1;
			}
			mode = PARSE_MODE_EQUAL;
			break;

		    case PARSE_MODE_EQUAL:		/* Equal sign */
			if (*buffer == '=')
			{
				mode = PARSE_MODE_VALUE;
				buffer++;
			}
			else
			{
				rc_log(LOG_ERR, "rc_avpair_parse: missing or misplaced equal sign");
				if (*first_pair) {
					rc_avpair_free(*first_pair);
					*first_pair = NULL;
				}
				return -1;
			}
			break;

		    case PARSE_MODE_VALUE:		/* Value */
			rc_fieldcpy (valstr, &buffer, " \t\n,", sizeof(valstr));

			if ((pair = malloc (sizeof (VALUE_PAIR))) == NULL)
			{
				rc_log(LOG_CRIT, "rc_avpair_parse: out of memory");
				if (*first_pair) {
					rc_avpair_free(*first_pair);
					*first_pair = NULL;
				}
				return -1;
			}
			strcpy (pair->name, attr->name);
			pair->attribute = attr->value;
			pair->type = attr->type;

			switch (pair->type)
			{

			    case PW_TYPE_STRING:
				strcpy (pair->strvalue, valstr);
				pair->lvalue = (uint32_t)strlen(valstr);
				break;

			    case PW_TYPE_INTEGER:
				if (isdigit (*valstr))
				{
					pair->lvalue = atoi (valstr);
				}
				else
				{
					if ((dval = rc_dict_findval (rh, valstr))
							== NULL)
					{
						rc_log(LOG_ERR, "rc_avpair_parse: unknown attribute value: %s", valstr);
						if (*first_pair) {
							rc_avpair_free(*first_pair);
							*first_pair = NULL;
						}
						free (pair);
						return -1;
					}
					else
					{
						pair->lvalue = dval->value;
					}
				}
				break;

			    case PW_TYPE_IPADDR:
			    	if (inet_pton(AF_INET, valstr, &pair->lvalue) == 0) {
			    		rc_log(LOG_ERR, "rc_avpair_parse: invalid IPv4 address %s", valstr);
			    		free(pair);
			    		return -1;
			    	}

                                pair->lvalue = ntohl(pair->lvalue);
				break;

			    case PW_TYPE_IPV6ADDR:
			    	if (inet_pton(AF_INET6, valstr, pair->strvalue) == 0) {
			    		rc_log(LOG_ERR, "rc_avpair_parse: invalid IPv6 address %s", valstr);
			    		free(pair);
			    		return -1;
			    	}
				pair->lvalue = 16;
				break;

			    case PW_TYPE_IPV6PREFIX:
			    	p = strchr(valstr, '/');
			    	if (p == NULL) {
			    		rc_log(LOG_ERR, "rc_avpair_parse: invalid IPv6 prefix %s", valstr);
			    		free(pair);
			    		return -1;
			    	}
			    	*p = 0;
			    	p++;
			    	pair->strvalue[0] = 0;
			    	pair->strvalue[1] = atoi(p);

			    	if (inet_pton(AF_INET6, valstr, pair->strvalue+2) == 0) {
			    		rc_log(LOG_ERR, "rc_avpair_parse: invalid IPv6 prefix %s", valstr);
			    		free(pair);
			    		return -1;
			    	}
				pair->lvalue = 2+16;
				break;

			    case PW_TYPE_DATE:
				timeval = time (0);
				tm = localtime (&timeval);
				tm->tm_hour = 0;
				tm->tm_min = 0;
				tm->tm_sec = 0;
				rc_str2tm (valstr, tm);
#ifdef TIMELOCAL
				pair->lvalue = (uint32_t) timelocal (tm);
#else	/* TIMELOCAL */
				pair->lvalue = (uint32_t) mktime (tm);
#endif	/* TIMELOCAL */
				break;

			    default:
				rc_log(LOG_ERR, "rc_avpair_parse: unknown attribute type %d", pair->type);
				if (*first_pair) {
					rc_avpair_free(*first_pair);
					*first_pair = NULL;
				}
				free (pair);
				return -1;
			}

			/* XXX: Fix up Digest-Attributes */
			switch (pair->attribute) {
			case PW_DIGEST_REALM:
			case PW_DIGEST_NONCE:
			case PW_DIGEST_METHOD:
			case PW_DIGEST_URI:
			case PW_DIGEST_QOP:
			case PW_DIGEST_ALGORITHM:
			case PW_DIGEST_BODY_DIGEST:
			case PW_DIGEST_CNONCE:
			case PW_DIGEST_NONCE_COUNT:
			case PW_DIGEST_USER_NAME:
				/* overlapping! */
				if (pair->lvalue > AUTH_STRING_LEN - 2)
					pair->lvalue = AUTH_STRING_LEN - 2;
				memmove(&pair->strvalue[2], &pair->strvalue[0], pair->lvalue);
				pair->strvalue[0] = pair->attribute - PW_DIGEST_REALM + 1;
				pair->lvalue += 2;
				pair->strvalue[1] = pair->lvalue;
				pair->strvalue[pair->lvalue] = '\0';
				pair->attribute = PW_DIGEST_ATTRIBUTES;
			}

			pair->next = NULL;

			if (*first_pair == NULL)
			{
				*first_pair = pair;
			}
			else
			{
				link = *first_pair;
				while (link->next != NULL)
				{
					link = link->next;
				}
				link->next = pair;
			}

			mode = PARSE_MODE_NAME;
			break;

		    default:
			mode = PARSE_MODE_NAME;
			break;
		}
	}
	return 0;
}
Ejemplo n.º 14
0
int rc_avpair_parse (char *buffer, VALUE_PAIR **first_pair)
{
	int             mode;
	char            attrstr[AUTH_ID_LEN];
	char            valstr[AUTH_ID_LEN];
	DICT_ATTR      *attr = NULL;
	DICT_VALUE     *dval;
	VALUE_PAIR     *pair;
	VALUE_PAIR     *link;
	struct tm      *tm;
	time_t          timeval;

	mode = PARSE_MODE_NAME;
	while (*buffer != '\n' && *buffer != '\0')
	{
		if (*buffer == ' ' || *buffer == '\t')
		{
			buffer++;
			continue;
		}

		switch (mode)
		{
		    case PARSE_MODE_NAME:		/* Attribute Name */
			rc_fieldcpy (attrstr, &buffer);
			if ((attr =
				rc_dict_findattr (attrstr)) == (DICT_ATTR *) NULL)
			{
				error("rc_avpair_parse: unknown attribute");
				if (*first_pair) {
					rc_avpair_free(*first_pair);
					*first_pair = (VALUE_PAIR *) NULL;
				}
				return (-1);
			}
			mode = PARSE_MODE_EQUAL;
			break;

		    case PARSE_MODE_EQUAL:		/* Equal sign */
			if (*buffer == '=')
			{
				mode = PARSE_MODE_VALUE;
				buffer++;
			}
			else
			{
				error("rc_avpair_parse: missing or misplaced equal sign");
				if (*first_pair) {
					rc_avpair_free(*first_pair);
					*first_pair = (VALUE_PAIR *) NULL;
				}
				return (-1);
			}
			break;

		    case PARSE_MODE_VALUE:		/* Value */
			rc_fieldcpy (valstr, &buffer);

			if ((pair =
				(VALUE_PAIR *) malloc (sizeof (VALUE_PAIR)))
							== (VALUE_PAIR *) NULL)
			{
				novm("rc_avpair_parse");
				if (*first_pair) {
					rc_avpair_free(*first_pair);
					*first_pair = (VALUE_PAIR *) NULL;
				}
				return (-1);
			}
			strcpy (pair->name, attr->name);
			pair->attribute = attr->value;
			pair->type = attr->type;
			pair->vendorcode = attr->vendorcode;

			switch (pair->type)
			{

			    case PW_TYPE_STRING:
				strcpy ((char *)pair->strvalue, valstr);
				pair->lvalue = strlen(valstr);
				break;

			    case PW_TYPE_INTEGER:
				if (isdigit (*valstr))
				{
					pair->lvalue = atoi (valstr);
				}
				else
				{
					if ((dval = rc_dict_findval (valstr))
							== (DICT_VALUE *) NULL)
					{
						error("rc_avpair_parse: unknown attribute value: %s", valstr);
						if (*first_pair) {
							rc_avpair_free(*first_pair);
							*first_pair = (VALUE_PAIR *) NULL;
						}
						free (pair);
						return (-1);
					}
					else
					{
						pair->lvalue = dval->value;
					}
				}
				break;

			    case PW_TYPE_IPADDR:
				pair->lvalue = rc_get_ipaddr(valstr);
				break;

			    case PW_TYPE_DATE:
				timeval = time (0);
				tm = localtime (&timeval);
				tm->tm_hour = 0;
				tm->tm_min = 0;
				tm->tm_sec = 0;
				rc_str2tm (valstr, tm);
#ifdef TIMELOCAL
				pair->lvalue = (UINT4) timelocal (tm);
#else	/* TIMELOCAL */
				pair->lvalue = (UINT4) mktime (tm);
#endif	/* TIMELOCAL */
				break;

			    default:
				error("rc_avpair_parse: unknown attribute type %d", pair->type);
				if (*first_pair) {
					rc_avpair_free(*first_pair);
					*first_pair = (VALUE_PAIR *) NULL;
				}
				free (pair);
				return (-1);
			}
			pair->next = (VALUE_PAIR *) NULL;

			if (*first_pair == (VALUE_PAIR *) NULL)
			{
				*first_pair = pair;
			}
			else
			{
				link = *first_pair;
				while (link->next != (VALUE_PAIR *) NULL)
				{
					link = link->next;
				}
				link->next = pair;
			}

			mode = PARSE_MODE_NAME;
			break;

		    default:
			mode = PARSE_MODE_NAME;
			break;
		}
	}
	return (0);
}
Ejemplo n.º 15
0
/*      日時を表わす文字列から、年月日時分秒を取り出す */
time_t
getDateTimeFromDateString(
        const char *date,   /* (I) 日時情報(文字列) */
        int        *yyyy,   /* (O) 年               */
        int        *mm,     /* (O) 月               */
        int        *dd,     /* (O) 日               */
        int        *HH,     /* (O) 時               */
        int        *MM,     /* (O) 分               */
        int        *SS      /* (O) 秒               */
    )
{
    const char  *p = date;
    const char  *q;
    time_t      t = 0;
    struct tm   tm;
    int         i;
    int         dHH = 0, dMM = 0, d = 0;
    BOOL        found = FALSE;
    static char monStr[12][4] = {
        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    };

    *yyyy = 0;
    *mm   = 0;
    *dd   = 0;
    *HH   = 0;
    *MM   = 0;
    *SS   = 0;

    /* まず、「年月日」部分を処理 */
    for ( i = 0; i < 12; i++ ) {
        q = strstr( p, monStr[i] );
        if ( q                                 &&
             (*(q - 1) == ' ')                 &&
             (*(q + strlen(monStr[i])) == ' ')    ) {
            found = TRUE;
            break;
        }
    }
    if ( found ) {
        /* RFC 822 形式の日付の場合              */
        /*   例) Tue, 20 May 2003 08:56:02 GMT   */
        /*       20 May 2003 08:56:02 GMT        */
        /*       Tue, 20 May 2003 17:56:02 JST   */
        /*       Tue, 20 May 2003 17:56:02 +0900 */
        /*       Tue, 20 May 2003 17:56:02+0900  */
        /*       Wed, 06 Dec 2006 14:54:02 +0900 */
        /*       Wed, 6 Dec 2006 14:54:02 +0900  */
        while ( *p && ((*p < '0') || (*p > '9')) )
            p++;
        if ( (*p >= '0') && (*p <= '9') ) {
            *dd = *p - '0';
            p++;
            if ( (*p >= '0') && (*p <= '9') ) {
                *dd = *dd * 10 + (*p - '0');
                p++;
            }
        }

        while ( *p && ((*p < 'A') || (*p > 'Z')) )
            p++;
        *mm = i + 1;

        while ( *p && ((*p < '0') || (*p > '9')) )
            p++;
        if ( (*p >= '0') && (*p <= '9') ) {
            *yyyy = *p - '0';
            p++;
            if ( (*p >= '0') && (*p <= '9') ) {
                *yyyy = *yyyy * 10 + (*p - '0');
                p++;
            }
            if ( (*p >= '0') && (*p <= '9') ) {
                *yyyy = *yyyy * 10 + (*p - '0');
                p++;
            }
            if ( (*p >= '0') && (*p <= '9') ) {
                *yyyy = *yyyy * 10 + (*p - '0');
                p++;
            }
        }

        while ( *p && ((*p < '0') || (*p > '9')) )
            p++;
    }
    else {
     // q = strchr( p, 'T' );
     // if ( q &&
     //      (*(q - 1) >= '0') && (*(q - 1) <= '9') &&
     //      (*(q + 1) >= '0') && (*(q + 1) <= '9')    ) {
            /* ISO8601 形式の日付の場合      */
            /* 例) 2003-12-03T23:59:59+09:00 */
            /*     2003-12-03T23:59:59Z      */
            while ( *p && ((*p < '0') || (*p > '9')) )
                p++;
            if ( (*p >= '0') && (*p <= '9') ) {
                *yyyy = *p - '0';
                p++;
                if ( (*p >= '0') && (*p <= '9') ) {
                    *yyyy = *yyyy * 10 + (*p - '0');
                    p++;
                }
                if ( (*p >= '0') && (*p <= '9') ) {
                    *yyyy = *yyyy * 10 + (*p - '0');
                    p++;
                }
                if ( (*p >= '0') && (*p <= '9') ) {
                    *yyyy = *yyyy * 10 + (*p - '0');
                    p++;
                }
            }

            while ( *p && ((*p < '0') || (*p > '9')) )
                p++;
            if ( (*p >= '0') && (*p <= '9') ) {
                *mm = *p - '0';
                p++;
                if ( (*p >= '0') && (*p <= '9') ) {
                    *mm = *mm * 10 + (*p - '0');
                    p++;
                }
            }

            while ( *p && ((*p < '0') || (*p > '9')) )
                p++;
            if ( (*p >= '0') && (*p <= '9') ) {
                *dd = *p - '0';
                p++;
                if ( (*p >= '0') && (*p <= '9') ) {
                    *dd = *dd * 10 + (*p - '0');
                    p++;
                }
            }
    //  }
    //  else {
    //      /* それ以外の形式の場合 */
    //  }
    }

    /* 次に、「時分秒」部分を処理 */
    while ( *p && ((*p < '0') || (*p > '9')) )
        p++;
    if ( (*p >= '0') && (*p <= '9') ) {
        *HH = *p - '0';
        p++;
        if ( (*p >= '0') && (*p <= '9') ) {
            *HH = *HH * 10 + (*p - '0');
            p++;
        }
    }

    while ( *p && ((*p < '0') || (*p > '9')) )
        p++;
    if ( (*p >= '0') && (*p <= '9') ) {
        *MM = *p - '0';
        p++;
        if ( (*p >= '0') && (*p <= '9') ) {
            *MM = *MM * 10 + (*p - '0');
            p++;
        }
    }

    while ( *p                         &&
            ((*p < '0') || (*p > '9')) &&
            (*p != '-')                &&
            (*p != '+')                &&
            ((*p < 'A') || (*p > 'Z'))    )
        p++;
    if ( (*p >= '0') && (*p <= '9') ) {
        *SS = *p - '0';
        p++;
        if ( (*p >= '0') && (*p <= '9') ) {
            *SS = *SS * 10 + (*p - '0');
            p++;
        }
    }

    while ( *p ) {
        /* 「UTC との時差」部分を処理 */
        if ( *p == 'Z' )
            ;   // UTC(なので、特に処理する必要はない)
        else if ( (*p == '-') || (*p == '+') ) {
            /* +09:00 と +0900 の2パターン(':'の有無)ある */
            d = (*p == '-') ? -1 : 1;
            while ( *p && ((*p < '0') || (*p > '9')) )
                p++;
            if ( (*p >= '0') && (*p <= '9') ) {
                dHH = *p - '0';
                p++;
                if ( (*p >= '0') && (*p <= '9') ) {
                    dHH = dHH * 10 + (*p - '0');
                    p++;
                }
            }

            while ( *p && ((*p < '0') || (*p > '9')) )
                p++;
            if ( (*p >= '0') && (*p <= '9') ) {
                dMM = *p - '0';
                p++;
                if ( (*p >= '0') && (*p <= '9') ) {
                    dMM = dMM * 10 + (*p - '0');
                    p++;
                }
            }
            break;
        }
        else {
            // ローカル時間(このプログラムを動かしているPCのタイムゾーンを採用)
            //  -- 本当は、サーバ設置場所のローカル時間を採用する必要がある
#ifdef  WIN32
            if ( _timezone != 0 ) {
                d = (_timezone > 0 ) ? 1 : -1;
                if ( d == -1 )
                    _timezone *= d;
                dHH = (timezone / 60) / 60;
                dMM = (timezone / 60) % 60;
            }
#else
            /* JST → GMT (とりあえず、日本以外でこのプログラムを使う人の */
            /*             ことは忘れる) [暫定]                           */
            d   = 1;
            dHH = 9;
            dMM = 0;
#endif
        }
        p++;
    }

    if ( *yyyy > 2000 ) {    
        struct tm   *m;

        tm.tm_year = *yyyy - 1900;
        tm.tm_mon  = *mm   - 1;
        tm.tm_mday = *dd;
        tm.tm_hour = *HH;
        tm.tm_min  = *MM;
        tm.tm_sec  = *SS;

        t = timelocal( &tm );
        if ( d != 0 )
            t -= (dHH * 60 + dMM) * 60 * d; // UTC
#ifdef  USE_UTC
        m = gmtime( &t );       // UTC のまま保持
#else
        m = localtime( &t );    // ローカル時間に変換して保持
#endif
        *yyyy = m->tm_year + 1900;
        *mm   = m->tm_mon  + 1;
        *dd   = m->tm_mday;
        *HH   = m->tm_hour;
        *MM   = m->tm_min;
        *SS   = m->tm_sec;
    }

    return ( t );
}
Ejemplo n.º 16
0
void
outputOPML(
        const MyClip *mp,
        int          numOfClips,
        const char   *title,
        int          codeChange,
        FILE         *fp
    )
{
    int         i;
    int         rate;
    char        buf[BUFSIZ];
    char        tag[4096];
    char        comment[4096];

    struct tm   tm, *tt;
    time_t      t;
    int         yyyy, mm, dd, HH, MM, SS;
    char        *p = NULL;

    /* OPML ファイル書き出し */
    switch ( codeChange ) {
    case SJIS2UTF:
        p = sjis2utf( title );
        break;

    case EUC2UTF:
        p = euc2utf( title );
        break;

    case UTF8:
    default:
        p = NULL;
        break;
    }
    fprintf( fp,
             "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
             "<opml version=\"1.1\">\n<head>\n"
             "<title>%s</title>\n",
             p ? p : title );
    fprintf( fp, "</head>\n<body>\n" );

    for ( i = 0; i < numOfClips; i++ ) {
        switch ( codeChange ) {
        case SJIS2UTF:
         // p = sjis2utf( mp[i].title );
         // strcpy( buf, p ? p : mp[i].title );
            p = sjis2utf( mp[i].tags );
            strcpy( tag, p ? p : mp[i].tags );
            p = sjis2utf( mp[i].comment );
            strcpy( comment, p ? p : mp[i].comment );
            break;

        case EUC2UTF:
         // p = euc2utf( mp[i].title );
         // strcpy( buf, p ? p : mp[i].title );
            p = euc2utf( mp[i].tags );
            strcpy( tag, p ? p : mp[i].tags );
            p = euc2utf( mp[i].comment );
            strcpy( comment, p ? p : mp[i].comment );
            break;

        case UTF8:
        default:
         // strcpy( buf, mp[i].title );
            strcpy( tag, mp[i].tags );
            strcpy( comment, mp[i].comment );
            break;
        }

        // MM/Memo 形式の title を扱うための処理
        strcpy( buf, mp[i].title );
        rate = getEvaluation( buf, UTF8 );

        regularize( buf );
        regularize( tag );
        regularize( comment );

        tm.tm_year = mp[i].yyyy - 1900;
        tm.tm_mon  = mp[i].mm - 1;
        tm.tm_mday = mp[i].dd;
        tm.tm_hour = mp[i].HH;
        tm.tm_min  = mp[i].MM;
        tm.tm_sec  = mp[i].SS;
        t = timelocal( &tm );
#ifdef  WIN32
        if ( _timezone != 0 )
            t += _timezone;
#else
        t -= 9 * 60 * 60;   /* JST → GMT */
#endif

        tt = gmtime( &t );
        if ( !tt )
            tt = localtime( &t );
        if ( tt ) {
            yyyy = tt->tm_year + 1900;
            mm   = tt->tm_mon + 1;
            dd   = tt->tm_mday;
            HH   = tt->tm_hour;
            MM   = tt->tm_min;
            SS   = tt->tm_sec;
        }
        else {
            yyyy = mp[i].yyyy;
            mm   = mp[i].mm;
            dd   = mp[i].dd;
            HH   = mp[i].HH;
            MM   = mp[i].MM;
            SS   = mp[i].SS;
        }

        strcpy( buf, escapeQuote( buf ) );
        fprintf( fp,
                 "<outline text=\"%s\" type=\"Link\" "
                 "url=\"%s\" title=\"%s\" notes=\"%s\" "
                 "date=\"%04d-%02d-%02dT%02d:%02d:%02dZ\"",
                 buf,
                 escapeURL( mp[i].url ),
                 tag,
                 escapeQuote( comment ),
                 yyyy, mm, dd, HH, MM, SS );

        // 以下は bookey 独自拡張 [OPML 1.0 の仕様書を読む限りは、独自に属性を
        //                         追加するのは問題なさそう]
        //   -- 2006年11月17日現在、OPML validator は Internal database error
        //      が発生して利用できない(新しいデータベースでサービス再開するま
        //      で待っていてください、云々と表示される)ため、本当に valid なの
        //      かどうかは未確認
        if ( ((rate >= EVL_ONE)  &&
              (rate <= EVL_FIVE)    )             ||
             ((mp[i].evaluation >= EVL_ONE)  &&
              (mp[i].evaluation <= EVL_FIVE)    )    )
            fprintf( fp,
                     " evaluation=\"%d\"",
                     mp[i].evaluation );
        if ( (mp[i].rating >= RAT_ONE) && (mp[i].rating <= RAT_THREE) )
            fprintf( fp,
                     " rating=\"%d\"",
                     mp[i].rating );
        if ((mp[i].affirmation == AFF_GOOD) || (mp[i].affirmation == AFF_BAD))
            fprintf( fp,
                     " affirmation=\"%s\"",
                     mp[i].affirmation == AFF_GOOD ? "good" : "bad" );

        if ( mp[i].publication != PUB_EVERYONE ) {
            switch ( mp[i].publication ) {
            case PUB_FRIENDS:
                fprintf( fp, " publication=\"friends\"" );
                break;
            case PUB_PRIVATE:
                fprintf( fp, " publication=\"private\"" );
                break;
            }
        }

        fputs( " />\n", fp );
#ifdef  _DEBUG
        fprintf( stderr, "%d) %s (URL: %s)\n",
                 i + 1, utf2sjis(buf),
                 mp[i].url );
#endif
    }

 // fprintf( fp, "</body>\n</opml>\n" );
    fputs( "</body>\n</opml>\n", fp );
}