idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
37,400 | private static RtcpReceiverReport buildReceiverReport ( RtpStatistics statistics , boolean padding ) { RtcpReceiverReport report = new RtcpReceiverReport ( padding , statistics . getSsrc ( ) ) ; long ssrc = statistics . getSsrc ( ) ; List < Long > members = statistics . getMembersList ( ) ; for ( Long memberSsrc : members ) { if ( ssrc != memberSsrc ) { RtpMember memberStats = statistics . getMember ( memberSsrc . longValue ( ) ) ; RtcpReportBlock rcvrReport = buildSubReceiverReport ( memberStats ) ; report . addReceiverReport ( rcvrReport ) ; } } return report ; } | Builds a packet containing an RTCP Receiver Report |
37,401 | public static RtcpPacket buildReport ( RtpStatistics statistics ) { boolean padding = false ; RtcpReport report ; if ( statistics . hasSent ( ) ) { report = buildSenderReport ( statistics , padding ) ; } else { report = buildReceiverReport ( statistics , padding ) ; } RtcpSdes sdes = buildSdes ( statistics , padding ) ; return new RtcpPacket ( report , sdes ) ; } | Builds a packet containing an RTCP Report . |
37,402 | public static RtcpPacket buildBye ( RtpStatistics statistics ) { boolean padding = false ; RtcpReport report ; if ( statistics . hasSent ( ) ) { report = buildSenderReport ( statistics , padding ) ; } else { report = buildReceiverReport ( statistics , padding ) ; } RtcpSdes sdes = buildSdes ( statistics , padding ) ; RtcpBye bye = new RtcpBye ( padding ) ; bye . addSsrc ( statistics . getSsrc ( ) ) ; return new RtcpPacket ( report , sdes , bye ) ; } | Builds a packet containing an RTCP BYE message . |
37,403 | public void addLocalCandidates ( List < LocalCandidateWrapper > candidatesWrapper ) { for ( LocalCandidateWrapper candidateWrapper : candidatesWrapper ) { addLocalCandidate ( candidateWrapper , false ) ; } sortCandidates ( ) ; } | Registers a collection of local candidates to the component . |
37,404 | private void addLocalCandidate ( LocalCandidateWrapper candidateWrapper , boolean sort ) { IceCandidate candidate = candidateWrapper . getCandidate ( ) ; candidate . setPriority ( calculatePriority ( candidate ) ) ; synchronized ( this . localCandidates ) { if ( ! this . localCandidates . contains ( candidateWrapper ) ) { this . localCandidates . add ( candidateWrapper ) ; sortCandidates ( ) ; } } } | Attempts to registers a local candidate . |
37,405 | private Enumeration < NetworkInterface > getNetworkInterfaces ( ) throws HarvestException { try { return NetworkInterface . getNetworkInterfaces ( ) ; } catch ( SocketException e ) { throw new HarvestException ( "Could not retrieve list of available Network Interfaces." , e ) ; } } | Finds all Network interfaces available on this server . |
37,406 | private boolean useNetworkInterface ( NetworkInterface networkInterface ) throws HarvestException { try { return ! networkInterface . isLoopback ( ) && networkInterface . isUp ( ) ; } catch ( SocketException e ) { throw new HarvestException ( "Could not evaluate whether network interface is loopback." , e ) ; } } | Decides whether a certain network interface can be used as a host candidate . |
37,407 | private List < InetAddress > findAddresses ( ) throws HarvestException { List < InetAddress > found = new ArrayList < InetAddress > ( 3 ) ; Enumeration < NetworkInterface > interfaces = getNetworkInterfaces ( ) ; while ( interfaces . hasMoreElements ( ) ) { NetworkInterface iface = interfaces . nextElement ( ) ; if ( ! useNetworkInterface ( iface ) ) { continue ; } Enumeration < InetAddress > addresses = iface . getInetAddresses ( ) ; while ( addresses . hasMoreElements ( ) ) { InetAddress address = addresses . nextElement ( ) ; if ( address . isLoopbackAddress ( ) ) { continue ; } if ( address instanceof Inet4Address ) { found . add ( address ) ; } } } return found ; } | Finds available addresses that will be used to gather candidates from . |
37,408 | private DatagramChannel openUdpChannel ( InetAddress localAddress , int port , Selector selector ) throws IOException { DatagramChannel channel = DatagramChannel . open ( ) ; channel . configureBlocking ( false ) ; channel . register ( selector , SelectionKey . OP_READ | SelectionKey . OP_WRITE ) ; channel . bind ( new InetSocketAddress ( localAddress , port ) ) ; return channel ; } | Opens a datagram channel and binds it to an address . |
37,409 | private boolean gatherCandidate ( IceComponent component , InetAddress address , int startingPort , RtpPortManager portManager , Selector selector ) { if ( startingPort == portManager . peek ( ) ) { return false ; } try { int port = portManager . current ( ) ; DatagramChannel channel = openUdpChannel ( address , port , selector ) ; HostCandidate candidate = new HostCandidate ( component , address , port ) ; this . foundations . assignFoundation ( candidate ) ; component . addLocalCandidate ( new LocalCandidateWrapper ( candidate , channel ) ) ; return true ; } catch ( IOException e ) { portManager . next ( ) ; return gatherCandidate ( component , address , startingPort , portManager , selector ) ; } } | Gathers a candidate and registers it in the respective ICE Component . A datagram channel will be bound to the local candidate address . |
37,410 | public byte [ ] process ( byte [ ] media ) { frame ++ ; float [ ] new_speech = new float [ media . length ] ; short [ ] shortMedia = Util . byteArrayToShortArray ( media ) ; for ( int i = 0 ; i < LD8KConstants . L_FRAME ; i ++ ) { new_speech [ i ] = ( float ) shortMedia [ i ] ; } preProc . pre_process ( new_speech , LD8KConstants . L_FRAME ) ; encoder . loadSpeech ( new_speech ) ; encoder . coder_ld8k ( prm , 0 ) ; Bits . prm2bits_ld8k ( prm , serial ) ; return Bits . toRealBits ( serial ) ; } | Perform compression . |
37,411 | public void exclude ( String formatName ) { for ( int i = 0 ; i < count ; i ++ ) { md [ i ] . exclude ( formatName ) ; } } | Excludes specified formats from descriptor . |
37,412 | public boolean contains ( String encoding ) { if ( encoding . equalsIgnoreCase ( "sendrecv" ) || encoding . equalsIgnoreCase ( "fmtp" ) || encoding . equalsIgnoreCase ( "audio" ) || encoding . equalsIgnoreCase ( "AS" ) || encoding . equalsIgnoreCase ( "IP4" ) ) { return true ; } for ( int i = 0 ; i < count ; i ++ ) { if ( md [ i ] . contains ( encoding ) ) { return true ; } } return false ; } | Checks that specified format is described by this sdp . |
37,413 | private void cancelSignals ( ) { Iterator < String > keys = this . signals . keySet ( ) . iterator ( ) ; while ( keys . hasNext ( ) ) { cancelSignal ( keys . next ( ) ) ; } } | Cancels any ongoing signal . |
37,414 | public static boolean isInRangeV4 ( byte [ ] network , byte [ ] subnet , byte [ ] ipAddress ) { if ( network . length != 4 || subnet . length != 4 || ipAddress . length != 4 ) return false ; return compareByteValues ( network , subnet , ipAddress ) ; } | Checks whether ipAddress is in IPV4 network with specified subnet |
37,415 | public static boolean isInRangeV6 ( byte [ ] network , byte [ ] subnet , byte [ ] ipAddress ) { if ( network . length != 16 || subnet . length != 16 || ipAddress . length != 16 ) return false ; return compareByteValues ( network , subnet , ipAddress ) ; } | Checks whether ipAddress is in IPV6 network with specified subnet |
37,416 | private static boolean compareByteValues ( byte [ ] network , byte [ ] subnet , byte [ ] ipAddress ) { for ( int i = 0 ; i < network . length ; i ++ ) if ( ( network [ i ] & subnet [ i ] ) != ( ipAddress [ i ] & subnet [ i ] ) ) return false ; return true ; } | Checks whether ipAddress is in network with specified subnet by comparing byte logical end values |
37,417 | public static IPAddressType getAddressType ( String ipAddress ) { if ( IPAddressUtil . isIPv4LiteralAddress ( ipAddress ) ) return IPAddressType . IPV4 ; if ( IPAddressUtil . isIPv6LiteralAddress ( ipAddress ) ) return IPAddressType . IPV6 ; return IPAddressType . INVALID ; } | Gets IP address type |
37,418 | public void start ( ) { synchronized ( LOCK ) { if ( ! this . active ) { this . active = true ; logger . info ( "Starting UDP Manager" ) ; try { generateTasks ( ) ; logger . info ( "Initialized UDP interface[" + inet + "]: bind address=" + bindAddress ) ; } catch ( IOException e ) { logger . error ( "An error occurred while initializing the polling tasks" , e ) ; stop ( ) ; } } } } | Starts polling the network . |
37,419 | public void stop ( ) { synchronized ( LOCK ) { if ( this . active ) { this . active = false ; logger . info ( "Stopping UDP Manager" ) ; stopTasks ( ) ; closeSelectors ( ) ; cleanResources ( ) ; logger . info ( "UDP Manager has stopped" ) ; } } } | Stops polling the network . |
37,420 | public IceMediaStream getMediaStream ( String streamName ) { IceMediaStream mediaStream ; synchronized ( mediaStreams ) { mediaStream = this . mediaStreams . get ( streamName ) ; } return mediaStream ; } | Gets a media stream by name |
37,421 | public void harvest ( RtpPortManager portManager ) throws HarvestException , NoCandidatesGatheredException { if ( this . selector == null || ! this . selector . isOpen ( ) ) { try { this . selector = Selector . open ( ) ; } catch ( IOException e ) { throw new HarvestException ( "Could not initialize selector" , e ) ; } } for ( IceMediaStream mediaStream : getMediaStreams ( ) ) { this . harvestManager . harvest ( mediaStream , portManager , this . selector ) ; } } | Gathers all available candidates and sets the components of each media stream . |
37,422 | private void fireCandidatePairSelectedEvent ( ) { this . stop ( ) ; List < IceEventListener > listeners ; synchronized ( this . iceListeners ) { listeners = new ArrayList < IceEventListener > ( this . iceListeners ) ; } SelectedCandidatesEvent event = new SelectedCandidatesEvent ( this ) ; for ( IceEventListener listener : listeners ) { listener . onSelectedCandidates ( event ) ; } } | Fires an event when all candidate pairs are selected . |
37,423 | public void getPayload ( byte [ ] buff , int offset ) { buffer . position ( FIXED_HEADER_SIZE ) ; buffer . get ( buff , offset , buffer . limit ( ) - FIXED_HEADER_SIZE ) ; } | Reads the data transported by RTP in a packet for example audio samples or compressed video data . |
37,424 | public void wrap ( boolean mark , int payloadType , int seqNumber , long timestamp , long ssrc , byte [ ] data , int offset , int len ) { buffer . clear ( ) ; buffer . rewind ( ) ; buffer . put ( ( byte ) 0x80 ) ; byte b = ( byte ) ( payloadType ) ; if ( mark ) { b = ( byte ) ( b | 0x80 ) ; } buffer . put ( b ) ; buffer . put ( ( byte ) ( ( seqNumber & 0xFF00 ) >> 8 ) ) ; buffer . put ( ( byte ) ( seqNumber & 0x00FF ) ) ; buffer . put ( ( byte ) ( ( timestamp & 0xFF000000 ) >> 24 ) ) ; buffer . put ( ( byte ) ( ( timestamp & 0x00FF0000 ) >> 16 ) ) ; buffer . put ( ( byte ) ( ( timestamp & 0x0000FF00 ) >> 8 ) ) ; buffer . put ( ( byte ) ( ( timestamp & 0x000000FF ) ) ) ; buffer . put ( ( byte ) ( ( ssrc & 0xFF000000 ) >> 24 ) ) ; buffer . put ( ( byte ) ( ( ssrc & 0x00FF0000 ) >> 16 ) ) ; buffer . put ( ( byte ) ( ( ssrc & 0x0000FF00 ) >> 8 ) ) ; buffer . put ( ( byte ) ( ( ssrc & 0x000000FF ) ) ) ; buffer . put ( data , offset , len ) ; buffer . flip ( ) ; buffer . rewind ( ) ; } | Encapsulates data into the packet for transmission via RTP . |
37,425 | public int getExtensionLength ( ) { if ( ! getExtensionBit ( ) ) return 0 ; int extLenIndex = FIXED_HEADER_SIZE + getCsrcCount ( ) * 4 + 2 ; return ( ( buffer . get ( extLenIndex ) << 8 ) | buffer . get ( extLenIndex + 1 ) * 4 ) ; } | Returns the length of the extensions currently added to this packet . |
37,426 | public void grow ( int delta ) { if ( delta == 0 ) { return ; } int newLen = buffer . limit ( ) + delta ; if ( newLen <= buffer . capacity ( ) ) { buffer . limit ( newLen ) ; return ; } else { ByteBuffer newBuffer = buffer . isDirect ( ) ? ByteBuffer . allocateDirect ( newLen ) : ByteBuffer . allocate ( newLen ) ; buffer . rewind ( ) ; newBuffer . put ( buffer ) ; newBuffer . limit ( newLen ) ; buffer = newBuffer ; } } | Grow the internal packet buffer . |
37,427 | public MgcpEndpoint registerEndpoint ( String namespace ) throws UnrecognizedMgcpNamespaceException { MgcpEndpointProvider < ? > provider = this . providers . get ( namespace ) ; if ( provider == null ) { throw new UnrecognizedMgcpNamespaceException ( "Namespace " + namespace + " is unrecognized" ) ; } MgcpEndpoint endpoint = provider . provide ( ) ; endpoint . observe ( ( MgcpEndpointObserver ) this ) ; endpoint . observe ( ( MgcpMessageObserver ) this ) ; this . endpoints . put ( endpoint . getEndpointId ( ) . toString ( ) , endpoint ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Registered endpoint " + endpoint . getEndpointId ( ) . toString ( ) + ". Count: " + this . endpoints . size ( ) ) ; } return endpoint ; } | Registers a new endpoint . |
37,428 | public void unregisterEndpoint ( String endpointId ) throws MgcpEndpointNotFoundException { MgcpEndpoint endpoint = this . endpoints . remove ( endpointId ) ; if ( endpoint == null ) { throw new MgcpEndpointNotFoundException ( "Endpoint " + endpointId + " not found" ) ; } endpoint . forget ( ( MgcpMessageObserver ) this ) ; endpoint . forget ( ( MgcpEndpointObserver ) this ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Unregistered endpoint " + endpoint . getEndpointId ( ) . toString ( ) + ". Count: " + this . endpoints . size ( ) ) ; } } | Unregisters an active endpoint . |
37,429 | public void offer ( Event event ) { sequence += event . toString ( ) ; if ( patterns != null && sequence . length ( ) > 0 ) { for ( int i = 0 ; i < patterns . length ; i ++ ) { if ( sequence . matches ( patterns [ i ] ) ) { listener . patternMatches ( i , sequence ) ; sequence = "" ; return ; } } } if ( count > 0 && sequence . length ( ) == count ) { listener . countMatches ( sequence ) ; sequence = "" ; count = - 1 ; } } | Queues next event to the buffer . |
37,430 | private int getMax ( double data [ ] ) { int idx = 0 ; double max = data [ 0 ] ; for ( int i = 1 ; i < data . length ; i ++ ) { if ( max < data [ i ] ) { max = data [ i ] ; idx = i ; } } return idx ; } | Searches maximum value in the specified array . |
37,431 | private String getTone ( double f [ ] , double F [ ] ) { int fm = getMax ( f ) ; boolean fd = true ; for ( int i = 0 ; i < f . length ; i ++ ) { if ( fm == i ) { continue ; } double r = f [ fm ] / ( f [ i ] + 1E-15 ) ; if ( r < threshold ) { fd = false ; break ; } } if ( ! fd ) { return null ; } int Fm = getMax ( F ) ; boolean Fd = true ; for ( int i = 0 ; i < F . length ; i ++ ) { if ( Fm == i ) { continue ; } double r = F [ Fm ] / ( F [ i ] + 1E-15 ) ; if ( r < threshold ) { Fd = false ; break ; } } if ( ! Fd ) { return null ; } return events [ fm ] [ Fm ] ; } | Searches DTMF tone . |
37,432 | public void setMessageType ( char indicationType ) throws IllegalArgumentException { if ( ! isIndicationType ( indicationType ) && indicationType != StunMessage . OLD_DATA_INDICATION ) { throw new IllegalArgumentException ( ( int ) ( indicationType ) + " - is not a valid indication type." ) ; } super . setMessageType ( indicationType ) ; } | Checks whether indicationType is a valid indication type and if yes sets it as the type of this instance . |
37,433 | public void run ( ) { if ( this . isActive ) { try { perform ( ) ; if ( this . listener != null ) { this . listener . onTerminate ( ) ; } } catch ( Exception e ) { logger . error ( "Could not execute task " + this . taskId + ": " + e . getMessage ( ) , e ) ; if ( this . listener != null ) { listener . handlerError ( e ) ; } } } } | call should not be synchronized since can run only once in queue cycle |
37,434 | public byte [ ] encode ( ) { char type = getAttributeType ( ) ; byte binValue [ ] = new byte [ HEADER_LENGTH + getDataLength ( ) ] ; binValue [ 0 ] = ( byte ) ( type >> 8 ) ; binValue [ 1 ] = ( byte ) ( type & 0x00FF ) ; binValue [ 2 ] = ( byte ) ( getDataLength ( ) >> 8 ) ; binValue [ 3 ] = ( byte ) ( getDataLength ( ) & 0x00FF ) ; return binValue ; } | Returns a binary representation of this attribute . |
37,435 | public void push ( String symbol ) { long now = System . currentTimeMillis ( ) ; if ( ! symbol . equals ( lastSymbol ) || ( now - lastActivity > interdigitInterval ) ) { lastActivity = now ; lastSymbol = symbol ; detectorImpl . fireEvent ( symbol ) ; } else lastActivity = now ; } | Handles inter digit intervals . |
37,436 | protected void queue ( DtmfEventImpl evt ) { if ( queue . size ( ) == size ) { queue . poll ( ) ; } queue . offer ( evt ) ; logger . info ( String . format ( "(%s) Buffer size: %d" , detectorImpl . getName ( ) , queue . size ( ) ) ) ; } | Queues specified event . |
37,437 | public void flush ( ) { logger . info ( String . format ( "(%s) Flush, buffer size: %d" , detectorImpl . getName ( ) , queue . size ( ) ) ) ; while ( queue . size ( ) > 0 ) detectorImpl . fireEvent ( queue . poll ( ) ) ; } | Flushes the buffer content . |
37,438 | public Date getCreationTime ( ) { calendar . set ( Calendar . YEAR , 1904 ) ; calendar . set ( Calendar . MONTH , Calendar . JANUARY ) ; calendar . set ( Calendar . DATE , 1 ) ; calendar . set ( Calendar . HOUR_OF_DAY , 0 ) ; calendar . set ( Calendar . MINUTE , 0 ) ; calendar . set ( Calendar . SECOND , 0 ) ; calendar . roll ( Calendar . SECOND , ( int ) creationTime ) ; return calendar . getTime ( ) ; } | Gets the creation time of this presentation . |
37,439 | public String generateFingerprint ( String hashFunction ) { try { this . hashFunction = hashFunction ; org . bouncycastle . crypto . tls . Certificate chain = TlsUtils . loadCertificateChain ( certificateResources ) ; Certificate certificate = chain . getCertificateAt ( 0 ) ; return TlsUtils . fingerprint ( this . hashFunction , certificate ) ; } catch ( IOException e ) { LOGGER . error ( "Could not get local fingerprint: " + e . getMessage ( ) ) ; return "" ; } } | Gets the fingerprint of the Certificate associated to the server . |
37,440 | public void getCipherStream ( BlockCipher aesCipher , byte [ ] out , int length , byte [ ] iv ) { System . arraycopy ( iv , 0 , cipherInBlock , 0 , 14 ) ; int ctr ; for ( ctr = 0 ; ctr < length / BLKLEN ; ctr ++ ) { cipherInBlock [ 14 ] = ( byte ) ( ( ctr & 0xFF00 ) >> 8 ) ; cipherInBlock [ 15 ] = ( byte ) ( ( ctr & 0x00FF ) ) ; aesCipher . processBlock ( cipherInBlock , 0 , out , ctr * BLKLEN ) ; } cipherInBlock [ 14 ] = ( byte ) ( ( ctr & 0xFF00 ) >> 8 ) ; cipherInBlock [ 15 ] = ( byte ) ( ( ctr & 0x00FF ) ) ; aesCipher . processBlock ( cipherInBlock , 0 , tmpCipherBlock , 0 ) ; System . arraycopy ( tmpCipherBlock , 0 , out , ctr * BLKLEN , length % BLKLEN ) ; } | Computes the cipher stream for AES CM mode . See section 4 . 1 . 1 in RFC3711 for detailed description . |
37,441 | private void processComponents ( MAPDialogImpl mapDialogImpl , Component [ ] components ) { for ( Component c : components ) { doProcessComponent ( mapDialogImpl , c ) ; } } | private service methods |
37,442 | private void fireTCAbortACNNotSupported ( Dialog tcapDialog , MAPExtensionContainer mapExtensionContainer , ApplicationContextName alternativeApplicationContext , boolean returnMessageOnError ) throws MAPException { if ( this . getTCAPProvider ( ) . getPreviewMode ( ) ) { return ; } if ( tcapDialog . getApplicationContextName ( ) == null ) this . fireTCAbortV1 ( tcapDialog , returnMessageOnError ) ; TCUserAbortRequest tcUserAbort = this . getTCAPProvider ( ) . getDialogPrimitiveFactory ( ) . createUAbort ( tcapDialog ) ; MAPRefuseInfoImpl mapRefuseInfoImpl = new MAPRefuseInfoImpl ( ) ; mapRefuseInfoImpl . setReason ( Reason . noReasonGiven ) ; AsnOutputStream localasnOs = new AsnOutputStream ( ) ; mapRefuseInfoImpl . encodeAll ( localasnOs ) ; UserInformation userInformation = TcapFactory . createUserInformation ( ) ; userInformation . setOid ( true ) ; userInformation . setOidValue ( MAPDialogueAS . MAP_DialogueAS . getOID ( ) ) ; userInformation . setAsn ( true ) ; userInformation . setEncodeType ( localasnOs . toByteArray ( ) ) ; if ( returnMessageOnError ) tcUserAbort . setReturnMessageOnError ( true ) ; if ( alternativeApplicationContext != null ) tcUserAbort . setApplicationContextName ( alternativeApplicationContext ) ; else tcUserAbort . setApplicationContextName ( tcapDialog . getApplicationContextName ( ) ) ; tcUserAbort . setDialogServiceUserType ( DialogServiceUserType . AcnNotSupported ) ; tcUserAbort . setUserInformation ( userInformation ) ; try { tcapDialog . send ( tcUserAbort ) ; } catch ( TCAPSendException e ) { throw new MAPException ( e . getMessage ( ) , e ) ; } } | Issue TC - U - ABORT with the abort reason = application - content - name - not - supported |
37,443 | protected void fireTCAbortUser ( Dialog tcapDialog , MAPUserAbortChoice mapUserAbortChoice , MAPExtensionContainer mapExtensionContainer , boolean returnMessageOnError ) throws MAPException { if ( this . getTCAPProvider ( ) . getPreviewMode ( ) ) { return ; } if ( tcapDialog . getApplicationContextName ( ) == null ) this . fireTCAbortV1 ( tcapDialog , returnMessageOnError ) ; TCUserAbortRequest tcUserAbort = this . getTCAPProvider ( ) . getDialogPrimitiveFactory ( ) . createUAbort ( tcapDialog ) ; MAPUserAbortInfoImpl mapUserAbortInfoImpl = new MAPUserAbortInfoImpl ( ) ; mapUserAbortInfoImpl . setMAPUserAbortChoice ( mapUserAbortChoice ) ; mapUserAbortInfoImpl . setExtensionContainer ( mapExtensionContainer ) ; AsnOutputStream localasnOs = new AsnOutputStream ( ) ; mapUserAbortInfoImpl . encodeAll ( localasnOs ) ; UserInformation userInformation = TcapFactory . createUserInformation ( ) ; userInformation . setOid ( true ) ; userInformation . setOidValue ( MAPDialogueAS . MAP_DialogueAS . getOID ( ) ) ; userInformation . setAsn ( true ) ; userInformation . setEncodeType ( localasnOs . toByteArray ( ) ) ; if ( returnMessageOnError ) tcUserAbort . setReturnMessageOnError ( true ) ; tcUserAbort . setUserInformation ( userInformation ) ; try { tcapDialog . send ( tcUserAbort ) ; } catch ( TCAPSendException e ) { throw new MAPException ( e . getMessage ( ) , e ) ; } } | Issue TC - U - ABORT with the ABRT apdu with MAPUserAbortInfo userInformation |
37,444 | protected void fireTCAbortProvider ( Dialog tcapDialog , MAPProviderAbortReason mapProviderAbortReason , MAPExtensionContainer mapExtensionContainer , boolean returnMessageOnError ) throws MAPException { if ( this . getTCAPProvider ( ) . getPreviewMode ( ) ) { return ; } if ( tcapDialog . getApplicationContextName ( ) == null ) this . fireTCAbortV1 ( tcapDialog , returnMessageOnError ) ; TCUserAbortRequest tcUserAbort = this . getTCAPProvider ( ) . getDialogPrimitiveFactory ( ) . createUAbort ( tcapDialog ) ; MAPProviderAbortInfoImpl mapProviderAbortInfo = new MAPProviderAbortInfoImpl ( ) ; mapProviderAbortInfo . setMAPProviderAbortReason ( mapProviderAbortReason ) ; mapProviderAbortInfo . setExtensionContainer ( mapExtensionContainer ) ; AsnOutputStream localasnOs = new AsnOutputStream ( ) ; mapProviderAbortInfo . encodeAll ( localasnOs ) ; UserInformation userInformation = TcapFactory . createUserInformation ( ) ; userInformation . setOid ( true ) ; userInformation . setOidValue ( MAPDialogueAS . MAP_DialogueAS . getOID ( ) ) ; userInformation . setAsn ( true ) ; userInformation . setEncodeType ( localasnOs . toByteArray ( ) ) ; if ( returnMessageOnError ) tcUserAbort . setReturnMessageOnError ( true ) ; tcUserAbort . setUserInformation ( userInformation ) ; try { tcapDialog . send ( tcUserAbort ) ; } catch ( TCAPSendException e ) { throw new MAPException ( e . getMessage ( ) , e ) ; } } | Issue TC - U - ABORT with the ABRT apdu with MAPProviderAbortInfo userInformation |
37,445 | protected void fireTCAbortV1 ( Dialog tcapDialog , boolean returnMessageOnError ) throws MAPException { if ( this . getTCAPProvider ( ) . getPreviewMode ( ) ) { return ; } TCUserAbortRequest tcUserAbort = this . getTCAPProvider ( ) . getDialogPrimitiveFactory ( ) . createUAbort ( tcapDialog ) ; if ( returnMessageOnError ) tcUserAbort . setReturnMessageOnError ( true ) ; try { tcapDialog . send ( tcUserAbort ) ; } catch ( TCAPSendException e ) { throw new MAPException ( e . getMessage ( ) , e ) ; } } | Issue TC - U - ABORT without any apdu - for MAP V1 |
37,446 | protected void startInitialAlignment ( boolean resetTxOffset ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( String . format ( "(%s) Starting initial alignment" , name ) ) ; } if ( resetTxOffset ) { this . txFrame . offset = 3 ; } this . reset ( ) ; this . setState ( MTP2_NOT_ALIGNED ) ; start_T2 ( ) ; } | should not be used |
37,447 | private void processRx ( byte [ ] buff , int len ) { int i = 0 ; while ( i < len ) { while ( rxState . bits <= 24 && i < len ) { int b = buff [ i ++ ] & 0xff ; hdlc . fasthdlc_rx_load_nocheck ( rxState , b ) ; if ( rxState . state == 0 ) { nCount = ( nCount + 1 ) % 16 ; if ( nCount == 0 ) { countError ( "on receive" ) ; } } } int res = hdlc . fasthdlc_rx_run ( rxState ) ; switch ( res ) { case FastHDLC . RETURN_COMPLETE_FLAG : countFrame ( ) ; if ( rxFrame . len == 0 ) { } else if ( rxFrame . len < 5 ) { countError ( "hdlc error, frame LI<5" ) ; } else if ( rxCRC == 0xF0B8 ) { processFrame ( ) ; } else { countError ( "hdlc complete, wrong terms." ) ; } rxFrame . len = 0 ; rxCRC = 0xffff ; break ; case FastHDLC . RETURN_DISCARD_FLAG : rxCRC = 0xffff ; rxFrame . len = 0 ; countFrame ( ) ; countError ( "hdlc discard." ) ; break ; case FastHDLC . RETURN_EMPTY_FLAG : rxFrame . len = 0 ; break ; default : if ( rxFrame . len > 279 ) { rxState . state = 0 ; rxFrame . len = 0 ; rxCRC = 0xffff ; eCount = 0 ; countFrame ( ) ; countError ( "Overlong MTP frame, entering octet mode on link '" + name + "'" ) ; } else { rxFrame . frame [ rxFrame . len ++ ] = ( byte ) res ; rxCRC = PPP_FCS ( rxCRC , res & 0xff ) ; } } } } | Handles received data . |
37,448 | private void countFrame ( ) { if ( state == MTP2_ALIGNED_READY || state == MTP2_INSERVICE ) { dCount = ( dCount + 1 ) % 256 ; if ( dCount == 0 && eCount > 0 ) { eCount -- ; } } } | Increment number of received frames decrement error monitor countor for each 256 good frames . |
37,449 | public static void main ( String [ ] args ) throws Throwable { String homeDir = getHomeDir ( args ) ; System . setProperty ( TRACE_PARSER_HOME , homeDir ) ; String dataDir = homeDir + File . separator + "data" + File . separator ; System . setProperty ( TRACE_PARSER_DATA , dataDir ) ; if ( ! initLOG4JProperties ( homeDir ) && ! initLOG4JXml ( homeDir ) ) { logger . error ( "Failed to initialize loggin, no configuration. Defaults are used." ) ; } logger . info ( "log4j configured" ) ; Ss7ParseParameters par = null ; String persistDir = homeDir + File . separator + "data" ; try { BufferedInputStream bis = new BufferedInputStream ( new FileInputStream ( persistDir + File . separator + "Ss7ParseParameters.xml" ) ) ; XMLDecoder d = new XMLDecoder ( bis ) ; par = ( Ss7ParseParameters ) d . readObject ( ) ; d . close ( ) ; } catch ( Exception e ) { } Main main = new Main ( ) ; main . boot ( persistDir , par ) ; } | private int httpPort = - 1 ; |
37,450 | protected void encode ( ByteBuffer txBuffer ) { txBuffer . position ( 4 ) ; txBuffer . put ( data ) ; int length = txBuffer . position ( ) ; txBuffer . rewind ( ) ; txBuffer . putInt ( length ) ; txBuffer . position ( length ) ; } | Encodes this message . The protocol is first 4 bytes are length of this command followed by the byte stream of command |
37,451 | public void initializeMessageNumbering ( SccpConnDt2MessageImpl msg ) { sendSequenceNumber = getNextSequenceNumber ( ) ; msg . setSequencing ( sendSequenceNumber , sendSequenceNumberExpectedAtInput ) ; inputWindow . setLowerEdge ( sendSequenceNumberExpectedAtInput ) ; } | IT DT2 AK |
37,452 | public boolean checkInputMessageNumbering ( SccpConnectionImpl conn , SequenceNumber sendSequenceNumber , SequenceNumber receiveSequenceNumber ) throws Exception { if ( sendSequenceNumber != null ) { if ( expectingFirstMessageInputAfterInit && ! sendSequenceNumber . equals ( new SequenceNumberImpl ( 0 ) ) ) { conn . reset ( new ResetCauseImpl ( ResetCauseValue . MESSAGE_OUT_OF_ORDER_INCORRECT_PS ) ) ; return false ; } else if ( sendSequenceNumber . equals ( sendSequenceNumberExpectedAtInput ) && inputWindow . contains ( sendSequenceNumber ) ) { sendSequenceNumberExpectedAtInput = sendSequenceNumberExpectedAtInput . nextNumber ( ) ; } else { if ( ! inputWindow . contains ( sendSequenceNumber ) ) { conn . reset ( new ResetCauseImpl ( ResetCauseValue . REMOTE_PROCEDURE_ERROR_MESSAGE_OUT_OF_WINDOW ) ) ; } else if ( ! sendSequenceNumber . equals ( sendSequenceNumberExpectedAtInput ) ) { conn . resetSection ( new ResetCauseImpl ( ResetCauseValue . MESSAGE_OUT_OF_ORDER_INCORRECT_PS ) ) ; } return false ; } } if ( rangeContains ( lastReceiveSequenceNumberReceived , this . sendSequenceNumber . nextNumber ( ) , receiveSequenceNumber ) ) { outputWindow . setLowerEdge ( receiveSequenceNumber ) ; } else { conn . resetSection ( new ResetCauseImpl ( ResetCauseValue . MESSAGE_OUT_OF_ORDER_INCORRECT_PS ) ) ; return false ; } lastReceiveSequenceNumberReceived = receiveSequenceNumber ; expectingFirstMessageInputAfterInit = false ; return true ; } | if true then message can be accepted |
37,453 | public void reinitialize ( ) { inputWindow = new SccpFlowControlWindow ( new SequenceNumberImpl ( 0 ) , maximumWindowSize ) ; outputWindow = new SccpFlowControlWindow ( new SequenceNumberImpl ( 0 ) , maximumWindowSize ) ; sendSequenceNumberExpectedAtInput = new SequenceNumberImpl ( 0 ) ; lastReceiveSequenceNumberReceived = new SequenceNumberImpl ( 0 ) ; sendSequenceNumber = new SequenceNumberImpl ( 0 , false , true ) ; expectingFirstMessageInputAfterInit = true ; } | after connection establishing and on connection reset |
37,454 | private void rebind ( Object stack ) throws NamingException { if ( jndiName != null ) { Context ctx = new InitialContext ( ) ; String [ ] tokens = jndiName . split ( "/" ) ; for ( int i = 0 ; i < tokens . length - 1 ; i ++ ) { if ( tokens [ i ] . trim ( ) . length ( ) > 0 ) { try { ctx = ( Context ) ctx . lookup ( tokens [ i ] ) ; } catch ( NamingException e ) { ctx = ctx . createSubcontext ( tokens [ i ] ) ; } } } ctx . bind ( tokens [ tokens . length - 1 ] , stack ) ; } } | Binds trunk object to the JNDI under the jndiName . |
37,455 | private void unbind ( String jndiName ) throws NamingException { InitialContext initialContext = new InitialContext ( ) ; initialContext . unbind ( jndiName ) ; } | Unbounds object under specified name . |
37,456 | public void handleHeartbeat ( Heartbeat hrtBeat ) { HeartbeatAck hrtBeatAck = ( HeartbeatAck ) this . aspFactoryImpl . messageFactory . createMessage ( MessageClass . ASP_STATE_MAINTENANCE , MessageType . HEARTBEAT_ACK ) ; hrtBeatAck . setHeartbeatData ( hrtBeat . getHeartbeatData ( ) ) ; this . aspFactoryImpl . write ( hrtBeatAck ) ; } | If we receive Heartbeat we send back response |
37,457 | protected void reset ( ) { for ( RouteMap . Entry < String , RouteAsImpl > e = this . route . head ( ) , end = this . route . tail ( ) ; ( e = e . getNext ( ) ) != end ; ) { String key = e . getKey ( ) ; RouteAsImpl routeAs = e . getValue ( ) ; routeAs . setM3uaManagement ( this . m3uaManagement ) ; routeAs . reset ( ) ; As [ ] asList = routeAs . getAsArray ( ) ; try { String [ ] keys = key . split ( KEY_SEPARATOR ) ; int dpc = Integer . parseInt ( keys [ 0 ] ) ; for ( count = 0 ; count < asList . length ; count ++ ) { AsImpl asImpl = ( AsImpl ) asList [ count ] ; if ( asImpl != null ) { this . addAsToDPC ( dpc , asImpl ) ; } } } catch ( Exception ex ) { logger . error ( String . format ( "Error while adding key=%s to As list=%s" , key , Arrays . toString ( asList ) ) ) ; } } } | Reset the routeTable . Called after the persistance state of route is read from xml file . |
37,458 | public Message createMessage ( ByteBuffer buffer ) { if ( ! isHeaderReady ) { int len = Math . min ( MESSAGE_HEADER_SIZE - pos , buffer . remaining ( ) ) ; buffer . get ( header , pos , len ) ; pos += len ; isHeaderReady = pos == header . length ; if ( ! isHeaderReady ) { return null ; } length = ( ( header [ 0 ] & 0xff ) << 24 ) ; length += ( ( header [ 1 ] & 0xff ) << 16 ) ; length += ( ( header [ 2 ] & 0xff ) << 8 ) ; length += ( header [ 3 ] & 0xff ) ; length -= MESSAGE_HEADER_SIZE ; params = new byte [ length ] ; pos = 0 ; message = new Message ( ) ; } if ( length > 0 && ! buffer . hasRemaining ( ) ) { return null ; } int len = Math . min ( ( params . length - pos ) , buffer . remaining ( ) ) ; buffer . get ( params , pos , len ) ; pos += len ; if ( pos < params . length ) { return null ; } message . decode ( params ) ; this . isHeaderReady = false ; this . pos = 0 ; return message ; } | The received buffer may not have necessary bytes to decode a message . Instance of this factory keeps data locally till next set of data is received and a message can be successfully decoded |
37,459 | protected void encodeMandatoryVariableParameters ( Map < Integer , ISUPParameter > parameters , ByteArrayOutputStream bos , boolean isOptionalPartPresent ) throws ParameterException { try { byte [ ] pointers = null ; if ( ! mandatoryVariablePartPossible ( ) ) { if ( optionalPartIsPossible ( ) ) { if ( isOptionalPartPresent ) { pointers = new byte [ ] { 0x01 } ; } else { pointers = new byte [ ] { 0x00 } ; } bos . write ( pointers ) ; } else { } } else { if ( optionalPartIsPossible ( ) ) { pointers = new byte [ parameters . size ( ) + 1 ] ; } else { pointers = new byte [ parameters . size ( ) ] ; } ByteArrayOutputStream parametersBodyBOS = new ByteArrayOutputStream ( ) ; byte lastParameterLength = 0 ; byte currentParameterLength = 0 ; for ( int index = 0 ; index < parameters . size ( ) ; index ++ ) { AbstractISUPParameter p = ( AbstractISUPParameter ) parameters . get ( index ) ; byte [ ] body = p . encode ( ) ; currentParameterLength = ( byte ) body . length ; if ( body . length > 255 ) { throw new ParameterException ( "Length of body must not be greater than one octet - 255 " ) ; } if ( index == 0 ) { lastParameterLength = currentParameterLength ; pointers [ index ] = ( byte ) ( parameters . size ( ) + ( optionalPartIsPossible ( ) ? 1 : 0 ) ) ; } else { pointers [ index ] = ( byte ) ( pointers [ index - 1 ] + lastParameterLength ) ; lastParameterLength = currentParameterLength ; } parametersBodyBOS . write ( currentParameterLength ) ; parametersBodyBOS . write ( body ) ; } if ( optionalPartIsPossible ( ) ) { if ( isOptionalPartPresent ) { pointers [ pointers . length - 1 ] = ( byte ) ( pointers [ pointers . length - 2 ] + lastParameterLength ) ; } else { } } else { } bos . write ( pointers ) ; bos . write ( parametersBodyBOS . toByteArray ( ) ) ; } } catch ( ParameterException pe ) { throw pe ; } catch ( Exception e ) { throw new ParameterException ( e ) ; } } | takes care of endoding parameters - poniters and actual parameters . |
37,460 | protected int decodeMandatoryParameters ( ISUPParameterFactory parameterFactory , byte [ ] b , int index ) throws ParameterException { int localIndex = index ; if ( b . length - index >= 3 ) { try { byte [ ] cic = new byte [ 2 ] ; cic [ 0 ] = b [ index ++ ] ; cic [ 1 ] = b [ index ++ ] ; this . cic = new CircuitIdentificationCodeImpl ( ) ; ( ( AbstractISUPParameter ) this . cic ) . decode ( cic ) ; } catch ( Exception e ) { throw new ParameterException ( "Failed to parse CircuitIdentificationCode due to: " , e ) ; } try { if ( b [ index ] != this . getMessageType ( ) . getCode ( ) ) { throw new ParameterException ( "Message code is not: " + this . getMessageType ( ) . getCode ( ) ) ; } } catch ( Exception e ) { throw new ParameterException ( "Failed to parse MessageCode due to: " , e ) ; } index ++ ; return index - localIndex ; } else { throw new IllegalArgumentException ( "byte[] must have atleast three octets" ) ; } } | Unfortunelty this cant be generic can it? |
37,461 | protected int decodeMandatoryVariableParameters ( ISUPParameterFactory parameterFactory , byte [ ] b , int index ) throws ParameterException { int readCount = 0 ; if ( b . length - index > 0 ) { byte extPIndex = - 1 ; try { int count = getNumberOfMandatoryVariableLengthParameters ( ) ; readCount = count ; for ( int parameterIndex = 0 ; parameterIndex < count ; parameterIndex ++ ) { int lengthPointerIndex = index + parameterIndex ; int parameterLengthIndex = b [ lengthPointerIndex ] + lengthPointerIndex ; int parameterLength = b [ parameterLengthIndex ] ; byte [ ] parameterBody = new byte [ parameterLength ] ; System . arraycopy ( b , parameterLengthIndex + 1 , parameterBody , 0 , parameterLength ) ; decodeMandatoryVariableBody ( parameterFactory , parameterBody , parameterIndex ) ; } } catch ( ArrayIndexOutOfBoundsException aioobe ) { throw new ParameterException ( "Failed to read parameter, to few octets in buffer, parameter index: " + extPIndex , aioobe ) ; } catch ( IllegalArgumentException e ) { throw new ParameterException ( "Failed to parse, paramet index: " + extPIndex , e ) ; } } else { throw new ParameterException ( "To few bytes to decode mandatory variable part. There should be atleast on byte to indicate optional part." ) ; } return readCount ; } | decodes ptrs and returns offset from passed index value to first optional parameter parameter |
37,462 | private boolean addIncomingInvokeId ( Long invokeId ) { synchronized ( this . incomingInvokeList ) { if ( this . incomingInvokeList . contains ( invokeId ) ) return false ; else { this . incomingInvokeList . add ( invokeId ) ; return true ; } } } | Adding the new incoming invokeId into incomingInvokeList list |
37,463 | public void resetTimer ( Long invokeId ) throws TCAPException { try { this . dialogLock . lock ( ) ; int index = getIndexFromInvokeId ( invokeId ) ; InvokeImpl invoke = operationsSent [ index ] ; if ( invoke == null ) { throw new TCAPException ( "No operation with this ID" ) ; } invoke . startTimer ( ) ; } finally { this . dialogLock . unlock ( ) ; } } | TC - TIMER - RESET |
37,464 | public static String hexDump ( String label , byte [ ] bytes ) { final int modulo = 16 ; final int brk = modulo / 2 ; int indent = ( label == null ) ? 0 : label . length ( ) ; StringBuffer sb = new StringBuffer ( indent + 1 ) ; while ( indent > 0 ) { sb . append ( " " ) ; indent -- ; } String ind = sb . toString ( ) ; if ( bytes == null ) { return null ; } sb = new StringBuffer ( bytes . length * 4 ) ; StringBuffer cb = new StringBuffer ( 16 ) ; boolean nl = true ; int i = 0 ; for ( i = 1 ; i <= bytes . length ; i ++ ) { if ( nl ) { nl = false ; if ( i > 1 ) { sb . append ( ind ) ; } else if ( label != null ) { sb . append ( label ) ; } String ha = Integer . toHexString ( i - 1 ) ; for ( int j = ha . length ( ) ; j <= 8 ; j ++ ) { sb . append ( "0" ) ; } sb . append ( ha ) . append ( " " ) ; } sb . append ( " " ) ; int c = ( bytes [ i - 1 ] & 0xFF ) ; String hx = Integer . toHexString ( c ) . toUpperCase ( ) ; if ( hx . length ( ) == 1 ) { sb . append ( "0" ) ; } sb . append ( hx ) ; cb . append ( ( c < 0x21 || c > 0x7e ) ? '.' : ( char ) ( c ) ) ; if ( ( i % brk ) == 0 ) { sb . append ( " " ) ; } if ( ( i % modulo ) == 0 ) { sb . append ( "|" ) . append ( cb ) . append ( "|\n" ) ; nl = true ; cb = new StringBuffer ( 16 ) ; } } int mod = i % modulo ; if ( mod != 1 ) { while ( mod <= modulo ) { sb . append ( " " ) ; if ( ( mod % brk ) == 0 ) { sb . append ( " " ) ; } mod ++ ; } sb . append ( "|" ) . append ( cb ) . append ( "|\n" ) ; } return sb . toString ( ) ; } | Construct a String containing a hex - dump of a byte array |
37,465 | public void setMaxSequenceNumber ( int maxSequenceNumber ) throws Exception { if ( this . isStarted ) throw new Exception ( "MaxSequenceNumber parameter can be updated only when M3UA stack is NOT running" ) ; if ( maxSequenceNumber < 1 ) { maxSequenceNumber = 1 ; } else if ( maxSequenceNumber > MAX_SEQUENCE_NUMBER ) { maxSequenceNumber = MAX_SEQUENCE_NUMBER ; } this . maxSequenceNumber = maxSequenceNumber ; } | Set the maximum SLS that can be used by SCTP . Internally SLS vs SCTP Stream Sequence Number is maintained . Stream Seq Number 0 is for management . |
37,466 | public void startAsp ( String aspName ) throws Exception { AspFactoryImpl aspFactoryImpl = this . getAspFactory ( aspName ) ; if ( aspFactoryImpl == null ) { throw new Exception ( String . format ( M3UAOAMMessages . NO_ASP_FOUND , aspName ) ) ; } if ( aspFactoryImpl . getStatus ( ) ) { throw new Exception ( String . format ( M3UAOAMMessages . ASP_ALREADY_STARTED , aspName ) ) ; } if ( aspFactoryImpl . aspList . size ( ) == 0 ) { throw new Exception ( String . format ( M3UAOAMMessages . ASP_NOT_ASSIGNED_TO_AS , aspName ) ) ; } aspFactoryImpl . start ( ) ; this . store ( ) ; for ( FastList . Node < M3UAManagementEventListener > n = this . managementEventListeners . head ( ) , end = this . managementEventListeners . tail ( ) ; ( n = n . getNext ( ) ) != end ; ) { M3UAManagementEventListener m3uaManagementEventListener = n . getValue ( ) ; try { m3uaManagementEventListener . onAspFactoryStarted ( aspFactoryImpl ) ; } catch ( Throwable ee ) { logger . error ( "Exception while invoking onAspFactoryStarted" , ee ) ; } } } | This method should be called by management to start the ASP |
37,467 | public void add ( Mtp2 link ) { for ( int i = 0 ; i < links . length ; i ++ ) { if ( links [ i ] == null ) { links [ i ] = link ; break ; } } count ++ ; remap ( ) ; } | Adds link to this link set . |
37,468 | private void remap ( ) { int k = - 1 ; for ( int i = 0 ; i < map . length ; i ++ ) { boolean found = false ; for ( int j = k + 1 ; j < links . length ; j ++ ) { if ( links [ j ] != null ) { found = true ; k = j ; map [ i ] = k ; break ; } } if ( found ) { continue ; } for ( int j = 0 ; j < k ; j ++ ) { if ( links [ j ] != null ) { found = true ; k = j ; map [ i ] = k ; break ; } } if ( ! found ) { map [ i ] = 0 ; } } } | This method is called each time when number of links has changed to reestablish relation between link selection indicator and link |
37,469 | protected Dialog createNewTCAPDialog ( SccpAddress origAddress , SccpAddress destAddress , Long localTrId ) throws MAPException { try { return this . mapProviderImpl . getTCAPProvider ( ) . getNewDialog ( origAddress , destAddress , localTrId ) ; } catch ( TCAPException e ) { throw new MAPException ( e . getMessage ( ) , e ) ; } } | Creating new outgoing TCAP Dialog . Used when creating a new outgoing MAP Dialog |
37,470 | private synchronized Long getAvailableTxId ( ) throws TCAPException { if ( this . dialogs . size ( ) >= this . stack . getMaxDialogs ( ) ) throw new TCAPException ( "Current dialog count exceeds its maximum value" ) ; while ( true ) { if ( this . curDialogId < this . stack . getDialogIdRangeStart ( ) ) this . curDialogId = this . stack . getDialogIdRangeStart ( ) - 1 ; if ( ++ this . curDialogId > this . stack . getDialogIdRangeEnd ( ) ) this . curDialogId = this . stack . getDialogIdRangeStart ( ) ; Long id = this . curDialogId ; if ( checkAvailableTxId ( id ) ) return id ; } } | some help methods ... crude but will work for first impl . |
37,471 | protected int getNextSeqControl ( ) { int res = seqControl . getAndIncrement ( ) ; if ( this . stack . getSlsRangeType ( ) == SlsRangeType . Odd ) { if ( res % 2 == 0 ) res ++ ; } else if ( this . stack . getSlsRangeType ( ) == SlsRangeType . Even ) { if ( res % 2 != 0 ) res ++ ; } res = res & 0xFF ; return res ; } | get next Seq Control value available |
37,472 | protected Dialog createNewTCAPDialog ( SccpAddress origAddress , SccpAddress destAddress , Long localTrId ) throws CAPException { try { return this . capProviderImpl . getTCAPProvider ( ) . getNewDialog ( origAddress , destAddress , localTrId ) ; } catch ( TCAPException e ) { throw new CAPException ( e . getMessage ( ) , e ) ; } } | Creating new outgoing TCAP Dialog . Used when creating a new outgoing CAP Dialog |
37,473 | public int encodeDigits ( ByteArrayOutputStream bos ) { boolean isOdd = this . oddFlag == _FLAG_ODD ; byte b = 0 ; int count = ( ! isOdd ) ? address . length ( ) : address . length ( ) - 1 ; int bytesCount = 0 ; for ( int i = 0 ; i < count - 1 ; i += 2 ) { String ds1 = address . substring ( i , i + 1 ) ; String ds2 = address . substring ( i + 1 , i + 2 ) ; int d1 = Integer . parseInt ( ds1 , 16 ) ; int d2 = Integer . parseInt ( ds2 , 16 ) ; b = ( byte ) ( d2 << 4 | d1 ) ; bos . write ( b ) ; bytesCount ++ ; } if ( isOdd ) { String ds1 = address . substring ( count , count + 1 ) ; int d = Integer . parseInt ( ds1 ) ; b = ( byte ) ( d & 0x0f ) ; bos . write ( b ) ; bytesCount ++ ; } return bytesCount ; } | This method is used in encode . Encodes digits part . This is because |
37,474 | public ShellChannel accept ( ) throws IOException { SocketChannel newChannel = ( ( ServerSocketChannel ) channel ) . accept ( ) ; if ( newChannel == null ) return null ; return new ShellChannelExt ( chanProvider , newChannel ) ; } | Accepts a connection made to this channel s socket . |
37,475 | private void parseSmsSignalInfo ( SmsSignalInfo si , boolean isMo , boolean isMt ) { if ( si == null ) return ; if ( isMo ) { try { SmsTpdu tpdu = si . decodeTpdu ( true ) ; parseSmsTpdu ( tpdu ) ; } catch ( MAPException e ) { e . printStackTrace ( ) ; } } if ( isMt ) { try { SmsTpdu tpdu = si . decodeTpdu ( false ) ; parseSmsTpdu ( tpdu ) ; } catch ( MAPException e ) { e . printStackTrace ( ) ; } } } | SMS service listener |
37,476 | protected AspImpl getAspForNullRc ( ) { AspImpl aspImpl = ( AspImpl ) this . aspFactoryImpl . aspList . get ( 0 ) ; if ( this . aspFactoryImpl . aspList . size ( ) > 1 ) { ErrorCode errorCodeObj = this . aspFactoryImpl . parameterFactory . createErrorCode ( ErrorCode . Invalid_Routing_Context ) ; sendError ( null , errorCodeObj ) ; return null ; } return aspImpl ; } | Get s the ASP for any ASP Traffic Maintenance Management Signalling Network Management and Transfer m3ua message s received which has null Routing Context |
37,477 | protected void sendTransferMessageToLocalUser ( Mtp3TransferPrimitive msg , int seqControl ) { if ( this . isStarted ) { MsgTransferDeliveryHandler hdl = new MsgTransferDeliveryHandler ( msg ) ; seqControl = seqControl & slsFilter ; this . msgDeliveryExecutors [ this . slsTable [ seqControl ] ] . execute ( hdl ) ; } else { logger . error ( String . format ( "Received Mtp3TransferPrimitive=%s but Mtp3UserPart is not started. Message will be dropped" , msg ) ) ; } } | Deliver an incoming message to the local user |
37,478 | protected static String getHomeDir ( String [ ] args ) { if ( System . getenv ( HOME_DIR ) == null ) { if ( args . length > index ) { return args [ index ++ ] ; } else { return "." ; } } else { return System . getenv ( HOME_DIR ) ; } } | Gets the Media Server Home directory . |
37,479 | private void linkUp ( Mtp2 link ) { if ( link . mtp2Listener != null ) { link . mtp2Listener . linkUp ( ) ; } linkset . add ( link ) ; if ( linkset . isActive ( ) && this . mtp3Listener != null ) { try { mtp3Listener . linkUp ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } if ( logger . isInfoEnabled ( ) ) { logger . info ( String . format ( "(%s) Link now IN_SERVICE" , link . getName ( ) ) ) ; } } | Notify that link is up . |
37,480 | private boolean checkPattern ( Mtp2Buffer frame , int sltmLen , byte [ ] pattern ) { if ( sltmLen != pattern . length ) { return false ; } for ( int i = 0 ; i < pattern . length ; i ++ ) { if ( frame . frame [ i + PATTERN_OFFSET ] != pattern [ i ] ) { return false ; } } return true ; } | + 2 becuase frame . len contains 2B for CRC |
37,481 | public static String bcdToHexString ( int encodingScheme , byte bcdByte ) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder ( ) ; byte leftNibble = ( byte ) ( bcdByte & 0xf0 ) ; leftNibble = ( byte ) ( leftNibble >>> 4 ) ; leftNibble = ( byte ) ( leftNibble & 0x0f ) ; byte rightNibble = ( byte ) ( bcdByte & 0x0f ) ; switch ( encodingScheme ) { case GenericDigits . _ENCODING_SCHEME_BCD_EVEN : case GenericDigits . _ENCODING_SCHEME_BCD_ODD : sb . append ( convertHexByteToTelcoChar ( rightNibble ) ) ; sb . append ( convertHexByteToTelcoChar ( leftNibble ) ) ; break ; default : throw new UnsupportedEncodingException ( "Specified GenericDigits encoding: " + encodingScheme + " is unsupported" ) ; } return sb . toString ( ) ; } | Converts single BCD encoded byte into String Hex representation . |
37,482 | public static String bcdDecodeToHexString ( int encodingScheme , byte [ ] bcdBytes ) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder ( ) ; for ( byte b : bcdBytes ) { sb . append ( bcdToHexString ( encodingScheme , b ) ) ; } if ( GenericDigits . _ENCODING_SCHEME_BCD_ODD == encodingScheme ) { sb . deleteCharAt ( sb . length ( ) - 1 ) ; } return sb . toString ( ) ; } | Decoded BCD encoded string into Hex digits string . |
37,483 | private PowerShell initalize ( String powerShellExecutablePath ) throws PowerShellNotAvailableException { String codePage = PowerShellCodepage . getIdentifierByCodePageName ( Charset . defaultCharset ( ) . name ( ) ) ; ProcessBuilder pb ; if ( OSDetector . isWindows ( ) ) { pb = new ProcessBuilder ( "cmd.exe" , "/c" , "chcp" , codePage , ">" , "NUL" , "&" , powerShellExecutablePath , "-ExecutionPolicy" , "Bypass" , "-NoExit" , "-NoProfile" , "-Command" , "-" ) ; } else { pb = new ProcessBuilder ( powerShellExecutablePath , "-nologo" , "-noexit" , "-Command" , "-" ) ; } pb . redirectErrorStream ( true ) ; try { p = pb . start ( ) ; if ( p . waitFor ( 5 , TimeUnit . SECONDS ) && ! p . isAlive ( ) ) { throw new PowerShellNotAvailableException ( "Cannot execute PowerShell. Please make sure that it is installed in your system. Errorcode:" + p . exitValue ( ) ) ; } } catch ( IOException | InterruptedException ex ) { throw new PowerShellNotAvailableException ( "Cannot execute PowerShell. Please make sure that it is installed in your system" , ex ) ; } this . commandWriter = new PrintWriter ( new OutputStreamWriter ( new BufferedOutputStream ( p . getOutputStream ( ) ) ) , true ) ; this . threadpool = Executors . newFixedThreadPool ( 2 ) ; this . pid = getPID ( ) ; return this ; } | Initializes PowerShell console in which we will enter the commands |
37,484 | public static PowerShellResponse executeSingleCommand ( String command ) { PowerShellResponse response = null ; try ( PowerShell session = PowerShell . openSession ( ) ) { response = session . executeCommand ( command ) ; } catch ( PowerShellNotAvailableException ex ) { logger . log ( Level . SEVERE , "PowerShell not available" , ex ) ; } return response ; } | Execute a single command in PowerShell console and gets result |
37,485 | private void handleResponse ( PowerShellResponseHandler response , PowerShellResponse powerShellResponse ) { try { response . handle ( powerShellResponse ) ; } catch ( Exception ex ) { logger . log ( Level . SEVERE , "PowerShell not available" , ex ) ; } } | Handle response in callback way |
37,486 | @ SuppressWarnings ( "WeakerAccess" ) public PowerShellResponse executeScript ( String scriptPath , String params ) { BufferedReader srcReader ; try { srcReader = new BufferedReader ( new FileReader ( new File ( scriptPath ) ) ) ; } catch ( FileNotFoundException fnfex ) { logger . log ( Level . SEVERE , "Unexpected error when processing PowerShell script: file not found" , fnfex ) ; return new PowerShellResponse ( true , "Wrong script path: " + scriptPath , false ) ; } return executeScript ( srcReader , params ) ; } | Executed the provided PowerShell script in PowerShell console and gets result . |
37,487 | public PowerShellResponse executeScript ( BufferedReader srcReader , String params ) { PowerShellResponse response ; if ( srcReader != null ) { File tmpFile = createWriteTempFile ( srcReader ) ; if ( tmpFile != null ) { this . scriptMode = true ; response = executeCommand ( tmpFile . getAbsolutePath ( ) + " " + params ) ; tmpFile . delete ( ) ; } else { response = new PowerShellResponse ( true , "Cannot create temp script file!" , false ) ; } } else { logger . log ( Level . SEVERE , "Script buffered reader is null!" ) ; response = new PowerShellResponse ( true , "Script buffered reader is null!" , false ) ; } return response ; } | Execute the provided PowerShell script in PowerShell console and gets result . |
37,488 | private File createWriteTempFile ( BufferedReader srcReader ) { BufferedWriter tmpWriter = null ; File tmpFile = null ; try { tmpFile = File . createTempFile ( "psscript_" + new Date ( ) . getTime ( ) , ".ps1" , this . tempFolder ) ; if ( ! tmpFile . exists ( ) ) { return null ; } tmpWriter = new BufferedWriter ( new FileWriter ( tmpFile ) ) ; String line ; while ( srcReader != null && ( line = srcReader . readLine ( ) ) != null ) { tmpWriter . write ( line ) ; tmpWriter . newLine ( ) ; } tmpWriter . write ( "Write-Output \"" + END_SCRIPT_STRING + "\"" ) ; } catch ( IOException ioex ) { logger . log ( Level . SEVERE , "Unexpected error while writing temporary PowerShell script" , ioex ) ; } finally { try { if ( tmpWriter != null ) { tmpWriter . close ( ) ; } } catch ( IOException ex ) { logger . log ( Level . SEVERE , "Unexpected error when processing temporary PowerShell script" , ex ) ; } } return tmpFile ; } | Writes a temp powershell script file based on the srcReader |
37,489 | public void close ( ) { if ( ! this . closed ) { try { Future < String > closeTask = threadpool . submit ( ( ) -> { commandWriter . println ( "exit" ) ; p . waitFor ( ) ; return "OK" ; } ) ; if ( ! closeAndWait ( closeTask ) && this . pid > 0 ) { Logger . getLogger ( PowerShell . class . getName ( ) ) . log ( Level . INFO , "Forcing PowerShell to close. PID: " + this . pid ) ; try { Runtime . getRuntime ( ) . exec ( "taskkill.exe /PID " + pid + " /F /T" ) ; this . closed = true ; } catch ( IOException e ) { Logger . getLogger ( PowerShell . class . getName ( ) ) . log ( Level . SEVERE , "Unexpected error while killing powershell process" , e ) ; } } } catch ( InterruptedException | ExecutionException ex ) { logger . log ( Level . SEVERE , "Unexpected error when when closing PowerShell" , ex ) ; } finally { commandWriter . close ( ) ; try { if ( p . isAlive ( ) ) { p . getInputStream ( ) . close ( ) ; } } catch ( IOException ex ) { logger . log ( Level . SEVERE , "Unexpected error when when closing streams" , ex ) ; } if ( this . threadpool != null ) { try { this . threadpool . shutdownNow ( ) ; this . threadpool . awaitTermination ( 5 , TimeUnit . SECONDS ) ; } catch ( InterruptedException ex ) { logger . log ( Level . SEVERE , "Unexpected error when when shutting down thread pool" , ex ) ; } } this . closed = true ; } } } | Closes all the resources used to maintain the PowerShell context |
37,490 | private File getTempFolder ( String tempPath ) { if ( tempPath != null ) { File folder = new File ( tempPath ) ; if ( folder . exists ( ) ) { return folder ; } } return null ; } | Return the temp folder File object or null if the path does not exist |
37,491 | public static String getIdentifierByCodePageName ( String cpName ) { if ( cpName != null ) { for ( Entry < String , String > codePage : codePages . entrySet ( ) ) { if ( codePage . getValue ( ) . toLowerCase ( ) . equals ( cpName . toLowerCase ( ) ) ) { return codePage . getKey ( ) ; } } } return "65001" ; } | Get the CodePage code from encoding value |
37,492 | public String call ( ) throws InterruptedException { StringBuilder powerShellOutput = new StringBuilder ( ) ; try { if ( startReading ( ) ) { readData ( powerShellOutput ) ; } } catch ( IOException ioe ) { Logger . getLogger ( PowerShell . class . getName ( ) ) . log ( Level . SEVERE , "Unexpected error reading PowerShell output" , ioe ) ; return ioe . getMessage ( ) ; } return powerShellOutput . toString ( ) . replaceAll ( "\\s+$" , "" ) ; } | Calls the command and returns its output |
37,493 | private void readData ( StringBuilder powerShellOutput ) throws IOException { String line ; while ( null != ( line = this . reader . readLine ( ) ) ) { if ( this . scriptMode ) { if ( line . equals ( PowerShell . END_SCRIPT_STRING ) ) { break ; } } powerShellOutput . append ( line ) . append ( CRLF ) ; if ( ! this . scriptMode ) { try { if ( this . closed || ! canContinueReading ( ) ) { break ; } } catch ( InterruptedException ex ) { Logger . getLogger ( PowerShellCommandProcessor . class . getName ( ) ) . log ( Level . SEVERE , "Error executing command and reading result" , ex ) ; } } } } | Reads all data from output |
37,494 | private boolean startReading ( ) throws IOException , InterruptedException { while ( ! this . reader . ready ( ) ) { Thread . sleep ( this . waitPause ) ; if ( this . closed ) { return false ; } } return true ; } | Checks when we can start reading the output . Timeout if it takes too long in order to avoid hangs |
37,495 | private boolean canContinueReading ( ) throws IOException , InterruptedException { if ( ! this . reader . ready ( ) ) { Thread . sleep ( this . waitPause ) ; } if ( ! this . reader . ready ( ) ) { Thread . sleep ( 50 ) ; } return this . reader . ready ( ) ; } | Checks when we the reader can continue to read . |
37,496 | public static FilterBuilder any ( final Predicate ... alternatives ) { return new CommonFilterBuilder ( ) { public boolean matches ( Class < ? > klass ) { for ( Predicate alternative : alternatives ) { if ( alternative . matches ( klass ) ) { return true ; } } return false ; } } ; } | Returns a filter which satisfies any of the selected predicates . |
37,497 | protected final void indexAnnotations ( Class < ? > ... classes ) { for ( Class < ? > klass : classes ) { indexedAnnotations . add ( klass . getCanonicalName ( ) ) ; } annotationDriven = false ; } | Adds given annotations for indexing . |
37,498 | protected final void indexSubclasses ( Class < ? > ... classes ) { for ( Class < ? > klass : classes ) { indexedSuperclasses . add ( klass . getCanonicalName ( ) ) ; } annotationDriven = false ; } | Adds given classes for subclass indexing . |
37,499 | public final boolean isRouteExternal ( RouteHeader routeHeader ) { if ( routeHeader != null ) { javax . sip . address . SipURI routeUri = ( javax . sip . address . SipURI ) routeHeader . getAddress ( ) . getURI ( ) ; String routeTransport = routeUri . getTransportParam ( ) ; if ( routeTransport == null ) { routeTransport = ListeningPoint . UDP ; } return isExternal ( routeUri . getHost ( ) , routeUri . getPort ( ) , routeTransport ) ; } return true ; } | Check if the route is external |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.