Re: Convert zval array to char **

From: Date: Fri, 22 Jul 2005 17:05:00 +0000
Subject: Re: Convert zval array to char **
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-2638@lists.php.net to get a copy of this message
The char** the function wants is a vector of strings, not a single delimited string. Try this out: > PHP_FUNCTION(hsbc_cpi_make_hash) > { > > char *strEncryptedKey; > int strEncryptedKey_len; > zval *arr, **data; > HashTable *arr_hash; > HashPosition pointer; > char **ppHashElements; > char *strHashValue; > int rc=0; > int array_count; > int count = 0; > int bcount = 0; > > if ( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "as", &arr, > &strEncryptedKey, &strEncryptedKey_len) == FAILURE ) { > RETURN_NULL(); > } > > arr_hash = Z_ARRVAL_P(arr); > array_count = zend_hash_num_elements(arr_hash); > /* Allocate a vector of char* pointers to point at individual string elements * Leave room for one additional pointer at the end to act as a terminating NULL */ ppHashElements = safe_emalloc(array_count, sizeof(char*), sizeof(char*)); > > for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); > zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == > SUCCESS; > zend_hash_move_forward_ex(arr_hash, &pointer)){ > zval temp; > temp = **data; > zval_copy_ctor(&temp); > convert_to_string(&temp); ppHashElements[count] = Z_STRVAL(temp); /* zval needn't be dtor'd here since the alloc'd portion will be freed below */ > count++; > } ppHashElements[count] = NULL; > > strHashValue = GenerateHash(ppHashElements, strEncryptedKey ); > > php_printf("%s\n", strEncryptedKey); > php_printf("%s\n", strHashValue); > while((--count) >= 0) { /* Free individual hash elements */ efree(ppHashElements[count]); } /* Free vector */ efree(ppHashElements); > /* This smells a little non-threadsafe, you might want to look a little closer */ > if(!strHashValue){ > RETURN_FALSE; > } > > RETURN_STRING(strHashValue, 1); > > }

« previous php.pecl.dev (#2638) next »