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