xapian-core  1.4.27
replicatetcpserver.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2008,2010,2011 Olly Betts
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <config.h>
22 
23 #include "replicatetcpserver.h"
24 
25 #include <xapian/error.h>
26 #include "api/replication.h"
27 #include "remoteconnection.h"
28 
29 using namespace std;
30 
31 ReplicateTcpServer::ReplicateTcpServer(const string & host, int port,
32  const string & path_)
33  : TcpServer(host, port, false, false), path(path_)
34 {
35 }
36 
38 }
39 
40 void
42 {
43  RemoteConnection client(socket, -1);
44  try {
45  // Read start_revision from the client.
46  string start_revision;
47  if (client.get_message(start_revision, 0.0) != 'R') {
48  throw Xapian::NetworkError("Bad replication client message");
49  }
50 
51  // Read dbname from the client.
52  string dbname;
53  if (client.get_message(dbname, 0.0) != 'D') {
54  throw Xapian::NetworkError("Bad replication client message (2)");
55  }
56  if (dbname.find("..") != string::npos) {
57  throw Xapian::NetworkError("dbname contained '..'");
58  }
59 
60  string dbpath(path);
61  dbpath += '/';
62  dbpath += dbname;
63  Xapian::DatabaseMaster master(dbpath);
64  master.write_changesets_to_fd(socket, start_revision, NULL);
65  } catch (...) {
66  // Ignore exceptions.
67  }
68 }
A RemoteConnection object provides a bidirectional connection to another RemoteConnection object on a...
RemoteConnection class used by the remote backend.
int get_message(std::string &result, double end_time)
Read one message from fdin.
Access to a master database for replication.
Definition: replication.h:61
std::string path
The path to pass to DatabaseMaster.
void handle_one_connection(int socket)
Handle a single connection on an already connected socket.
STL namespace.
#define false
Definition: header.h:9
~ReplicateTcpServer()
Destructor.
Hierarchy of classes which Xapian can throw as exceptions.
ReplicateTcpServer(const std::string &host, int port, const std::string &path_)
Construct a ReplicateTcpServer and start listening for connections.
Replication support for Xapian databases.
Indicates a problem communicating with a remote database.
Definition: error.h:803
void write_changesets_to_fd(int fd, const std::string &start_revision, ReplicationInfo *info) const
Write a set of changesets for upgrading the database to a file.
Definition: replication.cc:70
TCP/IP replication server class.