B2G/gecko/dom/mobilemessage/src/ril/WspPduHelper.jsm
/**
   * @param data
   *        A wrapped object containing raw PDU data.
   *
   * @return An array of objects representing multipart entries or null in case
   *         of errors found.
   *
   * @see WAP-230-WSP-20010705-a section 8.5
   */
@param data
A wrapped object containing raw PDU data.

@return An array of objects representing multipart entries or null in case
of errors found.


@param data A wrapped object containing raw PDU data . @return An array of objects representing multipart entries or null in case of errors found .
function parseMultiPart(data) {
    let nEntries = UintVar.decode(data);
    if (!nEntries) {
      return null;
    }
    let parts = new Array(nEntries);
    for (let i = 0; i < nEntries; i++) {
      let headersLen = UintVar.decode(data);
      let contentLen = UintVar.decode(data);
      let headersEnd = data.offset + headersLen;
      let contentEnd = headersEnd + contentLen;
      try {
        let headers = {};
        let contentType = ContentTypeValue.decode(data);
        headers["content-type"] = contentType;
        headers["content-length"] = contentLen;
        headers = this.parseHeaders(data, headersEnd, headers);
        let octetArray = Octet.decodeMultiple(data, contentEnd);
        let content = null;
        let charset = headers["content-type"].params &&
                      headers["content-type"].params.charset
                    ? headers["content-type"].params.charset.charset
                    : null;
        let mimeType = headers["content-type"].media;
        if (mimeType) {
          if (mimeType == "application/smil") {
            content = this.decodeStringContent(octetArray, charset);
          } else if (mimeType.indexOf("text/") == 0 && charset != "utf-8") {
            let tmpStr = this.decodeStringContent(octetArray, charset);
            let encoder = new TextEncoder("UTF-8");
            content = new Blob([encoder.encode(tmpStr)], {type : mimeType});
            if (!headers["content-type"].params) {
              headers["content-type"].params = {};
            }
            if (!headers["content-type"].params.charset) {
              headers["content-type"].params.charset = {};
            }
            headers["content-type"].params.charset.charset = "utf-8";
          }
        }
        if (!content) {
          content = new Blob([octetArray], {type : mimeType});
        }
        parts[i] = {
          index: i,
          headers: headers,
          content: content,
        };
      } catch (e) {
        debug("Failed to parse multipart entry, message: " + e.message);
        parts[i] = null;
      }
      if (data.offset != contentEnd) {
        data.offset = contentEnd;
      }
    }
    return parts;
  }
function parseMultiPart ( data ) { let nEntries = UintVar . decode ( data ) ; if ( ! nEntries ) { return null ; } let parts = new Array ( nEntries ) ; for ( let i = 0 ; i < nEntries ; i ++ ) { let headersLen = UintVar . decode ( data ) ; let contentLen = UintVar . decode ( data ) ; let headersEnd = data . offset + headersLen ; let contentEnd = headersEnd + contentLen ; try { let headers = { } ; let contentType = ContentTypeValue . decode ( data ) ; headers [ "content-type" ] = contentType ; headers [ "content-length" ] = contentLen ; headers = this . parseHeaders ( data , headersEnd , headers ) ; let octetArray = Octet . decodeMultiple ( data , contentEnd ) ; let content = null ; let charset = headers [ "content-type" ] . params && headers [ "content-type" ] . params . charset ? headers [ "content-type" ] . params . charset . charset : null ; let mimeType = headers [ "content-type" ] . media ; if ( mimeType ) { if ( mimeType == "application/smil" ) { content = this . decodeStringContent ( octetArray , charset ) ; } else if ( mimeType . indexOf ( "text/" ) == 0 && charset != "utf-8" ) { let tmpStr = this . decodeStringContent ( octetArray , charset ) ; let encoder = new TextEncoder ( "UTF-8" ) ; content = new Blob ( [ encoder . encode ( tmpStr ) ] , { type : mimeType } ) ; if ( ! headers [ "content-type" ] . params ) { headers [ "content-type" ] . params = { } ; } if ( ! headers [ "content-type" ] . params . charset ) { headers [ "content-type" ] . params . charset = { } ; } headers [ "content-type" ] . params . charset . charset = "utf-8" ; } } if ( ! content ) { content = new Blob ( [ octetArray ] , { type : mimeType } ) ; } parts [ i ] = { index : i , headers : headers , content : content , } ; } catch ( e ) { debug ( "Failed to parse multipart entry, message: " + e . message ) ; parts [ i ] = null ; } if ( data . offset != contentEnd ) { data . offset = contentEnd ; } } return parts ; }
@param data
        A wrapped object containing raw PDU data.
@param data A wrapped object containing raw PDU data .
// Length of the ContentType and Headers fields combined. // Length of the Data field // If the content is a SMIL type, convert it to a string. // We hope to save and expose the SMIL content in a string way. // If the content is a "text/plain" type, we have to make sure // the encoding of the blob content should always be "utf-8". // Make up the missing encoding info. // Placeholder to keep original index of following entries. // Seek to entry boundary for next entry.