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 "SQLSocket.h"
27 #include "DatabaseMgr.h"
31 SQLSocket::SQLSocket(ISocketHandler
& h
) :
37 SQLSocket::~SQLSocket(void)
42 void SQLSocket::OnAccept()
44 std::string addr
= GetRemoteAddress();
45 if(addr
.compare("127.0.0.1") && addr
.compare("localhost"))
47 Global::Get()->logf("Unauthorized SQL request from '%s'!\n", addr
.c_str());
53 void SQLSocket::OnLine(const std::string
&line
)
55 Global::Get()->logf("SQL request: '%s'\n", line
.c_str());
56 Query
q(DatabaseMgr::Get()->DBref());
59 std::vector
< std::vector
<std::string
> > result
;
62 std::vector
<std::string
> row
;
63 std::string column
= q
.getstr();
66 row
.push_back(column
);
69 result
.push_back(row
);
72 if(result
.size() == 0)
79 for(std::vector
< std::vector
<std::string
> >::iterator its
= result
.begin(); its
!= result
.end(); its
++)
81 std::vector
<std::string
> row
= *its
;
93 for(std::vector
<std::string
>::iterator it
= row
.begin(); it
!= row
.end(); it
++)
108 void SQLSocket::Send(const std::string
& msg
)
110 SendBuf(msg
.c_str(), msg
.size());