library/src/javascript/JSON/BP-JSON.cc
// Attempts to append a hreg to json at a path
Attempts to append a hreg to json at a path
Attempts to append a hreg to json at a path
BP_ERROR_T BP_JSONAppendHRegByTablePath
(
		P_BP_JSON                 json,
		P_BP_HASH_TABLE_REGISTRY  hreg,
		char                     *new_appended_table_name,
		char                    **initial_append_path,
		BP_BOOL                   include_data,
		BP_BOOL                   base64_encode_bin_data
)
{
	if(!json)
		return ERR_FAILURE;
	if(!hreg)
		return ERR_FAILURE;
	if(!initial_append_path)
		return ERR_FAILURE;
	if(!json)
		return ERR_FAILURE;
	if(!hreg)
		return ERR_FAILURE;
	if(!hreg->hive)
		return ERR_FAILURE;
	if(!hreg->hive->key)
		return ERR_FAILURE;
	if(!initial_append_path)
		return ERR_FAILURE;
	if(!new_appended_table_name)
		return ERR_FAILURE;
	if(!BP_StringIsReasonableForJSONPropertyNameString(new_appended_table_name, bpstrlen(new_appended_table_name)))
		return ERR_FAILURE;
	P_BP_HASH_TABLE_KEYED_ENTRY hreg_entry = BP_JSONLookupEntryByPath(json, initial_append_path);
	if(!hreg_entry)
	{
		printf("\n [!!] JSON parent path entry not found.");
		return ERR_FAILURE;
	}
	char *tmp_add_path[] =
	{
		new_appended_table_name,
		NULL
	};
	printf("\n Appending HREG NAME?: %s", new_appended_table_name);
	char **combined_path = BP_CombineStringArray(initial_append_path, (char **) &tmp_add_path);
	if(!combined_path)
		return ERR_FAILURE;
	if(BP_JSONLookupEntryByPath(json, combined_path))
	{
		printf("\n [!!] JSON parent path entry not found.");
		BP_DestroyPointerArrayNullTerminated((void **) combined_path);
		bpfree(combined_path);
		return ERR_FAILURE;
	}
	char ** parent_table_entry = BP_JSONEntryToPath(hreg_entry);
	if(!parent_table_entry)
	{
		BP_DestroyPointerArrayNullTerminated((void **) combined_path);
		bpfree(combined_path);
		return ERR_FAILURE;
	}
	hreg_entry = BP_JSONLookupEntryByPath(json, initial_append_path);
	BP_ERROR_T append_ret = BP_JSONAppendHReg_r
	(
		json,
		(P_BP_HTKE) hreg->hive,
		(char **) combined_path,
		include_data,
		base64_encode_bin_data
	);
	if(!append_ret)
	{
		BP_DestroyPointerArrayNullTerminated((void **) combined_path);
		bpfree(combined_path);
		return ERR_FAILURE;
	}
	BP_DestroyPointerArrayNullTerminated((void **) combined_path);
	bpfree(combined_path);
	BP_DestroyPointerArrayNullTerminated((void **) parent_table_entry);
	bpfree(parent_table_entry);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_JSONAppendHRegByTablePath ( P_BP_JSON json , P_BP_HASH_TABLE_REGISTRY hreg , char * new_appended_table_name , char * * initial_append_path , BP_BOOL include_data , BP_BOOL base64_encode_bin_data ) { if ( ! json ) return ERR_FAILURE ; if ( ! hreg ) return ERR_FAILURE ; if ( ! initial_append_path ) return ERR_FAILURE ; if ( ! json ) return ERR_FAILURE ; if ( ! hreg ) return ERR_FAILURE ; if ( ! hreg -> hive ) return ERR_FAILURE ; if ( ! hreg -> hive -> key ) return ERR_FAILURE ; if ( ! initial_append_path ) return ERR_FAILURE ; if ( ! new_appended_table_name ) return ERR_FAILURE ; if ( ! BP_StringIsReasonableForJSONPropertyNameString ( new_appended_table_name , bpstrlen ( new_appended_table_name ) ) ) return ERR_FAILURE ; P_BP_HASH_TABLE_KEYED_ENTRY hreg_entry = BP_JSONLookupEntryByPath ( json , initial_append_path ) ; if ( ! hreg_entry ) { printf ( " \n " ) ; return ERR_FAILURE ; } char * tmp_add_path [ ] = { new_appended_table_name , NULL } ; printf ( " \n " , new_appended_table_name ) ; char * * combined_path = BP_CombineStringArray ( initial_append_path , ( char * * ) & tmp_add_path ) ; if ( ! combined_path ) return ERR_FAILURE ; if ( BP_JSONLookupEntryByPath ( json , combined_path ) ) { printf ( " \n " ) ; BP_DestroyPointerArrayNullTerminated ( ( void * * ) combined_path ) ; bpfree ( combined_path ) ; return ERR_FAILURE ; } char * * parent_table_entry = BP_JSONEntryToPath ( hreg_entry ) ; if ( ! parent_table_entry ) { BP_DestroyPointerArrayNullTerminated ( ( void * * ) combined_path ) ; bpfree ( combined_path ) ; return ERR_FAILURE ; } hreg_entry = BP_JSONLookupEntryByPath ( json , initial_append_path ) ; BP_ERROR_T append_ret = BP_JSONAppendHReg_r ( json , ( P_BP_HTKE ) hreg -> hive , ( char * * ) combined_path , include_data , base64_encode_bin_data ) ; if ( ! append_ret ) { BP_DestroyPointerArrayNullTerminated ( ( void * * ) combined_path ) ; bpfree ( combined_path ) ; return ERR_FAILURE ; } BP_DestroyPointerArrayNullTerminated ( ( void * * ) combined_path ) ; bpfree ( combined_path ) ; BP_DestroyPointerArrayNullTerminated ( ( void * * ) parent_table_entry ) ; bpfree ( parent_table_entry ) ; return ERR_SUCCESS ; }
Attempts to append a hreg to json at a path
Attempts to append a hreg to json at a path
// run basic checks // -- ensure initial path exists --- // attempt to lookup the entry within our json (ensure it doesn't exist) // --- ensure combined path does NOT exist ------- // key operation // attempt to combine string arrays // ensure combined path entry doesn't already exist // lookup parent table entry // attempt to lookup the entry within our json (ensure it does exist after creation) // attempt to add registry // ensure we have successfully appended our json // destroy allocated memory before exit // return indicating success