📄 gatewayutilities.java
字号:
package gov.nist.examples.busy.gateway;import java.util.*;import javax.sip.*;import javax.sip.message.*; import javax.sip.header.*;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;/** Utilities for the Gateway.**@version JAIN-SIP-1.1**@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 GatewayUtilities { protected Gateway gateway; public static final String BRANCH_MAGIC_COOKIE = "z9hG4bK"; protected GatewayUtilities(Gateway gateway) { this.gateway=gateway; } /** 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(); } 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 void printTransaction(Transaction transaction) { if (transaction==null) { GatewayDebug.println ("DEBUG TRANSACTION INFO: the transaction is null "); return; } if ( transaction instanceof ServerTransaction) { ServerTransaction serverTransaction=(ServerTransaction)transaction; GatewayDebug.println ("DEBUG TRANSACTION INFO: here is the "+ " server transaction: "+serverTransaction); GatewayDebug.println ("DEBUG INFO: Its dialog is: "+serverTransaction.getDialog()); } else if ( transaction instanceof ClientTransaction) { ClientTransaction clientTransaction=(ClientTransaction)transaction; GatewayDebug.println ("DEBUG TRANSACTION INFO: here is the "+ " client transaction: "+clientTransaction); GatewayDebug.println ("DEBUG TRANSACTION INFO: Its dialog is: "+clientTransaction.getDialog()); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -