MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / MakeUniqueObjectPath

Function MakeUniqueObjectPath

extern/nfd/nfd_portal.cpp:852–870  ·  view source on GitHub ↗

Allocates and returns a path like "/org/freedesktop/portal/desktop/request/SENDER/TOKEN" with randomly generated TOKEN as recommended by flatpak. `handle_token_ptr` is a pointer to the TOKEN part.

Source from the content-addressed store, hash-verified

850// randomly generated TOKEN as recommended by flatpak. `handle_token_ptr` is a pointer to the
851// TOKEN part.
852char* MakeUniqueObjectPath(const char** handle_token_ptr) {
853 const char* sender = dbus_unique_name;
854 if (*sender == ':') ++sender;
855 const size_t sender_len = strlen(sender);
856 const size_t sz = STR_RESPONSE_HANDLE_PREFIX_LEN + sender_len + 1 +
857 64; // 1 for '/', followed by 64 random chars
858 char* path = NFDi_Malloc<char>(sz + 1);
859 char* path_ptr = path;
860 path_ptr = copy(STR_RESPONSE_HANDLE_PREFIX,
861 STR_RESPONSE_HANDLE_PREFIX + STR_RESPONSE_HANDLE_PREFIX_LEN,
862 path_ptr);
863 path_ptr = transform(
864 sender, sender + sender_len, path_ptr, [](char ch) { return ch != '.' ? ch : '_'; });
865 *path_ptr++ = '/';
866 *handle_token_ptr = path_ptr;
867 path_ptr = Generate64RandomChars(path_ptr);
868 *path_ptr = '\0';
869 return path;
870}
871
872constexpr const char STR_RESPONSE_SUBSCRIPTION_PATH_1[] =
873 "type='signal',sender='org.freedesktop.portal.Desktop',path='";

Callers 2

NFD_DBus_OpenFileFunction · 0.85
NFD_DBus_SaveFileFunction · 0.85

Calls 3

transformFunction · 0.85
Generate64RandomCharsFunction · 0.85
copyFunction · 0.70

Tested by

no test coverage detected