-
-
Notifications
You must be signed in to change notification settings - Fork 199
feat: Support modifying attachments after init (continued) #1266
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 9 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
fb699b9
feat: Support modifying attachments after init
Swatinem 72341ec
feat: pass added and removed attachments to the backend
jpnurmi 9a317be
add `_n`
jpnurmi 5ca524d
scope api
jpnurmi 9569d04
merge & apply attachments
jpnurmi 9c99b5d
update note on attachments
jpnurmi 30cf867
integration tests
jpnurmi 55336fc
Update README.md
jpnurmi 32a6aea
Update CHANGELOG.md
jpnurmi 09c9dc4
Apply suggestions from code review
jpnurmi 7200e78
remove ticks
jpnurmi 939a918
Apply more suggestions from code review
jpnurmi 12c7b56
De-duplicate envelope attachment code
jpnurmi b8e47dc
sentry_add_attachment -> sentry_add_attachment_path
jpnurmi d672c29
Update CHANGELOG.md
jpnurmi 17197d4
fixup: missed rename
jpnurmi e9a2df1
fixup: another missed rename
jpnurmi a542aca
remove_attachmentw() without _path
jpnurmi 3a0cb45
revise sentry_attach_file & removal
jpnurmi 5a00273
fix windows
jpnurmi 759caa0
Update CHANGELOG.md
jpnurmi deb6fce
clean up
jpnurmi d36e17b
fix attachments_add_remove on windows
jpnurmi 62eff3b
Update CHANGELOG.md & NOTE on attachments
jpnurmi 05b138f
Update external/crashpad
jpnurmi 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
Submodule crashpad
updated
15 files
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,155 @@ | ||
| #include "sentry_attachment.h" | ||
| #include "sentry_alloc.h" | ||
| #include "sentry_envelope.h" | ||
| #include "sentry_options.h" | ||
| #include "sentry_path.h" | ||
| #include "sentry_utils.h" | ||
| #include "sentry_value.h" | ||
|
|
||
| #include <assert.h> | ||
|
|
||
| static const char * | ||
| str_from_attachment_type(sentry_attachment_type_t attachment_type) | ||
| { | ||
| switch (attachment_type) { | ||
| case ATTACHMENT: | ||
| return "event.attachment"; | ||
| case MINIDUMP: | ||
| return "event.minidump"; | ||
| case VIEW_HIERARCHY: | ||
| return "event.view_hierarchy"; | ||
| default: | ||
| UNREACHABLE("Unknown attachment type"); | ||
| return "event.attachment"; | ||
| } | ||
| } | ||
|
|
||
| static void | ||
| sentry__attachment_free(sentry_attachment_t *attachment) | ||
jpnurmi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (!attachment) { | ||
| return; | ||
| } | ||
| sentry__path_free(attachment->path); | ||
| sentry_free(attachment); | ||
| } | ||
|
|
||
| void | ||
| sentry__attachments_free(sentry_attachment_t *attachments) | ||
| { | ||
| sentry_attachment_t *next_attachment = attachments; | ||
| while (next_attachment) { | ||
| sentry_attachment_t *attachment = next_attachment; | ||
| next_attachment = attachment->next; | ||
|
|
||
| sentry__attachment_free(attachment); | ||
| } | ||
| } | ||
|
|
||
| void | ||
| sentry__attachment_add(sentry_attachment_t **attachments_ptr, | ||
| sentry_path_t *path, sentry_attachment_type_t attachment_type, | ||
| const char *content_type) | ||
| { | ||
| if (!path) { | ||
| return; | ||
| } | ||
| sentry_attachment_t *attachment = SENTRY_MAKE(sentry_attachment_t); | ||
| if (!attachment) { | ||
| sentry__path_free(path); | ||
| return; | ||
| } | ||
| attachment->path = path; | ||
| attachment->next = NULL; | ||
| attachment->type = attachment_type; | ||
| attachment->content_type = content_type; | ||
|
|
||
| sentry_attachment_t **next_ptr = attachments_ptr; | ||
|
|
||
| for (sentry_attachment_t *last_attachment = *attachments_ptr; | ||
| last_attachment; last_attachment = last_attachment->next) { | ||
| if (sentry__path_eq(last_attachment->path, path)) { | ||
| sentry__attachment_free(attachment); | ||
| return; | ||
| } | ||
|
|
||
| next_ptr = &last_attachment->next; | ||
| } | ||
|
|
||
| *next_ptr = attachment; | ||
| } | ||
|
|
||
| void | ||
| sentry__attachment_remove( | ||
| sentry_attachment_t **attachments_ptr, sentry_path_t *path) | ||
| { | ||
| sentry_attachment_t **next_ptr = attachments_ptr; | ||
|
|
||
| for (sentry_attachment_t *attachment = *attachments_ptr; attachment; | ||
| attachment = attachment->next) { | ||
| if (sentry__path_eq(attachment->path, path)) { | ||
| *next_ptr = attachment->next; | ||
| sentry__attachment_free(attachment); | ||
| goto out; | ||
| } | ||
|
|
||
| next_ptr = &attachment->next; | ||
| } | ||
|
|
||
| out: | ||
| sentry__path_free(path); | ||
| } | ||
|
|
||
| /** | ||
| * Reads the attachments from disk and adds them to the `envelope`. | ||
| */ | ||
| void | ||
| sentry__apply_attachments_to_envelope( | ||
jpnurmi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sentry_envelope_t *envelope, const sentry_attachment_t *attachments) | ||
| { | ||
| if (!attachments) { | ||
| return; | ||
| } | ||
|
|
||
| SENTRY_DEBUG("adding attachments to envelope"); | ||
| for (const sentry_attachment_t *attachment = attachments; attachment; | ||
| attachment = attachment->next) { | ||
| sentry_envelope_item_t *item = sentry__envelope_add_from_path( | ||
| envelope, attachment->path, "attachment"); | ||
| if (!item) { | ||
| continue; | ||
| } | ||
| if (attachment->type != ATTACHMENT) { // don't need to set the default | ||
| sentry__envelope_item_set_header(item, "attachment_type", | ||
| sentry_value_new_string( | ||
| str_from_attachment_type(attachment->type))); | ||
| } | ||
| if (attachment->content_type) { | ||
| sentry__envelope_item_set_header(item, "content_type", | ||
| sentry_value_new_string(attachment->content_type)); | ||
| } | ||
| sentry__envelope_item_set_header(item, "filename", | ||
| #ifdef SENTRY_PLATFORM_WINDOWS | ||
| sentry__value_new_string_from_wstr( | ||
| #else | ||
| sentry_value_new_string( | ||
| #endif | ||
| sentry__path_filename(attachment->path))); | ||
| } | ||
| } | ||
|
|
||
| void | ||
| sentry__attachments_extend( | ||
| sentry_attachment_t **attachments_ptr, sentry_attachment_t *attachments) | ||
| { | ||
| if (!attachments) { | ||
| return; | ||
| } | ||
|
|
||
| for (sentry_attachment_t *attachment = attachments; attachment; | ||
| attachment = attachment->next) { | ||
| sentry__attachment_add(attachments_ptr, | ||
| sentry__path_clone(attachment->path), attachment->type, | ||
| attachment->content_type); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.