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

📄 pidf.c

📁 用来作为linux中SIP SERVER,完成VOIP网络电话中服务器的功能
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Presence Agent, PIDF document support * * $Id: pidf.c,v 1.13.2.1 2005/07/20 17:11:52 andrei Exp $ * * Copyright (C) 2001-2003 FhG Fokus * * This file is part of ser, a free SIP server. * * ser is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version * * For a license to use the ser software under conditions * other than those described here, or to purchase support for this * software, please contact iptel.org by e-mail at the following addresses: *    info@iptel.org * * ser is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License  * along with this program; if not, write to the Free Software  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <string.h>#include <stdlib.h>#include <libxml/parser.h>#include <libxml/xpath.h>#include "../../dprint.h"#include "paerrno.h"#include "common.h"#include "presentity.h"#include "pidf.h"#include "ptime.h"#include "pa_mod.h"#define CRLF "\r\n"#define CRLF_L (sizeof(CRLF) - 1)#define PUBLIC_ID "//IETF//DTD RFCxxxx PIDF 1.0//EN"#define PUBLIC_ID_L (sizeof(PUBLIC_ID) - 1)#define MIME_TYPE "application/pidf+xml"#define MIME_TYPE_L (sizeof(MIME_TYPE) - 1)#define XML_VERSION "<?xml version=\"1.0\"?>"#define XML_VERSION_L (sizeof(XML_VERSION) - 1)#define TUPLE_ETAG "</tuple>"#define TUPLE_ETAG_L (sizeof(TUPLE_ETAG) - 1)#define PIDF_DTD "pidf.dtd"#define PIDF_DTD_L (sizeof(XPDIF_DTD) - 1)#define DOCTYPE "<!DOCTYPE presence PUBLIC \"" PUBLIC_ID "\" \"" PIDF_DTD "\">"#define DOCTYPE_L (sizeof(DOCTYPE) - 1)#define PRESENCE_START "<presence entity=\"sip:"#define PRESENCE_START_L (sizeof(PRESENCE_START) - 1)#define PRESENCE_END "\">"#define PRESENCE_END_L (sizeof(PRESENCE_END) - 1)#define PRESENCE_ETAG "</presence>"#define PRESENCE_ETAG_L (sizeof(PRESENCE_ETAG) - 1)#define TUPLE_START "<tuple id=\"9r28r49\">"#define TUPLE_START_L (sizeof(TUPLE_START) - 1)#define TUPLE_END "\">"#define TUPLE_END_L (sizeof(TUPLE_END) - 1)#define CONTACT_START "  <contact"#define CONTACT_START_L (sizeof(CONTACT_START) - 1)#define PRIORITY_START "  priority=\""#define PRIORITY_START_L (sizeof(PRIORITY_START) - 1)#define PRIORITY_END "\""#define PRIORITY_END_L (sizeof(PRIORITY_END) - 1)#define CONTACT_END ">"#define CONTACT_END_L (sizeof(CONTACT_END) - 1)#define CONTACT_ETAG "</contact>"#define CONTACT_ETAG_L (sizeof(CONTACT_ETAG) - 1)#define STATUS_STAG "  <status>"#define STATUS_STAG_L (sizeof(STATUS_STAG) - 1)#define STATUS_ETAG "  </status>"#define STATUS_ETAG_L (sizeof(STATUS_ETAG) - 1)#define BASIC_OPEN "    <basic>open</basic>\r\n"#define BASIC_OPEN_L (sizeof(BASIC_OPEN) - 1)#define BASIC_CLOSED "    <basic>closed</basic>\r\n"#define BASIC_CLOSED_L (sizeof(BASIC_CLOSED) - 1)#define LOCATION_STAG "    <geopriv><location-info><civilAddress>"#define LOCATION_STAG_L (sizeof(LOCATION_STAG) - 1)#define LOCATION_ETAG "    </civilAddress></location-info></geopriv>"#define LOCATION_ETAG_L (sizeof(LOCATION_ETAG) - 1)#define LOC_STAG "      <loc>"#define LOC_STAG_L (sizeof(LOC_STAG) - 1)#define LOC_ETAG "</loc>"#define LOC_ETAG_L (sizeof(LOC_ETAG) - 1)#define SITE_STAG "      <site>"#define SITE_STAG_L (sizeof(SITE_STAG) - 1)#define SITE_ETAG "</site>"#define SITE_ETAG_L (sizeof(SITE_ETAG) - 1)#define FLOOR_STAG "      <floor>"#define FLOOR_STAG_L (sizeof(FLOOR_STAG) - 1)#define FLOOR_ETAG "</floor>"#define FLOOR_ETAG_L (sizeof(FLOOR_ETAG) - 1)#define ROOM_STAG "      <room>"#define ROOM_STAG_L (sizeof(ROOM_STAG) - 1)#define ROOM_ETAG "</room>"#define ROOM_ETAG_L (sizeof(ROOM_ETAG) - 1)#define X_STAG "      <x>"#define X_STAG_L (sizeof(X_STAG) - 1)#define X_ETAG "</x>"#define X_ETAG_L (sizeof(X_ETAG) - 1)#define Y_STAG "      <y>"#define Y_STAG_L (sizeof(Y_STAG) - 1)#define Y_ETAG "</y>"#define Y_ETAG_L (sizeof(Y_ETAG) - 1)#define RADIUS_STAG "      <radius>"#define RADIUS_STAG_L (sizeof(RADIUS_STAG) - 1)#define RADIUS_ETAG "</radius>"#define RADIUS_ETAG_L (sizeof(RADIUS_ETAG) - 1)#define PRESCAPS_STAG "  <prescaps>"#define PRESCAPS_STAG_L (sizeof(PRESCAPS_STAG) - 1)#define PRESCAPS_ETAG "  </prescaps>"#define PRESCAPS_ETAG_L (sizeof(PRESCAPS_ETAG) - 1)const char *prescap_names[] = {     "audio",     "video",     "text",     "application"};/* * Create start of pidf document */int start_pidf_doc(str* _b, int _l){	if ((XML_VERSION_L + 	     CRLF_L +	     DOCTYPE_L + 	     CRLF_L	    ) > _l) {		paerrno = PA_SMALL_BUFFER;		LOG(L_ERR, "start_pidf_doc(): Buffer too small\n");		return -1;	}	str_append(_b, XML_VERSION CRLF DOCTYPE CRLF,		   XML_VERSION_L + CRLF_L + DOCTYPE_L + CRLF_L);	return 0;}/* * Add a presentity information */int pidf_add_presentity(str* _b, int _l, str* _uri){	if (_l < PRESENCE_START_L + _uri->len + PRESENCE_END_L + CRLF_L) {		paerrno = PA_SMALL_BUFFER;		LOG(L_ERR, "pidf_add_presentity(): Buffer too small\n");		return -1;	}	str_append(_b, PRESENCE_START, PRESENCE_START_L);	str_append(_b, _uri->s, _uri->len);	str_append(_b, PRESENCE_END CRLF, 		   PRESENCE_END_L + CRLF_L);	return 0;}/* * Create start of pidf tuple */int pidf_start_tuple(str* _b, str *id, int _l){	if ((TUPLE_START_L + 	     id->len +	     TUPLE_END_L +	     CRLF_L	    ) > _l) {		paerrno = PA_SMALL_BUFFER;		LOG(L_ERR, "start_pidf_tuple(): Buffer too small: _l=%d\n", _l);		return -1;	}	str_append(_b, TUPLE_START, TUPLE_START_L);	str_append(_b, id->s, id->len);	str_append(_b, TUPLE_END CRLF, TUPLE_END_L + CRLF_L);	return 0;}/* * Add a contact address with given status and priority */int pidf_add_contact(str* _b, int _l, str* _addr, double priority){	char priority_s[32];	int priority_len = 0;	if (_addr->len) {		priority_len = sprintf(priority_s, "%f", priority);		str_append(_b, CONTACT_START, CONTACT_START_L);		if (pa_pidf_priority) {			str_append(_b, PRIORITY_START, PRIORITY_START_L);			str_append(_b, priority_s, priority_len);			str_append(_b, PRIORITY_END, PRIORITY_END_L);		}		str_append(_b, CONTACT_END, CONTACT_END_L);		str_append(_b, _addr->s, _addr->len);		str_append(_b, CONTACT_ETAG CRLF , 			   CONTACT_ETAG_L + CRLF_L);	}	return 0;}int pidf_start_status(str *_b, int _l, pidf_status_t _st){	int len = 0;	char* basic;	switch(_st) {	case PIDF_ST_OPEN:   basic = BASIC_OPEN;   len = BASIC_OPEN_L;   break;	case PIDF_ST_CLOSED: basic = BASIC_CLOSED; len = BASIC_CLOSED_L; break;	default:              basic = BASIC_CLOSED; len = BASIC_CLOSED_L; break; /* Makes gcc happy */	}	str_append(_b, STATUS_STAG CRLF, STATUS_STAG_L + CRLF_L);	str_append(_b, basic, len);	return 0;}int pidf_end_status(str *_b, int _l){	str_append(_b, STATUS_ETAG CRLF, STATUS_ETAG_L + CRLF_L);	return 0;}/* * Add location information */int pidf_add_location(str* _b, int _l, str *_loc, str *_site, str *_floor, str *_room, double _x, double _y, double _radius,		      enum prescaps prescaps){	str_append(_b, LOCATION_STAG, LOCATION_STAG_L);	if (_loc->len) {		str_append(_b, LOC_STAG, LOC_STAG_L);		str_append(_b, _loc->s, _loc->len);		str_append(_b, LOC_ETAG CRLF, LOC_ETAG_L + CRLF_L);	}	if (_site->len) {		str_append(_b, SITE_STAG, SITE_STAG_L);		str_append(_b, _site->s, _site->len);		str_append(_b, SITE_ETAG CRLF, SITE_ETAG_L + CRLF_L);	}	if (_floor->len) {		str_append(_b, FLOOR_STAG, FLOOR_STAG_L);		str_append(_b, _floor->s, _floor->len);		str_append(_b, FLOOR_ETAG CRLF, FLOOR_ETAG_L + CRLF_L);	}	if (_room->len) {		str_append(_b, ROOM_STAG, ROOM_STAG_L);		str_append(_b, _room->s, _room->len);		str_append(_b, ROOM_ETAG CRLF, ROOM_ETAG_L + CRLF_L);	}	if (_x) {		char buf[128];		int len = sprintf(buf, "%g", _x);		str_append(_b, X_STAG, X_STAG_L);		str_append(_b, buf, len);		str_append(_b, X_ETAG CRLF, X_ETAG_L + CRLF_L);	}	if (_y) {		char buf[128];		int len = sprintf(buf, "%g", _y);		str_append(_b, Y_STAG, Y_STAG_L);		str_append(_b, buf, len);		str_append(_b, Y_ETAG CRLF, Y_ETAG_L + CRLF_L);	}	if (_radius) {		char buf[128];		int len = sprintf(buf, "%g", _radius);		str_append(_b, RADIUS_STAG, RADIUS_STAG_L);		str_append(_b, buf, len);		str_append(_b, RADIUS_ETAG CRLF, RADIUS_ETAG_L + CRLF_L);	}	str_append(_b, LOCATION_ETAG CRLF, CRLF_L + LOCATION_ETAG_L);	if (prescaps) {	     int i;	     str_append(_b, PRESCAPS_STAG CRLF, PRESCAPS_STAG_L + CRLF_L);	     for (i = 0; i < 4; i++) {		  const char *prescap_name = prescap_names[i];		  char prescap[128];		  int prescap_l = sprintf(prescap, "      <%s>%s</%s>%s",

⌨️ 快捷键说明

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