forked from Ylianst/MeshAgent
-
Notifications
You must be signed in to change notification settings - Fork 0
Hotfix/machine id header #78
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0899660
Send x-machine-id and Authorization headers on OpenFrame-mode connect…
mikhailm-coder 1db9462
Clean openframe object files between builds
mikhailm-coder 0626d8f
Set Host header on OpenFrame-mode agent HTTP requests
mikhailm-coder b8b366e
fix: only append authorization query param for a non-empty token
mikhailm-coder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include "machine_id_reader.h" | ||
|
|
||
| #define MAX_MACHINE_ID_LEN 128 | ||
|
|
||
| #ifdef _WIN32 | ||
| #include <windows.h> | ||
|
|
||
| char* read_machine_id() { | ||
| // Read from C:\ProgramData\OpenFrame\machine_id | ||
| char path[MAX_PATH]; | ||
| char* programData = getenv("ProgramData"); | ||
| if (!programData) { | ||
| return NULL; | ||
| } | ||
|
|
||
| snprintf(path, sizeof(path), "%s\\OpenFrame\\machine_id", programData); | ||
|
|
||
| FILE* file = fopen(path, "r"); | ||
| if (!file) { | ||
| return NULL; | ||
| } | ||
|
|
||
| char* machineId = malloc(MAX_MACHINE_ID_LEN); | ||
| if (!machineId) { | ||
| fclose(file); | ||
| return NULL; | ||
| } | ||
|
|
||
| if (fgets(machineId, MAX_MACHINE_ID_LEN, file) == NULL) { | ||
| free(machineId); | ||
| fclose(file); | ||
| return NULL; | ||
| } | ||
|
mikhailm-coder marked this conversation as resolved.
|
||
|
|
||
| fclose(file); | ||
|
|
||
| // Trim newline | ||
| size_t len = strlen(machineId); | ||
| while (len > 0 && (machineId[len-1] == '\n' || machineId[len-1] == '\r')) { | ||
| machineId[--len] = '\0'; | ||
| } | ||
|
|
||
| if (len == 0) { | ||
| free(machineId); | ||
| return NULL; | ||
| } | ||
|
|
||
| return machineId; | ||
| } | ||
|
|
||
| #else | ||
| // macOS / Linux | ||
|
|
||
| char* read_machine_id() { | ||
| #ifdef __APPLE__ | ||
| const char* path = "/Library/Application Support/OpenFrame/machine_id"; | ||
| #else | ||
| const char* path = "/var/lib/openframe/machine_id"; | ||
| #endif | ||
|
|
||
| FILE* file = fopen(path, "r"); | ||
| if (!file) { | ||
| return NULL; | ||
| } | ||
|
|
||
| char* machineId = malloc(MAX_MACHINE_ID_LEN); | ||
| if (!machineId) { | ||
| fclose(file); | ||
| return NULL; | ||
| } | ||
|
|
||
| if (fgets(machineId, MAX_MACHINE_ID_LEN, file) == NULL) { | ||
| free(machineId); | ||
| fclose(file); | ||
| return NULL; | ||
| } | ||
|
|
||
| fclose(file); | ||
|
|
||
| // Trim newline | ||
| size_t len = strlen(machineId); | ||
| while (len > 0 && (machineId[len-1] == '\n' || machineId[len-1] == '\r')) { | ||
| machineId[--len] = '\0'; | ||
| } | ||
|
|
||
| if (len == 0) { | ||
| free(machineId); | ||
| return NULL; | ||
| } | ||
|
|
||
| return machineId; | ||
| } | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #ifndef MACHINE_ID_READER_H | ||
| #define MACHINE_ID_READER_H | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * Read machine ID from shared OpenFrame location | ||
| * - macOS: /Library/Application Support/OpenFrame/machine_id | ||
| * - Windows: C:\ProgramData\OpenFrame\machine_id | ||
| * - Linux: /var/lib/openframe/machine_id | ||
| * | ||
| * @return Machine ID string (caller must free) or NULL if not found | ||
| */ | ||
| char* read_machine_id(void); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif // MACHINE_ID_READER_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.