@@ -753,40 +753,94 @@ PHP_FUNCTION(git_remote_set_transport)
753
753
}
754
754
/* }}} */
755
755
756
- static int cred_cb (git_cred * * cred , const char * url , const char * username_from_url , unsigned int allowed_types , void * data )
757
- {
758
- fprintf (stderr , "url: %s\n" , url );
759
- fprintf (stderr , "name: %s\n" , username_from_url );
760
- fprintf (stderr , "types: %d\n" , allowed_types );
761
-
762
- return 0 ;
763
- }
764
756
765
757
typedef struct php_git2_fcall_t {
766
758
zend_fcall_info fci ;
767
759
zend_fcall_info_cache fcc ;
760
+ zval * value ;
768
761
} php_git2_fcall_t ;
762
+
769
763
typedef struct php_git2_remote_cb_t {
770
764
php_git2_fcall_t callbacks [4 ];
771
765
zval * payload ;
766
+ GIT2_TSRMLS_DECL
772
767
} php_git2_remote_cb_t ;
773
768
769
+ static int cred_cb (git_cred * * cred , const char * url , const char * username_from_url , unsigned int allowed_types , void * data )
770
+ {
771
+ php_git2_t * result ;
772
+ zval * param_url = NULL , * param_username_from_url = NULL , * param_allowed_types = NULL , * retval_ptr ;
773
+ php_git2_remote_cb_t * cb = (php_git2_remote_cb_t * )data ;
774
+ GIT2_TSRMLS_SET (cb -> tsrm_ls );
775
+ int retval = 1 ;
776
+
777
+ if (cb != NULL ) {
778
+ MAKE_STD_ZVAL (param_url );
779
+ MAKE_STD_ZVAL (param_username_from_url );
780
+ MAKE_STD_ZVAL (param_allowed_types );
781
+ ZVAL_NULL (param_url );
782
+ ZVAL_NULL (param_username_from_url );
783
+
784
+ if (url != NULL ) {
785
+ ZVAL_STRING (param_url , url , 1 );
786
+ }
787
+ if (username_from_url != NULL ) {
788
+ ZVAL_STRING (param_username_from_url , username_from_url , 1 );
789
+ }
790
+ ZVAL_LONG (param_allowed_types , allowed_types );
791
+ Z_ADDREF_P (cb -> payload );
792
+ SEPARATE_ZVAL_TO_MAKE_IS_REF (& cb -> payload );
793
+
794
+ if (php_git2_call_function_v (& cb -> callbacks [0 ].fci , & cb -> callbacks [0 ].fcc TSRMLS_CC , & retval_ptr , 4 ,
795
+ & param_url , & param_username_from_url , & param_allowed_types , & cb -> payload )) {
796
+ fprintf (stderr , "CALL FUNCTION ERROR" );
797
+ }
798
+ }
799
+
800
+ if (retval_ptr && Z_TYPE_P (retval_ptr ) == IS_RESOURCE ) {
801
+ ZEND_FETCH_RESOURCE_NO_RETURN (result , php_git2_t * , & retval_ptr , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
802
+ * cred = PHP_GIT2_V (result , cred );
803
+ zval_ptr_dtor (& retval_ptr );
804
+ }
805
+ return retval ;
806
+ }
807
+
774
808
/* {{{ proto long git_remote_set_callbacks(remote, callbacks)
775
809
*/
776
810
PHP_FUNCTION (git_remote_set_callbacks )
777
811
{
778
812
zval * remote ;
779
813
php_git2_t * _remote ;
780
- zval * callbacks ;
814
+ zval * callbacks , * credentials_cb = NULL ;
781
815
php_git2_t * _callbacks ;
782
816
struct git_remote_callbacks cb = GIT_REMOTE_CALLBACKS_INIT ;
817
+ php_git2_remote_cb_t * _payload = NULL , payload = {0 };
783
818
784
819
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC ,
785
820
"ra" , & remote , & callbacks ) == FAILURE ) {
786
821
return ;
787
822
}
788
823
824
+ /* TODO(chobie): support other callbacks */
789
825
cb .credentials = cred_cb ;
826
+ credentials_cb = php_git2_read_arrval (callbacks , ZEND_STRS ("credentials" ) TSRMLS_CC );
827
+
828
+ /* TODO(chobie): can we free payload? */
829
+ _payload = emalloc (sizeof (php_git2_remote_cb_t ));
830
+ MAKE_STD_ZVAL (_payload -> payload );
831
+ GIT2_TSRMLS_SET2 (_payload , TSRMLS_C );
832
+
833
+ if (credentials_cb != NULL ) {
834
+ char * is_callable_error ;
835
+
836
+ if (zend_fcall_info_init (credentials_cb , 0 , & (_payload -> callbacks [0 ].fci ), & (_payload -> callbacks [0 ].fci ), NULL , & is_callable_error TSRMLS_CC ) == SUCCESS ) {
837
+ if (is_callable_error ) {
838
+ efree (is_callable_error );
839
+ }
840
+ }
841
+ Z_ADDREF_P (credentials_cb );
842
+ }
843
+ cb .payload = _payload ;
790
844
791
845
ZEND_FETCH_RESOURCE (_remote , php_git2_t * , & remote , -1 , PHP_GIT2_RESOURCE_NAME , git2_resource_handle );
792
846
git_remote_set_callbacks (PHP_GIT2_V (_remote , remote ), & cb );
0 commit comments