aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/protocol/sip/SipStackProperties.java
blob: 37e4f60fd03d7b6269a819cbdd27366487949dc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.java.sip.communicator.impl.protocol.sip;

import java.io.*;
import java.util.*;
import java.util.logging.*;

import javax.net.ssl.*;

import net.java.sip.communicator.impl.protocol.sip.net.*;
import net.java.sip.communicator.util.Logger;

import org.jitsi.util.*;

/**
 * The properties used at the creation of the JAIN-SIP stack.
 *
 * @author Sebastien Mazy
 * @author Emil Ivov
 */
public class SipStackProperties
    extends Properties
{
    private static final long serialVersionUID = 0L;

    private static final Logger logger
        = Logger.getLogger(SipStackProperties.class);

    /**
     * The name of the property under which the jain-sip-ri would expect to find
     * the name of a debug log file.
     */
    private static final String NSPNAME_DEBUG_LOG =
        "gov.nist.javax.sip.DEBUG_LOG";

    /**
     * The default name of a debug log file for the jain-sip RI.
     * (not final on purpose, see constructor)
     */
    private static String NSPVALUE_DEBUG_LOG = "log/sc-jainsipdebug.log";

    /**
     * The name of the property under which the jain-sip-ri would expect to find
     * if the content of the messages (eg SDP) has to be logged
     */
    private static final String NSPNAME_LOG_MESSAGE_CONTENT
        = "gov.nist.javax.sip.LOG_MESSAGE_CONTENT";

    /**
     * A string indicating to jain-sip-ri if the content of the messages (eg
     * SDP) has to be logged
     */
    private static final String NSPVALUE_LOG_MESSAGE_CONTENT = "true";

    /**
     * The name of the property indicating a custom logger class for the stack
     */
    private static final String NSPNAME_STACK_LOGGER
        = "gov.nist.javax.sip.STACK_LOGGER";

    /**
     * The value of the property indicating a custom logger class for the stack
     */
    private static final String NSPVALUE_STACK_LOGGER
        = "net.java.sip.communicator.impl.protocol.sip.SipLogger";

    /**
     * The name of the property indicating a custom logger class
     * for the server messages
     */
    private static final String NSPNAME_SERVER_LOGGER
        = "gov.nist.javax.sip.SERVER_LOGGER";

    /**
     * The value of the property indicating a custom logger class
     * for the server messages
     */
    private static final String NSPVALUE_SERVER_LOGGER
        = "net.java.sip.communicator.impl.protocol.sip.SipLogger";

    /**
     * The name of the property under which the jain-sip-ri would expect to find
     * if the debug log file has to be overwritten when starting.
     */
    private static final String NSPNAME_DEBUG_LOG_OVERWRITE
        = "gov.nist.javax.sip.DEBUG_LOG_OVERWRITE";

    /**
     * A string indicating to jain-sip-ri if the debug log file has to be
     * overwritten when starting.
     */
    private static final String NSPVALUE_DEBUG_LOG_OVERWRITE = "true";

    /**
     * The name of the property under which the jain-sip-ri would expect to find
     * if the server log file has to be overwritten when starting.
     */
    private static final String NSPNAME_SERVER_LOG_OVERWRITE
        = "gov.nist.javax.sip.SERVER_LOG_OVERWRITE";

    /**
     * A string indicating to jain-sip-ri if the server log file has to be
     * overwritten when starting.
     */
    private static final String NSPVALUE_SERVER_LOG_OVERWRITE
        = "true";

    /**
     * The name of the property under which the jain-sip-ri would expect to find
     * a property specifying whether or not it is to cache client connections.
     */
    private static final String NSPNAME_CACHE_CLIENT_CONNECTIONS =
        "gov.nist.javax.sip.CACHE_CLIENT_CONNECTIONS";

    /**
     * A default specifier telling the stack whether or not to cache client
     * connections.
     */
    private static final String NSPVALUE_CACHE_CLIENT_CONNECTIONS = "true";

    /**
     * The name of the property that tells jain-sip whether that we would like
     * to receive messages from the stack in a concurrent/reentrant/non-blocking
     * manner.
     */
    private static final String NSPNAME_REENTRANT_LISTENER
        = "gov.nist.javax.sip.REENTRANT_LISTENER";

    /**
     * The value of the property that tells jain-sip whether or we would like to
     * receive messages from the stack in a concurrent or blocking manner.
     */
    private static final String NSPVALUE_REENTRANT_LISTENER = "true";

    /**
     * The name of the property under which the jain-sip-ri would expect to find
     * the log level (detail) for all stack logging.
     */
    private static final String NSPNAME_TRACE_LEVEL =
        "gov.nist.javax.sip.TRACE_LEVEL";

    /**
     * A String indicating the default debug level for the jain-sip-ri (must be
     * log4j compatible).
     */
    private static final String NSPVALUE_DEFAULT_TRACE_LEVEL = "ERROR";

    /**
     * The name of the property under which jain-sip will know if it must
     * deliver some unsolicited notify.
     */
    private static final String NSPNAME_DELIVER_UNSOLICITED_NOTIFY =
        "gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY";

    /**
     * The value of the property under which jain-sip will know if it must
     * deliver some unsolicited notify.
     */
    private static final String NSPVALUE_DELIVER_UNSOLICITED_NOTIFY = "true";

    /**
     * The name of the property under which jain-sip will know if it must
     * always use the custom application provided router
     */
    private static final String NSPNAME_USE_ROUTER_FOR_ALL_URIS =
        "javax.sip.USE_ROUTER_FOR_ALL_URIS";

    /**
     * The name of the property under which jain-sip will know if it must
     * always use the custom application provided router
     */
    private static final String NSPVALUE_USE_ROUTER_FOR_ALL_URIS =
        "true";

    /**
     * The name of the property under which jain-sip will know if it must
     * always use the custom application provided router
     */
    private static final String NSPNAME_ROUTER_PATH =
        "javax.sip.ROUTER_PATH";

    /**
     * The name of the property under which jain-sip will know if it must
     * always use the custom application provided router
     */
    private static final String NSPVALUE_ROUTER_PATH =
        "net.java.sip.communicator.impl.protocol.sip.ProxyRouter";

    /**
     * The name of the property under which the jain-sip-ri would expect to find
     * the the name of the stack..
     */
    private static final String JSPNAME_STACK_NAME =
        "javax.sip.STACK_NAME";

    /**
     * The name of the property that defines the supported SSL protocols of the
     * JSIP stack.
     */
    private static final String NSPNAME_TLS_CLIENT_PROTOCOLS =
        "gov.nist.javax.sip.TLS_CLIENT_PROTOCOLS";

    /**
     * Init sip stack properties.
     */
    public SipStackProperties()
    {
        super();

        String logDir
            = SipActivator.getConfigurationService().getScHomeDirLocation()
            + System.getProperty("file.separator")
            + SipActivator.getConfigurationService().getScHomeDirName()
            + System.getProperty("file.separator");

        // don't do it more than one time if many providers are initialised
        if (!NSPVALUE_DEBUG_LOG.startsWith(logDir))
            NSPVALUE_DEBUG_LOG = logDir + NSPVALUE_DEBUG_LOG;

        this.setProperty(JSPNAME_STACK_NAME, "Sip Communicator");

        // NIST SIP specific properties
        this.setProperty(NSPNAME_DEBUG_LOG, NSPVALUE_DEBUG_LOG);

        this.setProperty(NSPNAME_LOG_MESSAGE_CONTENT,
                NSPVALUE_LOG_MESSAGE_CONTENT);

        this.setProperty(NSPNAME_DEBUG_LOG_OVERWRITE,
                         NSPVALUE_DEBUG_LOG_OVERWRITE);

        this.setProperty(NSPNAME_SERVER_LOG_OVERWRITE,
                         NSPVALUE_SERVER_LOG_OVERWRITE);

        // Drop the client connection after we are done with the transaction.
        this.setProperty(NSPNAME_CACHE_CLIENT_CONNECTIONS,
                NSPVALUE_CACHE_CLIENT_CONNECTIONS);

        //handling SIP messages in a reentrant/non-blocking mode
        this.setProperty(NSPNAME_REENTRANT_LISTENER,
                NSPVALUE_REENTRANT_LISTENER);

        // deliver unsolicited NOTIFY
        this.setProperty(NSPNAME_DELIVER_UNSOLICITED_NOTIFY,
                NSPVALUE_DELIVER_UNSOLICITED_NOTIFY);

        // always use custom router for all URIs
        // (the custom router is a wrapper around the default router anyway)
        this.setProperty(NSPNAME_USE_ROUTER_FOR_ALL_URIS,
                NSPVALUE_USE_ROUTER_FOR_ALL_URIS);

        // router to use when no Route header is set
        // our ProxyRouter will send the message to the outbound proxy
        this.setProperty(NSPNAME_ROUTER_PATH,
                NSPVALUE_ROUTER_PATH);

        //make sure that jain-sip would accept java generated addresses
        //containing address scope zones
        System.setProperty("gov.nist.core.STRIP_ADDR_SCOPES", "true");

        //set stack log (trace) level properties according to parameters
        //set in logging.properties for the gov.nist packages
        String logLevel
            = LogManager.getLogManager().getProperty("gov.nist.level");

        String jainSipTraceLevel = null;

        //if this is a java logging level - convert it to a NIST level
        if (logLevel == null)
        {
            jainSipTraceLevel = NSPVALUE_DEFAULT_TRACE_LEVEL;
        }
        else if (logLevel.equals(Level.FINEST.getName()))
        {
            jainSipTraceLevel = "TRACE";
        }
        else if (logLevel.equals(Level.FINER.getName()))
        {
            jainSipTraceLevel = "DEBUG";
        }
        else if (logLevel.equals(Level.FINE.getName()))
        {
            jainSipTraceLevel = "INFO";
        }
        else if (logLevel.equals(Level.WARNING.getName())
                 || logLevel.equals(Level.SEVERE.getName()))
        {
            jainSipTraceLevel = "ERROR";
        }
        else if (logLevel.equals(Level.OFF.getName()))
        {
            jainSipTraceLevel = "OFF";
        }
        else
        {
            //doesn't look like a java logging level, so we just supposed the
            //string was a jain-sip level and pass it directly
            jainSipTraceLevel = logLevel;
        }

        this.setProperty(NSPNAME_TRACE_LEVEL, jainSipTraceLevel);

        this.setProperty(NSPNAME_STACK_LOGGER, NSPVALUE_STACK_LOGGER);
        this.setProperty(NSPNAME_SERVER_LOGGER, NSPVALUE_SERVER_LOGGER);

        if(OSUtils.IS_ANDROID)
        {
            this.setProperty("gov.nist.javax.sip.NETWORK_LAYER",
                AndroidNetworkLayer.class.getName());
        }
        else
        {
            this.setProperty("gov.nist.javax.sip.NETWORK_LAYER",
                SslNetworkLayer.class.getName());
        }

        try
        {
            String enabledSslProtocols = SipActivator.getConfigurationService()
                .getString(NSPNAME_TLS_CLIENT_PROTOCOLS);
            if(StringUtils.isNullOrEmpty(enabledSslProtocols, true))
            {
                SSLSocket temp = (SSLSocket) SSLSocketFactory
                    .getDefault().createSocket();
                String[] enabledDefaultProtocols = temp.getEnabledProtocols();
                enabledSslProtocols = "";
                for(int i = 0; i < enabledDefaultProtocols.length; i++)
                {
                    enabledSslProtocols += enabledDefaultProtocols[i];
                    if(i < enabledDefaultProtocols.length - 1)
                        enabledSslProtocols += ",";
                }
            }
            this.setProperty(NSPNAME_TLS_CLIENT_PROTOCOLS, enabledSslProtocols);
        }
        catch(IOException ex)
        {
            logger.error("Unable to obtain default SSL protocols from Java,"
                + " using JSIP defaults.", ex);
        }
    }
}