⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpl_parser.c

📁 用来作为linux中SIP SERVER,完成VOIP网络电话中服务器的功能
💻 C
📖 第 1 页 / 共 3 页
字号:
	return p-p_orig;error:	return -1;}/* Attr. encoding for STRING_SWITCH node: *  [| attr1_t(2) attr1_len(2) attr_val(2*x) |]?  IS attr  (NT) *  [| attr2_t(2) attr2_len(2) attr_val(2*x) |]?  CONTAINS attr (NT) */static inline int encode_string_switch_attr(xmlNodePtr  node, char *node_ptr,																char *buf_end){	xmlAttrPtr     attr;	char           *p, *p_orig;	unsigned char  *nr_attr;	str            val;	nr_attr = &(NR_OF_ATTR(node_ptr));	*nr_attr = 0;	p = p_orig = ATTR_PTR(node_ptr);	FOR_ALL_ATTR(node,attr) {		(*nr_attr)++;		/* there is only one attribute -> MATCHES */		if (attr->name[0]!='F' && attr->name[0]!='f') {			LOG(L_ERR,"ERROR:cpl_c:encode_string_switch_attr: unknown "				"attribute <%s>\n",attr->name);			goto error;		}		set_attr_type(p, FIELD_ATTR, buf_end, error);		/* attribute's encoded value */		get_attr_val( attr->name , val, error);		switch (val.s[0]) {			case 'S': case 's':				append_short_attr(p, SUBJECT_VAL, buf_end, error);				break;			case 'O': case 'o':				append_short_attr(p, ORGANIZATION_VAL, buf_end, error);				break;			case 'U': case 'u':				append_short_attr(p, USER_AGENT_VAL, buf_end, error);				break;			case 'D': case 'd':				append_short_attr(p, DISPLAY_VAL, buf_end, error);				break;			default:				LOG(L_ERR,"ERROR:cpl_c:encode_string_switch_attr: unknown "					"value <%s> for FIELD\n",attr->name);				goto error;		}	}	return p-p_orig;error:	return -1;}/* Attr. encoding for STRING node: *  [| attr1_t(2) attr1_len(2) attr_val(2*x) |]?  IS attr  (NT) *  [| attr2_t(2) attr2_len(2) attr_val(2*x) |]?  CONTAINS attr (NT) */static inline int encode_string_attr(xmlNodePtr  node, char *node_ptr, char *buf_end){	xmlAttrPtr     attr;	char  *p, *p_orig;	unsigned char  *nr_attr;	str            val;	nr_attr = &(NR_OF_ATTR(node_ptr));	*nr_attr = 0;	p = p_orig = ATTR_PTR(node_ptr);	FOR_ALL_ATTR(node,attr) {		(*nr_attr)++;		switch(attr->name[0]) {			case 'I': case 'i':				set_attr_type(p, IS_ATTR, buf_end, error);				break;			case 'C': case 'c':				set_attr_type(p, CONTAINS_ATTR, buf_end, error);				break;			default:				LOG(L_ERR,"ERROR:cpl_c:encode_string_attr: unknown "					"attribute <%s>\n",attr->name);				goto error;		}		/* attribute's encoded value */		get_attr_val( attr->name , val, error);		val.len++; /* grab also the \0 */		append_str_attr(p,val, buf_end, error);	}	return p-p_orig;error:	return -1;}/* Attr. encoding for TIME_SWITCH node: *  [| attr1_t(2) attr1_len(2) attr_val(2*x) |]?  TZID attr  (NT) *  [| attr2_t(2) attr2_len(2) attr_val(2*x) |]?  TZURL attr (NT) */static inline int encode_time_switch_attr(xmlNodePtr  node, char *node_ptr,																char *buf_end){	static str     tz_str = {"TZ=",3};	xmlAttrPtr     attr;	char           *p, *p_orig;	unsigned char  *nr_attr;	str            val;	nr_attr = &(NR_OF_ATTR(node_ptr));	*nr_attr = 0;	p = p_orig = ATTR_PTR(node_ptr);	FOR_ALL_ATTR(node,attr) {		(*nr_attr)++;		switch(attr->name[2]) {			case 'I': case 'i':				set_attr_type(p, TZID_ATTR, buf_end, error);				/* attribute's encoded value */				get_attr_val( attr->name , val, error);				val.len++; /* grab also the \0 */				append_double_str_attr(p,tz_str,val, buf_end, error);				break;			case 'U': case 'u':				/* set_attr_type(p, TZURL_ATTR, buf_end, error);				 * is a waste of space to copy the url - the interpreter doesn't				 * use it at all ;-) */				break;			default:				LOG(L_ERR,"ERROR:cpl_c:encode_time_switch_attr: unknown "					"attribute <%s>\n",attr->name);				goto error;		}	}	return p-p_orig;error:	return -1;}/* Attr. encoding for TIME node: *   | attr1_t(2) attr1_len(2) attr1_val(2*x) |       DSTART attr  (NT) *  [| attr2_t(2) attr2_len(2) attr2_val(2*x) |]?     DTEND attr (NT) *  [| attr3_t(2) attr3_len(2) attr3_val(2*x) |]?     DURATION attr (NT) *  [| attr4_t(2) attr4_len(2) attr4_val(2*x) |]?     FREQ attr (NT) *  [| attr5_t(2) attr5_len(2) attr5_val(2*x) |]?     WKST attr (NT) *  [| attr6_t(2) attr6_len(2) attr6_val(2*x) |]?     BYYEARDAY attr (NT) *  [| attr7_t(2) attr7_len(2) attr7_val(2*x) |]?     COUNT attr (NT) *  [| attr8_t(2) attr8_len(2) attr8_val(2*x) |]?     BYSETPOS attr (NT) *  [| attr9_t(2) attr9_len(2) attr9_val(2*x) |]?     BYMONTH attr (NT) *  [| attr10_t(2) attr10_len(2) attr_val10(2*x) |]?  BYMONTHDAY attr (NT) *  [| attr11_t(2) attr11_len(2) attr_val11(2*x) |]?  BYMINUTE attr (NT) *  [| attr12_t(2) attr12_len(2) attr_val12(2*x) |]?  INTERVAL attr (NT) *  [| attr13_t(2) attr13_len(2) attr_val13(2*x) |]?  UNTIL attr (NT) *  [| attr14_t(2) attr14_len(2) attr_val14(2*x) |]?  BYSECOND attr (NT) *  [| attr15_t(2) attr15_len(2) attr_val15(2*x) |]?  BYHOUR attr (NT) *  [| attr16_t(2) attr16_len(2) attr_val16(2*x) |]?  BYDAY attr (NT) *  [| attr17_t(2) attr17_len(2) attr_val17(2*x) |]?  BYWEEKNO attr (NT) */static inline int encode_time_attr(xmlNodePtr  node, char *node_ptr,																char *buf_end){	xmlAttrPtr     attr;	char           *p, *p_orig;	unsigned char  *nr_attr;	str            val;	nr_attr = &(NR_OF_ATTR(node_ptr));	*nr_attr = 0;	p = p_orig = ATTR_PTR(node_ptr);	FOR_ALL_ATTR(node,attr) {		(*nr_attr)++;		switch (attr->name[4]) {			case 0:				if (attr->name[0]=='F' || attr->name[0]=='f')					set_attr_type(p, FREQ_ATTR, buf_end, error);				else if (attr->name[0]=='W' || attr->name[0]=='w')					set_attr_type(p, WKST_ATTR, buf_end, error);				break;			case 'a': case 'A':				if (attr->name[0]=='D' || attr->name[0]=='d')					set_attr_type(p, DTSTART_ATTR, buf_end, error);				else if (attr->name[0]=='B' || attr->name[0]=='b')					set_attr_type(p, BYYEARDAY_ATTR, buf_end, error);				break;			case 't': case 'T':				if (attr->name[0]=='D' || attr->name[0]=='d')					set_attr_type(p, DURATION_ATTR, buf_end, error);				else if (attr->name[0]=='C' || attr->name[0]=='c')					set_attr_type(p, COUNT_ATTR, buf_end, error);				else if (attr->name[0]=='B' || attr->name[0]=='b')					set_attr_type(p, BYSETPOS_ATTR, buf_end, error);				break;			case 'n': case 'N':				if (!attr->name[0])					set_attr_type(p, BYMONTH_ATTR, buf_end, error);				else if (attr->name[0]=='D' || attr->name[0]=='d')					set_attr_type(p, BYMONTHDAY_ATTR, buf_end, error);				else if (attr->name[0]=='e' || attr->name[0]=='E')					set_attr_type(p, BYMINUTE_ATTR, buf_end, error);				break;			case 'd': case 'D':				set_attr_type(p, DTEND_ATTR, buf_end, error);				break;			case 'r': case 'R':				set_attr_type(p, INTERVAL_ATTR, buf_end, error);				break;			case 'l': case 'L':				set_attr_type(p, UNTIL_ATTR, buf_end, error);				break;			case 'c': case 'C':				set_attr_type(p, BYSECOND_ATTR, buf_end, error);				break;			case 'u': case 'U':				set_attr_type(p, BYHOUR_ATTR, buf_end, error);				break;			case 'y': case 'Y':				set_attr_type(p, BYDAY_ATTR, buf_end, error);				break;			case 'e': case 'E':				set_attr_type(p, BYWEEKNO_ATTR, buf_end, error);				break;			default:				LOG(L_ERR,"ERROR:cpl_c:encode_time_attr: unknown "					"attribute <%s>\n",attr->name);				goto error;		}		/* attribute's encoded value */		get_attr_val( attr->name , val, error);		val.len++; /* grab also the \0 */		append_str_attr(p,val, buf_end, error);	}	return p-p_orig;error:	return -1;}/* Attr. encoding for LOOKUP node: *  | attr1_t(2) attr1_len(2) attr1_val(2*x) |      SOURCE attr  (NT) * [| attr2_t(2) attr2_val(2) |]?                   CLEAR attr */static inline int encode_lookup_attr(xmlNodePtr  node, char *node_ptr,																char *buf_end){	xmlAttrPtr     attr;	char           *p, *p_orig;	unsigned char  *nr_attr;	str            val;	nr_attr = &(NR_OF_ATTR(node_ptr));	*nr_attr = 0;	p = p_orig = ATTR_PTR(node_ptr);	FOR_ALL_ATTR(node,attr) {		/* get attribute's value */		get_attr_val( attr->name , val, error);		if ( !strcasecmp((const char*)attr->name,"source") ) {			/* this param will not be copied, since it has only one value ;-)*/			if ( val.len!=SOURCE_REG_STR_LEN ||			strncasecmp( val.s, SOURCE_REG_STR, val.len) ) {				LOG(L_ERR,"ERROR:cpl_c:encode_lookup_attr: unsupported value"					" <%.*s> in SOURCE param\n",val.len,val.s);				goto error;			}		} else if ( !strcasecmp((const char*)attr->name,"clear") ) {			(*nr_attr)++;			set_attr_type(p, CLEAR_ATTR, buf_end, error);			if ( val.len==3 && !strncasecmp(val.s,"yes",3) )				append_short_attr(p, YES_VAL, buf_end, error);			else if ( val.len==2 && !strncasecmp(val.s,"no",2) )				append_short_attr(p, NO_VAL, buf_end, error);			else {				LOG(L_ERR,"ERROR:cpl_c:encode_lookup_attr: unknown value "					"<%.*s> for attribute CLEAR\n",val.len,val.s);				goto error;			}		} else if ( !strcasecmp((const char*)attr->name,"timeout") ) {			LOG(L_WARN,"WARNING:cpl_c:encode_lookup_attr: unsupported param "				"TIMEOUT; skipping\n");		} else {			LOG(L_ERR,"ERROR:cpl_c:encode_lookup_attr: unknown attribute "				"<%s>\n",attr->name);			goto error;		}	}	return p-p_orig;error:	return -1;}/* Attr. encoding for LOCATION node: *  | attr1_t(2) attr1_len(2) attr1_val(2*x) |      URL attr  (NT) * [| attr2_t(2) attr2_val(2) |]?                   PRIORITY attr * [| attr3_t(2) attr3_val(2) |]?                   CLEAR attr */static inline int encode_location_attr(xmlNodePtr  node, char *node_ptr,																char *buf_end){	struct sip_uri uri;	xmlAttrPtr     attr;	char           *p, *p_orig;	unsigned char  *nr_attr;	unsigned short nr;	str            val;	nr_attr = &(NR_OF_ATTR(node_ptr));	*nr_attr = 0;	p = p_orig = ATTR_PTR(node_ptr);	FOR_ALL_ATTR(node,attr) {		(*nr_attr)++;		/* get attribute's value */		get_attr_val( attr->name , val, error);		switch(attr->name[0]) {			case 'U': case 'u':				set_attr_type(p, URL_ATTR, buf_end, error);				/* check if it's a valid SIP URL -> just call				 * parse uri function and see if returns error ;-) */				if (parse_uri( val.s, val.len, &uri)!=0) {					LOG(L_ERR,"ERROR:cpl-c:encrypt_location_attr: <%s> is "						"not a valid SIP URL\n",val.s);					goto error;				}				val.len++; /*copy also the \0 */				append_str_attr(p,val, buf_end, error);				break;			case 'P': case 'p':				set_attr_type(p, PRIORITY_ATTR, buf_end, error);				if (val.s[0]=='0') nr=0;				else if (val.s[0]=='1') nr=10;				else goto prio_error;				if (val.s[1]!='.') goto prio_error;				if (val.s[2]<'0' || val.s[2]>'9') goto prio_error;				nr += val.s[2] - '0';				if (nr>10)					goto prio_error;				append_short_attr(p, nr, buf_end, error);				break;			case 'C': case 'c':				set_attr_type(p, CLEAR_ATTR, buf_end, error);				if (val.s[0]=='y' || val.s[0]=='Y')					append_short_attr(p, YES_VAL, buf_end, error);				else					append_short_attr(p, NO_VAL, buf_end, error);				break;			default:				LOG(L_ERR,"ERROR:cpl_c:encode_location_attr: unknown attribute "					"<%s>\n",attr->name);				goto error;		}	}	return p-p_orig;prio_error:	LOG(L_ERR,"ERROR:cpl_c:encode_location_attr: invalid priority <%s>\n",		val.s);error:	return -1;}/* Attr. encoding for REMOVE_LOCATION node: * [| attr1_t(2) attr1_len(2) attr1_val(2*x) |]?    LOCATION attr  (NT) */static inline int encode_rmvloc_attr(xmlNodePtr  node, char *node_ptr, char *buf_end){	struct sip_uri uri;	xmlAttrPtr     attr;	char           *p, *p_orig;	unsigned char  *nr_attr;	str            val;	nr_attr = &(NR_OF_ATTR(node_ptr));	*nr_attr = 0;	p = p_orig = ATTR_PTR(node_ptr);	FOR_ALL_ATTR(node,attr) {		(*nr_attr)++;		switch(attr->name[0]) {			case 'L': case 'l':				set_attr_type(p, LOCATION_ATTR, buf_end, error);				/* get the value of the attribute */				get_attr_val( attr->name , val, error);				/* check if it's a valid SIP URL -> just call				 * parse uri function and see if returns error ;-) */				if (parse_uri( val.s, val.len, &uri)!=0) {					LOG(L_ERR,"ERROR:cpl-c:encrypt_rmvloc_attr: <%s> is "						"not a valid SIP URL\n",val.s);					goto error;				}				val.len++; /*copy also the \0 */				append_str_attr(p,val, buf_end, error);				break;			case 'P': case 'p':			case 'V': case 'v':				/* as the interpreter ignores PARAM and VALUE attributes, we will				 * do the same ;-) */				break;			default:				LOG(L_ERR,"ERROR:cpl_c:encode_rmvloc_attr: unknown attribute "					"<%s>\n",attr->name);				goto error;		}	}	return p-p_orig;error:	return -1;}/* Attr. encoding for PROXY node: * [| attr1_t(2) attr1_val(2) |]?                   RECURSE attr * [| attr2_t(2) attr2_val(2) |]?                   TIMEOUT attr * [| attr3_t(2) attr3_val(2) |]?                   ORDERING attr */static inline int encode_proxy_attr(xmlNodePtr  node, char *node_ptr,																char *buf_end){	xmlAttrPtr     attr;	char           *p, *p_orig;	unsigned char  *nr_attr;	unsigned int   nr;	str            val;	nr_attr = &(NR_OF_ATTR(node_ptr));	*nr_attr = 0;	p = p_orig = ATTR_PTR(node_ptr);	FOR_ALL_ATTR(node,attr) {		(*nr_attr)++;		/* get the value of the attribute */		get_attr_val( attr->name , val, error);		switch(attr->name[0]) {			case 'R': case 'r':				set_attr_type(p, RECURSE_ATTR, buf_end, error);				if (val.s[0]=='y' || val.s[0]=='Y')					append_short_attr(p, YES_VAL, buf_end, error);				else if (val.s[0]=='n' || val.s[0]=='N')					append_short_attr(p, NO_VAL, buf_end, error);				else {					LOG(L_ERR,"ERROR:cpl_c:encode_proxy_attr: unknown value "					"<%s> for attribute RECURSE\n",val.s);					goto error;				}				break;			case 'T': case 't':				set_attr_type(p, TIMEOUT_ATTR, buf_end, error);				if (str2int(&val,&nr)==-1) {					LOG(L_ERR,"ERROR:cpl_c:encode_proxy_attr: bad value <%.*s>"						" for attribute TIMEOUT\n",val.len,val.s);					goto error;				}				append_short_attr(p, (unsigned short)nr, buf_end, error);				break;			case 'O': case 'o':				set_attr_type(p, ORDERING_ATTR, buf_end, error);				switch (val.s[0]) {					case 'p': case'P':						append_short_attr(p, PARALLEL_VAL, buf_end, error);						break;					case 'S': case 's':						append_short_attr(p, SEQUENTIAL_VAL, buf_end, error);						break;					case 'F': case 'f':						append_short_attr(p, FIRSTONLY_VAL, buf_end, error);						break;					default:						LOG(L_ERR,"ERROR:cpl_c:encode_proxy_attr: unknown "							"value <%s> for attribute ORDERING\n",val.s);						goto error;				}				break;			default:				LOG(L_ERR,"ERROR:cpl_c:encode_proxy_attr: unknown attribute "					"<%s>\n",attr->name);				goto error;		}	}	return p-p_orig;error:	return -1;}/* Attr. encoding for REJECT node: *  | attr1_t(2) attr1_val(2) |                      STATUS attr * [| attr2_t(2) attr2_len(2) attr2_val(2*x)|]?      REASON attr (NT) */static inline int encode_reject_attr(xmlNodePtr  node, char *node_ptr, char *buf_end){	xmlAttrPtr     attr;	char           *p, *p_orig;	unsigned char  *nr_attr;	unsigned int   nr;	str            val;	nr_attr = &(NR_OF_ATTR(node_ptr));	*nr_attr = 0;	p = p_orig = ATTR_PTR(node_ptr);	FOR_ALL_ATTR(node,attr) {		(*nr_attr)++;		/* get the value of the attribute */		get_attr_val( attr->name , val, error);		switch(attr->name[0]) {			case 'R': case 'r':				set_attr_type(p, REASON_ATTR, buf_end, error);				val.len++; /* grab also the /0 */				append_str_attr(p, val, buf_end, error);				break;			case 'S': case 's':				set_attr_type(p, STATUS_ATTR, buf_end, error);				if (str2int(&val,&nr)==-1) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -