* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
[svn.git] / subversion / bindings / swig / ruby / libsvn_swig_ruby / swigutil_rb.c
blobfbd5a8240234eb464d10a709d1be159b9e8b7fb0
2 /* Tell swigutil_rb.h that we're inside the implementation */
3 #define SVN_SWIG_SWIGUTIL_RB_C
5 #include "swig_ruby_external_runtime.swg"
6 #include "swigutil_rb.h"
7 #include <st.h>
9 #undef PACKAGE_BUGREPORT
10 #undef PACKAGE_NAME
11 #undef PACKAGE_STRING
12 #undef PACKAGE_TARNAME
13 #undef PACKAGE_VERSION
14 #undef _
16 #include "svn_private_config.h"
18 #ifndef RE_OPTION_IGNORECASE
19 # ifdef ONIG_OPTION_IGNORECASE
20 # define RE_OPTION_IGNORECASE ONIG_OPTION_IGNORECASE
21 # endif
22 #endif
24 #ifndef RSTRING_LEN
25 # define RSTRING_LEN(str) (RSTRING(str)->len)
26 #endif
28 #ifndef RSTRING_PTR
29 # define RSTRING_PTR(str) (RSTRING(str)->ptr)
30 #endif
32 #include <locale.h>
34 #include "svn_nls.h"
35 #include "svn_pools.h"
36 #include "svn_time.h"
37 #include "svn_utf.h"
40 #if APR_HAS_LARGE_FILES
41 # define AOFF2NUM(num) LL2NUM(num)
42 #else
43 # define AOFF2NUM(num) LONG2NUM(num)
44 #endif
46 #if SIZEOF_LONG_LONG == 8
47 # define AI642NUM(num) LL2NUM(num)
48 #else
49 # define AI642NUM(num) LONG2NUM(num)
50 #endif
52 #define EMPTY_CPP_ARGUMENT
54 #define POOL_P(obj) (RTEST(rb_obj_is_kind_of(obj, rb_svn_core_pool())))
55 #define CONTEXT_P(obj) (RTEST(rb_obj_is_kind_of(obj, rb_svn_client_context())))
56 #define SVN_ERR_P(obj) (RTEST(rb_obj_is_kind_of(obj, rb_svn_error())))
58 static VALUE mSvn = Qnil;
59 static VALUE mSvnClient = Qnil;
60 static VALUE mSvnUtil = Qnil;
61 static VALUE cSvnClientContext = Qnil;
62 static VALUE mSvnCore = Qnil;
63 static VALUE cSvnCorePool = Qnil;
64 static VALUE cSvnCoreStream = Qnil;
65 static VALUE cSvnDelta = Qnil;
66 static VALUE cSvnDeltaEditor = Qnil;
67 static VALUE cSvnDeltaTextDeltaWindowHandler = Qnil;
68 static VALUE cSvnError = Qnil;
69 static VALUE cSvnErrorSvnError = Qnil;
70 static VALUE cSvnFs = Qnil;
71 static VALUE cSvnFsFileSystem = Qnil;
72 static VALUE cSvnRa = Qnil;
73 static VALUE cSvnRaReporter3 = Qnil;
75 #define DECLARE_ID(key) static ID id_ ## key
76 #define DEFINE_ID(key) DEFINE_ID_WITH_NAME(key, #key)
77 #define DEFINE_ID_WITH_NAME(key, name) id_ ## key = rb_intern(name)
79 DECLARE_ID(code);
80 DECLARE_ID(message);
81 DECLARE_ID(call);
82 DECLARE_ID(read);
83 DECLARE_ID(write);
84 DECLARE_ID(eqq);
85 DECLARE_ID(baton);
86 DECLARE_ID(new);
87 DECLARE_ID(new_corresponding_error);
88 DECLARE_ID(set_target_revision);
89 DECLARE_ID(open_root);
90 DECLARE_ID(delete_entry);
91 DECLARE_ID(add_directory);
92 DECLARE_ID(open_directory);
93 DECLARE_ID(change_dir_prop);
94 DECLARE_ID(close_directory);
95 DECLARE_ID(absent_directory);
96 DECLARE_ID(add_file);
97 DECLARE_ID(open_file);
98 DECLARE_ID(apply_textdelta);
99 DECLARE_ID(change_file_prop);
100 DECLARE_ID(absent_file);
101 DECLARE_ID(close_file);
102 DECLARE_ID(close_edit);
103 DECLARE_ID(abort_edit);
104 DECLARE_ID(__pool__);
105 DECLARE_ID(__pools__);
106 DECLARE_ID(name);
107 DECLARE_ID(value);
108 DECLARE_ID(swig_type_regex);
109 DECLARE_ID(open_tmp_file);
110 DECLARE_ID(get_wc_prop);
111 DECLARE_ID(set_wc_prop);
112 DECLARE_ID(push_wc_prop);
113 DECLARE_ID(invalidate_wc_props);
114 DECLARE_ID(progress_func);
115 DECLARE_ID(auth_baton);
116 DECLARE_ID(found_entry);
117 DECLARE_ID(file_changed);
118 DECLARE_ID(file_added);
119 DECLARE_ID(file_deleted);
120 DECLARE_ID(dir_added);
121 DECLARE_ID(dir_deleted);
122 DECLARE_ID(dir_props_changed);
123 DECLARE_ID(handler);
124 DECLARE_ID(handler_baton);
125 DECLARE_ID(__batons__);
126 DECLARE_ID(destroy);
127 DECLARE_ID(filename_to_temp_file);
128 DECLARE_ID(inspect);
129 DECLARE_ID(handle_error);
130 DECLARE_ID(set_path);
131 DECLARE_ID(delete_path);
132 DECLARE_ID(link_path);
133 DECLARE_ID(finish_report);
134 DECLARE_ID(abort_report);
135 DECLARE_ID(to_s);
136 DECLARE_ID(upcase);
139 typedef void *(*r2c_func)(VALUE value, void *ctx, apr_pool_t *pool);
140 typedef VALUE (*c2r_func)(void *value, void *ctx);
141 typedef struct hash_to_apr_hash_data_t
143 apr_hash_t *apr_hash;
144 r2c_func func;
145 void *ctx;
146 apr_pool_t *pool;
147 } hash_to_apr_hash_data_t;
149 static void r2c_swig_type2(VALUE value, const char *type_name, void **result);
150 static const char *r2c_inspect(VALUE object);
154 /* constant getter */
155 static VALUE
156 rb_svn(void)
158 if (NIL_P(mSvn)) {
159 mSvn = rb_const_get(rb_cObject, rb_intern("Svn"));
161 return mSvn;
164 static VALUE
165 rb_svn_util(void)
167 if (NIL_P(mSvnUtil)) {
168 mSvnUtil = rb_const_get(rb_svn(), rb_intern("Util"));
170 return mSvnUtil;
173 static VALUE
174 rb_svn_client(void)
176 if (NIL_P(mSvnClient)) {
177 mSvnClient = rb_const_get(rb_svn(), rb_intern("Client"));
179 return mSvnClient;
182 static VALUE
183 rb_svn_client_context(void)
185 if (NIL_P(cSvnClientContext)) {
186 cSvnClientContext = rb_const_get(rb_svn_client(), rb_intern("Context"));
188 return cSvnClientContext;
191 static VALUE
192 rb_svn_core(void)
194 if (NIL_P(mSvnCore)) {
195 mSvnCore = rb_const_get(rb_svn(), rb_intern("Core"));
197 return mSvnCore;
200 static VALUE
201 rb_svn_core_pool(void)
203 if (NIL_P(cSvnCorePool)) {
204 cSvnCorePool = rb_const_get(rb_svn_core(), rb_intern("Pool"));
205 rb_ivar_set(cSvnCorePool, id___pools__, rb_hash_new());
207 return cSvnCorePool;
210 static VALUE
211 rb_svn_core_stream(void)
213 if (NIL_P(cSvnCoreStream)) {
214 cSvnCoreStream = rb_const_get(rb_svn_core(), rb_intern("Stream"));
216 return cSvnCoreStream;
219 static VALUE
220 rb_svn_delta(void)
222 if (NIL_P(cSvnDelta)) {
223 cSvnDelta = rb_const_get(rb_svn(), rb_intern("Delta"));
225 return cSvnDelta;
228 VALUE
229 svn_swig_rb_svn_delta_editor(void)
231 if (NIL_P(cSvnDeltaEditor)) {
232 cSvnDeltaEditor =
233 rb_const_get(rb_svn_delta(), rb_intern("Editor"));
235 return cSvnDeltaEditor;
238 VALUE
239 svn_swig_rb_svn_delta_text_delta_window_handler(void)
241 if (NIL_P(cSvnDeltaTextDeltaWindowHandler)) {
242 cSvnDeltaTextDeltaWindowHandler =
243 rb_const_get(rb_svn_delta(), rb_intern("TextDeltaWindowHandler"));
245 return cSvnDeltaTextDeltaWindowHandler;
248 static VALUE
249 rb_svn_error(void)
251 if (NIL_P(cSvnError)) {
252 cSvnError = rb_const_get(rb_svn(), rb_intern("Error"));
254 return cSvnError;
257 static VALUE
258 rb_svn_error_svn_error(void)
260 if (NIL_P(cSvnErrorSvnError)) {
261 cSvnErrorSvnError = rb_const_get(rb_svn_error(), rb_intern("SvnError"));
263 return cSvnErrorSvnError;
266 static VALUE
267 rb_svn_fs(void)
269 if (NIL_P(cSvnFs)) {
270 cSvnFs = rb_const_get(rb_svn(), rb_intern("Fs"));
272 return cSvnFs;
275 static VALUE
276 rb_svn_fs_file_system(void)
278 if (NIL_P(cSvnFsFileSystem)) {
279 cSvnFsFileSystem = rb_const_get(rb_svn_fs(), rb_intern("FileSystem"));
280 rb_ivar_set(cSvnFsFileSystem, id___batons__, rb_hash_new());
282 return cSvnFsFileSystem;
285 static VALUE
286 rb_svn_ra(void)
288 if (NIL_P(cSvnRa)) {
289 cSvnRa = rb_const_get(rb_svn(), rb_intern("Ra"));
291 return cSvnRa;
294 static VALUE
295 rb_svn_ra_reporter3(void)
297 if (NIL_P(cSvnRaReporter3)) {
298 cSvnRaReporter3 = rb_const_get(rb_svn_ra(), rb_intern("Reporter3"));
300 return cSvnRaReporter3;
304 /* constant resolver */
305 static VALUE
306 resolve_constant(VALUE parent, const char *prefix, VALUE name)
308 VALUE const_name;
310 const_name = rb_str_new2(prefix);
311 rb_str_concat(const_name,
312 rb_funcall(rb_funcall(name, id_to_s, 0),
313 id_upcase, 0));
314 return rb_const_get(parent, rb_intern(StringValuePtr(const_name)));
318 /* initialize */
319 static VALUE
320 svn_swig_rb_converter_to_locale_encoding(VALUE self, VALUE str)
322 apr_pool_t *pool;
323 svn_error_t *err;
324 const char *dest;
325 VALUE result;
327 pool = svn_pool_create(NULL);
328 err = svn_utf_cstring_from_utf8(&dest, StringValueCStr(str), pool);
329 if (err) {
330 svn_pool_destroy(pool);
331 svn_swig_rb_handle_svn_error(err);
334 result = rb_str_new2(dest);
335 svn_pool_destroy(pool);
336 return result;
339 static VALUE
340 svn_swig_rb_locale_set(int argc, VALUE *argv, VALUE self)
342 char *result;
343 int category;
344 const char *locale;
345 VALUE rb_category, rb_locale;
347 rb_scan_args(argc, argv, "02", &rb_category, &rb_locale);
349 if (NIL_P(rb_category))
350 category = LC_ALL;
351 else
352 category = NUM2INT(rb_category);
354 if (NIL_P(rb_locale))
355 locale = "";
356 else
357 locale = StringValueCStr(rb_locale);
359 result = setlocale(category, locale);
361 return result ? rb_str_new2(result) : Qnil;
364 static VALUE
365 svn_swig_rb_gettext_bindtextdomain(VALUE self, VALUE path)
367 #ifdef ENABLE_NLS
368 bindtextdomain(PACKAGE_NAME, StringValueCStr(path));
369 #endif
370 return Qnil;
373 static VALUE
374 svn_swig_rb_gettext__(VALUE self, VALUE message)
376 #ifdef ENABLE_NLS
377 return rb_str_new2(_(StringValueCStr(message)));
378 #else
379 return message;
380 #endif
383 static void
384 svn_swig_rb_initialize_ids(void)
386 DEFINE_ID(code);
387 DEFINE_ID(message);
388 DEFINE_ID(call);
389 DEFINE_ID(read);
390 DEFINE_ID(write);
391 DEFINE_ID_WITH_NAME(eqq, "===");
392 DEFINE_ID(baton);
393 DEFINE_ID(new);
394 DEFINE_ID(new_corresponding_error);
395 DEFINE_ID(set_target_revision);
396 DEFINE_ID(open_root);
397 DEFINE_ID(delete_entry);
398 DEFINE_ID(add_directory);
399 DEFINE_ID(open_directory);
400 DEFINE_ID(change_dir_prop);
401 DEFINE_ID(close_directory);
402 DEFINE_ID(absent_directory);
403 DEFINE_ID(add_file);
404 DEFINE_ID(open_file);
405 DEFINE_ID(apply_textdelta);
406 DEFINE_ID(change_file_prop);
407 DEFINE_ID(absent_file);
408 DEFINE_ID(close_file);
409 DEFINE_ID(close_edit);
410 DEFINE_ID(abort_edit);
411 DEFINE_ID(__pool__);
412 DEFINE_ID(__pools__);
413 DEFINE_ID(name);
414 DEFINE_ID(value);
415 DEFINE_ID(swig_type_regex);
416 DEFINE_ID(open_tmp_file);
417 DEFINE_ID(get_wc_prop);
418 DEFINE_ID(set_wc_prop);
419 DEFINE_ID(push_wc_prop);
420 DEFINE_ID(invalidate_wc_props);
421 DEFINE_ID(progress_func);
422 DEFINE_ID(auth_baton);
423 DEFINE_ID(found_entry);
424 DEFINE_ID(file_changed);
425 DEFINE_ID(file_added);
426 DEFINE_ID(file_deleted);
427 DEFINE_ID(dir_added);
428 DEFINE_ID(dir_deleted);
429 DEFINE_ID(dir_props_changed);
430 DEFINE_ID(handler);
431 DEFINE_ID(handler_baton);
432 DEFINE_ID(__batons__);
433 DEFINE_ID(destroy);
434 DEFINE_ID(filename_to_temp_file);
435 DEFINE_ID(inspect);
436 DEFINE_ID(handle_error);
437 DEFINE_ID(set_path);
438 DEFINE_ID(delete_path);
439 DEFINE_ID(link_path);
440 DEFINE_ID(finish_report);
441 DEFINE_ID(abort_report);
442 DEFINE_ID(to_s);
443 DEFINE_ID(upcase);
446 void
447 svn_swig_rb_initialize(void)
449 apr_status_t status;
450 apr_pool_t *pool;
451 VALUE mSvnConverter, mSvnLocale, mSvnGetText;
453 status = apr_initialize();
454 if (status) {
455 char buf[1024];
456 apr_strerror(status, buf, sizeof(buf) - 1);
457 rb_raise(rb_eLoadError, "cannot initialize APR: %s", buf);
460 if (atexit(apr_terminate)) {
461 rb_raise(rb_eLoadError, "atexit registration failed");
464 pool = svn_pool_create(NULL);
465 svn_utf_initialize(pool);
467 svn_swig_rb_initialize_ids();
469 mSvnConverter = rb_define_module_under(rb_svn(), "Converter");
470 rb_define_module_function(mSvnConverter, "to_locale_encoding",
471 svn_swig_rb_converter_to_locale_encoding, 1);
473 mSvnLocale = rb_define_module_under(rb_svn(), "Locale");
474 rb_define_const(mSvnLocale, "ALL", INT2NUM(LC_ALL));
475 rb_define_const(mSvnLocale, "COLLATE", INT2NUM(LC_COLLATE));
476 rb_define_const(mSvnLocale, "CTYPE", INT2NUM(LC_CTYPE));
477 #ifdef LC_MESSAGES
478 rb_define_const(mSvnLocale, "MESSAGES", INT2NUM(LC_MESSAGES));
479 #endif
480 rb_define_const(mSvnLocale, "MONETARY", INT2NUM(LC_MONETARY));
481 rb_define_const(mSvnLocale, "NUMERIC", INT2NUM(LC_NUMERIC));
482 rb_define_const(mSvnLocale, "TIME", INT2NUM(LC_TIME));
483 rb_define_module_function(mSvnLocale, "set", svn_swig_rb_locale_set, -1);
485 mSvnGetText = rb_define_module_under(rb_svn(), "GetText");
486 rb_define_module_function(mSvnGetText, "bindtextdomain",
487 svn_swig_rb_gettext_bindtextdomain, 1);
488 rb_define_module_function(mSvnGetText, "_",
489 svn_swig_rb_gettext__, 1);
493 /* pool holder */
494 static VALUE
495 rb_svn_pool_holder(void)
497 return rb_ivar_get(rb_svn_core_pool(), id___pools__);
500 static VALUE
501 rb_svn_fs_warning_callback_baton_holder(void)
503 return rb_ivar_get(rb_svn_fs_file_system(), id___batons__);
506 static VALUE
507 rb_holder_push(VALUE holder, VALUE obj)
509 VALUE key, objs;
511 key = rb_obj_id(obj);
512 objs = rb_hash_aref(holder, key);
514 if (NIL_P(objs)) {
515 objs = rb_ary_new();
516 rb_hash_aset(holder, key, objs);
519 rb_ary_push(objs, obj);
521 return Qnil;
524 static VALUE
525 rb_holder_pop(VALUE holder, VALUE obj)
527 VALUE key, objs;
528 VALUE result = Qnil;
530 key = rb_obj_id(obj);
531 objs = rb_hash_aref(holder, key);
533 if (!NIL_P(objs)) {
534 result = rb_ary_pop(objs);
535 if (RARRAY(objs)->len == 0) {
536 rb_hash_delete(holder, key);
540 return result;
544 /* pool */
545 static VALUE
546 rb_get_pool(VALUE self)
548 return rb_ivar_get(self, id___pool__);
551 static VALUE
552 rb_pools(VALUE self)
554 VALUE pools = rb_ivar_get(self, id___pools__);
556 if (NIL_P(pools)) {
557 pools = rb_hash_new();
558 rb_ivar_set(self, id___pools__, pools);
561 return pools;
564 static VALUE
565 rb_set_pool(VALUE self, VALUE pool)
567 if (NIL_P(pool)) {
568 VALUE old_pool = rb_ivar_get(self, id___pool__);
569 rb_hash_aset(rb_pools(self), rb_obj_id(old_pool), old_pool);
570 rb_ivar_set(self, id___pool__, Qnil);
571 } else {
572 if (NIL_P(rb_ivar_get(self, id___pool__))) {
573 rb_ivar_set(self, id___pool__, pool);
574 } else {
575 rb_hash_aset(rb_pools(self), rb_obj_id(pool), pool);
579 return Qnil;
582 static VALUE
583 rb_pool_new(VALUE parent)
585 return rb_funcall(rb_svn_core_pool(), id_new, 1, parent);
588 static VALUE swig_type_re = Qnil;
590 static VALUE
591 swig_type_regex(void)
593 if (NIL_P(swig_type_re)) {
594 char reg_str[] = "\\A(?:SWIG|Svn::Ext)::";
595 swig_type_re = rb_reg_new(reg_str, strlen(reg_str), 0);
596 rb_ivar_set(rb_svn(), id_swig_type_regex, swig_type_re);
598 return swig_type_re;
601 static VALUE
602 find_swig_type_object(int num, VALUE *objects)
604 VALUE re = swig_type_regex();
605 int i;
607 for (i = 0; i < num; i++) {
608 if (RTEST(rb_reg_match(re,
609 rb_funcall(rb_obj_class(objects[i]),
610 id_name,
611 0)))) {
612 return objects[i];
616 return Qnil;
619 void
620 svn_swig_rb_get_pool(int argc, VALUE *argv, VALUE self,
621 VALUE *rb_pool, apr_pool_t **pool)
623 *rb_pool = Qnil;
625 if (argc > 0) {
626 if (POOL_P(argv[argc - 1])) {
627 *rb_pool = rb_pool_new(argv[argc - 1]);
628 argc -= 1;
632 if (NIL_P(*rb_pool) && !NIL_P(self)) {
633 *rb_pool = rb_get_pool(self);
634 if (POOL_P(*rb_pool)) {
635 *rb_pool = rb_pool_new(*rb_pool);
636 } else {
637 *rb_pool = Qnil;
641 if (NIL_P(*rb_pool)) {
642 VALUE target;
643 target = find_swig_type_object(argc, argv);
644 *rb_pool = rb_pool_new(rb_get_pool(target));
647 if (pool) {
648 apr_pool_wrapper_t *pool_wrapper;
649 apr_pool_wrapper_t **pool_wrapper_p;
651 pool_wrapper_p = &pool_wrapper;
652 r2c_swig_type2(*rb_pool, "apr_pool_wrapper_t *", (void **)pool_wrapper_p);
653 *pool = pool_wrapper->pool;
657 static svn_boolean_t
658 rb_set_pool_if_swig_type_object(VALUE target, VALUE pool)
660 VALUE targets[1] = {target};
662 if (!NIL_P(find_swig_type_object(1, targets))) {
663 rb_set_pool(target, pool);
664 return TRUE;
665 } else {
666 return FALSE;
670 struct rb_set_pool_for_hash_arg {
671 svn_boolean_t set;
672 VALUE pool;
675 static int
676 rb_set_pool_for_hash_callback(VALUE key, VALUE value,
677 struct rb_set_pool_for_hash_arg *arg)
679 if (svn_swig_rb_set_pool(value, arg->pool))
680 arg->set = TRUE;
681 return ST_CONTINUE;
684 svn_boolean_t
685 svn_swig_rb_set_pool(VALUE target, VALUE pool)
687 if (NIL_P(target)) {
688 return FALSE;
691 if (RTEST(rb_obj_is_kind_of(target, rb_cArray))) {
692 long i;
693 svn_boolean_t set = FALSE;
695 for (i = 0; i < RARRAY(target)->len; i++) {
696 if (svn_swig_rb_set_pool(RARRAY(target)->ptr[i], pool))
697 set = TRUE;
699 return set;
700 } else if (RTEST(rb_obj_is_kind_of(target, rb_cHash))) {
701 struct rb_set_pool_for_hash_arg arg;
702 arg.set = FALSE;
703 arg.pool = pool;
704 rb_hash_foreach(target, rb_set_pool_for_hash_callback, (VALUE)&arg);
705 return arg.set;
706 } else {
707 return rb_set_pool_if_swig_type_object(target, pool);
711 void
712 svn_swig_rb_set_pool_for_no_swig_type(VALUE target, VALUE pool)
714 if (NIL_P(target)) {
715 return;
718 if (!RTEST(rb_obj_is_kind_of(target, rb_cArray))) {
719 target = rb_ary_new3(1, target);
722 rb_iterate(rb_each, target, rb_set_pool, pool);
725 void
726 svn_swig_rb_push_pool(VALUE pool)
728 if (!NIL_P(pool)) {
729 rb_holder_push(rb_svn_pool_holder(), pool);
733 void
734 svn_swig_rb_pop_pool(VALUE pool)
736 if (!NIL_P(pool)) {
737 rb_holder_pop(rb_svn_pool_holder(), pool);
741 void
742 svn_swig_rb_destroy_pool(VALUE pool)
744 if (!NIL_P(pool)) {
745 rb_funcall(pool, id_destroy, 0);
749 void
750 svn_swig_rb_destroy_internal_pool(VALUE object)
752 svn_swig_rb_destroy_pool(rb_get_pool(object));
756 /* error */
757 void
758 svn_swig_rb_raise_svn_fs_already_close(void)
760 static VALUE rb_svn_error_fs_already_close = 0;
762 if (!rb_svn_error_fs_already_close) {
763 rb_svn_error_fs_already_close =
764 rb_const_get(rb_svn_error(), rb_intern("FsAlreadyClose"));
767 rb_raise(rb_svn_error_fs_already_close, "closed file system");
770 void
771 svn_swig_rb_raise_svn_repos_already_close(void)
773 static VALUE rb_svn_error_repos_already_close = 0;
775 if (!rb_svn_error_repos_already_close) {
776 rb_svn_error_repos_already_close =
777 rb_const_get(rb_svn_error(), rb_intern("ReposAlreadyClose"));
780 rb_raise(rb_svn_error_repos_already_close, "closed repository");
783 VALUE
784 svn_swig_rb_svn_error_new(VALUE code, VALUE message, VALUE file, VALUE line)
786 return rb_funcall(rb_svn_error_svn_error(),
787 id_new_corresponding_error,
788 4, code, message, file, line);
791 VALUE
792 svn_swig_rb_svn_error_to_rb_error(svn_error_t *error)
794 VALUE error_code = INT2NUM(error->apr_err);
795 VALUE message;
796 VALUE file = Qnil;
797 VALUE line = Qnil;
799 if (error->file)
800 file = rb_str_new2(error->file);
801 if (error->line)
802 line = LONG2NUM(error->line);
804 message = rb_str_new2(error->message ? error->message : "");
806 while (error->child) {
807 error = error->child;
808 if (error->message) {
809 rb_str_concat(message, rb_str_new2("\n"));
810 rb_str_concat(message, rb_str_new2(error->message));
814 return svn_swig_rb_svn_error_new(error_code, message, file, line);
817 void
818 svn_swig_rb_handle_svn_error(svn_error_t *error)
820 VALUE rb_error = svn_swig_rb_svn_error_to_rb_error(error);
821 svn_error_clear(error);
822 rb_exc_raise(rb_error);
826 static VALUE inited = Qnil;
827 /* C -> Ruby */
828 VALUE
829 svn_swig_rb_from_swig_type(void *value, void *ctx)
831 swig_type_info *info;
833 if (NIL_P(inited)) {
834 SWIG_InitRuntime();
835 inited = Qtrue;
838 info = SWIG_TypeQuery((char *)ctx);
839 if (info) {
840 return SWIG_NewPointerObj(value, info, 0);
841 } else {
842 rb_raise(rb_eArgError, "invalid SWIG type: %s", (char *)ctx);
845 #define c2r_swig_type svn_swig_rb_from_swig_type
847 svn_depth_t
848 svn_swig_rb_to_depth(VALUE value)
850 if (NIL_P(value)) {
851 return svn_depth_infinity;
852 } else if (value == Qtrue) {
853 return SVN_DEPTH_INFINITY_OR_FILES(TRUE);
854 } else if (value == Qfalse) {
855 return SVN_DEPTH_INFINITY_OR_FILES(FALSE);
856 } else if (RTEST(rb_obj_is_kind_of(value, rb_cString)) ||
857 RTEST(rb_obj_is_kind_of(value, rb_cSymbol))) {
858 value = rb_funcall(value, id_to_s, 0);
859 return svn_depth_from_word(StringValueCStr(value));
860 } else if (RTEST(rb_obj_is_kind_of(value, rb_cInteger))) {
861 return NUM2INT(value);
862 } else {
863 rb_raise(rb_eArgError,
864 "'%s' must be DEPTH_STRING (e.g. \"infinity\" or :infinity) "
865 "or Svn::Core::DEPTH_*",
866 r2c_inspect(value));
870 svn_mergeinfo_inheritance_t
871 svn_swig_rb_to_mergeinfo_inheritance(VALUE value)
873 if (NIL_P(value)) {
874 return svn_mergeinfo_inherited;
875 } else if (RTEST(rb_obj_is_kind_of(value, rb_cString)) ||
876 RTEST(rb_obj_is_kind_of(value, rb_cSymbol))) {
877 value = rb_funcall(value, id_to_s, 0);
878 return svn_inheritance_from_word(StringValueCStr(value));
879 } else if (RTEST(rb_obj_is_kind_of(value, rb_cInteger))) {
880 return NUM2INT(value);
881 } else {
882 rb_raise(rb_eArgError,
883 "'%s' must be MERGEINFO_STRING (e.g. \"explicit\" or :explicit) "
884 "or Svn::Core::MERGEINFO_*",
885 r2c_inspect(value));
889 static VALUE
890 c2r_string(void *value, void *ctx)
892 if (value) {
893 return rb_str_new2((const char *)value);
894 } else {
895 return Qnil;
899 static VALUE
900 c2r_string2(const char *cstr)
902 return c2r_string((void *)cstr, NULL);
905 #define c2r_bool2(bool) (bool ? Qtrue : Qfalse)
907 VALUE
908 svn_swig_rb_svn_date_string_to_time(const char *date)
910 if (date) {
911 apr_time_t tm;
912 svn_error_t *error;
913 apr_pool_t *pool;
915 pool = svn_pool_create(NULL);
916 error = svn_time_from_cstring(&tm, date, pool);
917 svn_pool_destroy(pool);
918 if (error)
919 svn_swig_rb_handle_svn_error(error);
920 return rb_time_new((time_t)apr_time_sec(tm), (time_t)apr_time_usec(tm));
921 } else {
922 return Qnil;
925 #define c2r_svn_date_string2 svn_swig_rb_svn_date_string_to_time
927 static VALUE
928 c2r_long(void *value, void *ctx)
930 return INT2NUM(*(long *)value);
933 static VALUE
934 c2r_svn_string(void *value, void *ctx)
936 const svn_string_t *s = (svn_string_t *)value;
938 return c2r_string2(s->data);
941 typedef struct {
942 apr_array_header_t *array;
943 apr_pool_t *pool;
944 } prop_hash_each_arg_t;
946 static int
947 svn_swig_rb_to_apr_array_row_prop_callback(VALUE key, VALUE value,
948 prop_hash_each_arg_t *arg)
950 svn_prop_t *prop;
952 prop = apr_array_push(arg->array);
953 prop->name = apr_pstrdup(arg->pool, StringValueCStr(key));
954 prop->value = svn_string_ncreate(RSTRING_PTR(value), RSTRING_LEN(value),
955 arg->pool);
956 return ST_CONTINUE;
959 apr_array_header_t *
960 svn_swig_rb_to_apr_array_row_prop(VALUE array_or_hash, apr_pool_t *pool)
962 if (RTEST(rb_obj_is_kind_of(array_or_hash, rb_cArray))) {
963 int i, len;
964 apr_array_header_t *result;
966 len = RARRAY(array_or_hash)->len;
967 result = apr_array_make(pool, len, sizeof(svn_prop_t));
968 result->nelts = len;
969 for (i = 0; i < len; i++) {
970 VALUE name, value, item;
971 svn_prop_t *prop;
973 item = rb_ary_entry(array_or_hash, i);
974 name = rb_funcall(item, id_name, 0);
975 value = rb_funcall(item, id_value, 0);
976 prop = &APR_ARRAY_IDX(result, i, svn_prop_t);
977 prop->name = apr_pstrdup(pool, StringValueCStr(name));
978 prop->value = svn_string_ncreate(RSTRING_PTR(value), RSTRING_LEN(value),
979 pool);
981 return result;
982 } else if (RTEST(rb_obj_is_kind_of(array_or_hash, rb_cHash))) {
983 apr_array_header_t *result;
984 prop_hash_each_arg_t arg;
986 result = apr_array_make(pool, 0, sizeof(svn_prop_t));
987 arg.array = result;
988 arg.pool = pool;
989 rb_hash_foreach(array_or_hash, svn_swig_rb_to_apr_array_row_prop_callback,
990 (VALUE)&arg);
991 return result;
992 } else {
993 rb_raise(rb_eArgError,
994 "'%s' must be [Svn::Core::Prop, ...] or {'name' => 'value', ...}",
995 r2c_inspect(array_or_hash));
999 static int
1000 svn_swig_rb_to_apr_array_prop_callback(VALUE key, VALUE value,
1001 prop_hash_each_arg_t *arg)
1003 svn_prop_t *prop;
1005 prop = apr_palloc(arg->pool, sizeof(svn_prop_t));
1006 prop->name = apr_pstrdup(arg->pool, StringValueCStr(key));
1007 prop->value = svn_string_ncreate(RSTRING_PTR(value), RSTRING_LEN(value),
1008 arg->pool);
1009 APR_ARRAY_PUSH(arg->array, svn_prop_t *) = prop;
1010 return ST_CONTINUE;
1013 apr_array_header_t *
1014 svn_swig_rb_to_apr_array_prop(VALUE array_or_hash, apr_pool_t *pool)
1016 if (RTEST(rb_obj_is_kind_of(array_or_hash, rb_cArray))) {
1017 int i, len;
1018 apr_array_header_t *result;
1020 len = RARRAY(array_or_hash)->len;
1021 result = apr_array_make(pool, len, sizeof(svn_prop_t *));
1022 result->nelts = len;
1023 for (i = 0; i < len; i++) {
1024 VALUE name, value, item;
1025 svn_prop_t *prop;
1027 item = rb_ary_entry(array_or_hash, i);
1028 name = rb_funcall(item, id_name, 0);
1029 value = rb_funcall(item, id_value, 0);
1030 prop = apr_palloc(pool, sizeof(svn_prop_t));
1031 prop->name = apr_pstrdup(pool, StringValueCStr(name));
1032 prop->value = svn_string_ncreate(RSTRING_PTR(value), RSTRING_LEN(value),
1033 pool);
1034 APR_ARRAY_IDX(result, i, svn_prop_t *) = prop;
1036 return result;
1037 } else if (RTEST(rb_obj_is_kind_of(array_or_hash, rb_cHash))) {
1038 apr_array_header_t *result;
1039 prop_hash_each_arg_t arg;
1041 result = apr_array_make(pool, 0, sizeof(svn_prop_t *));
1042 arg.array = result;
1043 arg.pool = pool;
1044 rb_hash_foreach(array_or_hash, svn_swig_rb_to_apr_array_prop_callback,
1045 (VALUE)&arg);
1046 return result;
1047 } else {
1048 rb_raise(rb_eArgError,
1049 "'%s' must be [Svn::Core::Prop, ...] or {'name' => 'value', ...}",
1050 r2c_inspect(array_or_hash));
1055 /* C -> Ruby (dup) */
1056 #define DEFINE_DUP_BASE(type, dup_func, type_prefix) \
1057 static VALUE \
1058 c2r_ ## type ## _dup(void *type, void *ctx) \
1060 apr_pool_t *pool; \
1061 VALUE rb_pool; \
1062 svn_ ## type ## _t *copied_item; \
1063 VALUE rb_copied_item; \
1065 if (!type) \
1066 return Qnil; \
1068 svn_swig_rb_get_pool(0, (VALUE *)0, 0, &rb_pool, &pool); \
1069 copied_item = svn_ ## dup_func((type_prefix svn_ ## type ## _t *)type, \
1070 pool); \
1071 rb_copied_item = c2r_swig_type((void *)copied_item, \
1072 (void *)"svn_" # type "_t *"); \
1073 rb_set_pool(rb_copied_item, rb_pool); \
1075 return rb_copied_item; \
1078 #define DEFINE_DUP_BASE_WITH_CONVENIENCE(type, dup_func, type_prefix) \
1079 DEFINE_DUP_BASE(type, dup_func, type_prefix) \
1080 static VALUE \
1081 c2r_ ## type ## __dup(type_prefix svn_ ## type ## _t *type) \
1083 void *void_type; \
1084 void_type = (void *)type; \
1085 return c2r_ ## type ## _dup(void_type, NULL); \
1088 #define DEFINE_DUP_WITH_FUNCTION_NAME(type, dup_func) \
1089 DEFINE_DUP_BASE_WITH_CONVENIENCE(type, dup_func, const)
1090 #define DEFINE_DUP(type) \
1091 DEFINE_DUP_WITH_FUNCTION_NAME(type, type ## _dup)
1093 #define DEFINE_DUP_NO_CONVENIENCE_WITH_FUNCTION_NAME(type, dup_func) \
1094 DEFINE_DUP_BASE(type, dup_func, const)
1095 #define DEFINE_DUP_NO_CONVENIENCE(type) \
1096 DEFINE_DUP_NO_CONVENIENCE_WITH_FUNCTION_NAME(type, type ## _dup)
1098 #define DEFINE_DUP_NO_CONST_WITH_FUNCTION_NAME(type, dup_func) \
1099 DEFINE_DUP_BASE_WITH_CONVENIENCE(type, dup_func,)
1100 #define DEFINE_DUP_NO_CONST(type) \
1101 DEFINE_DUP_NO_CONST_WITH_FUNCTION_NAME(type, type ## _dup)
1103 #define DEFINE_DUP_NO_CONST_NO_CONVENIENCE_WITH_FUNCTION_NAME(type, dup_func) \
1104 DEFINE_DUP_BASE(type, dup_func,)
1105 #define DEFINE_DUP_NO_CONST_NO_CONVENIENCE(type) \
1106 DEFINE_DUP_NO_CONST_NO_CONVENIENCE_WITH_FUNCTION_NAME(type, type ## _dup)
1109 DEFINE_DUP_WITH_FUNCTION_NAME(wc_notify, wc_dup_notify)
1110 DEFINE_DUP(txdelta_window)
1111 DEFINE_DUP(info)
1112 DEFINE_DUP(commit_info)
1113 DEFINE_DUP(lock)
1114 DEFINE_DUP(auth_ssl_server_cert_info)
1115 DEFINE_DUP(wc_entry)
1116 DEFINE_DUP(client_diff_summarize)
1117 DEFINE_DUP(dirent)
1118 DEFINE_DUP_NO_CONVENIENCE(client_commit_item3)
1119 DEFINE_DUP_NO_CONVENIENCE(client_proplist_item)
1120 DEFINE_DUP_NO_CONVENIENCE(wc_external_item2)
1121 DEFINE_DUP_NO_CONVENIENCE(log_changed_path)
1122 DEFINE_DUP_NO_CONST_WITH_FUNCTION_NAME(wc_status2, wc_dup_status2)
1123 DEFINE_DUP_NO_CONST_NO_CONVENIENCE(merge_range)
1126 /* Ruby -> C */
1127 static const char *
1128 r2c_inspect(VALUE object)
1130 VALUE inspected;
1131 inspected = rb_funcall(object, id_inspect, 0);
1132 return StringValueCStr(inspected);
1135 static void *
1136 r2c_string(VALUE value, void *ctx, apr_pool_t *pool)
1138 return (void *)apr_pstrdup(pool, StringValuePtr(value));
1141 static void *
1142 r2c_svn_string(VALUE value, void *ctx, apr_pool_t *pool)
1144 return (void *)svn_string_create(StringValuePtr(value), pool);
1147 void *
1148 svn_swig_rb_to_swig_type(VALUE value, void *ctx, apr_pool_t *pool)
1150 void **result = NULL;
1151 result = apr_palloc(pool, sizeof(void *));
1152 r2c_swig_type2(value, (const char *)ctx, result);
1153 return *result;
1155 #define r2c_swig_type svn_swig_rb_to_swig_type
1157 static void
1158 r2c_swig_type2(VALUE value, const char *type_name, void **result)
1160 int res;
1161 res = SWIG_ConvertPtr(value, result, SWIG_TypeQuery(type_name),
1162 SWIG_POINTER_EXCEPTION);
1163 #ifdef SWIG_IsOK
1164 if (!SWIG_IsOK(res)) {
1165 VALUE message = rb_funcall(value, rb_intern("inspect"), 0);
1166 rb_str_cat2(message, "must be ");
1167 rb_str_cat2(message, type_name);
1168 SWIG_Error(SWIG_ArgError(res), StringValuePtr(message));
1170 #endif
1173 static void *
1174 r2c_long(VALUE value, void *ctx, apr_pool_t *pool)
1176 return (void *)NUM2LONG(value);
1179 static void *
1180 r2c_svn_err(VALUE rb_svn_err, void *ctx, apr_pool_t *pool)
1182 VALUE message;
1183 svn_error_t *err;
1185 message = rb_funcall(rb_svn_err, id_message, 0);
1186 err = svn_error_create(NUM2INT(rb_funcall(rb_svn_err, id_code, 0)),
1187 NULL,
1188 StringValuePtr(message));
1189 return (void *)err;
1192 static void *
1193 r2c_revnum(VALUE value, void *ctx, apr_pool_t *pool)
1195 svn_revnum_t *revnum;
1196 revnum = apr_palloc(pool, sizeof(svn_revnum_t));
1197 *revnum = NUM2INT(value);
1198 return revnum;
1201 static void *
1202 r2c_merge_range(VALUE value, void *ctx, apr_pool_t *pool)
1204 return svn_swig_rb_array_to_apr_array_merge_range(value, pool);
1208 /* apr_array_t -> Ruby Array */
1209 #define DEFINE_APR_ARRAY_TO_ARRAY(return_type, name, conv, amp, type, ctx) \
1210 return_type \
1211 name(const apr_array_header_t *apr_ary) \
1213 VALUE ary = rb_ary_new(); \
1214 int i; \
1216 for (i = 0; i < apr_ary->nelts; i++) { \
1217 rb_ary_push(ary, conv((void *)amp(APR_ARRAY_IDX(apr_ary, i, type)), \
1218 ctx)); \
1221 return ary; \
1224 DEFINE_APR_ARRAY_TO_ARRAY(VALUE, svn_swig_rb_apr_array_to_array_string,
1225 c2r_string, EMPTY_CPP_ARGUMENT, const char *, NULL)
1226 DEFINE_APR_ARRAY_TO_ARRAY(VALUE, svn_swig_rb_apr_array_to_array_svn_string,
1227 c2r_svn_string, &, svn_string_t, NULL)
1228 DEFINE_APR_ARRAY_TO_ARRAY(static VALUE, c2r_commit_item3_array,
1229 c2r_client_commit_item3_dup, EMPTY_CPP_ARGUMENT,
1230 svn_client_commit_item3_t *, NULL)
1231 DEFINE_APR_ARRAY_TO_ARRAY(VALUE, svn_swig_rb_apr_array_to_array_svn_rev,
1232 c2r_long, &, svn_revnum_t, NULL)
1233 DEFINE_APR_ARRAY_TO_ARRAY(VALUE, svn_swig_rb_apr_array_to_array_proplist_item,
1234 c2r_client_proplist_item_dup, EMPTY_CPP_ARGUMENT,
1235 svn_client_proplist_item_t *, NULL)
1236 DEFINE_APR_ARRAY_TO_ARRAY(VALUE, svn_swig_rb_apr_array_to_array_external_item2,
1237 c2r_wc_external_item2_dup, EMPTY_CPP_ARGUMENT,
1238 svn_wc_external_item2_t *, NULL)
1239 DEFINE_APR_ARRAY_TO_ARRAY(VALUE, svn_swig_rb_apr_array_to_array_merge_range,
1240 c2r_merge_range_dup, EMPTY_CPP_ARGUMENT,
1241 svn_merge_range_t *, NULL)
1243 VALUE
1244 c2r_merge_range_array(void *value, void *ctx)
1246 return svn_swig_rb_apr_array_to_array_merge_range(value);
1249 VALUE
1250 svn_swig_rb_prop_apr_array_to_hash_prop(const apr_array_header_t *apr_ary)
1252 VALUE hash;
1253 int i;
1255 hash = rb_hash_new();
1256 for (i = 0; i < apr_ary->nelts; i++) {
1257 svn_prop_t prop;
1258 prop = APR_ARRAY_IDX(apr_ary, i, svn_prop_t);
1259 rb_hash_aset(hash,
1260 prop.name ? rb_str_new2(prop.name) : Qnil,
1261 prop.value && prop.value->data ?
1262 rb_str_new2(prop.value->data) : Qnil);
1265 return hash;
1268 apr_array_header_t *
1269 svn_swig_rb_array_to_apr_array_revision_range(VALUE array, apr_pool_t *pool)
1271 int i, len;
1272 apr_array_header_t *apr_ary;
1274 Check_Type(array, T_ARRAY);
1275 len = RARRAY(array)->len;
1276 apr_ary = apr_array_make(pool, len, sizeof(svn_opt_revision_range_t *));
1277 apr_ary->nelts = len;
1278 for (i = 0; i < len; i++) {
1279 VALUE value;
1280 svn_opt_revision_range_t *range;
1282 value = rb_ary_entry(array, i);
1283 if (RTEST(rb_obj_is_kind_of(value, rb_cArray))) {
1284 if (RARRAY(value)->len != 2)
1285 rb_raise(rb_eArgError,
1286 "revision range should be [start, end]: %s",
1287 r2c_inspect(value));
1288 range = apr_palloc(pool, sizeof(*range));
1289 svn_swig_rb_set_revision(&range->start, rb_ary_entry(value, 0));
1290 svn_swig_rb_set_revision(&range->end, rb_ary_entry(value, 1));
1291 } else {
1292 range = r2c_swig_type(value, (void *)"svn_opt_revision_range_t *", pool);
1294 APR_ARRAY_IDX(apr_ary, i, svn_opt_revision_range_t *) = range;
1296 return apr_ary;
1301 /* Ruby Array -> apr_array_t */
1302 #define DEFINE_ARRAY_TO_APR_ARRAY(type, name, converter, context) \
1303 apr_array_header_t * \
1304 name(VALUE array, apr_pool_t *pool) \
1306 int i, len; \
1307 apr_array_header_t *apr_ary; \
1309 Check_Type(array, T_ARRAY); \
1310 len = RARRAY(array)->len; \
1311 apr_ary = apr_array_make(pool, len, sizeof(type)); \
1312 apr_ary->nelts = len; \
1313 for (i = 0; i < len; i++) { \
1314 VALUE value; \
1315 type val; \
1316 value = rb_ary_entry(array, i); \
1317 val = (type)converter(value, context, pool); \
1318 APR_ARRAY_IDX(apr_ary, i, type) = val; \
1320 return apr_ary; \
1323 DEFINE_ARRAY_TO_APR_ARRAY(const char *, svn_swig_rb_strings_to_apr_array,
1324 r2c_string, NULL)
1325 DEFINE_ARRAY_TO_APR_ARRAY(svn_auth_provider_object_t *,
1326 svn_swig_rb_array_to_auth_provider_object_apr_array,
1327 r2c_swig_type, (void *)"svn_auth_provider_object_t *")
1328 DEFINE_ARRAY_TO_APR_ARRAY(svn_revnum_t,
1329 svn_swig_rb_array_to_apr_array_revnum,
1330 r2c_long, NULL)
1331 DEFINE_ARRAY_TO_APR_ARRAY(svn_merge_range_t *,
1332 svn_swig_rb_array_to_apr_array_merge_range,
1333 r2c_swig_type, (void *)"svn_merge_range_t *")
1334 DEFINE_ARRAY_TO_APR_ARRAY(svn_client_copy_source_t *,
1335 svn_swig_rb_array_to_apr_array_copy_source,
1336 r2c_swig_type, (void *)"svn_client_copy_source_t *")
1339 /* apr_hash_t -> Ruby Hash */
1340 static VALUE
1341 c2r_hash_with_key_convert(apr_hash_t *hash,
1342 c2r_func key_conv,
1343 void *key_ctx,
1344 c2r_func value_conv,
1345 void *value_ctx)
1347 apr_hash_index_t *hi;
1348 VALUE r_hash;
1350 if (!hash)
1351 return Qnil;
1353 r_hash = rb_hash_new();
1355 for (hi = apr_hash_first(NULL, hash); hi; hi = apr_hash_next(hi)) {
1356 const void *key;
1357 void *val;
1358 VALUE v = Qnil;
1360 apr_hash_this(hi, &key, NULL, &val);
1361 if (val) {
1362 v = (*value_conv)(val, value_ctx);
1364 rb_hash_aset(r_hash, (*key_conv)((void *)key, key_ctx), v);
1367 return r_hash;
1370 VALUE
1371 c2r_hash(apr_hash_t *hash,
1372 c2r_func value_conv,
1373 void *ctx)
1375 return c2r_hash_with_key_convert(hash, c2r_string, NULL, value_conv, ctx);
1378 VALUE
1379 svn_swig_rb_apr_hash_to_hash_string(apr_hash_t *hash)
1381 return c2r_hash(hash, c2r_string, NULL);
1384 VALUE
1385 svn_swig_rb_apr_hash_to_hash_svn_string(apr_hash_t *hash)
1387 return c2r_hash(hash, c2r_svn_string, NULL);
1390 VALUE
1391 svn_swig_rb_apr_hash_to_hash_swig_type(apr_hash_t *hash, const char *type_name)
1393 return c2r_hash(hash, c2r_swig_type, (void *)type_name);
1396 VALUE
1397 svn_swig_rb_apr_hash_to_hash_merge_range(apr_hash_t *hash)
1399 return c2r_hash(hash, c2r_merge_range_array, NULL);
1402 static VALUE
1403 c2r_merge_range_hash(void *value, void *ctx)
1405 apr_hash_t *hash = value;
1407 return svn_swig_rb_apr_hash_to_hash_merge_range(hash);
1410 VALUE
1411 svn_swig_rb_apr_hash_to_hash_merge_range_hash(apr_hash_t *hash)
1413 return c2r_hash(hash, c2r_merge_range_hash, NULL);
1416 VALUE
1417 svn_swig_rb_prop_hash_to_hash(apr_hash_t *prop_hash)
1419 return svn_swig_rb_apr_hash_to_hash_svn_string(prop_hash);
1422 VALUE
1423 c2r_revnum(void *value, void *ctx)
1425 svn_revnum_t *num = value;
1426 return INT2NUM(*num);
1429 VALUE
1430 svn_swig_rb_apr_revnum_key_hash_to_hash_string(apr_hash_t *hash)
1432 return c2r_hash_with_key_convert(hash, c2r_revnum, NULL, c2r_string, NULL);
1436 /* Ruby Hash -> apr_hash_t */
1437 static int
1438 r2c_hash_i(VALUE key, VALUE value, hash_to_apr_hash_data_t *data)
1440 if (key != Qundef) {
1441 void *val = data->func(value, data->ctx, data->pool);
1442 apr_hash_set(data->apr_hash,
1443 apr_pstrdup(data->pool, StringValuePtr(key)),
1444 APR_HASH_KEY_STRING,
1445 val);
1447 return ST_CONTINUE;
1450 static apr_hash_t *
1451 r2c_hash(VALUE hash, r2c_func func, void *ctx, apr_pool_t *pool)
1453 if (NIL_P(hash)) {
1454 return NULL;
1455 } else {
1456 apr_hash_t *apr_hash;
1457 hash_to_apr_hash_data_t data = {
1458 NULL,
1459 func,
1460 ctx,
1461 pool
1464 apr_hash = apr_hash_make(pool);
1465 data.apr_hash = apr_hash;
1466 rb_hash_foreach(hash, r2c_hash_i, (VALUE)&data);
1468 return apr_hash;
1473 apr_hash_t *
1474 svn_swig_rb_hash_to_apr_hash_string(VALUE hash, apr_pool_t *pool)
1476 return r2c_hash(hash, r2c_string, NULL, pool);
1479 apr_hash_t *
1480 svn_swig_rb_hash_to_apr_hash_svn_string(VALUE hash, apr_pool_t *pool)
1482 return r2c_hash(hash, r2c_svn_string, NULL, pool);
1485 apr_hash_t *
1486 svn_swig_rb_hash_to_apr_hash_swig_type(VALUE hash, const char *typename, apr_pool_t *pool)
1488 return r2c_hash(hash, r2c_swig_type, (void *)typename, pool);
1491 apr_hash_t *
1492 svn_swig_rb_hash_to_apr_hash_revnum(VALUE hash, apr_pool_t *pool)
1494 return r2c_hash(hash, r2c_revnum, NULL, pool);
1497 apr_hash_t *
1498 svn_swig_rb_hash_to_apr_hash_merge_range(VALUE hash, apr_pool_t *pool)
1500 return r2c_hash(hash, r2c_merge_range, NULL, pool);
1504 /* callback */
1505 typedef struct {
1506 VALUE pool;
1507 VALUE receiver;
1508 ID message;
1509 VALUE args;
1510 } callback_baton_t;
1512 typedef struct {
1513 svn_error_t **err;
1514 VALUE pool;
1515 } callback_rescue_baton_t;
1517 typedef struct {
1518 callback_baton_t *callback_baton;
1519 callback_rescue_baton_t *rescue_baton;
1520 } callback_handle_error_baton_t;
1522 static VALUE
1523 callback(VALUE baton)
1525 callback_baton_t *cbb = (callback_baton_t *)baton;
1526 VALUE result;
1528 result = rb_apply(cbb->receiver, cbb->message, cbb->args);
1529 svn_swig_rb_push_pool(cbb->pool);
1531 return result;
1534 static VALUE
1535 callback_rescue(VALUE baton)
1537 callback_rescue_baton_t *rescue_baton = (callback_rescue_baton_t*)baton;
1539 *(rescue_baton->err) = r2c_svn_err(ruby_errinfo, NULL, NULL);
1540 svn_swig_rb_push_pool(rescue_baton->pool);
1542 return Qnil;
1545 static VALUE
1546 callback_ensure(VALUE pool)
1548 svn_swig_rb_pop_pool(pool);
1550 return Qnil;
1553 static VALUE
1554 invoke_callback(VALUE baton, VALUE pool)
1556 callback_baton_t *cbb = (callback_baton_t *)baton;
1557 VALUE sub_pool;
1558 VALUE argv[] = {pool};
1560 svn_swig_rb_get_pool(1, argv, Qnil, &sub_pool, NULL);
1561 cbb->pool = sub_pool;
1562 return rb_ensure(callback, baton, callback_ensure, sub_pool);
1565 static VALUE
1566 callback_handle_error(VALUE baton)
1568 callback_handle_error_baton_t *handle_error_baton;
1569 handle_error_baton = (callback_handle_error_baton_t *)baton;
1571 return rb_rescue2(callback,
1572 (VALUE)(handle_error_baton->callback_baton),
1573 callback_rescue,
1574 (VALUE)(handle_error_baton->rescue_baton),
1575 rb_svn_error(),
1576 (VALUE)0);
1579 static VALUE
1580 invoke_callback_handle_error(VALUE baton, VALUE pool, svn_error_t **err)
1582 callback_baton_t *cbb = (callback_baton_t *)baton;
1583 callback_handle_error_baton_t handle_error_baton;
1584 callback_rescue_baton_t rescue_baton;
1586 rescue_baton.err = err;
1587 rescue_baton.pool = pool;
1588 cbb->pool = pool;
1589 handle_error_baton.callback_baton = cbb;
1590 handle_error_baton.rescue_baton = &rescue_baton;
1592 return rb_ensure(callback_handle_error, (VALUE)&handle_error_baton,
1593 callback_ensure, pool);
1597 /* svn_delta_editor_t */
1598 typedef struct {
1599 VALUE editor;
1600 VALUE baton;
1601 } item_baton;
1603 static void
1604 add_baton(VALUE editor, VALUE baton)
1606 if (NIL_P((rb_ivar_get(editor, id_baton)))) {
1607 rb_ivar_set(editor, id_baton, rb_ary_new());
1610 rb_ary_push(rb_ivar_get(editor, id_baton), baton);
1613 static item_baton *
1614 make_baton(apr_pool_t *pool, VALUE editor, VALUE baton)
1616 item_baton *newb = apr_palloc(pool, sizeof(*newb));
1618 newb->editor = editor;
1619 newb->baton = baton;
1620 add_baton(editor, baton);
1622 return newb;
1625 static VALUE
1626 add_baton_if_delta_editor(VALUE target, VALUE baton)
1628 if (RTEST(rb_obj_is_kind_of(target, svn_swig_rb_svn_delta_editor()))) {
1629 add_baton(target, baton);
1632 return Qnil;
1635 void
1636 svn_swig_rb_set_baton(VALUE target, VALUE baton)
1638 if (NIL_P(baton)) {
1639 return;
1642 if (!RTEST(rb_obj_is_kind_of(target, rb_cArray))) {
1643 target = rb_ary_new3(1, target);
1646 rb_iterate(rb_each, target, add_baton_if_delta_editor, baton);
1650 static svn_error_t *
1651 delta_editor_set_target_revision(void *edit_baton,
1652 svn_revnum_t target_revision,
1653 apr_pool_t *pool)
1655 item_baton *ib = edit_baton;
1656 svn_error_t *err = SVN_NO_ERROR;
1657 callback_baton_t cbb;
1659 cbb.receiver = ib->editor;
1660 cbb.message = id_set_target_revision;
1661 cbb.args = rb_ary_new3(1, INT2NUM(target_revision));
1662 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1663 return err;
1666 static svn_error_t *
1667 delta_editor_open_root(void *edit_baton,
1668 svn_revnum_t base_revision,
1669 apr_pool_t *dir_pool,
1670 void **root_baton)
1672 item_baton *ib = edit_baton;
1673 svn_error_t *err = SVN_NO_ERROR;
1674 callback_baton_t cbb;
1675 VALUE result;
1677 cbb.receiver = ib->editor;
1678 cbb.message = id_open_root;
1679 cbb.args = rb_ary_new3(1, INT2NUM(base_revision));
1680 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1681 *root_baton = make_baton(dir_pool, ib->editor, result);
1682 return err;
1685 static svn_error_t *
1686 delta_editor_delete_entry(const char *path,
1687 svn_revnum_t revision,
1688 void *parent_baton,
1689 apr_pool_t *pool)
1691 item_baton *ib = parent_baton;
1692 svn_error_t *err = SVN_NO_ERROR;
1693 callback_baton_t cbb;
1695 cbb.receiver = ib->editor;
1696 cbb.message = id_delete_entry;
1697 cbb.args = rb_ary_new3(3, c2r_string2(path), INT2NUM(revision), ib->baton);
1698 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1699 return err;
1702 static svn_error_t *
1703 delta_editor_add_directory(const char *path,
1704 void *parent_baton,
1705 const char *copyfrom_path,
1706 svn_revnum_t copyfrom_revision,
1707 apr_pool_t *dir_pool,
1708 void **child_baton)
1710 item_baton *ib = parent_baton;
1711 svn_error_t *err = SVN_NO_ERROR;
1712 callback_baton_t cbb;
1713 VALUE result;
1715 cbb.receiver = ib->editor;
1716 cbb.message = id_add_directory;
1717 cbb.args = rb_ary_new3(4,
1718 c2r_string2(path),
1719 ib->baton,
1720 c2r_string2(copyfrom_path),
1721 INT2NUM(copyfrom_revision));
1722 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1723 *child_baton = make_baton(dir_pool, ib->editor, result);
1724 return err;
1727 static svn_error_t *
1728 delta_editor_open_directory(const char *path,
1729 void *parent_baton,
1730 svn_revnum_t base_revision,
1731 apr_pool_t *dir_pool,
1732 void **child_baton)
1734 item_baton *ib = parent_baton;
1735 svn_error_t *err = SVN_NO_ERROR;
1736 callback_baton_t cbb;
1737 VALUE result;
1739 cbb.receiver = ib->editor;
1740 cbb.message = id_open_directory;
1741 cbb.args = rb_ary_new3(3,
1742 c2r_string2(path),
1743 ib->baton,
1744 INT2NUM(base_revision));
1745 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1746 *child_baton = make_baton(dir_pool, ib->editor, result);
1747 return err;
1750 static svn_error_t *
1751 delta_editor_change_dir_prop(void *dir_baton,
1752 const char *name,
1753 const svn_string_t *value,
1754 apr_pool_t *pool)
1756 item_baton *ib = dir_baton;
1757 svn_error_t *err = SVN_NO_ERROR;
1758 callback_baton_t cbb;
1760 cbb.receiver = ib->editor;
1761 cbb.message = id_change_dir_prop;
1762 cbb.args = rb_ary_new3(3,
1763 ib->baton,
1764 c2r_string2(name),
1765 value ? rb_str_new(value->data, value->len) : Qnil);
1766 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1767 return err;
1770 static svn_error_t *
1771 delta_editor_close_baton(void *baton, ID method_id)
1773 item_baton *ib = baton;
1774 svn_error_t *err = SVN_NO_ERROR;
1775 callback_baton_t cbb;
1777 cbb.receiver = ib->editor;
1778 cbb.message = method_id;
1779 cbb.args = rb_ary_new3(1, ib->baton);
1780 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1781 return err;
1784 static svn_error_t *
1785 delta_editor_close_directory(void *dir_baton, apr_pool_t *pool)
1787 return delta_editor_close_baton(dir_baton, id_close_directory);
1790 static svn_error_t *
1791 delta_editor_absent_directory(const char *path,
1792 void *parent_baton,
1793 apr_pool_t *pool)
1795 item_baton *ib = parent_baton;
1796 svn_error_t *err = SVN_NO_ERROR;
1797 callback_baton_t cbb;
1799 cbb.receiver = ib->editor;
1800 cbb.message = id_absent_directory;
1801 cbb.args = rb_ary_new3(2, c2r_string2(path), ib->baton);
1802 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1803 return err;
1806 static svn_error_t *
1807 delta_editor_add_file(const char *path,
1808 void *parent_baton,
1809 const char *copyfrom_path,
1810 svn_revnum_t copyfrom_revision,
1811 apr_pool_t *file_pool,
1812 void **file_baton)
1814 item_baton *ib = parent_baton;
1815 svn_error_t *err = SVN_NO_ERROR;
1816 callback_baton_t cbb;
1817 VALUE result;
1819 cbb.receiver = ib->editor;
1820 cbb.message = id_add_file;
1821 cbb.args = rb_ary_new3(4,
1822 c2r_string2(path),
1823 ib->baton,
1824 c2r_string2(copyfrom_path),
1825 INT2NUM(copyfrom_revision));
1826 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1827 *file_baton = make_baton(file_pool, ib->editor, result);
1828 return err;
1831 static svn_error_t *
1832 delta_editor_open_file(const char *path,
1833 void *parent_baton,
1834 svn_revnum_t base_revision,
1835 apr_pool_t *file_pool,
1836 void **file_baton)
1838 item_baton *ib = parent_baton;
1839 svn_error_t *err = SVN_NO_ERROR;
1840 callback_baton_t cbb;
1841 VALUE result;
1843 cbb.receiver = ib->editor;
1844 cbb.message = id_open_file;
1845 cbb.args = rb_ary_new3(3,
1846 c2r_string2(path),
1847 ib->baton,
1848 INT2NUM(base_revision));
1849 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1850 *file_baton = make_baton(file_pool, ib->editor, result);
1851 return err;
1854 static svn_error_t *
1855 delta_editor_window_handler(svn_txdelta_window_t *window, void *baton)
1857 VALUE handler = (VALUE)baton;
1858 callback_baton_t cbb;
1859 VALUE result;
1860 svn_error_t *err = SVN_NO_ERROR;
1862 cbb.receiver = handler;
1863 cbb.message = id_call;
1864 cbb.args = rb_ary_new3(1, c2r_txdelta_window__dup(window));
1865 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1866 return err;
1869 static svn_error_t *
1870 delta_editor_apply_textdelta(void *file_baton,
1871 const char *base_checksum,
1872 apr_pool_t *pool,
1873 svn_txdelta_window_handler_t *handler,
1874 void **h_baton)
1876 item_baton *ib = file_baton;
1877 svn_error_t *err = SVN_NO_ERROR;
1878 callback_baton_t cbb;
1879 VALUE result;
1881 cbb.receiver = ib->editor;
1882 cbb.message = id_apply_textdelta;
1883 cbb.args = rb_ary_new3(2, ib->baton, c2r_string2(base_checksum));
1884 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1885 if (NIL_P(result)) {
1886 *handler = svn_delta_noop_window_handler;
1887 *h_baton = NULL;
1888 } else {
1889 *handler = delta_editor_window_handler;
1890 *h_baton = (void *)result;
1893 return err;
1896 static svn_error_t *
1897 delta_editor_change_file_prop(void *file_baton,
1898 const char *name,
1899 const svn_string_t *value,
1900 apr_pool_t *pool)
1902 item_baton *ib = file_baton;
1903 svn_error_t *err = SVN_NO_ERROR;
1904 callback_baton_t cbb;
1906 cbb.receiver = ib->editor;
1907 cbb.message = id_change_file_prop;
1908 cbb.args = rb_ary_new3(3,
1909 ib->baton,
1910 c2r_string2(name),
1911 value ? rb_str_new(value->data, value->len) : Qnil);
1912 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1914 return err;
1917 static svn_error_t *
1918 delta_editor_close_file(void *file_baton,
1919 const char *text_checksum,
1920 apr_pool_t *pool)
1922 item_baton *ib = file_baton;
1923 svn_error_t *err = SVN_NO_ERROR;
1924 callback_baton_t cbb;
1926 cbb.receiver = ib->editor;
1927 cbb.message = id_close_file;
1928 cbb.args = rb_ary_new3(2, ib->baton, c2r_string2(text_checksum));
1929 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1931 return err;
1934 static svn_error_t *
1935 delta_editor_absent_file(const char *path,
1936 void *parent_baton,
1937 apr_pool_t *pool)
1939 item_baton *ib = parent_baton;
1940 svn_error_t *err = SVN_NO_ERROR;
1941 callback_baton_t cbb;
1943 cbb.receiver = ib->editor;
1944 cbb.message = id_absent_file;
1945 cbb.args = rb_ary_new3(2, c2r_string2(path), ib->baton);
1946 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
1948 return err;
1951 static svn_error_t *
1952 delta_editor_close_edit(void *edit_baton, apr_pool_t *pool)
1954 item_baton *ib = edit_baton;
1955 svn_error_t *err = delta_editor_close_baton(edit_baton, id_close_edit);
1956 rb_ary_clear(rb_ivar_get(ib->editor, id_baton));
1957 return err;
1960 static svn_error_t *
1961 delta_editor_abort_edit(void *edit_baton, apr_pool_t *pool)
1963 item_baton *ib = edit_baton;
1964 svn_error_t *err = delta_editor_close_baton(edit_baton, id_abort_edit);
1965 rb_ary_clear(rb_ivar_get(ib->editor, id_baton));
1966 return err;
1969 void
1970 svn_swig_rb_make_delta_editor(svn_delta_editor_t **editor,
1971 void **edit_baton,
1972 VALUE rb_editor,
1973 apr_pool_t *pool)
1975 svn_delta_editor_t *thunk_editor = svn_delta_default_editor(pool);
1977 thunk_editor->set_target_revision = delta_editor_set_target_revision;
1978 thunk_editor->open_root = delta_editor_open_root;
1979 thunk_editor->delete_entry = delta_editor_delete_entry;
1980 thunk_editor->add_directory = delta_editor_add_directory;
1981 thunk_editor->open_directory = delta_editor_open_directory;
1982 thunk_editor->change_dir_prop = delta_editor_change_dir_prop;
1983 thunk_editor->close_directory = delta_editor_close_directory;
1984 thunk_editor->absent_directory = delta_editor_absent_directory;
1985 thunk_editor->add_file = delta_editor_add_file;
1986 thunk_editor->open_file = delta_editor_open_file;
1987 thunk_editor->apply_textdelta = delta_editor_apply_textdelta;
1988 thunk_editor->change_file_prop = delta_editor_change_file_prop;
1989 thunk_editor->close_file = delta_editor_close_file;
1990 thunk_editor->absent_file = delta_editor_absent_file;
1991 thunk_editor->close_edit = delta_editor_close_edit;
1992 thunk_editor->abort_edit = delta_editor_abort_edit;
1994 *editor = thunk_editor;
1995 rb_ivar_set(rb_editor, id_baton, rb_ary_new());
1996 *edit_baton = make_baton(pool, rb_editor, Qnil);
2000 VALUE
2001 svn_swig_rb_make_baton(VALUE proc, VALUE pool)
2003 if (NIL_P(proc)) {
2004 return Qnil;
2005 } else {
2006 return rb_ary_new3(2, proc, pool);
2010 void
2011 svn_swig_rb_from_baton(VALUE baton, VALUE *proc, VALUE *pool)
2013 if (NIL_P(baton)) {
2014 *proc = Qnil;
2015 *pool = Qnil;
2016 } else {
2017 *proc = rb_ary_entry(baton, 0);
2018 *pool = rb_ary_entry(baton, 1);
2022 svn_error_t *
2023 svn_swig_rb_log_receiver(void *baton,
2024 apr_hash_t *changed_paths,
2025 svn_revnum_t revision,
2026 const char *author,
2027 const char *date,
2028 const char *message,
2029 apr_pool_t *pool)
2031 svn_error_t *err = SVN_NO_ERROR;
2032 VALUE proc, rb_pool;
2034 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2036 if (!NIL_P(proc)) {
2037 callback_baton_t cbb;
2038 VALUE rb_changed_paths = Qnil;
2040 if (changed_paths) {
2041 rb_changed_paths = c2r_hash(changed_paths,
2042 c2r_log_changed_path_dup,
2043 NULL);
2046 cbb.receiver = proc;
2047 cbb.message = id_call;
2048 cbb.args = rb_ary_new3(5,
2049 rb_changed_paths,
2050 c2r_long(&revision, NULL),
2051 c2r_string2(author),
2052 c2r_svn_date_string2(date),
2053 c2r_string2(message));
2054 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2056 return err;
2060 svn_error_t *
2061 svn_swig_rb_repos_authz_func(svn_boolean_t *allowed,
2062 svn_fs_root_t *root,
2063 const char *path,
2064 void *baton,
2065 apr_pool_t *pool)
2067 svn_error_t *err = SVN_NO_ERROR;
2068 VALUE proc, rb_pool;
2070 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2072 *allowed = TRUE;
2074 if (!NIL_P(proc)) {
2075 callback_baton_t cbb;
2076 VALUE result;
2078 cbb.receiver = proc;
2079 cbb.message = id_call;
2080 cbb.args = rb_ary_new3(2,
2081 c2r_swig_type((void *)root,
2082 (void *)"svn_fs_root_t *"),
2083 c2r_string2(path));
2084 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2086 *allowed = RTEST(result);
2088 return err;
2091 svn_error_t *
2092 svn_swig_rb_repos_authz_callback(svn_repos_authz_access_t required,
2093 svn_boolean_t *allowed,
2094 svn_fs_root_t *root,
2095 const char *path,
2096 void *baton,
2097 apr_pool_t *pool)
2099 svn_error_t *err = SVN_NO_ERROR;
2100 VALUE proc, rb_pool;
2102 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2104 *allowed = TRUE;
2106 if (!NIL_P(proc)) {
2107 callback_baton_t cbb;
2108 VALUE result;
2110 cbb.receiver = proc;
2111 cbb.message = id_call;
2112 cbb.args = rb_ary_new3(3,
2113 INT2NUM(required),
2114 c2r_swig_type((void *)root,
2115 (void *)"svn_fs_root_t *"),
2116 c2r_string2(path));
2117 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2119 *allowed = RTEST(result);
2121 return err;
2124 svn_error_t *
2125 svn_swig_rb_get_commit_log_func(const char **log_msg,
2126 const char **tmp_file,
2127 const apr_array_header_t *commit_items,
2128 void *baton,
2129 apr_pool_t *pool)
2131 svn_error_t *err = SVN_NO_ERROR;
2132 VALUE proc, rb_pool;
2134 *log_msg = NULL;
2135 *tmp_file = NULL;
2137 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2139 if (!NIL_P(proc)) {
2140 callback_baton_t cbb;
2141 VALUE result;
2142 VALUE is_message;
2143 VALUE value;
2144 char *ret;
2146 cbb.receiver = proc;
2147 cbb.message = id_call;
2148 cbb.args = rb_ary_new3(1, c2r_commit_item3_array(commit_items));
2149 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2151 if (!err) {
2152 char error_message[] =
2153 "log_msg_func should return an array not '%s': "
2154 "[TRUE_IF_IT_IS_MESSAGE, MESSAGE_OR_FILE_AS_STRING]";
2156 if (!RTEST(rb_obj_is_kind_of(result, rb_cArray)))
2157 rb_raise(rb_eTypeError, error_message, r2c_inspect(result));
2158 is_message = rb_ary_entry(result, 0);
2159 value = rb_ary_entry(result, 1);
2161 if (!RTEST(rb_obj_is_kind_of(value, rb_cString)))
2162 rb_raise(rb_eTypeError, error_message, r2c_inspect(result));
2163 ret = (char *)r2c_string(value, NULL, pool);
2164 if (RTEST(is_message)) {
2165 *log_msg = ret;
2166 } else {
2167 *tmp_file = ret;
2171 return err;
2175 void
2176 svn_swig_rb_notify_func2(void *baton,
2177 const svn_wc_notify_t *notify,
2178 apr_pool_t *pool)
2180 VALUE proc, rb_pool;
2181 callback_baton_t cbb;
2183 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2185 if (!NIL_P(proc)) {
2186 cbb.receiver = proc;
2187 cbb.message = id_call;
2188 cbb.args = rb_ary_new3(1, c2r_wc_notify__dup(notify));
2191 if (notify->err)
2192 svn_error_clear(notify->err);
2194 if (!NIL_P(proc))
2195 invoke_callback((VALUE)(&cbb), rb_pool);
2198 svn_error_t *
2199 svn_swig_rb_conflict_resolver_func
2200 (svn_wc_conflict_result_t **result,
2201 const svn_wc_conflict_description_t *description,
2202 void *baton,
2203 apr_pool_t *pool)
2205 svn_error_t *err = SVN_NO_ERROR;
2206 VALUE proc, rb_pool;
2208 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2210 if (NIL_P(proc)) {
2211 *result = svn_wc_create_conflict_result(svn_wc_conflict_choose_postpone,
2212 description->merged_file,
2213 pool);
2214 } else {
2215 callback_baton_t cbb;
2216 VALUE fret;
2218 cbb.receiver = proc;
2219 cbb.message = id_call;
2220 cbb.args = rb_ary_new3(
2222 c2r_swig_type((void *)description,
2223 (void *)"svn_wc_conflict_description_t *") );
2224 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2225 fret = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2226 *result = svn_wc_create_conflict_result(NUM2INT(fret),
2227 description->merged_file,
2228 pool);
2231 return err;
2234 svn_error_t *
2235 svn_swig_rb_commit_callback(svn_revnum_t new_revision,
2236 const char *date,
2237 const char *author,
2238 void *baton)
2240 svn_error_t *err = SVN_NO_ERROR;
2241 VALUE proc, rb_pool;
2243 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2245 if (!NIL_P(proc)) {
2246 callback_baton_t cbb;
2248 cbb.receiver = proc;
2249 cbb.message = id_call;
2250 cbb.args = rb_ary_new3(3,
2251 INT2NUM(new_revision),
2252 c2r_svn_date_string2(date),
2253 c2r_string2(author));
2254 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2257 return err;
2260 svn_error_t *
2261 svn_swig_rb_commit_callback2(const svn_commit_info_t *commit_info,
2262 void *baton, apr_pool_t *pool)
2264 svn_error_t *err = SVN_NO_ERROR;
2265 VALUE proc, rb_pool;
2267 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2269 if (!NIL_P(proc)) {
2270 callback_baton_t cbb;
2272 cbb.receiver = proc;
2273 cbb.message = id_call;
2274 cbb.args = rb_ary_new3(1, c2r_commit_info__dup(commit_info));
2275 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2278 return err;
2281 svn_error_t *
2282 svn_swig_rb_cancel_func(void *cancel_baton)
2284 svn_error_t *err = SVN_NO_ERROR;
2285 VALUE proc, rb_pool;
2287 svn_swig_rb_from_baton((VALUE)cancel_baton, &proc, &rb_pool);
2289 if (!NIL_P(proc)) {
2290 callback_baton_t cbb;
2292 cbb.receiver = proc;
2293 cbb.message = id_call;
2294 cbb.args = rb_ary_new3(0);
2295 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2298 return err;
2301 svn_error_t *
2302 svn_swig_rb_info_receiver(void *baton,
2303 const char *path,
2304 const svn_info_t *info,
2305 apr_pool_t *pool)
2307 svn_error_t *err = SVN_NO_ERROR;
2308 VALUE proc, rb_pool;
2310 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2312 if (!NIL_P(proc)) {
2313 callback_baton_t cbb;
2315 cbb.receiver = proc;
2316 cbb.message = id_call;
2317 cbb.args = rb_ary_new3(2, c2r_string2(path), c2r_info__dup(info));
2318 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2321 return err;
2324 svn_boolean_t
2325 svn_swig_rb_config_enumerator(const char *name,
2326 const char *value,
2327 void *baton,
2328 apr_pool_t *pool)
2330 svn_boolean_t result = FALSE;
2331 VALUE proc, rb_pool;
2333 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2335 if (!NIL_P(proc)) {
2336 callback_baton_t cbb;
2338 cbb.receiver = proc;
2339 cbb.message = id_call;
2340 cbb.args = rb_ary_new3(2, c2r_string2(name), c2r_string2(value));
2341 result = RTEST(invoke_callback((VALUE)(&cbb), rb_pool));
2344 return result;
2347 svn_boolean_t
2348 svn_swig_rb_config_section_enumerator(const char *name,
2349 void *baton,
2350 apr_pool_t *pool)
2352 svn_boolean_t result = FALSE;
2353 VALUE proc, rb_pool;
2355 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2357 if (!NIL_P(proc)) {
2358 callback_baton_t cbb;
2360 cbb.receiver = proc;
2361 cbb.message = id_call;
2362 cbb.args = rb_ary_new3(1, c2r_string2(name));
2363 result = RTEST(invoke_callback((VALUE)(&cbb), rb_pool));
2366 return result;
2369 svn_error_t *
2370 svn_swig_rb_delta_path_driver_cb_func(void **dir_baton,
2371 void *parent_baton,
2372 void *callback_baton,
2373 const char *path,
2374 apr_pool_t *pool)
2376 svn_error_t *err = SVN_NO_ERROR;
2377 VALUE proc, rb_pool;
2379 svn_swig_rb_from_baton((VALUE)callback_baton, &proc, &rb_pool);
2381 if (!NIL_P(proc)) {
2382 callback_baton_t cbb;
2383 VALUE result;
2384 item_baton *ib = (item_baton *)parent_baton;
2386 cbb.receiver = proc;
2387 cbb.message = id_call;
2388 cbb.args = rb_ary_new3(2, ib->baton, c2r_string2(path));
2389 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2390 *dir_baton = make_baton(pool, ib->editor, result);
2393 return err;
2396 svn_error_t *
2397 svn_swig_rb_txdelta_window_handler(svn_txdelta_window_t *window,
2398 void *baton)
2400 svn_error_t *err = SVN_NO_ERROR;
2401 VALUE proc, rb_pool;
2403 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2405 if (!NIL_P(proc)) {
2406 callback_baton_t cbb;
2408 cbb.receiver = proc;
2409 cbb.message = id_call;
2410 cbb.args = rb_ary_new3(1, c2r_txdelta_window__dup(window));
2411 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2414 return err;
2417 void
2418 svn_swig_rb_fs_warning_callback(void *baton, svn_error_t *err)
2420 VALUE proc, rb_pool;
2422 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2424 if (!NIL_P(proc)) {
2425 callback_baton_t cbb;
2427 cbb.receiver = proc;
2428 cbb.message = id_call;
2429 cbb.args = rb_ary_new3(1, svn_swig_rb_svn_error_to_rb_error(err));
2430 invoke_callback((VALUE)(&cbb), rb_pool);
2434 static apr_status_t
2435 cleanup_fs_warning_callback_baton(void *baton)
2437 rb_holder_pop(rb_svn_fs_warning_callback_baton_holder(), (VALUE)baton);
2438 return APR_SUCCESS;
2441 void
2442 svn_swig_rb_fs_warning_callback_baton_register(VALUE baton, apr_pool_t *pool)
2444 rb_holder_push(rb_svn_fs_warning_callback_baton_holder(), (VALUE)baton);
2445 apr_pool_cleanup_register(pool, (void *)baton,
2446 cleanup_fs_warning_callback_baton,
2447 apr_pool_cleanup_null);
2450 svn_error_t *
2451 svn_swig_rb_fs_get_locks_callback(void *baton,
2452 svn_lock_t *lock,
2453 apr_pool_t *pool)
2455 svn_error_t *err = SVN_NO_ERROR;
2456 VALUE proc, rb_pool;
2458 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2460 if (!NIL_P(proc)) {
2461 callback_baton_t cbb;
2463 cbb.receiver = proc;
2464 cbb.message = id_call;
2465 cbb.args = rb_ary_new3(1, c2r_lock__dup(lock));
2466 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2469 return err;
2473 /* svn_ra_callbacks_t */
2474 static svn_error_t *
2475 ra_callbacks_open_tmp_file(apr_file_t **fp,
2476 void *callback_baton,
2477 apr_pool_t *pool)
2479 VALUE callbacks = (VALUE)callback_baton;
2480 svn_error_t *err = SVN_NO_ERROR;
2482 if (!NIL_P(callbacks)) {
2483 callback_baton_t cbb;
2484 VALUE result;
2486 cbb.receiver = callbacks;
2487 cbb.message = id_open_tmp_file;
2488 cbb.args = rb_ary_new3(0);
2490 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
2491 *fp = svn_swig_rb_make_file(result, pool);
2494 return err;
2497 static svn_error_t *
2498 ra_callbacks_get_wc_prop(void *baton,
2499 const char *relpath,
2500 const char *name,
2501 const svn_string_t **value,
2502 apr_pool_t *pool)
2504 VALUE callbacks = (VALUE)baton;
2505 svn_error_t *err = SVN_NO_ERROR;
2507 if (!NIL_P(callbacks)) {
2508 callback_baton_t cbb;
2509 VALUE result;
2511 cbb.receiver = callbacks;
2512 cbb.message = id_get_wc_prop;
2513 cbb.args = rb_ary_new3(2, c2r_string2(relpath), c2r_string2(name));
2514 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
2515 if (NIL_P(result)) {
2516 *value = NULL;
2517 } else {
2518 *value = r2c_svn_string(result, NULL, pool);
2522 return err;
2525 static svn_error_t *
2526 ra_callbacks_set_wc_prop(void *baton,
2527 const char *path,
2528 const char *name,
2529 const svn_string_t *value,
2530 apr_pool_t *pool)
2532 VALUE callbacks = (VALUE)baton;
2533 svn_error_t *err = SVN_NO_ERROR;
2535 if (!NIL_P(callbacks)) {
2536 callback_baton_t cbb;
2538 cbb.receiver = callbacks;
2539 cbb.message = id_set_wc_prop;
2540 cbb.args = rb_ary_new3(3,
2541 c2r_string2(path),
2542 c2r_string2(name),
2543 c2r_svn_string((void *)value, NULL));
2544 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
2547 return err;
2550 static svn_error_t *
2551 ra_callbacks_push_wc_prop(void *baton,
2552 const char *path,
2553 const char *name,
2554 const svn_string_t *value,
2555 apr_pool_t *pool)
2557 VALUE callbacks = (VALUE)baton;
2558 svn_error_t *err = SVN_NO_ERROR;
2560 if (!NIL_P(callbacks)) {
2561 callback_baton_t cbb;
2563 cbb.receiver = callbacks;
2564 cbb.message = id_push_wc_prop;
2565 cbb.args = rb_ary_new3(3,
2566 c2r_string2(path),
2567 c2r_string2(name),
2568 c2r_svn_string((void *)value, NULL));
2569 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
2572 return err;
2575 static svn_error_t *
2576 ra_callbacks_invalidate_wc_props(void *baton,
2577 const char *path,
2578 const char *name,
2579 apr_pool_t *pool)
2581 VALUE callbacks = (VALUE)baton;
2582 svn_error_t *err = SVN_NO_ERROR;
2584 if (!NIL_P(callbacks)) {
2585 callback_baton_t cbb;
2587 cbb.receiver = callbacks;
2588 cbb.message = id_invalidate_wc_props;
2589 cbb.args = rb_ary_new3(2, c2r_string2(path), c2r_string2(name));
2590 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
2593 return err;
2597 static void
2598 ra_callbacks_progress_func(apr_off_t progress,
2599 apr_off_t total,
2600 void *baton,
2601 apr_pool_t *pool)
2603 VALUE callbacks = (VALUE)baton;
2604 if (!NIL_P(callbacks)) {
2605 callback_baton_t cbb;
2607 cbb.receiver = callbacks;
2608 cbb.message = id_progress_func;
2609 cbb.args = rb_ary_new3(2, AOFF2NUM(progress), AOFF2NUM(total));
2610 invoke_callback((VALUE)(&cbb), Qnil);
2614 void
2615 svn_swig_rb_setup_ra_callbacks(svn_ra_callbacks2_t **callbacks,
2616 void **baton,
2617 VALUE rb_callbacks,
2618 apr_pool_t *pool)
2620 void *auth_baton = NULL;
2622 if (!NIL_P(rb_callbacks)) {
2623 VALUE rb_auth_baton = Qnil;
2624 rb_auth_baton = rb_funcall(rb_callbacks, id_auth_baton, 0);
2625 auth_baton = r2c_swig_type(rb_auth_baton,
2626 (void *)"svn_auth_baton_t *",
2627 pool);
2630 *callbacks = apr_pcalloc(pool, sizeof(**callbacks));
2632 (*callbacks)->open_tmp_file = ra_callbacks_open_tmp_file;
2633 (*callbacks)->auth_baton = auth_baton;
2634 (*callbacks)->get_wc_prop = ra_callbacks_get_wc_prop;
2635 (*callbacks)->set_wc_prop = ra_callbacks_set_wc_prop;
2636 (*callbacks)->push_wc_prop = ra_callbacks_push_wc_prop;
2637 (*callbacks)->invalidate_wc_props = ra_callbacks_invalidate_wc_props;
2638 (*callbacks)->progress_func = ra_callbacks_progress_func;
2639 (*callbacks)->progress_baton = (void *)rb_callbacks;
2643 svn_error_t *
2644 svn_swig_rb_ra_lock_callback(void *baton,
2645 const char *path,
2646 svn_boolean_t do_lock,
2647 const svn_lock_t *lock,
2648 svn_error_t *ra_err,
2649 apr_pool_t *pool)
2651 svn_error_t *err = SVN_NO_ERROR;
2652 VALUE proc, rb_pool;
2654 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2656 if (!NIL_P(proc)) {
2657 callback_baton_t cbb;
2659 cbb.receiver = proc;
2660 cbb.message = id_call;
2661 cbb.args = rb_ary_new3(4,
2662 c2r_string2(path),
2663 do_lock ? Qtrue : Qfalse,
2664 c2r_lock__dup(lock),
2665 ra_err ?
2666 svn_swig_rb_svn_error_to_rb_error(ra_err) :
2667 Qnil);
2668 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2671 return err;
2674 svn_error_t *
2675 svn_swig_rb_just_call(void *baton)
2677 svn_error_t *err = SVN_NO_ERROR;
2678 VALUE proc, rb_pool;
2680 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2682 if (!NIL_P(proc)) {
2683 callback_baton_t cbb;
2685 cbb.receiver = proc;
2686 cbb.message = id_call;
2687 cbb.args = rb_ary_new3(0);
2688 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2691 return err;
2694 svn_error_t *
2695 svn_swig_rb_ra_file_rev_handler(void *baton,
2696 const char *path,
2697 svn_revnum_t rev,
2698 apr_hash_t *rev_props,
2699 svn_txdelta_window_handler_t *delta_handler,
2700 void **delta_baton,
2701 apr_array_header_t *prop_diffs,
2702 apr_pool_t *pool)
2704 svn_error_t *err = SVN_NO_ERROR;
2705 VALUE proc, rb_pool;
2707 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2709 if (!NIL_P(proc)) {
2710 callback_baton_t cbb;
2712 cbb.receiver = proc;
2713 cbb.message = id_call;
2714 cbb.args = rb_ary_new3(4,
2715 c2r_string2(path),
2716 c2r_long(&rev, NULL),
2717 svn_swig_rb_apr_hash_to_hash_svn_string(rev_props),
2718 svn_swig_rb_prop_apr_array_to_hash_prop(prop_diffs));
2719 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2722 return err;
2725 svn_error_t *
2726 svn_swig_rb_repos_history_func(void *baton,
2727 const char *path,
2728 svn_revnum_t revision,
2729 apr_pool_t *pool)
2731 svn_error_t *err = SVN_NO_ERROR;
2732 VALUE proc, rb_pool;
2734 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2736 if (!NIL_P(proc)) {
2737 callback_baton_t cbb;
2738 VALUE result = Qnil;
2740 cbb.receiver = proc;
2741 cbb.message = id_call;
2742 cbb.args = rb_ary_new3(2,
2743 c2r_string2(path),
2744 c2r_long(&revision, NULL));
2745 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2747 if (!err && SVN_ERR_P(result)) {
2748 err = r2c_svn_err(result, NULL, NULL);
2752 return err;
2755 svn_error_t *
2756 svn_swig_rb_repos_file_rev_handler(void *baton,
2757 const char *path,
2758 svn_revnum_t rev,
2759 apr_hash_t *rev_props,
2760 svn_txdelta_window_handler_t *delta_handler,
2761 void **delta_baton,
2762 apr_array_header_t *prop_diffs,
2763 apr_pool_t *pool)
2765 svn_error_t *err = SVN_NO_ERROR;
2766 VALUE proc, rb_pool;
2768 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2770 if (!NIL_P(proc)) {
2771 callback_baton_t cbb;
2773 cbb.receiver = proc;
2774 cbb.message = id_call;
2775 cbb.args = rb_ary_new3(4,
2776 c2r_string2(path),
2777 c2r_long(&rev, NULL),
2778 svn_swig_rb_apr_hash_to_hash_svn_string(rev_props),
2779 svn_swig_rb_prop_apr_array_to_hash_prop(prop_diffs));
2780 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2783 return err;
2786 svn_error_t *
2787 svn_swig_rb_wc_relocation_validator3(void *baton,
2788 const char *uuid,
2789 const char *url,
2790 const char *root_url,
2791 apr_pool_t *pool)
2793 svn_error_t *err = SVN_NO_ERROR;
2794 VALUE proc, rb_pool;
2796 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2798 if (!NIL_P(proc)) {
2799 callback_baton_t cbb;
2801 cbb.receiver = proc;
2802 cbb.message = id_call;
2803 cbb.args = rb_ary_new3(3,
2804 c2r_string2(uuid),
2805 c2r_string2(url),
2806 c2r_string2(root_url));
2807 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2810 return err;
2815 /* auth provider callbacks */
2816 svn_error_t *
2817 svn_swig_rb_auth_simple_prompt_func(svn_auth_cred_simple_t **cred,
2818 void *baton,
2819 const char *realm,
2820 const char *username,
2821 svn_boolean_t may_save,
2822 apr_pool_t *pool)
2824 svn_auth_cred_simple_t *new_cred = NULL;
2825 svn_error_t *err = SVN_NO_ERROR;
2826 VALUE proc, rb_pool;
2828 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2830 if (!NIL_P(proc)) {
2831 callback_baton_t cbb;
2832 VALUE result;
2834 cbb.receiver = proc;
2835 cbb.message = id_call;
2836 cbb.args = rb_ary_new3(3,
2837 c2r_string2(realm),
2838 c2r_string2(username),
2839 RTEST(may_save) ? Qtrue : Qfalse);
2840 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2842 if (!NIL_P(result)) {
2843 void *result_cred = NULL;
2844 svn_auth_cred_simple_t *tmp_cred = NULL;
2846 r2c_swig_type2(result, "svn_auth_cred_simple_t *", &result_cred);
2847 tmp_cred = (svn_auth_cred_simple_t *)result_cred;
2848 new_cred = apr_pcalloc(pool, sizeof(*new_cred));
2849 new_cred->username = tmp_cred->username ?
2850 apr_pstrdup(pool, tmp_cred->username) : NULL;
2851 new_cred->password = tmp_cred->password ?
2852 apr_pstrdup(pool, tmp_cred->password) : NULL;
2853 new_cred->may_save = tmp_cred->may_save;
2857 *cred = new_cred;
2858 return err;
2861 svn_error_t *
2862 svn_swig_rb_auth_username_prompt_func(svn_auth_cred_username_t **cred,
2863 void *baton,
2864 const char *realm,
2865 svn_boolean_t may_save,
2866 apr_pool_t *pool)
2868 svn_auth_cred_username_t *new_cred = NULL;
2869 svn_error_t *err = SVN_NO_ERROR;
2870 VALUE proc, rb_pool;
2872 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2874 if (!NIL_P(proc)) {
2875 callback_baton_t cbb;
2876 VALUE result;
2878 cbb.receiver = proc;
2879 cbb.message = id_call;
2880 cbb.args = rb_ary_new3(2,
2881 c2r_string2(realm),
2882 RTEST(may_save) ? Qtrue : Qfalse);
2883 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2885 if (!NIL_P(result)) {
2886 void *result_cred = NULL;
2887 svn_auth_cred_username_t *tmp_cred = NULL;
2889 r2c_swig_type2(result, "svn_auth_cred_username_t *", &result_cred);
2890 tmp_cred = (svn_auth_cred_username_t *)result_cred;
2891 new_cred = apr_pcalloc(pool, sizeof(*new_cred));
2892 new_cred->username = tmp_cred->username ?
2893 apr_pstrdup(pool, tmp_cred->username) : NULL;
2894 new_cred->may_save = tmp_cred->may_save;
2898 *cred = new_cred;
2899 return err;
2902 svn_error_t *
2903 svn_swig_rb_auth_ssl_server_trust_prompt_func(
2904 svn_auth_cred_ssl_server_trust_t **cred,
2905 void *baton,
2906 const char *realm,
2907 apr_uint32_t failures,
2908 const svn_auth_ssl_server_cert_info_t *cert_info,
2909 svn_boolean_t may_save,
2910 apr_pool_t *pool)
2912 svn_auth_cred_ssl_server_trust_t *new_cred = NULL;
2913 svn_error_t *err = SVN_NO_ERROR;
2914 VALUE proc, rb_pool;
2916 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2918 if (!NIL_P(proc)) {
2919 callback_baton_t cbb;
2920 VALUE result;
2922 cbb.receiver = proc;
2923 cbb.message = id_call;
2924 cbb.args = rb_ary_new3(4,
2925 c2r_string2(realm),
2926 UINT2NUM(failures),
2927 c2r_auth_ssl_server_cert_info__dup(cert_info),
2928 RTEST(may_save) ? Qtrue : Qfalse);
2929 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2931 if (!NIL_P(result)) {
2932 void *result_cred;
2933 svn_auth_cred_ssl_server_trust_t *tmp_cred = NULL;
2935 r2c_swig_type2(result, "svn_auth_cred_ssl_server_trust_t *",
2936 &result_cred);
2937 tmp_cred = (svn_auth_cred_ssl_server_trust_t *)result_cred;
2938 new_cred = apr_pcalloc(pool, sizeof(*new_cred));
2939 *new_cred = *tmp_cred;
2943 *cred = new_cred;
2944 return err;
2947 svn_error_t *
2948 svn_swig_rb_auth_ssl_client_cert_prompt_func(
2949 svn_auth_cred_ssl_client_cert_t **cred,
2950 void *baton,
2951 const char *realm,
2952 svn_boolean_t may_save,
2953 apr_pool_t *pool)
2955 svn_auth_cred_ssl_client_cert_t *new_cred = NULL;
2956 svn_error_t *err = SVN_NO_ERROR;
2957 VALUE proc, rb_pool;
2959 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2961 if (!NIL_P(proc)) {
2962 callback_baton_t cbb;
2963 VALUE result;
2965 cbb.receiver = proc;
2966 cbb.message = id_call;
2967 cbb.args = rb_ary_new3(2,
2968 c2r_string2(realm),
2969 RTEST(may_save) ? Qtrue : Qfalse);
2970 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2972 if (!NIL_P(result)) {
2973 void *result_cred = NULL;
2974 svn_auth_cred_ssl_client_cert_t *tmp_cred = NULL;
2976 r2c_swig_type2(result, "svn_auth_cred_ssl_client_cert_t *",
2977 &result_cred);
2978 tmp_cred = (svn_auth_cred_ssl_client_cert_t *)result_cred;
2979 new_cred = apr_pcalloc(pool, sizeof(*new_cred));
2980 new_cred->cert_file = tmp_cred->cert_file ?
2981 apr_pstrdup(pool, tmp_cred->cert_file) : NULL;
2982 new_cred->may_save = tmp_cred->may_save;
2986 *cred = new_cred;
2987 return err;
2990 svn_error_t *
2991 svn_swig_rb_auth_ssl_client_cert_pw_prompt_func(
2992 svn_auth_cred_ssl_client_cert_pw_t **cred,
2993 void *baton,
2994 const char *realm,
2995 svn_boolean_t may_save,
2996 apr_pool_t *pool)
2998 svn_auth_cred_ssl_client_cert_pw_t *new_cred = NULL;
2999 svn_error_t *err = SVN_NO_ERROR;
3000 VALUE proc, rb_pool;
3002 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3004 if (!NIL_P(proc)) {
3005 callback_baton_t cbb;
3006 VALUE result;
3008 cbb.receiver = proc;
3009 cbb.message = id_call;
3010 cbb.args = rb_ary_new3(2,
3011 c2r_string2(realm),
3012 RTEST(may_save) ? Qtrue : Qfalse);
3013 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3015 if (!NIL_P(result)) {
3016 void *result_cred = NULL;
3017 svn_auth_cred_ssl_client_cert_pw_t *tmp_cred = NULL;
3019 r2c_swig_type2(result, "svn_auth_cred_ssl_client_cert_pw_t *",
3020 &result_cred);
3021 tmp_cred = (svn_auth_cred_ssl_client_cert_pw_t *)result_cred;
3022 new_cred = apr_pcalloc(pool, sizeof(*new_cred));
3023 new_cred->password = tmp_cred->password ?
3024 apr_pstrdup(pool, tmp_cred->password) : NULL;
3025 new_cred->may_save = tmp_cred->may_save;
3029 *cred = new_cred;
3030 return err;
3034 apr_file_t *
3035 svn_swig_rb_make_file(VALUE file, apr_pool_t *pool)
3037 apr_file_t *apr_file = NULL;
3039 apr_file_open(&apr_file, StringValuePtr(file),
3040 APR_CREATE | APR_READ | APR_WRITE,
3041 APR_OS_DEFAULT,
3042 pool);
3044 return apr_file;
3048 static svn_error_t *
3049 read_handler_rbio(void *baton, char *buffer, apr_size_t *len)
3051 VALUE result;
3052 VALUE io = (VALUE)baton;
3053 svn_error_t *err = SVN_NO_ERROR;
3055 result = rb_funcall(io, id_read, 1, INT2NUM(*len));
3056 if (NIL_P(result)) {
3057 *len = 0;
3058 } else {
3059 memcpy(buffer, StringValuePtr(result), RSTRING(result)->len);
3060 *len = RSTRING(result)->len;
3063 return err;
3066 static svn_error_t *
3067 write_handler_rbio(void *baton, const char *data, apr_size_t *len)
3069 VALUE io = (VALUE)baton;
3070 svn_error_t *err = SVN_NO_ERROR;
3072 rb_funcall(io, id_write, 1, rb_str_new(data, *len));
3074 return err;
3077 svn_stream_t *
3078 svn_swig_rb_make_stream(VALUE io)
3080 svn_stream_t *stream;
3082 if (RTEST(rb_funcall(rb_svn_core_stream(), id_eqq, 1, io))) {
3083 svn_stream_t **stream_p;
3084 stream_p = &stream;
3085 r2c_swig_type2(io, "svn_stream_t *", (void **)stream_p);
3086 } else {
3087 VALUE rb_pool = rb_pool_new(Qnil);
3088 apr_pool_wrapper_t *pool_wrapper;
3089 apr_pool_wrapper_t **pool_wrapper_p;
3091 rb_set_pool(io, rb_pool);
3092 pool_wrapper_p = &pool_wrapper;
3093 r2c_swig_type2(rb_pool, "apr_pool_wrapper_t *", (void **)pool_wrapper_p);
3094 stream = svn_stream_create((void *)io, pool_wrapper->pool);
3095 svn_stream_set_read(stream, read_handler_rbio);
3096 svn_stream_set_write(stream, write_handler_rbio);
3099 return stream;
3102 VALUE
3103 svn_swig_rb_filename_to_temp_file(const char *file_name)
3105 return rb_funcall(rb_svn_util(), id_filename_to_temp_file,
3106 1, rb_str_new2(file_name));
3109 void
3110 svn_swig_rb_set_revision(svn_opt_revision_t *rev, VALUE value)
3112 switch (TYPE(value)) {
3113 case T_NIL:
3114 rev->kind = svn_opt_revision_unspecified;
3115 break;
3116 case T_FIXNUM:
3117 rev->kind = svn_opt_revision_number;
3118 rev->value.number = NUM2LONG(value);
3119 break;
3120 case T_STRING:
3121 if (RTEST(rb_reg_match(rb_reg_new("^BASE$",
3122 strlen("^BASE$"),
3123 RE_OPTION_IGNORECASE),
3124 value)))
3125 rev->kind = svn_opt_revision_base;
3126 else if (RTEST(rb_reg_match(rb_reg_new("^HEAD$",
3127 strlen("^HEAD$"),
3128 RE_OPTION_IGNORECASE),
3129 value)))
3130 rev->kind = svn_opt_revision_head;
3131 else if (RTEST(rb_reg_match(rb_reg_new("^WORKING$",
3132 strlen("^WORKING$"),
3133 RE_OPTION_IGNORECASE),
3134 value)))
3135 rev->kind = svn_opt_revision_working;
3136 else if (RTEST(rb_reg_match(rb_reg_new("^COMMITTED$",
3137 strlen("^COMMITTED$"),
3138 RE_OPTION_IGNORECASE),
3139 value)))
3140 rev->kind = svn_opt_revision_committed;
3141 else if (RTEST(rb_reg_match(rb_reg_new("^PREV$",
3142 strlen("^PREV$"),
3143 RE_OPTION_IGNORECASE),
3144 value)))
3145 rev->kind = svn_opt_revision_previous;
3146 else
3147 rb_raise(rb_eArgError,
3148 "invalid value: %s",
3149 StringValuePtr(value));
3150 break;
3151 default:
3152 if (rb_obj_is_kind_of(value,
3153 rb_const_get(rb_cObject, rb_intern("Time")))) {
3154 rev->kind = svn_opt_revision_date;
3155 rev->value.date = NUM2LONG(rb_funcall(value, rb_intern("to_i"), 0));
3156 } else {
3157 rb_raise(rb_eArgError,
3158 "invalid type: %s",
3159 rb_class2name(CLASS_OF(value)));
3161 break;
3165 void
3166 svn_swig_rb_adjust_arg_for_client_ctx_and_pool(int *argc, VALUE **argv)
3168 if (*argc > 1) {
3169 VALUE last_arg = (*argv)[*argc - 1];
3170 if (NIL_P(last_arg) || POOL_P(last_arg)) {
3171 *argv += *argc - 2;
3172 *argc = 2;
3173 } else {
3174 if (CONTEXT_P(last_arg)) {
3175 *argv += *argc - 1;
3176 *argc = 1;
3177 } else {
3178 *argv += *argc - 2;
3179 *argc = 2;
3185 void
3186 svn_swig_rb_wc_status_func(void *baton,
3187 const char *path,
3188 svn_wc_status2_t *status)
3190 VALUE proc, rb_pool;
3192 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3194 if (!NIL_P(proc)) {
3195 callback_baton_t cbb;
3197 cbb.receiver = proc;
3198 cbb.message = id_call;
3199 cbb.args = rb_ary_new3(2, c2r_string2(path), c2r_wc_status2__dup(status));
3200 invoke_callback((VALUE)(&cbb), rb_pool);
3204 svn_error_t *
3205 svn_swig_rb_client_blame_receiver_func(void *baton,
3206 apr_int64_t line_no,
3207 svn_revnum_t revision,
3208 const char *author,
3209 const char *date,
3210 const char *line,
3211 apr_pool_t *pool)
3213 svn_error_t *err = SVN_NO_ERROR;
3214 VALUE proc, rb_pool;
3216 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3218 if (!NIL_P(proc)) {
3219 callback_baton_t cbb;
3221 cbb.receiver = proc;
3222 cbb.message = id_call;
3223 cbb.args = rb_ary_new3(5,
3224 AI642NUM(line_no),
3225 INT2NUM(revision),
3226 c2r_string2(author),
3227 c2r_svn_date_string2(date),
3228 c2r_string2(line));
3229 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3232 return err;
3237 /* svn_wc_entry_callbacks2_t */
3238 static svn_error_t *
3239 wc_entry_callbacks2_found_entry(const char *path,
3240 const svn_wc_entry_t *entry,
3241 void *walk_baton,
3242 apr_pool_t *pool)
3244 svn_error_t *err = SVN_NO_ERROR;
3245 VALUE callbacks, rb_pool;
3247 svn_swig_rb_from_baton((VALUE)walk_baton, &callbacks, &rb_pool);;
3249 if (!NIL_P(callbacks)) {
3250 callback_baton_t cbb;
3252 cbb.receiver = callbacks;
3253 cbb.message = id_found_entry;
3254 cbb.args = rb_ary_new3(2,
3255 c2r_string2(path),
3256 c2r_wc_entry__dup(entry));
3257 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3260 return err;
3263 static svn_error_t *
3264 wc_entry_callbacks2_handle_error(const char *path,
3265 svn_error_t *err,
3266 void *walk_baton,
3267 apr_pool_t *pool)
3269 VALUE callbacks, rb_pool;
3271 svn_swig_rb_from_baton((VALUE)walk_baton, &callbacks, &rb_pool);;
3273 if (!NIL_P(callbacks)) {
3274 callback_baton_t cbb;
3275 ID message;
3277 message = id_handle_error;
3278 if (rb_obj_respond_to(callbacks, message, FALSE)) {
3279 VALUE rb_err;
3281 cbb.receiver = callbacks;
3282 cbb.message = id_handle_error;
3283 rb_err = err ? svn_swig_rb_svn_error_to_rb_error(err) : Qnil;
3284 if (err)
3285 svn_error_clear(err);
3286 err = NULL;
3287 cbb.args = rb_ary_new3(2, c2r_string2(path), rb_err);
3288 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3292 return err;
3295 svn_wc_entry_callbacks2_t *
3296 svn_swig_rb_wc_entry_callbacks2(void)
3298 static svn_wc_entry_callbacks2_t wc_entry_callbacks = {
3299 wc_entry_callbacks2_found_entry,
3300 wc_entry_callbacks2_handle_error,
3303 return &wc_entry_callbacks;
3308 /* svn_wc_diff_callbacks2_t */
3309 static svn_error_t *
3310 wc_diff_callbacks_file_changed(svn_wc_adm_access_t *adm_access,
3311 svn_wc_notify_state_t *contentstate,
3312 svn_wc_notify_state_t *propstate,
3313 const char *path,
3314 const char *tmpfile1,
3315 const char *tmpfile2,
3316 svn_revnum_t rev1,
3317 svn_revnum_t rev2,
3318 const char *mimetype1,
3319 const char *mimetype2,
3320 const apr_array_header_t *propchanges,
3321 apr_hash_t *originalprops,
3322 void *diff_baton)
3324 VALUE callbacks, rb_pool;
3325 svn_error_t *err = SVN_NO_ERROR;
3327 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3328 if (!NIL_P(callbacks)) {
3329 callback_baton_t cbb;
3330 VALUE result = Qnil;
3332 cbb.receiver = callbacks;
3333 cbb.message = id_file_changed;
3334 cbb.args = rb_ary_new3(10,
3335 c2r_swig_type((void *)adm_access,
3336 (void *)"svn_wc_adm_access_t *"),
3337 c2r_string2(path),
3338 c2r_string2(tmpfile1),
3339 c2r_string2(tmpfile2),
3340 INT2NUM(rev1),
3341 INT2NUM(rev2),
3342 c2r_string2(mimetype1),
3343 c2r_string2(mimetype2),
3344 svn_swig_rb_prop_apr_array_to_hash_prop(propchanges),
3345 svn_swig_rb_prop_hash_to_hash(originalprops));
3346 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3348 if (contentstate)
3349 *contentstate = NUM2INT(rb_ary_entry(result, 0));
3350 if (propstate)
3351 *propstate = NUM2INT(rb_ary_entry(result, 1));
3354 return err;
3357 static svn_error_t *
3358 wc_diff_callbacks_file_added(svn_wc_adm_access_t *adm_access,
3359 svn_wc_notify_state_t *contentstate,
3360 svn_wc_notify_state_t *propstate,
3361 const char *path,
3362 const char *tmpfile1,
3363 const char *tmpfile2,
3364 svn_revnum_t rev1,
3365 svn_revnum_t rev2,
3366 const char *mimetype1,
3367 const char *mimetype2,
3368 const apr_array_header_t *propchanges,
3369 apr_hash_t *originalprops,
3370 void *diff_baton)
3372 VALUE callbacks, rb_pool;
3373 svn_error_t *err = SVN_NO_ERROR;
3375 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3376 if (!NIL_P(callbacks)) {
3377 callback_baton_t cbb;
3378 VALUE result = Qnil;
3380 cbb.receiver = callbacks;
3381 cbb.message = id_file_added;
3382 cbb.args = rb_ary_new3(10,
3383 c2r_swig_type((void *)adm_access,
3384 (void *)"svn_wc_adm_access_t *"),
3385 c2r_string2(path),
3386 c2r_string2(tmpfile1),
3387 c2r_string2(tmpfile2),
3388 INT2NUM(rev1),
3389 INT2NUM(rev2),
3390 c2r_string2(mimetype1),
3391 c2r_string2(mimetype2),
3392 svn_swig_rb_prop_apr_array_to_hash_prop(propchanges),
3393 svn_swig_rb_prop_hash_to_hash(originalprops));
3394 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3396 if (contentstate)
3397 *contentstate = NUM2INT(rb_ary_entry(result, 0));
3398 if (propstate)
3399 *propstate = NUM2INT(rb_ary_entry(result, 1));
3402 return err;
3405 static svn_error_t *
3406 wc_diff_callbacks_file_deleted(svn_wc_adm_access_t *adm_access,
3407 svn_wc_notify_state_t *state,
3408 const char *path,
3409 const char *tmpfile1,
3410 const char *tmpfile2,
3411 const char *mimetype1,
3412 const char *mimetype2,
3413 apr_hash_t *originalprops,
3414 void *diff_baton)
3416 VALUE callbacks, rb_pool;
3417 svn_error_t *err = SVN_NO_ERROR;
3419 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3420 if (!NIL_P(callbacks)) {
3421 callback_baton_t cbb;
3422 VALUE result = Qnil;
3424 cbb.receiver = callbacks;
3425 cbb.message = id_file_deleted;
3426 cbb.args = rb_ary_new3(7,
3427 c2r_swig_type((void *)adm_access,
3428 (void *)"svn_wc_adm_access_t *"),
3429 c2r_string2(path),
3430 c2r_string2(tmpfile1),
3431 c2r_string2(tmpfile2),
3432 c2r_string2(mimetype1),
3433 c2r_string2(mimetype2),
3434 svn_swig_rb_prop_hash_to_hash(originalprops));
3435 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3436 if (state)
3437 *state = NUM2INT(result);
3440 return err;
3443 static svn_error_t *
3444 wc_diff_callbacks_dir_added(svn_wc_adm_access_t *adm_access,
3445 svn_wc_notify_state_t *state,
3446 const char *path,
3447 svn_revnum_t rev,
3448 void *diff_baton)
3450 VALUE callbacks, rb_pool;
3451 svn_error_t *err = SVN_NO_ERROR;
3453 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3454 if (!NIL_P(callbacks)) {
3455 callback_baton_t cbb;
3456 VALUE result = Qnil;
3458 cbb.receiver = callbacks;
3459 cbb.message = id_dir_added;
3460 cbb.args = rb_ary_new3(3,
3461 c2r_swig_type((void *)adm_access,
3462 (void *)"svn_wc_adm_access_t *"),
3463 c2r_string2(path),
3464 INT2NUM(rev));
3465 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3466 if (state)
3467 *state = NUM2INT(result);
3470 return err;
3473 static svn_error_t *
3474 wc_diff_callbacks_dir_deleted(svn_wc_adm_access_t *adm_access,
3475 svn_wc_notify_state_t *state,
3476 const char *path,
3477 void *diff_baton)
3479 VALUE callbacks, rb_pool;
3480 svn_error_t *err = SVN_NO_ERROR;
3482 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3483 if (!NIL_P(callbacks)) {
3484 callback_baton_t cbb;
3485 VALUE result = Qnil;
3487 cbb.receiver = callbacks;
3488 cbb.message = id_dir_deleted;
3489 cbb.args = rb_ary_new3(2,
3490 c2r_swig_type((void *)adm_access,
3491 (void *)"svn_wc_adm_access_t *"),
3492 c2r_string2(path));
3493 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3494 if (state)
3495 *state = NUM2INT(result);
3498 return err;
3501 static svn_error_t *
3502 wc_diff_callbacks_dir_props_changed(svn_wc_adm_access_t *adm_access,
3503 svn_wc_notify_state_t *state,
3504 const char *path,
3505 const apr_array_header_t *propchanges,
3506 apr_hash_t *originalprops,
3507 void *diff_baton)
3509 VALUE callbacks, rb_pool;
3510 svn_error_t *err = SVN_NO_ERROR;
3512 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3513 if (!NIL_P(callbacks)) {
3514 callback_baton_t cbb;
3515 VALUE result = Qnil;
3517 cbb.receiver = callbacks;
3518 cbb.message = id_dir_props_changed;
3519 cbb.args = rb_ary_new3(4,
3520 c2r_swig_type((void *)adm_access,
3521 (void *)"svn_wc_adm_access_t *"),
3522 c2r_string2(path),
3523 svn_swig_rb_prop_apr_array_to_hash_prop(propchanges),
3524 svn_swig_rb_prop_hash_to_hash(originalprops));
3525 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3527 if (state)
3528 *state = NUM2INT(result);
3531 return err;
3534 svn_wc_diff_callbacks2_t *
3535 svn_swig_rb_wc_diff_callbacks2(void)
3537 static svn_wc_diff_callbacks2_t wc_diff_callbacks2 = {
3538 wc_diff_callbacks_file_changed,
3539 wc_diff_callbacks_file_added,
3540 wc_diff_callbacks_file_deleted,
3541 wc_diff_callbacks_dir_added,
3542 wc_diff_callbacks_dir_deleted,
3543 wc_diff_callbacks_dir_props_changed
3546 return &wc_diff_callbacks2;
3550 VALUE
3551 svn_swig_rb_make_txdelta_window_handler_wrapper(VALUE *rb_handler_pool,
3552 apr_pool_t **handler_pool,
3553 svn_txdelta_window_handler_t **handler,
3554 void ***handler_baton)
3556 VALUE obj;
3558 obj = rb_class_new_instance(0, NULL, rb_cObject);
3559 svn_swig_rb_get_pool(0, NULL, obj, rb_handler_pool, handler_pool);
3560 svn_swig_rb_set_pool_for_no_swig_type(obj, *rb_handler_pool);
3561 *handler = apr_palloc(*handler_pool, sizeof(svn_txdelta_window_handler_t));
3562 *handler_baton = apr_palloc(*handler_pool, sizeof(void *));
3564 return obj;
3567 VALUE
3568 svn_swig_rb_setup_txdelta_window_handler_wrapper(VALUE obj,
3569 svn_txdelta_window_handler_t handler,
3570 void *handler_baton)
3572 rb_ivar_set(obj, id_handler,
3573 c2r_swig_type((void *)handler,
3574 (void *)"svn_txdelta_window_handler_t"));
3575 rb_ivar_set(obj, id_handler_baton,
3576 c2r_swig_type(handler_baton, (void *)"void *"));
3577 return obj;
3580 svn_error_t *
3581 svn_swig_rb_invoke_txdelta_window_handler_wrapper(VALUE obj,
3582 svn_txdelta_window_t *window,
3583 apr_pool_t *pool)
3585 svn_txdelta_window_handler_t handler;
3586 svn_txdelta_window_handler_t *handler_p;
3587 void *handler_baton;
3589 handler_p = &handler;
3590 r2c_swig_type2(rb_ivar_get(obj, id_handler),
3591 "svn_txdelta_window_handler_t", (void **)handler_p);
3592 r2c_swig_type2(rb_ivar_get(obj, id_handler_baton),
3593 "void *", &handler_baton);
3595 return handler(window, handler_baton);
3599 VALUE
3600 svn_swig_rb_txdelta_window_t_ops_get(svn_txdelta_window_t *window)
3602 VALUE ops;
3603 const svn_txdelta_op_t *op;
3604 int i;
3606 ops = rb_ary_new2(window->num_ops);
3608 for (i = 0; i < window->num_ops; i++) {
3609 op = window->ops + i;
3610 rb_ary_push(ops, c2r_swig_type((void *)op, (void *)"svn_txdelta_op_t *"));
3613 return ops;
3617 svn_error_t *
3618 svn_swig_rb_client_diff_summarize_func(const svn_client_diff_summarize_t *diff,
3619 void *baton,
3620 apr_pool_t *pool)
3622 svn_error_t *err = SVN_NO_ERROR;
3623 VALUE proc, rb_pool;
3625 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3627 if (!NIL_P(proc)) {
3628 callback_baton_t cbb;
3630 cbb.receiver = proc;
3631 cbb.message = id_call;
3632 cbb.args = rb_ary_new3(1, c2r_client_diff_summarize__dup(diff));
3633 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3636 return err;
3639 svn_error_t *
3640 svn_swig_rb_client_list_func(void *baton,
3641 const char *path,
3642 const svn_dirent_t *dirent,
3643 const svn_lock_t *lock,
3644 const char *abs_path,
3645 apr_pool_t *pool)
3647 svn_error_t *err = SVN_NO_ERROR;
3648 VALUE proc, rb_pool;
3650 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3652 if (!NIL_P(proc)) {
3653 callback_baton_t cbb;
3655 cbb.receiver = proc;
3656 cbb.message = id_call;
3657 cbb.args = rb_ary_new3(4,
3658 c2r_string2(path),
3659 c2r_dirent__dup(dirent),
3660 c2r_lock__dup(lock),
3661 c2r_string2(abs_path));
3662 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3665 return err;
3668 svn_error_t *
3669 svn_swig_rb_proplist_receiver(void *baton,
3670 const char *path,
3671 apr_hash_t *prop_hash,
3672 apr_pool_t *pool)
3674 svn_error_t *err = SVN_NO_ERROR;
3675 VALUE proc, rb_pool;
3677 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3678 if (!NIL_P(proc)) {
3679 callback_baton_t cbb;
3681 cbb.receiver = proc;
3682 cbb.message = id_call;
3683 cbb.args = rb_ary_new3(2,
3684 c2r_string2(path),
3685 svn_swig_rb_prop_hash_to_hash(prop_hash));
3686 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3689 return err;
3692 svn_error_t *
3693 svn_swig_rb_changelist_receiver(void *baton,
3694 const char *path,
3695 const char *changelist,
3696 apr_pool_t *pool)
3698 svn_error_t *err = SVN_NO_ERROR;
3699 VALUE proc, rb_pool;
3701 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3702 if (!NIL_P(proc)) {
3703 callback_baton_t cbb;
3705 cbb.receiver = proc;
3706 cbb.message = id_call;
3707 cbb.args = rb_ary_new3(2,
3708 c2r_string2(path),
3709 c2r_string2(changelist));
3710 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3713 return err;
3717 /* svn_ra_reporter3_t */
3718 static void
3719 c2r_ra_reporter3(VALUE rb_reporter, svn_ra_reporter3_t **reporter, void **baton,
3720 apr_pool_t *pool)
3722 VALUE rb_baton;
3724 r2c_swig_type2(rb_reporter, "svn_ra_reporter3_t *", (void **)reporter);
3726 rb_baton = rb_funcall(rb_reporter, id_baton, 0);
3727 r2c_swig_type2(rb_baton, "void *", baton);
3730 static svn_error_t *
3731 svn_swig_rb_ra_reporter_set_path(void *report_baton, const char *path,
3732 svn_revnum_t revision, svn_depth_t depth,
3733 svn_boolean_t start_empty,
3734 const char *lock_token, apr_pool_t *pool)
3736 svn_error_t *err = SVN_NO_ERROR;
3737 VALUE reporter, rb_pool;
3739 svn_swig_rb_from_baton((VALUE)report_baton, &reporter, &rb_pool);
3740 if (rb_obj_is_kind_of(reporter, rb_svn_ra_reporter3())) {
3741 svn_ra_reporter3_t *svn_reporter;
3742 void *baton;
3744 c2r_ra_reporter3(reporter, &svn_reporter, &baton, pool);
3745 err = svn_reporter->set_path(baton, path, revision, depth,
3746 start_empty, lock_token, pool);
3747 } else if (!NIL_P(reporter)) {
3748 callback_baton_t cbb;
3750 cbb.receiver = reporter;
3751 cbb.message = id_set_path;
3752 cbb.args = rb_ary_new3(4,
3753 c2r_string2(path),
3754 INT2NUM(revision),
3755 INT2NUM(depth),
3756 c2r_bool2(start_empty));
3757 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3760 return err;
3763 static svn_error_t *
3764 svn_swig_rb_ra_reporter_delete_path(void *report_baton, const char *path,
3765 apr_pool_t *pool)
3767 svn_error_t *err = SVN_NO_ERROR;
3768 VALUE reporter, rb_pool;
3770 svn_swig_rb_from_baton((VALUE)report_baton, &reporter, &rb_pool);
3771 if (rb_obj_is_kind_of(reporter, rb_svn_ra_reporter3())) {
3772 svn_ra_reporter3_t *svn_reporter;
3773 void *baton;
3775 c2r_ra_reporter3(reporter, &svn_reporter, &baton, pool);
3776 err = svn_reporter->delete_path(baton, path, pool);
3777 } else if (!NIL_P(reporter)) {
3778 callback_baton_t cbb;
3780 cbb.receiver = reporter;
3781 cbb.message = id_delete_path;
3782 cbb.args = rb_ary_new3(1,
3783 c2r_string2(path));
3784 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3787 return err;
3790 static svn_error_t *
3791 svn_swig_rb_ra_reporter_link_path(void *report_baton, const char *path,
3792 const char *url, svn_revnum_t revision,
3793 svn_depth_t depth, svn_boolean_t start_empty,
3794 const char *lock_token, apr_pool_t *pool)
3796 svn_error_t *err = SVN_NO_ERROR;
3797 VALUE reporter, rb_pool;
3799 svn_swig_rb_from_baton((VALUE)report_baton, &reporter, &rb_pool);
3800 if (rb_obj_is_kind_of(reporter, rb_svn_ra_reporter3())) {
3801 svn_ra_reporter3_t *svn_reporter;
3802 void *baton;
3804 c2r_ra_reporter3(reporter, &svn_reporter, &baton, pool);
3805 err = svn_reporter->link_path(baton, path, url, revision, depth,
3806 start_empty, lock_token, pool);
3807 } else if (!NIL_P(reporter)) {
3808 callback_baton_t cbb;
3810 cbb.receiver = reporter;
3811 cbb.message = id_link_path;
3812 cbb.args = rb_ary_new3(5,
3813 c2r_string2(path),
3814 c2r_string2(url),
3815 INT2NUM(revision),
3816 INT2NUM(depth),
3817 c2r_bool2(start_empty));
3818 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3821 return err;
3824 static svn_error_t *
3825 svn_swig_rb_ra_reporter_finish_report(void *report_baton, apr_pool_t *pool)
3827 svn_error_t *err = SVN_NO_ERROR;
3828 VALUE reporter, rb_pool;
3830 svn_swig_rb_from_baton((VALUE)report_baton, &reporter, &rb_pool);
3831 if (rb_obj_is_kind_of(reporter, rb_svn_ra_reporter3())) {
3832 svn_ra_reporter3_t *svn_reporter;
3833 void *baton;
3835 c2r_ra_reporter3(reporter, &svn_reporter, &baton, pool);
3836 err = svn_reporter->finish_report(baton, pool);
3837 } else if (!NIL_P(reporter)) {
3838 callback_baton_t cbb;
3840 cbb.receiver = reporter;
3841 cbb.message = id_finish_report;
3842 cbb.args = rb_ary_new();
3843 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3846 return err;
3849 static svn_error_t *
3850 svn_swig_rb_ra_reporter_abort_report(void *report_baton, apr_pool_t *pool)
3852 svn_error_t *err = SVN_NO_ERROR;
3853 VALUE reporter, rb_pool;
3855 svn_swig_rb_from_baton((VALUE)report_baton, &reporter, &rb_pool);
3856 if (rb_obj_is_kind_of(reporter, rb_svn_ra_reporter3())) {
3857 svn_ra_reporter3_t *svn_reporter;
3858 void *baton;
3860 c2r_ra_reporter3(reporter, &svn_reporter, &baton, pool);
3861 err = svn_reporter->abort_report(baton, pool);
3862 } else if (!NIL_P(reporter)) {
3863 callback_baton_t cbb;
3865 cbb.receiver = reporter;
3866 cbb.message = id_abort_report;
3867 cbb.args = rb_ary_new();
3868 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3871 return err;
3874 static svn_ra_reporter3_t rb_ra_reporter3 = {
3875 svn_swig_rb_ra_reporter_set_path,
3876 svn_swig_rb_ra_reporter_delete_path,
3877 svn_swig_rb_ra_reporter_link_path,
3878 svn_swig_rb_ra_reporter_finish_report,
3879 svn_swig_rb_ra_reporter_abort_report
3882 svn_ra_reporter3_t *svn_swig_rb_ra_reporter3 = &rb_ra_reporter3;