6 #include <libsmbclient.h>
15 static struct stream_priv_s
{
16 } stream_priv_dflts
= {
19 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
21 static m_option_t stream_opts_fields
[] = {
22 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
25 static struct m_struct_st stream_opts
= {
27 sizeof(struct stream_priv_s
),
32 static char smb_password
[15];
33 static char smb_username
[15];
35 static void smb_auth_fn(const char *server
, const char *share
,
36 char *workgroup
, int wgmaxlen
, char *username
, int unmaxlen
,
37 char *password
, int pwmaxlen
)
42 if (temp
[strlen(temp
) - 1] == 0x0a)
43 temp
[strlen(temp
) - 1] = 0x00;
45 if (temp
[0]) strncpy(workgroup
, temp
, wgmaxlen
- 1);
47 strcpy(temp
, smb_username
);
48 if (temp
[strlen(temp
) - 1] == 0x0a)
49 temp
[strlen(temp
) - 1] = 0x00;
51 if (temp
[0]) strncpy(username
, temp
, unmaxlen
- 1);
53 strcpy(temp
, smb_password
);
54 if (temp
[strlen(temp
) - 1] == 0x0a)
55 temp
[strlen(temp
) - 1] = 0x00;
57 if (temp
[0]) strncpy(password
, temp
, pwmaxlen
- 1);
60 static int seek(stream_t
*s
,off_t newpos
) {
62 if(smbc_lseek(s
->fd
,s
->pos
,SEEK_SET
)<0) {
69 static int fill_buffer(stream_t
*s
, char* buffer
, int max_len
){
70 int r
= smbc_read(s
->fd
,buffer
,max_len
);
71 return (r
<= 0) ? -1 : r
;
74 static int write_buffer(stream_t
*s
, char* buffer
, int len
) {
75 int r
= smbc_write(s
->fd
,buffer
,len
);
76 return (r
<= 0) ? -1 : r
;
79 static void close_f(stream_t
*s
){
83 static int open_f (stream_t
*stream
, int mode
, void *opts
, int* file_format
) {
84 struct stream_priv_s
*p
= (struct stream_priv_s
*)opts
;
90 filename
= stream
->url
;
92 if(mode
== STREAM_READ
)
94 else if (mode
== STREAM_WRITE
) //who's gonna do that ?
97 mp_msg(MSGT_OPEN
, MSGL_ERR
, "[smb] Unknown open mode %d\n", mode
);
98 m_struct_free (&stream_opts
, opts
);
99 return STREAM_UNSUPORTED
;
103 mp_msg(MSGT_OPEN
,MSGL_ERR
, "[smb] Bad url\n");
104 m_struct_free(&stream_opts
, opts
);
108 err
= smbc_init(smb_auth_fn
, 1);
110 mp_msg(MSGT_OPEN
,MSGL_ERR
,MSGTR_SMBInitError
,err
);
111 m_struct_free(&stream_opts
, opts
);
115 fd
= smbc_open(filename
, m
,0644);
117 mp_msg(MSGT_OPEN
,MSGL_ERR
,MSGTR_SMBFileNotFound
, filename
);
118 m_struct_free(&stream_opts
, opts
);
122 len
= smbc_lseek(fd
,0,SEEK_END
);
123 smbc_lseek (fd
, 0, SEEK_SET
);
127 stream
->flags
= STREAM_READ
| STREAM_SEEK
;
128 stream
->end_pos
= len
;
131 stream
->type
= STREAMTYPE_SMB
;
133 stream
->fill_buffer
= fill_buffer
;
134 stream
->write_buffer
= write_buffer
;
135 stream
->close
= close_f
;
137 m_struct_free(&stream_opts
, opts
);
141 stream_info_t stream_info_smb
= {
142 "Server Message Block",
145 "based on the code from 'a bulgarian' (one says)",
149 0 //Url is an option string