static int _ptxrx(Pcall *ptx, Pcall *prx, uint16 timeoutms, uint16 preamblems) { static Rcall tx, rx; tx.type = Ttxrx; tx.timeoutms = timeoutms; tx.preamblems = preamblems; if(convC2P(ptx, tx.pkt) < 0) return -1; switch(ptx->type){ default: tx.type = Ttxrx; tx.timeoutms = timeoutms; tx.preamblems = preamblems; if(rcall(&tx, &rx) < 0) return -1; if(rx.type == Rerr){ if(rx.err == Etimeout){ werrstr("timeout"); return 0; }else return -1; } if(convP2C(rx.pkt, prx) < 0) return -1; /* TODO: push this as a filter down to the radio */ if(prx->tag != (ptx->tag^0xff)){ werrstr("bad reply tag"); return -1; } break; case Tadjourn: tx.type = Ttx; tx.preamblems = preamblems; if(rcall(&tx, &rx) < 0) return -1; if(rx.type == Rerr) return -1; prx->type = Radjourn; break; } return 1; }
int close(int fd) { rp_t rp = fd_rp(fd); if (!rp) { // is not valid file descriptor return -1; } if (fd_mode(fd) & ACCS_EVENT) { // stop listening to events free(rcall(rp, fd_getkey(fd, AC_EVENT), "un-listen")); } if (fd_mode(fd) & ACCS_WRITE) { // finish writing free(rcall(rp, fd_getkey(fd, AC_WRITE), "finish")); } // clear file descriptor entry return fd_set(fd, rp, 0); }
int main(int argc, char **argv) { char *path, *args, *reply; uint64_t ctrl; int i; if (argc < 2) { fprintf(stderr, "%s: missing operand\n", argv[0]); return 1; } if (argv[1][0] == '/') { path = strdup(argv[1]); } else if (argv[1][0] == '@') { path = strdup(argv[1]); } else { path = strvcat("/sys/", argv[1]); } ctrl = fs_find(path); if (!ctrl) { fprintf(stderr, "%s: %s: control file not accessible\n", argv[0], path); return 1; } args = malloc(1000); args[0] = '\0'; for (i = 2; i < argc; i++) { strlcat(args, argv[i], 1000); strlcat(args, " ", 1000); } if (args[0]) args[strlen(args)-1] = '\0'; reply = rcall(ctrl, args); if (!reply) { printf("! nosys (not implemented)\n"); return 1; } if (iserror(reply)) { printf("%s (%s)\n", reply, strerror(geterror(reply))); } else { printf("%s\n", reply); } return 0; }
int rp_admin(rp_t rp, uint32_t user, int access) { char *reply; if (!rp) { return 1; } reply = rcall(rp, "set-access %d %d", user, access); if (iserror(reply)) { errno = geterror(reply); free(reply); return 1; } free(reply); return 0; }
int rp_ulink(rp_t dir, const char *name) { char *reply; if (!name) { return 1; } reply = rcall(dir, rp_getkey(dir, AC_ALTER), "unlink %s", name); if (iserror(reply)) { errno = geterror(reply); free(reply); return 1; } free(reply); return 0; }
int rp_link(uint64_t dir, const char *name, uint64_t link) { char *reply; if (!name) { return 1; } if (link && RP_PID(dir) != RP_PID(link)) { return 1; } reply = rcall(dir, rp_getkey(dir, AC_ALTER), "link %s %r", name, link); if (iserror(reply)) { errno = geterror(reply); free(reply); return 1; } free(reply); return 0; }
int _presume() { static Rcall tx, rx; tagseqidx = 0; /* We try to reset the radio for good measure. */ tx.type = Treset; rcall(&tx, &rx); switch(_pcallsimple(Twakeup)){ case 1: break; case 0: werrstr("session wakeup timeout"); return -1; default: werrstr("session wakeup error: %r"); return -1; } return 0; }
int rp_type(rp_t rp, const char *type) { char *reply; if (!rp) { return 0; } reply = rcall(rp, 0, "type"); if (iserror(reply)) { errno = geterror(reply); free(reply); return 0; } if (strstr(reply, type)) { free(reply); return 1; } else { free(reply); return 0; } }
void ScriptMgr::LoadScripts() { if(HookInterface::getSingletonPtr() == NULL) new HookInterface; Log.Success("Server", "Loading External Script Libraries..."); std::string Path; std::string FileMask; Path = PREFIX; Path += '/'; #ifdef WIN32 /*Path = Config.MainConfig.GetStringDefault( "Script", "BinaryLocation", "script_bin" ); Path += "\\";*/ FileMask = ".dll"; #else #ifndef __APPLE__ FileMask = ".so"; #else FileMask = ".dylib"; #endif #endif Arcpro::FindFilesResult findres; std::vector< ScriptingEngine_dl > Engines; Arcpro::FindFiles(Path.c_str(), FileMask.c_str(), findres); uint32 count = 0; while(findres.HasNext()) { std::stringstream loadmessage; std::string fname = Path + findres.GetNext(); Arcpro::DynLib* dl = new Arcpro::DynLib(fname.c_str()); loadmessage << " " << dl->GetName() << " : "; if(!dl->Load()) { loadmessage << "ERROR: Cannot open library."; LOG_ERROR(loadmessage.str().c_str()); delete dl; continue; } else { exp_get_version vcall = reinterpret_cast< exp_get_version >(dl->GetAddressForSymbol("_exp_get_version")); exp_script_register rcall = reinterpret_cast< exp_script_register >(dl->GetAddressForSymbol("_exp_script_register")); exp_get_script_type scall = reinterpret_cast< exp_get_script_type >(dl->GetAddressForSymbol("_exp_get_script_type")); if((vcall == NULL) || (rcall == NULL) || (scall == NULL)) { loadmessage << "ERROR: Cannot find version functions."; LOG_ERROR(loadmessage.str().c_str()); delete dl; continue; } else { const char *version = vcall(); uint32 stype = scall(); if( strcmp( version, BUILD_HASH_STR ) != 0 ) { loadmessage << "ERROR: Version mismatch."; LOG_ERROR(loadmessage.str().c_str()); delete dl; continue; } else { loadmessage << ' ' << std::string( BUILD_HASH_STR ) << " : "; if((stype & SCRIPT_TYPE_SCRIPT_ENGINE) != 0) { ScriptingEngine_dl se; se.dl = dl; se.InitializeCall = rcall; se.Type = stype; Engines.push_back(se); loadmessage << "delayed load"; } else { rcall(this); dynamiclibs.push_back(dl); loadmessage << "loaded"; } LOG_BASIC(loadmessage.str().c_str()); count++; } } } } if(count == 0) { LOG_ERROR(" No external scripts found! Server will continue to function with limited functionality."); } else { Log.Success("Server", "Loaded %u external libraries.", count); Log.Success("Server", "Loading optional scripting engine(s)..."); for(std::vector< ScriptingEngine_dl >::iterator itr = Engines.begin(); itr != Engines.end(); ++itr) { itr->InitializeCall(this); dynamiclibs.push_back(itr->dl); } Log.Success("Server", "Done loading scripting engine(s)..."); } }
void SystemManager::Init() { /* Loading system for win32 */ #ifdef WIN32 string search_path = "./Plugins/*.dll"; WIN32_FIND_DATA data; uint32 count = 0; HANDLE find_handle = FindFirstFile( search_path.c_str(), &data ); if(find_handle == INVALID_HANDLE_VALUE) WriteConsole("No external scripts found." ); else { do { string full_path = data.cFileName; HMODULE mod = LoadLibrary( full_path.c_str() ); if( mod == 0 ) printf("Loading %s failed, crc=0x%p\r\n", data.cFileName, reinterpret_cast< uint32* >( mod )); else { // find version import exp_get_version vcall = (exp_get_version)GetProcAddress(mod, "_exp_get_version"); exp_script_update ucall = (exp_script_update)GetProcAddress(mod, "_exp_script_update"); exp_script_register rcall = (exp_script_register)GetProcAddress(mod, "_exp_script_register"); exp_get_script_type scall = (exp_get_script_type)GetProcAddress(mod, "_exp_get_script_type"); if(vcall == 0 || rcall == 0 || scall == 0 || ucall == 0) { printf("Loading %s failed, version info not found\r\n", data.cFileName); FreeLibrary(mod); } else { uint32 version = vcall(); uint32 stype = scall(); uint32 versionhigh = SCRIPTLIB_HIPART(version), versionlow = SCRIPTLIB_LOPART(version); std::stringstream cmsg; cmsg << "Loading " << data.cFileName << ", crc:0x" << reinterpret_cast< uint32* >( mod ); cmsg << ", Version:" << versionhigh << " " << versionlow << " delayed loading."; ScriptDLLs se; se.Handle = mod; se.InitializeCall = rcall; se.UpdateCall = ucall; se.Type = stype; se.highrev = versionhigh; se.lowrev = versionlow; DLLScriptVector.push_back( se ); WriteConsole(cmsg.str()); ++count; } } }while(FindNextFile(find_handle, &data)); FindClose(find_handle); printf("Loading %u external libraries.\r\n", count); for(vector<ScriptDLLs>::iterator itr = DLLScriptVector.begin(); itr != DLLScriptVector.end(); itr++) (*itr).InitializeCall(this); } #else /* Loading system for *nix */ struct dirent ** list; int filecount = scandir(PREFIX "/lib/", &list, 0, 0); uint32 count = 0; if(!filecount || !list || filecount < 0) WriteConsole("No external scripts found."); else { char *ext; while(filecount--) { ext = strrchr(list[filecount]->d_name, '.'); #ifdef HAVE_DARWIN if (ext != NULL && strstr(list[filecount]->d_name, ".0.dylib") == NULL && !strcmp(ext, ".dylib")) { #else if (ext != NULL && !strcmp(ext, ".so")) { #endif string full_path = "../lib/" + string(list[filecount]->d_name); SCRIPT_MODULE mod = dlopen(full_path.c_str(), RTLD_NOW); printf(" %s : 0x%p : ", list[filecount]->d_name, mod); if(mod == 0) printf("error! [%s]\r\n", dlerror()); else { // find version import exp_get_version vcall = (exp_get_version)dlsym(mod, "_exp_get_version"); exp_script_update ucall = (exp_script_update)dlsym(mod, "_exp_script_update"); exp_script_register rcall = (exp_script_register)dlsym(mod, "_exp_script_register"); exp_get_script_type scall = (exp_get_script_type)dlsym(mod, "_exp_get_script_type"); if(vcall == 0 || rcall == 0 || scall == 0 || ucall == 0) { WriteConsole("version functions not found!"); dlclose(mod); } else { int32 version = vcall(); uint32 stype = scall(); uint32 versionhigh = SCRIPTLIB_HIPART(version), versionlow = SCRIPTLIB_LOPART(version); ScriptDLLs se; se.Handle = mod; se.InitializeCall = rcall; se.UpdateCall = ucall; se.Type = stype; se.highrev = versionhigh; se.lowrev = versionlow; DLLScriptVector.push_back( se ); printf("v%u.%u : loaded.\r\n", versionhigh, versionlow); rcall(this); ++count; } } } free(list[filecount]); } free(list); WriteConsole(""); printf("Loaded %u external libraries.", count); WriteConsole(""); WriteConsole("Loading optional scripting engines..."); for(vector<ScriptingEngine>::iterator itr = ScriptEngines.begin(); itr != ScriptEngines.end(); itr++) itr->InitializeCall(this); WriteConsole("Done loading script engines..."); } #endif } void SystemManager::WriteConsole(const char* message) { Console::Write(gcnew System::String(message)+"\r\n"); }
void ScriptMgr::LoadScripts() { if(!HookInterface::getSingletonPtr()) new HookInterface; sLog.outString("Loading External Script Libraries..."); sLog.outString(""); string start_path = Config.MainConfig.GetStringDefault("Script", "BinaryLocation", "script_bin") + "\\"; string search_path = start_path + "*."; /* Loading system for win32 */ #ifdef WIN32 search_path += "dll"; WIN32_FIND_DATA data; uint32 count = 0; HANDLE find_handle = FindFirstFile(search_path.c_str(), &data); if(find_handle == INVALID_HANDLE_VALUE) sLog.outError(" No external scripts found! Server will continue to function with limited functionality."); else { do { string full_path = start_path + data.cFileName; HMODULE mod = LoadLibrary(full_path.c_str()); printf(" %s : 0x%.08X : ", data.cFileName, ((uint32)mod)); if(mod == 0) printf("error!\n"); else { // find version import exp_get_version vcall = (exp_get_version)GetProcAddress(mod, "_exp_get_version"); exp_script_register rcall = (exp_script_register)GetProcAddress(mod, "_exp_script_register"); if(vcall == 0 || rcall == 0) { printf("version functions not found!\n"); FreeLibrary(mod); } else { uint32 version = vcall(); if(UINT32_LOPART(version) == SCRIPTLIB_VERSION_MINOR && UINT32_HIPART(version) == SCRIPTLIB_VERSION_MAJOR) { _handles.push_back(((SCRIPT_MODULE)mod)); printf("v%u.%u : ", UINT32_HIPART(version), UINT32_LOPART(version)); rcall(this); printf("loaded.\n"); ++count; } else { FreeLibrary(mod); printf("version mismatch!\n"); } } } } while(FindNextFile(find_handle, &data)); FindClose(find_handle); sLog.outString(""); sLog.outString("Loaded %u external libraries.", count); sLog.outString(""); } #else /* Loading system for *nix */ struct dirent ** list; int filecount = scandir(PREFIX "/lib/", &list, 0, 0); uint32 count = 0; if(!filecount || !list || filecount < 0) sLog.outError(" No external scripts found! Server will continue to function with limited functionality."); else { char *ext; while(filecount--) { ext = strrchr(list[filecount]->d_name, '.'); if (ext != NULL && !strcmp(ext, ".so")) { string full_path = "../lib/" + string(list[filecount]->d_name); SCRIPT_MODULE mod = dlopen(full_path.c_str(), RTLD_NOW); printf(" %s : 0x%08X : ", list[filecount]->d_name, (unsigned int)mod); if(mod == 0) printf("error! [%s]\n", dlerror()); else { // find version import exp_get_version vcall = (exp_get_version)dlsym(mod, "_exp_get_version"); exp_script_register rcall = (exp_script_register)dlsym(mod, "_exp_script_register"); if(vcall == 0 || rcall == 0) { printf("version functions not found!\n"); dlclose(mod); } else { uint32 version = vcall(); if(UINT32_LOPART(version) == SCRIPTLIB_VERSION_MINOR && UINT32_HIPART(version) == SCRIPTLIB_VERSION_MAJOR) { _handles.push_back(((SCRIPT_MODULE)mod)); printf("v%u.%u : ", UINT32_HIPART(version), UINT32_LOPART(version)); rcall(this); printf("loaded.\n"); ++count; } else { dlclose(mod); printf("version mismatch!\n"); } } } } free(list[filecount]); } free(list); sLog.outString(""); sLog.outString("Loaded %u external libraries.", count); sLog.outString(""); } #endif }
void Data::shutdown() { rcall( boost::bind(&BaseDatabase::shutdown, _1) ); }