library/src/javascript/JSON/BP-JSON.cc
// generate a json buffer from local tq (destroys old if already set)
generate a json buffer from local tq (destroys old if already set)
generate a json buffer from local tq ( destroys old if already set )
BP_ERROR_T BP_JSONGenerateJSONBufferFromLocalTQ(P_BP_JSON json)
{
	if(!json)
		return ERR_FAILURE;
	if(!json->json_out_prepare_tq)
		return ERR_FAILURE;
	BP_LinkLFlattenJoinStringElements(json->json_out_prepare_tq);
	if(!json->json_out_prepare_tq->flat_buff)
		return ERR_FAILURE;
	size_t buff_len = bpstrlen((char *) json->json_out_prepare_tq->flat_buff);
	if(!buff_len)
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString((char *) json->json_out_prepare_tq->flat_buff, buff_len, BP_TRUE, BP_TRUE))
		return ERR_FAILURE;
	if(json->json_out)
	{
		ht_free(json->system_hreg, json->json_out);
		json->json_out = NULL;
		json->json_out_len = 0;
	}
	json->json_out = ht_strndup
	(
		json->system_hreg,
		(char *) json->json_out_prepare_tq->flat_buff,
		buff_len
	);
	if(!json->json_out)
		return ERR_FAILURE;
	json->json_out_len = bpstrlen((char *) json->json_out);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_JSONGenerateJSONBufferFromLocalTQ ( P_BP_JSON json ) { if ( ! json ) return ERR_FAILURE ; if ( ! json -> json_out_prepare_tq ) return ERR_FAILURE ; BP_LinkLFlattenJoinStringElements ( json -> json_out_prepare_tq ) ; if ( ! json -> json_out_prepare_tq -> flat_buff ) return ERR_FAILURE ; size_t buff_len = bpstrlen ( ( char * ) json -> json_out_prepare_tq -> flat_buff ) ; if ( ! buff_len ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( ( char * ) json -> json_out_prepare_tq -> flat_buff , buff_len , BP_TRUE , BP_TRUE ) ) return ERR_FAILURE ; if ( json -> json_out ) { ht_free ( json -> system_hreg , json -> json_out ) ; json -> json_out = NULL ; json -> json_out_len = 0 ; } json -> json_out = ht_strndup ( json -> system_hreg , ( char * ) json -> json_out_prepare_tq -> flat_buff , buff_len ) ; if ( ! json -> json_out ) return ERR_FAILURE ; json -> json_out_len = bpstrlen ( ( char * ) json -> json_out ) ; return ERR_SUCCESS ; }
generate a json buffer from local tq (destroys old if already set)
generate a json buffer from local tq ( destroys old if already set )
// if we don't have a json object, exit failure // ensure we have a prepare tq (should be created via JSONCreateOutput) // flatten string elements // ensure we have a flat buffer // calculate length from buff // ensure the buffer is reasonable // clear old if necessary // destroy old json if it exists // set parameter to null // attempt to duplicate the prepared buffer // ensure we could create space for our output buffer // set the output length // return indicating success