parser/parse_rr.h
63f03e61
 /*
  * $Id$
  *
  * Route & Record-Route Parser
  *
c32feee5
  * Copyright (C) 2001-2003 FhG Fokus
63f03e61
  *
  * This file is part of ser, a free SIP server.
  *
  * ser is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
  * For a license to use the ser software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info@iptel.org
  *
  * ser 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 General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
1eb01c66
 /*! \file
  * \brief Parser :: Route & Record-Route header field parser
  *
  * \ingroup parser
  */
63f03e61
 
 #ifndef PARSE_RR_H
 #define PARSE_RR_H
 
1c6135b6
 #include <stdio.h>
5d17eb17
 #include "msg_parser.h"
644cd741
 #include "parse_nameaddr.h"
 #include "parse_param.h"
 #include "hf.h"
63f03e61
 
 
1eb01c66
 /*! \brief
63f03e61
  * Structure representing a Route & Record-Route HF body
  */
 typedef struct rr {
1eb01c66
 	name_addr_t nameaddr; /*!< Name-addr part */
 	param_t* r2;          /*!< Hook to r2 parameter */
 	param_t* params;      /*!< Linked list of other parameters */
 	int len;              /*!< Length of the whole route field */
 	struct rr* next;      /*!< Next RR in the list */
63f03e61
 } rr_t;
 
 
 /*
  * Parse Route & Record-Route header fields
  */
644cd741
 int parse_rr(struct hdr_field* _r);
63f03e61
 
9c622bc1
 /*
  * Parse the body of Route & Record-Route headers
  */
 int parse_rr_body(char *buf, int len, rr_t **head);
63f03e61
 
 /*
  * Free list of rr
  * _c is head of the list
  */
644cd741
 void free_rr(rr_t** _r);
63f03e61
 
 
 /*
91804f9b
  * Free list of rr
  * _c is head of the list
  */
 void shm_free_rr(rr_t** _r);
 
 
 /*
63f03e61
  * Print list of rrs, just for debugging
  */
1c6135b6
 void print_rr(FILE* _o, rr_t* _r);
63f03e61
 
 
5d17eb17
 /*
  * Duplicate a single rr_t structure using pkg_malloc
  */
22c83b92
 int duplicate_rr(rr_t** _new, rr_t* _r);
5d17eb17
 
 
91804f9b
 /*
  * Duplicate a single rr_t structure using pkg_malloc
  */
22c83b92
 int shm_duplicate_rr(rr_t** _new, rr_t* _r);
91804f9b
 
4efa8778
 /*
  * Find out if a URI contains r2 parameter which indicates
  * that we put 2 record routes
  */
 static inline int is_2rr(str* _params)
 {
 	str s;
 	int i, state = 0;
 
 	if (_params->len == 0) return 0;
 	s = *_params;
 
 	for(i = 0; i < s.len; i++) {
 		switch(state) {
 		case 0:
 			switch(s.s[i]) {
 			case ' ':
 			case '\r':
 			case '\n':
 			case '\t':           break;
 			case 'r':
 			case 'R': state = 1; break;
 			default:  state = 4; break;
 			}
 			break;
 
 		case 1:
 			switch(s.s[i]) {
 			case '2': state = 2; break;
 			default:  state = 4; break;
 			}
 			break;
 
 		case 2:
 			switch(s.s[i]) {
 			case ';':  return 1;
 			case '=':  return 1;
 			case ' ':
 			case '\r':
 			case '\n':
 			case '\t': state = 3; break;
 			default:   state = 4; break;
 			}
 			break;
 
 		case 3:
 			switch(s.s[i]) {
 			case ';':  return 1;
 			case '=':  return 1;
 			case ' ':
 			case '\r':
 			case '\n':
 			case '\t': break;
 			default:   state = 4; break;
 			}
 			break;
 
 		case 4:
 			switch(s.s[i]) {
 			case '\"': state = 5; break;
 			case ';':  state = 0; break;
 			default:              break;
 			}
 			break;
 
 		case 5:
 			switch(s.s[i]) {
 			case '\\': state = 6; break;
 			case '\"': state = 4; break;
 			default:              break;
 			}
 			break;
 
 		case 6: state = 5; break;
 		}
 	}
 
 	if ((state == 2) || (state == 3)) return 1;
 	else return 0;
 }
91804f9b
 
63f03e61
 #endif /* PARSE_RR_H */