-
-
Notifications
You must be signed in to change notification settings - Fork 196
feat: Add attachment support to user feedback #1414
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
base: master
Are you sure you want to change the base?
Changes from all commits
9c7fd8f
a339ca6
8126992
3f000f4
fccb567
2e74b67
121b078
eeefd2d
4c392e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| #include "sentry_core.h" | ||
| #include "sentry_database.h" | ||
| #include "sentry_envelope.h" | ||
| #include "sentry_feedback.h" | ||
| #include "sentry_logs.h" | ||
| #include "sentry_options.h" | ||
| #include "sentry_path.h" | ||
|
|
@@ -766,7 +767,8 @@ prepare_user_report(sentry_value_t user_report) | |
| } | ||
|
|
||
| static sentry_envelope_t * | ||
| prepare_user_feedback(sentry_value_t user_feedback) | ||
| prepare_user_feedback( | ||
| sentry_value_t user_feedback, sentry_feedback_hint_t *hint) | ||
| { | ||
| sentry_envelope_t *envelope = NULL; | ||
|
|
||
|
|
@@ -776,6 +778,10 @@ prepare_user_feedback(sentry_value_t user_feedback) | |
| goto fail; | ||
| } | ||
|
|
||
| if (hint && hint->attachments) { | ||
| sentry__envelope_add_attachments(envelope, hint->attachments); | ||
| } | ||
|
|
||
| return envelope; | ||
|
|
||
| fail: | ||
|
|
@@ -1483,17 +1489,27 @@ sentry_capture_user_feedback(sentry_value_t user_report) | |
|
|
||
| void | ||
| sentry_capture_feedback(sentry_value_t user_feedback) | ||
| { | ||
| // Reuse the implementation with NULL hint | ||
| sentry_capture_feedback_with_hint(user_feedback, NULL); | ||
| } | ||
|
|
||
| void | ||
| sentry_capture_feedback_with_hint( | ||
| sentry_value_t user_feedback, sentry_feedback_hint_t *hint) | ||
| { | ||
| sentry_envelope_t *envelope = NULL; | ||
|
|
||
| SENTRY_WITH_OPTIONS (options) { | ||
| envelope = prepare_user_feedback(user_feedback); | ||
| envelope = prepare_user_feedback(user_feedback, hint); | ||
| if (envelope) { | ||
| sentry__capture_envelope(options->transport, envelope); | ||
| } else { | ||
| sentry_value_decref(user_feedback); | ||
| } | ||
| } | ||
|
|
||
| if (hint) { | ||
| sentry__feedback_hint_free(hint); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Feedback Capture Function Ownership ViolationThe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If envelope was created successfully it takes ownership of the |
||
| } | ||
|
|
||
| bool | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| #include "sentry_feedback.h" | ||
|
|
||
| #include "sentry_alloc.h" | ||
| #include "sentry_attachment.h" | ||
| #include "sentry_path.h" | ||
| #include "sentry_string.h" | ||
|
|
||
| #include <string.h> | ||
|
|
||
| sentry_feedback_hint_t * | ||
| sentry_feedback_hint_new(void) | ||
| { | ||
| sentry_feedback_hint_t *hint = SENTRY_MAKE(sentry_feedback_hint_t); | ||
| if (!hint) { | ||
| return NULL; | ||
| } | ||
| memset(hint, 0, sizeof(sentry_feedback_hint_t)); | ||
| return hint; | ||
| } | ||
|
|
||
| void | ||
| sentry__feedback_hint_free(sentry_feedback_hint_t *hint) | ||
| { | ||
| if (!hint) { | ||
| return; | ||
| } | ||
| sentry__attachments_free(hint->attachments); | ||
| sentry_free(hint); | ||
| } | ||
|
|
||
| sentry_attachment_t * | ||
| sentry_feedback_hint_attach_file(sentry_feedback_hint_t *hint, const char *path) | ||
| { | ||
| return sentry_feedback_hint_attach_file_n( | ||
| hint, path, sentry__guarded_strlen(path)); | ||
| } | ||
|
|
||
| sentry_attachment_t * | ||
| sentry_feedback_hint_attach_file_n( | ||
| sentry_feedback_hint_t *hint, const char *path, size_t path_len) | ||
| { | ||
| if (!hint) { | ||
| return NULL; | ||
| } | ||
| return sentry__attachments_add_path(&hint->attachments, | ||
| sentry__path_from_str_n(path, path_len), ATTACHMENT, NULL); | ||
| } | ||
|
|
||
| sentry_attachment_t * | ||
| sentry_feedback_hint_attach_bytes(sentry_feedback_hint_t *hint, const char *buf, | ||
| size_t buf_len, const char *filename) | ||
| { | ||
| return sentry_feedback_hint_attach_bytes_n( | ||
| hint, buf, buf_len, filename, sentry__guarded_strlen(filename)); | ||
| } | ||
|
|
||
| sentry_attachment_t * | ||
| sentry_feedback_hint_attach_bytes_n(sentry_feedback_hint_t *hint, | ||
| const char *buf, size_t buf_len, const char *filename, size_t filename_len) | ||
| { | ||
| if (!hint) { | ||
| return NULL; | ||
| } | ||
| return sentry__attachments_add(&hint->attachments, | ||
| sentry__attachment_from_buffer( | ||
| buf, buf_len, sentry__path_from_str_n(filename, filename_len)), | ||
| ATTACHMENT, NULL); | ||
| } | ||
|
|
||
| #ifdef SENTRY_PLATFORM_WINDOWS | ||
| sentry_attachment_t * | ||
| sentry_feedback_hint_attach_filew( | ||
| sentry_feedback_hint_t *hint, const wchar_t *path) | ||
| { | ||
| size_t path_len = path ? wcslen(path) : 0; | ||
| return sentry_feedback_hint_attach_filew_n(hint, path, path_len); | ||
| } | ||
|
|
||
| sentry_attachment_t * | ||
| sentry_feedback_hint_attach_filew_n( | ||
| sentry_feedback_hint_t *hint, const wchar_t *path, size_t path_len) | ||
| { | ||
| if (!hint) { | ||
| return NULL; | ||
| } | ||
| return sentry__attachments_add_path(&hint->attachments, | ||
| sentry__path_from_wstr_n(path, path_len), ATTACHMENT, NULL); | ||
| } | ||
|
|
||
| sentry_attachment_t * | ||
| sentry_feedback_hint_attach_bytesw(sentry_feedback_hint_t *hint, | ||
| const char *buf, size_t buf_len, const wchar_t *filename) | ||
| { | ||
| size_t filename_len = filename ? wcslen(filename) : 0; | ||
| return sentry_feedback_hint_attach_bytesw_n( | ||
| hint, buf, buf_len, filename, filename_len); | ||
| } | ||
|
|
||
| sentry_attachment_t * | ||
| sentry_feedback_hint_attach_bytesw_n(sentry_feedback_hint_t *hint, | ||
| const char *buf, size_t buf_len, const wchar_t *filename, | ||
| size_t filename_len) | ||
| { | ||
| if (!hint) { | ||
| return NULL; | ||
| } | ||
| return sentry__attachments_add(&hint->attachments, | ||
| sentry__attachment_from_buffer( | ||
| buf, buf_len, sentry__path_from_wstr_n(filename, filename_len)), | ||
| ATTACHMENT, NULL); | ||
| } | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #ifndef SENTRY_FEEDBACK_H_INCLUDED | ||
| #define SENTRY_FEEDBACK_H_INCLUDED | ||
|
|
||
| #include "sentry_boot.h" | ||
|
|
||
| /** | ||
| * A sentry Feedback Hint used to pass additional data along with a feedback | ||
| * when it's being captured. | ||
| */ | ||
| struct sentry_feedback_hint_s { | ||
| sentry_attachment_t *attachments; | ||
| }; | ||
|
|
||
| /** | ||
| * Frees a feedback hint (internal use only). | ||
| */ | ||
| void sentry__feedback_hint_free(sentry_feedback_hint_t *hint); | ||
|
|
||
| #endif |
Uh oh!
There was an error while loading. Please reload this page.