|
a/libupnpp/upnpplib.cxx |
|
b/libupnpp/upnpplib.cxx |
|
... |
|
... |
36 |
#include "upnpplib.hxx"
|
36 |
#include "upnpplib.hxx"
|
37 |
extern "C" {
|
37 |
extern "C" {
|
38 |
#include "getsyshwaddr.h"
|
38 |
#include "getsyshwaddr.h"
|
39 |
}
|
39 |
}
|
40 |
#include "md5.hxx"
|
40 |
#include "md5.hxx"
|
|
|
41 |
#include "log.hxx"
|
|
|
42 |
|
|
|
43 |
// Level for the local log, not libupnp's
|
|
|
44 |
int upnppdebug::loglevel = LLDEB;
|
41 |
|
45 |
|
42 |
static LibUPnP *theLib;
|
46 |
static LibUPnP *theLib;
|
43 |
|
47 |
|
44 |
LibUPnP *LibUPnP::getLibUPnP(bool server)
|
48 |
LibUPnP *LibUPnP::getLibUPnP(bool server)
|
45 |
{
|
49 |
{
|
|
... |
|
... |
61 |
setMaxContentLength(2000*1024);
|
65 |
setMaxContentLength(2000*1024);
|
62 |
|
66 |
|
63 |
#ifdef DEBUG
|
67 |
#ifdef DEBUG
|
64 |
const char *ip_address = UpnpGetServerIpAddress();
|
68 |
const char *ip_address = UpnpGetServerIpAddress();
|
65 |
int port = UpnpGetServerPort();
|
69 |
int port = UpnpGetServerPort();
|
66 |
cerr << "Using IP " << ip_address << " port " << port << endl;
|
70 |
LOGDEB("Using IP " << ip_address << " port " << port << endl);
|
67 |
UpnpCloseLog();
|
71 |
UpnpCloseLog();
|
68 |
#endif
|
72 |
#endif
|
69 |
|
73 |
|
70 |
if (server) {
|
74 |
if (server) {
|
71 |
m_ok = true;
|
75 |
m_ok = true;
|
|
... |
|
... |
104 |
void LibUPnP::setMaxContentLength(int bytes)
|
108 |
void LibUPnP::setMaxContentLength(int bytes)
|
105 |
{
|
109 |
{
|
106 |
UpnpSetMaxContentLength(bytes);
|
110 |
UpnpSetMaxContentLength(bytes);
|
107 |
}
|
111 |
}
|
108 |
|
112 |
|
109 |
bool LibUPnP::setLogFileName(const std::string& fn)
|
113 |
bool LibUPnP::setLogFileName(const std::string& fn, LogLevel level)
|
110 |
{
|
114 |
{
|
111 |
PTMutexLocker lock(m_mutex);
|
115 |
PTMutexLocker lock(m_mutex);
|
112 |
if (fn.empty()) {
|
116 |
if (fn.empty() || level == LogLevelNone) {
|
113 |
#ifdef DEBUG
|
117 |
#ifdef DEBUG
|
114 |
UpnpCloseLog();
|
118 |
UpnpCloseLog();
|
115 |
#endif
|
119 |
#endif
|
116 |
} else {
|
120 |
} else {
|
117 |
#ifdef DEBUG
|
121 |
#ifdef DEBUG
|
118 |
UpnpSetLogLevel(UPNP_INFO);
|
122 |
setLogLevel(level);
|
119 |
UpnpSetLogFileNames(fn.c_str(), fn.c_str());
|
123 |
UpnpSetLogFileNames(fn.c_str(), fn.c_str());
|
120 |
int code = UpnpInitLog();
|
124 |
int code = UpnpInitLog();
|
121 |
if (code != UPNP_E_SUCCESS) {
|
125 |
if (code != UPNP_E_SUCCESS) {
|
122 |
cerr << errAsString("UpnpInitLog", code);
|
126 |
cerr << errAsString("UpnpInitLog", code);
|
123 |
return false;
|
127 |
return false;
|
124 |
}
|
128 |
}
|
125 |
#endif
|
129 |
#endif
|
126 |
}
|
130 |
}
|
127 |
return true;
|
131 |
return true;
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
bool LibUPnP::setLogLevel(LogLevel level)
|
|
|
135 |
{
|
|
|
136 |
#ifdef DEBUG
|
|
|
137 |
switch (level) {
|
|
|
138 |
case LogLevelNone:
|
|
|
139 |
setLogFileName("", LogLevelNone);
|
|
|
140 |
break;
|
|
|
141 |
case LogLevelError:
|
|
|
142 |
UpnpSetLogLevel(UPNP_CRITICAL);
|
|
|
143 |
break;
|
|
|
144 |
case LogLevelDebug:
|
|
|
145 |
UpnpSetLogLevel(UPNP_ALL);
|
|
|
146 |
break;
|
|
|
147 |
}
|
|
|
148 |
#endif
|
128 |
}
|
149 |
}
|
129 |
|
150 |
|
130 |
void LibUPnP::registerHandler(Upnp_EventType et, Upnp_FunPtr handler,
|
151 |
void LibUPnP::registerHandler(Upnp_EventType et, Upnp_FunPtr handler,
|
131 |
void *cookie)
|
152 |
void *cookie)
|
132 |
{
|
153 |
{
|