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

📄 ie.c

📁 一个非常美妙的proxy。功能强大。基于sip的协议。如果还要的话
💻 C
📖 第 1 页 / 共 3 页
字号:
	if (!p)		return;	if (p[0] < 1)	{		printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);		return;	}	*coding = (p[1]&0x60) >> 5;	*location = p[1] & 0x0f;	*progress = p[2] & 0x7f;	if (MISDN_IE_DEBG) printf("    coding=%d location=%d progress=%d\n", *coding, *location, *progress);}/* IE_REDIR_NR (redirecting = during MT_SETUP) */void enc_ie_redir_nr(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, int reason, unsigned char *number, int nt, struct misdn_bchannel *bc){	unsigned char *p;	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);	int l;	if (type<0 || type>7)	{		printf("%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);		return;	}	if (plan<0 || plan>15)	{		printf("%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);		return;	}	if (present > 3)	{		printf("%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present);		return;	}	if (present >= 0) if (screen<0 || screen>3)	{		printf("%s: ERROR: screen(%d) is out of range.\n", __FUNCTION__, screen);		return;	}	if (reason > 0x0f)	{		printf("%s: ERROR: reason(%d) is out of range.\n", __FUNCTION__, reason);		return;	}	if (MISDN_IE_DEBG) printf("    type=%d plan=%d present=%d screen=%d readon=%d number='%s'\n", type, plan, present, screen, reason, number);	l = 1;	if (number)		l += strlen((char *)number);	if (present >= 0)	{		l += 1;		if (reason >= 0)			l += 1;	}	p = msg_put(msg, l+2);	if (nt)		*ntmode = p+1;	else		qi->redirect_nr = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_REDIR_NR;	p[1] = l;	if (present >= 0)	{		if (reason >= 0)		{			p[2] = 0x00 + (type<<4) + plan;			p[3] = 0x00 + (present<<5) + screen;			p[4] = 0x80 + reason;			if (number)				strncpy((char *)p+5, (char *)number, strlen((char *)number));		} else		{			p[2] = 0x00 + (type<<4) + plan;			p[3] = 0x80 + (present<<5) + screen;			if (number)				strncpy((char *)p+4, (char *)number, strlen((char *)number));		}	} else	{		p[2] = 0x80 + (type<<4) + plan;		if (number) if (number[0])			strncpy((char *)p+3, (char *)number, strlen((char *)number));	}}void dec_ie_redir_nr(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, int *reason, unsigned char *number, int number_len, int nt, struct misdn_bchannel *bc){	*type = -1;	*plan = -1;	*present = -1;	*screen = -1;	*reason = -1;	*number = '\0';	if (!nt)	{		p = NULL;		if (qi->redirect_nr)			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redirect_nr + 1;	}	if (!p)		return;	if (p[0] < 1)	{		printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);		return;	}	*type = (p[1]&0x70) >> 4;	*plan = p[1] & 0xf;	if (!(p[1] & 0x80))	{		*present = (p[2]&0x60) >> 5;		*screen = p[2] & 0x3;		if (!(p[2] & 0x80))		{			*reason = p[3] & 0x0f;			strnncpy(number, p+4, p[0]-3, number_len);		} else		{			strnncpy(number, p+3, p[0]-2, number_len);		}	} else	{		strnncpy(number, p+2, p[0]-1, number_len);	}	if (MISDN_IE_DEBG) printf("    type=%d plan=%d present=%d screen=%d reason=%d number='%s'\n", *type, *plan, *present, *screen, *reason, number);}/* IE_REDIR_DN (redirection = during MT_NOTIFY) */void enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, unsigned char *number, int nt, struct misdn_bchannel *bc){	unsigned char *p;/* 	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN); */	int l;	if (type<0 || type>7)	{		printf("%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);		return;	}	if (plan<0 || plan>15)	{		printf("%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);		return;	}	if (present > 3)	{		printf("%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present);		return;	}	if (MISDN_IE_DEBG) printf("    type=%d plan=%d present=%d number='%s'\n", type, plan, present, number);	l = 1;	if (number)		l += strlen((char *)number);	if (present >= 0)		l += 1;	p = msg_put(msg, l+2);	if (nt)		*ntmode = p+1;	else/* #warning REINSERT redir_dn, when included in te-mode */		/*qi->redir_dn = p - (unsigned char *)qi - sizeof(Q931_info_t)*/;	p[0] = IE_REDIR_DN;	p[1] = l;	if (present >= 0)	{		p[2] = 0x00 + (type<<4) + plan;		p[3] = 0x80 + (present<<5);		if (number)			strncpy((char *)p+4, (char *)number, strlen((char *)number));	} else	{		p[2] = 0x80 + (type<<4) + plan;		if (number)			strncpy((char *)p+3, (char *)number, strlen((char *)number));	}}void dec_ie_redir_dn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, unsigned char *number, int number_len, int nt, struct misdn_bchannel *bc){	*type = -1;	*plan = -1;	*present = -1;	*number = '\0';	if (!nt)	{		p = NULL;/* #warning REINSERT redir_dn, when included in te-mode *//* 		if (qi->redir_dn) *//* 			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->redir_dn + 1; */	}	if (!p)		return;	if (p[0] < 1)	{		printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);		return;	}	*type = (p[1]&0x70) >> 4;	*plan = p[1] & 0xf;	if (!(p[1] & 0x80))	{		*present = (p[2]&0x60) >> 5;		strnncpy(number, p+3, p[0]-2, number_len);	} else	{		strnncpy(number, p+2, p[0]-1, number_len);	}	if (MISDN_IE_DEBG) printf("    type=%d plan=%d present=%d number='%s'\n", *type, *plan, *present, number);}/* IE_FACILITY */void enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *facility, int facility_len, int nt, struct misdn_bchannel *bc){	unsigned char *p;	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);	int l;	char debug[768];	int i;	if (!facility || facility_len<=0)	{		return;	}	i = 0;	while(i < facility_len)	{		if (MISDN_IE_DEBG) printf(debug+(i*3), " %02x", facility[i]);		i++;	}			if (MISDN_IE_DEBG) printf("    facility%s\n", debug);	l = facility_len;	p = msg_put(msg, l+2);	if (nt)		*ntmode = p+1;	else		qi->facility = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_FACILITY;	p[1] = l;	memcpy(p+2, facility, facility_len);}void dec_ie_facility(unsigned char *p, Q931_info_t *qi, unsigned char *facility, int *facility_len, int nt, struct misdn_bchannel *bc){	int i;	struct misdn_stack *stack=get_stack_by_bc(bc);		*facility_len = 0;	if (!nt)	{		p = NULL;		if (qi->facility)			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->facility + 1;	}	if (!p)		return;	*facility_len = p[0];	memcpy(facility, p+1, *facility_len);		i = 0;	while(i < *facility_len)	{		cb_log(3, stack->port, " %02x", facility[i]);		i++;	}	cb_log(3, stack->port, "    facility\n");}/* facility for siemens CENTEX (known parts implemented only) */void enc_facility_centrex(unsigned char **ntmode, msg_t *msg, unsigned char *cnip, int setup, int nt, struct misdn_bchannel *bc){	unsigned char centrex[256];	int i = 0;	if (!cnip)		return;	/* centrex facility */	centrex[i++] = CENTREX_FAC;	centrex[i++] = CENTREX_ID;	/* cnip */	if (strlen((char *)cnip) > 15)	{/* 		if (options.deb & DEBUG_PORT) */		if (MISDN_IE_DEBG) printf("%s: CNIP/CONP text too long (max 13 chars), cutting.\n", __FUNCTION__);		cnip[15] = '\0';	}	/*  dunno what the 8 bytes mean */	if (setup)	{		centrex[i++] = 0x17;		centrex[i++] = 0x02;		centrex[i++] = 0x02;		centrex[i++] = 0x44;		centrex[i++] = 0x18;		centrex[i++] = 0x02;		centrex[i++] = 0x01;		centrex[i++] = 0x09;	} else	{		centrex[i++] = 0x18;		centrex[i++] = 0x02;		centrex[i++] = 0x02;		centrex[i++] = 0x81;		centrex[i++] = 0x09;		centrex[i++] = 0x02;		centrex[i++] = 0x01;		centrex[i++] = 0x0a;	}	centrex[i++] = 0x80;	centrex[i++] = strlen((char *)cnip);	strcpy((char *)(&centrex[i]), (char *)cnip);	i += strlen((char *)cnip);	if (MISDN_IE_DEBG) printf("    cnip='%s'\n", cnip);	/* encode facility */	enc_ie_facility(ntmode, msg, centrex, i, nt , bc);}void dec_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *cnip, int cnip_len, int nt, struct misdn_bchannel *bc){	unsigned char centrex[256];	char debug[768];	int facility_len = 0;	int i = 0, j;	*cnip = '\0';	dec_ie_facility(p, qi, centrex, &facility_len,  nt, bc);	if (facility_len >= 2)	{		if (centrex[i++] != CENTREX_FAC)			return;		if (centrex[i++] != CENTREX_ID)			return;	}	/* loop sub IEs of facility */	while(facility_len > i+1)	{		if (centrex[i+1]+i+1 > facility_len)		{			printf("%s: ERROR: short read of centrex facility.\n", __FUNCTION__);			return;		}		switch(centrex[i])		{		case 0x80:			strnncpy(cnip, &centrex[i+2], centrex[i+1], cnip_len);			if (MISDN_IE_DEBG) printf("    CENTREX cnip='%s'\n", cnip);			break;		default:			j = 0;			while(j < centrex[i+1])			{				if (MISDN_IE_DEBG) printf(debug+(j*3), " %02x", centrex[i+1+j]);				i++;			}			if (MISDN_IE_DEBG) printf("    CENTREX unknown=0x%2x len=%d%s\n", centrex[i], centrex[i+1], debug);		}		i += 1+centrex[i+1];	}}/* facility for siemens CENTEX (known parts implemented only) */void enc_facility_calldeflect(unsigned char **ntmode, msg_t *msg, unsigned char *nr, int nt, struct misdn_bchannel *bc){	unsigned char fac[256];		if (!nr)		return;		/* calldeflect facility */		/* cnip */	if (strlen((char *)nr) > 15)	{/* 		if (options.deb & DEBUG_PORT) */		if (MISDN_IE_DEBG) printf("%s: NR text too long (max 13 chars), cutting.\n", __FUNCTION__);		nr[15] = '\0';	}		fac[0]=0; // len 	fac[1]=0; //len 	fac[2]=0x01; // Use D-Chan	fac[3]=0; // Keypad len	fac[4]=31;	// user user data? len = 31 = 29 + 2	fac[5]=0x1c;	// magic?	fac[6]=0x1d;	// strlen destination + 18 = 29	fac[7]=0x91;	// ..	fac[8]=0xA1;	fac[9]=0x1A;	// strlen destination + 15 = 26	fac[10]=0x02;	fac[11]=0x01;	fac[12]=0x70;	fac[13]=0x02;	fac[14]=0x01;	fac[15]=0x0d;	fac[16]=0x30;	fac[17]=0x12;	// strlen destination + 7 = 18	fac[18]=0x30;	// ...hm 0x30	fac[19]=0x0d;	// strlen destination + 2		fac[20]=0x80;	// CLIP	fac[21]=0x0b;	//  strlen destination 	fac[22]=0x01;	//  destination start	fac[23]=0x01;	//  	fac[24]=0x01;	//  	fac[25]=0x01;	//  	fac[26]=0x01;	//  	fac[27]=0x01;	//  	fac[28]=0x01;	//  	fac[29]=0x01;	//  	fac[30]=0x01;	//  	fac[31]=0x01;	//  	fac[32]=0x01;	//  	fac[33]=0x01;	// 0x1 = sending complete	fac[34]=0x01;	fac[35]=0x01;				   	memcpy((unsigned char *)fac+22,nr,strlen(nr));	fac[22+strlen( nr)]=0x01;	// fill with 0x01 if number is only 6 numbers (local call)	fac[23+strlen(nr)]=0x01;	fac[24+strlen(nr)]=0x01;	fac[25+strlen(nr)]=0x01;	fac[26+strlen(nr)]=0x01;		fac[6]=18+strlen(nr);	fac[9]=15+strlen(nr);	fac[17]=7+strlen(nr);	fac[19]=2+strlen(nr);	fac[21]=strlen(nr);		enc_ie_facility(ntmode, msg, &fac[4], 36-4, nt , bc);}/* IE_USERUSER */void enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, unsigned char *user, int user_len, int nt, struct misdn_bchannel *bc){	unsigned char *p;	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);	int l;	char debug[768];	int i;	if (protocol<0 || protocol>127)	{		printf("%s: ERROR: protocol(%d) is out of range.\n", __FUNCTION__, protocol);		return;	}	if (!user || user_len<=0)	{		return;	}	i = 0;	while(i < user_len)	{		if (MISDN_IE_DEBG) printf(debug+(i*3), " %02x", user[i]);		i++;	}			if (MISDN_IE_DEBG) printf("    protocol=%d user-user%s\n", protocol, debug);	l = user_len;	p = msg_put(msg, l+3);	if (nt)		*ntmode = p+1;	else		qi->useruser = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_USER_USER;	p[1] = l;	p[2] = 0x80 + protocol;	memcpy(p+3, user, user_len);}void dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, unsigned char *user, int *user_len, int nt, struct misdn_bchannel *bc){	char debug[768];	int i;	*user_len = 0;	*protocol = -1;	if (!nt)	{		p = NULL;		if (qi->useruser)			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->useruser + 1;	}	if (!p)		return;	*user_len = p[0]-1;	if (p[0] < 1)		return;	*protocol = p[1];	memcpy(user, p+2, (*user_len<=128)?*(user_len):128); /* clip to 128 maximum */	i = 0;	while(i < *user_len)	{		if (MISDN_IE_DEBG) printf(debug+(i*3), " %02x", user[i]);		i++;	}	debug[i*3] = '\0';			if (MISDN_IE_DEBG) printf("    protocol=%d user-user%s\n", *protocol, debug);}

⌨️ 快捷键说明

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