CGI: Add download mode. Default charset UTF8.

This commit is contained in:
Fabian Kurz 2020-05-22 21:46:11 +02:00
parent f514a80e7d
commit 03a558dfd4
2 changed files with 24 additions and 2 deletions

View File

@ -1,4 +1,4 @@
0.8.3 / 2020-04-15 Fabian Kurz <fabian@fkurz.net>
0.8.3 / 2020-05-24 Fabian Kurz <fabian@fkurz.net>
* Added lowercase Greek alphabet
* Added multiple language support by GNU gettext.
* Added text command |Sx will add x (1 < x < 20000) milliseconds
@ -7,6 +7,7 @@
a hash sign (#) will be treated as such (suggested by DM3DA)
* Warning message for unknown characters improved (tells line
number and character position; suggested by DL2KI)
* CGI mode accepts UTF8 by default, download mode added
0.8.2 / 2013-01-04 Fabian Kurz <fabian@fkurz.net>
* Time of conversion and speed-up calculations

View File

@ -336,6 +336,8 @@ int main (int argc, char** argv) {
#ifdef CGI
/* CGI: utf8 input by default */
cw.encoding = UTF8;
/* CGI standard: write directly to stdout ==> no Content-Length possible
* CGI buffered: write to file /tmp/$time-$rnd and later generate output */
#ifndef CGIBUFFERED
@ -374,7 +376,22 @@ int main (int argc, char** argv) {
if ((querystring == NULL) || strlen(querystring) > 9000) {
exit(1);
}
sscanf(querystring, "s=%d&e=%d&f=%d&t=%9000s", &cw.wpm, &cw.farnsworth, &cw.freq, text);
/* the query parameters may look like:
* d=001&s=25&e=20&f=600&t=text => download, offer as filename "lcwo-001.mp3"
* s=25&e=20&f=600&t=text => return normal file
*/
int download = 0;
printf("QS: >%s<\n", querystring);
if (querystring[0] == 'd') {
sscanf(querystring, "d=%d&s=%d&e=%d&f=%d&t=%9000s", &download, &cw.wpm, &cw.farnsworth, &cw.freq, text);
}
else {
sscanf(querystring, "s=%d&e=%d&f=%d&t=%9000s", &cw.wpm, &cw.farnsworth, &cw.freq, text);
}
strcat(text, " ");
urldecode(text);
@ -553,6 +570,10 @@ int main (int argc, char** argv) {
free(cw.dah_buf);
free(cw.dit_buf);
if (download) {
printf("Content-Disposition: attachment; filename=\"lcwo-%03d.txt\"\n", download);
}
#ifdef CGIBUFFERED
/* File is completed, so we know the length and can send the
* content length header, and then the whole file */