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

📄 pidf.c

📁 用来作为linux中SIP SERVER,完成VOIP网络电话中服务器的功能
💻 C
📖 第 1 页 / 共 2 页
字号:
					  prescap_name, ((prescaps & (1 << i)) ? "true" : "false"), prescap_name, CRLF);		  str_append(_b, prescap, prescap_l);	     }	     str_append(_b, PRESCAPS_ETAG CRLF, PRESCAPS_ETAG_L + CRLF_L);	}	str_append(_b, STATUS_ETAG CRLF, STATUS_ETAG_L + CRLF_L);	return 0;}/* * Create start of pidf tuple */int pidf_end_tuple(str* _b, int _l){	if ((TUPLE_ETAG_L + 	     CRLF_L	    ) > _l) {		paerrno = PA_SMALL_BUFFER;		LOG(L_ERR, "pidf_end_tuple(): Buffer too small\n");		return -1;	}	str_append(_b, TUPLE_ETAG CRLF,		   TUPLE_ETAG_L + CRLF_L);	return 0;}/* * End the document */int end_pidf_doc(str* _b, int _l){	if (_l < (PRESENCE_ETAG_L + CRLF_L)) {		paerrno = PA_SMALL_BUFFER;		LOG(L_ERR, "end_pidf_doc(): Buffer too small\n");		return -1;	}	str_append(_b, PRESENCE_ETAG CRLF, PRESENCE_ETAG_L + CRLF_L);	return 0;}xmlDocPtr event_body_parse(char *event_body){	return xmlParseMemory(event_body, strlen(event_body));}/* * apply procedure f to each xmlNodePtr in doc matched by xpath */void xpath_map(xmlDocPtr doc, char *xpath, void (*f)(xmlNodePtr, void *), void *data){	xmlXPathContextPtr context;	xmlXPathObjectPtr result;	xmlNodeSetPtr nodeset;	int i;	context = xmlXPathNewContext(doc);	result = xmlXPathEvalExpression((xmlChar*)xpath, context);	if(!result || xmlXPathNodeSetIsEmpty(result->nodesetval)){		fprintf(stderr, "xpath_map: no result for xpath=%s\n", xpath);		return;	}	nodeset = result->nodesetval;	for (i=0; i < nodeset->nodeNr; i++) {		xmlNodePtr node = nodeset->nodeTab[i];		printf("name[%d]: %s\n", i, node->name);		f(node, data);	}	xmlXPathFreeContext(context);}xmlNodePtr xpath_get_node(xmlDocPtr doc, char *xpath){	xmlXPathContextPtr context;	xmlXPathObjectPtr result;	xmlNodeSetPtr nodeset;	xmlNodePtr node;	context = xmlXPathNewContext(doc);	result = xmlXPathEvalExpression((xmlChar*)xpath, context);	if(xmlXPathNodeSetIsEmpty(result->nodesetval)){		fprintf(stderr, "xpath_get_node: no result for xpath=%s\n", xpath);		return NULL;	}	nodeset = result->nodesetval;	node = nodeset->nodeTab[0];	xmlXPathFreeContext(context);	return node;}xmlAttrPtr xmlNodeGetAttrByName(xmlNodePtr node, const char *name){	xmlAttrPtr attr = node->properties;	while (attr) {		if (xmlStrcasecmp(attr->name, (xmlChar*)name) == 0)			return attr;		attr = attr->next;	}	return NULL;}char *xmlNodeGetAttrContentByName(xmlNodePtr node, const char *name){     xmlAttrPtr attr = xmlNodeGetAttrByName(node, name);     if (attr)	  return (char*)xmlNodeGetContent(attr->children);     else	  return NULL;}xmlNodePtr xmlNodeGetChildByName(xmlNodePtr node, const char *name){	xmlNodePtr cur = node->children;	while (cur) {		if (xmlStrcasecmp(cur->name, (xmlChar*)name) == 0)			return cur;		cur = cur->next;	}	return NULL;}xmlNodePtr xmlNodeGetNodeByName(xmlNodePtr node, const char *name, const char *ns){	xmlNodePtr cur = node;	while (cur) {		xmlNodePtr match = NULL;		if (xmlStrcasecmp(cur->name, (xmlChar*)name) == 0) {			if (!ns || (cur->ns && 						xmlStrcasecmp(cur->ns->prefix, (xmlChar*)ns) == 0))				return cur;		}		match = xmlNodeGetNodeByName(cur->children, name, ns);		if (match)			return match;		cur = cur->next;	}	return NULL;}char *xmlNodeGetNodeContentByName(xmlNodePtr root, const char *name, const char *ns){	xmlNodePtr node = xmlNodeGetNodeByName(root, name, ns);	if (node)		return (char*)xmlNodeGetContent(node->children);	else		return NULL;}xmlNodePtr xmlDocGetNodeByName(xmlDocPtr doc, const char *name, const char *ns){	xmlNodePtr cur = doc->children;	return xmlNodeGetNodeByName(cur, name, ns);}char *xmlDocGetNodeContentByName(xmlDocPtr doc, const char *name, const char *ns){	xmlNodePtr node = xmlDocGetNodeByName(doc, name, ns);	if (node)		return (char*)xmlNodeGetContent(node->children);	else		return NULL;}void xmlNodeMapByName(xmlNodePtr node, const char *name, const char *ns, 		      void (f)(xmlNodePtr, void*), void *data){	xmlNodePtr cur = node;	if (!f)		return;	while (cur) {		if (xmlStrcasecmp(cur->name, (xmlChar*)name) == 0) {			if (!ns || (cur->ns &&						xmlStrcasecmp(cur->ns->prefix, (xmlChar*)ns) == 0))				f(cur, data);		}		/* visit children */		xmlNodeMapByName(cur->children, name, ns, f, data);		cur = cur->next;	}}void xmlDocMapByName(xmlDocPtr doc, const char *name, const char *ns,			   void (f)(xmlNodePtr, void*), void *data ){	xmlNodePtr cur = doc->children;	xmlNodeMapByName(cur, name, ns, f, data);}int parse_pidf(char *pidf_body, str *contact_str, str *basic_str, str *status_str, 	       str *location_str, str *site_str, str *floor_str, str *room_str,	       double *xp, double *yp, double *radiusp,	       str *packet_loss_str, double *priorityp, time_t *expiresp,	       int *prescapsp){     int flags = 0;     xmlDocPtr doc = NULL;     xmlNodePtr presenceNode = NULL;     xmlNodePtr prescapsNode = NULL;     char *presence = NULL;     char *sipuri = NULL;     char *contact = NULL;     char *basic = NULL;     char *status = NULL;     char *location = NULL;     char *site = NULL;     char *floor = NULL;     char *room = NULL;     char *x = NULL;     char *y = NULL;     char *radius = NULL;     char *packet_loss = NULL;     char *priority_str = NULL;     char *expires_str = NULL;     int prescaps = 0;     doc = event_body_parse(pidf_body);     if (!doc) {	  return flags;     }     presenceNode = xmlDocGetNodeByName(doc, "presence", NULL);     presence = xmlDocGetNodeContentByName(doc, "presence", NULL);     contact = xmlDocGetNodeContentByName(doc, "contact", NULL);     basic = xmlDocGetNodeContentByName(doc, "basic", NULL);     status = xmlDocGetNodeContentByName(doc, "status", NULL);     location = xmlDocGetNodeContentByName(doc, "loc", NULL);     site = xmlDocGetNodeContentByName(doc, "site", NULL);     floor = xmlDocGetNodeContentByName(doc, "floor", NULL);     room = xmlDocGetNodeContentByName(doc, "room", NULL);     x = xmlDocGetNodeContentByName(doc, "x", NULL);     y = xmlDocGetNodeContentByName(doc, "y", NULL);     radius = xmlDocGetNodeContentByName(doc, "radius", NULL);     packet_loss = xmlDocGetNodeContentByName(doc, "packet-loss", NULL);     priority_str = xmlDocGetNodeContentByName(doc, "priority", NULL);     expires_str = xmlDocGetNodeContentByName(doc, "expires", NULL);     prescapsNode = xmlDocGetNodeByName(doc, "prescaps", NULL);		     if (presenceNode)	  sipuri = xmlNodeGetAttrContentByName(presenceNode, "entity");     LOG(L_INFO, "parse_pidf: sipuri=%p:%s contact=%p:%s basic=%p:%s location=%p:%s\n",	 sipuri, sipuri, contact, contact, basic, basic, location, location);     LOG(L_INFO, "parse_pidf: site=%p:%s floor=%p:%s room=%p:%s\n",	 site, site, floor, floor, room, room);     LOG(L_INFO, "parse_pidf: x=%p:%s y=%p:%s radius=%p:%s\n",	 x, x, y, y, radius, radius);     if (packet_loss)	  LOG(L_INFO, "packet_loss=%p:%s\n", packet_loss, packet_loss);     if (contact_str && contact) {	  contact_str->len = strlen(contact);	  contact_str->s = strdup(contact);	  flags |= PARSE_PIDF_CONTACT;     }     if (basic_str && basic) {	  basic_str->len = strlen(basic);	  basic_str->s = strdup(basic);	  flags |= PARSE_PIDF_BASIC;     }     if (status_str && status) {	  status_str->len = strlen(status);	  status_str->s = strdup(status);	  flags |= PARSE_PIDF_STATUS;     }     if (location_str && location) {	  location_str->len = strlen(location);	  location_str->s = strdup(location);	  flags |= PARSE_PIDF_LOC;     }     if (site_str && site) {	  site_str->len = strlen(site);	  site_str->s = strdup(site);	  flags |= PARSE_PIDF_SITE;     }     if (floor_str && floor) {	  floor_str->len = strlen(floor);	  floor_str->s = strdup(floor);	  flags |= PARSE_PIDF_FLOOR;     }     if (room_str && room) {	  room_str->len = strlen(room);	  room_str->s = strdup(room);	  flags |= PARSE_PIDF_ROOM;     }     if (xp && x) {	  *xp = strtod(x, NULL);	  flags |= PARSE_PIDF_X;     }     if (yp && y) {	  *yp = strtod(y, NULL);	  flags |= PARSE_PIDF_Y;     }     if (radiusp && radius) {	  *radiusp = strtod(radius, NULL);	  flags |= PARSE_PIDF_RADIUS;     }     if (packet_loss_str && packet_loss) {	  packet_loss_str->len = strlen(packet_loss);	  packet_loss_str->s = strdup(packet_loss);	  flags |= PARSE_PIDF_PACKET_LOSS;     }     if (expiresp && expires_str) {       *expiresp = act_time + strtod(expires_str, NULL);       flags |= PARSE_PIDF_EXPIRES;     }     if (priorityp && priority_str) {	  *priorityp = strtod(priority_str, NULL);	  flags |= PARSE_PIDF_PRIORITY;     }     if (prescapsNode) {	  int i;	  for (i = 0; i < 4; i++) {	       const char *prescap_name = prescap_names[i];	       xmlNodePtr prescap_node = xmlNodeGetNodeByName(prescapsNode, prescap_name, NULL);	       const char *prescap_str = xmlNodeGetNodeContentByName(prescapsNode, prescap_name, NULL);	       if (prescap_str && (strcasecmp(prescap_str, "true") == 0))		    prescaps |= (1 << i);	       LOG(L_INFO, "parse_pidf: prescap=%s node=%p value=%s\n", prescap_name, prescap_node, prescap_str);	  }	  LOG(L_INFO, "parse_pidf: prescaps=%x\n", prescaps);     }     if (prescapsp) {	  *prescapsp = prescaps;	  flags |= PARSE_PIDF_PRESCAPS;     }     return flags;}

⌨️ 快捷键说明

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