sip_parser.c 16.3 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
8
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

/**@ingroup sip_parser
 * @CFILE sip_parser.c
 *
 * SIP parser.
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>.
 *
 * @date Created: Thu Oct  5 14:01:24 2000 ppessi
 */

#include "config.h"

37 38 39 40 41 42 43 44
/* Avoid casting sip_t to msg_pub_t and sip_header_t to msg_header_t */
#define MSG_PUB_T       struct sip_s
#define MSG_HDR_T       union sip_header_u

#include <sofia-sip/su_tagarg.h>
#include "sofia-sip/sip_parser.h"
#include <sofia-sip/msg_mclass.h>

Pekka Pessi's avatar
Pekka Pessi committed
45 46 47 48 49 50 51
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <limits.h>

52 53 54 55
#ifndef UINT32_MAX
#define UINT32_MAX (0xffffffffU)
#endif

Pekka Pessi's avatar
Pekka Pessi committed
56 57 58 59 60 61 62
/** Version of the SIP module */
char const sip_parser_version[] = VERSION;

/** SIP version 2.0. */
char const sip_version_2_0[] = "SIP/2.0";

/** Default message class */
63
extern msg_mclass_t sip_mclass[];
Pekka Pessi's avatar
Pekka Pessi committed
64

65 66 67
static msg_mclass_t const *_default = sip_mclass;

/** Return a built-in SIP parser object. */
68
msg_mclass_t const *sip_default_mclass(void)
Pekka Pessi's avatar
Pekka Pessi committed
69
{
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  return _default;
}

/** Update the default SIP parser.
 *
 * Use the extended SIP parser as default one.
 *
 * If the applications want to use headers added after @VERSION_1_12_5,
 * they should call this function before doing any other initialization, e.g.,
 * @code
 *   su_init();
 *   if (sip_update_default_mclass(sip_extend_mclass(NULL)) < 0) {
 *     su_deinit();
 *     exit(2);
 *   }
 * @endcode
 *
 * The default parser is not extended because it may break the old
 * applications looking for extension headers from sip_unknown list.
 *
 * @retval 0 when successful
 * @retval -1 upon an error
 *
Pekka Pessi's avatar
Pekka Pessi committed
93
 * @NEW_1_12_7.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
 */
int sip_update_default_mclass(msg_mclass_t const *mclass)
{
  if (mclass == NULL)
    return -1;
  _default = mclass;
  return 0;
}

/**Extend SIP parser class with extension headers.
 *
 * Extend given SIP parser class with extension headers. If the given parser
 * class is the default one or NULL, make a clone of it before extending it.
 *
 * @param input pointer to a SIP message class (may be NULL)
 *
 * @return Pointer to extended mclass, or NULL upon an error.
 *
Pekka Pessi's avatar
Pekka Pessi committed
112
 * @NEW_1_12_7.
113 114 115 116 117 118 119 120 121 122 123
 */
msg_mclass_t *sip_extend_mclass(msg_mclass_t *input)
{
  msg_mclass_t *mclass;

  if (input == NULL || input == _default)
    mclass = msg_mclass_clone(_default, 0, 0);
  else
    mclass = input;

  if (mclass) {
124
    extern msg_hclass_t * const sip_extensions[];
125 126 127
    int i;

    for (i = 0; sip_extensions[i]; i++) {
128
      msg_hclass_t *hclass = sip_extensions[i];
129 130 131 132 133 134 135 136 137 138 139 140
      if (mclass->mc_unknown != msg_find_hclass(mclass, hclass->hc_name, NULL))
	continue;

      if (msg_mclass_insert_header(mclass, hclass, 0) < 0) {
	if (input != mclass)
	  free(mclass);
	return mclass = NULL;
      }
    }
  }

  return mclass;
Pekka Pessi's avatar
Pekka Pessi committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154
}

/** Extract the SIP message body, including separator line. 
 *
 * @param msg  message object [IN]
 * @param sip  public SIP message structure [IN/OUT]
 * @param b    buffer containing unparsed data [IN]
 * @param bsiz buffer size [IN]
 * @param eos  true if buffer contains whole message [IN]
 *
 * @retval -1 error
 * @retval 0  cannot proceed
 * @retval m 
 */
155
issize_t sip_extract_body(msg_t *msg, sip_t *sip, char b[], isize_t bsiz, int eos)
Pekka Pessi's avatar
Pekka Pessi committed
156
{
157 158
  ssize_t m = 0;
  size_t body_len;
Pekka Pessi's avatar
Pekka Pessi committed
159 160 161
  
  if (!(sip->sip_flags & MSG_FLG_BODY)) {
    /* We are looking at a potential empty line */
Pekka Pessi's avatar
Pekka Pessi committed
162
    m = msg_extract_separator(msg, (msg_pub_t *)sip, b, bsiz, eos);
Pekka Pessi's avatar
Pekka Pessi committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    if (m <= 0)
      return m;
    sip->sip_flags |= MSG_FLG_BODY;
    b += m;
    bsiz -= m;
  }

  if (sip->sip_content_length)
    body_len = sip->sip_content_length->l_length;
  else if (MSG_IS_MAILBOX(sip->sip_flags)) /* message fragments */
    body_len = 0;
  else if (eos)
    body_len = bsiz;
  else if (bsiz == 0)
    return m;
  else
    return -1;

  if (body_len == 0) {
    sip->sip_flags |= MSG_FLG_COMPLETE;
    return m;
  }

  if (m)
    return m;

  if (eos && body_len > bsiz) {
    sip->sip_flags |= MSG_FLG_TRUNC | MSG_FLG_ERROR;
    return bsiz;
  }

Pekka Pessi's avatar
Pekka Pessi committed
194 195
  if ((m = msg_extract_payload(msg, (msg_pub_t *)sip, 
			       NULL, body_len, b, bsiz, eos)) == -1)
Pekka Pessi's avatar
Pekka Pessi committed
196 197 198 199 200 201 202 203 204 205 206
    return -1;
  
  sip->sip_flags |= MSG_FLG_FRAGS;
  if (bsiz >= body_len)
    sip->sip_flags |= MSG_FLG_COMPLETE;

  return m;
}

/** Parse SIP version.
 *
207
 * Parse a SIP version string. Update the 
Pekka Pessi's avatar
Pekka Pessi committed
208 209 210 211 212 213 214 215 216 217 218 219
 * pointer at @a ss to first non-LWS character after the version string.
 *
 * @param ss   string to be parsed [IN/OUT]
 * @param ver  value result for version [OUT]
 *
 * @retval 0 when successful,
 * @retval -1 upon an error.
 */
int sip_version_d(char **ss, char const **ver)
{
  char *s = *ss;
  char const *result;
220
  size_t const version_size = sizeof(sip_version_2_0) - 1;
Pekka Pessi's avatar
Pekka Pessi committed
221 222 223 224 225 226 227 228

  if (strncasecmp(s, sip_version_2_0, version_size) == 0 && 
      !IS_TOKEN(s[version_size])) {
    result = sip_version_2_0;
    s += version_size;
  }
  else {
    /* Version consists of two tokens, separated by / */
229
    size_t l1 = 0, l2 = 0, n;
Pekka Pessi's avatar
Pekka Pessi committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268

    result = s;

    l1 = span_token(s);
    for (n = l1; IS_LWS(s[n]); n++);
    if (s[n] == '/') {
      for (n++; IS_LWS(s[n]); n++);
      l2 = span_token(s + n);
      n += l2;
    }

    if (l1 == 0 || l2 == 0)
      return -1;

    /* If there is extra ws between tokens, compact version */
    if (n > l1 + 1 + l2) {
      s[l1] = '/';
      memmove(s + l1 + 1, s + n - l2, l2);
      s[l1 + 1 + l2] = 0;

      /* Compare again with compacted version */ 
      if (strcasecmp(s, sip_version_2_0) == 0)
	result = sip_version_2_0;
    }

    s += n;
  }

  while (IS_WS(*s)) *s++ = '\0';
  
  *ss = s;

  if (ver) 
    *ver = result;

  return 0;
}

/** Calculate extra space required by version string */
269
isize_t sip_version_xtra(char const *version)
Pekka Pessi's avatar
Pekka Pessi committed
270 271 272
{
  if (version == SIP_VERSION_CURRENT)
    return 0;
Pekka Pessi's avatar
Pekka Pessi committed
273
  return MSG_STRING_SIZE(version);
Pekka Pessi's avatar
Pekka Pessi committed
274 275 276 277 278 279 280 281
}

/** Duplicate a transport string */
void sip_version_dup(char **pp, char const **dd, char const *s)
{
  if (s == SIP_VERSION_CURRENT)
    *dd = s;
  else
Pekka Pessi's avatar
Pekka Pessi committed
282
    MSG_STRING_DUP(*pp, *dd, s);
Pekka Pessi's avatar
Pekka Pessi committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
}

char const sip_method_name_invite[] =  	 "INVITE";
char const sip_method_name_ack[] =     	 "ACK";
char const sip_method_name_cancel[] =  	 "CANCEL";
char const sip_method_name_bye[] =     	 "BYE";
char const sip_method_name_options[] = 	 "OPTIONS";
char const sip_method_name_register[] =  "REGISTER";
char const sip_method_name_info[] =      "INFO";
char const sip_method_name_prack[] =     "PRACK";
char const sip_method_name_update[] =    "UPDATE";
char const sip_method_name_message[] =   "MESSAGE";
char const sip_method_name_subscribe[] = "SUBSCRIBE";
char const sip_method_name_notify[] =    "NOTIFY";
char const sip_method_name_refer[] =     "REFER";
char const sip_method_name_publish[] =   "PUBLISH";

/** Well-known SIP method names. */
char const * const sip_method_names[] = {
  "<UNKNOWN>",
  sip_method_name_invite,
  sip_method_name_ack,
  sip_method_name_cancel,
  sip_method_name_bye,
  sip_method_name_options,
  sip_method_name_register,
  sip_method_name_info,
  sip_method_name_prack,
  sip_method_name_update,
  sip_method_name_message,
  sip_method_name_subscribe,
  sip_method_name_notify,
  sip_method_name_refer,
  sip_method_name_publish,
  /* If you add something here, add also them to sip_method_d! */
  NULL
};

/** Get canonic method name. */
char const *sip_method_name(sip_method_t method, char const *name)
{
  const size_t N = sizeof(sip_method_names)/sizeof(sip_method_names[0]);
325
  if (method > 0 && (size_t)method <= N)
Pekka Pessi's avatar
Pekka Pessi committed
326 327 328 329 330 331 332 333 334
    return sip_method_names[method];
  else if (method == 0)
    return name;
  else
    return NULL;
}

/**Parse a SIP method name.
 *
335 336 337
 * Parse a SIP method name and return a code corresponding to the method. 
 * The address of the first non-LWS character after method name is stored in
 * @a *ss.
Pekka Pessi's avatar
Pekka Pessi committed
338 339 340 341 342
 *
 * @param ss    pointer to pointer to string to be parsed
 * @param return_name  value-result parameter for method name
 *
 * @note
343
 * If there is no whitespace after method name, the value in @a *return_name
Pekka Pessi's avatar
Pekka Pessi committed
344 345 346
 * may not be NUL-terminated.  The calling function @b must NUL terminate
 * the value by setting the @a **ss to NUL after first examining its value.
 *
347
 * @return The method code if method
Pekka Pessi's avatar
Pekka Pessi committed
348 349 350
 * was identified, 0 (sip_method_unknown()) if method is not known, or @c -1
 * (sip_method_invalid()) if an error occurred.
 *
351 352
 * If the value-result argument @a return_name is not @c NULL,
 * a pointer to the method name is stored to it.
Pekka Pessi's avatar
Pekka Pessi committed
353 354 355 356 357 358
 */
sip_method_t sip_method_d(char **ss, char const **return_name)
{
  char *s = *ss, c = *s;
  char const *name;
  int code = sip_method_unknown;
359
  size_t n = 0;
Pekka Pessi's avatar
Pekka Pessi committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441

#define MATCH(s, m) (strncmp(s, m, n = sizeof(m) - 1) == 0)

  switch (c) {
  case 'A': if (MATCH(s, "ACK")) code = sip_method_ack; break;
  case 'B': if (MATCH(s, "BYE")) code = sip_method_bye; break;
  case 'C': 
    if (MATCH(s, "CANCEL")) 
      code = sip_method_cancel; 
    break;
  case 'I': 
    if (MATCH(s, "INVITE"))
      code = sip_method_invite;
    else if (MATCH(s, "INFO"))
      code = sip_method_info;
    break;
  case 'M': if (MATCH(s, "MESSAGE")) code = sip_method_message; break;
  case 'N': if (MATCH(s, "NOTIFY")) code = sip_method_notify; break;
  case 'O': if (MATCH(s, "OPTIONS")) code = sip_method_options; break;
  case 'P': 
    if (MATCH(s, "PRACK")) code = sip_method_prack; 
    else if (MATCH(s, "PUBLISH")) code = sip_method_publish; 
    break;
  case 'R': 
    if (MATCH(s, "REGISTER")) 
      code = sip_method_register; 
    else if (MATCH(s, "REFER"))
      code = sip_method_refer; 
    break;
  case 'S': 
    if (MATCH(s, "SUBSCRIBE")) 
      code = sip_method_subscribe; 
    break;
  case 'U':
    if (MATCH(s, "UPDATE"))
      code = sip_method_update;
    break;
  }

#undef MATCH

  if (IS_NON_WS(s[n])) 
    /* Unknown method */
    code = sip_method_unknown;

  if (code == sip_method_unknown) {
    name = s;
    for (n = 0; IS_UNRESERVED(s[n]); n++)
      ;
    if (s[n]) {
      if (!IS_LWS(s[n]))
	return sip_method_invalid;
      if (return_name)
	s[n++] = '\0';
    }
  }
  else {
    name = sip_method_names[code];
  }

  while (IS_LWS(s[n]))
    n++;

  *ss = (s + n);
  if (return_name) *return_name = name;

  return code;
}

/** Get method enum corresponding to method name */
sip_method_t sip_method_code(char const *name)
{
  /* Note that sip_method_d() does not change string if return_name is NULL */
  return sip_method_d((char **)&name, NULL);
}

char const sip_transport_udp[] = "SIP/2.0/UDP";
char const sip_transport_tcp[] = "SIP/2.0/TCP";
char const sip_transport_sctp[] = "SIP/2.0/SCTP";
char const sip_transport_tls[] = "SIP/2.0/TLS";

/** Decode transport */
442
issize_t sip_transport_d(char **ss, char const **ttransport)
Pekka Pessi's avatar
Pekka Pessi committed
443 444 445
{
  char const *transport;
  char *pn, *pv, *pt;
446
  size_t pn_len, pv_len, pt_len;
Pekka Pessi's avatar
Pekka Pessi committed
447 448
  char *s = *ss;

449 450 451
#define TRANSPORT_MATCH(t)					     \
  (strncasecmp(s+7, t+7, sizeof(t)-8) == 0 && (IS_LWS(s[sizeof(t)])) \
   && (transport = t, s += sizeof(t) - 1))
Pekka Pessi's avatar
Pekka Pessi committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510

  if (strncasecmp(s, "SIP/2.0", 7) != 0 ||
      (!TRANSPORT_MATCH(sip_transport_udp) &&
       !TRANSPORT_MATCH(sip_transport_tcp) &&
       !TRANSPORT_MATCH(sip_transport_sctp) &&
       !TRANSPORT_MATCH(sip_transport_tls))) {
    /* Protocol name */ 
    transport = pn = s;
    skip_token(&s);
    pn_len = s - pn;
    skip_lws(&s);
    if (pn_len == 0 || *s++ != '/') return -1;
    skip_lws(&s);
    
    /* Protocol version */
    pv = s;
    skip_token(&s);
    pv_len = s - pv;
    skip_lws(&s);
    if (pv_len == 0 || *s++ != '/') return -1;
    skip_lws(&s);
    
    /* Transport protocol */
    pt = s;
    skip_token(&s);
    pt_len = s - pt;
    if (pt_len == 0) return -1;
    
    /* Remove whitespace between protocol name and version */
    if (pn + pn_len + 1 != pv) {
      pn[pn_len] = '/';
      pv = memmove(pn + pn_len + 1, pv, pv_len);
    }

    /* Remove whitespace between protocol version and transport */
    if (pv + pv_len + 1 != pt) {
      pv[pv_len] = '/';
      pt = memmove(pv + pv_len + 1, pt, pt_len);
      pt[pt_len] = '\0';
      
      /* extra whitespace? */
      if (!strcasecmp(transport, sip_transport_udp))
	transport = sip_transport_udp;
      else if (!strcasecmp(transport, sip_transport_tcp))
	transport = sip_transport_tcp;
      else if (!strcasecmp(transport, sip_transport_sctp))
	transport = sip_transport_sctp;
      else if (!strcasecmp(transport, sip_transport_tls))
	transport = sip_transport_tls;
    }
  }

  if (IS_LWS(*s)) { *s++ = '\0'; skip_lws(&s); }
  *ss = s;
  *ttransport = transport;
  return 0;
}

/** Calculate extra space required by sip_transport_dup() */
511
isize_t sip_transport_xtra(char const *transport)
Pekka Pessi's avatar
Pekka Pessi committed
512 513 514 515 516 517 518 519 520 521 522
{
  if (transport == sip_transport_udp ||
      transport == sip_transport_tcp ||
      transport == sip_transport_sctp ||
      transport == sip_transport_tls ||
      strcasecmp(transport, sip_transport_udp) == 0 ||
      strcasecmp(transport, sip_transport_tcp) == 0 ||
      strcasecmp(transport, sip_transport_sctp) == 0 ||
      strcasecmp(transport, sip_transport_tls) == 0)
    return 0;

Pekka Pessi's avatar
Pekka Pessi committed
523
  return MSG_STRING_SIZE(transport);
Pekka Pessi's avatar
Pekka Pessi committed
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
}

/** Duplicate a transport string */
void sip_transport_dup(char **pp, char const **dd, char const *s)
{
  if (s == sip_transport_udp)
    *dd = s;
  else if (s == sip_transport_tcp)
    *dd = s;
  else if (s == sip_transport_sctp)
    *dd = s;
  else if (s == sip_transport_tls)
    *dd = s;
  else if (strcasecmp(s, sip_transport_udp) == 0)
    *dd = sip_transport_udp;
  else if (strcasecmp(s, sip_transport_tcp) == 0)
    *dd = sip_transport_tcp;
  else if (strcasecmp(s, sip_transport_sctp) == 0)
    *dd = sip_transport_sctp;
  else if (strcasecmp(s, sip_transport_tls) == 0)
    *dd = sip_transport_tls;
  else
Pekka Pessi's avatar
Pekka Pessi committed
546
    MSG_STRING_DUP(*pp, *dd, s);
Pekka Pessi's avatar
Pekka Pessi committed
547 548
}

549
/** Parse SIP <word "@" word> construct used in @CallID. */
Pekka Pessi's avatar
Pekka Pessi committed
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
char *sip_word_at_word_d(char **ss)
{
  char *rv = *ss, *s0 = *ss;

  skip_word(ss);
  if (s0 == *ss)
    return NULL;
  if (**ss == '@') {
    (*ss)++;
    s0 = *ss;
    skip_word(ss);
    if (s0 == *ss)
      return NULL;
  }
  if (IS_LWS(**ss))
    (*ss)++;
  skip_lws(ss);

  return rv;
}

/**Add message separator, then test if message is complete. 
 *
Pekka Pessi's avatar
Pekka Pessi committed
573
 * Add sip_content_length and sip_separator if they are missing. 
574 575
 * The test that all necessary message components ( @From, @To,
 * @CSeq, @CallID, @ContentLength and message separator are present.
Pekka Pessi's avatar
Pekka Pessi committed
576 577
 *
 * @retval 0 when successful
578
 * @retval -1 upon an error: headers are missing and they could not be added
Pekka Pessi's avatar
Pekka Pessi committed
579 580 581 582 583
 */
int sip_complete_message(msg_t *msg)
{
  sip_t *sip = sip_object(msg);
  su_home_t *home = msg_home(msg);
584 585
  size_t len = 0;
  ssize_t mplen;
Pekka Pessi's avatar
Pekka Pessi committed
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608

  if (sip == NULL)
    return -1;

  if (!sip->sip_separator)
    sip->sip_separator = sip_separator_create(msg_home(msg));

  if (sip->sip_multipart) {
    sip_content_type_t *c = sip->sip_content_type;
    msg_multipart_t *mp = sip->sip_multipart;
    sip_common_t *head;

    if (!c || msg_multipart_complete(msg_home(msg), c, mp) < 0)
      return -1;

    if (sip->sip_payload)
      head = sip->sip_payload->pl_common;
    else
      head = sip->sip_separator->sep_common;

    if (!head || !msg_multipart_serialize(&head->h_succ, mp))
      return -1;

609 610
    mplen = msg_multipart_prepare(msg, mp, sip->sip_flags);
    if (mplen == -1)
Pekka Pessi's avatar
Pekka Pessi committed
611
      return -1;
612
    len = (size_t)mplen;
Pekka Pessi's avatar
Pekka Pessi committed
613 614 615 616 617
  } 

  if (sip->sip_payload)
    len += sip->sip_payload->pl_len;

618 619 620
  if (len > UINT32_MAX)
    return -1;

Pekka Pessi's avatar
Pekka Pessi committed
621
  if (!sip->sip_content_length) {
Pekka Pessi's avatar
Pekka Pessi committed
622
    msg_header_insert(msg, (msg_pub_t *)sip, (msg_header_t*)
623
		      sip_content_length_create(home, (uint32_t)len));
Pekka Pessi's avatar
Pekka Pessi committed
624 625 626
  }
  else {
    if (sip->sip_content_length->l_length != len) {
627
      sip->sip_content_length->l_length = (uint32_t)len;
Pekka Pessi's avatar
Pekka Pessi committed
628 629 630 631 632 633 634 635 636 637 638 639 640 641
      sip_fragment_clear(sip->sip_content_length->l_common);
    }
  }
  
  if (!sip->sip_cseq || 
      !sip->sip_call_id ||
      !sip->sip_to ||
      !sip->sip_from ||
      !sip->sip_separator ||
      !sip->sip_content_length)
    return -1;
  
  return 0;
}