|
Packit |
534379 |
// Copyright(c) 2019-2020, Intel Corporation
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
534379 |
// modification, are permitted provided that the following conditions are met:
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer.
|
|
Packit |
534379 |
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
534379 |
// this list of conditions and the following disclaimer in the documentation
|
|
Packit |
534379 |
// and/or other materials provided with the distribution.
|
|
Packit |
534379 |
// * Neither the name of Intel Corporation nor the names of its contributors
|
|
Packit |
534379 |
// may be used to endorse or promote products derived from this software
|
|
Packit |
534379 |
// without specific prior written permission.
|
|
Packit |
534379 |
//
|
|
Packit |
534379 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
534379 |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
534379 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
534379 |
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
534379 |
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
534379 |
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
534379 |
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
534379 |
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
534379 |
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
534379 |
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
534379 |
// POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* @file bits_utils.h
|
|
Packit |
534379 |
* @brief Utility functions for GBS metadata parsing.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* These functions extract basic types (strings,
|
|
Packit |
534379 |
* integers, doubles)
|
|
Packit |
534379 |
* from the given JSON object.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#ifndef __OPAE_BITS_UTILS_H__
|
|
Packit |
534379 |
#define __OPAE_BITS_UTILS_H__
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#include <json-c/json.h>
|
|
Packit |
534379 |
#include <opae/types.h>
|
|
Packit |
534379 |
#include <stdbool.h>
|
|
Packit |
534379 |
#include <stdint.h>
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#ifdef __cplusplus
|
|
Packit |
534379 |
extern "C" {
|
|
Packit |
534379 |
#endif /* __cplusplus */
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Allocate and populate string value from JSON object.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @param[in] parent The JSON object in which to search for `name`.
|
|
Packit |
534379 |
* @param[in] name The search key.
|
|
Packit |
534379 |
* @param[out] value Receives the allocated buffer.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @returns FPGA_OK on success. FPGA_EXCEPTION if `name`
|
|
Packit |
534379 |
* is not found or if `name` is not a key of type string.
|
|
Packit |
534379 |
* FPGA_NO_MEMORY if memory allocation fails.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @note Allocates memory. The buffer saved at `*value`
|
|
Packit |
534379 |
* on success must be tracked and freed when no longer
|
|
Packit |
534379 |
* needed.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
fpga_result opae_bitstream_get_json_string(json_object *parent,
|
|
Packit |
534379 |
const char *name,
|
|
Packit |
534379 |
char **value);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Populate integer value from JSON object.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @param[in] parent The JSON object in which to search for `name`.
|
|
Packit |
534379 |
* @param[in] name The search key.
|
|
Packit |
534379 |
* @param[out] value Receives the integer value.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @returns FPGA_OK on success. FPGA_EXCEPTION if `name`
|
|
Packit |
534379 |
* is not found or if `name` is not a key of type integer.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
fpga_result opae_bitstream_get_json_int(json_object *parent,
|
|
Packit |
534379 |
const char *name,
|
|
Packit |
534379 |
int *value);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Populate double value from JSON object.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @param[in] parent The JSON object in which to search for `name`.
|
|
Packit |
534379 |
* @param[in] name The search key.
|
|
Packit |
534379 |
* @param[out] value Receives the double value.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @returns FPGA_OK on success. FPGA_EXCEPTION if `name`
|
|
Packit |
534379 |
* is not found or if `name` is not a key of type double.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
fpga_result opae_bitstream_get_json_double(json_object *parent,
|
|
Packit |
534379 |
const char *name,
|
|
Packit |
534379 |
double *value);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#define OPAE_BITSTREAM_PATH_NO_PARENT 0x00000001
|
|
Packit |
534379 |
#define OPAE_BITSTREAM_PATH_NO_SYMLINK 0x00000002
|
|
Packit |
534379 |
/**
|
|
Packit |
534379 |
* Verify the given file path.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* Basic verification involves searching for invalid characters
|
|
Packit |
534379 |
* and character sequences. See `flags` for additional options.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @param[in] path The path in question.
|
|
Packit |
534379 |
* @param[in] flags Require additional checks (bit mask).
|
|
Packit |
534379 |
* If `flags` contains `OPAE_BITSTREAM_PATH_NO_PARENT`,
|
|
Packit |
534379 |
* then `path` is rejected if it contains `..`. If `flags`
|
|
Packit |
534379 |
* contains `OPAE_BITSTREAM_PATH_NO_SYMLINK`, then `path`
|
|
Packit |
534379 |
* is rejected if a component of the path is a symbolic
|
|
Packit |
534379 |
* link.
|
|
Packit |
534379 |
*
|
|
Packit |
534379 |
* @returns true if `path` is accepted, or false if `path`
|
|
Packit |
534379 |
* is rejected, based on the requested checks.
|
|
Packit |
534379 |
*/
|
|
Packit |
534379 |
bool opae_bitstream_path_is_valid(const char *path,
|
|
Packit |
534379 |
uint32_t flags);
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#ifdef __cplusplus
|
|
Packit |
534379 |
}
|
|
Packit |
534379 |
#endif /* __cplusplus */
|
|
Packit |
534379 |
|
|
Packit |
534379 |
#endif /* __OPAE_BITS_UTILS_H__ */
|