2 * props.c: Utility functions for property handling
4 * ====================================================================
5 * Copyright (c) 2000-2007 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 /* ==================================================================== */
26 #include "svn_cmdline.h"
27 #include "svn_string.h"
28 #include "svn_error.h"
29 #include "svn_subst.h"
30 #include "svn_props.h"
31 #include "svn_string.h"
34 #include "svn_base64.h"
37 #include "svn_private_config.h"
42 svn_cl__revprop_prepare(const svn_opt_revision_t
*revision
,
43 apr_array_header_t
*targets
,
49 if (revision
->kind
!= svn_opt_revision_number
50 && revision
->kind
!= svn_opt_revision_date
51 && revision
->kind
!= svn_opt_revision_head
)
52 return svn_error_create
53 (SVN_ERR_CL_ARG_PARSING_ERROR
, NULL
,
54 _("Must specify the revision as a number, a date or 'HEAD' "
55 "when operating on a revision property"));
57 /* There must be exactly one target at this point. If it was optional and
58 unspecified by the user, the caller has already added the implicit '.'. */
59 if (targets
->nelts
!= 1)
60 return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR
, NULL
,
61 _("Wrong number of targets specified"));
63 /* (The docs say the target must be either a URL or implicit '.', but
64 explicit WC targets are also accepted.) */
65 target
= APR_ARRAY_IDX(targets
, 0, const char *);
66 SVN_ERR(svn_client_url_from_path(URL
, target
, pool
));
68 return svn_error_create
69 (SVN_ERR_UNVERSIONED_RESOURCE
, NULL
,
70 _("Either a URL or versioned item is required"));
77 svn_cl__print_prop_hash(apr_hash_t
*prop_hash
,
78 svn_boolean_t names_only
,
83 for (hi
= apr_hash_first(pool
, prop_hash
); hi
; hi
= apr_hash_next(hi
))
88 svn_string_t
*propval
;
89 const char *pname_stdout
;
91 apr_hash_this(hi
, &key
, NULL
, &val
);
95 if (svn_prop_needs_translation(pname
))
96 SVN_ERR(svn_subst_detranslate_string(&propval
, propval
,
99 SVN_ERR(svn_cmdline_cstring_from_utf8(&pname_stdout
, pname
, pool
));
101 /* ### We leave these printfs for now, since if propval wasn't translated
102 * above, we don't know anything about its encoding. In fact, it
103 * might be binary data... */
105 printf(" %s\n", pname_stdout
);
107 printf(" %s : %s\n", pname_stdout
, propval
->data
);
114 svn_cl__print_xml_prop(svn_stringbuf_t
**outstr
,
115 const char* propname
,
116 svn_string_t
*propval
,
119 const char *xml_safe
;
120 const char *encoding
= NULL
;
123 *outstr
= svn_stringbuf_create("", pool
);
125 if (svn_xml_is_xml_safe(propval
->data
, propval
->len
))
127 svn_stringbuf_t
*xml_esc
= NULL
;
128 svn_xml_escape_cdata_string(&xml_esc
, propval
, pool
);
129 xml_safe
= xml_esc
->data
;
133 const svn_string_t
*base64ed
= svn_base64_encode_string(propval
, pool
);
135 xml_safe
= base64ed
->data
;
139 svn_xml_make_open_tag(outstr
, pool
, svn_xml_protect_pcdata
,
140 "property", "name", propname
,
141 "encoding", encoding
, NULL
);
143 svn_xml_make_open_tag(outstr
, pool
, svn_xml_protect_pcdata
,
144 "property", "name", propname
, NULL
);
146 svn_stringbuf_appendcstr(*outstr
, xml_safe
);
148 svn_xml_make_close_tag(outstr
, pool
, "property");
154 svn_cl__print_xml_prop_hash(svn_stringbuf_t
**outstr
,
155 apr_hash_t
*prop_hash
,
156 svn_boolean_t names_only
,
159 apr_hash_index_t
*hi
;
162 *outstr
= svn_stringbuf_create("", pool
);
164 for (hi
= apr_hash_first(pool
, prop_hash
); hi
; hi
= apr_hash_next(hi
))
169 svn_string_t
*propval
;
171 apr_hash_this(hi
, &key
, NULL
, &val
);
177 svn_xml_make_open_tag(outstr
, pool
, svn_xml_self_closing
, "property",
178 "name", pname
, NULL
);
182 const char *pname_out
;
184 if (svn_prop_needs_translation(pname
))
185 SVN_ERR(svn_subst_detranslate_string(&propval
, propval
,
188 SVN_ERR(svn_cmdline_cstring_from_utf8(&pname_out
, pname
, pool
));
190 svn_cl__print_xml_prop(outstr
, pname_out
, propval
, pool
);
199 svn_cl__check_boolean_prop_val(const char *propname
, const char *propval
,
202 svn_stringbuf_t
*propbuf
;
204 if (!svn_prop_is_boolean(propname
))
207 propbuf
= svn_stringbuf_create(propval
, pool
);
208 svn_stringbuf_strip_whitespace(propbuf
);
210 if (propbuf
->data
[0] == '\0'
211 || strcmp(propbuf
->data
, "no") == 0
212 || strcmp(propbuf
->data
, "off") == 0
213 || strcmp(propbuf
->data
, "false") == 0)
215 svn_error_t
*err
= svn_error_createf
216 (SVN_ERR_BAD_PROPERTY_VALUE
, NULL
,
217 _("To turn off the %s property, use 'svn propdel';\n"
218 "setting the property to '%s' will not turn it off."),
220 svn_handle_warning(stderr
, err
);
221 svn_error_clear(err
);