예제 #1
0
/*
 * Attempt to parse the line as a timezone abbrev spec (name, offset, dst)
 *
 * Returns TRUE if OK, else false; data is stored in *tzentry
 */
static bool
splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
{
	char	   *abbrev;
	char	   *offset;
	char	   *offset_endptr;
	char	   *remain;
	char	   *is_dst;

	tzentry->lineno = lineno;
	tzentry->filename = filename;

	abbrev = strtok(line, WHITESPACE);
	if (!abbrev)
	{
		GUC_check_errmsg("missing time zone abbreviation in time zone file \"%s\", line %d",
						 filename, lineno);
		return false;
	}
	tzentry->abbrev = abbrev;

	offset = strtok(NULL, WHITESPACE);
	if (!offset)
	{
		GUC_check_errmsg("missing time zone offset in time zone file \"%s\", line %d",
						 filename, lineno);
		return false;
	}
	tzentry->offset = strtol(offset, &offset_endptr, 10);
	if (offset_endptr == offset || *offset_endptr != '\0')
	{
		GUC_check_errmsg("invalid number for time zone offset in time zone file \"%s\", line %d",
						 filename, lineno);
		return false;
	}

	is_dst = strtok(NULL, WHITESPACE);
	if (is_dst && pg_strcasecmp(is_dst, "D") == 0)
	{
		tzentry->is_dst = true;
		remain = strtok(NULL, WHITESPACE);
	}
	else
	{
		/* there was no 'D' dst specifier */
		tzentry->is_dst = false;
		remain = is_dst;
	}

	if (!remain)				/* no more non-whitespace chars */
		return true;

	if (remain[0] != '#')		/* must be a comment */
	{
		GUC_check_errmsg("invalid syntax in time zone file \"%s\", line %d",
						 filename, lineno);
		return false;
	}
	return true;
}
예제 #2
0
/*
 * Apply additional validation checks to a tzEntry
 *
 * Returns TRUE if OK, else false
 */
static bool
validateTzEntry(tzEntry *tzentry)
{
	unsigned char *p;

	/*
	 * Check restrictions imposed by datetkntbl storage format (see
	 * datetime.c)
	 */
	if (strlen(tzentry->abbrev) > TOKMAXLEN)
	{
		GUC_check_errmsg("time zone abbreviation \"%s\" is too long (maximum %d characters) in time zone file \"%s\", line %d",
						 tzentry->abbrev, TOKMAXLEN,
						 tzentry->filename, tzentry->lineno);
		return false;
	}
	if (tzentry->offset % 900 != 0)
	{
		GUC_check_errmsg("time zone offset %d is not a multiple of 900 sec (15 min) in time zone file \"%s\", line %d",
						 tzentry->offset,
						 tzentry->filename, tzentry->lineno);
		return false;
	}

	/*
	 * Sanity-check the offset: shouldn't exceed 14 hours
	 */
	if (tzentry->offset > 14 * 60 * 60 ||
		tzentry->offset < -14 * 60 * 60)
	{
		GUC_check_errmsg("time zone offset %d is out of range in time zone file \"%s\", line %d",
						 tzentry->offset,
						 tzentry->filename, tzentry->lineno);
		return false;
	}

	/*
	 * Convert abbrev to lowercase (must match datetime.c's conversion)
	 */
	for (p = (unsigned char *) tzentry->abbrev; *p; p++)
		*p = pg_tolower(*p);

	return true;
}
예제 #3
0
	static bool check_enabled(
		bool *newval, void **extra, GucSource source)
	{
		if ( initstage < IS_PLJAVA_ENABLED )
			return true;
		if ( *newval )
			return true;
		GUC_check_errmsg(
			"too late to change \"pljava.enable\" setting");
		GUC_check_errdetail(
			"Start-up has progressed past the point where it is checked.");
		GUC_check_errhint(
			"For another chance, exit this session and start a new one.");
		return false;
	}
예제 #4
0
	static bool check_classpath(
		char **newval, void **extra, GucSource source)
	{
		if ( initstage < IS_JAVAVM_OPTLIST )
			return true;
		if ( classpath == *newval )
			return true;
		if ( classpath && *newval && 0 == strcmp(classpath, *newval) )
			return true;
		GUC_check_errmsg(
			"too late to change \"pljava.classpath\" setting");
		GUC_check_errdetail(
			"Changing the setting has no effect after "
			"PL/Java has started the Java virtual machine.");
		GUC_check_errhint(
			"To try a different value, exit this session and start a new one.");
		return false;
	}
예제 #5
0
	static bool check_libjvm_location(
		char **newval, void **extra, GucSource source)
	{
		if ( initstage < IS_CAND_JVMOPENED )
			return true;
		if ( libjvmlocation == *newval )
			return true;
		if ( libjvmlocation && *newval && 0 == strcmp(libjvmlocation, *newval) )
			return true;
		GUC_check_errmsg(
			"too late to change \"pljava.libjvm_location\" setting");
		GUC_check_errdetail(
			"Changing the setting can have no effect after "
			"PL/Java has found and opened the library it points to.");
		GUC_check_errhint(
			"To try a different value, exit this session and start a new one.");
		return false;
	}
예제 #6
0
/*
 * Attempt to parse the line as a timezone abbrev spec
 *
 * Valid formats are:
 *	name  zone
 *	name  offset  dst
 *
 * Returns TRUE if OK, else false; data is stored in *tzentry
 */
static bool
splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
{
	char	   *abbrev;
	char	   *offset;
	char	   *offset_endptr;
	char	   *remain;
	char	   *is_dst;

	tzentry->lineno = lineno;
	tzentry->filename = filename;

	abbrev = strtok(line, WHITESPACE);
	if (!abbrev)
	{
		GUC_check_errmsg("missing time zone abbreviation in time zone file \"%s\", line %d",
						 filename, lineno);
		return false;
	}
	tzentry->abbrev = pstrdup(abbrev);

	offset = strtok(NULL, WHITESPACE);
	if (!offset)
	{
		GUC_check_errmsg("missing time zone offset in time zone file \"%s\", line %d",
						 filename, lineno);
		return false;
	}

	/* We assume zone names don't begin with a digit or sign */
	if (isdigit((unsigned char) *offset) || *offset == '+' || *offset == '-')
	{
		tzentry->zone = NULL;
		tzentry->offset = strtol(offset, &offset_endptr, 10);
		if (offset_endptr == offset || *offset_endptr != '\0')
		{
			GUC_check_errmsg("invalid number for time zone offset in time zone file \"%s\", line %d",
							 filename, lineno);
			return false;
		}

		is_dst = strtok(NULL, WHITESPACE);
		if (is_dst && pg_strcasecmp(is_dst, "D") == 0)
		{
			tzentry->is_dst = true;
			remain = strtok(NULL, WHITESPACE);
		}
		else
		{
			/* there was no 'D' dst specifier */
			tzentry->is_dst = false;
			remain = is_dst;
		}
	}
	else
	{
		/*
		 * Assume entry is a zone name.  We do not try to validate it by
		 * looking up the zone, because that would force loading of a lot of
		 * zones that probably will never be used in the current session.
		 */
		tzentry->zone = pstrdup(offset);
		tzentry->offset = 0;
		tzentry->is_dst = false;
		remain = strtok(NULL, WHITESPACE);
	}

	if (!remain)				/* no more non-whitespace chars */
		return true;

	if (remain[0] != '#')		/* must be a comment */
	{
		GUC_check_errmsg("invalid syntax in time zone file \"%s\", line %d",
						 filename, lineno);
		return false;
	}
	return true;
}