| 1 | /* melder_trust.cpp |
| 2 | * |
| 3 | * Copyright (C) 2024,2026 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "Interpreter.h" |
| 20 | #include "Script.h" |
| 21 | #include "Notebook.h" |
| 22 | |
| 23 | void MelderTrust::_defaultProc (void *void_interpreter, conststring32 message) { |
| 24 | Interpreter interpreter = (Interpreter) void_interpreter; |
| 25 | if (interpreter) { |
| 26 | Script script = interpreter -> scriptReference; |
| 27 | Notebook notebook = interpreter -> notebookReference; |
| 28 | if (Melder_appVersion() < 7000) |
| 29 | return; // no trust checking before Praat 7.0 |
| 30 | if (script && ! script -> trusted) |
| 31 | Melder_throw (U"The following potentially dangerous action was requested by the script “", script -> string.get(), |
| 32 | U"” but is not allowed without --FULL-TRUST:\n\n", message, |
| 33 | U"\n\nUse --FULL-TRUST to prevent this message, but of course only if you indeed trust" |
| 34 | " the intentions and skills of the authors of the script and of the scripts or notebooks it calls." |
| 35 | ); |
| 36 | if (notebook && ! notebook -> trusted) |
| 37 | Melder_throw (U"The following potentially dangerous action was requested by the notebook “", notebook -> string.get(), |
| 38 | U"” but is not allowed without --FULL-TRUST:\n\n", message, |
| 39 | U"\n\nUse --FULL-TRUST to prevent this message, but of course only if you indeed trust" |
| 40 | " the intentions and skills of the authors of the notebook and of the scripts or notebooks it calls." |
| 41 | ); |
| 42 | if (! script && ! notebook) |
| 43 | Melder_throw (U"The following potentially dangerous action was requested" |
| 44 | " but is not allowed without --FULL-TRUST:\n\n", message, |
| 45 | U"\n\nUse --FULL-TRUST to prevent this message, but of course only if you indeed trust" |
| 46 | " the intentions and skills of the authors of the script or notebook and of the scripts or notebooks it calls." |
| 47 | ); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | MelderTrust::Proc MelderTrust::_p_currentProc = & MelderTrust::_defaultProc; |
| 52 | |
| 53 | MelderString MelderTrust::_buffer; |
| 54 | |
| 55 | void Melder_setTrustProc (MelderTrust::Proc p_proc) { |
| 56 | MelderTrust::_p_currentProc = ( p_proc ? p_proc : & MelderTrust::_defaultProc ); |
| 57 | } |
| 58 | |
| 59 | /* End of file melder_trust.cpp */ |