From 10d5a1ea2ded21623d1abcb6a955f5098faad334 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= jaakko.keranen@iki.fi
Date: Sun, 6 Dec 2020 14:23:15 +0200
Subject: [PATCH 1/1] Report errors in MIME hooks; added to about:debug
src/app.c | 10 +++++++++-
src/mimehooks.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/mimehooks.h | 2 ++
3 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/src/app.c b/src/app.c
index ba7d41d2..da6a343f 100644
--- a/src/app.c
+++ b/src/app.c
@@ -502,6 +502,8 @@ const iString *debugInfo_App(void) {
iConstForEach(StringList, j, d->launchCommands) {
appendFormat_String(msg, "%s\n", cstr_String(j.value));
}
return msg;
}
@@ -1034,7 +1036,13 @@ iBool willUseProxy_App(const iRangecc scheme) {
iBool handleCommand_App(const char *cmd) {
iApp *d = &app_;
makeMessage_Widget(uiTextCaution_ColorEscape "CONFIG ERROR",
format_CStr("Error in config file: %s\nSee \"about:debug\" for details.",
suffixPtr_Command(cmd, "where")));
return iTrue;
d->prefs.dialogTab = arg_Command(cmd);
return iTrue;
}
diff --git a/src/mimehooks.c b/src/mimehooks.c
index 8bb838ef..fd535643 100644
--- a/src/mimehooks.c
+++ b/src/mimehooks.c
@@ -1,6 +1,8 @@
#include "mimehooks.h"
+#include "app.h"
#include <the_Foundation/file.h>
+#include <the_Foundation/fileinfo.h>
#include <the_Foundation/path.h>
#include <the_Foundation/process.h>
#include <the_Foundation/stringlist.h>
@@ -23,6 +25,7 @@ void deinit_FilterHook(iFilterHook *d) {
void setMimePattern_FilterHook(iFilterHook *d, const iString *pattern) {
iReleasePtr(&d->mimeRegex);
d->mimeRegex = new_RegExp(cstr_String(pattern), caseInsensitive_RegExpOption);
}
@@ -105,6 +108,7 @@ iBlock *tryFilter_MimeHooks(const iMimeHooks *d, const iString *mime, const iBlo
static const char *mimeHooksFilename_MimeHooks_ = "mimehooks.txt";
void load_MimeHooks(iMimeHooks *d, const char *saveDir) {
iFile *f = newCStr_File(concatPath_CStr(saveDir, mimeHooksFilename_MimeHooks_));
if (open_File(f, read_FileMode | text_FileMode)) {
iBlock * src = readAll_File(f);
@@ -124,6 +128,15 @@ void load_MimeHooks(iMimeHooks *d, const char *saveDir) {
setRange_String(&hook->label, lines[0]);
setMimePattern_FilterHook(hook, collect_String(newRange_String(lines[1])));
setCommand_FilterHook(hook, collect_String(newRange_String(lines[2])));
/* Check if commmand is valid. */ {
iRangecc seg = iNullRange;
while (nextSplit_Rangecc(range_String(&hook->command), ";", &seg)) {
if (!fileExistsCStr_FileInfo(cstr_Rangecc(seg))) {
reportError = iTrue;
}
break;
}
}
pushBack_PtrArray(&d->filters, hook);
pos = 0;
}
@@ -131,9 +144,37 @@ void load_MimeHooks(iMimeHooks *d, const char *saveDir) {
delete_Block(src);
}
iRelease(f);
postCommand_App("~config.error where:mimehooks.txt");
}
void save_MimeHooks(const iMimeHooks *d) {
iUnused(d);
}
+const iString *debugInfo_MimeHooks(const iMimeHooks *d) {
const iFilterHook *filter = i.ptr;
appendFormat_String(str, "### %d: %s\n", index, cstr_String(&filter->label));
appendFormat_String(str, "MIME regex:\n```\n%s\n```\n", cstr_String(&filter->mimePattern));
iStringList *args = iClob(split_String(&filter->command, ";"));
if (isEmpty_StringList(args)) {
appendFormat_String(str, "\u26a0 Command not specified!\n");
continue;
}
const iString *exec = constAt_StringList(args, 0);
if (isEmpty_String(exec)) {
appendFormat_String(str, "\u26a0 Command not specified!\n");
}
else {
appendFormat_String(str, "Executable: %s\n```\n%s\n```\n",
fileExists_FileInfo(exec) ? "" : "\u26a0 FILE NOT FOUND",
cstr_String(exec));
}
index++;
+}
diff --git a/src/mimehooks.h b/src/mimehooks.h
index c78a3c86..7a8cd2c9 100644
--- a/src/mimehooks.h
+++ b/src/mimehooks.h
@@ -29,3 +29,5 @@ iBlock * tryFilter_MimeHooks (const iMimeHooks *, const iString *mime,
void load_MimeHooks (iMimeHooks *, const char *saveDir);
void save_MimeHooks (const iMimeHooks *);
+const iString *debugInfo_MimeHooks (const iMimeHooks *);
--
2.25.1
text/plain
This content has been proxied by September (ba2dc).