bool cfg_conf_set(struct cfg_state *cmd, char *args) { int fields = countfields(args); char var[50], val[1024], val2[1024], val3[1024]; /* Require a value */ if ( fields < 2 || !copyfield(args, 1, var, sizeof(var)) || !copyfield(args, 2, val, sizeof(val))) { sock_printf(cmd->sock, "400 The command is: set <variable> <value> [<value> ...]\n"); return false; } if (fields > 2) copyfield(args, 3, val2, sizeof(val2)); if (fields > 3) copyfields(args, 4, 0, val3, sizeof(val3)); if (strcasecmp(var, "service_name") == 0 && fields == 2) { if (g_conf->service_name) free(g_conf->service_name); g_conf->service_name = strdup(val); return true; } if (strcasecmp(var, "service_description") == 0 && fields == 2) { if (g_conf->service_description) free(g_conf->service_description); g_conf->service_description = strdup(val); return true; } if (strcasecmp(var, "admin_location1") == 0 && fields == 2) { if (g_conf->admin_location1) free(g_conf->admin_location1); g_conf->admin_location1 = strdup(val); return true; } if (strcasecmp(var, "admin_location2") == 0 && fields == 2) { if (g_conf->admin_location2) free(g_conf->admin_location2); g_conf->admin_location2 = strdup(val); return true; } if (strcasecmp(var, "admin_email") == 0 && fields == 2) { if (g_conf->admin_email) free(g_conf->admin_email); g_conf->admin_email = strdup(val); return true; } if (strcasecmp(var, "motd_file") == 0 && fields == 2) { if (g_conf->motd_file) free(g_conf->motd_file); g_conf->motd_file = strdup(val); return true; } if (strcasecmp(var, "config_password") == 0 && fields == 2) { if (g_conf->config_password) free(g_conf->config_password); g_conf->config_password = (unsigned char *)strdup(val); return true; } if (strcasecmp(var, "bitlbee_auto_add") == 0 && fields == 2) { if ( strcasecmp(val, "true") == 0 || strcasecmp(val, "on") == 0) { g_conf->bitlbee_auto_add = true; } else g_conf->bitlbee_auto_add = false; return true; } if (strcasecmp(var, "verbose") == 0 && fields == 2) { if ( strcasecmp(val, "on") == 0 || strcasecmp(val, "true") == 0 ) { g_conf->verbose = true; /* Report back */ sock_printf(cmd->sock, "200 Verbosity Activated\n"); return true; } else if (strcasecmp(val, "off") == 0 || strcasecmp(val, "false") == 0 ) { g_conf->verbose = true; /* Report back */ sock_printf(cmd->sock, "200 Verbosity Disabled\n"); return true; } sock_printf(cmd->sock, "400 verbose only accepts 'on' and 'off' and not '%s'\n", var); return false; } sock_printf(cmd->sock, "400 Unknown settable value '%s' with %u fields\n", var, fields); return false; }
LUAMODULE_API int luaopen_ex_core(lua_State *L) { const char *name = lua_tostring(L, 1); int ex; const luaL_reg ex_iolib[] = { {"pipe", ex_pipe}, #define ex_iofile_methods (ex_iolib + 1) {"lock", ex_lock}, {"unlock", ex_lock}, {0,0} }; const luaL_reg ex_oslib[] = { /* environment */ {"getenv", ex_getenv}, {"setenv", ex_setenv}, {"environ", ex_environ}, /* file system */ {"access", ex_access}, {"getcwd", ex_getcwd}, {"chdir", ex_chdir}, {"chmod", ex_chmod}, {"mkdir", ex_mkdir}, {"remove", ex_remove}, {"dir", ex_dir}, {"dirent", ex_dirent}, {"copyfile", ex_copyfile}, {"movefile", ex_movefile}, {"touch", ex_touch}, {"stdin_binary", ex_stdin_binary}, {"stdout_binary", ex_stdout_binary}, /* process control */ {"sleep", ex_sleep}, {"spawn", ex_spawn}, {0,0} }; const luaL_reg ex_diriter_methods[] = { {"__gc", diriter_close}, {0,0} }; const luaL_reg ex_process_methods[] = { {"__tostring", process_tostring}, #define ex_process_functions (ex_process_methods + 1) {"wait", process_wait}, {"__gc", process_close}, {0,0} }; /* diriter metatable */ luaL_newmetatable(L, DIR_HANDLE); /* . D */ luaL_register(L, 0, ex_diriter_methods); /* . D */ /* proc metatable */ luaL_newmetatable(L, PROCESS_HANDLE); /* . P */ luaL_register(L, 0, ex_process_methods); /* . P */ lua_pushvalue(L, -1); /* . P P */ lua_setfield(L, -2, "__index"); /* . P */ /* make all functions available via ex. namespace */ luaL_register(L, name, ex_oslib); /* . P ex */ luaL_register(L, 0, ex_iolib); copyfields(L, ex_process_functions, -2, -1); ex = lua_gettop(L); /* extend the os table */ lua_getglobal(L, "os"); /* . os */ if (lua_isnil(L, -1)) return luaL_error(L, "os not loaded"); copyfields(L, ex_oslib, ex, -1); luaopen_os_path(L); /* extend the io table */ lua_getglobal(L, "io"); /* . io */ if (lua_isnil(L, -1)) return luaL_error(L, "io not loaded"); copyfields(L, ex_iolib, ex, -1); // copyfields(L, ex_iolib, ex, -1); lua_getfield(L, ex, "pipe"); /* . io ex_pipe */ newfenv(L, pipe_close); /* create environment for 'popen' */ lua_setfenv(L, -2); /* set fenv for 'popen' */ lua_pop(L, 1); /* pop 'popen' */ /* extend the io.file metatable */ luaL_getmetatable(L, LUA_FILEHANDLE); /* . F */ if (lua_isnil(L, -1)) return luaL_error(L, "can't find FILE* metatable"); copyfields(L, ex_iofile_methods, ex, -1); luaopen_windows_hkey(L); return 1; }