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

📄 ie.c

📁 Asterisk中信道部分的源码 。。。。
💻 C
📖 第 1 页 / 共 3 页
字号:
		return;	}	if (MISDN_IE_DEBG) printf("    keypad='%s'\n", keypad);	l = strlen(keypad);	p = msg_put(msg, l+2);	if (nt)		*ntmode = p+1;	else		qi->QI_ELEMENT(keypad) = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_KEYPAD;	p[1] = l;	strncpy((char *)p+2, keypad, strlen(keypad));}#endifstatic void dec_ie_keypad(unsigned char *p, Q931_info_t *qi, char *keypad, int keypad_len, int nt, struct misdn_bchannel *bc){	*keypad = '\0';	if (!nt)	{		p = NULL;		if (qi->QI_ELEMENT(keypad))			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(keypad) + 1;	}	if (!p)		return;	if (p[0] < 1)	{		printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);		return;	}	strnncpy(keypad, (char *)p+1, p[0], keypad_len);	if (MISDN_IE_DEBG) printf("    keypad='%s'\n", keypad);}/* IE_NOTIFY */#if 0static void enc_ie_notify(unsigned char **ntmode, msg_t *msg, int notify, int nt, struct misdn_bchannel *bc){	unsigned char *p;	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);	int l;	if (notify<0 || notify>0x7f)	{		printf("%s: ERROR: notify(%d) is out of range.\n", __FUNCTION__, notify);		return;	}	if (MISDN_IE_DEBG) printf("    notify=%d\n", notify);	l = 1;	p = msg_put(msg, l+2);	if (nt)		*ntmode = p+1;	else		qi->QI_ELEMENT(notify) = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_NOTIFY;	p[1] = l;	p[2] = 0x80 + notify;}#endif#if 0static void dec_ie_notify(unsigned char *p, Q931_info_t *qi, int *notify, int nt, struct misdn_bchannel *bc){	*notify = -1;	if (!nt)	{		p = NULL;		if (qi->QI_ELEMENT(notify))			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(notify) + 1;	}	if (!p)		return;	if (p[0] < 1)	{		printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);		return;	}	*notify = p[1] & 0x7f;	if (MISDN_IE_DEBG) printf("    notify=%d\n", *notify);}#endif/* IE_PROGRESS */static void enc_ie_progress(unsigned char **ntmode, msg_t *msg, int coding, int location, int progress, int nt, struct misdn_bchannel *bc){	unsigned char *p;	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);	int l;	if (coding<0 || coding>0x03)	{		printf("%s: ERROR: coding(%d) is out of range.\n", __FUNCTION__, coding);		return;	}	if (location<0 || location>0x0f)	{		printf("%s: ERROR: location(%d) is out of range.\n", __FUNCTION__, location);		return;	}	if (progress<0 || progress>0x7f)	{		printf("%s: ERROR: progress(%d) is out of range.\n", __FUNCTION__, progress);		return;	}	if (MISDN_IE_DEBG) printf("    coding=%d location=%d progress=%d\n", coding, location, progress);	l = 2;	p = msg_put(msg, l+2);	if (nt)		*ntmode = p+1;	else		qi->QI_ELEMENT(progress) = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_PROGRESS;	p[1] = l;	p[2] = 0x80 + (coding<<5) + location;	p[3] = 0x80 + progress;}static void dec_ie_progress(unsigned char *p, Q931_info_t *qi, int *coding, int *location, int *progress, int nt, struct misdn_bchannel *bc){	*coding = -1;	*location = -1;	//*progress = -1;	*progress = 0;		if (!nt)	{		p = NULL;		if (qi->QI_ELEMENT(progress))			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(progress) + 1;	}	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) */static void enc_ie_redir_nr(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, int reason, 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->QI_ELEMENT(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));	}}static void dec_ie_redir_nr(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, int *reason, 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->QI_ELEMENT(redirect_nr))			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(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, (char *)p+4, p[0]-3, number_len);		} else		{			strnncpy(number, (char *)p+3, p[0]-2, number_len);		}	} else	{		strnncpy(number, (char *)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) */#if 0static void enc_ie_redir_dn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, 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->QI_ELEMENT(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));	}}#endif#if 0static void dec_ie_redir_dn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, 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->QI_ELEMENT(redir_dn)) *//* 			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(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, (char *)p+3, p[0]-2, number_len);	} else	{		strnncpy(number, (char *)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);}#endif/* IE_USERUSER */#if 1static void enc_ie_useruser(unsigned char **ntmode, msg_t *msg, int protocol, 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+1;	p = msg_put(msg, l+3);	if (nt)		*ntmode = p+1;	else		qi->QI_ELEMENT(useruser) = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_USER_USER;	p[1] = l;	p[2] = protocol;	memcpy(p+3, user, user_len);}#endif#if 1static void dec_ie_useruser(unsigned char *p, Q931_info_t *qi, int *protocol, 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->QI_ELEMENT(useruser))			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(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);}#endif/* IE_DISPLAY */static void enc_ie_restart_ind(unsigned char **ntmode, msg_t *msg, unsigned char rind, int nt, struct misdn_bchannel *bc){	unsigned char *p;	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);	/* if (MISDN_IE_DEBG) printf("    display='%s' (len=%d)\n", display, strlen((char *)display)); */	p = msg_put(msg, 3);	if (nt)		*ntmode = p+1;	else		qi->QI_ELEMENT(restart_ind) = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_RESTART_IND;	p[1] = 1;	p[2] = rind;}

⌨️ 快捷键说明

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