{
char *end;
do {
if ((end = strchr(element, '&')) != NULL)
*end = '\0';
if (!acceptable_simple_element(release, element))
return (0);
if (end != NULL)
element = end + 1;
} while (end != NULL);
return (1);
}
/*
* Checks if release is acceptable by the specification version-string.
* Return true if this version-string (as defined in JSR 56) forms
* an acceptable match. A version-string is the union (or) of multiple
* elements.
*/
int
JLI_AcceptableRelease(char *release, char *version_string)
{
char *vs;
char *m1;
char *end;
m1 = vs = JLI_StringDup(version_string);
do {
if ((end = strchr(vs, ' ')) != NULL)
*end = '\0';
if (acceptable_element(release, vs)) {
JLI_MemFree(m1);
return (1);
}
if (end != NULL)
vs = end + 1;
} while (end != NULL);
JLI_MemFree(m1);
return (0);
}
/*
* Return true if this is a valid simple-element (as defined in JSR 56).
*
* The official grammar for a simple-element is:
*
* simple-element ::= version-id | version-id modifier
* modifier ::= '+' | '*'
* version-id ::= string ( separator string )*
* string ::= char ( char )*
* char ::= Any ASCII character except a space, an
* ampersand, a separator or a modifier
* separator ::= '.' | '-' | '_'
*
* However, for efficiency, it is time to abandon the top down parser
* implementation. After deleting the potential trailing modifier, we
* are left with a version-id.
*
* Note that a valid version-id has three simple properties:
*
* 1) Doesn't contain a space, an ampersand or a modifier.
*
* 2) Doesn't begin or end with a separator.
*
* 3) Doesn't contain two adjacent separators.
*
* Any other line noise constitutes a valid version-id.
*/
static int
valid_simple_element(char *simple_element)
{
char *last;
size_t len;
if ((simple_element == NULL) || ((len = strlen(simple_element)) == 0))
return (0);
last = simple_element + len - 1;
if (*last == '*' || *last == '+') {
if (--len == 0)
return (0);
*last-- = '\0';
}
if (strpbrk(simple_element, " &+*") != NULL) /* Property #1 */
return (0);
if ((strchr(".-_", *simple_element) != NULL) || /* Property #2 */
(strchr(".-_", *last) != NULL))
return (0);
for (; simple_element != last; simple_element++) /* Property #3 */
if ((strchr(".-_", *simple_element) != NULL) &&
(strchr(".-_", *(simple_element + 1)) != NULL))
return (0);
return (1);
}
/*
* Return true if this is a valid element (as defined in JSR 56).
* An element is the intersection (and) of multiple simple-elements.
*/
static int
valid_element(char *element)
{
=3= |