webpg-npapi 0.6.1
void webpgPluginAPI::init ( )

Initializes the webpgPlugin and sets the status variables.

Definition at line 187 of file webpgPluginAPI.cpp.

References get_gpgme_ctx(), getPlugin(), and gpgconf_detected().

Referenced by get_webpg_status(), and webpgPluginAPI().

{
    gpgme_ctx_t ctx;
    gpgme_error_t err;
    FB::VariantMap error_map;
    FB::VariantMap response;
    FB::VariantMap protocol_info, plugin_info;
    gpgme_engine_info_t engine_info;

    plugin_info["source_url"] = m_host->getDOMWindow()->getLocation();
    plugin_info["path"] = getPlugin()->getPluginPath();
    plugin_info["params"] = getPlugin()->getPluginParams();
    plugin_info["version"] = FBSTRING_PLUGIN_VERSION;
    response["plugin"] = plugin_info;

#ifdef _EXTENSIONIZE
    response["extensionize"] = true;
    std::string location = m_host->getDOMWindow()->getLocation();
    size_t firefox_ext = location.find("chrome://");
    size_t chrome_ext = location.find("chrome-extension://");
    response["extension"] = (chrome_ext != std::string::npos) ?
        "chrome" : (firefox_ext != std::string::npos) ? "firefox" : "unknown";
#endif

    /* Initialize the locale environment.
     * The function `gpgme_check_version` must be called before any other
     * function in the library, because it initializes the thread support
     * subsystem in GPGME. (from the info page) */
    std::string gpgme_version = (char *) gpgme_check_version(NULL);

    setlocale (LC_ALL, "");
    gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
#ifdef LC_MESSAGES
    gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
#endif

    err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
    if (err != GPG_ERR_NO_ERROR)
        error_map = get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    if (error_map.size()) {
        response["openpgp_valid"] = false;
        response["error"] = true;
        response["error_map"] = error_map;
        webpgPluginAPI::webpg_status_map = error_map;
        gpgme_invalid = true;
        return;
    }

    ctx = get_gpgme_ctx();

    response["error"] = false;
    response["gpgme_valid"] = true;
    response["gpgconf_detected"] = gpgconf_detected();
    if (!gpgconf_detected())
        response["gpgconf_response"] = gpgme_strerror (gpgme_engine_check_version (GPGME_PROTOCOL_GPGCONF));
    response["gpgme_version"] = gpgme_version;
    engine_info = gpgme_ctx_get_engine_info (ctx);
    if (engine_info) {
        if (engine_info->file_name)
            protocol_info["file_name"] = (char *) engine_info->file_name;
        if (engine_info->version)
            protocol_info["version"] = (char *) engine_info->version;
        if (engine_info->home_dir)
            protocol_info["home_dir"] = (char *) engine_info->home_dir;
        if (engine_info->req_version)
            protocol_info["req_version"] = (char *) engine_info->req_version;
        response[(char *) gpgme_get_protocol_name (engine_info->protocol)] = protocol_info;
    } else {
        response["OpenPGP"] = get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);
    }

    response["GNUPGHOME"] = GNUPGHOME;

    // Retrieve the GPG_AGENT_INFO environment variable
    char *gpg_agent_info = getenv("GPG_AGENT_INFO");

    if (gpg_agent_info != NULL) {
        response["gpg_agent_info"] = gpg_agent_info;
    } else {
        response["gpg_agent_info"] = "unknown";
    }

    if (ctx)
        gpgme_release (ctx);

    webpgPluginAPI::webpg_status_map = response;
};

Here is the call graph for this function:

 All Classes Functions