1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.profile;
17
18 import org.fourthline.cling.model.message.Connection;
19 import org.fourthline.cling.model.message.StreamRequestMessage;
20 import org.fourthline.cling.model.message.UpnpHeaders;
21 import org.fourthline.cling.model.message.header.UpnpHeader;
22 import org.fourthline.cling.model.message.header.UserAgentHeader;
23 import org.seamless.http.RequestInfo;
24
25 import java.net.InetAddress;
26
27
28
29
30
31
32
33
34
35
36
37 public class RemoteClientInfo extends ClientInfo {
38
39 final protected Connection connection;
40 final protected UpnpHeaders extraResponseHeaders = new UpnpHeaders();
41
42 public RemoteClientInfo() {
43 this(null);
44 }
45
46 public RemoteClientInfo(StreamRequestMessage requestMessage) {
47 this(requestMessage != null ? requestMessage.getConnection() : null,
48 requestMessage != null ? requestMessage.getHeaders() : new UpnpHeaders());
49 }
50
51 public RemoteClientInfo(Connection connection, UpnpHeaders requestHeaders) {
52 super(requestHeaders);
53 this.connection = connection;
54 }
55
56 public Connection getConnection() {
57 return connection;
58 }
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 public boolean isRequestCancelled() {
74 return !getConnection().isOpen();
75 }
76
77
78
79
80 public void throwIfRequestCancelled() throws InterruptedException{
81 if(isRequestCancelled())
82 throw new InterruptedException("Client's request cancelled");
83 }
84
85 public InetAddress getRemoteAddress() {
86 return getConnection().getRemoteAddress();
87 }
88
89 public InetAddress getLocalAddress() {
90 return getConnection().getLocalAddress();
91 }
92
93 public UpnpHeaders getExtraResponseHeaders() {
94 return extraResponseHeaders;
95 }
96
97 public void setResponseUserAgent(String userAgent) {
98 setResponseUserAgent(new UserAgentHeader(userAgent));
99 }
100
101 public void setResponseUserAgent(UserAgentHeader userAgentHeader) {
102 getExtraResponseHeaders().add(
103 UpnpHeader.Type.USER_AGENT,
104 userAgentHeader
105 );
106 }
107
108
109 public boolean isWMPRequest() {
110 return RequestInfo.isWMPRequest(getRequestUserAgent());
111 }
112
113 public boolean isXbox360Request() {
114 return RequestInfo.isXbox360Request(
115 getRequestUserAgent(),
116 getRequestHeaders().getFirstHeaderString(UpnpHeader.Type.SERVER)
117 );
118 }
119
120 public boolean isPS3Request() {
121 return RequestInfo.isPS3Request(
122 getRequestUserAgent(),
123 getRequestHeaders().getFirstHeaderString(UpnpHeader.Type.EXT_AV_CLIENT_INFO)
124 );
125 }
126
127 @Override
128 public String toString() {
129 return "(" + getClass().getSimpleName() + ") Remote Address: " + getRemoteAddress();
130 }
131 }