#include <simgear/compiler.h>
-#include STL_STRING
-#include STL_FSTREAM
+#include <string>
+#include <fstream>
#include <simgear/sg_inlines.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/exception.hxx>
#include <simgear/structure/commands.hxx>
#include <simgear/props/props.hxx>
+#include <simgear/structure/event_mgr.hxx>
#include <Cockpit/panel.hxx>
#include <Cockpit/panel_io.hxx>
#include "viewmgr.hxx"
#include "main.hxx"
-SG_USING_STD(string);
-SG_USING_STD(ifstream);
-SG_USING_STD(ofstream);
+using std::string;
+using std::ifstream;
+using std::ofstream;
\f
static bool
do_load (const SGPropertyNode * arg)
{
- const string &file = arg->getStringValue("file", "fgfs.sav");
- ifstream input(file.c_str());
- if (input.good() && fgLoadFlight(input)) {
- input.close();
- SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
- return true;
- } else {
- SG_LOG(SG_INPUT, SG_WARN, "Cannot load flight from " << file);
- return false;
- }
+ string file = arg->getStringValue("file", "fgfs.sav");
+ if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
+ file += ".sav";
+
+ if (!fgValidatePath(file.c_str(), false)) {
+ SG_LOG(SG_IO, SG_ALERT, "load: reading '" << file << "' denied "
+ "(unauthorized access)");
+ return false;
+ }
+
+ ifstream input(file.c_str());
+ if (input.good() && fgLoadFlight(input)) {
+ input.close();
+ SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
+ return true;
+ } else {
+ SG_LOG(SG_INPUT, SG_WARN, "Cannot load flight from " << file);
+ return false;
+ }
}
static bool
do_save (const SGPropertyNode * arg)
{
- const string &file = arg->getStringValue("file", "fgfs.sav");
- bool write_all = arg->getBoolValue("write-all", false);
- SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
- ofstream output(file.c_str());
- if (output.good() && fgSaveFlight(output, write_all)) {
- output.close();
- SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
- return true;
- } else {
- SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
- return false;
- }
+ string file = arg->getStringValue("file", "fgfs.sav");
+ if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
+ file += ".sav";
+
+ if (!fgValidatePath(file.c_str(), false)) {
+ SG_LOG(SG_IO, SG_ALERT, "save: reading '" << file << "' denied "
+ "(unauthorized access)");
+ return false;
+ }
+
+ bool write_all = arg->getBoolValue("write-all", false);
+ SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
+ ofstream output(file.c_str());
+ if (output.good() && fgSaveFlight(output, write_all)) {
+ output.close();
+ SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
+ return true;
+ } else {
+ SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
+ return false;
+ }
}
}
+/**
+ * Adds model to the scenery. The path to the added branch (/models/model[*])
+ * is returned in property "property".
+ */
+static bool
+do_add_model (const SGPropertyNode * arg)
+{
+ SGPropertyNode * model = fgGetNode("models", true);
+ for (int i = 0;; i++) {
+ if (i < 0)
+ return false;
+ if (!model->getChild("model", i, false)) {
+ model = model->getChild("model", i, true);
+ break;
+ }
+ }
+ copyProperties(arg, model);
+ if (model->hasValue("elevation-m"))
+ model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m")
+ * SG_METER_TO_FEET);
+ model->getNode("load", true);
+ model->removeChildren("load");
+ const_cast<SGPropertyNode *>(arg)->setStringValue("property", model->getPath());
+ return true;
+}
+
+
/**
* Set mouse cursor coordinates and cursor shape.
*/
if (file.extension() != "xml")
file.concat(".xml");
+ if (!fgValidatePath(file.c_str(), false)) {
+ SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
+ "(unauthorized access)");
+ return false;
+ }
+
SGPropertyNode *targetnode;
if (arg->hasValue("targetnode"))
targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
return false;
}
- return true;
+ return true;
}
if (file.extension() != "xml")
file.concat(".xml");
+ if (!fgValidatePath(file.c_str(), true)) {
+ SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file.str() << "' denied "
+ "(unauthorized access)");
+ return false;
+ }
+
SGPropertyNode *sourcenode;
if (arg->hasValue("sourcenode"))
sourcenode = fgGetNode(arg->getStringValue("sourcenode"), true);
{ "dialog-update", do_dialog_update },
{ "dialog-apply", do_dialog_apply },
{ "gui-redraw", do_gui_redraw },
+ { "add-model", do_add_model },
{ "set-cursor", do_set_cursor },
{ "play-audio-sample", do_play_audio_sample },
{ "presets-commit", do_presets_commit },