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
37
39 char *workgroup, int workgroup_len,
40 char *username, int username_len,
41 char *password, int password_len)
42 {
43 /* Do nothing yet. Credentials are passed via url.
44 * Callback must exists, there might be a segmentation fault otherwise. */
45 }
46
48 {
50
51 libsmbc->
ctx = smbc_new_context();
55 }
56 if (!smbc_init_context(libsmbc->
ctx)) {
59 }
60 smbc_set_context(libsmbc->
ctx);
61
62 smbc_setOptionUserData(libsmbc->
ctx, h);
64
66 smbc_setTimeout(libsmbc->
ctx, libsmbc->
timeout);
69
70 if (smbc_init(NULL, 0) < 0) {
73 }
74 return 0;
75 }
76
78 {
80 if (libsmbc->
fd >= 0) {
81 smbc_close(libsmbc->
fd);
83 }
85 smbc_free_context(libsmbc->
ctx, 1);
87 }
88 return 0;
89 }
90
92 {
95 struct stat st;
96
99
101 goto fail;
102
104 access = O_CREAT | O_RDWR;
106 access |= O_TRUNC;
107 } else if (flags & AVIO_FLAG_WRITE) {
108 access = O_CREAT | O_WRONLY;
110 access |= O_TRUNC;
111 } else
112 access = O_RDONLY;
113
114 /* 0666 = -rw-rw-rw- = read+write for everyone, minus umask */
115 if ((libsmbc->
fd = smbc_open(url, access, 0666)) < 0) {
118 goto fail;
119 }
120
121 if (smbc_fstat(libsmbc->
fd, &st) < 0)
123 else
125
126 return 0;
127 fail:
130 }
131
133 {
135 int64_t newpos;
136
141 } else
143 }
144
145 if ((newpos = smbc_lseek(libsmbc->
fd, pos, whence)) < 0) {
146 int err = errno;
149 }
150
151 return newpos;
152 }
153
155 {
157 int bytes_read;
158
159 if ((bytes_read = smbc_read(libsmbc->
fd, buf, size)) < 0) {
162 }
163
164 return bytes_read;
165 }
166
168 {
170 int bytes_written;
171
172 if ((bytes_written = smbc_write(libsmbc->
fd, buf, size)) < 0) {
175 }
176
177 return bytes_written;
178 }
179
180 #define OFFSET(x) offsetof(LIBSMBContext, x)
181 #define D AV_OPT_FLAG_DECODING_PARAM
182 #define E AV_OPT_FLAG_ENCODING_PARAM
184 {
"timeout",
"set timeout in ms of socket I/O operations",
OFFSET(timeout),
AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX,
D|
E },
187 {NULL}
188 };
189
195 };
196
205 .priv_data_class = &libsmbclient_context_class,
207 };