1 /* 2 * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 */ 4 5 #ifndef _DM_UTILS_H_ 6 #define _DM_UTILS_H_ 7 8 #define DM_UTILS_UINT16_STRLEN (5) 9 #define DM_UTILS_UINT32_STRLEN (10) 10 #define DM_UTILS_UINT64_STRLEN (20) 11 12 int dm_utils_copy_direct(void *input, int input_len, void **output, 13 int output_len); 14 15 int dm_utils_copy(void *input, int input_len, void **output, int output_len); 16 17 /** 18 * @brief search array index in a string. 19 * This function used to search array index in a string. 20 * 21 * @param input. The string to be searched 22 * @param input_len. The length of input 23 * @param partial_input_len. The length of input except [xx] 24 * @param array_input_len. The length of input include [xx] 25 * @param array_index. The array index in [xx] 26 * 27 * @warning input must be type of "xxxxx[xx]" 28 * @return success or fail. 29 * 30 */ 31 int dm_utils_strarr_index(char *input, int input_len, int *partial_input_len, 32 int *array_input_len, int *array_index); 33 34 int dm_utils_itoa_direct(int input, char **output); 35 int dm_utils_itoa(int input, char **output); 36 int dm_utils_ftoa_direct(double input, char **output); 37 int dm_utils_ftoa(double input, char **output); 38 int dm_utils_hex_to_str(unsigned char *input, int input_len, char **output); 39 int dm_utils_str_to_hex(char *input, int input_len, unsigned char **output, 40 int *output_len); 41 int dm_utils_memtok(char *input, int input_len, char delimiter, int index, 42 int *offset); 43 int dm_utils_replace_char(char *input, int input_len, char src, char dest); 44 int dm_utils_service_name(const char *prefix, const char *name, 45 char product_key[IOTX_PRODUCT_KEY_LEN + 1], 46 char device_name[IOTX_DEVICE_NAME_LEN + 1], 47 char **service_name); 48 int dm_utils_uri_add_prefix(const char *prefix, char *uri, char **new_uri); 49 int dm_utils_json_parse(const char *payload, int payload_len, int type, 50 lite_cjson_t *lite); 51 int dm_utils_json_object_item(lite_cjson_t *lite, const char *key, int key_len, 52 int type, lite_cjson_t *lite_item); 53 void *dm_utils_malloc(unsigned int size); 54 void dm_utils_free(void *ptr); 55 #endif 56