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

📄 notify.c

📁 sip代理服务器源码
💻 C
字号:
/***********************************************************************\	SIP Server		Date		Ver		Author		MemoRandom	Jul 3,2002	1.0		Hiroaki Hata	Created	(C) 2002 All Copyrights reserved. *************************************************************************/#include <sys/types.h>#include <stdio.h>#include <sys/types.h>#include <sys/socket.h>#include <string.h>#include <netinet/in.h>#include <netdb.h>#include <time.h>#include "udp.h"#include "sipd.h"#include "parser.h"extern int dump_flag;extern	char HOSTID[CLEN];extern	unsigned short HOSTPORT;//static int debug=0;#ifdef TESTstatic int debug;#endif/*  NORTIFY REQUEST Example **********************Internet Draft draft-ietf-simple-presence-01.txtiJuly 20, 2001Expires: February 2002<presence entityInfo="pres:presentity@example.com"><tuple destination="sip:presentity@example.com" status="open"/></presence>*************************************************/static int make_notify_message_body(		char *body,char *name,char *domain,char *hostid,short hostport,int expires){	char	line[128];	*body='\0';	sprintf(line,"<?xml version=\"1.0\"?>\n");	strcat(body,line);	sprintf(line,"<!DOCTYPE presence\n");	strcat(body,line);	sprintf(line,"PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n");	strcat(body,line);	sprintf(line,"<presence>\n");	strcat(body,line);	sprintf(line,	    "<presentity uri=\"sip:%s@%s;method=SUBSCRIBE\"/>\n",name,domain);	strcat(body,line);		sprintf(line,"<atom id=\"1\" >\n");	strcat(body,line);		sprintf(line,		"<address uri=\"sip:%s:%d;user=ip\" priority=\"1.0\">\n",		hostid,hostport);	strcat(body,line);		if(expires==0){		/* 	closed	锣朗面			inuse	艰り哈み面		*/		sprintf(line,"<status status=\"inuse\"/>\n");		strcat(body,line);			//sprintf(line,"<msnsubstatus substatus=\"offline\"/>\n");		//strcat(body,line);		}else{		sprintf(line,"<status status=\"open\"/>\n");		strcat(body,line);			//sprintf(line,"<msnsubstatus substatus=\"online\"/>\n");		//strcat(body,line);		}	sprintf(line,"</address>");	strcat(body,line);	sprintf(line,"</atom></presence>");	strcat(body,line);	return 0;}static int  make_notify_message_header(char *buff,char *body,MESSAGE *mes,		char *hostid,short hostport,int seq,int expires){	char	line[512];	if(buff==NULL) return -1;	*buff='\0';		//FirstLine	sprintf(line,"NOTIFY sip:%s@%s SIP/2.0\r\n" ,		mes->header.from.username,mes->header.from.host);	strcat(buff,line);	//Via Header	sprintf(line,"Via: SIP/2.0/UDP %s:%d\r\n",hostid,hostport); 	strcat(buff,line);	//From	sprintf(line,"From: <sip:%s@%s>\r\n",		mes->header.to.username,mes->header.to.host);	strcat(buff,line);	//To	/*******Modified by Hata 2003 Sep 24 ******************/	sprintf(line,"To: <sip:%s@%s>%s\r\n",		mes->header.from.username,mes->header.from.host,		mes->header.from.aux);	strcat(buff,line);	//Call-ID	sprintf(line,"Call-ID: %s\r\n",mes->header.callid); 	strcat(buff,line);	//Contact	sprintf(line,"Contact: <sip:%s:%d>\r\n",hostid,hostport);	strcat(buff,line);	//CSEQ	sprintf(line,"CSeq: %d %s\r\n",seq,"NOTIFY"); 	strcat(buff,line);	//Event	sprintf(line,"Event: presence\r\n"); 	strcat(buff,line);	//SS  ******Modified Sep 24 2003 Hata	//expiresが赖猛の眷圭にのみ、Subscription-Stateを烧裁 	if(mes->header.expires>0){		sprintf(line,"Subscription-State: active;expires=%d\r\n",						mes->header.expires); 		strcat(buff,line);	}	//max-Forwards	sprintf(line,"Max-Forwards: 70\r\n"); 	strcat(buff,line);	//Expires /	/******Modified Sep 24 2003 Hata*/	if(expires>0){		sprintf(line,"Expires: %d\r\n",expires); 		strcat(buff,line);	}	//	if(body!='\0' && *body!='\0'){		sprintf(line,"Content-Type: %s\r\n",			"application/xpidf+xml"); 		strcat(buff,line);		sprintf(line,"Content-Length: %d\r\n",strlen(body)); 		strcat(buff,line);		strcat(buff,"\r\n");		strcat(buff,body);	}else{		strcat(buff,"\r\n");	}	return 0;}static int notify(MESSAGE *mes,int seq,int expires){	char	buff[2048];	char	body[1024];	URI	*c;	make_notify_message_body(body,mes->header.to.username,				mes->header.to.host,HOSTID,HOSTPORT,expires);	make_notify_message_header(buff,body,mes,HOSTID,HOSTPORT,seq,expires);DEBUG	printf("%s\n",buff);DEND	for(c=mes->header.contact;c->next!=NULL;c=c->next){}		SendData(c->host,c->port, buff,strlen(buff));	return 0;}void SubscribeNotify(MESSAGE *mes){	MESSAGE	nmes;		int	ret;	//nmesはREGISTERユ〖ザの铜痰を澄千するためのものでContactは	//稍妥であるため艰评しない。nitify黎は,mesのcontactである	memset(&nmes,0,sizeof(MESSAGE));	strcpy(nmes.header.from.username,mes->header.to.username);	strcpy(nmes.header.from.host,mes->header.to.host);	ret=GetREGDB(&nmes);	if(ret!=1){		//That User Is OFFLINE		return ;	}	ret=AddNSeqSUBDB(mes);	notify(mes,ret,mes->header.expires);}void RegisterNotify(MESSAGE *mes){	MESSAGE	nmes;	int	ret;	int	expires;	MESSAGE	*ptr[USER_MAX];	int i;	expires=mes->header.expires;	for(i=0;i<USER_MAX;i++)ptr[i]=NULL;	memcpy(&nmes,mes,sizeof(MESSAGE));	nmes.header.from.username[0]='\0';	nmes.header.from.host[0]='\0';	GetSUBDB(&nmes,ptr);	for(i=0;i<USER_MAX;i++){		if(ptr[i]==NULL) break;		ret=AddNSeqSUBDB(ptr[i]);DEBUG 		printf("Notify--------------\n");		printf("To:%s@%s\n",ptr[i]->header.to.username,					ptr[i]->header.to.host);		printf("From:%s@%s\n",ptr[i]->header.from.username,					ptr[i]->header.from.host);		printf("Expires:%d\n",expires);		printf("CSeq:%d\n",ret);DEND		notify(ptr[i],ret,expires);		free_message_buffer(ptr[i]);		ptr[i]=NULL;	}}#ifdef TEST main(int argc,char **argv){	MESSAGE	mes;	char	ip[24];	char	to[24];	short	port;	if(argc!=2){		printf("%s ip port SIP-URL\n",argv[0]);		exit(1);	}	mes.header.cseq.seq=atoi(argv[1]);	debug=1;	strcpy(mes.header.contact.host,"10.233.25.249");	mes.header.contact.port=13164;	notify(&mes);}staic void syserr(char *s){	exit(1);}#endif

⌨️ 快捷键说明

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