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

📄 notify.c

📁 用来作为linux中SIP SERVER,完成VOIP网络电话中服务器的功能
💻 C
📖 第 1 页 / 共 2 页
字号:
		LOG(L_ERR, "send_xpidf_notify(): end_xpidf_doc failed\n");		return -5;	}	if (create_headers(_w) < 0) {		LOG(L_ERR, "send_xpidf_notify(): Error while adding headers\n");		return -6;	}	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);	return 0;}static int send_lpidf_notify(struct presentity* _p, struct watcher* _w){	lpidf_status_t st;	presence_tuple_t *tuple = _p->tuples;	if (lpidf_add_presentity(&body, BUF_LEN - body.len, &_p->uri) < 0) {		LOG(L_ERR, "send_lpidf_notify(): Error in lpidf_add_presentity\n");		return -2;	}	while (tuple) {		switch(tuple->state) {		case PS_OFFLINE: st = LPIDF_ST_CLOSED; break;		default: st = LPIDF_ST_OPEN; break;		}		if (lpidf_add_address(&body, BUF_LEN - body.len, &_p->uri, st) < 0) {			LOG(L_ERR, "send_lpidf_notify(): lpidf_add_address failed\n");			return -3;		}		tuple = tuple->next;	}	if (create_headers(_w) < 0) {		LOG(L_ERR, "send_lpidf_notify(): Error while adding headers\n");		return -4;	}	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);	return 0;}static int send_pidf_notify(struct presentity* _p, struct watcher* _w){	xpidf_status_t st;	presence_tuple_t *tuple = _p->tuples;	/* Send a notify, saved Contact will be put in	 * Request-URI, To will be put in from and new tag	 * will be generated, callid will be callid,	 * from will be put in to including tag	 */	LOG(L_ERR, "  send_pidf_notify\n");	if (start_pidf_doc(&body, BUF_LEN) < 0) {		LOG(L_ERR, "send_pidf_notify(): start_pidf_doc failed\n");		return -1;	}	if (pidf_add_presentity(&body, BUF_LEN - body.len, &_p->uri) < 0) {		LOG(L_ERR, "send_pidf_notify(): pidf_add_presentity failed\n");		return -3;	}	if (tuple) {		while (tuple) {			if (pidf_start_tuple(&body, &tuple->id, BUF_LEN - body.len) < 0) {				LOG(L_ERR, "send_pidf_notify(): start_pidf_tuple failed\n");				return -4;			}			switch(tuple->state) {			case PS_ONLINE: st = XPIDF_ST_OPEN; break;			default: st = XPIDF_ST_CLOSED; break;			}			if (pidf_add_contact(&body, BUF_LEN - body.len, &tuple->contact, tuple->priority) < 0) {				LOG(L_ERR, "send_pidf_notify(): pidf_add_contact failed\n");				return -3;			}			if (pidf_start_status(&body, BUF_LEN - body.len, st) < 0) {				LOG(L_ERR, "send_pidf_notify(): pidf_start_status failed\n");				return -3;			}			if (pidf_add_location(&body, BUF_LEN - body.len,					      &tuple->location.loc,					      &tuple->location.site, &tuple->location.floor, &tuple->location.room,					      tuple->location.x, tuple->location.y, tuple->location.radius, 					      tuple->prescaps) < 0) {				LOG(L_ERR, "send_pidf_notify(): pidf_add_location failed\n");				return -4;			}			if (pidf_end_status(&body, BUF_LEN - body.len) < 0) {				LOG(L_ERR, "send_pidf_notify(): pidf_end_status failed\n");				return -5;			}			if (pidf_end_tuple(&body, BUF_LEN - body.len) < 0) {				LOG(L_ERR, "send_pidf_notify(): end_pidf_tuple failed\n");				return -5;			}			tuple = tuple->next;		}	} else {		str id = { "ser", 3 };		str contact = { NULL, 0 };		float priority = 0.8;		st = XPIDF_ST_CLOSED;		if (pidf_start_tuple(&body, &id, BUF_LEN - body.len) < 0) {			LOG(L_ERR, "send_pidf_notify(): start_pidf_tuple failed\n");			return -4;		}		if (pidf_add_contact(&body, BUF_LEN - body.len, &contact, priority) < 0) {			LOG(L_ERR, "send_pidf_notify(): pidf_add_contact failed\n");			return -3;		}		if (pidf_start_status(&body, BUF_LEN - body.len, st) < 0) {			LOG(L_ERR, "send_pidf_notify(): pidf_start_status failed\n");			return -3;		}		if (pidf_end_status(&body, BUF_LEN - body.len) < 0) {			LOG(L_ERR, "send_pidf_notify(): pidf_end_status failed\n");			return -5;		}		if (pidf_end_tuple(&body, BUF_LEN - body.len) < 0) {			LOG(L_ERR, "send_pidf_notify(): end_pidf_tuple failed\n");			return -5;		}	}	if (end_pidf_doc(&body, BUF_LEN - body.len) < 0) {		LOG(L_ERR, "send_pidf_notify(): end_xpidf_doc failed\n");		return -6;	}	if (create_headers(_w) < 0) {		LOG(L_ERR, "send_pidf_notify(): Error while adding headers\n");		return -7;	}	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);	return 0;}static int send_winfo_notify(struct presentity* _p, struct watcher* _w){	watcher_t *watcher = _p->watchers;	LOG(L_INFO, "send_winfo_notify: watcher=%p winfo_watcher=%p\n", watcher, _w);	if (start_winfo_doc(&body, BUF_LEN) < 0) {		LOG(L_ERR, "send_winfo_notify(): start_winfo_doc failed\n");		return -1;	}	if (winfo_start_resource(&body, BUF_LEN - body.len, &_p->uri, _w) < 0) {		LOG(L_ERR, "send_winfo_notify(): winfo_add_resource failed\n");		return -3;	}	while (watcher) {		if (winfo_add_watcher(&body, BUF_LEN - body.len, watcher) < 0) {			LOG(L_ERR, "send_winfo_notify(): winfo_add_watcher failed\n");			return -3;		}		watcher = watcher->next;	}	if (winfo_end_resource(&body, BUF_LEN - body.len) < 0) {		LOG(L_ERR, "send_winfo_notify(): winfo_add_resource failed\n");		return -5;	}	if (end_winfo_doc(&body, BUF_LEN - body.len) < 0) {		LOG(L_ERR, "send_winfo_notify(): end_xwinfo_doc failed\n");		return -6;	}	if (create_headers(_w) < 0) {		LOG(L_ERR, "send_winfo_notify(): Error while adding headers\n");		return -7;	}	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);	return 0;}static int send_xcap_change_notify(struct presentity* _p, struct watcher* _w){	int len = 0;	int presence_list_changed = _p->flags & PFLAG_PRESENCE_LISTS_CHANGED;	int watcherinfo_changed = _p->flags & PFLAG_WATCHERINFO_CHANGED;		LOG(L_ERR, "  send_xcap_change flags=%x\n", _p->flags);	len += sprintf(body.s + len, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");	len += sprintf(body.s + len, "<documents xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n");	if (presence_list_changed) { 		len += sprintf(body.s + len, "  <document uri=\"http://%.*s/presence-lists/users/%.*s/presence.xml\">\r\n",			       pa_domain.len, pa_domain.s, _p->uri.len, _p->uri.s);		len += sprintf(body.s + len, "    <change method=\"PUT\">someone@example.com</change>\r\n");		len += sprintf(body.s + len, "  </document>\r\n");	}	if (watcherinfo_changed) {		len += sprintf(body.s + len, "  <document uri=\"http://%.*s/watcherinfo/users/%.*s/watcherinfo.xml\">\r\n",			       pa_domain.len, pa_domain.s, _p->uri.len, _p->uri.s);		len += sprintf(body.s + len, "    <change method=\"PUT\">someone@example.com</change>\r\n");		len += sprintf(body.s + len, "  </document>\r\n");	}	len += sprintf(body.s + len, "</documents>\r\n");	body.len = len;	if (create_headers(_w) < 0) {		LOG(L_ERR, "send_location_notify(): Error while adding headers\n");		return -7;	}	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);	return 0;}int send_location_notify(struct presentity* _p, struct watcher* _w){	resource_list_t *user = _p->location_package.users;	LOG(L_ERR, "send_location_notify to watcher %.*s\n", _w->uri.len, _w->uri.s);	if (location_doc_start(&body, BUF_LEN) < 0) {		LOG(L_ERR, "send_location_notify(): start_location_doc failed\n");		return -1;	}	if (location_doc_start_userlist(&body, BUF_LEN - body.len, &_p->uri) < 0) {		LOG(L_ERR, "send_location_notify(): location_add_uri failed\n");		return -3;	}	while (user) {		if (location_doc_add_user(&body, BUF_LEN - body.len, &user->uri) < 0) {			LOG(L_ERR, "send_location_notify(): location_add_watcher failed\n");			return -3;		}		user = user->next;	}	if (location_doc_end_resource(&body, BUF_LEN - body.len) < 0) {		LOG(L_ERR, "send_location_notify(): location_add_resource failed\n");		return -5;	}	if (location_doc_end(&body, BUF_LEN - body.len) < 0) {		LOG(L_ERR, "send_location_notify(): end_xlocation_doc failed\n");		return -6;	}	if (create_headers(_w) < 0) {		LOG(L_ERR, "send_location_notify(): Error while adding headers\n");		return -7;	}	tmb.t_request_within(&method, &headers, &body, _w->dialog, 0, 0);	return 0;}int send_notify(struct presentity* _p, struct watcher* _w){	int rc = 0;	body.len = 0;	if (_w->uri.s == NULL) {		LOG(L_ERR, "watcher uri.s is NULL\n");		return -1;	}	if (strlen(_w->uri.s) == 0) {		LOG(L_ERR, "watcher uri.s is zero length\n");		return -2;	}	LOG(L_ERR, "notifying %.*s _p->flags=%x _w->event_package=%d _w->accept=%d _w->status=%d\n", 	    _w->uri.len, _w->uri.s, _p->flags, _w->event_package, _w->accept, _w->status);	if ((_p->flags & (PFLAG_PRESENCE_CHANGED|PFLAG_WATCHERINFO_CHANGED)) 	    && (_w->event_package == EVENT_PRESENCE)	    && (_w->status = WS_ACTIVE)) {		switch(_w->accept) {		case DOC_XPIDF:			rc = send_xpidf_notify(_p, _w);			if (rc) LOG(L_ERR, "send_xpidf_notify returned %d\n", rc);			break;		case DOC_LPIDF:			rc = send_lpidf_notify(_p, _w);			if (rc) LOG(L_ERR, "send_lpidf_notify returned %d\n", rc);			break;		case DOC_PIDF:		default:			rc = send_pidf_notify(_p, _w);			if (rc) LOG(L_ERR, "send_pidf_notify returned %d\n", rc);		}	}	if ((_p->flags & PFLAG_WATCHERINFO_CHANGED) 	    && (_w->event_package == EVENT_PRESENCE_WINFO)) {		switch(_w->accept) {		case DOC_WINFO:			rc = send_winfo_notify(_p, _w);			if (rc) LOG(L_ERR, "send_winfo_notify returned %d\n", rc);			return rc;		default:			/* inapplicable */		  ;		}	}	if ((_p->flags & PFLAG_XCAP_CHANGED) 	    && (_w->event_package == EVENT_XCAP_CHANGE)) {		switch(_w->accept) {		case DOC_XCAP_CHANGE:		default:			rc = send_xcap_change_notify(_p, _w);			if (rc) LOG(L_ERR, "send_xcap_change_notify returned %d\n", rc);		}	}	if ((_p->flags & PFLAG_LOCATION_CHANGED) 	    && (_w->event_package == EVENT_LOCATION)) {		switch(_w->accept) {		case DOC_LOCATION:			rc = send_location_notify(_p, _w);			if (rc) LOG(L_ERR, "send_location_notify returned %d\n", rc);			return rc;		default:		  rc = -1;		  ;		}	}	return rc;}

⌨️ 快捷键说明

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