Search in sources :

Example 1 with ContentType

use of gov.nist.javax.sip.header.ContentType in project XobotOS by xamarin.

the class SIPMessage method setMessageContent.

/**
     * Set the message content given type and subtype.
     * 
     * @param type is the message type (eg. application)
     * @param subType is the message sybtype (eg. sdp)
     * @param messageContent is the messge content as a string.
     */
public void setMessageContent(String type, String subType, String messageContent) {
    if (messageContent == null)
        throw new IllegalArgumentException("messgeContent is null");
    ContentType ct = new ContentType(type, subType);
    this.setHeader(ct);
    this.messageContent = messageContent;
    this.messageContentBytes = null;
    this.messageContentObject = null;
    // Could be double byte so we need to compute length
    // after converting to byte[]
    computeContentLength(messageContent);
}
Also used : ContentType(gov.nist.javax.sip.header.ContentType)

Example 2 with ContentType

use of gov.nist.javax.sip.header.ContentType in project XobotOS by xamarin.

the class MessageChannel method createBadReqRes.

/**
     * Creates a response to a bad request (ie one that causes a ParseException)
     * 
     * @param badReq
     * @return message bytes, null if unable to formulate response
     */
protected final String createBadReqRes(String badReq, ParseException pe) {
    StringBuffer buf = new StringBuffer(512);
    buf.append("SIP/2.0 400 Bad Request (" + pe.getLocalizedMessage() + ')');
    // We need the following headers: all Vias, CSeq, Call-ID, From, To
    if (!copyViaHeaders(badReq, buf))
        return null;
    if (!copyHeader(CSeqHeader.NAME, badReq, buf))
        return null;
    if (!copyHeader(CallIdHeader.NAME, badReq, buf))
        return null;
    if (!copyHeader(FromHeader.NAME, badReq, buf))
        return null;
    if (!copyHeader(ToHeader.NAME, badReq, buf))
        return null;
    // Should add a to-tag if not already present...
    int toStart = buf.indexOf(ToHeader.NAME);
    if (toStart != -1 && buf.indexOf("tag", toStart) == -1) {
        buf.append(";tag=badreq");
    }
    // Let's add a Server header too..
    ServerHeader s = MessageFactoryImpl.getDefaultServerHeader();
    if (s != null) {
        buf.append("\r\n" + s.toString());
    }
    int clength = badReq.length();
    if (!(this instanceof UDPMessageChannel) || clength + buf.length() + ContentTypeHeader.NAME.length() + ": message/sipfrag\r\n".length() + ContentLengthHeader.NAME.length() < 1300) {
        /*
             * Check to see we are within one UDP packet.
             */
        ContentTypeHeader cth = new ContentType("message", "sipfrag");
        buf.append("\r\n" + cth.toString());
        ContentLength clengthHeader = new ContentLength(clength);
        buf.append("\r\n" + clengthHeader.toString());
        buf.append("\r\n\r\n" + badReq);
    } else {
        ContentLength clengthHeader = new ContentLength(0);
        buf.append("\r\n" + clengthHeader.toString());
    }
    return buf.toString();
}
Also used : ContentType(gov.nist.javax.sip.header.ContentType) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ServerHeader(javax.sip.header.ServerHeader) ContentLength(gov.nist.javax.sip.header.ContentLength)

Example 3 with ContentType

use of gov.nist.javax.sip.header.ContentType in project XobotOS by xamarin.

the class SIPMessage method setMessageContent.

/**
     * Set the message content for a given type and subtype.
     * 
     * @param type is the messge type.
     * @param subType is the message subType.
     * @param messageContent is the message content as a byte array.
     */
public void setMessageContent(String type, String subType, byte[] messageContent) {
    ContentType ct = new ContentType(type, subType);
    this.setHeader(ct);
    this.setMessageContent(messageContent);
    computeContentLength(messageContent);
}
Also used : ContentType(gov.nist.javax.sip.header.ContentType)

Example 4 with ContentType

use of gov.nist.javax.sip.header.ContentType in project XobotOS by xamarin.

the class SIPResponse method createRequest.

/**
     * Generate a request from a response.
     *
     * @param requestURI -- the request URI to assign to the request.
     * @param via -- the Via header to assign to the request
     * @param cseq -- the CSeq header to assign to the request
     * @param from -- the From header to assign to the request
     * @param to -- the To header to assign to the request
     * @return -- the newly generated sip request.
     */
public SIPRequest createRequest(SipUri requestURI, Via via, CSeq cseq, From from, To to) {
    SIPRequest newRequest = new SIPRequest();
    String method = cseq.getMethod();
    newRequest.setMethod(method);
    newRequest.setRequestURI(requestURI);
    this.setBranch(via, method);
    newRequest.setHeader(via);
    newRequest.setHeader(cseq);
    Iterator headerIterator = getHeaders();
    while (headerIterator.hasNext()) {
        SIPHeader nextHeader = (SIPHeader) headerIterator.next();
        // Some headers do not belong in a Request ....
        if (SIPMessage.isResponseHeader(nextHeader) || nextHeader instanceof ViaList || nextHeader instanceof CSeq || nextHeader instanceof ContentType || nextHeader instanceof ContentLength || nextHeader instanceof RecordRouteList || nextHeader instanceof RequireList || // JvB: added
        nextHeader instanceof ContactList || nextHeader instanceof ContentLength || nextHeader instanceof ServerHeader || nextHeader instanceof ReasonHeader || nextHeader instanceof SessionExpires || nextHeader instanceof ReasonList) {
            continue;
        }
        if (nextHeader instanceof To)
            nextHeader = (SIPHeader) to;
        else if (nextHeader instanceof From)
            nextHeader = (SIPHeader) from;
        try {
            newRequest.attachHeader(nextHeader, false);
        } catch (SIPDuplicateHeaderException e) {
            //Should not happen!
            e.printStackTrace();
        }
    }
    try {
        // JvB: all requests need a Max-Forwards
        newRequest.attachHeader(new MaxForwards(70), false);
    } catch (Exception d) {
    }
    if (MessageFactoryImpl.getDefaultUserAgentHeader() != null) {
        newRequest.setHeader(MessageFactoryImpl.getDefaultUserAgentHeader());
    }
    return newRequest;
}
Also used : RequireList(gov.nist.javax.sip.header.RequireList) SessionExpires(gov.nist.javax.sip.header.extensions.SessionExpires) ReasonList(gov.nist.javax.sip.header.ReasonList) CSeq(gov.nist.javax.sip.header.CSeq) ContentType(gov.nist.javax.sip.header.ContentType) MaxForwards(gov.nist.javax.sip.header.MaxForwards) ContactList(gov.nist.javax.sip.header.ContactList) From(gov.nist.javax.sip.header.From) ReasonHeader(javax.sip.header.ReasonHeader) ParseException(java.text.ParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ViaList(gov.nist.javax.sip.header.ViaList) SIPHeader(gov.nist.javax.sip.header.SIPHeader) Iterator(java.util.Iterator) RecordRouteList(gov.nist.javax.sip.header.RecordRouteList) ServerHeader(javax.sip.header.ServerHeader) ContentLength(gov.nist.javax.sip.header.ContentLength) To(gov.nist.javax.sip.header.To)

Aggregations

ContentType (gov.nist.javax.sip.header.ContentType)4 ContentLength (gov.nist.javax.sip.header.ContentLength)2 ServerHeader (javax.sip.header.ServerHeader)2 CSeq (gov.nist.javax.sip.header.CSeq)1 ContactList (gov.nist.javax.sip.header.ContactList)1 From (gov.nist.javax.sip.header.From)1 MaxForwards (gov.nist.javax.sip.header.MaxForwards)1 ReasonList (gov.nist.javax.sip.header.ReasonList)1 RecordRouteList (gov.nist.javax.sip.header.RecordRouteList)1 RequireList (gov.nist.javax.sip.header.RequireList)1 SIPHeader (gov.nist.javax.sip.header.SIPHeader)1 To (gov.nist.javax.sip.header.To)1 ViaList (gov.nist.javax.sip.header.ViaList)1 SessionExpires (gov.nist.javax.sip.header.extensions.SessionExpires)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ParseException (java.text.ParseException)1 Iterator (java.util.Iterator)1 ContentTypeHeader (javax.sip.header.ContentTypeHeader)1 ReasonHeader (javax.sip.header.ReasonHeader)1