summaryrefslogtreecommitdiffstats
path: root/src/ahl-policy-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ahl-policy-utils.c')
-rw-r--r--src/ahl-policy-utils.c94
1 files changed, 15 insertions, 79 deletions
diff --git a/src/ahl-policy-utils.c b/src/ahl-policy-utils.c
index 52c5862..60ddd36 100644
--- a/src/ahl-policy-utils.c
+++ b/src/ahl-policy-utils.c
@@ -38,76 +38,12 @@ void Add_Endpoint_Property_String( EndpointInfoT * io_pEndpointInfo, char * in_p
g_hash_table_insert(io_pEndpointInfo->pPropTable, in_pPropertyName, propValueJ);
}
-int PolicyCtxStructToJSON(AHLPolicyCtxT * pPolicyCtx, json_object **ppPolicyCxtJ)
-{
- if(pPolicyCtx == NULL)
- {
- AFB_ERROR("Policy context is NULL");
- return AHL_FAIL;
- }
-
- //Create json object for HALList
- json_object *HallListJ = json_object_new_array();
- for(int i=0; i<pPolicyCtx->pHALList->len; i++)
- {
- char *hallname = g_ptr_array_index(pPolicyCtx->pHALList, i);
- json_object *hallNameJ = json_object_new_string(hallname);
- json_object_array_add(HallListJ, hallNameJ);
- }
-
- int err = wrap_json_pack(ppPolicyCxtJ, "{s:i,s:o}",
- "number_roles", (int)g_hash_table_size(pPolicyCtx->pRoleInfo),
- "halllist", HallListJ);
- if (err) {
- AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(err));
- }
-
- return AHL_SUCCESS;
-}
-
-
- int PolicyCtxJSONToStruct(json_object *CtxJ, int *pNbAudioRole, GPtrArray *pHALList)
-{
- if(CtxJ == NULL || pHALList == NULL)
- {
- AFB_ERROR("Invalid arguments to PolicyCtxJSONToStruct");
- return AHL_FAIL;
- }
-
- json_object *HallListJ = NULL;
- int err = wrap_json_unpack(CtxJ, "{s:i, s:o}",
- "number_roles", &pNbAudioRole,
- "halllist", &HallListJ);
- if (err) {
- AFB_ERROR("Unable to unpack JSON endpoint, =%s", wrap_json_get_error_string(err));
- return AHL_FAIL;
- }
-
- if(HallListJ)
- {
- int nbHall = json_object_array_length(HallListJ);
- //Create HallList
- for(int i=0; i<nbHall; i++)
- {
- char * pHAL = NULL;
- json_object * jHAL = json_object_array_get_idx(HallListJ,i);
- if (jHAL) {
- pHAL = (char *)json_object_get_string(jHAL);
- char * pHALName = g_strdup( pHAL );
- g_ptr_array_add( pHALList, pHALName );
- }
- }
- }
-
- return AHL_SUCCESS;
-}
-
int PolicyEndpointStructToJSON(EndpointInfoT * pEndpointInfo, json_object **ppPolicyEndpointJ)
{
if(pEndpointInfo == NULL || pEndpointInfo->pPropTable == NULL)
{
AFB_ERROR("Invalid PolicyEndpointStructToJSON arguments");
- return AHL_FAIL;
+ return AHL_POLICY_UTIL_FAIL;
}
//Create json object for PropTable
@@ -126,7 +62,7 @@ int PolicyEndpointStructToJSON(EndpointInfoT * pEndpointInfo, json_object **ppPo
if(error)
{
AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(error));
- return AHL_FAIL;
+ return AHL_POLICY_UTIL_FAIL;
}
json_object_array_add(pPropTableJ, pPropertyJ);
}
@@ -155,10 +91,10 @@ int PolicyEndpointStructToJSON(EndpointInfoT * pEndpointInfo, json_object **ppPo
);
if (err) {
AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(err));
- return AHL_FAIL;
+ return AHL_POLICY_UTIL_FAIL;
}
AFB_DEBUG("JSON endpoint information=%s", json_object_get_string(*ppPolicyEndpointJ));
- return AHL_SUCCESS;
+ return AHL_POLICY_UTIL_SUCCESS;
}
int PolicyStreamStructToJSON(StreamInfoT * pPolicyStream, json_object **ppPolicyStreamJ)
@@ -166,7 +102,7 @@ int PolicyStreamStructToJSON(StreamInfoT * pPolicyStream, json_object **ppPolicy
if(pPolicyStream == NULL)
{
AFB_ERROR("Invalid arguments to PolicyStreamStructToJSON");
- return AHL_FAIL;
+ return AHL_POLICY_UTIL_FAIL;
}
json_object * pEndpointJ = NULL;
@@ -189,12 +125,12 @@ int PolicyStreamStructToJSON(StreamInfoT * pPolicyStream, json_object **ppPolicy
);
if (err) {
AFB_ERROR("Unable to pack JSON endpoint, =%s", wrap_json_get_error_string(err));
- return AHL_FAIL;
+ return AHL_POLICY_UTIL_FAIL;
}
AFB_DEBUG("JSON stream information=%s", json_object_get_string(*ppPolicyStreamJ));
- return AHL_SUCCESS;
+ return AHL_POLICY_UTIL_SUCCESS;
}
int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pEndpointInfo)
@@ -202,7 +138,7 @@ int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pEndpointIn
if(pEndpointJ == NULL || pEndpointInfo == NULL /*|| pEndpointInfo->pPropTable == NULL */ )
{
AFB_ERROR("Invalid arguments for PolicyCtxJSONToEndpoint");
- return AHL_FAIL;
+ return AHL_POLICY_UTIL_FAIL;
}
//Unpack Endpoint
@@ -228,7 +164,7 @@ int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pEndpointIn
);
if (err) {
AFB_ERROR("Unable to unpack JSON endpoint, =%s", wrap_json_get_error_string(err));
- return AHL_FAIL;
+ return AHL_POLICY_UTIL_FAIL;
}
// Unpack prop table
@@ -249,7 +185,7 @@ int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pEndpointIn
"property_value", &pPropertyValueJ);
if (err) {
AFB_ERROR("Unable to unpack JSON endpoint, = %s", wrap_json_get_error_string(err));
- return AHL_FAIL;
+ return AHL_POLICY_UTIL_FAIL;
}
// Object type detection for property value (string = state, numeric = property)
@@ -266,13 +202,13 @@ int PolicyCtxJSONToEndpoint(json_object *pEndpointJ, EndpointInfoT * pEndpointIn
break;
default:
AFB_ERROR("Invalid property argument Property value not a valid json object query=%s", json_object_get_string(pPropertyValueJ));
- return AHL_FAIL;
+ return AHL_POLICY_UTIL_FAIL;
}
}
}
}
- return AHL_SUCCESS;
+ return AHL_POLICY_UTIL_SUCCESS;
}
int PolicyCtxJSONToStream(json_object *pStreamJ, StreamInfoT * pPolicyStream)
@@ -280,7 +216,7 @@ int PolicyCtxJSONToStream(json_object *pStreamJ, StreamInfoT * pPolicyStream)
if(pStreamJ == NULL || pPolicyStream == NULL)
{
AFB_ERROR("Invalid arguments for PolicyCtxJSONToStream");
- return AHL_FAIL;
+ return AHL_POLICY_UTIL_FAIL;
}
//Unpack StreamInfo
@@ -300,13 +236,13 @@ int PolicyCtxJSONToStream(json_object *pStreamJ, StreamInfoT * pPolicyStream)
if (err) {
AFB_ERROR("Unable to parse JSON stream information=%s", json_object_get_string(pStreamJ));
- return AHL_FAIL;
+ return AHL_POLICY_UTIL_FAIL;
}
int iRet = PolicyCtxJSONToEndpoint(pEndpointJ,pPolicyStream->pEndpointInfo);
if (iRet) {
return iRet;
}
- return AHL_SUCCESS;
+ return AHL_POLICY_UTIL_SUCCESS;
}
\ No newline at end of file