configure.ac: Move the encoders before the audio outputs.
[mpd-mk.git] / src / uri.c
blobfc44399678c474601e4fd07eeecf4ff66ccb59fb
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "config.h"
21 #include "uri.h"
23 #include <glib.h>
25 #include <assert.h>
26 #include <string.h>
28 bool uri_has_scheme(const char *uri)
30 return strstr(uri, "://") != NULL;
33 /* suffixes should be ascii only characters */
34 const char *
35 uri_get_suffix(const char *uri)
37 const char *suffix = strrchr(g_basename(uri), '.');
38 if (suffix == NULL)
39 return NULL;
41 ++suffix;
43 if (strchr(suffix, '/') != NULL)
44 return NULL;
46 return suffix;
49 static const char *
50 verify_uri_segment(const char *p)
52 const char *q;
54 unsigned dots = 0;
55 while (*p == '.')
56 ++p;
57 if (dots <= 2 && (*p == 0 || *p == '/'))
58 return NULL;
60 q = strchr(p + 1, '/');
61 return q != NULL ? q : "";
64 bool
65 uri_safe_local(const char *uri)
67 while (true) {
68 uri = verify_uri_segment(uri);
69 if (uri == NULL)
70 return false;
72 if (*uri == 0)
73 return true;
75 assert(*uri == '/');
77 ++uri;
81 char *
82 uri_remove_auth(const char *uri)
84 const char *auth, *slash, *at;
85 char *p;
87 if (strncmp(uri, "http://", 7) == 0)
88 auth = uri + 7;
89 else if (strncmp(uri, "https://", 8) == 0)
90 auth = uri + 8;
91 else
92 /* unrecognized URI */
93 return NULL;
95 slash = strchr(auth, '/');
96 if (slash == NULL)
97 slash = auth + strlen(auth);
99 at = memchr(auth, '@', slash - auth);
100 if (at == NULL)
101 /* no auth info present, do nothing */
102 return NULL;
104 /* duplicate the full URI and then delete the auth
105 information */
106 p = g_strdup(uri);
107 memmove(p + (auth - uri), p + (at + 1 - uri),
108 strlen(at));
110 return p;