Skip to content

Commit

Permalink
Add and apply ObjC clang-format configuration. (#1456)
Browse files Browse the repository at this point in the history
No functional changes.

Relates-To: OLPEDGE-2849

Signed-off-by: Rustam Gamidov <[email protected]>
  • Loading branch information
rustam-gamidov-here authored Dec 8, 2023
1 parent a06b5b1 commit 7c45d8e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInParentheses: false
SpacesInSquareBrackets: false

---
Language: ObjC
BasedOnStyle: Google
ColumnLimit: 80
17 changes: 9 additions & 8 deletions olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#import <CommonCrypto/CommonDigest.h>
#import <Security/Security.h>

#include "olp/core/logging/Log.h"
#include "olp/core/http/Network.h"
#include "olp/core/http/NetworkProxySettings.h"
#include "olp/core/logging/Log.h"

#import "OLPHttpTask+Internal.h"

Expand Down Expand Up @@ -389,15 +389,16 @@ - (NSURLSession*)urlSessionWithProxy:
if (ProxyType::SOCKS4 == requestedProxyType ||
ProxyType::SOCKS5 == requestedProxyType ||
ProxyType::SOCKS5_HOSTNAME == requestedProxyType) {
proxyDict[(__bridge NSString*)kCFProxyTypeKey] = (__bridge NSString*)kCFProxyTypeSOCKS;
proxyDict[(__bridge NSString*)kCFProxyTypeKey] =
(__bridge NSString*)kCFProxyTypeSOCKS;
} else if (ProxyType::HTTP == requestedProxyType) {
proxyDict[(__bridge NSString*)kCFNetworkProxiesHTTPEnable] = @(1);
proxyDict[(__bridge NSString*)kCFNetworkProxiesHTTPProxy] = proxyName;
proxyDict[(__bridge NSString*)kCFNetworkProxiesHTTPPort] = @(port);
proxyDict[(__bridge NSString*)kCFNetworkProxiesHTTPEnable] = @(1);
proxyDict[(__bridge NSString*)kCFNetworkProxiesHTTPProxy] = proxyName;
proxyDict[(__bridge NSString*)kCFNetworkProxiesHTTPPort] = @(port);
} else if (ProxyType::HTTPS == requestedProxyType) {
proxyDict[@"HTTPSEnable"] = @(1);
proxyDict[@"HTTPSProxy"] = proxyName;
proxyDict[@"HTTPSPort"] = @(port);
proxyDict[@"HTTPSEnable"] = @(1);
proxyDict[@"HTTPSProxy"] = proxyName;
proxyDict[@"HTTPSPort"] = @(port);
}

proxyDict[(__bridge NSString*)kCFProxyHostNameKey] = proxyName;
Expand Down
4 changes: 3 additions & 1 deletion olp-cpp-sdk-core/src/http/ios/OLPHttpTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ typedef NS_ENUM(NSUInteger, OLPHttpTaskStatus) {

typedef void (^OLPHttpTaskReponseHandler)(NSHTTPURLResponse* response);
typedef void (^OLPHttpTaskDataHandler)(NSData* data);
typedef void (^OLPHttpTaskCompletionHandler)(NSError* error, uint64_t bytesDownloaded, uint64_t bytesUploadeds);
typedef void (^OLPHttpTaskCompletionHandler)(NSError* error,
uint64_t bytesDownloaded,
uint64_t bytesUploadeds);

/**
* @brief This class holds the response data from OLPHttpTask request.
Expand Down
21 changes: 10 additions & 11 deletions olp-cpp-sdk-core/src/http/ios/OLPHttpTask.mm
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,8 @@ - (BOOL)cancel {

- (void)didCompleteWithError:(NSError*)error {
int status = 0;
if (self.responseData)
{
status = self.responseData.status;
if (self.responseData) {
status = self.responseData.status;
}

OLP_SDK_LOG_DEBUG_F(kLogTag,
Expand All @@ -163,9 +162,11 @@ - (void)didCompleteWithError:(NSError*)error {
}

if (completionHandler) {
completionHandler(error,
_headersSizeReceived + (_contentLength ? _contentLength : _dataTask.countOfBytesReceived),
_headersSizeSent + _dataTask.countOfBytesSent);
completionHandler(
error,
_headersSizeReceived +
(_contentLength ? _contentLength : _dataTask.countOfBytesReceived),
_headersSizeSent + _dataTask.countOfBytesSent);
}

@synchronized(self) {
Expand All @@ -192,11 +193,9 @@ - (void)didReceiveResponse:(NSURLResponse*)response {

if (responseHandler) {
auto headers = ((NSHTTPURLResponse*)response).allHeaderFields;
for (NSString* key in headers)
{
for (NSString* key in headers) {
NSString* value = headers[key];
if ([key isEqualToString:@"Content-Length"])
{
if ([key isEqualToString:@"Content-Length"]) {
auto longLongValue = [value longLongValue];
_contentLength = longLongValue < 0 ? 0 : longLongValue;
}
Expand Down Expand Up @@ -227,7 +226,7 @@ - (void)didReceiveData:(NSData*)data {
}
}

- (NSString*) createTaskDescription {
- (NSString*)createTaskDescription {
return [NSString stringWithFormat:@"%llu", self.requestId];
}

Expand Down
3 changes: 1 addition & 2 deletions olp-cpp-sdk-core/src/http/ios/OLPNetworkIOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class OLPNetworkIOS : public olp::http::Network {
~OLPNetworkIOS();

olp::http::SendOutcome Send(
olp::http::NetworkRequest request,
std::shared_ptr<std::ostream> payload,
olp::http::NetworkRequest request, std::shared_ptr<std::ostream> payload,
olp::http::Network::Callback callback,
olp::http::Network::HeaderCallback header_callback = nullptr,
olp::http::Network::DataCallback data_callback = nullptr) override;
Expand Down
23 changes: 12 additions & 11 deletions olp-cpp-sdk-core/src/http/ios/OLPNetworkIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

#import <Foundation/Foundation.h>

#include "olp/core/logging/Log.h"
#include "olp/core/http/Network.h"
#include "olp/core/http/NetworkTypes.h"
#include "olp/core/http/NetworkUtils.h"
#include "olp/core/logging/Log.h"

#import "OLPHttpClient+Internal.h"
#import "OLPHttpTask.h"
Expand Down Expand Up @@ -145,8 +145,8 @@
OLP_SDK_LOG_WARNING_F(kLogTag,
"Send failed - reached max requests "
"count=%lu/%lu, url=%s",
http_client_.activeTasks.count, max_requests_count_,
request.GetUrl().c_str());
http_client_.activeTasks.count,
max_requests_count_, request.GetUrl().c_str());
return SendOutcome(ErrorCode::NETWORK_OVERLOAD_ERROR);
}

Expand All @@ -165,8 +165,10 @@
// Setup task request data:
const NetworkSettings& settings = request.GetSettings();

const auto connectionTimeoutSeconds = std::chrono::duration_cast<std::chrono::seconds>(
settings.GetConnectionTimeoutDuration()).count();
const auto connectionTimeoutSeconds =
std::chrono::duration_cast<std::chrono::seconds>(
settings.GetConnectionTimeoutDuration())
.count();

task.url = url;
task.connectionTimeout = static_cast<int>(connectionTimeoutSeconds);
Expand Down Expand Up @@ -252,10 +254,9 @@
if (payload->tellp() != std::streampos(response_data.count)) {
payload->seekp(response_data.count);
if (payload->fail()) {
OLP_SDK_LOG_WARNING_F(kLogTag,
"Payload seekp() failed, request_id=%llu, url=%s",
strong_task.requestId,
[strong_task.url UTF8String]);
OLP_SDK_LOG_WARNING_F(
kLogTag, "Payload seekp() failed, request_id=%llu, url=%s",
strong_task.requestId, [strong_task.url UTF8String]);
payload->clear();
}
}
Expand All @@ -267,7 +268,8 @@
};

// setup handler for NSURLSessionDataTask::didCompleteWithError callback
task.completionHandler = ^(NSError* error, uint64_t bytesDownloaded, uint64_t bytesUploaded) {
task.completionHandler = ^(NSError* error, uint64_t bytesDownloaded,
uint64_t bytesUploaded) {
if (!weak_task) {
OLP_SDK_LOG_WARNING_F(
kLogTag,
Expand Down Expand Up @@ -312,7 +314,6 @@
.WithBytesDownloaded(bytesDownloaded)
.WithBytesUploaded(bytesUploaded));
}

};

// Perform send request asycnrhonously in a NSURLSession's thread
Expand Down

0 comments on commit 7c45d8e

Please sign in to comment.