rem: unsigned char *p; unsigned char *kid; unsigned char *not_present_node; unsigned char attr_name;
add: char *p; char *kid; char *not_present_node; unsigned short attr_name;
context: inline unsigned char *run_string_switch( struct cpl_interpreter *intr ){	unsigned short field;	unsigned char *p;	unsigned char *kid;	unsigned char *not_present_node;	unsigned char attr_name;	int i;	str cpl_val;	str msg_val;	not_present_node = 0;	msg_val.s = 0;	msg_val.len = 0;	/* parse the attribute */	if (NR_OF_ATTR(intr->ip)!=1) {		LOG(L_ERR,"ERROR:cpl_c:run_string_switch: node should have 1 attr, not"			" (%d)\n",NR_OF_ATTR(intr->ip));		goto script_error;	}	p=ATTR_PTR(intr->ip);	get_basic_attr( p, attr_name, field, intr, script_error);	if (attr_name!=FIELD_ATTR) {		LOG(L_ERR,"ERROR:cpl_c:run_string_switch: unknown param type (%d)"			" for STRING_SWITCH node\n",*p);		goto script_error;	}	for( i=0 ; i<NR_OF_KIDS(intr->ip) ; i++ ) {		kid = intr->ip + KID_OFFSET(intr->ip,i);		check_overflow_by_ptr( kid+SIMPLE_NODE_SIZE(kid), intr, script_error);		switch ( NODE_TYPE(kid) ) {			case NOT_PRESENT_NODE:				if (not_present_node) {					LOG(L_ERR,"ERROR:run_string_switch: NOT_PRESENT node "						"found twice!\n");					goto script_error;				}				not_present_node = kid;				break;			case OTHERWISE_NODE :				if (i!=NR_OF_KIDS(intr->ip)-1) {					LOG(L_ERR,"ERROR:run_string_switch: OTHERWISE node "						"not found as the last sub-node!\n");					goto script_error;				}				DBG("DEBUG:run_string_switch: matching on OTHERWISE node\n");				return get_first_child(kid);			case STRING_NODE :				/* check the number of attributes */				if (NR_OF_ATTR(kid)!=1) {					LOG(L_ERR,"ERROR:run_string_switch: incorect nr of attrs "						"(%d) in STRING node (expected 1)\n",NR_OF_ATTR(kid));					goto script_error;				}				/* get the attribute name */				p = ATTR_PTR(kid);				get_basic_attr( p, attr_name, cpl_val.len, intr, script_error);				if (attr_name!=IS_ATTR && attr_name!=CONTAINS_ATTR ) {					LOG(L_ERR,"ERROR:run_string_switch: unknown attribut "						"(%d) in STRING node\n",attr_name);					goto script_error;				}				/* get attribute value */				get_str_attr( p, cpl_val.s, cpl_val.len, intr, script_error,1);				DBG("DEBUG:run_string_switch: testing STRING branch "					"attr_name=%d attr_val=[%.*s](%d)..\n",					attr_name,cpl_val.len,cpl_val.s,cpl_val.len);				if (!msg_val.s) {					switch (field) {						case SUBJECT_VAL: /* SUBJECT */							if (intr->subject==STR_NOT_FOUND)								goto not_present;							if (!intr->subject) {								/* get the subject header */								if (!intr->msg->subject) {									if (parse_headers(intr->msg,									HDR_SUBJECT,0)==-1) {										LOG(L_ERR,"ERROR:run_string_switch: "										"bad SUBJECT header\n");										goto runtime_error;									} else if (!intr->msg->subject) {										/* hdr not present */										intr->subject = STR_NOT_FOUND;										goto not_present;									}								}								intr->subject =									&(intr->msg->subject->body);							}							trim_len( msg_val.len,msg_val.s,								*(intr->subject));							break;						case ORGANIZATION_VAL: /* ORGANIZATION */							if (intr->organization==STR_NOT_FOUND)								goto not_present;							if (!intr->organization) {								/* get the organization header */								if (!intr->msg->organization) {									if (parse_headers(intr->msg,									HDR_ORGANIZATION,0)==-1) {										LOG(L_ERR,"ERROR:run_string_switch: "										"bad ORGANIZATION hdr\n");										goto runtime_error;									} else if (!intr->msg->organization) {										/* hdr not present */										intr->organization = STR_NOT_FOUND;										goto not_present;									}								}								intr->organization =									&(intr->msg->organization->body);							}							trim_len( msg_val.len,msg_val.s,								*(intr->organization));							break;						case USER_AGENT_VAL: /* User Agent */							if (intr->user_agent==STR_NOT_FOUND)								goto not_present;							if (!intr->user_agent) {								/* get the  header */								if (!intr->msg->user_agent) {									if (parse_headers(intr->msg,									HDR_USERAGENT,0)==-1) {										LOG(L_ERR,"ERROR:run_string_switch: "										"bad USERAGENT hdr\n");										goto runtime_error;									} else if (!intr->msg->user_agent) {										/* hdr not present */										intr->user_agent = STR_NOT_FOUND;										goto not_present;									}								}								intr->user_agent =									&(intr->msg->user_agent->body);							}							trim_len( msg_val.len,msg_val.s,								*(intr->user_agent));							break;						default:							LOG(L_ERR,"ERROR:run_string_switch: unknown "								"attribute (%d) in STRING node\n",field);							goto script_error;					}					DBG("DEBUG:run_string_switch: extracted msg string is "						"<%.*s>\n",msg_val.len, msg_val.s);				}				/* does the value from script match the one from message? */				switch (attr_name) {					case IS_ATTR:						if ( (!msg_val.s && !cpl_val.s) ||						(msg_val.len==cpl_val.len &&						strncasecmp(msg_val.s,cpl_val.s,cpl_val.len)==0)) {							DBG("DEBUG:run_string_switch: matching on "								"STRING node (IS)\n");							return get_first_child(kid);						}						break;					case CONTAINS_ATTR:						if (cpl_val.len<=msg_val.len &&						strcasestr_str(&msg_val, &cpl_val)!=0 ) {							DBG("DEBUG:run_string_switch: matching on "								"STRING node (CONTAINS)\n");							return get_first_child(kid);						}						break;				}				break;			default:				LOG(L_ERR,"ERROR:run_string_switch: unknown output node type "					"(%d) for STRING_SWITCH node\n",NODE_TYPE(kid));				goto script_error;		}	}	/* none of the branches of STRING_SWITCH mached -> go for default */	return DEFAULT_ACTION;not_present:	DBG("DEBUG:run_string_switch: required hdr not present in sip msg\n");	if (not_present_node)		return get_first_child(not_present_node);	/* look for the NOT_PRESENT node */	DBG("DEBUG:run_string_switch: searching for NOT_PRESENT sub-node..\n");	for(; i<NR_OF_KIDS(intr->ip) ; i++ ) {		kid = intr->ip + KID_OFFSET(intr->ip,i);		check_overflow_by_ptr( kid+SIMPLE_NODE_SIZE(kid), intr, script_error);		if (NODE_TYPE(kid)==NOT_PRESENT_NODE)			return get_first_child(kid);	}	return DEFAULT_ACTION;runtime_error:	return CPL_RUNTIME_ERROR;script_error:	return CPL_SCRIPT_ERROR;}