mirror of
https://github.com/fhmq/hmq.git
synced 2026-04-24 10:38:34 +00:00
byte
This commit is contained in:
@@ -17,6 +17,6 @@
|
||||
"certFile": "ssl/server/cert.pem",
|
||||
"keyFile": "ssl/server/key.pem"
|
||||
},
|
||||
"acl": true,
|
||||
"acl": false,
|
||||
"aclConf": "conf/acl.conf"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ type client struct {
|
||||
|
||||
type subscription struct {
|
||||
client *client
|
||||
topic []byte
|
||||
topic string
|
||||
qos byte
|
||||
queue bool
|
||||
}
|
||||
@@ -158,7 +158,7 @@ func (c *client) ProcessPublish(packet *packets.PublishPacket) {
|
||||
|
||||
if packet.Retain {
|
||||
if b := c.broker; b != nil {
|
||||
err := b.rl.Insert([]byte(topic), packet)
|
||||
err := b.rl.Insert(topic, packet)
|
||||
if err != nil {
|
||||
log.Error("Insert Retain Message error: ", err)
|
||||
}
|
||||
@@ -246,7 +246,7 @@ func (c *client) ProcessSubscribe(packet *packets.SubscribePacket) {
|
||||
var retcodes []byte
|
||||
|
||||
for i, topic := range topics {
|
||||
t := []byte(topic)
|
||||
t := topic
|
||||
//check topic auth for client
|
||||
if c.typ == CLIENT {
|
||||
if !c.CheckTopicAuth(SUB, topic) {
|
||||
@@ -310,7 +310,7 @@ func (c *client) ProcessSubscribe(packet *packets.SubscribePacket) {
|
||||
|
||||
//process retain message
|
||||
for _, t := range topics {
|
||||
packets := b.rl.Match([]byte(t))
|
||||
packets := b.rl.Match(t)
|
||||
for _, packet := range packets {
|
||||
log.Info("process retain message: ", packet)
|
||||
if packet != nil {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package broker
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
@@ -47,16 +46,10 @@ const (
|
||||
QosFailure = 0x80
|
||||
)
|
||||
|
||||
func SubscribeTopicCheckAndSpilt(subject []byte) ([]string, error) {
|
||||
|
||||
topic := string(subject)
|
||||
|
||||
if bytes.IndexByte(subject, '#') != -1 {
|
||||
if bytes.IndexByte(subject, '#') != len(subject)-1 {
|
||||
return nil, errors.New("Topic format error with index of #")
|
||||
}
|
||||
func SubscribeTopicCheckAndSpilt(topic string) ([]string, error) {
|
||||
if strings.Index(topic, "#") != -1 && strings.Index(topic, "#") != len(topic)-1 {
|
||||
return nil, errors.New("Topic format error with index of #")
|
||||
}
|
||||
|
||||
re := strings.Split(topic, "/")
|
||||
for i, v := range re {
|
||||
if i != 0 && i != (len(re)-1) {
|
||||
@@ -76,11 +69,10 @@ func SubscribeTopicCheckAndSpilt(subject []byte) ([]string, error) {
|
||||
|
||||
}
|
||||
|
||||
func PublishTopicCheckAndSpilt(subject []byte) ([]string, error) {
|
||||
if bytes.IndexByte(subject, '#') != -1 || bytes.IndexByte(subject, '+') != -1 {
|
||||
func PublishTopicCheckAndSpilt(topic string) ([]string, error) {
|
||||
if strings.Index(topic, "#") != -1 || strings.Index(topic, "+") != -1 {
|
||||
return nil, errors.New("Publish Topic format error with + and #")
|
||||
}
|
||||
topic := string(subject)
|
||||
re := strings.Split(topic, "/")
|
||||
for i, v := range re {
|
||||
if v == "" {
|
||||
|
||||
@@ -32,7 +32,7 @@ func NewRetainList() *RetainList {
|
||||
return &RetainList{root: newRLevel()}
|
||||
}
|
||||
|
||||
func (r *RetainList) Insert(topic []byte, buf *packets.PublishPacket) error {
|
||||
func (r *RetainList) Insert(topic string, buf *packets.PublishPacket) error {
|
||||
|
||||
tokens, err := PublishTopicCheckAndSpilt(topic)
|
||||
if err != nil {
|
||||
@@ -59,7 +59,7 @@ func (r *RetainList) Insert(topic []byte, buf *packets.PublishPacket) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RetainList) Match(topic []byte) []*packets.PublishPacket {
|
||||
func (r *RetainList) Match(topic string) []*packets.PublishPacket {
|
||||
|
||||
tokens, err := SubscribeTopicCheckAndSpilt(topic)
|
||||
if err != nil {
|
||||
|
||||
@@ -124,8 +124,8 @@ func (s *Sublist) removeFromCache(topic string, sub *subscription) {
|
||||
}
|
||||
|
||||
func matchLiteral(literal, topic string) bool {
|
||||
tok, _ := SubscribeTopicCheckAndSpilt([]byte(topic))
|
||||
li, _ := PublishTopicCheckAndSpilt([]byte(literal))
|
||||
tok, _ := SubscribeTopicCheckAndSpilt(topic)
|
||||
li, _ := PublishTopicCheckAndSpilt(literal)
|
||||
|
||||
for i := 0; i < len(tok); i++ {
|
||||
b := tok[i]
|
||||
@@ -207,7 +207,7 @@ func (s *Sublist) Match(topic string) *SublistResult {
|
||||
return rc
|
||||
}
|
||||
|
||||
tokens, err := PublishTopicCheckAndSpilt([]byte(topic))
|
||||
tokens, err := PublishTopicCheckAndSpilt(topic)
|
||||
if err != nil {
|
||||
log.Error("\tserver/sublist.go: ", err)
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user