Mercurial > mplayer.hg
comparison stream/stream_smb.c @ 19271:64d82a45a05d
introduce new 'stream' directory for all stream layer related components and split them from libmpdemux
author | ben |
---|---|
date | Mon, 31 Jul 2006 17:39:17 +0000 |
parents | libmpdemux/stream_smb.c@d2d9d011203f |
children | 74d09d421f72 |
comparison
equal
deleted
inserted
replaced
19270:7d39b911f0bd | 19271:64d82a45a05d |
---|---|
1 | |
2 #include "config.h" | |
3 | |
4 #include <libsmbclient.h> | |
5 #include <unistd.h> | |
6 | |
7 #include "mp_msg.h" | |
8 #include "stream.h" | |
9 #include "help_mp.h" | |
10 #include "m_option.h" | |
11 #include "m_struct.h" | |
12 | |
13 static struct stream_priv_s { | |
14 } stream_priv_dflts = { | |
15 }; | |
16 | |
17 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f) | |
18 // URL definition | |
19 static m_option_t stream_opts_fields[] = { | |
20 { NULL, NULL, 0, 0, 0, 0, NULL } | |
21 }; | |
22 | |
23 static struct m_struct_st stream_opts = { | |
24 "smb", | |
25 sizeof(struct stream_priv_s), | |
26 &stream_priv_dflts, | |
27 stream_opts_fields | |
28 }; | |
29 | |
30 static char smb_password[15]; | |
31 static char smb_username[15]; | |
32 | |
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) | |
36 { | |
37 char temp[128]; | |
38 | |
39 strcpy(temp, "LAN"); | |
40 if (temp[strlen(temp) - 1] == 0x0a) | |
41 temp[strlen(temp) - 1] = 0x00; | |
42 | |
43 if (temp[0]) strncpy(workgroup, temp, wgmaxlen - 1); | |
44 | |
45 strcpy(temp, smb_username); | |
46 if (temp[strlen(temp) - 1] == 0x0a) | |
47 temp[strlen(temp) - 1] = 0x00; | |
48 | |
49 if (temp[0]) strncpy(username, temp, unmaxlen - 1); | |
50 | |
51 strcpy(temp, smb_password); | |
52 if (temp[strlen(temp) - 1] == 0x0a) | |
53 temp[strlen(temp) - 1] = 0x00; | |
54 | |
55 if (temp[0]) strncpy(password, temp, pwmaxlen - 1); | |
56 } | |
57 | |
58 static int seek(stream_t *s,off_t newpos) { | |
59 s->pos = newpos; | |
60 if(smbc_lseek(s->fd,s->pos,SEEK_SET)<0) { | |
61 s->eof=1; | |
62 return 0; | |
63 } | |
64 return 1; | |
65 } | |
66 | |
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; | |
70 } | |
71 | |
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; | |
75 } | |
76 | |
77 static void close_f(stream_t *s){ | |
78 smbc_close(s->fd); | |
79 } | |
80 | |
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; | |
83 char *filename; | |
84 mode_t m = 0; | |
85 off_t len; | |
86 int fd, err; | |
87 | |
88 filename = stream->url; | |
89 | |
90 if(mode == STREAM_READ) | |
91 m = O_RDONLY; | |
92 else if (mode == STREAM_WRITE) //who's gonna do that ? | |
93 m = O_WRONLY; | |
94 else { | |
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; | |
98 } | |
99 | |
100 if(!filename) { | |
101 mp_msg(MSGT_OPEN,MSGL_ERR, "[smb] Bad url\n"); | |
102 m_struct_free(&stream_opts, opts); | |
103 return STREAM_ERROR; | |
104 } | |
105 | |
106 err = smbc_init(smb_auth_fn, 1); | |
107 if (err < 0) { | |
108 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBInitError,err); | |
109 m_struct_free(&stream_opts, opts); | |
110 return STREAM_ERROR; | |
111 } | |
112 | |
113 fd = smbc_open(filename, m,0644); | |
114 if (fd < 0) { | |
115 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBFileNotFound, filename); | |
116 m_struct_free(&stream_opts, opts); | |
117 return STREAM_ERROR; | |
118 } | |
119 | |
120 len = smbc_lseek(fd,0,SEEK_END); | |
121 smbc_lseek (fd, 0, SEEK_SET); | |
122 if (len <= 0) | |
123 stream->flags = 0; | |
124 else { | |
125 stream->flags = STREAM_READ | STREAM_SEEK; | |
126 stream->end_pos = len; | |
127 stream->seek = seek; | |
128 } | |
129 stream->type = STREAMTYPE_SMB; | |
130 stream->fd = fd; | |
131 stream->fill_buffer = fill_buffer; | |
132 stream->write_buffer = write_buffer; | |
133 stream->close = close_f; | |
134 | |
135 m_struct_free(&stream_opts, opts); | |
136 return STREAM_OK; | |
137 } | |
138 | |
139 stream_info_t stream_info_smb = { | |
140 "Server Message Block", | |
141 "smb", | |
142 "M. Tourne", | |
143 "based on the code from 'a bulgarian' (one says)", | |
144 open_f, | |
145 {"smb", NULL}, | |
146 &stream_opts, | |
147 0 //Url is an option string | |
148 }; |