2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2010, Digium, Inc.
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
19 * \brief sip request response parser header file
22 #ifndef _SIP_REQRESP_H
23 #define _SIP_REQRESP_H
25 /*! \brief uri parameters */
36 AST_LIST_ENTRY(contact) list;
41 struct uriparams params;
47 AST_LIST_HEAD_NOLOCK(contactliststruct, contact);
50 * \brief parses a URI in its components.
53 * - Multiple scheme's can be specified ',' delimited. ex: "sip:,sips:"
54 * - If a component is not requested, do not split around it. This means
55 * that if we don't have domain, we cannot split name:pass.
56 * - It is safe to call with ret_name, pass, hostport pointing all to
58 * - If no secret parameter is provided, ret_name will return with both
60 * - If the URI contains a port number, hostport will return with both
62 * - This function overwrites the the URI string.
64 * \retval 0 on success
65 * \retval -1 on error.
68 * general form we are expecting is sip:user:password;user-parameters@host:port;uri-parameters?headers
71 int parse_uri(char *uri, const char *scheme, char **ret_name, char **pass,
72 char **hostport, char **transport);
75 * \brief parses a URI in to all of its components and any trailing residue
77 * \retval 0 on success
78 * \retval -1 on error.
81 int parse_uri_full(char *uri, const char *scheme, char **user, char **pass,
82 char **hostport, struct uriparams *params, char **headers,
86 * \brief Get caller id name from SIP headers, copy into output buffer
88 * \retval input string pointer placed after display-name field if possible
90 const char *get_calleridname(const char *input, char *output, size_t outputsize);
93 * \brief Get name and number from sip header
95 * \note name and number point to malloced memory on return and must be
96 * freed. If name or number is not found, they will be returned as NULL.
101 int get_name_and_number(const char *hdr, char **name, char **number);
103 /*! \brief Pick out text in brackets from character string
104 * \return pointer to terminated stripped string
105 * \param tmp input string that will be modified
109 * "foo" <bar> valid input, returns bar
110 * foo returns the whole string
111 * < "foo ... > returns the string between brackets
112 * < "foo... bogus (missing closing bracket), returns the whole string
115 char *get_in_brackets(char *tmp);
117 /*! \brief Get text in brackets on a const without copy
119 * \param src String to search
120 * \param[out] start Set to first character inside left bracket.
121 * \param[out] length Set to lenght of string inside brackets
124 * \retval 1 no brackets so got all
126 int get_in_brackets_const(const char *src,const char **start,int *length);
128 /*! \brief Get text in brackets and any trailing residue
132 * \retval 1 no brackets so got all
134 int get_in_brackets_full(char *tmp, char **out, char **residue);
136 /*! \brief Parse the ABNF structure
137 * name-andor-addr = name-addr / addr-spec
138 * into its components and return any trailing message-header parameters
143 int parse_name_andor_addr(char *uri, const char *scheme, char **name,
144 char **user, char **pass, char **domain,
145 struct uriparams *params, char **headers,
148 /*! \brief Parse all contact header contacts
151 * \retval 1 all contacts (star)
154 int get_comma(char *parse, char **out);
156 int parse_contact_header(char *contactheader, struct contactliststruct *contactlist);
159 * \brief register request parsing tests
161 void sip_request_parser_register_tests(void);
164 * \brief unregister request parsing tests
166 void sip_request_parser_unregister_tests(void);
169 * \brief Parse supported header in incoming packet
171 * \details This function parses through the options parameters and
172 * builds a bit field representing all the SIP options in that field. When an
173 * item is found that is not supported, it is copied to the unsupported
177 * \param unsupported out buffer (optional)
178 * \param unsupported out buffer length (optional)
180 unsigned int parse_sip_options(const char *options, char *unsupported, size_t unsupported_len);
183 * \brief Compare two URIs as described in RFC 3261 Section 19.1.4
185 * \param input1 First URI
186 * \param input2 Second URI
187 * \retval 0 URIs match
188 * \retval nonzero URIs do not match or one or both is malformed
190 int sip_uri_cmp(const char *input1, const char *input2);
193 * \brief initialize request and response parser data
198 int sip_reqresp_parser_init(void);
201 * \brief Free resources used by request and response parser
203 void sip_reqresp_parser_exit(void);
206 * \brief Parse a Via header
208 * This function parses the Via header and processes it according to section
209 * 18.2 of RFC 3261 and RFC 3581. Since we don't have a transport layer, we
210 * only care about the maddr and ttl parms. The received and rport params are
213 * \note This function fails to parse some odd combinations of SWS in parameter
217 * VIA syntax. RFC 3261 section 25.1
218 * Via = ( "Via" / "v" ) HCOLON via-parm *(COMMA via-parm)
219 * via-parm = sent-protocol LWS sent-by *( SEMI via-params )
220 * via-params = via-ttl / via-maddr
221 * / via-received / via-branch
223 * via-ttl = "ttl" EQUAL ttl
224 * via-maddr = "maddr" EQUAL host
225 * via-received = "received" EQUAL (IPv4address / IPv6address)
226 * via-branch = "branch" EQUAL token
227 * via-extension = generic-param
228 * sent-protocol = protocol-name SLASH protocol-version
230 * protocol-name = "SIP" / token
231 * protocol-version = token
232 * transport = "UDP" / "TCP" / "TLS" / "SCTP"
234 * sent-by = host [ COLON port ]
235 * ttl = 1*3DIGIT ; 0 to 255
238 struct sip_via *parse_via(const char *header);
241 * \brief Free parsed Via data.
243 void free_via(struct sip_via *v);