|
a/upmpd/upmpdutils.cxx |
|
b/upmpd/upmpdutils.cxx |
|
... |
|
... |
35 |
#define O_STREAMING 0
|
35 |
#define O_STREAMING 0
|
36 |
#endif
|
36 |
#endif
|
37 |
|
37 |
|
38 |
#include <iostream>
|
38 |
#include <iostream>
|
39 |
#include <sstream>
|
39 |
#include <sstream>
|
|
|
40 |
#include <fstream>
|
40 |
using namespace std;
|
41 |
using namespace std;
|
41 |
|
42 |
|
42 |
#include "mpdcli.hxx"
|
43 |
#include "mpdcli.hxx"
|
43 |
#include "upmpdutils.hxx"
|
44 |
#include "upmpdutils.hxx"
|
44 |
#include "libupnpp/log.hxx"
|
45 |
#include "libupnpp/log.hxx"
|
|
... |
|
... |
82 |
(void)strerror_r(_errno, errbuf, ERRBUFSZ);
|
83 |
(void)strerror_r(_errno, errbuf, ERRBUFSZ);
|
83 |
reason->append(errbuf);
|
84 |
reason->append(errbuf);
|
84 |
#endif
|
85 |
#endif
|
85 |
}
|
86 |
}
|
86 |
|
87 |
|
|
|
88 |
bool read_protocolinfo(const string& fn, string& out)
|
|
|
89 |
{
|
|
|
90 |
ifstream input;
|
|
|
91 |
input.open(fn, ios::in);
|
|
|
92 |
if (!input.is_open()) {
|
|
|
93 |
return false;
|
|
|
94 |
}
|
|
|
95 |
bool eof = false;
|
|
|
96 |
for (;;) {
|
|
|
97 |
string line;
|
|
|
98 |
getline(input, line);
|
|
|
99 |
if (!input.good()) {
|
|
|
100 |
if (input.bad()) {
|
|
|
101 |
return false;
|
|
|
102 |
}
|
|
|
103 |
// Must be eof ? But maybe we have a partial line which
|
|
|
104 |
// must be processed. This happens if the last line before
|
|
|
105 |
// eof ends with a backslash, or there is no final \n
|
|
|
106 |
eof = true;
|
|
|
107 |
}
|
|
|
108 |
trimstring(line, " \t\n\r");
|
|
|
109 |
if (line[0] == '#')
|
|
|
110 |
continue;
|
|
|
111 |
out += line;
|
|
|
112 |
if (eof)
|
|
|
113 |
break;
|
|
|
114 |
}
|
|
|
115 |
return true;
|
|
|
116 |
}
|
|
|
117 |
|
87 |
bool file_to_string(const string &fn, string &data, string *reason)
|
118 |
bool file_to_string(const string &fn, string &data, string *reason)
|
88 |
{
|
119 |
{
|
89 |
const int RDBUFSZ = 4096;
|
120 |
const int RDBUFSZ = 4096;
|
90 |
bool ret = false;
|
121 |
bool ret = false;
|
91 |
int fd = -1;
|
122 |
int fd = -1;
|
|
... |
|
... |
179 |
|
210 |
|
180 |
pos = s.find_last_not_of(ws);
|
211 |
pos = s.find_last_not_of(ws);
|
181 |
if (pos != string::npos && pos != s.length()-1)
|
212 |
if (pos != string::npos && pos != s.length()-1)
|
182 |
s.replace(pos+1, string::npos, string());
|
213 |
s.replace(pos+1, string::npos, string());
|
183 |
}
|
214 |
}
|
|
|
215 |
|
184 |
void stringToTokens(const string& str, vector<string>& tokens,
|
216 |
void stringToTokens(const string& str, vector<string>& tokens,
|
185 |
const string& delims, bool skipinit)
|
217 |
const string& delims, bool skipinit)
|
186 |
{
|
218 |
{
|
187 |
string::size_type startPos = 0, pos;
|
219 |
string::size_type startPos = 0, pos;
|
188 |
|
220 |
|