Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • api-redesign
  • main
  • 0.10.0
  • 0.10.1
  • 0.10.2
  • 0.7.0
  • 0.8.0
  • 0.8.1
  • 0.9.0
  • 0.9.1
  • 0.9.2
11 results

Target

Select target project
  • justJanne/libquassel
1 result
Select Git revision
  • api-redesign
  • main
  • 0.10.0
  • 0.10.1
  • 0.10.2
  • 0.7.0
  • 0.8.0
  • 0.8.1
  • 0.9.0
  • 0.9.1
  • 0.9.2
11 results
Show changes
Showing
with 238 additions and 249 deletions
......@@ -14,10 +14,12 @@ enum class HighlightNickType(
) {
NoNick(0),
CurrentNick(1),
AllNicks(2);
AllNicks(2),
;
companion object {
private val values = enumValues<HighlightNickType>()
private val values =
enumValues<HighlightNickType>()
.associateBy(HighlightNickType::value)
/**
......
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.models.rules
import de.justjanne.libquassel.protocol.util.expression.ExpressionMatch
data class HighlightRule(
val id: Int,
val content: String,
val isRegEx: Boolean = false,
val isCaseSensitive: Boolean = false,
val isEnabled: Boolean = true,
val isInverse: Boolean = false,
val sender: String,
val channel: String
) {
val contentMatch = ExpressionMatch(
content,
if (isRegEx) ExpressionMatch.MatchMode.MatchRegEx
else ExpressionMatch.MatchMode.MatchPhrase,
isCaseSensitive
)
val senderMatch = ExpressionMatch(
sender,
if (isRegEx) ExpressionMatch.MatchMode.MatchRegEx
else ExpressionMatch.MatchMode.MatchMultiWildcard,
isCaseSensitive
)
val channelMatch = ExpressionMatch(
channel,
if (isRegEx) ExpressionMatch.MatchMode.MatchRegEx
else ExpressionMatch.MatchMode.MatchMultiWildcard,
isCaseSensitive
)
}
/*
* libquassel
* Copyright (c) 2021 Janne Mareike Koschinski
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*/
package de.justjanne.libquassel.protocol.models.rules
import de.justjanne.libquassel.protocol.util.expression.ExpressionMatch
data class IgnoreRule(
val type: IgnoreType,
val ignoreRule: String,
val isRegEx: Boolean = false,
val strictness: StrictnessType,
val isEnabled: Boolean = true,
val scope: ScopeType,
val scopeRule: String
) {
val ignoreMatch = ExpressionMatch(
ignoreRule,
if (isRegEx) ExpressionMatch.MatchMode.MatchRegEx
else ExpressionMatch.MatchMode.MatchWildcard,
false
)
val scopeMatch = ExpressionMatch(
scopeRule,
ExpressionMatch.MatchMode.MatchMultiWildcard,
false
)
}
......@@ -10,14 +10,16 @@
package de.justjanne.libquassel.protocol.models.rules
enum class IgnoreType(
val value: Int
val value: Int,
) {
SenderIgnore(0),
MessageIgnore(1),
CtcpIgnore(2);
CtcpIgnore(2),
;
companion object {
private val values = enumValues<IgnoreType>()
private val values =
enumValues<IgnoreType>()
.associateBy(IgnoreType::value)
/**
......
......@@ -10,14 +10,16 @@
package de.justjanne.libquassel.protocol.models.rules
enum class ScopeType(
val value: Int
val value: Int,
) {
GlobalScope(0),
NetworkScope(1),
ChannelScope(2);
ChannelScope(2),
;
companion object {
private val values = enumValues<ScopeType>()
private val values =
enumValues<ScopeType>()
.associateBy(ScopeType::value)
/**
......
......@@ -10,14 +10,16 @@
package de.justjanne.libquassel.protocol.models.rules
enum class StrictnessType(
val value: Int
val value: Int,
) {
UnmatchedStrictness(0),
SoftStrictness(1),
HardStrictness(2);
HardStrictness(2),
;
companion object {
private val values = enumValues<StrictnessType>()
private val values =
enumValues<StrictnessType>()
.associateBy(StrictnessType::value)
/**
......
......@@ -25,61 +25,72 @@ object BackendInfoSerializer {
/**
* Serialize backend info into a [QVariantMap] (for further serialization)
*/
fun serialize(data: BackendInfo): QVariantMap = mapOf(
"SetupKeys" to qVariant<QStringList>(
fun serialize(data: BackendInfo): QVariantMap =
mapOf(
"SetupKeys" to
qVariant<QStringList>(
data.entries.map(SetupEntry::key),
QtType.QStringList
QtType.QStringList,
),
"SetupDefaults" to qVariant<QVariantMap>(
"SetupDefaults" to
qVariant<QVariantMap>(
data.entries.map { it.key to it.defaultValue }.toMap<String, QVariant_>(),
QtType.QVariantMap
QtType.QVariantMap,
),
"SetupData" to qVariant<QVariantList>(
"SetupData" to
qVariant<QVariantList>(
data.entries.flatMap {
listOf<QVariant_>(
qVariant(it.key, QtType.QString),
qVariant(it.displayName, QtType.QString),
it.defaultValue
it.defaultValue,
)
},
QtType.QVariantList
QtType.QVariantList,
),
"IsDefault" to qVariant(
"IsDefault" to
qVariant(
data.isDefault,
QtType.Bool
QtType.Bool,
),
"DisplayName" to qVariant(
"DisplayName" to
qVariant(
data.displayName,
QtType.QString
QtType.QString,
),
"Description" to qVariant(
"Description" to
qVariant(
data.description,
QtType.QString
QtType.QString,
),
"BackendId" to qVariant(
"BackendId" to
qVariant(
data.backendId,
QtType.QString
QtType.QString,
),
)
private fun parseSetupEntries(
data: QVariantList?,
defaults: QVariantMap
): List<SetupEntry> = data?.triples { key, displayName, defaultValue ->
defaults: QVariantMap,
): List<SetupEntry> =
data?.triples { key, displayName, defaultValue ->
SetupEntry(key.into(""), displayName.into(""), defaultValue)
} ?: defaults.map { (key, value) -> SetupEntry(key, key, value) }
/**
* Deserialize backend info from a [QVariantMap]
*/
fun deserialize(data: QVariantMap) = BackendInfo(
entries = parseSetupEntries(
fun deserialize(data: QVariantMap) =
BackendInfo(
entries =
parseSetupEntries(
data["SetupData"].into<QVariantList>(),
data["SetupDefaults"].into<QVariantMap>().orEmpty()
data["SetupDefaults"].into<QVariantMap>().orEmpty(),
),
isDefault = data["IsDefault"].into<Boolean>(false),
displayName = data["DisplayName"].into<String>(""),
description = data["Description"].into<String>(""),
backendId = data["BackendId"].into<String>("")
backendId = data["BackendId"].into<String>(""),
)
}
......@@ -47,7 +47,7 @@ enum class QtType(
* Serializer for data described by this type
*/
@PublishedApi
internal val serializer: PrimitiveSerializer<*>? = null
internal val serializer: PrimitiveSerializer<*>? = null,
) {
/**
* Void, no data at all
......@@ -186,7 +186,8 @@ enum class QtType(
* Custom data with a special (de-)serializer
* See [QuasselType]
*/
UserType(127);
UserType(127),
;
/**
* Obtain a serializer for this type (type safe)
......@@ -201,7 +202,8 @@ enum class QtType(
}
companion object {
private val values = enumValues<QtType>()
private val values =
enumValues<QtType>()
.associateBy(QtType::id)
/**
......
......@@ -149,7 +149,8 @@ enum class QuasselType(
* This is used in the core to return responses to the same client that made
* a request.
*/
PeerPtr("PeerPtr", PeerPtrSerializer);
PeerPtr("PeerPtr", PeerPtrSerializer),
;
/**
* Obtain a serializer for this type (type safe)
......@@ -164,7 +165,8 @@ enum class QuasselType(
}
companion object {
private val values = enumValues<QuasselType>()
private val values =
enumValues<QuasselType>()
.associateBy(QuasselType::typeName)
/**
......
......@@ -83,11 +83,18 @@ object HandshakeMessageSerializer : PrimitiveSerializer<HandshakeMessage> {
throw NoSerializerForTypeException.Handshake(type)
}
override fun serialize(buffer: ChainedByteBuffer, data: HandshakeMessage, featureSet: FeatureSet) {
override fun serialize(
buffer: ChainedByteBuffer,
data: HandshakeMessage,
featureSet: FeatureSet,
) {
HandshakeMapSerializer.serialize(buffer, serializeToMap(data), featureSet)
}
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet): HandshakeMessage {
override fun deserialize(
buffer: ByteBuffer,
featureSet: FeatureSet,
): HandshakeMessage {
return deserializeFromMap(HandshakeMapSerializer.deserialize(buffer, featureSet))
}
}
......@@ -21,11 +21,11 @@ sealed class NoSerializerForTypeException : Exception() {
*/
data class Qt(
private val type: Int,
private val javaType: Class<*>? = null
private val javaType: Class<*>? = null,
) : NoSerializerForTypeException() {
constructor(
type: QtType,
javaType: Class<*>? = null
javaType: Class<*>? = null,
) : this(type.id, javaType)
override fun toString(): String {
......@@ -39,17 +39,17 @@ sealed class NoSerializerForTypeException : Exception() {
data class Quassel(
private val type: Int,
private val typename: String?,
private val javaType: Class<*>? = null
private val javaType: Class<*>? = null,
) : NoSerializerForTypeException() {
constructor(
type: QtType,
typename: String?,
javaType: Class<*>? = null
javaType: Class<*>? = null,
) : this(type.id, typename, javaType)
constructor(
type: QuasselType,
javaType: Class<*>? = null
javaType: Class<*>? = null,
) : this(type.qtType, type.typeName, javaType)
override fun toString(): String {
......@@ -62,7 +62,7 @@ sealed class NoSerializerForTypeException : Exception() {
*/
data class Handshake(
private val type: String,
private val javaType: Class<*>? = null
private val javaType: Class<*>? = null,
) : NoSerializerForTypeException() {
override fun toString(): String {
return "NoSerializerForTypeException.Handshake(type='$type', javaType=$javaType)"
......@@ -74,7 +74,7 @@ sealed class NoSerializerForTypeException : Exception() {
*/
data class SignalProxy(
private val type: Int,
private val javaType: Class<*>? = null
private val javaType: Class<*>? = null,
) : NoSerializerForTypeException() {
override fun toString(): String {
return "NoSerializerForTypeException.SignalProxy(type='$type', javaType=$javaType)"
......
......@@ -24,6 +24,7 @@ interface PrimitiveSerializer<T> {
* Used for type-safe serializer autodiscovery.
*/
val javaType: Class<out T>
/**
* Serialize data with the Quassel protocol to a buffer
* @param buffer target buffer to serialize to
......@@ -31,7 +32,11 @@ interface PrimitiveSerializer<T> {
* @param featureSet features to use when serializing, usually the featureset
* of the currently negotiated connection
*/
fun serialize(buffer: ChainedByteBuffer, data: T, featureSet: FeatureSet)
fun serialize(
buffer: ChainedByteBuffer,
data: T,
featureSet: FeatureSet,
)
/**
* Deserialize Quassel protocol data from a buffer
......@@ -39,5 +44,8 @@ interface PrimitiveSerializer<T> {
* @param featureSet features to use when deserializing, usually the
* featureset of the currently negotiated connection
*/
fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet): T
fun deserialize(
buffer: ByteBuffer,
featureSet: FeatureSet,
): T
}
......@@ -63,11 +63,18 @@ object SignalProxyMessageSerializer : PrimitiveSerializer<SignalProxyMessage> {
throw NoSerializerForTypeException.SignalProxy(type)
}
override fun serialize(buffer: ChainedByteBuffer, data: SignalProxyMessage, featureSet: FeatureSet) {
override fun serialize(
buffer: ChainedByteBuffer,
data: SignalProxyMessage,
featureSet: FeatureSet,
) {
QVariantListSerializer.serialize(buffer, serializeToList(data), featureSet)
}
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet): SignalProxyMessage {
override fun deserialize(
buffer: ByteBuffer,
featureSet: FeatureSet,
): SignalProxyMessage {
return deserializeFromList(QVariantListSerializer.deserialize(buffer, featureSet))
}
}
......@@ -30,47 +30,55 @@ import de.justjanne.libquassel.protocol.variant.qVariant
object ClientInitAckSerializer : HandshakeSerializer<HandshakeMessage.ClientInitAck> {
override val type: String = "ClientInitAck"
override fun serialize(data: HandshakeMessage.ClientInitAck) = mapOf(
override fun serialize(data: HandshakeMessage.ClientInitAck) =
mapOf(
"MsgType" to qVariant(type, QtType.QString),
"CoreFeatures" to qVariant(data.featureSet.legacyFeatures().toBits(), QtType.UInt),
"StorageBackends" to qVariant<QVariantList>(
"StorageBackends" to
qVariant<QVariantList>(
data.backendInfo.map {
qVariant<QVariantMap>(
BackendInfoSerializer.serialize(it),
QtType.QVariantMap
QtType.QVariantMap,
)
},
QtType.QVariantList
QtType.QVariantList,
),
"Authenticator" to qVariant<QVariantList>(
"Authenticator" to
qVariant<QVariantList>(
data.authenticatorInfo.map {
qVariant<QVariantMap>(
BackendInfoSerializer.serialize(it),
QtType.QVariantMap
QtType.QVariantMap,
)
},
QtType.QVariantList
QtType.QVariantList,
),
"Configured" to qVariant(data.coreConfigured, QtType.Bool),
"FeatureList" to qVariant(
"FeatureList" to
qVariant(
data.featureSet.featureList().map(QuasselFeatureName::name),
QtType.QStringList
)
QtType.QStringList,
),
)
override fun deserialize(data: QVariantMap) = HandshakeMessage.ClientInitAck(
override fun deserialize(data: QVariantMap) =
HandshakeMessage.ClientInitAck(
coreConfigured = data["Configured"].into(),
backendInfo = data["StorageBackends"].into<QVariantList>()?.mapNotNull {
backendInfo =
data["StorageBackends"].into<QVariantList>()?.mapNotNull {
it.into<QVariantMap>()
}?.map(BackendInfoSerializer::deserialize).orEmpty(),
authenticatorInfo = data["Authenticator"].into<QVariantList>()?.mapNotNull {
authenticatorInfo =
data["Authenticator"].into<QVariantList>()?.mapNotNull {
it.into<QVariantMap>()
}?.map(BackendInfoSerializer::deserialize).orEmpty(),
featureSet = FeatureSet.build(
featureSet =
FeatureSet.build(
LegacyFeature.of(data["CoreFeatures"].into<UInt>()),
data["FeatureList"].into<QStringList>(emptyList())
.filterNotNull()
.map(::QuasselFeatureName)
)
.map(::QuasselFeatureName),
),
)
}
......@@ -22,12 +22,14 @@ import de.justjanne.libquassel.protocol.variant.qVariant
object ClientInitRejectSerializer : HandshakeSerializer<HandshakeMessage.ClientInitReject> {
override val type: String = "ClientInitReject"
override fun serialize(data: HandshakeMessage.ClientInitReject) = mapOf(
override fun serialize(data: HandshakeMessage.ClientInitReject) =
mapOf(
"MsgType" to qVariant(type, QtType.QString),
"Error" to qVariant(data.errorString, QtType.QString)
"Error" to qVariant(data.errorString, QtType.QString),
)
override fun deserialize(data: QVariantMap) = HandshakeMessage.ClientInitReject(
errorString = data["Error"].into()
override fun deserialize(data: QVariantMap) =
HandshakeMessage.ClientInitReject(
errorString = data["Error"].into(),
)
}
......@@ -28,25 +28,29 @@ import de.justjanne.libquassel.protocol.variant.qVariant
object ClientInitSerializer : HandshakeSerializer<HandshakeMessage.ClientInit> {
override val type: String = "ClientInit"
override fun serialize(data: HandshakeMessage.ClientInit) = mapOf(
override fun serialize(data: HandshakeMessage.ClientInit) =
mapOf(
"MsgType" to qVariant(type, QtType.QString),
"ClientVersion" to qVariant(data.clientVersion, QtType.QString),
"ClientDate" to qVariant(data.buildDate, QtType.QString),
"Features" to qVariant(data.featureSet.legacyFeatures().toBits(), QtType.UInt),
"FeatureList" to qVariant(
"FeatureList" to
qVariant(
data.featureSet.featureList().map(QuasselFeatureName::name),
QtType.QStringList
QtType.QStringList,
),
)
override fun deserialize(data: QVariantMap) = HandshakeMessage.ClientInit(
override fun deserialize(data: QVariantMap) =
HandshakeMessage.ClientInit(
clientVersion = data["ClientVersion"].into(),
buildDate = data["ClientDate"].into(),
featureSet = FeatureSet.build(
featureSet =
FeatureSet.build(
LegacyFeature.of(data["Features"].into<UInt>()),
data["FeatureList"].into<QStringList>(emptyList())
.filterNotNull()
.map(::QuasselFeatureName)
)
.map(::QuasselFeatureName),
),
)
}
......@@ -21,7 +21,8 @@ import de.justjanne.libquassel.protocol.variant.qVariant
object ClientLoginAckSerializer : HandshakeSerializer<HandshakeMessage.ClientLoginAck> {
override val type: String = "ClientLoginAck"
override fun serialize(data: HandshakeMessage.ClientLoginAck) = mapOf(
override fun serialize(data: HandshakeMessage.ClientLoginAck) =
mapOf(
"MsgType" to qVariant(type, QtType.QString),
)
......
......@@ -22,12 +22,14 @@ import de.justjanne.libquassel.protocol.variant.qVariant
object ClientLoginRejectSerializer : HandshakeSerializer<HandshakeMessage.ClientLoginReject> {
override val type: String = "ClientLoginReject"
override fun serialize(data: HandshakeMessage.ClientLoginReject) = mapOf(
override fun serialize(data: HandshakeMessage.ClientLoginReject) =
mapOf(
"MsgType" to qVariant(type, QtType.QString),
"Error" to qVariant(data.errorString, QtType.QString)
"Error" to qVariant(data.errorString, QtType.QString),
)
override fun deserialize(data: QVariantMap) = HandshakeMessage.ClientLoginReject(
errorString = data["Error"].into()
override fun deserialize(data: QVariantMap) =
HandshakeMessage.ClientLoginReject(
errorString = data["Error"].into(),
)
}
......@@ -22,13 +22,15 @@ import de.justjanne.libquassel.protocol.variant.qVariant
object ClientLoginSerializer : HandshakeSerializer<HandshakeMessage.ClientLogin> {
override val type: String = "ClientLogin"
override fun serialize(data: HandshakeMessage.ClientLogin) = mapOf(
override fun serialize(data: HandshakeMessage.ClientLogin) =
mapOf(
"MsgType" to qVariant(type, QtType.QString),
"User" to qVariant(data.user, QtType.QString),
"Password" to qVariant(data.password, QtType.QString)
"Password" to qVariant(data.password, QtType.QString),
)
override fun deserialize(data: QVariantMap) = HandshakeMessage.ClientLogin(
override fun deserialize(data: QVariantMap) =
HandshakeMessage.ClientLogin(
user = data["User"].into(),
password = data["Password"].into(),
)
......
......@@ -21,8 +21,9 @@ import de.justjanne.libquassel.protocol.variant.qVariant
object CoreSetupAckSerializer : HandshakeSerializer<HandshakeMessage.CoreSetupAck> {
override val type: String = "CoreSetupAck"
override fun serialize(data: HandshakeMessage.CoreSetupAck) = mapOf(
"MsgType" to qVariant(type, QtType.QString)
override fun serialize(data: HandshakeMessage.CoreSetupAck) =
mapOf(
"MsgType" to qVariant(type, QtType.QString),
)
override fun deserialize(data: QVariantMap) = HandshakeMessage.CoreSetupAck
......