int rs;
timelib_time *t;
timelib_tzinfo *tzi;
- char *retstr;
+ zend_string *retstr;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ldddd", &time, &retformat, &latitude, &longitude, &zenith, &gmt_offset) == FAILURE) {
RETURN_FALSE;
switch (retformat) {
case SUNFUNCS_RET_STRING:
- spprintf(&retstr, 0, "%02d:%02d", (int) N, (int) (60 * (N - (int) N)));
- // TODO: avoid reallocation ???
- RETVAL_STRINGL(retstr, 5);
- efree(retstr);
- return;
+ retstr = strpprintf(0, "%02d:%02d", (int) N, (int) (60 * (N - (int) N)));
+ RETURN_STR(retstr);
break;
case SUNFUNCS_RET_DOUBLE:
RETURN_DOUBLE(N);
static void _php_make_header_object(zval *myzvalue, ENVELOPE *en TSRMLS_DC);
static void _php_imap_add_body(zval *arg, BODY *body TSRMLS_DC);
-static char* _php_imap_parse_address(ADDRESS *addresslist, zval *paddress TSRMLS_DC);
-static char* _php_rfc822_write_address(ADDRESS *addresslist TSRMLS_DC);
+static zend_string* _php_imap_parse_address(ADDRESS *addresslist, zval *paddress TSRMLS_DC);
+static zend_string* _php_rfc822_write_address(ADDRESS *addresslist TSRMLS_DC);
/* the gets we use */
static char *php_mail_gets(readfn_t f, void *stream, unsigned long size, GETS_DATA *md);
ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
- limits.text.data = "STORAGE";
+ limits.text.data = (unsigned char*)"STORAGE";
limits.text.size = mailbox_size;
limits.next = NIL;
array_init(return_value);
cur=IMAPG(imap_folders);
while (cur != NIL) {
- add_next_index_string(return_value, cur->LTEXT);
+ add_next_index_string(return_value, (char*)cur->LTEXT);
cur=cur->next;
}
mail_free_stringlist (&IMAPG(imap_folders));
cur=IMAPG(imap_folder_objects);
while (cur != NIL) {
object_init(&mboxob);
- add_property_string(&mboxob, "name", cur->LTEXT);
+ add_property_string(&mboxob, "name", (char*)cur->LTEXT);
add_property_long(&mboxob, "attributes", cur->attributes);
#ifdef IMAP41
delim[0] = (char)cur->delimiter;
array_init(return_value);
cur=IMAPG(imap_folders);
while (cur != NIL) {
- add_next_index_string(return_value, cur->LTEXT);
+ add_next_index_string(return_value, (char*)cur->LTEXT);
cur=cur->next;
}
mail_free_stringlist (&IMAPG(imap_folders));
array_init(return_value);
cur=IMAPG(imap_sfolders);
while (cur != NIL) {
- add_next_index_string(return_value, cur->LTEXT);
+ add_next_index_string(return_value, (char*)cur->LTEXT);
cur=cur->next;
}
mail_free_stringlist (&IMAPG(imap_sfolders));
cur=IMAPG(imap_sfolder_objects);
while (cur != NIL) {
object_init(&mboxob);
- add_property_string(&mboxob, "name", cur->LTEXT);
+ add_property_string(&mboxob, "name", (char*)cur->LTEXT);
add_property_long(&mboxob, "attributes", cur->attributes);
#ifdef IMAP41
delim[0] = (char)cur->delimiter;
return;
}
- decode = rfc822_binary(text, text_len, &newlength);
+ decode = (char*)rfc822_binary(text, text_len, &newlength);
if (decode == NULL) {
RETURN_FALSE;
char *mailbox, *host, *personal;
int mailbox_len, host_len, personal_len;
ADDRESS *addr;
- char *string;
+ zend_string *string;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &mailbox, &mailbox_len, &host, &host_len, &personal, &personal_len) == FAILURE) {
return;
string = _php_rfc822_write_address(addr TSRMLS_CC);
if (string) {
- RETVAL_STRING(string);
- efree(string);
+ RETVAL_STR(string);
} else {
RETURN_FALSE;
}
#else
utf8_mime2text(&src, &dest, U8T_DECOMPOSE);
#endif
- RETVAL_STRINGL(dest.data, dest.size);
+ RETVAL_STRINGL((char*)dest.data, dest.size);
if (dest.data) {
free(dest.data);
}
}
#endif
- RETURN_STRINGL(out, outlen);
+ RETURN_STRINGL((char*)out, outlen);
}
/* }}} */
out = STR_ALLOC(outlen, 0);
/* encode input string */
- outp = out->val;
+ outp = (unsigned char*)out->val;
state = ST_NORMAL;
endp = (inp = in) + inlen;
while (inp < endp || state != ST_NORMAL) {
object_init(return_value);
- body=mail_body(imap_le_struct->imap_stream, msg, section);
+ body=mail_body(imap_le_struct->imap_stream, msg, (unsigned char*)section);
if (body == NULL) {
zval_dtor(return_value);
RETURN_FALSE;
int sequence_len;
pils *imap_le_struct;
zval myoverview;
- char *address;
+ zend_string *address;
long status, flags = 0L;
int argc = ZEND_NUM_ARGS();
array_init(return_value);
status = (flags & FT_UID)
- ? mail_uid_sequence(imap_le_struct->imap_stream, sequence)
- : mail_sequence(imap_le_struct->imap_stream, sequence);
+ ? mail_uid_sequence(imap_le_struct->imap_stream, (unsigned char*)sequence)
+ : mail_sequence(imap_le_struct->imap_stream, (unsigned char*)sequence);
if (status) {
MESSAGECACHE *elt;
env->from->next=NULL;
address =_php_rfc822_write_address(env->from TSRMLS_CC);
if (address) {
- // TODO: avoid reallocation ???
- add_property_string(&myoverview, "from", address);
- efree(address);
+ add_property_str(&myoverview, "from", address);
}
}
if (env->to) {
env->to->next = NULL;
address = _php_rfc822_write_address(env->to TSRMLS_CC);
if (address) {
- // TODO: avoid reallocation ???
- add_property_string(&myoverview, "to", address);
- efree(address);
+ add_property_str(&myoverview, "to", address);
}
}
if (env->date) {
- add_property_string(&myoverview, "date", env->date);
+ add_property_string(&myoverview, "date", (char*)env->date);
}
if (env->message_id) {
add_property_string(&myoverview, "message_id", env->message_id);
}
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(envelope), "date", sizeof("date") - 1)) != NULL) {
convert_to_string_ex(pvalue);
- env->date = cpystr(Z_STRVAL_P(pvalue));
+ env->date = (unsigned char*)cpystr(Z_STRVAL_P(pvalue));
}
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(envelope), "from", sizeof("from") - 1)) != NULL) {
convert_to_string_ex(pvalue);
}
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) {
convert_to_string_ex(pvalue);
- bod->contents.text.data = (char *) fs_get(Z_STRLEN_P(pvalue) + 1);
+ bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1);
memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1);
bod->contents.text.size = Z_STRLEN_P(pvalue);
} else {
- bod->contents.text.data = (char *) fs_get(1);
+ bod->contents.text.data = fs_get(1);
memcpy(bod->contents.text.data, "", 1);
bod->contents.text.size = 0;
}
}
if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) {
convert_to_string_ex(pvalue);
- bod->contents.text.data = (char *) fs_get(Z_STRLEN_P(pvalue) + 1);
+ bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1);
memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue) + 1);
bod->contents.text.size = Z_STRLEN_P(pvalue);
} else {
- bod->contents.text.data = (char *) fs_get(1);
+ bod->contents.text.data = fs_get(1);
memcpy(bod->contents.text.data, "", 1);
bod->contents.text.size = 0;
}
cur = IMAPG(imap_alertstack);
while (cur != NIL) {
- add_next_index_string(return_value, cur->LTEXT);
+ add_next_index_string(return_value, (char*)cur->LTEXT);
cur = cur->next;
}
mail_free_stringlist(&IMAPG(imap_alertstack));
cur = IMAPG(imap_errorstack);
while (cur != NIL) {
- add_next_index_string(return_value, cur->LTEXT);
+ add_next_index_string(return_value, (char*)cur->LTEXT);
cur = cur->next;
}
mail_free_errorlist(&IMAPG(imap_errorstack));
cur = IMAPG(imap_errorstack);
while (cur != NIL) {
if (cur->next == NIL) {
- RETURN_STRING(cur->LTEXT);
+ RETURN_STRING((char*)cur->LTEXT);
}
cur = cur->next;
}
/* {{{ _php_rfc822_write_address
*/
-static char* _php_rfc822_write_address(ADDRESS *addresslist TSRMLS_DC)
+static zend_string* _php_rfc822_write_address(ADDRESS *addresslist TSRMLS_DC)
{
char address[MAILTMPLEN];
- char *str;
smart_str ret = {0};
RFC822BUFFER buf;
rfc822_output_address_list(&buf, addresslist, 0, NULL);
rfc822_output_flush(&buf);
smart_str_0(&ret);
- /* avoide dup? */
- str = estrndup(ret.s->val, ret.s->len);
- smart_str_free(&ret);
-
- return str;
+ return ret.s;
}
/* }}} */
/* {{{ _php_rfc822_write_address
*/
-static char* _php_rfc822_write_address(ADDRESS *addresslist TSRMLS_DC)
+static zend_string* _php_rfc822_write_address(ADDRESS *addresslist TSRMLS_DC)
{
char address[SENDBUFLEN];
}
address[0] = 0;
rfc822_write_address(address, addresslist);
- return estrdup(address);
+ return STR_INIT(address, strlen(address), 0);
}
/* }}} */
#endif
/* {{{ _php_imap_parse_address
*/
-static char* _php_imap_parse_address (ADDRESS *addresslist, zval *paddress TSRMLS_DC)
+static zend_string* _php_imap_parse_address (ADDRESS *addresslist, zval *paddress TSRMLS_DC)
{
- char *fulladdress;
+ zend_string *fulladdress;
ADDRESS *addresstmp;
zval tmpvals;
static void _php_make_header_object(zval *myzvalue, ENVELOPE *en TSRMLS_DC)
{
zval paddress;
- char *fulladdress=NULL;
+ zend_string *fulladdress=NULL;
object_init(myzvalue);
if (en->remail) add_property_string(myzvalue, "remail", en->remail);
- if (en->date) add_property_string(myzvalue, "date", en->date);
- if (en->date) add_property_string(myzvalue, "Date", en->date);
+ if (en->date) add_property_string(myzvalue, "date", (char*)en->date);
+ if (en->date) add_property_string(myzvalue, "Date", (char*)en->date);
if (en->subject) add_property_string(myzvalue, "subject", en->subject);
if (en->subject) add_property_string(myzvalue, "Subject", en->subject);
if (en->in_reply_to) add_property_string(myzvalue, "in_reply_to", en->in_reply_to);
array_init(&paddress);
fulladdress = _php_imap_parse_address(en->to, &paddress TSRMLS_CC);
if (fulladdress) {
- // TODO: avoid reallocation ???
- add_property_string(myzvalue, "toaddress", fulladdress);
- efree(fulladdress);
+ add_property_str(myzvalue, "toaddress", fulladdress);
}
add_assoc_object(myzvalue, "to", &paddress TSRMLS_CC);
}
array_init(&paddress);
fulladdress = _php_imap_parse_address(en->from, &paddress TSRMLS_CC);
if (fulladdress) {
- // TODO: avoid reallocation ???
- add_property_string(myzvalue, "fromaddress", fulladdress);
- efree(fulladdress);
+ add_property_str(myzvalue, "fromaddress", fulladdress);
}
add_assoc_object(myzvalue, "from", &paddress TSRMLS_CC);
}
array_init(&paddress);
fulladdress = _php_imap_parse_address(en->cc, &paddress TSRMLS_CC);
if (fulladdress) {
- // TODO: avoid reallocation ???
- add_property_string(myzvalue, "ccaddress", fulladdress);
- efree(fulladdress);
+ add_property_str(myzvalue, "ccaddress", fulladdress);
}
add_assoc_object(myzvalue, "cc", &paddress TSRMLS_CC);
}
array_init(&paddress);
fulladdress = _php_imap_parse_address(en->bcc, &paddress TSRMLS_CC);
if (fulladdress) {
- // TODO: avoid reallocation ???
- add_property_string(myzvalue, "bccaddress", fulladdress);
- efree(fulladdress);
+ add_property_str(myzvalue, "bccaddress", fulladdress);
}
add_assoc_object(myzvalue, "bcc", &paddress TSRMLS_CC);
}
array_init(&paddress);
fulladdress = _php_imap_parse_address(en->reply_to, &paddress TSRMLS_CC);
if (fulladdress) {
- // TODO: avoid reallocation ???
- add_property_string(myzvalue, "reply_toaddress", fulladdress);
- efree(fulladdress);
+ add_property_str(myzvalue, "reply_toaddress", fulladdress);
}
add_assoc_object(myzvalue, "reply_to", &paddress TSRMLS_CC);
}
array_init(&paddress);
fulladdress = _php_imap_parse_address(en->sender, &paddress TSRMLS_CC);
if (fulladdress) {
- // TODO: avoid reallocation ???
- add_property_string(myzvalue, "senderaddress", fulladdress);
- efree(fulladdress);
+ add_property_str(myzvalue, "senderaddress", fulladdress);
}
add_assoc_object(myzvalue, "sender", &paddress TSRMLS_CC);
}
array_init(&paddress);
fulladdress = _php_imap_parse_address(en->return_path, &paddress TSRMLS_CC);
if (fulladdress) {
- // TODO: avoid reallocation ???
- add_property_string(myzvalue, "return_pathaddress", fulladdress);
- efree(fulladdress);
+ add_property_str(myzvalue, "return_pathaddress", fulladdress);
}
add_assoc_object(myzvalue, "return_path", &paddress TSRMLS_CC);
}
if (strncmp(str, "[ALERT] ", 8) == 0) {
if (IMAPG(imap_alertstack) == NIL) {
IMAPG(imap_alertstack) = mail_newstringlist();
- IMAPG(imap_alertstack)->LSIZE = strlen(IMAPG(imap_alertstack)->LTEXT = cpystr(str));
+ IMAPG(imap_alertstack)->LSIZE = strlen((char*)(IMAPG(imap_alertstack)->LTEXT = (unsigned char*)cpystr(str)));
IMAPG(imap_alertstack)->next = NIL;
} else {
cur = IMAPG(imap_alertstack);
}
cur->next = mail_newstringlist ();
cur = cur->next;
- cur->LSIZE = strlen(cur->LTEXT = cpystr(str));
+ cur->LSIZE = strlen((char*)(cur->LTEXT = (unsigned char*)cpystr(str)));
cur->next = NIL;
}
}
/* Author: CJH */
if (IMAPG(imap_folder_objects) == NIL) {
IMAPG(imap_folder_objects) = mail_newfolderobjectlist();
- IMAPG(imap_folder_objects)->LSIZE=strlen(IMAPG(imap_folder_objects)->LTEXT=cpystr(mailbox));
+ IMAPG(imap_folder_objects)->LSIZE=strlen((char*)(IMAPG(imap_folder_objects)->LTEXT = (unsigned char*)cpystr(mailbox)));
IMAPG(imap_folder_objects)->delimiter = delimiter;
IMAPG(imap_folder_objects)->attributes = attributes;
IMAPG(imap_folder_objects)->next = NIL;
ocur=IMAPG(imap_folder_objects_tail);
ocur->next=mail_newfolderobjectlist();
ocur=ocur->next;
- ocur->LSIZE = strlen(ocur->LTEXT = cpystr(mailbox));
+ ocur->LSIZE = strlen((char*)(ocur->LTEXT = (unsigned char*)cpystr(mailbox)));
ocur->delimiter = delimiter;
ocur->attributes = attributes;
ocur->next = NIL;
if (!(attributes & LATT_NOSELECT)) {
if (IMAPG(imap_folders) == NIL) {
IMAPG(imap_folders)=mail_newstringlist();
- IMAPG(imap_folders)->LSIZE=strlen(IMAPG(imap_folders)->LTEXT=cpystr(mailbox));
+ IMAPG(imap_folders)->LSIZE=strlen((char*)(IMAPG(imap_folders)->LTEXT = (unsigned char*)cpystr(mailbox)));
IMAPG(imap_folders)->next=NIL;
IMAPG(imap_folders_tail) = IMAPG(imap_folders);
} else {
cur=IMAPG(imap_folders_tail);
cur->next=mail_newstringlist ();
cur=cur->next;
- cur->LSIZE = strlen (cur->LTEXT = cpystr (mailbox));
+ cur->LSIZE = strlen((char*)(cur->LTEXT = (unsigned char*)cpystr(mailbox)));
cur->next = NIL;
IMAPG(imap_folders_tail) = cur;
}
/* Author: CJH */
if (IMAPG(imap_sfolder_objects) == NIL) {
IMAPG(imap_sfolder_objects) = mail_newfolderobjectlist();
- IMAPG(imap_sfolder_objects)->LSIZE=strlen(IMAPG(imap_sfolder_objects)->LTEXT=cpystr(mailbox));
+ IMAPG(imap_sfolder_objects)->LSIZE = strlen((char*)(IMAPG(imap_sfolder_objects)->LTEXT = (unsigned char*)cpystr(mailbox)));
IMAPG(imap_sfolder_objects)->delimiter = delimiter;
IMAPG(imap_sfolder_objects)->attributes = attributes;
IMAPG(imap_sfolder_objects)->next = NIL;
ocur=IMAPG(imap_sfolder_objects_tail);
ocur->next=mail_newfolderobjectlist();
ocur=ocur->next;
- ocur->LSIZE=strlen(ocur->LTEXT = cpystr(mailbox));
+ ocur->LSIZE=strlen((char*)(ocur->LTEXT = (unsigned char*)cpystr(mailbox)));
ocur->delimiter = delimiter;
ocur->attributes = attributes;
ocur->next = NIL;
/* build the old simple array for imap_listsubscribed() */
if (IMAPG(imap_sfolders) == NIL) {
IMAPG(imap_sfolders)=mail_newstringlist();
- IMAPG(imap_sfolders)->LSIZE=strlen(IMAPG(imap_sfolders)->LTEXT=cpystr(mailbox));
+ IMAPG(imap_sfolders)->LSIZE=strlen((char*)(IMAPG(imap_sfolders)->LTEXT = (unsigned char*)cpystr(mailbox)));
IMAPG(imap_sfolders)->next=NIL;
IMAPG(imap_sfolders_tail) = IMAPG(imap_sfolders);
} else {
cur=IMAPG(imap_sfolders_tail);
cur->next=mail_newstringlist ();
cur=cur->next;
- cur->LSIZE = strlen (cur->LTEXT = cpystr (mailbox));
+ cur->LSIZE = strlen((char*)(cur->LTEXT = (unsigned char*)cpystr(mailbox)));
cur->next = NIL;
IMAPG(imap_sfolders_tail) = cur;
}
if (errflg != NIL) { /* CJH: maybe put these into a more comprehensive log for debugging purposes? */
if (IMAPG(imap_errorstack) == NIL) {
IMAPG(imap_errorstack) = mail_newerrorlist();
- IMAPG(imap_errorstack)->LSIZE = strlen(IMAPG(imap_errorstack)->LTEXT = cpystr(str));
+ IMAPG(imap_errorstack)->LSIZE = strlen((char*)(IMAPG(imap_errorstack)->LTEXT = (unsigned char*)cpystr(str)));
IMAPG(imap_errorstack)->errflg = errflg;
IMAPG(imap_errorstack)->next = NIL;
} else {
}
cur->next = mail_newerrorlist();
cur = cur->next;
- cur->LSIZE = strlen(cur->LTEXT = cpystr(str));
+ cur->LSIZE = strlen((char*)(cur->LTEXT = (unsigned char*)cpystr(str)));
cur->errflg = errflg;
cur->next = NIL;
}
}
/* }}} */
-int php_openssl_x509_fingerprint(X509 *peer, const char *method, zend_bool raw, char **out, int *out_len TSRMLS_DC)
+zend_string* php_openssl_x509_fingerprint(X509 *peer, const char *method, zend_bool raw TSRMLS_DC)
{
unsigned char md[EVP_MAX_MD_SIZE];
const EVP_MD *mdtype;
unsigned int n;
+ zend_string *ret;
if (!(mdtype = EVP_get_digestbyname(method))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown signature algorithm");
- return FAILURE;
+ return NULL;
} else if (!X509_digest(peer, mdtype, md, &n)) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not generate signature");
- return FAILURE;
+ return NULL;
}
if (raw) {
- *out_len = n;
- *out = estrndup((char *) md, n);
+ ret = STR_INIT((char*)md, n, 0);
} else {
- *out_len = n * 2;
- *out = emalloc(*out_len + 1);
-
- make_digest_ex(*out, md, n);
+ ret = STR_ALLOC(n * 2, 0);
+ make_digest_ex(ret->val, md, n);
+ ret->val[n * 2] = '\0';
}
- return SUCCESS;
+ return ret;
}
PHP_FUNCTION(openssl_x509_fingerprint)
zend_bool raw_output = 0;
char *method = "sha1";
int method_len;
-
- char *fingerprint;
- int fingerprint_len;
+ zend_string *fingerprint;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|sb", &zcert, &method, &method_len, &raw_output) == FAILURE) {
return;
RETURN_FALSE;
}
- if (php_openssl_x509_fingerprint(cert, method, raw_output, &fingerprint, &fingerprint_len TSRMLS_CC) == SUCCESS) {
- // TODO: avoid reallocation ???
- RETVAL_STRINGL(fingerprint, fingerprint_len);
- efree(fingerprint);
+ fingerprint = php_openssl_x509_fingerprint(cert, method, raw_output TSRMLS_CC);
+ if (fingerprint) {
+ RETVAL_STR(fingerprint);
} else {
RETVAL_FALSE;
}
#define OPENSSL_PKEY_GET_BN(_type, _name) do { \
if (pkey->pkey._type->_name != NULL) { \
int len = BN_num_bytes(pkey->pkey._type->_name); \
- char *str = emalloc(len + 1); \
- BN_bn2bin(pkey->pkey._type->_name, (unsigned char*)str); \
- str[len] = 0; \
- /* TODO: avoid reallocation ??? */ \
- add_assoc_stringl(&_type, #_name, str, len); \
- efree(str); \
+ zend_string *str = STR_ALLOC(len, 0); \
+ BN_bn2bin(pkey->pkey._type->_name, (unsigned char*)str->val); \
+ str->val[len] = 0; \
+ add_assoc_str(&_type, #_name, str); \
} \
} while (0)
char *password; int password_len;
char *salt; int salt_len;
char *method; int method_len = 0;
- unsigned char *out_buffer;
+ zend_string *out_buffer;
const EVP_MD *digest;
RETURN_FALSE;
}
- out_buffer = emalloc(key_length + 1);
- out_buffer[key_length] = '\0';
+ out_buffer = STR_ALLOC(key_length, 0);
- if (PKCS5_PBKDF2_HMAC(password, password_len, (unsigned char *)salt, salt_len, iterations, digest, key_length, out_buffer) == 1) {
- // TODO: avoid reallocation ???
- RETVAL_STRINGL((char *)out_buffer, key_length);
- efree(out_buffer);
+ if (PKCS5_PBKDF2_HMAC(password, password_len, (unsigned char *)salt, salt_len, iterations, digest, key_length, (unsigned char*)out_buffer->val) == 1) {
+ out_buffer->val[key_length] = 0;
+ RETURN_STR(out_buffer);
} else {
- efree(out_buffer);
+ STR_RELEASE(out_buffer);
RETURN_FALSE;
}
}
zval *key, *crypted;
EVP_PKEY *pkey;
int cryptedlen;
- unsigned char *cryptedbuf = NULL;
+ zend_string *cryptedbuf = NULL;
int successful = 0;
zend_resource *keyresource = NULL;
char * data;
}
cryptedlen = EVP_PKEY_size(pkey);
- cryptedbuf = emalloc(cryptedlen + 1);
+ cryptedbuf = STR_ALLOC(cryptedlen, 0);
switch (pkey->type) {
case EVP_PKEY_RSA:
case EVP_PKEY_RSA2:
successful = (RSA_private_encrypt(data_len,
(unsigned char *)data,
- cryptedbuf,
+ (unsigned char *)cryptedbuf->val,
pkey->pkey.rsa,
padding) == cryptedlen);
break;
if (successful) {
zval_dtor(crypted);
- cryptedbuf[cryptedlen] = '\0';
- // TODO: avoid reallocation ???
- ZVAL_STRINGL(crypted, (char *)cryptedbuf, cryptedlen);
- efree(cryptedbuf);
+ cryptedbuf->val[cryptedlen] = '\0';
+ ZVAL_STR(crypted, cryptedbuf);
cryptedbuf = NULL;
RETVAL_TRUE;
}
if (cryptedbuf) {
- efree(cryptedbuf);
+ STR_RELEASE(cryptedbuf);
}
if (keyresource == NULL) {
EVP_PKEY_free(pkey);
zval *key, *crypted;
EVP_PKEY *pkey;
int cryptedlen;
- unsigned char *cryptedbuf = NULL;
+ zend_string *cryptedbuf = NULL;
unsigned char *crypttemp;
int successful = 0;
long padding = RSA_PKCS1_PADDING;
pkey->pkey.rsa,
padding);
if (cryptedlen != -1) {
- cryptedbuf = emalloc(cryptedlen + 1);
- memcpy(cryptedbuf, crypttemp, cryptedlen);
+ cryptedbuf = STR_ALLOC(cryptedlen, 0);
+ memcpy(cryptedbuf->val, crypttemp, cryptedlen);
successful = 1;
}
break;
if (successful) {
zval_dtor(crypted);
- cryptedbuf[cryptedlen] = '\0';
- // TODO: avoid reallocation ???
- ZVAL_STRINGL(crypted, (char *)cryptedbuf, cryptedlen);
- efree(cryptedbuf);
+ cryptedbuf->val[cryptedlen] = '\0';
+ ZVAL_STR(crypted, cryptedbuf);
cryptedbuf = NULL;
RETVAL_TRUE;
}
EVP_PKEY_free(pkey);
}
if (cryptedbuf) {
- efree(cryptedbuf);
+ STR_RELEASE(cryptedbuf);
}
}
/* }}} */
zval *key, *crypted;
EVP_PKEY *pkey;
int cryptedlen;
- unsigned char *cryptedbuf;
+ zend_string *cryptedbuf;
int successful = 0;
zend_resource *keyresource = NULL;
long padding = RSA_PKCS1_PADDING;
}
cryptedlen = EVP_PKEY_size(pkey);
- cryptedbuf = emalloc(cryptedlen + 1);
+ cryptedbuf = STR_ALLOC(cryptedlen, 0);
switch (pkey->type) {
case EVP_PKEY_RSA:
case EVP_PKEY_RSA2:
successful = (RSA_public_encrypt(data_len,
(unsigned char *)data,
- cryptedbuf,
+ (unsigned char *)cryptedbuf->val,
pkey->pkey.rsa,
padding) == cryptedlen);
break;
if (successful) {
zval_dtor(crypted);
- cryptedbuf[cryptedlen] = '\0';
- // TODO: avoid reallocation ???
- ZVAL_STRINGL(crypted, (char *)cryptedbuf, cryptedlen);
- efree(cryptedbuf);
+ cryptedbuf->val[cryptedlen] = '\0';
+ ZVAL_STR(crypted, cryptedbuf);
cryptedbuf = NULL;
RETVAL_TRUE;
}
EVP_PKEY_free(pkey);
}
if (cryptedbuf) {
- efree(cryptedbuf);
+ STR_RELEASE(cryptedbuf);
}
}
/* }}} */
zval *key, *crypted;
EVP_PKEY *pkey;
int cryptedlen;
- unsigned char *cryptedbuf = NULL;
+ zend_string *cryptedbuf = NULL;
unsigned char *crypttemp;
int successful = 0;
zend_resource *keyresource = NULL;
pkey->pkey.rsa,
padding);
if (cryptedlen != -1) {
- cryptedbuf = emalloc(cryptedlen + 1);
- memcpy(cryptedbuf, crypttemp, cryptedlen);
+ cryptedbuf = STR_ALLOC(cryptedlen, 0);
+ memcpy(cryptedbuf->val, crypttemp, cryptedlen);
successful = 1;
}
break;
if (successful) {
zval_dtor(crypted);
- cryptedbuf[cryptedlen] = '\0';
- // TODO: avoid reallocation ???
- ZVAL_STRINGL(crypted, (char *)cryptedbuf, cryptedlen);
- efree(cryptedbuf);
+ cryptedbuf->val[cryptedlen] = '\0';
+ ZVAL_STR(crypted, cryptedbuf);
cryptedbuf = NULL;
RETVAL_TRUE;
}
if (cryptedbuf) {
- efree(cryptedbuf);
+ STR_RELEASE(cryptedbuf);
}
if (keyresource == NULL) {
EVP_PKEY_free(pkey);
{
zval *key, *signature;
EVP_PKEY *pkey;
- int siglen;
- unsigned char *sigbuf;
+ unsigned int siglen;
+ zend_string *sigbuf;
zend_resource *keyresource = NULL;
char * data;
int data_len;
}
siglen = EVP_PKEY_size(pkey);
- sigbuf = emalloc(siglen + 1);
+ sigbuf = STR_ALLOC(siglen, 0);
EVP_SignInit(&md_ctx, mdtype);
EVP_SignUpdate(&md_ctx, data, data_len);
- if (EVP_SignFinal (&md_ctx, sigbuf,(unsigned int *)&siglen, pkey)) {
+ if (EVP_SignFinal (&md_ctx, (unsigned char*)sigbuf->val, &siglen, pkey)) {
zval_dtor(signature);
- sigbuf[siglen] = '\0';
- // TODO: avoid reallocation ???
- ZVAL_STRINGL(signature, (char *)sigbuf, siglen);
- efree(sigbuf);
+ sigbuf->val[siglen] = '\0';
+ sigbuf->len = siglen;
+ ZVAL_STR(signature, sigbuf);
RETVAL_TRUE;
} else {
efree(sigbuf);
int data_len, method_len;
const EVP_MD *mdtype;
EVP_MD_CTX md_ctx;
- int siglen;
- unsigned char *sigbuf;
+ unsigned int siglen;
+ zend_string *sigbuf;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &data, &data_len, &method, &method_len, &raw_output) == FAILURE) {
return;
}
siglen = EVP_MD_size(mdtype);
- sigbuf = emalloc(siglen + 1);
+ sigbuf = STR_ALLOC(siglen, 0);
EVP_DigestInit(&md_ctx, mdtype);
EVP_DigestUpdate(&md_ctx, (unsigned char *)data, data_len);
- if (EVP_DigestFinal (&md_ctx, (unsigned char *)sigbuf, (unsigned int *)&siglen)) {
+ if (EVP_DigestFinal (&md_ctx, (unsigned char *)sigbuf->val, &siglen)) {
if (raw_output) {
- sigbuf[siglen] = '\0';
- // TODO: avoid reallocation ???
- RETVAL_STRINGL((char *)sigbuf, siglen);
- efree(sigbuf);
+ sigbuf->val[siglen] = '\0';
+ sigbuf->len = siglen;
+ RETVAL_STR(sigbuf);
} else {
int digest_str_len = siglen * 2;
- char *digest_str = emalloc(digest_str_len + 1);
+ zend_string *digest_str = STR_ALLOC(digest_str_len, 0);
- make_digest_ex(digest_str, sigbuf, siglen);
- efree(sigbuf);
- // TODO: avid reallocation ???
- RETVAL_STRINGL(digest_str, digest_str_len);
- efree(digest_str);
+ make_digest_ex(digest_str->val, (unsigned char*)sigbuf->val, siglen);
+ digest_str->val[digest_str_len] = '\0';
+ STR_RELEASE(sigbuf);
+ RETVAL_STR(digest_str);
}
} else {
- efree(sigbuf);
+ STR_RELEASE(sigbuf);
RETVAL_FALSE;
}
}
const EVP_CIPHER *cipher_type;
EVP_CIPHER_CTX cipher_ctx;
int i=0, outlen, keylen;
- unsigned char *outbuf, *key;
+ zend_string *outbuf;
+ unsigned char *key;
zend_bool free_iv;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|ls", &data, &data_len, &method, &method_len, &password, &password_len, &options, &iv, &iv_len) == FAILURE) {
free_iv = php_openssl_validate_iv(&iv, &iv_len, max_iv_len TSRMLS_CC);
outlen = data_len + EVP_CIPHER_block_size(cipher_type);
- outbuf = emalloc(outlen + 1);
+ outbuf = STR_ALLOC(outlen, 0);
EVP_EncryptInit(&cipher_ctx, cipher_type, NULL, NULL);
if (password_len > keylen) {
EVP_CIPHER_CTX_set_padding(&cipher_ctx, 0);
}
if (data_len > 0) {
- EVP_EncryptUpdate(&cipher_ctx, outbuf, &i, (unsigned char *)data, data_len);
+ EVP_EncryptUpdate(&cipher_ctx, (unsigned char*)outbuf->val, &i, (unsigned char *)data, data_len);
}
outlen = i;
- if (EVP_EncryptFinal(&cipher_ctx, (unsigned char *)outbuf + i, &i)) {
+ if (EVP_EncryptFinal(&cipher_ctx, (unsigned char *)outbuf->val + i, &i)) {
outlen += i;
if (options & OPENSSL_RAW_DATA) {
- outbuf[outlen] = '\0';
- // TODO: avoid reallocation ???
- RETVAL_STRINGL((char *)outbuf, outlen);
- efree(outbuf);
+ outbuf->val[outlen] = '\0';
+ outbuf->len = outlen;
+ RETVAL_STR(outbuf);
} else {
zend_string *base64_str;
- base64_str = php_base64_encode(outbuf, outlen);
- efree(outbuf);
+ base64_str = php_base64_encode((unsigned char*)outbuf->val, outlen);
+ STR_RELEASE(outbuf);
RETVAL_STR(base64_str);
}
} else {
- efree(outbuf);
+ STR_RELEASE(outbuf);
RETVAL_FALSE;
}
if (key != (unsigned char*)password) {
const EVP_CIPHER *cipher_type;
EVP_CIPHER_CTX cipher_ctx;
int i, outlen, keylen;
- unsigned char *outbuf, *key;
+ zend_string *outbuf;
+ unsigned char *key;
zend_string *base64_str = NULL;
zend_bool free_iv;
free_iv = php_openssl_validate_iv(&iv, &iv_len, EVP_CIPHER_iv_length(cipher_type) TSRMLS_CC);
outlen = data_len + EVP_CIPHER_block_size(cipher_type);
- outbuf = emalloc(outlen + 1);
+ outbuf = STR_ALLOC(outlen, 0);
EVP_DecryptInit(&cipher_ctx, cipher_type, NULL, NULL);
if (password_len > keylen) {
if (options & OPENSSL_ZERO_PADDING) {
EVP_CIPHER_CTX_set_padding(&cipher_ctx, 0);
}
- EVP_DecryptUpdate(&cipher_ctx, outbuf, &i, (unsigned char *)data, data_len);
+ EVP_DecryptUpdate(&cipher_ctx, (unsigned char*)outbuf->val, &i, (unsigned char *)data, data_len);
outlen = i;
- if (EVP_DecryptFinal(&cipher_ctx, (unsigned char *)outbuf + i, &i)) {
+ if (EVP_DecryptFinal(&cipher_ctx, (unsigned char *)outbuf->val + i, &i)) {
outlen += i;
- outbuf[outlen] = '\0';
- // TODO: avoid reallocation ???
- RETVAL_STRINGL((char *)outbuf, outlen);
- efree(outbuf);
+ outbuf->val[outlen] = '\0';
+ outbuf->len = outlen;
+ RETVAL_STR(outbuf);
} else {
- efree(outbuf);
+ STR_RELEASE(outbuf);
RETVAL_FALSE;
}
if (key != (unsigned char*)password) {
int pub_len;
EVP_PKEY *pkey;
BIGNUM *pub;
- char *data;
+ zend_string *data;
int len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sr", &pub_str, &pub_len, &key) == FAILURE) {
pub = BN_bin2bn((unsigned char*)pub_str, pub_len, NULL);
- data = emalloc(DH_size(pkey->pkey.dh) + 1);
- len = DH_compute_key((unsigned char*)data, pub, pkey->pkey.dh);
+ data = STR_ALLOC(DH_size(pkey->pkey.dh), 0);
+ len = DH_compute_key((unsigned char*)data->val, pub, pkey->pkey.dh);
if (len >= 0) {
- data[len] = 0;
- // TODO: avoid reallocation ???
- RETVAL_STRINGL(data, len);
- efree(data);
+ data->len = len;
+ data->val[len] = 0;
+ RETVAL_STR(data);
} else {
- efree(data);
+ STR_RELEASE(data);
RETVAL_FALSE;
}
PHP_FUNCTION(openssl_random_pseudo_bytes)
{
long buffer_length;
- unsigned char *buffer = NULL;
+ zend_string *buffer = NULL;
zval *zstrong_result_returned = NULL;
int strong_result = 0;
ZVAL_BOOL(zstrong_result_returned, 0);
}
- buffer = emalloc(buffer_length + 1);
+ buffer = STR_ALLOC(buffer_length, 0);
#ifdef PHP_WIN32
strong_result = 1;
/* random/urandom equivalent on Windows */
- if (php_win32_get_random_bytes(buffer, (size_t) buffer_length) == FAILURE){
- efree(buffer);
+ if (php_win32_get_random_bytes((unsigned char*)buffer->val, (size_t) buffer_length) == FAILURE){
+ STR_RELEASE(buffer);
if (zstrong_result_returned) {
ZVAL_BOOL(zstrong_result_returned, 0);
}
RETURN_FALSE;
}
#else
- if ((strong_result = RAND_pseudo_bytes(buffer, buffer_length)) < 0) {
- efree(buffer);
+ if ((strong_result = RAND_pseudo_bytes((unsigned char*)buffer->val, buffer_length)) < 0) {
+ STR_RELEASE(buffer);
if (zstrong_result_returned) {
ZVAL_BOOL(zstrong_result_returned, 0);
}
}
#endif
- buffer[buffer_length] = 0;
- // TODO: avoid reallocation ???
- RETVAL_STRINGL((char *)buffer, buffer_length);
- efree(buffer);
+ buffer->val[buffer_length] = 0;
+ RETVAL_STR(buffer);
if (zstrong_result_returned) {
ZVAL_BOOL(zstrong_result_returned, strong_result);
#define PHP_X509_NAME_ENTRY_TO_UTF8(ne, i, out) ASN1_STRING_to_UTF8(&out, X509_NAME_ENTRY_get_data(X509_NAME_get_entry(ne, i)))
extern php_stream* php_openssl_get_stream_from_ssl_handle(const SSL *ssl);
-extern int php_openssl_x509_fingerprint(X509 *peer, const char *method, zend_bool raw, char **out, int *out_len TSRMLS_DC);
+extern zend_string* php_openssl_x509_fingerprint(X509 *peer, const char *method, zend_bool raw TSRMLS_DC);
extern int php_openssl_get_ssl_stream_data_index();
extern int php_openssl_get_x509_list_id(void);
static int php_x509_fingerprint_cmp(X509 *peer, const char *method, const char *expected TSRMLS_DC)
{
- char *fingerprint;
- int fingerprint_len;
+ zend_string *fingerprint;
int result = -1;
- if (php_openssl_x509_fingerprint(peer, method, 0, &fingerprint, &fingerprint_len TSRMLS_CC) == SUCCESS) {
- result = strcmp(expected, fingerprint);
- efree(fingerprint);
+ fingerprint = php_openssl_x509_fingerprint(peer, method, 0 TSRMLS_CC);
+ if (fingerprint) {
+ result = strcmp(expected, fingerprint->val);
+ STR_RELEASE(fingerprint);
}
return result;
return;
}
-//??? intern = Z_SPLDUAL_IT_P(getThis());
SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis());
zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "getchildren", &retval);
}
use_copy = zend_make_printable_zval(&intern->u.caching.zstr, &expr_copy TSRMLS_CC);
if (use_copy) {
- ZVAL_COPY(&intern->u.caching.zstr, &expr_copy);
-//??? INIT_PZVAL(intern->u.caching.zstr);
- //zval_copy_ctor(&intern->u.caching.zstr);
- zval_dtor(&expr_copy);
+ ZVAL_COPY_VALUE(&intern->u.caching.zstr, &expr_copy);
} else if (Z_REFCOUNTED(intern->u.caching.zstr)) {
-//??? INIT_PZVAL(intern->u.caching.zstr);
- //zval_copy_ctor(&intern->u.caching.zstr);
Z_ADDREF(intern->u.caching.zstr);
}
}
}
ret[i] = d;
}
+ ret[i] = '\0';
return str;
}
/* {{{ startup, shutdown and info functions */
static PHP_GINIT_FUNCTION(xml)
{
- xml_globals->default_encoding = "UTF-8";
+ xml_globals->default_encoding = (XML_Char*)"UTF-8";
}
static void *php_xml_malloc_wrapper(size_t sz)
array_init(&args[2]);
while (attributes && *attributes) {
+ zval tmp;
+
att = _xml_decode_tag(parser, (const char *)attributes[0]);
val = xml_utf8_decode(attributes[1], strlen((char *)attributes[1]), parser->target_encoding);
- // TODO: avoid reallocation ???
- add_assoc_str(&args[2], att->val, val);
+ ZVAL_STR(&tmp, val);
+ zend_symtable_update(Z_ARRVAL(args[2]), att, &tmp);
attributes += 2;
attributes = (const XML_Char **) attrs;
while (attributes && *attributes) {
+ zval tmp;
+
att = _xml_decode_tag(parser, (const char *)attributes[0]);
val = xml_utf8_decode(attributes[1], strlen((char *)attributes[1]), parser->target_encoding);
- // TODO: avoid reallocation ???
- add_assoc_str(&atr, att->val, val);
+ ZVAL_STR(&tmp, val);
+ zend_symtable_update(Z_ARRVAL(atr), att, &tmp);
atcnt++;
attributes += 2;
decoded_value->val, decoded_value->len + 1);
STR_RELEASE(decoded_value);
} else {
- // TODO: avoid reallocation ???
add_assoc_str(parser->ctag, "value", decoded_value);
}
_xml_add_to_info(parser,parser->ltags[parser->level-1] + parser->toffset);
add_assoc_string(&tag, "tag", parser->ltags[parser->level-1] + parser->toffset);
- // TODO: avoid reallocation ???
add_assoc_str(&tag, "value", decoded_value);
add_assoc_string(&tag, "type", "cdata");
add_assoc_long(&tag, "level", parser->level);
encoding = XML(default_encoding);
auto_detect = 1;
} else if (strcasecmp(encoding_param, "ISO-8859-1") == 0) {
- encoding = "ISO-8859-1";
+ encoding = (XML_Char*)"ISO-8859-1";
} else if (strcasecmp(encoding_param, "UTF-8") == 0) {
- encoding = "UTF-8";
+ encoding = (XML_Char*)"UTF-8";
} else if (strcasecmp(encoding_param, "US-ASCII") == 0) {
- encoding = "US-ASCII";
+ encoding = (XML_Char*)"US-ASCII";
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "unsupported source encoding \"%s\"", encoding_param);
RETURN_FALSE;
parser = ecalloc(1, sizeof(xml_parser));
parser->parser = XML_ParserCreate_MM((auto_detect ? NULL : encoding),
- &php_xml_mem_hdlrs, ns_param);
+ &php_xml_mem_hdlrs, (XML_Char*)ns_param);
parser->target_encoding = encoding;
parser->case_folding = 1;
ZEND_FETCH_RESOURCE(parser, xml_parser *, pind, -1, "XML Parser", le_xml_parser);
parser->isparsing = 1;
- ret = XML_Parse(parser->parser, data, data_len, isFinal);
+ ret = XML_Parse(parser->parser, (XML_Char*)data, data_len, isFinal);
parser->isparsing = 0;
RETVAL_LONG(ret);
}
XML_SetCharacterDataHandler(parser->parser, _xml_characterDataHandler);
parser->isparsing = 1;
- ret = XML_Parse(parser->parser, data, data_len, 1);
+ ret = XML_Parse(parser->parser, (XML_Char*)data, data_len, 1);
parser->isparsing = 0;
RETVAL_LONG(ret);
case PHP_XML_OPTION_TARGET_ENCODING: {
xml_encoding *enc;
convert_to_string_ex(val);
- enc = xml_get_encoding(Z_STRVAL_P(val));
+ enc = xml_get_encoding((XML_Char*)Z_STRVAL_P(val));
if (enc == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported target encoding \"%s\"", Z_STRVAL_P(val));
RETURN_FALSE;
return;
}
- encoded = xml_utf8_encode(arg, arg_len, "ISO-8859-1");
+ encoded = xml_utf8_encode(arg, arg_len, (XML_Char*)"ISO-8859-1");
if (encoded == NULL) {
RETURN_FALSE;
}
return;
}
- decoded = xml_utf8_decode(arg, arg_len, "ISO-8859-1");
+ decoded = xml_utf8_decode((XML_Char*)arg, arg_len, (XML_Char*)"ISO-8859-1");
if (decoded == NULL) {
RETURN_FALSE;
}
HashTable *headers;
zend_string *key;
char *value;
- HashPosition pos;
+ zval tmp;
if (zend_parse_parameters_none() == FAILURE) {
return;
array_init_size(return_value, zend_hash_num_elements(headers));
- zend_hash_internal_pointer_reset_ex(headers, &pos);
- while ((value = zend_hash_get_current_data_ptr_ex(headers, &pos)) != NULL) {
- zend_hash_get_current_key_ex(headers, &key, NULL, 0, &pos);
-//???
- add_assoc_string_ex(return_value, key->val, key->len, value);
- zend_hash_move_forward_ex(headers, &pos);
- }
+ ZEND_HASH_FOREACH_STR_KEY_PTR(headers, key, value) {
+ ZVAL_STRING(&tmp, value);
+ zend_symtable_update(Z_ARRVAL_P(return_value), key, &tmp);
+ } ZEND_HASH_FOREACH_END();
}
/* }}} */