• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

char_msg_val.h

Go to the documentation of this file.
00001 /* 
00002  * $Id$
00003  * 
00004  * Copyright (C) 2010 iptelorg GmbH
00005  *
00006  * Permission to use, copy, modify, and distribute this software for any
00007  * purpose with or without fee is hereby granted, provided that the above
00008  * copyright notice and this permission notice appear in all copies.
00009  *
00010  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00011  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00012  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00013  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00014  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00016  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00017  */
00018 /*
00019  * char_msg_val.h
00020  */
00021 /*
00022  * History:
00023  * --------
00024  *  2010-02-10  moved from parser/msg_parser.h and added tag only mode
00025  *               by default (andrei)
00026 */
00031 /* Defines:
00032  *  BRANCH_INCLUDE_FROMTO_BODY - if defined the old (pre 3.1) mode of
00033  *   including the full from & to bodies will be used (instead of only the
00034  *   tags).
00035  * BRANCH_IGNORE_3261_VIA - if defined, no check and special/simpler handling
00036  *   of messages with 3261 cookies in the via branch will be made (same
00037  *   behaviour as in pre 3.1 versions).
00038 */
00039 
00040 #ifndef __char_msg_val_h
00041 #define __char_msg_val_h
00042 
00043 #include "comp_defs.h"
00044 #include "compiler_opt.h"
00045 #include "str.h"
00046 #include "parser/msg_parser.h"
00047 #include "parser/parse_to.h"
00048 #include "parser/parse_from.h"
00049 #include "md5utils.h"
00050 
00055 inline static int char_msg_val( struct sip_msg *msg, char *cv )
00056 {
00057         str src[8];
00058 
00059         if (unlikely(!check_transaction_quadruple(msg))) {
00060                 LOG(L_ERR, "ERROR: can't calculate char_value due "
00061                         "to a parsing error\n");
00062                 memset( cv, '0', MD5_LEN );
00063                 return 0;
00064         }
00065 #ifndef BRANCH_IGNORE_3261_VIA
00066         if (likely(msg->via1->branch && msg->via1->branch->value.len>MCOOKIE_LEN &&
00067                                 memcmp(msg->via1->branch->value.s, MCOOKIE, MCOOKIE_LEN)==0)){
00068                 /* 3261 branch cookie present => hash only the received branch ID */
00069                 src[0]=msg->via1->branch->value;
00070                 MD5StringArray ( cv, src, 1 );
00071                 return 1; /* success */
00072         }
00073 #endif /* BRANCH_IGNORE_3261_VIA */
00074 #ifdef BRANCH_INCLUDE_FROMTO_BODY
00075         /* use the from & to full bodies */
00076         src[0]= msg->from->body;
00077         src[1]= msg->to->body;
00078 #else
00079         /* to body is automatically parsed (via check_transactionquadruple / 
00080            parse_header), but the from body has to be parsed manually */
00081         if (msg->from->parsed==0){
00082                 /* parse from body */
00083                 if (unlikely(parse_from_header(msg) == -1)){
00084                         LOG(L_ERR, "error while parsing From header\n");
00085                         return 0;
00086                 }
00087         }
00088         /* use only the from & to tags */
00089         src[0]=get_from(msg)->tag_value;
00090         src[1]=get_to(msg)->tag_value;
00091 #endif /* BRANCH_INCLUDE_FROMTO_BODY */
00092         src[2]= msg->callid->body;
00093         src[3]= msg->first_line.u.request.uri;
00094         src[4]= get_cseq( msg )->number;
00095 
00096         /* topmost Via is part of transaction key as well ! */
00097         src[5]= msg->via1->host;
00098         src[6]= msg->via1->port_str;
00099         if (likely(msg->via1->branch)) {
00100                 src[7]= msg->via1->branch->value;
00101                 MD5StringArray ( cv, src, 8 );
00102         } else {
00103                 MD5StringArray( cv, src, 7 );
00104         }
00105         return 1;
00106 }
00107 
00108 
00109 
00110 #endif /*__char_msg_val_h*/
00111 
00112 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */

Generated on Tue May 22 2012 13:10:04 for SIP Router by  doxygen 1.7.1