Skip to content

Commit

Permalink
Merge pull request #45 from vijs/master
Browse files Browse the repository at this point in the history
Updated certifierUtil to use xc APIs
  • Loading branch information
vijs committed Jul 30, 2024
2 parents 1707914 + 8f0a8f5 commit 6aba143
Show file tree
Hide file tree
Showing 9 changed files with 584 additions and 60 deletions.
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ include(DoxygenDoc)
include(CheckCCompilerFlag)

file(GLOB SOURCES "src/*.c")
list(FILTER SOURCES EXCLUDE REGEX "src/main.c|src/test.c")
list(FILTER SOURCES EXCLUDE REGEX "src/main.c|src/main-legacy.c|src/test.c")

configure_file(certifier.ver.in certifier.ver @ONLY)
add_library(certifier SHARED ${SOURCES})
Expand All @@ -104,7 +104,11 @@ target_link_libraries(certifier_ ${CERTIFIER_LIBS})
SET_TARGET_PROPERTIES(certifier_ PROPERTIES
OUTPUT_NAME certifier CLEAN_DIRECT_OUTPUT 1)

add_executable(certifierUtil "src/error.c" "src/main.c" )
add_executable(certifierUtilLegacy "src/error.c" "src/main-legacy.c" )
target_link_libraries(certifierUtilLegacy ${CERTIFIER_UTIL_LIBS})
target_include_directories(certifierUtilLegacy PUBLIC include PRIVATE internal_headers ${CERTIFIER_INCLUDE_DIRS} ${MBED_TLS_INCLUDE_DIR})

add_executable(certifierUtil "src/main.c" )
target_link_libraries(certifierUtil ${CERTIFIER_UTIL_LIBS})
target_include_directories(certifierUtil PUBLIC include PRIVATE internal_headers ${CERTIFIER_INCLUDE_DIRS} ${MBED_TLS_INCLUDE_DIR})

Expand Down Expand Up @@ -341,6 +345,7 @@ endif ()

install(TARGETS certifier LIBRARY DESTINATION lib)
install(DIRECTORY include/certifier DESTINATION include)
install(TARGETS certifierUtilLegacy RUNTIME DESTINATION bin)
install(TARGETS certifierUtil RUNTIME DESTINATION bin)
install(FILES libcertifier.cfg.sample DESTINATION etc/certifier RENAME libcertifier.cfg)
install(FILES libcertifier-cert.crt DESTINATION etc/certifier)
Expand Down
33 changes: 33 additions & 0 deletions internal_headers/certifier/code_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef CODE_UTILS_H
#define CODE_UTILS_H

#define ReturnErrorOnFailure(expr) \
do \
{ \
int __err = (expr); \
if (__err != 0) \
{ \
return __err; \
} \
} while (0)

#define VerifyOrReturnError(expr, code) \
do \
{ \
if (!(expr)) \
{ \
return (code); \
} \
} while (0)

#define VerifyOrExit(statement, action) \
do \
{ \
if ((statement) != 1) \
{ \
action; \
goto exit; \
} \
} while (0)

#endif // CODE_UTILS_H
8 changes: 8 additions & 0 deletions internal_headers/certifier/xpki_client_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef XPKI_CLIENT_INTERNAL_H
#define XPKI_CLIENT_INTERNAL_H

#include "certifier/certifier.h"

extern Certifier * get_certifier_instance();

#endif // XPKI_CLIENT_INTERNAL_H
46 changes: 46 additions & 0 deletions src/main-legacy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright 2019 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

#define _POSIX_C_SOURCE 2

// Includes
#include "certifier/certifier_api_easy.h"
#include "certifier/log.h"
#include "certifier/types.h"

// Main
int main(int argc, char * argv[])
{
int return_code = 0;
CERTIFIER * easy = certifier_api_easy_new();

certifier_api_easy_set_cli_args(easy, argc, argv);
certifier_api_easy_set_mode(easy, certifier_api_easy_get_mode(easy));
return_code = certifier_api_easy_perform(easy);

const char * result = certifier_api_easy_get_result_json(easy);

if (result != NULL)
{
log_info(result);
}

certifier_api_easy_destroy(easy);

return return_code != 0;
}
Loading

0 comments on commit 6aba143

Please sign in to comment.