Skip to content
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

fix: Continuously read from buffer while no errors occur. #11

Merged
merged 4 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.0.4 (26–12-2023)

### Fixes

- Continuously read from buffer while no errors occur. The buffer was closing itself after being put on hold, rather than waiting to read the entire package from the SSLRead.

# 0.0.2 (09–26-2022)

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ During the current phase of this project, we only support SPM. We have plans to
dependencies: [
.package(
url: "https://github.com/twilio/twilio-verify-sna-ios.git",
.upToNextMajor(from: "0.0.2")
.upToNextMajor(from: "0.0.4")
yafuquen marked this conversation as resolved.
Show resolved Hide resolved
)
]
```
Expand Down
30 changes: 19 additions & 11 deletions SNASources/CellularSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ - (CellularSessionResult * _Nonnull)performRequest:(NSURL * _Nonnull)url {
const char* request = [requestString UTF8String];

char buffer[4096];

NSMutableData *responseData = [NSMutableData dataWithCapacity:0];

// Step 4). Invoke the HTTP request using the instantiated socket

if ([[url scheme] isEqualToString:@"http"]) {
Expand Down Expand Up @@ -282,14 +283,21 @@ - (CellularSessionResult * _Nonnull)performRequest:(NSURL * _Nonnull)url {
do {
// SSLRead performs a typical application-level read operation.
status = SSLRead(context, buffer, sizeof(buffer) - 1, &processed);
buffer[processed] = 0;

// If the buffer was filled, then continue reading
if (processed == sizeof(buffer) - 1) {
status = errSSLWouldBlock;

if (status == noErr && processed > 0) {
[responseData appendBytes:buffer length:processed]; // Append the received data to responseData
} else if (status == errSSLWouldBlock) {
// No more data available
SSLClose(context);
CFRelease(context);
status = noErr;
break;
} else {
// No data received
break;
}
} while (status == errSSLWouldBlock);
} while (status == noErr);

if (status && status != errSSLClosedGraceful) {
SSLClose(context);
CFRelease(context);
Expand All @@ -301,9 +309,9 @@ - (CellularSessionResult * _Nonnull)performRequest:(NSURL * _Nonnull)url {

}
}
NSString *response = [[NSString alloc] initWithBytes:buffer length:sizeof(buffer) encoding:NSASCIIStringEncoding];

NSString *response = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];

// Step 5). Parse the HTTP response and check whether it contains a redirect HTTP code

if ([response rangeOfString:@"HTTP/"].location == NSNotFound) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/TwilioVerifySNAConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
import Foundation

public struct TwilioVerifySNAConfig {
public static let version = "0.0.2"
public static let version = "0.0.4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,4 @@ extension PhoneNumberViewController {
}

/// Not required for the SDK implementation.
private let sampleAppVersion = "0.0.3"
private let sampleAppVersion = "0.0.4"
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Configuration/Info.plist;
Expand All @@ -417,7 +417,7 @@
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 0.0.3;
MARKETING_VERSION = 0.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.twilio.TwilioVerifySNADemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -433,7 +433,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 4;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Configuration/Info.plist;
Expand All @@ -448,7 +448,7 @@
"@executable_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 0.0.3;
MARKETING_VERSION = 0.0.4;
PRODUCT_BUNDLE_IDENTIFIER = com.twilio.TwilioVerifySNADemo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down