|
| 1 | +#include "sentry_hint.h" |
| 2 | + |
| 3 | +#include "sentry_alloc.h" |
| 4 | +#include "sentry_attachment.h" |
| 5 | +#include "sentry_path.h" |
| 6 | +#include "sentry_string.h" |
| 7 | + |
| 8 | +#include <string.h> |
| 9 | + |
| 10 | +sentry_hint_t * |
| 11 | +sentry_hint_new(void) |
| 12 | +{ |
| 13 | + sentry_hint_t *hint = SENTRY_MAKE(sentry_hint_t); |
| 14 | + if (!hint) { |
| 15 | + return NULL; |
| 16 | + } |
| 17 | + memset(hint, 0, sizeof(sentry_hint_t)); |
| 18 | + return hint; |
| 19 | +} |
| 20 | + |
| 21 | +void |
| 22 | +sentry__hint_free(sentry_hint_t *hint) |
| 23 | +{ |
| 24 | + if (!hint) { |
| 25 | + return; |
| 26 | + } |
| 27 | + sentry__attachments_free(hint->attachments); |
| 28 | + sentry_free(hint); |
| 29 | +} |
| 30 | + |
| 31 | +sentry_attachment_t * |
| 32 | +sentry_hint_attach_file(sentry_hint_t *hint, const char *path) |
| 33 | +{ |
| 34 | + return sentry_hint_attach_file_n(hint, path, sentry__guarded_strlen(path)); |
| 35 | +} |
| 36 | + |
| 37 | +sentry_attachment_t * |
| 38 | +sentry_hint_attach_file_n( |
| 39 | + sentry_hint_t *hint, const char *path, size_t path_len) |
| 40 | +{ |
| 41 | + if (!hint) { |
| 42 | + return NULL; |
| 43 | + } |
| 44 | + return sentry__attachments_add_path(&hint->attachments, |
| 45 | + sentry__path_from_str_n(path, path_len), ATTACHMENT, NULL); |
| 46 | +} |
| 47 | + |
| 48 | +sentry_attachment_t * |
| 49 | +sentry_hint_attach_bytes( |
| 50 | + sentry_hint_t *hint, const char *buf, size_t buf_len, const char *filename) |
| 51 | +{ |
| 52 | + return sentry_hint_attach_bytes_n( |
| 53 | + hint, buf, buf_len, filename, sentry__guarded_strlen(filename)); |
| 54 | +} |
| 55 | + |
| 56 | +sentry_attachment_t * |
| 57 | +sentry_hint_attach_bytes_n(sentry_hint_t *hint, const char *buf, size_t buf_len, |
| 58 | + const char *filename, size_t filename_len) |
| 59 | +{ |
| 60 | + if (!hint) { |
| 61 | + return NULL; |
| 62 | + } |
| 63 | + return sentry__attachments_add(&hint->attachments, |
| 64 | + sentry__attachment_from_buffer( |
| 65 | + buf, buf_len, sentry__path_from_str_n(filename, filename_len)), |
| 66 | + ATTACHMENT, NULL); |
| 67 | +} |
| 68 | + |
| 69 | +#ifdef SENTRY_PLATFORM_WINDOWS |
| 70 | +sentry_attachment_t * |
| 71 | +sentry_hint_attach_filew(sentry_hint_t *hint, const wchar_t *path) |
| 72 | +{ |
| 73 | + size_t path_len = path ? wcslen(path) : 0; |
| 74 | + return sentry_hint_attach_filew_n(hint, path, path_len); |
| 75 | +} |
| 76 | + |
| 77 | +sentry_attachment_t * |
| 78 | +sentry_hint_attach_filew_n( |
| 79 | + sentry_hint_t *hint, const wchar_t *path, size_t path_len) |
| 80 | +{ |
| 81 | + if (!hint) { |
| 82 | + return NULL; |
| 83 | + } |
| 84 | + return sentry__attachments_add_path(&hint->attachments, |
| 85 | + sentry__path_from_wstr_n(path, path_len), ATTACHMENT, NULL); |
| 86 | +} |
| 87 | + |
| 88 | +sentry_attachment_t * |
| 89 | +sentry_hint_attach_bytesw(sentry_hint_t *hint, const char *buf, size_t buf_len, |
| 90 | + const wchar_t *filename) |
| 91 | +{ |
| 92 | + size_t filename_len = filename ? wcslen(filename) : 0; |
| 93 | + return sentry_hint_attach_bytesw_n( |
| 94 | + hint, buf, buf_len, filename, filename_len); |
| 95 | +} |
| 96 | + |
| 97 | +sentry_attachment_t * |
| 98 | +sentry_hint_attach_bytesw_n(sentry_hint_t *hint, const char *buf, |
| 99 | + size_t buf_len, const wchar_t *filename, size_t filename_len) |
| 100 | +{ |
| 101 | + if (!hint) { |
| 102 | + return NULL; |
| 103 | + } |
| 104 | + return sentry__attachments_add(&hint->attachments, |
| 105 | + sentry__attachment_from_buffer( |
| 106 | + buf, buf_len, sentry__path_from_wstr_n(filename, filename_len)), |
| 107 | + ATTACHMENT, NULL); |
| 108 | +} |
| 109 | +#endif |
0 commit comments