90 const char *localURL = url;
91 char *urlWithEmptyAuthority = NULL;
92 struct http_parser_url parsedUrl;
93 size_t urlLen = strlen(url);
94 if (http_parser_parse_url(url, urlLen,
false, &parsedUrl))
97 if (strncmp(url,
"data:", 5) == 0)
118 else if (strncmp(url,
"file:/", 6) == 0 && urlLen > 6 && url[6] !=
'/')
120 urlWithEmptyAuthority = malloc(urlLen + 2 + 1);
121 strcpy(urlWithEmptyAuthority,
"file://");
122 strcat(urlWithEmptyAuthority, url + 5);
123 if (http_parser_parse_url(urlWithEmptyAuthority, urlLen + 2,
false, &parsedUrl))
125 free(urlWithEmptyAuthority);
128 localURL = urlWithEmptyAuthority;
137 if (parsedUrl.field_set & (1 << UF_SCHEMA))
138 *scheme =
VuoText_makeWithMaxLength(localURL + parsedUrl.field_data[UF_SCHEMA ].off, parsedUrl.field_data[UF_SCHEMA ].len);
145 if (parsedUrl.field_set & (1 << UF_USERINFO))
146 *user =
VuoText_makeWithMaxLength(localURL + parsedUrl.field_data[UF_USERINFO].off, parsedUrl.field_data[UF_USERINFO].len);
153 if (parsedUrl.field_set & (1 << UF_HOST))
161 if (parsedUrl.field_set & (1 << UF_PORT))
163 *port = parsedUrl.port;
168 if (strcmp(*scheme,
"http") == 0)
170 else if (strcmp(*scheme,
"https") == 0)
177 if (parsedUrl.field_set & (1 << UF_PATH))
185 if (parsedUrl.field_set & (1 << UF_QUERY))
193 if (parsedUrl.field_set & (1 << UF_FRAGMENT))
194 *fragment =
VuoText_makeWithMaxLength(localURL + parsedUrl.field_data[UF_FRAGMENT].off, parsedUrl.field_data[UF_FRAGMENT].len);
199 if (urlWithEmptyAuthority)
200 free(urlWithEmptyAuthority);
457 VuoText u = url + fileSchemeLength;
458 if (strncmp(u,
"//", 2) == 0)
474 size_t urlLen = strlen(trimmedUrl);
475 size_t spaceCount = 0;
476 for (
size_t i = 0; i < urlLen; ++i)
477 if (trimmedUrl[i] ==
' ')
481 resolvedUrl = (
char *)malloc(strlen(trimmedUrl) + spaceCount*2);
483 for (
size_t i = 0; i < urlLen; ++i)
484 if (trimmedUrl[i] ==
' ')
486 resolvedUrl[p++] =
'%';
487 resolvedUrl[p++] =
'2';
488 resolvedUrl[p++] =
'0';
491 resolvedUrl[p++] = trimmedUrl[i];
495 resolvedUrl = strdup(trimmedUrl);
501 char *filePath = (
char *)trimmedUrl;
508 if (access(filePath, 0) != 0)
510 char userTempDir[PATH_MAX];
511 size_t userTempDirLen;
512 if ((userTempDirLen = confstr(_CS_DARWIN_USER_TEMP_DIR, userTempDir, PATH_MAX)) > 0)
514 size_t filePathLen = strlen(filePath);
515 size_t mallocSize = userTempDirLen + filePathLen + 1;
516 char *privateFilePath = (
char *)malloc(mallocSize);
517 strlcpy(privateFilePath, userTempDir, mallocSize);
518 strlcat(privateFilePath, filePath + 4, mallocSize);
519 filePath = privateFilePath;
527 if (access(filePath, 0) != 0)
529 const char *systemPrefix =
"/System";
530 size_t systemPrefixLen = strlen(systemPrefix);
531 size_t filePathLen = strlen(filePath);
532 size_t mallocSize = systemPrefixLen + filePathLen + 1;
533 char *systemPath = (
char *)malloc(mallocSize);
534 strlcpy(systemPath, systemPrefix, mallocSize);
535 strlcat(systemPath, filePath, mallocSize);
536 if (access(systemPath, 0) == 0)
537 filePath = systemPath;
543 char *realPath = realpath(filePath, NULL);
549 if (filePath != trimmedUrl)
553 resolvedUrl = (
char *)malloc(mallocSize);
555 strlcat(resolvedUrl, escapedPath, mallocSize);
566 char *homeDir = getenv(
"HOME");
567 VuoText paths[2] = { homeDir, trimmedUrl+1 };
573 char *realPath = realpath(absolutePath, NULL);
582 resolvedUrl = (
char *)malloc(mallocSize);
584 strlcat(resolvedUrl, escapedPath, mallocSize);
592 resolvedUrl = (
char *)malloc(mallocSize);
594 strlcat(resolvedUrl, trimmedUrl, mallocSize);
605 bool compositionIsExportedAppOrPlugin =
false;
607 if (strcmp(currentWorkingDir,
"/") == 0
608 || strstr(currentWorkingDir,
"/Library/Containers/"))
615 char rawExecutablePath[PATH_MAX+1];
616 uint32_t size =
sizeof(rawExecutablePath);
617 _NSGetExecutablePath(rawExecutablePath, &size);
619 char cleanedExecutablePath[PATH_MAX+1];
620 realpath(rawExecutablePath, cleanedExecutablePath);
623 size_t pathSize = PATH_MAX + 1;
624 char executableDir[pathSize];
625 strlcpy(executableDir, dirname(cleanedExecutablePath), pathSize);
627 const char *resourcesPathFromExecutable =
"/../Resources";
628 pathSize = strlen(executableDir) + strlen(resourcesPathFromExecutable) + 1;
629 char rawResourcesPath[pathSize];
630 strlcpy(rawResourcesPath, executableDir, pathSize);
631 strlcat(rawResourcesPath, resourcesPathFromExecutable, pathSize);
633 char cleanedResourcesPath[PATH_MAX+1];
634 realpath(rawResourcesPath, cleanedResourcesPath);
638 if (access(cleanedResourcesPath, 0) == 0)
642 char *homeDir = getenv(
"HOME");
645 const char *desktop =
"/Desktop/";
646 size_t mallocSize = strlen(homeDir) + strlen(desktop) + strlen(trimmedUrl) + 1;
647 absolutePath = (
char *)malloc(mallocSize);
648 strlcpy(absolutePath, homeDir, mallocSize);
649 strlcat(absolutePath, desktop, mallocSize);
650 strlcat(absolutePath, trimmedUrl, mallocSize);
651 compositionIsExportedAppOrPlugin =
true;
656 size_t mallocSize = strlen(cleanedResourcesPath) + strlen(
"/") + strlen(trimmedUrl) + 1;
657 absolutePath = (
char *)malloc(mallocSize);
658 strlcpy(absolutePath, cleanedResourcesPath, mallocSize);
659 strlcat(absolutePath,
"/", mallocSize);
660 strlcat(absolutePath, trimmedUrl, mallocSize);
661 compositionIsExportedAppOrPlugin =
true;
667 if (!compositionIsExportedAppOrPlugin)
669 size_t mallocSize = strlen(currentWorkingDir) + strlen(
"/") + strlen(trimmedUrl) + 1;
670 absolutePath = (
char *)malloc(mallocSize);
671 strlcpy(absolutePath, currentWorkingDir, mallocSize);
672 strlcat(absolutePath,
"/", mallocSize);
673 strlcat(absolutePath, trimmedUrl, mallocSize);
681 char *homeDir = getenv(
"HOME");
684 const char *applicationsPrefix =
"/Applications/";
685 size_t homeDirLen = strlen(homeDir);
686 size_t applicationsPrefixLen = strlen(applicationsPrefix);
687 size_t trimmedUrlLen = strlen(trimmedUrl);
688 size_t mallocSize = homeDirLen + applicationsPrefixLen + trimmedUrlLen + 1;
689 char *path = (
char *)malloc(mallocSize);
690 strlcpy(path, homeDir, mallocSize);
691 strlcat(path, applicationsPrefix, mallocSize);
692 strlcat(path, trimmedUrl, mallocSize);
693 if (access(path, 0) == 0)
704 const char *applicationsPrefix =
"/Applications/";
705 size_t applicationsPrefixLen = strlen(applicationsPrefix);
706 size_t trimmedUrlLen = strlen(trimmedUrl);
707 size_t mallocSize = applicationsPrefixLen + trimmedUrlLen + 1;
708 char *path = (
char *)malloc(mallocSize);
709 strlcpy(path, applicationsPrefix, mallocSize);
710 strlcat(path, trimmedUrl, mallocSize);
711 if (access(path, 0) == 0)
722 const char *applicationsPrefix =
"/System/Applications/";
723 size_t applicationsPrefixLen = strlen(applicationsPrefix);
724 size_t trimmedUrlLen = strlen(trimmedUrl);
725 size_t mallocSize = applicationsPrefixLen + trimmedUrlLen + 1;
726 char *path = (
char *)malloc(mallocSize);
727 strlcpy(path, applicationsPrefix, mallocSize);
728 strlcat(path, trimmedUrl, mallocSize);
729 if (access(path, 0) == 0)
740 char *realPath = realpath(absolutePath, NULL);
750 resolvedUrl = (
char *)malloc(mallocSize);
752 strlcat(resolvedUrl, escapedPath, mallocSize);
758 size_t lastIndex = strlen(resolvedUrl) - 1;
759 if (resolvedUrl[lastIndex] ==
'/')
760 resolvedUrl[lastIndex] = 0;