00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include "replicatetcpserver.h"
00024
00025 #include <xapian/error.h>
00026 #include "replication.h"
00027
00028 using namespace std;
00029
00030 ReplicateTcpServer::ReplicateTcpServer(const string & host, int port,
00031 const string & path_)
00032 : TcpServer(host, port, false, false), path(path_)
00033 {
00034 }
00035
00036 ReplicateTcpServer::~ReplicateTcpServer() {
00037 }
00038
00039 void
00040 ReplicateTcpServer::handle_one_connection(int socket)
00041 {
00042 RemoteConnection client(socket, -1);
00043 try {
00044
00045 string start_revision;
00046 if (client.get_message(start_revision, 0.0) != 'R') {
00047 throw Xapian::NetworkError("Bad replication client message");
00048 }
00049
00050
00051 string dbname;
00052 if (client.get_message(dbname, 0.0) != 'D') {
00053 throw Xapian::NetworkError("Bad replication client message (2)");
00054 }
00055 if (dbname.find("..") != string::npos) {
00056 throw Xapian::NetworkError("dbname contained '..'");
00057 }
00058
00059 string dbpath(path);
00060 dbpath += '/';
00061 dbpath += dbname;
00062 Xapian::DatabaseMaster master(dbpath);
00063 master.write_changesets_to_fd(socket, start_revision, NULL);
00064 } catch (...) {
00065
00066 }
00067 }