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 49
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

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

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

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

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

#define sip_info_update NULL

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

Pekka Pessi's avatar
Pekka Pessi committed
66 67 68
/**@SIP_HEADER sip_call_info Call-Info Header
 * 
 * The Call-Info header provides additional information about the caller or
69
 * callee. Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
70 71 72 73 74 75 76 77
 * 
 * @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
 * 
78 79
 *
 * The parsed Call-Info header is stored in #sip_call_info_t structure.
Pekka Pessi's avatar
Pekka Pessi committed
80 81
 */

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

Pekka Pessi's avatar
Pekka Pessi committed
101
#define sip_call_info_dup_xtra  sip_info_dup_xtra
102 103
#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
104 105 106 107 108

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

109
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
110
{
111
  issize_t retval = sip_info_d(home, h, s, slen);
Pekka Pessi's avatar
Pekka Pessi committed
112 113

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

  return retval;
}

120
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
121
{
122
  sip_call_info_t *ci = (sip_call_info_t *)h;
Pekka Pessi's avatar
Pekka Pessi committed
123

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

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

/** @internal
130
 * Update parameter in a @CallInfo object.
Pekka Pessi's avatar
Pekka Pessi committed
131 132
 * 
 */
133 134
static
int sip_call_info_update(msg_common_t *h, 
135
			  char const *name, isize_t namelen,
136
			  char const *value)
Pekka Pessi's avatar
Pekka Pessi committed
137
{
138 139 140 141 142 143 144 145 146 147 148
  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
149 150 151 152 153 154 155
}

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

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

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

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

189
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
190 191 192 193
{
  return sip_info_d(home, h, s, slen);
}

194
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
195 196 197 198 199 200 201 202 203 204 205 206 207 208
{
  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
 * 
209 210 211
 * 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
212 213 214 215
 * 
 * @code
 *    In-Reply-To  =  "In-Reply-To" HCOLON callid *(COMMA callid)
 * @endcode
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
 *
 * 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
235 236 237 238 239
 */

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

240
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
241 242 243 244
{
  return msg_list_d(home, h, s, slen);
}

245
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
246 247 248 249 250 251 252 253 254 255 256 257
{
  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
258
 * defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
259 260 261 262 263
 * 
 * @code
 *    Organization  =  "Organization" HCOLON [TEXT-UTF8-TRIM]
 * @endcode
 * 
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
 *
 * 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
283 284 285 286 287
 */

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

288
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
289 290 291 292
{
  return sip_generic_d(home, h, s, slen);
}

293
issize_t sip_organization_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
294 295 296 297 298 299 300 301 302 303
{
  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
304
 * perceived by the client. Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
305 306 307 308 309 310 311 312
 * 
 * @code
 *    Priority        =  "Priority" HCOLON priority-value
 *    priority-value  =  "emergency" / "urgent" / "normal"
 *                       / "non-urgent" / other-priority
 *    other-priority  =  token
 * @endcode
 * 
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
 *
 * 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
332 333 334 335 336
 */

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

337
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
338
{
339 340 341 342 343 344 345 346 347
  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
348 349
}

350
issize_t sip_priority_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
351 352 353 354 355 356 357 358 359 360 361
{
  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
362
 * defined in @RFC2616 section 14.38 and @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
363 364 365 366 367 368 369
 * 
 * @code
 *    Server           =  "Server" HCOLON server-val *(LWS server-val)
 *    server-val       =  product / comment
 *    product          =  token [SLASH product-version]
 *    product-version  =  token
 * @endcode
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
 *
 * 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
389 390 391 392 393
 */

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

394
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
395 396 397 398
{
  return sip_generic_d(home, h, s, slen);
}

399
issize_t sip_server_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
400 401 402 403 404 405 406 407 408 409
{
  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
410
 * request. Its syntax is defined in @RFC3261 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
411 412 413 414 415
 * 
 * @code
 *    Subject  =  ( "Subject" / "s" ) HCOLON [TEXT-UTF8-TRIM]
 * @endcode
 * 
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
 * 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
434 435 436 437 438
 */

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

439
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
440 441 442 443
{
  return sip_generic_d(home, h, s, slen);
}

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

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

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

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

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

496
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
497 498
{
  sip_timestamp_t *ts = (sip_timestamp_t*)h;
499

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

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

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

521
issize_t sip_timestamp_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
522 523 524 525 526 527
{
  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
528
  MSG_STRING_E(b, end, ts->ts_stamp);
Pekka Pessi's avatar
Pekka Pessi committed
529
  if (ts->ts_delay) {
Pekka Pessi's avatar
Pekka Pessi committed
530 531
    MSG_CHAR_E(b, end, ' ');
    MSG_STRING_E(b, end, ts->ts_delay);
Pekka Pessi's avatar
Pekka Pessi committed
532 533 534 535 536 537 538
  }

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

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

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

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

550
static
Pekka Pessi's avatar
Pekka Pessi committed
551 552 553
char *sip_timestamp_dup_one(sip_header_t *dst,
			    sip_header_t const *src,
			    char *b,
554
			    isize_t xtra)
Pekka Pessi's avatar
Pekka Pessi committed
555 556 557 558 559
{
  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
560 561
  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
562

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

  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
 * 
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
 * 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
601 602 603 604 605
 */

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

606
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
607 608 609 610
{
  return sip_generic_d(home, h, s, slen);
}

611
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
612 613 614 615 616 617 618 619 620 621
{
  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
622
 * syntax is defined in @RFC3903 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
623 624 625 626 627
 * 
 * @code
 *      SIP-ETag           = "SIP-ETag" HCOLON entity-tag
 *      entity-tag         = token
 * @endcode
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
 *
 * 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
647 648 649 650 651
 */

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

652
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
653 654 655 656 657 658
{
  sip_etag_t *etag = (sip_etag_t *)h;

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

659
issize_t sip_etag_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
Pekka Pessi's avatar
Pekka Pessi committed
660 661 662 663 664 665 666 667 668 669
{
  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
670
 * is defined in @RFC3903 as follows:
Pekka Pessi's avatar
Pekka Pessi committed
671 672 673 674 675
 * 
 * @code
 *      SIP-If-Match       = "SIP-If-Match" HCOLON entity-tag
 *      entity-tag         = token
 * @endcode
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
 *
 * 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
695 696 697 698 699
 */

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

700
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
701 702 703 704
{
  return sip_etag_d(home, h, s, slen);
}

705
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
706 707 708 709 710 711
{
  return sip_etag_e(b, bsiz, h, f);
}

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

712 713
/** Parsing @CallInfo, @ErrorInfo. */
static
714
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
715 716 717 718 719 720 721
{
  sip_call_info_t *ci = h->sh_call_info;
  char *end = s + slen;

  assert(h);

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

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

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

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

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

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

char *sip_info_dup_one(sip_header_t *dst,
		       sip_header_t const *src,
		       char *b,
744
		       isize_t xtra)
Pekka Pessi's avatar
Pekka Pessi committed
745 746 747 748 749
{
  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
750
  b = msg_params_dup(&ci->ci_params, o->ci_params, b, xtra);
Pekka Pessi's avatar
Pekka Pessi committed
751 752 753 754 755 756
  URL_DUP(b, end, ci->ci_url, o->ci_url);

  assert(b <= end);

  return b;
}
757 758 759

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

760 761
#if SU_HAVE_EXPERIMENTAL

762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
/**@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
 *
778
 * @EXP_1_12_5. Note that #sip_t does not contain @a
779 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
 * 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
 *
844
 * @EXP_1_12_5. Note that #sip_t does not contain @a
845 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
 * 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);
}

892
#endif