Mercurial > audlegacy-plugins
annotate src/smb/smb.c @ 2162:c4b97a9c1f6b
remove get_time().
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Tue, 13 Nov 2007 05:11:47 +0900 |
parents | fa9f85cebade |
children | 3134a0987162 |
rev | line source |
---|---|
845 | 1 /* Audacious |
2 * Copyright (c) 2007 Daniel Bradshaw | |
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 | |
1961
e8ea3a76a84e
Various #include cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
1954
diff
changeset
|
19 #include "config.h" |
845 | 20 #include <audacious/plugin.h> |
21 #include <stdio.h> | |
22 | |
23 #include <unistd.h> | |
24 #include <sys/stat.h> | |
25 #include <sys/types.h> | |
26 | |
27 #include <libsmbclient.h> | |
28 | |
29 static void smb_auth_fn(const char *srv, | |
30 const char *shr, | |
31 char *wg, int wglen, | |
32 char *un, int unlen, | |
33 char *pw, int pwlen) | |
34 { | |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
35 /* Does absolutely nothing :P */ |
845 | 36 } |
37 | |
871 | 38 typedef struct _SMBFile { |
845 | 39 int fd; |
40 long length; | |
871 | 41 } SMBFile; |
845 | 42 |
871 | 43 /* TODO: make writing work. */ |
1978 | 44 VFSFile *smb_aud_vfs_fopen_impl(const gchar * path, const gchar * mode) |
845 | 45 { |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
46 VFSFile *file; |
871 | 47 SMBFile *handle; |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
48 struct stat st; |
845 | 49 |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
50 if (!path || !mode) |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
51 return NULL; |
845 | 52 |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
53 file = g_new0(VFSFile, 1); |
871 | 54 handle = g_new0(SMBFile, 1); |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
55 handle->fd = smbc_open(path, O_RDONLY, 0); |
845 | 56 |
871 | 57 if (handle->fd < 0) { |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
58 g_free(file); |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
59 file = NULL; |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
60 } else { |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
61 smbc_stat(path,&st); |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
62 handle->length = st.st_size; |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
63 file->handle = (void *)handle; |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
64 } |
845 | 65 |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
66 return file; |
845 | 67 } |
68 | |
1978 | 69 gint smb_aud_vfs_fclose_impl(VFSFile * file) |
845 | 70 { |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
71 gint ret = 0; |
871 | 72 SMBFile *handle; |
845 | 73 |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
74 if (file == NULL) |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
75 return -1; |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
76 |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
77 if (file->handle) |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
78 { |
871 | 79 handle = (SMBFile *)file->handle; |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
80 if (smbc_close(handle->fd) != 0) |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
81 ret = -1; |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
82 g_free(file->handle); |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
83 } |
845 | 84 |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
85 return ret; |
845 | 86 } |
87 | |
1978 | 88 size_t smb_aud_vfs_fread_impl(gpointer ptr, size_t size, size_t nmemb, VFSFile * file) |
845 | 89 { |
871 | 90 SMBFile *handle; |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
91 if (file == NULL) |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
92 return 0; |
871 | 93 handle = (SMBFile *)file->handle; |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
94 return smbc_read(handle->fd, ptr, size * nmemb); |
845 | 95 } |
96 | |
1978 | 97 size_t smb_aud_vfs_fwrite_impl(gconstpointer ptr, size_t size, size_t nmemb, VFSFile * file) |
845 | 98 { |
99 return 0; | |
100 } | |
101 | |
1978 | 102 gint smb_aud_vfs_getc_impl(VFSFile *file) |
845 | 103 { |
871 | 104 SMBFile *handle; |
105 char temp; | |
106 handle = (SMBFile *)file->handle; | |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
107 smbc_read(handle->fd, &temp, 1); |
871 | 108 return (gint) temp; |
845 | 109 } |
110 | |
1978 | 111 gint smb_aud_vfs_fseek_impl(VFSFile * file, glong offset, gint whence) |
845 | 112 { |
871 | 113 SMBFile *handle; |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
114 glong roffset = offset; |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
115 gint ret = 0; |
845 | 116 if (file == NULL) |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
117 return 0; |
845 | 118 |
871 | 119 handle = (SMBFile *)file->handle; |
845 | 120 |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
121 if (whence == SEEK_END) |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
122 { |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
123 roffset = handle->length + offset; |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
124 if (roffset < 0) |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
125 roffset = 0; |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
126 |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
127 ret = smbc_lseek(handle->fd, roffset, SEEK_SET); |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
128 //printf("%ld -> %ld = %d\n",offset, roffset, ret); |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
129 } |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
130 else |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
131 { |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
132 if (roffset < 0) |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
133 roffset = 0; |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
134 ret = smbc_lseek(handle->fd, roffset, whence); |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
135 //printf("%ld %d = %d\n",roffset, whence, ret); |
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
136 } |
845 | 137 |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
138 return ret; |
845 | 139 } |
140 | |
1978 | 141 gint smb_aud_vfs_ungetc_impl(gint c, VFSFile *file) |
845 | 142 { |
1978 | 143 smb_aud_vfs_fseek_impl(file, -1, SEEK_CUR); |
845 | 144 return c; |
145 } | |
146 | |
1978 | 147 void smb_aud_vfs_rewind_impl(VFSFile * file) |
845 | 148 { |
1978 | 149 smb_aud_vfs_fseek_impl(file, 0, SEEK_SET); |
845 | 150 } |
151 | |
152 glong | |
1978 | 153 smb_aud_vfs_ftell_impl(VFSFile * file) |
845 | 154 { |
871 | 155 SMBFile *handle; |
156 handle = (SMBFile *)file->handle; | |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
157 return smbc_lseek(handle->fd, 0, SEEK_CUR); |
845 | 158 } |
159 | |
160 gboolean | |
1978 | 161 smb_aud_vfs_feof_impl(VFSFile * file) |
845 | 162 { |
871 | 163 SMBFile *handle; |
845 | 164 off_t at; |
871 | 165 |
1978 | 166 at = smb_aud_vfs_ftell_impl(file); |
871 | 167 |
846
76983ca8178a
[svn] - Adjust indenting cause the previous indenting was painful
nazca
parents:
845
diff
changeset
|
168 //printf("%d %d %ld %ld\n",sizeof(int), sizeof(off_t), at, handle->length); |
845 | 169 return (gboolean) (at == handle->length) ? TRUE : FALSE; |
170 } | |
171 | |
172 gint | |
1978 | 173 smb_aud_vfs_truncate_impl(VFSFile * file, glong size) |
845 | 174 { |
175 return -1; | |
176 } | |
177 | |
965 | 178 off_t |
1978 | 179 smb_aud_vfs_fsize_impl(VFSFile * file) |
965 | 180 { |
971 | 181 SMBFile *handle = (SMBFile *)file->handle; |
182 | |
183 return handle->length; | |
965 | 184 } |
185 | |
845 | 186 VFSConstructor smb_const = { |
187 "smb://", | |
1978 | 188 smb_aud_vfs_fopen_impl, |
189 smb_aud_vfs_fclose_impl, | |
190 smb_aud_vfs_fread_impl, | |
191 smb_aud_vfs_fwrite_impl, | |
192 smb_aud_vfs_getc_impl, | |
193 smb_aud_vfs_ungetc_impl, | |
194 smb_aud_vfs_fseek_impl, | |
195 smb_aud_vfs_rewind_impl, | |
196 smb_aud_vfs_ftell_impl, | |
197 smb_aud_vfs_feof_impl, | |
198 smb_aud_vfs_truncate_impl, | |
199 smb_aud_vfs_fsize_impl | |
845 | 200 }; |
201 | |
202 static void init(void) | |
203 { | |
871 | 204 int err; |
205 | |
206 err = smbc_init(smb_auth_fn, 1); | |
872
ad00b785dec0
[svn] - Slight tweak ... smbc_init returns 0 on sucess, not fail
nazca
parents:
871
diff
changeset
|
207 if (err < 0) |
871 | 208 { |
209 g_message("[smb] not starting samba support due to error code %d", err); | |
210 return; | |
211 } | |
212 | |
1978 | 213 aud_vfs_register_transport(&smb_const); |
845 | 214 } |
215 | |
216 static void cleanup(void) | |
217 { | |
218 #if 0 | |
1978 | 219 aud_vfs_unregister_transport(&smb_const); |
845 | 220 #endif |
221 } | |
222 | |
223 LowlevelPlugin llp_smb = { | |
224 NULL, | |
225 NULL, | |
226 "smb:// URI Transport", | |
227 init, | |
228 cleanup, | |
229 }; | |
230 | |
231 LowlevelPlugin *get_lplugin_info(void) | |
232 { | |
233 return &llp_smb; | |
234 } | |
235 |