Handle the EINTR error when doing a waitpid() in wvmagicloopback.
[wvapps.git] / evolution / sync.cc
blob434fa3b940f61bdecd1159abd75183082ae587bc
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Authors : Patrick Patterson <ppatters@nit.ca>
4 * Peter Colijn <pcolijn@nit.ca>
5 * Scott MacLean <scott@nit.ca>
6 * William Lachance <wlach@nit.ca>
8 * Copyright 2003-2004, Net Integration Technologies, Inc.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
25 #include "sync.h"
26 #include "wvstream.h"
27 #include "exchangeitadaptor.h"
28 #include "exchangeitstorage.h"
29 #include "eituniconfkeys.h"
31 bool Sync::apply_response(WvStringList &parts,
32 WvStream &stream,
33 ExchangeItStorage *storage)
35 if (!parts.count())
37 log(WvLog::Debug1, "Malformed response: no response!!\n");
38 return false;
41 WvString response = parts.popstr();
43 if (response == "NOFOLDER")
45 if (!adaptor || !adaptor->get_key())
46 return false;
48 log(WvLog::Debug1, "Got %s, removing %s\n",
49 response, adaptor->get_key());
51 // remove the folder if it doesn't exist on the server, but we
52 // think it does? this is what ExchangeItOutlook does..
53 UniConf folders = storage->get_state()[FOLDERS_KEY];
54 folders[TODELETE_KEY][adaptor->get_key()].setmeint(1);
56 // this isn't technically a problem; we have successfully applied
57 // the response
58 return true;
60 else if (response == "BADFOLDER")
62 // BADFOLDER usually means we tried to sync an email folder,
63 // which does nothing right now
64 log(WvLog::Debug1, "Got %s, ignoring\n", response);
65 return true;
68 if (response != "OK")
70 log(WvLog::Debug1, "Got %s, expected OK\n", response);
71 return false;
74 if (!parts.count())
76 log(WvLog::Debug1, "Malformed response: too few parameters!\n");
77 return false;
80 WvString version = parts.popstr();
81 uint32_t new_version = version.num();
83 if (new_version < adaptor->get_version())
84 log(WvLog::Error,
85 "Adaptor claims it has a later version (%s vs. %s) "
86 "than what's on the server!\n",
87 adaptor->get_version(), new_version);
89 adaptor->set_version(new_version);
90 return true;
93 void Sync::get_command(WvString &command,
94 WvStringList &params,
95 WvStringList &lines)
97 command = "SYNC";
99 params.zap();
100 lines.zap();
102 params.append(new WvString(adaptor->get_version()), true);
103 params.append(new WvString(url_encode(adaptor->key)), true);
104 params.append(new WvString(adaptor->get_type()), true);
107 #if 0
108 bool SyncFolders::check_error(const string &response, const Strings &params)
110 if (response != "ERROR")
111 return false;
113 string error;
114 for (Strings::const_iterator i = params.begin(); i != params.end(); ++i)
115 error += *i + " ";
117 if (error.empty())
118 set_error("Unknown server error");
119 else
121 error.erase(error.size() - 1);
122 set_error(error);
125 return true;
127 #endif