4 #include <libsmbclient.h>
13 static struct stream_priv_s
{
14 } stream_priv_dflts
= {
17 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
19 static const m_option_t stream_opts_fields
[] = {
20 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
23 static const struct m_struct_st stream_opts
= {
25 sizeof(struct stream_priv_s
),
30 static char smb_password
[15];
31 static char smb_username
[15];
33 static void smb_auth_fn(const char *server
, const char *share
,
34 char *workgroup
, int wgmaxlen
, char *username
, int unmaxlen
,
35 char *password
, int pwmaxlen
)
40 if (temp
[strlen(temp
) - 1] == 0x0a)
41 temp
[strlen(temp
) - 1] = 0x00;
43 if (temp
[0]) strncpy(workgroup
, temp
, wgmaxlen
- 1);
45 strcpy(temp
, smb_username
);
46 if (temp
[strlen(temp
) - 1] == 0x0a)
47 temp
[strlen(temp
) - 1] = 0x00;
49 if (temp
[0]) strncpy(username
, temp
, unmaxlen
- 1);
51 strcpy(temp
, smb_password
);
52 if (temp
[strlen(temp
) - 1] == 0x0a)
53 temp
[strlen(temp
) - 1] = 0x00;
55 if (temp
[0]) strncpy(password
, temp
, pwmaxlen
- 1);
58 static int control(stream_t
*s
, int cmd
, void *arg
) {
60 case STREAM_CTRL_GET_SIZE
: {
61 off_t size
= smbc_lseek(s
->fd
,0,SEEK_END
);
62 smbc_lseek(s
->fd
,s
->pos
,SEEK_SET
);
63 if(size
!= (off_t
)-1) {
64 *((off_t
*)arg
) = size
;
69 return STREAM_UNSUPPORTED
;
72 static int seek(stream_t
*s
,off_t newpos
) {
74 if(smbc_lseek(s
->fd
,s
->pos
,SEEK_SET
)<0) {
81 static int fill_buffer(stream_t
*s
, char* buffer
, int max_len
){
82 int r
= smbc_read(s
->fd
,buffer
,max_len
);
83 return (r
<= 0) ? -1 : r
;
86 static int write_buffer(stream_t
*s
, char* buffer
, int len
) {
87 int r
= smbc_write(s
->fd
,buffer
,len
);
88 return (r
<= 0) ? -1 : r
;
91 static void close_f(stream_t
*s
){
95 static int open_f (stream_t
*stream
, int mode
, void *opts
, int* file_format
) {
96 struct stream_priv_s
*p
= (struct stream_priv_s
*)opts
;
102 filename
= stream
->url
;
104 if(mode
== STREAM_READ
)
106 else if (mode
== STREAM_WRITE
) //who's gonna do that ?
107 m
= O_RDWR
|O_CREAT
|O_TRUNC
;
109 mp_msg(MSGT_OPEN
, MSGL_ERR
, "[smb] Unknown open mode %d\n", mode
);
110 m_struct_free (&stream_opts
, opts
);
111 return STREAM_UNSUPPORTED
;
115 mp_msg(MSGT_OPEN
,MSGL_ERR
, "[smb] Bad url\n");
116 m_struct_free(&stream_opts
, opts
);
120 err
= smbc_init(smb_auth_fn
, 1);
122 mp_tmsg(MSGT_OPEN
,MSGL_ERR
,"Cannot init the libsmbclient library: %d\n",err
);
123 m_struct_free(&stream_opts
, opts
);
127 fd
= smbc_open(filename
, m
,0644);
129 mp_tmsg(MSGT_OPEN
,MSGL_ERR
,"Could not open from LAN: '%s'\n", filename
);
130 m_struct_free(&stream_opts
, opts
);
134 stream
->flags
= mode
;
136 if(mode
== STREAM_READ
) {
137 len
= smbc_lseek(fd
,0,SEEK_END
);
138 smbc_lseek (fd
, 0, SEEK_SET
);
140 if(len
> 0 || mode
== STREAM_WRITE
) {
141 stream
->flags
|= STREAM_SEEK
;
143 if(mode
== STREAM_READ
) stream
->end_pos
= len
;
145 stream
->type
= STREAMTYPE_SMB
;
147 stream
->fill_buffer
= fill_buffer
;
148 stream
->write_buffer
= write_buffer
;
149 stream
->close
= close_f
;
150 stream
->control
= control
;
152 m_struct_free(&stream_opts
, opts
);
156 const stream_info_t stream_info_smb
= {
157 "Server Message Block",
160 "based on the code from 'a bulgarian' (one says)",
164 0 //Url is an option string