lnk commit front code
This commit is contained in:
293
include/obs_sdk/cJSON.h
Normal file
293
include/obs_sdk/cJSON.h
Normal file
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef cJSON__h
|
||||
#define cJSON__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
|
||||
|
||||
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
|
||||
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
|
||||
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
|
||||
|
||||
For *nix builds that support visibility attribute, you can define similar behavior by
|
||||
|
||||
setting default visibility to hidden by adding
|
||||
-fvisibility=hidden (for gcc)
|
||||
or
|
||||
-xldscope=hidden (for sun cc)
|
||||
to CFLAGS
|
||||
|
||||
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
|
||||
|
||||
*/
|
||||
|
||||
#define CJSON_CDECL __cdecl
|
||||
#define CJSON_STDCALL __stdcall
|
||||
|
||||
/* export symbols by default, this is necessary for copy pasting the C and header file */
|
||||
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_EXPORT_SYMBOLS
|
||||
#endif
|
||||
|
||||
#if defined(CJSON_HIDE_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) type CJSON_STDCALL
|
||||
#elif defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
|
||||
#elif defined(CJSON_IMPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
|
||||
#endif
|
||||
#else /* !__WINDOWS__ */
|
||||
#define CJSON_CDECL
|
||||
#define CJSON_STDCALL
|
||||
|
||||
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
|
||||
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
||||
#else
|
||||
#define CJSON_PUBLIC(type) type
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* project version */
|
||||
#define CJSON_VERSION_MAJOR 1
|
||||
#define CJSON_VERSION_MINOR 7
|
||||
#define CJSON_VERSION_PATCH 15
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* cJSON Types: */
|
||||
#define cJSON_Invalid (0)
|
||||
#define cJSON_False (1 << 0)
|
||||
#define cJSON_True (1 << 1)
|
||||
#define cJSON_NULL (1 << 2)
|
||||
#define cJSON_Number (1 << 3)
|
||||
#define cJSON_String (1 << 4)
|
||||
#define cJSON_Array (1 << 5)
|
||||
#define cJSON_Object (1 << 6)
|
||||
#define cJSON_Raw (1 << 7) /* raw json */
|
||||
|
||||
#define cJSON_IsReference 256
|
||||
#define cJSON_StringIsConst 512
|
||||
|
||||
/* The cJSON structure: */
|
||||
typedef struct cJSON
|
||||
{
|
||||
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON *next;
|
||||
struct cJSON *prev;
|
||||
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||
struct cJSON *child;
|
||||
|
||||
/* The type of the item, as above. */
|
||||
int type;
|
||||
|
||||
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
|
||||
char *valuestring;
|
||||
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
|
||||
int valueint;
|
||||
/* The item's number, if type==cJSON_Number */
|
||||
double valuedouble;
|
||||
|
||||
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||
char *string;
|
||||
} cJSON;
|
||||
|
||||
typedef struct cJSON_Hooks
|
||||
{
|
||||
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
||||
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
||||
void (CJSON_CDECL *free_fn)(void *ptr);
|
||||
} cJSON_Hooks;
|
||||
|
||||
typedef int cJSON_bool;
|
||||
|
||||
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
|
||||
* This is to prevent stack overflows. */
|
||||
#ifndef CJSON_NESTING_LIMIT
|
||||
#define CJSON_NESTING_LIMIT 1000
|
||||
#endif
|
||||
|
||||
/* returns the version of cJSON as a string */
|
||||
CJSON_PUBLIC(const char*) cJSON_Version(void);
|
||||
|
||||
/* Supply malloc, realloc and free functions to cJSON */
|
||||
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||
|
||||
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
|
||||
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
||||
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||
|
||||
/* Render a cJSON entity to text for transfer/storage. */
|
||||
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
|
||||
/* Render a cJSON entity to text for transfer/storage without any formatting. */
|
||||
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
||||
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
||||
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
||||
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
||||
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
|
||||
/* Delete a cJSON entity and all subentities. */
|
||||
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
|
||||
|
||||
/* Returns the number of items in an array (or object). */
|
||||
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
|
||||
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
|
||||
/* Get item "string" from object. Case insensitive. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
|
||||
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
||||
|
||||
/* Check item type and return its value */
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
|
||||
|
||||
/* These functions check the type of an item */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
|
||||
|
||||
/* These calls create a cJSON item of the appropriate type. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
|
||||
/* raw json */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
|
||||
|
||||
/* Create a string where valuestring references a string so
|
||||
* it will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
|
||||
/* Create an object/array that only references it's elements so
|
||||
* they will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
|
||||
|
||||
/* These utilities create an Array of count items.
|
||||
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
|
||||
|
||||
/* Append item to the specified array/object. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
|
||||
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
|
||||
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
|
||||
* writing to `item->string` */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
|
||||
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
|
||||
|
||||
/* Remove/Detach items from Arrays/Objects. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
|
||||
/* Update array items. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
|
||||
|
||||
/* Duplicate a cJSON item */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
|
||||
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
|
||||
* The item->next and ->prev pointers are always zero on return from Duplicate. */
|
||||
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
|
||||
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
|
||||
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
|
||||
* The input pointer json cannot point to a read-only address area, such as a string constant,
|
||||
* but should point to a readable and writable address area. */
|
||||
CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
||||
|
||||
/* Helper functions for creating and adding items to an object at the same time.
|
||||
* They return the added item or NULL on failure. */
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
|
||||
|
||||
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
|
||||
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
||||
/* helper for the cJSON_SetNumberValue macro */
|
||||
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
||||
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
||||
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
|
||||
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
|
||||
|
||||
/* Macro for iterating over an array or object */
|
||||
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
||||
|
||||
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
|
||||
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
|
||||
CJSON_PUBLIC(void) cJSON_free(void *object);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
336
include/obs_sdk/demo_common.h
Normal file
336
include/obs_sdk/demo_common.h
Normal file
@@ -0,0 +1,336 @@
|
||||
/*********************************************************************************
|
||||
* Copyright 2019 Huawei Technologies Co.,Ltd.
|
||||
* 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.
|
||||
**********************************************************************************
|
||||
*/
|
||||
#ifndef DEMO_COMMON_H
|
||||
#define DEMO_COMMON_H
|
||||
|
||||
|
||||
extern obs_status statusG;
|
||||
extern int showResponsePropertiesG;
|
||||
extern char errorDetailsG[4096];
|
||||
extern char locationconstraint[2048];
|
||||
extern char ACCESS_KEY_ID_OBS[2048];
|
||||
extern char SECRET_ACCESS_KEY[2048];
|
||||
extern char HOST_NAME[2048];
|
||||
extern char BUCKET_NAME_OBS[2048];
|
||||
extern char UPLOAD_ID[2048];
|
||||
extern obs_protocol protocolG;
|
||||
extern obs_canned_acl canned_acl;
|
||||
extern int forceG;
|
||||
extern char *ca_file;
|
||||
extern char ca_info[2048];
|
||||
extern int demoUseObsApi;
|
||||
extern char UPLOAD_ETAG[][256];
|
||||
extern char OBJECT_VER[][256];
|
||||
extern obs_uri_style gDefaultURIStyle;
|
||||
|
||||
// struct------------------------------------------
|
||||
typedef struct head_object_data
|
||||
{
|
||||
obs_status ret_status;
|
||||
int object_length;
|
||||
}head_object_data;
|
||||
|
||||
|
||||
typedef struct tagkv
|
||||
{
|
||||
char key[250];
|
||||
char value[250];
|
||||
}tagkv;
|
||||
|
||||
typedef struct TaggingInfo
|
||||
{
|
||||
int tagCount;
|
||||
tagkv taglist[10];
|
||||
obs_status ret_status;
|
||||
}TaggingInfo;
|
||||
|
||||
typedef struct list_object_callback_data
|
||||
{
|
||||
int is_truncated;
|
||||
char next_marker[1024];
|
||||
int keyCount;
|
||||
int allDetails;
|
||||
obs_status ret_status;
|
||||
} list_object_callback_data;
|
||||
|
||||
typedef struct list_bucket_callback_data
|
||||
{
|
||||
int is_truncated;
|
||||
char next_marker[1024];
|
||||
int keyCount;
|
||||
int allDetails;
|
||||
obs_status ret_status;
|
||||
} list_bucket_callback_data;
|
||||
|
||||
typedef struct list_versions_callback_data
|
||||
{
|
||||
char bucket_name[1024];
|
||||
char prefix[1024];
|
||||
char key_marker[1024];
|
||||
char delimiter[1024];
|
||||
int max_keys;
|
||||
int is_truncated;
|
||||
char next_key_marker[1024];
|
||||
char next_versionId_marker[1024];
|
||||
int keyCount;
|
||||
int allDetails;
|
||||
obs_status ret_status;
|
||||
} list_versions_callback_data;
|
||||
|
||||
typedef struct growbuffer
|
||||
{
|
||||
int size;
|
||||
int start;
|
||||
char data[64 * 1024];
|
||||
struct growbuffer *prev, *next;
|
||||
} growbuffer;
|
||||
|
||||
typedef struct put_file_object_callback_data
|
||||
{
|
||||
FILE *infile;
|
||||
uint64_t content_length;
|
||||
obs_status ret_status;
|
||||
} put_file_object_callback_data;
|
||||
|
||||
typedef struct put_buffer_object_callback_data
|
||||
{
|
||||
char *put_buffer;
|
||||
uint64_t buffer_size;
|
||||
uint64_t cur_offset;
|
||||
obs_status ret_status;
|
||||
} put_buffer_object_callback_data;
|
||||
|
||||
|
||||
typedef struct put_object_callback_data
|
||||
{
|
||||
FILE *infile;
|
||||
growbuffer *gb;
|
||||
uint64_t content_length, originalContentLength;
|
||||
int noStatus;
|
||||
obs_status put_status;
|
||||
} put_object_callback_data;
|
||||
|
||||
|
||||
typedef struct get_object_callback_data
|
||||
{
|
||||
FILE *outfile;
|
||||
obs_status ret_status;
|
||||
}get_object_callback_data;
|
||||
|
||||
typedef struct list_service_data
|
||||
{
|
||||
int headerPrinted;
|
||||
int allDetails;
|
||||
obs_status ret_status;
|
||||
} list_service_data;
|
||||
|
||||
typedef struct test_upload_file_callback_data
|
||||
{
|
||||
FILE *infile;
|
||||
int part_num;
|
||||
uint64_t part_size;
|
||||
uint64_t start_byte;
|
||||
int noStatus;
|
||||
obs_status ret_status;
|
||||
} test_upload_file_callback_data;
|
||||
|
||||
|
||||
typedef struct list_parts_callback_data
|
||||
{
|
||||
int isTruncated;
|
||||
char initiatorId[1024];
|
||||
char initiatorDisplayName[1024];
|
||||
char ownerId[1024];
|
||||
char ownerDisplayName[1024];
|
||||
unsigned int nextPartNumberMarker;
|
||||
char storageClass[64];
|
||||
int keyCount;
|
||||
int allDetails;
|
||||
obs_status ret_status;
|
||||
}list_parts_callback_data;
|
||||
|
||||
typedef struct _test_concurrent_upload_file_callback_data
|
||||
{
|
||||
FILE *infile;
|
||||
char etag[1024];
|
||||
char *upload_id;
|
||||
unsigned int part_num;
|
||||
uint64_t part_size;
|
||||
uint64_t start_byte;
|
||||
uint64_t offset;
|
||||
obs_options *option;
|
||||
char * key;
|
||||
obs_status ret_status;
|
||||
}test_concurrent_upload_file_callback_data;
|
||||
|
||||
typedef struct __tempAuthResult
|
||||
{
|
||||
char tmpAuthUrl[1024];
|
||||
char actualHeaders[1024];
|
||||
}tempAuthResult;
|
||||
|
||||
typedef struct list_multipart_uploads_callback_data
|
||||
{
|
||||
obs_status ret_status;
|
||||
}list_multipart_uploads_callback_data;
|
||||
|
||||
// common handle-------------------------------------
|
||||
void printError();
|
||||
FILE * write_to_file(char *localfile);
|
||||
void common_error_handle(const obs_error_details *error);
|
||||
void create_and_write_file(char *filename, unsigned int file_size);
|
||||
void print_grant_info(int acl_grant_count,obs_acl_grant *acl_grants);
|
||||
void printListBucketHeader(int allDetails);
|
||||
void printListServiceHeader(int allDetails);
|
||||
void printListVersionsHeader(int allDetails);
|
||||
uint64_t open_file_and_get_length(char *localfile, put_file_object_callback_data *data);
|
||||
|
||||
|
||||
|
||||
// callback-----------------------------------
|
||||
obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data);
|
||||
void response_complete_callback(obs_status status, const obs_error_details *error,
|
||||
void *callback_data);
|
||||
obs_status head_properties_callback(const obs_response_properties *properties, void *callback_data);
|
||||
void head_complete_callback(obs_status status, const obs_error_details *error,
|
||||
void *callback_data);
|
||||
obs_status get_bucket_storageclass_handler(const char * storage_class, void * callBackData);
|
||||
obs_status get_bucket_tagging_callback(int tagging_count, obs_name_value *tagging_list, void *callback_data);
|
||||
void get_tagging_complete_callback(obs_status status, const obs_error_details *error,
|
||||
void *callback_data);
|
||||
obs_status get_bucket_websiteconf_callback(const char *hostname,
|
||||
const char *protocol,
|
||||
const char *suffix,
|
||||
const char *key,
|
||||
const bucket_website_routingrule *websiteconf,
|
||||
int webdatacount,
|
||||
void *callback_data);
|
||||
obs_status list_objects_callback(int is_truncated, const char *next_marker,
|
||||
int contents_count,
|
||||
const obs_list_objects_content *contents,
|
||||
int common_prefixes_count,
|
||||
const char **common_prefixes,
|
||||
void *callback_data);
|
||||
void list_object_complete_callback(obs_status status, const obs_error_details *error,
|
||||
void *callback_data);
|
||||
obs_status listVersionsCallback(int is_truncated, const char *next_key_marker, const char *next_versionId_marker,
|
||||
const obs_list_versions *list_versions, void *callback_data);
|
||||
void list_versions_complete_callback(obs_status status, const obs_error_details *error,
|
||||
void *callback_data);
|
||||
|
||||
obs_status getBucketLifecycleConfigurationCallbackEx (obs_lifecycle_conf* bucketLifeCycleConf,
|
||||
unsigned int blccNumber, void *callback_data);
|
||||
|
||||
obs_status get_cors_info_callback(obs_bucket_cors_conf* bucket_cors_conf,
|
||||
unsigned int bcc_number,
|
||||
void *callback_data);
|
||||
obs_status get_notification_info_callback(obs_smn_notification_configuration* notification_conf,
|
||||
void *callback_data);
|
||||
|
||||
void put_file_complete_callback(obs_status status,
|
||||
const obs_error_details *error,
|
||||
void *callback_data);
|
||||
void put_buffer_complete_callback(obs_status status, const obs_error_details *error,
|
||||
void *callback_data);
|
||||
int put_file_data_callback(int buffer_size, char *buffer, void *callback_data);
|
||||
int put_buffer_data_callback(int buffer_size, char *buffer, void *callback_data);
|
||||
obs_status get_properties_callback(const obs_response_properties *properties, void *callback_data);
|
||||
obs_status set_online_request_max_rate(uint64_t online_request_rate);
|
||||
void initialize_get_token_lock();
|
||||
void deinitialize_get_token_lock();
|
||||
void preduce_token();
|
||||
int get_token(int buffer_size);
|
||||
obs_status get_object_data_callback(int buffer_size, const char *buffer,
|
||||
void *callback_data);
|
||||
void get_object_complete_callback(obs_status status, const obs_error_details *error,
|
||||
void *callback_data);
|
||||
|
||||
obs_status delete_objects_data_callback(int contentsCount, obs_delete_objects *delobjs,
|
||||
void *callbackData);
|
||||
obs_status listServiceCallback(const char *owner_id,
|
||||
const char *owner_display_name,
|
||||
const char *bucket_name,
|
||||
int64_t creationDate, void *callback_data);
|
||||
obs_status listServiceObsCallback(const char *owner_id,
|
||||
const char *bucket_name,
|
||||
int64_t creationDate,
|
||||
const char *location,
|
||||
void *callback_data);
|
||||
void list_bucket_complete_callback(obs_status status,
|
||||
const obs_error_details *error,
|
||||
void *callback_data);
|
||||
|
||||
|
||||
void upload_part_from_file(test_upload_file_callback_data *data);
|
||||
|
||||
int test_upload_file_data_callback(int buffer_size, char *buffer, void *callback_data);
|
||||
int test_concurrent_upload_part_data_callback(int buffer_size, char *buffer, void *callback_data);
|
||||
|
||||
|
||||
uint64_t get_file_info(char *localfile, test_upload_file_callback_data *data);
|
||||
|
||||
obs_status CompleteMultipartUploadCallback(const char *location,
|
||||
const char *bucket,
|
||||
const char *key,
|
||||
const char* eTag,
|
||||
void *callbackData);
|
||||
void upload_part_complete_callback(obs_status status,
|
||||
const obs_error_details *error,
|
||||
void *callback_data);
|
||||
obs_status listPartsCallbackEx(obs_uploaded_parts_total_info* uploadedParts,
|
||||
obs_list_parts *parts,
|
||||
void *callbackData);
|
||||
void list_part_complete_callback(obs_status status,
|
||||
const obs_error_details *error,
|
||||
void *callback_data);
|
||||
void listMultiPartUploadsCompleteCallback(obs_status status,
|
||||
const obs_error_details *error,
|
||||
void *callback_data);
|
||||
obs_status listMultiPartUploadsCallback(int is_truncated, const char *next_marker,
|
||||
const char *next_uploadId_marker, int uploads_count,
|
||||
const obs_list_multipart_upload *uploads, int common_prefixes_count,
|
||||
const char **common_prefixes, void *callback_data);
|
||||
void uploadFileResultCallback(obs_status status,
|
||||
char *resultMsg,
|
||||
int partCountReturn,
|
||||
obs_upload_file_part_info * uploadInfoList,
|
||||
void *callbackData);
|
||||
void downloadFileResultCallback(obs_status status,
|
||||
char *resultMsg,
|
||||
int partCountReturn,
|
||||
obs_download_file_part_info * downloadInfoList,
|
||||
void *callbackData);
|
||||
obs_status concurrent_response_properties_callback(
|
||||
const obs_response_properties *properties, void *callback_data);
|
||||
|
||||
void concurrent_upload_file_complete_callback(obs_status status, const obs_error_details *error,
|
||||
void *callback_data);
|
||||
|
||||
obs_status DeleteObjectsDataCallback(int contentsCount,
|
||||
obs_delete_objects *delobjs,
|
||||
void *callbackData);
|
||||
|
||||
int get_certificate_info(char *buffer, int buffer_length);
|
||||
void tempAuthCallBack_getResult(char *tempAuthUrl, uint64_t tempAuthUrlLen, char *tempAuthActualHeaders,
|
||||
uint64_t tempAuthActualHeadersLen, void *callbackData);
|
||||
|
||||
void init_bucket_get_logging_message(bucket_logging_message *logging_message);
|
||||
void destroy_logging_message(bucket_logging_message *logging_message);
|
||||
|
||||
FILE** init_uploadfilepool(FILE **fd, uint64_t part_num, char *filename);
|
||||
void deinit_uploadfilepool(FILE **fd, uint64_t part_num);
|
||||
|
||||
#endif /* UTIL_H */
|
||||
|
||||
1519
include/obs_sdk/eSDKOBS.h
Normal file
1519
include/obs_sdk/eSDKOBS.h
Normal file
File diff suppressed because it is too large
Load Diff
232
include/obs_sdk/securec.h
Normal file
232
include/obs_sdk/securec.h
Normal file
@@ -0,0 +1,232 @@
|
||||
/*********************************************************************************
|
||||
* Copyright 2019 Huawei Technologies Co.,Ltd.
|
||||
* 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.
|
||||
**********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27
|
||||
#define __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27
|
||||
|
||||
/* If you need high performance, enable the WITH_PERFORMANCE_ADDONS macro! */
|
||||
#define WITH_PERFORMANCE_ADDONS
|
||||
|
||||
#include "securectype.h" /*lint !e537*/
|
||||
#include <stdarg.h>
|
||||
|
||||
/* If stack size on some embedded platform is limited, you can define the following macro
|
||||
* which will put some variables on heap instead of stack.
|
||||
#define STACK_SIZE_LESS_THAN_1K
|
||||
*/
|
||||
|
||||
/* for performance consideration, the following macro will call the corresponding API
|
||||
* of libC for memcpy, memmove and memset
|
||||
*/
|
||||
#define CALL_LIBC_COR_API
|
||||
|
||||
/* codes should run under the macro COMPATIBLE_LINUX_FORMAT in unknow system on default,
|
||||
and strtold. The function
|
||||
strtold is referenced first at ISO9899:1999(C99), and some old compilers can
|
||||
not support these functions. Here provides a macro to open these functions:
|
||||
|
||||
SECUREC_SUPPORT_STRTOLD -- if defined, strtold will be used
|
||||
*/
|
||||
|
||||
/*define error code*/
|
||||
#ifndef errno_t
|
||||
typedef int errno_t;
|
||||
#endif
|
||||
|
||||
/* success */
|
||||
#ifndef EOK
|
||||
#define EOK (0)
|
||||
#endif
|
||||
|
||||
/* invalid parameter */
|
||||
#ifdef EINVAL
|
||||
#undef EINVAL
|
||||
#endif
|
||||
#define EINVAL (22)
|
||||
#define EINVAL_AND_RESET (22 | 0X80)
|
||||
/* invalid parameter range */
|
||||
#ifdef ERANGE
|
||||
#undef ERANGE /* to avoid redefinition */
|
||||
#endif
|
||||
#define ERANGE (34)
|
||||
#define ERANGE_AND_RESET (34 | 0X80)
|
||||
|
||||
/* A wide-character code has been detected that does not correspond to a
|
||||
* valid character, or a byte sequence does not form a valid wide-character code
|
||||
*/
|
||||
#ifdef EILSEQ
|
||||
#undef EILSEQ
|
||||
#endif
|
||||
#define EILSEQ (42)
|
||||
|
||||
#ifdef EOVERLAP_AND_RESET
|
||||
#undef EOVERLAP_AND_RESET
|
||||
#endif
|
||||
/*Once the buffer overlap is detected, the dest buffer must be reseted! */
|
||||
#define EOVERLAP_AND_RESET (54 | 0X80)
|
||||
|
||||
/*if you need export the function of this library in Win32 dll, use __declspec(dllexport) */
|
||||
#ifdef WIN32
|
||||
#ifndef USE_STATIC_HUAWEI_SECURE_C
|
||||
#ifdef HUAWEISECUREC_WXPORTS
|
||||
#define HUAWEISECUREC_API __declspec(dllexport)
|
||||
#else
|
||||
#define HUAWEISECUREC_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define HUAWEISECUREC_API
|
||||
#endif // !USE_STATIC_HUAWEI_SECURE_C
|
||||
|
||||
#else
|
||||
#define HUAWEISECUREC_API
|
||||
#endif//WIN32
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* memset function*/
|
||||
errno_t HUAWEISECUREC_API memset_s(void* dest, size_t destMax, int c, size_t count);
|
||||
|
||||
#if defined __GNUC__ || defined LINUX
|
||||
/* memcpy function*/
|
||||
errno_t memcpy_s(void* dest, size_t destMax, const void* src, size_t count);
|
||||
|
||||
/* return SecureC Version */
|
||||
void getHwSecureCVersion(char* verStr, int bufSize, unsigned short* verNumber);
|
||||
|
||||
/* wmemcpy */
|
||||
errno_t wmemcpy_s(wchar_t* dest, size_t destMax, const wchar_t* src, size_t count);
|
||||
|
||||
/* memmove */
|
||||
errno_t memmove_s(void* dest, size_t destMax, const void* src, size_t count);
|
||||
|
||||
errno_t wmemmove_s(wchar_t* dest, size_t destMax, const wchar_t* src, size_t count);
|
||||
|
||||
errno_t wcscpy_s(wchar_t* strDest, size_t destMax, const wchar_t* strSrc);
|
||||
|
||||
errno_t wcsncpy_s(wchar_t* strDest, size_t destMax, const wchar_t* strSrc, size_t count);
|
||||
|
||||
errno_t wcscat_s(wchar_t* strDest, size_t destMax, const wchar_t* strSrc);
|
||||
|
||||
errno_t wcsncat_s(wchar_t* strDest, size_t destMax, const wchar_t* strSrc, size_t count);
|
||||
|
||||
/* strtok */
|
||||
char* strtok_s(char* strToken, const char* strDelimit, char** context);
|
||||
|
||||
wchar_t* wcstok_s(wchar_t* strToken, const wchar_t* strDelimit, wchar_t** context);
|
||||
|
||||
/* sprintf */
|
||||
int sprintf_s(char* strDest, size_t destMax, const char* format, ...) SECUREC_ATTRIBUTE(3,4);
|
||||
|
||||
int swprintf_s(wchar_t* strDest, size_t destMax, const wchar_t* format, ...);
|
||||
|
||||
/* vsprintf */
|
||||
int vsprintf_s(char* strDest, size_t destMax, const char* format, va_list argptr) SECUREC_ATTRIBUTE(3,0);
|
||||
|
||||
int vswprintf_s(wchar_t* strDest, size_t destMax, const wchar_t* format, va_list argptr);
|
||||
|
||||
int vsnprintf_s(char* strDest, size_t destMax, size_t count, const char* format, va_list arglist) SECUREC_ATTRIBUTE(4,0);
|
||||
|
||||
/* snprintf */
|
||||
int snprintf_s(char* strDest, size_t destMax, size_t count, const char* format, ...) SECUREC_ATTRIBUTE(4,5);
|
||||
|
||||
/* scanf */
|
||||
int scanf_s(const char* format, ...);
|
||||
|
||||
int wscanf_s(const wchar_t* format, ...);
|
||||
|
||||
/* vscanf */
|
||||
int vscanf_s(const char* format, va_list arglist);
|
||||
|
||||
int vwscanf_s(const wchar_t* format, va_list arglist);
|
||||
|
||||
/* fscanf */
|
||||
int fscanf_s(FILE* stream, const char* format, ...);
|
||||
|
||||
int fwscanf_s(FILE* stream, const wchar_t* format, ...);
|
||||
|
||||
/* vfscanf */
|
||||
int vfscanf_s(FILE* stream, const char* format, va_list arglist);
|
||||
|
||||
int vfwscanf_s(FILE* stream, const wchar_t* format, va_list arglist);
|
||||
|
||||
/* sscanf */
|
||||
int sscanf_s(const char* buffer, const char* format, ...);
|
||||
|
||||
int swscanf_s(const wchar_t* buffer, const wchar_t* format, ...);
|
||||
|
||||
/* vsscanf */
|
||||
int vsscanf_s(const char* buffer, const char* format, va_list argptr);
|
||||
|
||||
int vswscanf_s(const wchar_t* buffer, const wchar_t* format, va_list arglist);
|
||||
|
||||
/* gets */
|
||||
char* gets_s(char* buffer, size_t destMax);
|
||||
|
||||
/* strcpy */
|
||||
errno_t strcpy_s(char* strDest, size_t destMax, const char* strSrc);
|
||||
/* strncpy */
|
||||
errno_t strncpy_s(char* strDest, size_t destMax, const char* strSrc, size_t count);
|
||||
|
||||
/* strcat */
|
||||
errno_t strcat_s(char* strDest, size_t destMax, const char* strSrc);
|
||||
/* strncat */
|
||||
errno_t strncat_s(char* strDest, size_t destMax, const char* strSrc, size_t count);
|
||||
|
||||
errno_t strncpy_error(char* strDest, size_t destMax, const char* strSrc, size_t count);
|
||||
errno_t strcpy_error(char* strDest, size_t destMax, const char* strSrc);
|
||||
|
||||
#if defined(WITH_PERFORMANCE_ADDONS)
|
||||
/* those functions are used by macro */
|
||||
errno_t memset_sOptTc(void* dest, size_t destMax, int c, size_t count);
|
||||
errno_t memcpy_sOptTc(void* dest, size_t destMax, const void* src, size_t count);
|
||||
|
||||
/* strcpy_sp is a macro, NOT a function in performance optimization mode. */
|
||||
#define strcpy_sp(dest, destMax, src) /*lint -save -e506 -e1055 */ (( __builtin_constant_p((destMax)) && __builtin_constant_p((src))) ? \
|
||||
STRCPY_SM((dest), (destMax), (src)) : strcpy_s((dest), (destMax), (src)) ) /*lint -restore */
|
||||
|
||||
/* strncpy_sp is a macro, NOT a function in performance optimization mode. */
|
||||
#define strncpy_sp(dest, destMax, src, count) /*lint -save -e506 -e1055 */ ((__builtin_constant_p((count)) && __builtin_constant_p((destMax)) && __builtin_constant_p((src))) ? \
|
||||
STRNCPY_SM((dest), (destMax), (src), (count)) : strncpy_s((dest), (destMax), (src), (count)) ) /*lint -restore */
|
||||
|
||||
/* strcat_sp is a macro, NOT a function in performance optimization mode. */
|
||||
#define strcat_sp(dest, destMax, src) /*lint -save -e506 -e1055 */ (( __builtin_constant_p((destMax)) && __builtin_constant_p((src))) ? \
|
||||
STRCAT_SM((dest), (destMax), (src)) : strcat_s((dest), (destMax), (src)) ) /*lint -restore */
|
||||
|
||||
/* strncat_sp is a macro, NOT a function in performance optimization mode. */
|
||||
#define strncat_sp(dest, destMax, src, count) /*lint -save -e506 -e1055 */ ((__builtin_constant_p((count)) && __builtin_constant_p((destMax)) && __builtin_constant_p((src))) ? \
|
||||
STRNCAT_SM((dest), (destMax), (src), (count)) : strncat_s((dest), (destMax), (src), (count)) ) /*lint -restore */
|
||||
|
||||
/* memcpy_sp is a macro, NOT a function in performance optimization mode. */
|
||||
#define memcpy_sp(dest, destMax, src, count) /*lint -save -e506 -e1055 */ (__builtin_constant_p((count)) ? (MEMCPY_SM((dest), (destMax), (src), (count))) : \
|
||||
(__builtin_constant_p((destMax)) ? (((size_t)(destMax) > 0 && (((UINT64T)(destMax) & (UINT64T)(-2)) < SECUREC_MEM_MAX_LEN)) ? memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE ) : memcpy_s((dest), (destMax), (src), (count)))) /*lint -restore */
|
||||
|
||||
/* memset_sp is a macro, NOT a function in performance optimization mode. */
|
||||
#define memset_sp(dest, destMax, c, count) /*lint -save -e506 -e1055 */ (__builtin_constant_p((count)) ? (MEMSET_SM((dest), (destMax), (c), (count))) : \
|
||||
(__builtin_constant_p((destMax)) ? (((size_t)(destMax) > 0 && (((UINT64T)(destMax) & (UINT64T)(-2)) < SECUREC_MEM_MAX_LEN)) ? memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE ) : memset_s((dest), (destMax), (c), (count)))) /*lint -restore */
|
||||
|
||||
#endif
|
||||
#else
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif/* __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 */
|
||||
|
||||
|
||||
289
include/obs_sdk/securectype.h
Normal file
289
include/obs_sdk/securectype.h
Normal file
@@ -0,0 +1,289 @@
|
||||
/*********************************************************************************
|
||||
* Copyright 2019 Huawei Technologies Co.,Ltd.
|
||||
* 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.
|
||||
**********************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7
|
||||
#define __SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7
|
||||
|
||||
/*Shielding VC symbol redefinition warning*/
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
#ifdef __STDC_WANT_SECURE_LIB__
|
||||
#undef __STDC_WANT_SECURE_LIB__
|
||||
#endif
|
||||
#define __STDC_WANT_SECURE_LIB__ 0
|
||||
#ifdef _CRTIMP_ALTERNATIVE
|
||||
#undef _CRTIMP_ALTERNATIVE
|
||||
#endif
|
||||
#define _CRTIMP_ALTERNATIVE //comment microsoft *_s function
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
/* #include <limits.h> this file is used to define some macros, such as INT_MAX and SIZE_MAX */
|
||||
|
||||
/*if enable COMPATIBLE_WIN_FORMAT, the output format will be compatible to Windows.*/
|
||||
#if (defined(_WIN32) || defined(_WIN64) || defined(_MSC_VER))
|
||||
#define COMPATIBLE_WIN_FORMAT
|
||||
#endif
|
||||
#if defined(COMPATIBLE_WIN_FORMAT)
|
||||
/* in windows platform, can't use optimized function for there is no __builtin_constant_p like function */
|
||||
/* If need optimized macro, can define this: #define __builtin_constant_p(x) 1 */
|
||||
#ifdef WITH_PERFORMANCE_ADDONS
|
||||
#undef WITH_PERFORMANCE_ADDONS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (defined(__VXWORKS__) || defined(__vxworks) || defined(__VXWORKS) || defined(_VXWORKS_PLATFORM_) || defined(SECUREC_VXWORKS_VERSION_5_4))
|
||||
#if !defined(SECUREC_VXWORKS_PLATFORM)
|
||||
#define SECUREC_VXWORKS_PLATFORM
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SECUREC_VXWORKS_PLATFORM
|
||||
#include <version.h>
|
||||
#endif
|
||||
|
||||
/*if enable COMPATIBLE_LINUX_FORMAT, the output format will be compatible to Linux.*/
|
||||
#if !(defined(COMPATIBLE_WIN_FORMAT) || defined(SECUREC_VXWORKS_PLATFORM))
|
||||
#define COMPATIBLE_LINUX_FORMAT
|
||||
#endif
|
||||
#ifdef COMPATIBLE_LINUX_FORMAT
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && !defined(WIN32)
|
||||
#define SECUREC_ATTRIBUTE(x,y) __attribute__((format(printf, (x), (y) )))
|
||||
#else
|
||||
#define SECUREC_ATTRIBUTE(x,y)
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && ((__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3 /*above 3.4*/ )) )
|
||||
long __builtin_expect(long exp, long c);
|
||||
#define LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
#else
|
||||
#define LIKELY(x) (x)
|
||||
#define UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
#ifndef TWO_MIN
|
||||
#define TWO_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#define WCHAR_SIZE sizeof(wchar_t)
|
||||
|
||||
/*ref //sourceforge.net/p/predef/wiki/OperatingSystems/
|
||||
#if !(defined(__hpux) || defined(_AIX) || defined(__VXWORKS__) || defined(__vxworks) ||defined(__ANDROID__) || defined(__WRLINUX__)|| defined(_TYPE_uint8_t))
|
||||
typedef unsigned char unit8_t;
|
||||
#endif
|
||||
*/
|
||||
typedef signed char INT8T;
|
||||
typedef unsigned char UINT8T;
|
||||
|
||||
#if defined(COMPATIBLE_WIN_FORMAT) || defined(__ARMCC_VERSION)
|
||||
typedef __int64 INT64T;
|
||||
typedef unsigned __int64 UINT64T;
|
||||
#if defined(__ARMCC_VERSION)
|
||||
typedef int INT32T;
|
||||
typedef unsigned int UINT32T;
|
||||
#else
|
||||
typedef __int32 INT32T;
|
||||
typedef unsigned __int32 UINT32T;
|
||||
#endif
|
||||
#else
|
||||
typedef int INT32T;
|
||||
typedef unsigned int UINT32T;
|
||||
typedef long long INT64T;
|
||||
typedef unsigned long long UINT64T;
|
||||
#endif
|
||||
|
||||
/* define the max length of the string */
|
||||
#define SECUREC_STRING_MAX_LEN (0x7fffffffUL)
|
||||
#define SECUREC_WCHAR_STRING_MAX_LEN (SECUREC_STRING_MAX_LEN / WCHAR_SIZE)
|
||||
|
||||
/* add SECUREC_MEM_MAX_LEN for memcpy and memmove*/
|
||||
#define SECUREC_MEM_MAX_LEN (0x7fffffffUL)
|
||||
#define SECUREC_WCHAR_MEM_MAX_LEN (SECUREC_MEM_MAX_LEN / WCHAR_SIZE)
|
||||
|
||||
#if SECUREC_STRING_MAX_LEN > 0x7fffffff
|
||||
#error "max string is 2G, or you may remove this macro"
|
||||
#endif
|
||||
|
||||
#if (defined(__GNUC__ ) && defined(__SIZEOF_POINTER__ ))
|
||||
#if (__SIZEOF_POINTER__ != 4) && (__SIZEOF_POINTER__ != 8)
|
||||
#error "unsupported system, contact Security Design Technology Department of 2012 Labs"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define IN_REGISTER register
|
||||
|
||||
#define SECC_MALLOC(x) malloc((size_t)(x))
|
||||
#define SECC_FREE(x) free((void *)(x))
|
||||
|
||||
#if defined(_WIN64) || defined(WIN64) || defined(__LP64__) || defined(_LP64)
|
||||
#define SECUREC_ON_64BITS
|
||||
#endif
|
||||
|
||||
#if (!defined(SECUREC_ON_64BITS) && defined(__GNUC__ ) && defined(__SIZEOF_POINTER__ ))
|
||||
#if __SIZEOF_POINTER__ == 8
|
||||
#define SECUREC_ON_64BITS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__SVR4) || defined(__svr4__)
|
||||
#define __SOLARIS
|
||||
#endif
|
||||
|
||||
#if (defined(__hpux) || defined(_AIX) || defined(__SOLARIS))
|
||||
#define __UNIX
|
||||
#endif
|
||||
|
||||
#if ((!defined(SECUREC_SUPPORT_STRTOLD)) && defined(COMPATIBLE_LINUX_FORMAT))
|
||||
#if defined(__USE_ISOC99) \
|
||||
|| (defined(_AIX) && defined(_ISOC99_SOURCE)) \
|
||||
|| (defined(__hpux) && defined(__ia64)) \
|
||||
|| (defined(__SOLARIS) && (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || defined(_STDC_C99) || defined(__EXTENSIONS__))
|
||||
#define SECUREC_SUPPORT_STRTOLD
|
||||
#endif
|
||||
#endif
|
||||
#if ((defined(SECUREC_WRLINUX_BELOW4) || defined(_WRLINUX_BELOW4_)) && defined(SECUREC_SUPPORT_STRTOLD))
|
||||
#undef SECUREC_SUPPORT_STRTOLD
|
||||
#endif
|
||||
|
||||
#if defined(WITH_PERFORMANCE_ADDONS)
|
||||
/* for strncpy_s performance optimization */
|
||||
#define STRNCPY_SM(dest, destMax, src, count) \
|
||||
((NULL != (void*)dest && NULL != (void*)src && (size_t)destMax >0 && (((UINT64T)(destMax) & (UINT64T)(-2)) < SECUREC_STRING_MAX_LEN) && (TWO_MIN(count , strlen(src)) + 1) <= (size_t)destMax ) ? ( (count < strlen(src))? (memcpy(dest, src, count), *((char*)dest + count) = '\0', EOK) :( memcpy(dest, src, strlen(src) + 1), EOK ) ) :(strncpy_error(dest, destMax, src, count)) )
|
||||
|
||||
#define STRCPY_SM(dest, destMax, src) \
|
||||
(( NULL != (void*)dest && NULL != (void*)src && (size_t)destMax >0 && (((UINT64T)(destMax) & (UINT64T)(-2)) < SECUREC_STRING_MAX_LEN) && ( strlen(src) + 1) <= (size_t)destMax )? (memcpy(dest, src, strlen(src) + 1), EOK) :( strcpy_error(dest, destMax, src)))
|
||||
|
||||
/* for strcat_s performance optimization */
|
||||
#if defined(__GNUC__)
|
||||
#define STRCAT_SM(dest, destMax, src) \
|
||||
({ int catRet =EOK;\
|
||||
if ( NULL != (void*)dest && NULL != (void*)src && (size_t)(destMax) >0 && (((UINT64T)(destMax) & (UINT64T)(-2)) < SECUREC_STRING_MAX_LEN) ) {\
|
||||
char* pCatTmpDst = (dest);\
|
||||
size_t catRestSz = (destMax);\
|
||||
do{\
|
||||
while(catRestSz > 0 && *pCatTmpDst) {\
|
||||
++pCatTmpDst;\
|
||||
--catRestSz;\
|
||||
}\
|
||||
if (catRestSz == 0) {\
|
||||
catRet = EINVAL;\
|
||||
break;\
|
||||
}\
|
||||
if ( ( strlen(src) + 1) <= catRestSz ) {\
|
||||
memcpy(pCatTmpDst, (src), strlen(src) + 1);\
|
||||
catRet = EOK;\
|
||||
}else{\
|
||||
catRet = ERANGE;\
|
||||
}\
|
||||
}while(0);\
|
||||
if ( EOK != catRet) catRet = strcat_s((dest), (destMax), (src));\
|
||||
}else{\
|
||||
catRet = strcat_s((dest), (destMax), (src));\
|
||||
}\
|
||||
catRet;})
|
||||
#else
|
||||
#define STRCAT_SM(dest, destMax, src) strcat_s(dest, destMax, src)
|
||||
#endif
|
||||
|
||||
/*for strncat_s performance optimization*/
|
||||
#if defined(__GNUC__)
|
||||
#define STRNCAT_SM(dest, destMax, src, count) \
|
||||
({ int ncatRet = EOK;\
|
||||
if (NULL != (void*)dest && NULL != (void*)src && (size_t)destMax > 0 && (((UINT64T)(destMax) & (UINT64T)(-2)) < SECUREC_STRING_MAX_LEN) && (((UINT64T)(count) & (UINT64T)(-2)) < SECUREC_STRING_MAX_LEN)) {\
|
||||
char* pCatTmpDest = (dest);\
|
||||
size_t ncatRestSz = (destMax);\
|
||||
do{\
|
||||
while(ncatRestSz > 0 && *pCatTmpDest) {\
|
||||
++pCatTmpDest;\
|
||||
--ncatRestSz;\
|
||||
}\
|
||||
if (ncatRestSz == 0) {\
|
||||
ncatRet = EINVAL;\
|
||||
break;\
|
||||
}\
|
||||
if ( (TWO_MIN((count) , strlen(src)) + 1) <= ncatRestSz ) {\
|
||||
if ((count) < strlen(src)) {\
|
||||
memcpy(pCatTmpDest, (src), (count));\
|
||||
*(pCatTmpDest + (count)) = '\0';\
|
||||
}else {\
|
||||
memcpy(pCatTmpDest, (src), strlen(src) + 1);\
|
||||
}\
|
||||
}else{\
|
||||
ncatRet = ERANGE;\
|
||||
}\
|
||||
}while(0);\
|
||||
if ( EOK != ncatRet) ncatRet = strncat_s((dest), (destMax), (src), (count));\
|
||||
}else{\
|
||||
ncatRet = strncat_s((dest), (destMax), (src), (count));\
|
||||
}\
|
||||
ncatRet;})
|
||||
#else
|
||||
#define STRNCAT_SM(dest, destMax, src, count) strncat_s(dest, destMax, src, count)
|
||||
#endif
|
||||
|
||||
/*
|
||||
MEMCPY_SM do NOT check buffer overlap by default, or you can add this check to improve security
|
||||
condCheck = condCheck || (dest == src) || (dest > src && dest < (void*)((UINT8T*)src + count));\
|
||||
condCheck = condCheck || (src > dest && src < (void*)((UINT8T*)dest + count)); \
|
||||
*/
|
||||
|
||||
#define MEMCPY_SM(dest, destMax, src, count)\
|
||||
(!(((size_t)destMax== 0 )||(((UINT64T)(destMax) & (UINT64T)(-2)) > SECUREC_MEM_MAX_LEN)||((size_t)count > (size_t)destMax) || (NULL == (void*)dest) || (NULL == (void*)src))? (memcpy(dest, src, count), EOK) : (memcpy_s(dest, destMax, src, count)))
|
||||
|
||||
#define MEMSET_SM(dest, destMax, c, count)\
|
||||
(!(((size_t)destMax == 0 ) || (((UINT64T)(destMax) & (UINT64T)(-2)) > SECUREC_MEM_MAX_LEN) || (NULL == (void*)dest) || ((size_t)count > (size_t)destMax)) ? (memset(dest, c, count), EOK) : ( memset_s(dest, destMax, c, count)))
|
||||
|
||||
#endif /* WITH_PERFORMANCE_ADDONS */
|
||||
|
||||
/* 20150105 For software and hardware decoupling,such as UMG*/
|
||||
#ifdef SECUREC_SYSAPI4VXWORKS
|
||||
#ifdef feof
|
||||
#undef feof
|
||||
#endif
|
||||
extern int feof(FILE *stream);
|
||||
|
||||
#ifndef isspace
|
||||
#define isspace(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\r') || ((c) == '\n'))
|
||||
#endif
|
||||
#ifndef isascii
|
||||
#define isascii(c) (((unsigned char)(c))<=0x7f)
|
||||
#endif
|
||||
#ifndef isupper
|
||||
#define isupper(c) ((c) >= 'A' && (c) <= 'Z')
|
||||
#endif
|
||||
#ifndef islower
|
||||
#define islower(c) ((c) >= 'a' && (c) <= 'z')
|
||||
#endif
|
||||
#ifndef isalpha
|
||||
#define isalpha(c) (isupper(c) || (islower(c)))
|
||||
#endif
|
||||
#ifndef isdigit
|
||||
#define isdigit(c) ((c) >= '0' && (c) <= '9')
|
||||
#endif
|
||||
#ifndef isxdigit
|
||||
#define isxupper(c) ((c) >= 'A' && (c) <= 'F')
|
||||
#define isxlower(c) ((c) >= 'a' && (c) <= 'f')
|
||||
#define isxdigit(c) (isdigit(c) || isxupper(c) ||isxlower(c))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /*__SECURECTYPE_H__A7BBB686_AADA_451B_B9F9_44DACDAE18A7*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user