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

« back to all changes in this revision

Viewing changes to subversion/libsvn_subr/skel.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:
23
23
#include <string.h>
24
24
#include "svn_string.h"
25
25
#include "svn_error.h"
 
26
#include "svn_props.h"
 
27
#include "svn_pools.h"
26
28
#include "private/svn_skel.h"
 
29
#include "private/svn_string_private.h"
27
30
 
28
31
 
29
32
/* Parsing skeletons.  */
135
138
    }
136
139
}
137
140
 
138
 
/* Store the ASCII decimal representation of VALUE at DATA.  Return
139
 
   the length of the representation if all goes well; return zero if
140
 
   the result doesn't fit in LEN bytes.  */
141
 
static int
142
 
putsize(char *data, apr_size_t len, apr_size_t value)
143
 
{
144
 
  apr_size_t i = 0;
145
 
 
146
 
  /* Generate the digits, least-significant first.  */
147
 
  do
148
 
    {
149
 
      if (i >= len)
150
 
        return 0;
151
 
 
152
 
      data[i] = (value % 10) + '0';
153
 
      value /= 10;
154
 
      i++;
155
 
    }
156
 
  while (value > 0);
157
 
 
158
 
  /* Put the digits in most-significant-first order.  */
159
 
  {
160
 
    int left, right;
161
 
 
162
 
    for (left = 0, right = i-1; left < right; left++, right--)
163
 
      {
164
 
        char t = data[left];
165
 
        data[left] = data[right];
166
 
        data[right] = t;
167
 
      }
168
 
  }
169
 
 
170
 
  return i;
171
 
}
172
 
 
173
141
 
174
142
/* Checking validity of skels. */
175
143
static svn_error_t *
201
169
  return FALSE;
202
170
}
203
171
 
 
172
static svn_boolean_t
 
173
is_valid_iproplist_skel(const svn_skel_t *skel)
 
174
{
 
175
  int len = svn_skel__list_length(skel);
 
176
 
 
177
  if ((len >= 0) && (len & 1) == 0)
 
178
    {
 
179
      svn_skel_t *elt;
 
180
 
 
181
      for (elt = skel->children; elt; elt = elt->next)
 
182
        {
 
183
          if (!elt->is_atom)
 
184
            return FALSE;
 
185
 
 
186
          if (elt->next == NULL)
 
187
            return FALSE;
 
188
 
 
189
          elt = elt->next;
 
190
 
 
191
          if (! is_valid_proplist_skel(elt))
 
192
            return FALSE;
 
193
        }
 
194
 
 
195
      return TRUE;
 
196
    }
 
197
 
 
198
  return FALSE;
 
199
}
 
200
 
204
201
 
205
202
static svn_skel_t *parse(const char *data, apr_size_t len,
206
203
                         apr_pool_t *pool);
401
398
 
402
399
static apr_size_t estimate_unparsed_size(const svn_skel_t *skel);
403
400
static svn_stringbuf_t *unparse(const svn_skel_t *skel,
404
 
                                svn_stringbuf_t *str,
405
 
                                apr_pool_t *pool);
 
401
                                svn_stringbuf_t *str);
406
402
 
407
403
 
408
404
svn_stringbuf_t *
409
405
svn_skel__unparse(const svn_skel_t *skel, apr_pool_t *pool)
410
406
{
411
 
  svn_stringbuf_t *str;
412
 
 
413
 
  /* Allocate a string to hold the data.  */
414
 
  str = apr_palloc(pool, sizeof(*str));
415
 
  str->pool = pool;
416
 
  str->blocksize = estimate_unparsed_size(skel) + 200;
417
 
  str->data = apr_palloc(pool, str->blocksize);
418
 
  str->len = 0;
419
 
 
420
 
  return unparse(skel, str, pool);
 
407
  svn_stringbuf_t *str
 
408
    = svn_stringbuf_create_ensure(estimate_unparsed_size(skel) + 200, pool);
 
409
 
 
410
  return unparse(skel, str);
421
411
}
422
412
 
423
413
 
440
430
    }
441
431
  else
442
432
    {
443
 
      int total_len;
 
433
      apr_size_t total_len;
444
434
      svn_skel_t *child;
445
435
 
446
436
      /* Allow space for opening and closing parens, and a space
486
476
}
487
477
 
488
478
 
489
 
/* Append the concrete representation of SKEL to the string STR.
490
 
   Grow S with new space from POOL as necessary.  */
 
479
/* Append the concrete representation of SKEL to the string STR. */
491
480
static svn_stringbuf_t *
492
 
unparse(const svn_skel_t *skel, svn_stringbuf_t *str, apr_pool_t *pool)
 
481
unparse(const svn_skel_t *skel, svn_stringbuf_t *str)
493
482
{
494
483
  if (skel->is_atom)
495
484
    {
498
487
        svn_stringbuf_appendbytes(str, skel->data, skel->len);
499
488
      else
500
489
        {
501
 
          /* Append the length to STR.  */
502
 
          char buf[200];
503
 
          int length_len;
 
490
          /* Append the length to STR.  Ensure enough space for at least
 
491
           * one 64 bit int. */
 
492
          char buf[200 + SVN_INT64_BUFFER_SIZE];
 
493
          apr_size_t length_len;
504
494
 
505
 
          length_len = putsize(buf, sizeof(buf), skel->len);
 
495
          length_len = svn__ui64toa(buf, skel->len);
506
496
 
507
497
          SVN_ERR_ASSERT_NO_RETURN(length_len > 0);
508
498
 
510
500
             atom's contents.  */
511
501
          svn_stringbuf_ensure(str, str->len + length_len + 1 + skel->len);
512
502
          svn_stringbuf_appendbytes(str, buf, length_len);
513
 
          str->data[str->len++] = ' ';
 
503
          svn_stringbuf_appendbyte(str, ' ');
514
504
          svn_stringbuf_appendbytes(str, skel->data, skel->len);
515
505
        }
516
506
    }
517
507
  else
518
508
    {
519
 
      /* Append a list to STR.  */
 
509
      /* Append a list to STR: an opening parenthesis, the list elements
 
510
       * separated by a space, and a closing parenthesis.  */
520
511
      svn_skel_t *child;
521
512
 
522
 
      /* Emit an opening parenthesis.  */
523
 
      svn_stringbuf_ensure(str, str->len + 1);
524
 
      str->data[str->len++] = '(';
 
513
      svn_stringbuf_appendbyte(str, '(');
525
514
 
526
 
      /* Append each element.  Emit a space between each pair of elements.  */
527
515
      for (child = skel->children; child; child = child->next)
528
516
        {
529
 
          unparse(child, str, pool);
 
517
          unparse(child, str);
530
518
          if (child->next)
531
 
            {
532
 
              svn_stringbuf_ensure(str, str->len + 1);
533
 
              str->data[str->len++] = ' ';
534
 
            }
 
519
            svn_stringbuf_appendbyte(str, ' ');
535
520
        }
536
521
 
537
 
      /* Emit a closing parenthesis.  */
538
522
      svn_stringbuf_appendbyte(str, ')');
539
523
    }
540
524
 
579
563
  return skel;
580
564
}
581
565
 
 
566
svn_skel_t *svn_skel__dup(const svn_skel_t *src_skel, svn_boolean_t dup_data,
 
567
                          apr_pool_t *result_pool)
 
568
{
 
569
  svn_skel_t *skel = apr_pmemdup(result_pool, src_skel, sizeof(svn_skel_t));
 
570
 
 
571
  if (dup_data && skel->data)
 
572
    {
 
573
      if (skel->is_atom)
 
574
        skel->data = apr_pmemdup(result_pool, skel->data, skel->len);
 
575
      else
 
576
        {
 
577
          /* When creating a skel this would be NULL, 0 for a list.
 
578
             When parsing a string to a skel this might point to real data
 
579
             delimiting the sublist. We don't copy that from here. */
 
580
          skel->data = NULL;
 
581
          skel->len = 0;
 
582
        }
 
583
    }
 
584
 
 
585
  if (skel->children)
 
586
    skel->children = svn_skel__dup(skel->children, dup_data, result_pool);
 
587
 
 
588
  if (skel->next)
 
589
    skel->next = svn_skel__dup(skel->next, dup_data, result_pool);
 
590
 
 
591
  return skel;
 
592
}
582
593
 
583
594
void
584
595
svn_skel__prepend(svn_skel_t *skel, svn_skel_t *list_skel)
596
607
                           svn_skel_t *skel,
597
608
                           apr_pool_t *result_pool)
598
609
{
599
 
  const char *str = apr_psprintf(result_pool, "%" APR_INT64_T_FMT, value);
 
610
  char *val_string = apr_palloc(result_pool, SVN_INT64_BUFFER_SIZE);
 
611
  svn__i64toa(val_string, value);
600
612
 
601
 
  svn_skel__prepend_str(str, skel, result_pool);
 
613
  svn_skel__prepend_str(val_string, skel, result_pool);
602
614
}
603
615
 
604
616
 
708
720
  return SVN_NO_ERROR;
709
721
}
710
722
 
 
723
svn_error_t *
 
724
svn_skel__parse_iprops(apr_array_header_t **iprops,
 
725
                       const svn_skel_t *skel,
 
726
                       apr_pool_t *result_pool)
 
727
{
 
728
  svn_skel_t *elt;
 
729
 
 
730
  /* Validate the skel. */
 
731
  if (! is_valid_iproplist_skel(skel))
 
732
    return skel_err("iprops");
 
733
 
 
734
  /* Create the returned structure */
 
735
  *iprops = apr_array_make(result_pool, 1,
 
736
                           sizeof(svn_prop_inherited_item_t *));
 
737
 
 
738
  for (elt = skel->children; elt; elt = elt->next->next)
 
739
    {
 
740
      svn_prop_inherited_item_t *new_iprop = apr_palloc(result_pool,
 
741
                                                        sizeof(*new_iprop));
 
742
      svn_string_t *repos_parent = svn_string_ncreate(elt->data, elt->len,
 
743
                                                      result_pool);
 
744
      SVN_ERR(svn_skel__parse_proplist(&(new_iprop->prop_hash), elt->next,
 
745
                                       result_pool));
 
746
      new_iprop->path_or_url = repos_parent->data;
 
747
      APR_ARRAY_PUSH(*iprops, svn_prop_inherited_item_t *) = new_iprop;
 
748
    }
 
749
  return SVN_NO_ERROR;
 
750
}
711
751
 
712
752
svn_error_t *
713
753
svn_skel__parse_prop(svn_string_t **propval,
744
784
 
745
785
svn_error_t *
746
786
svn_skel__unparse_proplist(svn_skel_t **skel_p,
747
 
                           apr_hash_t *proplist,
 
787
                           const apr_hash_t *proplist,
748
788
                           apr_pool_t *pool)
749
789
{
750
790
  svn_skel_t *skel = svn_skel__make_empty_list(pool);
754
794
  if (proplist)
755
795
    {
756
796
      /* Loop over hash entries */
757
 
      for (hi = apr_hash_first(pool, proplist); hi; hi = apr_hash_next(hi))
 
797
      for (hi = apr_hash_first(pool, (apr_hash_t *)proplist); hi;
 
798
           hi = apr_hash_next(hi))
758
799
        {
759
800
          const void *key;
760
801
          void *val;
779
820
  *skel_p = skel;
780
821
  return SVN_NO_ERROR;
781
822
}
 
823
 
 
824
svn_error_t *
 
825
svn_skel__unparse_iproplist(svn_skel_t **skel_p,
 
826
                            const apr_array_header_t *inherited_props,
 
827
                            apr_pool_t *result_pool,
 
828
                            apr_pool_t *scratch_pool)
 
829
{
 
830
  svn_skel_t *skel = svn_skel__make_empty_list(result_pool);
 
831
 
 
832
  /* Create the skel. */
 
833
  if (inherited_props)
 
834
    {
 
835
      int i;
 
836
      apr_hash_index_t *hi;
 
837
 
 
838
      for (i = 0; i < inherited_props->nelts; i++)
 
839
        {
 
840
          svn_prop_inherited_item_t *iprop =
 
841
            APR_ARRAY_IDX(inherited_props, i, svn_prop_inherited_item_t *);
 
842
 
 
843
          svn_skel_t *skel_list = svn_skel__make_empty_list(result_pool);
 
844
          svn_skel_t *skel_atom;
 
845
 
 
846
          /* Loop over hash entries */
 
847
          for (hi = apr_hash_first(scratch_pool, iprop->prop_hash);
 
848
               hi;
 
849
               hi = apr_hash_next(hi))
 
850
            {
 
851
              const void *key;
 
852
              void *val;
 
853
              apr_ssize_t klen;
 
854
              svn_string_t *value;
 
855
 
 
856
              apr_hash_this(hi, &key, &klen, &val);
 
857
              value = val;
 
858
 
 
859
              /* VALUE */
 
860
              svn_skel__prepend(svn_skel__mem_atom(value->data, value->len,
 
861
                                                   result_pool), skel_list);
 
862
 
 
863
              /* NAME */
 
864
              svn_skel__prepend(svn_skel__mem_atom(key, klen, result_pool),
 
865
                                skel_list);
 
866
            }
 
867
 
 
868
          skel_atom = svn_skel__str_atom(
 
869
            apr_pstrdup(result_pool, iprop->path_or_url), result_pool);
 
870
          svn_skel__append(skel, skel_atom);
 
871
          svn_skel__append(skel, skel_list);
 
872
        }
 
873
    }
 
874
 
 
875
  /* Validate and return the skel. */
 
876
  if (! is_valid_iproplist_skel(skel))
 
877
    return skel_err("iproplist");
 
878
 
 
879
  *skel_p = skel;
 
880
  return SVN_NO_ERROR;
 
881
}