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 m_option_t stream_opts_fields
[] = {
20 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
23 static 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 seek(stream_t
*s
,off_t newpos
) {
60 if(smbc_lseek(s
->fd
,s
->pos
,SEEK_SET
)<0) {
67 static int fill_buffer(stream_t
*s
, char* buffer
, int max_len
){
68 int r
= smbc_read(s
->fd
,buffer
,max_len
);
69 return (r
<= 0) ? -1 : r
;
72 static int write_buffer(stream_t
*s
, char* buffer
, int len
) {
73 int r
= smbc_write(s
->fd
,buffer
,len
);
74 return (r
<= 0) ? -1 : r
;
77 static void close_f(stream_t
*s
){
81 static int open_f (stream_t
*stream
, int mode
, void *opts
, int* file_format
) {
82 struct stream_priv_s
*p
= (struct stream_priv_s
*)opts
;
88 filename
= stream
->url
;
90 if(mode
== STREAM_READ
)
92 else if (mode
== STREAM_WRITE
) //who's gonna do that ?
95 mp_msg(MSGT_OPEN
, MSGL_ERR
, "[smb] Unknown open mode %d\n", mode
);
96 m_struct_free (&stream_opts
, opts
);
97 return STREAM_UNSUPORTED
;
101 mp_msg(MSGT_OPEN
,MSGL_ERR
, "[smb] Bad url\n");
102 m_struct_free(&stream_opts
, opts
);
106 err
= smbc_init(smb_auth_fn
, 1);
108 mp_msg(MSGT_OPEN
,MSGL_ERR
,MSGTR_SMBInitError
,err
);
109 m_struct_free(&stream_opts
, opts
);
113 fd
= smbc_open(filename
, m
,0644);
115 mp_msg(MSGT_OPEN
,MSGL_ERR
,MSGTR_SMBFileNotFound
, filename
);
116 m_struct_free(&stream_opts
, opts
);
120 len
= smbc_lseek(fd
,0,SEEK_END
);
121 smbc_lseek (fd
, 0, SEEK_SET
);
125 stream
->flags
= STREAM_READ
| STREAM_SEEK
;
126 stream
->end_pos
= len
;
129 stream
->type
= STREAMTYPE_SMB
;
131 stream
->fill_buffer
= fill_buffer
;
132 stream
->write_buffer
= write_buffer
;
133 stream
->close
= close_f
;
135 m_struct_free(&stream_opts
, opts
);
139 stream_info_t stream_info_smb
= {
140 "Server Message Block",
143 "based on the code from 'a bulgarian' (one says)",
147 0 //Url is an option string