diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-04-06 19:13:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-04-06 19:13:51 +0000 |
commit | 514721c24c7212c084ad2530e8239ff121097818 (patch) | |
tree | bfe5d346e767df47d10a5631e33a2e0540d72604 /src/tests | |
parent | aaeaa599a14642e916bbd8a32a208ee96a26eaac (diff) | |
download | libbu++-514721c24c7212c084ad2530e8239ff121097818.tar.gz libbu++-514721c24c7212c084ad2530e8239ff121097818.tar.bz2 libbu++-514721c24c7212c084ad2530e8239ff121097818.tar.xz libbu++-514721c24c7212c084ad2530e8239ff121097818.zip |
Ok, I rearranged some things, we have a tools dir now, those build by default.
Also I added a bunch of classes that I've been tinkering with that are almost
ready for use, so I figured I may as well throw them in here.
Diffstat (limited to '')
-rw-r--r-- | src/tests/fastcgi.cpp | 81 | ||||
-rw-r--r-- | src/tests/url.cpp | 45 | ||||
-rw-r--r-- | src/tools/nidstool.cpp (renamed from src/tests/nidstool.cpp) | 0 |
3 files changed, 105 insertions, 21 deletions
diff --git a/src/tests/fastcgi.cpp b/src/tests/fastcgi.cpp new file mode 100644 index 0000000..53dd68a --- /dev/null +++ b/src/tests/fastcgi.cpp | |||
@@ -0,0 +1,81 @@ | |||
1 | #include "bu/fastcgi.h" | ||
2 | |||
3 | class Cgi : public Bu::FastCgi | ||
4 | { | ||
5 | public: | ||
6 | Cgi() : | ||
7 | Bu::FastCgi::FastCgi() | ||
8 | { | ||
9 | } | ||
10 | |||
11 | Cgi( int iPort ) : | ||
12 | Bu::FastCgi::FastCgi( iPort ) | ||
13 | { | ||
14 | } | ||
15 | |||
16 | virtual ~Cgi() | ||
17 | { | ||
18 | } | ||
19 | |||
20 | virtual int request( const StrHash &hParams, | ||
21 | const Bu::FString &sStdIn, Bu::Stream &sStdOut, | ||
22 | Bu::Stream &sStdErr ) | ||
23 | { | ||
24 | Bu::FString sOut("Content-Type: text/html\r\n\r\n"); | ||
25 | sOut += "<html><body><h1>Environment:</h1><ul>"; | ||
26 | for( StrHash::const_iterator i = hParams.begin(); i; i++ ) | ||
27 | { | ||
28 | sOut += "<li>" + i.getKey() + " = " + | ||
29 | i.getValue() + "</li>"; | ||
30 | } | ||
31 | sOut += "</ul>"; | ||
32 | char buf[2048]; | ||
33 | sOut += "<h1>Cwd:</h1><ul><li>"; | ||
34 | sOut += getcwd( buf, 2048 ); | ||
35 | sOut += "</li></ul>"; | ||
36 | sOut += "<h1>Stdin:</h1>"; | ||
37 | sOut.formatAppend("%d bytes<pre>", sStdIn.getSize() ); | ||
38 | Bu::FString sL, sR; | ||
39 | for( Bu::FString::const_iterator i = sStdIn.begin(); | ||
40 | i; i++ ) | ||
41 | { | ||
42 | sL.formatAppend("%02X ", | ||
43 | (unsigned int)((unsigned char)*i) ); | ||
44 | if( *i < 27 ) | ||
45 | sR += ". "; | ||
46 | else | ||
47 | sR.formatAppend("&#%d; ", | ||
48 | (unsigned int)((unsigned char)*i) ); | ||
49 | if( sL.getSize()/3 == 8 ) | ||
50 | { | ||
51 | sOut += sL + " | " + sR + "\n"; | ||
52 | sL = sR = ""; | ||
53 | } | ||
54 | } | ||
55 | if( sL != "" ) | ||
56 | { | ||
57 | while( sL.getSize()/3 < 8 ) | ||
58 | sL += " "; | ||
59 | sOut += sL + " | " + sR + "\n"; | ||
60 | } | ||
61 | sOut += "</pre><hr/><pre>"; | ||
62 | sOut += sStdIn; | ||
63 | sOut += "</pre>"; | ||
64 | sOut += "<form method=\"post\" enctype=\"multipart/form-data\"><textarea name=\"bob\"></textarea><br /><input type=\"file\" name=\"somefile\" /><br /><input type=\"submit\" name=\"yeah\" value=\"try it\" /></form>"; | ||
65 | sOut += "</body></html>"; | ||
66 | |||
67 | sStdOut.write( sOut ); | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | }; | ||
72 | |||
73 | int main() | ||
74 | { | ||
75 | Cgi c( 8789 ); | ||
76 | |||
77 | c.run(); | ||
78 | |||
79 | return 0; | ||
80 | } | ||
81 | |||
diff --git a/src/tests/url.cpp b/src/tests/url.cpp index c9af676..4dc8c46 100644 --- a/src/tests/url.cpp +++ b/src/tests/url.cpp | |||
@@ -4,28 +4,31 @@ | |||
4 | 4 | ||
5 | int main( int argc, char *argv[] ) | 5 | int main( int argc, char *argv[] ) |
6 | { | 6 | { |
7 | printf("encodede: %s\n", Bu::Url::encode( argv[1] ).getStr() ); | 7 | for( argc--, argv++; argc >= 0; argc--, argv++ ) |
8 | printf("decodede: %s\n", Bu::Url::decode( argv[1] ).getStr() ); | ||
9 | Bu::Url u( argv[1] ); | ||
10 | |||
11 | printf("Protocol: %s\n", u.getProtocol().getStr() ); | ||
12 | printf("User: %s\n", u.getUser().getStr() ); | ||
13 | printf("Pass: %s\n", u.getPass().getStr() ); | ||
14 | printf("Host: %s\n", u.getHost().getStr() ); | ||
15 | printf("Path: %s\n", u.getPath().getStr() ); | ||
16 | try | ||
17 | { | ||
18 | printf("Port: %d\n", u.getPort() ); | ||
19 | } catch( Bu::ExceptionBase &e ) | ||
20 | { | 8 | { |
21 | printf("Port: not set.\n"); | 9 | printf("encodede: %s\n", Bu::Url::encode( *argv ).getStr() ); |
22 | } | 10 | printf("decodede: %s\n", Bu::Url::decode( *argv ).getStr() ); |
23 | printf("Parameters:\n"); | 11 | Bu::Url u( *argv ); |
24 | for( Bu::Url::ParamList::const_iterator i = u.getParamBegin(); i; i++ ) | 12 | |
25 | { | 13 | printf("Protocol: %s\n", u.getProtocol().getStr() ); |
26 | printf(" \"%s\" = \"%s\"\n", | 14 | printf("User: %s\n", u.getUser().getStr() ); |
27 | (*i).sName.getStr(), (*i).sValue.getStr() | 15 | printf("Pass: %s\n", u.getPass().getStr() ); |
28 | ); | 16 | printf("Host: %s\n", u.getHost().getStr() ); |
17 | printf("Path: %s\n", u.getPath().getStr() ); | ||
18 | try | ||
19 | { | ||
20 | printf("Port: %d\n", u.getPort() ); | ||
21 | } catch( Bu::ExceptionBase &e ) | ||
22 | { | ||
23 | printf("Port: not set.\n"); | ||
24 | } | ||
25 | printf("Parameters:\n"); | ||
26 | for( Bu::Url::ParamList::const_iterator i = u.getParamBegin(); i; i++ ) | ||
27 | { | ||
28 | printf(" \"%s\" = \"%s\"\n", | ||
29 | (*i).sName.getStr(), (*i).sValue.getStr() | ||
30 | ); | ||
31 | } | ||
29 | } | 32 | } |
30 | 33 | ||
31 | return 0; | 34 | return 0; |
diff --git a/src/tests/nidstool.cpp b/src/tools/nidstool.cpp index d1465ce..d1465ce 100644 --- a/src/tests/nidstool.cpp +++ b/src/tools/nidstool.cpp | |||