mirror of
https://github.com/znc/znc.git
synced 2026-08-05 08:23:12 +02:00
Disable legacy encoding mode when modpython is loaded.
Python is not happy when using non-unicode text as str. Fix #1229
This commit is contained in:
@@ -584,6 +584,9 @@ if test "x$PYTHON" != "xno"; then
|
||||
LIBS="$my_saved_LIBS"
|
||||
CXXFLAGS="$my_saved_CXXFLAGS"
|
||||
fi
|
||||
if test "x$HAVE_ICU" != "xyes"; then
|
||||
AC_MSG_ERROR([Modpython requires ZNC to be compiled with charset support, but ICU library not found. Try --disable-python or install libicu.])
|
||||
fi
|
||||
if test "x$PYTHON" = "xno"; then
|
||||
ZNC_AUTO_FAIL([PYTHON],
|
||||
[python not found. Try --disable-python.],
|
||||
|
||||
@@ -233,6 +233,11 @@ class CZNC {
|
||||
void PauseConnectQueue();
|
||||
void ResumeConnectQueue();
|
||||
|
||||
void ForceEncoding();
|
||||
void UnforceEncoding();
|
||||
bool IsForcingEncoding() const;
|
||||
CString FixupEncoding(const CString& sEncoding) const;
|
||||
|
||||
// Never call this unless you are CConnectQueueTimer::~CConnectQueueTimer()
|
||||
void LeakConnectQueueTimer(CConnectQueueTimer* pTimer);
|
||||
|
||||
@@ -289,6 +294,7 @@ class CZNC {
|
||||
std::list<CIRCNetwork*> m_lpConnectQueue;
|
||||
CConnectQueueTimer* m_pConnectQueueTimer;
|
||||
unsigned int m_uiConnectPaused;
|
||||
unsigned int m_uiForceEncoding;
|
||||
TCacheMap<CString> m_sConnectThrottle;
|
||||
bool m_bProtectWebSessions;
|
||||
bool m_bHideVersion;
|
||||
|
||||
@@ -3,10 +3,15 @@
|
||||
<div>
|
||||
ZNC is compiled without encodings support. <a href="http://icu-project.org/">ICU</a> is required for it.
|
||||
</div>
|
||||
<? ENDIF ?>
|
||||
<? ELSE ?><?IF LegacyEncodingDisabled ?>
|
||||
<div>
|
||||
<!-- TODO don't hardcode modpython here -->
|
||||
Legacy mode is disabled by modpython.
|
||||
</div>
|
||||
<? ENDIF ?><? ENDIF ?>
|
||||
<div>
|
||||
<div class="checkboxandlabel checkbox">
|
||||
<input type="radio" name="encoding_utf" id="encoding_utf_legacy" value="legacy" <? IF EncodingUtf == "legacy" ?>checked="checked"<? ENDIF ?> <? IF EncodingDisabled ?>disabled="disabled"<? ENDIF ?> />
|
||||
<input type="radio" name="encoding_utf" id="encoding_utf_legacy" value="legacy" <? IF EncodingUtf == "legacy" ?>checked="checked"<? ENDIF ?> <? IF LegacyEncodingDisabled ?>disabled="disabled"<? ENDIF ?> />
|
||||
<label for="encoding_utf_legacy">Don't ensure any encoding at all (legacy mode, not recommended)</label>
|
||||
</div>
|
||||
<div class="checkboxandlabel checkbox">
|
||||
|
||||
@@ -82,6 +82,7 @@ class CModPython : public CModule {
|
||||
}
|
||||
|
||||
MODCONSTRUCTOR(CModPython) {
|
||||
CZNC::Get().ForceEncoding();
|
||||
Py_Initialize();
|
||||
m_PyFormatException = nullptr;
|
||||
m_PyZNCModule = nullptr;
|
||||
@@ -386,6 +387,7 @@ class CModPython : public CModule {
|
||||
Py_CLEAR(m_PyFormatException);
|
||||
Py_CLEAR(m_PyZNCModule);
|
||||
Py_Finalize();
|
||||
CZNC::Get().UnforceEncoding();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1013,7 +1013,10 @@ class CWebAdminMod : public CModule {
|
||||
Tmpl["EncodingUtf"] = "simple";
|
||||
Tmpl["Encoding"] = sEncoding;
|
||||
}
|
||||
Tmpl["LegacyEncodingDisabled"] =
|
||||
CString(CZNC::Get().IsForcingEncoding());
|
||||
#else
|
||||
Tmpl["LegacyEncodingDisabled"] = "true";
|
||||
Tmpl["EncodingDisabled"] = "true";
|
||||
Tmpl["EncodingUtf"] = "legacy";
|
||||
#endif
|
||||
@@ -1353,7 +1356,10 @@ class CWebAdminMod : public CModule {
|
||||
Tmpl["EncodingUtf"] = "simple";
|
||||
Tmpl["Encoding"] = sEncoding;
|
||||
}
|
||||
Tmpl["LegacyEncodingDisabled"] =
|
||||
CString(CZNC::Get().IsForcingEncoding());
|
||||
#else
|
||||
Tmpl["LegacyEncodingDisabled"] = "true";
|
||||
Tmpl["EncodingDisabled"] = "true";
|
||||
Tmpl["EncodingUtf"] = "legacy";
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -384,7 +384,7 @@ void CClient::AcceptLogin(CUser& User) {
|
||||
SetTimeout(CIRCNetwork::NO_TRAFFIC_TIMEOUT, TMO_READ);
|
||||
|
||||
SetSockName("USR::" + m_pUser->GetUserName());
|
||||
SetEncoding(m_pUser->GetClientEncoding());
|
||||
SetEncoding(CZNC::Get().FixupEncoding(m_pUser->GetClientEncoding()));
|
||||
|
||||
if (!m_sNetwork.empty()) {
|
||||
m_pNetwork = m_pUser->FindNetwork(m_sNetwork);
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ CIRCSock::CIRCSock(CIRCNetwork* pNetwork)
|
||||
EnableReadLine();
|
||||
m_Nick.SetIdent(m_pNetwork->GetIdent());
|
||||
m_Nick.SetHost(m_pNetwork->GetBindHost());
|
||||
SetEncoding(m_pNetwork->GetEncoding());
|
||||
SetEncoding(CZNC::Get().FixupEncoding((m_pNetwork->GetEncoding())));
|
||||
|
||||
m_mueChanModes['b'] = ListArg;
|
||||
m_mueChanModes['e'] = ListArg;
|
||||
|
||||
+11
@@ -72,6 +72,7 @@ CZNC::CZNC()
|
||||
m_lpConnectQueue(),
|
||||
m_pConnectQueueTimer(nullptr),
|
||||
m_uiConnectPaused(0),
|
||||
m_uiForceEncoding(0),
|
||||
m_sConnectThrottle(),
|
||||
m_bProtectWebSessions(true),
|
||||
m_bHideVersion(false) {
|
||||
@@ -2071,6 +2072,16 @@ void CZNC::ResumeConnectQueue() {
|
||||
}
|
||||
}
|
||||
|
||||
void CZNC::ForceEncoding() { m_uiForceEncoding++; }
|
||||
void CZNC::UnforceEncoding() { m_uiForceEncoding--; }
|
||||
bool CZNC::IsForcingEncoding() const { return m_uiForceEncoding; }
|
||||
CString CZNC::FixupEncoding(const CString& sEncoding) const {
|
||||
if (sEncoding.empty() && m_uiForceEncoding) {
|
||||
return "UTF-8";
|
||||
}
|
||||
return sEncoding;
|
||||
}
|
||||
|
||||
void CZNC::AddNetworkToQueue(CIRCNetwork* pNetwork) {
|
||||
// Make sure we are not already in the queue
|
||||
if (std::find(m_lpConnectQueue.begin(), m_lpConnectQueue.end(), pNetwork) !=
|
||||
|
||||
Reference in New Issue
Block a user