commit
1f9850aded
3 changed files with 199 additions and 0 deletions
@ -0,0 +1,140 @@ |
|||||
|
/* Bibliothek zur Verarbeitung von gePOSTeten oder geGETeten |
||||
|
* Formulardaten ueber das CGI-Interface an ein C-Programm. |
||||
|
* Es wird der Datenstrom ueber die Standardeingabe bzw. die |
||||
|
* Variable QUERY_STRING gelesen, zerlegt und decodiert. |
||||
|
* Die Zeichenketten werden mit Hilfe der Funktion Feldwert |
||||
|
* zur Verfuegung gestellt. |
||||
|
* |
||||
|
* Weitere Funktion: htmlprint |
||||
|
* Gibt Zeichenkette aus, Umlaute und andere Sonderzeichen |
||||
|
* werden aber durch die HTML-Schreibweise (z. B. "ö"=>"ö") |
||||
|
* ersetzt. Liste der Sonderzeichen ist noch nicht vollstaendig! |
||||
|
*/ |
||||
|
|
||||
|
/* MAX ist die maximale Anzahl Felder, die im Formular enthalten |
||||
|
sein duerfen. Checkboxen zaehlen als 1 Feld */ |
||||
|
#define MAX 50 |
||||
|
|
||||
|
#include <string.h> |
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <alloca.h> |
||||
|
#include "cgilib.h" |
||||
|
|
||||
|
char *Feld [MAX], *Inhalt [MAX]; |
||||
|
char *SZhex[] = {"%20", "%21", "%5c", "%5C", "%23", "%24", "%25", |
||||
|
"%26", "%27", "%28", "%29", |
||||
|
"%b0", "%B0", "%5e", "%5E", |
||||
|
"%2b", "%2B", "%2c", "%2C", "%2f", "%2F", |
||||
|
"%3a", "%3A", "%3b", "%3B", "%3d", "%3D", |
||||
|
"%3f", "%3F", "%0a", "%0A", "%0d", "%0D", |
||||
|
"%e4", "%E4", "%f6", "%F6", "%fc", "%FC", "%df", "%DF", |
||||
|
"%C4", "%c4", "%d6", "%D6", "%dc", "%DC", |
||||
|
"%e9", "%E9", "%e8", "%E8", "%ea", "%EA", |
||||
|
"%e1", "%E1", "%e0", "%E0", "%e2", "%E2", |
||||
|
"%ed", "%ED", "%ec", "%EC", "%ee", "%EE", |
||||
|
"%f3", "%F3", "%f2", "%F2", "%f4", "%F4", |
||||
|
"%fa", "%FA", "%f9", "%F9", "%fb", "%FB", |
||||
|
"%5b", "%5B", "%5d", "%5D", "%7b", "%7B", "%7d", "%7D", |
||||
|
"%3c", "%3C", "%3e", "%3E", "%7c", "%7C", |
||||
|
"%b2", "%B2", "%b3", "%B3", "%b5", "%B5", |
||||
|
"%7e", "%7E", "%a9", "%A9", "%ae", "%AE", |
||||
|
"%99"}; |
||||
|
char SZ[] = " !\\\\#$%&'()°°^^++,,//::;;==??\012\012\015\015ääööüüßßÄÄÖÖÜÜ\ |
||||
|
ééèèêêááààââííììîîóóòòôôúúùùûû[[]]{{}}<<>>||²²³³µµ~~©©®®™"; |
||||
|
|
||||
|
|
||||
|
|
||||
|
void Sonderzeichen (char *s) { |
||||
|
char *x; |
||||
|
int i; |
||||
|
for (i=0; i < strlen (s); i++) { |
||||
|
if (s [i] == '+') s [i] = ' '; |
||||
|
} |
||||
|
for (i=0; i < strlen (SZ); i++) { |
||||
|
while ((x = strstr (s, SZhex [i])) != NULL) { |
||||
|
*x = SZ [i]; |
||||
|
strcpy (x+1, x+3); |
||||
|
} |
||||
|
} |
||||
|
} /* Sonderzeichen */ |
||||
|
|
||||
|
|
||||
|
|
||||
|
void werteeinlesen (void) { |
||||
|
char *zk; |
||||
|
char *ret; |
||||
|
char *inh; |
||||
|
int i=0, len; |
||||
|
|
||||
|
memset (Feld, 0, sizeof (Feld)); |
||||
|
memset (Inhalt, 0, sizeof (Inhalt)); |
||||
|
|
||||
|
if (strcmp (getenv ("REQUEST_METHOD"), "GET") == 0) { |
||||
|
zk = getenv ("QUERY_STRING"); |
||||
|
} else { |
||||
|
len = atoi (getenv ("CONTENT_LENGTH")); |
||||
|
zk = (char *) alloca (len+1); |
||||
|
fread (zk, 1, len, stdin); |
||||
|
} |
||||
|
|
||||
|
ret = strtok (zk, "&"); |
||||
|
while (ret != NULL && i < MAX) { |
||||
|
inh = strchr (ret, '=') + 1; |
||||
|
Sonderzeichen (inh); |
||||
|
Inhalt [i] = (char *) malloc (strlen (inh) + 1); |
||||
|
strcpy (Inhalt [i], inh); |
||||
|
*(--inh) = '\0'; |
||||
|
Feld [i] = (char *) malloc (strlen (ret) + 1); |
||||
|
strcpy (Feld [i], ret); |
||||
|
if (i > 0 && strcmp (Feld [i], Feld [i-1]) == 0) { |
||||
|
/* Feldnamen sind identisch => es war eine Checkbox, |
||||
|
bei der mehrere Alternativen angekreuzt wurden; also |
||||
|
muss der Feldinhalt an das vorige Feld angehaengt |
||||
|
werden, durch Komma getrennt */ |
||||
|
Inhalt [i-1] = (char *) realloc (Inhalt [i-1], |
||||
|
strlen (Inhalt [i-1]) + strlen (Inhalt [i]) + 2); |
||||
|
strcat (Inhalt [i-1], ","); |
||||
|
strcat (Inhalt [i-1], Inhalt [i]); |
||||
|
free (Feld [i]); free (Inhalt [i]); |
||||
|
} else i++; |
||||
|
ret = strtok (NULL, "&"); |
||||
|
} |
||||
|
free (zk); /* wird nicht mehr gebraucht */ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void htmlprint (const char *s) { |
||||
|
int i; |
||||
|
for (i=0; i < strlen (s); i++) { |
||||
|
switch (s[i]) { |
||||
|
case 'ä': fputs ("ä", stdout); break; |
||||
|
case 'ö': fputs ("ö", stdout); break; |
||||
|
case 'ü': fputs ("ü", stdout); break; |
||||
|
case 'Ä': fputs ("Ä", stdout); break; |
||||
|
case 'Ö': fputs ("Ö", stdout); break; |
||||
|
case 'Ü': fputs ("Ü", stdout); break; |
||||
|
case 'ß': fputs ("ß", stdout); break; |
||||
|
default: fputc (s [i], stdout); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
char *Feldwert (const char *Feldname) { |
||||
|
static int init=0; |
||||
|
int i; |
||||
|
if (!init) { |
||||
|
werteeinlesen(); |
||||
|
init=1; |
||||
|
} |
||||
|
for (i=0; i<MAX; i++) { |
||||
|
if (Feld [i] == NULL) return NULL; |
||||
|
if (strcmp (Feldname, Feld [i]) == 0) return Inhalt [i]; |
||||
|
} |
||||
|
return NULL; |
||||
|
} /* Feldwert */ |
||||
|
|
||||
|
|
||||
|
|
||||
@ -0,0 +1,30 @@ |
|||||
|
/* Bibliothek zur Verarbeitung von gePOSTeten oder getGETeten |
||||
|
* Formulardaten ueber das CGI-Interface an ein C-Programm. Bei |
||||
|
* der Methode POST wird der Datenstrom ueber die Standardeingabe |
||||
|
* gelesen, zerlegt und decodiert. Bei der Methode GET wird die |
||||
|
* Environment-Variable QUERY_STRING gelesen, zerlegt und decodiert. |
||||
|
* Die Zeichenketten werden mit Hilfe der Funktion Feldwert zur |
||||
|
* Verfuegung gestellt. |
||||
|
* |
||||
|
* Weitere Funktion: htmlprint |
||||
|
* Gibt Zeichenkette aus, Umlaute und andere Sonderzeichen |
||||
|
* werden aber durch die HTML-Schreibweise (z. B. "ö"=>"ö") |
||||
|
* ersetzt. |
||||
|
*/ |
||||
|
|
||||
|
/* Die maximale Anzahl Felder, die im Formular enthalten sein duerfen, |
||||
|
betraegt zur Zeit 50. Checkboxen zaehlen als 1 Feld */ |
||||
|
|
||||
|
#ifndef CGILIB_INCLUDED |
||||
|
|
||||
|
#define CGILIB_INCLUDED |
||||
|
|
||||
|
#include <string.h> |
||||
|
#include <stdio.h> |
||||
|
|
||||
|
char *Feldwert (const char *Feldname); |
||||
|
|
||||
|
void htmlprint (const char *s); |
||||
|
|
||||
|
#endif |
||||
|
|
||||
@ -0,0 +1,29 @@ |
|||||
|
/* Bibliothek zur Verarbeitung von gePOSTeten oder getGETeten |
||||
|
* Formulardaten ueber das CGI-Interface an ein C-Programm. Bei |
||||
|
* der Methode POST wird der Datenstrom ueber die Standardeingabe |
||||
|
* gelesen, zerlegt und decodiert. Bei der Methode GET wird die |
||||
|
* Environment-Variable QUERY_STRING gelesen, zerlegt und decodiert. |
||||
|
* Die Zeichenketten werden mit Hilfe der Funktion Feldwert zur |
||||
|
* Verfuegung gestellt. |
||||
|
* |
||||
|
* Weitere Funktion: htmlprint |
||||
|
* Gibt Zeichenkette aus, Umlaute und andere Sonderzeichen |
||||
|
* werden aber durch die HTML-Schreibweise (z. B. "ö"=>"ö") |
||||
|
* ersetzt. |
||||
|
*/ |
||||
|
|
||||
|
/* Die maximale Anzahl Felder, die im Formular enthalten sein duerfen, |
||||
|
betraegt zur Zeit 50. Checkboxen zaehlen als 1 Feld */ |
||||
|
|
||||
|
#ifndef CGILIB_INCLUDED |
||||
|
|
||||
|
#define CGILIB_INCLUDED |
||||
|
|
||||
|
#include <string.h> |
||||
|
#include <stdio.h> |
||||
|
|
||||
|
char *Feldwert (const char *Feldname); |
||||
|
|
||||
|
void htmlprint (const char *s); |
||||
|
|
||||
|
#endif |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue