swigutil_pl.c

来自「linux subdivision ying gai ke yi le ba」· C语言 代码 · 共 1,411 行 · 第 1/3 页

C
1,411
字号
                                               apr_pool_t *pool)
{
    item_baton *ib = edit_baton;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"set_target_revision", NULL,
				         "Or", ib->editor, target_revision));

    return SVN_NO_ERROR;
}

static svn_error_t * thunk_open_root(void *edit_baton,
                                     svn_revnum_t base_revision,
                                     apr_pool_t *dir_pool,
                                     void **root_baton)
{
    item_baton *ib = edit_baton;
    SV *result;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"open_root", &result,
				         "OrS", ib->editor, base_revision,
				         dir_pool, POOLINFO));

    *root_baton = make_baton(dir_pool, ib->editor, result);
    return SVN_NO_ERROR;
}

static svn_error_t * thunk_delete_entry(const char *path,
                                        svn_revnum_t revision,
                                        void *parent_baton,
                                        apr_pool_t *pool)
{
    item_baton *ib = parent_baton;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"delete_entry", NULL,
				         "OsrOS", ib->editor, path, revision,
				         ib->baton, pool, POOLINFO));
    return SVN_NO_ERROR;
}

static svn_error_t * thunk_add_directory(const char *path,
                                         void *parent_baton,
                                         const char *copyfrom_path,
                                         svn_revnum_t copyfrom_revision,
                                         apr_pool_t *dir_pool,
                                         void **child_baton)
{
    item_baton *ib = parent_baton;
    SV *result;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"add_directory", &result,
				         "OsOsrS", ib->editor, path, ib->baton,
				         copyfrom_path, copyfrom_revision, 
				         dir_pool, POOLINFO));
    *child_baton = make_baton(dir_pool, ib->editor, result);
    return SVN_NO_ERROR;
}

static svn_error_t * thunk_open_directory(const char *path,
                                          void *parent_baton,
                                          svn_revnum_t base_revision,
                                          apr_pool_t *dir_pool,
                                          void **child_baton)
{
    item_baton *ib = parent_baton;
    SV *result;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"open_directory", &result,
				         "OsOrS", ib->editor, path, ib->baton,
				         base_revision, dir_pool, POOLINFO));

    *child_baton = make_baton(dir_pool, ib->editor, result);

    return SVN_NO_ERROR;
}

static svn_error_t * thunk_change_dir_prop(void *dir_baton,
                                           const char *name,
                                           const svn_string_t *value,
                                           apr_pool_t *pool)
{
    item_baton *ib = dir_baton;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"change_dir_prop", NULL,
				         "OOssS", ib->editor, ib->baton, name,
				         value ? value->data : NULL,
				         pool, POOLINFO));

    return SVN_NO_ERROR;
}

static svn_error_t * thunk_close_directory(void *dir_baton,
                                           apr_pool_t *pool)
{
    return close_baton(dir_baton, "close_directory", pool);
}

static svn_error_t * thunk_absent_directory(const char *path,
					    void *parent_baton,
					    apr_pool_t *pool)
{
    item_baton *ib = parent_baton;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
	   			         (void *)"absent_directory", NULL,
				         "OsOS", ib->editor, path, ib->baton,
				         pool, POOLINFO));

    return SVN_NO_ERROR;
}

static svn_error_t * thunk_add_file(const char *path,
                                    void *parent_baton,
                                    const char *copyfrom_path,
                                    svn_revnum_t copyfrom_revision,
                                    apr_pool_t *file_pool,
                                    void **file_baton)
{
    item_baton *ib = parent_baton;
    SV *result;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"add_file", &result,
				         "OsOsrS", ib->editor, path, ib->baton,
				         copyfrom_path, copyfrom_revision,
				         file_pool, POOLINFO));

    *file_baton = make_baton(file_pool, ib->editor, result);
    return SVN_NO_ERROR;
}

static svn_error_t * thunk_open_file(const char *path,
                                     void *parent_baton,
                                     svn_revnum_t base_revision,
                                     apr_pool_t *file_pool,
                                     void **file_baton)
{
    item_baton *ib = parent_baton;
    SV *result;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"open_file", &result,
				         "OsOrS", ib->editor, path, ib->baton,
				         base_revision, file_pool, POOLINFO));

    *file_baton = make_baton(file_pool, ib->editor, result);
    return SVN_NO_ERROR;
}

static svn_error_t * thunk_window_handler(svn_txdelta_window_t *window,
                                          void *baton)
{
    SV *handler = baton;

    if (window == NULL) {
	SVN_ERR (svn_swig_pl_callback_thunk (CALL_SV,
				             handler, NULL, "O",
				             &PL_sv_undef));
        SvREFCNT_dec(handler);
    }
    else {
	swig_type_info *tinfo = _SWIG_TYPE("svn_txdelta_window_t *");
	SVN_ERR (svn_swig_pl_callback_thunk (CALL_SV, handler,
				             NULL, "S", window, tinfo));
    }

    return SVN_NO_ERROR;
}

static svn_error_t *
thunk_apply_textdelta(void *file_baton, 
                      const char *base_checksum,
                      apr_pool_t *pool,
                      svn_txdelta_window_handler_t *handler,
                      void **h_baton)
{
    item_baton *ib = file_baton;
    SV *result;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"apply_textdelta", &result,
				         "OOsS", ib->editor, ib->baton,
					 base_checksum, pool, POOLINFO));
    if (SvOK(result)) {
	if (SvROK(result) && SvTYPE(SvRV(result)) == SVt_PVAV) {
	    swig_type_info *handler_info = 
              _SWIG_TYPE("svn_txdelta_window_handler_t");
            swig_type_info *void_info = _SWIG_TYPE("void *");
	    AV *array = (AV *)SvRV(result);

	    if (SWIG_ConvertPtr(*av_fetch (array, 0, 0),
				(void **)handler, handler_info,0) < 0) {
		croak("Unable to convert from SWIG Type");
	    }
	    if (SWIG_ConvertPtr(*av_fetch (array, 1, 0),
				h_baton, void_info,0) < 0) {
		croak("Unable to convert from SWIG Type ");
	    }
            SvREFCNT_dec(result);
	}
	else {
	    *handler = thunk_window_handler;
	    *h_baton = result;
	}
    }
    else {
	*handler = svn_delta_noop_window_handler;
	*h_baton = NULL;
    }

    return SVN_NO_ERROR;
}

static svn_error_t * thunk_change_file_prop(void *file_baton,
                                            const char *name,
                                            const svn_string_t *value,
                                            apr_pool_t *pool)
{
    item_baton *ib = file_baton;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"change_file_prop", NULL,
				         "OOssS", ib->editor, ib->baton, name,
				         value ? value->data : NULL,
				         pool, POOLINFO));
  
    return SVN_NO_ERROR;
}

static svn_error_t * thunk_close_file(void *file_baton,
                                      const char *text_checksum,
                                      apr_pool_t *pool)
{
    item_baton *ib = file_baton;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"close_file", NULL, "OOsS",
				         ib->editor, ib->baton, text_checksum,
				         pool, POOLINFO));

    SvREFCNT_dec(ib->editor);
    SvREFCNT_dec(ib->baton);

    return SVN_NO_ERROR;
}

static svn_error_t * thunk_absent_file(const char *path,
				       void *parent_baton,
				       apr_pool_t *pool)
{
    item_baton *ib = parent_baton;

    SVN_ERR (svn_swig_pl_callback_thunk (CALL_METHOD,
				         (void *)"absent_file", NULL,
				         "OsOS", ib->editor, path, ib->baton,
				         pool, POOLINFO));

    return SVN_NO_ERROR;
}

static svn_error_t * thunk_close_edit(void *edit_baton,
                                      apr_pool_t *pool)
{
    return close_baton(edit_baton, "close_edit", pool);
}

static svn_error_t * thunk_abort_edit(void *edit_baton,
                                      apr_pool_t *pool)
{
    return close_baton(edit_baton, "abort_edit", pool);
}

void svn_delta_make_editor(svn_delta_editor_t **editor,
			   void **edit_baton,
			   SV *perl_editor,
			   apr_pool_t *pool)
{
    svn_delta_editor_t *thunk_editor = svn_delta_default_editor (pool);
  
    thunk_editor->set_target_revision = thunk_set_target_revision;
    thunk_editor->open_root = thunk_open_root;
    thunk_editor->delete_entry = thunk_delete_entry;
    thunk_editor->add_directory = thunk_add_directory;
    thunk_editor->open_directory = thunk_open_directory;
    thunk_editor->change_dir_prop = thunk_change_dir_prop;
    thunk_editor->close_directory = thunk_close_directory;
    thunk_editor->absent_directory = thunk_absent_directory;
    thunk_editor->add_file = thunk_add_file;
    thunk_editor->open_file = thunk_open_file;
    thunk_editor->apply_textdelta = thunk_apply_textdelta;
    thunk_editor->change_file_prop = thunk_change_file_prop;
    thunk_editor->close_file = thunk_close_file;
    thunk_editor->absent_file = thunk_absent_file;
    thunk_editor->close_edit = thunk_close_edit;
    thunk_editor->abort_edit = thunk_abort_edit;

    *editor = thunk_editor;
    *edit_baton = make_baton(pool, perl_editor, NULL);
}

svn_error_t *svn_swig_pl_thunk_log_receiver(void *baton,
					    apr_hash_t *changed_paths,
					    svn_revnum_t rev,
					    const char *author,
					    const char *date,
					    const char *msg,
					    apr_pool_t *pool)
{
    SV *receiver = baton;
    swig_type_info *tinfo = _SWIG_TYPE("svn_log_changed_path_t *");

    if (!SvOK(receiver))
	return SVN_NO_ERROR;

    svn_swig_pl_callback_thunk (CALL_SV,
			        receiver, NULL,
			        "OrsssS", (changed_paths) ?
			        svn_swig_pl_convert_hash(changed_paths, tinfo)
			        : &PL_sv_undef,
			        rev, author, date, msg, pool, POOLINFO);

    return SVN_NO_ERROR;
}

svn_error_t *svn_swig_pl_thunk_history_func(void *baton,
                                            const char *path,
                                            svn_revnum_t revision,
                                            apr_pool_t *pool)
{
    SV *func = baton;

    if (!SvOK(func))
	return SVN_NO_ERROR;

    svn_swig_pl_callback_thunk (CALL_SV,
			        func, NULL,
			        "srS", path, revision, pool, POOLINFO);

    return SVN_NO_ERROR;
}

svn_error_t *svn_swig_pl_thunk_authz_func (svn_boolean_t *allowed,
                                           svn_fs_root_t *root,
                                           const char *path,
                                           void *baton,
                                           apr_pool_t *pool)
{
    SV *func = baton, *result;

    if (!SvOK(func))
	return SVN_NO_ERROR;

    svn_swig_pl_callback_thunk (CALL_SV,
			        func, &result,
			        "SsS", root, _SWIG_TYPE("svn_fs_root_t *"),
                                path, pool, POOLINFO);

    *allowed = SvIV (result);
    SvREFCNT_dec (result);

    return SVN_NO_ERROR;
}

svn_error_t *svn_swig_pl_thunk_commit_callback(svn_revnum_t new_revision,
					       const char *date,
					       const char *author,
					       void *baton)
{
    if (!SvOK((SV *)baton))
	return SVN_NO_ERROR;

    svn_swig_pl_callback_thunk (CALL_SV, baton, NULL,
			        "rss", new_revision, date, author);

    return SVN_NO_ERROR;
}

/* Wrap RA */

static svn_error_t * thunk_open_tmp_file(apr_file_t **fp,
					 void *callback_baton,
					 apr_pool_t *pool)
{
    SV *result;
    swig_type_info *tinfo = _SWIG_TYPE("apr_file_t *");

    svn_swig_pl_callback_thunk (CALL_METHOD, (void *)"open_tmp_file",
			        &result, "OS", callback_baton, pool, POOLINFO);

    if (SWIG_ConvertPtr(result, (void *)fp, tinfo,0) < 0) {
	croak("Unable to convert from SWIG Type");
    }

    SvREFCNT_dec(result);
    return SVN_NO_ERROR;
}

svn_error_t *thunk_get_wc_prop (void *baton,
				const char *relpath,
				const char *name,
				const svn_string_t **value,
				apr_pool_t *pool)
{
    SV *result;

    svn_swig_pl_callback_thunk (CALL_METHOD, (void *)"get_wc_prop",
			        &result, "OssS", baton, relpath, name,
			       	pool, POOLINFO);

    /* this is svn_string_t * typemap in */
    if (!SvOK (result) || result == &PL_sv_undef) {
	*value = NULL;
    }
    else if (SvPOK(result)) {
	*value = svn_string_create (SvPV_nolen (result), pool);
    }
    else {
	SvREFCNT_dec(result);
	croak("not a string");
    }

    SvREFCNT_dec(result);
    return SVN_NO_ERROR;
}


svn_error_t *svn_ra_make_callbacks(svn_ra_callbacks_t **cb,
				   void **c_baton,
				   SV *perl_callbacks,
				   apr_pool_t *pool)
{
    SV *auth_baton;

    *cb = apr_pcalloc (pool, sizeof(**cb));

    (*cb)->open_tmp_file = thunk_open_tmp_file;
    (*cb)->get_wc_prop = thunk_get_wc_prop;
    (*cb)->set_wc_prop = NULL;
    (*cb)->push_wc_prop = NULL;
    (*cb)->invalidate_wc_props = NULL;
    auth_baton = *hv_fetch((HV *)SvRV(perl_callbacks), "auth", 4, 0);

    if (SWIG_ConvertPtr(auth_baton, 
                        (void **)&(*cb)->auth_baton, _SWIG_TYPE("svn_auth_baton_t *"),0) < 0) {
	croak("Unable to convert from SWIG Type");
    }
    *c_baton = perl_callbacks;
    svn_swig_pl_hold_ref_in_pool (pool, perl_callbacks);
    return SVN_NO_ERROR;
}

svn_error_t *svn_swig_pl_thunk_simple_prompt(svn_auth_cred_simple_t **cred,
                                             void *baton,
                                             const char *realm,
                                             const char *username,
                                             svn_boolean_t may_save,
                                             apr_pool_t *pool)
{
    /* Be nice and allocate the memory for the cred structure before passing it
     * off to the perl space */
    *cred = apr_pcalloc (pool, sizeof (**cred));
    if (!*cred) {
        croak ("Could not allocate memory for cred structure");
    }
    svn_swig_pl_callback_thunk (CALL_SV,
                                baton, NULL,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?