annotate stream/stream_smb.c @ 31714:140bde72c97f

Add some "const" to avoid incompatible pointer type warnings
author reimar
date Sat, 24 Jul 2010 11:33:28 +0000
parents ce0122361a39
children 77d81e27a176
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30426
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
1 /*
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
2 * This file is part of MPlayer.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
3 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
5 * it under the terms of the GNU General Public License as published by
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
7 * (at your option) any later version.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
8 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
12 * GNU General Public License for more details.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
13 *
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
14 * You should have received a copy of the GNU General Public License along
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ce0122361a39 Add license header to all files missing it in the stream subdirectory.
diego
parents: 29920
diff changeset
17 */
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
18
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
19 #include "config.h"
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
20
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
21 #include <libsmbclient.h>
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
22 #include <unistd.h>
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
23
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
24 #include "mp_msg.h"
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
25 #include "stream.h"
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
26 #include "help_mp.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 15521
diff changeset
27 #include "m_option.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 15521
diff changeset
28 #include "m_struct.h"
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
29
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
30 static struct stream_priv_s {
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
31 } stream_priv_dflts = {
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
32 };
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
33
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
34 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s,f)
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
35 // URL definition
25242
371a40dcc1cc stream_opts arrays should be const
reimar
parents: 25211
diff changeset
36 static const m_option_t stream_opts_fields[] = {
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
37 { NULL, NULL, 0, 0, 0, 0, NULL }
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
38 };
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
39
25691
68015115f63a stream_opts should be const
reimar
parents: 25242
diff changeset
40 static const struct m_struct_st stream_opts = {
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
41 "smb",
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
42 sizeof(struct stream_priv_s),
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
43 &stream_priv_dflts,
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
44 stream_opts_fields
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
45 };
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
46
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
47 static char smb_password[15];
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
48 static char smb_username[15];
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
49
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
50 static void smb_auth_fn(const char *server, const char *share,
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
51 char *workgroup, int wgmaxlen, char *username, int unmaxlen,
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
52 char *password, int pwmaxlen)
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
53 {
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
54 char temp[128];
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
55
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
56 strcpy(temp, "LAN");
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
57 if (temp[strlen(temp) - 1] == 0x0a)
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
58 temp[strlen(temp) - 1] = 0x00;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
59
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
60 if (temp[0]) strncpy(workgroup, temp, wgmaxlen - 1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
61
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
62 strcpy(temp, smb_username);
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
63 if (temp[strlen(temp) - 1] == 0x0a)
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
64 temp[strlen(temp) - 1] = 0x00;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
65
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
66 if (temp[0]) strncpy(username, temp, unmaxlen - 1);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
67
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
68 strcpy(temp, smb_password);
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
69 if (temp[strlen(temp) - 1] == 0x0a)
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
70 temp[strlen(temp) - 1] = 0x00;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
71
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
72 if (temp[0]) strncpy(password, temp, pwmaxlen - 1);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
73 }
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
74
21674
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
75 static int control(stream_t *s, int cmd, void *arg) {
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
76 switch(cmd) {
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
77 case STREAM_CTRL_GET_SIZE: {
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
78 off_t size = smbc_lseek(s->fd,0,SEEK_END);
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
79 smbc_lseek(s->fd,s->pos,SEEK_SET);
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
80 if(size != (off_t)-1) {
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
81 *((off_t*)arg) = size;
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
82 return 1;
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
83 }
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
84 }
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
85 }
24257
d261f5109660 cosmetics: typo fix UNSUPORTED --> UNSUPPORTED
diego
parents: 22451
diff changeset
86 return STREAM_UNSUPPORTED;
21674
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
87 }
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
88
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
89 static int seek(stream_t *s,off_t newpos) {
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
90 s->pos = newpos;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
91 if(smbc_lseek(s->fd,s->pos,SEEK_SET)<0) {
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
92 s->eof=1;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
93 return 0;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
94 }
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
95 return 1;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
96 }
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
97
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
98 static int fill_buffer(stream_t *s, char* buffer, int max_len){
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
99 int r = smbc_read(s->fd,buffer,max_len);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
100 return (r <= 0) ? -1 : r;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
101 }
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
102
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
103 static int write_buffer(stream_t *s, char* buffer, int len) {
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
104 int r = smbc_write(s->fd,buffer,len);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
105 return (r <= 0) ? -1 : r;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
106 }
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
107
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
108 static void close_f(stream_t *s){
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
109 smbc_close(s->fd);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
110 }
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
111
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
112 static int open_f (stream_t *stream, int mode, void *opts, int* file_format) {
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
113 struct stream_priv_s *p = (struct stream_priv_s*)opts;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
114 char *filename;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
115 mode_t m = 0;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
116 off_t len;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
117 int fd, err;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
118
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
119 filename = stream->url;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
120
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
121 if(mode == STREAM_READ)
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
122 m = O_RDONLY;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
123 else if (mode == STREAM_WRITE) //who's gonna do that ?
22451
86f7b9cab33b truncate mencoder's output file if it exists, instead of overwriting just part of it.
lorenm
parents: 21688
diff changeset
124 m = O_RDWR|O_CREAT|O_TRUNC;
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
125 else {
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
126 mp_msg(MSGT_OPEN, MSGL_ERR, "[smb] Unknown open mode %d\n", mode);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
127 m_struct_free (&stream_opts, opts);
24257
d261f5109660 cosmetics: typo fix UNSUPORTED --> UNSUPPORTED
diego
parents: 22451
diff changeset
128 return STREAM_UNSUPPORTED;
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
129 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
130
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
131 if(!filename) {
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
132 mp_msg(MSGT_OPEN,MSGL_ERR, "[smb] Bad url\n");
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
133 m_struct_free(&stream_opts, opts);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
134 return STREAM_ERROR;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
135 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
136
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
137 err = smbc_init(smb_auth_fn, 1);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
138 if (err < 0) {
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
139 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBInitError,err);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
140 m_struct_free(&stream_opts, opts);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
141 return STREAM_ERROR;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
142 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
143
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
144 fd = smbc_open(filename, m,0644);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
145 if (fd < 0) {
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
146 mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_SMBFileNotFound, filename);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
147 m_struct_free(&stream_opts, opts);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
148 return STREAM_ERROR;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
149 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
150
21674
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
151 stream->flags = mode;
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
152 len = 0;
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
153 if(mode == STREAM_READ) {
21688
950dfaa7612c reindented after yesterday's commit
nicodvb
parents: 21674
diff changeset
154 len = smbc_lseek(fd,0,SEEK_END);
950dfaa7612c reindented after yesterday's commit
nicodvb
parents: 21674
diff changeset
155 smbc_lseek (fd, 0, SEEK_SET);
21674
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
156 }
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
157 if(len > 0 || mode == STREAM_WRITE) {
29920
4f740437ed2b Finally rename the STREAM_SEEK define to MP_STREAM_SEEK, there are just too many
reimar
parents: 29263
diff changeset
158 stream->flags |= MP_STREAM_SEEK;
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
159 stream->seek = seek;
21674
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
160 if(mode == STREAM_READ) stream->end_pos = len;
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
161 }
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
162 stream->type = STREAMTYPE_SMB;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
163 stream->fd = fd;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
164 stream->fill_buffer = fill_buffer;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
165 stream->write_buffer = write_buffer;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
166 stream->close = close_f;
21674
74d09d421f72 support for writing over smb shares
nicodvb
parents: 19271
diff changeset
167 stream->control = control;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25691
diff changeset
168
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
169 m_struct_free(&stream_opts, opts);
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
170 return STREAM_OK;
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
171 }
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
172
25211
c1d17bd6683c Mark all stream_info_t as const
reimar
parents: 24257
diff changeset
173 const stream_info_t stream_info_smb = {
15519
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
174 "Server Message Block",
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
175 "smb",
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
176 "M. Tourne",
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
177 "based on the code from 'a bulgarian' (one says)",
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
178 open_f,
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
179 {"smb", NULL},
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
180 &stream_opts,
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
181 0 //Url is an option string
07a841d9a8e1 ported smb:// to the new stream api, patch by Matthieu Tourne [matthieu puntum tourne ab gmail puntum com]
nicodvb
parents:
diff changeset
182 };