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

📄 textops.c

📁 性能优秀的SIP Proxy
💻 C
📖 第 1 页 / 共 3 页
字号:
	model = (xl_elem_t*)key;	if (xl_printf_s(msg, model, &s0)<0)	{		LOG(L_ERR,"textops:add_hf_helper: error - cannot print the format\n");		return -1;	} 	if ( add_lump_rpl( msg, s0.s, s0.len, LUMP_RPL_HDR)==0 )	{		LOG(L_ERR,"ERROR:append_to_reply : unable to add lump_rl\n");		return -1;	}	return 1;}/* add str1 to end of header or str1.r-uri.str2 */static int add_hf_helper(struct sip_msg* msg, str *str1, str *str2,		xl_elem_t *model, int mode, str *hfs){	struct lump* anchor;	struct hdr_field *hf;	char *s;	int len;	str s0;	if (parse_headers(msg, HDR_EOH_F, 0) == -1) {		LOG(L_ERR, "textops:add_hf_helper: Error while parsing message\n");		return -1;	}		hf = 0;	if(hfs!=NULL) {		for (hf=msg->headers; hf; hf=hf->next) {			if((str*)hfs->s==NULL)			{				if (((str*)hfs)->len!=hf->type)				continue;			} else {				if (hf->name.len!=((str*)hfs)->len)					continue;				if (strncasecmp(hf->name.s,((str*)hfs)->s,hf->name.len)!=0)					continue;			}			break;		}	}	if(mode == 0) { /* append */		if(hf==0) { /* after last header */			anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0);		} else { /* after hf */			anchor = anchor_lump(msg, hf->name.s + hf->len - msg->buf, 0, 0);		}	} else { /* insert */		if(hf==0) { /* before first header */			anchor = anchor_lump(msg, msg->headers->name.s - msg->buf, 0, 0);		} else { /* before hf */			anchor = anchor_lump(msg, hf->name.s - msg->buf, 0, 0);		}	}	if(anchor == 0) {		LOG(L_ERR, "textops:add_hf_helper: Can't get anchor\n");		return -1;	}	if(str1) {		s0 = *str1;	} else {		if(model) {			if (xl_printf_s(msg, model, &s0)<0)			{				LOG(L_ERR,				"textops:add_hf_helper: error - cannot print the format\n");				return -1;			}		} else {			s0.len = 0;			s0.s   = 0;		}	}			len=s0.len;	if (str2) len+= str2->len + REQ_LINE(msg).uri.len;	s = (char*)pkg_malloc(len);	if (!s) {		LOG(L_ERR, "textops:add_hf_helper: No memory left\n");		return -1;	}	memcpy(s, s0.s, s0.len);	if (str2) {		memcpy(s+str1->len, REQ_LINE(msg).uri.s, REQ_LINE(msg).uri.len);		memcpy(s+str1->len+REQ_LINE(msg).uri.len, str2->s, str2->len );	}	if (insert_new_lump_before(anchor, s, len, 0) == 0) {		LOG(L_ERR, "textops:add_hf_helper: Can't insert lump\n");		pkg_free(s);		return -1;	}	return 1;}static int append_hf_1(struct sip_msg *msg, char *str1, char *str2 ){	return add_hf_helper(msg, 0, 0, (xl_elem_t*)str1, 0, 0);}static int append_hf_2(struct sip_msg *msg, char *str1, char *str2 ){	return add_hf_helper(msg, 0, 0, (xl_elem_t*)str1, 0,			(str*)str2);}static int insert_hf_1(struct sip_msg *msg, char *str1, char *str2 ){	return add_hf_helper(msg, 0, 0, (xl_elem_t*)str1, 1, 0);}static int insert_hf_2(struct sip_msg *msg, char *str1, char *str2 ){	return add_hf_helper(msg, 0, 0, (xl_elem_t*)str1, 1, 			(str*)str2);}static int append_urihf(struct sip_msg *msg, char *str1, char *str2){	return add_hf_helper(msg, (str*)str1, (str*)str2, 0, 0, 0);}static int is_method_f(struct sip_msg *msg, char *meth, char *str2 ){	str *m;	m = (str*)meth;	if(msg->first_line.type==SIP_REQUEST)	{		if(m->s==0)			return (msg->first_line.u.request.method_value&m->len)?1:-1;		else			return (msg->first_line.u.request.method_value==METHOD_OTHER					&& msg->first_line.u.request.method.len==m->len					&& (strncasecmp(msg->first_line.u.request.method.s, m->s,					m->len)==0))?1:-1;	}	if(parse_headers(msg, HDR_CSEQ_F, 0)!=0)	{		LOG(L_ERR, "textops:is_method: ERROR - cannot parse cseq header\n");		return -1; /* should it be 0 ?!?! */	}	if(m->s==0)		return (get_cseq(msg)->method_id&m->len)?1:-1;	else		return (get_cseq(msg)->method_id==METHOD_OTHER				&& get_cseq(msg)->method.len==m->len				&& (strncasecmp(get_cseq(msg)->method.s, m->s,				m->len)==0))?1:-1;}/* * Convert char* parameter to str* parameter */static int str_fixup(void** param, int param_no){	str* s;	s = (str*)pkg_malloc(sizeof(str));	if (!s) {		LOG(L_ERR, "str_fixup(): No memory left\n");		return E_UNSPEC;	}	s->s = (char*)*param;	s->len = strlen(s->s);	*param = (void*)s;	return 0;}/* * Convert char* header_name to str* parameter */static int hname_fixup(void** param, int param_no){	str* s;	char c;	struct hdr_field hdr;	s = (str*)pkg_malloc(sizeof(str));	if (!s) {		LOG(L_ERR, "textops:hname_fixup: No memory left\n");		return E_UNSPEC;	}	s->s = (char*)*param;	s->len = strlen(s->s);	if(s->len==0)	{		LOG(L_ERR,"textops:hname_fixup: empty header name parameter\n");		pkg_free(s);		return E_UNSPEC;	}		c = s->s[s->len];	s->s[s->len] = ':';	s->len++;		if (parse_hname2(s->s, s->s + ((s->len<4)?4:s->len), &hdr)==0)	{		LOG(L_ERR,"textops:hname_fixup: error parsing header name\n");		pkg_free(s);		return E_UNSPEC;	}		s->len--;	s->s[s->len] = c;	if (hdr.type!=HDR_OTHER_T && hdr.type!=HDR_ERROR_T)	{		LOG(L_INFO,"INFO:textops:hname_fixup: using "				"hdr type (%d) instead of <%.*s>\n",				hdr.type, s->len, s->s);		pkg_free(s->s);		s->s = NULL;		s->len = hdr.type;	} else {		LOG(L_INFO,"INFO:textops:hname_fixup: using "				"hdr type name <%.*s>\n", s->len, s->s);	}		*param = (void*)s;	return 0;}/* * Convert char* method to str* parameter */static int fixup_method(void** param, int param_no){	str* s;	char *p;	int m;	unsigned int method;		s = (str*)pkg_malloc(sizeof(str));	if (!s) {		LOG(L_ERR, "textops:fixup_method: No memory left\n");		return E_UNSPEC;	}	s->s = (char*)*param;	s->len = strlen(s->s);	if(s->len==0)	{		LOG(L_ERR,"textops:fixup_method: empty method name\n");		pkg_free(s);		return E_UNSPEC;	}	m=0;	p=s->s;	while(*p)	{		if(*p=='|')		{			*p = ',';			m=1;		}		p++;	}	if(parse_methods(s, &method)!=0)	{		LOG(L_ERR,"textops:fixup_method: bad method names\n");		pkg_free(s);		return E_UNSPEC;	}	if(m==1)	{		if(method==METHOD_UNDEF || method&METHOD_OTHER)		{			LOG(L_ERR,				"textops:fixup_method: unknown method in list [%.*s/%d]"				" - must be only defined methods\n",				s->len, s->s, method);			return E_UNSPEC;		}		DBG("textops:fixup_method: using id for methods [%.*s/%d]\n",				s->len, s->s, method);		s->s = 0;		s->len = method;	} else {		if(method!=METHOD_UNDEF && method!=METHOD_OTHER)		{			DBG("textops:fixup_method: using id for method [%.*s/%d]\n",				s->len, s->s, method);			s->s = 0;			s->len = method;		} else			DBG("textops:fixup_method: name for method [%.*s/%d]\n",				s->len, s->s, method);	}	*param = (void*)s;	return 0;}/* * Convert char* parameter to xl_elem parameter */static int it_list_fixup(void** param, int param_no){	xl_elem_t *model;	if(*param)	{		if(xl_parse_format((char*)(*param), &model, XL_DISABLE_COLORS)<0)		{			LOG(L_ERR, "ERROR:textops:item_list_fixup: wrong format[%s]\n",				(char*)(*param));			return E_UNSPEC;		}		*param = (void*)model;	}	return 0;}static int add_header_fixup(void** param, int param_no){	if(param_no==1)	{		return it_list_fixup(param, param_no);	} else if(param_no==2) {		return hname_fixup(param, param_no);	} else {		LOG(L_ERR,			"ERROR:textops:add_header_fixup: wrong number of parameters\n");		return E_UNSPEC;	}}static int fixup_body_type(void** param, int param_no){	char *p;	char *r;	unsigned int type;	if(param_no==1) {		p = (char*)*param;		if (p==0 || p[0]==0) {			type = 0;		} else {			r = decode_mime_type( p, p+strlen(p) , &type);			if (r==0) {				LOG(L_ERR,"ERROR:textops:fixup_body_type: unsupported "					"mime <%s>\n",p);				return E_CFG;			}			if ( r!=p+strlen(p) ) {				LOG(L_ERR,"ERROR:textops:fixup_body_type: multiple mimes not "					"supported!\n");				return E_CFG;			}		}		pkg_free(*param);		*param = (void*)(long)type;	}	return 0;}static int has_body_f(struct sip_msg *msg, char *type, char *str2 ){	int mime;	/* get body pointer */	if ( get_body(msg)==0 )		return -1;	/* all headears are already parsed by "get_body" */	if (msg->content_length==0) {		LOG (L_ERR, "ERROR:textops:has_body: very bogus message with body "			"but no content length hdr\n");		return -1;	}	if (get_content_length (msg)==0) {		DBG("DEBUG:textops:has_body: content length is zero\n");		/* Nothing to see here, please move on. */		return -1;	}	/* check type also? */	if (type==0)		return 1;	mime = parse_content_type_hdr (msg);	if (mime<0) {		LOG (L_ERR, "ERROR:textops:has_body: failed to extract "			"content type hdr\n");		return -1;	}	if (mime==0) {		/* content type hdr not found -> according the RFC3261 we		 * assume APPLICATION/SDP  --bogdan */		mime = ((TYPE_APPLICATION << 16) + SUBTYPE_SDP);	}	DBG("DBUG:textops:has_body: Content type is %d\n",mime);	if ( (unsigned int)mime!=(unsigned int)(unsigned long)type )		return -1;	return 1;}

⌨️ 快捷键说明

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