diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-12-07 21:31:56 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-12-07 21:31:56 +0200 |
commit | f60c945da324c82eb0d4c10ffa5ba9e48bbe6141 (patch) | |
tree | 78df140328302700f2b84b70c4ba5ef75d36d6cd /src | |
parent | 73c96402a21872dba8999caba8f4374a91f0d8e4 (diff) |
Set REQUEST_URL in the MIME hook environment
This time without a race.
IssueID #90
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 4 | ||||
-rw-r--r-- | src/gmrequest.c | 4 | ||||
-rw-r--r-- | src/mimehooks.c | 14 | ||||
-rw-r--r-- | src/mimehooks.h | 2 |
4 files changed, 16 insertions, 8 deletions
@@ -550,7 +550,7 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
550 | if (ev.type == SDL_USEREVENT && ev.user.code == asleep_UserEventCode) { | 550 | if (ev.type == SDL_USEREVENT && ev.user.code == asleep_UserEventCode) { |
551 | if (SDL_GetTicks() - d->lastEventTime > idleThreshold_App_) { | 551 | if (SDL_GetTicks() - d->lastEventTime > idleThreshold_App_) { |
552 | if (!d->isIdling) { | 552 | if (!d->isIdling) { |
553 | printf("[App] idling...\n"); | 553 | // printf("[App] idling...\n"); |
554 | fflush(stdout); | 554 | fflush(stdout); |
555 | } | 555 | } |
556 | d->isIdling = iTrue; | 556 | d->isIdling = iTrue; |
@@ -559,7 +559,7 @@ void processEvents_App(enum iAppEventMode eventMode) { | |||
559 | } | 559 | } |
560 | d->lastEventTime = SDL_GetTicks(); | 560 | d->lastEventTime = SDL_GetTicks(); |
561 | if (d->isIdling) { | 561 | if (d->isIdling) { |
562 | printf("[App] ...woke up\n"); | 562 | // printf("[App] ...woke up\n"); |
563 | fflush(stdout); | 563 | fflush(stdout); |
564 | } | 564 | } |
565 | d->isIdling = iFalse; | 565 | d->isIdling = iFalse; |
diff --git a/src/gmrequest.c b/src/gmrequest.c index fe026a5b..884486b3 100644 --- a/src/gmrequest.c +++ b/src/gmrequest.c | |||
@@ -263,8 +263,8 @@ static void requestFinished_GmRequest_(iGmRequest *d, iTlsRequest *req) { | |||
263 | unlock_Mutex(d->mtx); | 263 | unlock_Mutex(d->mtx); |
264 | /* Check for mimehooks. */ | 264 | /* Check for mimehooks. */ |
265 | if (d->isRespFiltered && d->state == finished_GmRequestState) { | 265 | if (d->isRespFiltered && d->state == finished_GmRequestState) { |
266 | setenv("REQUEST_URL", cstr_String(&d->url), 1); | 266 | iBlock *xbody = |
267 | iBlock *xbody = tryFilter_MimeHooks(mimeHooks_App(), &d->resp->meta, &d->resp->body); | 267 | tryFilter_MimeHooks(mimeHooks_App(), &d->resp->meta, &d->resp->body, &d->url); |
268 | if (xbody) { | 268 | if (xbody) { |
269 | lock_Mutex(d->mtx); | 269 | lock_Mutex(d->mtx); |
270 | clear_String(&d->resp->meta); | 270 | clear_String(&d->resp->meta); |
diff --git a/src/mimehooks.c b/src/mimehooks.c index 8f1eb9db..5a1f0a9e 100644 --- a/src/mimehooks.c +++ b/src/mimehooks.c | |||
@@ -33,7 +33,8 @@ void setCommand_FilterHook(iFilterHook *d, const iString *command) { | |||
33 | set_String(&d->command, command); | 33 | set_String(&d->command, command); |
34 | } | 34 | } |
35 | 35 | ||
36 | iBlock *run_FilterHook_(const iFilterHook *d, const iString *mime, const iBlock *body) { | 36 | iBlock *run_FilterHook_(const iFilterHook *d, const iString *mime, const iBlock *body, |
37 | const iString *requestUrl) { | ||
37 | iProcess * proc = new_Process(); | 38 | iProcess * proc = new_Process(); |
38 | iStringList *args = new_StringList(); | 39 | iStringList *args = new_StringList(); |
39 | iRangecc seg = iNullRange; | 40 | iRangecc seg = iNullRange; |
@@ -46,6 +47,12 @@ iBlock *run_FilterHook_(const iFilterHook *d, const iString *mime, const iBlock | |||
46 | } | 47 | } |
47 | setArguments_Process(proc, args); | 48 | setArguments_Process(proc, args); |
48 | iRelease(args); | 49 | iRelease(args); |
50 | if (!isEmpty_String(requestUrl)) { | ||
51 | setEnvironment_Process( | ||
52 | proc, | ||
53 | newStrings_StringList( | ||
54 | collectNewFormat_String("REQUEST_URL=%s", cstr_String(requestUrl)), NULL)); | ||
55 | } | ||
49 | iBlock *output = NULL; | 56 | iBlock *output = NULL; |
50 | if (start_Process(proc)) { | 57 | if (start_Process(proc)) { |
51 | writeInput_Process(proc, body); | 58 | writeInput_Process(proc, body); |
@@ -92,13 +99,14 @@ iBool willTryFilter_MimeHooks(const iMimeHooks *d, const iString *mime) { | |||
92 | return iFalse; | 99 | return iFalse; |
93 | } | 100 | } |
94 | 101 | ||
95 | iBlock *tryFilter_MimeHooks(const iMimeHooks *d, const iString *mime, const iBlock *body) { | 102 | iBlock *tryFilter_MimeHooks(const iMimeHooks *d, const iString *mime, const iBlock *body, |
103 | const iString *requestUrl) { | ||
96 | iRegExpMatch m; | 104 | iRegExpMatch m; |
97 | iConstForEach(PtrArray, i, &d->filters) { | 105 | iConstForEach(PtrArray, i, &d->filters) { |
98 | const iFilterHook *xc = i.ptr; | 106 | const iFilterHook *xc = i.ptr; |
99 | init_RegExpMatch(&m); | 107 | init_RegExpMatch(&m); |
100 | if (matchString_RegExp(xc->mimeRegex, mime, &m)) { | 108 | if (matchString_RegExp(xc->mimeRegex, mime, &m)) { |
101 | iBlock *result = run_FilterHook_(xc, mime, body); | 109 | iBlock *result = run_FilterHook_(xc, mime, body, requestUrl); |
102 | if (result) { | 110 | if (result) { |
103 | return result; | 111 | return result; |
104 | } | 112 | } |
diff --git a/src/mimehooks.h b/src/mimehooks.h index 7a8cd2c9..6da14fdf 100644 --- a/src/mimehooks.h +++ b/src/mimehooks.h | |||
@@ -25,7 +25,7 @@ iDeclareTypeConstruction(MimeHooks) | |||
25 | 25 | ||
26 | iBool willTryFilter_MimeHooks (const iMimeHooks *, const iString *mime); | 26 | iBool willTryFilter_MimeHooks (const iMimeHooks *, const iString *mime); |
27 | iBlock * tryFilter_MimeHooks (const iMimeHooks *, const iString *mime, | 27 | iBlock * tryFilter_MimeHooks (const iMimeHooks *, const iString *mime, |
28 | const iBlock *body); | 28 | const iBlock *body, const iString *requestUrl); |
29 | 29 | ||
30 | void load_MimeHooks (iMimeHooks *, const char *saveDir); | 30 | void load_MimeHooks (iMimeHooks *, const char *saveDir); |
31 | void save_MimeHooks (const iMimeHooks *); | 31 | void save_MimeHooks (const iMimeHooks *); |