📄 cpl_switches.h
字号:
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 matched -> 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;}/* UPDATED + CHECKED */static inline char *run_priority_switch( struct cpl_interpreter *intr ){ static str default_val={"normal",6}; unsigned short n; char *p; char *kid; char *not_present_node; unsigned short attr_name; unsigned short attr_val; unsigned short msg_attr_val; unsigned short msg_prio; int i; str cpl_val = {0,0}; str msg_val = {0,0}; not_present_node = 0; msg_attr_val = NORMAL_VAL; 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_priority_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_priority_switch: OTHERWISE node " "not found as the last sub-node!\n"); goto script_error; } DBG("DEBUG:run_priority_switch: matching on OTHERWISE node\n"); return get_first_child(kid); case PRIORITY_NODE : if (NR_OF_ATTR(kid)!=1) goto script_error; /* get the attribute */ p = ATTR_PTR(kid); get_basic_attr( p, attr_name, attr_val, intr, script_error); if (attr_name!=LESS_ATTR && attr_name!=GREATER_ATTR && attr_name!=EQUAL_ATTR){ LOG(L_ERR,"ERROR:run_priority_switch: unknown attribute " "(%d) in PRIORITY node\n",attr_name); goto script_error; } /* attribute's encoded value */ if (attr_val!=EMERGENCY_VAL && attr_val!=URGENT_VAL && attr_val!=NORMAL_VAL && attr_val!=NON_URGENT_VAL && attr_val!=UNKNOWN_PRIO_VAL) { LOG(L_ERR,"ERROR:run_priority_switch: unknown encoded " "value (%d) for attribute (*d) in PRIORITY node\n",*p); goto script_error; } if (attr_val==UNKNOWN_PRIO_VAL) { if (attr_name!=EQUAL_ATTR) { LOG(L_ERR,"ERROR:cpl_c:run_priority_switch:bad PRIORITY" " branch: attr=EQUAL doesn't match val=UNKNOWN\n"); goto script_error; } /* if the attr is UNKNOWN, its string value is present */ get_basic_attr(p, n,cpl_val.len, intr, script_error); if (n!=PRIOSTR_ATTR) { LOG(L_ERR,"ERROR:run_priority_switch: expected PRIOSTR" "(%d) attr, found (%d)\n",PRIOSTR_ATTR,n); goto script_error; } get_str_attr(p, cpl_val.s, cpl_val.len,intr,script_error,1); } DBG("DEBUG:run_priority_switch: testing PRIORITY branch " "(attr=%d,val=%d) [%.*s](%d)..\n", attr_name,attr_val,cpl_val.len,cpl_val.s,cpl_val.len); if (!msg_val.s) { if (!intr->priority) { /* get the PRIORITY header from message */ if (!intr->msg->priority) { if (parse_headers(intr->msg,HDR_PRIORITY,0)==-1) { LOG(L_ERR,"ERROR:run_priority_switch: bad " "sip msg or PRIORITY header !\n"); goto runtime_error; } else if (!intr->msg->priority) { LOG(L_NOTICE,"NOTICE:run_priority_switch: " "missing PRIORITY header -> using " "default value \"normal\"!\n"); intr->priority = &default_val; } else { intr->priority = &(intr->msg->priority->body); } } else { intr->priority = &(intr->msg->priority->body); } } trim_len( msg_val.len, msg_val.s, *(intr->priority)); /* encode attribute's value from SIP message */ if ( msg_val.len==EMERGENCY_STR_LEN && !strncasecmp(msg_val.s,EMERGENCY_STR,msg_val.len) ) { msg_attr_val = EMERGENCY_VAL; } else if ( msg_val.len==URGENT_STR_LEN && !strncasecmp(msg_val.s,URGENT_STR,msg_val.len) ) { msg_attr_val = URGENT_VAL; } else if ( msg_val.len==NORMAL_STR_LEN && !strncasecmp(msg_val.s,NORMAL_STR,msg_val.len) ) { msg_attr_val = NORMAL_VAL; } else if ( msg_val.len==NON_URGENT_STR_LEN && !strncasecmp(msg_val.s,NON_URGENT_STR,msg_val.len) ) { msg_attr_val = NON_URGENT_VAL; } else { msg_attr_val = UNKNOWN_PRIO_VAL; } DBG("DEBUG:run_priority_switch: extracted msg priority is " "<%.*s> decoded as [%d]\n", msg_val.len,msg_val.s,msg_attr_val); } DBG("DEBUG:run_priority_switch: using msg string <%.*s>\n", msg_val.len, msg_val.s); /* attr_val (from cpl) cannot be UNKNOWN - we already * check it -> check only for msg_attr_val for non-EQUAL op */ if (msg_attr_val==UNKNOWN_PRIO_VAL && attr_name!=EQUAL_ATTR) { LOG(L_NOTICE,"NOTICE:run_priority_switch: UNKNOWN " "value found in sip_msg when string a LESS/GREATER " "cmp -> force the value to default \"normal\"\n"); msg_prio = NORMAL_VAL; } else { msg_prio = msg_attr_val; } /* does the value from script match the one from message? */ switch (attr_name) { case LESS_ATTR: switch (attr_val) { case EMERGENCY_VAL: if (msg_prio!=EMERGENCY_VAL) break; /*OK*/ else continue; /* for cycle for all kids */ case URGENT_VAL: if (msg_prio!=EMERGENCY_VAL && msg_prio!=URGENT_VAL) break; /* OK */ else continue; /* for cycle for all kids */ case NORMAL_VAL: if (msg_prio==NON_URGENT_VAL) break; /*OK*/ else continue; /* for cycle for all kids */ case NON_URGENT_VAL: continue; /* for cycle for all kids */ } break; case GREATER_ATTR: switch (attr_val) { case EMERGENCY_VAL: continue; /* for cycle for all kids */ case URGENT_VAL: if (msg_prio!=EMERGENCY_VAL) break; /*OK*/ else continue; /* for cycle for all kids */ case NORMAL_VAL: if (msg_prio!=NON_URGENT_VAL && msg_prio!=NORMAL_VAL) break; /*OK*/ else continue; /* for cycle for all kids */ case NON_URGENT_VAL: if (msg_prio!=NON_URGENT_VAL) break; /*OK*/ else continue; /* for cycle for all kids */ } break; case EQUAL_ATTR: if ( attr_val==msg_prio ) { if (attr_val==UNKNOWN_PRIO_VAL) { if ( msg_val.len==cpl_val.len && !strncasecmp(msg_val.s,cpl_val.s,msg_val.len)){ break; /* OK */ } } else { break; /* OK */ } } continue; /* for cycle for all kids */ break; } /* end switch for attr_name */ DBG("DEBUG:run_priority_switch: matching current " "PRIORITY node\n"); return get_first_child(kid); break; default: LOG(L_ERR,"ERROR:run_priority_switch: unknown output node type" " (%d) for PRIORITY_SWITCH node\n",NODE_TYPE(kid)); goto script_error; } /* end switch for NODE_TYPE */ } /* end for for all kids */ /* none of the branches of PRIORITY_SWITCH matched -> go for default */ return DEFAULT_ACTION;runtime_error: return CPL_RUNTIME_ERROR;script_error: return CPL_SCRIPT_ERROR;}inline static int set_TZ(char *tz_env){ DBG("DEBUG:cpl-c:set_TZ: switching TZ as \"%s\"\n",tz_env); if (putenv( tz_env )==-1) { LOG(L_ERR,"ERROR:cpl-c:set_TZ: setenv failed -> unable to set TZ " " \"%s\"\n",tz_env); return -1; } tzset(); /* just to be sure */ return 0;}/* UPDATED + CHECKED */static inline char *run_time_switch( struct cpl_interpreter *intr ){ char *p; char *kid; char *attr_str; unsigned short attr_name; unsigned short attr_len; unsigned char flags = 0; int nr_attrs; int i,j; str user_tz = {0,0}; ac_tm_t att; tmrec_t trt; DBG("DEBUG:cpl-c:run_time_switch: checking recv. time stamp <%d>\n", intr->recv_time); switch (NR_OF_ATTR(intr->ip)) { case 1: p = ATTR_PTR(intr->ip); get_basic_attr( p, attr_name, user_tz.len, intr, script_error); if (attr_name!=TZID_ATTR) { LOG(L_ERR,"ERROR:cpl-c:run_time_switch: bad attribute -> " " expected=%d, found=%d\n",TZID_ATTR,attr_name); goto script_error; } get_str_attr( p, user_tz.s, user_tz.len, intr, script_error, 1); case 0: break; default: LOG(L_ERR,"ERROR:cpl-c:run_time_switch: incorrect number of attr ->" " found=%d expected=(0,1)\n",NR_OF_ATTR(intr->ip)); goto script_error; } if (user_tz.s && user_tz.len) { if (set_TZ(user_tz.s)==-1) goto runtime_error; flags |= (1<<7); } 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:cpl-c:run_time_switch: NOT_PRESENT node found ->"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -