1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-26 01:15:37 +00:00

[dgi] Some code for cdplayer.dgi

This commit is contained in:
Witold Filipczyk 2022-05-17 22:21:16 +02:00
parent f4979cb5a4
commit ced830020b
3 changed files with 61 additions and 17 deletions

View File

@ -46,6 +46,9 @@
/* Define if you want: Debug mode support */ /* Define if you want: Debug mode support */
#mesondefine CONFIG_DEBUG #mesondefine CONFIG_DEBUG
/* Define if you want: DGI support */
#mesondefine CONFIG_DGI
/* Define if you want: Documentation Tools support */ /* Define if you want: Documentation Tools support */
#mesondefine CONFIG_DOC #mesondefine CONFIG_DOC

View File

@ -53,8 +53,8 @@ struct dgi_entry {
const char *cmdline; const char *cmdline;
}; };
struct dgi_entry *entries[] = { struct dgi_entry entries[] = {
{ "cdplayer.dgi", "cdplayer.exe $q" }, { "cdplayer.dgi", "cdplayer.exe $s > $2" },
NULL NULL
}; };
@ -71,8 +71,19 @@ struct module dgi_protocol_module = struct_module(
static struct dgi_entry * static struct dgi_entry *
find_dgi(const char *name) find_dgi(const char *name)
{ {
if (!strcmp(name, "cdplayer.dgi")) { const char *last = strrchr(name, '/');
return entries[0]; struct dgi_entry *entry;
if (last) {
name = last + 1;
}
for (entry = entries; entry; entry++) {
if (!entry->name) break;
if (!strcmp(name, entry->name)) {
return entry;
}
} }
return NULL; return NULL;
@ -100,40 +111,55 @@ write_request_to_file(struct connection *conn, const char *filename)
enum dgi_state { enum dgi_state {
NORMAL, NORMAL,
DOLAR DOLAR,
PERCENT
}; };
static void static void
prepare_command(struct dgi_entry *entry, struct string *cmd, char **temp, char **out) prepare_command(struct dgi_entry *entry, const char *query, struct string *cmd, char **inp, char **out)
{ {
const char *ch; const char *ch;
dgi_state state = NORMAL; dgi_state state = NORMAL;
for (ch = entry->cmdline; *ch; ch++) { for (ch = entry->cmdline; *ch; ch++) {
switch (state) { switch (state) {
NORMAL: case NORMAL:
default: default:
if (*ch == '$') { if (*ch == '$') {
state = DOLAR; state = DOLAR;
} else if (*ch == '%') {
state = PERCENT;
} else { } else {
add_char_to_string(cmd, *ch); add_char_to_string(cmd, *ch);
} }
break; break;
case DOLAR: case DOLAR:
case PERCENT:
switch(*ch) { switch(*ch) {
case 'q': case 'e':
add_to_string(cmd, post); break;
state = NORMAL; case 's':
case 't': if (query) {
*temp = tempnam(); add_to_string(cmd, query);
}
state = NORMAL; state = NORMAL;
break; break;
case 'o': case '1':
*out = tempnam(); *inp = tempname(NULL, "elinks", ".txt");
if (*inp) {
add_to_string(cmd, *inp);
}
state = NORMAL;
break;
case '2':
*out = tempname(NULL, "elinks", ".htm");
if (*out) {
add_to_string(cmd, *out);
}
state = NORMAL; state = NORMAL;
break; break;
default: default:
add_to_string(cmd, *ch); add_char_to_string(cmd, *ch);
break; break;
} }
break; break;
@ -166,7 +192,7 @@ execute_dgi(struct connection *conn)
entry = find_dgi(script); entry = find_dgi(script);
if (!entry) { if (!entry) {
mem_free(script); mem_free(script);
return 0; return 1;
} }
if (!init_string(&command)) { if (!init_string(&command)) {
@ -174,12 +200,20 @@ execute_dgi(struct connection *conn)
return 0; return 0;
} }
prepare_command(entry, &command, &tempfilename, &outputfilename); char *query = get_uri_string(conn->uri, URI_QUERY);
prepare_command(entry, query, &command, &tempfilename, &outputfilename);
mem_free_if(query);
if (tempfilename) { if (tempfilename) {
write_request_to_file(conn, tempfilename); write_request_to_file(conn, tempfilename);
} }
fprintf(stderr, "%s\n", command.source);
system(command.source); system(command.source);
done_string(&command); done_string(&command);
mem_free(script); mem_free(script);
@ -189,6 +223,8 @@ execute_dgi(struct connection *conn)
} }
if (!outputfilename) { if (!outputfilename) {
state = connection_state(S_OK);
abort_connection(conn, state);
return 0; return 0;
} }

View File

@ -32,6 +32,7 @@
#include "osdep/osdep.h" #include "osdep/osdep.h"
#include "protocol/common.h" #include "protocol/common.h"
#include "protocol/file/cgi.h" #include "protocol/file/cgi.h"
#include "protocol/file/dgi.h"
#include "protocol/file/file.h" #include "protocol/file/file.h"
#include "protocol/http/http.h" #include "protocol/http/http.h"
#include "protocol/uri.h" #include "protocol/uri.h"
@ -265,6 +266,10 @@ file_protocol_handler(struct connection *connection)
if (!execute_cgi(connection)) return; if (!execute_cgi(connection)) return;
#endif /* CONFIG_CGI */ #endif /* CONFIG_CGI */
#ifdef CONFIG_DGI
if (!execute_dgi(connection)) return;
#endif
/* Treat /dev/stdin in special way */ /* Treat /dev/stdin in special way */
if (!strcmp(connection->uri->string, "file:///dev/stdin")) { if (!strcmp(connection->uri->string, "file:///dev/stdin")) {
int fd = open("/dev/stdin", O_RDONLY); int fd = open("/dev/stdin", O_RDONLY);