fastcgipp-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fastcgipp-users] A basic C++ question probably


From: ninti
Subject: [Fastcgipp-users] A basic C++ question probably
Date: Sat, 28 Nov 2009 16:36:05 +1030

 PREAMBLE: As explained earlier, I have almost 10 years experience with PHP 
including object oriented PHP5, and almost no C++ background whatsoever. 
 
I am experimenting with creating a very simple web application based on the 
echo.fcgi example. 
The intention is that one fcgi program is able to serve multiple pages 
(possibly an entire site). 
At the moment, the content for each separate page is read in from a file (a 
kind of 'php include' strategy), with a common header and footer being provided 
in echo.fcgi. Other strategies of course are to read content from a database or 
process XML files with XSLT (I'm leaving them for later!). 
 
First of all, if have NGINX rewriting all requests as follows: 
 
if (!-f $request_filename) { 
  rewrite ^/(.*)$ /echo2.fcgi?$1 last; 
} 
  
Next, I have modified the response() section of echo.cpp as follows: 
 
bool response() 
 { 
        // QUERY STRING MATCHES 
        wchar_t one[]   = { 0x006f, 0x006e, 0x0065, 0x0000 }; 
        wchar_t two[]   = { 0x74, 0x77, 0x006f, 0x0000 }; 
        wchar_t three[] = { 0x0074, 0x0068, 0x0072, 0x0065, 0x0065, 0x0000 }; 
 
        out << "Content-Type: text/html; charset=utf-8\r\n\r\n"; 
        out << "<html><head><meta http-equiv='Content-Type' content='text/html; 
charset=utf-8' />"; 
        out << "<title>fastcgi++: Echo in UTF-8</title></head><body>"; 
 
        std::wifstream fin; 
        if (environment.queryString == one) { 
            fin.open("one"); 
        } 
        else if (environment.queryString == two) { 
            fin.open("two"); 
        } 
        else if (environment.queryString == three) { 
            fin.open("three"); 
        } 
        else { 
            fin.open("default"); 
        } 
 
        wchar_t ch; 
        while (fin.get(ch)) { 
            out << ch; 
        } 
        fin.close(); 
 
        out << "<body></html>"; 
} 
 
'one', 'two', 'three' and 'default' are simple text files containing HTML. 
This works OK (error handling etc aside), but will get ugly very quickly as the 
number of pages grows. 
I have tried Googling and reading everything I can lay my hands on in order to 
figure out how to do something like this instead: 
 
 
std::wifstream fin; 
if (environment.queryString.size > 0) { 
    std::string incfile = environment.queryString; 
} 
else { 
    std::string incfile = "default"; 
} 
 
fin.open(incfile.c_str); 
wchar_t ch; 
while (fin.get(ch)) { 
   out << ch; 
} 
fin.close(); 
 
 
I have tried too many combinations of fiddling with the environment.queryString 
and incfile variables (type, type conversion, etc) to list here but just can't 
crack it. I managed to get the compiler down to a single error on a couple of 
occasions. 
 
I know this is probably very simple. What am I doing wrong? 
 
Thanks  
                                                                                
        
 
 
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]