Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

**Features**:

- Resume interrupted TUS attachment uploads from the server-provided upload offset. ([#2058](https://github.com/getsentry/sentry-native/pull/2058))
- Add `sentry_is_enabled` for checking whether the SDK has been initialized. ([#2045](https://github.com/getsentry/sentry-native/pull/2045))
- Add `sentry_event_set_level` for setting the level of an individual event. ([#2038](https://github.com/getsentry/sentry-native/pull/2038))

Expand Down
17 changes: 13 additions & 4 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,15 @@ SENTRY_EXPERIMENTAL_API const char *sentry_http_request_get_body(
SENTRY_EXPERIMENTAL_API const char *sentry_http_request_get_body_file_path(
const sentry_http_request_t *req, size_t *len_out);

/**
* Returns the byte offset at which a file-backed request body starts. The
* client must seek to this position before streaming the number of bytes
* returned by `sentry_http_request_get_body_file_path`. Returns `0` for
* requests without a file-backed body.
*/
SENTRY_EXPERIMENTAL_API size_t sentry_http_request_get_body_file_offset(
const sentry_http_request_t *req);

#ifdef SENTRY_PLATFORM_WINDOWS
/**
* Wide char version of `sentry_http_request_get_body_file_path`.
Expand All @@ -1126,10 +1135,10 @@ SENTRY_EXPERIMENTAL_API void sentry_http_response_set_status_code(
/**
* Records a response header on `resp`. `key` is matched case-insensitively
* against the headers sentry-native cares about (currently `Retry-After`,
* `X-Sentry-Rate-Limits`, and `Location`); anything else is ignored. Pass
* every header the HTTP response actually had -- sentry-native, not the
* client, decides which ones matter, so headers Sentry starts caring about
* later don't require client changes.
* `X-Sentry-Rate-Limits`, `Location`, and `Upload-Offset`); anything else is
* ignored. Pass every header the HTTP response actually had -- sentry-native,
* not the client, decides which ones matter, so headers Sentry starts caring
* about later don't require client changes.
*/
SENTRY_EXPERIMENTAL_API void sentry_http_response_set_header(
sentry_http_response_t *resp, const char *key, const char *value);
Expand Down
36 changes: 36 additions & 0 deletions src/path/sentry_path.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "sentry_path.h"
#include "sentry_alloc.h"

#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>

sentry_path_t *
sentry__path_from_str_n(const char *s, size_t s_len)
Expand Down Expand Up @@ -153,3 +155,37 @@ sentry__path_basename(const sentry_path_t *path, const char *suffix)
}
return NULL;
}

FILE *
sentry__path_open(const sentry_path_t *path, const char *mode, size_t offset)
{
if (!path || !mode) {
return NULL;
}
#ifdef SENTRY_PLATFORM_WINDOWS
wchar_t *mode_w = sentry__string_to_wstr(mode);
FILE *file = mode_w ? _wfopen(path->path_w, mode_w) : NULL;
sentry_free(mode_w);
#else
FILE *file = fopen(path->path, mode);
#endif
if (!file) {
return NULL;
}
#ifdef SENTRY_PLATFORM_WINDOWS
int result
= offset > INT64_MAX ? -1 : _fseeki64(file, (__int64)offset, SEEK_SET);
#elif defined(SENTRY_PLATFORM_NX)
int result = offset > LONG_MAX ? -1 : fseek(file, (long)offset, SEEK_SET);
#else
off_t file_offset = (off_t)offset;
int result = file_offset < 0 || (size_t)file_offset != offset
? -1
: fseeko(file, file_offset, SEEK_SET);
#endif
if (result != 0) {
fclose(file);
return NULL;
}
return file;
}
7 changes: 7 additions & 0 deletions src/sentry_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "sentry_boot.h"
#include "sentry_string.h"

#include <stdio.h>
#include <time.h>

struct sentry_path_s {
Expand Down Expand Up @@ -207,6 +208,12 @@ int sentry__path_touch(const sentry_path_t *path);
*/
size_t sentry__path_get_size(const sentry_path_t *path);

/**
* Opens `path` with `mode` and seeks to `offset`, or returns NULL on failure.
*/
FILE *sentry__path_open(
const sentry_path_t *path, const char *mode, size_t offset);

/**
* This will return the last modification time of the file at `path`, or 0 on
* failure.
Expand Down
Loading
Loading