Examples of SipMessage


Examples of gov.nist.javax.sip.message.SIPMessage

   
    // Iterate thru the request/status line and headers.
    String currentLine = null;
    String currentHeader = null;
    boolean isFirstLine = true;
    SIPMessage message = null;
    do
    {
      int lineStart = i;
     
      // Find the length of the line.
      try {
        while (msgBuffer[i] != '\r' && msgBuffer[i] != '\n')
          i++;
      }
      catch (ArrayIndexOutOfBoundsException e) {
        // End of the message.
        break;
      }
      int lineLength = i - lineStart;

      // Make it a String.
      try {
        currentLine = new String(msgBuffer, lineStart, lineLength, "UTF-8");
      } catch (UnsupportedEncodingException e) {
        throw new ParseException("Bad message encoding!", 0);
      }

      currentLine = trimEndOfLine(currentLine);

      if (currentLine.length() == 0) {
        // Last header line, process the previous buffered header.
        if (currentHeader != null && message != null) {
           processHeader(currentHeader, message);
         }
       
      }
      else {
        if (isFirstLine) {
          message = processFirstLine(currentLine);
        } else {
          char firstChar = currentLine.charAt(0);
          if (firstChar == '\t' || firstChar == ' ') {
            if (currentHeader == null)
              throw new ParseException("Bad header continuation.", 0);
 
            // This is a continuation, append it to the previous line.
            currentHeader += currentLine.substring(1);
          }
          else {
            if (currentHeader != null && message != null) {
               processHeader(currentHeader, message);
             }
            currentHeader = currentLine;
          }
        }
      }

      if (msgBuffer[i] == '\r' && msgBuffer.length > i+1 && msgBuffer[i+1] == '\n')
        i++;

      i++;

      isFirstLine = false;
    } while (currentLine.length() > 0); // End do - while
   
    if (message == null) throw new ParseException("Bad message", 0);
    message.setSize(i);
   
    if (readBody && message.getContentLength() != null &&
        message.getContentLength().getContentLength() != 0) {

      int bodyLength = msgBuffer.length - i;
     
      byte[] body = new byte[bodyLength];
      System.arraycopy(msgBuffer, i, body, 0, bodyLength);
      message.setMessageContent(body,computeContentLengthFromMessage ,message.getContentLength().getContentLength() );
    }
   
    return message;
  }
View Full Code Here

Examples of gov.nist.javax.sip.message.SIPMessage

    // Iterate thru the request/status line and headers.
    String currentLine = null;
    String currentHeader = null;
    boolean isFirstLine = true;
    SIPMessage message = null;
    do
    {
      int lineStart = i;

      // Find the length of the line.
      try {
        char c = msgString.charAt(i);
        while (c != '\r' && c != '\n')
          c = msgString.charAt(++i);
      }
      catch (ArrayIndexOutOfBoundsException e) {
        // End of the message.
        break;
      } catch ( StringIndexOutOfBoundsException ex) {
        break;
      }

      // Make it a String.
      currentLine = msgString.substring(lineStart, i);
      currentLine = trimEndOfLine(currentLine);

      if (currentLine.length() == 0) {
        // Last header line, process the previous buffered header.
        if (currentHeader != null) {
          processHeader(currentHeader, message);
        }
      }
      else {
        if (isFirstLine) {
          message = processFirstLine(currentLine);
        } else {
          char firstChar = currentLine.charAt(0);
          if (firstChar == '\t' || firstChar == ' ') {
            if (currentHeader == null)
              throw new ParseException("Bad header continuation.", 0);

            // This is a continuation, append it to the previous line.
            currentHeader += currentLine.substring(1);
          }
          else {
            if (currentHeader != null) {
              processHeader(currentHeader, message);
            }
            currentHeader = currentLine;
          }
        }
      }

      if (msgString.charAt(i) == '\r' && msgString.length() > i+1 && msgString.charAt(i+1) == '\n')
        i++;

      i++;

      isFirstLine = false;
    }
    while (currentLine.length() > 0);

    message.setSize(i);

    // Check for content legth header
    if (readBody && message.getContentLength() != null &&
        message.getContentLength().getContentLength() != 0) {
      String body = msgString.substring(i);
      message.setMessageContent(body,computeContentLengthFromMessage,message.getContentLength().getContentLength());
     
    }

    return message;
  }
View Full Code Here

Examples of gov.nist.javax.sip.message.SIPMessage

   
    return line.substring(0, i+1);
  }

  private SIPMessage processFirstLine(String firstLine) throws ParseException {
    SIPMessage message;
    if (!firstLine.startsWith(SIPConstants.SIP_VERSION_STRING)) {
      message = new SIPRequest();
      try {
        RequestLine requestLine = new RequestLineParser(firstLine + "\n")
            .parse();
View Full Code Here

Examples of gov.nist.javax.sip.message.SIPMessage

      public void run() {
        for (int i = 0; i < messages.length; i++) {
          StringMsgParser smp = new StringMsgParser();
          try {
            SIPMessage sipMessage = smp
                .parseSIPMessage(messages[i]);
            System.out.println(" i = " + i + " branchId = "
                + sipMessage.getTopmostVia().getBranch());
            // System.out.println("encoded " +
            // sipMessage.toString());
          } catch (ParseException ex) {

          }
View Full Code Here

Examples of gov.nist.javax.sip.message.SIPMessage

      public void run() {
        for (int i = 0; i < messages.length; i++) {
          StringMsgParser smp = new StringMsgParser();
          try {
            SIPMessage sipMessage = smp
                .parseSIPMessage(messages[i]);
            System.out.println(" i = " + i + " branchId = "
                + sipMessage.getTopmostVia().getBranch());
            // System.out.println("encoded " +
            // sipMessage.toString());
          } catch (ParseException ex) {

          }
View Full Code Here

Examples of gov.nist.javax.sip.message.SIPMessage

                // Stop the timer that will kill the read.
                this.rawInputStream.stopTimer();
                inputBuffer.append(line2);              
//                smp.setParseExceptionListener(sipMessageListener);
//                smp.setReadBody(false);
                SIPMessage sipMessage = null;

                try {
                    if (stackLogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        stackLogger.logDebug("About to parse : " + inputBuffer.toString());
                    }
                    sipMessage = smp.parseSIPMessage(inputBuffer.toString().getBytes(), false, false, sipMessageListener);
                    if (sipMessage == null) {
                        this.rawInputStream.stopTimer();
                        continue;
                    }
                } catch (ParseException ex) {
                    // Just ignore the parse exception.
                    stackLogger.logError("Detected a parse error", ex);
                    continue;
                }

                if (logger.isLoggingEnabled(LogLevels.TRACE_DEBUG)) {
                  logger.logDebug("Completed parsing message");
                }
                String clString = sipMessage.getHeaderAsFormattedString(ContentLength.NAME);
                if(clString.length()>30) throw new RuntimeException("Bad content lenght header " + clString);
                ContentLength cl = (ContentLength) sipMessage
                        .getContentLength();
               
            
                int contentLength = 0;
                if (cl != null) {
                    contentLength = cl.getContentLength();
                } else {
                    contentLength = 0;
                }

                if (logger.isLoggingEnabled(LogLevels.TRACE_DEBUG)) {
                  logger.logDebug("Content length = " + contentLength);
                }
               
                if(maxMessageSize > 0 && contentLength > maxMessageSize) throw new RuntimeException("Max content size Exceeded! :" + contentLength + " allowed max size is " + maxMessageSize);

                if (contentLength == 0) {
                    sipMessage.removeContent();
                } else if (maxMessageSize == 0
                        || contentLength < this.sizeCounter) {
                    byte[] message_body = new byte[contentLength];
                    int nread = 0;
                    while (nread < contentLength) {
                        // Start my starvation timer.
                        // This ensures that the other end
                        // writes at least some data in
                        // or we will close the pipe from
                        // him. This prevents DOS attack
                        // that takes up all our connections.
                        this.rawInputStream.startTimer();
                        try {

                            int readlength = inputStream.read(message_body,
                                    nread, contentLength - nread);
                            if (readlength > 0) {
                                nread += readlength;
                            } else {
                                break;
                            }
                        } catch (IOException ex) {
                            stackLogger.logError("Exception Reading Content",ex);
                            break;
                        } finally {
                            // Stop my starvation timer.
                            this.rawInputStream.stopTimer();
                        }
                    }
                    sipMessage.setMessageContent(message_body);
                }
                // Content length too large - process the message and
                // return error from there.
                if (sipMessageListener != null) {
                    try {
                        if(postParseExecutor == null) {
                         
                            /**
                             * If gov.nist.javax.sip.TCP_POST_PARSING_THREAD_POOL_SIZE is disabled
                             * we continue with the old logic here.
                             */
                          if(sipStack.sipEventInterceptor != null) {
                              sipStack.sipEventInterceptor.beforeMessage(sipMessage);
                            }
                            sipMessageListener.processMessage(sipMessage);
                            if(sipStack.sipEventInterceptor != null) {
                              sipStack.sipEventInterceptor.afterMessage(sipMessage);
                            }
                        } else {
                            /**
                             * gov.nist.javax.sip.TCP_POST_PARSING_THREAD_POOL_SIZE is enabled so
                             * we use the threadpool to execute the task.
                             */
                            // we need to guarantee message ordering on the same socket on TCP
                            // so we lock and queue of messages per Call Id
                           
                            final String callId = sipMessage.getCallId().getCallId();
                            // http://dmy999.com/article/34/correct-use-of-concurrenthashmap
                            CallIDOrderingStructure orderingStructure = messagesOrderingMap.get(callId);
                            if(orderingStructure == null) {
                                CallIDOrderingStructure newCallIDOrderingStructure = new CallIDOrderingStructure();
                                orderingStructure = messagesOrderingMap.putIfAbsent(callId, newCallIDOrderingStructure);
View Full Code Here

Examples of gov.nist.javax.sip.message.SIPMessage

                semaphore.acquire();                                       
            } catch (InterruptedException e) {
                logger.logError("Semaphore acquisition for callId " + callId + " interrupted", e);
            }
            // once acquired we get the first message to process
            SIPMessage message = messagesForCallID.poll();
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
              logger.logDebug("semaphore acquired for message " + message);
            }
           
            try {
View Full Code Here

Examples of gov.nist.javax.sip.message.SIPMessage

                // Stop the timer that will kill the read.
                this.rawInputStream.stopTimer();
                inputBuffer.append(line2);              
//                smp.setParseExceptionListener(sipMessageListener);
//                smp.setReadBody(false);
                SIPMessage sipMessage = null;

                try {
                    if (stackLogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                        stackLogger.logDebug("About to parse : " + inputBuffer.toString());
                    }
                    sipMessage = smp.parseSIPMessage(inputBuffer.toString().getBytes(), false, false, sipMessageListener);
                    if (sipMessage == null) {
                        this.rawInputStream.stopTimer();
                        continue;
                    }
                } catch (ParseException ex) {
                    // Just ignore the parse exception.
                    stackLogger.logError("Detected a parse error", ex);
                    continue;
                }

                if (logger.isLoggingEnabled(LogLevels.TRACE_DEBUG)) {
                  logger.logDebug("Completed parsing message");
                }
                ContentLength cl = (ContentLength) sipMessage
                        .getContentLength();
                int contentLength = 0;
                if (cl != null) {
                    contentLength = cl.getContentLength();
                } else {
                    contentLength = 0;
                }

                if (logger.isLoggingEnabled(LogLevels.TRACE_DEBUG)) {
                  logger.logDebug("Content length = " + contentLength);
                }

                if (contentLength == 0) {
                    sipMessage.removeContent();
                } else if (maxMessageSize == 0
                        || contentLength < this.sizeCounter) {
                    byte[] message_body = new byte[contentLength];
                    int nread = 0;
                    while (nread < contentLength) {
                        // Start my starvation timer.
                        // This ensures that the other end
                        // writes at least some data in
                        // or we will close the pipe from
                        // him. This prevents DOS attack
                        // that takes up all our connections.
                        this.rawInputStream.startTimer();
                        try {

                            int readlength = inputStream.read(message_body,
                                    nread, contentLength - nread);
                            if (readlength > 0) {
                                nread += readlength;
                            } else {
                                break;
                            }
                        } catch (IOException ex) {
                            stackLogger.logError("Exception Reading Content",ex);
                            break;
                        } finally {
                            // Stop my starvation timer.
                            this.rawInputStream.stopTimer();
                        }
                    }
                    sipMessage.setMessageContent(message_body);
                }
                // Content length too large - process the message and
                // return error from there.
                if (sipMessageListener != null) {
                    try {
                        if(postParseExecutor == null) {
                         
                            /**
                             * If gov.nist.javax.sip.TCP_POST_PARSING_THREAD_POOL_SIZE is disabled
                             * we continue with the old logic here.
                             */
                          if(sipStack.sipEventInterceptor != null) {
                              sipStack.sipEventInterceptor.beforeMessage(sipMessage);
                            }
                            sipMessageListener.processMessage(sipMessage);
                            if(sipStack.sipEventInterceptor != null) {
                              sipStack.sipEventInterceptor.afterMessage(sipMessage);
                            }
                        } else {
                            /**
                             * gov.nist.javax.sip.TCP_POST_PARSING_THREAD_POOL_SIZE is enabled so
                             * we use the threadpool to execute the task.
                             */
                            // we need to guarantee message ordering on the same socket on TCP
                            // so we lock and queue of messages per Call Id
                           
                            final String callId = sipMessage.getCallId().getCallId();
                            // http://dmy999.com/article/34/correct-use-of-concurrenthashmap
                            CallIDOrderingStructure orderingStructure = messagesOrderingMap.get(callId);
                            if(orderingStructure == null) {
                                CallIDOrderingStructure newCallIDOrderingStructure = new CallIDOrderingStructure();
                                orderingStructure = messagesOrderingMap.putIfAbsent(callId, newCallIDOrderingStructure);
View Full Code Here

Examples of gov.nist.javax.sip.message.SIPMessage

                semaphore.acquire();                                       
            } catch (InterruptedException e) {
                logger.logError("Semaphore acquisition for callId " + callId + " interrupted", e);
            }
            // once acquired we get the first message to process
            SIPMessage message = messagesForCallID.poll();
            if (logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
              logger.logDebug("semaphore acquired for message " + message);
            }
           
            try {
View Full Code Here

Examples of gov.nist.javax.sip.message.SIPMessage

                this.rawInputStream.stopTimer();
                inputBuffer.append(line2);
                MessageParser smp = sipStack.getMessageParserFactory().createMessageParser(sipStack);
                smp.setParseExceptionListener(sipMessageListener);
                smp.setReadBody(false);
                SIPMessage sipMessage = null;

                try {
                    if (stackLogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
                      stackLogger.logDebug("About to parse : " + inputBuffer.toString());
                    }
                    sipMessage = smp.parseSIPMessage(inputBuffer.toString().getBytes());
                    if (sipMessage == null) {
                        this.rawInputStream.stopTimer();
                        continue;
                    }
                } catch (ParseException ex) {
                    // Just ignore the parse exception.
                  stackLogger.logError("Detected a parse error", ex);
                    continue;
                }

                if (Debug.debug) {
                    Debug.println("Completed parsing message");
                }
                ContentLength cl = (ContentLength) sipMessage
                        .getContentLength();
                int contentLength = 0;
                if (cl != null) {
                    contentLength = cl.getContentLength();
                } else {
                    contentLength = 0;
                }

                if (Debug.debug) {
                    Debug.println("contentLength " + contentLength);
                }

                if (contentLength == 0) {
                    sipMessage.removeContent();
                } else if (maxMessageSize == 0
                        || contentLength < this.sizeCounter) {
                    byte[] message_body = new byte[contentLength];
                    int nread = 0;
                    while (nread < contentLength) {
                        // Start my starvation timer.
                        // This ensures that the other end
                        // writes at least some data in
                        // or we will close the pipe from
                        // him. This prevents DOS attack
                        // that takes up all our connections.
                        this.rawInputStream.startTimer();
                        try {

                            int readlength = inputStream.read(message_body,
                                    nread, contentLength - nread);
                            if (readlength > 0) {
                                nread += readlength;
                            } else {
                                break;
                            }
                        } catch (IOException ex) {
                            stackLogger.logError("Exception Reading Content",ex);
                            break;
                        } finally {
                            // Stop my starvation timer.
                            this.rawInputStream.stopTimer();
                        }
                    }
                    sipMessage.setMessageContent(message_body);
                }
                // Content length too large - process the message and
                // return error from there.
                if (sipMessageListener != null) {
                    try {
                      if(postParseExecutor == null) {
                        /**
                         * If gov.nist.javax.sip.TCP_POST_PARSING_THREAD_POOL_SIZE is disabled
                         * we continue with the old logic here.
                         */
                        sipMessageListener.processMessage(sipMessage);
                      } else {
                        /**
                         * gov.nist.javax.sip.TCP_POST_PARSING_THREAD_POOL_SIZE is enabled so
                         * we use the threadpool to execute the task.
                         */
                        final SIPMessage message = sipMessage;
                       
                        // we need to guarantee message ordering on the same socket on TCP
                        // so we lock per Call Id
                       
                        final String callId = message.getCallId().getCallId();
                        // http://dmy999.com/article/34/correct-use-of-concurrenthashmap
                        Semaphore semaphore = messagesOrderingMap.get(callId);
                        if(semaphore == null) {
                          Semaphore newSemaphore = new Semaphore(1, true);
                          semaphore = messagesOrderingMap.putIfAbsent(callId, newSemaphore);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.