summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-12-06 14:23:15 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-12-06 14:23:15 +0200
commit10d5a1ea2ded21623d1abcb6a955f5098faad334 (patch)
tree52e07514e38d466aa0cd42974a1e9a583a66b7a4 /src
parent6a565ea71745aaf4c91a7698bbf56f7d906fcaaa (diff)
Report errors in MIME hooks; added to about:debug
Diffstat (limited to 'src')
-rw-r--r--src/app.c10
-rw-r--r--src/mimehooks.c41
-rw-r--r--src/mimehooks.h2
3 files changed, 52 insertions, 1 deletions
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) {
502 iConstForEach(StringList, j, d->launchCommands) { 502 iConstForEach(StringList, j, d->launchCommands) {
503 appendFormat_String(msg, "%s\n", cstr_String(j.value)); 503 appendFormat_String(msg, "%s\n", cstr_String(j.value));
504 } 504 }
505 appendFormat_String(msg, "## MIME hooks\n");
506 append_String(msg, debugInfo_MimeHooks(d->mimehooks));
505 return msg; 507 return msg;
506} 508}
507 509
@@ -1034,7 +1036,13 @@ iBool willUseProxy_App(const iRangecc scheme) {
1034 1036
1035iBool handleCommand_App(const char *cmd) { 1037iBool handleCommand_App(const char *cmd) {
1036 iApp *d = &app_; 1038 iApp *d = &app_;
1037 if (equal_Command(cmd, "prefs.dialogtab")) { 1039 if (equal_Command(cmd, "config.error")) {
1040 makeMessage_Widget(uiTextCaution_ColorEscape "CONFIG ERROR",
1041 format_CStr("Error in config file: %s\nSee \"about:debug\" for details.",
1042 suffixPtr_Command(cmd, "where")));
1043 return iTrue;
1044 }
1045 else if (equal_Command(cmd, "prefs.dialogtab")) {
1038 d->prefs.dialogTab = arg_Command(cmd); 1046 d->prefs.dialogTab = arg_Command(cmd);
1039 return iTrue; 1047 return iTrue;
1040 } 1048 }
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 @@
1#include "mimehooks.h" 1#include "mimehooks.h"
2#include "app.h"
2 3
3#include <the_Foundation/file.h> 4#include <the_Foundation/file.h>
5#include <the_Foundation/fileinfo.h>
4#include <the_Foundation/path.h> 6#include <the_Foundation/path.h>
5#include <the_Foundation/process.h> 7#include <the_Foundation/process.h>
6#include <the_Foundation/stringlist.h> 8#include <the_Foundation/stringlist.h>
@@ -23,6 +25,7 @@ void deinit_FilterHook(iFilterHook *d) {
23 25
24void setMimePattern_FilterHook(iFilterHook *d, const iString *pattern) { 26void setMimePattern_FilterHook(iFilterHook *d, const iString *pattern) {
25 iReleasePtr(&d->mimeRegex); 27 iReleasePtr(&d->mimeRegex);
28 set_String(&d->mimePattern, pattern);
26 d->mimeRegex = new_RegExp(cstr_String(pattern), caseInsensitive_RegExpOption); 29 d->mimeRegex = new_RegExp(cstr_String(pattern), caseInsensitive_RegExpOption);
27} 30}
28 31
@@ -105,6 +108,7 @@ iBlock *tryFilter_MimeHooks(const iMimeHooks *d, const iString *mime, const iBlo
105static const char *mimeHooksFilename_MimeHooks_ = "mimehooks.txt"; 108static const char *mimeHooksFilename_MimeHooks_ = "mimehooks.txt";
106 109
107void load_MimeHooks(iMimeHooks *d, const char *saveDir) { 110void load_MimeHooks(iMimeHooks *d, const char *saveDir) {
111 iBool reportError = iFalse;
108 iFile *f = newCStr_File(concatPath_CStr(saveDir, mimeHooksFilename_MimeHooks_)); 112 iFile *f = newCStr_File(concatPath_CStr(saveDir, mimeHooksFilename_MimeHooks_));
109 if (open_File(f, read_FileMode | text_FileMode)) { 113 if (open_File(f, read_FileMode | text_FileMode)) {
110 iBlock * src = readAll_File(f); 114 iBlock * src = readAll_File(f);
@@ -124,6 +128,15 @@ void load_MimeHooks(iMimeHooks *d, const char *saveDir) {
124 setRange_String(&hook->label, lines[0]); 128 setRange_String(&hook->label, lines[0]);
125 setMimePattern_FilterHook(hook, collect_String(newRange_String(lines[1]))); 129 setMimePattern_FilterHook(hook, collect_String(newRange_String(lines[1])));
126 setCommand_FilterHook(hook, collect_String(newRange_String(lines[2]))); 130 setCommand_FilterHook(hook, collect_String(newRange_String(lines[2])));
131 /* Check if commmand is valid. */ {
132 iRangecc seg = iNullRange;
133 while (nextSplit_Rangecc(range_String(&hook->command), ";", &seg)) {
134 if (!fileExistsCStr_FileInfo(cstr_Rangecc(seg))) {
135 reportError = iTrue;
136 }
137 break;
138 }
139 }
127 pushBack_PtrArray(&d->filters, hook); 140 pushBack_PtrArray(&d->filters, hook);
128 pos = 0; 141 pos = 0;
129 } 142 }
@@ -131,9 +144,37 @@ void load_MimeHooks(iMimeHooks *d, const char *saveDir) {
131 delete_Block(src); 144 delete_Block(src);
132 } 145 }
133 iRelease(f); 146 iRelease(f);
147 if (reportError) {
148 postCommand_App("~config.error where:mimehooks.txt");
149 }
134} 150}
135 151
136void save_MimeHooks(const iMimeHooks *d) { 152void save_MimeHooks(const iMimeHooks *d) {
137 iUnused(d); 153 iUnused(d);
138} 154}
139 155
156const iString *debugInfo_MimeHooks(const iMimeHooks *d) {
157 iString *str = collectNew_String();
158 size_t index = 0;
159 iConstForEach(PtrArray, i, &d->filters) {
160 const iFilterHook *filter = i.ptr;
161 appendFormat_String(str, "### %d: %s\n", index, cstr_String(&filter->label));
162 appendFormat_String(str, "MIME regex:\n```\n%s\n```\n", cstr_String(&filter->mimePattern));
163 iStringList *args = iClob(split_String(&filter->command, ";"));
164 if (isEmpty_StringList(args)) {
165 appendFormat_String(str, "\u26a0 Command not specified!\n");
166 continue;
167 }
168 const iString *exec = constAt_StringList(args, 0);
169 if (isEmpty_String(exec)) {
170 appendFormat_String(str, "\u26a0 Command not specified!\n");
171 }
172 else {
173 appendFormat_String(str, "Executable: %s\n```\n%s\n```\n",
174 fileExists_FileInfo(exec) ? "" : "\u26a0 FILE NOT FOUND",
175 cstr_String(exec));
176 }
177 index++;
178 }
179 return str;
180}
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,
29 29
30void load_MimeHooks (iMimeHooks *, const char *saveDir); 30void load_MimeHooks (iMimeHooks *, const char *saveDir);
31void save_MimeHooks (const iMimeHooks *); 31void save_MimeHooks (const iMimeHooks *);
32
33const iString *debugInfo_MimeHooks (const iMimeHooks *);