root/nntp/date.cc
| Revision 868b365c127bbf4f0b52f22da03e32a94a4f6653, 2.1 KB (checked in by Antti-Juhani Kaijanaho <antti-juhani@…>, 3 years ago) | |
|---|---|
|
|
| Line | |
|---|---|
| 1 | /* This file is part of Alue, the multiprotocol Internet discussion daemon |
| 2 | |
| 3 | Copyright © 2009 Antti-Juhani Kaijanaho |
| 4 | |
| 5 | Alue is free software: you can redistribute it and/or modify it |
| 6 | 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. |
| 9 | |
| 10 | Alue is distributed in the hope that it will be useful, but |
| 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with Alue. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | */ |
| 19 | #include "connection.hh" |
| 20 | |
| 21 | #include <boost/date_time/gregorian/gregorian.hpp> |
| 22 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 23 | |
| 24 | namespace nntp { |
| 25 | |
| 26 | // FIXME local time handling |
| 27 | |
| 28 | class date : public connection::command |
| 29 | { |
| 30 | public: |
| 31 | date(std::string s) { |
| 32 | connection::register_command(s, this); |
| 33 | } |
| 34 | |
| 35 | connection::continuation::ptr |
| 36 | perform(connection::cb, const std::string [], size_t) const; |
| 37 | }; |
| 38 | |
| 39 | connection::continuation::ptr |
| 40 | date::perform(connection::cb c, const std::string [], size_t nargs) |
| 41 | const |
| 42 | { |
| 43 | using namespace boost::posix_time; |
| 44 | using namespace boost::gregorian; |
| 45 | if (nargs != 0) |
| 46 | { |
| 47 | c.send_line("501 syntax error"); |
| 48 | return c.dispatch(); |
| 49 | } |
| 50 | ptime pt = second_clock::universal_time(); |
| 51 | |
| 52 | std::ostringstream ss; |
| 53 | time_facet *tf = new time_facet("%Y%m%d%H%M%S"); |
| 54 | ss.imbue(std::locale(std::locale::classic(), tf)); |
| 55 | ss << "111 " << pt; |
| 56 | c.send_line(ss.str()); |
| 57 | return c.dispatch(); |
| 58 | } |
| 59 | }; |
| 60 | namespace { |
| 61 | nntp::date date("date"); |
| 62 | } |
Note: See TracBrowser
for help on using the browser.
