webpg-npapi 0.6.1
FB::variant webpgPluginAPI::gpgAddUID ( const std::string &  keyid,
const std::string &  name,
const std::string &  email,
const std::string &  comment 
)

Adds a new UID to the key specified by keyid.

Parameters:
keyidThe ID of the key to add the UID to.
nameThe name to assign to the new UID.
emailThe email address to assign to the new UID.
commentThe comment to assign to the new UID.

Definition at line 2491 of file webpgPluginAPI.cpp.

References get_gpgme_ctx().

Referenced by webpgPluginAPI().

{
    gpgme_ctx_t ctx = get_gpgme_ctx();
    gpgme_error_t err;
    gpgme_data_t out = NULL;
    gpgme_key_t key = NULL;
    FB::VariantMap response;
    genuid_name = name;
    genuid_email = email;
    genuid_comment = comment;

    if (isdigit(name.c_str()[0])) {
        response["error"] = true;
        response["result"] = "UID names cannot start with a digit...";
        return response;
    }

    if (strlen (name.c_str()) < 5) {
        response["error"] = true;
        response["result"] = "UID's must be at least 5 chars long...";
        return response;
    }

    err = gpgme_op_keylist_start (ctx, keyid.c_str(), 0);
    if (err != GPG_ERR_NO_ERROR)
        return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    err = gpgme_op_keylist_next (ctx, &key);
    if (err != GPG_ERR_NO_ERROR)
        return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    err = gpgme_op_keylist_end (ctx);
    if (err != GPG_ERR_NO_ERROR)
        return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    err = gpgme_data_new (&out);
    if (err != GPG_ERR_NO_ERROR)
        return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    edit_status = "gpgAddUID(keyid='" + keyid + "', name='" + name + "', email='" + email + 
        "', comment='" + comment + "');\n";
    err = gpgme_op_edit (ctx, key, edit_fnc_add_uid, out, out);
    if (err != GPG_ERR_NO_ERROR)
        return get_error_map(__func__, gpgme_err_code (err), gpgme_strerror (err), __LINE__, __FILE__);

    response["name"] = genuid_name;
    response["email"] = genuid_email;
    response["comment"] = genuid_comment;

    genuid_name = "";
    genuid_email = "";
    genuid_comment = "";

    gpgme_data_release (out);
    gpgme_key_unref (key);
    gpgme_release (ctx);

    response["error"] = false;
    response["edit_status"] = edit_status;
    response["result"] = "UID added";

    return response;
}

Here is the call graph for this function:

 All Classes Functions