1 /*
2  * swigutil_pl.h :  utility functions and stuff for the SWIG Perl bindings
3  *
4  * ====================================================================
5  *    Licensed to the Apache Software Foundation (ASF) under one
6  *    or more contributor license agreements.  See the NOTICE file
7  *    distributed with this work for additional information
8  *    regarding copyright ownership.  The ASF licenses this file
9  *    to you under the Apache License, Version 2.0 (the
10  *    "License"); you may not use this file except in compliance
11  *    with the License.  You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  *    Unless required by applicable law or agreed to in writing,
16  *    software distributed under the License is distributed on an
17  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  *    KIND, either express or implied.  See the License for the
19  *    specific language governing permissions and limitations
20  *    under the License.
21  * ====================================================================
22  */
23 
24 
25 #ifndef SVN_SWIG_SWIGUTIL_PL_H
26 #define SVN_SWIG_SWIGUTIL_PL_H
27 
28 #include <EXTERN.h>
29 #include <perl.h>
30 #include <XSUB.h>
31 
32 /* Perl defines a _ macro, but SVN uses it for translations.
33  * So undefine _ after including the Perl headers. */
34 #undef _
35 
36 #include <apr.h>
37 #include <apr_pools.h>
38 #include <apr_strings.h>
39 #include <apr_hash.h>
40 #include <apr_tables.h>
41 
42 #include "svn_types.h"
43 #include "svn_string.h"
44 #include "svn_delta.h"
45 #include "svn_client.h"
46 #include "svn_repos.h"
47 #include "svn_private_config.h"
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif /* __cplusplus */
52 
53 #if defined(_MSC_VER)
54 #  if _MSC_VER >= 1300 && _INTEGRAL_MAX_BITS >= 64
55 #    define strtoll _strtoi64
56 #  else
57 #    define strtoll(str, endptr, base) _atoi64(str)
58 #  endif
59 #endif
60 
61 
62 typedef apr_pool_t *(*svn_swig_pl_get_current_pool_func_t)(void);
63 typedef void (*svn_swig_pl_set_current_pool_func_t)(apr_pool_t *pool);
64 
65 void svn_swig_pl__bind_current_pool_fns(svn_swig_pl_get_current_pool_func_t get,
66                                        svn_swig_pl_set_current_pool_func_t set);
67 
68 apr_pool_t * svn_swig_pl_get_current_pool();
69 void svn_swig_pl_set_current_pool(apr_pool_t *pool);
70 
71 apr_pool_t *svn_swig_pl_make_pool(SV *obj);
72 
73 typedef enum perl_func_invoker {
74     CALL_METHOD,
75     CALL_SV
76 } perl_func_invoker_t;
77 
78 svn_error_t *svn_swig_pl_callback_thunk(perl_func_invoker_t caller_func,
79                                         void *func,
80                                         SV **result,
81                                         const char *fmt, ...);
82 
83 SV *svn_swig_pl_prophash_to_hash(apr_hash_t *hash);
84 SV *svn_swig_pl_convert_hash(apr_hash_t *hash, swig_type_info *tinfo);
85 
86 apr_array_header_t *svn_swig_pl_strings_to_array(SV *source,
87                                                        apr_pool_t *pool);
88 
89 apr_hash_t *svn_swig_pl_strings_to_hash(SV *source,
90                                         apr_pool_t *pool);
91 apr_hash_t *svn_swig_pl_objs_to_hash(SV *source, swig_type_info *tinfo,
92                                      apr_pool_t *pool);
93 apr_hash_t *svn_swig_pl_objs_to_hash_by_name(SV *source,
94                                              const char *typename,
95                                              apr_pool_t *pool);
96 apr_hash_t *svn_swig_pl_objs_to_hash_of_revnum_t(SV *source,
97                                                  apr_pool_t *pool);
98 apr_hash_t *svn_swig_pl_hash_to_prophash(SV *source, apr_pool_t *pool);
99 apr_array_header_t *svn_swig_pl_objs_to_array(SV *source,
100                                                     swig_type_info *tinfo,
101                                                     apr_pool_t *pool);
102 apr_array_header_t *svn_swig_pl_array_to_apr_array_revision_range(
103         SV *source, apr_pool_t *pool);
104 
105 SV *svn_swig_pl_array_to_list(const apr_array_header_t *array);
106 SV *svn_swig_pl_convert_array(const apr_array_header_t *array,
107                               swig_type_info *tinfo);
108 
109 SV *svn_swig_pl_revnums_to_list(const apr_array_header_t *array);
110 
111 svn_opt_revision_t *svn_swig_pl_set_revision(svn_opt_revision_t *rev,
112                                              SV *source,
113                                              svn_boolean_t croak_on_error,
114                                              apr_pool_t *pool);
115 
116 /* thunked log_message receiver function.  */
117 svn_error_t * svn_swig_pl_thunk_log_receiver(void *baton,
118                                              apr_hash_t *changed_paths,
119                                              svn_revnum_t rev,
120                                              const char *author,
121                                              const char *date,
122                                              const char *msg,
123                                              apr_pool_t *pool);
124 
125 /* thunked log_entry receiver function.  */
126 svn_error_t * svn_swig_pl_thunk_log_entry_receiver(void *baton,
127                                                    svn_log_entry_t *log_entry,
128                                                    apr_pool_t *pool);
129 
130 /* thunked diff summarize callback.  */
131 svn_error_t * svn_swig_pl_thunk_client_diff_summarize_func(
132                      const svn_client_diff_summarize_t *diff,
133                      void *baton,
134                      apr_pool_t *pool);
135 
136 /* thunked commit editor callback. */
137 svn_error_t *svn_swig_pl_thunk_commit_callback(svn_revnum_t new_revision,
138                                                const char *date,
139                                                const char *author,
140                                                void *baton);
141 
142 /* thunked commit editor callback2. */
143 svn_error_t *svn_swig_pl_thunk_commit_callback2(const svn_commit_info_t *commit_info,
144                                                 void *baton,
145                                                 apr_pool_t *pool);
146 
147 /* thunked repos_history callback. */
148 svn_error_t *svn_swig_pl_thunk_history_func(void *baton,
149                                             const char *path,
150                                             svn_revnum_t revision,
151                                             apr_pool_t *pool);
152 
153 /* thunked dir_delta authz read function. */
154 svn_error_t *svn_swig_pl_thunk_authz_func(svn_boolean_t *allowed,
155                                           svn_fs_root_t *root,
156                                           const char *path,
157                                           void *baton,
158                                           apr_pool_t *pool);
159 
160 /* ra callbacks. */
161 svn_error_t *svn_swig_pl_make_callbacks(svn_ra_callbacks_t **cb,
162                                         void **c_baton,
163                                         SV *perl_callbacks,
164                                         apr_pool_t *pool);
165 
166 /* thunked gnome_keyring_unlock_prompt callback function */
167 svn_error_t *svn_swig_pl_thunk_gnome_keyring_unlock_prompt(char **keyring_password,
168                                                            const char *keyring_name,
169                                                            void *baton,
170                                                            apr_pool_t *pool);
171 /* thunked simple_prompt callback function */
172 svn_error_t *svn_swig_pl_thunk_simple_prompt(svn_auth_cred_simple_t **cred,
173                                              void *baton,
174                                              const char *realm,
175                                              const char *username,
176                                              svn_boolean_t may_save,
177                                              apr_pool_t *pool);
178 
179 /* thunked username_prompt callback function */
180 svn_error_t *svn_swig_pl_thunk_username_prompt(svn_auth_cred_username_t **cred,
181                                                void *baton,
182                                                const char *realm,
183                                                svn_boolean_t may_save,
184                                                apr_pool_t *pool);
185 
186 /* thunked ssl_server_trust_prompt callback function */
187 svn_error_t *svn_swig_pl_thunk_ssl_server_trust_prompt
188   (svn_auth_cred_ssl_server_trust_t **cred,
189    void *baton,
190    const char *realm,
191    apr_uint32_t failures,
192    const svn_auth_ssl_server_cert_info_t *cert_info,
193    svn_boolean_t may_save,
194    apr_pool_t *pool);
195 
196 /* thunked ssl_client_cert callback function */
197 svn_error_t *svn_swig_pl_thunk_ssl_client_cert_prompt
198   (svn_auth_cred_ssl_client_cert_t **cred,
199    void *baton,
200    const char *realm,
201    svn_boolean_t may_save,
202    apr_pool_t *pool);
203 
204 /* thunked ssl_client_cert_pw callback function */
205 svn_error_t *svn_swig_pl_thunk_ssl_client_cert_pw_prompt
206   (svn_auth_cred_ssl_client_cert_pw_t **cred,
207    void *baton,
208    const char *realm,
209    svn_boolean_t may_save,
210    apr_pool_t *pool);
211 
212 /* Thunked version of svn_wc_notify_func_t callback type */
213 void svn_swig_pl_notify_func(void * baton,
214                              const char *path,
215                              svn_wc_notify_action_t action,
216                              svn_node_kind_t kind,
217                              const char *mime_type,
218                              svn_wc_notify_state_t content_state,
219                              svn_wc_notify_state_t prop_state,
220                              svn_revnum_t revision);
221 
222 
223 /* Thunked version of svn_client_get_commit_log3_t callback type. */
224 svn_error_t *svn_swig_pl_get_commit_log_func(const char **log_msg,
225                                              const char **tmp_file,
226                                              const apr_array_header_t *
227                                              commit_items,
228                                              void *baton,
229                                              apr_pool_t *pool);
230 
231 /* Thunked version of svn_client_info_t callback type. */
232 svn_error_t *svn_swig_pl_info_receiver(void *baton,
233                                        const char *path,
234                                        const svn_info_t *info,
235                                        apr_pool_t *pool);
236 
237 /* Thunked version of svn_wc_cancel_func_t callback type. */
238 svn_error_t *svn_swig_pl_cancel_func(void *cancel_baton);
239 
240 /* Thunked version of svn_wc_status_func_t callback type. */
241 void svn_swig_pl_status_func(void *baton,
242                              const char *path,
243                              svn_wc_status_t *status);
244 
245 /* Thunked version of svn_wc_status_func2_t callback type. */
246 void svn_swig_pl_status_func2(void *baton,
247                               const char *path,
248                               svn_wc_status2_t *status);
249 
250 /* Thunked version of svn_wc_status_func2_t callback type. */
251 svn_error_t *svn_swig_pl_status_func3(void *baton,
252                                       const char *path,
253                                       svn_wc_status2_t *status,
254                                       apr_pool_t *pool);
255 
256 /* Thunked version of svn_client_blame_receiver_t callback type. */
257 svn_error_t *svn_swig_pl_blame_func(void *baton,
258                                     apr_int64_t line_no,
259                                     svn_revnum_t revision,
260                                     const char *author,
261                                     const char *date,
262                                     const char *line,
263                                     apr_pool_t *pool);
264 
265 /* Thunked config enumerator */
266 svn_boolean_t svn_swig_pl_thunk_config_enumerator(const char *name, const char *value, void *baton);
267 
268 /* helper for making the editor */
269 void svn_swig_pl_make_editor(svn_delta_editor_t **editor,
270                              void **edit_baton,
271                              SV *perl_editor,
272                              apr_pool_t *pool);
273 
274 /* svn_stream_t helpers */
275 svn_error_t *svn_swig_pl_make_stream(svn_stream_t **stream, SV *obj);
276 SV *svn_swig_pl_from_stream(svn_stream_t *stream);
277 
278 /* apr_file_t * */
279 apr_file_t *svn_swig_pl_make_file(SV *file, apr_pool_t *pool);
280 
281 void svn_swig_pl_hold_ref_in_pool(apr_pool_t *pool, SV *sv);
282 
283 /* md5 access class */
284 SV *svn_swig_pl_from_md5(unsigned char *digest);
285 
286 svn_error_t *svn_swig_pl_ra_lock_callback(void *baton,
287                                           const char *path,
288                                           svn_boolean_t do_lock,
289                                           const svn_lock_t *lock,
290                                           svn_error_t *ra_err,
291                                           apr_pool_t *pool);
292 
293 #ifdef __cplusplus
294 }
295 #endif /* __cplusplus */
296 
297 #endif  /* SVN_SWIG_SWIGUTIL_PL_H */
298