nc_reply* rpc_reload_module(xmlNodePtr input) { xmlNodePtr module_node = get_rpc_node("module", input); char* module_name; struct np_module* module = netopeer_options.modules; if (module_node) { module_name = (char*)xmlNodeGetContent(module_node); } else { return nc_reply_error(nc_err_new(NC_ERR_MISSING_ELEM)); } while (module) { if (strcmp(module->name, module_name) == 0) { break; } module = module->next; } free(module_name); if (module == NULL) { return nc_reply_error(nc_err_new(NC_ERR_INVALID_VALUE)); } if (module_disable(module, 0) || module_enable(module, 0)) { return nc_reply_error(nc_err_new(NC_ERR_OP_FAILED)); } return nc_reply_ok(); }
nc_reply* rpc_netopeer_reboot(xmlNodePtr input) { xmlNodePtr type_node = get_rpc_node("type", input); char* type_str = NULL; if (type_node) { type_str = (char*)xmlNodeGetContent(type_node); } if (type_str == NULL || strcmp(type_str, "soft") == 0) { restart_soft = 1; } else if (strcmp(type_str, "hard") == 0) { quit = 1; restart_hard = 1; } else { free(type_str); return nc_reply_error(nc_err_new(NC_ERR_INVALID_VALUE)); } free(type_str); return nc_reply_ok(); }
static PyObject *ncProcessRPC(ncSessionObject *self) { NC_MSG_TYPE ret; NC_RPC_TYPE req_type; NC_OP req_op; nc_rpc *rpc = NULL; nc_reply *reply = NULL; struct nc_err* e = NULL; SESSION_CHECK(self); /* receive incoming message */ ret = nc_session_recv_rpc(self->session, -1, &rpc); if (ret != NC_MSG_RPC) { if (nc_session_get_status(self->session) != NC_SESSION_STATUS_WORKING) { /* something really bad happend, and communication is not possible anymore */ nc_session_free(self->session); self->session = NULL; } Py_RETURN_NONE; } /* process it */ req_type = nc_rpc_get_type(rpc); req_op = nc_rpc_get_op(rpc); if (req_type == NC_RPC_SESSION) { /* process operations affectinf session */ switch(req_op) { case NC_OP_CLOSESESSION: /* exit the event loop immediately without processing any following request */ reply = nc_reply_ok(); break; case NC_OP_KILLSESSION: /* todo: kill the requested session */ reply = nc_reply_error(nc_err_new(NC_ERR_OP_NOT_SUPPORTED)); break; default: reply = nc_reply_error(nc_err_new(NC_ERR_OP_NOT_SUPPORTED)); break; } } else if (req_type == NC_RPC_DATASTORE_READ) { /* process operations reading datastore */ switch (req_op) { case NC_OP_GET: case NC_OP_GETCONFIG: reply = ncds_apply_rpc2all(self->session, rpc, NULL); break; default: reply = nc_reply_error(nc_err_new(NC_ERR_OP_NOT_SUPPORTED)); break; } } else if (req_type == NC_RPC_DATASTORE_WRITE) { /* process operations affecting datastore */ switch (req_op) { case NC_OP_LOCK: case NC_OP_UNLOCK: case NC_OP_COPYCONFIG: case NC_OP_DELETECONFIG: case NC_OP_EDITCONFIG: reply = ncds_apply_rpc2all(self->session, rpc, NULL); break; default: reply = nc_reply_error(nc_err_new(NC_ERR_OP_NOT_SUPPORTED)); break; } } else { /* process other operations */ reply = ncds_apply_rpc2all(self->session, rpc, NULL); } /* create reply */ if (reply == NULL) { reply = nc_reply_error(nc_err_new(NC_ERR_OP_FAILED)); } else if (reply == NCDS_RPC_NOT_APPLICABLE) { e = nc_err_new(NC_ERR_OP_FAILED); nc_err_set(e, NC_ERR_PARAM_MSG, "Requested operation cannot be performed on the managed datastore."); reply = nc_reply_error(e); } /* and send the reply to the client */ nc_session_send_reply(self->session, rpc, reply); nc_rpc_free(rpc); nc_reply_free(reply); if (req_op == NC_OP_CLOSESESSION) { /* free the Session */ nc_session_free(self->session); self->session = NULL; } Py_RETURN_NONE; }