Skip to content

Commit

Permalink
Sanitize arguments given to NSLog() (should fix #157)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Apr 14, 2016
1 parent ac4e857 commit 2cb978e
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 69 deletions.
4 changes: 3 additions & 1 deletion src/PluginEnumerateDevices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class PluginEnumerateDevices {
position = "front"
}

NSLog("- device [uniqueID:'\(device.uniqueID)', localizedName:'\(device.localizedName)', position:\(position), audio:\(hasAudio), video:\(hasVideo), connected:\(device.connected)")
NSLog("- device [uniqueID:'%@', localizedName:'%@', position:%@, audio:%@, video:%@, connected:%@]",
String(device.uniqueID), String(device.localizedName), String(position),
String(hasAudio), String(hasVideo), String(device.connected))

if device.connected == false || (hasAudio == false && hasVideo == false) {
continue
Expand Down
16 changes: 8 additions & 8 deletions src/PluginGetUserMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class PluginGetUserMedia {

// Video device specified.
else {
NSLog("PluginGetUserMedia#call() | video requested (specified device id: \(videoDeviceId!))")
NSLog("PluginGetUserMedia#call() | video requested (specified device id: '%@')", String(videoDeviceId!))

for device: AVCaptureDevice in (AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) as! Array<AVCaptureDevice>) {
if device.uniqueID == videoDeviceId {
Expand All @@ -114,32 +114,32 @@ class PluginGetUserMedia {
return
}

NSLog("PluginGetUserMedia#call() | chosen video device: \(videoDevice!)")
NSLog("PluginGetUserMedia#call() | chosen video device: %@", String(videoDevice!))

rtcVideoCapturer = RTCVideoCapturer(deviceName: videoDevice!.localizedName)

if videoMinWidth > 0 {
NSLog("PluginGetUserMedia#call() | adding media constraint [minWidth:\(videoMinWidth)]")
NSLog("PluginGetUserMedia#call() | adding media constraint [minWidth:%@]", String(videoMinWidth))
mandatoryConstraints.append(RTCPair(key: "minWidth", value: String(videoMinWidth)))
}
if videoMaxWidth > 0 {
NSLog("PluginGetUserMedia#call() | adding media constraint [maxWidth:\(videoMaxWidth)]")
NSLog("PluginGetUserMedia#call() | adding media constraint [maxWidth:%@]", String(videoMaxWidth))
mandatoryConstraints.append(RTCPair(key: "maxWidth", value: String(videoMaxWidth)))
}
if videoMinHeight > 0 {
NSLog("PluginGetUserMedia#call() | adding media constraint [minHeight:\(videoMinHeight)]")
NSLog("PluginGetUserMedia#call() | adding media constraint [minHeight:%@]", String(videoMinHeight))
mandatoryConstraints.append(RTCPair(key: "minHeight", value: String(videoMinHeight)))
}
if videoMaxHeight > 0 {
NSLog("PluginGetUserMedia#call() | adding media constraint [maxHeight:\(videoMaxHeight)]")
NSLog("PluginGetUserMedia#call() | adding media constraint [maxHeight:%@]", String(videoMaxHeight))
mandatoryConstraints.append(RTCPair(key: "maxHeight", value: String(videoMaxHeight)))
}
if videoMinFrameRate > 0 {
NSLog("PluginGetUserMedia#call() | adding media constraint [videoMinFrameRate:\(videoMinFrameRate)]")
NSLog("PluginGetUserMedia#call() | adding media constraint [videoMinFrameRate:%@]", String(videoMinFrameRate))
mandatoryConstraints.append(RTCPair(key: "minFrameRate", value: String(videoMinFrameRate)))
}
if videoMaxFrameRate > 0 {
NSLog("PluginGetUserMedia#call() | adding media constraint [videoMaxFrameRate:\(videoMaxFrameRate)]")
NSLog("PluginGetUserMedia#call() | adding media constraint [videoMaxFrameRate:%@]", String(videoMaxFrameRate))
mandatoryConstraints.append(RTCPair(key: "maxFrameRate", value: String(videoMaxFrameRate)))
}

Expand Down
8 changes: 4 additions & 4 deletions src/PluginMediaStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class PluginMediaStream : NSObject, RTCMediaStreamDelegate {


func OnAddAudioTrack(rtcMediaStream: RTCMediaStream!, track: RTCMediaStreamTrack!) {
NSLog("PluginMediaStream | OnAddAudioTrack [label:\(track.label)]")
NSLog("PluginMediaStream | OnAddAudioTrack [label:%@]", String(track.label))

let pluginMediaStreamTrack = PluginMediaStreamTrack(rtcMediaStreamTrack: track)

Expand All @@ -159,7 +159,7 @@ class PluginMediaStream : NSObject, RTCMediaStreamDelegate {


func OnAddVideoTrack(rtcMediaStream: RTCMediaStream!, track: RTCMediaStreamTrack!) {
NSLog("PluginMediaStream | OnAddVideoTrack [label:\(track.label)]")
NSLog("PluginMediaStream | OnAddVideoTrack [label:%@]", String(track.label))

let pluginMediaStreamTrack = PluginMediaStreamTrack(rtcMediaStreamTrack: track)

Expand All @@ -178,7 +178,7 @@ class PluginMediaStream : NSObject, RTCMediaStreamDelegate {


func OnRemoveAudioTrack(rtcMediaStream: RTCMediaStream!, track: RTCMediaStreamTrack!) {
NSLog("PluginMediaStream | OnRemoveAudioTrack [label:\(track.label)]")
NSLog("PluginMediaStream | OnRemoveAudioTrack [label:%@]", String(track.label))

// It may happen that track was removed due to user action (removeTrack()).
if self.audioTracks[track.label] == nil {
Expand All @@ -202,7 +202,7 @@ class PluginMediaStream : NSObject, RTCMediaStreamDelegate {


func OnRemoveVideoTrack(rtcMediaStream: RTCMediaStream!, track: RTCMediaStreamTrack!) {
NSLog("PluginMediaStream | OnRemoveVideoTrack [label:\(track.label)]")
NSLog("PluginMediaStream | OnRemoveVideoTrack [label:%@]", String(track.label))

// It may happen that track was removed due to user action (removeTrack()).
if self.videoTracks[track.label] == nil {
Expand Down
8 changes: 6 additions & 2 deletions src/PluginMediaStreamRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ class PluginMediaStreamRenderer : NSObject, RTCEAGLVideoViewDelegate {
let clip = data.objectForKey("clip") as? Bool ?? true
let borderRadius = data.objectForKey("borderRadius") as? Float ?? 0

NSLog("PluginMediaStreamRenderer#refresh() [elementLeft:\(elementLeft), elementTop:\(elementTop), elementWidth:\(elementWidth), elementHeight:\(elementHeight), videoViewWidth:\(videoViewWidth), videoViewHeight:\(videoViewHeight), visible:\(visible), opacity:\(opacity), zIndex:\(zIndex), mirrored:\(mirrored), clip:\(clip), borderRadius:\(borderRadius)]")
NSLog("PluginMediaStreamRenderer#refresh() [elementLeft:%@, elementTop:%@, elementWidth:%@, elementHeight:%@, videoViewWidth:%@, videoViewHeight:%@, visible:%@, opacity:%@, zIndex:%@, mirrored:%@, clip:%@, borderRadius:%@]",
String(elementLeft), String(elementTop), String(elementWidth), String(elementHeight),
String(videoViewWidth), String(videoViewHeight), String(visible), String(opacity), String(zIndex),
String(mirrored), String(clip), String(borderRadius))

let videoViewLeft: Float = (elementWidth - videoViewWidth) / 2
let videoViewTop: Float = (elementHeight - videoViewHeight) / 2
Expand Down Expand Up @@ -233,7 +236,8 @@ class PluginMediaStreamRenderer : NSObject, RTCEAGLVideoViewDelegate {


func videoView(videoView: RTCEAGLVideoView!, didChangeVideoSize size: CGSize) {
NSLog("PluginMediaStreamRenderer | video size changed [width:\(size.width), height:\(size.height)]")
NSLog("PluginMediaStreamRenderer | video size changed [width:%@, height:%@]",
String(size.width), String(size.height))

self.eventListener(data: [
"type": "videoresize",
Expand Down
12 changes: 7 additions & 5 deletions src/PluginMediaStreamTrack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PluginMediaStreamTrack : NSObject, RTCMediaStreamTrackDelegate {


func run() {
NSLog("PluginMediaStreamTrack#run() [kind:\(self.kind), id:\(self.id)]")
NSLog("PluginMediaStreamTrack#run() [kind:%@, id:%@]", String(self.kind), String(self.id))

self.rtcMediaStreamTrack.delegate = self
}
Expand All @@ -46,7 +46,7 @@ class PluginMediaStreamTrack : NSObject, RTCMediaStreamTrackDelegate {
eventListener: (data: NSDictionary) -> Void,
eventListenerForEnded: () -> Void
) {
NSLog("PluginMediaStreamTrack#setListener() [kind:\(self.kind), id:\(self.id)]")
NSLog("PluginMediaStreamTrack#setListener() [kind:%@, id:%@]", String(self.kind), String(self.id))

self.eventListener = eventListener
self.eventListenerForEnded = eventListenerForEnded
Expand All @@ -67,14 +67,15 @@ class PluginMediaStreamTrack : NSObject, RTCMediaStreamTrackDelegate {


func setEnabled(value: Bool) {
NSLog("PluginMediaStreamTrack#setEnabled() [kind:\(self.kind), id:\(self.id), value:\(value)]")
NSLog("PluginMediaStreamTrack#setEnabled() [kind:%@, id:%@, value:%@]",
String(self.kind), String(self.id), String(value))

self.rtcMediaStreamTrack.setEnabled(value)
}


func stop() {
NSLog("PluginMediaStreamTrack#stop() [kind:\(self.kind), id:\(self.id)]")
NSLog("PluginMediaStreamTrack#stop() [kind:%@, id:%@]", String(self.kind), String(self.id))

self.rtcMediaStreamTrack.setState(RTCTrackStateEnded)
}
Expand All @@ -88,7 +89,8 @@ class PluginMediaStreamTrack : NSObject, RTCMediaStreamTrackDelegate {
func mediaStreamTrackDidChange(rtcMediaStreamTrack: RTCMediaStreamTrack!) {
let state_str = PluginRTCTypes.mediaStreamTrackStates[self.rtcMediaStreamTrack.state().rawValue] as String!

NSLog("PluginMediaStreamTrack | state changed [kind:\(self.kind), id:\(self.id), state:\(state_str), enabled:\(self.rtcMediaStreamTrack.isEnabled() ? true : false)]")
NSLog("PluginMediaStreamTrack | state changed [kind:%@, id:%@, state:%@, enabled:%@]",
String(self.kind), String(self.id), String(state_str), String(self.rtcMediaStreamTrack.isEnabled()))

if self.eventListener != nil {
self.eventListener!(data: [
Expand Down
4 changes: 2 additions & 2 deletions src/PluginRTCDataChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PluginRTCDataChannel : NSObject, RTCDataChannelDelegate {
)

if self.rtcDataChannel == nil {
NSLog("PluginRTCDataChannel#init() | rtcPeerConnection.createDataChannelWithLabel() failed !!!")
NSLog("PluginRTCDataChannel#init() | rtcPeerConnection.createDataChannelWithLabel() failed")
return
}

Expand Down Expand Up @@ -187,7 +187,7 @@ class PluginRTCDataChannel : NSObject, RTCDataChannelDelegate {
func channelDidChangeState(channel: RTCDataChannel!) {
let state_str = PluginRTCTypes.dataChannelStates[self.rtcDataChannel!.state.rawValue] as String!

NSLog("PluginRTCDataChannel | state changed [state:\(state_str)]")
NSLog("PluginRTCDataChannel | state changed [state:%@]", String(state_str))

if self.eventListener != nil {
self.eventListener!(data: [
Expand Down
21 changes: 11 additions & 10 deletions src/PluginRTCPeerConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate, RTCSessionD
let pluginRTCPeerConnectionConstraints = PluginRTCPeerConnectionConstraints(pcConstraints: options)

self.onCreateDescriptionSuccessCallback = { (rtcSessionDescription: RTCSessionDescription) -> Void in
NSLog("PluginRTCPeerConnection#createOffer() | success callback [type:\(rtcSessionDescription.type)]")
NSLog("PluginRTCPeerConnection#createOffer() | success callback")

let data = [
"type": rtcSessionDescription.type,
Expand All @@ -77,7 +77,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate, RTCSessionD
}

self.onCreateDescriptionFailureCallback = { (error: NSError) -> Void in
NSLog("PluginRTCPeerConnection#createOffer() | failure callback: \(error)")
NSLog("PluginRTCPeerConnection#createOffer() | failure callback: %@", String(error))

errback(error: error)
}
Expand All @@ -101,7 +101,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate, RTCSessionD
let pluginRTCPeerConnectionConstraints = PluginRTCPeerConnectionConstraints(pcConstraints: options)

self.onCreateDescriptionSuccessCallback = { (rtcSessionDescription: RTCSessionDescription) -> Void in
NSLog("PluginRTCPeerConnection#createAnswer() | success callback [type:\(rtcSessionDescription.type)]")
NSLog("PluginRTCPeerConnection#createAnswer() | success callback")

let data = [
"type": rtcSessionDescription.type,
Expand All @@ -112,7 +112,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate, RTCSessionD
}

self.onCreateDescriptionFailureCallback = { (error: NSError) -> Void in
NSLog("PluginRTCPeerConnection#createAnswer() | failure callback: \(error)")
NSLog("PluginRTCPeerConnection#createAnswer() | failure callback: %@", String(error))

errback(error: error)
}
Expand Down Expand Up @@ -149,7 +149,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate, RTCSessionD
}

self.onSetDescriptionFailureCallback = { (error: NSError) -> Void in
NSLog("PluginRTCPeerConnection#setLocalDescription() | failure callback: \(error)")
NSLog("PluginRTCPeerConnection#setLocalDescription() | failure callback: %@", String(error))

errback(error: error)
}
Expand Down Expand Up @@ -187,7 +187,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate, RTCSessionD
}

self.onSetDescriptionFailureCallback = { (error: NSError) -> Void in
NSLog("PluginRTCPeerConnection#setRemoteDescription() | failure callback: \(error)")
NSLog("PluginRTCPeerConnection#setRemoteDescription() | failure callback: %@", String(error))

errback(error: error)
}
Expand Down Expand Up @@ -395,7 +395,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate, RTCSessionD
signalingStateChanged newState: RTCSignalingState) {
let state_str = PluginRTCTypes.signalingStates[newState.rawValue] as String!

NSLog("PluginRTCPeerConnection | onsignalingstatechange [signalingState:\(state_str)]")
NSLog("PluginRTCPeerConnection | onsignalingstatechange [signalingState:%@]", String(state_str))

self.eventListener(data: [
"type": "signalingstatechange",
Expand All @@ -408,7 +408,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate, RTCSessionD
iceGatheringChanged newState: RTCICEGatheringState) {
let state_str = PluginRTCTypes.iceGatheringStates[newState.rawValue] as String!

NSLog("PluginRTCPeerConnection | onicegatheringstatechange [iceGatheringState:\(state_str)]")
NSLog("PluginRTCPeerConnection | onicegatheringstatechange [iceGatheringState:%@]", String(state_str))

self.eventListener(data: [
"type": "icegatheringstatechange",
Expand Down Expand Up @@ -436,7 +436,8 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate, RTCSessionD

func peerConnection(peerConnection: RTCPeerConnection!,
gotICECandidate candidate: RTCICECandidate!) {
NSLog("PluginRTCPeerConnection | onicecandidate [sdpMid:\(candidate.sdpMid), sdpMLineIndex:\(candidate.sdpMLineIndex), candidate:\(candidate.sdp)]")
NSLog("PluginRTCPeerConnection | onicecandidate [sdpMid:%@, sdpMLineIndex:%@, candidate:%@]",
String(candidate.sdpMid), String(candidate.sdpMLineIndex), String(candidate.sdp))

if self.rtcPeerConnection.signalingState.rawValue == RTCSignalingClosed.rawValue {
return
Expand All @@ -461,7 +462,7 @@ class PluginRTCPeerConnection : NSObject, RTCPeerConnectionDelegate, RTCSessionD
iceConnectionChanged newState: RTCICEConnectionState) {
let state_str = PluginRTCTypes.iceConnectionStates[newState.rawValue] as String!

NSLog("PluginRTCPeerConnection | oniceconnectionstatechange [iceConnectionState:\(state_str)]")
NSLog("PluginRTCPeerConnection | oniceconnectionstatechange [iceConnectionState:%@]", String(state_str))

self.eventListener(data: [
"type": "iceconnectionstatechange",
Expand Down
3 changes: 2 additions & 1 deletion src/PluginRTCPeerConnectionConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class PluginRTCPeerConnectionConfig {
let password = iceServer.objectForKey("credential") as? String ?? ""

if (url != nil) {
NSLog("PluginRTCPeerConnectionConfig#init() | adding ICE server [url:\(url!), username:\(username), password:\(password)]")
NSLog("PluginRTCPeerConnectionConfig#init() | adding ICE server [url:'%@', username:'%@', password:'******']",
String(url!), String(username))

self.iceServers.append(RTCICEServer(
URI: NSURL(string: url!),
Expand Down
3 changes: 2 additions & 1 deletion src/PluginRTCPeerConnectionConstraints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class PluginRTCPeerConnectionConstraints {
offerToReceiveVideo = false
}

NSLog("PluginRTCPeerConnectionConstraints#init() | [offerToReceiveAudio:\(offerToReceiveAudio!) | offerToReceiveVideo:\(offerToReceiveVideo!)]")
NSLog("PluginRTCPeerConnectionConstraints#init() | [offerToReceiveAudio:%@, offerToReceiveVideo:%@]",
String(offerToReceiveAudio!), String(offerToReceiveVideo!))

self.constraints = RTCMediaConstraints(
mandatoryConstraints: [
Expand Down
Loading

0 comments on commit 2cb978e

Please sign in to comment.