📄 cpl_switches.h
字号:
"skipping (useless in this case)\n"); break; case OTHERWISE_NODE : if (i!=NR_OF_KIDS(intr->ip)-1) { LOG(L_ERR,"ERROR:cpl-c:run_time_switch: OTHERWISE node " "not found as the last sub-node!\n"); goto script_error; } DBG("DEBUG:cpl-c:run_time_switch: matching on " "OTHERWISE node\n"); return get_first_child(kid); case TIME_NODE : /* init structures */ memset( &att, 0, sizeof(att)); memset( &trt, 0, sizeof(trt)); if(ac_tm_set_time( &att, intr->recv_time)) goto runtime_error; /* let's see how many attributes we have */ nr_attrs = NR_OF_ATTR(kid); /* get the attributes */ p = ATTR_PTR(kid); for(j=0;j<nr_attrs;j++) { /* get the attribute */ get_basic_attr( p, attr_name, attr_len, intr, script_error); get_str_attr( p, attr_str, attr_len, intr, script_error,1); /* process the attribute */ DBG("DEBUG:cpl_c:run_time_node: attribute [%d] found :" "[%s]\n",attr_name, attr_str); switch (attr_name) { case DTSTART_ATTR: if( !attr_str || tr_parse_dtstart(&trt, attr_str)) goto parse_err; flags ^= (1<<0); break; case DTEND_ATTR: if( !attr_str || tr_parse_dtend(&trt, attr_str)) goto parse_err; flags ^= (1<<1); break; case DURATION_ATTR: if( !attr_str || tr_parse_duration(&trt, attr_str)) goto parse_err; flags ^= (1<<1); break; case FREQ_ATTR: if( attr_str && tr_parse_freq(&trt, attr_str)) goto parse_err; break; case UNTIL_ATTR: if( attr_str && tr_parse_until(&trt, attr_str)) goto parse_err; break; case INTERVAL_ATTR: if( attr_str && tr_parse_interval(&trt, attr_str)) goto parse_err; break; case BYDAY_ATTR: if( attr_str && tr_parse_byday(&trt, attr_str)) goto parse_err; break; case BYMONTHDAY_ATTR: if( attr_str && tr_parse_bymday(&trt, attr_str)) goto parse_err; break; case BYYEARDAY_ATTR: if( attr_str && tr_parse_byyday(&trt, attr_str)) goto parse_err; break; case BYMONTH_ATTR: if( attr_str && tr_parse_bymonth(&trt, attr_str)) goto parse_err; break; case BYWEEKNO_ATTR: if( attr_str && tr_parse_byweekno(&trt, attr_str)) goto parse_err; break; case WKST_ATTR: if( attr_str && tr_parse_wkst(&trt, attr_str)) goto parse_err; break; default: LOG(L_ERR,"ERROR:cpl_c:run_time_switch: " "unsupported attribute [%d] found in TIME " "node\n",attr_name); goto script_error; } /* end attribute switch */ } /* end for*/ /* check the mandatory attributes */ if ( (flags&0x03)!=((1<<0)|(1<<1)) ) { LOG(L_ERR,"ERROR:cpl_c:run_time_switch: attribute DTSTART" ",DTEND,DURATION missing or multi-present\n"); goto script_error; } /* does the recv_time match the specified interval? */ j = check_tmrec( &trt, &att, 0); /* restore the orig TZ */ if ( flags&(1<<7) ) set_TZ(cpl_env.orig_tz.s); /* free structs that I don't need any more */ ac_tm_free( &att ); tmrec_free( &trt ); /* let's see the result ;-) */ switch (j) { case 0: DBG("DEBUG:run_time_switch: matching current " "TIME node\n"); return get_first_child(kid); case -1: LOG(L_ERR,"ERROR:cpl_c:run_time_switch: check_tmrec " "ret. err. when testing time cond. !\n"); goto runtime_error; break; case 1: DBG("DEBUG:cpl_c:run_time_switch: time cond. doesn't" " match !\n"); break; } break; default: LOG(L_ERR,"ERROR:cpl-c: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 TIME_SWITCH matched -> go for default */ ac_tm_free( &att ); tmrec_free( &trt ); return DEFAULT_ACTION;runtime_error: if ( flags&(1<<7) ) set_TZ(cpl_env.orig_tz.s); ac_tm_free( &att ); tmrec_free( &trt ); return CPL_RUNTIME_ERROR;parse_err: LOG(L_ERR,"ERROR:cpl-c:run_priority_switch: error parsing attr [%d][%s]\n", attr_name,attr_str?(char*)attr_str:"NULL");script_error: if ( flags&(1<<7) ) set_TZ(cpl_env.orig_tz.s); ac_tm_free( &att ); tmrec_free( &trt ); return CPL_SCRIPT_ERROR;}inline static int is_lang_tag_matching(str *range,str *cpl_tag,str *cpl_subtag){ char *c; char *end; str tag = {0,0}; str subtag = {0,0}; c = range->s; end = range->s + range->len; while(c<end) { /* eat all spaces to first letter */ while(c<end && (*c==' ' || *c=='\t')) c++; if (c==end) goto error; /* init tag and subtag */ tag.len = 0; subtag.len = 0; /* get the tag */ tag.s = c; if (*c=='*' && (c+1==end||*(c+1)!='-')) { tag.len++; c++; } else while (c<end && ((*c)|0x20)>='a' && ((*c)|0x20)<='z' ) { /*DBG("--- tag ---> <%c>[%d]\n",*c,*c);*/ tag.len++; c++; } if (tag.len==0) goto error; if (c<end && *c=='-') { /* go for the subtag */ subtag.s = ++c; while (c<end && ((*c)|0x20)>='a' && ((*c)|0x20)<='z' ) { /*DBG("--- subtag ---> <%c>[%d]\n",*c,*c);*/ subtag.len++; c++; } if (subtag.len==0) goto error; } else { subtag.s = 0; } if (c<end && *c==';') { /* eat all the params to the ',' */ while(c<end && *c!=',') c++; if (c==end) goto no_matche; } while(c<end && (*c==' '||*c=='\t')) c++; if (c==end || *c==',') { /* do compare */ DBG("DEBUG:cpl-c:is_lang_tag_matching: testing range [%.*s]-[%.*s]" " against tag [%.*s]-[%.*s]\n", tag.len,tag.s,subtag.len,subtag.s, cpl_tag->len,cpl_tag->s,cpl_subtag->len,cpl_subtag->s); /* language range of "*" is ignored for the purpose of matching*/ if ( !(tag.len==1 && *tag.s=='*') ) { /* does the language tag matches ? */ if (tag.len==cpl_tag->len && !strncasecmp(tag.s,cpl_tag->s, tag.len)) { DBG("cucu bau \n"); /* if the subtag of the range is void -> matche */ if (subtag.len==0) return 1; /* the subtags equals -> matche */ if (subtag.len==cpl_subtag->len && !strncasecmp(subtag.s,cpl_subtag->s,subtag.len) ) return 1; } } /* if ',' go for the next language range */ if (*c==',') c++; } else { goto error; } }no_matche: return 0;error: LOG(L_ERR,"ERROR:cpl-c:is_lang_tag_matching: parse error in Accept-" "Language body <%.*s> at char <%c>[%d] offset %ld!\n", range->len,range->s,*c,*c,(long)(c-range->s)); return -1;}/* UPDATED + CHECKED */static inline char *run_language_switch( struct cpl_interpreter *intr ){ char *p; char *kid; char *not_present_node; unsigned short attr_name; int nr_attr; int i,j; str attr = {0,0}; str msg_val = {0,0}; str lang_tag = {0,0}; str lang_subtag = {0,0}; not_present_node = 0; 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_language_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_language_switch: OTHERWISE node " "not found as the last sub-node!\n"); goto script_error; } DBG("DEBUG:run_language_switch: matching on OTHERWISE node\n"); return get_first_child(kid); case LANGUAGE_NODE : /* check the number of attributes */ nr_attr = NR_OF_ATTR(kid); if (nr_attr<1 || nr_attr>2) { LOG(L_ERR,"ERROR:run_string_switch: incorrect nr of attrs " "(%d) in LANGUAGE node (1 or 2)\n",NR_OF_ATTR(kid)); goto script_error; } /* get the attributes */ p = ATTR_PTR(kid); lang_tag.s = lang_subtag.s = 0; lang_tag.len = lang_subtag.len = 0; for(j=0;j<nr_attr;j++) { get_basic_attr( p, attr_name, attr.len, intr, script_error); get_str_attr( p, attr.s, attr.len, intr, script_error,0); if (attr_name==MATCHES_TAG_ATTR ) { lang_tag = attr; DBG("DEBUG:cpl-c:run_language_string: language-tag is" " [%.*s]\n",attr.len,attr.s); }else if (attr_name==MATCHES_SUBTAG_ATTR) { lang_subtag = attr; DBG("DEBUG:cpl-c:run_language_string: language-subtag" " is [%.*s]\n",attr.len,attr.s); }else { LOG(L_ERR,"ERROR:run_language_switch: unknown attribute" " (%d) in LANGUAGE node\n",attr_name); goto script_error; } } /* get the value from the SIP message -> if not yet, do it now * and remember it for the next times */ if (!msg_val.s) { if (intr->accept_language==STR_NOT_FOUND) goto not_present; if (!intr->accept_language) { /* get the accept_language header */ if (!intr->msg->accept_language) { if (parse_headers(intr->msg, HDR_ACCEPTLANGUAGE,0)==-1) { LOG(L_ERR,"ERROR:run_language_switch: " "bad ACCEPT_LANGUAGE header\n"); goto runtime_error; } else if (!intr->msg->accept_language) { /* hdr not present */ intr->accept_language = STR_NOT_FOUND; goto not_present; } } intr->subject = &(intr->msg->accept_language->body); } } trim_len( msg_val.len,msg_val.s, *(intr->subject)); DBG("DEBUG:run_language_switch: extracted msg string is " "<%.*s>\n",msg_val.len, msg_val.s); /* does the value from script match the one from message? */ if (msg_val.len && msg_val.s) { j = is_lang_tag_matching(&msg_val,&lang_tag,&lang_subtag); if (j==1) { DBG("DEBUG:run_language_switch: matching on " "LANGUAGE node\n"); return get_first_child(kid); }else if (j==-1) { goto runtime_error; } } break; default: LOG(L_ERR,"ERROR:cpl_c:run_language_switch: unknown output " "node type (%d) for LANGUAGE_SWITCH node\n", NODE_TYPE(kid)); goto script_error; } /* end switch for NODE_TYPE */ } /* end for for all kids */ 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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -