-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ceb5329
Showing
24 changed files
with
3,892 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Original Contribution: | ||
|
||
* Dell Inc. -- Patrick Boyd ([email protected]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
# Change Log | ||
|
||
## [1.0.0] - 2017-10-17 | ||
- Initial Public Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
cmake_minimum_required(VERSION 2.6) | ||
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}") | ||
|
||
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
|
||
set(REDFISH_HDR_PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/redfish.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/redfishPayload.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/redpath.h) | ||
|
||
file(GLOB REDFISH_SRC src/*.c) | ||
|
||
source_group("Library Sources" FILES ${REDFISH_SRC}) | ||
|
||
find_package(CURL REQUIRED) | ||
find_package(Jansson REQUIRED) | ||
find_package(CZMQ) | ||
|
||
add_library(redfish SHARED ${REDFISH_SRC} ${REDFISH_HDR_PRIVATE}) | ||
if(CZMQ_FOUND) | ||
target_link_libraries(redfish jansson curl czmq) | ||
else() | ||
target_link_libraries(redfish jansson curl) | ||
add_definitions( -DNO_CZMQ ) | ||
endif() | ||
|
||
add_executable(redfishtest "${CMAKE_CURRENT_SOURCE_DIR}/examples/test.c") | ||
target_link_libraries(redfishtest redfish) | ||
|
||
if(CZMQ_FOUND) | ||
add_executable(redfishevent "${CMAKE_CURRENT_SOURCE_DIR}/httpd/cgi.c") | ||
target_link_libraries(redfishevent czmq) | ||
endif() | ||
|
||
ENABLE_TESTING() | ||
|
||
if(CMAKE_COMPILER_IS_GNUCC) | ||
add_definitions(-Wall -Wextra -Wdeclaration-after-statement -ggdb3) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
include(FindPkgConfig) | ||
PKG_CHECK_MODULES(PC_CZMQ "libczmq") | ||
|
||
find_path( | ||
CZMQ_INCLUDE_DIRS | ||
NAMES czmq.h | ||
HINTS ${PC_CZMQ_INCLUDE_DIRS} | ||
) | ||
|
||
find_library( | ||
CZMQ_LIBRARIES | ||
NAMES czmq | ||
HINTS ${PC_CZMQ_LIBRARY_DIRS} | ||
) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CZMQ DEFAULT_MSG CZMQ_LIBRARIES CZMQ_INCLUDE_DIRS) | ||
mark_as_advanced(CZMQ_LIBRARIES CZMQ_INCLUDE_DIRS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# - Try to find Jansson | ||
# Once done this will define | ||
# | ||
# JANSSON_FOUND - system has Jansson | ||
# JANSSON_INCLUDE_DIRS - the Jansson include directory | ||
# JANSSON_LIBRARIES - Link these to use Jansson | ||
# | ||
# Copyright (c) 2011 Lee Hambley <[email protected]> | ||
# | ||
# Redistribution and use is allowed according to the terms of the New | ||
# BSD license. | ||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file. | ||
# | ||
|
||
if (JANSSON_LIBRARIES AND JANSSON_INCLUDE_DIRS) | ||
# in cache already | ||
set(JANSSON_FOUND TRUE) | ||
else (JANSSON_LIBRARIES AND JANSSON_INCLUDE_DIRS) | ||
find_path(JANSSON_INCLUDE_DIR | ||
NAMES | ||
jansson.h | ||
PATHS | ||
/usr/include | ||
/usr/local/include | ||
/opt/local/include | ||
/sw/include | ||
) | ||
|
||
find_library(JANSSON_LIBRARY | ||
NAMES | ||
jansson | ||
PATHS | ||
/usr/lib | ||
/usr/local/lib | ||
/opt/local/lib | ||
/sw/lib | ||
) | ||
|
||
set(JANSSON_INCLUDE_DIRS | ||
${JANSSON_INCLUDE_DIR} | ||
) | ||
|
||
if (JANSSON_LIBRARY) | ||
set(JANSSON_LIBRARIES | ||
${JANSSON_LIBRARIES} | ||
${JANSSON_LIBRARY} | ||
) | ||
endif (JANSSON_LIBRARY) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(Jansson DEFAULT_MSG | ||
JANSSON_LIBRARIES JANSSON_INCLUDE_DIRS) | ||
|
||
# show the JANSSON_INCLUDE_DIRS and JANSSON_LIBRARIES variables only in the advanced view | ||
mark_as_advanced(JANSSON_INCLUDE_DIRS JANSSON_LIBRARIES) | ||
|
||
endif (JANSSON_LIBRARIES AND JANSSON_INCLUDE_DIRS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
The Distributed Management Task Force (DMTF) grants rights under copyright in | ||
this software on the terms of the BSD 3-Clause License as set forth below; no | ||
other rights are granted by DMTF. This software might be subject to other rights | ||
(such as patent rights) of other parties. | ||
|
||
|
||
### Copyrights. | ||
|
||
Copyright (c) 2017, Contributing Member(s) of Distributed Management Task Force, | ||
Inc.. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, this | ||
list of conditions and the following disclaimer in the documentation and/or | ||
other materials provided with the distribution. | ||
* Neither the name of the Distributed Management Task Force (DMTF) nor the names | ||
of its contributors may be used to endorse or promote products derived from this | ||
software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
### Patents. | ||
|
||
This software may be subject to third party patent rights, including provisional | ||
patent rights ("patent rights"). DMTF makes no representations to users of the | ||
standard as to the existence of such rights, and is not responsible to | ||
recognize, disclose, or identify any or all such third party patent right, | ||
owners or claimants, nor for any incomplete or inaccurate identification or | ||
disclosure of such rights, owners or claimants. DMTF shall have no liability to | ||
any party, in any manner or circumstance, under any legal theory whatsoever, for | ||
failure to recognize, disclose, or identify any such third party patent rights, | ||
or for such party's reliance on the software or incorporation thereof in its | ||
product, protocols or testing procedures. DMTF shall have no liability to any | ||
party using such software, whether such use is foreseeable or not, nor to any | ||
patent owner or claimant, and shall have no liability or responsibility for | ||
costs or losses incurred if software is withdrawn or modified after publication, | ||
and shall be indemnified and held harmless by any party using the software from | ||
any and all claims of infringement by a patent owner for such use. | ||
|
||
DMTF Members that contributed to this software source code might have made | ||
patent licensing commitments in connection with their participation in the DMTF. | ||
For details, see http://dmtf.org/sites/default/files/patent-10-18-01.pdf and | ||
http://www.dmtf.org/about/policies/disclosures. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# libRedfish | ||
|
||
Copyright 2017 Distributed Management Task Force, Inc. All rights reserved. | ||
|
||
## About | ||
|
||
libRedfish is a C client library that allows for Creation of Entities (POST), Read of Entities (GET), Update of Entities (PATCH), Deletion of Entities (DELETE), running Actions (POST), receiving events, and providing some basic query abilities. | ||
|
||
## Pre-requisists | ||
|
||
libRedfish is based on C and the compiling system is required to have: | ||
* CMake | ||
* C Compiler | ||
* libjanson - http://www.digip.org/jansson/ | ||
* libcurl - https://curl.haxx.se/libcurl/ | ||
To receive events a user needs an existing webserver supporting FastCGI (such as Apache or nginx) and libczmq (https://github.com/zeromq/czmq). | ||
|
||
## Compilation | ||
|
||
Run cmake. | ||
|
||
## RedPath | ||
|
||
libRedfish uses a query language based on XPath (https://www.w3.org/TR/1999/REC-xpath-19991116/). This library and query language essentially treat the entire Redfish Service like it was a single JSON document. In other words whenever it encounters an @odata.id it will retrieve the new document (if needed). | ||
|
||
| Expression | Description | | ||
| ----------------- | -------------------------------------------------------------------------------------------------------------- | | ||
| *nodename* | Selects the JSON entity with the name "nodename" | | ||
| / | Selects from the root node | | ||
| [*index*] | Selects the index number JSON entity from an array or object | | ||
| [*nodename*] | Selects all the elements from an array or object that contain a property named "nodename" | | ||
| [*name*=*value*] | Selects all the elements from an array or object where the property "name" is equal to "value" | | ||
| [*name*<*value*] | Selects all the elements from an array or object where the property "name" is less than "value" | | ||
| [*name*<=*value*] | Selects all the elements from an array or object where the property "name" is less than or equal to "value" | | ||
| [*name*>*value*] | Selects all the elements from an array or object where the property "name" is greater than "value" | | ||
| [*name*>=*value*] | Selects all the elements from an array or object where the property "name" is greater than or equal to "value" | | ||
|
||
Some examples: | ||
|
||
* /Chassis[1] - Will return the first Chassis instance | ||
* /Chassis[SKU=1234] - Will return all Chassis instances with a SKU field equal to 1234 | ||
* /Systems[Storage] - Will return all the System instances that have Storage field populated | ||
|
||
## C Example | ||
|
||
```C | ||
#include <redfish.h> | ||
#include <stdio.h> | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
redfishService* service = createRedfishServiceEnumerator(argv[1], NULL, NULL, 0); | ||
redfishPayload* payload = getPayloadByPath(service, argv[2]); | ||
char* payloadStr = payloadToString(payload, true); | ||
printf("Payload Value = %s\n", payloadStr); | ||
free(payloadStr); | ||
cleanupPayload(payload); | ||
cleanupEnumerator(service); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//---------------------------------------------------------------------------- | ||
// Copyright Notice: | ||
// Copyright 2017 Distributed Management Task Force, Inc. All rights reserved. | ||
// License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libredfish/LICENSE.md | ||
//---------------------------------------------------------------------------- | ||
public class RedfishAuth { | ||
public RedfishAuthType authType; | ||
public String username; | ||
public String password; | ||
public String token; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//---------------------------------------------------------------------------- | ||
// Copyright Notice: | ||
// Copyright 2017 Distributed Management Task Force, Inc. All rights reserved. | ||
// License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libredfish/LICENSE.md | ||
//---------------------------------------------------------------------------- | ||
public enum RedfishAuthType { | ||
NoAuth, | ||
BasicAuth, | ||
TokenAuth, | ||
RedfishSessionAuth | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//---------------------------------------------------------------------------- | ||
// Copyright Notice: | ||
// Copyright 2017 Distributed Management Task Force, Inc. All rights reserved. | ||
// License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libredfish/LICENSE.md | ||
//---------------------------------------------------------------------------- | ||
public class RedfishPayload { | ||
static { | ||
System.loadLibrary("redfish"); | ||
} | ||
|
||
private long cPayload; | ||
|
||
public RedfishPayload(long cPayload) { | ||
this.cPayload = cPayload; | ||
} | ||
|
||
public RedfishPayload(RedfishService service, String content) { | ||
this.cPayload = service.createRedfishPayloadFromString(content); | ||
} | ||
|
||
protected void finalize( ) throws Throwable { | ||
this.cleanupPayload(this.cPayload); | ||
this.cPayload = 0; | ||
super.finalize(); | ||
} | ||
|
||
private native boolean isPayloadCollection(long payload); | ||
private native String getPayloadStringValue(long payload); | ||
private native long getPayloadIntValue(long payload); | ||
private native long getPayloadByNodeName(long payload, String nodeName); | ||
private native long getPayloadByIndex(long payload, long index); | ||
private native long getPayloadForPathString(long payload, String path); | ||
private native long cGetCollectionSize(long payload); | ||
private native long patchPayloadStringProperty(long payload, String propertyName, String value); | ||
private native long postPayload(long target, long payload); | ||
private native boolean deletePayload(long payload); | ||
private native String payloadToString(long payload, boolean prettyPrint); | ||
private native void cleanupPayload(long payload); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//---------------------------------------------------------------------------- | ||
// Copyright Notice: | ||
// Copyright 2017 Distributed Management Task Force, Inc. All rights reserved. | ||
// License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libredfish/LICENSE.md | ||
//---------------------------------------------------------------------------- | ||
public class RedfishService { | ||
static { | ||
System.loadLibrary("redfish"); | ||
} | ||
|
||
private long cService; | ||
|
||
public RedfishService(String host) { | ||
RedfishAuth auth = new RedfishAuth(); | ||
auth.authType = RedfishAuthType.NoAuth; | ||
this.cService = this.createServiceEnumerator(host, "", auth, 0); | ||
} | ||
|
||
public RedfishService(String host, String rootUri) { | ||
RedfishAuth auth = new RedfishAuth(); | ||
auth.authType = RedfishAuthType.NoAuth; | ||
this.cService = this.createServiceEnumerator(host, rootUri, auth, 0); | ||
} | ||
|
||
public RedfishService(String host, String rootUri, RedfishAuth auth) { | ||
this.cService = this.createServiceEnumerator(host, rootUri, auth, 0); | ||
} | ||
|
||
public RedfishService(String host, String rootUri, RedfishAuth auth, int flags) { | ||
this.cService = this.createServiceEnumerator(host, rootUri, auth, flags); | ||
} | ||
|
||
protected void finalize( ) throws Throwable { | ||
this.cleanupServiceEnumerator(this.cService); | ||
this.cService = 0; | ||
super.finalize(); | ||
} | ||
|
||
public RedfishPayload getServiceRoot() { | ||
return new RedfishPayload(this.getRedfishServiceRoot(this.cService, "")); | ||
} | ||
|
||
public RedfishPayload getServiceRoot(String version) { | ||
return new RedfishPayload(this.getRedfishServiceRoot(this.cService, version)); | ||
} | ||
|
||
public RedfishPayload getPayloadByPath(String path) { | ||
return new RedfishPayload(this.cGetPayloadByPath(this.cService, path)); | ||
} | ||
|
||
private native long createServiceEnumerator(String host, String rootUri, RedfishAuth auth, int flags); | ||
private native long getRedfishServiceRoot(long service, String version); | ||
private native long cGetPayloadByPath(long service, String path); | ||
private native void cleanupServiceEnumerator(long service); | ||
|
||
// Test Driver | ||
public static void main(String[] args) { | ||
new RedfishService("http://127.0.0.1"); | ||
} | ||
} |
Oops, something went wrong.