@@ -708,6 +708,14 @@ bool make_http_soap_request(
708708 php_hash_bin2hex (cnonce , nonce , sizeof (nonce ));
709709 cnonce [32 ] = 0 ;
710710
711+ zval * digest_realm = zend_hash_str_find (Z_ARRVAL_P (digest ), ZEND_STRL ("realm" ));
712+ const zend_string * realm = digest_realm && Z_TYPE_P (digest_realm ) == IS_STRING ? Z_STR_P (digest_realm ) : NULL ;
713+ zval * digest_nonce = zend_hash_str_find (Z_ARRVAL_P (digest ), ZEND_STRL ("nonce" ));
714+ const zend_string * nonce_zstr = digest_nonce && Z_TYPE_P (digest_nonce ) == IS_STRING ? Z_STR_P (digest_nonce ) : NULL ;
715+ zval * digest_algorithm = zend_hash_str_find (Z_ARRVAL_P (digest ), ZEND_STRL ("algorithm" ));
716+ const zend_string * algorithm = digest_algorithm && Z_TYPE_P (digest_algorithm ) == IS_STRING ? Z_STR_P (digest_algorithm ) : NULL ;
717+ bool has_qop = zend_hash_str_exists (Z_ARRVAL_P (digest ), ZEND_STRL ("qop" ));
718+
711719 if ((tmp = zend_hash_str_find (Z_ARRVAL_P (digest ), "nc" , sizeof ("nc" )- 1 )) != NULL &&
712720 Z_TYPE_P (tmp ) == IS_LONG ) {
713721 Z_LVAL_P (tmp )++ ;
@@ -720,9 +728,8 @@ bool make_http_soap_request(
720728 PHP_MD5Init (& md5ctx );
721729 PHP_MD5Update (& md5ctx , (unsigned char * )Z_STRVAL_P (login ), Z_STRLEN_P (login ));
722730 PHP_MD5Update (& md5ctx , (unsigned char * )":" , 1 );
723- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (digest ), "realm" , sizeof ("realm" )- 1 )) != NULL &&
724- Z_TYPE_P (tmp ) == IS_STRING ) {
725- PHP_MD5Update (& md5ctx , (unsigned char * )Z_STRVAL_P (tmp ), Z_STRLEN_P (tmp ));
731+ if (realm ) {
732+ PHP_MD5Update (& md5ctx , (unsigned char * )ZSTR_VAL (realm ), ZSTR_LEN (realm ));
726733 }
727734 PHP_MD5Update (& md5ctx , (unsigned char * )":" , 1 );
728735 zval * password = Z_CLIENT_PASSWORD_P (this_ptr );
@@ -731,16 +738,12 @@ bool make_http_soap_request(
731738 }
732739 PHP_MD5Final (hash , & md5ctx );
733740 make_digest (HA1 , hash );
734- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (digest ), "algorithm" , sizeof ("algorithm" )- 1 )) != NULL &&
735- Z_TYPE_P (tmp ) == IS_STRING &&
736- Z_STRLEN_P (tmp ) == sizeof ("md5-sess" )- 1 &&
737- stricmp (Z_STRVAL_P (tmp ), "md5-sess" ) == 0 ) {
741+ if (algorithm && zend_string_equals_literal_ci (algorithm , "md5-sess" )) {
738742 PHP_MD5Init (& md5ctx );
739743 PHP_MD5Update (& md5ctx , (unsigned char * )HA1 , 32 );
740744 PHP_MD5Update (& md5ctx , (unsigned char * )":" , 1 );
741- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (digest ), "nonce" , sizeof ("nonce" )- 1 )) != NULL &&
742- Z_TYPE_P (tmp ) == IS_STRING ) {
743- PHP_MD5Update (& md5ctx , (unsigned char * )Z_STRVAL_P (tmp ), Z_STRLEN_P (tmp ));
745+ if (nonce_zstr ) {
746+ PHP_MD5Update (& md5ctx , (unsigned char * )ZSTR_VAL (nonce_zstr ), ZSTR_LEN (nonce_zstr ));
744747 }
745748 PHP_MD5Update (& md5ctx , (unsigned char * )":" , 1 );
746749 PHP_MD5Update (& md5ctx , (unsigned char * )cnonce , 8 );
@@ -766,13 +769,11 @@ bool make_http_soap_request(
766769 PHP_MD5Init (& md5ctx );
767770 PHP_MD5Update (& md5ctx , (unsigned char * )HA1 , 32 );
768771 PHP_MD5Update (& md5ctx , (unsigned char * )":" , 1 );
769- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (digest ), "nonce" , sizeof ("nonce" )- 1 )) != NULL &&
770- Z_TYPE_P (tmp ) == IS_STRING ) {
771- PHP_MD5Update (& md5ctx , (unsigned char * )Z_STRVAL_P (tmp ), Z_STRLEN_P (tmp ));
772+ if (nonce_zstr ) {
773+ PHP_MD5Update (& md5ctx , (unsigned char * )ZSTR_VAL (nonce_zstr ), ZSTR_LEN (nonce_zstr ));
772774 }
773775 PHP_MD5Update (& md5ctx , (unsigned char * )":" , 1 );
774- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (digest ), "qop" , sizeof ("qop" )- 1 )) != NULL &&
775- Z_TYPE_P (tmp ) == IS_STRING ) {
776+ if (has_qop ) {
776777 PHP_MD5Update (& md5ctx , (unsigned char * )nc , 8 );
777778 PHP_MD5Update (& md5ctx , (unsigned char * )":" , 1 );
778779 PHP_MD5Update (& md5ctx , (unsigned char * )cnonce , 8 );
@@ -787,15 +788,13 @@ bool make_http_soap_request(
787788
788789 smart_str_append_const (& soap_headers , "Authorization: Digest username=\"" );
789790 smart_str_append (& soap_headers , Z_STR_P (login ));
790- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (digest ), "realm" , sizeof ("realm" )- 1 )) != NULL &&
791- Z_TYPE_P (tmp ) == IS_STRING ) {
791+ if (realm ) {
792792 smart_str_append_const (& soap_headers , "\", realm=\"" );
793- smart_str_append (& soap_headers , Z_STR_P ( tmp ) );
793+ smart_str_append (& soap_headers , realm );
794794 }
795- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (digest ), "nonce" , sizeof ("nonce" )- 1 )) != NULL &&
796- Z_TYPE_P (tmp ) == IS_STRING ) {
795+ if (nonce_zstr ) {
797796 smart_str_append_const (& soap_headers , "\", nonce=\"" );
798- smart_str_append (& soap_headers , Z_STR_P ( tmp ) );
797+ smart_str_append (& soap_headers , nonce_zstr );
799798 }
800799 smart_str_append_const (& soap_headers , "\", uri=\"" );
801800 if (phpurl -> path ) {
@@ -811,8 +810,7 @@ bool make_http_soap_request(
811810 smart_str_appendc (& soap_headers , '#' );
812811 smart_str_append (& soap_headers , phpurl -> fragment );
813812 }
814- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (digest ), "qop" , sizeof ("qop" )- 1 )) != NULL &&
815- Z_TYPE_P (tmp ) == IS_STRING ) {
813+ if (has_qop ) {
816814 /* TODO: Support for qop=auth-int */
817815 smart_str_append_const (& soap_headers , "\", qop=auth" );
818816 smart_str_append_const (& soap_headers , ", nc=" );
@@ -827,10 +825,9 @@ bool make_http_soap_request(
827825 smart_str_append_const (& soap_headers , "\", opaque=\"" );
828826 smart_str_append (& soap_headers , Z_STR_P (tmp ));
829827 }
830- if ((tmp = zend_hash_str_find (Z_ARRVAL_P (digest ), "algorithm" , sizeof ("algorithm" )- 1 )) != NULL &&
831- Z_TYPE_P (tmp ) == IS_STRING ) {
828+ if (algorithm ) {
832829 smart_str_append_const (& soap_headers , "\", algorithm=\"" );
833- smart_str_append (& soap_headers , Z_STR_P ( tmp ) );
830+ smart_str_append (& soap_headers , algorithm );
834831 }
835832 smart_str_append_const (& soap_headers , "\"\r\n" );
836833 } else {
0 commit comments