/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <pthread.h>
#include <strings.h>
#include <stdlib.h>
#include <sip.h>
#include "sip_msg.h"
#include "sip_miscdefs.h"
/*
* Returns number of digits in the given int
*/
static int
{
int num_of_bytes = 0;
do {
num_of_bytes += 1;
} while (num > 0);
return (num_of_bytes);
}
/*
* Return the int as a string
*/
static char *
sip_int_to_str(int i)
{
int count;
int t;
int x;
char *str;
if (i < 0)
return (NULL);
/*
* the following two loops convert int i to str
*/
count = 1;
t = i;
while ((t = t / 10) != 0) {
count++;
}
return (NULL);
t = i;
for (x = 0; x < count; x++) {
int a;
a = t % 10;
t = t / 10;
}
return (str);
}
/*
* Add quotes to the give str and return the quoted string
*/
static char *
{
char *new_str;
int size;
tmp++;
if (*tmp != SIP_LAQUOT) {
return (NULL);
new_str[0] = SIP_LAQUOT;
return (new_str);
}
return (str);
}
/*
* Add an empty header
*/
static int
{
int header_size;
int csize = sizeof (char);
return (EINVAL);
if (_sip_msg->sip_msg_cannot_be_modified) {
return (ENOTSUP);
}
if (new_header == NULL) {
return (ENOMEM);
}
return (0);
}
/*
* Generic function to add a header with two strings to message
*/
static int
{
int header_size;
int csize = sizeof (char);
return (EINVAL);
}
if (_sip_msg->sip_msg_cannot_be_modified) {
return (ENOTSUP);
}
} else {
}
if (qstr1)
header_size += 2 * sizeof (char);
if (new_header == NULL) {
return (ENOMEM);
}
if (qstr1) {
} else {
}
} else {
if (qstr1) {
header_size + 1,
} else {
}
}
return (0);
}
/*
* Generic function to add a header with a string to message
*/
static int
char param_sep)
{
int header_size;
int csize = sizeof (char);
return (EINVAL);
if (_sip_msg->sip_msg_cannot_be_modified) {
return (ENOTSUP);
}
} else {
}
if (new_header == NULL) {
return (ENOMEM);
}
} else {
}
return (0);
}
/*
* Add an header with an int to sip_msg
*/
static int
{
int header_size;
char *digit_str;
int csize = sizeof (char);
return (EINVAL);
if (_sip_msg->sip_msg_cannot_be_modified) {
return (ENOTSUP);
}
/*
* the following two loops convert int i to str
*/
digit_str = sip_int_to_str(i);
return (EINVAL);
} else {
}
if (new_header == NULL) {
return (ENOMEM);
}
} else {
}
return (0);
}
/*
* Add a header with an int and string to sip_msg
*/
static int
char *plist)
{
int header_size;
char *digit_str;
int csize = sizeof (char);
return (EINVAL);
if (_sip_msg->sip_msg_cannot_be_modified) {
return (ENOTSUP);
}
/*
* the following two loops convert int i to str
*/
digit_str = sip_int_to_str(i);
return (EINVAL);
}
} else {
}
if (new_header == NULL) {
return (ENOMEM);
}
SIP_CRLF);
} else {
}
return (0);
}
/*
* Generic function to add Contact, From, To, Route or Record-Route header
*/
static int
{
char *t = uri;
int r;
return (EINVAL);
return (EINVAL);
if (add_aquot) {
if (t == NULL)
return (ENOMEM);
}
int plen;
return (EINVAL);
return (ENOMEM);
}
if (display_name == NULL) {
} else {
}
if (qalloc)
free(t);
if (palloc)
return (r);
}
/*
* Accept = "Accept" ":" (media-range [ accept-params ])
* media-range = ( "X/X" | (type "/" "*") | (type "/" subtype))*(";" parameter)
* accept-params = ";" "q" "=" qvalue *(accept-extension)
* accept-extension = ";" token [ "=" (token | quoted-str)
*
* function take two char ptrs - type and subtype - if any of them is NULL
* the corresponding value will be set to "*" in header
*/
int
char *a_par)
{
int ret;
char *plist;
int size;
return (ret);
}
} else
} else {
}
return (ret);
}
/*
* Accept-Encoding = "Accept-Encoding" ":" 1#(codings [ ";" "q" "=" qval])
* codings = ( content-coding | "*" )
* content-coding = token
*
* function take one char ptr, if NULL value will be set to "*"
*/
int
{
int ret;
SIP_SEMI);
} else {
}
return (ret);
}
/*
* Accept-Language = "Accept-Language" ":" 1#( language-range [ ";" "q""=" val])
* language-range = ( ( 1*8ALPHA *("-" 1*8ALPHA))|"*")
*/
int
{
int ret;
return (ret);
}
SIP_SEMI);
return (ret);
}
/*
* Alert-Info = "Alert-Info" ":" "<" URI ">"
*/
int
{
int ret;
char *tmp;
return (EINVAL);
return (ENOMEM);
if (alloc)
return (ret);
}
/*
* Allow = "Allow" ":" method-name1[, method-name2..]
* method-name = "INVITE" | "ACK" | "OPTIONS" | "CANCEL" | "BYE"
*/
int
{
int ret;
return (EINVAL);
return (ret);
}
/*
* 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
*/
int
{
char *tmp;
int r;
return (EINVAL);
return (ENOMEM);
if (alloc)
return (r);
}
/*
* Content-Disposition = "Content-Disposition" HCOLON
* disp-type *( SEMI disp-param )
* disp-type = "render" / "session" / "icon" / "alert"
* / disp-extension-token
* disp-param = handling-param / generic-param
* handling-param = "handling" EQUAL
* ( "optional" / "required"
* / other-handling )
* other-handling = token
* disp-extension-token = token
*/
int
{
int ret;
return (EINVAL);
SIP_SEMI);
return (ret);
}
/*
* Content-Encoding = ( "Content-Encoding" / "e" ) HCOLON
* content-coding *(COMMA content-coding)
* content-coding = token
*/
int
{
int ret;
return (EINVAL);
(char)NULL);
return (ret);
}
/*
* Content-Language = "Content-Language" HCOLON
* language-tag *(COMMA language-tag)
* language-tag = primary-tag *( "-" subtag )
* primary-tag = 1*8ALPHA
* subtag = 1*8ALPHA
*/
int
{
int ret;
return (EINVAL);
(char)NULL);
return (ret);
}
/*
* Date = "Date" HCOLON SIP-date
* SIP-date = rfc1123-date
* rfc1123-date = wkday "," SP date1 SP time SP "GMT"
* date1 = 2DIGIT SP month SP 4DIGIT
* ; day month year (e.g., 02 Jun 1982)
* time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
* ; 00:00:00 - 23:59:59
* wkday = "Mon" / "Tue" / "Wed"
* / "Thu" / "Fri" / "Sat" / "Sun"
* month = "Jan" / "Feb" / "Mar" / "Apr"
* / "May" / "Jun" / "Jul" / "Aug"
* / "Sep" / "Oct" / "Nov" / "Dec"
*/
int
{
int ret;
return (EINVAL);
return (ret);
}
/*
* Error-Info = "Error-Info" HCOLON error-uri *(COMMA error-uri)
* error-uri = LAQUOT absoluteURI RAQUOT *( SEMI generic-param )
*/
int
{
char *tmp;
int r;
return (EINVAL);
return (EINVAL);
if (alloc)
return (r);
}
/*
* Expires = "Expires" HCOLON delta-seconds
* delta-seconds = 1*DIGIT
*/
int
{
int ret;
return (EINVAL);
return (ret);
}
/*
* In-Reply-To = "In-Reply-To" HCOLON callid *(COMMA callid)
* callid = word [ "@" word ]
*/
int
{
int r;
return (EINVAL);
(char)NULL);
return (r);
}
/*
* RSeq = "RSeq" HCOLON response-num
*/
int
{
int ret;
return (EINVAL);
return (ret);
}
/*
* Min-Expires = "Min-Expires" HCOLON delta-seconds
*/
int
{
int ret;
return (EINVAL);
return (ret);
}
/*
* MIME-Version = "MIME-Version" HCOLON 1*DIGIT "." 1*DIGIT
*/
int
{
int ret;
return (EINVAL);
(char)NULL);
return (ret);
}
/*
* Organization = "Organization" HCOLON [TEXT-UTF8-TRIM]
*/
int
{
int ret;
} else {
(char)NULL);
}
return (ret);
}
/*
* Priority = "Priority" HCOLON priority-value
* priority-value = "emergency" / "urgent" / "normal"
* / "non-urgent" / other-priority
* other-priority = token
*/
int
{
int ret;
return (EINVAL);
return (ret);
}
/*
* Reply-To = "Reply-To" HCOLON rplyto-spec
* rplyto-spec = ( name-addr / addr-spec )
* *( SEMI rplyto-param )
* rplyto-param = generic-param
*/
int
{
SIP_REPLYTO, plist));
}
/*
* Privacy-hdr = "Privacy" HCOLON priv-value *(";" priv-value)
* priv-value = "header" / "session" / "user" / "none" / "critical"
* / token
*/
int
{
int ret;
return (EINVAL);
(char)NULL);
return (ret);
}
/*
* Require = "Require" HCOLON option-tag *(COMMA option-tag)
* option-tag = token
*/
int
{
int ret;
return (EINVAL);
return (ret);
}
/*
* Retry-After = "Retry-After" HCOLON delta-seconds
* [ comment ] *( SEMI retry-param )
* retry-param = ("duration" EQUAL delta-seconds)
* / generic-param
*/
int
{
int r;
if (secs <= 0)
return (EINVAL);
return (r);
}
return (r);
}
/*
* Server = "Server" HCOLON server-val *(LWS server-val)
* server-val = product / comment
* product = token [SLASH product-version]
* product-version = token
*/
int
{
int ret;
return (EINVAL);
return (ret);
}
/*
* Subject = ( "Subject" / "s" ) HCOLON [TEXT-UTF8-TRIM]
*/
int
{
int ret;
} else {
(char)NULL);
}
return (ret);
}
/*
* Supported = ( "Supported" / "k" ) HCOLON
* [option-tag *(COMMA option-tag)]
*/
int
{
int ret;
} else {
(char)NULL);
}
return (ret);
}
/*
* Timestamp = "Timestamp" HCOLON 1*(DIGIT)
* [ "." *(DIGIT) ] [ LWS delay ]
* delay = *(DIGIT) [ "." *(DIGIT) ]
*/
int
{
int ret;
(char)NULL);
} else {
}
return (ret);
}
/*
* Unsupported = "Unsupported" HCOLON option-tag *(COMMA option-tag)
*/
int
{
int ret;
return (EINVAL);
(char)NULL);
return (ret);
}
/*
* User-Agent = "User-Agent" HCOLON server-val *(LWS server-val)
*/
int
{
int r;
return (EINVAL);
return (r);
}
/*
* Warning = "Warning" HCOLON warning-value *(COMMA warning-value)
* warning-value = warn-code SP warn-agent SP warn-text
* warn-code = 3DIGIT
* warn-agent = hostport / pseudonym
* ; the name or pseudonym of the server adding
* ; the Warning header, for use in debugging
* warn-text = quoted-string
* pseudonym = token
*/
int
{
int header_size;
return (EINVAL);
}
if (_sip_msg->sip_msg_cannot_be_modified) {
return (ENOTSUP);
}
if (new_header == NULL) {
return (ENOMEM);
}
return (0);
}
/*
* RAck = "RAck" HCOLON response-num LWS CSeq-num LWS Method
* response-num = 1*DIGIT
* CSeq-num = 1*DIGIT
*/
int
{
int header_size;
method >= MAX_SIP_METHODS) {
return (EINVAL);
}
if (_sip_msg->sip_msg_cannot_be_modified) {
return (ENOTSUP);
}
if (new_header == NULL) {
return (ENOMEM);
}
return (0);
}
/*
* Allow-Events = ( "Allow-Events" / "u" ) HCOLON event-type
* *(COMMA event-type)
*/
int
{
(char)NULL));
}
/*
* Event = ( "Event" / "o" ) HCOLON event-type
* *( SEMI event-param )
* event-type = event-package *( "." event-template )
* event-package = token-nodot
* event-template = token-nodot
* token-nodot = 1*( alphanum / "-" / "!" / "%" / "*"
* / "_" / "+" / "`" / "'" / "~" )
* event-param = generic-param / ( "id" EQUAL token )
*/
int
{
SIP_SEMI));
}
/*
* Subscription-State = "Subscription-State" HCOLON substate-value
* *( SEMI subexp-params )
* substate-value = "active" / "pending" / "terminated"
* / extension-substate
* extension-substate = token
* subexp-params = ("reason" EQUAL event-reason-value)
* / ("expires" EQUAL delta-seconds)*
* / ("retry-after" EQUAL delta-seconds)
* / generic-param
* event-reason-value = "deactivated"
* / "probation"
* / "rejected"
* / "timeout"
* / "giveup"
* / "noresource"
* / event-reason-extension
* event-reason-extension = token
*/
int
{
SIP_SEMI));
}
/*
* Authorization = "Authorization" HCOLON credentials
* credentials = ("Digest" LWS digest-response)
* / other-response
* digest-response = dig-resp *(COMMA dig-resp)
* dig-resp = username / realm / nonce / digest-uri
* / dresponse / algorithm / cnonce
* / opaque / message-qop
* / nonce-count / auth-param
* username = "username" EQUAL username-value
* username-value = quoted-string
* digest-uri = "uri" EQUAL LDQUOT digest-uri-value RDQUOT
* digest-uri-value = rquest-uri ; Equal to request-uri as specified
* by HTTP/1.1
* message-qop = "qop" EQUAL qop-value
* cnonce = "cnonce" EQUAL cnonce-value
* cnonce-value = nonce-value
* nonce-count = "nc" EQUAL nc-value
* nc-value = 8LHEX
* dresponse = "response" EQUAL request-digest
* request-digest = LDQUOT 32LHEX RDQUOT
* auth-param = auth-param-name EQUAL
* ( token / quoted-string )
* auth-param-name = token
* other-response = auth-scheme LWS auth-param
* *(COMMA auth-param)
* auth-scheme = token
*/
int
{
}
/*
* Authentication-Info = "Authentication-Info" HCOLON ainfo
* *(COMMA ainfo)
* ainfo = nextnonce / message-qop
* / response-auth / cnonce
* / nonce-count
* nextnonce = "nextnonce" EQUAL nonce-value
* response-auth = "rspauth" EQUAL response-digest
* response-digest = LDQUOT *LHEX RDQUOT
*/
int
{
(char)NULL));
}
/*
* Proxy-Authenticate = "Proxy-Authenticate" HCOLON challenge
* challenge = ("Digest" LWS digest-cln *(COMMA digest-cln))
* / other-challenge
* other-challenge = auth-scheme LWS auth-param
* *(COMMA auth-param)
* digest-cln = realm / domain / nonce
* / opaque / stale / algorithm
* / qop-options / auth-param
* realm = "realm" EQUAL realm-value
* realm-value = quoted-string
* domain = "domain" EQUAL LDQUOT URI
* *( 1*SP URI ) RDQUOT
* URI = absoluteURI / abs-path
* nonce = "nonce" EQUAL nonce-value
* nonce-value = quoted-string
* opaque = "opaque" EQUAL quoted-string
* stale = "stale" EQUAL ( "true" / "false" )
* algorithm = "algorithm" EQUAL ( "MD5" / "MD5-sess"
* / token )
* qop-options = "qop" EQUAL LDQUOT qop-value
* *("," qop-value) RDQUOT
* qop-value = "auth" / "auth-int" / token
*/
int
{
SIP_SP));
}
/*
* Proxy-Authorization = "Proxy-Authorization" HCOLON credentials
*/
int
{
SIP_SP));
}
/*
* Proxy-Require = "Proxy-Require" HCOLON option-tag
* *(COMMA option-tag)
* option-tag = token
*/
int
{
(char)NULL));
}
/*
* WWW-Authenticate = "WWW-Authenticate" HCOLON challenge
* extension-header = header-name HCOLON header-value
* header-name = token
* header-value = *(TEXT-UTF8char / UTF8-CONT / LWS)
* message-body = *OCTET
*/
int
{
SIP_SP));
}
/*
* Call-ID = ( "Call-ID" / "i" ) HCOLON callid
*/
int
{
int ret;
return (EINVAL);
return (ENOMEM);
}
(char)NULL);
if (allocd)
return (ret);
}
/*
* CSeq = "CSeq" HCOLON 1*DIGIT LWS Method
*/
int
{
int r;
method >= MAX_SIP_METHODS) {
return (EINVAL);
}
return (r);
}
/*
* Via = ( "Via" / "v" ) HCOLON via-parm *(COMMA via-parm)
* via-parm = sent-protocol LWS sent-by *( SEMI via-params )
* via-params = via-ttl / via-maddr
* / via-received / via-branch
* / via-extension
* via-ttl = "ttl" EQUAL ttl
* via-maddr = "maddr" EQUAL host
* via-received = "received" EQUAL (IPv4address / IPv6address)
* via-branch = "branch" EQUAL token
* via-extension = generic-param
* sent-protocol = protocol-name SLASH protocol-version
* SLASH transport
* protocol-name = "SIP" / token
* protocol-version = token
* transport = "UDP" / "TCP" / "TLS" / "SCTP"
* / other-transport
* sent-by = host [ COLON port ]
* ttl = 1*3DIGIT ; 0 to 255
*/
int sent_by_port, char *via_params)
{
int header_size;
int count;
if (sent_by_port > 0) {
}
if (via_params != NULL) {
header_size += SIP_SPACE_LEN + sizeof (char) +
}
return (NULL);
"%s %c %s/%s %s",
header_size -= count;
if (sent_by_port > 0) {
header_size -= count;
}
if (via_params != NULL) {
header_size -= count;
}
"%s", SIP_CRLF);
return (new_header);
}
/*
* There can be multiple via headers we always append the header.
* We expect the via params to be a semi-colon separated list of parameters.
* We will add a semi-clone, before adding the list to the header.
*/
int
{
return (EINVAL);
}
if (_sip_msg->sip_msg_cannot_be_modified) {
return (ENOTSUP);
}
if (new_header == NULL) {
return (ENOMEM);
}
return (0);
}
/*
* Max-Forwards = "Max-Forwards" HCOLON 1*DIGIT
*/
int
{
return (EINVAL);
NULL));
}
/*
* Content-Type = ( "Content-Type" / "c" ) HCOLON media-type
* media-type = m-type SLASH m-subtype *(SEMI m-parameter)
* m-type = discrete-type / composite-type
* discrete-type = "text" / "image" / "audio" / "video"
* / "application" / extension-token
* composite-type = "message" / "multipart" / extension-token
* extension-token = ietf-token / x-token
* ietf-token = token
* x-token = "x-" token
* m-subtype = extension-token / iana-token
* iana-token = token
* m-parameter = m-attribute EQUAL m-value
* m-attribute = token
* m-value = token / quoted-string
*/
int
{
return (EINVAL);
}
/*
* Content-Length = ( "Content-Length" / "l" ) HCOLON 1*DIGIT
*/
int
{
int header_size;
return (EINVAL);
if (_sip_msg->sip_msg_cannot_be_modified) {
return (ENOTSUP);
}
if (new_header == NULL) {
return (ENOMEM);
}
return (0);
}
/*
* Contact = ("Contact" / "m" ) HCOLON
* ( STAR / (contact-param *(COMMA contact-param)))
* contact-param = (name-addr / addr-spec) *(SEMI contact-params)
* name-addr = [ display-name ] LAQUOT addr-spec RAQUOT
* addr-spec = SIP-URI / SIPS-URI / absoluteURI
* display-name = *(token LWS)/ quoted-string
* contact-params = c-p-q / c-p-expires
* / contact-extension
*/
int
{
}
/*
* From = ( "From" / "f" ) HCOLON from-spec
* from-spec = ( name-addr / addr-spec )
* *( SEMI from-param )
* from-param = tag-param / generic-param
* tag-param = "tag" EQUAL token
*
* Since there can be more than one tags, fromtags is a semi colon separated
* list of tags.
*/
int
{
}
/*
* To = ( "To" / "t" ) HCOLON ( name-addr
* / addr-spec ) *( SEMI to-param )
* to-param = tag-param / generic-param
*/
int
{
}
/*
* Route = "Route" HCOLON route-param *(COMMA route-param)
* route-param = name-addr *( SEMI rr-param )
*/
int
char *route_params)
{
}
/*
* Record-Route = "Record-Route" HCOLON rec-route *(COMMA rec-route)
* rec-route = name-addr *( SEMI rr-param )
* rr-param = generic-param
*/
int
char *route_params)
{
}
/*
* PAssertedID = "P-Asserted-Identity" HCOLON PAssertedID-value
* *(COMMA PAssertedID-value)
* PAssertedID-value = name-addr / addr-spec
*/
int
{
SIP_PASSERTEDID, NULL));
}
/*
* PPreferredID = "P-Preferred-Identity" HCOLON PPreferredID-value
* *(COMMA PPreferredID-value)
* PPreferredID-value = name-addr / addr-spec
*/
int
{
SIP_PPREFERREDID, NULL));
}