Skip to content

Commit

Permalink
Format using clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwoj-microsoft committed Feb 21, 2025
1 parent df99404 commit 033c331
Show file tree
Hide file tree
Showing 23 changed files with 996 additions and 841 deletions.
88 changes: 88 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
BasedOnStyle: Microsoft
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: BeforeColon
PackConstructorInitializers: Never
ColumnLimit: 152
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
IndentCaseLabels: true
IndentExternBlock: NoIndent
IndentWidth: 4
IndentPPDirectives: AfterHash
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 100
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: CaseSensitive
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatementsExceptControlMacros
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseCRLF: false
UseTab: Never
IndentAccessModifiers: false
AccessModifierOffset: -4
EmptyLineBeforeAccessModifier: Always
IncludeBlocks: Regroup
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ repos:
.*\.cmd|
.*\.csrpoj
)$
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.6
hooks:
- id: clang-format
files: |
(?x)(
^src/modules/compliance/.*\.h$|
^src/modules/compliance/.*\.cpp$
)
146 changes: 74 additions & 72 deletions src/modules/compliance/src/lib/Base64.cpp
Original file line number Diff line number Diff line change
@@ -1,96 +1,98 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include <string>
#include "Result.h"
#include "Base64.h"

#include "Result.h"

#include <string>

namespace compliance
{
static inline char Base64Char(const unsigned char c)
static inline char Base64Char(const unsigned char c)
{
if (c >= 'A' && c <= 'Z')
{
if (c >= 'A' && c <= 'Z')
{
return c - 'A';
}
else if (c >= 'a' && c <= 'z')
{
return c - 'a' + 26;
}
else if (c >= '0' && c <= '9')
{
return c - '0' + 52;
}
else if (c == '+')
{
return 62;
}
else if (c == '/')
{
return 63;
}
else
{
return 0;
}
return c - 'A';
}

static inline bool IsBase64(const unsigned char c)
else if (c >= 'a' && c <= 'z')
{
return c - 'a' + 26;
}
else if (c >= '0' && c <= '9')
{
return (isalnum(c) || (c == '+') || (c == '/') || (c == '='));
return c - '0' + 52;
}
else if (c == '+')
{
return 62;
}
else if (c == '/')
{
return 63;
}
else
{
return 0;
}
}

Result<std::string> Base64Decode(const std::string &input)
static inline bool IsBase64(const unsigned char c)
{
return (isalnum(c) || (c == '+') || (c == '/') || (c == '='));
}

Result<std::string> Base64Decode(const std::string& input)
{
if (input.size() % 4 != 0)
{
return Error("Invalid base64 length", EINVAL);
}
for (const char c : input)
{
if (input.size() % 4 != 0)
if (!IsBase64(c))
{
return Error("Invalid base64 length", EINVAL);
}
for (const char c : input)
{
if (!IsBase64(c))
{
return Error("Invalid base64 character", EINVAL);
}
return Error("Invalid base64 character", EINVAL);
}
}

std::string ret;
ret.reserve((input.size() * 3) / 4);
std::string ret;
ret.reserve((input.size() * 3) / 4);

for (size_t i = 0; i < input.size(); i += 4)
{
unsigned char enc[4];
for (size_t i = 0; i < input.size(); i += 4)
{
unsigned char enc[4];

int j = 0;
for (j = 0; j < 4; j++)
int j = 0;
for (j = 0; j < 4; j++)
{
if (input[i + j] == '=')
{
if (input[i+j] == '=')
{
break;
}
enc[j] = Base64Char(input[i + j]);
break;
}
enc[j] = Base64Char(input[i + j]);
}

if (j == 4)
{
ret += (enc[0] << 2) | (enc[1] >> 4);
ret += ((enc[1] & 0x0f) << 4) | (enc[2] >> 2);
ret += ((enc[2] & 0x03) << 6) | enc[3];
}
else if (j == 3)
{
ret += (enc[0] << 2) | (enc[1] >> 4);
ret += ((enc[1] & 0x0f) << 4) | (enc[2] >> 2);
}
else if (j == 2)
{
ret += (enc[0] << 2) | (enc[1] >> 4);
}
else
{
return Error("Invalid base64", EINVAL);
}
if (j == 4)
{
ret += (enc[0] << 2) | (enc[1] >> 4);
ret += ((enc[1] & 0x0f) << 4) | (enc[2] >> 2);
ret += ((enc[2] & 0x03) << 6) | enc[3];
}
else if (j == 3)
{
ret += (enc[0] << 2) | (enc[1] >> 4);
ret += ((enc[1] & 0x0f) << 4) | (enc[2] >> 2);
}
else if (j == 2)
{
ret += (enc[0] << 2) | (enc[1] >> 4);
}
else
{
return Error("Invalid base64", EINVAL);
}
return ret;
}
return ret;
}
} // namespace compliance
5 changes: 3 additions & 2 deletions src/modules/compliance/src/lib/Base64.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#ifndef BASE64_H
#define BASE64_H

#include <string>
#include "Result.h"

#include <string>

namespace compliance
{
Result<std::string> Base64Decode(const std::string &input);
Result<std::string> Base64Decode(const std::string& input);
}

#endif // BASE64_H
11 changes: 10 additions & 1 deletion src/modules/compliance/src/lib/ComplianceInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
// Licensed under the MIT License.

#include "ComplianceInterface.h"

#include "CommonUtils.h"
#include "Engine.h"
#include "Logging.h"
#include "Mmi.h"

#include <cerrno>
#include <cstddef>
#include <cstring>
#include <exception>

using compliance::Engine;

Expand Down Expand Up @@ -126,7 +134,8 @@ int ComplianceMmiSet(MMI_HANDLE clientSession, const char* componentName, const
return result.error().code;
}

OsConfigLogInfo(engine.log(), "MmiSet(%p, %s, %s, %.*s, %d) returned %s", clientSession, componentName, objectName, payloadSizeBytes, payload, payloadSizeBytes, result.value() ? "true" : "false");
OsConfigLogInfo(engine.log(), "MmiSet(%p, %s, %s, %.*s, %d) returned %s", clientSession, componentName, objectName, payloadSizeBytes, payload,
payloadSizeBytes, result.value() ? "true" : "false");
return MMI_OK;
}
catch (const std::exception& e)
Expand Down
Loading

0 comments on commit 033c331

Please sign in to comment.