* Parse contacts in a Contact HF */
| 178 | * Parse contacts in a Contact HF |
| 179 | */ |
| 180 | int parse_contacts(str* _s, contact_t** _c) |
| 181 | { |
| 182 | contact_t* c; |
| 183 | contact_t* last; |
| 184 | param_hooks_t hooks; |
| 185 | |
| 186 | last = NULL; |
| 187 | |
| 188 | while(1) { |
| 189 | /* Allocate and clear contact structure */ |
| 190 | c = (contact_t*)pkg_malloc(sizeof(contact_t)); |
| 191 | if (c == 0) { |
| 192 | LM_ERR("no pkg memory left\n"); |
| 193 | goto error; |
| 194 | } |
| 195 | memset(c, 0, sizeof(contact_t)); |
| 196 | |
| 197 | c->name.s = _s->s; |
| 198 | |
| 199 | if (skip_name(_s) < 0) { |
| 200 | LM_ERR("failed to skip name part\n"); |
| 201 | goto error; |
| 202 | } |
| 203 | |
| 204 | c->uri.s = _s->s; |
| 205 | c->name.len = _s->s - c->name.s; |
| 206 | trim_trailing(&c->name); |
| 207 | |
| 208 | /* Find the end of the URI */ |
| 209 | if (skip_uri(_s) < 0) { |
| 210 | LM_ERR("failed to skip URI\n"); |
| 211 | goto error; |
| 212 | } |
| 213 | |
| 214 | c->uri.len = _s->s - c->uri.s; /* Calculate URI length */ |
| 215 | trim_trailing(&(c->uri)); /* Remove any trailing spaces from URI */ |
| 216 | |
| 217 | /* Remove <> if any */ |
| 218 | if ((c->uri.len >= 2) && (c->uri.s[0] == '<') && |
| 219 | (c->uri.s[c->uri.len - 1] == '>')) { |
| 220 | c->uri.s++; |
| 221 | c->uri.len -= 2; |
| 222 | } |
| 223 | |
| 224 | trim(&c->uri); |
| 225 | |
| 226 | /* RFC3261 grammar enforces the existence of an URI */ |
| 227 | if (c->uri.len==0) { |
| 228 | LM_ERR("Empty URI found in contact body\n"); |
| 229 | goto error; |
| 230 | } |
| 231 | |
| 232 | if (_s->len == 0) goto ok; |
| 233 | |
| 234 | if (_s->s[0] == ';') { /* Contact parameter found */ |
| 235 | _s->s++; |
| 236 | _s->len--; |
| 237 | trim_leading(_s); |
no test coverage detected