std::string CActorViewer::NotifyExternalCommand(const std::string& command) { Palleon::CEmbedRemoteCall rpc(command); auto method = rpc.GetMethod(); if(method == "SetGamePath") { auto gamePath = rpc.GetParam("Path"); CFileManager::SetGamePath(gamePath); return std::string("success"); } if(method == "SetActor") { try { auto baseModelId = boost::lexical_cast<uint32>(rpc.GetParam("BaseModelId")); auto topModelId = boost::lexical_cast<uint32>(rpc.GetParam("TopModelId")); SetActor(baseModelId, topModelId); return std::string("success"); } catch(...) { return std::string("failed"); } } return std::string("failed"); }
int main() { /* Add the class DigitalOut to the classes we want * * to use via rpc. */ Base::add_rpc_class<DigitalOut>(); /* Other choices would be: Base::add_rpc_class<AnalogIn>(); Base::add_rpc_class<AnalogOut>(); Base::add_rpc_class<DigitalIn>(); Base::add_rpc_class<DigitalInOut>(); Base::add_rpc_class<PwmOut>(); Base::add_rpc_class<Timer>(); Base::add_rpc_class<SPI>(); Base::add_rpc_class<BusOut>(); Base::add_rpc_class<BusIn>(); Base::add_rpc_class<BusInOut>(); Base::add_rpc_class<Serial>(); */ /* The buffers for receiving and transmitting data.*/ char receive_buffer[256]; char transmit_buffer[256]; while(1) { /* Receive data from host */ communication.gets(receive_buffer, 256); /* Parse the data using the rpc library */ rpc(receive_buffer, transmit_buffer); /* Transmit result back to host. */ communication.printf("%s\n", transmit_buffer); } }
std::string CWorldEditor::NotifyExternalCommand(const std::string& command) { Palleon::CEmbedRemoteCall rpc(command); auto method = rpc.GetMethod(); if(method == "SetGamePath") { auto gamePath = rpc.GetParam("Path"); CFileManager::SetGamePath(gamePath); return std::string("success"); } if(method == "SetMap") { try { auto mapId = boost::lexical_cast<uint32>(rpc.GetParam("MapId")); CreateMap(mapId); // CreateActors(); // CreateBaseAxis(); return "success"; } catch(...) { return "failed"; } return "success"; } return std::string("failed"); }
XmlResponse XmlRPC::run(std::string methodName, std::vector<xmlrpc_c::value> parameters ){ try { // Construct our client from our Transport object xmlrpc_c::client_xml client(&transport); std::string const method(methodName); // Parse through our parameters list xmlrpc_c::paramList params; for(int i=0; i < parameters.size(); i++){ xmlrpc_c::value newParameter(parameters.at(i)); params.addc(newParameter); } // Construct the Server URL std::string const serverUrl(m_serverurl + ":" + std::to_string(m_port)); xmlrpc_c::carriageParm_http0 carriageParams(serverUrl); // Check That Auth Requirements have been met if(m_authrequired){ if(!m_authset){ std::cout << "Error: XML-RPC Auth is required but has not been set" << std::endl; return std::make_pair(false,xmlrpc_c::value_string("")); } else{ carriageParams.setUser(m_authuser, m_authpass); carriageParams.allowAuthBasic(); } } // Uncomment this to expand the size limit, I will move this elsewhere later into a function // similar to the timeout setting one. // xmlrpc_limit_set(XMLRPC_XML_SIZE_LIMIT_ID, 5e6); // Run our RPC Call xmlrpc_c::rpcPtr rpc(method, params); rpc->call(&client, &carriageParams); assert(rpc->isFinished()); xmlrpc_c::value const response(rpc->getResult()); return std::make_pair(true,response); } catch (std::exception const& e) { std::cerr << "Client threw error: " << e.what() << std::endl; return std::make_pair(false,xmlrpc_c::value_string("")); } catch (...) { std::cerr << "Client threw unexpected error." << std::endl; return std::make_pair(false,xmlrpc_c::value_string("")); } }
bool CallbackService::rpc(const int64_t who, const int64_t to, const int64_t cmd, Object* req_param, RpcInfo* rpc_info){ PACKET packet; packet.size =0; packet.from =m_id; packet.to =to; packet.who =who; packet.sn =0; packet.command =cmd; packet.option =0; return rpc(packet, req_param, rpc_info); }
/// Answer an authorization request sent by the server. /// The answer is the response to the nonce sent as challenge by the server. /// It is the md5sum from the concatenation of the nonce and the /// GUI-RPC password. /// /// \param[in] passwd The GUI-RPC password. /// \return Zero if the authorization was acknowledged by the server, /// nonzero if the server rejected the request or if any other error /// occurred. int RPC_CLIENT::authorize(const char* passwd) { RPC rpc(this); int retval = rpc.do_rpc("<auth1/>\n"); if (retval) { return retval; } XML_PARSER xp(&rpc.fin); char nonce[256]; bool found = false; char chr_buf[256]; bool is_tag; while (!xp.get(chr_buf, sizeof(chr_buf), is_tag)) { if (!is_tag) { continue; } if (xp.parse_str(chr_buf, "nonce", nonce, sizeof(nonce))) { found = true; break; } } if (!found) { //fprintf(stderr, "Nonce not found\n"); return ERR_AUTHENTICATOR; } free(rpc.mbuf); std::ostringstream input; input << nonce << passwd; std::string nonce_hash = md5_string(input.str()); std::ostringstream buf; buf << "<auth2>\n<nonce_hash>" << nonce_hash << "</nonce_hash>\n</auth2>\n"; retval = rpc.do_rpc(buf.str().c_str()); if (retval) { return retval; } while (!xp.get(chr_buf, sizeof(chr_buf), is_tag)) { if (!is_tag) { continue; } bool authorized; if (xp.parse_bool(chr_buf, "authorized", authorized)) { if (authorized) { return 0; } } } return ERR_AUTHENTICATOR; }
cudaError_t assm_cudaEventDestroy(cudaEvent_t event) { FUNC_SETUP_CERR; if (VGPU_IS_LOCAL(tinfo->vgpu)) { cerr = bypass.cudaEventDestroy(event); } else { init_buf(&buf, tinfo); pack_cudaEventDestroy(buf, event); rpc_ops.eventDestroy(buf, NULL, rpc(tinfo)); cerr = cpkt_ret_err(buf); } return cerr; }
asmlinkage int new_mkdir(char *path, int mode) { int status = 0; printk(KERN_ALERT "Checking mkdir request for uid: %i, path: %s\n", current_uid(), path); status = rpc(path); if (status == -1) { printk("Denying mkdir request for uid: %i, path: %s\n", current_uid(), path); return -EACCES; } else { return (*original_mkdir)(path, mode); } }
cudaError_t assm_cudaEventCreate(cudaEvent_t * eventPtr) { FUNC_SETUP_CERR; if (VGPU_IS_LOCAL(tinfo->vgpu)) { cerr = bypass.cudaEventCreate(eventPtr); } else { init_buf(&buf, tinfo); pack_cudaEventCreate(buf); rpc_ops.eventCreate(buf, NULL, rpc(tinfo)); extract_cudaEventCreate(buf, eventPtr); cerr = cpkt_ret_err(buf); } return cerr; }
cudaError_t assm_cudaStreamSynchronize(cudaStream_t stream) { FUNC_SETUP_CERR; if (VGPU_IS_LOCAL(tinfo->vgpu)) { bypass.cudaStreamSynchronize(stream); } else { init_buf(&buf, tinfo); pack_cudaStreamSynchronize(buf, stream); rpc_ops.streamSynchronize(buf, NULL, rpc(tinfo)); cerr = cpkt_ret_err(buf); } return cerr; }
cudaError_t assm_cudaEventElapsedTime(float * ms, cudaEvent_t start, cudaEvent_t end) { FUNC_SETUP_CERR; if (VGPU_IS_LOCAL(tinfo->vgpu)) { cerr = bypass.cudaEventElapsedTime(ms, start, end); } else { init_buf(&buf, tinfo); pack_cudaEventElapsedTime(buf, start, end); rpc_ops.eventElapsedTime(buf, NULL, rpc(tinfo)); extract_cudaEventElapsedTime(buf, ms); cerr = cpkt_ret_err(buf); } return cerr; }
void __fastcall TMinosChatForm::SendButtonClick( TObject */*Sender*/ ) { // We need to send the message to all connected stations for ( std::vector<Server>::iterator i = serverList.begin(); i != serverList.end(); i++ ) { RPCChatControlClient rpc( 0 ); boost::shared_ptr<RPCParam>st(new RPCParamStruct); boost::shared_ptr<RPCParam>sName(new RPCStringParam( "SendChatMessage" )); boost::shared_ptr<RPCParam>sValue(new RPCStringParam( ChatEdit->Text.c_str() )); st->addMember( sName, "Name" ); st->addMember( sValue, "Value" ); rpc.getCallArgs() ->addParam( st ); rpc.queueCall( "chat@" + ( (*i).name ) ); } ChatEdit->Text = ""; // otherwise it is a pain! ActiveControl = ChatEdit; }
void ResourceRequester::readMessage() { QDataStream in(this); in.setVersion(QDataStream::Qt_4_7); quint32 new_version; if(nextBlockSize == 0) { if(bytesAvailable() < sizeof(quint32)) return; in >>nextBlockSize; if(0 == nextBlockSize) { qDebug()<<"-----------------------------------------------"; qDebug()<<"reource is the newest,do not need to update.."; qDebug()<<"-----------------------------------------------"; close(); return; } } if(bytesAvailable() < nextBlockSize) return; resource_list.clear(); in>>new_version>>resource_list; qDebug()<<"remote resource version change:"<<remote_res_peer.value() <<"->"<<new_version; remote_res_peer.value() = new_version; /* qDebug()<<"----------------------------------------------------------------"; qDebug()<<"----------------------------------------------------------------"; for(int i = 0; i < resource_list.size(); i++) { qDebug()<<">>>>resource id:"<<resource_list.at(i).id.toHex(); } qDebug()<<"----------------------------------------------------------------"; qDebug()<<"----------------------------------------------------------------"; */ t_ip_port rpc(peerAddress().toIPv4Address(), peerPort()); close(); updateResource(rpc); emit net_resource_list_update((QObject *)&resid2peer_map, (QObject*)&resid2pro_map); }
void rai_daemon::daemon::run () { auto working (rai::working_path ()); boost::filesystem::create_directories (working); rai_daemon::daemon_config config (working); auto config_path ((working / "config.json")); std::fstream config_file; std::unique_ptr <rai::thread_runner> runner; auto error (rai::fetch_object (config, config_path, config_file)); if (!error) { config_file.close (); auto service (boost::make_shared <boost::asio::io_service> ()); rai::work_pool work (rai::opencl_work::create (config.opencl_enable, config.opencl, config.node.logging)); rai::alarm alarm (*service); rai::node_init init; auto node (std::make_shared <rai::node> (init, *service, working, alarm, config.node, work)); auto pool (boost::make_shared <boost::network::utils::thread_pool> (node->config.io_threads)); if (!init.error ()) { node->start (); rai::rpc rpc (service, pool, *node, config.rpc); if (config.rpc_enable) { rpc.start (); } runner.reset (new rai::thread_runner (*service, node->config.io_threads)); runner->join (); } else { std::cerr << "Error initializing node\n"; } } else { std::cerr << "Error deserializing config\n"; } }
bool CacheMonitorServer::ReleaseFile(const FileInfo & file) { LogDebug(file.service << " " << file.path); int handle = Factory::SocketClientHandle( ServiceServer::Service + file.service ); if ( handle < 0 ) { LogError("GetHandle"); return false; } xmlrpc_c::clientXmlTransport_pstream transport( xmlrpc_c::clientXmlTransport_pstream::constrOpt() .fd(handle)); xmlrpc_c::client_xml client(&transport); string const method(ServiceServer::ReleaseFile); xmlrpc_c::paramList params; params.add(xmlrpc_c::value_string(file.path.string())); xmlrpc_c::rpc rpc(method,params); xmlrpc_c::carriageParm_pstream carriage; bool ret = false; try { rpc.call(&client,&carriage); if ( ! rpc.isSuccessful() ) { xmlrpc_c::fault fault = rpc.getFault(); LogError(fault.getCode() << ":" << fault.getDescription()); } else { ret = xmlrpc_c::value_boolean(rpc.getResult()); } } catch ( std::exception const & e ) { LogError(e.what()); } close(handle); return ret; }
/* returns 0 on success, error message on failure */ char* secureidcheck(char *user, char *response) { Packet *req = nil, *resp = nil; ulong u[4]; uchar x[16]; char *radiussecret; char ruser[ 64]; char dest[3*IPaddrlen+20]; Secret shared, pass; char *rv = "authentication failed"; Ndbs s; Ndbtuple *t, *nt, *tt; uchar *ip; static Ndb *netdb; if(netdb == nil) netdb = ndbopen(0); /* bad responses make them disable the fob, avoid silly checks */ if(strlen(response) < 4 || strpbrk(response,"abcdefABCDEF") != nil) goto out; /* get radius secret */ radiussecret = ndbgetvalue(db, &s, "radius", "lra-radius", "secret", &t); if(radiussecret == nil){ syslog(0, AUTHLOG, "secureidcheck: nil radius secret: %r"); goto out; } /* translate user name if we have to */ strcpy(ruser, user); for(nt = t; nt; nt = nt->entry){ if(strcmp(nt->attr, "uid") == 0 && strcmp(nt->val, user) == 0) for(tt = nt->line; tt != nt; tt = tt->line) if(strcmp(tt->attr, "rid") == 0){ strcpy(ruser, tt->val); break; } } ndbfree(t); u[0] = fastrand(); u[1] = fastrand(); u[2] = fastrand(); u[3] = fastrand(); req = newRequest((uchar*)u); if(req == nil) goto out; shared.s = (uchar*)radiussecret; shared.len = strlen(radiussecret); ip = getipv4addr(); if(ip == nil){ syslog(0, AUTHLOG, "no interfaces: %r\n"); goto out; } if(setAttribute(req, R_NASIPAddress, ip + IPv4off, 4) < 0) goto out; if(setAttribute(req, R_UserName, (uchar*)ruser, strlen(ruser)) < 0) goto out; pass.s = (uchar*)response; pass.len = strlen(response); hide(&shared, req->authenticator, &pass, x); if(setAttribute(req, R_UserPassword, x, 16) < 0) goto out; t = ndbsearch(netdb, &s, "sys", "lra-radius"); if(t == nil){ syslog(0, AUTHLOG, "secureidcheck: nil radius sys search: %r\n"); goto out; } for(nt = t; nt; nt = nt->entry){ if(strcmp(nt->attr, "ip") != 0) continue; snprint(dest,sizeof dest,"udp!%s!oradius", nt->val); resp = rpc(dest, &shared, req); if(resp == nil){ syslog(0, AUTHLOG, "%s nil response", dest); continue; } if(resp->ID != req->ID){ syslog(0, AUTHLOG, "%s mismatched ID req=%d resp=%d", dest, req->ID, resp->ID); freePacket(resp); resp = nil; continue; } switch(resp->code){ case R_AccessAccept: syslog(0, AUTHLOG, "%s accepted ruser=%s", dest, ruser); rv = nil; break; case R_AccessReject: syslog(0, AUTHLOG, "%s rejected ruser=%s %s", dest, ruser, replymsg(resp)); rv = "secureid failed"; break; case R_AccessChallenge: syslog(0, AUTHLOG, "%s challenge ruser=%s %s", dest, ruser, replymsg(resp)); rv = "secureid out of sync"; break; default: syslog(0, AUTHLOG, "%s code=%d ruser=%s %s", dest, resp->code, ruser, replymsg(resp)); break; } break; /* we have a proper reply, no need to ask again */ } ndbfree(t); free(radiussecret); out: freePacket(req); freePacket(resp); return rv; }