aboutsummaryrefslogtreecommitdiff
path: root/src/tests/rot13.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/rot13.cpp')
-rw-r--r--src/tests/rot13.cpp91
1 files changed, 0 insertions, 91 deletions
diff --git a/src/tests/rot13.cpp b/src/tests/rot13.cpp
deleted file mode 100644
index 1530af3..0000000
--- a/src/tests/rot13.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "bu/protocol.h"
9#include "bu/multiserver.h"
10#include "bu/client.h"
11#include "bu/filter.h"
12
13using namespace Bu;
14
15class Rot13Filter : public Filter
16{
17public:
18 Rot13Filter( Stream &next ) :
19 Filter( next )
20 {
21 }
22
23 virtual ~Rot13Filter()
24 {
25 }
26
27 virtual void start()
28 {
29 }
30
31 virtual Bu::size stop()
32 {
33 return 0;
34 }
35
36 virtual Bu::size read( void *pBuf, Bu::size nBytes )
37 {
38 return rNext.read( pBuf, nBytes );
39 }
40
41 virtual Bu::size write( const void *pBuf, Bu::size nBytes )
42 {
43 const char *cBuf = (const char *)pBuf;
44 char *buf = new char[nBytes];
45 for( Bu::size j = 0; j < nBytes; j++ )
46 {
47 if( cBuf[j] >= 'a' && cBuf[j] <= 'z' )
48 buf[j] = (cBuf[j]-'a'+13)%26+'a';
49 else if( cBuf[j] >= 'A' && cBuf[j] <= 'Z' )
50 buf[j] = (cBuf[j]-'A'+13)%26+'A';
51 else
52 buf[j] = cBuf[j];
53 }
54 rNext.write( buf, nBytes );
55 delete[] buf;
56 return nBytes;
57 }
58};
59
60class Rot13Protocol : public Protocol
61{
62public:
63 void onNewConnection( Bu::Client *pClient )
64 {
65 pClient->pushFilter<Rot13Filter>();
66 }
67
68 void onNewData( Bu::Client *pClient )
69 {
70 char buf[1024];
71 while( pClient->hasInput() )
72 {
73 int iAmnt = pClient->read( buf, 1024 );
74 pClient->write( buf, iAmnt );
75 }
76 }
77};
78
79int main()
80{
81 MultiServer xSrv;
82
83 xSrv.setTimeout( 5 );
84 xSrv.addProtocol( genProtocol<Rot13Protocol>, 9999 );
85
86 for(;;)
87 xSrv.scan();
88
89 return 0;
90}
91