2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
< |
// Maker.cpp |
5 |
> |
// $Id: Maker.cpp,v 1.10 2003/07/31 00:56:29 douglas Exp $ |
6 |
|
|
7 |
|
#include "Maker.h" |
8 |
|
|
9 |
|
void Maker::make() |
10 |
|
{ |
11 |
+ |
if (!good) return; |
12 |
+ |
|
13 |
|
samba(); |
14 |
|
|
15 |
|
struct stat dir; |
36 |
|
} |
37 |
|
} |
38 |
|
|
39 |
+ |
if (debug) cerr << "folders = {\n"; |
40 |
+ |
|
41 |
|
for (map<string, Folder>::iterator itor = folders.begin(); itor |
42 |
|
!= folders.end(); itor++) |
43 |
|
{ |
44 |
+ |
if (debug) cerr << " " << itor->first << " = {\n" |
45 |
+ |
<< " local = " << itor->second.local << "\n" |
46 |
+ |
<< " remote = " << itor->second.remote << "\n" |
47 |
+ |
<< " }\n"; |
48 |
+ |
|
49 |
|
make(itor->first, itor->second.local); |
50 |
|
} |
51 |
+ |
|
52 |
+ |
if (debug) cerr << "}\n"; |
53 |
|
} |
54 |
|
|
55 |
|
void Maker::samba() |
77 |
|
|
78 |
|
ipstream smbclient(config.smbclient, args); |
79 |
|
|
80 |
< |
// |
80 |
> |
if (debug) cerr << "smbclient = {\n"; |
81 |
> |
|
82 |
> |
if (connect(smbclient)) |
83 |
> |
{ |
84 |
> |
for (unsigned index = 0; index < 2; index++) |
85 |
> |
{ |
86 |
> |
string line; |
87 |
> |
|
88 |
> |
getline(smbclient, line); |
89 |
> |
|
90 |
> |
if (debug) cerr << line << "\n"; |
91 |
> |
} |
92 |
> |
|
93 |
> |
samba(smbclient); |
94 |
> |
} |
95 |
> |
else |
96 |
> |
{ |
97 |
> |
cerr << program << ": Connection to " << host << " failed\n"; |
98 |
> |
} |
99 |
> |
|
100 |
> |
if (debug) cerr << "}\n"; |
101 |
> |
|
102 |
> |
smbclient.close(); |
103 |
|
|
104 |
|
unlink(credentials); |
105 |
|
} |
106 |
|
|
107 |
+ |
bool Maker::connect(ipstream& pin) |
108 |
+ |
{ |
109 |
+ |
while (pin.good()) |
110 |
+ |
{ |
111 |
+ |
string line; |
112 |
+ |
|
113 |
+ |
getline(pin, line); |
114 |
+ |
|
115 |
+ |
if (debug) cerr << line << "\n"; |
116 |
+ |
|
117 |
+ |
if (line == "") |
118 |
+ |
{ |
119 |
+ |
return true; |
120 |
+ |
} |
121 |
+ |
else if (line == "Connection to " + host + " failed") |
122 |
+ |
{ |
123 |
+ |
return false; |
124 |
+ |
} |
125 |
+ |
} |
126 |
+ |
|
127 |
+ |
return false; |
128 |
+ |
} |
129 |
+ |
|
130 |
+ |
void Maker::samba(ipstream& pin) |
131 |
+ |
{ |
132 |
+ |
while (pin.good()) |
133 |
+ |
{ |
134 |
+ |
if (pin.peek() != '\t') break; |
135 |
+ |
|
136 |
+ |
pin.ignore(); |
137 |
+ |
|
138 |
+ |
char share[16]; |
139 |
+ |
char type[11]; |
140 |
+ |
string comment; |
141 |
+ |
|
142 |
+ |
pin.get(share, 16); |
143 |
+ |
pin.get(type, 11); |
144 |
+ |
getline(pin, comment); |
145 |
+ |
|
146 |
+ |
if (debug) cerr << "\t" << share << type << comment << "\n"; |
147 |
+ |
|
148 |
+ |
strip(share); |
149 |
+ |
strip(type); |
150 |
+ |
|
151 |
+ |
if (string(type) == "Disk") |
152 |
+ |
{ |
153 |
+ |
unsigned end = strlen(share) - 1; |
154 |
+ |
|
155 |
+ |
if (share[end] == '$') continue; |
156 |
+ |
|
157 |
+ |
if (folders.find(share) == folders.end()) |
158 |
+ |
{ |
159 |
+ |
folders.insert(pair<string, Folder>(share, regular)); |
160 |
+ |
} |
161 |
+ |
} |
162 |
+ |
} |
163 |
+ |
|
164 |
+ |
string line; |
165 |
+ |
|
166 |
+ |
getline(pin, line); |
167 |
+ |
|
168 |
+ |
if (debug) cerr << line << "\n"; |
169 |
+ |
|
170 |
+ |
if (line != "") |
171 |
+ |
{ |
172 |
+ |
cerr << program << ": Error returning browse list\n"; |
173 |
+ |
} |
174 |
+ |
} |
175 |
+ |
|
176 |
|
void Maker::make(const string& folder, const string& user) |
177 |
|
{ |
178 |
|
struct stat dir; |