MCPcopy
hub / github.com/livekit/livekit / validateInternal

Method validateInternal

pkg/service/rtcservice.go:130–284  ·  view source on GitHub ↗
(
	lgr logger.Logger,
	r *http.Request,
	needsJoinRequest bool,
	strict bool,
)

Source from the content-addressed store, hash-verified

128var errJoinRequestTooLarge = errors.New("join request too large")
129
130func (s *RTCService) validateInternal(
131 lgr logger.Logger,
132 r *http.Request,
133 needsJoinRequest bool,
134 strict bool,
135) (livekit.RoomName, routing.ParticipantInit, int, error) {
136 if claims := GetGrants(r.Context()); claims == nil || claims.Video == nil {
137 return "", routing.ParticipantInit{}, http.StatusUnauthorized, rtc.ErrPermissionDenied
138 }
139
140 var params ValidateConnectRequestParams
141 useSinglePeerConnection := false
142 joinRequest := &livekit.JoinRequest{}
143
144 wrappedJoinRequestBase64 := r.FormValue("join_request")
145 if wrappedJoinRequestBase64 == "" {
146 if needsJoinRequest {
147 return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("join_request is required")
148 }
149
150 params.publish = r.FormValue("publish")
151
152 attributesStrParam := r.FormValue("attributes")
153 if attributesStrParam != "" {
154 attrs, err := decodeAttributes(attributesStrParam)
155 if err != nil {
156 if strict {
157 return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot decode attributes")
158 }
159 lgr.Debugw("failed to decode attributes", "error", err)
160 // attrs will be empty here, so just proceed
161 }
162 params.attributes = attrs
163 }
164 } else {
165 useSinglePeerConnection = true
166 if wrappedProtoBytes, err := base64.URLEncoding.DecodeString(wrappedJoinRequestBase64); err != nil {
167 return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot base64 decode wrapped join request")
168 } else {
169 wrappedJoinRequest := &livekit.WrappedJoinRequest{}
170 if err := proto.Unmarshal(wrappedProtoBytes, wrappedJoinRequest); err != nil {
171 return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot unmarshal wrapped join request")
172 }
173
174 switch wrappedJoinRequest.Compression {
175 case livekit.WrappedJoinRequest_NONE:
176 if len(wrappedJoinRequest.JoinRequest) > http.DefaultMaxHeaderBytes {
177 return "", routing.ParticipantInit{}, http.StatusBadRequest, errJoinRequestTooLarge
178 }
179 if err := proto.Unmarshal(wrappedJoinRequest.JoinRequest, joinRequest); err != nil {
180 return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("cannot unmarshal join request")
181 }
182
183 case livekit.WrappedJoinRequest_GZIP:
184 protoBytes, err := DecompressGzip(wrappedJoinRequest.JoinRequest)
185 if err != nil {
186 switch {
187 case errors.Is(err, ErrGzipTooLarge):

Callers 3

v0ValidateMethod · 0.95
v1ValidateMethod · 0.95
serveMethod · 0.95

Calls 10

GetGrantsFunction · 0.85
decodeAttributesFunction · 0.85
DecompressGzipFunction · 0.85
ValidateConnectRequestFunction · 0.85
boolValueFunction · 0.85
ParseClientInfoFunction · 0.85
AugmentClientInfoFunction · 0.85
GetAdaptiveStreamMethod · 0.65
UnmarshalMethod · 0.45
ParticipantIDMethod · 0.45

Tested by

no test coverage detected