Skip to content
Merged
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
8 changes: 4 additions & 4 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@
FAE80C242E4695B40010A595 /* SentryEvent+Serialize.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE80C232E4695AE0010A595 /* SentryEvent+Serialize.h */; };
FAEC270E2DF3526000878871 /* SentryUserFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */; };
FAEC273D2DF3933A00878871 /* NSData+Unzip.m in Sources */ = {isa = PBXBuildFile; fileRef = FAEC273C2DF3933200878871 /* NSData+Unzip.m */; };
FAEEC0522E75E55F00E79CA9 /* DataDeserialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEEC04C2E75E55A00E79CA9 /* DataDeserialization.swift */; };
FAEEC0522E75E55F00E79CA9 /* SentrySerializationSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEEC04C2E75E55A00E79CA9 /* SentrySerializationSwift.swift */; };
FAEFA12F2E4FAE1900C431D9 /* SentrySDKSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEFA1292E4FAE1700C431D9 /* SentrySDKSettings.swift */; };
FAF120182E70C08F006E1DA3 /* SentryEnvelopeHeaderHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = FAF120122E70C088006E1DA3 /* SentryEnvelopeHeaderHelper.h */; };
FAF1201A2E70C0EE006E1DA3 /* SentryEnvelopeHeaderHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = FAF120192E70C0EA006E1DA3 /* SentryEnvelopeHeaderHelper.m */; };
Expand Down Expand Up @@ -2470,7 +2470,7 @@
FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUserFeedback.swift; sourceTree = "<group>"; };
FAEC273C2DF3933200878871 /* NSData+Unzip.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Unzip.m"; sourceTree = "<group>"; };
FAEC273E2DF393E000878871 /* NSData+Unzip.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+Unzip.h"; sourceTree = "<group>"; };
FAEEC04C2E75E55A00E79CA9 /* DataDeserialization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataDeserialization.swift; sourceTree = "<group>"; };
FAEEC04C2E75E55A00E79CA9 /* SentrySerializationSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySerializationSwift.swift; sourceTree = "<group>"; };
FAEFA1292E4FAE1700C431D9 /* SentrySDKSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySDKSettings.swift; sourceTree = "<group>"; };
FAF120122E70C088006E1DA3 /* SentryEnvelopeHeaderHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEnvelopeHeaderHelper.h; path = include/SentryEnvelopeHeaderHelper.h; sourceTree = "<group>"; };
FAF120192E70C0EA006E1DA3 /* SentryEnvelopeHeaderHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryEnvelopeHeaderHelper.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2606,7 +2606,7 @@
isa = PBXGroup;
children = (
62CB19242E77F8FD00AF5DA2 /* SentryDispatchSourceWrapper.swift */,
FAEEC04C2E75E55A00E79CA9 /* DataDeserialization.swift */,
FAEEC04C2E75E55A00E79CA9 /* SentrySerializationSwift.swift */,
FA94E71B2E6F26BF00576666 /* SentrySerialization+ReplayRecording.swift */,
FA94E7232E6F32FA00576666 /* SentryEnvelopeItemType.swift */,
FA458CBD2E691A6E0061B13D /* SentryProcessInfo.swift */,
Expand Down Expand Up @@ -5583,7 +5583,7 @@
FA90FAA82E06614E008CAAE8 /* SentryExtraPackages.swift in Sources */,
7BD86ED1264A7CF6005439DB /* SentryAppStartMeasurement.m in Sources */,
7DC27EC723997EB7006998B5 /* SentryAutoBreadcrumbTrackingIntegration.m in Sources */,
FAEEC0522E75E55F00E79CA9 /* DataDeserialization.swift in Sources */,
FAEEC0522E75E55F00E79CA9 /* SentrySerializationSwift.swift in Sources */,
D84D2CDF2C2BF9370011AF8A /* SentryReplayType.swift in Sources */,
63FE717B20DA4C1100CDBAE8 /* SentryCrashReport.c in Sources */,
D8F67B222BEAB6CC00C9197B /* SentryRRWebEvent.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/PrivateSentrySDKOnly.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ + (void)captureEnvelope:(SentryEnvelope *)envelope

+ (nullable SentryEnvelope *)envelopeWithData:(NSData *)data
{
return [SentrySerialization envelopeWithData:data];
return [SentrySerializationSwift envelopeWithData:data];
}

#if !SDK_V9
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/Public/SentryEnvelopeItemHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SENTRY_NO_INIT

- (instancetype)initWithType:(NSString *)type
length:(NSUInteger)length
contentType:(NSString *)contentType
contentType:(NSString *_Nullable)contentType
itemCount:(NSNumber *)itemCount;

/**
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryAttachment.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ - (instancetype)initWithPath:(NSString *)path
}

SentryAttachmentType
typeForSentryAttachmentName(NSString *name)
typeForSentryAttachmentName(NSString *_Nullable name)
{
if ([name isEqualToString:kSentryAttachmentTypeNameViewHierarchy]) {
return kSentryAttachmentTypeViewHierarchy;
Expand Down
6 changes: 3 additions & 3 deletions Sources/Sentry/SentryFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ - (nullable SentrySession *)readSession:(NSString *)sessionFilePath
return nil;
}
}
SentrySession *currentSession = [DataDeserialization sessionWithData:currentData];
SentrySession *currentSession = [SentrySerializationSwift sessionWithData:currentData];
if (nil == currentSession) {
SENTRY_LOG_ERROR(
@"Data stored in session: '%@' was not parsed as session.", sessionFilePath);
Expand All @@ -993,7 +993,7 @@ - (SentryAppState *_Nullable)readAppStateFrom:(NSString *)path
SENTRY_LOG_WARN(@"No app state data found at %@", path);
return nil;
}
return [DataDeserialization appStateWithData:currentData];
return [SentrySerializationSwift appStateWithData:currentData];
}

- (void)deleteAppStateFrom:(NSString *)path
Expand Down Expand Up @@ -1073,7 +1073,7 @@ - (void)handleEnvelopesLimit
[envelopePathsCopy removeObjectAtIndex:i];

NSData *envelopeData = [[NSFileManager defaultManager] contentsAtPath:envelopeFilePath];
SentryEnvelope *envelope = [SentrySerialization envelopeWithData:envelopeData];
SentryEnvelope *envelope = [SentrySerializationSwift envelopeWithData:envelopeData];

BOOL didMigrateSessionInit =
[SentryMigrateSessionInit migrateSessionInit:envelope
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryHttpTransport.m
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ - (void)sendAllCachedEnvelopes

envelopeFilePath = envelopeFileContents.path;

envelope = [SentrySerialization envelopeWithData:envelopeFileContents.contents];
envelope = [SentrySerializationSwift envelopeWithData:envelopeFileContents.contents];
if (nil == envelope) {
SENTRY_LOG_DEBUG(@"Envelope contained no deserializable data.");
[self deleteEnvelopeAndSendNext:envelopeFilePath];
Expand Down
6 changes: 3 additions & 3 deletions Sources/Sentry/SentryMigrateSessionInit.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ + (BOOL)migrateSessionInit:(nullable SentryEnvelope *)envelope
@"Could not migrate session init, because the envelope item has no data.");
continue;
}
SentrySession *session = [DataDeserialization sessionWithData:data];
SentrySession *session = [SentrySerializationSwift sessionWithData:data];
if (nil != session && [session.flagInit boolValue]) {
BOOL didSetInitFlag =
[self setInitFlagOnNextEnvelopeWithSameSessionId:session
Expand Down Expand Up @@ -56,7 +56,7 @@ + (BOOL)setInitFlagOnNextEnvelopeWithSameSessionId:(SentrySession *)session
continue;
}

SentryEnvelope *envelope = [SentrySerialization envelopeWithData:envelopeData];
SentryEnvelope *envelope = [SentrySerializationSwift envelopeWithData:envelopeData];

if (nil != envelope) {
BOOL didSetInitFlag = [self setInitFlagIfContainsSameSessionId:session.sessionId
Expand Down Expand Up @@ -84,7 +84,7 @@ + (BOOL)setInitFlagIfContainsSameSessionId:(NSUUID *)sessionId
@"Could not migrate session init, because the envelope item has no data.");
continue;
}
SentrySession *localSession = [DataDeserialization sessionWithData:data];
SentrySession *localSession = [SentrySerializationSwift sessionWithData:data];

if (nil != localSession && [localSession.sessionId isEqual:sessionId]) {
[localSession setFlagInit];
Expand Down
159 changes: 0 additions & 159 deletions Sources/Sentry/SentrySerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,171 +70,12 @@
}
[envelopeData appendData:itemHeader];
[envelopeData appendData:newLineData];
[envelopeData appendData:envelope.items[i].data];

Check warning on line 73 in Sources/Sentry/SentrySerialization.m

View workflow job for this annotation

GitHub Actions / Build XCFramework Slices (SentrySwiftUI, mh_dylib, sentry-swiftui) / watchos

implicit conversion from nullable pointer 'NSData * _Nullable' to non-nullable pointer type 'NSData * _Nonnull' [-Wnullable-to-nonnull-conversion]

Check warning on line 73 in Sources/Sentry/SentrySerialization.m

View workflow job for this annotation

GitHub Actions / Sample watchOS-Swift WatchKit App Debug

implicit conversion from nullable pointer 'NSData * _Nullable' to non-nullable pointer type 'NSData * _Nonnull' [-Wnullable-to-nonnull-conversion]

Check warning on line 73 in Sources/Sentry/SentrySerialization.m

View workflow job for this annotation

GitHub Actions / Build XCFramework Slices (Sentry, mh_dylib, -WithoutUIKitOrAppKit, WithoutUIKit, sentry-withoutui... / appletvos

implicit conversion from nullable pointer 'NSData * _Nullable' to non-nullable pointer type 'NSData * _Nonnull' [-Wnullable-to-nonnull-conversion]

Check warning on line 73 in Sources/Sentry/SentrySerialization.m

View workflow job for this annotation

GitHub Actions / Build XCFramework Slices (Sentry, staticlib, sentry-static) / watchos

implicit conversion from nullable pointer 'NSData * _Nullable' to non-nullable pointer type 'NSData * _Nonnull' [-Wnullable-to-nonnull-conversion]

Check warning on line 73 in Sources/Sentry/SentrySerialization.m

View workflow job for this annotation

GitHub Actions / Build XCFramework Slices (Sentry, mh_dylib, -Dynamic, sentry-dynamic) / watchos

implicit conversion from nullable pointer 'NSData * _Nullable' to non-nullable pointer type 'NSData * _Nonnull' [-Wnullable-to-nonnull-conversion]

Check warning on line 73 in Sources/Sentry/SentrySerialization.m

View workflow job for this annotation

GitHub Actions / Build XCFramework Slices (Sentry, mh_dylib, -WithoutUIKitOrAppKit, WithoutUIKit, sentry-withoutui... / xros

implicit conversion from nullable pointer 'NSData * _Nullable' to non-nullable pointer type 'NSData * _Nonnull' [-Wnullable-to-nonnull-conversion]

Check warning on line 73 in Sources/Sentry/SentrySerialization.m

View workflow job for this annotation

GitHub Actions / Build XCFramework Slices (Sentry, mh_dylib, -WithoutUIKitOrAppKit, WithoutUIKit, sentry-withoutui... / watchos

implicit conversion from nullable pointer 'NSData * _Nullable' to non-nullable pointer type 'NSData * _Nonnull' [-Wnullable-to-nonnull-conversion]
}

return envelopeData;
}

+ (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data
{
SentryEnvelopeHeader *envelopeHeader = nil;
const unsigned char *bytes = [data bytes];
NSUInteger envelopeHeaderIndex = 0;

for (NSUInteger i = 0; i < data.length; ++i) {
if (bytes[i] == '\n') {
envelopeHeaderIndex = i;
// Envelope header end
NSData *headerData = [NSData dataWithBytes:bytes length:i];
#ifdef DEBUG
NSString *headerString = [[NSString alloc] initWithData:headerData
encoding:NSUTF8StringEncoding];
SENTRY_LOG_DEBUG(@"Header %@", headerString);
#endif
NSError *error = nil;
NSDictionary *headerDictionary = [NSJSONSerialization JSONObjectWithData:headerData
options:0
error:&error];
if (nil != error) {
SENTRY_LOG_ERROR(@"Failed to parse envelope header %@", error);
break;
}

SentryId *eventId = nil;
NSString *eventIdAsString = headerDictionary[@"event_id"];
if (nil != eventIdAsString) {
eventId = [[SentryId alloc] initWithUUIDString:eventIdAsString];
}

SentrySdkInfo *sdkInfo = nil;
if (nil != headerDictionary[@"sdk"] &&
[headerDictionary[@"sdk"] isKindOfClass:[NSDictionary class]]) {
sdkInfo = [[SentrySdkInfo alloc]
initWithDict:SENTRY_UNWRAP_NULLABLE(NSDictionary, headerDictionary[@"sdk"])];
}

SentryTraceContext *traceContext = nil;
if (nil != headerDictionary[@"trace"] &&
[headerDictionary[@"trace"] isKindOfClass:[NSDictionary class]]) {
traceContext = [[SentryTraceContext alloc]
initWithDict:SENTRY_UNWRAP_NULLABLE(NSDictionary, headerDictionary[@"trace"])];
}

envelopeHeader = [[SentryEnvelopeHeader alloc] initWithId:eventId
sdkInfo:sdkInfo
traceContext:traceContext];

if (headerDictionary[@"sent_at"] != nil &&
[headerDictionary[@"sent_at"] isKindOfClass:[NSString class]]) {
envelopeHeader.sentAt = sentry_fromIso8601String(
SENTRY_UNWRAP_NULLABLE(NSString, headerDictionary[@"sent_at"]));
}

break;
}
}

if (nil == envelopeHeader) {
SENTRY_LOG_ERROR(@"Invalid envelope. No header found.");
return nil;
}

if (envelopeHeaderIndex == 0) {
SENTRY_LOG_ERROR(@"EnvelopeHeader was parsed, its index is expected.");
return nil;
}

// Parse items
NSUInteger itemHeaderStart = envelopeHeaderIndex + 1;

NSMutableArray<SentryEnvelopeItem *> *items = [NSMutableArray new];
NSUInteger endOfEnvelope = data.length - 1;

for (NSUInteger i = itemHeaderStart; i <= endOfEnvelope; ++i) {
if (bytes[i] == '\n' || i == endOfEnvelope) {

NSData *itemHeaderData =
[data subdataWithRange:NSMakeRange(itemHeaderStart, i - itemHeaderStart)];
#ifdef DEBUG
NSString *itemHeaderString = [[NSString alloc] initWithData:itemHeaderData
encoding:NSUTF8StringEncoding];
SENTRY_LOG_DEBUG(@"Item Header %@", itemHeaderString);
#endif
NSError *error = nil;
NSDictionary *headerDictionary = [NSJSONSerialization JSONObjectWithData:itemHeaderData
options:0
error:&error];
if (nil != error) {
SENTRY_LOG_ERROR(@"Failed to parse envelope item header %@", error);
return nil;
}
NSString *_Nullable nullableType = [headerDictionary valueForKey:@"type"];
if (nil == nullableType) {
SENTRY_LOG_ERROR(@"Envelope item type is required.");
break;
}
NSString *_Nonnull type = SENTRY_UNWRAP_NULLABLE(NSString, nullableType);

NSNumber *bodyLengthNumber = [headerDictionary valueForKey:@"length"];
NSUInteger bodyLength = [bodyLengthNumber unsignedIntegerValue];
if (endOfEnvelope == i && bodyLength != 0) {
SENTRY_LOG_ERROR(
@"Envelope item has no data but header indicates it's length is %d.",
(int)bodyLength);
break;
}

NSString *filename = [headerDictionary valueForKey:@"filename"];
NSString *contentType = [headerDictionary valueForKey:@"content_type"];
NSString *attachmentType = [headerDictionary valueForKey:@"attachment_type"];
NSNumber *itemCount = [headerDictionary valueForKey:@"item_count"];

SentryEnvelopeItemHeader *itemHeader;
if (nil != filename) {
itemHeader = [[SentryEnvelopeAttachmentHeader alloc]
initWithType:type
length:bodyLength
filename:filename
contentType:contentType
attachmentType:typeForSentryAttachmentName(attachmentType)];
} else if (nil != itemCount) {
itemHeader = [[SentryEnvelopeItemHeader alloc] initWithType:type
length:bodyLength
contentType:contentType
itemCount:itemCount];
} else {
itemHeader = [[SentryEnvelopeItemHeader alloc] initWithType:type length:bodyLength];
}

if (endOfEnvelope == i) {
i++; // 0 byte attachment
}

if (bodyLength > 0 && data.length < (i + 1 + bodyLength)) {
SENTRY_LOG_ERROR(@"Envelope is corrupted or has invalid data. Trying to read %li "
@"bytes by skipping %li from a buffer of %li bytes.",
(unsigned long)data.length, (unsigned long)bodyLength, (long)(i + 1));
return nil;
}

NSData *itemBody = [data subdataWithRange:NSMakeRange(i + 1, bodyLength)];
SentryEnvelopeItem *envelopeItem = [[SentryEnvelopeItem alloc] initWithHeader:itemHeader
data:itemBody];
[items addObject:envelopeItem];
i = itemHeaderStart = i + 1 + [bodyLengthNumber integerValue];
}
}

if (items.count == 0) {
SENTRY_LOG_ERROR(@"Envelope has no items.");
return nil;
}

SentryEnvelope *envelope = [[SentryEnvelope alloc] initWithHeader:envelopeHeader items:items];
return envelope;
}

+ (NSData *_Nullable)dataWithSession:(SentrySession *)session
{
return [self dataWithJSONObject:[session serialize]];
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/include/SentryAttachment+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef NS_ENUM(NSInteger, SentryAttachmentType) {

NSString *nameForSentryAttachmentType(SentryAttachmentType attachmentType);

SentryAttachmentType typeForSentryAttachmentName(NSString *name);
SentryAttachmentType typeForSentryAttachmentName(NSString *_Nullable name);

@interface SentryAttachment ()
SENTRY_NO_INIT
Expand Down
2 changes: 0 additions & 2 deletions Sources/Sentry/include/SentrySerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ NS_ASSUME_NONNULL_BEGIN

+ (NSData *_Nullable)dataWithEnvelope:(SentryEnvelope *)envelope;

+ (SentryEnvelope *_Nullable)envelopeWithData:(NSData *)data;

/**
* Retrieves the json object from an event envelope item data.
*/
Expand Down
32 changes: 0 additions & 32 deletions Sources/Swift/Helper/DataDeserialization.swift

This file was deleted.

Loading
Loading