Port to phpc some functions and fix CS

This commit is contained in:
Jakub Zelenka 2016-05-22 12:07:13 +01:00
parent fdf573ac73
commit 4229b54fd6
2 changed files with 453 additions and 425 deletions

360
gnupg.c
View file

@ -48,6 +48,9 @@ PHPC_OBJ_DEFINE_HANDLER_VAR(gnupg);
} while (0)
/* }}} */
#define GNUPG_RES_FETCH() \
PHPC_THIS = (PHPC_OBJ_STRUCT_NAME(gnupg) *) PHPC_RES_FETCH(res, "ctx", le_gnupg)
/* {{{ GNUPG_ERR */
#define GNUPG_ERR(error) \
if (PHPC_THIS) { \
@ -389,9 +392,11 @@ PHP_MINFO_FUNCTION(gnupg)
}
/* }}} */
/* {{{ callback func for setting the passphrase */
gpgme_error_t passphrase_cb(PHPC_THIS_DECLARE(gnupg), const char *uid_hint, const char *passphrase_info,int last_was_bad, int fd TSRMLS_DC)
/* {{{ passphrase_cb */
gpgme_error_t passphrase_cb(
PHPC_THIS_DECLARE(gnupg),
const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd TSRMLS_DC)
{
char uid[17];
int idx;
@ -415,15 +420,20 @@ gpgme_error_t passphrase_cb(PHPC_THIS_DECLARE(gnupg), const char *uid_hint, cons
return 1;
}
if (write (fd, passphrase, strlen(passphrase))==strlen(passphrase)
&& write (fd, "\n", 1)==1) {
if (write(fd, passphrase, strlen(passphrase)) == strlen(passphrase) && write(fd, "\n", 1) == 1) {
return 0;
}
GNUPG_ERR("write failed");
return 1;
}
/* }}} */
gpgme_error_t passphrase_decrypt_cb (PHPC_THIS_DECLARE(gnupg), const char *uid_hint, const char *passphrase_info,int last_was_bad, int fd TSRMLS_DC){
/* {{{ passphrase_decrypt_cb */
gpgme_error_t passphrase_decrypt_cb (
PHPC_THIS_DECLARE(gnupg),
const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd TSRMLS_DC)
{
char uid[17];
int idx;
char *passphrase = NULL;
@ -445,29 +455,28 @@ gpgme_error_t passphrase_decrypt_cb (PHPC_THIS_DECLARE(gnupg), const char *uid_h
GNUPG_ERR("no passphrase set");
return 1;
}
if (write (fd, passphrase, strlen(passphrase))==strlen(passphrase)
&& write (fd, "\n", 1)==1) {
if (write(fd, passphrase, strlen(passphrase)) == strlen(passphrase) && write(fd, "\n", 1) == 1) {
return 0;
}
GNUPG_ERR("write failed");
return 1;
}
/* }}} */
/* {{{ gnupg_fetchsignatures */
int gnupg_fetchsignatures(gpgme_signature_t gpgme_signatures, zval *main_arr){
int gnupg_fetchsignatures(gpgme_signature_t gpgme_signatures, zval *main_arr)
{
zval sig_arr;
array_init (main_arr);
PHPC_ARRAY_INIT(main_arr);
while (gpgme_signatures) {
array_init (&sig_arr);
add_assoc_string (&sig_arr, "fingerprint", gpgme_signatures->fpr );
add_assoc_long (&sig_arr, "validity", gpgme_signatures->validity );
add_assoc_long (&sig_arr, "timestamp", gpgme_signatures->timestamp );
add_assoc_long (&sig_arr, "status", gpgme_signatures->status );
add_assoc_long (&sig_arr, "summary", gpgme_signatures->summary );
add_next_index_zval (main_arr, &sig_arr);
PHPC_ARRAY_INIT(&sig_arr);
PHPC_ARRAY_ADD_ASSOC_CSTR(&sig_arr, "fingerprint", gpgme_signatures->fpr);
PHPC_ARRAY_ADD_ASSOC_LONG(&sig_arr, "validity", gpgme_signatures->validity);
PHPC_ARRAY_ADD_ASSOC_LONG(&sig_arr, "timestamp", gpgme_signatures->timestamp);
PHPC_ARRAY_ADD_ASSOC_LONG(&sig_arr, "status", gpgme_signatures->status);
PHPC_ARRAY_ADD_ASSOC_LONG(&sig_arr, "summary", gpgme_signatures->summary);
PHPC_ARRAY_ADD_NEXT_INDEX_ZVAL(main_arr, &sig_arr);
gpgme_signatures = gpgme_signatures->next;
}
@ -478,11 +487,12 @@ int gnupg_fetchsignatures(gpgme_signature_t gpgme_signatures, zval *main_arr){
/* {{{ proto resource gnupg_init()
* inits gnupg and returns a resource
*/
PHP_FUNCTION(gnupg_init){
PHP_FUNCTION(gnupg_init)
{
PHPC_THIS_DECLARE(gnupg);
PHPC_THIS = emalloc(sizeof(gnupg_object));
PHPC_THIS = emalloc(sizeof(PHPC_OBJ_STRUCT_NAME(gnupg)));
gnupg_res_init(PHPC_THIS TSRMLS_CC);
RETURN_RES(zend_register_resource(PHPC_THIS,le_gnupg));
PHPC_RES_RETURN(PHPC_RES_REGISTER(PHPC_THIS, le_gnupg));
}
/* }}} */
@ -491,8 +501,9 @@ PHP_FUNCTION(gnupg_init){
* 0 = off
* >0 = on
* */
PHP_FUNCTION(gnupg_setarmor){
zend_long armor;
PHP_FUNCTION(gnupg_setarmor)
{
phpc_long_t armor;
GNUPG_GETOBJ();
@ -504,7 +515,7 @@ PHP_FUNCTION(gnupg_setarmor){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &armor) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if (armor > 1) {
@ -517,8 +528,9 @@ PHP_FUNCTION(gnupg_setarmor){
/* }}} */
/* {{{ proto bool gnupg_seterrormode(int errormde) */
PHP_FUNCTION(gnupg_seterrormode){
zend_long errormode;
PHP_FUNCTION(gnupg_seterrormode)
{
phpc_long_t errormode;
GNUPG_GETOBJ();
@ -530,7 +542,7 @@ PHP_FUNCTION(gnupg_seterrormode){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &errormode) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
switch (errormode) {
@ -544,13 +556,15 @@ PHP_FUNCTION(gnupg_seterrormode){
default:
GNUPG_ERR("invalid errormode");
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool gnupg_setsignmode(int signmode)
* sets the mode for signing operations
*/
PHP_FUNCTION(gnupg_setsignmode){
PHP_FUNCTION(gnupg_setsignmode)
{
zend_long signmode;
GNUPG_GETOBJ();
@ -563,7 +577,7 @@ PHP_FUNCTION(gnupg_setsignmode){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &res, &signmode) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
PHPC_THIS = (gnupg_object *) PHPC_RES_FETCH(res, "ctx", le_gnupg);
}
switch (signmode) {
case GPGME_SIG_MODE_NORMAL:
@ -577,25 +591,27 @@ PHP_FUNCTION(gnupg_setsignmode){
RETVAL_FALSE;
break;
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto string gnupg_geterror(void)
* returns the last errormessage
*/
PHP_FUNCTION(gnupg_geterror){
PHP_FUNCTION(gnupg_geterror)
{
GNUPG_GETOBJ();
if (!this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if (!PHPC_THIS->errortxt) {
RETURN_FALSE;
} else {
RETURN_STRINGL(PHPC_THIS->errortxt, strlen(PHPC_THIS->errortxt));
PHPC_CSTR_RETURN(PHPC_THIS->errortxt);
}
}
/* }}} */
@ -616,13 +632,8 @@ PHP_FUNCTION(gnupg_getprotocol){
PHP_FUNCTION(gnupg_keyinfo)
{
char *searchkey = NULL;
size_t searchkey_len;
zval subarr;
zval userid;
zval userids;
zval subkey;
zval subkeys;
phpc_str_size_t searchkey_len;
phpc_val subarr, userid, userids, subkey, subkeys;
gpgme_key_t gpgme_key;
gpgme_subkey_t gpgme_subkey;
gpgme_user_id_t gpgme_userid;
@ -637,87 +648,90 @@ PHP_FUNCTION(gnupg_keyinfo)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &searchkey, &searchkey_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if ((PHPC_THIS->err = gpgme_op_keylist_start(PHPC_THIS->ctx, searchkey, 0)) != GPG_ERR_NO_ERROR) {
GNUPG_ERR("could not init keylist");
return;
}
array_init(return_value);
PHPC_ARRAY_INIT(return_value);
while (!(PHPC_THIS->err = gpgme_op_keylist_next(PHPC_THIS->ctx, &gpgme_key))) {
array_init (&subarr);
PHPC_VAL_MAKE(subarr);
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(subarr));
array_init (&subkeys);
PHPC_VAL_MAKE(subkeys);
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(subkeys));
array_init (&userids);
PHPC_VAL_MAKE(userids);
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(userids));
add_assoc_bool (&subarr, "disabled", gpgme_key->disabled );
add_assoc_bool (&subarr, "expired", gpgme_key->expired );
add_assoc_bool (&subarr, "revoked", gpgme_key->revoked );
add_assoc_bool (&subarr, "is_secret", gpgme_key->secret );
add_assoc_bool (&subarr, "can_sign", gpgme_key->can_sign );
add_assoc_bool (&subarr, "can_encrypt", gpgme_key->can_encrypt );
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subarr), "disabled", gpgme_key->disabled);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subarr), "expired", gpgme_key->expired);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subarr), "revoked", gpgme_key->revoked);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subarr), "is_secret", gpgme_key->secret);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subarr), "can_sign", gpgme_key->can_sign);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subarr), "can_encrypt", gpgme_key->can_encrypt);
gpgme_userid = gpgme_key->uids;
while (gpgme_userid) {
array_init (&userid);
PHPC_VAL_MAKE(userid);
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(userid));
add_assoc_string (&userid, "name", gpgme_userid->name );
add_assoc_string (&userid, "comment", gpgme_userid->comment );
add_assoc_string (&userid, "email", gpgme_userid->email );
add_assoc_string (&userid, "uid", gpgme_userid->uid );
PHPC_ARRAY_ADD_ASSOC_CSTR(PHPC_VAL_CAST_TO_PZVAL(userid), "name", gpgme_userid->name);
PHPC_ARRAY_ADD_ASSOC_CSTR(PHPC_VAL_CAST_TO_PZVAL(userid), "comment", gpgme_userid->comment);
PHPC_ARRAY_ADD_ASSOC_CSTR(PHPC_VAL_CAST_TO_PZVAL(userid), "email", gpgme_userid->email);
PHPC_ARRAY_ADD_ASSOC_CSTR(PHPC_VAL_CAST_TO_PZVAL(userid), "uid", gpgme_userid->uid);
add_assoc_bool (&userid, "revoked", gpgme_userid->revoked );
add_assoc_bool (&userid, "invalid", gpgme_userid->invalid );
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(userid), "revoked", gpgme_userid->revoked);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(userid), "invalid", gpgme_userid->invalid);
add_next_index_zval (&userids, &userid);
PHPC_ARRAY_ADD_NEXT_INDEX_ZVAL(PHPC_VAL_CAST_TO_PZVAL(userids), PHPC_VAL_CAST_TO_PZVAL(userid));
gpgme_userid = gpgme_userid->next;
}
add_assoc_zval (&subarr, "uids", &userids);
add_assoc_zval(PHPC_VAL_CAST_TO_PZVAL(subarr), "uids", PHPC_VAL_CAST_TO_PZVAL(userids));
gpgme_subkey = gpgme_key->subkeys;
while (gpgme_subkey) {
array_init (&subkey);
PHPC_ARRAY_INIT(PHPC_VAL_CAST_TO_PZVAL(subkey));
if (gpgme_subkey->fpr) {
add_assoc_string (&subkey, "fingerprint", gpgme_subkey->fpr );
PHPC_ARRAY_ADD_ASSOC_CSTR(PHPC_VAL_CAST_TO_PZVAL(subkey), "fingerprint", gpgme_subkey->fpr);
}
add_assoc_string (&subkey, "keyid", gpgme_subkey->keyid );
PHPC_ARRAY_ADD_ASSOC_CSTR(PHPC_VAL_CAST_TO_PZVAL(subkey), "keyid", gpgme_subkey->keyid);
add_assoc_long (&subkey, "timestamp", gpgme_subkey->timestamp );
add_assoc_long (&subkey, "expires", gpgme_subkey->expires );
add_assoc_bool (&subkey, "is_secret", gpgme_subkey->secret );
add_assoc_bool (&subkey, "invalid", gpgme_subkey->invalid );
add_assoc_bool (&subkey, "can_encrypt", gpgme_subkey->can_encrypt );
add_assoc_bool (&subkey, "can_sign", gpgme_subkey->can_sign );
add_assoc_bool (&subkey, "disabled", gpgme_subkey->disabled );
add_assoc_bool (&subkey, "expired", gpgme_subkey->expired );
add_assoc_bool (&subkey, "revoked", gpgme_subkey->revoked );
PHPC_ARRAY_ADD_ASSOC_LONG(PHPC_VAL_CAST_TO_PZVAL(subkey), "timestamp", gpgme_subkey->timestamp);
PHPC_ARRAY_ADD_ASSOC_LONG(PHPC_VAL_CAST_TO_PZVAL(subkey), "expires", gpgme_subkey->expires);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subkey), "is_secret", gpgme_subkey->secret);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subkey), "invalid", gpgme_subkey->invalid);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subkey), "can_encrypt", gpgme_subkey->can_encrypt);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subkey), "can_sign", gpgme_subkey->can_sign);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subkey), "disabled", gpgme_subkey->disabled);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subkey), "expired", gpgme_subkey->expired);
PHPC_ARRAY_ADD_ASSOC_BOOL(PHPC_VAL_CAST_TO_PZVAL(subkey), "revoked", gpgme_subkey->revoked);
add_next_index_zval (&subkeys, &subkey);
PHPC_ARRAY_ADD_NEXT_INDEX_ZVAL(PHPC_VAL_CAST_TO_PZVAL(subkeys), PHPC_VAL_CAST_TO_PZVAL(subkey));
gpgme_subkey = gpgme_subkey->next;
}
add_assoc_zval (&subarr, "subkeys", &subkeys);
add_assoc_zval(PHPC_VAL_CAST_TO_PZVAL(subarr), "subkeys", PHPC_VAL_CAST_TO_PZVAL(subkeys));
add_next_index_zval (return_value, &subarr);
PHPC_ARRAY_ADD_NEXT_INDEX_ZVAL(return_value, PHPC_VAL_CAST_TO_PZVAL(subarr));
gpgme_key_unref(gpgme_key);
}
return;
}
/* }}} */
/* {{{ proto bool gnupg_addsignkey(string key) */
PHP_FUNCTION(gnupg_addsignkey){
PHP_FUNCTION(gnupg_addsignkey)
{
char *key_id = NULL;
size_t key_id_len;
phpc_str_size_t key_id_len;
char *passphrase = NULL;
size_t passphrase_len;
phpc_str_size_t passphrase_len;
gpgme_key_t gpgme_key;
gpgme_subkey_t gpgme_subkey;
@ -731,7 +745,7 @@ PHP_FUNCTION(gnupg_addsignkey){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s", &res, &key_id, &key_id_len, &passphrase, &passphrase_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if ((PHPC_THIS->err = gpgme_get_key(PHPC_THIS->ctx, key_id, &gpgme_key, 1)) != GPG_ERR_NO_ERROR) {
GNUPG_ERR("get_key failed");
@ -741,7 +755,7 @@ PHP_FUNCTION(gnupg_addsignkey){
gpgme_subkey = gpgme_key->subkeys;
while (gpgme_subkey) {
if (gpgme_subkey->can_sign == 1) {
zend_hash_str_add_ptr(PHPC_THIS->signkeys, (char *) gpgme_subkey->keyid, (uint) strlen(gpgme_subkey->keyid), passphrase);
PHPC_HASH_CSTR_ADD_PTR(PHPC_THIS->signkeys, gpgme_subkey->keyid, passphrase);
}
gpgme_subkey = gpgme_subkey->next;
}
@ -756,12 +770,12 @@ PHP_FUNCTION(gnupg_addsignkey){
/* }}} */
/* {{{ proto bool gnupg_adddecryptkey(string key) */
PHP_FUNCTION(gnupg_adddecryptkey){
PHP_FUNCTION(gnupg_adddecryptkey)
{
char *key_id = NULL;
size_t key_id_len;
phpc_str_size_t key_id_len;
char *passphrase = NULL;
size_t passphrase_len;
phpc_str_size_t passphrase_len;
gpgme_key_t gpgme_key;
gpgme_subkey_t gpgme_subkey;
@ -775,7 +789,7 @@ PHP_FUNCTION(gnupg_adddecryptkey){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &res, &key_id, &key_id_len, &passphrase, &passphrase_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if ((PHPC_THIS->err = gpgme_get_key(PHPC_THIS->ctx, key_id, &gpgme_key, 1)) != GPG_ERR_NO_ERROR) {
GNUPG_ERR("get_key failed");
@ -784,7 +798,7 @@ PHP_FUNCTION(gnupg_adddecryptkey){
gpgme_subkey = gpgme_key->subkeys;
while (gpgme_subkey) {
if (gpgme_subkey->secret == 1) {
zend_hash_str_add_ptr(PHPC_THIS->decryptkeys, (char *) gpgme_subkey->keyid, strlen(gpgme_subkey->keyid), passphrase);
PHPC_HASH_CSTR_ADD_PTR(PHPC_THIS->decryptkeys, gpgme_subkey->keyid, passphrase);
}
gpgme_subkey = gpgme_subkey->next;
}
@ -794,10 +808,10 @@ PHP_FUNCTION(gnupg_adddecryptkey){
/* }}} */
/* {{{ proto bool gnupg_addencryptkey(string key) */
PHP_FUNCTION(gnupg_addencryptkey){
PHP_FUNCTION(gnupg_addencryptkey)
{
char *key_id = NULL;
size_t key_id_len;
phpc_str_size_t key_id_len;
gpgme_key_t gpgme_key = NULL;
GNUPG_GETOBJ();
@ -810,7 +824,7 @@ PHP_FUNCTION(gnupg_addencryptkey){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &key_id, &key_id_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if ((PHPC_THIS->err = gpgme_get_key(PHPC_THIS->ctx, key_id, &gpgme_key, 0)) != GPG_ERR_NO_ERROR) {
@ -828,14 +842,15 @@ PHP_FUNCTION(gnupg_addencryptkey){
/* {{{ proto bool gnupg_clearsignerkeys(void)
* removes all keys which are set for signing
*/
PHP_FUNCTION(gnupg_clearsignkeys){
PHP_FUNCTION(gnupg_clearsignkeys)
{
GNUPG_GETOBJ();
if (!this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
gpgme_signers_clear (PHPC_THIS->ctx);
@ -847,14 +862,15 @@ PHP_FUNCTION(gnupg_clearsignkeys){
/* {{{ proto bool gnupg_clearencryptkeys(void)
* removes all keys which are set for encryption
*/
PHP_FUNCTION(gnupg_clearencryptkeys){
PHP_FUNCTION(gnupg_clearencryptkeys)
{
GNUPG_GETOBJ();
if (!this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
gnupg_free_encryptkeys(PHPC_THIS TSRMLS_CC);
@ -865,14 +881,15 @@ PHP_FUNCTION(gnupg_clearencryptkeys){
/* {{{ proto bool gnupg_clearsignerkeys(void)
* removes all keys which are set for signing
*/
PHP_FUNCTION(gnupg_cleardecryptkeys){
PHP_FUNCTION(gnupg_cleardecryptkeys)
{
GNUPG_GETOBJ();
if (!this) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &res) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
zend_hash_clean(PHPC_THIS->decryptkeys);
@ -885,12 +902,13 @@ PHP_FUNCTION(gnupg_cleardecryptkeys){
* and returns the signed text
* the signmode depends on gnupg_setsignmode
*/
PHP_FUNCTION(gnupg_sign){
PHP_FUNCTION(gnupg_sign)
{
char *value = NULL;
size_t value_len;
phpc_str_size_t value_len;
char *userret;
size_t ret_size;
phpc_str_size_t ret_size;
gpgme_data_t in, out;
gpgme_sign_result_t result;
@ -905,7 +923,7 @@ PHP_FUNCTION(gnupg_sign){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &value, &value_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
gpgme_set_passphrase_cb (PHPC_THIS->ctx, (void*) passphrase_cb, PHPC_THIS);
@ -956,11 +974,12 @@ PHP_FUNCTION(gnupg_sign){
* encrypts the given text with the key, which was set with setencryptkey before
* and returns the encrypted text
*/
PHP_FUNCTION(gnupg_encrypt){
PHP_FUNCTION(gnupg_encrypt)
{
char *value = NULL;
size_t value_len;
phpc_str_size_t value_len;
char *userret = NULL;
size_t ret_size;
phpc_str_size_t ret_size;
gpgme_data_t in, out;
gpgme_encrypt_result_t result;
@ -975,7 +994,7 @@ PHP_FUNCTION(gnupg_encrypt){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &value, &value_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if (!PHPC_THIS->encryptkeys) {
GNUPG_ERR("no key for encryption set");
@ -1017,11 +1036,12 @@ PHP_FUNCTION(gnupg_encrypt){
* encrypts and signs the given text with the keys, which weres set with setencryptkey and setsignkey before
* and returns the encrypted text
*/
PHP_FUNCTION(gnupg_encryptsign){
PHP_FUNCTION(gnupg_encryptsign)
{
char *value = NULL;
size_t value_len;
phpc_str_size_t value_len;
char *userret = NULL;
size_t ret_size;
phpc_str_size_t ret_size;
gpgme_data_t in, out;
gpgme_encrypt_result_t result;
@ -1037,7 +1057,7 @@ PHP_FUNCTION(gnupg_encryptsign){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &value, &value_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if (!PHPC_THIS->encryptkeys) {
@ -1099,7 +1119,8 @@ PHP_FUNCTION(gnupg_encryptsign){
/* {{{ proto array gnupg_verify(string text, string signature [, string &plaintext])
* verifies the given clearsigned text and returns information about the result in an array
*/
PHP_FUNCTION(gnupg_verify){
PHP_FUNCTION(gnupg_verify)
{
gpgme_data_t gpgme_text, gpgme_sig;
gpgme_verify_result_t gpgme_result;
@ -1108,7 +1129,7 @@ PHP_FUNCTION(gnupg_verify){
zval *plain_text = NULL; /* signed_text without the signature if its not a detached sig */
char *gpg_plain;
size_t gpg_plain_len;
phpc_str_size_t gpg_plain_len;
GNUPG_GETOBJ();
@ -1120,7 +1141,7 @@ PHP_FUNCTION(gnupg_verify){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rzz|z", &res, &signed_text, &signature, &plain_text) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if (Z_TYPE_P(signature) == IS_STRING) { /* detached signature */
/* setup signature-databuffer for gpgme */
@ -1184,12 +1205,13 @@ PHP_FUNCTION(gnupg_verify){
/* {{{ proto string gnupg_decrypt(string enctext)
* decrypts the given enctext
*/
PHP_FUNCTION(gnupg_decrypt){
PHP_FUNCTION(gnupg_decrypt)
{
char *enctxt;
size_t enctxt_len;
phpc_str_size_t enctxt_len;
char *userret;
size_t ret_size;
phpc_str_size_t ret_size;
gpgme_data_t in, out;
gpgme_decrypt_result_t result;
@ -1204,7 +1226,7 @@ PHP_FUNCTION(gnupg_decrypt){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &enctxt, &enctxt_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
gpgme_set_passphrase_cb (PHPC_THIS->ctx, (void*) passphrase_decrypt_cb, PHPC_THIS);
@ -1246,13 +1268,14 @@ PHP_FUNCTION(gnupg_decrypt){
/* {{{ proto string gnupg_decryptverify(string enctext, string &plaintext)
* decrypts the given enctext
*/
PHP_FUNCTION(gnupg_decryptverify){
PHP_FUNCTION(gnupg_decryptverify)
{
char *enctxt;
size_t enctxt_len;
phpc_str_size_t enctxt_len;
zval *plaintext;
char *userret;
size_t ret_size;
phpc_str_size_t ret_size;
gpgme_data_t in, out;
gpgme_decrypt_result_t decrypt_result;
@ -1268,7 +1291,7 @@ PHP_FUNCTION(gnupg_decryptverify){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsz", &res, &enctxt, &enctxt_len, &plaintext) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
ZVAL_DEREF(plaintext);
@ -1314,11 +1337,12 @@ PHP_FUNCTION(gnupg_decryptverify){
/* {{{ proto string gnupg_export(string pattern)
* exports the first public key which matches against the given pattern
*/
PHP_FUNCTION(gnupg_export){
PHP_FUNCTION(gnupg_export)
{
char *searchkey = NULL;
size_t searchkey_len;
phpc_str_size_t searchkey_len;
char *userret;
size_t ret_size;
phpc_str_size_t ret_size;
gpgme_data_t out;
@ -1332,7 +1356,7 @@ PHP_FUNCTION(gnupg_export){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &searchkey, &searchkey_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if ((PHPC_THIS->err = gpgme_data_new (&out))!=GPG_ERR_NO_ERROR) {
GNUPG_ERR("could not create data buffer");
@ -1355,9 +1379,10 @@ PHP_FUNCTION(gnupg_export){
/* {{{ proto array gnupg_import(string key)
* imports the given key and returns a status-array
*/
PHP_FUNCTION(gnupg_import){
PHP_FUNCTION(gnupg_import)
{
char *importkey = NULL;
size_t importkey_len;
phpc_str_size_t importkey_len;
gpgme_data_t in;
gpgme_import_result_t result;
@ -1372,7 +1397,7 @@ PHP_FUNCTION(gnupg_import){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &importkey, &importkey_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if ((PHPC_THIS->err = gpgme_data_new_from_mem (&in, importkey, importkey_len, 0))!=GPG_ERR_NO_ERROR) {
GNUPG_ERR("could not create in-data buffer");
@ -1389,17 +1414,17 @@ PHP_FUNCTION(gnupg_import){
if (!result || !result->imports || result->imports->result != GPG_ERR_NO_ERROR) {
RETURN_FALSE;
}
array_init (return_value);
add_assoc_long (return_value, "imported", result->imported);
add_assoc_long (return_value, "unchanged", result->unchanged);
add_assoc_long (return_value, "newuserids", result->new_user_ids);
add_assoc_long (return_value, "newsubkeys", result->new_sub_keys);
add_assoc_long (return_value, "secretimported", result->secret_imported);
add_assoc_long (return_value, "secretunchanged", result->secret_unchanged);
add_assoc_long (return_value, "newsignatures", result->new_signatures);
add_assoc_long (return_value, "skippedkeys", result->skipped_new_keys);
PHPC_ARRAY_INIT (return_value);
PHPC_ARRAY_ADD_ASSOC_LONG (return_value, "imported", result->imported);
PHPC_ARRAY_ADD_ASSOC_LONG (return_value, "unchanged", result->unchanged);
PHPC_ARRAY_ADD_ASSOC_LONG (return_value, "newuserids", result->new_user_ids);
PHPC_ARRAY_ADD_ASSOC_LONG (return_value, "newsubkeys", result->new_sub_keys);
PHPC_ARRAY_ADD_ASSOC_LONG (return_value, "secretimported", result->secret_imported);
PHPC_ARRAY_ADD_ASSOC_LONG (return_value, "secretunchanged", result->secret_unchanged);
PHPC_ARRAY_ADD_ASSOC_LONG (return_value, "newsignatures", result->new_signatures);
PHPC_ARRAY_ADD_ASSOC_LONG (return_value, "skippedkeys", result->skipped_new_keys);
if (result->imports && result->imports->fpr) {
add_assoc_string (return_value, "fingerprint", result->imports->fpr);
PHPC_ARRAY_ADD_ASSOC_CSTR (return_value, "fingerprint", result->imports->fpr);
}
}
/* }}} */
@ -1407,9 +1432,10 @@ PHP_FUNCTION(gnupg_import){
/* {{{ proto book gnupg_deletekey(string key)
* deletes a key from the keyring
*/
PHP_FUNCTION(gnupg_deletekey){
PHP_FUNCTION(gnupg_deletekey)
{
char *key;
size_t key_len;
phpc_str_size_t key_len;
zend_long allow_secret = 0;
gpgme_key_t gpgme_key;
@ -1424,7 +1450,7 @@ PHP_FUNCTION(gnupg_deletekey){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &res, &key, &key_len, &allow_secret) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if ((PHPC_THIS->err = gpgme_get_key(PHPC_THIS->ctx, key, &gpgme_key, 0)) != GPG_ERR_NO_ERROR) {
@ -1444,9 +1470,10 @@ PHP_FUNCTION(gnupg_deletekey){
/* {{{ proto array gnupg_gettrustlist(string pattern)
* searching for trust items which match PATTERN
*/
PHP_FUNCTION(gnupg_gettrustlist){
PHP_FUNCTION(gnupg_gettrustlist)
{
char *pattern;
size_t pattern_len;
phpc_str_size_t pattern_len;
zval sub_arr;
gpgme_trust_item_t item;
@ -1461,32 +1488,33 @@ PHP_FUNCTION(gnupg_gettrustlist){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &pattern, &pattern_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if ((PHPC_THIS->err = gpgme_op_trustlist_start (PHPC_THIS->ctx, pattern, 0))!=GPG_ERR_NO_ERROR) {
GNUPG_ERR("could not start trustlist");
return;
}
array_init(return_value);
PHPC_ARRAY_INIT(return_value);
while (!(PHPC_THIS->err = gpgme_op_trustlist_next (PHPC_THIS->ctx, &item))) {
array_init (&sub_arr);
PHPC_ARRAY_INIT (&sub_arr);
add_assoc_long (&sub_arr, "level", item->level );
add_assoc_long (&sub_arr, "type", item->type );
add_assoc_string (&sub_arr, "keyid", item->keyid );
add_assoc_string (&sub_arr, "ownertrust", item->owner_trust );
add_assoc_string (&sub_arr, "validity", item->validity );
add_assoc_string (&sub_arr, "name", item->name );
PHPC_ARRAY_ADD_ASSOC_LONG (&sub_arr, "level", item->level );
PHPC_ARRAY_ADD_ASSOC_LONG (&sub_arr, "type", item->type );
PHPC_ARRAY_ADD_ASSOC_CSTR (&sub_arr, "keyid", item->keyid );
PHPC_ARRAY_ADD_ASSOC_CSTR (&sub_arr, "ownertrust", item->owner_trust );
PHPC_ARRAY_ADD_ASSOC_CSTR (&sub_arr, "validity", item->validity );
PHPC_ARRAY_ADD_ASSOC_CSTR (&sub_arr, "name", item->name );
gpgme_trust_item_unref (item);
add_next_index_zval (return_value, &sub_arr);
PHPC_ARRAY_ADD_NEXT_INDEX_ZVAL (return_value, &sub_arr);
}
}
/* }}} */
/* {{{ proto array gnupg_listsignatures(string keyid) */
PHP_FUNCTION(gnupg_listsignatures){
PHP_FUNCTION(gnupg_listsignatures)
{
char *keyid;
size_t keyid_len;
phpc_str_size_t keyid_len;
zval sub_arr;
zval sig_arr;
@ -1505,7 +1533,7 @@ PHP_FUNCTION(gnupg_listsignatures){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &res, &keyid, &keyid_len) == FAILURE) {
return;
}
PHPC_THIS = (gnupg_object *) zend_fetch_resource(Z_RES_P(res), "ctx", le_gnupg);
GNUPG_RES_FETCH();
}
if ((PHPC_THIS->err = gpgme_set_keylist_mode(PHPC_THIS->ctx,GPGME_KEYLIST_MODE_SIGS))!=GPG_ERR_NO_ERROR) {
GNUPG_ERR("could not switch to sigmode");
@ -1520,22 +1548,22 @@ PHP_FUNCTION(gnupg_listsignatures){
gpgme_key_unref(gpgme_key);
return;
}
array_init(return_value);
PHPC_ARRAY_INIT(return_value);
gpgme_userid = gpgme_key->uids;
while (gpgme_userid) {
array_init (&sub_arr);
PHPC_ARRAY_INIT (&sub_arr);
gpgme_signature = gpgme_userid->signatures;
while (gpgme_signature) {
array_init (&sig_arr);
PHPC_ARRAY_INIT (&sig_arr);
add_assoc_string (&sig_arr, "uid", gpgme_signature->uid );
add_assoc_string (&sig_arr, "name", gpgme_signature->name );
add_assoc_string (&sig_arr, "email", gpgme_signature->email );
add_assoc_string (&sig_arr, "comment", gpgme_signature->comment );
add_assoc_long (&sig_arr, "expires", gpgme_signature->expires );
add_assoc_bool (&sig_arr, "revoked", gpgme_signature->revoked );
add_assoc_bool (&sig_arr, "expired", gpgme_signature->expired );
add_assoc_bool (&sig_arr, "invalid", gpgme_signature->invalid );
PHPC_ARRAY_ADD_ASSOC_CSTR (&sig_arr, "uid", gpgme_signature->uid );
PHPC_ARRAY_ADD_ASSOC_CSTR(&sig_arr, "name", gpgme_signature->name );
PHPC_ARRAY_ADD_ASSOC_CSTR(&sig_arr, "email", gpgme_signature->email );
PHPC_ARRAY_ADD_ASSOC_CSTR(&sig_arr, "comment", gpgme_signature->comment );
PHPC_ARRAY_ADD_ASSOC_LONG (&sig_arr, "expires", gpgme_signature->expires );
PHPC_ARRAY_ADD_ASSOC_BOOL (&sig_arr, "revoked", gpgme_signature->revoked );
PHPC_ARRAY_ADD_ASSOC_BOOL (&sig_arr, "expired", gpgme_signature->expired );
PHPC_ARRAY_ADD_ASSOC_BOOL (&sig_arr, "invalid", gpgme_signature->invalid );
add_assoc_zval (&sub_arr, gpgme_signature->keyid, &sig_arr);
gpgme_signature = gpgme_signature->next;
}

2
phpc

@ -1 +1 @@
Subproject commit 28b8bdf2a78a31772a325099806eb984ac9063ea
Subproject commit 11299415b61f6c90f26410517e0c673b47efb7d8