public Intent getAddNumberIntent() { final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); ArrayList<ContentValues> data = new ArrayList<>(); ContentValues values = new ContentValues(); SipUri number = getPhones().get(0).getNumber(); if (number.isRingId()) { values.put( ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE); values.put(ContactsContract.CommonDataKinds.Im.DATA, number.getRawUriString()); values.put( ContactsContract.CommonDataKinds.Im.PROTOCOL, ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM); values.put(ContactsContract.CommonDataKinds.Im.CUSTOM_PROTOCOL, "Ring"); } else { values.put( ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE); values.put(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS, number.getRawUriString()); } data.add(values); intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data); return intent; }
/** Set the default values in the request URI if necessary. */ protected void setDefaults() { // The request line may be unparseable (set to null by the // exception handler. if (requestLine == null) return; String method = requestLine.getMethod(); // The requestLine may be malformed! if (method == null) return; GenericURI u = (GenericURI) requestLine.getUri(); if (u == null) return; if (method.compareTo(Request.REGISTER) == 0 || method.compareTo(Request.INVITE) == 0) { if (u instanceof SipUri) { SipUri sipUri = (SipUri) u; sipUri.setUserParam(DEFAULT_USER); try { sipUri.setTransportParam(DEFAULT_TRANSPORT); } catch (ParseException ex) { } } } }
public static CallContact buildUnknown(SipUri to) { ArrayList<Phone> phones = new ArrayList<>(); phones.add(new Phone(to, 0)); return new CallContact(-1, null, to.getRawUriString(), 0, phones, "", false); }
public boolean hasNumber(SipUri number) { if (number == null || number.isEmpty()) return false; for (Phone p : phones) if (p.getNumber().equals(number)) return true; return false; }
/** * Check header for constraints. (1) Invite options and bye requests can only have SIP URIs in the * contact headers. (2) Request must have cseq, to and from and via headers. (3) Method in request * URI must match that in CSEQ. */ public void checkHeaders() throws ParseException { String prefix = "Missing a required header : "; /* Check for required headers */ if (getCSeq() == null) { throw new ParseException(prefix + CSeqHeader.NAME, 0); } if (getTo() == null) { throw new ParseException(prefix + ToHeader.NAME, 0); } if (this.callIdHeader == null || this.callIdHeader.getCallId() == null || callIdHeader.getCallId().equals("")) { throw new ParseException(prefix + CallIdHeader.NAME, 0); } if (getFrom() == null) { throw new ParseException(prefix + FromHeader.NAME, 0); } if (getViaHeaders() == null) { throw new ParseException(prefix + ViaHeader.NAME, 0); } if (getMaxForwards() == null) { throw new ParseException(prefix + MaxForwardsHeader.NAME, 0); } if (getTopmostVia() == null) throw new ParseException("No via header in request! ", 0); if (getMethod().equals(Request.NOTIFY)) { if (getHeader(SubscriptionStateHeader.NAME) == null) throw new ParseException(prefix + SubscriptionStateHeader.NAME, 0); if (getHeader(EventHeader.NAME) == null) throw new ParseException(prefix + EventHeader.NAME, 0); } else if (getMethod().equals(Request.PUBLISH)) { /* * For determining the type of the published event state, the EPA MUST include a * single Event header field in PUBLISH requests. The value of this header field * indicates the event package for which this request is publishing event state. */ if (getHeader(EventHeader.NAME) == null) throw new ParseException(prefix + EventHeader.NAME, 0); } /* * RFC 3261 8.1.1.8 The Contact header field MUST be present and contain exactly one SIP * or SIPS URI in any request that can result in the establishment of a dialog. For the * methods defined in this specification, that includes only the INVITE request. For these * requests, the scope of the Contact is global. That is, the Contact header field value * contains the URI at which the UA would like to receive requests, and this URI MUST be * valid even if used in subsequent requests outside of any dialogs. * * If the Request-URI or top Route header field value contains a SIPS URI, the Contact * header field MUST contain a SIPS URI as well. */ if (requestLine.getMethod().equals(Request.INVITE) || requestLine.getMethod().equals(Request.SUBSCRIBE) || requestLine.getMethod().equals(Request.REFER)) { if (this.getContactHeader() == null) { // Make sure this is not a target refresh. If this is a target // refresh its ok not to have a contact header. Otherwise // contact header is mandatory. if (this.getToTag() == null) throw new ParseException(prefix + ContactHeader.NAME, 0); } if (requestLine.getUri() instanceof SipUri) { String scheme = ((SipUri) requestLine.getUri()).getScheme(); if ("sips".equalsIgnoreCase(scheme)) { SipUri sipUri = (SipUri) this.getContactHeader().getAddress().getURI(); if (!sipUri.getScheme().equals("sips")) { throw new ParseException("Scheme for contact should be sips:" + sipUri, 0); } } } } /* * Contact header is mandatory for a SIP INVITE request. */ if (this.getContactHeader() == null && (this.getMethod().equals(Request.INVITE) || this.getMethod().equals(Request.REFER) || this.getMethod().equals(Request.SUBSCRIBE))) { throw new ParseException("Contact Header is Mandatory for a SIP INVITE", 0); } if (requestLine != null && requestLine.getMethod() != null && getCSeq().getMethod() != null && requestLine.getMethod().compareTo(getCSeq().getMethod()) != 0) { throw new ParseException("CSEQ method mismatch with Request-Line ", 0); } }
/** * Parse and return a structure for a SIP URL. * * @return a URL structure for a SIP url. * @throws ParsException if there was a problem parsing. */ public SipUri sipURL() throws ParseException { if (debug) dbg_enter("sipURL"); SipUri retval = new SipUri(); try { lexer.match(TokenTypes.SIP); lexer.match(':'); retval.setScheme(TokenNames.SIP); int m = lexer.markInputPosition(); try { String user = user(); // char la; // la = lexer.lookAhead(0); // name:password@hostPort lexer.match(':'); String password = password(); lexer.match('@'); HostNameParser hnp = new HostNameParser(this.getLexer()); HostPort hp = hnp.hostPort(); retval.setUser(user); retval.setUserPassword(password); retval.setHostPort(hp); } catch (ParseException ex) { // name@hostPort try { lexer.rewindInputPosition(m); String user = user(); lexer.match('@'); HostNameParser hnp = new HostNameParser(this.getLexer()); HostPort hp = hnp.hostPort(); retval.setUser(user); retval.setHostPort(hp); } catch (ParseException e) { // hostPort lexer.rewindInputPosition(m); HostNameParser hnp = new HostNameParser(this.getLexer()); HostPort hp = hnp.hostPort(); retval.setHostPort(hp); } } lexer.selectLexer("charLexer"); while (lexer.hasMoreChars()) { if (lexer.lookAhead(0) != ';') break; lexer.consume(1); NameValue parms = uriParam(); if (parms != null) retval.setUriParameter(parms); } if (lexer.hasMoreChars() && lexer.lookAhead(0) == '?') { lexer.consume(1); while (lexer.hasMoreChars()) { NameValue parms = qheader(); retval.setQHeader(parms); if (lexer.hasMoreChars() && lexer.lookAhead(0) != '&') break; else lexer.consume(1); } } return retval; } finally { if (debug) dbg_leave("sipURL"); } }
/** * Get the display name of remote party. * * @return The remote display name */ public String getDisplayName() { return SipUri.getDisplayedSimpleContact(fullFrom); }