RDK Documentation (Open Sourced RDK Components)
request_handler.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 #include <stdlib.h>
21 #ifdef __cplusplus
22 extern "C"
23 {
24 #endif
25 #include <wdmp-c.h>
26 #ifdef __cplusplus
27 }
28 #endif
29 
30 #include "hostIf_main.h"
31 #include "hostIf_msgHandler.h"
32 #include "request_handler.h"
33 #include "waldb.h"
34 #include "XrdkCentralComRFCVar.h"
35 #include "hostIf_utils.h"
36 
37 #define MAX_NUM_PARAMETERS 2048
38 #define DEVICE_REBOOT_PARAM "Device.X_CISCO_COM_DeviceControl.RebootDevice"
39 
40 static DATA_TYPE getWdmpDataType(char *dmParamDataType)
41 {
42  DATA_TYPE wdmpDataType = WDMP_NONE;
43 
44  if(!strcmp(dmParamDataType, "string"))
45  wdmpDataType = WDMP_STRING;
46  else if(!strcmp(dmParamDataType, "boolean"))
47  wdmpDataType = WDMP_BOOLEAN;
48  else if(!strcmp(dmParamDataType, "unsignedInt"))
49  wdmpDataType = WDMP_UINT;
50  else if(!strcmp(dmParamDataType, "int"))
51  wdmpDataType = WDMP_INT;
52  else if(!strcmp(dmParamDataType, "unsignedLong"))
53  wdmpDataType = WDMP_ULONG;
54  else if(!strcmp(dmParamDataType, "dataTime"))
55  wdmpDataType = WDMP_DATETIME;
56  else
57  {
58  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Unknown data type identified...\n");
59  wdmpDataType = WDMP_NONE;
60  }
61  return wdmpDataType;
62 }
63 
64 static HostIf_ParamType_t getHostIfParamType(DATA_TYPE wdmpDataType)
65 {
66  HostIf_ParamType_t hostIfDataType = hostIf_StringType;
67 
68  switch(wdmpDataType)
69  {
70  case WDMP_STRING:
71  hostIfDataType = hostIf_StringType;
72  break;
73 
74  case WDMP_INT:
75  hostIfDataType = hostIf_IntegerType;
76  break;
77 
78  case WDMP_UINT:
79  case WDMP_ULONG:
80  hostIfDataType = hostIf_UnsignedIntType;
81  break;
82 
83  case WDMP_BOOLEAN:
84  hostIfDataType = hostIf_BooleanType;
85  break;
86 
87  case WDMP_DATETIME:
88  hostIfDataType = hostIf_DateTimeType;
89  break;
90 
91  case WDMP_BASE64:
92  case WDMP_LONG:
93  case WDMP_FLOAT:
94  case WDMP_DOUBLE:
95  case WDMP_BYTE:
96  default:
97  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"No matching hostif datatype - default to String\n");
98  break;
99  };
100  return hostIfDataType;
101 }
102 
103 static void convertAndAssignParamValue (HOSTIF_MsgData_t *param, char *value)
104 {
105  switch (param->paramtype)
106  {
107  case hostIf_StringType:
108  case hostIf_DateTimeType:
109  snprintf(param->paramValue,TR69HOSTIFMGR_MAX_PARAM_LEN, "%s", value);
110  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF, ">> Type: String/Date, Value = %s\n", param->paramValue);
111  break;
112  case hostIf_IntegerType:
113  case hostIf_UnsignedIntType:
114  {
115  int ivalue = atoi(value);
116  int *iptr = (int *)param->paramValue;
117  *iptr = ivalue;
118  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF, ">> Type: Integer/UnsignedInt, Value = %d\n", param->paramValue);
119  }
120  break;
121  case hostIf_UnsignedLongType:
122  {
123  long lvalue = atol(value);
124  long *lptr = (long *)param->paramValue;
125  *lptr = lvalue;
126  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF, ">> Type: UnsignedLong, Value = %ul\n", param->paramValue);
127  }
128  break;
129  case hostIf_BooleanType:
130  {
131  bool *bptr = (bool *)param->paramValue;
132  *bptr = (0 == strncasecmp(value, "TRUE", 4)|| (isdigit(value[0]) && value[0] != '0' ));
133  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF, ">> Type: Boolean, Value = %d\n", param->paramValue);
134  }
135  break;
136  default:
137  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF, ">> This path should never be reached. param type is %d\n", param->paramtype);
138  }
139 }
140 static char* getStringValue(HostIf_ParamType_t paramType, char *value)
141 {
142  char tempValue[TR69HOSTIFMGR_MAX_PARAM_LEN] = {'\0'};
143  switch (paramType)
144  {
145  case hostIf_StringType:
146  case hostIf_DateTimeType:
147  snprintf(tempValue,TR69HOSTIFMGR_MAX_PARAM_LEN, "%s", value);
148  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF, ">> String value of String = %s\n", tempValue);
149  break;
150  case hostIf_IntegerType:
151  case hostIf_UnsignedIntType:
152  {
153  snprintf(tempValue,TR69HOSTIFMGR_MAX_PARAM_LEN, "%d", *((int *)value));
154  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF, ">> String value of Integer/UnsignedInt = %s\n", tempValue);
155  }
156  break;
157  case hostIf_UnsignedLongType:
158  {
159  snprintf(tempValue,TR69HOSTIFMGR_MAX_PARAM_LEN, "%lu", *((unsigned long *)value));
160  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF, ">> String value of UnsignedLong = %s\n", tempValue);
161  }
162  break;
163  case hostIf_BooleanType:
164  {
165  if(*((bool*)value) == true)
166  strncpy(tempValue, "true", 4);
167  else
168  strncpy(tempValue, "false", 5);
169  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF, ">> String value of Boolean = %s\n", tempValue);
170  }
171  break;
172  default:
173  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF, ">> This path should never be reached. param type is %d\n", paramType);
174  }
175  return strdup(tempValue);
176 }
177 
178 static bool validateParamValue(const string &paramValue, HostIf_ParamType_t dataType)
179 {
180  bool ret = true;
181  size_t index = 0;
182  switch(dataType)
183  {
184  case hostIf_StringType:
185  case hostIf_DateTimeType:
186  if(paramValue.length() > TR69HOSTIFMGR_MAX_PARAM_LEN)
187  {
188  RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Parameter Value greater than allowed %d\n", TR69HOSTIFMGR_MAX_PARAM_LEN);
189  ret = false;
190  }
191  break;
192 
193  case hostIf_IntegerType:
194  if(isdigit(paramValue[0]) || (paramValue[0] == '-' && isdigit(paramValue[1])))
195  {
196  int value = stoi(paramValue, &index);
197  if(index != paramValue.length())
198  {
199  RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Invalid Parameter Value for an Integer Type\n");
200  ret = false;
201  }
202  }
203  else
204  {
205  ret = false;
206  }
207  break;
208 
209  case hostIf_UnsignedIntType:
210  case hostIf_UnsignedLongType:
211  if(isdigit(paramValue[0]))
212  {
213  unsigned long value = stoul(paramValue, &index);
214  if(index != paramValue.length())
215  {
216  RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Invalid Parameter Value for an UnsignedInt or UnsignedLong Type\n");
217  ret = false;
218  }
219  }
220  else
221  {
222  ret = false;
223  }
224  break;
225 
226  case hostIf_BooleanType:
227  if(!strcasecmp(paramValue.c_str(), "true")
228  || !strcasecmp(paramValue.c_str(), "false")
229  || !strcmp(paramValue.c_str(), "1")
230  || !strcmp(paramValue.c_str(), "0"))
231  {
232  RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Valid Boolean Value\n");
233  }
234  else
235  {
236  RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Invalid Parameter Value for a Boolean\n");
237  ret = false;
238  }
239  break;
240 
241  default:
242  RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF, "Unknown Data Type\n");
243  ret = false;
244  break;
245  };
246 
247  return ret;
248 }
249 
250 static void getHostIfParamStFromRequest(REQ_TYPE reqType, param_t *param, HOSTIF_MsgData_t *hostIfParam)
251 {
252  strncpy(hostIfParam->paramName, param->name, strlen(param->name));
253  hostIfParam->paramName[strlen(param->name)] = '\0';
254 
255  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Entering %s\n", __FUNCTION__);
256  switch(reqType)
257  {
258  case GET:
259  hostIfParam->reqType = HOSTIF_GET;
260  hostIfParam->paramtype = getHostIfParamType(param->type);
261  break;
262 
263  case SET:
264  hostIfParam->reqType = HOSTIF_SET;
265  hostIfParam->paramtype = getHostIfParamType(param->type);
266  convertAndAssignParamValue(hostIfParam, param->value);
267  break;
268 
269  default:
270  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s : Operation not handled : Shouldn't come here\n", __FUNCTION__);
271  break;
272  };
273 
274  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Leaving %s\n", __FUNCTION__);
275 }
276 
277 static WDMP_STATUS handleRFCRequest(REQ_TYPE reqType, param_t *param)
278 {
279  WDMP_STATUS wdmpStatus = WDMP_SUCCESS;
280 
281  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Entering %s\n", __FUNCTION__);
282 
283  switch(reqType)
284  {
285  case GET:
286  param->value = strdup(XRFCVarStore::getInstance()->getValue(param->name).c_str());
287  if(strlen(param->value) == 0)
288  wdmpStatus = WDMP_ERR_VALUE_IS_NULL;
289  break;
290 
291  case SET:
292  if(!strcmp(param->name, XRFC_VAR_STORE_RELOADCACHE) && (!strcasecmp(param->value, "true") || !strcmp(param->value, "1")))
293  XRFCVarStore::getInstance()->reloadCache();
294  else
295  {
296  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"SET operation not supported\n");
297  wdmpStatus = WDMP_ERR_METHOD_NOT_SUPPORTED;
298  }
299  break;
300 
301  default:
302  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s : Invalid operation - Not Supported\n", __FUNCTION__);
303  };
304  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Leaving %s\n", __FUNCTION__);
305  return wdmpStatus;
306 }
307 
308 static WDMP_STATUS invokeHostIfAPI(REQ_TYPE reqType, param_t *param, HostIf_Source_Type_t bsUpdate, const char *pcCallerID)
309 {
310  WDMP_STATUS wdmpStatus = WDMP_SUCCESS;
311  int result = NOK;
312  HOSTIF_MsgData_t hostIfParam;
313  memset(&hostIfParam,0,sizeof(HOSTIF_MsgData_t));
314  if (strcmp(pcCallerID, "rfc") == 0)
315  hostIfParam.requestor = HOSTIF_SRC_RFC;
316  else
317  hostIfParam.requestor = HOSTIF_SRC_WEBPA;
318  hostIfParam.bsUpdate = bsUpdate;
319  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Entering %s\n", __FUNCTION__);
320 
321  getHostIfParamStFromRequest(reqType, param, &hostIfParam);
322 
323  switch(reqType)
324  {
325  case GET:
326  result = hostIf_GetMsgHandler(&hostIfParam);
327  break;
328 
329  case SET:
330  if(!validateParamValue(param->value, getHostIfParamType(param->type)))
331  {
332  result = fcInvalidParameterValue;
333  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Invalid Parameter Value\n");
334  }
335  else
336  result = hostIf_SetMsgHandler(&hostIfParam);
337  break;
338 
339  default:
340  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s : Invalid operation - Not Supported\n", __FUNCTION__);
341  };
342 
343  if(result == OK)
344  {
345  if(hostIfParam.faultCode == fcNoFault)
346  {
347  param->value = getStringValue(hostIfParam.paramtype, hostIfParam.paramValue);
348  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"The value for param: %s = %s\n", hostIfParam.paramName, param->value);
349  }
350  else
351  {
352  param->value = strdup("");
353  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error in HostIf : %d\n", hostIfParam.faultCode);
354  wdmpStatus = WDMP_FAILURE;
355  }
356  }
357  else
358  {
359  param->value = strdup("");
360  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Failed in hostIf_msgHandler, with return value: %d\n", result);
361  if(result == fcInvalidParameterValue)
362  wdmpStatus = WDMP_ERR_INVALID_PARAMETER_VALUE;
363  else
364  wdmpStatus = WDMP_ERR_INTERNAL_ERROR;
365  }
366 
367  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Leaving %s\n", __FUNCTION__);
368  return wdmpStatus;
369 }
370 
371 static WDMP_STATUS validateAgainstDataModel(REQ_TYPE reqType, char* paramName, const char* paramValue, DATA_TYPE *dataType, char **defaultValue, HostIf_Source_Type_t *bsUpdate)
372 {
373  DataModelParam dmParam = {0};
374  WDMP_STATUS ret = WDMP_SUCCESS;
375 
376  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Entering... %s\n", __FUNCTION__);
377 
378  const char* dbParamName = paramName;
379  if(!getParamInfoFromDataModel(getDataModelHandle(), dbParamName, &dmParam))
380  {
381  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Invalid parameter name %s: doesn't exist in data-model\n", paramName);
382  return WDMP_ERR_INVALID_PARAMETER_NAME;
383  }
384  *bsUpdate = getBSUpdateEnum(dmParam.bsUpdate);
385  if(reqType == GET)
386  {
387  if(dmParam.dataType != NULL)
388  {
389  *dataType = getWdmpDataType(dmParam.dataType); //CID:89885 - FORWARD NULL
390  }
391  if(dmParam.defaultValue)
392  *defaultValue = strdup(dmParam.defaultValue);
393  }
394  else if(reqType == SET)
395  {
396  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Validating paramValue and dataType against data-model\n");
397  if(paramValue == NULL || *dataType >= WDMP_NONE)
398  {
399  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"ParameterValue is NULL or Unknown Datatype\n");
400  ret = WDMP_ERR_VALUE_IS_NULL;
401  }
402  else if(dmParam.access != NULL && !strcasecmp(dmParam.access, "readOnly"))
403  {
404  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Parameter is readOnly\n");
405  ret = WDMP_ERR_NOT_WRITABLE;
406  }
407  else if (getWdmpDataType(dmParam.dataType) != *dataType)
408  {
409  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Datatype doesn't match\n");
410  ret = WDMP_ERR_INVALID_PARAMETER_TYPE;
411  }
412  }
413  else
414  {
415  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s : Invalid operation - Not Supported\n", __FUNCTION__);
416  ret = WDMP_FAILURE;
417  }
418 
419  if(dmParam.objectName)
420  free(dmParam.objectName);
421  if(dmParam.paramName)
422  free(dmParam.paramName);
423  if(dmParam.bsUpdate)
424  free(dmParam.bsUpdate);
425  if(dmParam.access)
426  free(dmParam.access);
427  if(dmParam.dataType)
428  free(dmParam.dataType);
429  if(dmParam.defaultValue)
430  free(dmParam.defaultValue);
431 
432  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Leaving... %s\n", __FUNCTION__);
433  return ret;
434 }
435 
436 static void freeParam(param_t *param)
437 {
438  if(param)
439  {
440  free(param->name);
441  free(param->value);
442  free(param);
443  }
444 }
445 
446 static bool isAuthorized(const char* pcCallerID, const char* pcParamName)
447 {
448  if(!strcmp(pcParamName, DEVICE_REBOOT_PARAM))
449  {
450  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"%s : Invalid operation - Device Reboot Not Allowed Using tr181 command/RFC API\n", __FUNCTION__);
451  return false;
452  }
453  else
454  return true;
455 }
456 
457 static bool allocate_res_struct_members(res_struct *respSt, req_struct *reqSt)
458 {
459  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Entering... %s\n", __FUNCTION__);
460  respSt->reqType = reqSt->reqType;
461  respSt->timeSpan = NULL;
462  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Allocating res_struct for reqType : ... %d\n", reqSt->reqType);
463  switch(reqSt->reqType)
464  {
465  case GET:
466  if(reqSt->u.getReq->paramCnt == 0)
467  return false;
468 
469  respSt->paramCnt = reqSt->u.getReq->paramCnt;
470  respSt->retStatus = (WDMP_STATUS *)calloc(respSt->paramCnt, sizeof(WDMP_STATUS));
471  respSt->u.getRes = (get_res_t *)malloc(sizeof(get_res_t));
472  if(respSt->u.getRes != NULL && respSt->retStatus != NULL)
473  {
474  memset(respSt->u.getRes, 0, sizeof(get_res_t));
475 
476  respSt->u.getRes->paramCnt = reqSt->u.getReq->paramCnt;
477  respSt->u.getRes->paramNames = (char **)malloc(sizeof(char *) * (reqSt->u.getReq->paramCnt));
478  respSt->u.getRes->params = (param_t **)malloc(sizeof(param_t *) * reqSt->u.getReq->paramCnt);
479  respSt->u.getRes->retParamCnt = (size_t *)malloc(sizeof(size_t) * reqSt->u.getReq->paramCnt);
480 
481  if(respSt->u.getRes->paramNames == NULL || respSt->u.getRes->params == NULL || respSt->u.getRes->retParamCnt == NULL)
482  {
483  if(respSt->u.getRes->paramNames) free(respSt->u.getRes->paramNames);
484  if(respSt->u.getRes->params) free(respSt->u.getRes->params);
485  if(respSt->u.getRes->retParamCnt) free(respSt->u.getRes->retParamCnt);
486  free(respSt);
487  return false;
488  }
489  else
490  {
491  memset(respSt->u.getRes->paramNames, 0, sizeof(char *) * reqSt->u.getReq->paramCnt);
492  memset(respSt->u.getRes->params, 0, sizeof(param_t *) * reqSt->u.getReq->paramCnt);
493  memset(respSt->u.getRes->retParamCnt, 0, sizeof(size_t) * reqSt->u.getReq->paramCnt);
494  }
495  }
496  else
497  {
498 
499  return false;
500  }
501  break;
502 
503  case SET:
504  if(reqSt->u.setReq->paramCnt == 0)
505  return false;
506 
507  respSt->paramCnt = reqSt->u.setReq->paramCnt;
508  respSt->retStatus = (WDMP_STATUS *)calloc(respSt->paramCnt, sizeof(WDMP_STATUS));
509  respSt->u.paramRes = (param_res_t *)malloc(sizeof(param_res_t));
510  if(respSt->u.paramRes != NULL)
511  {
512  memset(respSt->u.paramRes, 0, sizeof(param_res_t));
513 
514  respSt->u.paramRes->params = (param_t *)malloc(sizeof(param_t) * reqSt->u.setReq->paramCnt);
515  if(respSt->u.paramRes->params == NULL)
516  {
517  free(respSt->u.paramRes);
518  return false;
519  }
520  else
521  {
522  memset(respSt->u.paramRes->params, 0, sizeof(param_t) * reqSt->u.setReq->paramCnt);
523  }
524  }
525  break;
526  default:
527  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s : Invalid Request Type\n", __FUNCTION__);
528  return false;
529  };
530  return true;
531 }
532 
533 res_struct* handleRequest(const char* pcCallerID, req_struct *reqSt)
534 {
535  unsigned int paramIndex = 0;
536  res_struct *respSt = NULL;
537  DATA_TYPE dataType = WDMP_NONE;
538 
539  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Entering... %s\n", __FUNCTION__);
540  respSt = (res_struct *) malloc(sizeof(res_struct));
541  if(respSt == NULL)
542  {
543  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Failed to allocate respSt - returning\n");
544  return NULL;
545  }
546  memset(respSt, 0, sizeof(res_struct));
547  if(!allocate_res_struct_members(respSt, reqSt))
548  {
549  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Failed to allocate respSt members\n");
550  wdmp_free_res_struct(respSt);
551  respSt = NULL;
552  return NULL;
553  }
554 
555  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"processing each paramName ... with reqType - %d\n", respSt->reqType);
556 
557  switch(respSt->reqType)
558  {
559  case GET:
560  for(paramIndex = 0; paramIndex < respSt->paramCnt; paramIndex++)
561  {
562  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Request:> paramNames[%d] = %s\n",paramIndex,reqSt->u.getReq->paramNames[paramIndex]);
563  respSt->u.getRes->paramNames[paramIndex] = strdup(reqSt->u.getReq->paramNames[paramIndex]);
564 
565  if(strlen(respSt->u.getRes->paramNames[paramIndex]) > MAX_PARAMETERNAME_LEN)
566  {
567  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"paramName > MAX_PARAMETERNAME_LEN for : %s\n", reqSt->u.getReq->paramNames[paramIndex]);
568  respSt->u.getRes->retParamCnt[paramIndex] = 1;
569  respSt->u.getRes->params[paramIndex] = (param_t *)malloc(sizeof(param_t) * respSt->u.getRes->retParamCnt[paramIndex]);
570  respSt->u.getRes->params[paramIndex][0].name = strdup(respSt->u.getRes->paramNames[paramIndex]);
571  respSt->u.getRes->params[paramIndex][0].value = NULL;
572  respSt->u.getRes->params[paramIndex][0].type = WDMP_NONE;
573 
574  respSt->retStatus[paramIndex] = WDMP_ERR_INVALID_PARAMETER_NAME;
575  continue;
576  }
577 
578  if(isWildCardParam(respSt->u.getRes->paramNames[paramIndex]))
579  {
580  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s is a WildCardParam \n", respSt->u.getRes->paramNames[paramIndex]);
581  char **childParamNames = (char**) calloc (MAX_NUM_PARAMETERS, sizeof(char*));
582  if (NULL == childParamNames)
583  {
584  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error allocating memory\n");
585  wdmp_free_res_struct(respSt);
586  respSt = NULL;
587  return respSt;
588  }
589  char **childParamDataTypes = (char**) calloc (MAX_NUM_PARAMETERS, sizeof(char*));
590  if(NULL == childParamDataTypes)
591  {
592  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error allocating memory\n");
593  free(childParamNames);
594  wdmp_free_res_struct(respSt);
595  respSt = NULL;
596  return respSt;
597  }
598  param_t *childParams = NULL;
599 
600  if(DB_SUCCESS == getChildParamNamesFromDataModel(getDataModelHandle(), respSt->u.getRes->paramNames[paramIndex], childParamNames, childParamDataTypes, (int *)&respSt->u.getRes->retParamCnt[paramIndex]))
601  {
602  childParams = (param_t *)malloc(sizeof(param_t) * (int) respSt->u.getRes->retParamCnt[paramIndex]);
603  respSt->retStatus[paramIndex] = WDMP_SUCCESS;
604 
605  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"No of child params = %d\n", respSt->u.getRes->retParamCnt[paramIndex]);
606  for(int childParamIndex = 0; childParamIndex < (int)respSt->u.getRes->retParamCnt[paramIndex]; childParamIndex++)
607  {
608  childParams[childParamIndex].name = childParamNames[childParamIndex];
609  childParams[childParamIndex].type = getWdmpDataType(childParamDataTypes[childParamIndex]);
610  childParams[childParamIndex].value = NULL;
611 
612  //retStatus represents the first error while trying to retrieve the values of a wild card parameter name.
613  if(WDMP_SUCCESS != invokeHostIfAPI(reqSt->reqType, childParams+childParamIndex, HOSTIF_NONE, pcCallerID) && respSt->retStatus[paramIndex] == WDMP_SUCCESS)
614  {
615  respSt->retStatus[paramIndex] = WDMP_ERR_VALUE_IS_EMPTY;
616  }
617  }
618  respSt->u.getRes->params[paramIndex] = childParams;
619  }
620  else
621  {
622  free(childParamDataTypes);
623  free(childParamNames);
624 
625  respSt->u.getRes->retParamCnt[paramIndex] = 1;
626  respSt->u.getRes->params[paramIndex] = (param_t *)malloc(sizeof(param_t) * respSt->u.getRes->retParamCnt[paramIndex]);
627 
628  respSt->u.getRes->params[paramIndex][0].name = strdup(respSt->u.getRes->paramNames[paramIndex]);
629  respSt->u.getRes->params[paramIndex][0].value = strdup("");
630  respSt->u.getRes->params[paramIndex][0].type = WDMP_NONE;
631  respSt->retStatus[paramIndex] = WDMP_ERR_INVALID_PARAMETER_NAME;
632  }
633  }
634  else
635  {
636  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Not a wildcard param - validating against data model...\n");
637  char *defaultValue = NULL;
638  bool rfcParam = false;
639  HostIf_Source_Type_t bsUpdate = HOSTIF_NONE;
640 
641  // Temporary handling for RFC Variables - Which are not validated against data-model.xml
642  if(strncmp(respSt->u.getRes->paramNames[paramIndex], "RFC_", 4) == 0 && strchr(respSt->u.getRes->paramNames[paramIndex], '.') == NULL)
643  {
644  dataType = WDMP_STRING;
645  rfcParam = true;
646  respSt->retStatus[paramIndex] = WDMP_SUCCESS;
647  }
648  else
649  {
650  respSt->retStatus[paramIndex] = validateAgainstDataModel(respSt->reqType, respSt->u.getRes->paramNames[paramIndex], NULL, &dataType, &defaultValue, &bsUpdate);
651  }
652 
653  respSt->u.getRes->retParamCnt[paramIndex] = 1;
654  respSt->u.getRes->params[paramIndex] = (param_t *)malloc(sizeof(param_t) * respSt->u.getRes->retParamCnt[paramIndex]);
655 
656  respSt->u.getRes->params[paramIndex][0].name = strdup(respSt->u.getRes->paramNames[paramIndex]);
657  respSt->u.getRes->params[paramIndex][0].value = NULL;
658  respSt->u.getRes->params[paramIndex][0].type = dataType;
659 
660  if(WDMP_SUCCESS == respSt->retStatus[paramIndex])
661  {
662  if(!rfcParam)
663  respSt->retStatus[paramIndex] = invokeHostIfAPI(reqSt->reqType, respSt->u.getRes->params[paramIndex], bsUpdate, pcCallerID);
664  else // Temporary handling for RFC Variables - handled using RFC API.
665  respSt->retStatus[paramIndex] = handleRFCRequest(reqSt->reqType, respSt->u.getRes->params[paramIndex]);
666 
667  if(respSt->retStatus[paramIndex] != WDMP_SUCCESS)
668  {
669  if(defaultValue)
670  {
671  respSt->u.getRes->params[paramIndex][0].value = strdup(defaultValue);
672  respSt->retStatus[paramIndex] = WDMP_ERR_DEFAULT_VALUE;
673  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Setting Default Value : %s\n", respSt->u.getRes->params[paramIndex][0].value);
674  }
675  else
676  {
677  respSt->retStatus[paramIndex] = WDMP_ERR_VALUE_IS_EMPTY;
678  }
679  }
680  }
681  else
682  {
683  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Failed in data-model validation\n");
684  respSt->u.getRes->params[paramIndex][0].value = strdup("");
685  }
686  if(defaultValue)
687  free(defaultValue);
688  }
689  }
690  break;
691 
692  case SET:
693  for(paramIndex = 0; paramIndex < respSt->paramCnt; paramIndex++)
694  {
695  bool rfcParam = false;
696 
697  respSt->u.paramRes->params[paramIndex].name = strdup(reqSt->u.setReq->param[paramIndex].name);
698  if(!isAuthorized(pcCallerID, reqSt->u.setReq->param[paramIndex].name))
699  {
700  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"CallerID : %s is not allowed to SET : %s\n", pcCallerID, reqSt->u.setReq->param[paramIndex].name);
701  respSt->retStatus[paramIndex] = WDMP_FAILURE;
702  continue;
703  }
704  else if(isWildCardParam(reqSt->u.setReq->param[paramIndex].name))
705  {
706  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Wildcard SET/SET-ATTRIBUTES is not supported \n");
707  respSt->retStatus[paramIndex] = WDMP_ERR_WILDCARD_NOT_SUPPORTED;
708  continue;
709  }
710  else if(reqSt->u.setReq->param[paramIndex].value == NULL)
711  {
712  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Parameter value is null\n");
713  respSt->retStatus[paramIndex] = WDMP_ERR_VALUE_IS_NULL;
714  continue;
715  }
716  else
717  {
718  respSt->u.paramRes->params[paramIndex].value = strdup(reqSt->u.setReq->param[paramIndex].value);
719  }
720 
721  // Temporary handling for RFC Variables - Which are not validated against data-model.xml
722  if(strncmp(reqSt->u.setReq->param[paramIndex].name, "RFC_", 4) == 0 && strchr(reqSt->u.setReq->param[paramIndex].name, '.') == NULL)
723  {
724  dataType = WDMP_STRING;
725  rfcParam = true;
726  respSt->retStatus[paramIndex] = handleRFCRequest(reqSt->reqType, reqSt->u.setReq->param + paramIndex);
727  }
728  else
729  {
730  HostIf_Source_Type_t bsUpdate = HOSTIF_NONE;
731  respSt->retStatus[paramIndex] = validateAgainstDataModel(reqSt->reqType, reqSt->u.setReq->param[paramIndex].name, reqSt->u.setReq->param[paramIndex].value, &reqSt->u.setReq->param[paramIndex].type, NULL, &bsUpdate);
732  if(WDMP_SUCCESS != respSt->retStatus[paramIndex])
733  {
734  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Operation not permitted : %d\n", respSt->retStatus[paramIndex]);
735  continue;
736  }
737  respSt->retStatus[paramIndex] = invokeHostIfAPI(reqSt->reqType, reqSt->u.setReq->param + paramIndex, bsUpdate, pcCallerID);
738  }
739  }
740  break;
741 
742  default:
743  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Invalid operation type : %d\n", reqSt->reqType);
744  wdmp_free_res_struct(respSt);
745  respSt = NULL;
746  };
747 
748  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"Leaving... %s\n", __FUNCTION__);
749  return respSt;
750 }
request_handler.h
API to handle single multiple and wild card parameters in HTTP JSON Interface.
__DataModelParam
Definition: waldb.h:39
_HostIf_MsgData_t::reqType
HostIf_ReqType_t reqType
Definition: hostIf_tr69ReqHandler.h:178
_HostIf_MsgData_t::bsUpdate
HostIf_Source_Type_t bsUpdate
Definition: hostIf_tr69ReqHandler.h:181
HostIf_Source_Type_t
enum _HostIf_Source_Type_t HostIf_Source_Type_t
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_main.h
hostIf_main API.
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
HostIf_ParamType_t
enum _HostIf_ParamType HostIf_ParamType_t
_HostIf_MsgData_t::faultCode
faultCode_t faultCode
Definition: hostIf_tr69ReqHandler.h:179
_HostIf_MsgData_t::paramName
char paramName[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:171
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
isWildCardParam
int isWildCardParam(const char *paramName)
Check if Parameter Name ends with . If yes it is a wild card param.
Definition: webpa_parameter.cpp:732
hostIf_msgHandler.h
The header file provides HostIf message handler information APIs.
_HostIf_MsgData_t::requestor
HostIf_Source_Type_t requestor
Definition: hostIf_tr69ReqHandler.h:180