sip_extra.c 29.6 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
{
  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);
}

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
/* ====================================================================== */

/**@SIP_HEADER sip_alert_info Alert-Info Header
 *
 * When present in an INVITE request, the Alert-Info header field
 * specifies an alternative ring tone to the UAS.  When present in a 180
 * (Ringing) response, the Alert-Info header field specifies an
 * alternative ringback tone to the UAC.  A typical usage is for a proxy
 * to insert this header field to provide a distinctive ring feature.
 *
 * @code
 *    Alert-Info   =  "Alert-Info" HCOLON alert-param *(COMMA alert-param)
 *    alert-param  =  LAQUOT absoluteURI RAQUOT *(SEMI generic-param)
 * @endcode
 *
 * The parsed Alert-Info header is stored in #sip_alert_info_t structure.
 *
 * @NEW_1_12_7
 */

/**@ingroup sip_alert_info
 * @typedef struct sip_alert_info_s sip_alert_info_t;
 *
 * The structure #sip_alert_info_t contains representation of an
 * @AlertInfo header.
 *
 * The #sip_alert_info_t is defined as follows:
 * @code
 * struct sip_alert_info_s
 * {
 *   sip_common_t        ai_common[1]; // Common fragment info
 *   sip_alert_info_t   *ai_next;      // Link to next @AlertInfo
 *   url_t               ai_url[1];    // URI to alert info
 *   msg_param_t const  *ai_params;    // List of optional parameters
 * };
 * @endcode
 *
 * @NEW_1_12_7
 */

msg_hclass_t sip_alert_info_class[] =
SIP_HEADER_CLASS(alert_info, "Alert-Info", "",
		 ai_params, append, info);

issize_t sip_alert_info_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
{
  return sip_info_d(home, h, s, slen);
}

issize_t sip_alert_info_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
{
  sip_alert_info_t *ai = (sip_alert_info_t *)h;
  return sip_name_addr_e(b, bsiz, f, NULL, 1, ai->ai_url, ai->ai_params, NULL);
}

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

/**@SIP_HEADER sip_reply_to Reply-To Header
 *
 * The @b Reply-To header field contains a logical return URI that may be
 * different from the @From header field. For example, the URI MAY be used to
 * return missed calls or unestablished sessions. If the user wished to
 * remain anonymous, the header field SHOULD either be omitted from the
 * request or populated in such a way that does not reveal any private
 * information. Its syntax is defined in @RFC3261 as follows:
 *
 * @code
 *   Reply-To      =  "Reply-To" HCOLON rplyto-spec
 *   rplyto-spec   =  ( name-addr / addr-spec )
 *                   *( SEMI rplyto-param )
 *   rplyto-param  =  generic-param
 * @endcode
 *
 * The parsed Reply-To header is stored in #sip_reply_to_t structure.
 */

/**@ingroup sip_reply_to
 * @typedef struct msg_list_s sip_reply_to_t;
 *
 * The structure #sip_reply_to_t contains representation of SIP
 * @ReplyTo header.
 *
 * The #sip_reply_to_t is defined as follows:
 * @code
 * struct sip_reply_to_s
 * {
 *   sip_common_t       rplyto_common[1]; // Common fragment info

 *   sip_error_t       *rplyto_next;	 // Dummy link to next header
 *   char const        *rplyto_display;	 // Display name
 *   url_t              rplyto_url[1];	 // Return URI
 *   msg_param_t const *rplyto_params;	 // List of optional parameters
 * };
 * @endcode
 */

static isize_t sip_reply_to_dup_xtra(sip_header_t const *h, isize_t offset);
static char *sip_reply_to_dup_one(sip_header_t *dst,
				  sip_header_t const *src,
				  char *b,
				  isize_t xtra);
#define sip_reply_to_update NULL

msg_hclass_t sip_reply_to_class[] =
  SIP_HEADER_CLASS(reply_to, "Reply-To", "", rplyto_params, single, reply_to);

issize_t sip_reply_to_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
{
  sip_reply_to_t *rplyto = (sip_reply_to_t *)h;

  return sip_name_addr_d(home,
			 &s,
			 &rplyto->rplyto_display,
			 rplyto->rplyto_url,
			 &rplyto->rplyto_params,
			 NULL);
}

issize_t sip_reply_to_e(char b[], isize_t bsiz, sip_header_t const *h, int flags)
{
  sip_reply_to_t *rplyto = (sip_reply_to_t *)h;

  return sip_name_addr_e(b, bsiz,
			 flags,
			 rplyto->rplyto_display,
			 MSG_IS_CANONIC(flags), rplyto->rplyto_url,
			 rplyto->rplyto_params,
			 NULL);
}

static isize_t sip_reply_to_dup_xtra(sip_header_t const *h, isize_t offset)
{
  sip_reply_to_t const *rplyto = (sip_reply_to_t const *)h;

  MSG_PARAMS_SIZE(offset, rplyto->rplyto_params);
  offset += MSG_STRING_SIZE(rplyto->rplyto_display);
  offset += url_xtra(rplyto->rplyto_url);

  return offset;
}

/**@internal Duplicate one sip_reply_to_t object. */
static char *sip_reply_to_dup_one(sip_header_t *dst, sip_header_t const *src,
				  char *b, isize_t xtra)
{
  sip_reply_to_t *rplyto = (sip_reply_to_t *)dst;
  sip_reply_to_t const *o = (sip_reply_to_t *)src;
  char *end = b + xtra;

  b = msg_params_dup(&rplyto->rplyto_params, o->rplyto_params, b, xtra);
  MSG_STRING_DUP(b, rplyto->rplyto_display, o->rplyto_display);
  URL_DUP(b, end, rplyto->rplyto_url, o->rplyto_url);

  assert(b <= end);

  return b;
}
Pekka Pessi's avatar
Pekka Pessi committed
362 363 364 365 366

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

/**@SIP_HEADER sip_in_reply_to In-Reply-To Header
 * 
367 368 369
 * 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
370 371 372 373
 * 
 * @code
 *    In-Reply-To  =  "In-Reply-To" HCOLON callid *(COMMA callid)
 * @endcode
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
 *
 * 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
391
 * } sip_in_reply_to_t;
392
 * @endcode
Pekka Pessi's avatar
Pekka Pessi committed
393 394 395 396 397
 */

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

398
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
399 400 401 402
{
  return msg_list_d(home, h, s, slen);
}

403
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
404 405 406 407 408 409 410 411 412 413 414
{
  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
415
 * defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
416 417 418 419 420
 * 
 * @code
 *    Organization  =  "Organization" HCOLON [TEXT-UTF8-TRIM]
 * @endcode
 * 
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
 *
 * 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
440 441 442 443 444
 */

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

445
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
446 447 448 449
{
  return sip_generic_d(home, h, s, slen);
}

450
issize_t sip_organization_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
451 452 453 454 455 456 457 458 459 460
{
  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
461
 * perceived by the client. Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
462 463 464 465 466 467 468 469
 * 
 * @code
 *    Priority        =  "Priority" HCOLON priority-value
 *    priority-value  =  "emergency" / "urgent" / "normal"
 *                       / "non-urgent" / other-priority
 *    other-priority  =  token
 * @endcode
 * 
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
 *
 * 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
489 490 491 492 493
 */

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

494
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
495
{
496 497 498 499 500 501 502 503 504
  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
505 506
}

507
issize_t sip_priority_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
508 509 510 511 512 513 514 515 516 517 518
{
  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
519
 * defined in @RFC2616 section 14.38 and @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
520 521 522 523 524 525 526
 * 
 * @code
 *    Server           =  "Server" HCOLON server-val *(LWS server-val)
 *    server-val       =  product / comment
 *    product          =  token [SLASH product-version]
 *    product-version  =  token
 * @endcode
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
 *
 * 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
546 547 548 549 550
 */

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

551
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
552 553 554 555
{
  return sip_generic_d(home, h, s, slen);
}

556
issize_t sip_server_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
557 558 559 560 561 562 563 564 565 566
{
  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
567
 * request. Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
568 569 570 571 572
 * 
 * @code
 *    Subject  =  ( "Subject" / "s" ) HCOLON [TEXT-UTF8-TRIM]
 * @endcode
 * 
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
 * 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
591 592 593 594 595
 */

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

596
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
597 598 599 600
{
  return sip_generic_d(home, h, s, slen);
}

601
issize_t sip_subject_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
602 603 604 605 606 607 608 609 610
{
  assert(sip_subject_p(h));
  return sip_generic_e(b, bsiz, h, f);
}

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

/**@SIP_HEADER sip_timestamp Timestamp Header
 * 
611
 * The @b Timestamp header describes when the client sent the request to the
Pekka Pessi's avatar
Pekka Pessi committed
612
 * server, and it is used by the client to adjust its retransmission
613
 * intervals. Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
614 615 616 617 618 619 620
 * 
 * @code
 *    Timestamp  =  "Timestamp" HCOLON 1*(DIGIT)
 *                   [ "." *(DIGIT) ] [ LWS delay ]
 *    delay      =  *(DIGIT) [ "." *(DIGIT) ]
 * @endcode
 * 
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
 * 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
640 641
 */

642
static isize_t sip_timestamp_dup_xtra(sip_header_t const *h, isize_t offset);
Pekka Pessi's avatar
Pekka Pessi committed
643
static char *sip_timestamp_dup_one(sip_header_t *dst,
644 645 646
				   sip_header_t const *src,
				   char *b,
				   isize_t xtra);
647
#define sip_timestamp_update NULL
Pekka Pessi's avatar
Pekka Pessi committed
648 649 650 651 652

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

653
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
654 655
{
  sip_timestamp_t *ts = (sip_timestamp_t*)h;
656

Pekka Pessi's avatar
Pekka Pessi committed
657
  ts->ts_stamp = s;
658
  s += span_digit(s); 
Pekka Pessi's avatar
Pekka Pessi committed
659 660
  if (s == ts->ts_stamp)
    return -1;
661
  if (*s == '.') { s += span_digit(s + 1) + 1; }
Pekka Pessi's avatar
Pekka Pessi committed
662 663

  if (IS_LWS(*s)) {
664 665
    *s = '\0';
    s += span_lws(s + 1) + 1;
Pekka Pessi's avatar
Pekka Pessi committed
666
    ts->ts_delay = s;
667
    s += span_digit(s); if (*s == '.') { s += span_digit(s + 1) + 1; }
Pekka Pessi's avatar
Pekka Pessi committed
668 669 670 671 672 673 674 675 676 677
  }

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

678
issize_t sip_timestamp_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
679 680 681 682 683 684
{
  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
685
  MSG_STRING_E(b, end, ts->ts_stamp);
Pekka Pessi's avatar
Pekka Pessi committed
686
  if (ts->ts_delay) {
Pekka Pessi's avatar
Pekka Pessi committed
687 688
    MSG_CHAR_E(b, end, ' ');
    MSG_STRING_E(b, end, ts->ts_delay);
Pekka Pessi's avatar
Pekka Pessi committed
689 690 691 692 693 694 695
  }

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

696 697
static
isize_t sip_timestamp_dup_xtra(sip_header_t const *h, isize_t offset)
Pekka Pessi's avatar
Pekka Pessi committed
698 699 700
{
  sip_timestamp_t const *ts = h->sh_timestamp;

701 702
  offset += MSG_STRING_SIZE(ts->ts_stamp);
  offset += MSG_STRING_SIZE(ts->ts_delay);
Pekka Pessi's avatar
Pekka Pessi committed
703

704
  return offset;
Pekka Pessi's avatar
Pekka Pessi committed
705 706
}

707
static
Pekka Pessi's avatar
Pekka Pessi committed
708 709 710
char *sip_timestamp_dup_one(sip_header_t *dst,
			    sip_header_t const *src,
			    char *b,
711
			    isize_t xtra)
Pekka Pessi's avatar
Pekka Pessi committed
712 713 714 715 716
{
  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
717 718
  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
719

720
  assert(b <= end); (void)end;
Pekka Pessi's avatar
Pekka Pessi committed
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739

  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
 * 
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
 * 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
758 759 760 761 762
 */

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

763
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
764 765 766 767
{
  return sip_generic_d(home, h, s, slen);
}

768
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
769 770 771 772 773 774 775 776 777 778
{
  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
779
 * syntax is defined in @RFC3903 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
780 781 782 783 784
 * 
 * @code
 *      SIP-ETag           = "SIP-ETag" HCOLON entity-tag
 *      entity-tag         = token
 * @endcode
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
 *
 * 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
804 805 806 807 808
 */

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

809
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
810 811 812 813 814 815
{
  sip_etag_t *etag = (sip_etag_t *)h;

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

816
issize_t sip_etag_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
817 818 819 820 821 822 823 824 825 826
{
  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
827
 * is defined in @RFC3903 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
828 829 830 831 832
 * 
 * @code
 *      SIP-If-Match       = "SIP-If-Match" HCOLON entity-tag
 *      entity-tag         = token
 * @endcode
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
 *
 * 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
852 853 854 855 856
 */

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

857
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
858 859 860 861
{
  return sip_etag_d(home, h, s, slen);
}

862
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
863 864 865 866 867 868
{
  return sip_etag_e(b, bsiz, h, f);
}

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

869 870
/** Parsing @CallInfo, @ErrorInfo. */
static
871
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
872 873 874 875 876 877 878
{
  sip_call_info_t *ci = h->sh_call_info;
  char *end = s + slen;

  assert(h);

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

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

884 885
  /* Recurse */
  return msg_parse_next_field(home, h, s, end - s);
Pekka Pessi's avatar
Pekka Pessi committed
886 887
}

888
isize_t sip_info_dup_xtra(sip_header_t const *h, isize_t offset)
Pekka Pessi's avatar
Pekka Pessi committed
889 890 891
{
  sip_call_info_t const *ci = h->sh_call_info;

892 893
  MSG_PARAMS_SIZE(offset, ci->ci_params);
  offset += url_xtra(ci->ci_url);
Pekka Pessi's avatar
Pekka Pessi committed
894

895
  return offset;
Pekka Pessi's avatar
Pekka Pessi committed
896 897 898 899 900
}

char *sip_info_dup_one(sip_header_t *dst,
		       sip_header_t const *src,
		       char *b,
901
		       isize_t xtra)
Pekka Pessi's avatar
Pekka Pessi committed
902 903 904 905 906
{
  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
907
  b = msg_params_dup(&ci->ci_params, o->ci_params, b, xtra);
Pekka Pessi's avatar
Pekka Pessi committed
908 909 910 911 912 913
  URL_DUP(b, end, ci->ci_url, o->ci_url);

  assert(b <= end);

  return b;
}
914 915 916

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

917 918
#if SU_HAVE_EXPERIMENTAL

919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934
/**@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
 *
935
 * @EXP_1_12_5. Note that #sip_t does not contain @a
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
 * 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
 *
1001
 * @EXP_1_12_5. Note that #sip_t does not contain @a
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
 * 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);
}

1049
#endif