22 #include "nomos_utils.h" 23 #include <json-c/json.h> 27 char realPathOfTarget[PATH_MAX];
28 json_object *result = json_object_new_object();
29 json_object *licenses = json_object_new_array();
30 json_object *fileLocation = NULL;
31 json_object *aLicense = NULL;
37 aLicense = json_object_new_string(cur.
licenseList[i]);
39 json_object_array_add(licenses, aLicense);
45 fileLocation = json_object_new_string(realPathOfTarget);
49 fileLocation = json_object_new_string(basename(cur.
targetFile));
51 json_object_object_add(result,
"file", fileLocation);
52 json_object_object_add(result,
"licenses", licenses);
54 json_object_to_json_string_ext(result, JSON_C_TO_STRING_PRETTY));
58 printf(
",%s\n", prettyJson);
63 printf(
"%s\n", prettyJson);
67 json_object_put(result);
72 const char *escapedSeparator =
"\\/";
73 const char *pathSeparator =
"/";
74 const int escPathLen = 2;
75 const int pathSepLen = 1;
76 size_t resultLength = 0;
77 size_t remainingLength = -1;
86 tempjson = strdup(json);
89 for (count = 0; (tmp = strstr(tmp, escapedSeparator)); count++)
94 resultLength = strlen(tempjson) - ((escPathLen - pathSepLen) * count);
96 result = (
char*) calloc(resultLength + 1,
sizeof(
char));
98 strncpy(result, strtok(tempjson, escapedSeparator), resultLength);
99 remainingLength = resultLength - strlen(result);
101 while (count-- && remainingLength > 0)
103 strncat(result, pathSeparator, remainingLength);
104 strncat(result, strtok(NULL, escapedSeparator), remainingLength - 1);
105 remainingLength = resultLength - strlen(result);
113 mutexJson = (sem_t *) mmap(NULL,
sizeof(sem_t),
114 PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
115 printcomma = (gboolean *) mmap(NULL,
sizeof(gboolean),
116 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
117 sem_init(mutexJson, 2, SEM_DEFAULT_VALUE);
122 sem_destroy(mutexJson);
123 munmap(printcomma,
sizeof(gboolean));
124 munmap(mutexJson,
sizeof(sem_t));
void writeJson()
Write the scan output as a JSON.
char targetFile[myBUFSIZ]
int optionIsSet(int val)
Check if an CLI option is set.
FUNCTION void parseLicenseList()
parse the comma separated list of license names found
char * unescapePathSeparator(const char *json)
Unescape the path separator from JSON.