-
Notifications
You must be signed in to change notification settings - Fork 20
5.4.24 #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
5.4.24 #111
Changes from all commits
dd9c505
b0276d9
4c1fab5
6cf3fe3
692cae7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,19 +133,28 @@ void license_free_list(struct license_list * ptr) | |
| ptr->count = 0; | ||
| } | ||
|
|
||
| static int license_priority(int id) | ||
| { | ||
| static const int priority[] = {0, 31, 32, 33, 35, 3, 1, 2, 5}; | ||
| static const int n = sizeof(priority) / sizeof(priority[0]); | ||
|
|
||
| for (int i = 0; i < n; i++) | ||
| if (priority[i] == id) | ||
| return i; | ||
|
|
||
| return n; /* unknown IDs go last */ | ||
| } | ||
|
|
||
| static int license_compare_by_id(const void *a, const void *b) | ||
| { | ||
| const struct license_type *la = a; | ||
| const struct license_type *lb = b; | ||
|
|
||
| /* IDs 5 and 6 should go to the end */ | ||
| bool a_is_last = (la->id == 5 || la->id == 6); | ||
| bool b_is_last = (lb->id == 5 || lb->id == 6); | ||
| int pa = license_priority(la->id); | ||
| int pb = license_priority(lb->id); | ||
|
|
||
| if (a_is_last && !b_is_last) | ||
| return 1; | ||
| if (!a_is_last && b_is_last) | ||
| return -1; | ||
| if (pa != pb) | ||
| return pa - pb; | ||
|
|
||
| return la->id - lb->id; | ||
| } | ||
|
|
@@ -291,7 +300,7 @@ static char *json_from_license(uint32_t *crclist, char *buffer, char *license, i | |
| if (!license_source_id) | ||
| return buffer; | ||
| //skip scancode licenses starting with "LicenseRef" | ||
| if (!strncmp(license_source_id, "scancode", 8) && !strncmp(license, "LicenseRef", 10)) | ||
| if (!strncmp(license_source_id, "scancode", 8) && strstr(license, "LicenseRef")) | ||
| return buffer; | ||
| /* Calculate CRC to avoid duplicates */ | ||
| uint32_t CRC = string_crc32c(license); | ||
|
|
@@ -313,8 +322,49 @@ static char *json_from_license(uint32_t *crclist, char *buffer, char *license, i | |
| len += sprintf(buffer + len, "\"name\": \"%s\",", license); | ||
| len += osadl_print_license(buffer + len, license, true); | ||
| len += sprintf(buffer + len, "\"source\": \"%s\"", license_source_id); | ||
| if (!strstr(license, "LicenseRef")) | ||
|
|
||
| /* Check if license contains AND/OR/WITH operators */ | ||
| if (strstr(license, " AND ") || strstr(license, " OR ") || strstr(license, " WITH ")) | ||
| { | ||
| /* Build "urls" object with each individual license mapped to its URL */ | ||
| len += sprintf(buffer + len, ",\"urls\": {"); | ||
| char lic_copy[MAX_FIELD_LN]; | ||
| strncpy(lic_copy, license, MAX_FIELD_LN - 1); | ||
| lic_copy[MAX_FIELD_LN - 1] = '\0'; | ||
|
|
||
| char first_license[MAX_FIELD_LN] = "\0"; | ||
| bool first_entry = true; | ||
| char *saveptr = NULL; | ||
| char *token = strtok_r(lic_copy, " ()", &saveptr); | ||
|
|
||
| while (token) | ||
| { | ||
| /* Skip AND/OR/WITH operators */ | ||
| if (strcmp(token, "AND") == 0 || strcmp(token, "OR") == 0 || strcmp(token, "WITH") == 0) | ||
| { | ||
| token = strtok_r(NULL, " ()", &saveptr); | ||
| continue; | ||
| } | ||
| if (!first_entry) | ||
| len += sprintf(buffer + len, ","); | ||
| else | ||
| { | ||
| strncpy(first_license, token, MAX_FIELD_LN - 1); | ||
| first_entry = false; | ||
| } | ||
| len += sprintf(buffer + len, "\"%s\": \"https://spdx.org/licenses/%s.html\"", token, token); | ||
|
Comment on lines
+342
to
+355
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In expressions like 💡 Suggested fix- char *token = strtok_r(lic_copy, " ()", &saveptr);
+ char *token = strtok_r(lic_copy, " ()", &saveptr);
+ const char *spdx_kind = "licenses";
while (token)
{
/* Skip AND/OR/WITH operators */
- if (strcmp(token, "AND") == 0 || strcmp(token, "OR") == 0 || strcmp(token, "WITH") == 0)
+ if (strcmp(token, "AND") == 0 || strcmp(token, "OR") == 0 || strcmp(token, "WITH") == 0)
{
+ spdx_kind = (strcmp(token, "WITH") == 0) ? "exceptions" : "licenses";
token = strtok_r(NULL, " ()", &saveptr);
continue;
}
if (!first_entry)
len += sprintf(buffer + len, ",");
@@
- len += sprintf(buffer + len, "\"%s\": \"https://spdx.org/licenses/%s.html\"", token, token);
+ len += sprintf(buffer + len, "\"%s\": \"https://spdx.org/%s/%s.html\"", token, spdx_kind, token);
+ spdx_kind = "licenses";
token = strtok_r(NULL, " ()", &saveptr);
}🤖 Prompt for AI Agents |
||
| token = strtok_r(NULL, " ()", &saveptr); | ||
| } | ||
| len += sprintf(buffer + len, "}"); | ||
|
|
||
| /* "url" points to the first license only */ | ||
| len += sprintf(buffer + len, ",\"url\": \"https://spdx.org/licenses/%s.html\"", first_license); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| else | ||
| { | ||
| len += sprintf(buffer + len, ",\"url\": \"https://spdx.org/licenses/%s.html\"", license); | ||
| } | ||
|
|
||
| len += sprintf(buffer + len, "}"); | ||
| return (buffer + len); | ||
| } | ||
|
|
@@ -507,14 +557,17 @@ void print_licenses(component_data_t *comp) | |
| len += sprintf(result + len, "\"licenses\": ["); | ||
| buffer = result + len; | ||
| bool first = true; | ||
|
|
||
| int last_id = -1; | ||
| /* Sort licenses by id (ascending) */ | ||
| if (licenses_by_type.count > 1) | ||
| qsort(licenses_by_type.licenses, licenses_by_type.count, sizeof(struct license_type), license_compare_by_id); | ||
|
|
||
| for (int i = 0; i < licenses_by_type.count; i++) | ||
| { | ||
| buffer = license_to_json(crclist, buffer, licenses_by_type.licenses[i].text, licenses_by_type.licenses[i].id, &first); | ||
| if (last_id >= 0 && last_id != licenses_by_type.licenses[i].id && !first && !full_license_report) | ||
| break; | ||
| last_id = licenses_by_type.licenses[i].id; | ||
| } | ||
|
|
||
| len = buffer - result; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't drop mixed SPDX expressions just because they contain
LicenseRef.This now skips the whole Scancode record for values like
MIT AND LicenseRef-scancode-foo, so the valid SPDX part is lost too. Restrict the skip to pureLicenseRef-*entries, or ignore only theLicenseRef-*token when expanding compound expressions.🤖 Prompt for AI Agents