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