Пример #1
0
/* Escape all non-ascii or control characters similar to
 * svn_xml_fuzzy_escape() and svn_utf_cstring_from_utf8_fuzzy().
 * All of the encoding formats somewhat overlap with ascii (BMPString
 * and UniversalString are actually always wider so you'll end up
 * with a bunch of escaped nul bytes, but ideally we don't get here
 * for those).  The result is always a nul-terminated C string. */
static const char *
fuzzy_escape(const svn_string_t *src, apr_pool_t *result_pool)
{
  const char *end = src->data + src->len;
  const char *p = src->data, *q;
  svn_stringbuf_t *outstr;
  char escaped_char[6]; /* ? \ u u u \0 */

  for (q = p; q < end; q++)
    {
      if (!svn_ctype_isascii(*q) || svn_ctype_iscntrl(*q))
        break;
    }

  if (q == end)
    return src->data;

  outstr = svn_stringbuf_create_empty(result_pool);
  while (1)
    {
      q = p;

      /* Traverse till either unsafe character or eos. */
      while (q < end && svn_ctype_isascii(*q) && !svn_ctype_iscntrl(*q))
        q++;

      /* copy chunk before marker */
      svn_stringbuf_appendbytes(outstr, p, q - p);

      if (q == end)
        break;

      apr_snprintf(escaped_char, sizeof(escaped_char), "?\\%03u",
                   (unsigned char) *q);
      svn_stringbuf_appendcstr(outstr, escaped_char);

      p = q + 1;
    }

  return outstr->data;
}
Пример #2
0
svn_error_t *
svn_fs_lock(svn_lock_t **lock, svn_fs_t *fs, const char *path,
            const char *token, const char *comment,
            svn_boolean_t is_dav_comment, apr_time_t expiration_date,
            svn_revnum_t current_rev, svn_boolean_t steal_lock,
            apr_pool_t *pool)
{
  /* Enforce that the comment be xml-escapable. */
  if (comment)
    {
      if (! svn_xml_is_xml_safe(comment, strlen(comment)))
        return svn_error_create
          (SVN_ERR_XML_UNESCAPABLE_DATA, NULL,
           _("Lock comment contains illegal characters"));
    }

  /* Enforce that the token be an XML-safe URI. */
  if (token)
    {
      const char *c;

      if (strncmp(token, "opaquelocktoken:", 16))
        return svn_error_createf(SVN_ERR_FS_BAD_LOCK_TOKEN, NULL,
                                 _("Lock token URI '%s' has bad scheme; "
                                   "expected '%s'"),
                                 token, "opaquelocktoken");

      for (c = token; *c; c++)
        if (! svn_ctype_isascii(*c))
          return svn_error_createf(SVN_ERR_FS_BAD_LOCK_TOKEN, NULL,
                                   _("Lock token '%s' is not ASCII "
                                     "at byte %u"),
                                   token, (unsigned)(c - token));

      /* strlen(token) == c - token. */
      if (! svn_xml_is_xml_safe(token, c - token))
        return svn_error_createf(SVN_ERR_FS_BAD_LOCK_TOKEN, NULL,
                                 _("Lock token URI '%s' is not XML-safe"),
                                 token);
    }

  if (expiration_date < 0)
        return svn_error_create
          (SVN_ERR_INCORRECT_PARAMS, NULL,
           _("Negative expiration date passed to svn_fs_lock"));

  return svn_error_trace(fs->vtable->lock(lock, fs, path, token, comment,
                                          is_dav_comment, expiration_date,
                                          current_rev, steal_lock, pool));
}