Mercurial > audlegacy-plugins
annotate src/mms/mms.c @ 1791:ea7ec02f2ea2
Automated merge with ssh://hg.atheme-project.org//hg/audacious-plugins
| author | Jonathan Schleifer <js@h3c.de> |
|---|---|
| date | Mon, 24 Sep 2007 19:19:59 +0200 |
| parents | 761e17b23e0c |
| children | e8ea3a76a84e |
| 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 | |
| 21 #include <audacious/vfs.h> | |
| 22 #include <audacious/plugin.h> | |
| 23 #include <stdio.h> | |
| 24 | |
| 25 #include <unistd.h> | |
| 26 #include <sys/stat.h> | |
| 27 #include <sys/types.h> | |
| 28 | |
| 29 #include <string.h> | |
| 30 #include <errno.h> | |
| 31 | |
| 32 #include <libmms/mms.h> | |
| 33 | |
| 34 /* | |
| 35 * TODO: | |
| 36 * - mmsh:// support | |
| 37 */ | |
| 38 | |
| 39 typedef struct { | |
| 40 mms_t *mms; | |
| 41 GSList *charstack; | |
| 42 } MMSHandle; | |
| 43 | |
| 44 VFSFile * | |
| 45 mms_vfs_fopen_impl(const gchar * path, | |
| 46 const gchar * mode) | |
| 47 { | |
| 48 VFSFile *file; | |
| 49 MMSHandle *handle; | |
| 50 | |
| 51 if (!path || !mode) | |
| 52 return NULL; | |
| 53 | |
| 54 file = g_new(VFSFile, 1); | |
| 55 handle = g_new0(MMSHandle, 1); | |
| 56 | |
| 57 file->handle = handle; | |
| 58 | |
| 59 if (file->handle == NULL) { | |
| 60 g_free(file); | |
| 61 file = NULL; | |
| 62 } | |
| 63 | |
| 64 handle->mms = mms_connect(NULL, NULL, path, 128 * 1024); | |
| 65 | |
| 66 if (handle->mms == NULL) { | |
| 67 g_free(handle); | |
| 68 g_free(file); | |
| 69 file = NULL; | |
| 70 } | |
| 71 | |
| 72 return file; | |
| 73 } | |
| 74 | |
| 75 gint | |
| 76 mms_vfs_fclose_impl(VFSFile * file) | |
| 77 { | |
| 78 gint ret = 0; | |
| 79 | |
| 80 if (file == NULL) | |
| 81 return -1; | |
| 82 | |
| 83 if (file->handle) | |
| 84 { | |
| 85 MMSHandle *handle = (MMSHandle *) file->handle; | |
| 86 | |
| 87 mms_close(handle->mms); | |
| 88 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
|
89 file->handle = NULL; |
| 503 | 90 } |
| 91 | |
| 92 return ret; | |
| 93 } | |
| 94 | |
| 95 size_t | |
| 96 mms_vfs_fread_impl(gpointer ptr, | |
| 97 size_t size, | |
| 98 size_t nmemb, | |
| 99 VFSFile * file) | |
| 100 { | |
| 101 MMSHandle *handle; | |
| 102 gint ret; | |
| 103 | |
| 104 if (file == NULL) | |
| 105 return 0; | |
| 106 | |
| 107 handle = (MMSHandle *) file->handle; | |
| 108 | |
| 109 ret = mms_read(NULL, handle->mms, ptr, size * nmemb); | |
| 110 | |
| 111 if (ret < 0) | |
| 112 { | |
| 113 g_message("** mms **: errno(%d): %s", errno, strerror(errno)); | |
| 114 ret = EOF; | |
| 115 } | |
| 116 | |
| 117 return ret; | |
| 118 } | |
| 119 | |
| 120 size_t | |
| 121 mms_vfs_fwrite_impl(gconstpointer ptr, | |
| 122 size_t size, | |
| 123 size_t nmemb, | |
| 124 VFSFile * file) | |
| 125 { | |
| 126 return -1; | |
| 127 } | |
| 128 | |
| 129 gint | |
| 130 mms_vfs_getc_impl(VFSFile *stream) | |
| 131 { | |
| 132 MMSHandle *handle = (MMSHandle *) stream->handle; | |
| 133 guchar c; | |
| 134 | |
| 135 if (handle->charstack != NULL) | |
| 136 { | |
| 137 c = GPOINTER_TO_UINT(handle->charstack->data); | |
| 138 handle->charstack = g_slist_remove_link(handle->charstack, handle->charstack); | |
| 139 return c; | |
| 140 } | |
| 141 else | |
| 142 { | |
|
1190
ed2d7787779e
more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1148
diff
changeset
|
143 mms_read(NULL, handle->mms, (char *)&c, 1); |
| 503 | 144 return c; |
| 145 } | |
| 146 | |
| 147 return EOF; | |
| 148 } | |
| 149 | |
| 150 gint | |
| 151 mms_vfs_ungetc_impl(gint c, VFSFile *stream) | |
| 152 { | |
| 153 MMSHandle *handle = (MMSHandle *) stream->handle; | |
| 154 | |
| 155 handle->charstack = g_slist_append(handle->charstack, GUINT_TO_POINTER(c)); | |
| 156 | |
| 157 if (handle->charstack != NULL) | |
| 158 return c; | |
| 159 | |
| 160 return EOF; | |
| 161 } | |
| 162 | |
| 163 gint | |
| 164 mms_vfs_fseek_impl(VFSFile * file, | |
| 165 glong offset, | |
| 166 gint whence) | |
| 167 { | |
| 168 return -1; | |
| 169 } | |
| 170 | |
| 171 void | |
| 172 mms_vfs_rewind_impl(VFSFile * file) | |
| 173 { | |
| 174 return; | |
| 175 } | |
| 176 | |
| 177 glong | |
| 178 mms_vfs_ftell_impl(VFSFile * file) | |
| 179 { | |
| 180 MMSHandle *handle = (MMSHandle *) file->handle; | |
| 181 | |
| 182 return mms_get_current_pos(handle->mms); | |
| 183 } | |
| 184 | |
| 185 gboolean | |
| 186 mms_vfs_feof_impl(VFSFile * file) | |
| 187 { | |
| 188 MMSHandle *handle = (MMSHandle *) file->handle; | |
| 189 | |
| 190 return (gboolean) (mms_get_current_pos(handle->mms) == | |
| 191 mms_get_length(handle->mms)); | |
| 192 } | |
| 193 | |
| 194 gint | |
| 195 mms_vfs_truncate_impl(VFSFile * file, glong size) | |
| 196 { | |
| 197 return -1; | |
| 198 } | |
| 199 | |
| 965 | 200 off_t |
| 201 mms_vfs_fsize_impl(VFSFile * file) | |
| 202 { | |
| 203 return -1; | |
| 204 } | |
| 205 | |
| 503 | 206 VFSConstructor mms_const = { |
| 207 "mms://", | |
| 208 mms_vfs_fopen_impl, | |
| 209 mms_vfs_fclose_impl, | |
| 210 mms_vfs_fread_impl, | |
| 211 mms_vfs_fwrite_impl, | |
| 212 mms_vfs_getc_impl, | |
| 213 mms_vfs_ungetc_impl, | |
| 214 mms_vfs_fseek_impl, | |
| 215 mms_vfs_rewind_impl, | |
| 216 mms_vfs_ftell_impl, | |
| 217 mms_vfs_feof_impl, | |
| 965 | 218 mms_vfs_truncate_impl, |
| 219 mms_vfs_fsize_impl | |
| 503 | 220 }; |
| 221 | |
| 222 static void init(void) | |
| 223 { | |
| 224 vfs_register_transport(&mms_const); | |
| 225 } | |
| 226 | |
| 227 static void cleanup(void) | |
| 228 { | |
| 229 #if 0 | |
| 230 vfs_unregister_transport(&mms_const); | |
| 231 #endif | |
| 232 } | |
| 233 | |
|
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1228
diff
changeset
|
234 DECLARE_PLUGIN(mms, init, cleanup, NULL, NULL, NULL, NULL, NULL, NULL); |
