parse_rr.h

Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Route & Record-Route Parser
00005  *
00006  * Copyright (C) 2001-2003 FhG Fokus
00007  *
00008  * This file is part of ser, a free SIP server.
00009  *
00010  * ser is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * For a license to use the ser software under conditions
00016  * other than those described here, or to purchase support for this
00017  * software, please contact iptel.org by e-mail at the following addresses:
00018  *    info@iptel.org
00019  *
00020  * ser is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  *
00025  * You should have received a copy of the GNU General Public License 
00026  * along with this program; if not, write to the Free Software 
00027  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028  */
00029 
00036 #ifndef PARSE_RR_H
00037 #define PARSE_RR_H
00038 
00039 #include <stdio.h>
00040 #include "msg_parser.h"
00041 #include "parse_nameaddr.h"
00042 #include "parse_param.h"
00043 #include "hf.h"
00044 
00045 
00049 typedef struct rr {
00050         name_addr_t nameaddr; 
00051         param_t* r2;          
00052         param_t* params;      
00053         int len;              
00054         struct rr* next;      
00055 } rr_t;
00056 
00057 
00058 /*
00059  * Parse Route & Record-Route header fields
00060  */
00061 int parse_rr(struct hdr_field* _r);
00062 
00063 /*
00064  * Parse the body of Route & Record-Route headers
00065  */
00066 int parse_rr_body(char *buf, int len, rr_t **head);
00067 
00068 /*
00069  * Free list of rr
00070  * _c is head of the list
00071  */
00072 void free_rr(rr_t** _r);
00073 
00074 
00075 /*
00076  * Free list of rr
00077  * _c is head of the list
00078  */
00079 void shm_free_rr(rr_t** _r);
00080 
00081 
00082 /*
00083  * Print list of rrs, just for debugging
00084  */
00085 void print_rr(FILE* _o, rr_t* _r);
00086 
00087 
00088 /*
00089  * Duplicate a single rr_t structure using pkg_malloc
00090  */
00091 int duplicate_rr(rr_t** _new, rr_t* _r);
00092 
00093 
00094 /*
00095  * Duplicate a single rr_t structure using pkg_malloc
00096  */
00097 int shm_duplicate_rr(rr_t** _new, rr_t* _r);
00098 
00099 /*
00100  * Find out if a URI contains r2 parameter which indicates
00101  * that we put 2 record routes
00102  */
00103 static inline int is_2rr(str* _params)
00104 {
00105         str s;
00106         int i, state = 0;
00107 
00108         if (_params->len == 0) return 0;
00109         s = *_params;
00110 
00111         for(i = 0; i < s.len; i++) {
00112                 switch(state) {
00113                 case 0:
00114                         switch(s.s[i]) {
00115                         case ' ':
00116                         case '\r':
00117                         case '\n':
00118                         case '\t':           break;
00119                         case 'r':
00120                         case 'R': state = 1; break;
00121                         default:  state = 4; break;
00122                         }
00123                         break;
00124 
00125                 case 1:
00126                         switch(s.s[i]) {
00127                         case '2': state = 2; break;
00128                         default:  state = 4; break;
00129                         }
00130                         break;
00131 
00132                 case 2:
00133                         switch(s.s[i]) {
00134                         case ';':  return 1;
00135                         case '=':  return 1;
00136                         case ' ':
00137                         case '\r':
00138                         case '\n':
00139                         case '\t': state = 3; break;
00140                         default:   state = 4; break;
00141                         }
00142                         break;
00143 
00144                 case 3:
00145                         switch(s.s[i]) {
00146                         case ';':  return 1;
00147                         case '=':  return 1;
00148                         case ' ':
00149                         case '\r':
00150                         case '\n':
00151                         case '\t': break;
00152                         default:   state = 4; break;
00153                         }
00154                         break;
00155 
00156                 case 4:
00157                         switch(s.s[i]) {
00158                         case '\"': state = 5; break;
00159                         case ';':  state = 0; break;
00160                         default:              break;
00161                         }
00162                         break;
00163 
00164                 case 5:
00165                         switch(s.s[i]) {
00166                         case '\\': state = 6; break;
00167                         case '\"': state = 4; break;
00168                         default:              break;
00169                         }
00170                         break;
00171 
00172                 case 6: state = 5; break;
00173                 }
00174         }
00175 
00176         if ((state == 2) || (state == 3)) return 1;
00177         else return 0;
00178 }
00179 
00185 int print_rr_body(struct hdr_field *iroute, str *oroute, int order,
00186                                   unsigned int * nb_recs);
00187 
00188 int get_path_dst_uri(str *_p, str *_dst);
00189 
00190 #endif /* PARSE_RR_H */