/**
 * Get the Zeipis core server via various methods.
 *
 * @return {String}   form "hostname:port"
 */
function getCoreServer()
{
    try {
        return getCoreServerFromPrefs();
    } catch (e) {
      try {
        return getCoreServerFromDotfiles();
      } catch (e) { throw "Please set core server, see docs"; }
    }
}

function getCoreServerFromPrefs()
{
    try {
        return prefService().getCharPref("zeipis.coreserver");
    } catch (e) { throw "Please set core server pref"; }
}

function getCoreServerFromDotfiles()
{
    var file = getSpecialFolder("Home");
    file.append(".zeipis");
    file.append("start.conf");
    try {
      var values = readINIFile(file);
    } catch (e) { throw "Please create ~/.zeipis/start.conf file, see docs"; }
    // TODO support /etc/zeipis/start.conf
    if ( ! values.CoreServerHostname)
      throw "~/.zeipis/start.conf does not contain the necessary values";
    var result = values.CoreServerHostname + ":";
    if (values.CoreServerPort)
      result += values.CoreServerHostname;
    else
      result += kPortDefault;
    return result;
}

const kPortDefault = 4962;
