|
a/libupnpp/upnpplib.cxx |
|
b/libupnpp/upnpplib.cxx |
|
... |
|
... |
106 |
int LibUPnP::getInitError() const
|
106 |
int LibUPnP::getInitError() const
|
107 |
{
|
107 |
{
|
108 |
return m->init_error;
|
108 |
return m->init_error;
|
109 |
}
|
109 |
}
|
110 |
|
110 |
|
|
|
111 |
static const char* ccpDevNull = "/dev/null";
|
|
|
112 |
|
111 |
LibUPnP::LibUPnP(bool serveronly, string* hwaddr,
|
113 |
LibUPnP::LibUPnP(bool serveronly, string* hwaddr,
|
112 |
const string ifname, const string inip, unsigned short port)
|
114 |
const string ifname, const string inip, unsigned short port)
|
113 |
{
|
115 |
{
|
114 |
LOGDEB1("LibUPnP: serveronly " << serveronly << " &hwaddr " << hwaddr <<
|
116 |
LOGDEB1("LibUPnP: serveronly " << serveronly << " &hwaddr " << hwaddr <<
|
115 |
" ifname [" << ifname << "] inip [" << inip << "] port " << port
|
117 |
" ifname [" << ifname << "] inip [" << inip << "] port " << port
|
|
... |
|
... |
142 |
// supplied IP address. If this is empty too, libupnp will choose
|
144 |
// supplied IP address. If this is empty too, libupnp will choose
|
143 |
// by itself (the first adapter).
|
145 |
// by itself (the first adapter).
|
144 |
if (ifname.empty())
|
146 |
if (ifname.empty())
|
145 |
strncpy(ip_address, inip.c_str(), ipalen);
|
147 |
strncpy(ip_address, inip.c_str(), ipalen);
|
146 |
|
148 |
|
|
|
149 |
#if defined(HAVE_UPNPSETLOGLEVEL)
|
|
|
150 |
// We used to UpnpCloseLog() after UpnpInit(), but this can cause
|
|
|
151 |
// crashes because of the awful way upnpdebug.c is programmed, so
|
|
|
152 |
// no more. We do have to do something though because
|
|
|
153 |
// UpnpInitLog() creates the current filenames. The initial file
|
|
|
154 |
// names are IUpnpErrFile.txt and IUpnpInfoFile.txt, and they will
|
|
|
155 |
// be created in the current directory if debug is enabled and we
|
|
|
156 |
// do nothing. UpnpInitlog() is called by upnpapi.c:
|
|
|
157 |
// UpnpInit()->UpnpInitPreamble()->UpnpInitLog() So, set safe file
|
|
|
158 |
// names before calling UpnpInit() (needs to be static, the lib
|
|
|
159 |
// keeps a pointer to it).
|
|
|
160 |
UpnpSetLogFileNames(ccpDevNull, ccpDevNull);
|
|
|
161 |
#endif
|
|
|
162 |
|
147 |
m->init_error = UpnpInit(ip_address[0] ? ip_address : 0, port);
|
163 |
m->init_error = UpnpInit(ip_address[0] ? ip_address : 0, port);
|
148 |
|
164 |
|
149 |
if (m->init_error != UPNP_E_SUCCESS) {
|
165 |
if (m->init_error != UPNP_E_SUCCESS) {
|
150 |
LOGERR(errAsString("UpnpInit", m->init_error) << endl);
|
166 |
LOGERR(errAsString("UpnpInit", m->init_error) << endl);
|
151 |
return;
|
167 |
return;
|
152 |
}
|
168 |
}
|
153 |
setMaxContentLength(2000*1024);
|
169 |
setMaxContentLength(2000*1024);
|
154 |
|
170 |
|
155 |
LOGDEB("LibUPnP: Using IP " << UpnpGetServerIpAddress() << " port " <<
|
171 |
LOGDEB("LibUPnP: Using IP " << UpnpGetServerIpAddress() << " port " <<
|
156 |
UpnpGetServerPort() << endl);
|
172 |
UpnpGetServerPort() << endl);
|
157 |
|
|
|
158 |
#if defined(HAVE_UPNPSETLOGLEVEL)
|
|
|
159 |
UpnpCloseLog();
|
|
|
160 |
#endif
|
|
|
161 |
|
173 |
|
162 |
// Client initialization is simple, just do it. Defer device
|
174 |
// Client initialization is simple, just do it. Defer device
|
163 |
// initialization because it's more complicated.
|
175 |
// initialization because it's more complicated.
|
164 |
if (serveronly) {
|
176 |
if (serveronly) {
|
165 |
m->ok = true;
|
177 |
m->ok = true;
|
|
... |
|
... |
206 |
UpnpSetMaxContentLength(size_t(bytes));
|
218 |
UpnpSetMaxContentLength(size_t(bytes));
|
207 |
}
|
219 |
}
|
208 |
|
220 |
|
209 |
bool LibUPnP::setLogFileName(const std::string& fn, LogLevel level)
|
221 |
bool LibUPnP::setLogFileName(const std::string& fn, LogLevel level)
|
210 |
{
|
222 |
{
|
|
|
223 |
#if defined(HAVE_UPNPSETLOGLEVEL)
|
211 |
std::unique_lock<std::mutex> lock(m->mutex);
|
224 |
std::unique_lock<std::mutex> lock(m->mutex);
|
212 |
#if defined(HAVE_UPNPSETLOGLEVEL)
|
|
|
213 |
if (fn.empty() || level == LogLevelNone) {
|
225 |
if (fn.empty() || level == LogLevelNone) {
|
|
|
226 |
// Can't call UpnpCloseLog() ! This closes the FILEs without
|
|
|
227 |
// any further precautions -> crashes
|
|
|
228 |
UpnpSetLogFileNames(ccpDevNull, ccpDevNull);
|
214 |
UpnpCloseLog();
|
229 |
UpnpInitLog();
|
215 |
} else {
|
230 |
} else {
|
216 |
setLogLevel(level);
|
231 |
setLogLevel(level);
|
|
|
232 |
// the lib only keeps a pointer !
|
|
|
233 |
static string fnkeep(fn);
|
217 |
UpnpSetLogFileNames(fn.c_str(), fn.c_str());
|
234 |
UpnpSetLogFileNames(fnkeep.c_str(), fnkeep.c_str());
|
|
|
235 |
// Because of the way upnpdebug.c is horribly coded, this
|
|
|
236 |
// loses 2 FILEs every time it's called.
|
218 |
int code = UpnpInitLog();
|
237 |
int code = UpnpInitLog();
|
219 |
if (code != UPNP_E_SUCCESS) {
|
238 |
if (code != UPNP_E_SUCCESS) {
|
220 |
LOGERR(errAsString("UpnpInitLog", code) << endl);
|
239 |
LOGERR(errAsString("UpnpInitLog", code) << endl);
|
221 |
return false;
|
240 |
return false;
|
222 |
}
|
241 |
}
|
|
... |
|
... |
230 |
bool LibUPnP::setLogLevel(LogLevel level)
|
249 |
bool LibUPnP::setLogLevel(LogLevel level)
|
231 |
{
|
250 |
{
|
232 |
#if defined(HAVE_UPNPSETLOGLEVEL)
|
251 |
#if defined(HAVE_UPNPSETLOGLEVEL)
|
233 |
switch (level) {
|
252 |
switch (level) {
|
234 |
case LogLevelNone:
|
253 |
case LogLevelNone:
|
|
|
254 |
// This does not exist directly in pupnp, so log to
|
|
|
255 |
// /dev/null. SetLogFileName knows not to call us back in this
|
|
|
256 |
// case...
|
|
|
257 |
UpnpSetLogLevel(UPNP_CRITICAL);
|
235 |
setLogFileName("", LogLevelNone);
|
258 |
setLogFileName("", LogLevelNone);
|
236 |
break;
|
259 |
break;
|
237 |
case LogLevelError:
|
260 |
case LogLevelError:
|
238 |
UpnpSetLogLevel(UPNP_CRITICAL);
|
261 |
UpnpSetLogLevel(UPNP_CRITICAL);
|
239 |
break;
|
262 |
break;
|