diff options
Diffstat (limited to 'ahl-binding/ahl-binding.c')
-rw-r--r-- | ahl-binding/ahl-binding.c | 110 |
1 files changed, 58 insertions, 52 deletions
diff --git a/ahl-binding/ahl-binding.c b/ahl-binding/ahl-binding.c index f2d7b09..708846c 100644 --- a/ahl-binding/ahl-binding.c +++ b/ahl-binding/ahl-binding.c @@ -347,6 +347,7 @@ PUBLIC int AhlBindingInit() #ifndef AHL_DISCONNECT_POLICY // Policy initialization + AFB_DEBUG("Audio high-level policy initialization"); err = Policy_Init(); if(err == AHL_POLICY_REJECT) { //Error messages already reported inside PolicyInit @@ -368,7 +369,7 @@ PUBLIC int AhlBindingInit() json_object *pInPolicyEndpointJ = NULL; err = EndpointInfoToJSON(pCurEndpointInfo, &pInPolicyEndpointJ); if (err) { - AFB_ERROR("Unable to Create Endpoint Json object error:%s ",wrap_json_get_error_string(err)); + AFB_ERROR("Unable to create source endpoint JSON object from endpoint info for endpoint_id:%d error:%s ",pCurEndpointInfo->endpointID, wrap_json_get_error_string(err)); return AHL_FAIL; } else @@ -376,13 +377,13 @@ PUBLIC int AhlBindingInit() json_object * pOutPolicyEndpointJ = NULL; err = Policy_Endpoint_Init(pInPolicyEndpointJ,&pOutPolicyEndpointJ); if (err == AHL_POLICY_REJECT) { - AFB_WARNING("Policy endpoint properties initalization failed for endpoint_id :%d type:%d",pCurEndpointInfo->endpointID, pCurEndpointInfo->type); + AFB_WARNING("Policy source endpoint properties initalization failed for endpoint_id :%d type:%d",pCurEndpointInfo->endpointID, pCurEndpointInfo->type); // continue } json_object_put(pInPolicyEndpointJ); err = UpdateEndpointInfo(pCurEndpointInfo,pOutPolicyEndpointJ); if (err) { - AFB_ERROR("Policy endpoint properties update failed for endpoint_id :%d type:%d",pCurEndpointInfo->endpointID, pCurEndpointInfo->type); + AFB_ERROR("Policy source endpoint properties update failed for endpoint_id :%d type:%d",pCurEndpointInfo->endpointID, pCurEndpointInfo->type); return AHL_FAIL; } // json_object_put(pOutPolicyEndpointJ); @@ -398,7 +399,7 @@ PUBLIC int AhlBindingInit() json_object *pInPolicyEndpointJ = NULL; err = EndpointInfoToJSON(pCurEndpointInfo, &pInPolicyEndpointJ); if (err) { - AFB_ERROR("Unable to Create Endpoint Json object error:%s ",wrap_json_get_error_string(err)); + AFB_ERROR("Unable to create sink endpoint JSON object from endpoint info for endpoint_id:%d error:%s ",pCurEndpointInfo->endpointID, wrap_json_get_error_string(err)); return AHL_FAIL; } else @@ -406,13 +407,13 @@ PUBLIC int AhlBindingInit() json_object *pOutPolicyEndpointJ = NULL; err = Policy_Endpoint_Init(pInPolicyEndpointJ,&pOutPolicyEndpointJ); if (err == AHL_POLICY_REJECT) { - AFB_WARNING("Policy endpoint properties initalization failed for endpoint_id :%d type:%d",pCurEndpointInfo->endpointID, pCurEndpointInfo->type); + AFB_WARNING("Policy sink endpoint properties initalization failed for endpoint_id :%d type:%d",pCurEndpointInfo->endpointID, pCurEndpointInfo->type); // continue } json_object_put(pInPolicyEndpointJ); err = UpdateEndpointInfo(pCurEndpointInfo,pOutPolicyEndpointJ); if (err) { - AFB_ERROR("Policy endpoint properties update failed for endpoint_id :%d type:%d",pCurEndpointInfo->endpointID, pCurEndpointInfo->type); + AFB_ERROR("Policy sink endpoint properties update failed for endpoint_id :%d type:%d",pCurEndpointInfo->endpointID, pCurEndpointInfo->type); return AHL_FAIL; } //json_object_put(pOutPolicyEndpointJ); @@ -429,7 +430,7 @@ PUBLIC int AhlBindingInit() AFB_ERROR("Unable to create Active Stream List"); return AHL_FAIL; } - AFB_DEBUG("Audio high-level Binding success"); + AFB_DEBUG("Audio high-level binding initialization success"); return AHL_SUCCESS; } @@ -465,7 +466,7 @@ PUBLIC void audiohlapi_get_endpoints(struct afb_req req) RoleInfoT * pRole = GetRole(audioRole); if ( pRole == NULL ) { - afb_req_fail_f(req, "Invalid arguments", "Requested audio role does not exist in current configuration -> %s", json_object_get_string(queryJ)); + afb_req_fail_f(req, "Invalid arguments", "Requested audio role:%s does not exist in current configuration -> %s", audioRole, json_object_get_string(queryJ)); return; } else @@ -584,14 +585,14 @@ PUBLIC void audiohlapi_stream_open(struct afb_req req) err = StreamInfoToJSON(pStreamInfo,&pPolicyStreamJ); if (err) { - afb_req_fail(req, "Audio policy violation", "Unable to get JSON object for Policy_OpenStream"); + afb_req_fail(req, "Cannot convert stream info to JSON", "Unable to get JSON object for Policy_OpenStream"); return; } int policyAllowed = Policy_OpenStream(pPolicyStreamJ); if (policyAllowed == AHL_POLICY_REJECT) { - afb_req_fail(req, "Audio policy violation", "Open stream not allowed in current context"); + afb_req_fail_f(req, "Audio policy violation", "Open stream for role: %s on endpoint_id:%d not allowed in current context",pRole->pRoleName,pEndpointInfo->endpointID); return; } #endif @@ -602,13 +603,13 @@ PUBLIC void audiohlapi_stream_open(struct afb_req req) pStreamInfo->streamStateEvent = afb_daemon_make_event(streamEventName); err = !afb_event_is_valid(pStreamInfo->streamStateEvent); if (err) { - afb_req_fail(req, "Stream event creation failure", "Could not create stream specific state change event"); + afb_req_fail_f(req, "Stream event creation failure", "Could not create stream specific state change event: %s",streamEventName); return; } err = afb_req_subscribe(req,pStreamInfo->streamStateEvent); if (err) { - afb_req_fail(req, "Stream event subscription failure", "Could not subscribe to stream specific state change event"); + afb_req_fail_f(req, "Stream event subscription failure", "Could not subscribe to stream specific state change event for event name: %s",streamEventName); return; } @@ -641,11 +642,12 @@ PUBLIC void audiohlapi_stream_close(struct afb_req req) AHLClientCtxT * pClientCtx = afb_req_context_get(req); // Retrieve client-specific data structure if (pClientCtx == NULL) { - afb_req_fail(req, "Bad state", "No client context associated with the request (is there an opened stream by this client?)"); + afb_req_fail(req, "Missing client info context", "No client context associated with the request (is there an opened stream by this client?)"); return; } if (streamID == AHL_UNDEFINED) { + AFB_DEBUG("StreamID not specified. Closing all stream for client"); err = CloseAllClientStreams(pClientCtx,&req); if (err) { afb_req_fail(req, "Error closing streams", "Streams cannot close"); @@ -653,6 +655,7 @@ PUBLIC void audiohlapi_stream_close(struct afb_req req) } } else { + AFB_DEBUG("Closing streamID:%d",streamID); err = CloseStream(pClientCtx,streamID,&req); if (err) { afb_req_fail_f(req, "Error closing stream", "Specified stream cannot close stream_id -> %d",streamID); @@ -675,7 +678,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s int iStreamAccessControl = CheckStreamAccessControl( in_pClientCtx, streamID ); if (iStreamAccessControl == AHL_ACCESS_CONTROL_DENIED) { - afb_req_fail(*pReq, "Access control denied", "Set stream state not allowed in current client context"); + afb_req_fail_f(*pReq, "Access control denied", "Current client is not the owner of streamID:%d", streamID); return AHL_FAIL; } @@ -686,7 +689,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s int err = StreamInfoToJSON(pStreamInfo, &pPolicyStreamJ); if (err == AHL_POLICY_UTIL_FAIL) { - afb_req_fail(*pReq, "Audio policy violation", "Unable to get JSON object for Policy_SetStreamState"); + afb_req_fail_f(*pReq, "JSON packaging error", "Unable to create stream JSON object for Policy_SetStreamState for streamID:%d",streamID); return AHL_FAIL; } @@ -696,7 +699,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s int policyAllowed = Policy_SetStreamState(pPolicyStreamJ); if (policyAllowed == AHL_POLICY_REJECT) { - afb_req_fail(*pReq, "Audio policy violation", "Change stream state not allowed in current context"); + afb_req_fail_f(*pReq, "Audio policy violation", "Change stream state not allowed by policy in current context for streamID:%d",streamID); return AHL_FAIL; } #else @@ -710,7 +713,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s int err = StreamInfoToJSON(pStreamInfo, &pPolicyStreamJ); if (err == AHL_POLICY_UTIL_FAIL) { - afb_req_fail((*pReq), "Audio policy violation", "Unable to get JSON object for Policy_SetStreamMute"); + afb_req_fail_f((*pReq), "JSON packaging error", "Unable to create stream JSON object for Policy_SetStreamMute for streamID:%d",streamID); return AHL_FAIL; } @@ -720,7 +723,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s int policyAllowed = Policy_SetStreamMute(pPolicyStreamJ); if (policyAllowed == AHL_POLICY_REJECT) { - afb_req_fail(*pReq, "Audio policy violation", "Mute stream not allowed in current context"); + afb_req_fail_f(*pReq, "Audio policy violation", "Mute stream not allowed by policy in current context for streamID:%d",streamID); return AHL_FAIL; } #else @@ -749,7 +752,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s AHLClientCtxT * pClientCtx = afb_req_context_get(req); // Retrieve client-specific data structure if (pClientCtx == NULL) { - afb_req_fail(req, "Bad state", "No client context associated with the request (is there an opened stream by this client?)"); + afb_req_fail(req, "Missing client info context", "No client context associated with the request (is there an opened stream by this client?)"); return; } @@ -761,6 +764,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s streamID_t curStreamID = g_array_index(pClientCtx->pStreamAccessList,streamID_t,i); err = SetStreamState(pClientCtx,&req,curStreamID,streamStateStr,iMuteValue); if (err) { + // Error displayed within SetStreamState return; } } @@ -769,6 +773,7 @@ static int SetStreamState(AHLClientCtxT * in_pClientCtx,struct afb_req * pReq, s else { err = SetStreamState(pClientCtx,&req,streamID,streamStateStr,iMuteValue); if (err) { + // Error displayed within SetStreamState return; } } @@ -819,7 +824,7 @@ PUBLIC void audiohlapi_volume(struct afb_req req) EndpointInfoT * pEndpointInfo = GetEndpointInfo(endpointID,endpointType); if (pEndpointInfo == NULL) { - afb_req_fail_f(req, "Endpoint not found", "Endpoint information not found for id:%d type%d",endpointID,endpointType); + afb_req_fail_f(req, "Endpoint not found", "Endpoint information not found for endpoint_id:%d type:%d",endpointID,endpointType); return; } @@ -829,7 +834,7 @@ PUBLIC void audiohlapi_volume(struct afb_req req) err = EndpointInfoToJSON(pEndpointInfo, &pPolicyEndpointJ); if (err == AHL_POLICY_UTIL_FAIL) { - afb_req_fail(req, "Audio policy violation", "Unable to get JSON object for Policy_SetVolume"); + afb_req_fail_f(req, "JSON packaging error", "Unable to create endpoint JSON object for Policy_SetVolume for endpoint_id:%d type:%d",endpointID,endpointType); return; } @@ -840,13 +845,13 @@ PUBLIC void audiohlapi_volume(struct afb_req req) int policyAllowed = Policy_SetVolume(pPolicyEndpointJ,&pPolicyVolumeReply); if (!policyAllowed) { - afb_req_fail(req, "Audio policy violation", "Set volume not allowed in current context"); + afb_req_fail_f(req, "Audio policy violation", "Set volume not allowed by policy in current context for endpoint_id:%d type:%d",endpointID,endpointType); return; } err = wrap_json_unpack(pPolicyVolumeReply,"{s:i}","volume",&pEndpointInfo->iVolume); if (err) { - afb_req_fail_f(req, "Invalid policy reply", "Policy volume change reply not a valid json object=%s", json_object_get_string(pPolicyVolumeReply)); + afb_req_fail_f(req, "Invalid policy reply", "Policy volume change reply for endpoint_id:%d type:%d not a valid JSON object=%s", endpointID,endpointType,json_object_get_string(pPolicyVolumeReply)); return; } #else @@ -908,7 +913,7 @@ PUBLIC void audiohlapi_property(struct afb_req req) EndpointInfoT * pEndpointInfo = GetEndpointInfo(endpointID,endpointType); if (pEndpointInfo == NULL) { - afb_req_fail_f(req, "Endpoint not found", "Endpoint information not found for id:%d type%d",endpointID,endpointType); + afb_req_fail_f(req, "Endpoint not found", "Endpoint information not found for id:%d type:%d",endpointID,endpointType); return; } @@ -918,7 +923,7 @@ PUBLIC void audiohlapi_property(struct afb_req req) err = EndpointInfoToJSON(pEndpointInfo, &pPolicyEndpointJ); if (err == AHL_POLICY_UTIL_FAIL) { - afb_req_fail(req, "property fail", "Unable to get JSON object for Policy_SetProperty"); + afb_req_fail_f(req, "JSON packaging error", "Unable to create endpoint JSON object for Policy_SetProperty for endpoint_id:%d type:%d",endpointID,endpointType); return; } @@ -931,14 +936,14 @@ PUBLIC void audiohlapi_property(struct afb_req req) int policyAllowed = Policy_SetProperty(pPolicyEndpointJ,&pPropertyReply); if (!policyAllowed) { - afb_req_fail(req, "Policy Reject Set Property Control", "Policy Reject Set Property Control"); + afb_req_fail_f(req, "Policy violation", "Policy rejected set property control in current context for endpointID: %d type:%d",endpointID,endpointType); return; } json_object * pPropReplyValue = NULL; err = wrap_json_unpack(pPropertyReply,"{s:o}","value",&pPropReplyValue); if (err) { - afb_req_fail_f(req, "property fail", "Policy Property value not a valid json object=%s", json_object_get_string(pPropertyReply)); + afb_req_fail_f(req, "JSON parse error", "Policy returned property value for endpointID:%d type:%d not a valid JSON object=%s", endpointID,endpointType,json_object_get_string(pPropertyReply)); return; } if (pEndpointInfo->pPropTable && pPropReplyValue) { @@ -956,7 +961,7 @@ PUBLIC void audiohlapi_property(struct afb_req req) // Retrieve cached property value json_object * propertyValJ = (json_object *)g_hash_table_lookup(pEndpointInfo->pPropTable,propertyName); if (propertyValJ == NULL) { - afb_req_fail_f(req, "audiohlapi_property", "Property information not found: %s",propertyName); + afb_req_fail_f(req, "Property information not found", "Property information not found for property:%s endpointID:%d type:%d",propertyName,endpointID,endpointType); return; } @@ -1039,26 +1044,27 @@ PUBLIC void audiohlapi_post_action(struct afb_req req) } if (!iActionFound) { - afb_req_fail_f(req, "Event not found for audio role", "Event -> %s not found for role:%s",actionName,audioRole); + afb_req_fail_f(req, "Action not found for audio role", "Action -> %s not found for role:%s",actionName,audioRole); return; } -#ifndef AHL_DISCONNECT_POLICY - // Call policy to allow custom policy actions in current context (e.g. cancel playback) - json_object * pActionInfo = NULL; - err = wrap_json_pack(&pActionInfo, "{s:s,s:s,s?s,s?o}", "action_name", &actionName,"audio_role",&audioRole,"media_name",&mediaName,"action_context",&actionContext); - if (err) { - afb_req_fail_f(req, "Invalid arguments", "Could not create action JSON object arguments"); - return; - } - json_object_get(pActionInfo); - int policyAllowed = Policy_PostAction(pActionInfo); - if (!policyAllowed) - { - afb_req_fail(req, "Audio policy violation", "Post sound action not allowed in current context"); - return; - } -#endif + // Disable this to avoid problems (temporary solution) +// #ifndef AHL_DISCONNECT_POLICY +// // Call policy to allow custom policy actions in current context (e.g. cancel playback) +// json_object * pActionInfo = NULL; +// err = wrap_json_pack(&pActionInfo, "{s:s,s:s,s?s,s?o}", "action_name", &actionName,"audio_role",&audioRole,"media_name",&mediaName,"action_context",&actionContext); +// if (err) { +// afb_req_fail_f(req, "Invalid arguments", "Could not create action JSON object arguments"); +// return; +// } +// json_object_get(pActionInfo); +// int policyAllowed = Policy_PostAction(pActionInfo); +// if (!policyAllowed) +// { +// afb_req_fail_f(req, "Audio policy violation", "Post sound action not allowed by policy in current context for action:%s and audiorole:%s",actionName,audioRole); +// return; +// } +// #endif afb_req_success(req, NULL, "Posted sound action"); } @@ -1088,7 +1094,7 @@ PUBLIC void audiohlapi_event_subscription(struct afb_req req) json_object * jEvent = json_object_array_get_idx(eventArrayJ,i); pEventName = (char *)json_object_get_string(jEvent); if(pEventName == NULL) { - afb_req_fail(req, "failed", "Invalid event"); + afb_req_fail(req, "JSON arguments parse error", "Empty event"); return; } else if(!strcasecmp(pEventName, AHL_ENDPOINT_PROPERTY_EVENT)) { @@ -1110,7 +1116,7 @@ PUBLIC void audiohlapi_event_subscription(struct afb_req req) afb_req_unsubscribe(req, g_AHLCtx.policyCtx.postActionEvent); } else { - afb_req_fail(req, "failed", "Invalid event"); + afb_req_fail_f(req, "JSON arguments parse error", "Invalid event:%s",pEventName); return; } } @@ -1128,7 +1134,7 @@ PUBLIC void audiohlapi_raise_event(json_object * pEventDataJ) int err = wrap_json_unpack(pEventDataJ,"{s:s}","event_name", &pEventName); if(err) { - AFB_ERROR("Unable to retrieve event name"); + AFB_ERROR("Unable to retrieve event name %s",json_object_get_string(pEventDataJ)); return; } @@ -1146,7 +1152,7 @@ PUBLIC void audiohlapi_raise_event(json_object * pEventDataJ) "audio_role", &pAudioRole); if(err) { - AFB_ERROR("Unable to unpack property event"); + AFB_ERROR("Unable to unpack property event for event: %s",pEventName); return; } RoleInfoT * pRole = GetRole(pAudioRole); @@ -1170,7 +1176,7 @@ PUBLIC void audiohlapi_raise_event(json_object * pEventDataJ) g_hash_table_insert(pEndpointInfo->pPropTable, pPropertyName, json_object_new_string(json_object_get_string(propValueJ))); break; default: - AFB_ERROR("Invalid property argument Property value not a valid json object query=%s", json_object_get_string(propValueJ)); + AFB_ERROR("Invalid property argument property value not a valid JSON object query=%s", json_object_get_string(propValueJ)); return ; } } @@ -1226,7 +1232,7 @@ PUBLIC void audiohlapi_raise_event(json_object * pEventDataJ) "state_event", &streamEvent); if(err) { - AFB_ERROR("Unable to unpack stream event data"); + AFB_ERROR("Unable to unpack stream event data for event %s",pEventName); return; } @@ -1265,6 +1271,6 @@ PUBLIC void audiohlapi_raise_event(json_object * pEventDataJ) afb_event_push(pStreamInfo->streamStateEvent,pEventDataJ); } else { - AFB_ERROR("Unknown event name"); + AFB_ERROR("Unknown event name %s",pEventName); } }
\ No newline at end of file |