⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proxyutilities.java

📁 The source code for this package is located in src/gov/nist/sip/proxy. The proxy is a pure JAIN-SIP
💻 JAVA
字号:
package gov.nist.sip.proxy;import java.util.*;import javax.sip.*;import javax.sip.message.*;import javax.sip.header.*;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import javax.sip.address.*;import org.apache.log4j.Logger;/** * Utilities for the proxy. *  * @version JAIN-SIP-1.2 *  * @author Olvier Deruelle <deruelle@nist.gov> <br/> * @author M. Ranganathan <mranga@nist.gov> <br/> <a href="{@docRoot}/uncopyright.html">This *         code is in the public domain.</a> *  */public class ProxyUtilities {	private static Logger logger = Logger.getLogger(ProxyUtilities.class);	protected Proxy proxy;	public static final String BRANCH_MAGIC_COOKIE = "z9hG4bK";	protected ProxyUtilities(Proxy proxy) {		this.proxy = proxy;	}	/**	 * Generate a cryptographically random identifier that can be used to	 * generate a branch identifier.	 * 	 * @return a cryptographically random gloablly unique string that can be	 *         used as a branch identifier.	 */	public static String generateBranchId() {		String b = new Integer((int) (Math.random() * 10000)).toString()				+ System.currentTimeMillis();		try {			MessageDigest messageDigest = MessageDigest.getInstance("MD5");			byte bid[] = messageDigest.digest(b.getBytes());			// cryptographically random string.			// prepend with a magic cookie to indicate we			// are bis09 compatible.			return BRANCH_MAGIC_COOKIE + toHexString(bid);		} catch (NoSuchAlgorithmException ex) {			return null;		}	}	/**	 * to hex converter	 */	private static final char[] toHex = { '0', '1', '2', '3', '4', '5', '6',			'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };	/**	 * convert an array of bytes to an hexadecimal string	 * 	 * @return a string	 * @param b	 *            bytes array to convert to a hexadecimal string	 */	public static String toHexString(byte b[]) {		int pos = 0;		char[] c = new char[b.length * 2];		for (int i = 0; i < b.length; i++) {			c[pos++] = toHex[(b[i] >> 4) & 0x0F];			c[pos++] = toHex[b[i] & 0x0f];		}		return new String(c);	}	public static String generateTag() {		return new Integer((int) (Math.random() * 10000)).toString();	}	protected boolean matchProxyAddress(Request request) throws Exception {		javax.sip.address.URI uri = request.getRequestURI();		SipStack sipStack = proxy.getSipStack();		if (uri == null)			return false;		else {			SipURI sipURI = ((SipURI) uri);			String stackIPAddress = sipStack.getIPAddress();			String host = sipURI.getHost();			return stackIPAddress.equals(host);		}	}	public static int length(Message message) {		int cpt = 0;		try {			ListIterator l = message.getHeaders(ViaHeader.NAME);			while (l.hasNext()) {				l.next();				cpt++;			}			return cpt;		} catch (Exception e) {			return cpt;		}	}	public static boolean hasTopViaHeaderProxy(SipStack sipStack,			Message message) {		ListIterator viaList = message.getHeaders(ViaHeader.NAME);		if (viaList == null || length(message) == 0)			return false;		String stackIPAddress = sipStack.getIPAddress();		ViaHeader viaHeader = (ViaHeader) viaList.next();		if (viaHeader.getHost().equals(stackIPAddress)) {			Iterator lps = sipStack.getListeningPoints();			while (lps != null && lps.hasNext()) {				ListeningPoint lp = (ListeningPoint) lps.next();				int port = lp.getPort();				if (viaHeader.getPort() == port)					return true;			}		}		return false;	}	public static void printTransaction(Transaction transaction) {		if (transaction == null) {			logger.debug("DEBUG TRANSACTION INFO: the transaction is null ");			return;		}		if (transaction instanceof ServerTransaction) {			ServerTransaction serverTransaction = (ServerTransaction) transaction;			logger.debug("DEBUG TRANSACTION INFO: here is the "					+ " server transaction: " + serverTransaction);			logger.debug("DEBUG INFO: Its dialog is: "					+ serverTransaction.getDialog());		} else if (transaction instanceof ClientTransaction) {			ClientTransaction clientTransaction = (ClientTransaction) transaction;			logger.debug("DEBUG TRANSACTION INFO: here is the "					+ " client transaction: " + clientTransaction);			logger.debug("DEBUG TRANSACTION INFO: Its dialog is: "					+ clientTransaction.getDialog());		}	}}

⌨️ 快捷键说明

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