diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-25 09:12:27 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-25 09:12:27 +0300 |
commit | 89eca3384af875dc59f2563c33f8e35a923fbfe1 (patch) | |
tree | 40bdcc105aa8ff3b343fc3f93d44376a7f41acad | |
parent | a81b43d33c7b37996cd04c527917c3651c5cdc65 (diff) |
Encode spaces in URLs
-rw-r--r-- | src/app.c | 42 | ||||
-rw-r--r-- | src/gmrequest.c | 4 | ||||
-rw-r--r-- | src/gmutil.c | 9 | ||||
-rw-r--r-- | src/gmutil.h | 4 | ||||
-rw-r--r-- | src/ui/inputwidget.c | 1 | ||||
-rw-r--r-- | src/ui/window.c | 4 |
6 files changed, 55 insertions, 9 deletions
@@ -45,17 +45,18 @@ void deinit_HistoryItem(iHistoryItem *d) { | |||
45 | } | 45 | } |
46 | 46 | ||
47 | #if defined (iPlatformApple) | 47 | #if defined (iPlatformApple) |
48 | static const char *dataDir_App_ = "~/Library/Application Support/fi.skyjake.Lagrange"; | 48 | static const char *dataDir_App_ = "~/Library/Application Support/fi.skyjake.Lagrange"; |
49 | #endif | 49 | #endif |
50 | #if defined (iPlatformMsys) | 50 | #if defined (iPlatformMsys) |
51 | static const char *dataDir_App_ = "~/AppData/Roaming/fi.skyjake.Lagrange"; | 51 | static const char *dataDir_App_ = "~/AppData/Roaming/fi.skyjake.Lagrange"; |
52 | #endif | 52 | #endif |
53 | #if defined (iPlatformLinux) | 53 | #if defined (iPlatformLinux) |
54 | static const char *dataDir_App_ = "~/.config/lagrange"; | 54 | static const char *dataDir_App_ = "~/.config/lagrange"; |
55 | #endif | 55 | #endif |
56 | static const char *prefsFileName_App_ = "prefs.cfg"; | 56 | static const char *prefsFileName_App_ = "prefs.cfg"; |
57 | static const char *historyFileName_App_ = "history.txt"; | ||
57 | 58 | ||
58 | static const size_t HISTORY_MAX = 100; | 59 | static const size_t historyMax_App_ = 100; |
59 | 60 | ||
60 | struct Impl_App { | 61 | struct Impl_App { |
61 | iCommandLine args; | 62 | iCommandLine args; |
@@ -111,6 +112,10 @@ static const iString *prefsFileName_(void) { | |||
111 | return collect_String(concatCStr_Path(&iStringLiteral(dataDir_App_), prefsFileName_App_)); | 112 | return collect_String(concatCStr_Path(&iStringLiteral(dataDir_App_), prefsFileName_App_)); |
112 | } | 113 | } |
113 | 114 | ||
115 | static const iString *historyFileName_(void) { | ||
116 | return collect_String(concatCStr_Path(&iStringLiteral(dataDir_App_), historyFileName_App_)); | ||
117 | } | ||
118 | |||
114 | static void loadPrefs_App_(iApp *d) { | 119 | static void loadPrefs_App_(iApp *d) { |
115 | iUnused(d); | 120 | iUnused(d); |
116 | /* Create the data dir if it doesn't exist yet. */ | 121 | /* Create the data dir if it doesn't exist yet. */ |
@@ -150,6 +155,30 @@ static void savePrefs_App_(const iApp *d) { | |||
150 | delete_String(cfg); | 155 | delete_String(cfg); |
151 | } | 156 | } |
152 | 157 | ||
158 | static void saveHistory_App_(const iApp *d) { | ||
159 | iFile *f = new_File(historyFileName_()); | ||
160 | if (open_File(f, writeOnly_FileMode | text_FileMode)) { | ||
161 | iString *line = new_String(); | ||
162 | iConstForEach(Array, i, &d->history) { | ||
163 | const iHistoryItem *item = i.value; | ||
164 | iDate date; | ||
165 | init_Date(&date, &item->when); | ||
166 | format_String(line, | ||
167 | "%04d-%02d-%02dT%02d:%02d:%02d %s\n", | ||
168 | date.year, | ||
169 | date.month, | ||
170 | date.day, | ||
171 | date.hour, | ||
172 | date.minute, | ||
173 | date.second, | ||
174 | cstr_String(&item->url)); | ||
175 | writeData_File(f, cstr_String(line), size_String(line)); | ||
176 | } | ||
177 | delete_String(line); | ||
178 | } | ||
179 | iRelease(f); | ||
180 | } | ||
181 | |||
153 | static void clearHistory_App_(iApp *d) { | 182 | static void clearHistory_App_(iApp *d) { |
154 | iForEach(Array, i, &d->history) { | 183 | iForEach(Array, i, &d->history) { |
155 | deinit_HistoryItem(i.value); | 184 | deinit_HistoryItem(i.value); |
@@ -180,6 +209,7 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
180 | 209 | ||
181 | static void deinit_App(iApp *d) { | 210 | static void deinit_App(iApp *d) { |
182 | savePrefs_App_(d); | 211 | savePrefs_App_(d); |
212 | saveHistory_App_(d); | ||
183 | clearHistory_App_(d); | 213 | clearHistory_App_(d); |
184 | deinit_Array(&d->history); | 214 | deinit_Array(&d->history); |
185 | deinit_SortedArray(&d->tickers); | 215 | deinit_SortedArray(&d->tickers); |
@@ -385,7 +415,7 @@ iBool handleCommand_App(const char *cmd) { | |||
385 | set_String(&item.url, url); | 415 | set_String(&item.url, url); |
386 | pushBack_Array(&d->history, &item); | 416 | pushBack_Array(&d->history, &item); |
387 | /* Don't make it too long. */ | 417 | /* Don't make it too long. */ |
388 | if (size_Array(&d->history) > HISTORY_MAX) { | 418 | if (size_Array(&d->history) > historyMax_App_) { |
389 | deinit_HistoryItem(front_Array(&d->history)); | 419 | deinit_HistoryItem(front_Array(&d->history)); |
390 | remove_Array(&d->history, 0); | 420 | remove_Array(&d->history, 0); |
391 | } | 421 | } |
diff --git a/src/gmrequest.c b/src/gmrequest.c index ce53abee..6f2c2bc5 100644 --- a/src/gmrequest.c +++ b/src/gmrequest.c | |||
@@ -73,6 +73,7 @@ void deinit_GmRequest(iGmRequest *d) { | |||
73 | 73 | ||
74 | void setUrl_GmRequest(iGmRequest *d, const iString *url) { | 74 | void setUrl_GmRequest(iGmRequest *d, const iString *url) { |
75 | set_String(&d->url, url); | 75 | set_String(&d->url, url); |
76 | urlEncodeSpaces_String(&d->url); | ||
76 | } | 77 | } |
77 | 78 | ||
78 | static uint32_t timedOutWhileReceivingBody_GmRequest_(uint32_t interval, void *obj) { | 79 | static uint32_t timedOutWhileReceivingBody_GmRequest_(uint32_t interval, void *obj) { |
@@ -174,7 +175,8 @@ void submit_GmRequest(iGmRequest *d) { | |||
174 | iUrl url; | 175 | iUrl url; |
175 | init_Url(&url, &d->url); | 176 | init_Url(&url, &d->url); |
176 | if (!cmpCStrSc_Rangecc(&url.protocol, "file", &iCaseInsensitive)) { | 177 | if (!cmpCStrSc_Rangecc(&url.protocol, "file", &iCaseInsensitive)) { |
177 | iFile *f = new_File(collect_String(newRange_String(url.path))); | 178 | iString *path = collect_String(urlDecode_String(collect_String(newRange_String(url.path)))); |
179 | iFile * f = new_File(path); | ||
178 | if (open_File(f, readOnly_FileMode)) { | 180 | if (open_File(f, readOnly_FileMode)) { |
179 | /* TODO: Check supported file types: images, audio */ | 181 | /* TODO: Check supported file types: images, audio */ |
180 | d->code = success_GmStatusCode; | 182 | d->code = success_GmStatusCode; |
diff --git a/src/gmutil.c b/src/gmutil.c index 07861523..ce50f015 100644 --- a/src/gmutil.c +++ b/src/gmutil.c | |||
@@ -23,3 +23,12 @@ void init_Url(iUrl *d, const iString *text) { | |||
23 | } | 23 | } |
24 | iRelease(pattern); | 24 | iRelease(pattern); |
25 | } | 25 | } |
26 | |||
27 | void urlEncodeSpaces_String(iString *d) { | ||
28 | for (;;) { | ||
29 | const size_t pos = indexOfCStr_String(d, " "); | ||
30 | if (pos == iInvalidPos) break; | ||
31 | remove_Block(&d->chars, pos, 1); | ||
32 | insertData_Block(&d->chars, pos, "%20", 3); | ||
33 | } | ||
34 | } | ||
diff --git a/src/gmutil.h b/src/gmutil.h index 264ad8a8..41711af7 100644 --- a/src/gmutil.h +++ b/src/gmutil.h | |||
@@ -13,4 +13,6 @@ struct Impl_Url { | |||
13 | iRangecc query; | 13 | iRangecc query; |
14 | }; | 14 | }; |
15 | 15 | ||
16 | void init_Url(iUrl *d, const iString *text); | 16 | void init_Url (iUrl *, const iString *text); |
17 | |||
18 | void urlEncodeSpaces_String (iString *); | ||
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c index 22b30616..e23e5acc 100644 --- a/src/ui/inputwidget.c +++ b/src/ui/inputwidget.c | |||
@@ -311,6 +311,7 @@ static void draw_InputWidget_(const iInputWidget *d) { | |||
311 | add_I2(topLeft_Rect(bounds), | 311 | add_I2(topLeft_Rect(bounds), |
312 | init_I2(xOff, yOff)), | 312 | init_I2(xOff, yOff)), |
313 | white_ColorId, | 313 | white_ColorId, |
314 | "%s", | ||
314 | cstr_String(&text)); | 315 | cstr_String(&text)); |
315 | clearClip_Paint(&p); | 316 | clearClip_Paint(&p); |
316 | /* Cursor blinking. */ | 317 | /* Cursor blinking. */ |
diff --git a/src/ui/window.c b/src/ui/window.c index 896b1e66..e08f6d6c 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -78,7 +78,9 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { | |||
78 | if (equal_Command(cmd, "input.ended")) { | 78 | if (equal_Command(cmd, "input.ended")) { |
79 | iInputWidget *url = findChild_Widget(navBar, "url"); | 79 | iInputWidget *url = findChild_Widget(navBar, "url"); |
80 | if (arg_Command(cmd) && pointer_Command(cmd) == url) { | 80 | if (arg_Command(cmd) && pointer_Command(cmd) == url) { |
81 | postCommandf_App("open url:%s", cstr_String(text_InputWidget(url))); | 81 | postCommandf_App( |
82 | "open url:%s", | ||
83 | cstr_String(text_InputWidget(url))); | ||
82 | return iTrue; | 84 | return iTrue; |
83 | } | 85 | } |
84 | } | 86 | } |