1 /*
2 * Copyright (c) 2014 Lukasz Marek <lukasz.m.luki@gmail.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <libsmbclient.h>
27
38
40 char *workgroup, int workgroup_len,
41 char *username, int username_len,
42 char *password, int password_len)
43 {
44 /* Do nothing yet. Credentials are passed via url.
45 * Callback must exists, there might be a segmentation fault otherwise. */
46 }
47
49 {
51
52 libsmbc->
ctx = smbc_new_context();
57 }
58 if (!smbc_init_context(libsmbc->
ctx)) {
62 }
63 smbc_set_context(libsmbc->
ctx);
64
65 smbc_setOptionUserData(libsmbc->
ctx,
h);
67
69 smbc_setTimeout(libsmbc->
ctx, libsmbc->
timeout);
72
73 if (smbc_init(
NULL, 0) < 0) {
77 }
78 return 0;
79 }
80
82 {
84 if (libsmbc->
fd >= 0) {
85 smbc_close(libsmbc->
fd);
87 }
89 smbc_free_context(libsmbc->
ctx, 1);
91 }
92 return 0;
93 }
94
96 {
99 struct stat st;
100
103
106
108 access = O_CREAT | O_RDWR;
110 access |= O_TRUNC;
112 access = O_CREAT | O_WRONLY;
114 access |= O_TRUNC;
115 } else
116 access = O_RDONLY;
117
118 /* 0666 = -rw-rw-rw- = read+write for everyone, minus umask */
119 if ((libsmbc->
fd = smbc_open(url, access, 0666)) < 0) {
123 }
124
125 if (smbc_fstat(libsmbc->
fd, &st) < 0)
127 else
129
130 return 0;
134 }
135
137 {
139 int64_t newpos;
140
145 } else
147 }
148
149 if ((newpos = smbc_lseek(libsmbc->
fd,
pos, whence)) < 0) {
150 int err = errno;
153 }
154
155 return newpos;
156 }
157
159 {
161 int bytes_read;
162
163 if ((bytes_read = smbc_read(libsmbc->
fd, buf,
size)) < 0) {
167 }
168
170 }
171
173 {
175 int bytes_written;
176
177 if ((bytes_written = smbc_write(libsmbc->
fd, buf,
size)) < 0) {
181 }
182
183 return bytes_written;
184 }
185
187 {
190
193
194 if ((libsmbc->
dh = smbc_opendir(
h->filename)) < 0) {
198 }
199
200 return 0;
201
205 }
206
208 {
211 struct smbc_dirent *dirent =
NULL;
213 int skip_entry;
214
216 if (!entry)
218
219 do {
220 skip_entry = 0;
221 dirent = smbc_readdir(libsmbc->
dh);
222 if (!dirent) {
224 return 0;
225 }
226 switch (dirent->smbc_type) {
227 case SMBC_DIR:
229 break;
230 case SMBC_FILE:
232 break;
233 case SMBC_FILE_SHARE:
235 break;
236 case SMBC_SERVER:
238 break;
239 case SMBC_WORKGROUP:
241 break;
242 case SMBC_COMMS_SHARE:
243 case SMBC_IPC_SHARE:
244 case SMBC_PRINTER_SHARE:
245 skip_entry = 1;
246 break;
247 case SMBC_LINK:
248 default:
250 break;
251 }
252 } while (skip_entry || !strcmp(dirent->name, ".") ||
253 !strcmp(dirent->name, ".."));
254
259 }
260
262 if (url) {
263 struct stat st;
264 if (!smbc_stat(url, &st)) {
267 entry->
size = st.st_size;
268 entry->
filemode = st.st_mode & 0777;
272 }
274 }
275
276 return 0;
277 }
278
280 {
282 if (libsmbc->
dh >= 0) {
283 smbc_closedir(libsmbc->
dh);
285 }
287 return 0;
288 }
289
291 {
294 struct stat st;
295
298
299 if ((libsmbc->
fd = smbc_open(
h->filename, O_WRONLY, 0666)) < 0) {
302 }
303
304 if (smbc_fstat(libsmbc->
fd, &st) < 0) {
307 }
308
309 smbc_close(libsmbc->
fd);
311
312 if (S_ISDIR(st.st_mode)) {
313 if (smbc_rmdir(
h->filename) < 0) {
316 }
317 } else {
318 if (smbc_unlink(
h->filename) < 0) {
321 }
322 }
323
325
329 }
330
332 {
335
338
342 }
343
345
349 }
350
351 #define OFFSET(x) offsetof(LIBSMBContext, x)
352 #define D AV_OPT_FLAG_DECODING_PARAM
353 #define E AV_OPT_FLAG_ENCODING_PARAM
355 {
"timeout",
"set timeout in ms of socket I/O operations",
OFFSET(timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
359 };
360
366 };
367
383 };