sip_pref_util.c File Reference


Detailed Description

SIP callercaps and callerprefs utility functions.

Author:
Pekka Pessi <Pekka.Pessi@nokia-email.address.hidden>.
Date:
Created: Tue Nov 2 16:39:33 EET 2004 ppessi

#include "config.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <float.h>
#include "sofia-sip/sip_parser.h"
#include <sofia-sip/sip_header.h>
#include <sofia-sip/sip_util.h>
#include <sofia-sip/sip_status.h>

Include dependency graph for sip_pref_util.c:


Functions

int sip_prefs_parse (union sip_pref *sp, char const **in_out_s, int *return_negation)
 Parse a single preference.
int sip_prefs_match (union sip_pref const *a, union sip_pref const *b)
 Match preferences.
int sip_prefs_matching (char const *pvalue, char const *nvalue, int *return_parse_error)
 Check callerprefs.
int sip_is_callerpref (char const *param)
 Check if the parameter is a valid feature tag.
int sip_contact_is_immune (sip_contact_t const *m)
 Check if Contact is immune to callerprefs.
int sip_contact_accept (sip_contact_t const *m, sip_accept_contact_t const *cp, unsigned *return_S, unsigned *return_N, int *return_error)
 Check if Contact matches by Accept-Contact.
int sip_contact_reject (sip_contact_t const *m, sip_reject_contact_t const *reject)
 Check if Contact is rejected by Reject-Contact.
sip_contact_tsip_contact_immunize (su_home_t *home, sip_contact_t const *m)
 Immunize Contact to callerprefs.
int sip_contact_score (sip_contact_t const *m, sip_accept_contact_t const *ac, sip_reject_contact_t const *rc)
 Calculate score for contact.

Function Documentation

int sip_contact_accept ( sip_contact_t const *  m,
sip_accept_contact_t const *  cp,
unsigned *  return_S,
unsigned *  return_N,
int *  return_error 
)

Check if Contact matches by Accept-Contact.

Matching Accept-Contact and Contact headers is done as explained in RFC 3841 section 7.2.4. The caller score can be calculated from the returned S and N values.

Matching
The Accept-Contact header contains number of feature tag parameters. The count of feature tags is returned in return_N. For each feature tag in Accept-Contact, the feature tag with same name is searched from the Contact header. If both headers contain the feature tag with same name, their values are compared. If the value in Accept-Contact does not match with the value in Contact, there is mismatch and 0 is returned. If they match, S is increased by 1.
Parameters:
m pointer to Contact header structure
cp pointer to Accept-Contact header structure
return_N return-value parameter for number of feature tags in Accept-Contact
return_S return-value parameter for number of matching feature tags
return_error return-value parameter for parsing error
For example,
 if (sip_contact_accept(contact, accept_contact, &S, &N, &error)) {
   if (N == 0)
     score == 1.0;
   else
     score = (double)S / (double)N;
   if (accept_contact->cp_explicit) {
     if (accept_contact->cp_require)
       goto drop;
     else
       score = 0.0;
   }
 }
 else if (!error) {
   score = 0.0;
 }

Return values:
1 if Contact matches
Returns:
return_S contains number of matching feature tags

return_N contains number of feature tags in Accept-Contact

Return values:
0 if Contact does not match
Returns:
return_error contains -1 if feature tag value was malformed
See also:
RFC 3841 section 7.2.4, sip_contact_score(), sip_contact_reject(), sip_contact_is_immune(), sip_contact_immunize(), sip_is_callerpref(), sip_prefs_matching().

sip_contact_t* sip_contact_immunize ( su_home_t home,
sip_contact_t const *  m 
)

Immunize Contact to callerprefs.

Make a copy of Contact header m and remove all parameters which affect caller preferences.

Parameters:
home home object used when allocating copy
m pointer to Contact header structure to immunize
Return values:
pointer to immunized copy if successful
NULL upon an error
See also:
RFC 3841, sip_is_callerpref(), sip_contact_score(), sip_contact_accept(), sip_contact_reject(), Contact

int sip_contact_reject ( sip_contact_t const *  m,
sip_reject_contact_t const *  reject 
)

Check if Contact is rejected by Reject-Contact.

Parameters:
m pointer to Contact header
reject pointer to Reject-Contact header
Return values:
1 when rejecting
0 when Contact does not match with Reject-Contact
See also:
sip_contact_score(), sip_contact_accept(), sip_contact_immunize(), sip_contact_is_immune(), RFC 3841, Reject-Contact, Contact

int sip_contact_score ( sip_contact_t const *  m,
sip_accept_contact_t const *  ac,
sip_reject_contact_t const *  rc 
)

Calculate score for contact.

The caller preference score is an integer in range of 0 to 1000.

Return values:
-1 if the contact is rejected
1000 if contact is immune to caller preferences
0..1000 reflecting RFC 3481 score in 0.000 - 1.000.
See also:
sip_q_value(), sip_contact_accept(), sip_contact_reject(), sip_contact_is_immune(), sip_contact_immunize(), sip_is_callerpref(), sip_prefs_matching(), RFC 3481, Accept-Contact, Reject-Contact, Contact

int sip_is_callerpref ( char const *  param  ) 

Check if the parameter is a valid feature tag.

A feature tag is a parameter starting with a single plus, or a well-known feature tag listed in RFC 3841: "audio", "automata", "application", "class", "control", "duplex", "data", "description", "events", "isfocus", "language", "mobility", "methods", "priority", "schemes", "type", or "video". However, well-known feature tag can not start with plus. So, "+alarm" or "audio" is a feature tag, "alarm", "++alarm", or "+audio" are not.

Return values:
1 if string is a feature tag parameter
0 otherwise

int sip_prefs_matching ( char const *  pvalue,
char const *  nvalue,
int *  return_parse_error 
)

Check callerprefs.

Check if the given feature values match with each other.

Parameters:
pvalue first feature parameter
nvalue second feature parameter
return_parse_error return-value parameter for error (may be NULL)
Return values:
1 if given feature parameters match
0 if there is no match or a parse or type error occurred.
If there is a parsing or type error, 0 is returned and *return_parse_error is set to -1.

See also:
sip_prefs_parse(), sip_prefs_match(), union sip_pref.


Sofia-SIP 1.12.6 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.