1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-26 02:25:58 +01:00

Allow empty values in clientMessage.

This commit is contained in:
Juliusz Chroboczek 2020-12-02 19:33:53 +01:00
parent 4a4973fc44
commit 43047fc00e

View file

@ -26,12 +26,13 @@ func errorToWSCloseMessage(id string, err error) (*clientMessage, []byte) {
code = websocket.CloseNormalClosure code = websocket.CloseNormalClosure
case group.ProtocolError: case group.ProtocolError:
code = websocket.CloseProtocolError code = websocket.CloseProtocolError
s := e.Error()
m = &clientMessage{ m = &clientMessage{
Type: "usermessage", Type: "usermessage",
Kind: "error", Kind: "error",
Dest: id, Dest: id,
Priviledged: true, Priviledged: true,
Value: e.Error(), Value: &s,
} }
text = e.Error() text = e.Error()
case group.UserError, group.KickError: case group.UserError, group.KickError:
@ -169,7 +170,7 @@ type clientMessage struct {
Priviledged bool `json:"priviledged,omitempty"` Priviledged bool `json:"priviledged,omitempty"`
Permissions *group.ClientPermissions `json:"permissions,omitempty"` Permissions *group.ClientPermissions `json:"permissions,omitempty"`
Group string `json:"group,omitempty"` Group string `json:"group,omitempty"`
Value string `json:"value,omitempty"` Value *string `json:"value,omitempty"`
Time int64 `json:"time,omitempty"` Time int64 `json:"time,omitempty"`
Offer *webrtc.SessionDescription `json:"offer,omitempty"` Offer *webrtc.SessionDescription `json:"offer,omitempty"`
Answer *webrtc.SessionDescription `json:"answer,omitempty"` Answer *webrtc.SessionDescription `json:"answer,omitempty"`
@ -809,10 +810,11 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
} }
} }
case addLabelAction: case addLabelAction:
label := a.label
c.write(clientMessage{ c.write(clientMessage{
Type: "label", Type: "label",
Id: a.id, Id: a.id,
Value: a.label, Value: &label,
}) })
case pushConnsAction: case pushConnsAction:
for _, u := range c.up { for _, u := range c.up {
@ -1021,12 +1023,13 @@ func handleClientMessage(c *webClient, m clientMessage) error {
) )
} else if err == group.ErrNotAuthorised { } else if err == group.ErrNotAuthorised {
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
s := "not authorised"
return c.write(clientMessage{ return c.write(clientMessage{
Type: "joined", Type: "joined",
Kind: "fail", Kind: "fail",
Group: m.Group, Group: m.Group,
Permissions: &group.ClientPermissions{}, Permissions: &group.ClientPermissions{},
Value: "not authorised", Value: &s,
}) })
} }
return err return err
@ -1116,10 +1119,14 @@ func handleClientMessage(c *webClient, m clientMessage) error {
} }
tm := group.ToJSTime(time.Now()) tm := group.ToJSTime(time.Now())
if m.Type == "chat" { if m.Type == "chat" {
if m.Value == nil {
return group.ProtocolError("missing value")
}
if m.Dest == "" { if m.Dest == "" {
g.AddToChatHistory( g.AddToChatHistory(
m.Id, m.Username, tm, m.Kind, m.Value, m.Id, m.Username, tm, m.Kind, *m.Value,
) )
} }
} }
@ -1178,7 +1185,11 @@ func handleClientMessage(c *webClient, m clientMessage) error {
if !c.permissions.Op { if !c.permissions.Op {
return c.error(group.UserError("not authorised")) return c.error(group.UserError("not authorised"))
} }
g.SetLocked(m.Kind == "lock", m.Value) message := ""
if m.Value != nil {
message = *m.Value
}
g.SetLocked(m.Kind == "lock", message)
case "record": case "record":
if !c.permissions.Record { if !c.permissions.Record {
return c.error(group.UserError("not authorised")) return c.error(group.UserError("not authorised"))
@ -1234,7 +1245,11 @@ func handleClientMessage(c *webClient, m clientMessage) error {
if !c.permissions.Op { if !c.permissions.Op {
return c.error(group.UserError("not authorised")) return c.error(group.UserError("not authorised"))
} }
err := kickClient(g, m.Id, m.Username, m.Dest, m.Value) message := ""
if m.Value != nil {
message = *m.Value
}
err := kickClient(g, m.Id, m.Username, m.Dest, message)
if err != nil { if err != nil {
return c.error(err) return c.error(err)
} }
@ -1344,12 +1359,13 @@ func (c *webClient) close(data []byte) error {
func errorMessage(id string, err error) *clientMessage { func errorMessage(id string, err error) *clientMessage {
switch e := err.(type) { switch e := err.(type) {
case group.UserError: case group.UserError:
message := e.Error()
return &clientMessage{ return &clientMessage{
Type: "usermessage", Type: "usermessage",
Kind: "error", Kind: "error",
Dest: id, Dest: id,
Priviledged: true, Priviledged: true,
Value: e.Error(), Value: &message,
} }
case group.KickError: case group.KickError:
message := e.Message message := e.Message
@ -1363,7 +1379,7 @@ func errorMessage(id string, err error) *clientMessage {
Username: e.Username, Username: e.Username,
Dest: id, Dest: id,
Priviledged: true, Priviledged: true,
Value: message, Value: &message,
} }
default: default:
return nil return nil