rem: inline unsigned char *run_address_switch( struct cpl_interpreter *intr )
add: static inline char *run_address_switch( struct cpl_interpreter *intr )
context: inline unsigned char *run_address_switch( struct cpl_interpreter *intr ){	static str def_port_str = {"5060",4};	unsigned short field, subfield;	unsigned char  *p;	unsigned char  *kid;	unsigned char  attr_name;	unsigned short n;	int i;	int k;	str cpl_val;	str *msg_val;	str *uri;	struct sip_uri parsed_uri;	field = subfield = UNDEF_CHAR;	msg_val = 0;	p=ATTR_PTR(intr->ip);	/* parse the attributes */	for( i=NR_OF_ATTR(intr->ip) ; i>0 ; i-- ) {		get_basic_attr( p, attr_name, n, intr, script_error);		switch (attr_name) {			case FIELD_ATTR:				if (field!=UNDEF_CHAR) {					LOG(L_ERR,"ERROR:cpl-c:run_address_switch: mutiple FIELD "						"attrs found\n");					goto script_error;				}				field = n;				break;			case SUBFIELD_ATTR:				if (subfield!=UNDEF_CHAR) {					LOG(L_ERR,"ERROR:cpl-c:run_address_switch: mutiple SUBFIELD"						" attrs found\n");					goto script_error;				}				subfield = n; break;			default:				LOG(L_ERR,"ERROR:cpl_c:run_address_switch: unknown attribute "					"(%d) in ADDRESS_SWITCH node\n",*p);				goto script_error;		}	}	if (field==UNDEF_CHAR) {		LOG(L_ERR,"ERROR:cpl_c:run_address_switch: mandatory param FIELD "			"no found\n");		goto script_error;	}	/* test the condition from all the sub-nodes */	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:				DBG("DEBUG:run_address_switch: NOT_PRESENT node found ->"					"skipping (useless in this case)\n");				break;			case OTHERWISE_NODE :				if (i!=NR_OF_KIDS(intr->ip)-1) {					LOG(L_ERR,"ERROR:run_address_switch: OTHERWISE node "						"not found as the last sub-node!\n");					goto script_error;				}				DBG("DEBUG:run_address_switch: matching on OTHERWISE node\n");				return get_first_child(kid);			case ADDRESS_NODE :				/* check the number of attributes */				if (NR_OF_ATTR(kid)!=1) {					LOG(L_ERR,"ERROR:run_address_switch: incorect nr of attrs "						"(%d) in ADDRESS node\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 &&				attr_name!=SUBDOMAIN_OF_ATTR) {					LOG(L_ERR,"ERROR:run_address_switch: unknown attribut "						"(%d) in ADDRESS 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_address_switch: testing ADDRESS branch "					" attr_name=%d attr_val=[%.*s](%d)..\n",					attr_name,cpl_val.len,cpl_val.s,cpl_val.len);				/* extract the needed value from the message */				if (!msg_val) {					switch (field) {						case ORIGIN_VAL: /* FROM */							if (!intr->from) {								/* get the header */								if (parse_from_header( intr->msg )==-1)									goto runtime_error;								intr->from = &(get_from(intr->msg)->uri);							}							uri = intr->from;						break;						case DESTINATION_VAL: /* RURI */							if (!intr->ruri)								intr->ruri = GET_RURI( intr->msg );							uri = intr->ruri;							break;						case ORIGINAL_DESTINATION_VAL: /* TO */							if (!intr->to) {								/* get and parse the header */								if (!intr->msg->to &&								(parse_headers(intr->msg,HDR_TO,0)==-1 ||								!intr->msg->to)) {									LOG(L_ERR,"ERROR:run_address_switch: bad "										"msg or missing TO header\n");									goto runtime_error;								}								intr->to = &(get_to(intr->msg)->uri);							}							uri = intr->to;							break;						default:							LOG(L_ERR,"ERROR:run_address_switch: unknown "								"attribute (%d) in ADDRESS node\n",field);							goto script_error;					}					DBG("DEBUG:run_address_switch: extracted uri is <%.*s>\n",						uri->len, uri->s);					switch (subfield) {						case UNDEF_CHAR:							msg_val = uri;							break;						case USER_VAL:							if (parse_uri( uri->s, uri->len, &parsed_uri)<0)								goto runtime_error;							msg_val = &(parsed_uri.user);							break;						case HOST_VAL:							if (parse_uri( uri->s, uri->len, &parsed_uri)<0)								goto runtime_error;							msg_val = &(parsed_uri.host);							break;						case PORT_VAL:							if (parse_uri( uri->s, uri->len, &parsed_uri)<0)								goto runtime_error;							if (parsed_uri.port.len!=0)								msg_val = &(parsed_uri.port);							else								msg_val = &def_port_str;							break;						case TEL_VAL:							if (parse_uri( uri->s, uri->len, &parsed_uri)<0)								goto runtime_error;							if (parsed_uri.user_param_val.len==5 &&							memcmp(parsed_uri.user_param_val.s,"phone",5)==0)								msg_val = &(parsed_uri.user);							break;						case ADDRESS_TYPE_VAL:						case DISPLAY_VAL:						default:							LOG(L_ERR,"ERROR:run_address_switch: unsupported "								"value attribute (%d) in ADDRESS node\n",								subfield);							goto script_error;					}					DBG("DEBUG:run_address_switch: extracted val. is <%.*s>\n",						(msg_val==0)?0:msg_val->len, (msg_val==0)?0:msg_val->s);				}				/* does the value from script match the one from message? */				switch (attr_name) {					case IS_ATTR:						if ( (!msg_val && !cpl_val.s) ||						(msg_val && msg_val->len==cpl_val.len &&						strncasecmp(msg_val->s,cpl_val.s,cpl_val.len)==0)) {							DBG("DEBUG:run_address_switch: matching on "								"ADDRESS node (IS)\n");							return get_first_child(kid);						}						break;					case CONTAINS_ATTR:						if (subfield!=DISPLAY_VAL) {							LOG(L_WARN,"WARNING:run_addres_switch: operator "							"CONTAINS applys only to DISPLAY -> ignored\n");						} else {							if ( msg_val && cpl_val.len<=msg_val->len &&							strcasestr_str(msg_val, &cpl_val)!=0 ) {								DBG("DEBUG:run_address_switch: matching on "									"ADDRESS node (CONTAINS)\n");								return get_first_child(kid);							}						}						break;					case SUBDOMAIN_OF_ATTR:						switch (subfield) {							case HOST_VAL:								k = msg_val->len - cpl_val.len;								if (k>=0 && (k==0 || msg_val->s[k-1]=='.') &&								!strncasecmp(cpl_val.s,msg_val->s+k,cpl_val.len)								) {									DBG("DEBUG:run_address_switch: matching on "										"ADDRESS node (SUBDOMAIN_OF)\n");									return get_first_child(kid);								}								break;							case TEL_VAL:								if (msg_val==0) break;								if (msg_val->len>=cpl_val.len && !strncasecmp(								cpl_val.s,msg_val->s,cpl_val.len)) {									DBG("DEBUG:run_address_switch: matching on "										"ADDRESS node (SUBDOMAIN_OF)\n");									return get_first_child(kid);								}								break;							default:								LOG(L_WARN,"WARNING:run_addres_switch: operator"									" SUBDOMAIN_OF applys only to HOST or TEL "									"-> ignored\n");						}						break;				}				break;			default:				LOG(L_ERR,"ERROR:run_address_switch: unknown output node type "					"(%d) for ADDRESS_SWITCH node\n",NODE_TYPE(kid));				goto script_error;		}	}	/* none of the branches of ADDRESS_SWITCH mached -> go for default */	return DEFAULT_ACTION;runtime_error:	return CPL_RUNTIME_ERROR;script_error:	return CPL_SCRIPT_ERROR;}