void set(Map m)

Source

void set(Map m) {
  Path path = Path.getValidPath(m['path']);
  if (path == null || !path.isAbsolute) {
    closeResponse(m['rid'], error: DSError.INVALID_PATH);
    return;
  }

  if (!m.containsKey('value')) {
    closeResponse(m['rid'], error: DSError.INVALID_VALUE);
    return;
  }

  Object value = m['value'];
  int rid = m['rid'];
  if (path.isNode) {
    _getNode(path, (LocalNode node) {
      int permission = nodeProvider.permissions.getPermission(node.path, this);
      int maxPermit = Permission.parse(m['permit']);
      if (maxPermit < permission) {
        permission = maxPermit;
      }

      if (node.getSetPermission() <= permission) {
        node.setValue(value, this, addResponse(new Response(this, rid, 'set'), path, value));
      } else {
        closeResponse(m['rid'], error: DSError.PERMISSION_DENIED);
      }
      closeResponse(m['rid']);
    }, (e, stack) {
      var error = new DSError(
        "nodeError",
        msg: e.toString(),
        detail: stack.toString()
      );
      closeResponse(m['rid'], error: error);
    });
  } else if (path.isConfig) {
    LocalNode node;

    node = nodeProvider.getOrCreateNode(path.parentPath, false);

    int permission = nodeProvider.permissions.getPermission(node.path, this);
    if (permission < Permission.CONFIG) {
      closeResponse(m['rid'], error: DSError.PERMISSION_DENIED);
    } else {
      node.setConfig(
          path.name, value, this, addResponse(new Response(this, rid, 'set'), path, value));
    }
  } else if (path.isAttribute) {
    LocalNode node;

    node = nodeProvider.getOrCreateNode(path.parentPath, false);
    int permission = nodeProvider.permissions.getPermission(node.path, this);
    if (permission < Permission.WRITE) {
      closeResponse(m['rid'], error: DSError.PERMISSION_DENIED);
    } else {
      node.setAttribute(
          path.name, value, this, addResponse(new Response(this, rid, 'set'), path, value));
    }
  } else {
    // shouldn't be possible to reach here
    throw 'unexpected case';
  }
}