~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/bindings/swig/perl/libsvn_swig_perl/swigutil_pl.c

  • Committer: Package Import Robot
  • Author(s): James McCoy, Peter Samuelson, James McCoy
  • Date: 2014-01-12 19:48:33 UTC
  • mfrom: (0.2.10)
  • Revision ID: package-import@ubuntu.com-20140112194833-w3axfwksn296jn5x
Tags: 1.8.5-1
[ Peter Samuelson ]
* New upstream release.  (Closes: #725787) Rediff patches:
  - Remove apr-abi1 (applied upstream), rename apr-abi2 to apr-abi
  - Remove loosen-sqlite-version-check (shouldn't be needed)
  - Remove java-osgi-metadata (applied upstream)
  - svnmucc prompts for a changelog if none is provided. (Closes: #507430)
  - Remove fix-bdb-version-detection, upstream uses "apu-config --dbm-libs"
  - Remove ruby-test-wc (applied upstream)
  - Fix “svn diff -r N file” when file has svn:mime-type set.
    (Closes: #734163)
  - Support specifying an encoding for mod_dav_svn's environment in which
    hooks are run.  (Closes: #601544)
  - Fix ordering of “svnadmin dump” paths with certain APR versions.
    (Closes: #687291)
  - Provide a better error message when authentication fails with an
    svn+ssh:// URL.  (Closes: #273874)
  - Updated Polish translations.  (Closes: #690815)

[ James McCoy ]
* Remove all traces of libneon, replaced by libserf.
* patches/sqlite_3.8.x_workaround: Upstream fix for wc-queries-test test
  failurse.
* Run configure with --with-apache-libexecdir, which allows removing part of
  patches/rpath.
* Re-enable auth-test as upstream has fixed the problem of picking up
  libraries from the environment rather than the build tree.
  (Closes: #654172)
* Point LD_LIBRARY_PATH at the built auth libraries when running the svn
  command during the build.  (Closes: #678224)
* Add a NEWS entry describing how to configure mod_dav_svn to understand
  UTF-8.  (Closes: #566148)
* Remove ancient transitional package, libsvn-ruby.
* Enable compatibility with Sqlite3 versions back to Wheezy.
* Enable hardening flags.  (Closes: #734918)
* patches/build-fixes: Enable verbose build logs.
* Build against the default ruby version.  (Closes: #722393)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <perl.h>
30
30
#include <XSUB.h>
31
31
 
 
32
/* Perl defines a _ macro, but SVN uses it for translations.
 
33
 * So undefine _ after including the Perl headers. */
 
34
#undef _
 
35
 
32
36
#include <stdarg.h>
33
37
#ifdef WIN32
34
38
#include <io.h>
35
39
#endif
36
40
 
 
41
#include "svn_hash.h"
37
42
#include "svn_pools.h"
38
43
#include "svn_opt.h"
 
44
#include "svn_time.h"
39
45
#include "svn_private_config.h"
40
46
 
41
47
#include "swig_perl_external_runtime.swg"
96
102
  return (void *)result;
97
103
}
98
104
 
 
105
static void *convert_pl_svn_string_t(SV *value, void *dummy, apr_pool_t *pool)
 
106
{
 
107
    svn_string_t *result = apr_palloc(pool, sizeof(svn_string_t));
 
108
    /* just the in typemap for svn_string_t */
 
109
    result->data = SvPV(value, result->len);
 
110
    return (void *)result;
 
111
}
 
112
 
 
113
/* Convert a revision range and return a svn_opt_revision_range_t*.
 
114
 * Value can be:
 
115
 * - a _p_svn_opt_revision_range_t object
 
116
 * - a reference to a two-element array, [start, end],
 
117
 *   where start and end is anything accepted by svn_swig_pl_set_revision
 
118
 * If value is not acceptable and *(svn_boolean_t *)ctx is FALSE,
 
119
 * convert_pl_revision_range returns NULL, otherwise it croak()s.
 
120
 */
 
121
static void *convert_pl_revision_range(SV *value, void *ctx, apr_pool_t *pool)
 
122
{
 
123
    svn_boolean_t croak_on_error = *(svn_boolean_t *)ctx;
 
124
 
 
125
    if (sv_isobject(value) && sv_derived_from(value, "_p_svn_opt_revision_range_t")) {
 
126
        svn_opt_revision_range_t *range;
 
127
        /* this will assign to range */
 
128
        SWIG_ConvertPtr(value, (void **)&range, _SWIG_TYPE("svn_opt_revision_range_t *"), 0);
 
129
        return range;
 
130
    } 
 
131
 
 
132
    if (SvROK(value) 
 
133
        && SvTYPE(SvRV(value)) == SVt_PVAV
 
134
        && av_len((AV *)SvRV(value)) == 1) {    
 
135
        /* value is a two-element ARRAY */
 
136
        AV* array = (AV *)SvRV(value);
 
137
        svn_opt_revision_t temp_start, temp_end;
 
138
        svn_opt_revision_t *start, *end;
 
139
        svn_opt_revision_range_t *range;
 
140
 
 
141
        /* Note: Due to how svn_swig_pl_set_revision works,
 
142
         * either the passed in svn_opt_revision_t is modified
 
143
         * (and the original pointer returned) or a different pointer 
 
144
         * is returned. svn_swig_pl_set_revision may return NULL
 
145
         * only if croak_on_error is FALSE.
 
146
         */
 
147
        start = svn_swig_pl_set_revision(&temp_start, 
 
148
                                         *av_fetch(array, 0, 0), croak_on_error);
 
149
        if (start == NULL)
 
150
            return NULL;
 
151
        end = svn_swig_pl_set_revision(&temp_end, 
 
152
                                       *av_fetch(array, 1, 0), croak_on_error);
 
153
        if (end == NULL)
 
154
            return NULL;
 
155
 
 
156
        /* allocate a new range and copy in start and end fields */
 
157
        range = apr_palloc(pool, sizeof(*range));
 
158
        range->start = *start;
 
159
        range->end = *end;
 
160
        return range;
 
161
    } 
 
162
 
 
163
    if (croak_on_error)
 
164
        croak("unknown revision range: "
 
165
              "must be an array of length 2 whose elements are acceptable "
 
166
              "as opt_revision_t or a _p_svn_opt_revision_range_t object");
 
167
    return NULL;
 
168
}
 
169
 
99
170
/* perl -> c hash convertors */
100
171
static apr_hash_t *svn_swig_pl_to_hash(SV *source,
101
172
                                       pl_element_converter_t cv,
116
187
    while (cnt--) {
117
188
        SV* item = hv_iternextsv(h, &key, &retlen);
118
189
        void *val = cv(item, ctx, pool);
119
 
        apr_hash_set(hash, apr_pstrmemdup(pool, key, retlen), retlen, val);
 
190
        svn_hash_sets(hash, apr_pstrmemdup(pool, key, retlen), val);
120
191
    }
121
192
 
122
193
    return hash;
154
225
                             NULL, pool);
155
226
}
156
227
 
 
228
apr_hash_t *svn_swig_pl_hash_to_prophash(SV *source, apr_pool_t *pool)
 
229
{
 
230
  return svn_swig_pl_to_hash(source, convert_pl_svn_string_t, NULL, pool);
 
231
}
 
232
 
157
233
/* perl -> c array convertors */
158
234
static const
159
235
apr_array_header_t *svn_swig_pl_to_array(SV *source,
202
278
                              tinfo, pool);
203
279
}
204
280
 
 
281
/* Convert a single revision range or an array of revisions ranges
 
282
 * Note: We can't simply use svn_swig_pl_to_array() as is, since 
 
283
 * it immediatley checks whether source is an array reference and then
 
284
 * proceeds to treat this as the "array of ..." case. But a revision range
 
285
 * may be specified as a (two-element) array. Hence we first try to
 
286
 * convert source as a single revision range. Failing that and if it's
 
287
 * an array we then call svn_swig_pl_to_array(). Otherwise we croak().
 
288
 */
 
289
const apr_array_header_t *svn_swig_pl_array_to_apr_array_revision_range(
 
290
        SV *source, apr_pool_t *pool)
 
291
{
 
292
    svn_boolean_t croak_on_error = FALSE;
 
293
    svn_opt_revision_range_t *range;
 
294
 
 
295
    if (range = convert_pl_revision_range(source, &croak_on_error, pool)) {
 
296
        apr_array_header_t *temp = apr_array_make(pool, 1, 
 
297
                                                  sizeof(svn_opt_revision_range_t *));
 
298
        temp->nelts = 1;
 
299
        APR_ARRAY_IDX(temp, 0, svn_opt_revision_range_t *) = range;
 
300
        return temp;
 
301
    }
 
302
 
 
303
    if (SvROK(source) && SvTYPE(SvRV(source)) == SVt_PVAV) {
 
304
        croak_on_error = TRUE;
 
305
        return svn_swig_pl_to_array(source, convert_pl_revision_range, 
 
306
                                    &croak_on_error, pool);
 
307
    }
 
308
 
 
309
    croak("must pass a single revision range or a reference to an array of revision ranges");
 
310
 
 
311
    /* This return is actually unreachable because of the croak above,
 
312
     * however, Visual Studio's compiler doesn't like if all paths don't have
 
313
     * a return and errors out otherwise. */ 
 
314
    return NULL;
 
315
}
 
316
 
205
317
/* element convertors for c -> perl */
206
318
typedef SV *(*element_converter_t)(void *value, void *ctx);
207
319
 
229
341
  return sv_2mortal(newSViv(value));
230
342
}
231
343
 
 
344
static SV *convert_svn_revnum_t(svn_revnum_t revnum, void *dummy)
 
345
{
 
346
  return sv_2mortal(newSViv((long int)revnum));
 
347
 
 
348
}
 
349
 
232
350
/* c -> perl hash convertors */
233
351
static SV *convert_hash(apr_hash_t *hash, element_converter_t converter_func,
234
352
                        void *ctx)
301
419
                       tinfo);
302
420
}
303
421
 
 
422
SV *svn_swig_pl_revnums_to_list(const apr_array_header_t *array)
 
423
{
 
424
    return convert_array(array, (element_converter_t)convert_svn_revnum_t,
 
425
                         NULL);
 
426
}
 
427
 
 
428
/* perl -> c svn_opt_revision_t conversion */
 
429
svn_opt_revision_t *svn_swig_pl_set_revision(svn_opt_revision_t *rev, 
 
430
                                             SV *source, 
 
431
                                             svn_boolean_t croak_on_error)
 
432
{
 
433
#define maybe_croak(argv) do { if (croak_on_error) croak argv; \
 
434
                               else return NULL; } while (0)
 
435
 
 
436
    if (source == NULL || source == &PL_sv_undef || !SvOK(source)) {
 
437
        rev->kind = svn_opt_revision_unspecified;
 
438
    }
 
439
    else if (sv_isobject(source) && sv_derived_from(source, "_p_svn_opt_revision_t")) {
 
440
        /* this will assign to rev */
 
441
        SWIG_ConvertPtr(source, (void **)&rev, _SWIG_TYPE("svn_opt_revision_t *"), 0);
 
442
    }
 
443
    else if (looks_like_number(source)) {
 
444
        rev->kind = svn_opt_revision_number;
 
445
        rev->value.number = SvIV(source);
 
446
    }
 
447
    else if (SvPOK(source)) {
 
448
        char *input = SvPV_nolen(source);
 
449
        if (svn_cstring_casecmp(input, "BASE") == 0)
 
450
            rev->kind = svn_opt_revision_base;
 
451
        else if (svn_cstring_casecmp(input, "HEAD") == 0)
 
452
            rev->kind = svn_opt_revision_head;
 
453
        else if (svn_cstring_casecmp(input, "WORKING") == 0)
 
454
            rev->kind = svn_opt_revision_working;
 
455
        else if (svn_cstring_casecmp(input, "COMMITTED") == 0)
 
456
            rev->kind = svn_opt_revision_committed;
 
457
        else if (svn_cstring_casecmp(input, "PREV") == 0)
 
458
            rev->kind = svn_opt_revision_previous;
 
459
        else if (*input == '{') {
 
460
            svn_boolean_t matched;
 
461
            apr_time_t tm;
 
462
            svn_error_t *err;
 
463
 
 
464
            char *end = strchr(input,'}');
 
465
            if (!end)
 
466
                maybe_croak(("unknown opt_revision_t string \"%s\": "
 
467
                             "missing closing brace for \"{DATE}\"", input));
 
468
            *end = '\0';
 
469
            err = svn_parse_date (&matched, &tm, input + 1, apr_time_now(),
 
470
                                  svn_swig_pl_make_pool ((SV *)NULL));
 
471
            if (err) {
 
472
                svn_error_clear (err);
 
473
                maybe_croak(("unknown opt_revision_t string \"{%s}\": "
 
474
                             "internal svn_parse_date error", input + 1));
 
475
            }
 
476
            if (!matched)
 
477
                maybe_croak(("unknown opt_revision_t string \"{%s}\": "
 
478
                             "svn_parse_date failed to parse it", input + 1));
 
479
 
 
480
            rev->kind = svn_opt_revision_date;
 
481
            rev->value.date = tm;
 
482
        } else
 
483
            maybe_croak(("unknown opt_revision_t string \"%s\": must be one of "
 
484
                         "\"BASE\", \"HEAD\", \"WORKING\", \"COMMITTED\", "
 
485
                         "\"PREV\" or a \"{DATE}\"", input));
 
486
    } else
 
487
        maybe_croak(("unknown opt_revision_t type: must be undef, a number, "
 
488
                     "a string (one of \"BASE\", \"HEAD\", \"WORKING\", "
 
489
                     "\"COMMITTED\", \"PREV\" or a \"{DATE}\") "
 
490
                     "or a _p_svn_opt_revision_t object"));
 
491
 
 
492
    return rev;
 
493
#undef maybe_croak
 
494
}
 
495
 
304
496
/* put the va_arg in stack and invoke caller_func with func.
305
497
   fmt:
306
498
   * O: perl object
835
1027
    return SVN_NO_ERROR;
836
1028
}
837
1029
 
 
1030
svn_error_t *svn_swig_pl_thunk_log_entry_receiver(void *baton,
 
1031
                                                  svn_log_entry_t *log_entry,
 
1032
                                                  apr_pool_t *pool)
 
1033
{
 
1034
    SV *receiver = baton;
 
1035
 
 
1036
    if (!SvOK(receiver))
 
1037
        return SVN_NO_ERROR;
 
1038
 
 
1039
    svn_swig_pl_callback_thunk(CALL_SV,
 
1040
                               receiver, NULL,
 
1041
                               "SS", 
 
1042
                               log_entry, _SWIG_TYPE("svn_log_entry_t *"),
 
1043
                               pool, POOLINFO);
 
1044
 
 
1045
    return SVN_NO_ERROR;
 
1046
}
 
1047
 
838
1048
svn_error_t * svn_swig_pl_thunk_client_diff_summarize_func(
839
1049
                     const svn_client_diff_summarize_t *diff,
840
1050
                     void *baton,
907
1117
    return SVN_NO_ERROR;
908
1118
}
909
1119
 
 
1120
svn_error_t *svn_swig_pl_thunk_commit_callback2(const svn_commit_info_t *commit_info,
 
1121
                                                void *baton,
 
1122
                                                apr_pool_t *pool)
 
1123
{
 
1124
    if (!SvOK((SV *)baton))
 
1125
        return SVN_NO_ERROR;
 
1126
 
 
1127
    svn_swig_pl_callback_thunk(CALL_SV, baton, NULL,
 
1128
                               "SS",
 
1129
                               commit_info, _SWIG_TYPE("svn_commit_info_t *"),
 
1130
                               pool, POOLINFO);
 
1131
 
 
1132
    return SVN_NO_ERROR;
 
1133
}
 
1134
 
 
1135
 
910
1136
/* Wrap RA */
911
1137
 
912
1138
static svn_error_t * thunk_open_tmp_file(apr_file_t **fp,
984
1210
    return SVN_NO_ERROR;
985
1211
}
986
1212
 
 
1213
svn_error_t *svn_swig_pl_thunk_gnome_keyring_unlock_prompt(char **keyring_password,
 
1214
                                                           const char *keyring_name,
 
1215
                                                           void *baton,
 
1216
                                                           apr_pool_t *pool)
 
1217
{
 
1218
    SV *result;
 
1219
    STRLEN len;
 
1220
    /* The baton is the actual prompt function passed from perl, so we
 
1221
     * call that one and process the result. */
 
1222
    svn_swig_pl_callback_thunk(CALL_SV,
 
1223
                               baton, &result,
 
1224
                               "sS", keyring_name,
 
1225
                               pool, POOLINFO);
 
1226
    if (!SvOK(result) || result == &PL_sv_undef) {
 
1227
        *keyring_password = NULL;
 
1228
    }
 
1229
    else if (SvPOK(result)) {
 
1230
        *keyring_password = apr_pstrdup(pool, SvPV(result, len));
 
1231
    }
 
1232
    else {
 
1233
        SvREFCNT_dec(result);
 
1234
        croak("not a string");
 
1235
    }
 
1236
 
 
1237
    SvREFCNT_dec(result);
 
1238
    return SVN_NO_ERROR;
 
1239
}
 
1240
 
987
1241
svn_error_t *svn_swig_pl_thunk_simple_prompt(svn_auth_cred_simple_t **cred,
988
1242
                                             void *baton,
989
1243
                                             const char *realm,
1260
1514
 
1261
1515
}
1262
1516
 
 
1517
/* Thunked version of svn_wc_status_func2_t callback type. */
 
1518
void svn_swig_pl_status_func2(void *baton,
 
1519
                              const char *path,
 
1520
                              svn_wc_status2_t *status)
 
1521
{
 
1522
  swig_type_info *statusinfo = _SWIG_TYPE("svn_wc_status2 _t *");
 
1523
 
 
1524
  if (!SvOK((SV *)baton)) {
 
1525
    return;
 
1526
  }
 
1527
 
 
1528
  svn_swig_pl_callback_thunk(CALL_SV, baton, NULL, "sS",
 
1529
                             path, status, statusinfo);
 
1530
 
 
1531
}
 
1532
 
 
1533
/* Thunked version of svn_wc_status_func3_t callback type. */
 
1534
svn_error_t *svn_swig_pl_status_func3(void *baton,
 
1535
                                      const char *path,
 
1536
                                      svn_wc_status2_t *status,
 
1537
                                      apr_pool_t *pool)
 
1538
{
 
1539
  SV *result;
 
1540
  svn_error_t *ret_val = SVN_NO_ERROR;
 
1541
 
 
1542
  swig_type_info *statusinfo = _SWIG_TYPE("svn_wc_status2 _t *");
 
1543
 
 
1544
  if (!SvOK((SV *)baton)) {
 
1545
    return ret_val;
 
1546
  }
 
1547
 
 
1548
  svn_swig_pl_callback_thunk(CALL_SV, baton, &result, "sSS",
 
1549
                             path, status, statusinfo,
 
1550
                             pool, POOLINFO);
 
1551
 
 
1552
  if (sv_derived_from(result, "_p_svn_error_t")) {
 
1553
    swig_type_info *errorinfo = _SWIG_TYPE("svn_error_t *");
 
1554
    if (SWIG_ConvertPtr(result, (void *)&ret_val, errorinfo, 0) < 0) {
 
1555
        SvREFCNT_dec(result);
 
1556
        croak("Unable to convert from SWIG Type");
 
1557
    }
 
1558
  }
 
1559
 
 
1560
  SvREFCNT_dec(result);
 
1561
  return ret_val;
 
1562
}
 
1563
 
 
1564
 
1263
1565
/* Thunked version of svn_client_blame_receiver_t callback type. */
1264
1566
svn_error_t *svn_swig_pl_blame_func(void *baton,
1265
1567
                                    apr_int64_t line_no,