Skip to content

Commit

Permalink
Build: Add clang-format support (#37)
Browse files Browse the repository at this point in the history
* Add .clang-format

* Run clang-format

* Adds a basic clang-format target

* Add CONTIBUTING.md and update README.md and AUTHORS.
  • Loading branch information
PSUdaemon authored and linuxwolf committed Nov 14, 2016
1 parent 60b6b6a commit 7d0f556
Show file tree
Hide file tree
Showing 33 changed files with 2,056 additions and 2,543 deletions.
90 changes: 90 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
Language: Cpp
# BasedOnStyle: GNU
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 132
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp03
TabWidth: 8
UseTab: Never
...

2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Listed alphabetically by surname

Andrew Biggs <[email protected]>
Leif Hedström <[email protected]>
Matthew A. Miller <[email protected]>
Phil Sorber <[email protected]>
Andy Wang <[email protected]>
Hans Zandbelt <https://github.com/zandbelt>
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Contributing #

## Before Submitting PR ##

* Run `make clang-format`
* Run `make test`

*NOTE* You must use clang-format 3.9.0. You can download binaries from [here](https://bintray.com/apache/trafficserver/clang-format-tools).
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ package-prepare : dist

package-local : package-prepare
@echo packages built

clang-format:
clang-format -i `find . -name *.[ch]`
3 changes: 3 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,9 @@ package-prepare : dist
package-local : package-prepare
@echo packages built

clang-format:
clang-format -i `find . -name *.[ch]`

# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Implementation of JOSE for C/C++
* libtool (>= 2.4)
* Check (>= 0.9.4) - unit testing (e.g. check-devel)
* Doxygen (>= 1.8) - documentation
* clang-format (= 3.9.0)

### Libraries ###

Expand Down Expand Up @@ -86,3 +87,10 @@ This has been seen on Mac OSX 10.9 when openssl 1.0.1h or newer has been install
This has been seen on Mac OSX 10.9 when Jansson has been installed via brew. A solution is to explicitly include the jansson directory in the configure command:

./configure --with-jansson=/usr/local/opt/jansson

## Contributing ##

### Before Submitting PR ###

* Run `make clang-format`
* Run `make test`
4 changes: 1 addition & 3 deletions include/cjose/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#include "cjose/error.h"

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif

/**
Expand Down Expand Up @@ -80,7 +79,6 @@ bool cjose_base64_decode(const char *input, const size_t inlen, uint8_t **output
*/
bool cjose_base64url_decode(const char *input, const size_t inlen, uint8_t **output, size_t *outlen, cjose_err *err);


#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/cjose/cjose.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
#include "jws.h"
#include "util.h"

#endif // CJOSE_CJOSE_H
#endif // CJOSE_CJOSE_H
57 changes: 25 additions & 32 deletions include/cjose/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
#define CJOSE_ERROR_H

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif


/**
* Temporarily disable compiler warnings, if possible (>=gcc-4.6).
*
Expand All @@ -26,23 +24,21 @@ extern "C"
* specific points in the compilation.
*/
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
# define GCC_END_IGNORED_WARNING _Pragma("GCC diagnostic pop")
#define GCC_END_IGNORED_WARNING _Pragma("GCC diagnostic pop")

# define GCC_BEGIN_IGNORED_WARNING_ADDRESS \
_Pragma("GCC diagnostic push"); \
#define GCC_BEGIN_IGNORED_WARNING_ADDRESS \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Waddress\"")
# define GCC_END_IGNORED_WARNING_ADDRESS GCC_END_IGNORED_WARNING
#define GCC_END_IGNORED_WARNING_ADDRESS GCC_END_IGNORED_WARNING
#else
# define GCC_BEGIN_IGNORED_WARNING_ADDRESS
# define GCC_END_IGNORED_WARNING_ADDRESS
#define GCC_BEGIN_IGNORED_WARNING_ADDRESS
#define GCC_END_IGNORED_WARNING_ADDRESS
#endif /* defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC_MINOR__ > 5) */


/**
* Enumeration of defined error codes.
*/
typedef enum
{
typedef enum {
/** No error */
CJOSE_ERR_NONE = 0,

Expand All @@ -60,7 +56,6 @@ typedef enum

} cjose_errcode;


/**
* An instance of an error context. Unlike other structures, it
* is the API user's responsibility to allocate the structure; however
Expand All @@ -70,32 +65,30 @@ typedef enum
typedef struct
{
/** The error code */
cjose_errcode code;
cjose_errcode code;

/** The human readable message for the error code */
const char * message;
const char *message;

/** The function where the error occured, or "<unknown>"
if it cannot be determined */
const char * function;
const char *function;

/** The file where the error occured */
const char * file;
const char *file;

/** The line number in the file where the error occured */
unsigned long line;
unsigned long line;

} cjose_err;


/**
* Retrieves the error message for the given error code.
*
* \param code The error code to lookup
* \retval const char * The message for {code}
*/
const char * cjose_err_message(cjose_errcode code);

const char *cjose_err_message(cjose_errcode code);

/**
* \def CJOSE_ERROR(err, code)
Expand All @@ -105,20 +98,20 @@ const char * cjose_err_message(cjose_errcode code);
* \param err The pointer to the error context, or NULL if none
* \param errcode The error code
*/
#define CJOSE_ERROR(err, errcode) \
GCC_BEGIN_IGNORED_WARNING_ADDRESS \
if ((err) != NULL && (errcode) != CJOSE_ERR_NONE) \
{ \
(err)->code = (errcode); \
(err)->message = cjose_err_message((errcode)); \
(err)->function = __func__; \
(err)->file = __FILE__; \
(err)->line = __LINE__; \
} \
#define CJOSE_ERROR(err, errcode) \
GCC_BEGIN_IGNORED_WARNING_ADDRESS \
if ((err) != NULL && (errcode) != CJOSE_ERR_NONE) \
{ \
(err)->code = (errcode); \
(err)->message = cjose_err_message((errcode)); \
(err)->function = __func__; \
(err)->file = __FILE__; \
(err)->line = __LINE__; \
} \
GCC_END_IGNORED_WARNING_ADDRESS

#ifdef __cplusplus
}
#endif

#endif /* CJOSE_ERROR_H */
#endif /* CJOSE_ERROR_H */
31 changes: 7 additions & 24 deletions include/cjose/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
#include "cjose/error.h"

#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif


/** The JWE algorithm header attribute name. */
extern const char *CJOSE_HDR_ALG;

Expand Down Expand Up @@ -82,13 +80,11 @@ extern const char *CJOSE_HDR_ENC_A128CBC_HS256;
extern const char *CJOSE_HDR_ENC_A192CBC_HS384;
extern const char *CJOSE_HDR_ENC_A256CBC_HS512;


/**
* An instance of a header object (used when creating JWE/JWS objects).
*/
typedef struct json_t cjose_header_t;


/**
* Instsantiates a new header object. Caller is responsible for
* subsequently releasing the object through cjose_header_release().
Expand All @@ -97,9 +93,7 @@ typedef struct json_t cjose_header_t;
* information in the event of an error.
* \returns a newly allocated header object, or NULL if an error occurs.
*/
cjose_header_t *cjose_header_new(
cjose_err *err);

cjose_header_t *cjose_header_new(cjose_err *err);

/**
* Retains an existing header object. Callers must use this method if the
Expand All @@ -109,8 +103,7 @@ cjose_header_t *cjose_header_new(
* \param header[in] the header object to be retained.
* \returns the retained header object
*/
cjose_header_t *cjose_header_retain(
cjose_header_t *header);
cjose_header_t *cjose_header_retain(cjose_header_t *header);

/**
* Releases an existing header object. Callers must use this method
Expand All @@ -119,9 +112,7 @@ cjose_header_t *cjose_header_retain(
*
* \param header[in] the header object to be released.
*/
void cjose_header_release(
cjose_header_t *header);

void cjose_header_release(cjose_header_t *header);

/**
* Sets a header attribute on a header object. If that header was
Expand All @@ -134,11 +125,7 @@ void cjose_header_release(
* information in the event of an error.
* \returns true if header is successfully set.
*/
bool cjose_header_set(
cjose_header_t *header,
const char *attr,
const char *value,
cjose_err *err);
bool cjose_header_set(cjose_header_t *header, const char *attr, const char *value, cjose_err *err);

/**
* Retrieves the value of the requested header attribute from the header
Expand All @@ -150,14 +137,10 @@ bool cjose_header_set(
* information in the event of an error.
* \returns a string containing the current value for the requested attribute.
*/
const char *cjose_header_get(
cjose_header_t *header,
const char *attr,
cjose_err *err);

const char *cjose_header_get(cjose_header_t *header, const char *attr, cjose_err *err);

#ifdef __cplusplus
}
#endif

#endif // CJOSE_HEADER_H
#endif // CJOSE_HEADER_H
Loading

0 comments on commit 7d0f556

Please sign in to comment.