~ubuntu-branches/ubuntu/trusty/subversion/trusty-proposed

« back to all changes in this revision

Viewing changes to subversion/tests/cmdline/atomic-ra-revprop-change.c

  • Committer: Package Import Robot
  • Author(s): Andy Whitcroft
  • Date: 2012-06-21 15:36:36 UTC
  • mfrom: (0.4.13 sid)
  • Revision ID: package-import@ubuntu.com-20120621153636-amqqmuidgwgxz1ly
Tags: 1.7.5-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Create pot file on build.
  - Build a python-subversion-dbg package.
  - Build-depend on python-dbg.
  - Build-depend on default-jre-headless/-jdk.
  - Do not apply java-build patch.
  - debian/rules: Manually create the doxygen output directory, otherwise
    we get weird build failures when running parallel builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * atomic-ra-revprop-change.c :  wrapper around svn_ra_change_rev_prop2()
 
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
#include <stdlib.h>
 
25
#include <stdio.h>
 
26
 
 
27
#include <apr_pools.h>
 
28
#include <apr_general.h>
 
29
 
 
30
#include "svn_types.h"
 
31
#include "svn_pools.h"
 
32
#include "svn_dirent_uri.h"
 
33
#include "svn_ra.h"
 
34
 
 
35
#include "private/svn_skel.h"
 
36
 
 
37
#include "svn_private_config.h"
 
38
 
 
39
 
 
40
#define KEY_OLD_PROPVAL "old_value_p"
 
41
#define KEY_NEW_PROPVAL "value"
 
42
 
 
43
#define USAGE_MSG \
 
44
  "Usage: %s URL REVISION PROPNAME VALUES_SKEL HTTP_LIBRARY WANT_ERROR\n" \
 
45
  "\n" \
 
46
  "VALUES_SKEL is a proplist skel containing pseudo-properties '%s' \n" \
 
47
  "and '%s'.  A pseudo-property missing from the skel is interpreted \n" \
 
48
  "as unset.\n" \
 
49
  "\n" \
 
50
  "WANT_ERROR is 1 if the propchange is expected to fail due to the atomicity,"\
 
51
  "and 0 if it is expected to succeed.  If the expectation matches reality," \
 
52
  "the exit code shall be zero.\n"
 
53
 
 
54
 
 
55
 
 
56
/* implements svn_auth_simple_prompt_func_t */
 
57
static svn_error_t *
 
58
aborting_simple_prompt_func(svn_auth_cred_simple_t **cred,
 
59
                            void *baton,
 
60
                            const char *realm,
 
61
                            const char *username,
 
62
                            svn_boolean_t may_save,
 
63
                            apr_pool_t *pool)
 
64
{
 
65
  /* Oops, the jrandom:rayjandom we passed for SVN_AUTH_PARAM_DEFAULT_* failed,
 
66
     and the prompt provider has retried.
 
67
   */
 
68
  SVN_ERR_MALFUNCTION();
 
69
}
 
70
 
 
71
/* implements svn_auth_username_prompt_func_t */
 
72
static svn_error_t *
 
73
aborting_username_prompt_func(svn_auth_cred_username_t **cred,
 
74
                              void *baton,
 
75
                              const char *realm,
 
76
                              svn_boolean_t may_save,
 
77
                              apr_pool_t *pool)
 
78
{
 
79
  /* Oops, the jrandom:rayjandom we passed for SVN_AUTH_PARAM_DEFAULT_* failed,
 
80
     and the prompt provider has retried.
 
81
   */
 
82
  SVN_ERR_MALFUNCTION();
 
83
}
 
84
 
 
85
static svn_error_t *
 
86
construct_auth_baton(svn_auth_baton_t **auth_baton_p,
 
87
                     apr_pool_t *pool)
 
88
{
 
89
  apr_array_header_t *providers;
 
90
  svn_auth_provider_object_t *simple_provider;
 
91
  svn_auth_baton_t *auth_baton;
 
92
 
 
93
  /* A bit of dancing just to pass jrandom:rayjandom. */
 
94
  providers = apr_array_make(pool, 2, sizeof(svn_auth_provider_object_t *)),
 
95
  svn_auth_get_simple_prompt_provider(&simple_provider,
 
96
                                      aborting_simple_prompt_func, NULL,
 
97
                                      0, pool);
 
98
  APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = simple_provider;
 
99
  svn_auth_get_username_prompt_provider(&simple_provider,
 
100
                                        aborting_username_prompt_func, NULL,
 
101
                                        0, pool);
 
102
  APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = simple_provider;
 
103
  svn_auth_open(&auth_baton, providers, pool);
 
104
  svn_auth_set_parameter(auth_baton,
 
105
                         SVN_AUTH_PARAM_DEFAULT_USERNAME, "jrandom");
 
106
  svn_auth_set_parameter(auth_baton,
 
107
                         SVN_AUTH_PARAM_DEFAULT_PASSWORD, "rayjandom");
 
108
 
 
109
  *auth_baton_p = auth_baton;
 
110
  return SVN_NO_ERROR;
 
111
}
 
112
 
 
113
static svn_error_t *
 
114
construct_config(apr_hash_t **config_p,
 
115
                 const char *http_library,
 
116
                 apr_pool_t *pool)
 
117
{
 
118
  apr_hash_t *config;
 
119
  svn_config_t *servers;
 
120
 
 
121
  /* Populate SERVERS. */
 
122
  SVN_ERR(svn_config_create(&servers, FALSE,  pool));
 
123
  svn_config_set(servers, SVN_CONFIG_SECTION_GLOBAL,
 
124
                 SVN_CONFIG_OPTION_HTTP_LIBRARY, http_library);
 
125
 
 
126
  /* Populate CONFIG. */
 
127
  config = apr_hash_make(pool);
 
128
  apr_hash_set(config, SVN_CONFIG_CATEGORY_SERVERS,
 
129
               APR_HASH_KEY_STRING, servers);
 
130
 
 
131
  *config_p = config;
 
132
  return SVN_NO_ERROR;
 
133
}
 
134
 
 
135
static svn_error_t *
 
136
change_rev_prop(const char *url,
 
137
                svn_revnum_t revision,
 
138
                const char *propname,
 
139
                const svn_string_t *propval,
 
140
                const svn_string_t *old_value,
 
141
                const char *http_library,
 
142
                svn_boolean_t want_error,
 
143
                apr_pool_t *pool)
 
144
{
 
145
  svn_ra_callbacks2_t *callbacks;
 
146
  svn_ra_session_t *sess;
 
147
  apr_hash_t *config;
 
148
  svn_boolean_t capable;
 
149
  svn_error_t *err;
 
150
 
 
151
  SVN_ERR(svn_ra_create_callbacks(&callbacks, pool));
 
152
  SVN_ERR(construct_auth_baton(&callbacks->auth_baton, pool));
 
153
  SVN_ERR(construct_config(&config, http_library, pool));
 
154
 
 
155
  SVN_ERR(svn_ra_open4(&sess, NULL, url, NULL, callbacks, NULL /* baton */,
 
156
                       config, pool));
 
157
 
 
158
  SVN_ERR(svn_ra_has_capability(sess, &capable,
 
159
                                SVN_RA_CAPABILITY_ATOMIC_REVPROPS,
 
160
                                pool));
 
161
  if (capable)
 
162
    {
 
163
      err = svn_ra_change_rev_prop2(sess, revision, propname,
 
164
                                    &old_value, propval, pool);
 
165
 
 
166
      if (want_error && err
 
167
          && svn_error_find_cause(err, SVN_ERR_FS_PROP_BASEVALUE_MISMATCH))
 
168
        {
 
169
          /* Expectation was matched.  Get out. */
 
170
          svn_error_clear(err);
 
171
          return SVN_NO_ERROR;
 
172
        }
 
173
      else if (! want_error && ! err)
 
174
        /* Expectation was matched.  Get out. */
 
175
        return SVN_NO_ERROR;
 
176
      else if (want_error && ! err)
 
177
        return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
 
178
                                "An error was expected but not seen");
 
179
      else
 
180
        /* A real (non-SVN_ERR_FS_PROP_BASEVALUE_MISMATCH) error. */
 
181
        return svn_error_trace(err);
 
182
    }
 
183
  else
 
184
    /* Running under --server-minor-version? */
 
185
    return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
 
186
                            "Server doesn't advertise "
 
187
                            "SVN_RA_CAPABILITY_ATOMIC_REVPROPS");
 
188
}
 
189
 
 
190
/* Parse SKEL_CSTR according to the description in USAGE_MSG. */
 
191
static svn_error_t *
 
192
extract_values_from_skel(svn_string_t **old_propval_p,
 
193
                         svn_string_t **propval_p,
 
194
                         const char *skel_cstr,
 
195
                         apr_pool_t *pool)
 
196
{
 
197
  apr_hash_t *proplist;
 
198
  svn_skel_t *skel;
 
199
 
 
200
  skel = svn_skel__parse(skel_cstr, strlen(skel_cstr), pool);
 
201
  SVN_ERR(svn_skel__parse_proplist(&proplist, skel, pool));
 
202
  *old_propval_p = apr_hash_get(proplist, KEY_OLD_PROPVAL, APR_HASH_KEY_STRING);
 
203
  *propval_p = apr_hash_get(proplist, KEY_NEW_PROPVAL, APR_HASH_KEY_STRING);
 
204
 
 
205
  return SVN_NO_ERROR;
 
206
}
 
207
 
 
208
int
 
209
main(int argc, const char *argv[])
 
210
{
 
211
  apr_pool_t *pool;
 
212
  int exit_code = EXIT_SUCCESS;
 
213
  svn_error_t *err;
 
214
  const char *url;
 
215
  svn_revnum_t revision;
 
216
  const char *propname;
 
217
  svn_string_t *propval;
 
218
  svn_string_t *old_propval;
 
219
  const char *http_library;
 
220
  char *digits_end = NULL;
 
221
  svn_boolean_t want_error;
 
222
 
 
223
  if (argc != 7)
 
224
    {
 
225
      fprintf(stderr, USAGE_MSG, argv[0], KEY_OLD_PROPVAL, KEY_NEW_PROPVAL);
 
226
      exit(1);
 
227
    }
 
228
 
 
229
  if (apr_initialize() != APR_SUCCESS)
 
230
    {
 
231
      fprintf(stderr, "apr_initialize() failed.\n");
 
232
      exit(1);
 
233
    }
 
234
 
 
235
  /* set up the global pool */
 
236
  pool = svn_pool_create(NULL);
 
237
 
 
238
  /* Parse argv. */
 
239
  url = svn_uri_canonicalize(argv[1], pool);
 
240
  revision = strtol(argv[2], &digits_end, 10);
 
241
  propname = argv[3];
 
242
  SVN_INT_ERR(extract_values_from_skel(&old_propval, &propval, argv[4], pool));
 
243
  http_library = argv[5];
 
244
  want_error = !strcmp(argv[6], "1");
 
245
 
 
246
  if ((! SVN_IS_VALID_REVNUM(revision)) || (! digits_end) || *digits_end)
 
247
    SVN_INT_ERR(svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
 
248
                                 _("Invalid revision number supplied")));
 
249
 
 
250
  /* Do something. */
 
251
  err = change_rev_prop(url, revision, propname, propval, old_propval,
 
252
                        http_library, want_error, pool);
 
253
  if (err)
 
254
    {
 
255
      svn_handle_error2(err, stderr, FALSE, "atomic-ra-revprop-change: ");
 
256
      svn_error_clear(err);
 
257
      exit_code = EXIT_FAILURE;
 
258
    }
 
259
 
 
260
  /* Clean up, and get outta here */
 
261
  svn_pool_destroy(pool);
 
262
  apr_terminate();
 
263
 
 
264
  return exit_code;
 
265
}