Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 1 | module SIP_Templates { |
| 2 | |
| 3 | import from SIPmsg_Types all; |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 4 | import from TCCConversion_Functions all; |
| 5 | import from TCCOpenSecurity_Functions all; |
Pau Espin Pedrol | 95ad6a0 | 2024-04-18 16:52:46 +0200 | [diff] [blame] | 6 | import from TCCDateTime_Functions all; |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 7 | import from Native_Functions all; |
Pau Espin Pedrol | 6052a34 | 2024-03-28 20:20:46 +0100 | [diff] [blame] | 8 | import from Osmocom_Types all; |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 9 | import from Misc_Helpers all; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 10 | |
| 11 | /* wrapper type to encapsulate the Addr_Union + parameter list used in From, To. ... */ |
| 12 | type record SipAddr { |
| 13 | Addr_Union addr, |
| 14 | SemicolonParam_List params optional |
| 15 | } |
| 16 | |
| 17 | const charstring c_SIP_VERSION := "SIP/2.0"; |
| 18 | |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 19 | template (value) GenericParam ts_Param(template (value) charstring id, |
| 20 | template (omit) charstring paramValue := omit) := { |
| 21 | id := id, |
| 22 | paramValue := paramValue |
| 23 | } |
| 24 | template (present) GenericParam tr_Param(template (present) charstring id := ?, |
| 25 | template charstring paramValue := *) := { |
| 26 | id := id, |
| 27 | paramValue := paramValue |
| 28 | } |
| 29 | function f_ts_Param_omit(template (value) charstring id, |
| 30 | template (omit) charstring paramValue := omit) |
| 31 | return template (omit) GenericParam |
| 32 | { |
| 33 | if (istemplatekind(paramValue, "omit")) { |
| 34 | return omit; |
| 35 | } |
| 36 | return ts_Param(id, paramValue); |
| 37 | } |
| 38 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 39 | template (value) SipUrl ts_SipUrl(template (value) HostPort host_port, |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 40 | template (omit) UserInfo user_info := omit, |
| 41 | template (value) charstring scheme := "sip") := { |
| 42 | scheme := scheme, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 43 | userInfo := user_info, |
| 44 | hostPort := host_port, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 45 | urlParameters := omit, |
| 46 | headers := omit |
| 47 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 48 | template (present) SipUrl tr_SipUrl(template (present) HostPort host_port := ?, |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 49 | template UserInfo user_info := *, |
| 50 | template (present) charstring scheme := "sip") := { |
| 51 | scheme := scheme, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 52 | userInfo := user_info, |
| 53 | hostPort := host_port, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 54 | urlParameters := *, |
| 55 | headers := * |
| 56 | } |
| 57 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 58 | template (value) SipUrl ts_SipUrlHost(template (value) charstring host, |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 59 | template (omit) integer portField := omit, |
| 60 | template (value) charstring scheme := "sip") |
| 61 | := ts_SipUrl(ts_HostPort(host, portField), scheme := scheme); |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 62 | |
| 63 | function ts_SipUrl_from_Addr_Union(template (value) Addr_Union au) |
| 64 | return template (value) SipUrl { |
| 65 | if (ischosen(au.nameAddr)) { |
| 66 | return au.nameAddr.addrSpec; |
| 67 | } else { /* au.addrSpecUnion */ |
| 68 | return au.addrSpecUnion; |
| 69 | } |
| 70 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 71 | |
Pau Espin Pedrol | cb3a15b | 2024-05-13 16:25:11 +0200 | [diff] [blame] | 72 | // [20.5] |
| 73 | template (present) Allow tr_Allow(template Method_List methods := *) := { |
| 74 | fieldName := ALLOW_E, |
| 75 | methods := methods |
| 76 | } |
| 77 | template (value) Allow ts_Allow(template (omit) Method_List methods := omit) := { |
| 78 | fieldName := ALLOW_E, |
| 79 | methods := methods |
| 80 | } |
| 81 | |
Pau Espin Pedrol | a674d61 | 2024-05-14 19:56:33 +0200 | [diff] [blame] | 82 | template (present) Credentials tr_Credentials_DigestResponse(template (present) CommaParam_List digestResponse) := { |
| 83 | digestResponse := digestResponse |
| 84 | } |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 85 | template (value) Credentials ts_Credentials_DigestResponse(template (value) CommaParam_List digestResponse) := { |
| 86 | digestResponse := digestResponse |
| 87 | } |
| 88 | |
| 89 | template (value) Credentials ts_Credentials_DigestResponseMD5( |
| 90 | template (value) charstring username, |
| 91 | template (value) charstring realm, |
| 92 | template (value) charstring nonce, |
| 93 | template (value) charstring uri, |
| 94 | template (value) charstring response, |
| 95 | template (value) charstring opaque, |
| 96 | template (value) charstring algorithm := "MD5", |
| 97 | template (value) charstring qop := "auth", |
| 98 | template (omit) charstring cnonce := omit, |
| 99 | template (omit) charstring nc := omit |
| 100 | ) := { |
| 101 | digestResponse := { |
| 102 | // Already added by digestResponse automatically: |
| 103 | //ts_Param("Digest", omit), |
| 104 | ts_Param("username", f_sip_str_quote(username)), |
| 105 | ts_Param("realm", f_sip_str_quote(realm)), |
| 106 | ts_Param("nonce", f_sip_str_quote(nonce)), |
| 107 | ts_Param("uri", f_sip_str_quote(uri)), |
| 108 | ts_Param("response", f_sip_str_quote(response)), |
| 109 | ts_Param("opaque", f_sip_str_quote(opaque)), |
| 110 | ts_Param("algorithm", algorithm), |
| 111 | ts_Param("qop", qop), |
| 112 | // FIXME: If "omit" is passed, these below end up in; |
| 113 | // "Dynamic test case error: Performing a valueof or send operation on a non-specific template of type @SIPmsg_Types.GenericParam" |
| 114 | f_ts_Param_omit("cnonce", f_sip_str_quote(cnonce)), |
| 115 | f_ts_Param_omit("nc", nc) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | template (value) Credentials ts_Credentials_OtherAuth(template (value) OtherAuth otherResponse) := { |
| 120 | otherResponse := otherResponse |
| 121 | } |
| 122 | |
Pau Espin Pedrol | a674d61 | 2024-05-14 19:56:33 +0200 | [diff] [blame] | 123 | template (present) Authorization tr_Authorization(template (present) Credentials body) := { |
| 124 | fieldName := AUTHORIZATION_E, |
| 125 | body := body |
| 126 | } |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 127 | template (value) Authorization ts_Authorization(template (value) Credentials body) := { |
| 128 | fieldName := AUTHORIZATION_E, |
| 129 | body := body |
| 130 | } |
| 131 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 132 | // [20.10] |
| 133 | template (present) NameAddr tr_NameAddr(template (present) SipUrl addrSpec := ?, |
| 134 | template charstring displayName := *) := { |
| 135 | displayName := displayName, |
| 136 | addrSpec := addrSpec |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 137 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 138 | template (value) NameAddr ts_NameAddr(template (value) SipUrl addrSpec, |
| 139 | template (omit) charstring displayName := omit) := { |
| 140 | displayName := displayName, |
| 141 | addrSpec := addrSpec |
| 142 | } |
| 143 | |
| 144 | template (present) Addr_Union tr_Addr_Union_NameAddr(template (present) NameAddr nameAddr := ?) := { |
| 145 | nameAddr := nameAddr |
| 146 | } |
| 147 | template (value) Addr_Union ts_Addr_Union_NameAddr(template (value) NameAddr nameAddr) := { |
| 148 | nameAddr := nameAddr |
| 149 | } |
| 150 | |
| 151 | template (present) Addr_Union tr_Addr_Union_SipUrl(template (present) SipUrl sipUrl := ?) := { |
| 152 | addrSpecUnion := sipUrl |
| 153 | } |
| 154 | template (value) Addr_Union ts_Addr_Union_SipUrl(template (value) SipUrl sipUrl) := { |
| 155 | addrSpecUnion := sipUrl |
| 156 | } |
| 157 | |
| 158 | |
| 159 | template (present) ContactAddress tr_ContactAddress(template (present) Addr_Union addressField := ?, |
| 160 | template SemicolonParam_List contactParams := *) := { |
| 161 | addressField := addressField, |
| 162 | contactParams := contactParams |
| 163 | } |
| 164 | template (value) ContactAddress ts_ContactAddress(template (value) Addr_Union addressField, |
| 165 | template (omit) SemicolonParam_List contactParams := omit) := { |
| 166 | addressField := addressField, |
| 167 | contactParams := contactParams |
| 168 | } |
| 169 | |
| 170 | template (present) Contact tr_Contact(template (present) ContactAddress_List contactAddresses := ?) := { |
| 171 | fieldName := CONTACT_E, |
| 172 | contactBody := { |
| 173 | contactAddresses := contactAddresses |
| 174 | } |
| 175 | } |
| 176 | template (value) Contact ts_Contact(template (value) ContactAddress_List contactAddresses) := { |
| 177 | fieldName := CONTACT_E, |
| 178 | contactBody := { |
| 179 | contactAddresses := contactAddresses |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | template (value) Contact ts_ContactWildcard := { |
| 184 | fieldName := CONTACT_E, |
| 185 | contactBody := { |
| 186 | wildcard := "*" |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | template (present) Contact tr_Contact_SipAddr(template (present) SipAddr contact_addr := ?) |
| 191 | := tr_Contact({ tr_ContactAddress(contact_addr.addr, contact_addr.params) }); |
| 192 | |
| 193 | private function f_tr_Contact_SipAddr(template SipAddr contact_addr) return template Contact |
| 194 | { |
| 195 | if (istemplatekind(contact_addr, "omit")) { |
| 196 | return omit; |
| 197 | } else if (istemplatekind(contact_addr, "*")) { |
| 198 | return *; |
| 199 | } |
| 200 | return tr_Contact_SipAddr(contact_addr); |
| 201 | } |
| 202 | |
| 203 | template (value) Contact ts_Contact_SipAddr(template (value) SipAddr contact_addr) |
| 204 | := ts_Contact({ ts_ContactAddress(contact_addr.addr, contact_addr.params) }); |
| 205 | private function ts_Contact_SipAddr_omit(template (omit) SipAddr contact_addr := omit) return template (omit) Contact |
| 206 | { |
| 207 | if (istemplatekind(contact_addr, "omit")) { |
| 208 | return omit; |
| 209 | } |
| 210 | return ts_Contact_SipAddr(contact_addr); |
| 211 | } |
| 212 | |
| 213 | |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 214 | // [20.14] |
| 215 | template (value) ContentLength ts_ContentLength(template (value) integer len := 0) := { |
| 216 | fieldName := CONTENT_LENGTH_E, |
| 217 | len := len |
| 218 | } |
| 219 | template (present) ContentLength tr_ContentLength(template (present) integer len := ?) := { |
| 220 | fieldName := CONTENT_LENGTH_E, |
| 221 | len := len |
| 222 | } |
| 223 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 224 | // [20.19] |
| 225 | template (value) Expires ts_Expires(template (value) DeltaSec deltaSec := "7200") := { |
| 226 | fieldName := EXPIRES_E, |
| 227 | deltaSec := deltaSec |
| 228 | } |
Pau Espin Pedrol | 586eec5 | 2024-06-04 19:07:33 +0200 | [diff] [blame] | 229 | template (present) Expires tr_Expires(template (present) DeltaSec deltaSec := ?) := { |
| 230 | fieldName := EXPIRES_E, |
| 231 | deltaSec := deltaSec |
| 232 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 233 | |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 234 | // [20.20] |
| 235 | template (value) From ts_From(template (value) Addr_Union addressField, |
| 236 | template (omit) SemicolonParam_List fromParams := omit) := { |
| 237 | fieldName := FROM_E, |
| 238 | addressField := addressField, |
| 239 | fromParams := fromParams |
| 240 | } |
| 241 | template (present) From tr_From(template (present) Addr_Union addressField := ?, |
| 242 | template SemicolonParam_List fromParams := *) := { |
| 243 | fieldName := FROM_E, |
| 244 | addressField := addressField, |
| 245 | fromParams := fromParams |
| 246 | } |
| 247 | |
Pau Espin Pedrol | 2723940 | 2024-06-25 19:09:53 +0200 | [diff] [blame^] | 248 | // [20.23] |
| 249 | template (value) MinExpires ts_MinExpires(template (value) DeltaSec deltaSec := "800000") := { |
| 250 | fieldName := MIN_EXPIRES_E, |
| 251 | deltaSec := deltaSec |
| 252 | } |
| 253 | |
Pau Espin Pedrol | 0c5c647 | 2024-05-21 13:13:49 +0200 | [diff] [blame] | 254 | // [RFC3455 5.4] + 3GPP 24.229 V8.7.0 |
| 255 | template (present) Access_net_spec tr_Access_net_spec(template (present) charstring access_type := ?, |
| 256 | template SemicolonParam_List access_info := *) := { |
| 257 | access_type := access_type, |
| 258 | access_info := access_info |
| 259 | } |
| 260 | template (present) Access_net_spec tr_Access_net_spec_EUTRAN(template (present) charstring uli_str := ?) := { |
| 261 | access_type := "3GPP-E-UTRAN-FDD", |
| 262 | access_info := {tr_Param("utran-cell-id-3gpp", uli_str)} |
| 263 | } |
| 264 | |
| 265 | // [RFC3455 5.4] + 3GPP 24.229 V8.7.0 |
| 266 | template (present) P_Access_Network_Info tr_P_Access_Network_Info(template (present) Access_net_spec_list access_net_specs := ?) := { |
| 267 | fieldName := P_ACCESS_NETWORK_INFO, |
| 268 | access_net_specs := access_net_specs |
| 269 | } |
| 270 | |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 271 | // [RFC3455 4.1] |
| 272 | template (present) P_Assoc_uri_spec tr_P_Assoc_uri_spec(template (present) NameAddr p_asso_uri := ?, |
| 273 | template SemicolonParam_List ai_params := *) := { |
| 274 | p_asso_uri := p_asso_uri, |
| 275 | ai_params := ai_params |
| 276 | } |
| 277 | template (value) P_Assoc_uri_spec ts_P_Assoc_uri_spec(template (value) NameAddr p_asso_uri, |
| 278 | template (omit) SemicolonParam_List ai_params := omit) := { |
| 279 | p_asso_uri := p_asso_uri, |
| 280 | ai_params := ai_params |
| 281 | } |
| 282 | |
| 283 | // [RFC3455 4.1] |
| 284 | template (present) P_Associated_Uri tr_P_Associated_Uri(template (present) P_Assoc_uri_spec_list p_assoc_uris := ?) := { |
| 285 | fieldName := P_ASSOCIATED_URI, |
| 286 | p_assoc_uris := p_assoc_uris |
| 287 | } |
| 288 | template (value) P_Associated_Uri ts_P_Associated_Uri(template (value) P_Assoc_uri_spec_list p_assoc_uris := {}) := { |
| 289 | fieldName := P_ASSOCIATED_URI, |
| 290 | p_assoc_uris := p_assoc_uris |
| 291 | } |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 292 | |
Pau Espin Pedrol | 6088b89 | 2024-06-21 20:40:41 +0200 | [diff] [blame] | 293 | // [RFC6050] |
| 294 | template (present) P_Preferred_Service tr_P_Preferred_Service(template (present) Service_ID_List p_ps := ?) := { |
| 295 | fieldName := P_PREFERRED_SERVICE_E, |
| 296 | p_ps := p_ps |
| 297 | } |
| 298 | |
Pau Espin Pedrol | faf21be | 2024-06-12 16:42:00 +0200 | [diff] [blame] | 299 | // RFC 3262 |
| 300 | template (value) RAck ts_RAck(template (value) integer response_num, |
| 301 | template (value) integer seq_nr, |
| 302 | template (value) charstring method := "INVITE") := { |
| 303 | fieldName := RACK_E, |
| 304 | response_num := response_num, |
| 305 | seqNumber := seq_nr, |
| 306 | method := method |
| 307 | } |
| 308 | template (present) RAck tr_RAck(template (present) integer response_num := ?, |
| 309 | template (present) integer seq_nr := ?, |
| 310 | template (present) charstring method := ?) := { |
| 311 | fieldName := RACK_E, |
| 312 | response_num := response_num, |
| 313 | seqNumber := seq_nr, |
| 314 | method := method |
| 315 | } |
| 316 | |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 317 | // [20.32] |
| 318 | template (value) Require ts_Require(template (value) OptionTag_List optionsTags := {}) := { |
| 319 | fieldName := REQUIRE_E, |
| 320 | optionsTags := optionsTags |
| 321 | } |
| 322 | template (present) Require tr_Require(template (present) OptionTag_List optionsTags := ?) := { |
| 323 | fieldName := REQUIRE_E, |
| 324 | optionsTags := optionsTags |
| 325 | } |
| 326 | |
Pau Espin Pedrol | faf21be | 2024-06-12 16:42:00 +0200 | [diff] [blame] | 327 | // RFC 3262 |
| 328 | template (value) RSeq ts_RSeq(template (value) integer response_num) := { |
| 329 | fieldName := RSEQ_E, |
| 330 | response_num := response_num |
| 331 | } |
| 332 | template (present) RSeq tr_RSeq(template (present) integer response_num := ?) := { |
| 333 | fieldName := RSEQ_E, |
| 334 | response_num := response_num |
| 335 | } |
| 336 | |
Pau Espin Pedrol | 52cc2e5 | 2024-05-13 17:50:20 +0200 | [diff] [blame] | 337 | // [20.35 RFC2616 14.38] |
| 338 | template (value) Server ts_Server(template (value) ServerVal_List serverBody := {}) := { |
| 339 | fieldName := SERVER_E, |
| 340 | serverBody := serverBody |
| 341 | } |
| 342 | template (present) Server tr_Server(template (present) ServerVal_List serverBody := ?) := { |
| 343 | fieldName := SERVER_E, |
| 344 | serverBody := serverBody |
| 345 | } |
| 346 | |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 347 | // [20.37] |
| 348 | template (value) Supported ts_Supported(template (value) OptionTag_List optionsTags := {}) := { |
| 349 | fieldName := SUPPORTED_E, |
| 350 | optionsTags := optionsTags |
| 351 | } |
| 352 | template (present) Supported tr_Supported(template (present) OptionTag_List optionsTags := ?) := { |
| 353 | fieldName := SUPPORTED_E, |
| 354 | optionsTags := optionsTags |
| 355 | } |
| 356 | |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 357 | // [20.39] |
| 358 | template (value) To ts_To(template (value) Addr_Union addressField, |
| 359 | template (omit) SemicolonParam_List toParams := omit) := { |
| 360 | fieldName := TO_E, |
| 361 | addressField := addressField, |
| 362 | toParams := toParams |
| 363 | } |
| 364 | template (present) To tr_To(template (present) Addr_Union addressField := ?, |
| 365 | template SemicolonParam_List toParams := *) := { |
| 366 | fieldName := TO_E, |
| 367 | addressField := addressField, |
| 368 | toParams := toParams |
| 369 | } |
| 370 | |
Pau Espin Pedrol | 13c50ac | 2024-05-13 17:48:09 +0200 | [diff] [blame] | 371 | // [20.41 RFC2616 14.43] |
| 372 | template (value) UserAgent ts_UserAgent(template (value) ServerVal_List userAgentBody := {}) := { |
| 373 | fieldName := USER_AGENT_E, |
| 374 | userAgentBody := userAgentBody |
| 375 | } |
| 376 | template (present) UserAgent tr_UserAgent(template (present) ServerVal_List userAgentBody := ?) := { |
| 377 | fieldName := USER_AGENT_E, |
| 378 | userAgentBody := userAgentBody |
| 379 | } |
| 380 | |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 381 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 382 | template (value) SipAddr ts_SipAddr(template (value) HostPort host_port, |
| 383 | template (omit) UserInfo user_info := omit, |
| 384 | template (omit) charstring displayName := omit, |
| 385 | template (omit) SemicolonParam_List params := omit) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 386 | addr := { |
| 387 | nameAddr := { |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 388 | displayName := displayName, |
| 389 | addrSpec := ts_SipUrl(host_port, user_info) |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 390 | } |
| 391 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 392 | params := params |
| 393 | } |
| 394 | template (present) SipAddr tr_SipAddr(template (present) HostPort host_port := ?, |
| 395 | template UserInfo user_info := *, |
| 396 | template charstring displayName := *, |
| 397 | template SemicolonParam_List params := *) := { |
| 398 | addr := { |
| 399 | nameAddr := { |
| 400 | displayName := displayName, |
| 401 | addrSpec := tr_SipUrl(host_port, user_info) |
| 402 | } |
| 403 | }, |
| 404 | params := params |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /* build a receive template from a value: substitute '*' for omit */ |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 408 | function tr_SipUrl_from_val(template (value) SipUrl tin) return template (present) SipUrl { |
| 409 | var template (present) SipUrl ret := tin; |
| 410 | |
| 411 | /* if the port number is 5060, it may be omitted */ |
| 412 | if (ispresent(tin.hostPort.portField) and |
| 413 | valueof(tin.hostPort.portField) == 5060) { |
| 414 | ret.hostPort.portField := 5060 ifpresent; |
| 415 | } |
| 416 | if (not ispresent(tin.userInfo.password)) { |
| 417 | ret.userInfo.password := *; |
| 418 | } |
| 419 | |
| 420 | return ret; |
| 421 | } |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 422 | function tr_Addr_Union_from_val(template (value) Addr_Union tin) return template (present) Addr_Union { |
| 423 | var template (present) Addr_Union ret := tin; |
| 424 | |
| 425 | if (not ispresent(tin.nameAddr.displayName)) { |
| 426 | ret.nameAddr.displayName := *; |
| 427 | } else if (f_str_tolower(f_sip_str_unquote(tin.nameAddr.displayName)) == "anonymous") { |
| 428 | /* if the user is Anonymous, it may be omitted */ |
| 429 | ret.nameAddr.displayName := tin.nameAddr.displayName ifpresent; |
| 430 | } |
| 431 | |
| 432 | ret.nameAddr.addrSpec := tr_SipUrl_from_val(tin.nameAddr.addrSpec); |
| 433 | |
| 434 | return ret; |
| 435 | } |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 436 | function tr_SipAddr_from_val(template (value) SipAddr tin) return template (present) SipAddr { |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 437 | var template (present) SipAddr ret := tin; |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 438 | |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 439 | ret.addr := tr_Addr_Union_from_val(tin.addr); |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 440 | |
| 441 | if (not ispresent(tin.params)) { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 442 | ret.params := *; |
| 443 | } |
| 444 | return ret; |
| 445 | } |
| 446 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 447 | function ts_SipAddr_from_Addr_Union(template (value) Addr_Union au, |
| 448 | template (omit) SemicolonParam_List params := omit) |
| 449 | return template (value) SipAddr { |
| 450 | var template (value) SipUrl addrSpec := ts_SipUrl_from_Addr_Union(au); |
| 451 | var template (omit) charstring displayName; |
| 452 | |
| 453 | if (ischosen(au.nameAddr)) { |
| 454 | displayName := au.nameAddr.displayName; |
| 455 | } else { /* au.addrSpecUnion */ |
| 456 | displayName := omit |
| 457 | } |
| 458 | |
| 459 | return ts_SipAddr(addrSpec.hostPort, |
| 460 | addrSpec.userInfo, |
| 461 | displayName, |
| 462 | params); |
| 463 | } |
| 464 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 465 | template (value) HostPort ts_HostPort(template (omit) charstring host := omit, |
| 466 | template (omit) integer portField := omit) := { |
| 467 | host := host, |
| 468 | portField := portField |
| 469 | } |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 470 | |
| 471 | template (present) HostPort tr_HostPort(template charstring host := *, |
| 472 | template integer portField := *) := { |
| 473 | host := host, |
| 474 | portField := portField |
| 475 | } |
| 476 | function f_tr_HostPort(template charstring host := *, |
| 477 | template integer portField := *) |
| 478 | return template (present) HostPort { |
| 479 | return f_tr_HostPort_opt_defport(tr_HostPort(host, portField)); |
| 480 | } |
| 481 | function f_tr_HostPort_opt_defport(template (present) HostPort hp) return template (present) HostPort { |
| 482 | var template (present) HostPort hpout := hp; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 483 | /* if the port number is 5060, it may be omitted */ |
| 484 | if (isvalue(hp.portField) and valueof(hp.portField) == 5060) { |
| 485 | hpout.portField := 5060 ifpresent; |
| 486 | } |
| 487 | return hpout; |
| 488 | } |
| 489 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 490 | function f_tr_SipUrl_opt_defport(template (present) SipUrl url) return template (present) SipUrl { |
| 491 | var template (present) SipUrl urlout := url; |
| 492 | urlout.hostPort := f_tr_HostPort_opt_defport(url.hostPort); |
| 493 | return urlout; |
| 494 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 495 | |
| 496 | template (value) UserInfo ts_UserInfo(template (value) charstring userOrTelephoneSubscriber, |
| 497 | template (omit) charstring password := omit) := { |
| 498 | userOrTelephoneSubscriber := userOrTelephoneSubscriber, |
| 499 | password := password |
| 500 | } |
| 501 | template (present) UserInfo tr_UserInfo(template (present) charstring userOrTelephoneSubscriber := ?, |
| 502 | template charstring password := *) := { |
| 503 | userOrTelephoneSubscriber := userOrTelephoneSubscriber, |
| 504 | password := password |
| 505 | } |
| 506 | |
| 507 | template (value) RequestLine ts_SIP_ReqLine(Method method, |
| 508 | template (value) SipUrl uri, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 509 | charstring ver := c_SIP_VERSION) := { |
| 510 | method := method, |
| 511 | requestUri := uri, |
| 512 | sipVersion := ver |
| 513 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 514 | template (present) RequestLine tr_SIP_ReqLine(template (present) Method method := ?, |
| 515 | template (present) SipUrl uri := ?, |
| 516 | template (present) charstring ver := c_SIP_VERSION) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 517 | method := method, |
| 518 | requestUri := uri, |
| 519 | sipVersion := ver |
| 520 | } |
| 521 | |
| 522 | template (value) StatusLine ts_SIP_StatusLine(integer status_code, charstring reason) := { |
| 523 | sipVersion := "SIP/2.0", |
| 524 | statusCode := status_code, |
| 525 | reasonPhrase := reason |
| 526 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 527 | template (present) StatusLine tr_SIP_StatusLine(template integer status_code, |
| 528 | template charstring reason) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 529 | sipVersion := "SIP/2.0", |
| 530 | statusCode := status_code, |
| 531 | reasonPhrase := reason |
| 532 | } |
| 533 | |
| 534 | |
| 535 | template (value) PDU_SIP_Request ts_SIP_req(template (value) RequestLine rl) := { |
| 536 | requestLine := rl, |
| 537 | msgHeader := c_SIP_msgHeader_empty, |
| 538 | messageBody := omit, |
| 539 | payload := omit |
| 540 | } |
| 541 | |
| 542 | const Method_List c_SIP_defaultMethods := { |
| 543 | "INVITE", "ACK", "BYE", "CANCEL", "OPTIONS", "PRACK", "MESSAGE", "SUBSCRIBE", |
| 544 | "NOTIFY", "REFER", "UPDATE" }; |
| 545 | |
| 546 | private function f_ContentTypeOrOmit(template (omit) ContentType ct, template (omit) charstring body) |
| 547 | return template (omit) ContentType { |
| 548 | /* if user explicitly stated no content type */ |
| 549 | if (istemplatekind(ct, "omit")) { |
| 550 | return omit; |
| 551 | } |
| 552 | /* if there's no body, then there's no content-type either */ |
| 553 | if (istemplatekind(body, "omit")) { |
| 554 | return omit; |
| 555 | } |
| 556 | return ct; |
| 557 | } |
| 558 | |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 559 | private function f_ContentLength(template (omit) charstring body) |
| 560 | return template (value) ContentLength { |
| 561 | /* rfc3261 20.14: "If no body is present in a message, then the |
| 562 | * Content-Length header field value MUST be set to zero." */ |
| 563 | if (istemplatekind(body, "omit")) { |
| 564 | return ts_ContentLength(0); |
| 565 | } |
| 566 | return ts_ContentLength(lengthof(body)); |
| 567 | } |
| 568 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 569 | template (value) ContentType ts_CT_SDP := { |
| 570 | fieldName := CONTENT_TYPE_E, |
| 571 | mediaType := "application/sdp" |
| 572 | }; |
| 573 | |
Pau Espin Pedrol | 2a83337 | 2024-05-10 20:23:22 +0200 | [diff] [blame] | 574 | template (value) Via ts_Via_from(template (value) HostPort addr, |
| 575 | template (value) charstring transport := "UDP") := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 576 | fieldName := VIA_E, |
| 577 | viaBody := { |
| 578 | { |
Pau Espin Pedrol | 2a83337 | 2024-05-10 20:23:22 +0200 | [diff] [blame] | 579 | sentProtocol := { "SIP", "2.0", transport }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 580 | sentBy := addr, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 581 | viaParams := omit |
| 582 | } |
| 583 | } |
| 584 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 585 | template (present) Via tr_Via_from(template (present) HostPort host_port := ?, |
Pau Espin Pedrol | 2a83337 | 2024-05-10 20:23:22 +0200 | [diff] [blame] | 586 | template (present) charstring transport := ?, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 587 | template SemicolonParam_List viaParams := *) := { |
| 588 | fieldName := VIA_E, |
| 589 | viaBody := { |
| 590 | { |
Pau Espin Pedrol | 2a83337 | 2024-05-10 20:23:22 +0200 | [diff] [blame] | 591 | sentProtocol := { "SIP", "2.0", ? }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 592 | sentBy := host_port, |
| 593 | viaParams := viaParams |
| 594 | } |
| 595 | } |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | template (present) OtherAuth |
| 599 | tr_OtherAuth(template (present) charstring authScheme := ?, |
| 600 | template (present) CommaParam_List authParams := ?) := { |
| 601 | authScheme := authScheme, |
| 602 | authParams := authParams |
| 603 | } |
| 604 | |
| 605 | template (value) OtherAuth |
| 606 | ts_OtherAuth(template (value) charstring authScheme, |
| 607 | template (value) CommaParam_List authParams) := { |
| 608 | authScheme := authScheme, |
| 609 | authParams := authParams |
| 610 | } |
| 611 | |
| 612 | template (present) Challenge |
| 613 | tr_Challenge_digestCln(template (present) CommaParam_List digestCln := ?) := { |
| 614 | digestCln := digestCln |
| 615 | } |
| 616 | |
| 617 | template (value) Challenge |
| 618 | ts_Challenge_digestCln(template (value) CommaParam_List digestCln) := { |
| 619 | digestCln := digestCln |
| 620 | } |
| 621 | |
| 622 | template (present) Challenge |
| 623 | tr_Challenge_otherChallenge(template (present) OtherAuth otherChallenge := ?) := { |
| 624 | otherChallenge := otherChallenge |
| 625 | } |
| 626 | |
| 627 | template (value) Challenge |
| 628 | ts_Challenge_otherChallenge(template (value) OtherAuth otherChallenge) := { |
| 629 | otherChallenge := otherChallenge |
| 630 | } |
| 631 | |
| 632 | template (present) WwwAuthenticate |
| 633 | tr_WwwAuthenticate(template (present) Challenge_list challenge := ?) := { |
| 634 | fieldName := WWW_AUTHENTICATE_E, |
| 635 | challenge := challenge |
| 636 | } |
| 637 | |
| 638 | template (value) WwwAuthenticate |
| 639 | ts_WwwAuthenticate(template (value) Challenge_list challenge) := { |
| 640 | fieldName := WWW_AUTHENTICATE_E, |
| 641 | challenge := challenge |
| 642 | } |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 643 | |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 644 | // RFC3329 |
| 645 | template (present) Security_client |
| 646 | tr_Security_client(template (present) Security_mechanism_list sec_mechanism_list := ?) := { |
| 647 | fieldName := SECURITY_CLIENT_E, |
| 648 | sec_mechanism_list := sec_mechanism_list |
| 649 | } |
| 650 | template (value) Security_client |
| 651 | ts_Security_client(template (value) Security_mechanism_list sec_mechanism_list) := { |
| 652 | fieldName := SECURITY_CLIENT_E, |
| 653 | sec_mechanism_list := sec_mechanism_list |
| 654 | } |
| 655 | |
Pau Espin Pedrol | 7f41156 | 2024-05-13 13:58:41 +0200 | [diff] [blame] | 656 | template (present) Security_server |
| 657 | tr_Security_server(template (present) Security_mechanism_list sec_mechanism_list := ?) := { |
| 658 | fieldName := SECURITY_SERVER_E, |
| 659 | sec_mechanism_list := sec_mechanism_list |
| 660 | } |
| 661 | template (value) Security_server |
| 662 | ts_Security_server(template (value) Security_mechanism_list sec_mechanism_list) := { |
| 663 | fieldName := SECURITY_SERVER_E, |
| 664 | sec_mechanism_list := sec_mechanism_list |
| 665 | } |
| 666 | |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 667 | template (present) Security_mechanism |
| 668 | tr_Security_mechanism(template (present) charstring name := ?, |
| 669 | template SemicolonParam_List params := *) := { |
| 670 | mechanism_name := name, |
| 671 | mechanism_params := params |
| 672 | } |
| 673 | template (value) Security_mechanism |
| 674 | ts_Security_mechanism(template (value) charstring name, |
| 675 | template (omit) SemicolonParam_List params := omit) := { |
| 676 | mechanism_name := name, |
| 677 | mechanism_params := params |
| 678 | } |
| 679 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 680 | template (value) MessageHeader ts_SIP_msgHeader_empty := c_SIP_msgHeader_empty; |
| 681 | template (value) MessageHeader |
| 682 | ts_SIP_msgh_std(template (value) CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 683 | template (value) From from_addr, |
| 684 | template (value) To to_addr, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 685 | template (omit) Contact contact, |
| 686 | template (value) charstring method, |
| 687 | template (value) integer seq_nr, |
| 688 | template (value) Via via, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 689 | template (omit) ContentLength content_length := ts_ContentLength(0), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 690 | template (omit) ContentType content_type := omit, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 691 | template (omit)Authorization authorization := omit, |
Pau Espin Pedrol | cb3a15b | 2024-05-13 16:25:11 +0200 | [diff] [blame] | 692 | template (omit) Allow allow := ts_Allow(c_SIP_defaultMethods), |
Pau Espin Pedrol | 89d8c95 | 2024-05-10 20:28:24 +0200 | [diff] [blame] | 693 | template (omit) Expires expires := omit, |
Pau Espin Pedrol | 2723940 | 2024-06-25 19:09:53 +0200 | [diff] [blame^] | 694 | template (omit) MinExpires minExpires := omit, |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 695 | template (omit) P_Associated_Uri p_associated_uri := omit, |
Pau Espin Pedrol | faf21be | 2024-06-12 16:42:00 +0200 | [diff] [blame] | 696 | template (omit) RAck rack := omit, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 697 | template (omit) Require require := omit, |
Pau Espin Pedrol | faf21be | 2024-06-12 16:42:00 +0200 | [diff] [blame] | 698 | template (omit) RSeq rseq := omit, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 699 | template (omit) Security_client security_client := omit, |
Pau Espin Pedrol | 7f41156 | 2024-05-13 13:58:41 +0200 | [diff] [blame] | 700 | template (omit) Security_server security_server := omit, |
Pau Espin Pedrol | 52cc2e5 | 2024-05-13 17:50:20 +0200 | [diff] [blame] | 701 | template (omit) Server server := omit, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 702 | template (omit) Supported supported := omit, |
Pau Espin Pedrol | 13c50ac | 2024-05-13 17:48:09 +0200 | [diff] [blame] | 703 | template (omit) UserAgent userAgent := ts_UserAgent({ "osmo-ttcn3-hacks/0.23" }), |
Pau Espin Pedrol | 89d8c95 | 2024-05-10 20:28:24 +0200 | [diff] [blame] | 704 | template (omit) WwwAuthenticate wwwAuthenticate := omit |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 705 | ) modifies ts_SIP_msgHeader_empty := { |
Pau Espin Pedrol | cb3a15b | 2024-05-13 16:25:11 +0200 | [diff] [blame] | 706 | allow := allow, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 707 | authorization := authorization, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 708 | callId := { |
| 709 | fieldName := CALL_ID_E, |
| 710 | callid := call_id |
| 711 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 712 | contact := contact, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 713 | contentLength := content_length, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 714 | contentType := content_type, |
| 715 | cSeq := { |
| 716 | fieldName := CSEQ_E, |
| 717 | seqNumber := seq_nr, |
| 718 | method := method |
| 719 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 720 | expires := expires, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 721 | fromField := from_addr, |
Pau Espin Pedrol | 2723940 | 2024-06-25 19:09:53 +0200 | [diff] [blame^] | 722 | minExpires := minExpires, |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 723 | p_associated_uri := p_associated_uri, |
Pau Espin Pedrol | faf21be | 2024-06-12 16:42:00 +0200 | [diff] [blame] | 724 | rack := rack, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 725 | require := require, |
Pau Espin Pedrol | faf21be | 2024-06-12 16:42:00 +0200 | [diff] [blame] | 726 | rseq := rseq, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 727 | security_client := security_client, |
Pau Espin Pedrol | 7f41156 | 2024-05-13 13:58:41 +0200 | [diff] [blame] | 728 | security_server := security_server, |
Pau Espin Pedrol | 52cc2e5 | 2024-05-13 17:50:20 +0200 | [diff] [blame] | 729 | server := server, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 730 | supported := supported, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 731 | toField := to_addr, |
Pau Espin Pedrol | 13c50ac | 2024-05-13 17:48:09 +0200 | [diff] [blame] | 732 | userAgent := userAgent, |
Pau Espin Pedrol | 89d8c95 | 2024-05-10 20:28:24 +0200 | [diff] [blame] | 733 | via := via, |
| 734 | wwwAuthenticate := wwwAuthenticate |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 735 | } |
| 736 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 737 | template (present) MessageHeader |
| 738 | tr_SIP_msgh_std(template CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 739 | template From from_addr, |
| 740 | template To to_addr, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 741 | template Contact contact, |
| 742 | template (present) Via via := tr_Via_from(?), |
| 743 | template charstring method, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 744 | template integer seq_nr := ?, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 745 | template ContentLength content_length := *, |
| 746 | template ContentType content_type := *, |
Pau Espin Pedrol | cb3a15b | 2024-05-13 16:25:11 +0200 | [diff] [blame] | 747 | template Allow allow := *, |
Pau Espin Pedrol | a674d61 | 2024-05-14 19:56:33 +0200 | [diff] [blame] | 748 | template Authorization authorization := *, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 749 | template Expires expires := *, |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 750 | template P_Associated_Uri p_associated_uri := *, |
Pau Espin Pedrol | faf21be | 2024-06-12 16:42:00 +0200 | [diff] [blame] | 751 | template RAck rack := *, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 752 | template Require require := *, |
Pau Espin Pedrol | ce370df | 2024-06-18 13:45:53 +0200 | [diff] [blame] | 753 | template RSeq rseq := *, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 754 | template Security_client security_client := *, |
Pau Espin Pedrol | 7f41156 | 2024-05-13 13:58:41 +0200 | [diff] [blame] | 755 | template Security_server security_server := *, |
Pau Espin Pedrol | 52cc2e5 | 2024-05-13 17:50:20 +0200 | [diff] [blame] | 756 | template Server server := *, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 757 | template Supported supported := *, |
Pau Espin Pedrol | 13c50ac | 2024-05-13 17:48:09 +0200 | [diff] [blame] | 758 | template UserAgent userAgent := *, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 759 | template WwwAuthenticate wwwAuthenticate := * |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 760 | ) modifies t_SIP_msgHeader_any := { |
Pau Espin Pedrol | cb3a15b | 2024-05-13 16:25:11 +0200 | [diff] [blame] | 761 | allow := allow, |
Pau Espin Pedrol | a674d61 | 2024-05-14 19:56:33 +0200 | [diff] [blame] | 762 | authorization := authorization, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 763 | callId := { |
| 764 | fieldName := CALL_ID_E, |
| 765 | callid := call_id |
| 766 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 767 | contact := contact, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 768 | contentLength := content_length, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 769 | contentType := content_type, |
| 770 | cSeq := { |
| 771 | fieldName := CSEQ_E, |
| 772 | seqNumber := seq_nr, |
| 773 | method := method |
| 774 | }, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 775 | expires := expires, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 776 | fromField := from_addr, |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 777 | p_associated_uri := p_associated_uri, |
Pau Espin Pedrol | faf21be | 2024-06-12 16:42:00 +0200 | [diff] [blame] | 778 | rack := rack, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 779 | require := require, |
Pau Espin Pedrol | ce370df | 2024-06-18 13:45:53 +0200 | [diff] [blame] | 780 | rseq := rseq, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 781 | security_client := security_client, |
Pau Espin Pedrol | 7f41156 | 2024-05-13 13:58:41 +0200 | [diff] [blame] | 782 | security_server := security_server, |
Pau Espin Pedrol | 52cc2e5 | 2024-05-13 17:50:20 +0200 | [diff] [blame] | 783 | server := server, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 784 | supported := supported, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 785 | toField := to_addr, |
Pau Espin Pedrol | 13c50ac | 2024-05-13 17:48:09 +0200 | [diff] [blame] | 786 | userAgent := userAgent, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 787 | via := via, |
| 788 | wwwAuthenticate := wwwAuthenticate |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 792 | template (value) PDU_SIP_Request |
| 793 | ts_SIP_REGISTER(template (value) SipUrl sip_url_host_port, |
| 794 | template (value) CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 795 | template (value) From from_addr, |
| 796 | template (value) To to_addr, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 797 | template (value) Via via, |
| 798 | integer seq_nr, |
| 799 | template (omit) Contact contact, |
| 800 | template (omit) Expires expires, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 801 | template (omit) Authorization authorization := omit, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 802 | template (omit) Require require := omit, |
| 803 | template (omit) Security_client security_client := omit, |
| 804 | template (omit) Supported supported := omit, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 805 | template (omit) charstring body := omit) := { |
| 806 | requestLine := ts_SIP_ReqLine(REGISTER_E, sip_url_host_port), |
| 807 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, contact, |
| 808 | "REGISTER", seq_nr, via, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 809 | content_length := f_ContentLength(body), |
| 810 | content_type := f_ContentTypeOrOmit(ts_CT_SDP, body), |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 811 | authorization := authorization, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 812 | expires := expires, |
| 813 | require := require, |
| 814 | security_client := security_client, |
| 815 | supported := supported), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 816 | messageBody := body, |
| 817 | payload := omit |
| 818 | } |
| 819 | template (present) PDU_SIP_Request |
| 820 | tr_SIP_REGISTER(template (present) SipUrl sip_url_host_port := ?, |
| 821 | template (present) CallidString call_id := ?, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 822 | template (present) From from_addr := ?, |
| 823 | template (present) To to_addr := ?, |
Pau Espin Pedrol | 0dd3f26 | 2024-04-25 17:04:43 +0200 | [diff] [blame] | 824 | template (present) Via via := tr_Via_from(f_tr_HostPort_opt_defport(?)), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 825 | template integer seq_nr := *, |
Pau Espin Pedrol | a674d61 | 2024-05-14 19:56:33 +0200 | [diff] [blame] | 826 | template Authorization authorization := *, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 827 | template Contact contact := *, |
| 828 | template Expires expires := *, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 829 | template Require require := *, |
| 830 | template Security_client security_client := *, |
| 831 | template Supported supported := *, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 832 | template charstring body := *) := { |
| 833 | requestLine := tr_SIP_ReqLine(REGISTER_E, sip_url_host_port), |
| 834 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, contact, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 835 | via, "REGISTER", seq_nr, |
Pau Espin Pedrol | a674d61 | 2024-05-14 19:56:33 +0200 | [diff] [blame] | 836 | authorization := authorization, |
Pau Espin Pedrol | 73f6a31 | 2024-05-10 20:30:16 +0200 | [diff] [blame] | 837 | expires := expires, |
| 838 | require := require, |
| 839 | security_client := security_client, |
| 840 | supported := supported), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 841 | messageBody := body, |
| 842 | payload := omit |
| 843 | } |
| 844 | |
| 845 | template (value) PDU_SIP_Request |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 846 | ts_SIP_INVITE(template (value) CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 847 | template (value) From from_addr, |
| 848 | template (value) To to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 849 | template (value) Via via, |
| 850 | template (value) Contact contact, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 851 | integer seq_nr, |
Pau Espin Pedrol | ce370df | 2024-06-18 13:45:53 +0200 | [diff] [blame] | 852 | template (omit) Supported supported := omit, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 853 | template (omit) charstring body := omit) := { |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 854 | requestLine := ts_SIP_ReqLine(INVITE_E, to_addr.addressField.nameAddr.addrSpec), |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 855 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, contact, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 856 | "INVITE", seq_nr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 857 | via, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 858 | content_length := f_ContentLength(body), |
Pau Espin Pedrol | ce370df | 2024-06-18 13:45:53 +0200 | [diff] [blame] | 859 | content_type := f_ContentTypeOrOmit(ts_CT_SDP, body), |
| 860 | supported := supported), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 861 | messageBody := body, |
| 862 | payload := omit |
| 863 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 864 | template (present) PDU_SIP_Request |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 865 | tr_SIP_INVITE(template (present) SipUrl uri, |
| 866 | template CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 867 | template From from_addr, |
| 868 | template To to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 869 | template Via via := tr_Via_from(f_tr_HostPort_opt_defport(?)), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 870 | template integer seq_nr, |
| 871 | template charstring body) := { |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 872 | requestLine := tr_SIP_ReqLine(INVITE_E, uri), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 873 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, ?, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 874 | via, "INVITE", seq_nr), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 875 | messageBody := body, |
| 876 | payload := omit |
| 877 | } |
| 878 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 879 | template (value) PDU_SIP_Request |
| 880 | ts_SIP_BYE(CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 881 | template (value) From from_addr, |
| 882 | template (value) To to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 883 | template (value) Via via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 884 | integer seq_nr, |
| 885 | template (omit) charstring body) := { |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 886 | requestLine := ts_SIP_ReqLine(BYE_E, to_addr.addressField.nameAddr.addrSpec), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 887 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, "BYE", seq_nr, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 888 | via, |
| 889 | content_length := f_ContentLength(body), |
| 890 | content_type := f_ContentTypeOrOmit(ts_CT_SDP, body)), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 891 | messageBody := body, |
| 892 | payload := omit |
| 893 | } |
| 894 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 895 | template (present) PDU_SIP_Request |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 896 | tr_SIP_BYE(template (present) SipUrl uri, |
| 897 | template CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 898 | template From from_addr, |
| 899 | template To to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 900 | template Via via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 901 | template integer seq_nr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 902 | template charstring body := *) := { |
| 903 | requestLine := tr_SIP_ReqLine(BYE_E, uri), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 904 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, omit, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 905 | via, "BYE", seq_nr), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 906 | messageBody := body, |
| 907 | payload := omit |
| 908 | } |
| 909 | |
| 910 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 911 | template (value) PDU_SIP_Request |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 912 | ts_SIP_ACK(template (value) CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 913 | template (value) From from_addr, |
| 914 | template (value) To to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 915 | template (value) Via via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 916 | integer seq_nr, |
| 917 | template (omit) charstring body) := { |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 918 | requestLine := ts_SIP_ReqLine(ACK_E, to_addr.addressField.nameAddr.addrSpec), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 919 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 920 | ts_Contact({ ts_ContactAddress(from_addr.addressField, from_addr.fromParams) }), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 921 | "ACK", seq_nr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 922 | via, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 923 | content_length := f_ContentLength(body), |
| 924 | content_type := f_ContentTypeOrOmit(ts_CT_SDP, body)), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 925 | messageBody := body, |
| 926 | payload := omit |
| 927 | } |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 928 | template (present) PDU_SIP_Request |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 929 | tr_SIP_ACK(template (present) SipUrl uri, |
| 930 | template CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 931 | template From from_addr, |
| 932 | template To to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 933 | template Via via, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 934 | template integer seq_nr, |
| 935 | template charstring body) := { |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 936 | requestLine := tr_SIP_ReqLine(ACK_E, uri), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 937 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, *, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 938 | via, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 939 | "ACK", seq_nr), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 940 | messageBody := body, |
| 941 | payload := omit |
| 942 | } |
| 943 | |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 944 | template (present) PDU_SIP_Request |
| 945 | tr_SIP_CANCEL(template (present) SipUrl uri, |
| 946 | template (present) CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 947 | template (present) From from_addr, |
| 948 | template (present) To to_addr, |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 949 | template (present) Via via, |
| 950 | template (present) integer seq_nr, |
| 951 | template charstring body := *) := { |
| 952 | requestLine := tr_SIP_ReqLine(CANCEL_E, uri), |
| 953 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, *, |
| 954 | via, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 955 | "CANCEL", seq_nr), |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 956 | messageBody := body, |
| 957 | payload := omit |
| 958 | } |
| 959 | |
Pau Espin Pedrol | ce370df | 2024-06-18 13:45:53 +0200 | [diff] [blame] | 960 | template (value) PDU_SIP_Request |
| 961 | ts_SIP_PRACK(template (value) SipUrl uri, |
| 962 | template (value) CallidString call_id, |
| 963 | template (value) From from_addr, |
| 964 | template (value) To to_addr, |
| 965 | template (value) Via via, |
| 966 | integer seq_nr, |
| 967 | template (value) RAck rack, |
| 968 | template (omit) charstring body := omit) := { |
| 969 | requestLine := ts_SIP_ReqLine(PRACK_E, uri), |
| 970 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, |
| 971 | "PRACK", seq_nr, |
| 972 | via, |
| 973 | content_length := f_ContentLength(body), |
| 974 | content_type := f_ContentTypeOrOmit(ts_CT_SDP, body), |
| 975 | rack := rack), |
| 976 | messageBody := body, |
| 977 | payload := omit |
| 978 | } |
Pau Espin Pedrol | faf21be | 2024-06-12 16:42:00 +0200 | [diff] [blame] | 979 | template (present) PDU_SIP_Request |
| 980 | tr_SIP_PRACK(template (present) SipUrl uri, |
| 981 | template CallidString call_id, |
| 982 | template From from_addr, |
| 983 | template To to_addr, |
| 984 | template Via via, |
| 985 | template integer seq_nr, |
| 986 | template RAck rack := tr_RAck(?, ?, ?), |
| 987 | template charstring body := *) := { |
| 988 | requestLine := tr_SIP_ReqLine(PRACK_E, uri), |
| 989 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, *, |
| 990 | via, |
| 991 | "PRACK", seq_nr, |
| 992 | rack := rack), |
| 993 | messageBody := body, |
| 994 | payload := omit |
| 995 | } |
| 996 | |
Pau Espin Pedrol | ce370df | 2024-06-18 13:45:53 +0200 | [diff] [blame] | 997 | template (value) PDU_SIP_Request |
| 998 | ts_SIP_UPDATE(template (value) SipUrl uri, |
| 999 | template (value) CallidString call_id, |
| 1000 | template (value) From from_addr, |
| 1001 | template (value) To to_addr, |
| 1002 | template (value) Via via, |
| 1003 | integer seq_nr, |
| 1004 | template (omit) Contact contact, |
| 1005 | template (value) Require require := ts_Require({"sec-agree", "precondition"}), |
| 1006 | template (value) charstring body) := { |
| 1007 | requestLine := ts_SIP_ReqLine(UPDATE_E, uri), |
| 1008 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, contact, |
| 1009 | "UPDATE", seq_nr, |
| 1010 | via, |
| 1011 | require := require), |
| 1012 | messageBody := body, |
| 1013 | payload := omit |
| 1014 | } |
Pau Espin Pedrol | faf21be | 2024-06-12 16:42:00 +0200 | [diff] [blame] | 1015 | template (present) PDU_SIP_Request |
| 1016 | tr_SIP_UPDATE(template (present) SipUrl uri, |
| 1017 | template CallidString call_id, |
| 1018 | template From from_addr, |
| 1019 | template To to_addr, |
| 1020 | template Via via, |
| 1021 | template integer seq_nr, |
| 1022 | template Require require := *, |
| 1023 | template charstring body) := { |
| 1024 | requestLine := tr_SIP_ReqLine(UPDATE_E, uri), |
| 1025 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, *, |
| 1026 | via, |
| 1027 | "UPDATE", seq_nr, |
| 1028 | require := require), |
| 1029 | messageBody := body, |
| 1030 | payload := omit |
| 1031 | } |
| 1032 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 1033 | template (value) PDU_SIP_Response |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1034 | ts_SIP_Response(template (value) CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 1035 | template (value) From from_addr, |
| 1036 | template (value) To to_addr, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 1037 | charstring method, |
| 1038 | integer status_code, |
| 1039 | integer seq_nr, |
| 1040 | charstring reason, |
| 1041 | Via via, |
Pau Espin Pedrol | a674d61 | 2024-05-14 19:56:33 +0200 | [diff] [blame] | 1042 | template (omit) Allow allow := omit, |
Pau Espin Pedrol | 586eec5 | 2024-06-04 19:07:33 +0200 | [diff] [blame] | 1043 | template (omit) Contact contact := omit, |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 1044 | template (omit) P_Associated_Uri p_associated_uri := omit, |
Pau Espin Pedrol | a674d61 | 2024-05-14 19:56:33 +0200 | [diff] [blame] | 1045 | template (omit) Require require := omit, |
| 1046 | template (omit) Server server := omit, |
| 1047 | template (omit) Supported supported := omit, |
| 1048 | template (omit) UserAgent userAgent := omit, |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 1049 | template (omit) charstring body := omit) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 1050 | statusLine := ts_SIP_StatusLine(status_code, reason), |
Pau Espin Pedrol | 586eec5 | 2024-06-04 19:07:33 +0200 | [diff] [blame] | 1051 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, contact, method, seq_nr, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 1052 | via, |
| 1053 | content_length := f_ContentLength(body), |
Pau Espin Pedrol | a674d61 | 2024-05-14 19:56:33 +0200 | [diff] [blame] | 1054 | content_type := f_ContentTypeOrOmit(ts_CT_SDP, body), |
| 1055 | allow := allow, |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 1056 | p_associated_uri := p_associated_uri, |
Pau Espin Pedrol | a674d61 | 2024-05-14 19:56:33 +0200 | [diff] [blame] | 1057 | require := require, |
| 1058 | server := server, |
| 1059 | supported := supported, |
| 1060 | userAgent := userAgent), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 1061 | messageBody := body, |
| 1062 | payload := omit |
| 1063 | } |
Pau Espin Pedrol | 1b5f7ba | 2024-05-13 16:38:38 +0200 | [diff] [blame] | 1064 | /* 100 Trying */ |
| 1065 | template (value) PDU_SIP_Response |
| 1066 | ts_SIP_Response_Trying( |
| 1067 | template (value) CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 1068 | template (value) From from_addr, |
| 1069 | template (value) To to_addr, |
Pau Espin Pedrol | 1b5f7ba | 2024-05-13 16:38:38 +0200 | [diff] [blame] | 1070 | Via via, |
| 1071 | integer seq_nr, |
| 1072 | charstring method := "INVITE", |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 1073 | template (omit) Allow allow := omit, |
| 1074 | template (omit) Server server := omit, |
| 1075 | template (omit) UserAgent userAgent := omit, |
Pau Espin Pedrol | 1b5f7ba | 2024-05-13 16:38:38 +0200 | [diff] [blame] | 1076 | template (omit) charstring body := omit) := { |
| 1077 | statusLine := ts_SIP_StatusLine(100, "Trying"), |
| 1078 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, method, seq_nr, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 1079 | via, |
| 1080 | content_length := f_ContentLength(body), |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 1081 | content_type := f_ContentTypeOrOmit(ts_CT_SDP, body), |
| 1082 | allow := allow, |
| 1083 | server := server, |
| 1084 | userAgent := userAgent), |
Pau Espin Pedrol | 1b5f7ba | 2024-05-13 16:38:38 +0200 | [diff] [blame] | 1085 | messageBody := body, |
| 1086 | payload := omit |
| 1087 | } |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1088 | /* 180 Ringing */ |
| 1089 | template (value) PDU_SIP_Response |
| 1090 | ts_SIP_Response_Ringing( |
| 1091 | template (value) CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 1092 | template (value) From from_addr, |
| 1093 | template (value) To to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1094 | Via via, |
| 1095 | integer seq_nr, |
| 1096 | charstring method := "INVITE", |
| 1097 | template (omit) charstring body := omit) := { |
| 1098 | statusLine := ts_SIP_StatusLine(180, "Ringing"), |
| 1099 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, method, seq_nr, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 1100 | via, |
| 1101 | content_length := f_ContentLength(body), |
| 1102 | content_type := f_ContentTypeOrOmit(ts_CT_SDP, body)), |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1103 | messageBody := body, |
| 1104 | payload := omit |
| 1105 | } |
| 1106 | |
Pau Espin Pedrol | faf21be | 2024-06-12 16:42:00 +0200 | [diff] [blame] | 1107 | /* 183 Session Progress */ |
| 1108 | template (value) PDU_SIP_Response |
| 1109 | ts_SIP_Response_SessionProgress( |
| 1110 | template (value) CallidString call_id, |
| 1111 | template (value) From from_addr, |
| 1112 | template (value) To to_addr, |
| 1113 | Via via, |
| 1114 | integer seq_nr, |
| 1115 | charstring method := "INVITE", |
| 1116 | template (omit) Require require := ts_Require({"100rel", "precondition"}), |
| 1117 | template (omit) RSeq rseq := ts_RSeq(1), |
| 1118 | template (omit) charstring body := omit) := { |
| 1119 | statusLine := ts_SIP_StatusLine(183, "Session Progress"), |
| 1120 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, method, seq_nr, |
| 1121 | via, |
| 1122 | content_length := f_ContentLength(body), |
| 1123 | content_type := f_ContentTypeOrOmit(ts_CT_SDP, body), |
| 1124 | require := require, |
| 1125 | rseq := rseq), |
| 1126 | messageBody := body, |
| 1127 | payload := omit |
| 1128 | } |
| 1129 | |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 1130 | /* 401 Unauthorized */ |
| 1131 | template (value) PDU_SIP_Response |
| 1132 | ts_SIP_Response_Unauthorized( |
| 1133 | template (value) CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 1134 | template (value) From from_addr, |
| 1135 | template (value) To to_addr, |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 1136 | Via via, |
| 1137 | template (value) WwwAuthenticate wwwAuthenticate, |
| 1138 | integer seq_nr, |
| 1139 | charstring method := "REGISTER", |
| 1140 | template (omit) Allow allow := omit, |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 1141 | template (omit) P_Associated_Uri p_associated_uri := omit, |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 1142 | template (omit) Security_server security_server := omit, |
| 1143 | template (omit) Server server := omit, |
| 1144 | template (omit) Supported supported := omit, |
| 1145 | template (omit) UserAgent userAgent := omit, |
| 1146 | template (omit) charstring body := omit) := { |
| 1147 | statusLine := ts_SIP_StatusLine(401, "Unauthorized"), |
| 1148 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, method, seq_nr, |
| 1149 | via, |
| 1150 | content_length := f_ContentLength(body), |
| 1151 | content_type := f_ContentTypeOrOmit(ts_CT_SDP, body), |
| 1152 | allow := allow, |
Pau Espin Pedrol | 4e6672c | 2024-05-22 17:03:53 +0200 | [diff] [blame] | 1153 | p_associated_uri := p_associated_uri, |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 1154 | security_server := security_server, |
| 1155 | server := server, |
| 1156 | supported := supported, |
| 1157 | userAgent := userAgent, |
| 1158 | wwwAuthenticate := wwwAuthenticate), |
| 1159 | messageBody := body, |
| 1160 | payload := omit |
| 1161 | } |
| 1162 | |
Pau Espin Pedrol | 2723940 | 2024-06-25 19:09:53 +0200 | [diff] [blame^] | 1163 | /* Tx 423 Interval Too Brief */ |
| 1164 | template (value) PDU_SIP_Response |
| 1165 | ts_SIP_Response_423_Interval_Too_Brief( |
| 1166 | template (value) CallidString call_id, |
| 1167 | template (value) From from_addr, |
| 1168 | template (value) To to_addr, |
| 1169 | Via via, |
| 1170 | integer seq_nr, |
| 1171 | charstring method := "REGISTER", |
| 1172 | template (omit) Allow allow := omit, |
| 1173 | template (value) MinExpires minExpires := ts_MinExpires(), |
| 1174 | template (omit) Server server := omit, |
| 1175 | template (omit) Supported supported := omit, |
| 1176 | template (omit) UserAgent userAgent := omit) := { |
| 1177 | statusLine := ts_SIP_StatusLine(423, "Interval Too Brief"), |
| 1178 | msgHeader := ts_SIP_msgh_std(call_id, from_addr, to_addr, omit, method, seq_nr, |
| 1179 | via, |
| 1180 | content_length := f_ContentLength(omit), |
| 1181 | content_type := f_ContentTypeOrOmit(ts_CT_SDP, omit), |
| 1182 | allow := allow, |
| 1183 | minExpires := minExpires, |
| 1184 | server := server, |
| 1185 | supported := supported, |
| 1186 | userAgent := userAgent), |
| 1187 | messageBody := omit, |
| 1188 | payload := omit |
| 1189 | } |
| 1190 | |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 1191 | template (present) PDU_SIP_Response |
| 1192 | tr_SIP_Response(template CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 1193 | template From from_addr, |
| 1194 | template To to_addr, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1195 | template (present) Via via := tr_Via_from(?), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 1196 | template Contact contact, |
| 1197 | template charstring method, |
| 1198 | template integer status_code, |
| 1199 | template integer seq_nr := ?, |
| 1200 | template charstring reason := ?, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1201 | template charstring body := *) := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 1202 | statusLine := tr_SIP_StatusLine(status_code, reason), |
Pau Espin Pedrol | fb34d86 | 2024-03-28 20:21:38 +0100 | [diff] [blame] | 1203 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, contact, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1204 | via, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 1205 | method, seq_nr), |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 1206 | messageBody := body, |
| 1207 | payload := omit |
| 1208 | } |
| 1209 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1210 | /* Expect during first REGISTER/INVITE/... when authorization is required: */ |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 1211 | template (present) PDU_SIP_Response |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1212 | tr_SIP_Response_Unauthorized( |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 1213 | template CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 1214 | template From from_addr, |
| 1215 | template To to_addr, |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 1216 | template (present) Via via := tr_Via_from(?), |
| 1217 | template Contact contact := *, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1218 | template (present) WwwAuthenticate wwwAuthenticate := ?, |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 1219 | template integer seq_nr := ?, |
| 1220 | template charstring method := "REGISTER", |
| 1221 | template integer status_code := 401, |
| 1222 | template charstring reason := "Unauthorized", |
| 1223 | template charstring body := *) := { |
| 1224 | statusLine := tr_SIP_StatusLine(status_code, reason), |
| 1225 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, contact, |
| 1226 | via, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 1227 | method, seq_nr, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1228 | wwwAuthenticate := wwwAuthenticate), |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 1229 | messageBody := body, |
| 1230 | payload := omit |
| 1231 | } |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 1232 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1233 | /* 100 Trying */ |
| 1234 | template (present) PDU_SIP_Response |
| 1235 | tr_SIP_Response_Trying( |
| 1236 | template CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 1237 | template From from_addr, |
| 1238 | template To to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1239 | template (present) Via via := tr_Via_from(?), |
| 1240 | template integer seq_nr := ?, |
| 1241 | template charstring method := "INVITE", |
| 1242 | template integer status_code := 100, |
| 1243 | template charstring reason := "Trying", |
| 1244 | template charstring body := *) := { |
| 1245 | statusLine := tr_SIP_StatusLine(status_code, reason), |
| 1246 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, omit, |
| 1247 | via, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 1248 | method, seq_nr), |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1249 | messageBody := body, |
| 1250 | payload := omit |
| 1251 | } |
| 1252 | |
| 1253 | /* 180 Ringing */ |
| 1254 | template (present) PDU_SIP_Response |
| 1255 | tr_SIP_Response_Ringing( |
| 1256 | template CallidString call_id, |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 1257 | template From from_addr, |
| 1258 | template To to_addr, |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1259 | template (present) Via via := tr_Via_from(?), |
| 1260 | template integer seq_nr := ?, |
| 1261 | template charstring method := "INVITE", |
| 1262 | template integer status_code := 180, |
| 1263 | template charstring reason := "Ringing", |
| 1264 | template charstring body := *) := { |
| 1265 | statusLine := tr_SIP_StatusLine(status_code, reason), |
| 1266 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, *, |
| 1267 | via, |
Pau Espin Pedrol | 5c36a65 | 2024-05-14 16:05:59 +0200 | [diff] [blame] | 1268 | method, seq_nr), |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1269 | messageBody := body, |
| 1270 | payload := omit |
| 1271 | } |
| 1272 | |
Pau Espin Pedrol | ce370df | 2024-06-18 13:45:53 +0200 | [diff] [blame] | 1273 | /* 183 Session Progress */ |
| 1274 | template (present) PDU_SIP_Response |
| 1275 | tr_SIP_Response_SessionProgress( |
| 1276 | template (present) CallidString call_id, |
| 1277 | template (present) From from_addr, |
| 1278 | template (present) To to_addr, |
| 1279 | template (present) Via via, |
| 1280 | template (present) integer seq_nr := ?, |
| 1281 | template (present) charstring method := "INVITE", |
| 1282 | template Require require := *, |
| 1283 | template RSeq rseq := *, |
| 1284 | template (omit) charstring body := omit) := { |
| 1285 | statusLine := tr_SIP_StatusLine(183, "Session Progress"), |
| 1286 | msgHeader := tr_SIP_msgh_std(call_id, from_addr, to_addr, *, |
| 1287 | via, |
| 1288 | method, seq_nr, |
| 1289 | require := require, |
| 1290 | rseq := rseq), |
| 1291 | messageBody := body, |
| 1292 | payload := omit |
| 1293 | } |
| 1294 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1295 | /**************** |
| 1296 | * FUNCTIONS: |
| 1297 | ****************/ |
| 1298 | |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1299 | function f_sip_param_find(GenericParam_List li, |
| 1300 | template (present) charstring id := ?) |
| 1301 | return template (omit) GenericParam { |
| 1302 | var integer i; |
| 1303 | |
| 1304 | for (i := 0; i < lengthof(li); i := i + 1) { |
| 1305 | if (not ispresent(li[i])) { |
| 1306 | continue; |
| 1307 | } |
| 1308 | if (match(li[i].id, id)) { |
| 1309 | return li[i]; |
| 1310 | } |
| 1311 | } |
| 1312 | return omit; |
| 1313 | } |
| 1314 | |
| 1315 | function f_sip_param_find_or_fail(GenericParam_List li, |
| 1316 | template (present) charstring id := ?) |
| 1317 | return GenericParam { |
| 1318 | var template (omit) GenericParam parameter; |
| 1319 | parameter := f_sip_param_find(li, id); |
| 1320 | if (istemplatekind(parameter, "omit")) { |
| 1321 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 1322 | log2str("Param ", id, " not found in ", li)); |
| 1323 | } |
| 1324 | return valueof(parameter); |
| 1325 | } |
| 1326 | |
| 1327 | function f_sip_param_get_value(GenericParam_List li, |
| 1328 | template (present) charstring id := ?) |
| 1329 | return template (omit) charstring { |
| 1330 | var template (omit) GenericParam parameter; |
| 1331 | parameter := f_sip_param_find(li, id); |
| 1332 | if (istemplatekind(parameter, "omit")) { |
| 1333 | return omit; |
| 1334 | } |
| 1335 | return parameter.paramValue; |
| 1336 | } |
| 1337 | |
| 1338 | function f_sip_param_get_value_or_fail(GenericParam_List li, |
| 1339 | template (present) charstring id := ?) |
| 1340 | return template (omit) charstring { |
| 1341 | var GenericParam parameter; |
| 1342 | parameter := f_sip_param_find_or_fail(li, id); |
| 1343 | return parameter.paramValue; |
| 1344 | } |
| 1345 | |
| 1346 | function f_sip_param_get_value_present_or_fail(GenericParam_List li, |
| 1347 | template (present) charstring id := ?) |
| 1348 | return charstring { |
| 1349 | var GenericParam parameter; |
| 1350 | parameter := f_sip_param_find_or_fail(li, id); |
| 1351 | if (not ispresent(parameter.paramValue)) { |
| 1352 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 1353 | log2str("Param ", id, " value not present in ", li)); |
| 1354 | } |
| 1355 | return parameter.paramValue; |
| 1356 | } |
| 1357 | |
| 1358 | function f_sip_param_match_value(GenericParam_List li, |
| 1359 | template (present) charstring id := ?, |
| 1360 | template charstring exp_paramValue := *) |
| 1361 | return boolean { |
| 1362 | var template (omit) charstring val; |
| 1363 | val := f_sip_param_get_value_or_fail(li, id); |
| 1364 | if (istemplatekind(val, "omit")) { |
| 1365 | return istemplatekind(val, "omit") or istemplatekind(val, "*"); |
| 1366 | } |
| 1367 | return match(valueof(val), exp_paramValue); |
| 1368 | } |
| 1369 | |
| 1370 | function f_sip_param_match_value_or_fail(GenericParam_List li, |
| 1371 | template (present) charstring id := ?, |
| 1372 | template charstring exp_paramValue := *) |
| 1373 | { |
| 1374 | var template (omit) charstring val := f_sip_param_get_value_or_fail(li, id); |
| 1375 | if (istemplatekind(val, "omit")) { |
| 1376 | if (istemplatekind(val, "omit") or istemplatekind(val, "*")) { |
| 1377 | return; |
| 1378 | } else { |
| 1379 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 1380 | log2str("Param ", id, " match failed: val ", val, |
| 1381 | " vs exp ", exp_paramValue)); |
| 1382 | } |
| 1383 | } |
| 1384 | if (not match(valueof(val), exp_paramValue)) { |
| 1385 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 1386 | log2str("Param ", id, " match failed: val ", val, |
| 1387 | " vs exp ", exp_paramValue)); |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | function f_sip_param_remove(template (omit) GenericParam_List li_tpl, charstring id) |
| 1392 | return GenericParam_List { |
| 1393 | var integer i; |
| 1394 | var GenericParam_List li; |
| 1395 | var GenericParam_List new_li := {}; |
| 1396 | |
| 1397 | if (istemplatekind(li_tpl, "omit")) { |
| 1398 | return {}; |
| 1399 | } |
| 1400 | |
| 1401 | li := valueof(li_tpl); |
| 1402 | for (i := 0; i < lengthof(li); i := i + 1) { |
| 1403 | if (not ispresent(li[i]) or |
| 1404 | not match(li[i].id, id)) { |
| 1405 | new_li := new_li & {li[i]}; |
| 1406 | } |
| 1407 | } |
| 1408 | return new_li; |
| 1409 | } |
| 1410 | |
| 1411 | function f_sip_param_set(template (omit) GenericParam_List li_tpl, charstring id, charstring val) |
| 1412 | return GenericParam_List { |
| 1413 | var integer i; |
| 1414 | var GenericParam_List li; |
| 1415 | var GenericParam_List new_li := {}; |
| 1416 | var boolean found := false; |
| 1417 | |
| 1418 | if (istemplatekind(li_tpl, "omit")) { |
| 1419 | return { valueof(ts_Param(id, val)) }; |
| 1420 | } |
| 1421 | |
| 1422 | li := valueof(li_tpl); |
| 1423 | for (i := 0; i < lengthof(li); i := i + 1) { |
| 1424 | if (not ispresent(li[i]) or |
| 1425 | not match(li[i].id, id)) { |
| 1426 | new_li := new_li & {li[i]}; |
| 1427 | continue; |
| 1428 | } |
| 1429 | new_li := new_li & { valueof(ts_Param(li[i].id, val)) }; |
| 1430 | found := true; |
| 1431 | } |
| 1432 | |
| 1433 | if (not found) { |
| 1434 | new_li := new_li & { valueof(ts_Param(id, val)) }; |
| 1435 | } |
| 1436 | return new_li; |
| 1437 | } |
| 1438 | |
| 1439 | /* Make sure string is quoted. */ |
| 1440 | function f_sip_str_quote(template (value) charstring val) return charstring { |
| 1441 | var charstring str := valueof(val); |
| 1442 | if (lengthof(str) == 0) { |
| 1443 | return ""; |
| 1444 | } |
| 1445 | |
| 1446 | if (str[0] != "\"") { |
| 1447 | return "\"" & str & "\""; |
| 1448 | } |
| 1449 | return str; |
| 1450 | } |
| 1451 | |
| 1452 | /* Make sure string is unquoted. |
| 1453 | * Similar to unq() in RFC 2617 */ |
| 1454 | function f_sip_str_unquote(template (value) charstring val) return charstring { |
| 1455 | var charstring str := valueof(val); |
| 1456 | var integer len := lengthof(str); |
| 1457 | |
| 1458 | if (len <= 1) { |
| 1459 | return str; |
| 1460 | } |
| 1461 | |
| 1462 | if (str[0] == "\"" and str[len - 1] == "\"") { |
| 1463 | return substr(str, 1, len - 2); |
| 1464 | } |
| 1465 | return str; |
| 1466 | } |
| 1467 | |
| 1468 | /* RFC 2617 3.2.2.2 A1 */ |
| 1469 | function f_sip_digest_A1(charstring user, charstring realm, charstring password) return charstring { |
| 1470 | |
| 1471 | /* RFC 2617 3.2.2.2 A1 */ |
| 1472 | var charstring A1 := f_sip_str_unquote(user) & ":" & |
| 1473 | f_sip_str_unquote(realm) & ":" & |
| 1474 | password; |
| 1475 | var charstring digestA1 := f_str_tolower(f_calculateMD5(A1)); |
Pau Espin Pedrol | 80b981a | 2024-06-04 18:37:22 +0200 | [diff] [blame] | 1476 | log("A1: md5(", A1, ") = ", digestA1); |
| 1477 | return digestA1; |
| 1478 | } |
| 1479 | |
| 1480 | /* RFC 3310: Same as f_sip_digest_A1(), but using an octet buffer as password (AKAv1-MD5, pwd=RES) */ |
| 1481 | function f_sip_digest_A1_octpwd(charstring user, charstring realm, octetstring password) return charstring { |
| 1482 | var charstring A1pre := f_sip_str_unquote(user) & ":" & |
| 1483 | f_sip_str_unquote(realm) & ":"; |
| 1484 | var octetstring A1 := char2oct(A1pre) & password; |
| 1485 | var charstring digestA1 := f_str_tolower(oct2str(f_calculateMD5_oct(A1))); |
| 1486 | log("A1-octpwd: md5(", A1, ") = ", digestA1); |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1487 | return digestA1; |
| 1488 | } |
| 1489 | |
| 1490 | /* RFC 2617 3.2.2.2 A2 */ |
| 1491 | function f_sip_digest_A2(charstring method, charstring uri) return charstring { |
| 1492 | |
| 1493 | var charstring A2 := method & ":" & uri |
| 1494 | var charstring digestA2 := f_str_tolower(f_calculateMD5(A2)); |
Pau Espin Pedrol | 80b981a | 2024-06-04 18:37:22 +0200 | [diff] [blame] | 1495 | log("A2: md5(", A2, ") = ", digestA2); |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1496 | return digestA2; |
| 1497 | } |
| 1498 | |
| 1499 | /* RFC 2617 3.2.2.1 Request-Digest */ |
| 1500 | function f_sip_digest_RequestDigest(charstring digestA1, charstring nonce, |
| 1501 | charstring nc, charstring cnonce, |
| 1502 | charstring qop, charstring digestA2) return charstring { |
| 1503 | var charstring digest_data := f_sip_str_unquote(nonce) & ":" & |
| 1504 | nc & ":" & |
| 1505 | cnonce & ":" & |
| 1506 | f_sip_str_unquote(qop) & ":" & |
| 1507 | digestA2; |
| 1508 | var charstring req_digest := f_sip_digest_KD(digestA1, digest_data); |
Pau Espin Pedrol | 80b981a | 2024-06-04 18:37:22 +0200 | [diff] [blame] | 1509 | log("Request-Digest: md5(\"" & digestA1 & ":" & digest_data & "\") = " & "\"" & req_digest & "\""); |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1510 | return req_digest; |
| 1511 | } |
| 1512 | |
| 1513 | /* RFC 2617 3.2.1 The WWW-Authenticate Response Header |
| 1514 | * KD(secret, data) = H(concat(secret, ":", data)) |
| 1515 | */ |
| 1516 | function f_sip_digest_KD(charstring secret, charstring data) return charstring { |
| 1517 | return f_str_tolower(f_calculateMD5(secret & ":" & data)); |
| 1518 | } |
| 1519 | |
| 1520 | /* Digest Auth: RFC 2617 */ |
Pau Espin Pedrol | 80b981a | 2024-06-04 18:37:22 +0200 | [diff] [blame] | 1521 | function f_sip_digest_gen_Authorization_Response_MD5(charstring user, charstring realm, charstring password, |
| 1522 | charstring method, charstring uri, charstring qop, |
| 1523 | charstring nonce, charstring cnonce, charstring nc) |
| 1524 | return charstring { |
| 1525 | /* RFC 2617 3.2.2.2 A1 */ |
| 1526 | var charstring digestA1 := f_sip_digest_A1(user, realm, password); |
| 1527 | |
| 1528 | /* RFC 2617 3.2.2.3 A2 */ |
| 1529 | var charstring digestA2 := f_sip_digest_A2(method, uri); |
| 1530 | |
| 1531 | /* RFC 2617 3.2.2.1 Request-Digest */ |
| 1532 | var charstring req_digest := f_sip_digest_RequestDigest(digestA1, nonce, |
| 1533 | nc, cnonce, |
| 1534 | qop, digestA2); |
| 1535 | return req_digest; |
| 1536 | } |
| 1537 | |
| 1538 | /* Digest Auth: RFC 2617 */ |
| 1539 | function f_sip_digest_gen_Authorization_Response_AKAv1MD5(charstring user, charstring realm, octetstring password, |
| 1540 | charstring method, charstring uri, charstring qop, |
| 1541 | charstring nonce, charstring cnonce, charstring nc) |
| 1542 | return charstring { |
| 1543 | /* RFC 2617 3.2.2.2 A1 */ |
| 1544 | var charstring digestA1 := f_sip_digest_A1_octpwd(user, realm, password); |
| 1545 | /* RFC 2617 3.2.2.3 A2 */ |
| 1546 | var charstring digestA2 := f_sip_digest_A2(method, uri); |
| 1547 | |
| 1548 | /* RFC 2617 3.2.2.1 Request-Digest */ |
| 1549 | var charstring req_digest := f_sip_digest_RequestDigest(digestA1, nonce, |
| 1550 | nc, cnonce, |
| 1551 | qop, digestA2); |
| 1552 | return req_digest; |
| 1553 | } |
| 1554 | |
| 1555 | function f_sip_digest_gen_Authorization_MD5(WwwAuthenticate www_authenticate, |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1556 | charstring user, charstring password, |
| 1557 | charstring method, charstring uri, |
| 1558 | charstring cnonce := "0a4f113b", integer nc_int := 1) return Authorization { |
| 1559 | var CommaParam_List digestCln; |
| 1560 | var template (value) Authorization authorization; |
| 1561 | var template (value) Credentials cred; |
| 1562 | var template (omit) GenericParam rx_param; |
| 1563 | |
| 1564 | digestCln := www_authenticate.challenge[0].digestCln; |
| 1565 | |
| 1566 | var charstring algorithm; |
| 1567 | rx_param := f_sip_param_find(digestCln, "algorithm"); |
| 1568 | if (istemplatekind(rx_param, "omit")) { |
| 1569 | /* Assume MD5 if not set */ |
| 1570 | algorithm := "MD5" |
| 1571 | } else { |
| 1572 | algorithm := valueof(rx_param.paramValue); |
| 1573 | if (f_strstr(algorithm, "MD5") == -1) { |
| 1574 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 1575 | log2str("Unexpected algorithm: ", algorithm)); |
| 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | var charstring realm := f_sip_param_get_value_present_or_fail(digestCln, "realm"); |
| 1580 | var charstring nonce := f_sip_param_get_value_present_or_fail(digestCln, "nonce"); |
| 1581 | var charstring opaque := f_sip_param_get_value_present_or_fail(digestCln, "opaque"); |
| 1582 | var charstring qop := f_sip_param_get_value_present_or_fail(digestCln, "qop"); |
| 1583 | |
| 1584 | if (f_strstr(qop, "auth") == -1) { |
| 1585 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected qop: ", qop)); |
| 1586 | } |
| 1587 | var charstring selected_qop := "auth"; |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1588 | var charstring nc := f_str_tolower(hex2str(int2hex(nc_int, 8))); |
Pau Espin Pedrol | 80b981a | 2024-06-04 18:37:22 +0200 | [diff] [blame] | 1589 | |
| 1590 | var charstring req_digest; |
| 1591 | req_digest := |
| 1592 | f_sip_digest_gen_Authorization_Response_MD5(user, realm, password, |
| 1593 | method, uri, selected_qop, |
| 1594 | nonce, cnonce, nc); |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1595 | |
| 1596 | cred := ts_Credentials_DigestResponseMD5(user, realm, nonce, |
| 1597 | uri, req_digest, |
| 1598 | opaque, algorithm, selected_qop, cnonce, nc); |
| 1599 | |
| 1600 | authorization := ts_Authorization(cred); |
| 1601 | return valueof(authorization); |
| 1602 | } |
| 1603 | |
Pau Espin Pedrol | 80b981a | 2024-06-04 18:37:22 +0200 | [diff] [blame] | 1604 | /* RFC 3310: Same as f_sip_digest_validate_Authorization_MD5(), but using an octet buffer as password (AKAv1-MD5, pwd=RES) */ |
| 1605 | function f_sip_digest_validate_Authorization_AKAv1MD5(Authorization authorization, charstring method, octetstring password) { |
| 1606 | var CommaParam_List auth_pars := authorization.body.digestResponse; |
| 1607 | var template (omit) GenericParam rx_param; |
| 1608 | |
| 1609 | rx_param := f_sip_param_find(auth_pars, "algorithm"); |
| 1610 | if (istemplatekind(rx_param, "omit")) { |
| 1611 | /* Assume MD5 if not set */ |
| 1612 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Algorithm param not present"); |
| 1613 | } else { |
| 1614 | var charstring algorithm := valueof(rx_param.paramValue); |
| 1615 | if (f_strstr(algorithm, "AKAv1-MD5") == -1) { |
| 1616 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 1617 | log2str("Unexpected algorithm: ", algorithm)); |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | var charstring user := f_sip_param_get_value_present_or_fail(auth_pars, "username"); |
| 1622 | var charstring realm := f_sip_param_get_value_present_or_fail(auth_pars, "realm"); |
| 1623 | var charstring uri := f_sip_param_get_value_present_or_fail(auth_pars, "uri"); |
| 1624 | var charstring nonce := f_sip_param_get_value_present_or_fail(auth_pars, "nonce"); |
| 1625 | var charstring qop := f_sip_param_get_value_present_or_fail(auth_pars, "qop"); |
| 1626 | var charstring response := f_sip_param_get_value_present_or_fail(auth_pars, "response"); |
| 1627 | var charstring cnonce := f_sip_param_get_value_present_or_fail(auth_pars, "cnonce"); |
| 1628 | var charstring nc := f_sip_param_get_value_present_or_fail(auth_pars, "nc"); |
| 1629 | |
| 1630 | if (f_strstr(qop, "auth") == -1) { |
| 1631 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected qop: ", qop)); |
| 1632 | } |
| 1633 | |
| 1634 | var charstring exp_response := |
| 1635 | f_sip_digest_gen_Authorization_Response_AKAv1MD5(f_sip_str_unquote(user), |
| 1636 | f_sip_str_unquote(realm), |
| 1637 | password, |
| 1638 | method, |
| 1639 | f_sip_str_unquote(uri), |
| 1640 | qop, |
| 1641 | f_sip_str_unquote(nonce), |
| 1642 | f_sip_str_unquote(cnonce), |
| 1643 | nc); |
| 1644 | |
| 1645 | response := f_sip_str_unquote(response); |
| 1646 | if (response != exp_response) { |
| 1647 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 1648 | log2str("Wrong digest response: ", response, |
| 1649 | " vs exp: ", exp_response, ". Params: ", auth_pars)); |
| 1650 | } |
| 1651 | } |
| 1652 | |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1653 | /* RFC 2617 3.5 Example */ |
| 1654 | function f_sip_digest_selftest() { |
| 1655 | /* |
| 1656 | The following example assumes that an access-protected document is |
| 1657 | being requested from the server via a GET request. The URI of the |
| 1658 | document is "http://www.nowhere.org/dir/index.html". Both client and |
| 1659 | server know that the username for this document is "Mufasa", and the |
| 1660 | password is "Circle Of Life" (with one space between each of the |
| 1661 | three words). |
| 1662 | |
| 1663 | HTTP/1.1 401 Unauthorized |
| 1664 | WWW-Authenticate: Digest |
| 1665 | realm="testrealm@host.com", |
| 1666 | qop="auth,auth-int", |
| 1667 | nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", |
| 1668 | opaque="5ccc069c403ebaf9f0171e9517f40e41" |
| 1669 | |
| 1670 | Authorization: Digest username="Mufasa", |
| 1671 | realm="testrealm@host.com", |
| 1672 | nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", |
| 1673 | uri="/dir/index.html", |
| 1674 | qop=auth, |
| 1675 | nc=00000001, |
| 1676 | cnonce="0a4f113b", |
| 1677 | response="6629fae49393a05397450978507c4ef1", |
| 1678 | opaque="5ccc069c403ebaf9f0171e9517f40e41" |
| 1679 | */ |
| 1680 | var template (value) CommaParam_List digestCln := { |
| 1681 | ts_Param("realm", f_sip_str_quote("testrealm@host.com")), |
| 1682 | ts_Param("qop", f_sip_str_quote("auth,auth-int")), |
| 1683 | ts_Param("nonce", f_sip_str_quote("dcd98b7102dd2f0e8b11d0f600bfb0c093")), |
| 1684 | ts_Param("opaque", f_sip_str_quote("5ccc069c403ebaf9f0171e9517f40e41")) |
| 1685 | }; |
| 1686 | var template (value) WwwAuthenticate www_authenticate := |
| 1687 | ts_WwwAuthenticate( { ts_Challenge_digestCln(digestCln) } ) |
| 1688 | |
| 1689 | var Authorization authorization := |
Pau Espin Pedrol | 80b981a | 2024-06-04 18:37:22 +0200 | [diff] [blame] | 1690 | f_sip_digest_gen_Authorization_MD5(valueof(www_authenticate), |
| 1691 | "Mufasa", |
| 1692 | "Circle Of Life", |
| 1693 | "GET", |
| 1694 | "/dir/index.html", |
| 1695 | cnonce := "0a4f113b", |
| 1696 | nc_int := 1); |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1697 | |
| 1698 | var CommaParam_List digestResp := authorization.body.digestResponse; |
| 1699 | f_sip_param_match_value_or_fail(digestResp, "realm", f_sip_str_quote("testrealm@host.com")); |
| 1700 | f_sip_param_match_value_or_fail(digestResp, "nonce", f_sip_str_quote("dcd98b7102dd2f0e8b11d0f600bfb0c093")); |
| 1701 | f_sip_param_match_value_or_fail(digestResp, "uri", f_sip_str_quote("/dir/index.html")); |
| 1702 | f_sip_param_match_value_or_fail(digestResp, "qop", "auth"); |
| 1703 | f_sip_param_match_value_or_fail(digestResp, "nc", "00000001"); |
| 1704 | f_sip_param_match_value_or_fail(digestResp, "cnonce", f_sip_str_quote("0a4f113b")); |
| 1705 | f_sip_param_match_value_or_fail(digestResp, "response", f_sip_str_quote("6629fae49393a05397450978507c4ef1")); |
| 1706 | f_sip_param_match_value_or_fail(digestResp, "opaque", f_sip_str_quote("5ccc069c403ebaf9f0171e9517f40e41")); |
| 1707 | } |
| 1708 | |
Pau Espin Pedrol | 6052a34 | 2024-03-28 20:20:46 +0100 | [diff] [blame] | 1709 | /* RFC 3261 8.1.1.5: |
| 1710 | * "The sequence number value MUST be expressible as a 32-bit unsigned integer |
| 1711 | * and MUST be less than 2**31." |
| 1712 | */ |
| 1713 | function f_sip_rand_seq_nr() return integer { |
| 1714 | /* 2**31 = 2147483648 */ |
| 1715 | return f_rnd_int(2147483648) |
| 1716 | } |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 1717 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 1718 | function f_sip_next_seq_nr(integer seq_nr) return integer { |
| 1719 | return (seq_nr + 1) mod 2147483648; |
| 1720 | } |
| 1721 | |
| 1722 | function f_sip_Request_inc_seq_nr(inout template (value) PDU_SIP_Request req) { |
| 1723 | req.msgHeader.cSeq.seqNumber := f_sip_next_seq_nr(valueof(req.msgHeader.cSeq.seqNumber)); |
| 1724 | } |
| 1725 | |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1726 | function f_sip_rand_tag() return charstring { |
Pau Espin Pedrol | 95ad6a0 | 2024-04-18 16:52:46 +0200 | [diff] [blame] | 1727 | /* Tags shall have at least 32 bit of randomness */ |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1728 | var integer rnd_int := f_rnd_int(4294967296); |
Pau Espin Pedrol | 95ad6a0 | 2024-04-18 16:52:46 +0200 | [diff] [blame] | 1729 | /* Make collisions harder by appending time to the final string: */ |
| 1730 | var integer ts_int := f_time_ms() mod 4294967296; |
| 1731 | return hex2str(int2hex(rnd_int, 8)) & "-" & hex2str(int2hex(ts_int, 8)); |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | /* Generate a "branch" tag value. |
| 1735 | * RFC 3261 p.105 section 8: |
| 1736 | * "A common way to create this value is to compute a |
| 1737 | * cryptographic hash of the To tag, From tag, Call-ID header |
| 1738 | * field, the Request-URI of the request received (before |
| 1739 | * translation), the topmost Via header, and the sequence number |
| 1740 | * from the CSeq header field, in addition to any Proxy-Require |
| 1741 | * and Proxy-Authorization header fields that may be present. The |
| 1742 | * algorithm used to compute the hash is implementation-dependent, |
| 1743 | * but MD5 (RFC 1321 [35]),expressed in hexadecimal, is a reasonable |
| 1744 | * choice." |
| 1745 | * See also Section 8.1.1.7: |
| 1746 | * "The branch ID inserted by an element compliant with this |
| 1747 | * specification MUST always begin with the characters "z9hG4bK"." |
| 1748 | */ |
| 1749 | const charstring sip_magic_cookie := "z9hG4bK"; |
| 1750 | function f_sip_gen_branch(charstring tag_to, |
| 1751 | charstring tag_from, |
| 1752 | charstring tag_call_id, |
| 1753 | integer cseq) return charstring { |
| 1754 | var charstring str := tag_to & tag_from & tag_call_id & int2str(cseq); |
| 1755 | var charstring hash := f_calculateMD5(str); |
| 1756 | var charstring branch := sip_magic_cookie & hash; |
| 1757 | return branch; |
| 1758 | } |
| 1759 | |
| 1760 | function f_sip_HostPort_to_str(HostPort host_port) return charstring { |
| 1761 | var charstring str := ""; |
| 1762 | if (ispresent(host_port.host)) { |
| 1763 | str := host_port.host; |
| 1764 | } |
| 1765 | if (ispresent(host_port.portField)) { |
| 1766 | str := str & ":" & int2str(host_port.portField); |
| 1767 | } |
| 1768 | return str; |
| 1769 | } |
| 1770 | |
| 1771 | function f_sip_SipUrl_to_str(SipUrl uri) return charstring { |
Pau Espin Pedrol | b0dbf7a | 2024-05-22 18:12:15 +0200 | [diff] [blame] | 1772 | var charstring str := uri.scheme & ":"; |
| 1773 | if (ispresent(uri.userInfo)) { |
| 1774 | str := str & uri.userInfo.userOrTelephoneSubscriber & "@"; |
| 1775 | } |
| 1776 | str := str & f_sip_HostPort_to_str(uri.hostPort); |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1777 | return str; |
| 1778 | } |
| 1779 | |
| 1780 | function f_sip_NameAddr_to_str(NameAddr naddr) return charstring { |
| 1781 | if (ispresent(naddr.displayName)) { |
| 1782 | return naddr.displayName & " <" & f_sip_SipUrl_to_str(naddr.addrSpec) & ">"; |
| 1783 | } else { |
| 1784 | return f_sip_SipUrl_to_str(naddr.addrSpec); |
| 1785 | } |
| 1786 | } |
| 1787 | |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 1788 | function f_sip_Addr_Union_to_str(Addr_Union addru) return charstring { |
| 1789 | if (ischosen(addru.nameAddr)) { |
| 1790 | return f_sip_NameAddr_to_str(addru.nameAddr); |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1791 | } else { |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 1792 | return f_sip_SipUrl_to_str(addru.addrSpecUnion); |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 1793 | } |
| 1794 | } |
| 1795 | |
Pau Espin Pedrol | 41b0e07 | 2024-05-29 18:25:51 +0200 | [diff] [blame] | 1796 | function f_sip_SipAddr_to_str(SipAddr sip_addr) return charstring { |
| 1797 | return f_sip_Addr_Union_to_str(sip_addr.addr); |
| 1798 | } |
| 1799 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 1800 | } |