00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdlib.h>
00022 #include <glib.h>
00023 #include <stdarg.h>
00024 #include <string.h>
00025
00026 #include "xmmsc/xmmsc_util.h"
00027 #include "xmms/xmms_util.h"
00028 #include "xmmspriv/xmms_utils.h"
00029 #include "xmmsc/xmmsc_strlist.h"
00030
00031
00032
00033
00034
00035
00036
00037 char *
00038 xmms_build_path (const char *first, ...)
00039 {
00040 va_list ap;
00041 gchar confdir[PATH_MAX];
00042 gchar *ret, **vargv, **argv;
00043
00044 g_return_val_if_fail (first, NULL);
00045
00046 xmms_userconfdir_get (confdir, PATH_MAX);
00047
00048 va_start (ap, first);
00049 vargv = xmms_valist_to_strlist (first, ap);
00050 va_end (ap);
00051
00052 argv = xmms_strlist_prepend_copy (vargv, confdir);
00053
00054 ret = g_build_pathv (G_DIR_SEPARATOR_S, argv);
00055 xmms_strlist_destroy (vargv);
00056 xmms_strlist_destroy (argv);
00057 return ret;
00058 }
00059
00060 static gchar *
00061 path_get_body (const gchar *path)
00062 {
00063 gchar *beg, *end;
00064
00065 g_return_val_if_fail (path, NULL);
00066
00067 beg = strstr (path, "://");
00068
00069 if (!beg) {
00070 return g_strndup (path, strcspn (path, "/"));
00071 }
00072
00073 beg += 3;
00074 end = strchr (beg, '/');
00075
00076 if (!end) {
00077 return g_strdup (path);
00078 }
00079
00080 return g_strndup (path, end - path);
00081 }
00082
00083
00084
00085 static gchar *
00086 path_get_dirname (const gchar *path)
00087 {
00088 guint i, n = 0;
00089
00090 g_return_val_if_fail (path, NULL);
00091
00092 for (i = 0; path[i] ; i++) {
00093 if (path[i] == '/') {
00094 n = i;
00095 }
00096 }
00097
00098 return g_strndup (path, n);
00099 }
00100
00101 gchar *
00102 xmms_build_playlist_url (const gchar *plspath, const gchar *file)
00103 {
00104 gchar *url;
00105 gchar *path;
00106
00107 g_return_val_if_fail (plspath, NULL);
00108 g_return_val_if_fail (file, NULL);
00109
00110 if (strstr (file, "://") != NULL) {
00111 return g_strdup (file);
00112 }
00113
00114 if (file[0] == '/') {
00115 path = path_get_body (plspath);
00116 url = g_strconcat (path, file, NULL);
00117 } else {
00118 path = path_get_dirname (plspath);
00119 url = g_strconcat (path, "/", file, NULL);
00120 }
00121
00122 g_free (path);
00123 return url;
00124 }