10 #include "nomos_utils.h"
11 #include <json-c/json.h>
15 char realPathOfTarget[PATH_MAX];
16 json_object *result = json_object_new_object();
17 json_object *licenses = json_object_new_array();
18 json_object *fileLocation = NULL;
19 json_object *aLicense = NULL;
25 aLicense = json_object_new_string(cur.
licenseList[i]);
27 json_object_array_add(licenses, aLicense);
33 fileLocation = json_object_new_string(realPathOfTarget);
37 fileLocation = json_object_new_string(basename(cur.
targetFile));
39 json_object_object_add(result,
"file", fileLocation);
40 json_object_object_add(result,
"licenses", licenses);
42 json_object_to_json_string_ext(result, JSON_C_TO_STRING_PRETTY));
46 printf(
",%s\n", prettyJson);
51 printf(
"%s\n", prettyJson);
56 json_object_put(result);
61 const char *escapedSeparator =
"\\/";
62 const char *pathSeparator =
"/";
63 const int escPathLen = 2;
64 const int pathSepLen = 1;
65 size_t resultLength = 0;
66 size_t remainingLength = -1;
75 tempjson = strdup(json);
78 for (count = 0; (tmp = strstr(tmp, escapedSeparator)); count++)
83 resultLength = strlen(tempjson) - ((escPathLen - pathSepLen) * count);
85 result = (
char*) calloc(resultLength + 1,
sizeof(
char));
87 strncpy(result, strtok(tempjson, escapedSeparator), resultLength);
88 remainingLength = resultLength - strlen(result);
90 while (count-- && remainingLength > 0)
92 strncat(result, pathSeparator, remainingLength);
93 strncat(result, strtok(NULL, escapedSeparator), remainingLength - 1);
94 remainingLength = resultLength - strlen(result);
102 mutexJson = (sem_t *) mmap(NULL,
sizeof(sem_t),
103 PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
104 printcomma = (gboolean *) mmap(NULL,
sizeof(gboolean),
105 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
106 sem_init(
mutexJson, 2, SEM_DEFAULT_VALUE);
void writeJson()
Write the scan output as a JSON.
char * unescapePathSeparator(const char *json)
Unescape the path separator from JSON.
int optionIsSet(int val)
Check if an CLI option is set.
sem_t * mutexJson
Mutex to handle JSON writes.
FUNCTION void parseLicenseList()
parse the comma separated list of license names found
gboolean * printcomma
True to print comma while printing JSON object.
char targetFile[myBUFSIZ]