Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function buildDevAttr(req) {
var devAttr = {},
query = req.url ? req.url.split('?')[1] : undefined,
queryParams = query ? query.split('&') : undefined,
invalidAttrs = [];
_.forEach(queryParams, function (queryParam, idx) {
queryParams[idx] = queryParam.split('=');
});
_.forEach(queryParams, function(queryParam) { // 'ep=clientName<=86400&lwm2m=1.0.0'
if(queryParam[0] === 'ep') {
devAttr.clientName = queryParam[1];
} else if (queryParam[0] === 'lt') {
devAttr.lifetime = parseInt(queryParam[1]);
} else if (queryParam[0] === 'lwm2m') {
devAttr.version = queryParam[1];
} else if (queryParam[0] === 'mac') {
devAttr.mac = queryParam[1];
} else {
invalidAttrs.push(queryParam[0]);
}
});
.removeAllListeners(EVT_BTM.NcBannedDevIncoming)
.removeAllListeners(EVT_BTM.NcBannedDevReporting)
.removeAllListeners(EVT_BTM.NcBannedGadIncoming)
.removeAllListeners(EVT_BTM.NcBannedGadReporting)
.removeAllListeners(EVT_BTM.DevError)
.removeAllListeners(EVT_BTM.DevNetChanged)
.removeAllListeners(EVT_BTM.DevPropsChanged)
.removeAllListeners(EVT_BTM.DevAttrsChanged)
.removeAllListeners(EVT_BTM.GadError)
.removeAllListeners(EVT_BTM.GadPanelChanged)
.removeAllListeners(EVT_BTM.GadPropsChanged)
.removeAllListeners(EVT_BTM.GadAttrsChanged)
.removeAllListeners(EVT_BTM.GadAttrsAppend);
// Firstly bind the handlers to freebird
_.forEach(handlers, function (lsn, key) {
ncLsns[key] = lsn.bind(freebird);
});
// Then, attach the handlers to events // VVVVVVVVVVVVVVVVVVVVVV [TODO] all kvps need to be checked
freebird.on(EVT_BTM.NcError, ncLsns.ncError); // { ncName, error: err }
freebird.on(EVT_BTM.NcEnabled, ncLsns.ncEnabled);
freebird.on(EVT_BTM.NcDisabled, ncLsns.ncDisabled);
freebird.on(EVT_BTM.NcStarted, ncLsns.ncStarted);
freebird.on(EVT_BTM.NcStopped, ncLsns.ncStopped);
freebird.on(EVT_BTM.NcReady, ncLsns.ncReady); // { ncName }
freebird.on(EVT_BTM.NcPermitJoin, ncLsns.ncPermitJoin); // { ncName, timeLeft: self._joinTicks }
freebird.on(EVT_BTM.NcDevIncoming, ncLsns.ncDevIncoming); // { ncName, permAddr: permAddr, raw: rawDev }
freebird.on(EVT_BTM.NcDevLeaving, ncLsns.ncDevLeaving); // { ncName, permAddr: permAddr }
freebird.on(EVT_BTM.NcDevNetChanging, ncLsns.ncDevNetChanging); // { ncName, permAddr: permAddr, data: changes }
freebird.on(EVT_BTM.NcDevReporting, ncLsns.ncDevReporting); // { ncName, permAddr: permAddr, data: devAttrs }
module.exports = function attachEventListeners(freebird) {
var ncLsns;
freebird._ncEventListeners = freebird._ncEventListeners || {};
ncLsns = freebird._ncEventListeners;
// Firstly bind the handlers to freebird
_.forEach(listeners, function (lsn, key) {
if (key !== 'attachEventListeners')
ncLsns[key] = lsn.bind(freebird);
});
// Then, attach the handlers to events
freebird.on(LLEVT.NETCORE.ready, ncLsns.ncReady); // {}
freebird.on(LLEVT.NETCORE.error, ncLsns.ncError); // { error: err }
freebird.on(LLEVT.NETCORE.permitJoin, ncLsns.ncPermitJoin); // { timeLeft: self._joinTicks }
freebird.on(LLEVT.NETCORE.started, ncLsns.ncStarted);
freebird.on(LLEVT.NETCORE.stopped, ncLsns.ncStopped);
freebird.on(LLEVT.NETCORE.enabled, ncLsns.ncEnabled);
freebird.on(LLEVT.NETCORE.disabled, ncLsns.ncDisabled);
freebird.on(LLEVT.NETCORE.devNetChanging, ncLsns.ncDevNetChanging); // { permAddr: permAddr, data: changes }
freebird.on(LLEVT.NETCORE.devIncoming, ncLsns.ncDevIncoming); // { permAddr: permAddr, raw: rawDev }
freebird.on(LLEVT.NETCORE.bannedDevIncoming, ncLsns.ncBannedDevIncoming); // { permAddr: permAddr, raw: rawDev }
freebird.on(LLEVT.NETCORE.devLeaving, ncLsns.ncDevLeaving); // { permAddr: permAddr }
_.forEach(self.objList, (iids, oid) => {
_.forEach(iids, (iid) => {
const path = mutils.createPath('/', oid, iid)
readAllProms.push(self.readReq(path)) // readReq will update the database
})
})
return Q.all(readAllProms)
function getAttrQuery(attr) {
var query = '';
_.forEach(attr, function (value, key) {
if (key === 'step')
query = query + 'stp=' + value + '&';
else
query = query + key + '=' + value + '&';
});
return query.slice(0, query.length - 1); // take off the last '&'
}
function getAttrQuery(attr) {
var query = '';
_.forEach(attr, function (value, key) {
if (key === 'step')
query = query + 'stp=' + value + '&';
else
query = query + key + '=' + value + '&';
});
return query.slice(0, query.length - 1); // take off the last '&'
}
CoapNode.prototype._disableAllReport = function () {
var self = this;
helper.heartbeat(this, false);
_.forEach(this._reporters, function (rpt, key) {
var oid = key.split('/')[0],
iid = key.split('/')[1],
rid = key.split('/')[2];
self._disableReport(oid, iid, rid, function (err, result) {
if (err)
self.emit('error', err);
});
});
};
af.controller.once('ind:incoming' + ':' + rsp.ieeeaddr, function () {
if (af.controller.findEndpoint(msg.srcaddr, msg.srcendpoint) && _.isArray(msgBuffer))
_.forEach(msgBuffer, function(item) {
dispatchIncomingMsg(item.type, item.msg);
});
else
delete rebornDevs[msg.srcaddr];
});
af.controller.emit('ZDO:endDeviceAnnceInd', { srcaddr: rsp.nwkaddr, nwkaddr: rsp.nwkaddr, ieeeaddr: rsp.ieeeaddr, capabilities: {} });
Q.all(iObjsUpdater).done((resArray) => {
const resultObj = {}
_.forEach(resArray, (res, idx) => {
resultObj[iidArray[idx]] = res
})
updateFinalizer(null, resultObj)
}, (err) => {
updateFinalizer(err, null)
}).then(function () {
sendRsp(rsp, RSP.changed, '', 'update');
_.forEach(diff, function (val, key) {
msg[key] = val;
});
fireImmediate(shepherd, 'ind', {
type: 'devUpdate',
cnode: cnode,
data: msg
});
}, function (err) {
sendRsp(rsp, RSP.serverError, '', 'update');