Fix compiler warning due to missing function prototype.
[svn.git] / subversion / bindings / swig / ruby / libsvn_swig_ruby / swigutil_rb.c
blob8abbb09dac42cccea9d680e3690f0fa44968a238
1 /* -*- c-file-style: "ruby" -*- */
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;
2059 svn_error_t *
2060 svn_swig_rb_log_entry_receiver(void *baton,
2061 svn_log_entry_t *entry,
2062 apr_pool_t *pool)
2064 svn_error_t *err = SVN_NO_ERROR;
2065 VALUE proc, rb_pool;
2067 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2069 if (!NIL_P(proc)) {
2070 callback_baton_t cbb;
2072 cbb.receiver = proc;
2073 cbb.message = id_call;
2074 cbb.args = rb_ary_new3(1,
2075 c2r_swig_type((void *)entry,
2076 (void *)"svn_log_entry_t *"));
2077 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2079 return err;
2083 svn_error_t *
2084 svn_swig_rb_repos_authz_func(svn_boolean_t *allowed,
2085 svn_fs_root_t *root,
2086 const char *path,
2087 void *baton,
2088 apr_pool_t *pool)
2090 svn_error_t *err = SVN_NO_ERROR;
2091 VALUE proc, rb_pool;
2093 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2095 *allowed = TRUE;
2097 if (!NIL_P(proc)) {
2098 callback_baton_t cbb;
2099 VALUE result;
2101 cbb.receiver = proc;
2102 cbb.message = id_call;
2103 cbb.args = rb_ary_new3(2,
2104 c2r_swig_type((void *)root,
2105 (void *)"svn_fs_root_t *"),
2106 c2r_string2(path));
2107 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2109 *allowed = RTEST(result);
2111 return err;
2114 svn_error_t *
2115 svn_swig_rb_repos_authz_callback(svn_repos_authz_access_t required,
2116 svn_boolean_t *allowed,
2117 svn_fs_root_t *root,
2118 const char *path,
2119 void *baton,
2120 apr_pool_t *pool)
2122 svn_error_t *err = SVN_NO_ERROR;
2123 VALUE proc, rb_pool;
2125 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2127 *allowed = TRUE;
2129 if (!NIL_P(proc)) {
2130 callback_baton_t cbb;
2131 VALUE result;
2133 cbb.receiver = proc;
2134 cbb.message = id_call;
2135 cbb.args = rb_ary_new3(3,
2136 INT2NUM(required),
2137 c2r_swig_type((void *)root,
2138 (void *)"svn_fs_root_t *"),
2139 c2r_string2(path));
2140 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2142 *allowed = RTEST(result);
2144 return err;
2147 svn_error_t *
2148 svn_swig_rb_get_commit_log_func(const char **log_msg,
2149 const char **tmp_file,
2150 const apr_array_header_t *commit_items,
2151 void *baton,
2152 apr_pool_t *pool)
2154 svn_error_t *err = SVN_NO_ERROR;
2155 VALUE proc, rb_pool;
2157 *log_msg = NULL;
2158 *tmp_file = NULL;
2160 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2162 if (!NIL_P(proc)) {
2163 callback_baton_t cbb;
2164 VALUE result;
2165 VALUE is_message;
2166 VALUE value;
2167 char *ret;
2169 cbb.receiver = proc;
2170 cbb.message = id_call;
2171 cbb.args = rb_ary_new3(1, c2r_commit_item3_array(commit_items));
2172 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2174 if (!err) {
2175 char error_message[] =
2176 "log_msg_func should return an array not '%s': "
2177 "[TRUE_IF_IT_IS_MESSAGE, MESSAGE_OR_FILE_AS_STRING]";
2179 if (!RTEST(rb_obj_is_kind_of(result, rb_cArray)))
2180 rb_raise(rb_eTypeError, error_message, r2c_inspect(result));
2181 is_message = rb_ary_entry(result, 0);
2182 value = rb_ary_entry(result, 1);
2184 if (!RTEST(rb_obj_is_kind_of(value, rb_cString)))
2185 rb_raise(rb_eTypeError, error_message, r2c_inspect(result));
2186 ret = (char *)r2c_string(value, NULL, pool);
2187 if (RTEST(is_message)) {
2188 *log_msg = ret;
2189 } else {
2190 *tmp_file = ret;
2194 return err;
2198 void
2199 svn_swig_rb_notify_func2(void *baton,
2200 const svn_wc_notify_t *notify,
2201 apr_pool_t *pool)
2203 VALUE proc, rb_pool;
2204 callback_baton_t cbb;
2206 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2208 if (!NIL_P(proc)) {
2209 cbb.receiver = proc;
2210 cbb.message = id_call;
2211 cbb.args = rb_ary_new3(1, c2r_wc_notify__dup(notify));
2214 if (!NIL_P(proc))
2215 invoke_callback((VALUE)(&cbb), rb_pool);
2218 svn_error_t *
2219 svn_swig_rb_conflict_resolver_func
2220 (svn_wc_conflict_result_t **result,
2221 const svn_wc_conflict_description_t *description,
2222 void *baton,
2223 apr_pool_t *pool)
2225 svn_error_t *err = SVN_NO_ERROR;
2226 VALUE proc, rb_pool;
2228 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2230 if (NIL_P(proc)) {
2231 *result = svn_wc_create_conflict_result(svn_wc_conflict_choose_postpone,
2232 description->merged_file,
2233 pool);
2234 } else {
2235 callback_baton_t cbb;
2236 VALUE fret;
2238 cbb.receiver = proc;
2239 cbb.message = id_call;
2240 cbb.args = rb_ary_new3(
2242 c2r_swig_type((void *)description,
2243 (void *)"svn_wc_conflict_description_t *") );
2244 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2245 fret = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2246 *result = svn_wc_create_conflict_result(NUM2INT(fret),
2247 description->merged_file,
2248 pool);
2251 return err;
2254 svn_error_t *
2255 svn_swig_rb_commit_callback(svn_revnum_t new_revision,
2256 const char *date,
2257 const char *author,
2258 void *baton)
2260 svn_error_t *err = SVN_NO_ERROR;
2261 VALUE proc, rb_pool;
2263 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2265 if (!NIL_P(proc)) {
2266 callback_baton_t cbb;
2268 cbb.receiver = proc;
2269 cbb.message = id_call;
2270 cbb.args = rb_ary_new3(3,
2271 INT2NUM(new_revision),
2272 c2r_svn_date_string2(date),
2273 c2r_string2(author));
2274 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2277 return err;
2280 svn_error_t *
2281 svn_swig_rb_commit_callback2(const svn_commit_info_t *commit_info,
2282 void *baton, apr_pool_t *pool)
2284 svn_error_t *err = SVN_NO_ERROR;
2285 VALUE proc, rb_pool;
2287 svn_swig_rb_from_baton((VALUE)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(1, c2r_commit_info__dup(commit_info));
2295 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2298 return err;
2301 svn_error_t *
2302 svn_swig_rb_cancel_func(void *cancel_baton)
2304 svn_error_t *err = SVN_NO_ERROR;
2305 VALUE proc, rb_pool;
2307 svn_swig_rb_from_baton((VALUE)cancel_baton, &proc, &rb_pool);
2309 if (!NIL_P(proc)) {
2310 callback_baton_t cbb;
2312 cbb.receiver = proc;
2313 cbb.message = id_call;
2314 cbb.args = rb_ary_new3(0);
2315 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2318 return err;
2321 svn_error_t *
2322 svn_swig_rb_info_receiver(void *baton,
2323 const char *path,
2324 const svn_info_t *info,
2325 apr_pool_t *pool)
2327 svn_error_t *err = SVN_NO_ERROR;
2328 VALUE proc, rb_pool;
2330 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2332 if (!NIL_P(proc)) {
2333 callback_baton_t cbb;
2335 cbb.receiver = proc;
2336 cbb.message = id_call;
2337 cbb.args = rb_ary_new3(2, c2r_string2(path), c2r_info__dup(info));
2338 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2341 return err;
2344 svn_boolean_t
2345 svn_swig_rb_config_enumerator(const char *name,
2346 const char *value,
2347 void *baton,
2348 apr_pool_t *pool)
2350 svn_boolean_t result = FALSE;
2351 VALUE proc, rb_pool;
2353 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2355 if (!NIL_P(proc)) {
2356 callback_baton_t cbb;
2358 cbb.receiver = proc;
2359 cbb.message = id_call;
2360 cbb.args = rb_ary_new3(2, c2r_string2(name), c2r_string2(value));
2361 result = RTEST(invoke_callback((VALUE)(&cbb), rb_pool));
2364 return result;
2367 svn_boolean_t
2368 svn_swig_rb_config_section_enumerator(const char *name,
2369 void *baton,
2370 apr_pool_t *pool)
2372 svn_boolean_t result = FALSE;
2373 VALUE proc, rb_pool;
2375 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2377 if (!NIL_P(proc)) {
2378 callback_baton_t cbb;
2380 cbb.receiver = proc;
2381 cbb.message = id_call;
2382 cbb.args = rb_ary_new3(1, c2r_string2(name));
2383 result = RTEST(invoke_callback((VALUE)(&cbb), rb_pool));
2386 return result;
2389 svn_error_t *
2390 svn_swig_rb_delta_path_driver_cb_func(void **dir_baton,
2391 void *parent_baton,
2392 void *callback_baton,
2393 const char *path,
2394 apr_pool_t *pool)
2396 svn_error_t *err = SVN_NO_ERROR;
2397 VALUE proc, rb_pool;
2399 svn_swig_rb_from_baton((VALUE)callback_baton, &proc, &rb_pool);
2401 if (!NIL_P(proc)) {
2402 callback_baton_t cbb;
2403 VALUE result;
2404 item_baton *ib = (item_baton *)parent_baton;
2406 cbb.receiver = proc;
2407 cbb.message = id_call;
2408 cbb.args = rb_ary_new3(2, ib->baton, c2r_string2(path));
2409 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2410 *dir_baton = make_baton(pool, ib->editor, result);
2413 return err;
2416 svn_error_t *
2417 svn_swig_rb_txdelta_window_handler(svn_txdelta_window_t *window,
2418 void *baton)
2420 svn_error_t *err = SVN_NO_ERROR;
2421 VALUE proc, rb_pool;
2423 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2425 if (!NIL_P(proc)) {
2426 callback_baton_t cbb;
2428 cbb.receiver = proc;
2429 cbb.message = id_call;
2430 cbb.args = rb_ary_new3(1, c2r_txdelta_window__dup(window));
2431 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2434 return err;
2437 void
2438 svn_swig_rb_fs_warning_callback(void *baton, svn_error_t *err)
2440 VALUE proc, rb_pool;
2442 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2444 if (!NIL_P(proc)) {
2445 callback_baton_t cbb;
2447 cbb.receiver = proc;
2448 cbb.message = id_call;
2449 cbb.args = rb_ary_new3(1, svn_swig_rb_svn_error_to_rb_error(err));
2450 invoke_callback((VALUE)(&cbb), rb_pool);
2454 static apr_status_t
2455 cleanup_fs_warning_callback_baton(void *baton)
2457 rb_holder_pop(rb_svn_fs_warning_callback_baton_holder(), (VALUE)baton);
2458 return APR_SUCCESS;
2461 void
2462 svn_swig_rb_fs_warning_callback_baton_register(VALUE baton, apr_pool_t *pool)
2464 rb_holder_push(rb_svn_fs_warning_callback_baton_holder(), (VALUE)baton);
2465 apr_pool_cleanup_register(pool, (void *)baton,
2466 cleanup_fs_warning_callback_baton,
2467 apr_pool_cleanup_null);
2470 svn_error_t *
2471 svn_swig_rb_fs_get_locks_callback(void *baton,
2472 svn_lock_t *lock,
2473 apr_pool_t *pool)
2475 svn_error_t *err = SVN_NO_ERROR;
2476 VALUE proc, rb_pool;
2478 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2480 if (!NIL_P(proc)) {
2481 callback_baton_t cbb;
2483 cbb.receiver = proc;
2484 cbb.message = id_call;
2485 cbb.args = rb_ary_new3(1, c2r_lock__dup(lock));
2486 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2489 return err;
2493 /* svn_ra_callbacks_t */
2494 static svn_error_t *
2495 ra_callbacks_open_tmp_file(apr_file_t **fp,
2496 void *callback_baton,
2497 apr_pool_t *pool)
2499 VALUE callbacks = (VALUE)callback_baton;
2500 svn_error_t *err = SVN_NO_ERROR;
2502 if (!NIL_P(callbacks)) {
2503 callback_baton_t cbb;
2504 VALUE result;
2506 cbb.receiver = callbacks;
2507 cbb.message = id_open_tmp_file;
2508 cbb.args = rb_ary_new3(0);
2510 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
2511 *fp = svn_swig_rb_make_file(result, pool);
2514 return err;
2517 static svn_error_t *
2518 ra_callbacks_get_wc_prop(void *baton,
2519 const char *relpath,
2520 const char *name,
2521 const svn_string_t **value,
2522 apr_pool_t *pool)
2524 VALUE callbacks = (VALUE)baton;
2525 svn_error_t *err = SVN_NO_ERROR;
2527 if (!NIL_P(callbacks)) {
2528 callback_baton_t cbb;
2529 VALUE result;
2531 cbb.receiver = callbacks;
2532 cbb.message = id_get_wc_prop;
2533 cbb.args = rb_ary_new3(2, c2r_string2(relpath), c2r_string2(name));
2534 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
2535 if (NIL_P(result)) {
2536 *value = NULL;
2537 } else {
2538 *value = r2c_svn_string(result, NULL, pool);
2542 return err;
2545 static svn_error_t *
2546 ra_callbacks_set_wc_prop(void *baton,
2547 const char *path,
2548 const char *name,
2549 const svn_string_t *value,
2550 apr_pool_t *pool)
2552 VALUE callbacks = (VALUE)baton;
2553 svn_error_t *err = SVN_NO_ERROR;
2555 if (!NIL_P(callbacks)) {
2556 callback_baton_t cbb;
2558 cbb.receiver = callbacks;
2559 cbb.message = id_set_wc_prop;
2560 cbb.args = rb_ary_new3(3,
2561 c2r_string2(path),
2562 c2r_string2(name),
2563 c2r_svn_string((void *)value, NULL));
2564 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
2567 return err;
2570 static svn_error_t *
2571 ra_callbacks_push_wc_prop(void *baton,
2572 const char *path,
2573 const char *name,
2574 const svn_string_t *value,
2575 apr_pool_t *pool)
2577 VALUE callbacks = (VALUE)baton;
2578 svn_error_t *err = SVN_NO_ERROR;
2580 if (!NIL_P(callbacks)) {
2581 callback_baton_t cbb;
2583 cbb.receiver = callbacks;
2584 cbb.message = id_push_wc_prop;
2585 cbb.args = rb_ary_new3(3,
2586 c2r_string2(path),
2587 c2r_string2(name),
2588 c2r_svn_string((void *)value, NULL));
2589 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
2592 return err;
2595 static svn_error_t *
2596 ra_callbacks_invalidate_wc_props(void *baton,
2597 const char *path,
2598 const char *name,
2599 apr_pool_t *pool)
2601 VALUE callbacks = (VALUE)baton;
2602 svn_error_t *err = SVN_NO_ERROR;
2604 if (!NIL_P(callbacks)) {
2605 callback_baton_t cbb;
2607 cbb.receiver = callbacks;
2608 cbb.message = id_invalidate_wc_props;
2609 cbb.args = rb_ary_new3(2, c2r_string2(path), c2r_string2(name));
2610 invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
2613 return err;
2617 static void
2618 ra_callbacks_progress_func(apr_off_t progress,
2619 apr_off_t total,
2620 void *baton,
2621 apr_pool_t *pool)
2623 VALUE callbacks = (VALUE)baton;
2624 if (!NIL_P(callbacks)) {
2625 callback_baton_t cbb;
2627 cbb.receiver = callbacks;
2628 cbb.message = id_progress_func;
2629 cbb.args = rb_ary_new3(2, AOFF2NUM(progress), AOFF2NUM(total));
2630 invoke_callback((VALUE)(&cbb), Qnil);
2634 void
2635 svn_swig_rb_setup_ra_callbacks(svn_ra_callbacks2_t **callbacks,
2636 void **baton,
2637 VALUE rb_callbacks,
2638 apr_pool_t *pool)
2640 void *auth_baton = NULL;
2642 if (!NIL_P(rb_callbacks)) {
2643 VALUE rb_auth_baton = Qnil;
2644 rb_auth_baton = rb_funcall(rb_callbacks, id_auth_baton, 0);
2645 auth_baton = r2c_swig_type(rb_auth_baton,
2646 (void *)"svn_auth_baton_t *",
2647 pool);
2650 *callbacks = apr_pcalloc(pool, sizeof(**callbacks));
2651 *baton = (void *)rb_callbacks;
2653 (*callbacks)->open_tmp_file = ra_callbacks_open_tmp_file;
2654 (*callbacks)->auth_baton = auth_baton;
2655 (*callbacks)->get_wc_prop = ra_callbacks_get_wc_prop;
2656 (*callbacks)->set_wc_prop = ra_callbacks_set_wc_prop;
2657 (*callbacks)->push_wc_prop = ra_callbacks_push_wc_prop;
2658 (*callbacks)->invalidate_wc_props = ra_callbacks_invalidate_wc_props;
2659 (*callbacks)->progress_func = ra_callbacks_progress_func;
2660 (*callbacks)->progress_baton = (void *)rb_callbacks;
2664 svn_error_t *
2665 svn_swig_rb_ra_lock_callback(void *baton,
2666 const char *path,
2667 svn_boolean_t do_lock,
2668 const svn_lock_t *lock,
2669 svn_error_t *ra_err,
2670 apr_pool_t *pool)
2672 svn_error_t *err = SVN_NO_ERROR;
2673 VALUE proc, rb_pool;
2675 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2677 if (!NIL_P(proc)) {
2678 callback_baton_t cbb;
2680 cbb.receiver = proc;
2681 cbb.message = id_call;
2682 cbb.args = rb_ary_new3(4,
2683 c2r_string2(path),
2684 do_lock ? Qtrue : Qfalse,
2685 c2r_lock__dup(lock),
2686 ra_err ?
2687 svn_swig_rb_svn_error_to_rb_error(ra_err) :
2688 Qnil);
2689 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2692 return err;
2695 svn_error_t *
2696 svn_swig_rb_just_call(void *baton)
2698 svn_error_t *err = SVN_NO_ERROR;
2699 VALUE proc, rb_pool;
2701 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2703 if (!NIL_P(proc)) {
2704 callback_baton_t cbb;
2706 cbb.receiver = proc;
2707 cbb.message = id_call;
2708 cbb.args = rb_ary_new3(0);
2709 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2712 return err;
2715 svn_error_t *
2716 svn_swig_rb_ra_file_rev_handler(void *baton,
2717 const char *path,
2718 svn_revnum_t rev,
2719 apr_hash_t *rev_props,
2720 svn_txdelta_window_handler_t *delta_handler,
2721 void **delta_baton,
2722 apr_array_header_t *prop_diffs,
2723 apr_pool_t *pool)
2725 svn_error_t *err = SVN_NO_ERROR;
2726 VALUE proc, rb_pool;
2728 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2730 if (!NIL_P(proc)) {
2731 callback_baton_t cbb;
2733 cbb.receiver = proc;
2734 cbb.message = id_call;
2735 cbb.args = rb_ary_new3(4,
2736 c2r_string2(path),
2737 c2r_long(&rev, NULL),
2738 svn_swig_rb_apr_hash_to_hash_svn_string(rev_props),
2739 svn_swig_rb_prop_apr_array_to_hash_prop(prop_diffs));
2740 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2743 return err;
2746 svn_error_t *
2747 svn_swig_rb_repos_history_func(void *baton,
2748 const char *path,
2749 svn_revnum_t revision,
2750 apr_pool_t *pool)
2752 svn_error_t *err = SVN_NO_ERROR;
2753 VALUE proc, rb_pool;
2755 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2757 if (!NIL_P(proc)) {
2758 callback_baton_t cbb;
2759 VALUE result = Qnil;
2761 cbb.receiver = proc;
2762 cbb.message = id_call;
2763 cbb.args = rb_ary_new3(2,
2764 c2r_string2(path),
2765 c2r_long(&revision, NULL));
2766 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2768 if (!err && SVN_ERR_P(result)) {
2769 err = r2c_svn_err(result, NULL, NULL);
2773 return err;
2776 svn_error_t *
2777 svn_swig_rb_repos_file_rev_handler(void *baton,
2778 const char *path,
2779 svn_revnum_t rev,
2780 apr_hash_t *rev_props,
2781 svn_txdelta_window_handler_t *delta_handler,
2782 void **delta_baton,
2783 apr_array_header_t *prop_diffs,
2784 apr_pool_t *pool)
2786 svn_error_t *err = SVN_NO_ERROR;
2787 VALUE proc, rb_pool;
2789 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2791 if (!NIL_P(proc)) {
2792 callback_baton_t cbb;
2794 cbb.receiver = proc;
2795 cbb.message = id_call;
2796 cbb.args = rb_ary_new3(4,
2797 c2r_string2(path),
2798 c2r_long(&rev, NULL),
2799 svn_swig_rb_apr_hash_to_hash_svn_string(rev_props),
2800 svn_swig_rb_prop_apr_array_to_hash_prop(prop_diffs));
2801 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2804 return err;
2807 svn_error_t *
2808 svn_swig_rb_wc_relocation_validator3(void *baton,
2809 const char *uuid,
2810 const char *url,
2811 const char *root_url,
2812 apr_pool_t *pool)
2814 svn_error_t *err = SVN_NO_ERROR;
2815 VALUE proc, rb_pool;
2817 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2819 if (!NIL_P(proc)) {
2820 callback_baton_t cbb;
2822 cbb.receiver = proc;
2823 cbb.message = id_call;
2824 cbb.args = rb_ary_new3(3,
2825 c2r_string2(uuid),
2826 c2r_string2(url),
2827 c2r_string2(root_url));
2828 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2831 return err;
2836 /* auth provider callbacks */
2837 svn_error_t *
2838 svn_swig_rb_auth_simple_prompt_func(svn_auth_cred_simple_t **cred,
2839 void *baton,
2840 const char *realm,
2841 const char *username,
2842 svn_boolean_t may_save,
2843 apr_pool_t *pool)
2845 svn_auth_cred_simple_t *new_cred = NULL;
2846 svn_error_t *err = SVN_NO_ERROR;
2847 VALUE proc, rb_pool;
2849 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2851 if (!NIL_P(proc)) {
2852 callback_baton_t cbb;
2853 VALUE result;
2855 cbb.receiver = proc;
2856 cbb.message = id_call;
2857 cbb.args = rb_ary_new3(3,
2858 c2r_string2(realm),
2859 c2r_string2(username),
2860 RTEST(may_save) ? Qtrue : Qfalse);
2861 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2863 if (!NIL_P(result)) {
2864 void *result_cred = NULL;
2865 svn_auth_cred_simple_t *tmp_cred = NULL;
2867 r2c_swig_type2(result, "svn_auth_cred_simple_t *", &result_cred);
2868 tmp_cred = (svn_auth_cred_simple_t *)result_cred;
2869 new_cred = apr_pcalloc(pool, sizeof(*new_cred));
2870 new_cred->username = tmp_cred->username ?
2871 apr_pstrdup(pool, tmp_cred->username) : NULL;
2872 new_cred->password = tmp_cred->password ?
2873 apr_pstrdup(pool, tmp_cred->password) : NULL;
2874 new_cred->may_save = tmp_cred->may_save;
2878 *cred = new_cred;
2879 return err;
2882 svn_error_t *
2883 svn_swig_rb_auth_username_prompt_func(svn_auth_cred_username_t **cred,
2884 void *baton,
2885 const char *realm,
2886 svn_boolean_t may_save,
2887 apr_pool_t *pool)
2889 svn_auth_cred_username_t *new_cred = NULL;
2890 svn_error_t *err = SVN_NO_ERROR;
2891 VALUE proc, rb_pool;
2893 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2895 if (!NIL_P(proc)) {
2896 callback_baton_t cbb;
2897 VALUE result;
2899 cbb.receiver = proc;
2900 cbb.message = id_call;
2901 cbb.args = rb_ary_new3(2,
2902 c2r_string2(realm),
2903 RTEST(may_save) ? Qtrue : Qfalse);
2904 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2906 if (!NIL_P(result)) {
2907 void *result_cred = NULL;
2908 svn_auth_cred_username_t *tmp_cred = NULL;
2910 r2c_swig_type2(result, "svn_auth_cred_username_t *", &result_cred);
2911 tmp_cred = (svn_auth_cred_username_t *)result_cred;
2912 new_cred = apr_pcalloc(pool, sizeof(*new_cred));
2913 new_cred->username = tmp_cred->username ?
2914 apr_pstrdup(pool, tmp_cred->username) : NULL;
2915 new_cred->may_save = tmp_cred->may_save;
2919 *cred = new_cred;
2920 return err;
2923 svn_error_t *
2924 svn_swig_rb_auth_ssl_server_trust_prompt_func(
2925 svn_auth_cred_ssl_server_trust_t **cred,
2926 void *baton,
2927 const char *realm,
2928 apr_uint32_t failures,
2929 const svn_auth_ssl_server_cert_info_t *cert_info,
2930 svn_boolean_t may_save,
2931 apr_pool_t *pool)
2933 svn_auth_cred_ssl_server_trust_t *new_cred = NULL;
2934 svn_error_t *err = SVN_NO_ERROR;
2935 VALUE proc, rb_pool;
2937 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2939 if (!NIL_P(proc)) {
2940 callback_baton_t cbb;
2941 VALUE result;
2943 cbb.receiver = proc;
2944 cbb.message = id_call;
2945 cbb.args = rb_ary_new3(4,
2946 c2r_string2(realm),
2947 UINT2NUM(failures),
2948 c2r_auth_ssl_server_cert_info__dup(cert_info),
2949 RTEST(may_save) ? Qtrue : Qfalse);
2950 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2952 if (!NIL_P(result)) {
2953 void *result_cred;
2954 svn_auth_cred_ssl_server_trust_t *tmp_cred = NULL;
2956 r2c_swig_type2(result, "svn_auth_cred_ssl_server_trust_t *",
2957 &result_cred);
2958 tmp_cred = (svn_auth_cred_ssl_server_trust_t *)result_cred;
2959 new_cred = apr_pcalloc(pool, sizeof(*new_cred));
2960 *new_cred = *tmp_cred;
2964 *cred = new_cred;
2965 return err;
2968 svn_error_t *
2969 svn_swig_rb_auth_ssl_client_cert_prompt_func(
2970 svn_auth_cred_ssl_client_cert_t **cred,
2971 void *baton,
2972 const char *realm,
2973 svn_boolean_t may_save,
2974 apr_pool_t *pool)
2976 svn_auth_cred_ssl_client_cert_t *new_cred = NULL;
2977 svn_error_t *err = SVN_NO_ERROR;
2978 VALUE proc, rb_pool;
2980 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
2982 if (!NIL_P(proc)) {
2983 callback_baton_t cbb;
2984 VALUE result;
2986 cbb.receiver = proc;
2987 cbb.message = id_call;
2988 cbb.args = rb_ary_new3(2,
2989 c2r_string2(realm),
2990 RTEST(may_save) ? Qtrue : Qfalse);
2991 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
2993 if (!NIL_P(result)) {
2994 void *result_cred = NULL;
2995 svn_auth_cred_ssl_client_cert_t *tmp_cred = NULL;
2997 r2c_swig_type2(result, "svn_auth_cred_ssl_client_cert_t *",
2998 &result_cred);
2999 tmp_cred = (svn_auth_cred_ssl_client_cert_t *)result_cred;
3000 new_cred = apr_pcalloc(pool, sizeof(*new_cred));
3001 new_cred->cert_file = tmp_cred->cert_file ?
3002 apr_pstrdup(pool, tmp_cred->cert_file) : NULL;
3003 new_cred->may_save = tmp_cred->may_save;
3007 *cred = new_cred;
3008 return err;
3011 svn_error_t *
3012 svn_swig_rb_auth_ssl_client_cert_pw_prompt_func(
3013 svn_auth_cred_ssl_client_cert_pw_t **cred,
3014 void *baton,
3015 const char *realm,
3016 svn_boolean_t may_save,
3017 apr_pool_t *pool)
3019 svn_auth_cred_ssl_client_cert_pw_t *new_cred = NULL;
3020 svn_error_t *err = SVN_NO_ERROR;
3021 VALUE proc, rb_pool;
3023 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3025 if (!NIL_P(proc)) {
3026 callback_baton_t cbb;
3027 VALUE result;
3029 cbb.receiver = proc;
3030 cbb.message = id_call;
3031 cbb.args = rb_ary_new3(2,
3032 c2r_string2(realm),
3033 RTEST(may_save) ? Qtrue : Qfalse);
3034 result = invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3036 if (!NIL_P(result)) {
3037 void *result_cred = NULL;
3038 svn_auth_cred_ssl_client_cert_pw_t *tmp_cred = NULL;
3040 r2c_swig_type2(result, "svn_auth_cred_ssl_client_cert_pw_t *",
3041 &result_cred);
3042 tmp_cred = (svn_auth_cred_ssl_client_cert_pw_t *)result_cred;
3043 new_cred = apr_pcalloc(pool, sizeof(*new_cred));
3044 new_cred->password = tmp_cred->password ?
3045 apr_pstrdup(pool, tmp_cred->password) : NULL;
3046 new_cred->may_save = tmp_cred->may_save;
3050 *cred = new_cred;
3051 return err;
3055 apr_file_t *
3056 svn_swig_rb_make_file(VALUE file, apr_pool_t *pool)
3058 apr_file_t *apr_file = NULL;
3060 apr_file_open(&apr_file, StringValuePtr(file),
3061 APR_CREATE | APR_READ | APR_WRITE,
3062 APR_OS_DEFAULT,
3063 pool);
3065 return apr_file;
3069 static svn_error_t *
3070 read_handler_rbio(void *baton, char *buffer, apr_size_t *len)
3072 VALUE result;
3073 VALUE io = (VALUE)baton;
3074 svn_error_t *err = SVN_NO_ERROR;
3076 result = rb_funcall(io, id_read, 1, INT2NUM(*len));
3077 if (NIL_P(result)) {
3078 *len = 0;
3079 } else {
3080 memcpy(buffer, StringValuePtr(result), RSTRING(result)->len);
3081 *len = RSTRING(result)->len;
3084 return err;
3087 static svn_error_t *
3088 write_handler_rbio(void *baton, const char *data, apr_size_t *len)
3090 VALUE io = (VALUE)baton;
3091 svn_error_t *err = SVN_NO_ERROR;
3093 rb_funcall(io, id_write, 1, rb_str_new(data, *len));
3095 return err;
3098 svn_stream_t *
3099 svn_swig_rb_make_stream(VALUE io)
3101 svn_stream_t *stream;
3103 if (RTEST(rb_funcall(rb_svn_core_stream(), id_eqq, 1, io))) {
3104 svn_stream_t **stream_p;
3105 stream_p = &stream;
3106 r2c_swig_type2(io, "svn_stream_t *", (void **)stream_p);
3107 } else {
3108 VALUE rb_pool = rb_pool_new(Qnil);
3109 apr_pool_wrapper_t *pool_wrapper;
3110 apr_pool_wrapper_t **pool_wrapper_p;
3112 rb_set_pool(io, rb_pool);
3113 pool_wrapper_p = &pool_wrapper;
3114 r2c_swig_type2(rb_pool, "apr_pool_wrapper_t *", (void **)pool_wrapper_p);
3115 stream = svn_stream_create((void *)io, pool_wrapper->pool);
3116 svn_stream_set_read(stream, read_handler_rbio);
3117 svn_stream_set_write(stream, write_handler_rbio);
3120 return stream;
3123 VALUE
3124 svn_swig_rb_filename_to_temp_file(const char *file_name)
3126 return rb_funcall(rb_svn_util(), id_filename_to_temp_file,
3127 1, rb_str_new2(file_name));
3130 void
3131 svn_swig_rb_set_revision(svn_opt_revision_t *rev, VALUE value)
3133 switch (TYPE(value)) {
3134 case T_NIL:
3135 rev->kind = svn_opt_revision_unspecified;
3136 break;
3137 case T_FIXNUM:
3138 rev->kind = svn_opt_revision_number;
3139 rev->value.number = NUM2LONG(value);
3140 break;
3141 case T_STRING:
3142 if (RTEST(rb_reg_match(rb_reg_new("^BASE$",
3143 strlen("^BASE$"),
3144 RE_OPTION_IGNORECASE),
3145 value)))
3146 rev->kind = svn_opt_revision_base;
3147 else if (RTEST(rb_reg_match(rb_reg_new("^HEAD$",
3148 strlen("^HEAD$"),
3149 RE_OPTION_IGNORECASE),
3150 value)))
3151 rev->kind = svn_opt_revision_head;
3152 else if (RTEST(rb_reg_match(rb_reg_new("^WORKING$",
3153 strlen("^WORKING$"),
3154 RE_OPTION_IGNORECASE),
3155 value)))
3156 rev->kind = svn_opt_revision_working;
3157 else if (RTEST(rb_reg_match(rb_reg_new("^COMMITTED$",
3158 strlen("^COMMITTED$"),
3159 RE_OPTION_IGNORECASE),
3160 value)))
3161 rev->kind = svn_opt_revision_committed;
3162 else if (RTEST(rb_reg_match(rb_reg_new("^PREV$",
3163 strlen("^PREV$"),
3164 RE_OPTION_IGNORECASE),
3165 value)))
3166 rev->kind = svn_opt_revision_previous;
3167 else
3168 rb_raise(rb_eArgError,
3169 "invalid value: %s",
3170 StringValuePtr(value));
3171 break;
3172 default:
3173 if (rb_obj_is_kind_of(value,
3174 rb_const_get(rb_cObject, rb_intern("Time")))) {
3175 rev->kind = svn_opt_revision_date;
3176 rev->value.date = NUM2LONG(rb_funcall(value, rb_intern("to_i"), 0));
3177 } else {
3178 rb_raise(rb_eArgError,
3179 "invalid type: %s",
3180 rb_class2name(CLASS_OF(value)));
3182 break;
3186 void
3187 svn_swig_rb_adjust_arg_for_client_ctx_and_pool(int *argc, VALUE **argv)
3189 if (*argc > 1) {
3190 VALUE last_arg = (*argv)[*argc - 1];
3191 if (NIL_P(last_arg) || POOL_P(last_arg)) {
3192 *argv += *argc - 2;
3193 *argc = 2;
3194 } else {
3195 if (CONTEXT_P(last_arg)) {
3196 *argv += *argc - 1;
3197 *argc = 1;
3198 } else {
3199 *argv += *argc - 2;
3200 *argc = 2;
3206 void
3207 svn_swig_rb_wc_status_func(void *baton,
3208 const char *path,
3209 svn_wc_status2_t *status)
3211 VALUE proc, rb_pool;
3213 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3215 if (!NIL_P(proc)) {
3216 callback_baton_t cbb;
3218 cbb.receiver = proc;
3219 cbb.message = id_call;
3220 cbb.args = rb_ary_new3(2, c2r_string2(path), c2r_wc_status2__dup(status));
3221 invoke_callback((VALUE)(&cbb), rb_pool);
3225 svn_error_t *
3226 svn_swig_rb_client_blame_receiver_func(void *baton,
3227 apr_int64_t line_no,
3228 svn_revnum_t revision,
3229 const char *author,
3230 const char *date,
3231 const char *line,
3232 apr_pool_t *pool)
3234 svn_error_t *err = SVN_NO_ERROR;
3235 VALUE proc, rb_pool;
3237 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3239 if (!NIL_P(proc)) {
3240 callback_baton_t cbb;
3242 cbb.receiver = proc;
3243 cbb.message = id_call;
3244 cbb.args = rb_ary_new3(5,
3245 AI642NUM(line_no),
3246 INT2NUM(revision),
3247 c2r_string2(author),
3248 c2r_svn_date_string2(date),
3249 c2r_string2(line));
3250 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3253 return err;
3258 /* svn_wc_entry_callbacks2_t */
3259 static svn_error_t *
3260 wc_entry_callbacks2_found_entry(const char *path,
3261 const svn_wc_entry_t *entry,
3262 void *walk_baton,
3263 apr_pool_t *pool)
3265 svn_error_t *err = SVN_NO_ERROR;
3266 VALUE callbacks, rb_pool;
3268 svn_swig_rb_from_baton((VALUE)walk_baton, &callbacks, &rb_pool);;
3270 if (!NIL_P(callbacks)) {
3271 callback_baton_t cbb;
3273 cbb.receiver = callbacks;
3274 cbb.message = id_found_entry;
3275 cbb.args = rb_ary_new3(2,
3276 c2r_string2(path),
3277 c2r_wc_entry__dup(entry));
3278 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3281 return err;
3284 static svn_error_t *
3285 wc_entry_callbacks2_handle_error(const char *path,
3286 svn_error_t *err,
3287 void *walk_baton,
3288 apr_pool_t *pool)
3290 VALUE callbacks, rb_pool;
3292 svn_swig_rb_from_baton((VALUE)walk_baton, &callbacks, &rb_pool);;
3294 if (!NIL_P(callbacks)) {
3295 callback_baton_t cbb;
3296 ID message;
3298 message = id_handle_error;
3299 if (rb_obj_respond_to(callbacks, message, FALSE)) {
3300 VALUE rb_err;
3302 cbb.receiver = callbacks;
3303 cbb.message = id_handle_error;
3304 rb_err = err ? svn_swig_rb_svn_error_to_rb_error(err) : Qnil;
3305 if (err)
3306 svn_error_clear(err);
3307 err = NULL;
3308 cbb.args = rb_ary_new3(2, c2r_string2(path), rb_err);
3309 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3313 return err;
3316 svn_wc_entry_callbacks2_t *
3317 svn_swig_rb_wc_entry_callbacks2(void)
3319 static svn_wc_entry_callbacks2_t wc_entry_callbacks = {
3320 wc_entry_callbacks2_found_entry,
3321 wc_entry_callbacks2_handle_error,
3324 return &wc_entry_callbacks;
3329 /* svn_wc_diff_callbacks2_t */
3330 static svn_error_t *
3331 wc_diff_callbacks_file_changed(svn_wc_adm_access_t *adm_access,
3332 svn_wc_notify_state_t *contentstate,
3333 svn_wc_notify_state_t *propstate,
3334 const char *path,
3335 const char *tmpfile1,
3336 const char *tmpfile2,
3337 svn_revnum_t rev1,
3338 svn_revnum_t rev2,
3339 const char *mimetype1,
3340 const char *mimetype2,
3341 const apr_array_header_t *propchanges,
3342 apr_hash_t *originalprops,
3343 void *diff_baton)
3345 VALUE callbacks, rb_pool;
3346 svn_error_t *err = SVN_NO_ERROR;
3348 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3349 if (!NIL_P(callbacks)) {
3350 callback_baton_t cbb;
3351 VALUE result = Qnil;
3353 cbb.receiver = callbacks;
3354 cbb.message = id_file_changed;
3355 cbb.args = rb_ary_new3(10,
3356 c2r_swig_type((void *)adm_access,
3357 (void *)"svn_wc_adm_access_t *"),
3358 c2r_string2(path),
3359 c2r_string2(tmpfile1),
3360 c2r_string2(tmpfile2),
3361 INT2NUM(rev1),
3362 INT2NUM(rev2),
3363 c2r_string2(mimetype1),
3364 c2r_string2(mimetype2),
3365 svn_swig_rb_prop_apr_array_to_hash_prop(propchanges),
3366 svn_swig_rb_prop_hash_to_hash(originalprops));
3367 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3369 if (contentstate)
3370 *contentstate = NUM2INT(rb_ary_entry(result, 0));
3371 if (propstate)
3372 *propstate = NUM2INT(rb_ary_entry(result, 1));
3375 return err;
3378 static svn_error_t *
3379 wc_diff_callbacks_file_added(svn_wc_adm_access_t *adm_access,
3380 svn_wc_notify_state_t *contentstate,
3381 svn_wc_notify_state_t *propstate,
3382 const char *path,
3383 const char *tmpfile1,
3384 const char *tmpfile2,
3385 svn_revnum_t rev1,
3386 svn_revnum_t rev2,
3387 const char *mimetype1,
3388 const char *mimetype2,
3389 const apr_array_header_t *propchanges,
3390 apr_hash_t *originalprops,
3391 void *diff_baton)
3393 VALUE callbacks, rb_pool;
3394 svn_error_t *err = SVN_NO_ERROR;
3396 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3397 if (!NIL_P(callbacks)) {
3398 callback_baton_t cbb;
3399 VALUE result = Qnil;
3401 cbb.receiver = callbacks;
3402 cbb.message = id_file_added;
3403 cbb.args = rb_ary_new3(10,
3404 c2r_swig_type((void *)adm_access,
3405 (void *)"svn_wc_adm_access_t *"),
3406 c2r_string2(path),
3407 c2r_string2(tmpfile1),
3408 c2r_string2(tmpfile2),
3409 INT2NUM(rev1),
3410 INT2NUM(rev2),
3411 c2r_string2(mimetype1),
3412 c2r_string2(mimetype2),
3413 svn_swig_rb_prop_apr_array_to_hash_prop(propchanges),
3414 svn_swig_rb_prop_hash_to_hash(originalprops));
3415 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3417 if (contentstate)
3418 *contentstate = NUM2INT(rb_ary_entry(result, 0));
3419 if (propstate)
3420 *propstate = NUM2INT(rb_ary_entry(result, 1));
3423 return err;
3426 static svn_error_t *
3427 wc_diff_callbacks_file_deleted(svn_wc_adm_access_t *adm_access,
3428 svn_wc_notify_state_t *state,
3429 const char *path,
3430 const char *tmpfile1,
3431 const char *tmpfile2,
3432 const char *mimetype1,
3433 const char *mimetype2,
3434 apr_hash_t *originalprops,
3435 void *diff_baton)
3437 VALUE callbacks, rb_pool;
3438 svn_error_t *err = SVN_NO_ERROR;
3440 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3441 if (!NIL_P(callbacks)) {
3442 callback_baton_t cbb;
3443 VALUE result = Qnil;
3445 cbb.receiver = callbacks;
3446 cbb.message = id_file_deleted;
3447 cbb.args = rb_ary_new3(7,
3448 c2r_swig_type((void *)adm_access,
3449 (void *)"svn_wc_adm_access_t *"),
3450 c2r_string2(path),
3451 c2r_string2(tmpfile1),
3452 c2r_string2(tmpfile2),
3453 c2r_string2(mimetype1),
3454 c2r_string2(mimetype2),
3455 svn_swig_rb_prop_hash_to_hash(originalprops));
3456 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3457 if (state)
3458 *state = NUM2INT(result);
3461 return err;
3464 static svn_error_t *
3465 wc_diff_callbacks_dir_added(svn_wc_adm_access_t *adm_access,
3466 svn_wc_notify_state_t *state,
3467 const char *path,
3468 svn_revnum_t rev,
3469 void *diff_baton)
3471 VALUE callbacks, rb_pool;
3472 svn_error_t *err = SVN_NO_ERROR;
3474 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3475 if (!NIL_P(callbacks)) {
3476 callback_baton_t cbb;
3477 VALUE result = Qnil;
3479 cbb.receiver = callbacks;
3480 cbb.message = id_dir_added;
3481 cbb.args = rb_ary_new3(3,
3482 c2r_swig_type((void *)adm_access,
3483 (void *)"svn_wc_adm_access_t *"),
3484 c2r_string2(path),
3485 INT2NUM(rev));
3486 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3487 if (state)
3488 *state = NUM2INT(result);
3491 return err;
3494 static svn_error_t *
3495 wc_diff_callbacks_dir_deleted(svn_wc_adm_access_t *adm_access,
3496 svn_wc_notify_state_t *state,
3497 const char *path,
3498 void *diff_baton)
3500 VALUE callbacks, rb_pool;
3501 svn_error_t *err = SVN_NO_ERROR;
3503 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3504 if (!NIL_P(callbacks)) {
3505 callback_baton_t cbb;
3506 VALUE result = Qnil;
3508 cbb.receiver = callbacks;
3509 cbb.message = id_dir_deleted;
3510 cbb.args = rb_ary_new3(2,
3511 c2r_swig_type((void *)adm_access,
3512 (void *)"svn_wc_adm_access_t *"),
3513 c2r_string2(path));
3514 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3515 if (state)
3516 *state = NUM2INT(result);
3519 return err;
3522 static svn_error_t *
3523 wc_diff_callbacks_dir_props_changed(svn_wc_adm_access_t *adm_access,
3524 svn_wc_notify_state_t *state,
3525 const char *path,
3526 const apr_array_header_t *propchanges,
3527 apr_hash_t *originalprops,
3528 void *diff_baton)
3530 VALUE callbacks, rb_pool;
3531 svn_error_t *err = SVN_NO_ERROR;
3533 svn_swig_rb_from_baton((VALUE)diff_baton, &callbacks, &rb_pool);
3534 if (!NIL_P(callbacks)) {
3535 callback_baton_t cbb;
3536 VALUE result = Qnil;
3538 cbb.receiver = callbacks;
3539 cbb.message = id_dir_props_changed;
3540 cbb.args = rb_ary_new3(4,
3541 c2r_swig_type((void *)adm_access,
3542 (void *)"svn_wc_adm_access_t *"),
3543 c2r_string2(path),
3544 svn_swig_rb_prop_apr_array_to_hash_prop(propchanges),
3545 svn_swig_rb_prop_hash_to_hash(originalprops));
3546 result = invoke_callback_handle_error((VALUE)(&cbb), Qnil, &err);
3548 if (state)
3549 *state = NUM2INT(result);
3552 return err;
3555 svn_wc_diff_callbacks2_t *
3556 svn_swig_rb_wc_diff_callbacks2(void)
3558 static svn_wc_diff_callbacks2_t wc_diff_callbacks2 = {
3559 wc_diff_callbacks_file_changed,
3560 wc_diff_callbacks_file_added,
3561 wc_diff_callbacks_file_deleted,
3562 wc_diff_callbacks_dir_added,
3563 wc_diff_callbacks_dir_deleted,
3564 wc_diff_callbacks_dir_props_changed
3567 return &wc_diff_callbacks2;
3571 VALUE
3572 svn_swig_rb_make_txdelta_window_handler_wrapper(VALUE *rb_handler_pool,
3573 apr_pool_t **handler_pool,
3574 svn_txdelta_window_handler_t **handler,
3575 void ***handler_baton)
3577 VALUE obj;
3579 obj = rb_class_new_instance(0, NULL, rb_cObject);
3580 svn_swig_rb_get_pool(0, NULL, obj, rb_handler_pool, handler_pool);
3581 svn_swig_rb_set_pool_for_no_swig_type(obj, *rb_handler_pool);
3582 *handler = apr_palloc(*handler_pool, sizeof(svn_txdelta_window_handler_t));
3583 *handler_baton = apr_palloc(*handler_pool, sizeof(void *));
3585 return obj;
3588 VALUE
3589 svn_swig_rb_setup_txdelta_window_handler_wrapper(VALUE obj,
3590 svn_txdelta_window_handler_t handler,
3591 void *handler_baton)
3593 rb_ivar_set(obj, id_handler,
3594 c2r_swig_type((void *)handler,
3595 (void *)"svn_txdelta_window_handler_t"));
3596 rb_ivar_set(obj, id_handler_baton,
3597 c2r_swig_type(handler_baton, (void *)"void *"));
3598 return obj;
3601 svn_error_t *
3602 svn_swig_rb_invoke_txdelta_window_handler_wrapper(VALUE obj,
3603 svn_txdelta_window_t *window,
3604 apr_pool_t *pool)
3606 svn_txdelta_window_handler_t handler;
3607 svn_txdelta_window_handler_t *handler_p;
3608 void *handler_baton;
3610 handler_p = &handler;
3611 r2c_swig_type2(rb_ivar_get(obj, id_handler),
3612 "svn_txdelta_window_handler_t", (void **)handler_p);
3613 r2c_swig_type2(rb_ivar_get(obj, id_handler_baton),
3614 "void *", &handler_baton);
3616 return handler(window, handler_baton);
3620 VALUE
3621 svn_swig_rb_txdelta_window_t_ops_get(svn_txdelta_window_t *window)
3623 VALUE ops;
3624 const svn_txdelta_op_t *op;
3625 int i;
3627 ops = rb_ary_new2(window->num_ops);
3629 for (i = 0; i < window->num_ops; i++) {
3630 op = window->ops + i;
3631 rb_ary_push(ops, c2r_swig_type((void *)op, (void *)"svn_txdelta_op_t *"));
3634 return ops;
3638 svn_error_t *
3639 svn_swig_rb_client_diff_summarize_func(const svn_client_diff_summarize_t *diff,
3640 void *baton,
3641 apr_pool_t *pool)
3643 svn_error_t *err = SVN_NO_ERROR;
3644 VALUE proc, rb_pool;
3646 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3648 if (!NIL_P(proc)) {
3649 callback_baton_t cbb;
3651 cbb.receiver = proc;
3652 cbb.message = id_call;
3653 cbb.args = rb_ary_new3(1, c2r_client_diff_summarize__dup(diff));
3654 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3657 return err;
3660 svn_error_t *
3661 svn_swig_rb_client_list_func(void *baton,
3662 const char *path,
3663 const svn_dirent_t *dirent,
3664 const svn_lock_t *lock,
3665 const char *abs_path,
3666 apr_pool_t *pool)
3668 svn_error_t *err = SVN_NO_ERROR;
3669 VALUE proc, rb_pool;
3671 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3673 if (!NIL_P(proc)) {
3674 callback_baton_t cbb;
3676 cbb.receiver = proc;
3677 cbb.message = id_call;
3678 cbb.args = rb_ary_new3(4,
3679 c2r_string2(path),
3680 c2r_dirent__dup(dirent),
3681 c2r_lock__dup(lock),
3682 c2r_string2(abs_path));
3683 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3686 return err;
3689 svn_error_t *
3690 svn_swig_rb_proplist_receiver(void *baton,
3691 const char *path,
3692 apr_hash_t *prop_hash,
3693 apr_pool_t *pool)
3695 svn_error_t *err = SVN_NO_ERROR;
3696 VALUE proc, rb_pool;
3698 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3699 if (!NIL_P(proc)) {
3700 callback_baton_t cbb;
3702 cbb.receiver = proc;
3703 cbb.message = id_call;
3704 cbb.args = rb_ary_new3(2,
3705 c2r_string2(path),
3706 svn_swig_rb_prop_hash_to_hash(prop_hash));
3707 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3710 return err;
3713 svn_error_t *
3714 svn_swig_rb_changelist_receiver(void *baton,
3715 const char *path,
3716 const char *changelist,
3717 apr_pool_t *pool)
3719 svn_error_t *err = SVN_NO_ERROR;
3720 VALUE proc, rb_pool;
3722 svn_swig_rb_from_baton((VALUE)baton, &proc, &rb_pool);
3723 if (!NIL_P(proc)) {
3724 callback_baton_t cbb;
3726 cbb.receiver = proc;
3727 cbb.message = id_call;
3728 cbb.args = rb_ary_new3(2,
3729 c2r_string2(path),
3730 c2r_string2(changelist));
3731 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3734 return err;
3738 /* svn_ra_reporter3_t */
3739 static void
3740 c2r_ra_reporter3(VALUE rb_reporter, svn_ra_reporter3_t **reporter, void **baton,
3741 apr_pool_t *pool)
3743 VALUE rb_baton;
3745 r2c_swig_type2(rb_reporter, "svn_ra_reporter3_t *", (void **)reporter);
3747 rb_baton = rb_funcall(rb_reporter, id_baton, 0);
3748 r2c_swig_type2(rb_baton, "void *", baton);
3751 static svn_error_t *
3752 svn_swig_rb_ra_reporter_set_path(void *report_baton, const char *path,
3753 svn_revnum_t revision, svn_depth_t depth,
3754 svn_boolean_t start_empty,
3755 const char *lock_token, apr_pool_t *pool)
3757 svn_error_t *err = SVN_NO_ERROR;
3758 VALUE reporter, rb_pool;
3760 svn_swig_rb_from_baton((VALUE)report_baton, &reporter, &rb_pool);
3761 if (rb_obj_is_kind_of(reporter, rb_svn_ra_reporter3())) {
3762 svn_ra_reporter3_t *svn_reporter;
3763 void *baton;
3765 c2r_ra_reporter3(reporter, &svn_reporter, &baton, pool);
3766 err = svn_reporter->set_path(baton, path, revision, depth,
3767 start_empty, lock_token, pool);
3768 } else if (!NIL_P(reporter)) {
3769 callback_baton_t cbb;
3771 cbb.receiver = reporter;
3772 cbb.message = id_set_path;
3773 cbb.args = rb_ary_new3(4,
3774 c2r_string2(path),
3775 INT2NUM(revision),
3776 INT2NUM(depth),
3777 c2r_bool2(start_empty));
3778 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3781 return err;
3784 static svn_error_t *
3785 svn_swig_rb_ra_reporter_delete_path(void *report_baton, const char *path,
3786 apr_pool_t *pool)
3788 svn_error_t *err = SVN_NO_ERROR;
3789 VALUE reporter, rb_pool;
3791 svn_swig_rb_from_baton((VALUE)report_baton, &reporter, &rb_pool);
3792 if (rb_obj_is_kind_of(reporter, rb_svn_ra_reporter3())) {
3793 svn_ra_reporter3_t *svn_reporter;
3794 void *baton;
3796 c2r_ra_reporter3(reporter, &svn_reporter, &baton, pool);
3797 err = svn_reporter->delete_path(baton, path, pool);
3798 } else if (!NIL_P(reporter)) {
3799 callback_baton_t cbb;
3801 cbb.receiver = reporter;
3802 cbb.message = id_delete_path;
3803 cbb.args = rb_ary_new3(1,
3804 c2r_string2(path));
3805 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3808 return err;
3811 static svn_error_t *
3812 svn_swig_rb_ra_reporter_link_path(void *report_baton, const char *path,
3813 const char *url, svn_revnum_t revision,
3814 svn_depth_t depth, svn_boolean_t start_empty,
3815 const char *lock_token, apr_pool_t *pool)
3817 svn_error_t *err = SVN_NO_ERROR;
3818 VALUE reporter, rb_pool;
3820 svn_swig_rb_from_baton((VALUE)report_baton, &reporter, &rb_pool);
3821 if (rb_obj_is_kind_of(reporter, rb_svn_ra_reporter3())) {
3822 svn_ra_reporter3_t *svn_reporter;
3823 void *baton;
3825 c2r_ra_reporter3(reporter, &svn_reporter, &baton, pool);
3826 err = svn_reporter->link_path(baton, path, url, revision, depth,
3827 start_empty, lock_token, pool);
3828 } else if (!NIL_P(reporter)) {
3829 callback_baton_t cbb;
3831 cbb.receiver = reporter;
3832 cbb.message = id_link_path;
3833 cbb.args = rb_ary_new3(5,
3834 c2r_string2(path),
3835 c2r_string2(url),
3836 INT2NUM(revision),
3837 INT2NUM(depth),
3838 c2r_bool2(start_empty));
3839 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3842 return err;
3845 static svn_error_t *
3846 svn_swig_rb_ra_reporter_finish_report(void *report_baton, apr_pool_t *pool)
3848 svn_error_t *err = SVN_NO_ERROR;
3849 VALUE reporter, rb_pool;
3851 svn_swig_rb_from_baton((VALUE)report_baton, &reporter, &rb_pool);
3852 if (rb_obj_is_kind_of(reporter, rb_svn_ra_reporter3())) {
3853 svn_ra_reporter3_t *svn_reporter;
3854 void *baton;
3856 c2r_ra_reporter3(reporter, &svn_reporter, &baton, pool);
3857 err = svn_reporter->finish_report(baton, pool);
3858 } else if (!NIL_P(reporter)) {
3859 callback_baton_t cbb;
3861 cbb.receiver = reporter;
3862 cbb.message = id_finish_report;
3863 cbb.args = rb_ary_new();
3864 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3867 return err;
3870 static svn_error_t *
3871 svn_swig_rb_ra_reporter_abort_report(void *report_baton, apr_pool_t *pool)
3873 svn_error_t *err = SVN_NO_ERROR;
3874 VALUE reporter, rb_pool;
3876 svn_swig_rb_from_baton((VALUE)report_baton, &reporter, &rb_pool);
3877 if (rb_obj_is_kind_of(reporter, rb_svn_ra_reporter3())) {
3878 svn_ra_reporter3_t *svn_reporter;
3879 void *baton;
3881 c2r_ra_reporter3(reporter, &svn_reporter, &baton, pool);
3882 err = svn_reporter->abort_report(baton, pool);
3883 } else if (!NIL_P(reporter)) {
3884 callback_baton_t cbb;
3886 cbb.receiver = reporter;
3887 cbb.message = id_abort_report;
3888 cbb.args = rb_ary_new();
3889 invoke_callback_handle_error((VALUE)(&cbb), rb_pool, &err);
3892 return err;
3895 static svn_ra_reporter3_t rb_ra_reporter3 = {
3896 svn_swig_rb_ra_reporter_set_path,
3897 svn_swig_rb_ra_reporter_delete_path,
3898 svn_swig_rb_ra_reporter_link_path,
3899 svn_swig_rb_ra_reporter_finish_report,
3900 svn_swig_rb_ra_reporter_abort_report
3903 svn_ra_reporter3_t *svn_swig_rb_ra_reporter3 = &rb_ra_reporter3;