summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c56
-rw-r--r--plugins/lib/bluealsa/hal-bluealsa-transports.c2
-rw-r--r--plugins/lib/bluealsa/hal-bluealsa.c3
-rw-r--r--src/4a-hal-manager/4a-hal-manager-cb.c112
-rw-r--r--src/4a-internals-hal/4a-internals-hal-alsacore-link.c135
-rw-r--r--src/4a-internals-hal/4a-internals-hal-api-loader.c9
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c124
-rw-r--r--src/4a-internals-hal/4a-internals-hal-value-handler.c35
8 files changed, 359 insertions, 117 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
index 550faaa..c38bfdd 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
@@ -43,7 +43,7 @@ void HalUtlActionOnMixer(afb_req_t request, enum ActionOnMixerType actionType)
struct HalData *currentHalData;
struct InternalHalMixerData *currentMixerData = NULL;
- json_object *requestJson, *responseJ = NULL, *toReturnJ = NULL;
+ json_object *requestJson, *responseJ = NULL, *toReturnJ = NULL, *verboseBooleanJ;
apiHandle = afb_req_get_api(request);
if(! apiHandle) {
@@ -69,8 +69,17 @@ void HalUtlActionOnMixer(afb_req_t request, enum ActionOnMixerType actionType)
return;
}
- if(json_object_is_type(requestJson, json_type_object) && json_object_get_object(requestJson)->count > 0)
- json_object_object_add(requestJson, "verbose", json_object_new_boolean(1));
+ if(json_object_is_type(requestJson, json_type_object) && json_object_get_object(requestJson)->count > 0) {
+ verboseBooleanJ = json_object_new_boolean(1);
+ if(! verboseBooleanJ) {
+ afb_req_fail(request,
+ "verbose_boolean_allocation",
+ "Didn't succeed to allocate verbose value json boolean");
+ return;
+ }
+
+ json_object_object_add(requestJson, "verbose", verboseBooleanJ);
+ }
apiToCall = currentHalData->internalHalData->mixerApiName;
if(! apiToCall) {
@@ -99,6 +108,12 @@ void HalUtlActionOnMixer(afb_req_t request, enum ActionOnMixerType actionType)
case ACTION_ON_MIXER_ALL_STREAM:
count = (int) HalUtlGetNumberOfMixerDataInList(&currentMixerData);
toReturnJ = json_object_new_object();
+ if(! toReturnJ) {
+ afb_req_fail(request,
+ "response_json_object",
+ "Didn't succeed to allocate response json object");
+ return;
+ }
break;
default:
@@ -237,6 +252,8 @@ struct InternalHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(afb_api_t ap
char *verbToCall,
char *streamCardId)
{
+ int wrapRet;
+
json_object *streamAddedEventJ;
CtlConfigT *ctrlConfig;
@@ -290,11 +307,16 @@ struct InternalHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(afb_api_t ap
return NULL;
}
- wrap_json_pack(&streamAddedEventJ,
- "{s:s, s:s, s:s}",
- "action", "added",
- "name", createdStreamData->verb,
- "cardId", createdStreamData->streamCardId);
+ wrapRet = wrap_json_pack(&streamAddedEventJ,
+ "{s:s, s:s, s:s}",
+ "action", "added",
+ "name", createdStreamData->verb,
+ "cardId", createdStreamData->streamCardId);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle,"Didn't succeed to allocate added stream event json object");
+ HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsData, createdStreamData);
+ return NULL;
+ }
afb_event_push(currentHalData->internalHalData->streamUpdates, streamAddedEventJ);
@@ -306,7 +328,7 @@ int HalUtlRemoveStreamDataAndDeleteStreamVerb(afb_api_t apiHandle,
char *verbToCall,
char *streamCardId)
{
- int returnedErr = 0;
+ int returnedErr = 0, wrapRet;
json_object *streamRemovedEventJ;
@@ -334,12 +356,6 @@ int HalUtlRemoveStreamDataAndDeleteStreamVerb(afb_api_t apiHandle,
if(! toRemoveStreamData)
return -4;
- wrap_json_pack(&streamRemovedEventJ,
- "{s:s, s:s, s:s}",
- "action", "removed",
- "name", toRemoveStreamData->verb,
- "cardId", toRemoveStreamData->streamCardId);
-
if(afb_api_del_verb(apiHandle, verb, NULL)) {
AFB_API_ERROR(apiHandle,"Error while deleting verb for stream : '%s'", verb);
json_object_put(streamRemovedEventJ);
@@ -353,6 +369,16 @@ int HalUtlRemoveStreamDataAndDeleteStreamVerb(afb_api_t apiHandle,
return -6;
}
+ wrapRet = wrap_json_pack(&streamRemovedEventJ,
+ "{s:s, s:s, s:s}",
+ "action", "removed",
+ "name", toRemoveStreamData->verb,
+ "cardId", toRemoveStreamData->streamCardId);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle,"Didn't succeed to allocate removed stream event json object");
+ return -7;
+ }
+
afb_event_push(currentHalData->internalHalData->streamUpdates, streamRemovedEventJ);
return 0;
diff --git a/plugins/lib/bluealsa/hal-bluealsa-transports.c b/plugins/lib/bluealsa/hal-bluealsa-transports.c
index 341fb6b..8638b36 100644
--- a/plugins/lib/bluealsa/hal-bluealsa-transports.c
+++ b/plugins/lib/bluealsa/hal-bluealsa-transports.c
@@ -35,7 +35,7 @@ bluealsa_transport_t * halBlueAlsaTransportsAdd(
const struct ba_msg_transport * transport) {
bluealsa_transport_t * newTransport = (bluealsa_transport_t*) calloc(1, sizeof(bluealsa_transport_t));
- if (newTransport == NULL)
+ if (!newTransport)
goto fail;
memcpy(&newTransport->transport, transport, sizeof(struct ba_msg_transport));
diff --git a/plugins/lib/bluealsa/hal-bluealsa.c b/plugins/lib/bluealsa/hal-bluealsa.c
index efce322..ca49bda 100644
--- a/plugins/lib/bluealsa/hal-bluealsa.c
+++ b/plugins/lib/bluealsa/hal-bluealsa.c
@@ -125,6 +125,9 @@ CTLP_CAPI(init, source, argsJ, queryJ)
CtlPluginT * plugin = source->plugin;
hal_bluealsa_plugin_data_t * pluginData = (hal_bluealsa_plugin_data_t*) calloc(1, sizeof(hal_bluealsa_plugin_data_t));
+ if(!pluginData)
+ goto fail;
+
int error;
/*
diff --git a/src/4a-hal-manager/4a-hal-manager-cb.c b/src/4a-hal-manager/4a-hal-manager-cb.c
index 022bda8..facc15c 100644
--- a/src/4a-hal-manager/4a-hal-manager-cb.c
+++ b/src/4a-hal-manager/4a-hal-manager-cb.c
@@ -46,18 +46,26 @@ void HalMgrDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json_obje
void HalMgrPing(afb_req_t request)
{
static int count = 0;
+ json_object *countJ;
count++;
AFB_REQ_NOTICE(request, "ping count = %d", count);
- afb_req_success(request, json_object_new_int(count), NULL);
+
+ countJ = json_object_new_int(count);
+ if(! countJ) {
+ afb_req_fail(request, "count_json_int", "Didn't succeed to allocate count json integer");
+ return;
+ }
+
+ afb_req_success(request, countJ, "Ping count");
return;
}
void HalMgrLoaded(afb_req_t request)
{
- int requestJsonErr = 0, allHal = 0, verbose = 0;
+ int requestJsonErr = 0, allHal = 0, verbose = 0, wrapRet = 0;
char cardIdString[32];
@@ -65,7 +73,7 @@ void HalMgrLoaded(afb_req_t request)
struct HalMgrData *halMgrData;
struct HalData *currentHalData;
- json_object *requestJson, *requestAnswer, *apiObject;
+ json_object *requestJson, *requestAnswer, *apiRequestedInfoJ;
apiHandle = afb_req_get_api(request);
if(! apiHandle) {
@@ -87,7 +95,9 @@ void HalMgrLoaded(afb_req_t request)
requestAnswer = json_object_new_array();
if(! requestAnswer) {
- afb_req_fail(request, "json_answer", "Can't generate json answer");
+ afb_req_fail(request,
+ "response_json_array",
+ "Didn't succeed to allocate response json array");
return;
}
@@ -106,23 +116,32 @@ void HalMgrLoaded(afb_req_t request)
else
snprintf(cardIdString, sizeof(cardIdString), "not-found");
- wrap_json_pack(&apiObject,
- "{s:s s:i s:s s:i s:s s:s s:s s:s s:s}",
- "api", currentHalData->apiName,
- "status", (int) currentHalData->status,
- "sndcard", currentHalData->sndCardPath,
- "internal", (int) currentHalData->internal,
- "info", currentHalData->info ? currentHalData->info : "",
- "author", currentHalData->author ? currentHalData->author : "",
- "version", currentHalData->version ? currentHalData->version : "",
- "date", currentHalData->date ? currentHalData->date : "",
- "snd-dev-id", cardIdString);
- json_object_array_add(requestAnswer, apiObject);
+ wrapRet = wrap_json_pack(&apiRequestedInfoJ,
+ "{s:s s:i s:s s:i s:s s:s s:s s:s s:s}",
+ "api", currentHalData->apiName,
+ "status", (int) currentHalData->status,
+ "sndcard", currentHalData->sndCardPath,
+ "internal", (int) currentHalData->internal,
+ "info", currentHalData->info ? currentHalData->info : "",
+ "author", currentHalData->author ? currentHalData->author : "",
+ "version", currentHalData->version ? currentHalData->version : "",
+ "date", currentHalData->date ? currentHalData->date : "",
+ "snd-dev-id", cardIdString);
}
// Case if request is empty or not handled
else {
- json_object_array_add(requestAnswer, json_object_new_string(currentHalData->apiName));
+ apiRequestedInfoJ = json_object_new_string(currentHalData->apiName);
+ }
+
+ if(wrapRet || ! apiRequestedInfoJ) {
+ afb_req_fail(request,
+ "requestedinfo_json",
+ "Didn't succeed to allocate api requested info json");
+ json_object_put(requestAnswer);
+ return;
}
+
+ json_object_array_add(requestAnswer, apiRequestedInfoJ);
}
currentHalData = currentHalData->next;
@@ -186,19 +205,66 @@ void HalMgrLoad(afb_req_t request)
addedHal->status = HAL_STATUS_READY;
addedHal->apiName = strdup(apiName);
+ if(! addedHal->apiName) {
+ afb_req_fail(request,
+ "apiname_string_allocation",
+ "Didn't succeed to store (allocate) 'apiName' string");
+ HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal);
+ return;
+ }
+
addedHal->sndCardPath = strdup(sndCardPath);
+ if(! addedHal->sndCardPath) {
+ afb_req_fail(request,
+ "sndcardpath_string_allocation",
+ "Didn't succeed to store (allocate) 'sndCardPath' string");
+ HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal);
+ return;
+ }
- if(info)
+ if(info) {
addedHal->info = strdup(info);
+ if(! addedHal->info) {
+ afb_req_fail(request,
+ "info_string_allocation",
+ "Didn't succeed to store (allocate) 'info' string");
+ HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal);
+ return;
+ }
+ }
- if(author)
+ if(author) {
addedHal->author = strdup(author);
+ if(! addedHal->author) {
+ afb_req_fail(request,
+ "author_string_allocation",
+ "Didn't succeed to store (allocate) 'author' string");
+ HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal);
+ return;
+ }
+ }
- if(version)
+ if(version) {
addedHal->version = strdup(version);
+ if(! addedHal->version) {
+ afb_req_fail(request,
+ "version_string_allocation",
+ "Didn't succeed to store (allocate) 'version' string");
+ HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal);
+ return;
+ }
+ }
- if(date)
+ if(date) {
addedHal->date = strdup(date);
+ if(! addedHal->date) {
+ afb_req_fail(request,
+ "date_string_allocation",
+ "Didn't succeed to store (allocate) 'date' string");
+ HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal);
+ return;
+ }
+ }
addedHal->sndCardId = cardId;
@@ -266,7 +332,7 @@ void HalMgrSubscribeEvent(afb_req_t request)
{
AFB_REQ_WARNING(request, "Not implemented yet");
- afb_req_success(request, json_object_new_boolean(0), NULL);
+ afb_req_success(request, NULL, NULL);
}
// TBD JAI : to implement
@@ -274,5 +340,5 @@ void HalMgrUnsubscribeEvent(afb_req_t request)
{
AFB_REQ_WARNING(request, "Not implemented yet");
- afb_req_success(request, json_object_new_boolean(0), NULL);
+ afb_req_success(request, NULL, NULL);
}
diff --git a/src/4a-internals-hal/4a-internals-hal-alsacore-link.c b/src/4a-internals-hal/4a-internals-hal-alsacore-link.c
index 6eda170..db9e9b4 100644
--- a/src/4a-internals-hal/4a-internals-hal-alsacore-link.c
+++ b/src/4a-internals-hal/4a-internals-hal-alsacore-link.c
@@ -71,7 +71,7 @@ snd_ctl_elem_type_t InternalHalMapsAlsaTypeToEnum(const char *label)
int InternalHalGetCardIdByCardPath(afb_api_t apiHandle, char *devPath)
{
- int errorToReturn, cardId;
+ int errorToReturn, cardId, wrapRet;
char *returnedError = NULL, *returnedInfo = NULL;
@@ -87,7 +87,11 @@ int InternalHalGetCardIdByCardPath(afb_api_t apiHandle, char *devPath)
return -2;
}
- wrap_json_pack(&toSendJ, "{s:s}", "cardPath", devPath);
+ wrapRet = wrap_json_pack(&toSendJ, "{s:s}", "cardPath", devPath);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate cardpath json object (needed to search for audio card using path)");
+ return -3;
+ }
if(afb_api_call_sync(apiHandle,
ALSACORE_API,
@@ -102,25 +106,25 @@ int InternalHalGetCardIdByCardPath(afb_api_t apiHandle, char *devPath)
ALSACORE_API,
returnedError ? returnedError : "not returned",
returnedInfo ? returnedInfo : "not returned");
- errorToReturn = -3;
+ errorToReturn = -4;
}
else if(! responseJ) {
AFB_API_ERROR(apiHandle,
"Seems that %s call to api %s succeed but no response was returned",
ALSACORE_GETINFO_VERB,
ALSACORE_API);
- errorToReturn = -4;
+ errorToReturn = -5;
}
else if(! json_object_is_type(responseJ, json_type_object)) {
AFB_API_ERROR(apiHandle,
"Seems that %s call to api %s succeed but the returned response is invalid",
ALSACORE_GETINFO_VERB,
ALSACORE_API);
- errorToReturn = -5;
+ errorToReturn = -6;
}
else if(wrap_json_unpack(responseJ, "{s:i}", "cardNb", &cardId)) {
AFB_API_WARNING(apiHandle, "Response card id is not present/valid");
- errorToReturn = -6;
+ errorToReturn = -7;
}
else {
return cardId;
@@ -137,13 +141,18 @@ int InternalHalGetCardIdByCardPath(afb_api_t apiHandle, char *devPath)
int InternalHalSubscribeToAlsaCardEvent(afb_api_t apiHandle, char *cardId)
{
- int err = 0;
+ int err = 0, wrapRet;
char *returnedError = NULL, *returnedInfo = NULL;
json_object *subscribeQueryJ, *responseJ = NULL;
- wrap_json_pack(&subscribeQueryJ, "{s:s}", "devid", cardId);
+ wrapRet = wrap_json_pack(&subscribeQueryJ, "{s:s}", "devid", cardId);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate subscription query json object");
+ return -1;
+ }
+
if(afb_api_call_sync(apiHandle,
ALSACORE_API,
ALSACORE_SUBSCRIBE_VERB,
@@ -157,7 +166,7 @@ int InternalHalSubscribeToAlsaCardEvent(afb_api_t apiHandle, char *cardId)
ALSACORE_API,
returnedError ? returnedError : "not returned",
returnedInfo ? returnedInfo : "not returned");
- err = -1;
+ err = -2;
}
if(responseJ)
@@ -171,7 +180,7 @@ int InternalHalSubscribeToAlsaCardEvent(afb_api_t apiHandle, char *cardId)
int InternalHalGetAlsaCtlInfo(afb_api_t apiHandle, char *cardId, struct InternalHalAlsaCtl *currentAlsaCtl, json_object **returnedDataJ)
{
- int err = 0;
+ int err = 0, wrapRet;
char *returnedError = NULL, *returnedInfo = NULL;
@@ -202,16 +211,29 @@ int InternalHalGetAlsaCtlInfo(afb_api_t apiHandle, char *cardId, struct Internal
}
if(currentAlsaCtl->numid > 0) {
- wrap_json_pack(&queryJ, "{s:s s:i s:i}", "devid", cardId, "ctl", currentAlsaCtl->numid, "mode", 3);
+ wrapRet = wrap_json_pack(&queryJ,
+ "{s:s s:i s:i}",
+ "devid", cardId,
+ "ctl", currentAlsaCtl->numid,
+ "mode", 3);
}
else if(currentAlsaCtl->name) {
- wrap_json_pack(&queryJ, "{s:s s:s s:i}", "devid", cardId, "ctl", currentAlsaCtl->name, "mode", 3);
+ wrapRet = wrap_json_pack(&queryJ,
+ "{s:s s:s s:i}",
+ "devid", cardId,
+ "ctl", currentAlsaCtl->name,
+ "mode", 3);
}
else {
AFB_API_ERROR(apiHandle, "Need at least a control name or a control id");
return -4;
}
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate get ALSA control query json object");
+ return -5;
+ }
+
if(afb_api_call_sync(apiHandle,
ALSACORE_API,
ALSACORE_CTLGET_VERB,
@@ -227,19 +249,19 @@ int InternalHalGetAlsaCtlInfo(afb_api_t apiHandle, char *cardId, struct Internal
returnedInfo ? returnedInfo : "not returned");
free(returnedError);
free(returnedInfo);
- return -5;
+ return -6;
}
else if(! responseJ) {
AFB_API_ERROR(apiHandle,
"Seems that %s call to api %s succeed but no response was returned",
ALSACORE_CTLGET_VERB,
ALSACORE_API);
- return -6;
+ return -7;
}
else if(currentAlsaCtl->name && wrap_json_unpack(responseJ, "{s:i}", "id", &currentAlsaCtl->numid)) {
AFB_API_ERROR(apiHandle, "Can't find alsa control 'id' from control 'name': '%s' on device '%s'", currentAlsaCtl->name, cardId);
json_object_put(responseJ);
- return -7;
+ return -8;
}
*returnedDataJ = responseJ;
@@ -272,7 +294,7 @@ int InternalHalUpdateAlsaCtlProperties(afb_api_t apiHandle, char *cardId, struct
cardId,
json_object_get_string(returnedDataJ));
- err = -8;
+ err = -9;
}
if(returnedDataJ)
@@ -300,7 +322,7 @@ int InternalHalGetAlsaCtlValues(afb_api_t apiHandle, char *cardId, struct Intern
cardId,
json_object_get_string(returnedValuesArrayJ));
- err = -8;
+ err = -9;
}
else if(! json_object_is_type(returnedValuesArrayJ, json_type_array)) {
AFB_API_ERROR(apiHandle,
@@ -309,7 +331,7 @@ int InternalHalGetAlsaCtlValues(afb_api_t apiHandle, char *cardId, struct Intern
cardId,
json_object_get_string(returnedValuesArrayJ));
- err = -9;
+ err = -10;
}
if(! err)
@@ -323,7 +345,7 @@ int InternalHalGetAlsaCtlValues(afb_api_t apiHandle, char *cardId, struct Intern
int InternalHalSetAlsaCtlValue(afb_api_t apiHandle, char *cardId, int ctlId, json_object *valuesJ)
{
- int err = 0;
+ int err = 0, wrapRet;
char *returnedError = NULL, *returnedInfo = NULL;
@@ -349,7 +371,16 @@ int InternalHalSetAlsaCtlValue(afb_api_t apiHandle, char *cardId, int ctlId, jso
return -4;
}
- wrap_json_pack(&queryJ, "{s:s s:{s:i s:o}}", "devid", cardId, "ctl", "id", ctlId, "val", json_object_get(valuesJ));
+ wrapRet = wrap_json_pack(&queryJ,
+ "{s:s s:{s:i s:o}}",
+ "devid", cardId,
+ "ctl",
+ "id", ctlId,
+ "val", json_object_get(valuesJ));
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate set ALSA control query json object");
+ return -5;
+ }
if(afb_api_call_sync(apiHandle,
ALSACORE_API,
@@ -364,7 +395,7 @@ int InternalHalSetAlsaCtlValue(afb_api_t apiHandle, char *cardId, int ctlId, jso
ALSACORE_API,
returnedError ? returnedError : "not returned",
returnedInfo ? returnedInfo : "not returned");
- err = -5;
+ err = -6;
}
if(responseJ)
@@ -378,7 +409,7 @@ int InternalHalSetAlsaCtlValue(afb_api_t apiHandle, char *cardId, int ctlId, jso
int InternalHalCreateAlsaCtl(afb_api_t apiHandle, char *cardId, struct InternalHalAlsaCtl *alsaCtlToCreate)
{
- int err = 0;
+ int err = 0, wrapRet;
char *returnedError = NULL, *returnedInfo = NULL;
@@ -404,16 +435,21 @@ int InternalHalCreateAlsaCtl(afb_api_t apiHandle, char *cardId, struct InternalH
return -4;
}
- wrap_json_pack(&queryJ, "{s:s s:{s:i s:s s?:i s?:i s?:i s:i s:i}}",
- "devid", cardId,
- "ctl",
- "ctl", -1,
- "name", alsaCtlToCreate->name,
- "min", alsaCtlToCreate->alsaCtlCreation->minval,
- "max", alsaCtlToCreate->alsaCtlCreation->maxval,
- "step", alsaCtlToCreate->alsaCtlCreation->step,
- "type", (int) alsaCtlToCreate->alsaCtlCreation->type,
- "count", alsaCtlToCreate->alsaCtlCreation->count);
+ wrapRet = wrap_json_pack(&queryJ,
+ "{s:s s:{s:i s:s s?:i s?:i s?:i s:i s:i}}",
+ "devid", cardId,
+ "ctl",
+ "ctl", -1,
+ "name", alsaCtlToCreate->name,
+ "min", alsaCtlToCreate->alsaCtlCreation->minval,
+ "max", alsaCtlToCreate->alsaCtlCreation->maxval,
+ "step", alsaCtlToCreate->alsaCtlCreation->step,
+ "type", (int) alsaCtlToCreate->alsaCtlCreation->type,
+ "count", alsaCtlToCreate->alsaCtlCreation->count);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate create ALSA control query json object");
+ return -5;
+ }
if(afb_api_call_sync(apiHandle,
ALSACORE_API,
@@ -428,21 +464,21 @@ int InternalHalCreateAlsaCtl(afb_api_t apiHandle, char *cardId, struct InternalH
ALSACORE_API,
returnedError ? returnedError : "not returned",
returnedInfo ? returnedInfo : "not returned");
- err = -5;
+ err = -6;
}
else if(! responseJ) {
AFB_API_ERROR(apiHandle,
"Seems that %s call to api %s succeed but no response was returned",
ALSACORE_ADDCTL_VERB,
ALSACORE_API);
- err = -6;
+ err = -7;
}
else if(wrap_json_unpack(responseJ, "{s:i}", "id", &alsaCtlToCreate->numid)) {
AFB_API_ERROR(apiHandle,
"Can't get create id from %s of %s api",
ALSACORE_ADDCTL_VERB,
ALSACORE_API);
- err = -7;
+ err = -8;
}
else if(wrap_json_unpack(responseJ, "{s:o}", "ctl", NULL)) {
AFB_API_WARNING(apiHandle, "Control %s was already present but has been updated", alsaCtlToCreate->name);
@@ -463,6 +499,8 @@ int InternalHalCreateAlsaCtl(afb_api_t apiHandle, char *cardId, struct InternalH
void InternalHalActionOnAlsaCtl(afb_req_t request)
{
+ int wrapRet;
+
char cardIdString[6];
afb_api_t apiHandle;
@@ -536,9 +574,16 @@ void InternalHalActionOnAlsaCtl(afb_req_t request)
requestJson = afb_req_json(request);
if(! requestJson) {
- wrap_json_pack(&answerJ,
- "{s:o}",
- "current", normalizedPreviousControlValuesJ);
+ wrapRet = wrap_json_pack(&answerJ,
+ "{s:o}",
+ "current", normalizedPreviousControlValuesJ);
+ if(wrapRet) {
+ afb_req_fail(request,
+ "currentvalues_json_object",
+ "Didn't succeed to allocate ALSA control current values response json object");
+ return;
+ }
+
afb_req_success(request, answerJ, "Current controls values");
json_object_put(previousControlValuesJ);
return;
@@ -627,10 +672,16 @@ void InternalHalActionOnAlsaCtl(afb_req_t request)
json_object_put(appliedControlValuesJ);
- wrap_json_pack(&answerJ,
- "{s:o, s:o}",
- "previous", normalizedPreviousControlValuesJ,
- "current", normalizedAppliedControlValuesJ);
+ wrapRet = wrap_json_pack(&answerJ,
+ "{s:o, s:o}",
+ "previous", normalizedPreviousControlValuesJ,
+ "current", normalizedAppliedControlValuesJ);
+ if(wrapRet) {
+ afb_req_fail(request,
+ "values_json_object",
+ "Didn't succeed to allocate ALSA control previous and current values response json object");
+ return;
+ }
afb_req_success(request, answerJ, "Values correctly applied on alsa control");
} \ No newline at end of file
diff --git a/src/4a-internals-hal/4a-internals-hal-api-loader.c b/src/4a-internals-hal/4a-internals-hal-api-loader.c
index d70019e..75d0e6f 100644
--- a/src/4a-internals-hal/4a-internals-hal-api-loader.c
+++ b/src/4a-internals-hal/4a-internals-hal-api-loader.c
@@ -140,6 +140,11 @@ static int InternalHalLoadOneApi(void *cbdata, afb_api_t apiHandle)
}
ctrlCurrentSections = malloc(sizeof(ctrlSectionsDefault));
+ if(! ctrlCurrentSections) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate current internal hal section data structure for controller");
+ return -3;
+ }
+
memcpy(ctrlCurrentSections, ctrlSectionsDefault, sizeof(ctrlSectionsDefault));
// Load section for corresponding Api
@@ -192,6 +197,10 @@ int InternalHalCreateApi(afb_api_t apiHandle, char *path, struct HalMgrData *hal
// Allocation of the structure that will be used to store internal hal data
currentHalData->internalHalData = calloc(1, sizeof(struct InternalHalData));
+ if(! currentHalData->internalHalData) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate internal hal data structure");
+ return -5;
+ }
// Create one API
if(! afb_api_new_api(apiHandle, ctrlConfig->api, ctrlConfig->info, 1, InternalHalLoadOneApi, ctrlConfig)) {
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index ee0787b..bca4d82 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -276,11 +276,16 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
if(alsaMap->ctl.value) {
// TBD JAI : handle alsa controls type
valueJ = json_object_new_int(alsaMap->ctl.value);
+ if(! valueJ) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate ALSA control value json string");
+ return -4;
+ }
+
err = 0;
if(InternalHalConvertJsonValues(apiHandle, &alsaMap->ctl.alsaCtlProperties, valueJ, &convertedValueJ, CONVERSION_NORMALIZED_TO_ALSACORE)) {
AFB_API_ERROR(apiHandle, "Error when trying to convert initiate value json '%s'", json_object_get_string(valueJ));
- err = -4;
+ err = -5;
}
else if(InternalHalSetAlsaCtlValue(apiHandle, cardId, alsaMap->ctl.numid, convertedValueJ)) {
AFB_API_ERROR(apiHandle,
@@ -288,7 +293,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
alsaMap->ctl.numid,
cardId,
json_object_get_string(valueJ));
- err = -5;
+ err = -6;
}
json_object_put(valueJ);
@@ -302,11 +307,18 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
if(alsaMap->actionJ) {
alsaMap->action = calloc(1, sizeof(CtlActionT));
+ if(! alsaMap->action) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to allocate structure used to store action to perform"
+ "when the corresponding ALSA control is detected");
+ return -7;
+ }
+
if(ActionLoadOne(apiHandle, alsaMap->action, alsaMap->actionJ, 0)) {
AFB_API_ERROR(apiHandle,
"Didn't succeed to load action using alsa object : '%s'",
json_object_get_string(alsaMap->actionJ));
- return -6;
+ return -8;
}
}
@@ -314,7 +326,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
AFB_API_ERROR(apiHandle,
"Didn't succeed to create verb for current alsa control to load action using alsa object : '%s'",
json_object_get_string(alsaMap->actionJ));
- return -7;
+ return -9;
}
return 0;
@@ -346,6 +358,10 @@ int InternalHalProcessAllHalMap(afb_api_t apiHandle, json_object *AlsaMapJ, stru
}
ctlMaps = calloc(currentInternalHalAlsaMapT->ctlsCount, sizeof(struct InternalHalAlsaMap));
+ if(! ctlMaps) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate halmap data table");
+ return -2;
+ }
for(idx = 0; idx < currentInternalHalAlsaMapT->ctlsCount; idx++)
err += InternalHalProcessOneHalMapObject(apiHandle, &ctlMaps[idx], alsaMapType == json_type_array ? json_object_array_get_idx(AlsaMapJ, idx) : AlsaMapJ);
@@ -386,11 +402,15 @@ int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_obje
if(AlsaMapJ) {
currentHalData->internalHalData->alsaMapT = calloc(1, sizeof(struct InternalHalAlsaMapT));
+ if(! currentHalData->internalHalData->alsaMapT) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate data structure used to store halmap data table");
+ return -3;
+ }
if(InternalHalProcessAllHalMap(apiHandle, AlsaMapJ, currentHalData->internalHalData->alsaMapT)) {
AFB_API_ERROR(apiHandle, "Failed to process 'halmap' section");
HalUtlFreeAlsaCtlsMap(currentHalData->internalHalData->alsaMapT);
- return -3;
+ return -4;
}
}
else if(currentHalData->status == HAL_STATUS_UNAVAILABLE) {
@@ -399,7 +419,7 @@ int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_obje
}
else if(currentHalData->sndCardId < 0) {
AFB_API_ERROR(apiHandle, "Hal alsa card id is not valid, 'halmap' section data can't be handle");
- return -4;
+ return -5;
}
else if(! currentHalData->internalHalData->alsaMapT) {
AFB_API_WARNING(apiHandle, "'halmap' section data is empty");
@@ -411,7 +431,7 @@ int InternalHalHalMapConfig(afb_api_t apiHandle, CtlSectionT *section, json_obje
}
else if(InternalHalHandleAllHalMap(apiHandle, currentHalData->sndCardId, currentHalData->internalHalData->alsaMapT)) {
AFB_API_ERROR(apiHandle, "Failed to handle 'halmap' section");
- return -5;
+ return -6;
}
return 0;
@@ -425,6 +445,8 @@ json_object *InternalHalGetJsonArrayForMixerDataTable(afb_api_t apiHandle,
struct InternalHalMixerData **mixerDataList,
enum MixerDataType dataType)
{
+ int wrapRet;
+
json_object *mixerDataArrayJ, *currentMixerDataJ;
struct InternalHalMixerData *currentMixerData;
@@ -444,25 +466,32 @@ json_object *InternalHalGetJsonArrayForMixerDataTable(afb_api_t apiHandle,
while(currentMixerData) {
switch(dataType) {
case MIXER_DATA_STREAMS:
- wrap_json_pack(&currentMixerDataJ,
- "{s:s s:s}",
- "name", currentMixerData->verb,
- "cardId", currentMixerData->streamCardId);
+ wrapRet = wrap_json_pack(&currentMixerDataJ,
+ "{s:s s:s}",
+ "name", currentMixerData->verb,
+ "cardId", currentMixerData->streamCardId);
break;
case MIXER_DATA_PLAYBACKS:
case MIXER_DATA_CAPTURES :
- wrap_json_pack(&currentMixerDataJ,
- "{s:s s:s}",
- "name", currentMixerData->verb,
- "mixer-name", currentMixerData->verbToCall,
- "uid", currentMixerData->streamCardId ? currentMixerData->streamCardId : "none");
+ wrapRet = wrap_json_pack(&currentMixerDataJ,
+ "{s:s s:s}",
+ "name", currentMixerData->verb,
+ "mixer-name", currentMixerData->verbToCall,
+ "uid", currentMixerData->streamCardId ? currentMixerData->streamCardId : "none");
break;
default:
json_object_put(mixerDataArrayJ);
return NULL;
}
+
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate current mixer/playbacks/captures json object");
+ json_object_put(mixerDataArrayJ);
+ return NULL;
+ }
+
json_object_array_add(mixerDataArrayJ, currentMixerDataJ);
currentMixerData = currentMixerData->next;
@@ -473,6 +502,7 @@ json_object *InternalHalGetJsonArrayForMixerDataTable(afb_api_t apiHandle,
json_object *InternalHalGetJsonArrayForControls(afb_api_t apiHandle, struct InternalHalAlsaMapT *currentAlsaMapDataT)
{
+ int wrapRet;
unsigned int idx;
json_object *alsaMapDataArray, *currentAlsaMapData;
@@ -494,10 +524,15 @@ json_object *InternalHalGetJsonArrayForControls(afb_api_t apiHandle, struct Inte
}
for(idx = 0; idx < currentAlsaMapDataT->ctlsCount; idx++) {
- wrap_json_pack(&currentAlsaMapData,
- "{s:s s:s}",
- "name", currentAlsaMapDataT->ctls[idx].uid,
- "info", currentAlsaMapDataT->ctls[idx].info ? currentAlsaMapDataT->ctls[idx].info : "none");
+ wrapRet = wrap_json_pack(&currentAlsaMapData,
+ "{s:s s:s}",
+ "name", currentAlsaMapDataT->ctls[idx].uid,
+ "info", currentAlsaMapDataT->ctls[idx].info ? currentAlsaMapDataT->ctls[idx].info : "none");
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate current mixer/playbacks/captures json object");
+ json_object_put(alsaMapDataArray);
+ return NULL;
+ }
json_object_array_add(alsaMapDataArray, currentAlsaMapData);
}
@@ -507,6 +542,8 @@ json_object *InternalHalGetJsonArrayForControls(afb_api_t apiHandle, struct Inte
void InternalHalInfo(afb_req_t request)
{
+ int wrapRet;
+
char *apiToCall, *returnedError = NULL, *returnedInfo = NULL;
afb_api_t apiHandle;
@@ -595,12 +632,22 @@ void InternalHalInfo(afb_req_t request)
return;
}
- wrap_json_pack(&requestAnswer,
- "{s:o s:o s:o s:o}",
- "streams", streamsArray,
- "playbacks", playbacksArray,
- "captures", capturesArray,
- "controls", controlsArray);
+ wrapRet = wrap_json_pack(&requestAnswer,
+ "{s:o s:o s:o s:o}",
+ "streams", streamsArray,
+ "playbacks", playbacksArray,
+ "captures", capturesArray,
+ "controls", controlsArray);
+ if(wrapRet) {
+ afb_req_fail(request,
+ "halinfo_json_object",
+ "Didn't succeed to allocate hal info response json object");
+ json_object_put(streamsArray);
+ json_object_put(playbacksArray);
+ json_object_put(capturesArray);
+ json_object_put(controlsArray);
+ return;
+ }
afb_req_success(request, requestAnswer, "Requested data");
}
@@ -618,7 +665,10 @@ void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscrib
struct InternalHalMixerData *currentStreamData;
struct InternalHalAlsaMapT *InternalHalAlsaMapT;
- json_object *requestJson, *requestedSubscriptionsJ, *requestedSubscriptionJ = NULL;
+ json_object *requestJson,
+ *requestedSubscriptionsJ,
+ *requestedSubscriptionJ = NULL,
+ *subscriptionDoneNbJ = NULL;
json_type requestJsonType;
apiHandle = afb_req_get_api(request);
@@ -770,27 +820,39 @@ void InternalHalSubscribeUnsubscribe(afb_req_t request, enum SubscribeUnsubscrib
}
}
- if(subscriptionDoneNb == 0)
+ if(! subscriptionDoneNb) {
afb_req_fail_f(request,
"events_not_found",
"%s failed, event(s) were not found",
subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription");
+ return;
+ }
+ else {
+ subscriptionDoneNbJ = json_object_new_int(subscriptionDoneNb);
+ if(! subscriptionDoneNbJ) {
+ afb_req_fail(request,
+ "subscriptionnb_json_integer",
+ "Didn't succeed to allocate subscription number json integer");
+ return;
+ }
+ }
+
if(subscriptionDoneNb == count)
afb_req_success_f(request,
- json_object_new_int(subscriptionDoneNb),
+ subscriptionDoneNbJ,
"%s succeed for all the %i events requested",
subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription",
subscriptionDoneNb);
else if(subscriptionDoneNb < count)
afb_req_success_f(request,
- json_object_new_int(subscriptionDoneNb),
+ subscriptionDoneNbJ,
"%s succeed but only to %i events requested out of %i",
subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription",
subscriptionDoneNb,
count);
else
afb_req_success_f(request,
- json_object_new_int(subscriptionDoneNb),
+ subscriptionDoneNbJ,
"%s succeed but to more events than requested (%i out of %i)",
subscribeUnsubscribeType == SUBSCRIPTION ? "Subscription" : "Unsubscription",
subscriptionDoneNb,
diff --git a/src/4a-internals-hal/4a-internals-hal-value-handler.c b/src/4a-internals-hal/4a-internals-hal-value-handler.c
index 98e29ab..a8b0e2e 100644
--- a/src/4a-internals-hal/4a-internals-hal-value-handler.c
+++ b/src/4a-internals-hal/4a-internals-hal-value-handler.c
@@ -133,6 +133,10 @@ int InternalHalConvertJsonValueForIntegerControl(afb_api_t apiHandle,
}
*ConvertedJ = json_object_new_int(convertedValue);
+ if(! *ConvertedJ) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate converted value json integer");
+ return -5;
+ }
return 0;
}
@@ -187,6 +191,11 @@ int InternalHalConvertJsonValueForBooleanControl(afb_api_t apiHandle,
return -3;
}
+ if(! *ConvertedJ) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate converted value json");
+ return -4;
+ }
+
return 0;
}
@@ -207,6 +216,10 @@ int InternalHalConvertJsonValues(afb_api_t apiHandle,
count = (toConvertType == json_type_array) ? (int) json_object_array_length(toConvertJ) : 1;
convertedArrayJ = json_object_new_array();
+ if(! convertedArrayJ) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate converted values json array");
+ return -1;
+ }
for(idx = 0; idx < count; idx++) {
if(toConvertType == json_type_array)
@@ -229,7 +242,7 @@ int InternalHalConvertJsonValues(afb_api_t apiHandle,
idx,
json_object_get_string(toConvertObjectJ));
json_object_put(convertedArrayJ);
- return -1;
+ return -2;
}
break;
@@ -246,7 +259,7 @@ int InternalHalConvertJsonValues(afb_api_t apiHandle,
idx,
json_object_get_string(toConvertObjectJ));
json_object_put(convertedArrayJ);
- return -2;
+ return -3;
}
break;
@@ -255,7 +268,7 @@ int InternalHalConvertJsonValues(afb_api_t apiHandle,
"Conversion not handle for the alsa control type %i",
(int) alsaCtlProperties->type);
json_object_put(convertedArrayJ);
- return -3;
+ return -4;
}
json_object_array_put_idx(convertedArrayJ, idx, convertedValueJ);
@@ -276,7 +289,7 @@ int InternalHalChangePreviousValuesUsingJson(afb_api_t apiHandle,
char *requestedPercentageVariationString, *conversionEnd;
- json_object *toChangeObjectJ, *changedArrayJ;
+ json_object *toChangeObjectJ, *changedArrayJ, *changedValueJ;
*ChangedJ = NULL;
@@ -325,6 +338,10 @@ int InternalHalChangePreviousValuesUsingJson(afb_api_t apiHandle,
count = (int) json_object_array_length(previousControlValuesJ);
changedArrayJ = json_object_new_array();
+ if(! changedArrayJ) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate changed values json array");
+ return -1;
+ }
for(idx = 0; idx < count; idx++) {
toChangeObjectJ = json_object_array_get_idx(previousControlValuesJ, idx);
@@ -335,6 +352,7 @@ int InternalHalChangePreviousValuesUsingJson(afb_api_t apiHandle,
json_object_get_string(toChangeObjectJ),
idx,
count);
+ json_object_put(changedArrayJ);
return -5;
}
@@ -347,7 +365,14 @@ int InternalHalChangePreviousValuesUsingJson(afb_api_t apiHandle,
else
changedValue = toChangeValue + requestedVariation;
- json_object_array_put_idx(changedArrayJ, idx, json_object_new_int(changedValue));
+ changedValueJ = json_object_new_int(changedValue);
+ if(! changedValueJ) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate changed value json integer");
+ json_object_put(changedArrayJ);
+ return -6;
+ }
+
+ json_object_array_put_idx(changedArrayJ, idx, changedValueJ);
}
*ChangedJ = changedArrayJ;