sip_extra.c 24.8 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
 * 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
 *
 */

/**@CFILE sip_extra.c
 * @brief Non-critical SIP headers
 * 
28 29 30
 * This file contains implementation of @CallInfo, @ErrorInfo,
 * @Organization, @Priority, @RetryAfter, @Server, @Subject,
 * @Timestamp, and @UserAgent headers.
Pekka Pessi's avatar
Pekka Pessi committed
31 32 33 34 35 36 37 38
 * 
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>.
 * 
 * @date Created: Tue Jun 13 02:57:51 2000 ppessi
 */

#include "config.h"

39 40 41 42 43
/* 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/sip_parser.h"
44
#include "sofia-sip/sip_extra.h"
45

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

51
#include <assert.h>
Pekka Pessi's avatar
Pekka Pessi committed
52 53 54

/* ====================================================================== */

55
static issize_t sip_info_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen);
56

57
static isize_t sip_info_dup_xtra(sip_header_t const *h, isize_t offset);
58 59 60
static char *sip_info_dup_one(sip_header_t *dst,
			      sip_header_t const *src,
			      char *b,
61
			      isize_t xtra);
62 63 64 65 66

#define sip_info_update NULL

/* ====================================================================== */

Pekka Pessi's avatar
Pekka Pessi committed
67 68 69
/**@SIP_HEADER sip_call_info Call-Info Header
 * 
 * The Call-Info header provides additional information about the caller or
70
 * callee. Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
71 72 73 74 75 76 77 78
 * 
 * @code
 *    Call-Info   =  "Call-Info" HCOLON info *(COMMA info)
 *    info        =  LAQUOT absoluteURI RAQUOT *( SEMI info-param)
 *    info-param  =  ( "purpose" EQUAL ( "icon" / "info"
 *                   / "card" / token ) ) / generic-param
 * @endcode
 * 
79 80
 *
 * The parsed Call-Info header is stored in #sip_call_info_t structure.
Pekka Pessi's avatar
Pekka Pessi committed
81 82
 */

83 84 85
/**@ingroup sip_call_info
 * @typedef struct sip_call_info_s sip_call_info_t;
 *
86 87
 * The structure #sip_call_info_t contains representation of an 
 * @CallInfo header.
88
 *
89
 * The #sip_call_info_t is defined as follows:
90 91 92 93
 * @code
 * struct sip_call_info_s
 * {
 *   sip_common_t        ci_common[1]; // Common fragment info
94
 *   sip_call_info_t    *ci_next;      // Link to next @CallInfo
95
 *   url_t               ci_url[1];    // URI to call info
Pekka Pessi's avatar
Pekka Pessi committed
96
 *   msg_param_t const  *ci_params;    // List of parameters
97
 *   char const         *ci_purpose;   // Value of @b purpose parameter
98 99 100 101
 * };
 * @endcode
 */

Pekka Pessi's avatar
Pekka Pessi committed
102
#define sip_call_info_dup_xtra  sip_info_dup_xtra
103 104
#define sip_call_info_dup_one   sip_info_dup_one
static msg_update_f sip_call_info_update;
Pekka Pessi's avatar
Pekka Pessi committed
105 106 107 108 109

msg_hclass_t sip_call_info_class[] =
SIP_HEADER_CLASS(call_info, "Call-Info", "",
		 ci_params, append, call_info);

110
issize_t sip_call_info_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
111
{
112
  issize_t retval = sip_info_d(home, h, s, slen);
Pekka Pessi's avatar
Pekka Pessi committed
113 114

  if (retval == 0)
115 116
    for (;h; h = h->sh_next)
      msg_header_update_params(h->sh_common, 0);
Pekka Pessi's avatar
Pekka Pessi committed
117 118 119 120

  return retval;
}

121
issize_t sip_call_info_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
122
{
123
  sip_call_info_t *ci = (sip_call_info_t *)h;
Pekka Pessi's avatar
Pekka Pessi committed
124

125
  assert(sip_call_info_p(h));
Pekka Pessi's avatar
Pekka Pessi committed
126

127
  return sip_name_addr_e(b, bsiz, f, NULL, 1, ci->ci_url, ci->ci_params, NULL);
Pekka Pessi's avatar
Pekka Pessi committed
128 129 130
}

/** @internal
131
 * Update parameter in a @CallInfo object.
Pekka Pessi's avatar
Pekka Pessi committed
132 133
 * 
 */
134 135
static
int sip_call_info_update(msg_common_t *h, 
136
			  char const *name, isize_t namelen,
137
			  char const *value)
Pekka Pessi's avatar
Pekka Pessi committed
138
{
139 140 141 142 143 144 145 146 147 148 149
  sip_call_info_t *ci = (sip_call_info_t *)h;

  if (name == NULL) {
    ci->ci_purpose = NULL;
  }
  else if (namelen == strlen("purpose") && 
	   !strncasecmp(name, "purpose", namelen)) {
    ci->ci_purpose = value;
  }

  return 0;
Pekka Pessi's avatar
Pekka Pessi committed
150 151 152 153 154 155 156
}

/* ====================================================================== */

/**@SIP_HEADER sip_error_info Error-Info Header
 * 
 * The Error-Info header provides a pointer to additional information about
157
 * the error status response. Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
158 159 160 161 162 163
 * 
 * @code
 *    Error-Info  =  "Error-Info" HCOLON error-uri *(COMMA error-uri)
 *    error-uri   =  LAQUOT absoluteURI RAQUOT *( SEMI generic-param )
 * @endcode
 * 
164 165
 *
 * The parsed Error-Info header is stored in #sip_error_info_t structure.
Pekka Pessi's avatar
Pekka Pessi committed
166 167
 */

168 169 170
/**@ingroup sip_error_info
 * @typedef struct sip_error_info_s sip_error_info_t;
 *
171 172
 * The structure #sip_error_info_t contains representation of an 
 * @ErrorInfo header.
173
 *
174
 * The #sip_error_info_t is defined as follows:
175 176 177 178
 * @code
 * struct sip_error_info_s
 * {
 *   sip_common_t        ei_common[1]; // Common fragment info
179
 *   sip_error_info_t   *ei_next;      // Link to next @ErrorInfo
180
 *   url_t               ei_url[1];    // URI to error info
Pekka Pessi's avatar
Pekka Pessi committed
181
 *   msg_param_t const  *ei_params;    // List of parameters
182 183 184 185
 * };
 * @endcode
 */

Pekka Pessi's avatar
Pekka Pessi committed
186 187 188 189
msg_hclass_t sip_error_info_class[] = 
SIP_HEADER_CLASS(error_info, "Error-Info", "",
		 ei_params, append, info);

190
issize_t sip_error_info_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
191 192 193 194
{
  return sip_info_d(home, h, s, slen);
}

195
issize_t sip_error_info_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209
{
  sip_error_info_t const *ei = h->sh_error_info;

  assert(sip_error_info_p(h));

  return sip_name_addr_e(b, bsiz, f,
			 NULL, 1, ei->ei_url, ei->ei_params, NULL);
}


/* ====================================================================== */

/**@SIP_HEADER sip_in_reply_to In-Reply-To Header
 * 
210 211 212
 * The @b In-Reply-To request header field enumerates the 
 * @ref sip_call_id "Call-IDs" that this call references or returns.
 * Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
213 214 215 216
 * 
 * @code
 *    In-Reply-To  =  "In-Reply-To" HCOLON callid *(COMMA callid)
 * @endcode
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
 *
 * The parsed In-Reply-To header is stored in #sip_in_reply_to_t structure.
 */

/**@ingroup sip_in_reply_to
 * @typedef struct msg_list_s sip_in_reply_to_t;
 *
 * The structure #sip_in_reply_to_t contains representation of SIP 
 * @InReplyTo header. 
 *
 * The #sip_in_reply_to_t is defined as follows:
 * @code
 * typedef struct msg_list_s
 * {
 *   msg_common_t       k_common[1];  // Common fragment info
 *   msg_list_t        *k_next;       // Link to next header
 *   msg_param_t       *k_items;      // List of call ids
 * } sip_allow_events_t;
 * @endcode
Pekka Pessi's avatar
Pekka Pessi committed
236 237 238 239 240
 */

msg_hclass_t sip_in_reply_to_class[] = 
SIP_HEADER_CLASS_LIST(in_reply_to, "In-Reply-To", "", list);

241
issize_t sip_in_reply_to_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
242 243 244 245
{
  return msg_list_d(home, h, s, slen);
}

246
issize_t sip_in_reply_to_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
247 248 249 250 251 252 253 254 255 256 257 258
{
  assert(sip_in_reply_to_p(h));
  return msg_list_e(b, bsiz, h, f);
}


/* ====================================================================== */

/**@SIP_HEADER sip_organization Organization Header
 * 
 * The Organization header field conveys the name of the organization to
 * which the entity issuing the request or response belongs. Its syntax is
259
 * defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
260 261 262 263 264
 * 
 * @code
 *    Organization  =  "Organization" HCOLON [TEXT-UTF8-TRIM]
 * @endcode
 * 
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
 *
 * The parsed Organization header is stored in #sip_organization_t structure.
 */

/**@ingroup sip_organization
 * @typedef struct msg_generic_s sip_organization_t; 
 *
 * The structure #sip_organization_t contains representation of a SIP 
 * @Organization header.
 *
 * The #sip_organization_t is defined as follows:
 * @code
 * typedef struct msg_generic_s
 * {
 *   msg_common_t   g_common[1];    // Common fragment info
 *   msg_generic_t *g_next;	    // Link to next header
 *   char const    *g_string;	    // Organization text
 * } sip_organization_t;
 * @endcode
Pekka Pessi's avatar
Pekka Pessi committed
284 285 286 287 288
 */

msg_hclass_t sip_organization_class[] = 
SIP_HEADER_CLASS_G(organization, "Organization", "", single);

289
issize_t sip_organization_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
290 291 292 293
{
  return sip_generic_d(home, h, s, slen);
}

294
issize_t sip_organization_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
295 296 297 298 299 300 301 302 303 304
{
  assert(sip_organization_p(h));
  return sip_generic_e(b, bsiz, h, f);
}

/* ====================================================================== */

/**@SIP_HEADER sip_priority Priority Header
 * 
 * The Priority request-header field indicates the urgency of the request as
305
 * perceived by the client. Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
306 307 308 309 310 311 312 313
 * 
 * @code
 *    Priority        =  "Priority" HCOLON priority-value
 *    priority-value  =  "emergency" / "urgent" / "normal"
 *                       / "non-urgent" / other-priority
 *    other-priority  =  token
 * @endcode
 * 
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
 *
 * The parsed Priority header is stored in #sip_priority_t structure.
 */

/**@ingroup sip_priority
 * @typedef struct msg_generic_s sip_priority_t; 
 *
 * The structure #sip_priority_t contains representation of a SIP 
 * @Priority header.
 *
 * The #sip_priority_t is defined as follows:
 * @code
 * typedef struct msg_generic_s
 * {
 *   msg_common_t   g_common[1];    // Common fragment info
 *   msg_generic_t *g_next;	    // Dummy link to next header
 *   char const    *g_string;	    // Priority token
 * } sip_priority_t;
 * @endcode
Pekka Pessi's avatar
Pekka Pessi committed
333 334 335 336 337
 */

msg_hclass_t sip_priority_class[] = 
SIP_HEADER_CLASS_G(priority, "Priority", "", single);

338
issize_t sip_priority_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
339
{
340 341 342 343 344 345 346 347 348
  sip_priority_t *priority = (sip_priority_t *)h;
  
  if (msg_token_d(&s, &priority->g_string) < 0)
    return -1;

  if (*s && !IS_LWS(*s))	/* Something extra after priority token? */
    return -1;

  return 0;
Pekka Pessi's avatar
Pekka Pessi committed
349 350
}

351
issize_t sip_priority_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
352 353 354 355 356 357 358 359 360 361 362
{
  assert(sip_priority_p(h));
  return sip_generic_e(b, bsiz, h, f);
}

/* ====================================================================== */

/**@SIP_HEADER sip_server Server Header
 * 
 * The Server response-header field contains information about the software
 * used by the user agent server to handle the request. Its syntax is
363
 * defined in @RFC2616 section 14.38 and @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
364 365 366 367 368 369 370
 * 
 * @code
 *    Server           =  "Server" HCOLON server-val *(LWS server-val)
 *    server-val       =  product / comment
 *    product          =  token [SLASH product-version]
 *    product-version  =  token
 * @endcode
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
 *
 * The parsed Server header is stored in #sip_server_t structure.
 */

/**@ingroup sip_server
 * @typedef struct msg_generic_s sip_server_t; 
 *
 * The structure #sip_server_t contains representation of a SIP 
 * @Server header.
 *
 * The #sip_server_t is defined as follows:
 * @code
 * typedef struct msg_generic_s
 * {
 *   msg_common_t   g_common[1];    // Common fragment info
 *   msg_generic_t *g_next;	    // Link to next header
 *   char const    *g_string;	    // Server tokens
 * } sip_server_t;
 * @endcode
Pekka Pessi's avatar
Pekka Pessi committed
390 391 392 393 394
 */

msg_hclass_t sip_server_class[] = 
SIP_HEADER_CLASS_G(server, "Server", "", single);

395
issize_t sip_server_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
396 397 398 399
{
  return sip_generic_d(home, h, s, slen);
}

400
issize_t sip_server_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
401 402 403 404 405 406 407 408 409 410
{
  assert(sip_server_p(h));
  return sip_generic_e(b, bsiz, h, f);
}

/* ====================================================================== */

/**@SIP_HEADER sip_subject Subject Header
 * 
 * The Subject header provides a summary or indicates the nature of the
411
 * request. Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
412 413 414 415 416
 * 
 * @code
 *    Subject  =  ( "Subject" / "s" ) HCOLON [TEXT-UTF8-TRIM]
 * @endcode
 * 
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
 * The parsed Subject header is stored in #sip_subject_t structure.
 */

/**@ingroup sip_subject
 * @typedef struct msg_generic_s sip_subject_t; 
 *
 * The structure #sip_subject_t contains representation of a SIP 
 * @Subject header.
 *
 * The #sip_subject_t is defined as follows:
 * @code
 * typedef struct msg_generic_s
 * {
 *   msg_common_t   g_common[1];    // Common fragment info
 *   msg_generic_t *g_next;	    // Link to next header
 *   char const    *g_string;	    // Subject text
 * } sip_subject_t;
 * @endcode
Pekka Pessi's avatar
Pekka Pessi committed
435 436 437 438 439
 */

msg_hclass_t sip_subject_class[] = 
SIP_HEADER_CLASS_G(subject, "Subject", "s", single);

440
issize_t sip_subject_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
441 442 443 444
{
  return sip_generic_d(home, h, s, slen);
}

445
issize_t sip_subject_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
446 447 448 449 450 451 452 453 454
{
  assert(sip_subject_p(h));
  return sip_generic_e(b, bsiz, h, f);
}

/* ====================================================================== */

/**@SIP_HEADER sip_timestamp Timestamp Header
 * 
455
 * The @b Timestamp header describes when the client sent the request to the
Pekka Pessi's avatar
Pekka Pessi committed
456
 * server, and it is used by the client to adjust its retransmission
457
 * intervals. Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
458 459 460 461 462 463 464
 * 
 * @code
 *    Timestamp  =  "Timestamp" HCOLON 1*(DIGIT)
 *                   [ "." *(DIGIT) ] [ LWS delay ]
 *    delay      =  *(DIGIT) [ "." *(DIGIT) ]
 * @endcode
 * 
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
 * The parsed Timestamp header is stored in #sip_timestamp_t structure.
 */

/**@ingroup sip_timestamp
 * @typedef struct sip_timestamp_s sip_timestamp_t; 
 *
 * The structure #sip_timestamp_t contains representation of a SIP 
 * @Timestamp header.
 *
 * The #sip_timestamp_t is defined as follows:
 * @code
 * typedef struct sip_timestamp_s
 * {
 *   sip_common_t        ts_common[1]; // Common fragment info
 *   sip_error_t        *ts_next;      // Dummy link
 *   char const         *ts_stamp;     // Original timestamp
 *   char const         *ts_delay;     // Delay at UAS
 * } sip_timestamp_t;
 * @endcode
Pekka Pessi's avatar
Pekka Pessi committed
484 485
 */

486
static isize_t sip_timestamp_dup_xtra(sip_header_t const *h, isize_t offset);
Pekka Pessi's avatar
Pekka Pessi committed
487
static char *sip_timestamp_dup_one(sip_header_t *dst,
488 489 490
				   sip_header_t const *src,
				   char *b,
				   isize_t xtra);
491
#define sip_timestamp_update NULL
Pekka Pessi's avatar
Pekka Pessi committed
492 493 494 495 496

msg_hclass_t sip_timestamp_class[] = 
SIP_HEADER_CLASS(timestamp, "Timestamp", "", ts_common, single,
		 timestamp);

497
issize_t sip_timestamp_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
498 499
{
  sip_timestamp_t *ts = (sip_timestamp_t*)h;
500

Pekka Pessi's avatar
Pekka Pessi committed
501
  ts->ts_stamp = s;
502
  s += span_digit(s); 
Pekka Pessi's avatar
Pekka Pessi committed
503 504
  if (s == ts->ts_stamp)
    return -1;
505
  if (*s == '.') { s += span_digit(s + 1) + 1; }
Pekka Pessi's avatar
Pekka Pessi committed
506 507

  if (IS_LWS(*s)) {
508 509
    *s = '\0';
    s += span_lws(s + 1) + 1;
Pekka Pessi's avatar
Pekka Pessi committed
510
    ts->ts_delay = s;
511
    s += span_digit(s); if (*s == '.') { s += span_digit(s + 1) + 1; }
Pekka Pessi's avatar
Pekka Pessi committed
512 513 514 515 516 517 518 519 520 521
  }

  if (!*s || IS_LWS(*s))
    *s++ = '\0';
  else
    return -1;
  
  return 0;
}

522
issize_t sip_timestamp_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
523 524 525 526 527 528
{
  sip_timestamp_t const *ts = h->sh_timestamp;
  char *end = b + bsiz, *b0 = b;

  assert(sip_timestamp_p(h));

Pekka Pessi's avatar
Pekka Pessi committed
529
  MSG_STRING_E(b, end, ts->ts_stamp);
Pekka Pessi's avatar
Pekka Pessi committed
530
  if (ts->ts_delay) {
Pekka Pessi's avatar
Pekka Pessi committed
531 532
    MSG_CHAR_E(b, end, ' ');
    MSG_STRING_E(b, end, ts->ts_delay);
Pekka Pessi's avatar
Pekka Pessi committed
533 534 535 536 537 538 539
  }

  MSG_TERM_E(b, end);
    
  return b - b0;
}

540 541
static
isize_t sip_timestamp_dup_xtra(sip_header_t const *h, isize_t offset)
Pekka Pessi's avatar
Pekka Pessi committed
542 543 544
{
  sip_timestamp_t const *ts = h->sh_timestamp;

545 546
  offset += MSG_STRING_SIZE(ts->ts_stamp);
  offset += MSG_STRING_SIZE(ts->ts_delay);
Pekka Pessi's avatar
Pekka Pessi committed
547

548
  return offset;
Pekka Pessi's avatar
Pekka Pessi committed
549 550
}

551
static
Pekka Pessi's avatar
Pekka Pessi committed
552 553 554
char *sip_timestamp_dup_one(sip_header_t *dst,
			    sip_header_t const *src,
			    char *b,
555
			    isize_t xtra)
Pekka Pessi's avatar
Pekka Pessi committed
556 557 558 559 560
{
  sip_timestamp_t *ts = dst->sh_timestamp;
  sip_timestamp_t const *o = src->sh_timestamp;
  char *end = b + xtra;

Pekka Pessi's avatar
Pekka Pessi committed
561 562
  MSG_STRING_DUP(b, ts->ts_stamp, o->ts_stamp);
  MSG_STRING_DUP(b, ts->ts_delay, o->ts_delay);
Pekka Pessi's avatar
Pekka Pessi committed
563

564
  assert(b <= end); (void)end;
Pekka Pessi's avatar
Pekka Pessi committed
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583

  return b;
}

/* ====================================================================== */

/**@SIP_HEADER sip_user_agent User-Agent Header
 * 
 * The User-Agent header contains information about the client user agent
 * originating the request. Its syntax is defined in [H14.43, S10.45] as
 * follows:
 * 
 * @code
 *    User-Agent       =  "User-Agent" HCOLON server-val *(LWS server-val)
 *    server-val       =  product / comment
 *    product          =  token [SLASH product-version]
 *    product-version  =  token
 * @endcode
 * 
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
 * The parsed User-Agent header is stored in #sip_user_agent_t structure.
 */

/**@ingroup sip_user_agent
 * @typedef struct msg_generic_s sip_user_agent_t; 
 *
 * The structure #sip_user_agent_t contains representation of a SIP 
 * @UserAgent header.
 *
 * The #sip_user_agent_t is defined as follows:
 * @code
 * typedef struct msg_generic_s
 * {
 *   msg_common_t   g_common[1];    // Common fragment info
 *   msg_generic_t *g_next;	    // Link to next header
 *   char const    *g_string;	    // User-Agent components
 * } sip_user_agent_t;
 * @endcode
Pekka Pessi's avatar
Pekka Pessi committed
602 603 604 605 606
 */

msg_hclass_t sip_user_agent_class[] = 
SIP_HEADER_CLASS_G(user_agent, "User-Agent", "", single);

607
issize_t sip_user_agent_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
608 609 610 611
{
  return sip_generic_d(home, h, s, slen);
}

612
issize_t sip_user_agent_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
613 614 615 616 617 618 619 620 621 622
{
  assert(sip_user_agent_p(h));
  return sip_generic_e(b, bsiz, h, f);
}

/* ====================================================================== */

/**@SIP_HEADER sip_etag SIP-ETag Header
 * 
 * The @b SIP-ETag header field identifies the published event state. Its
623
 * syntax is defined in @RFC3903 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
624 625 626 627 628
 * 
 * @code
 *      SIP-ETag           = "SIP-ETag" HCOLON entity-tag
 *      entity-tag         = token
 * @endcode
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
 *
 * The parsed SIP-ETag header is stored in #sip_etag_t structure.
 */

/**@ingroup sip_etag
 * @typedef struct msg_generic_s sip_etag_t; 
 *
 * The structure #sip_etag_t contains representation of a SIP 
 * @SIPETag header.
 *
 * The #sip_etag_t is defined as follows:
 * @code
 * typedef struct msg_generic_s
 * {
 *   msg_common_t   g_common[1];    // Common fragment info
 *   msg_generic_t *g_next;	    // Link to next header
 *   char const    *g_string;	    // entity-tag
 * } sip_etag_t;
 * @endcode
Pekka Pessi's avatar
Pekka Pessi committed
648 649 650 651 652
 */

msg_hclass_t sip_etag_class[] = 
SIP_HEADER_CLASS_G(etag, "SIP-ETag", "", single);

653
issize_t sip_etag_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
654 655 656 657 658 659
{
  sip_etag_t *etag = (sip_etag_t *)h;

  return msg_token_d(&s, &etag->g_value);
}

660
issize_t sip_etag_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
661 662 663 664 665 666 667 668 669 670
{
  return msg_generic_e(b, bsiz, h, f);
}

/* ====================================================================== */

/**@SIP_HEADER sip_if_match SIP-If-Match Header
 * 
 * The @b SIP-If-Match header field identifies the specific entity of event
 * state that the request is refreshing, modifying or removing. Its syntax
671
 * is defined in @RFC3903 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
672 673 674 675 676
 * 
 * @code
 *      SIP-If-Match       = "SIP-If-Match" HCOLON entity-tag
 *      entity-tag         = token
 * @endcode
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
 *
 * The parsed SIP-If-Match header is stored in #sip_if_match_t structure.
 */

/**@ingroup sip_if_match
 * @typedef struct msg_generic_s sip_if_match_t; 
 *
 * The structure #sip_if_match_t contains representation of a SIP 
 * @SIPIfMatch header.
 *
 * The #sip_if_match_t is defined as follows:
 * @code
 * typedef struct msg_generic_s
 * {
 *   msg_common_t   g_common[1];    // Common fragment info
 *   msg_generic_t *g_next;	    // Link to next header
 *   char const    *g_string;	    // entity-tag
 * } sip_if_match_t;
 * @endcode
Pekka Pessi's avatar
Pekka Pessi committed
696 697 698 699 700
 */

msg_hclass_t sip_if_match_class[] = 
SIP_HEADER_CLASS_G(if_match, "SIP-If-Match", "", single);

701
issize_t sip_if_match_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
702 703 704 705
{
  return sip_etag_d(home, h, s, slen);
}

706
issize_t sip_if_match_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
707 708 709 710 711 712
{
  return sip_etag_e(b, bsiz, h, f);
}

/* ====================================================================== */

713 714
/** Parsing @CallInfo, @ErrorInfo. */
static
715
issize_t sip_info_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
Pekka Pessi's avatar
Pekka Pessi committed
716 717 718 719 720 721 722
{
  sip_call_info_t *ci = h->sh_call_info;
  char *end = s + slen;

  assert(h);

  while (*s == ',')
723
    s += span_lws(s + 1) + 1;
Pekka Pessi's avatar
Pekka Pessi committed
724

725
  if (sip_name_addr_d(home, &s, NULL, ci->ci_url, &ci->ci_params, NULL) < 0)
Pekka Pessi's avatar
Pekka Pessi committed
726 727
    return -1;

728 729
  /* Recurse */
  return msg_parse_next_field(home, h, s, end - s);
Pekka Pessi's avatar
Pekka Pessi committed
730 731
}

732
isize_t sip_info_dup_xtra(sip_header_t const *h, isize_t offset)
Pekka Pessi's avatar
Pekka Pessi committed
733 734 735
{
  sip_call_info_t const *ci = h->sh_call_info;

736 737
  MSG_PARAMS_SIZE(offset, ci->ci_params);
  offset += url_xtra(ci->ci_url);
Pekka Pessi's avatar
Pekka Pessi committed
738

739
  return offset;
Pekka Pessi's avatar
Pekka Pessi committed
740 741 742 743 744
}

char *sip_info_dup_one(sip_header_t *dst,
		       sip_header_t const *src,
		       char *b,
745
		       isize_t xtra)
Pekka Pessi's avatar
Pekka Pessi committed
746 747 748 749 750
{
  sip_call_info_t *ci = dst->sh_call_info;
  sip_call_info_t const *o = src->sh_call_info;
  char *end = b + xtra;

Pekka Pessi's avatar
Pekka Pessi committed
751
  b = msg_params_dup(&ci->ci_params, o->ci_params, b, xtra);
Pekka Pessi's avatar
Pekka Pessi committed
752 753 754 755 756 757
  URL_DUP(b, end, ci->ci_url, o->ci_url);

  assert(b <= end);

  return b;
}
758 759 760

/* ====================================================================== */

761 762
#if SU_HAVE_EXPERIMENTAL

763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
/**@SIP_HEADER sip_suppress_body_if_match Suppress-Body-If-Match Header
 *
 * The @b Suppress-Body-If-Match header field identifies a SIP event content
 * already known by the watcher. Its syntax is defined in
 * draft-niemi-sip-subnot-etags-01 as follows:
 *
 * @code
 *    Suppress-Body-If-Match = "Suppress-Body-If-Match" HCOLON entity-tag
 *    entity-tag             = token
 * @endcode
 *
 * The parsed Suppress-Body-If-Match header is stored in
 * #sip_suppress_body_if_match_t structure.
 *
 * @sa @RFC3265, draft-niemi-sip-subnot-etags-01.txt
 *
779
 * @EXP_1_12_5. Note that #sip_t does not contain @a
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
 * sip_suppress_body_if_match field, but sip_suppress_body_if_match()
 * function should be used for accessing the @b Suppress-Body-If-Match
 * header structure.
 */

/**@ingroup sip_suppress_body_if_match
 * @typedef struct sip_suppress_body_if_match_s sip_suppress_body_if_match_t;
 *
 * The structure #sip_suppress_body_if_match_t contains representation of a
 * SIP @SuppressBodyIfMatch header.
 *
 * The #sip_suppress_body_if_match_t is defined as follows:
 * @code
 * typedef struct sip_suppress_body_if_match_s
 * {
 *   sip_common_t   sbim_common[1]; // Common fragment info
 *   sip_error_t   *sbim_next;      // Dummy link to next header
 *   char const    *sbim_tag;       // entity-tag
 * } sip_suppress_body_if_match_t;
 * @endcode
 */

#define sip_suppress_body_if_match_dup_xtra  msg_generic_dup_xtra
#define sip_suppress_body_if_match_dup_one   msg_generic_dup_one
#define sip_suppress_body_if_match_update NULL

msg_hclass_t sip_suppress_body_if_match_class[] =
SIP_HEADER_CLASS(suppress_body_if_match,
		 "Suppress-Body-If-Match", "",
		 sbim_common, single, suppress_body_if_match);

issize_t sip_suppress_body_if_match_d(su_home_t *home,
				      sip_header_t *h,
				      char *s, isize_t slen)
{
  sip_suppress_body_if_match_t *sbim = (void *)h;
  return msg_token_d(&s, &sbim->sbim_tag);
}

issize_t sip_suppress_body_if_match_e(char b[], isize_t bsiz,
				      sip_header_t const *h,
				      int f)
{
  return sip_etag_e(b, bsiz, h, f);
}


/* ====================================================================== */

/**@SIP_HEADER sip_suppress_notify_if_match Suppress-Notify-If-Match Header
 *
 * The @b Suppress-Notify-If-Match header is used to suppress
 * superfluous NOTIFY transactions. Its syntax is defined in
 * draft-niemi-sip-subnot-etags-01 as follows:
 *
 * @code
 *    Suppress-Notify-If-Match = "Suppress-Notify-If-Match" HCOLON entity-tag
 *    entity-tag               = token
 * @endcode
 *
 * The parsed Suppress-Notify-If-Match header is stored in
 * #sip_suppress_notify_if_match_t structure.
 *
 * @sa @RFC3265, draft-niemi-sip-subnot-etag-01
 *
845
 * @EXP_1_12_5. Note that #sip_t does not contain @a
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
 * sip_suppress_notify_if_match field, but sip_suppress_notify_if_match()
 * function should be used for accessing the @b Suppress-Notify-If-Match
 * header structure.
 */

/**@ingroup sip_suppress_notify_if_match
 * @typedef struct sip_suppress_notify_if_match_s \
 * sip_suppress_notify_if_match_t;
 *
 * The structure #sip_suppress_notify_if_match_t contains representation of a
 * SIP @SuppressNotifyIfMatch header.
 *
 * The #sip_suppress_notify_if_match_t is defined as follows:
 * @code
 * typedef struct sip_suppress_notify_if_match_s
 * {
 *   sip_common_t   snim_common[1]; // Common fragment info
 *   sip_error_t   *snim_next;      // Dummy link to next header
 *   char const    *snim_tag;       // entity-tag
 * } sip_suppress_notify_if_match_t;
 * @endcode
 */

#define sip_suppress_notify_if_match_dup_xtra  msg_generic_dup_xtra
#define sip_suppress_notify_if_match_dup_one   msg_generic_dup_one
#define sip_suppress_notify_if_match_update NULL

msg_hclass_t sip_suppress_notify_if_match_class[] =
SIP_HEADER_CLASS(suppress_notify_if_match,
		 "Suppress-Notify-If-Match", "",
		 snim_common, single, suppress_notify_if_match);

issize_t sip_suppress_notify_if_match_d(su_home_t *home,
					sip_header_t *h,
					char *s, isize_t slen)
{
  sip_suppress_notify_if_match_t *snim = (void *)h;
  return msg_token_d(&s, &snim->snim_tag);
}

issize_t sip_suppress_notify_if_match_e(char b[], isize_t bsiz,
					sip_header_t const *h,
					int f)
{
  return msg_generic_e(b, bsiz, h, f);
}

893
#endif