Mercurial > audlegacy-plugins
annotate src/mms/mms.c @ 3203:f5456241bff9 default tip
changed include path from audacious to audlegacy.
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Tue, 10 Nov 2009 05:19:25 +0900 |
| parents | 3134a0987162 |
| children |
| rev | line source |
|---|---|
| 503 | 1 /* Audacious |
| 2 * Copyright (c) 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 | |
| 6 * the Free Software Foundation; either version 2 of the License, or | |
| 7 * (at your option) any later version. | |
| 8 * | |
| 9 * This program is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 14 * You should have received a copy of the GNU General Public License | |
| 15 * along with this program; if not, write to the Free Software | |
| 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 17 */ | |
| 18 | |
| 19 #include <glib.h> | |
| 20 | |
|
2971
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1978
diff
changeset
|
21 #include <audlegacy/plugin.h> |
| 503 | 22 #include <stdio.h> |
| 23 | |
| 24 #include <unistd.h> | |
| 25 #include <sys/stat.h> | |
| 26 #include <sys/types.h> | |
| 27 | |
| 28 #include <string.h> | |
| 29 #include <errno.h> | |
| 30 | |
| 31 #include <libmms/mms.h> | |
| 32 | |
| 33 /* | |
| 34 * TODO: | |
| 35 * - mmsh:// support | |
| 36 */ | |
| 37 | |
| 38 typedef struct { | |
| 39 mms_t *mms; | |
| 40 GSList *charstack; | |
| 41 } MMSHandle; | |
| 42 | |
| 43 VFSFile * | |
| 1978 | 44 mms_aud_vfs_fopen_impl(const gchar * path, |
| 503 | 45 const gchar * mode) |
| 46 { | |
| 47 VFSFile *file; | |
| 48 MMSHandle *handle; | |
| 49 | |
| 50 if (!path || !mode) | |
| 51 return NULL; | |
| 52 | |
| 53 file = g_new(VFSFile, 1); | |
| 54 handle = g_new0(MMSHandle, 1); | |
| 55 | |
| 56 file->handle = handle; | |
| 57 | |
| 58 if (file->handle == NULL) { | |
| 59 g_free(file); | |
| 60 file = NULL; | |
| 61 } | |
| 62 | |
| 63 handle->mms = mms_connect(NULL, NULL, path, 128 * 1024); | |
| 64 | |
| 65 if (handle->mms == NULL) { | |
| 66 g_free(handle); | |
| 67 g_free(file); | |
| 68 file = NULL; | |
| 69 } | |
| 70 | |
| 71 return file; | |
| 72 } | |
| 73 | |
| 74 gint | |
| 1978 | 75 mms_aud_vfs_fclose_impl(VFSFile * file) |
| 503 | 76 { |
| 77 gint ret = 0; | |
| 78 | |
| 79 if (file == NULL) | |
| 80 return -1; | |
| 81 | |
| 82 if (file->handle) | |
| 83 { | |
| 84 MMSHandle *handle = (MMSHandle *) file->handle; | |
| 85 | |
| 86 mms_close(handle->mms); | |
| 87 g_free(handle); | |
|
1228
01efa0e5b554
file->handle should be cleared on close, otherwise it can lead to double free.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1190
diff
changeset
|
88 file->handle = NULL; |
| 503 | 89 } |
| 90 | |
| 91 return ret; | |
| 92 } | |
| 93 | |
| 94 size_t | |
| 1978 | 95 mms_aud_vfs_fread_impl(gpointer ptr, |
| 503 | 96 size_t size, |
| 97 size_t nmemb, | |
| 98 VFSFile * file) | |
| 99 { | |
| 100 MMSHandle *handle; | |
| 101 gint ret; | |
| 102 | |
| 103 if (file == NULL) | |
| 104 return 0; | |
| 105 | |
| 106 handle = (MMSHandle *) file->handle; | |
| 107 | |
| 108 ret = mms_read(NULL, handle->mms, ptr, size * nmemb); | |
| 109 | |
| 110 if (ret < 0) | |
| 111 { | |
| 112 g_message("** mms **: errno(%d): %s", errno, strerror(errno)); | |
| 113 ret = EOF; | |
| 114 } | |
| 115 | |
| 116 return ret; | |
| 117 } | |
| 118 | |
| 119 size_t | |
| 1978 | 120 mms_aud_vfs_fwrite_impl(gconstpointer ptr, |
| 503 | 121 size_t size, |
| 122 size_t nmemb, | |
| 123 VFSFile * file) | |
| 124 { | |
| 125 return -1; | |
| 126 } | |
| 127 | |
| 128 gint | |
| 1978 | 129 mms_aud_vfs_getc_impl(VFSFile *stream) |
| 503 | 130 { |
| 131 MMSHandle *handle = (MMSHandle *) stream->handle; | |
| 132 guchar c; | |
| 133 | |
| 134 if (handle->charstack != NULL) | |
| 135 { | |
| 136 c = GPOINTER_TO_UINT(handle->charstack->data); | |
| 137 handle->charstack = g_slist_remove_link(handle->charstack, handle->charstack); | |
| 138 return c; | |
| 139 } | |
| 140 else | |
| 141 { | |
|
1190
ed2d7787779e
more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1148
diff
changeset
|
142 mms_read(NULL, handle->mms, (char *)&c, 1); |
| 503 | 143 return c; |
| 144 } | |
| 145 | |
| 146 return EOF; | |
| 147 } | |
| 148 | |
| 149 gint | |
| 1978 | 150 mms_aud_vfs_ungetc_impl(gint c, VFSFile *stream) |
| 503 | 151 { |
| 152 MMSHandle *handle = (MMSHandle *) stream->handle; | |
| 153 | |
| 154 handle->charstack = g_slist_append(handle->charstack, GUINT_TO_POINTER(c)); | |
| 155 | |
| 156 if (handle->charstack != NULL) | |
| 157 return c; | |
| 158 | |
| 159 return EOF; | |
| 160 } | |
| 161 | |
| 162 gint | |
| 1978 | 163 mms_aud_vfs_fseek_impl(VFSFile * file, |
| 503 | 164 glong offset, |
| 165 gint whence) | |
| 166 { | |
| 167 return -1; | |
| 168 } | |
| 169 | |
| 170 void | |
| 1978 | 171 mms_aud_vfs_rewind_impl(VFSFile * file) |
| 503 | 172 { |
| 173 return; | |
| 174 } | |
| 175 | |
| 176 glong | |
| 1978 | 177 mms_aud_vfs_ftell_impl(VFSFile * file) |
| 503 | 178 { |
| 179 MMSHandle *handle = (MMSHandle *) file->handle; | |
| 180 | |
| 181 return mms_get_current_pos(handle->mms); | |
| 182 } | |
| 183 | |
| 184 gboolean | |
| 1978 | 185 mms_aud_vfs_feof_impl(VFSFile * file) |
| 503 | 186 { |
| 187 MMSHandle *handle = (MMSHandle *) file->handle; | |
| 188 | |
| 189 return (gboolean) (mms_get_current_pos(handle->mms) == | |
| 190 mms_get_length(handle->mms)); | |
| 191 } | |
| 192 | |
| 193 gint | |
| 1978 | 194 mms_aud_vfs_truncate_impl(VFSFile * file, glong size) |
| 503 | 195 { |
| 196 return -1; | |
| 197 } | |
| 198 | |
| 965 | 199 off_t |
| 1978 | 200 mms_aud_vfs_fsize_impl(VFSFile * file) |
| 965 | 201 { |
| 202 return -1; | |
| 203 } | |
| 204 | |
| 503 | 205 VFSConstructor mms_const = { |
| 206 "mms://", | |
| 1978 | 207 mms_aud_vfs_fopen_impl, |
| 208 mms_aud_vfs_fclose_impl, | |
| 209 mms_aud_vfs_fread_impl, | |
| 210 mms_aud_vfs_fwrite_impl, | |
| 211 mms_aud_vfs_getc_impl, | |
| 212 mms_aud_vfs_ungetc_impl, | |
| 213 mms_aud_vfs_fseek_impl, | |
| 214 mms_aud_vfs_rewind_impl, | |
| 215 mms_aud_vfs_ftell_impl, | |
| 216 mms_aud_vfs_feof_impl, | |
| 217 mms_aud_vfs_truncate_impl, | |
| 218 mms_aud_vfs_fsize_impl | |
| 503 | 219 }; |
| 220 | |
| 221 static void init(void) | |
| 222 { | |
| 1978 | 223 aud_vfs_register_transport(&mms_const); |
| 503 | 224 } |
| 225 | |
| 226 static void cleanup(void) | |
| 227 { | |
| 228 #if 0 | |
| 1978 | 229 aud_vfs_unregister_transport(&mms_const); |
| 503 | 230 #endif |
| 231 } | |
| 232 | |
|
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
233 DECLARE_PLUGIN(mms, init, cleanup, NULL, NULL, NULL, NULL, NULL, NULL); |
