Skip to content

Commit

Permalink
Merge branch 'gemini' into guppy
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Oct 24, 2023
2 parents 4e27895 + fbe4ed5 commit 69caa36
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
9 changes: 9 additions & 0 deletions com.github.dimkr.gplaces.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
<developer_name>Dima Krasner</developer_name>

<releases>
<release date="2023-09-09" version="0.17.11">
<description>
<ul>
<li>Updated aliases in the default configuration file</li>
<li>Nicer printing of the handler program exit code</li>
</ul>
</description>
</release>

<release date="2023-08-10" version="0.17.10">
<description>
<ul>
Expand Down
24 changes: 13 additions & 11 deletions gplaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,18 +652,18 @@ static void reap(const char *command, pid_t pid, int silent) {
}


static pid_t start_handler(const char *handler, const char *filename, const Selector *sel, const URL *url, int stdin) {
static char command[1024], buffer[sizeof("/proc/self/fd/2147483647")];
size_t l;
static pid_t start_handler(const char *handler, const char *filename, char *command, size_t length, const Selector *sel, const URL *url, int stdin) {
static char buffer[sizeof("/proc/self/fd/2147483647")];
size_t i;
pid_t pid;

if (stdin != -1) {
sprintf(buffer, "/proc/self/fd/%d", stdin);
filename = buffer;
}

for (l = 0; *handler && l < sizeof(command) - 1; ) {
if (handler[0] == '%' && handler[1] != '\0') {
for (i = 0; *handler && i < length - 1; ) {
if (handler[0] == '%' && handler[i] != '\0') {
const char *append = "";
switch (handler[1]) {
case '%': append = "%"; break;
Expand All @@ -676,10 +676,10 @@ static pid_t start_handler(const char *handler, const char *filename, const Sele
case 'f': append = filename; break;
}
handler += 2;
while (*append && l < sizeof(command) - 1) command[l++] = *append++;
} else command[l++] = *handler++;
while (*append && i < length - 1) command[i++] = *append++;
} else command[i++] = *handler++;
}
command[l] = '\0';
command[i] = '\0';

if ((pid = fork()) == 0) {
#ifdef GPLACES_USE_FLATPAK_SPAWN
Expand All @@ -698,8 +698,9 @@ static pid_t start_handler(const char *handler, const char *filename, const Sele


static void execute_handler(const char *handler, const char *filename, const Selector *sel, const URL *url) {
static char command[1024];
pid_t pid;
if ((pid = start_handler(handler, filename, sel, url, -1)) > 0) reap(handler, pid, 0);
if ((pid = start_handler(handler, filename, command, sizeof(command), sel, url, -1)) > 0) reap(command, pid, 0);
}


Expand Down Expand Up @@ -1158,6 +1159,7 @@ static const char *get_filename(const URL *url, size_t *len) {


static void stream_to_handler(const Selector *sel, URL *url, const char *filename) {
static char command[1024];
int fds[2];
char *mime = NULL;
void *c;
Expand All @@ -1170,12 +1172,12 @@ static void stream_to_handler(const Selector *sel, URL *url, const char *filenam
if (fcntl(fds[1], F_SETFD, FD_CLOEXEC) == 0 && (fp = fdopen(fds[1], "w")) != NULL) {
setbuf(fp, NULL);
if ((c = url->proto->download(sel, url, &mime, &parser, 1)) != NULL) {
if ((handler = find_mime_handler(mime)) != NULL && (pid = start_handler(handler, filename, sel, url, fds[0])) > 0) {
if ((handler = find_mime_handler(mime)) != NULL && (pid = start_handler(handler, filename, command, sizeof(command), sel, url, fds[0])) > 0) {
close(fds[0]); fds[0] = -1;
save_body(url, c, fp);
fclose(fp); fp = NULL;
url->proto->close(c); /* close the connection while the handler is running */
reap(handler, pid, 0);
reap(command, pid, 0);
} else url->proto->close(c);
}
if (fds[0] != -1) close(fds[0]);
Expand Down
3 changes: 2 additions & 1 deletion gplacesrc.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ set license file://DOCDIR/LICENSE
set authors file://DOCDIR/AUTHORS
set search geminispace.info/search
set gsearch gopher://gopher.floodgap.com/7/v2/vs
set home gemini.circumlunar.space
set home geminiprotocol.net
set capcom gemini.circumlunar.space/capcom
set spacewalk rawtext.club/~sloum/spacewalk.gmi
set gmisub calcuode.com/gmisub-aggregate.gmi
set bbs bbs.geminispace.org
set station station.martinrue.com
set geddit geddit.glv.one
set antenna warmedal.se/~antenna/
Expand Down

0 comments on commit 69caa36

Please sign in to comment.