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 /* ==================================================================== */
26 #define APR_WANT_STRFUNC
29 #include "svn_error.h"
30 #include "svn_private_config.h"
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 const char *tspecials
= "()<>@,;:\\\"/[]?=";
48 return svn_error_createf
49 (SVN_ERR_BAD_MIME_TYPE
, NULL
,
50 _("MIME type '%s' has empty media type"), mime_type
);
52 if (slash_pos
== NULL
|| slash_pos
>= &mime_type
[len
])
53 return svn_error_createf
54 (SVN_ERR_BAD_MIME_TYPE
, NULL
,
55 _("MIME type '%s' does not contain '/'"), mime_type
);
57 /* Check the mime type for illegal characters. See RFC 1521. */
58 for (i
= 0; i
< len
; i
++)
60 if (&mime_type
[i
] != slash_pos
61 && (! apr_isascii(mime_type
[i
])
62 || apr_iscntrl(mime_type
[i
])
63 || apr_isspace(mime_type
[i
])
64 || (strchr(tspecials
, mime_type
[i
]) != NULL
)))
65 return svn_error_createf
66 (SVN_ERR_BAD_MIME_TYPE
, NULL
,
67 _("MIME type '%s' contains invalid character '%c'"),
68 mime_type
, mime_type
[i
]);
76 svn_mime_type_is_binary(const char *mime_type
)
78 /* See comment in svn_mime_type_validate() above. */
79 const apr_size_t len
= strcspn(mime_type
, "; ");
80 return ((strncmp(mime_type
, "text/", 5) != 0)
81 && (len
!= 15 || strncmp(mime_type
, "image/x-xbitmap", len
) != 0)
82 && (len
!= 15 || strncmp(mime_type
, "image/x-xpixmap", len
) != 0)