summaryrefslogtreecommitdiff
path: root/telephony/common
diff options
context:
space:
mode:
authorBrad Ebinger <breadley@google.com>2021-04-06 18:55:27 +0000
committerBrad Ebinger <breadley@google.com>2021-04-26 19:33:05 +0000
commit3cccf87d807b87be0a178644e91e29394fd2e524 (patch)
treec8dc3867b4ae03d70495302656389029e418eb99 /telephony/common
parent67a02c82dccee00dc82a0d8c92bc1a02374fe435 (diff)
Expose parsing util methods for telephony validation
Bug: 173828358 Test: atest TeleServiceTests Change-Id: I271a36bcecb332c30f04e7fb22c45098384bc634
Diffstat (limited to 'telephony/common')
-rw-r--r--telephony/common/com/android/internal/telephony/SipMessageParsingUtils.java18
1 files changed, 16 insertions, 2 deletions
diff --git a/telephony/common/com/android/internal/telephony/SipMessageParsingUtils.java b/telephony/common/com/android/internal/telephony/SipMessageParsingUtils.java
index 179248dd2cf9..33b0bbd23086 100644
--- a/telephony/common/com/android/internal/telephony/SipMessageParsingUtils.java
+++ b/telephony/common/com/android/internal/telephony/SipMessageParsingUtils.java
@@ -81,6 +81,15 @@ public class SipMessageParsingUtils {
}
/**
+ * @return true if the SIP message start line is considered a response.
+ */
+ public static boolean isSipResponse(String startLine) {
+ String[] splitLine = splitStartLineAndVerify(startLine);
+ if (splitLine == null) return false;
+ return verifySipResponse(splitLine);
+ }
+
+ /**
* Return the via branch parameter, which is used to identify the transaction ID (request and
* response pair) in a SIP transaction.
* @param headerString The string containing the headers of the SIP message.
@@ -140,7 +149,12 @@ public class SipMessageParsingUtils {
return !headers.isEmpty() ? headers.get(0).second : null;
}
- private static String[] splitStartLineAndVerify(String startLine) {
+ /**
+ * Validate that the start line is correct and split into its three segments.
+ * @param startLine The start line to verify and split.
+ * @return The split start line, which will always have three segments.
+ */
+ public static String[] splitStartLineAndVerify(String startLine) {
String[] splitLine = startLine.split(" ");
if (isStartLineMalformed(splitLine)) return null;
return splitLine;
@@ -184,7 +198,7 @@ public class SipMessageParsingUtils {
* (This is internally an equalsIgnoreMatch comparison).
* @return the matched header keys and values.
*/
- private static List<Pair<String, String>> parseHeaders(String headerString,
+ public static List<Pair<String, String>> parseHeaders(String headerString,
boolean stopAtFirstMatch, String... matchingHeaderKeys) {
// Ensure there is no leading whitespace
headerString = removeLeadingWhitespace(headerString);