reqresp_parser.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2010, Digium, Inc.
00005  *
00006  * See http://www.asterisk.org for more information about
00007  * the Asterisk project. Please do not directly contact
00008  * any of the maintainers of this project for assistance;
00009  * the project provides a web site, mailing lists and IRC
00010  * channels for your use.
00011  *
00012  * This program is free software, distributed under the terms of
00013  * the GNU General Public License Version 2. See the LICENSE file
00014  * at the top of the source tree.
00015  */
00016 
00017 /*!
00018  * \file
00019  * \brief sip request response parser header file
00020  */
00021 
00022 #ifndef _SIP_REQRESP_H
00023 #define _SIP_REQRESP_H
00024 
00025 /*! \brief uri parameters */
00026 struct uriparams {
00027    char *transport;
00028    char *user;
00029    char *method;
00030    char *ttl;
00031    char *maddr;
00032    int lr;
00033 };
00034 
00035 struct contact {
00036    AST_LIST_ENTRY(contact) list;
00037    char *name;
00038    char *user;
00039    char *pass;
00040    char *hostport;
00041    struct uriparams params;
00042    char *headers;
00043    char *expires;
00044    char *q;
00045 };
00046 
00047 AST_LIST_HEAD_NOLOCK(contactliststruct, contact);
00048 
00049 /*!
00050  * \brief parses a URI in its components.
00051  *
00052  * \note
00053  * - Multiple scheme's can be specified ',' delimited. ex: "sip:,sips:"
00054  * - If a component is not requested, do not split around it. This means
00055  *   that if we don't have domain, we cannot split name:pass.
00056  * - It is safe to call with ret_name, pass, hostport pointing all to
00057  *   the same place.
00058  * - If no secret parameter is provided, ret_name will return with both
00059  *   parts, user:secret.
00060  * - If the URI contains a port number, hostport will return with both
00061  *   parts, host:port.
00062  * - This function overwrites the the URI string.
00063  * 
00064  * \retval 0 on success
00065  * \retval -1 on error.
00066  *
00067  * \verbatim
00068  * general form we are expecting is sip:user:password;user-parameters@host:port;uri-parameters?headers
00069  * \endverbatim
00070  */
00071 int parse_uri(char *uri, const char *scheme, char **ret_name, char **pass,
00072          char **hostport, char **transport);
00073 
00074 /*!
00075  * \brief parses a URI in to all of its components and any trailing residue
00076  *
00077  * \retval 0 on success
00078  * \retval -1 on error.
00079  *
00080  */
00081 int parse_uri_full(char *uri, const char *scheme, char **user, char **pass,
00082          char **hostport, struct uriparams *params, char **headers,
00083          char **residue);
00084 
00085 /*!
00086  * \brief  Get caller id name from SIP headers, copy into output buffer
00087  *
00088  * \retval input string pointer placed after display-name field if possible
00089  */
00090 const char *get_calleridname(const char *input, char *output, size_t outputsize);
00091 
00092 /*!
00093  * \brief  Get name and number from sip header
00094  *
00095  * \note name and number point to malloced memory on return and must be
00096  * freed. If name or number is not found, they will be returned as NULL.
00097  *
00098  * \retval 0 success
00099  * \retval -1 failure
00100  */
00101 int get_name_and_number(const char *hdr, char **name, char **number);
00102 
00103 /*! \brief Pick out text in brackets from character string
00104  * \return pointer to terminated stripped string
00105  * \param tmp input string that will be modified
00106  *
00107  * Examples:
00108  * \verbatim
00109  * "foo" <bar> valid input, returns bar
00110  *  foo returns the whole string
00111  * < "foo ... >   returns the string between brackets
00112  * < "foo...    bogus (missing closing bracket), returns the whole string
00113  * \endverbatim
00114  */
00115 char *get_in_brackets(char *tmp);
00116 
00117 /*! \brief Get text in brackets on a const without copy
00118  *
00119  * \param src String to search
00120  * \param[out] start Set to first character inside left bracket.
00121  * \param[out] length Set to lenght of string inside brackets
00122  * \retval 0 success
00123  * \retval -1 failure
00124  * \retval 1 no brackets so got all
00125  */
00126 int get_in_brackets_const(const char *src,const char **start,int *length);
00127 
00128 /*! \brief Get text in brackets and any trailing residue
00129  *
00130  * \retval 0 success
00131  * \retval -1 failure
00132  * \retval 1 no brackets so got all
00133  */
00134 int get_in_brackets_full(char *tmp, char **out, char **residue);
00135 
00136 /*! \brief Parse the ABNF structure
00137  * name-andor-addr = name-addr / addr-spec
00138  * into its components and return any trailing message-header parameters
00139  *
00140  * \retval 0 success
00141  * \retval -1 failure
00142  */
00143 int parse_name_andor_addr(char *uri, const char *scheme, char **name,
00144            char **user, char **pass, char **domain,
00145            struct uriparams *params, char **headers,
00146            char **remander);
00147 
00148 /*! \brief Parse all contact header contacts
00149  * \retval 0 success
00150  * \retval -1 failure
00151  * \retval 1 all contacts (star)
00152  */
00153 
00154 int get_comma(char *parse, char **out);
00155 
00156 int parse_contact_header(char *contactheader, struct contactliststruct *contactlist);
00157 
00158 /*!
00159  * \brief register request parsing tests
00160  */
00161 void sip_request_parser_register_tests(void);
00162 
00163 /*!
00164  * \brief unregister request parsing tests
00165  */
00166 void sip_request_parser_unregister_tests(void);
00167 
00168 /*!
00169  * \brief Parse supported header in incoming packet
00170  *
00171  * \details This function parses through the options parameters and
00172  * builds a bit field representing all the SIP options in that field. When an
00173  * item is found that is not supported, it is copied to the unsupported
00174  * out buffer.
00175  *
00176  * \param option list
00177  * \param unsupported out buffer (optional)
00178  * \param unsupported out buffer length (optional)
00179  *
00180  * \note Because this function can be called multiple times, it will append
00181  * whatever options are specified in \c options to \c unsupported. Callers
00182  * of this function should make sure the unsupported buffer is clear before
00183  * calling this function.
00184  */
00185 unsigned int parse_sip_options(const char *options, char *unsupported, size_t unsupported_len);
00186 
00187 /*!
00188  * \brief Compare two URIs as described in RFC 3261 Section 19.1.4
00189  *
00190  * \param input1 First URI
00191  * \param input2 Second URI
00192  * \retval 0 URIs match
00193  * \retval nonzero URIs do not match or one or both is malformed
00194  */
00195 int sip_uri_cmp(const char *input1, const char *input2);
00196 
00197 /*!
00198  * \brief initialize request and response parser data
00199  *
00200  * \retval 0 Success
00201  * \retval -1 Failure
00202  */
00203 int sip_reqresp_parser_init(void);
00204 
00205 /*!
00206  * \brief Free resources used by request and response parser
00207  */
00208 void sip_reqresp_parser_exit(void);
00209 
00210 /*!
00211  * \brief Parse a Via header
00212  *
00213  * This function parses the Via header and processes it according to section
00214  * 18.2 of RFC 3261 and RFC 3581. Since we don't have a transport layer, we
00215  * only care about the maddr and ttl parms.  The received and rport params are
00216  * not parsed.
00217  *
00218  * \note This function fails to parse some odd combinations of SWS in parameter
00219  * lists.
00220  *
00221  * \code
00222  * VIA syntax. RFC 3261 section 25.1
00223  * Via               =  ( "Via" / "v" ) HCOLON via-parm *(COMMA via-parm)
00224  * via-parm          =  sent-protocol LWS sent-by *( SEMI via-params )
00225  * via-params        =  via-ttl / via-maddr
00226  *                   / via-received / via-branch
00227  *                   / via-extension
00228  * via-ttl           =  "ttl" EQUAL ttl
00229  * via-maddr         =  "maddr" EQUAL host
00230  * via-received      =  "received" EQUAL (IPv4address / IPv6address)
00231  * via-branch        =  "branch" EQUAL token
00232  * via-extension     =  generic-param
00233  * sent-protocol     =  protocol-name SLASH protocol-version
00234  *                   SLASH transport
00235  * protocol-name     =  "SIP" / token
00236  * protocol-version  =  token
00237  * transport         =  "UDP" / "TCP" / "TLS" / "SCTP"
00238  *                   / other-transport
00239  * sent-by           =  host [ COLON port ]
00240  * ttl               =  1*3DIGIT ; 0 to 255
00241  * \endcode
00242  */
00243 struct sip_via *parse_via(const char *header);
00244 
00245 /*
00246  * \brief Free parsed Via data.
00247  */
00248 void free_via(struct sip_via *v);
00249 
00250 #endif

Generated on Thu Apr 16 06:27:44 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6