33 #include "hostIf_utils.h"
35 #include "safec_lib.h"
37 #define NTPSTATUS_NAME_FILE "/tmp/ntp_status"
38 #define NTPENABLED_FILE "/opt/.ntpEnabled"
41 updateCallback TimeClientReqHandler::mUpdateCallback = NULL;
42 msgHandler* TimeClientReqHandler::getInstance()
61 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
62 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
77 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
79 hostIf_Time::closeAllInstances();
81 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
99 int ret = NOT_HANDLED;
100 const char *pSetting;
101 int instanceNumber = 0;
102 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s:%d] Found string as %s\n", __FUNCTION__, __FILE__, __LINE__, stMsgData->
paramName);
103 if(strncasecmp(stMsgData->
paramName,
"Device.Time",strlen(
"Device.Time"))==0)
106 hostIf_Time::getLock();
108 hostIf_Time *pIface = hostIf_Time::getInstance(instanceNumber);
112 hostIf_Time::releaseLock();
116 if (stMsgData->
bsUpdate != HOSTIF_NONE)
118 if ( (stMsgData->
bsUpdate == HOSTIF_SRC_RFC && stMsgData->
requestor == HOSTIF_SRC_RFC) ||
119 (stMsgData->
bsUpdate == HOSTIF_SRC_ALL && (stMsgData->
requestor == HOSTIF_SRC_RFC || stMsgData->
requestor == HOSTIF_SRC_WEBPA)) )
124 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s()] Not setting the bootstrap param:%s [bsUpdate=%d, requestor=%d]\n", __FUNCTION__, stMsgData->
paramName, stMsgData->
bsUpdate, stMsgData->
requestor);
127 else if (strcasecmp(stMsgData->
paramName,
"Device.Time.Enable") == 0)
133 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s:%d] parameter : \'%s\' Not handled \n", __FUNCTION__, __FILE__, __LINE__, stMsgData->
paramName);
134 stMsgData->
faultCode = fcInvalidParameterName;
137 hostIf_Time::releaseLock();
156 int ret = NOT_HANDLED;
157 const char *pSetting;
158 int instanceNumber = 0;
159 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s:%d] Found string as %s\n", __FUNCTION__, __FILE__, __LINE__, stMsgData->
paramName);
161 if(strncasecmp(stMsgData->
paramName,
"Device.Time",strlen(
"Device.Time"))==0)
164 hostIf_Time::getLock();
165 hostIf_Time *pIface = hostIf_Time::getInstance(instanceNumber);
169 hostIf_Time::releaseLock();
173 if (stMsgData->
bsUpdate != HOSTIF_NONE)
177 else if (strcasecmp(stMsgData->
paramName,
"Device.Time.LocalTimeZone") == 0)
181 else if (strcasecmp(stMsgData->
paramName,
"Device.Time.CurrentLocalTime") == 0)
185 else if (strcasecmp(stMsgData->
paramName,
"Device.Time.Status") == 0)
188 char ntpStatus[64] = {
'\0'};
190 fp = fopen(NTPSTATUS_NAME_FILE,
"r");
192 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s:%d] Failed to open NTP Status file\n.!",__FUNCTION__, __FILE__, __LINE__);
193 hostIf_Time::releaseLock();
196 if(fgets(ntpStatus, 64,fp)!=NULL) {
198 int len = strlen(ntpStatus);
199 if(ntpStatus[len-1] ==
'\n') ntpStatus[len-1] =
'\0';
200 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s:%s:%d] ntpStatus = %s.\n",__FUNCTION__, __FILE__, __LINE__,ntpStatus);
203 stMsgData->
paramLen = strlen(ntpStatus);
204 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s:%s:%d] paramValue: %s stMsgData->paramLen: %d \n", __FUNCTION__, __FILE__, __LINE__, stMsgData->
paramValue,stMsgData->
paramLen);
207 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s(): Failed to read ntp status.\n", __FUNCTION__);
211 else if (strcasecmp(stMsgData->
paramName,
"Device.Time.Enable") == 0)
214 ifstream ifp(NTPENABLED_FILE);
218 RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
"[%s] %s exists, NTP sync enabled\n", __FUNCTION__, NTPENABLED_FILE);
224 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s] File does not exist, NTP sync disabled\n", __FUNCTION__);
228 stMsgData->
paramtype = hostIf_BooleanType;
234 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s:%d] parameter : \'%s\' Not handled \n", __FUNCTION__, __FILE__, __LINE__, stMsgData->
paramName);
235 stMsgData->
faultCode = fcInvalidParameterName;
238 hostIf_Time::releaseLock();
242 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s:%d] parameter : \'%s\' Not handled \n", __FUNCTION__, __FILE__, __LINE__, stMsgData->
paramName);
243 stMsgData->
faultCode = fcInvalidParameterName;
249 void TimeClientReqHandler::registerUpdateCallback(updateCallback cb)
251 mUpdateCallback = cb;
254 int TimeClientReqHandler::handleGetAttributesMsg(
HOSTIF_MsgData_t *stMsgData)
256 int ret = NOT_HANDLED;
257 int instanceNumber =0;
259 hostIf_Time::getLock();
260 hostIf_Time *pIface = hostIf_Time::getInstance(instanceNumber);
264 hostIf_Time::releaseLock();
267 GHashTable* notifyhash = pIface->getNotifyHash();
268 if(notifyhash != NULL)
271 notifyValuePtr = (
int*) malloc(1 *
sizeof(
int));
276 char *notifyKey = NULL;
277 notifyKey = (
char*) calloc(
sizeof(
char),strlen(stMsgData->
paramName)+1);
278 if((NULL != notifyValuePtr) && (NULL != notifyKey))
287 g_hash_table_insert(notifyhash,notifyKey,notifyValuePtr);
293 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s:%d] Not able to allocate Notify pointer %s\n", __FUNCTION__, __FILE__, __LINE__, stMsgData->
paramName);
296 free(notifyValuePtr);
301 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s:%d] Not able to get notifyhash %s\n", __FUNCTION__, __FILE__, __LINE__, stMsgData->
paramName);
303 hostIf_Time::releaseLock();
307 int TimeClientReqHandler::handleSetAttributesMsg(
HOSTIF_MsgData_t *stMsgData)
309 int ret = NOT_HANDLED;
310 int instanceNumber = 0;
312 hostIf_Time::getLock();
313 hostIf_Time *pIface = hostIf_Time::getInstance(instanceNumber);
317 hostIf_Time::releaseLock();
320 GHashTable* notifyhash = pIface->getNotifyHash();
321 if(notifyhash != NULL)
324 notifyValuePtr = (
int*) malloc(1 *
sizeof(
int));
329 char *notifyKey = NULL;
330 notifyKey = (
char*) calloc(
sizeof(
char),strlen(stMsgData->
paramName)+1);
331 if((NULL != notifyValuePtr) && (NULL != notifyKey))
340 g_hash_table_insert(notifyhash,notifyKey,notifyValuePtr);
346 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s:%d] Not able to allocate Notify pointer %s\n", __FUNCTION__, __FILE__, __LINE__, stMsgData->
paramName);
349 free(notifyValuePtr);
354 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s:%d] EthernetClientReqHandler Not able to get notifyhash %s\n", __FUNCTION__, __FILE__, __LINE__, stMsgData->
paramName);
356 hostIf_Time::releaseLock();
359 void TimeClientReqHandler::checkForUpdates()
364 GHashTable* notifyhash = NULL;
366 hostIf_Time::getLock();
368 #ifdef HAVE_VALUE_CHANGE_EVENT
370 hostIf_Time *pIface = hostIf_Time::getInstance(instanceNumber);
373 notifyhash = pIface->getNotifyHash();
377 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s] Unable to get Time Instance\n", __FUNCTION__, __FILE__);
381 if(NULL != notifyhash)
383 GHashTableIter notifyHashIterator;
385 gpointer notifyEnable;
386 const char *pSetting;
388 g_hash_table_iter_init (¬ifyHashIterator, notifyhash);
389 while (g_hash_table_iter_next (¬ifyHashIterator, ¶mName, ¬ifyEnable))
391 int* isNotifyEnabled = (
int *)notifyEnable;
393 if(matchComponent((
const char*)paramName,
"Device.Time.Interface",&pSetting,instanceNumber))
397 hostIf_Time::releaseLock();
400 hostIf_Time *pTimeIface = hostIf_Time::getInstance(instanceNumber);
403 if (strcasecmp(pSetting,
"Enable") == 0)
406 if(mUpdateCallback && (*isNotifyEnabled == 1))
419 hostIf_Time::releaseLock();