Thursday, July 29th 2010, 1:36pm UTC+2
You are not logged in.
Allerdings hab ich bisher noch nichts mit CGI Schnittstellen gemacht. Danke Jürgen werd ich mir gleich mal durchlesen. 
Ich werd mal auf den Manpages suchen evtl. werd ich da fündig über die mir nötigen Infos. Falls du noch was auf Lager hast würd ich mich freuen wenn dus mir schreibst.

This post has been edited 2 times, last edit by "Dewey" (Sep 17th 2005, 12:38pm)
Quoted
Original von Dewie
In C Programmierung hab ich Kenntnisse.......................
Wie speichere ich bzw. kompiliere ich eine .c in eine cgi?

|
|
PHP Source code |
1 2 3 4 5 6 7 8 |
using namespace std:
int main()
{
cout << "Content-Type: text/html " << endl;
cout << endl;
cout << "<html>" << endl;
cout << "<body></body></html>" << endl;
}
|

|
|
PHP Source code |
1 2 3 4 5 6 7 8 |
string request_method = getenv( "REQUEST_METHOD" );
if ( request_method == "POST" )
{
l = atoi( getenv('CONTENT_LENGTH') ):
buff = new char[l+1];
for ( unsigned int i = 0; i < l; i++ )
cin.get( buff[i] );
}
|
|
|
PHP Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
/***************************************************************************
* Copyright (C) 2005 by undefined *
* undefined@flashbattle.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <vector>
using namespace std;
struct ListElement
{
ListElement* naechstes;
string schluessel;
string wert;
// __construct
ListElement() : naechstes(0)
{}
// __construct erweitert
ListElement( const string& _schluessel, const string& _wert ) :
naechstes( 0 ),
schluessel( _schluessel ),
wert( _wert )
{}
}
;
class Liste
{
private:
ListElement* erstes;
ListElement* letztes;
int anzahl;
public:
Liste() : erstes( 0 ), letztes( 0 ), anzahl( 0 )
{}
virtual ~Liste();
bool empty() const
{
return ( anzahl == 0 );
}
int size() const
{
return anzahl;
}
void push_back( const string& schluessel, const string& wert );
void pop_front();
ListElement* front()
{
return erstes;
}
};
void Liste::push_back( const string& _schluessel, const string& _wert )
{
ListElement* tmp = new ListElement( _schluessel, _wert );
if ( letztes != 0 )
letztes->naechstes = tmp;
else
erstes = tmp;
letztes = tmp;
anzahl++;
}
void Liste::pop_front()
{
if ( anzahl == 0 )
return;
ListElement* tmp = erstes;
erstes = tmp->naechstes;
if ( erstes == 0 )
letztes == 0;
delete tmp;
anzahl--;
}
Liste::~ Liste()
{
while( anzahl != 0 )
pop_front();
}
bool Anfrage( Liste& _liste )
{
string request_method = getenv( "REQUEST_METHOD" );
// Puffer fuer uebergeben Daten
char* buffer = 0;
unsigned int len;
// Behandle Post Variablen
if ( request_method == "POST" ) {
len = atoi( getenv( "QUERY_STRING" ) );
buffer = new char[len + 1];
for ( unsigned int i = 0; i < len; i++ ) {
cin.get( buffer[i] );
}
}
// Behandle GET Variablen
if ( request_method == "GET" ) {
len = strlen( getenv( "QUERY_STRING" ) );
buffer = new char[len+1];
strcpy( buffer, getenv( "QUERY_STRING" ) );
}
// Terminieren
buffer[len] = 0;
// Kopiere Puffer in String
string eingabe = buffer;
delete[] buffer;
// Lokale Variablen zur Teilstring Suche
size_t pos = 0;
size_t old_pos = 0;
// Lese Werte Paare
while ( pos < len ) {
pos = eingabe.find( "&", old_pos );
// Ein oder mehrer parameter wurden uebergeben ?
if ( pos == string::npos )
pos = eingabe.length();
// Splitten
string paar = eingabe.substr( old_pos, pos-old_pos );
size_t eq_pos = paar.find("=");
string schluessel = paar.substr( 0, eq_pos );
// Hier brauchts du noch eine Funktion zum Konvertieren von Leerzeichen( schluessel );
string wert = paar.substr( eq_pos + 1 );
// Hier brauchts du noch eine Funktion zum Konvertieren von Leerzeichen( wert );
// Erstelle Liste
_liste.push_back( schluessel, wert );
old_pos = pos + 1;
}
}
void Antworte( Liste& _liste )
{
cout << "Content-Type: text/html" << endl;
cout << endl;
cout << "<html><title>C++ Beispiel CGI GET/POST Beispiel</title>" << endl;
cout << "<head>" << endl;
cout << "<body><h2>Ausgabe</h2>" << endl;
ListElement* tmp;
for( tmp = _liste.front(); tmp != 0; tmp = tmp->naechstes ) {
cout << "<p><b>" << tmp->schluessel << "</b>" << tmp->wert << "</p>" << endl;
}
cout << "</body>" << endl;
cout << "</head>" << endl;
cout << "</html>" << endl;
}
int main()
{
Liste liste;
if ( Anfrage( liste ) == false ) {
cout << "Content-Type: text/html" << endl;
cout << endl;
cout << "<html><title>C++ Beispiel CGI GET/POST Beispiel</title>" << endl;
cout << "Keine Anfrage erhalten!" << endl;
cout << "</body>" << endl;
cout << "</head>" << endl;
cout << "</html>" << endl;
} else
Antworte( liste );
return EXIT_SUCCESS;
}
|
|
|
Source code |
1 |
http://localhost/cgi-bin/getpost?test=String |

Quoted
Also habe ich mir jetzt umsonst die mühe gemacht

Quoted
Verwende keine .cgi Endung das ist Steinzeit.

Es müsste doch dann auch möglich sein Daten zwischen einem C Programm und Flash z.B. mit der XML Schnittstelle auszutauschen oder? :-) This post has been edited 1 times, last edit by "Dewey" (Sep 17th 2005, 7:06pm)
Quoted
Original von Dewie
Quoted
Also habe ich mir jetzt umsonst die mühe gemacht
Nö hast du dir nicht. Danke sehr für das Bsp.
Quoted
Verwende keine .cgi Endung das ist Steinzeit.
Ok ich werde mich hüten.
Du hast mir oben den Link mit deiner Schnittstelle zwischen Flash und Perl gepostet. Hab mir das jetzt mal genauer angesehen und fleißig gegoogledEs müsste doch dann auch möglich sein Daten zwischen einem C Programm und Flash z.B. mit der XML Schnittstelle auszutauschen oder? :-)
|
|
Source code |
1 |
meinprog command=1 command=2 |