Package org.zoolu.sip.message

Examples of org.zoolu.sip.message.Message


     * @param reason the response reason
     * @param contact the contact address
     * @param local_tag the local tag in the 'To' header
     * @param body the message body */
   public static Message createResponse(Message req, int code, String reason, String local_tag, NameAddress contact, String content_type, String body)
   {  Message resp=new Message();
      resp.setStatusLine(new StatusLine(code,reason));
      resp.setVias(req.getVias());
      if (code>=180 && code<300 && req.hasRecordRouteHeader())
         resp.setRecordRoutes(req.getRecordRoutes());
      ToHeader toh=req.getToHeader();
      if (local_tag!=null)
         toh.setParameter("tag",local_tag);
      resp.setToHeader(toh);
      resp.setFromHeader(req.getFromHeader());
      resp.setCallIdHeader(req.getCallIdHeader());
      resp.setCSeqHeader(req.getCSeqHeader());
      if (contact!=null) resp.setContactHeader(new ContactHeader(contact));
      // add Server header field
      if (SipStack.server_info!=null) resp.setServerHeader(new ServerHeader(SipStack.server_info));
      //if (body!=null) resp.setBody(body); else resp.setBody("");
      if (content_type==null) resp.setBody(body);
      else resp.setBody(content_type,body);
      //System.out.println("DEBUG: MessageFactory: response:\n"+resp.toString());
      return resp;
   }
View Full Code Here


   // skip any CRLF sequence
      skipCRLF();
      // Get content length; if no Content-Length header found return null
      String text;
      if (getPos()==0) text=str; else text=getRemainingString();
      Message msg=new Message(text);
      if (!msg.hasContentLengthHeader()) return null;
      int body_len=msg.getContentLengthHeader().getContentLength();

      // gets the message (and go ahead), or returns null
      int begin=getPos();
      goToEndOfLastHeader();
      if (!hasMore()) return null;
      goTo('\n');
      if (!hasMore()) return null;
      skipChar().goTo('\n'); // skip the LF of last header and go the the new line
      if (!hasMore()) return null;
      int body_pos=skipChar().getPos(); // skip the LF of the empty line and go the the body
     
      int end=body_pos+body_len;
      if (end<=str.length())
      {  index=end;
         return new Message(str.substring(begin,end));
      }
      else return null;
  
View Full Code Here

   public void onReceivedData(TcpConnection tcp_conn, byte[] data, int len)
   {  last_time=System.currentTimeMillis();
     
      text+=new String(data,0,len);
      SipParser par=new SipParser(text);
      Message msg=par.getSipMessage();
      while (msg!=null)
      {  //System.out.println("DEBUG: message len: "+msg.getLength());
         msg.setRemoteAddress(tcp_conn.getRemoteAddress().toString());
         msg.setRemotePort(tcp_conn.getRemotePort());
         msg.setTransport(PROTO_TCP);
         msg.setConnectionId(connection_id);
         if (listener!=null) listener.onReceivedMessage(this,msg);

         text=par.getRemainingString();
         //System.out.println("DEBUG: text left: "+text.length());
         par=new SipParser(text);
View Full Code Here

   printLog("message received",LogLevel.MEDIUM);
      if (msg.isRequest()) // it is an INVITE or ACK or BYE or OPTIONS or REGISTER or CANCEL
      printLog("message is a request",LogLevel.MEDIUM);

         // validate the message
         Message err_resp=validateRequest(msg);
         if (err_resp!=null)
         {  // for non-ACK requests respond with an error message
            if (!msg.isAck()) sip_provider.sendMessage(err_resp);
            return;
         }
View Full Code Here

 
  public void onReceivedMessage(SipProvider sip_provider, Message message) {
    // TODO Auto-generated method stub
    if (message.isOption()) {
      log.debug("Received OPTION message");
      Message response = MessageFactory.createResponse(message, 200, "OK", message.getFromHeader().getNameAddress());
      sip_provider.sendMessage(response);
    }
  }
View Full Code Here

      TransactionServer t=new TransactionServer(sip_provider,msg,null);
         //t.listen();
  
         if (server_profile.do_authentication)
         {  // check message authentication
            Message err_resp=as.authenticateRequest(msg)
            if (err_resp!=null)
            {  t.respondWith(err_resp);
               return;
            }
         }
        
         Message resp=updateRegistration(msg);
         if (resp==null) return;
        
         if (server_profile.do_authentication)
         {  // add Authentication-Info header field
            resp.setAuthenticationInfoHeader(as.getAuthenticationInfoHeader());
         }
        
         t.respondWith(resp);
      }
      else
      if (!msg.isAck())
      {  // send a stateless error response
         int result=501; // response code 501 ("Not Implemented")
         Message resp=MessageFactory.createResponse(msg,result,SipResponses.reasonOf(result),null);
         sip_provider.sendMessage(resp);
      }    
   }
View Full Code Here

      //printLog("ContactHeader missed: message discarded",LogLevel.HIGH);
         //int result=484;
         //return MessageFactory.createResponse(msg,result,SipResponses.reasonOf(result),null,null); 
         printLog("no contact found: fetching bindings..",LogLevel.MEDIUM);
         int result=200;
         Message resp=MessageFactory.createResponse(msg,result,SipResponses.reasonOf(result),null)
         // add current contacts
         Vector v=new Vector();
         for (Enumeration e=location_service.getUserContactURLs(user); e.hasMoreElements(); )
         {  String url=(String)e.nextElement();
            int expires=(int)(location_service.getUserContactExpirationDate(user,url).getTime()-System.currentTimeMillis())/1000;
            if (expires>0)
            {  // not expired
               ContactHeader ch=new ContactHeader(location_service.getUserContactNameAddress(user,url));
               ch.setExpires(expires);
               v.addElement(ch);
            }
         }
         if (v.size()>0) resp.setContacts(new MultipleHeader(v));
         return resp;
      }
      // else    

      Vector contacts=msg.getContacts().getHeaders();
      int result=200;
      Message resp=MessageFactory.createResponse(msg,result,SipResponses.reasonOf(result),null)

      ContactHeader contact_0=new ContactHeader((Header)contacts.elementAt(0));
      if (contact_0.isStar())
      {  printLog("DEBUG: ContactHeader is star",LogLevel.LOW);
         Vector resp_contacts=new Vector();
         for (Enumeration e=location_service.getUserContactURLs(user); e.hasMoreElements();)
         {  String url=(String)(e.nextElement());
            NameAddress name_address=location_service.getUserContactNameAddress(user,url);
            // update db
            location_service.removeUserContact(user,url);
            printLog("contact removed: "+url,LogLevel.LOW);
            if (exp_secs>0)
            {  Date exp_date=new Date(System.currentTimeMillis()+((long)exp_secs)*1000);
               location_service.addUserContact(user,name_address,exp_date);
               //DateFormat df=new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'",Locale.ITALIAN);
               //printLog("contact added: "+url+"; expire: "+df.format(location_service.getUserContactExpire(user,url)),LogLevel.LOW);
               printLog("contact added: "+url+"; expire: "+DateFormat.formatEEEddMMM(location_service.getUserContactExpirationDate(user,url)),LogLevel.LOW);
            }
            ContactHeader contact_i=new ContactHeader(name_address.getAddress());
            contact_i.setExpires(exp_secs);
            resp_contacts.addElement(contact_i);
         }
         if (resp_contacts.size()>0) resp.setContacts(new MultipleHeader(resp_contacts));
      }
      else
      Vector resp_contacts=new Vector();
         for (int i=0; i<contacts.size(); i++)    
         {  ContactHeader contact_i=new ContactHeader((Header)contacts.elementAt(i));
            NameAddress name_address=contact_i.getNameAddress();    
            String url=name_address.getAddress().toString();    
            int exp_secs_i=exp_secs;
            if (contact_i.hasExpires())
            {  exp_secs_i=contact_i.getExpires();
            }
            // limit the expire value
            if (exp_secs_i<0) exp_secs_i=0;
            else
            if (exp_secs_i>server_profile.expires) exp_secs_i=server_profile.expires;
                       
            // update db
            location_service.removeUserContact(user,url);
            if (exp_secs_i>0)
            {  Date exp_date=new Date(System.currentTimeMillis()+((long)exp_secs)*1000);
               location_service.addUserContact(user,name_address,exp_date);
               printLog("registration of user "+user+" updated",LogLevel.HIGH);
            }          
            contact_i.setExpires(exp_secs_i);
            resp_contacts.addElement(contact_i);
         }
         if (resp_contacts.size()>0) resp.setContacts(new MultipleHeader(resp_contacts));
      }

      location_service.sync()
      return resp;
   }
View Full Code Here

   /** Inits the KeepAliveSip in SIP mode */
   private void init(SipProvider sip_provider, Message message)
   {  this.sip_provider=sip_provider;
      if (message==null)
      {  message=new Message("\r\n");
      }
      //if (target!=null)
      //{  message.setRemoteAddress(target.getAddress().toString());
      //   message.setRemotePort(target.getPort());
      //}
View Full Code Here

      if (!msg.isAck())
      {  // send a stateless error response
         //int result=501; // response code 501 ("Not Implemented")
         //int result=485; // response code 485 ("Ambiguous");
         int result=484; // response code 484 ("Address Incomplete");
         Message resp=MessageFactory.createResponse(msg,result,SipResponses.reasonOf(result),null);
         sip_provider.sendMessage(resp);
      }
   }
View Full Code Here

      if (server_profile.call_log) call_logger.update(msg);

      if (server_profile.do_proxy_authentication && !msg.isAck() && !msg.isCancel())
      {  // check message authentication
         Message err_resp=as.authenticateProxyRequest(msg)
         if (err_resp!=null)
         {  sip_provider.sendMessage(err_resp);
            return;
         }
      }

      // message targets
      Vector targets=getTargets(msg);
     
      if (targets.isEmpty())
      {  // try to treat the request-URI as a local username or phone URL with a prefix-based nexthop rule
         SipURL request_uri=msg.getRequestLine().getAddress();
         SipURL new_target=getPhoneTarget(request_uri);
         if (new_target!=null) targets.addElement(new_target.toString());
      }
      if (targets.isEmpty())
      {  printLog("No target found, message discarded",LogLevel.HIGH);
         if (!msg.isAck()) sip_provider.sendMessage(MessageFactory.createResponse(msg,404,SipResponses.reasonOf(404),null));
         return;
      }          
     
      printLog("message will be forwarded to all user's contacts",LogLevel.MEDIUM);
      for (int i=0; i<targets.size(); i++)
      {  SipURL url=new SipURL((String)(targets.elementAt(i)));
         Message request=new Message(msg);
         request.removeRequestLine();
         request.setRequestLine(new RequestLine(msg.getRequestLine().getMethod(),url));
        
         updateProxingRequest(request);
         sip_provider.sendMessage(request);
      }
   }
View Full Code Here

TOP

Related Classes of org.zoolu.sip.message.Message

Copyright © 2018 www.massapicom. 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.