Mercurial > audlegacy
annotate src/audacious/vfs.c @ 3395:df609e7e7bcf
updated romanian translation
| author | Cristi Magherusan <majeru@atheme-project.org> |
|---|---|
| date | Sun, 26 Aug 2007 03:06:40 +0300 |
| parents | 49c25e9ecf6d |
| children | faba4117b0d0 |
| rev | line source |
|---|---|
| 2313 | 1 /* Audacious |
| 2 * Copyright (c) 2006-2007 William Pitcock | |
| 3 * | |
| 4 * This program is free software; you can redistribute it and/or modify | |
| 5 * it under the terms of the GNU General Public License as published by | |
|
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3113
diff
changeset
|
6 * the Free Software Foundation; under version 3 of the License. |
| 2313 | 7 * |
| 8 * This program is distributed in the hope that it will be useful, | |
| 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11 * GNU General Public License for more details. | |
| 12 * | |
| 13 * You should have received a copy of the GNU General Public License | |
|
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3113
diff
changeset
|
14 * along with this program. If not, see <http://www.gnu.org/licenses>. |
|
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
15 * |
|
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
16 * The Audacious team does not consider modular code linking to |
|
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
17 * Audacious or using our public API to be a derived work. |
| 2313 | 18 */ |
| 19 | |
| 20 #include "vfs.h" | |
| 2579 | 21 #include "strings.h" |
| 2313 | 22 #include <stdio.h> |
| 23 | |
| 24 #include <unistd.h> | |
| 25 #include <sys/stat.h> | |
| 26 #include <sys/types.h> | |
| 27 | |
| 2336 | 28 #include <string.h> |
| 29 | |
| 2623 | 30 GList *vfs_transports = NULL; /* temporary. -nenolod */ |
| 2313 | 31 |
| 32 #ifdef VFS_DEBUG | |
| 33 # define DBG(x, args...) g_print(x, ## args); | |
| 34 #else | |
| 35 # define DBG(x, args...) | |
| 36 #endif | |
| 37 | |
| 38 /** | |
| 39 * vfs_register_transport: | |
| 40 * @vtable: The #VFSConstructor vtable to register. | |
| 41 * | |
| 42 * Registers a #VFSConstructor vtable with the VFS system. | |
| 43 * | |
| 44 * Return value: TRUE on success, FALSE on failure. | |
| 45 **/ | |
| 46 gboolean | |
| 47 vfs_register_transport(VFSConstructor *vtable) | |
| 48 { | |
| 49 vfs_transports = g_list_append(vfs_transports, vtable); | |
| 50 | |
| 51 return TRUE; | |
| 52 } | |
| 53 | |
| 54 /** | |
| 55 * vfs_fopen: | |
| 56 * @path: The path or URI to open. | |
| 57 * @mode: The preferred access privileges (not guaranteed). | |
| 58 * | |
| 59 * Opens a stream from a VFS transport using a #VFSConstructor. | |
| 60 * | |
| 61 * Return value: On success, a #VFSFile object representing the stream. | |
| 62 **/ | |
| 63 VFSFile * | |
| 64 vfs_fopen(const gchar * path, | |
| 65 const gchar * mode) | |
| 66 { | |
| 67 VFSFile *file; | |
| 68 VFSConstructor *vtable = NULL; | |
| 69 GList *node; | |
| 70 gchar *decpath; | |
| 71 | |
| 72 if (!path || !mode) | |
| 73 return NULL; | |
| 74 | |
|
2381
d49913587458
[svn] - changes to the nature of URI handling in the VFS subsystem, will be
nenolod
parents:
2376
diff
changeset
|
75 decpath = g_strdup(path); |
| 2313 | 76 |
|
2335
e80c9dfc93aa
[svn] - g_strsplit() wraps strsplit(3), and thus has different results on
nenolod
parents:
2313
diff
changeset
|
77 for (node = vfs_transports; node != NULL; node = g_list_next(node)) |
| 2313 | 78 { |
| 2534 | 79 VFSConstructor *vtptr = (VFSConstructor *) node->data; |
| 2313 | 80 |
|
2533
ab335d4391df
[svn] - don't return a bogus vtable for an unregistered URI scheme
nenolod
parents:
2416
diff
changeset
|
81 if (!strncasecmp(decpath, vtptr->uri_id, strlen(vtptr->uri_id))) |
|
ab335d4391df
[svn] - don't return a bogus vtable for an unregistered URI scheme
nenolod
parents:
2416
diff
changeset
|
82 { |
|
ab335d4391df
[svn] - don't return a bogus vtable for an unregistered URI scheme
nenolod
parents:
2416
diff
changeset
|
83 vtable = vtptr; |
|
2335
e80c9dfc93aa
[svn] - g_strsplit() wraps strsplit(3), and thus has different results on
nenolod
parents:
2313
diff
changeset
|
84 break; |
|
2533
ab335d4391df
[svn] - don't return a bogus vtable for an unregistered URI scheme
nenolod
parents:
2416
diff
changeset
|
85 } |
| 2313 | 86 } |
| 87 | |
| 88 /* no transport vtable has been registered, bail. */ | |
| 89 if (vtable == NULL) | |
|
2987
7f17c37db82b
Log a warning if an adequate transport was not found.
William Pitcock <nenolod@atheme-project.org>
parents:
2978
diff
changeset
|
90 { |
|
7f17c37db82b
Log a warning if an adequate transport was not found.
William Pitcock <nenolod@atheme-project.org>
parents:
2978
diff
changeset
|
91 g_warning("could not open '%s', no transport plugin available", decpath); |
| 2313 | 92 return NULL; |
|
2987
7f17c37db82b
Log a warning if an adequate transport was not found.
William Pitcock <nenolod@atheme-project.org>
parents:
2978
diff
changeset
|
93 } |
| 2313 | 94 |
|
2381
d49913587458
[svn] - changes to the nature of URI handling in the VFS subsystem, will be
nenolod
parents:
2376
diff
changeset
|
95 file = vtable->vfs_fopen_impl(decpath, mode); |
| 2313 | 96 |
| 97 if (file == NULL) | |
| 98 return NULL; | |
| 99 | |
| 100 file->uri = g_strdup(path); | |
| 101 file->base = vtable; | |
|
2562
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
102 file->ref = 1; |
| 2313 | 103 |
| 104 g_free(decpath); | |
| 105 | |
| 106 return file; | |
| 107 } | |
| 108 | |
| 109 /** | |
| 110 * vfs_fclose: | |
| 111 * @file: A #VFSFile object to destroy. | |
| 112 * | |
| 113 * Closes a VFS stream and destroys a #VFSFile object. | |
| 114 * | |
| 115 * Return value: -1 on failure, 0 on success. | |
| 116 **/ | |
| 117 gint | |
| 118 vfs_fclose(VFSFile * file) | |
| 119 { | |
| 120 gint ret = 0; | |
| 121 | |
| 122 if (file == NULL) | |
| 123 return -1; | |
| 124 | |
|
2562
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
125 if (--file->ref > 0) |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
126 return -1; |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
127 |
| 2313 | 128 if (file->base->vfs_fclose_impl(file) != 0) |
| 129 ret = -1; | |
| 130 | |
| 131 if (file->uri != NULL) | |
| 132 g_free(file->uri); | |
| 133 | |
| 134 g_free(file); | |
| 135 | |
| 136 return ret; | |
| 137 } | |
| 138 | |
| 139 /** | |
| 140 * vfs_fread: | |
| 141 * @ptr: A pointer to the destination buffer. | |
| 142 * @size: The size of each element to read. | |
| 143 * @nmemb: The number of elements to read. | |
| 144 * @file: #VFSFile object that represents the VFS stream. | |
| 145 * | |
| 146 * Reads from a VFS stream. | |
| 147 * | |
| 148 * Return value: The amount of elements succesfully read. | |
| 149 **/ | |
| 150 size_t | |
| 151 vfs_fread(gpointer ptr, | |
| 152 size_t size, | |
| 153 size_t nmemb, | |
| 154 VFSFile * file) | |
| 155 { | |
| 156 if (file == NULL) | |
| 157 return 0; | |
| 158 | |
| 159 return file->base->vfs_fread_impl(ptr, size, nmemb, file); | |
| 160 } | |
| 161 | |
| 162 /** | |
| 163 * vfs_fwrite: | |
| 164 * @ptr: A const pointer to the source buffer. | |
| 165 * @size: The size of each element to write. | |
| 166 * @nmemb: The number of elements to write. | |
| 167 * @file: #VFSFile object that represents the VFS stream. | |
| 168 * | |
| 169 * Writes to a VFS stream. | |
| 170 * | |
| 171 * Return value: The amount of elements succesfully written. | |
| 172 **/ | |
| 173 size_t | |
| 174 vfs_fwrite(gconstpointer ptr, | |
| 175 size_t size, | |
| 176 size_t nmemb, | |
| 177 VFSFile * file) | |
| 178 { | |
| 179 if (file == NULL) | |
| 180 return 0; | |
| 181 | |
| 182 return file->base->vfs_fwrite_impl(ptr, size, nmemb, file); | |
| 183 } | |
| 184 | |
| 185 /** | |
| 186 * vfs_getc: | |
| 187 * @stream: #VFSFile object that represents the VFS stream. | |
| 188 * | |
| 189 * Reads a character from a VFS stream. | |
| 190 * | |
| 191 * Return value: On success, a character. Otherwise, -1. | |
| 192 **/ | |
| 193 gint | |
| 194 vfs_getc(VFSFile *stream) | |
| 195 { | |
| 196 if (stream == NULL) | |
| 197 return -1; | |
| 198 | |
| 199 return stream->base->vfs_getc_impl(stream); | |
| 200 } | |
| 201 | |
| 202 /** | |
| 203 * vfs_ungetc: | |
| 204 * @c: The character to push back. | |
| 205 * @stream: #VFSFile object that represents the VFS stream. | |
| 206 * | |
| 207 * Pushes a character back to the VFS stream. | |
| 208 * | |
| 209 * Return value: On success, 0. Otherwise, -1. | |
| 210 **/ | |
| 211 gint | |
| 212 vfs_ungetc(gint c, VFSFile *stream) | |
| 213 { | |
| 214 if (stream == NULL) | |
| 215 return -1; | |
| 216 | |
| 217 return stream->base->vfs_ungetc_impl(c, stream); | |
| 218 } | |
| 219 | |
| 220 /** | |
| 221 * vfs_fseek: | |
| 222 * @file: #VFSFile object that represents the VFS stream. | |
| 223 * @offset: The offset to seek to. | |
| 224 * @whence: Whether or not the seek is absolute or not. | |
| 225 * | |
| 226 * Seeks through a VFS stream. | |
| 227 * | |
| 228 * Return value: On success, 1. Otherwise, 0. | |
| 229 **/ | |
| 230 gint | |
| 231 vfs_fseek(VFSFile * file, | |
| 232 glong offset, | |
| 233 gint whence) | |
| 234 { | |
| 235 if (file == NULL) | |
| 236 return 0; | |
| 237 | |
| 238 return file->base->vfs_fseek_impl(file, offset, whence); | |
| 239 } | |
| 240 | |
| 241 /** | |
| 242 * vfs_rewind: | |
| 243 * @file: #VFSFile object that represents the VFS stream. | |
| 244 * | |
| 245 * Rewinds a VFS stream. | |
| 246 **/ | |
| 247 void | |
| 248 vfs_rewind(VFSFile * file) | |
| 249 { | |
| 250 if (file == NULL) | |
| 251 return; | |
| 252 | |
| 253 file->base->vfs_rewind_impl(file); | |
| 254 } | |
| 255 | |
| 256 /** | |
| 257 * vfs_ftell: | |
| 258 * @file: #VFSFile object that represents the VFS stream. | |
| 259 * | |
| 260 * Returns the current position in the VFS stream's buffer. | |
| 261 * | |
| 262 * Return value: On success, the current position. Otherwise, -1. | |
| 263 **/ | |
| 264 glong | |
| 265 vfs_ftell(VFSFile * file) | |
| 266 { | |
| 267 if (file == NULL) | |
| 268 return -1; | |
| 269 | |
| 270 return file->base->vfs_ftell_impl(file); | |
| 271 } | |
| 272 | |
| 273 /** | |
| 274 * vfs_feof: | |
| 275 * @file: #VFSFile object that represents the VFS stream. | |
| 276 * | |
| 277 * Returns whether or not the VFS stream has reached EOF. | |
| 278 * | |
| 279 * Return value: On success, whether or not the VFS stream is at EOF. Otherwise, FALSE. | |
| 280 **/ | |
| 281 gboolean | |
| 282 vfs_feof(VFSFile * file) | |
| 283 { | |
| 284 if (file == NULL) | |
| 285 return FALSE; | |
| 286 | |
| 287 return (gboolean) file->base->vfs_feof_impl(file); | |
| 288 } | |
| 289 | |
| 290 /** | |
| 291 * vfs_truncate: | |
| 292 * @file: #VFSFile object that represents the VFS stream. | |
| 293 * @length: The length to truncate at. | |
| 294 * | |
| 295 * Truncates a VFS stream to a certain size. | |
| 296 * | |
| 297 * Return value: On success, 0. Otherwise, -1. | |
| 298 **/ | |
| 299 gint | |
| 300 vfs_truncate(VFSFile * file, glong length) | |
| 301 { | |
| 302 if (file == NULL) | |
| 303 return -1; | |
| 304 | |
| 305 return file->base->vfs_truncate_impl(file, length); | |
| 306 } | |
| 307 | |
| 308 /** | |
| 2688 | 309 * vfs_fsize: |
| 310 * @file: #VFSFile object that represents the VFS stream. | |
| 311 * | |
| 312 * Returns te size of the file | |
| 313 * | |
| 314 * Return value: On success, the size of the file in bytes. | |
| 315 * Otherwise, -1. | |
| 316 */ | |
| 317 off_t | |
| 318 vfs_fsize(VFSFile * file) | |
| 319 { | |
| 320 if (file == NULL) | |
| 321 return -1; | |
| 322 | |
| 323 return file->base->vfs_fsize_impl(file); | |
| 324 } | |
| 325 | |
| 326 /** | |
|
2376
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
327 * vfs_get_metadata: |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
328 * @file: #VFSFile object that represents the VFS stream. |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
329 * @field: The string constant field name to get. |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
330 * |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
331 * Returns metadata about the stream. |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
332 * |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
333 * Return value: On success, a copy of the value of the |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
334 * field. Otherwise, NULL. |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
335 **/ |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
336 gchar * |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
337 vfs_get_metadata(VFSFile * file, const gchar * field) |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
338 { |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
339 if (file == NULL) |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
340 return NULL; |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
341 |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
342 if (file->base->vfs_get_metadata_impl) |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
343 return file->base->vfs_get_metadata_impl(file, field); |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
344 return NULL; |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
345 } |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
346 |
|
e1513290ee3c
[svn] Add a VFSFile method for getting metadata associated with the file.
iabervon
parents:
2370
diff
changeset
|
347 /** |
| 2313 | 348 * vfs_file_test: |
| 349 * @path: A path to test. | |
| 350 * @test: A GFileTest to run. | |
| 351 * | |
| 352 * Wrapper for g_file_test(). | |
| 353 * | |
| 354 * Return value: The result of g_file_test(). | |
| 355 **/ | |
| 356 gboolean | |
| 357 vfs_file_test(const gchar * path, GFileTest test) | |
| 358 { | |
| 2575 | 359 gchar *path2; |
| 360 gboolean ret; | |
| 361 | |
|
2978
f4971c7d6384
Remove inlined urldecoding functions and use g_filename_from_uri() instead where appropriate.
William Pitcock <nenolod@atheme-project.org>
parents:
2976
diff
changeset
|
362 path2 = g_filename_from_uri(path, NULL, NULL); |
| 2575 | 363 |
|
2580
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
364 if (path2 == NULL) |
|
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
365 path2 = g_strdup(path); |
|
48288757d7c7
[svn] - fix a regression introduced by the DnD fix.
nenolod
parents:
2579
diff
changeset
|
366 |
| 2575 | 367 ret = g_file_test(path2, test); |
| 368 | |
| 369 g_free(path2); | |
| 370 | |
| 371 return ret; | |
| 2313 | 372 } |
| 373 | |
| 374 /** | |
| 375 * vfs_is_writeable: | |
| 376 * @path: A path to test. | |
| 377 * | |
| 378 * Tests if a file is writeable. | |
| 379 * | |
| 380 * Return value: TRUE if the file is writeable, otherwise FALSE. | |
| 381 **/ | |
| 382 gboolean | |
| 383 vfs_is_writeable(const gchar * path) | |
| 384 { | |
| 385 struct stat info; | |
|
3167
49c25e9ecf6d
Unbreak vfs_is_writeable().
William Pitcock <nenolod@atheme-project.org>
parents:
3142
diff
changeset
|
386 gchar *realfn = g_filename_from_uri(path, NULL, NULL); |
| 2313 | 387 |
|
3167
49c25e9ecf6d
Unbreak vfs_is_writeable().
William Pitcock <nenolod@atheme-project.org>
parents:
3142
diff
changeset
|
388 if (stat(realfn, &info) == -1) |
| 2313 | 389 return FALSE; |
| 390 | |
|
3167
49c25e9ecf6d
Unbreak vfs_is_writeable().
William Pitcock <nenolod@atheme-project.org>
parents:
3142
diff
changeset
|
391 g_free(realfn); |
|
49c25e9ecf6d
Unbreak vfs_is_writeable().
William Pitcock <nenolod@atheme-project.org>
parents:
3142
diff
changeset
|
392 |
| 2313 | 393 return (info.st_mode & S_IWUSR); |
| 394 } | |
|
2562
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
395 |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
396 /** |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
397 * vfs_dup: |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
398 * @in: The VFSFile handle to mark as duplicated. |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
399 * |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
400 * Increments the amount of references that are using this FD. |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
401 * References are removed by calling vfs_fclose on the handle returned |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
402 * from this function. |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
403 * If the amount of references reaches zero, then the file will be |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
404 * closed. |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
405 **/ |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
406 VFSFile * |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
407 vfs_dup(VFSFile *in) |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
408 { |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
409 g_return_val_if_fail(in != NULL, NULL); |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
410 |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
411 in->ref++; |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
412 |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
413 return in; |
|
07b990906823
[svn] - add reference-counting to VFS and add new function, vfs_dup() to
nenolod
parents:
2534
diff
changeset
|
414 } |
|
3142
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
415 |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
416 /** |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
417 * vfs_is_remote: |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
418 * @path: A path to test. |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
419 * |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
420 * Tests if a path is remote uri. |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
421 * |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
422 * Return value: TRUE if the file is remote, otherwise FALSE. |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
423 **/ |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
424 gboolean |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
425 vfs_is_remote(const gchar * path) |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
426 { |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
427 VFSConstructor *vtable = NULL; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
428 GList *node; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
429 gchar *decpath; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
430 |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
431 if (!path) |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
432 return FALSE; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
433 |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
434 decpath = g_strdup(path); |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
435 |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
436 for (node = vfs_transports; node != NULL; node = g_list_next(node)) |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
437 { |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
438 VFSConstructor *vtptr = (VFSConstructor *) node->data; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
439 |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
440 if (!strncasecmp(decpath, vtptr->uri_id, strlen(vtptr->uri_id))) |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
441 { |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
442 vtable = vtptr; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
443 break; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
444 } |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
445 } |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
446 |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
447 /* no transport vtable has been registered, bail. */ |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
448 if (vtable == NULL) |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
449 { |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
450 g_warning("could not open '%s', no transport plugin available", decpath); |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
451 return FALSE; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
452 } |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
453 |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
454 /* check if vtable->uri_id is file:// or not, for now. */ |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
455 if(!strncasecmp("file://", vtable->uri_id, strlen(vtable->uri_id))) |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
456 return FALSE; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
457 else |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
458 return TRUE; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
459 } |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
460 |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
461 /** |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
462 * vfs_is_streaming: |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
463 * @file: A #VFSFile object to test. |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
464 * |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
465 * Tests if a file is associated to streaming. |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
466 * |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
467 * Return value: TRUE if the file is streaming, otherwise FALSE. |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
468 **/ |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
469 gboolean |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
470 vfs_is_streaming(VFSFile *file) |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
471 { |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
472 off_t size = 0; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
473 glong curpos; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
474 |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
475 if(!file) |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
476 return FALSE; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
477 |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
478 curpos = file->base->vfs_ftell_impl(file); |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
479 size = file->base->vfs_fsize_impl(file); |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
480 file->base->vfs_fseek_impl(file, curpos, SEEK_SET); |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
481 |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
482 if(size == -1) |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
483 return TRUE; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
484 else |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
485 return FALSE; |
|
e8f2b130e59e
add vfs_is_remote() and vfs_is_streaming().
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3123
diff
changeset
|
486 } |
