proxyconfigurationhandler.java

来自「基于JAINSIP的一个proxy源码」· Java 代码 · 共 747 行 · 第 1/2 页

JAVA
747
字号
                        " for the authentication");                    }                    else {                        configuration.classFile=classFile.trim();                    }                    String passwordsFile=attrs.getValue("passwords_file");                    if (passwordsFile==null) {                        configurationMessage                        ("WARNING: The passwords file is not set"+                        " for the authentication");                    }                    else {                        configuration.passwordsFile=passwordsFile.trim();                    }                                    }                catch(Exception e) {                    configuration.enableAuthentication=false;                    configurationMessage			("ERROR: Error initializing authentication [" +			e.getMessage() + "]");		     System.exit(0);                }            }        }                if (element.compareToIgnoreCase("LOGGING") ==0 ) {	     String remoteLogAccess = 			attrs.getValue("access_log_via_rmi");	    	     if (remoteLogAccess != null && 		remoteLogAccess.equalsIgnoreCase("true")) {                     configurationMessage                ("INFORMATION: RMI access to log file enabled"); 		configuration.accessLogViaRMI = true;		String rmiPort = attrs.getValue("rmi_port");		if (rmiPort != null) {		   configuration.logRMIPort = rmiPort;	            configurationMessage	            ("INFORMATION: the RMI port for log file is: " 				+ configuration.logRMIPort);		} else {		   configuration.logRMIPort = "0";	        }                configurationMessage	            ("INFORMATION: the default RMI port for log file is: " 				+ configuration.logRMIPort);                		configuration.logLifetime = attrs.getValue("log_lifetime");		if (configuration.logLifetime != null) 	            configurationMessage	            ("INFORMATION: the log lifetime is: " + 			configuration.logLifetime); 	     }             else {                     configurationMessage                    ("INFORMATION: RMI access to log file disabled");              }	     String enableDebug=attrs.getValue("enable_debug");             if (enableDebug==null || enableDebug.trim().equals("") ) {                 configuration.enableDebug=false;		  configurationMessage		  ("INFORMATION: the Debug feature is not set");             } else {                  try{                      boolean deb=Boolean.valueOf				(enableDebug.trim()).booleanValue();                      if ( deb) {                            configurationMessage		  ("INFORMATION: the Debug feature is set");                               configuration.enableDebug=deb;                      }                      else  {                          configuration.enableDebug=false;                          configurationMessage		  ("INFORMATION: the Debug feature is not set");                      }                  }                     catch(Exception e) {                      configuration.enableDebug=false;                      configurationMessage		  ("INFORMATION: the Debug feature is not set");                  }             }             String serverLogFile=attrs.getValue("server_log");             if (serverLogFile==null || serverLogFile.trim().equals("")) {		  configurationMessage		  ("INFORMATION: the server message log file is not set");             } else {                 configuration.serverLogFile=serverLogFile.trim();		 configurationMessage		  ("INFORMATION: the server message log file is: " 		   + configuration.serverLogFile);             }             String badMessageLog=attrs.getValue("bad_message_log");             if (badMessageLog==null || badMessageLog.trim().equals("")) {	        configurationMessage		("INFORMATION: the bad message log file is not set");             } else {                configuration.badMessageLogFile= badMessageLog.trim();	        configurationMessage		("INFORMATION: the bad message log is: " + 		configuration.badMessageLogFile);             }             String debugLog=attrs.getValue("debug_log");            if (debugLog==null || debugLog.trim().equals("")) {		configurationMessage		("INFORMATION: the debug log file is not set");             } else {                 configuration.debugLogFile=debugLog.trim();                 configurationMessage		("INFORMATION: the debug log file is: " + 		configuration.debugLogFile);              }              String outputProxy=attrs.getValue("output_proxy");              if (outputProxy==null || outputProxy.trim().equals("")) {		  configurationMessage		  ("INFORMATION: the output proxy file is not set");              } else {                  configuration.outputProxy=outputProxy.trim();                   configurationMessage		("INFORMATION: the output proxy file is: " + 		configuration.outputProxy);               }        }        if (element.compareToIgnoreCase("REGISTRATIONS") ==0 ) {                        String expiresTimeString=attrs.getValue("expires_time");            if (expiresTimeString!=null && !expiresTimeString.trim().equals("") ) {                try{                    configuration.expiresTime=		     Integer.valueOf(expiresTimeString.trim()).intValue();                    configurationMessage                    ("INFORMATION: expires time is set to:"			+configuration.expiresTime);                }                catch(Exception e) {                     configurationMessage		("WARNING: expires time is set to default value:"				+configuration.expiresTime);                }            }            else {                configurationMessage		("WARNING: expires time is set to default value:"				+configuration.expiresTime);            }                            String enableRegistrationsString=attrs.getValue("enable");            if (enableRegistrationsString==null) {                configuration.enableRegistrations=false;		configurationMessage		("INFORMATION: registration uploading feature is disabled");            }            else {                try{                    Boolean b=Boolean.valueOf(enableRegistrationsString.trim());                    if ( b.booleanValue()) {                        configuration.enableRegistrations=true;                        configurationMessage                        ("INFORMATION: Uploading static registrations");                    }                    else {                        configuration.enableRegistrations=false;                        configurationMessage                        ("WARNING: No static registrations to upload" );                    }                    String registrationsFile=attrs.getValue                    ("registrations_file");                    if (registrationsFile==null) {                        configurationMessage                        ("WARNING: No registration file specified");                    }                    else {                        configurationMessage                        ("INFORMATION: registrations file is " + registrationsFile);                        configuration.registrationsFile=                        registrationsFile.trim();                    }                }                catch(Exception e) {                   configuration.enableRegistrations=false;		    configurationMessage		     ("ERROR: Error uploading static registrations [" + 				e.getMessage()  + "]" );                }            }        }                 }        public void endElement(String namespaceURI,    String sName, // simple name    String qName  // qualified name    )    throws SAXException    {        String element=qName;        if (element.compareToIgnoreCase("SIP_STACK") ==0 ) {                    }        if (element.compareToIgnoreCase("LISTENING_POINT") ==0 ) {                   }        if (element.compareToIgnoreCase("RMI") ==0 ) {                 }        if (element.compareToIgnoreCase("DEBUG") ==0 ) {                    }        if (element.compareToIgnoreCase("PRESENCE_SERVER") ==0 ) {                    }        if (element.compareToIgnoreCase("AUTHENTICATION") ==0 ) {                    }        if (element.compareToIgnoreCase("REGISTRATIONS") ==0 ) {                    }        if (element.compareToIgnoreCase("EXTENSION_HANDLERS") ==0 ) {                    }           }        public void characters(char buf[], int offset, int len)    throws SAXException    {        String str = new String(buf, offset, len);    }        public static String createTags(Configuration configuration) {	String res="<?xml version='1.0' encoding='us-ascii'?>\n"+ 		   "<CONFIGURATION> \n"+    		   "	<SIP_STACK \n";	if (configuration.stackName!=null)   		res+="stack_name=\""+configuration.stackName+"\"\n";	if (configuration.stackIPAddress!=null)   		res+="stack_IP_address=\""+configuration.stackIPAddress+"\"\n";	if (configuration.outboundProxy!=null)   		res+="outbound_proxy=\""+configuration.outboundProxy+"\"\n";	if (configuration.routerPath!=null)   		res+="router_path=\""+configuration.routerPath+"\"\n";	if (configuration.extensionMethods!=null)   		res+="extension_methods=\""+configuration.extensionMethods+"\"\n";        if (configuration.retransmissionFilter!=null)   		res+="retransmission_filter=\""+configuration.retransmissionFilter+"\"\n";        if (configuration.stopTime!=null)   		res+="stop_after=\""+configuration.stopTime+"\"\n";        if (configuration.maxConnections!=null)   		res+="max_connections=\""+configuration.maxConnections+"\"\n";        if (configuration.maxServerTransactions!=null)   		res+="max_server_transactions=\""+configuration.maxServerTransactions+"\"\n";        if (configuration.threadPoolSize!=null)   		res+="thread_pool_size=\""+configuration.threadPoolSize+"\"\n";               	res+="    >       \n\n";	Enumeration e=configuration.listeningPoints.elements();	while (e!=null && e.hasMoreElements() ) {		Association a=(Association)e.nextElement();		String port=a.port;		String transport=a.transport;		if (port!=null && transport!=null) {                                		res+="<LISTENING_POINT port=\""+port+"\" transport=\""+transport+"\" />\n";                 }        }                 if (configuration.domainList!=null)        for (int j=0;j<configuration.domainList.size();j++) {            String domain=(String)configuration.domainList.elementAt(j);            res+="<DOMAIN domain=\""+domain+"\" />\n";         }                if (configuration.proxyToRegisterWithList!=null)        for (int j=0;j<configuration.proxyToRegisterWithList.size();j++) {            Domain domain=(Domain)configuration.proxyToRegisterWithList.elementAt(j);            if (domain.hostPort!=null)                res+="<REGISTER_TO_PROXY from="+domain.from+" hostName=\""+domain.hostName+"\" hostPort=\""+                domain.hostPort+"\" />\n";             else res+="<REGISTER_TO_PROXY from="+domain.from+" hostName=\""+domain.hostName+"\" />\n";         }            	res+="</SIP_STACK>\n\n";        	res+="<REGISTRAR\n";        res+="export_registrations=\""+configuration.exportRegistry+"\"\n";   	if (configuration.registryPort!=null)        	res+="port=\""+configuration.registryPort+"\"\n";    	res+="/>\n\n";    	res+="<LOGGING\n";	res+="access_log_via_rmi=\""+configuration.accessLogViaRMI+"\"\n";	        if (configuration.logRMIPort!=null)		res+="rmi_port=\""+configuration.logRMIPort+"\"\n";        if (configuration.logLifetime!=null)		res+="log_lifetime=\""+configuration.logLifetime+"\"\n";        res+="enable_debug=\""+configuration.enableDebug+"\"\n";       	if (configuration.outputProxy!=null)		res+="output_proxy=\""+configuration.outputProxy+"\"\n";	if (configuration.serverLogFile!=null)		res+="server_log=\""+configuration.serverLogFile+"\"\n";     	if (configuration.badMessageLogFile!=null)		res+="bad_message_log=\""+configuration.badMessageLogFile+"\"\n";        if (configuration.debugLogFile!=null)		res+="debug_log=\""+configuration.debugLogFile+"\"\n";    	res+="/>\n\n";        	res+="<PRESENCE_SERVER \n";        res+="enable=\""+configuration.enablePresenceServer+"\"\n";    	res+="/>\n\n";            	res+="<AUTHENTICATION\n";        res+="enable=\""+configuration.enableAuthentication+"\"\n";	if (configuration.method!=null)        	res+="method=\""+configuration.method+"\"\n";	if (configuration.classFile!=null)        	res+="class_file=\""+configuration.classFile+"\"\n";	if (configuration.passwordsFile!=null)        	res+="passwords_file=\""+configuration.passwordsFile+"\"\n";    	res+="/>\n\n";        	res+="<REGISTRATIONS \n";        res+="enable=\""+configuration.enableRegistrations+"\"\n";        res+="expires_time=\""+configuration.expiresTime+"\"\n";	if (configuration.registrationsFile!=null)        	res+="registrations_file=\""+configuration.registrationsFile+"\"\n";        res+="/>\n\n";	    	    	res+="</CONFIGURATION> \n\n";                 return res;    }          /** Utility method for writing in a file       * @param outFile: file to write       * @param text String to set       */    public static void writeFile(String outFile, String text) {        try {                        File file=new File(outFile);                        if (file.exists()) {                FileWriter fileWriter = new FileWriter(outFile,false);                PrintWriter pw = new PrintWriter(fileWriter,true);                                pw.write(text);                                pw.close();                fileWriter.close();            }            else ProxyDebug.println("ProxyDebug, writeFile(),  unable to write, the file:"+                    outFile +" is missing.");        }        catch (Exception e) {            ProxyDebug.println("ProxyDebug, writeFile(),  unable to write, the file:"+                    outFile +" is missing.");            e.printStackTrace();        }    }        }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?