2 * This file is part of MPlayer.
4 * MPlayer 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.
9 * MPlayer 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.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <libsmbclient.h>
30 static struct stream_priv_s
{
31 } stream_priv_dflts
= {
34 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
36 static const m_option_t stream_opts_fields
[] = {
37 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
40 static const struct m_struct_st stream_opts
= {
42 sizeof(struct stream_priv_s
),
47 static char smb_password
[15];
48 static char smb_username
[15];
50 static void smb_auth_fn(const char *server
, const char *share
,
51 char *workgroup
, int wgmaxlen
, char *username
, int unmaxlen
,
52 char *password
, int pwmaxlen
)
57 if (temp
[strlen(temp
) - 1] == 0x0a)
58 temp
[strlen(temp
) - 1] = 0x00;
60 if (temp
[0]) strncpy(workgroup
, temp
, wgmaxlen
- 1);
62 strcpy(temp
, smb_username
);
63 if (temp
[strlen(temp
) - 1] == 0x0a)
64 temp
[strlen(temp
) - 1] = 0x00;
66 if (temp
[0]) strncpy(username
, temp
, unmaxlen
- 1);
68 strcpy(temp
, smb_password
);
69 if (temp
[strlen(temp
) - 1] == 0x0a)
70 temp
[strlen(temp
) - 1] = 0x00;
72 if (temp
[0]) strncpy(password
, temp
, pwmaxlen
- 1);
75 static int control(stream_t
*s
, int cmd
, void *arg
) {
77 case STREAM_CTRL_GET_SIZE
: {
78 off_t size
= smbc_lseek(s
->fd
,0,SEEK_END
);
79 smbc_lseek(s
->fd
,s
->pos
,SEEK_SET
);
80 if(size
!= (off_t
)-1) {
81 *((off_t
*)arg
) = size
;
86 return STREAM_UNSUPPORTED
;
89 static int seek(stream_t
*s
,off_t newpos
) {
91 if(smbc_lseek(s
->fd
,s
->pos
,SEEK_SET
)<0) {
98 static int fill_buffer(stream_t
*s
, char* buffer
, int max_len
){
99 int r
= smbc_read(s
->fd
,buffer
,max_len
);
100 return (r
<= 0) ? -1 : r
;
103 static int write_buffer(stream_t
*s
, char* buffer
, int len
) {
104 int r
= smbc_write(s
->fd
,buffer
,len
);
105 return (r
<= 0) ? -1 : r
;
108 static void close_f(stream_t
*s
){
112 static int open_f (stream_t
*stream
, int mode
, void *opts
, int* file_format
) {
113 struct stream_priv_s
*p
= (struct stream_priv_s
*)opts
;
119 filename
= stream
->url
;
121 if(mode
== STREAM_READ
)
123 else if (mode
== STREAM_WRITE
) //who's gonna do that ?
124 m
= O_RDWR
|O_CREAT
|O_TRUNC
;
126 mp_msg(MSGT_OPEN
, MSGL_ERR
, "[smb] Unknown open mode %d\n", mode
);
127 m_struct_free (&stream_opts
, opts
);
128 return STREAM_UNSUPPORTED
;
132 mp_msg(MSGT_OPEN
,MSGL_ERR
, "[smb] Bad url\n");
133 m_struct_free(&stream_opts
, opts
);
137 err
= smbc_init(smb_auth_fn
, 1);
139 mp_tmsg(MSGT_OPEN
,MSGL_ERR
,"Cannot init the libsmbclient library: %d\n",err
);
140 m_struct_free(&stream_opts
, opts
);
144 fd
= smbc_open(filename
, m
,0644);
146 mp_tmsg(MSGT_OPEN
,MSGL_ERR
,"Could not open from LAN: '%s'\n", filename
);
147 m_struct_free(&stream_opts
, opts
);
151 stream
->flags
= mode
;
153 if(mode
== STREAM_READ
) {
154 len
= smbc_lseek(fd
,0,SEEK_END
);
155 smbc_lseek (fd
, 0, SEEK_SET
);
157 if(len
> 0 || mode
== STREAM_WRITE
) {
158 stream
->flags
|= MP_STREAM_SEEK
;
160 if(mode
== STREAM_READ
) stream
->end_pos
= len
;
162 stream
->type
= STREAMTYPE_SMB
;
164 stream
->fill_buffer
= fill_buffer
;
165 stream
->write_buffer
= write_buffer
;
166 stream
->close
= close_f
;
167 stream
->control
= control
;
169 m_struct_free(&stream_opts
, opts
);
173 const stream_info_t stream_info_smb
= {
174 "Server Message Block",
177 "based on the code from 'a bulgarian' (one says)",
181 0 //Url is an option string