James Kuszmaul | 82f6c04 | 2021-01-17 11:30:16 -0800 | [diff] [blame] | 1 | /** |
| 2 | * @file sip/addr.c SIP Address decode |
| 3 | * |
| 4 | * Copyright (C) 2010 Creytiv.com |
| 5 | */ |
| 6 | #include <string.h> |
| 7 | #include <re_types.h> |
| 8 | #include <re_fmt.h> |
| 9 | #include <re_mbuf.h> |
| 10 | #include <re_uri.h> |
| 11 | #include <re_list.h> |
| 12 | #include <re_sa.h> |
| 13 | #include <re_msg.h> |
| 14 | #include <re_sip.h> |
| 15 | |
| 16 | |
| 17 | /** |
| 18 | * Decode a pointer-length string into a SIP Address object |
| 19 | * |
| 20 | * @param addr SIP Address object |
| 21 | * @param pl Pointer-length string |
| 22 | * |
| 23 | * @return 0 for success, otherwise errorcode |
| 24 | */ |
| 25 | int sip_addr_decode(struct sip_addr *addr, const struct pl *pl) |
| 26 | { |
| 27 | int err; |
| 28 | |
| 29 | if (!addr || !pl) |
| 30 | return EINVAL; |
| 31 | |
| 32 | memset(addr, 0, sizeof(*addr)); |
| 33 | |
| 34 | if (0 == re_regex(pl->p, pl->l, "[~ \t\r\n<]*[ \t\r\n]*<[^>]+>[^]*", |
| 35 | &addr->dname, NULL, &addr->auri, &addr->params)) { |
| 36 | |
| 37 | if (!addr->dname.l) |
| 38 | addr->dname.p = NULL; |
| 39 | |
| 40 | if (!addr->params.l) |
| 41 | addr->params.p = NULL; |
| 42 | } |
| 43 | else { |
| 44 | memset(addr, 0, sizeof(*addr)); |
| 45 | |
| 46 | if (re_regex(pl->p, pl->l, "[^;]+[^]*", |
| 47 | &addr->auri, &addr->params)) |
| 48 | return EBADMSG; |
| 49 | } |
| 50 | |
| 51 | err = uri_decode(&addr->uri, &addr->auri); |
| 52 | if (err) |
| 53 | memset(addr, 0, sizeof(*addr)); |
| 54 | |
| 55 | return err; |
| 56 | } |