Remove no-longer-used svn_*_get_mergeinfo_for_tree APIs.
[svn.git] / subversion / libsvn_subr / validate.c
blob04c188852be712ae858d83c534c3b92f0f91f6bd
1 /*
2 * validate.c: validation routines
4 * ====================================================================
5 * Copyright (c) 2000-2004 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 /* ==================================================================== */
23 /*** Includes. ***/
25 #include <apr_lib.h>
26 #define APR_WANT_STRFUNC
27 #include <apr_want.h>
29 #include "svn_error.h"
30 #include "svn_private_config.h"
34 /*** Code. ***/
36 svn_error_t *
37 svn_mime_type_validate(const char *mime_type, apr_pool_t *pool)
39 /* Since svn:mime-type can actually contain a full content type
40 specification, e.g., "text/html; charset=UTF-8", make sure we're
41 only looking at the media type here. */
42 const apr_size_t len = strcspn(mime_type, "; ");
43 const char *const slash_pos = strchr(mime_type, '/');
45 if (len == 0)
46 return svn_error_createf
47 (SVN_ERR_BAD_MIME_TYPE, NULL,
48 _("MIME type '%s' has empty media type"), mime_type);
50 if (slash_pos == NULL || slash_pos >= &mime_type[len])
51 return svn_error_createf
52 (SVN_ERR_BAD_MIME_TYPE, NULL,
53 _("MIME type '%s' does not contain '/'"), mime_type);
55 if (! apr_isalnum(mime_type[len - 1]))
56 return svn_error_createf
57 (SVN_ERR_BAD_MIME_TYPE, NULL,
58 _("MIME type '%s' ends with non-alphanumeric character"), mime_type);
60 return SVN_NO_ERROR;
64 svn_boolean_t
65 svn_mime_type_is_binary(const char *mime_type)
67 /* See comment in svn_mime_type_validate() above. */
68 const apr_size_t len = strcspn(mime_type, "; ");
69 return ((strncmp(mime_type, "text/", 5) != 0)
70 && (len != 15 || strncmp(mime_type, "image/x-xbitmap", len) != 0)
71 && (len != 15 || strncmp(mime_type, "image/x-xpixmap", len) != 0)