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>
29 static struct stream_priv_s
{
30 } stream_priv_dflts
= {
33 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
35 static const m_option_t stream_opts_fields
[] = {
36 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
39 static const struct m_struct_st stream_opts
= {
41 sizeof(struct stream_priv_s
),
46 static char smb_password
[15];
47 static char smb_username
[15];
49 static void smb_auth_fn(const char *server
, const char *share
,
50 char *workgroup
, int wgmaxlen
, char *username
, int unmaxlen
,
51 char *password
, int pwmaxlen
)
56 if (temp
[strlen(temp
) - 1] == 0x0a)
57 temp
[strlen(temp
) - 1] = 0x00;
59 if (temp
[0]) strncpy(workgroup
, temp
, wgmaxlen
- 1);
61 strcpy(temp
, smb_username
);
62 if (temp
[strlen(temp
) - 1] == 0x0a)
63 temp
[strlen(temp
) - 1] = 0x00;
65 if (temp
[0]) strncpy(username
, temp
, unmaxlen
- 1);
67 strcpy(temp
, smb_password
);
68 if (temp
[strlen(temp
) - 1] == 0x0a)
69 temp
[strlen(temp
) - 1] = 0x00;
71 if (temp
[0]) strncpy(password
, temp
, pwmaxlen
- 1);
74 static int control(stream_t
*s
, int cmd
, void *arg
) {
76 case STREAM_CTRL_GET_SIZE
: {
77 off_t size
= smbc_lseek(s
->fd
,0,SEEK_END
);
78 smbc_lseek(s
->fd
,s
->pos
,SEEK_SET
);
79 if(size
!= (off_t
)-1) {
80 *((off_t
*)arg
) = size
;
85 return STREAM_UNSUPPORTED
;
88 static int seek(stream_t
*s
,off_t newpos
) {
90 if(smbc_lseek(s
->fd
,s
->pos
,SEEK_SET
)<0) {
97 static int fill_buffer(stream_t
*s
, char* buffer
, int max_len
){
98 int r
= smbc_read(s
->fd
,buffer
,max_len
);
99 return (r
<= 0) ? -1 : r
;
102 static int write_buffer(stream_t
*s
, char* buffer
, int len
) {
103 int r
= smbc_write(s
->fd
,buffer
,len
);
104 return (r
<= 0) ? -1 : r
;
107 static void close_f(stream_t
*s
){
111 static int open_f (stream_t
*stream
, int mode
, void *opts
, int* file_format
) {
112 struct stream_priv_s
*p
= (struct stream_priv_s
*)opts
;
118 filename
= stream
->url
;
120 if(mode
== STREAM_READ
)
122 else if (mode
== STREAM_WRITE
) //who's gonna do that ?
123 m
= O_RDWR
|O_CREAT
|O_TRUNC
;
125 mp_msg(MSGT_OPEN
, MSGL_ERR
, "[smb] Unknown open mode %d\n", mode
);
126 m_struct_free (&stream_opts
, opts
);
127 return STREAM_UNSUPPORTED
;
131 mp_msg(MSGT_OPEN
,MSGL_ERR
, "[smb] Bad url\n");
132 m_struct_free(&stream_opts
, opts
);
136 err
= smbc_init(smb_auth_fn
, 1);
138 mp_tmsg(MSGT_OPEN
,MSGL_ERR
,"Cannot init the libsmbclient library: %d\n",err
);
139 m_struct_free(&stream_opts
, opts
);
143 fd
= smbc_open(filename
, m
,0644);
145 mp_tmsg(MSGT_OPEN
,MSGL_ERR
,"Could not open from LAN: '%s'\n", filename
);
146 m_struct_free(&stream_opts
, opts
);
150 stream
->flags
= mode
;
152 if(mode
== STREAM_READ
) {
153 len
= smbc_lseek(fd
,0,SEEK_END
);
154 smbc_lseek (fd
, 0, SEEK_SET
);
156 if(len
> 0 || mode
== STREAM_WRITE
) {
157 stream
->flags
|= MP_STREAM_SEEK
;
159 if(mode
== STREAM_READ
) stream
->end_pos
= len
;
161 stream
->type
= STREAMTYPE_SMB
;
163 stream
->fill_buffer
= fill_buffer
;
164 stream
->write_buffer
= write_buffer
;
165 stream
->close
= close_f
;
166 stream
->control
= control
;
168 m_struct_free(&stream_opts
, opts
);
172 const stream_info_t stream_info_smb
= {
173 "Server Message Block",
176 "based on the code from 'a bulgarian' (one says)",
180 0 //Url is an option string