@@ -29,8 +29,6 @@ extern VALUE rb_cRuggedRepo;
29
29
extern VALUE rb_eRuggedError ;
30
30
VALUE rb_cRuggedRemote ;
31
31
32
- #define RUGGED_REMOTE_CALLBACKS_INIT {1, progress_cb, NULL, credentials_cb, NULL, transfer_progress_cb, update_tips_cb, NULL, NULL, push_update_reference_cb, NULL}
33
-
34
32
static int progress_cb (const char * str , int len , void * data )
35
33
{
36
34
struct rugged_remote_cb_payload * payload = data ;
@@ -96,6 +94,27 @@ static int update_tips_cb(const char *refname, const git_oid *src, const git_oid
96
94
return payload -> exception ? GIT_ERROR : GIT_OK ;
97
95
}
98
96
97
+ static int certificate_check_cb (git_cert * cert , int valid , const char * host , void * data )
98
+ {
99
+ struct rugged_remote_cb_payload * payload = data ;
100
+ VALUE args = rb_ary_new2 (3 );
101
+ VALUE ret ;
102
+
103
+ if (NIL_P (payload -> certificate_check ))
104
+ return valid ? 0 : GIT_ECERTIFICATE ;
105
+
106
+ rb_ary_push (args , payload -> certificate_check );
107
+ rb_ary_push (args , valid ? Qtrue : Qfalse );
108
+ rb_ary_push (args , rb_str_new_utf8 (host ));
109
+
110
+ ret = rb_protect (rugged__block_yield_splat , args , & payload -> exception );
111
+
112
+ if (payload -> exception )
113
+ return GIT_ERROR ;
114
+
115
+ return rugged_parse_bool (ret ) ? GIT_OK : GIT_ECERTIFICATE ;
116
+ }
117
+
99
118
struct extract_cred_args
100
119
{
101
120
VALUE rb_callback ;
@@ -155,11 +174,9 @@ static int credentials_cb(
155
174
return payload -> exception ? GIT_ERROR : GIT_OK ;
156
175
}
157
176
158
- #define CALLABLE_OR_RAISE (ret , rb_options , name ) \
159
- do { \
160
- ret = rb_hash_aref(rb_options, CSTR2SYM(name)); \
161
- \
162
- if (!NIL_P(ret) && !rb_respond_to(ret, rb_intern("call"))) \
177
+ #define CALLABLE_OR_RAISE (ret , name ) \
178
+ do { \
179
+ if (!rb_respond_to(ret, rb_intern("call"))) \
163
180
rb_raise(rb_eArgError, "Expected a Proc or an object that responds to #call (:" name " )."); \
164
181
} while (0);
165
182
@@ -168,16 +185,39 @@ void rugged_remote_init_callbacks_and_payload_from_options(
168
185
git_remote_callbacks * callbacks ,
169
186
struct rugged_remote_cb_payload * payload )
170
187
{
171
- git_remote_callbacks prefilled = RUGGED_REMOTE_CALLBACKS_INIT ;
172
-
173
- prefilled .payload = payload ;
174
- memcpy (callbacks , & prefilled , sizeof (git_remote_callbacks ));
188
+ callbacks -> payload = payload ;
189
+ callbacks -> push_update_reference = push_update_reference_cb ;
175
190
176
191
if (!NIL_P (rb_options )) {
177
- CALLABLE_OR_RAISE (payload -> update_tips , rb_options , "update_tips" );
178
- CALLABLE_OR_RAISE (payload -> progress , rb_options , "progress" );
179
- CALLABLE_OR_RAISE (payload -> transfer_progress , rb_options , "transfer_progress" );
180
- CALLABLE_OR_RAISE (payload -> credentials , rb_options , "credentials" );
192
+ payload -> progress = rb_hash_aref (rb_options , CSTR2SYM ("progress" ));
193
+ if (!NIL_P (payload -> progress )) {
194
+ CALLABLE_OR_RAISE (payload -> progress , "progress" );
195
+ callbacks -> sideband_progress = progress_cb ;
196
+ }
197
+
198
+ payload -> credentials = rb_hash_aref (rb_options , CSTR2SYM ("credentials" ));
199
+ if (!NIL_P (payload -> credentials )) {
200
+ CALLABLE_OR_RAISE (payload -> credentials , "credentials" );
201
+ callbacks -> credentials = credentials_cb ;
202
+ }
203
+
204
+ payload -> certificate_check = rb_hash_aref (rb_options , CSTR2SYM ("certificate_check" ));
205
+ if (!NIL_P (payload -> certificate_check )) {
206
+ CALLABLE_OR_RAISE (payload -> certificate_check , "certificate_check" );
207
+ callbacks -> certificate_check = certificate_check_cb ;
208
+ }
209
+
210
+ payload -> transfer_progress = rb_hash_aref (rb_options , CSTR2SYM ("transfer_progress" ));
211
+ if (!NIL_P (payload -> transfer_progress )) {
212
+ CALLABLE_OR_RAISE (payload -> transfer_progress , "transfer_progress" );
213
+ callbacks -> transfer_progress = transfer_progress_cb ;
214
+ }
215
+
216
+ payload -> update_tips = rb_hash_aref (rb_options , CSTR2SYM ("update_tips" ));
217
+ if (!NIL_P (payload -> update_tips )) {
218
+ CALLABLE_OR_RAISE (payload -> update_tips , "update_tips" );
219
+ callbacks -> update_tips = update_tips_cb ;
220
+ }
181
221
}
182
222
}
183
223
@@ -274,7 +314,7 @@ static VALUE rb_git_remote_ls(int argc, VALUE *argv, VALUE self)
274
314
git_strarray custom_headers = {0 };
275
315
const git_remote_head * * heads ;
276
316
277
- struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
317
+ struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
278
318
279
319
VALUE rb_options ;
280
320
@@ -471,7 +511,7 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
471
511
git_remote * remote ;
472
512
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT ;
473
513
git_strarray custom_headers = {0 };
474
- struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
514
+ struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
475
515
VALUE rb_direction , rb_options ;
476
516
ID id_direction ;
477
517
int error , direction ;
@@ -537,6 +577,11 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
537
577
* A callback that will be executed each time a reference is updated locally. It will be
538
578
* passed the +refname+, +old_oid+ and +new_oid+.
539
579
*
580
+ * :certificate_check ::
581
+ * A callback that will be executed each time we validate a certificate using https. It
582
+ * will be passed the +valid+, +host_name+ and the callback should return a true/false to
583
+ * indicate if the certificate has been validated.
584
+ *
540
585
* :message ::
541
586
* The message to insert into the reflogs. Defaults to "fetch".
542
587
*
@@ -559,7 +604,7 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
559
604
git_strarray refspecs ;
560
605
git_fetch_options opts = GIT_FETCH_OPTIONS_INIT ;
561
606
const git_transfer_progress * stats ;
562
- struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
607
+ struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
563
608
564
609
char * log_message = NULL ;
565
610
int error ;
@@ -650,7 +695,7 @@ static VALUE rb_git_remote_push(int argc, VALUE *argv, VALUE self)
650
695
651
696
int error = 0 ;
652
697
653
- struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , rb_hash_new (), 0 };
698
+ struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , rb_hash_new (), 0 };
654
699
655
700
rb_scan_args (argc , argv , "01:" , & rb_refspecs , & rb_options );
656
701
0 commit comments