#ifndef SENTRY_UTILS_H_INCLUDED
#define SENTRY_UTILS_H_INCLUDED
#include "sentry_boot.h"
#ifdef SENTRY_PLATFORM_WINDOWS
# include <winnt.h>
#else
# include <sys/time.h>
# include <time.h>
#endif
typedef struct {
char *scheme;
char *host;
int port;
char *path;
char *query;
char *fragment;
char *username;
char *password;
} sentry_url_t;
int sentry__url_parse(sentry_url_t *url_out, const char *url);
void sentry__url_cleanup(sentry_url_t *url);
typedef struct sentry_dsn_s {
char *raw;
char *host;
char *path;
char *secret_key;
char *public_key;
uint64_t project_id;
int port;
long refcount;
bool is_valid;
bool is_secure;
} sentry_dsn_t;
sentry_dsn_t *sentry__dsn_new(const char *dsn);
sentry_dsn_t *sentry__dsn_incref(sentry_dsn_t *dsn);
void sentry__dsn_decref(sentry_dsn_t *dsn);
char *sentry__dsn_get_auth_header(const sentry_dsn_t *dsn);
char *sentry__dsn_get_envelope_url(const sentry_dsn_t *dsn);
char *sentry__dsn_get_minidump_url(const sentry_dsn_t *dsn);
static inline uint64_t
sentry__msec_time(void)
{
#ifdef SENTRY_PLATFORM_WINDOWS
FILETIME file_time;
SYSTEMTIME system_time;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
uint64_t timestamp = (uint64_t)file_time.dwLowDateTime
+ ((uint64_t)file_time.dwHighDateTime << 32);
timestamp -= 116444736000000000LL; timestamp /= 10000LL;
return timestamp;
#else
struct timeval tv;
return (gettimeofday(&tv, NULL) == 0)
? (uint64_t)tv.tv_sec * 1000 + tv.tv_usec / 1000
: 0;
#endif
}
static inline uint64_t
sentry__monotonic_time(void)
{
#ifdef SENTRY_PLATFORM_WINDOWS
static LARGE_INTEGER qpc_frequency = { 0 };
if (!qpc_frequency.QuadPart) {
QueryPerformanceFrequency(&qpc_frequency);
}
if (!qpc_frequency.QuadPart) {
# if _WIN32_WINNT >= 0x0600
return GetTickCount64();
# else
return GetTickCount();
# endif
}
LARGE_INTEGER qpc_counter;
QueryPerformanceCounter(&qpc_counter);
return qpc_counter.QuadPart * 1000 / qpc_frequency.QuadPart;
#else
struct timespec tv;
return (clock_gettime(CLOCK_MONOTONIC, &tv) == 0)
? (uint64_t)tv.tv_sec * 1000 + tv.tv_nsec / 1000000
: 0;
#endif
}
char *sentry__msec_time_to_iso8601(uint64_t time);
uint64_t sentry__iso8601_to_msec(const char *iso);
double sentry__strtod_c(const char *ptr, char **endptr);
int sentry__snprintf_c(char *buf, size_t buf_size, const char *fmt, ...);
#endif