示例#1
0
int soap_s2xsd__dateTime(struct soap *soap, const char *s, struct tm *a)
{ memset((void*)a, 0, sizeof(struct tm));
  if (s)
  { char *t;
    unsigned long d;
    d = soap_strtoul(s, &t, 10);
    if (*t == '-')
    { /* YYYY-MM-DD */
      a->tm_year = (int)d;
      a->tm_mon = (int)soap_strtoul(t + 1, &t, 10);
      a->tm_mday = (int)soap_strtoul(t + 1, &t, 10);
    }
    else if (!(soap->mode & SOAP_XML_STRICT))
    { /* YYYYMMDD */
      a->tm_year = (int)(d / 10000);
      a->tm_mon = (int)(d / 100 % 100);
      a->tm_mday = (int)(d % 100);
    }
    else
      return soap->error = SOAP_TYPE;
    if (*t == 'T' || ((*t == 't' || *t == ' ') && !(soap->mode & SOAP_XML_STRICT)))
    { d = soap_strtoul(t + 1, &t, 10);
      if (*t == ':')
      { /* Thh:mm:ss */
	a->tm_hour = (int)d;
	a->tm_min = (int)soap_strtoul(t + 1, &t, 10);
	a->tm_sec = (int)soap_strtoul(t + 1, &t, 10);
      }
      else if (!(soap->mode & SOAP_XML_STRICT))
      { /* Thhmmss */
        a->tm_hour = (int)(d / 10000);
	a->tm_min = (int)(d / 100 % 100);
	a->tm_sec = (int)(d % 100);
      }
      else
	return soap->error = SOAP_TYPE;
    }
    if (a->tm_year == 1)
      a->tm_year = 70;
    else
      a->tm_year -= 1900;
    a->tm_mon--;
    if (*t == '.')
    { for (t++; *t; t++)
        if (*t < '0' || *t > '9')
          break;
    }
    if (*t == ' ' && !(soap->mode & SOAP_XML_STRICT))
      t++;
    if (*t)
    {
#ifndef WITH_NOZONE
      if (*t == '+' || *t == '-')
      { int h, m;
	m = (int)soap_strtol(t, &t, 10);
        if (*t == ':')
        { /* +hh:mm */
	  h = m;
	  m = (int)soap_strtol(t + 1, &t, 10);
          if (h < 0)
            m = -m;
        }
        else if (!(soap->mode & SOAP_XML_STRICT))
	{ /* +hhmm */
          h = m / 100;
          m = m % 100;
        }
        else
	{ /* +hh */
          h = m;
	  m = 0;
        }
	if (*t)
	  return soap->error = SOAP_TYPE;
        a->tm_min -= m;
        a->tm_hour -= h;
        /* put hour and min in range */
        a->tm_hour += a->tm_min / 60;
        a->tm_min %= 60;
        if (a->tm_min < 0)
        { a->tm_min += 60;
          a->tm_hour--;
        }
        a->tm_mday += a->tm_hour / 24;
        a->tm_hour %= 24;
        if (a->tm_hour < 0)
        { a->tm_hour += 24;
          a->tm_mday--;
        }
        /* note: day of the month may be out of range, timegm() handles it */
      }
      else if (*t != 'Z')
	return soap->error = SOAP_TYPE;
#endif
    }
    else /* no UTC or timezone, so assume we got a localtime */
      a->tm_isdst = -1;
  }
  return soap->error;
}
示例#2
0
int soap_s2xsd__dateTime(struct soap *soap, const char *s, struct timeval *a)
{ memset((void*)a, 0, sizeof(struct timeval));
  if (s)
  { char *t;
    unsigned long d;
    struct tm T;
    memset((void*)&T, 0, sizeof(T));
    d = soap_strtoul(s, &t, 10);
    if (*t == '-')
    { /* YYYY-MM-DD */
      T.tm_year = (int)d;
      T.tm_mon = (int)soap_strtoul(t + 1, &t, 10);
      T.tm_mday = (int)soap_strtoul(t + 1, &t, 10);
    }
    else
    { /* YYYYMMDD */
      T.tm_year = (int)(d / 10000);
      T.tm_mon = (int)(d / 100 % 100);
      T.tm_mday = (int)(d % 100);
    }
    if (*t == 'T')
    { d = soap_strtoul(t + 1, &t, 10);
      if (*t == ':')
      { /* Thh:mm:ss */
	T.tm_hour = (int)d;
	T.tm_min = (int)soap_strtoul(t + 1, &t, 10);
	T.tm_sec = (int)soap_strtoul(t + 1, &t, 10);
      }
      else
      { /* Thhmmss */
        T.tm_hour = (int)(d / 10000);
	T.tm_min = (int)(d / 100 % 100);
	T.tm_sec = (int)(d % 100);
      }
    }
    if (T.tm_year == 1)
      T.tm_year = 70;
    else
      T.tm_year -= 1900;
    T.tm_mon--;
    if (*t == '.')
    { for (t++; *t; t++)
        if (*t < '0' || *t > '9')
          break;
    }
    if (*t)
    {
#ifndef WITH_NOZONE
      if (*t == '+' || *t == '-')
      { int h = 0, m = 0;
        if (t[3] == ':')
        { /* +hh:mm */
	  h = (int)soap_strtol(t, NULL, 10);
	  m = (int)soap_strtol(t + 4, NULL, 10);
          if (h < 0)
            m = -m;
        }
        else
	{ /* +hhmm */
          m = (int)soap_strtol(t, NULL, 10);
          h = m / 100;
          m = m % 100;
        }
        T.tm_min -= m;
        T.tm_hour -= h;
        /* put hour and min in range */
        T.tm_hour += T.tm_min / 60;
        T.tm_min %= 60;
        if (T.tm_min < 0)
        { T.tm_min += 60;
          T.tm_hour--;
        }
        T.tm_mday += T.tm_hour / 24;
        T.tm_hour %= 24;
        if (T.tm_hour < 0)
        { T.tm_hour += 24;
          T.tm_mday--;
        }
        /* note: day of the month may be out of range, timegm() handles it */
      }
#endif
      a->tv_sec = soap_timegm(&T);
    }
    else
      a->tv_sec = mktime(&T);
  }
  return soap->error;
}
示例#3
0
文件: duration.c 项目: allenway/onvif
int soap_s2xsd__duration(struct soap *soap, const char *s, LONG64 *a)
{ LONG64 sign = 1, Y = 0, M = 0, D = 0, H = 0, N = 0, S = 0;
  float f = 0;
  *a = 0;
  if (s)
  { if (*s == '-')
    { sign = -1;
      s++;
    }
    if (*s != 'P' && *s != 'p')
      return soap->error = SOAP_TYPE;
    s++;
    /* date part */
    while (s && *s)
    { char *r = NULL;
      LONG64 n;
      if (*s == 'T' || *s == 't')
      { s++;
	break;
      }
      n = soap_strtol(s, &r, 10);
      if (!r)
	return soap->error = SOAP_TYPE;
      s = r;
      switch (*s)
      { case 'Y':
        case 'y':
	  Y = n;
	  break;
	case 'M':
	case 'm':
	  M = n;
	  break;
	case 'D':
	case 'd':
	  D = n;
	  break;
	default:
	  return soap->error = SOAP_TYPE;
      }
      s++;
    }
    /* time part */
    while (s && *s)
    { char *r = NULL;
      LONG64 n;
      n = soap_strtol(s, &r, 10);
      if (!r)
	return soap->error = SOAP_TYPE;
      s = r;
      switch (*s)
      { case 'H':
        case 'h':
	  H = n;
	  break;
	case 'M':
	case 'm':
	  N = n;
	  break;
	case '.':
	  S = n;
#if defined(WITH_C_LOCALE) && defined(HAVE_STRTOD_L)
# ifdef WIN32
          f = (float)_strtod_l(s, NULL, SOAP_LOCALE(soap));
# else
          f = (float)strtod_l(s, NULL, SOAP_LOCALE(soap));
# endif
#elif defined(HAVE_STRTOD)
          f = (float)strtod(s, NULL);
#elif defined(WITH_C_LOCALE) && defined(HAVE_STRTOF_L)
          f = strtof_l((char*)s, NULL, SOAP_LOCALE(soap));
#elif defined(HAVE_STRTOF)
          f = strtof((char*)s, NULL);
#endif
	  s = NULL;
	  continue;
	case 'S':
	case 's':
	  S = n;
	  break;
	default:
	  return soap->error = SOAP_TYPE;
      }
      s++;
    }
    /* convert Y-M-D H:N:S.f to signed long long int milliseconds */
    *a = sign * ((((((((((((Y * 12) + M) * 30) + D) * 24) + H) * 60) + N) * 60) + S) * 1000) + (LONG64)(1000.0 * f + 0.5));
  }
  return soap->error;
}