webpg-npapi 0.6.1
FB::variant webpgPluginAPI::setTempGPGOption ( const std::string &  option,
const std::string &  value = NULL 
)

Creates a backup of the gpg.conf file and writes the options to gpg.conf; This should be called prior to initializing the context.

Definition at line 354 of file webpgPluginAPI.cpp.

References getGPGConfigFilename().

Referenced by gpgDecryptVerify(), gpgGenSubKeyWorker(), and webpgPluginAPI().

                                                                                          {

    std::string result;
    std::string config_path = webpgPluginAPI::getGPGConfigFilename();
    std::string tmp_config_path = config_path + "-webpg.save";

    std::string gpgconfigfile = LoadFileAsString(config_path);

    if (gpgconfigfile.length()) {
        // Test if we already made a backup, if not, make one!
        std::ifstream tmp_config_exists(tmp_config_path.c_str());
        if (!tmp_config_exists) {
            // Backup the current contents
            std::ofstream tmp_file(tmp_config_path.c_str());
            if (!tmp_file)
                return "error opening temp_file";
            tmp_file << gpgconfigfile;
            tmp_file.close();
        }

        // Ensure we are not appending to an existing line
        gpgconfigfile += "\n";
        gpgconfigfile += option;
        if (value.length())
            gpgconfigfile += " " + value;
        gpgconfigfile += "\n";

        std::ofstream gpg_file(config_path.c_str());
        if (!gpg_file)
            return "error writing gpg_file";
        gpg_file << gpgconfigfile;
        gpg_file.close();
    }

    if (gpgconfigfile.length())
        result = "Set ";
    else
        result = "Unable to set ";

    if (value.length())
        result += "'" + option + " = " + value + "' in file: " + config_path;
    else
        result += "'" + option + "' in file: " + config_path;

    return result;
}

Here is the call graph for this function:

 All Classes Functions