1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
25 #include "DatabaseMgr.h"
28 #include "SQLSocket.h"
30 SQLSocket::SQLSocket(ISocketHandler
& h
) :
36 SQLSocket::~SQLSocket(void)
41 void SQLSocket::OnAccept()
43 std::string addr
= GetRemoteAddress();
44 if(addr
.compare("127.0.0.1") && addr
.compare("localhost"))
46 std::string msg
= "Unauthorized SQL request from '";
50 Global::Get()->printlog(msg
);
56 void SQLSocket::OnLine(const std::string
&line
)
58 std::string msg
= "SQL request: '";
62 Query
q(DatabaseMgr::Get()->DBref());
65 std::vector
< std::vector
<std::string
> > result
;
68 std::vector
<std::string
> row
;
69 std::string column
= q
.getstr();
72 row
.push_back(column
);
75 result
.push_back(row
);
78 if(result
.size() == 0)
85 for(std::vector
< std::vector
<std::string
> >::iterator its
= result
.begin(); its
!= result
.end(); its
++)
87 std::vector
<std::string
> row
= *its
;
99 for(std::vector
<std::string
>::iterator it
= row
.begin(); it
!= row
.end(); it
++)
101 if(it
!= row
.begin())
102 rowres
.append(" | ");
114 void SQLSocket::Send(const std::string
& msg
)
116 SendBuf(msg
.c_str(), msg
.size());