campaignd: Refactor [campaign] searches into a get_campaign() method

This commit is contained in:
Ignacio R. Morelle 2015-04-25 02:08:10 -03:00
parent 28b3e384a6
commit 62c2890f8f
2 changed files with 7 additions and 4 deletions

View file

@ -334,7 +334,7 @@ void server::run()
} else {
const std::string& addon_id = ctl[1];
const std::string& newpass = ctl[2];
config& campaign = campaigns().find_child("campaign", "name", addon_id);
config& campaign = get_campaign(addon_id);
if(!campaign) {
ERR_CS << "Add-on '" << addon_id << "' not found, cannot set passphrase\n";
@ -530,7 +530,7 @@ void server::handle_request_campaign(const server::request& req)
{
LOG_CS << "sending campaign '" << req.cfg["name"] << "' to " << req.addr << " using gzip";
config& campaign = campaigns().find_child("campaign", "name", req.cfg["name"]);
config& campaign = get_campaign(req.cfg["name"]);
if(!campaign) {
send_error("Add-on '" + req.cfg["name"].str() + "' not found.", req.sock);
@ -755,7 +755,7 @@ void server::handle_delete(const server::request& req)
LOG_CS << "deleting campaign '" << erase["name"] << "' requested from " << req.addr << "\n";
const config& campaign = campaigns().find_child("campaign", "name", erase["name"]);
const config& campaign = get_campaign(erase["name"]);
if(!campaign) {
send_error("The add-on does not exist.", req.sock);
@ -805,7 +805,7 @@ void server::handle_change_passphrase(const server::request& req)
return;
}
config& campaign = campaigns().find_child("campaign", "name", cpass["name"]);
config& campaign = get_campaign(cpass["name"]);
if(!campaign) {
send_error("No add-on with that name exists.", req.sock);

View file

@ -130,6 +130,9 @@ private:
/** Retrieves the contents of the [campaigns] WML node. */
config& campaigns() { return cfg_.child("campaigns"); }
/** Retrieves a campaign by id if found, or a null config otherwise. */
config& get_campaign(const std::string& id) { return campaigns().find_child("campaign", "name", id); }
/** Retrieves the contents of the [server_info] WML node. */
const config& server_info() const { return cfg_.child("server_info"); }