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

📄 contact_ops.c

📁 用来作为linux中SIP SERVER,完成VOIP网络电话中服务器的功能
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * mangler module * * $Id: contact_ops.c,v 1.13.2.1 2005/07/20 17:11:51 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 *//* History: * -------- *  2003-04-07 first version.   */#include "contact_ops.h"#include "utils.h"#include "common.h"#include "../../mem/mem.h"#include "../../data_lump.h"#include "../../parser/hf.h"#include "../../parser/parse_uri.h"#include "../../parser/contact/parse_contact.h"#include "../../ut.h"#include <stdio.h>#include <string.h>//#define DEBUGintencode_contact (struct sip_msg *msg, char *encoding_prefix,char *public_ip){	contact_body_t *cb;	contact_t *c;	str uri;	str newUri;	int res;	char separator;	/*	 * I have a list of contacts in contact->parsed which is of type contact_body_t 	 * inside i have a contact->parsed->contact which is the head of the list of contacts	 * inside it is a 	 * str uri;	 * struct contact *next;	 * I just have to visit each uri and encode each uri according to a scheme	 */#ifdef DEBUG	fprintf (stdout,"---START--------ENCODE CONTACT-----------------\n");        fprintf (stdout,"%.*s\n",50,msg->buf);#endif		if ((msg->contact == NULL)&&((parse_headers(msg,HDR_CONTACT,0) == -1) ||				(msg->contact == NULL) ))		{		LOG(L_ERR,"ERROR: encode_contact: no Contact header present\n");		return -1;		}	separator = DEFAULT_SEPARATOR[0];	if (contact_flds_separator != NULL)		if (strlen(contact_flds_separator)>=1)			separator = contact_flds_separator[0];#ifdef DEBUG	fprintf (stdout,"Using separator %c\n",separator);#endif				if (msg->contact->parsed == NULL)	parse_contact (msg->contact);	if (msg->contact->parsed != NULL)	{		cb = (contact_body_t *) msg->contact->parsed;		c = cb->contacts;		/* we visit each contact */		if (c != NULL)		{			uri = c->uri;#ifdef DEBUG			fprintf (stdout, "olduri.s=[%.*s]\n", uri.len, uri.s);#endif			res = encode_uri (uri, encoding_prefix, public_ip,separator, &newUri);						if (res != 0)				{				LOG (L_ERR,"ERROR: encode_contact: Failed encoding contact.Code %d\n", res);#ifdef DEBUG				fprintf (stdout, "Encoding uri failed with code %d\n",res);#endif#ifdef STRICT_CHECK				return res;#endif				}			else				if (patch (msg, uri.s, uri.len, newUri.s, newUri.len) < 0)				{					LOG (L_ERR,"ERROR: encode_contact: lumping failed in mangling port \n");					return -2;				}				#ifdef DEBUG			if (res == 0) fprintf (stdout, "newuri.s=[%.*s]\nnewlen=%d\n", newUri.len, newUri.s,newUri.len);	#endif			/* encoding next contacts too?*/#ifdef ENCODE_ALL_CONTACTS			while (c->next != NULL)			{				c = c->next;				uri = c->uri;								res = encode_uri (uri, encoding_prefix,public_ip,separator,&newUri);				if (res != 0)					{					LOG(L_ERR,"ERROR: encode_contact: Failed encode_uri.Code %d\n",res);#ifdef STRICT_CHECK				return res;#endif					}				else				if (patch (msg, uri.s, uri.len, newUri.s, newUri.len)< 0)				{					LOG (L_ERR,"ERROR: encode_contact: lumping failed in mangling port \n");					return -3;				}			} /* while */#endif /* ENCODE_ALL_CONTACTS */		} /* if c != NULL */	} /* end if */	else /* after parsing still NULL */		{			LOG(L_ERR,"ERROR: encode_contact: Unable to parse Contact header\n");#ifdef DEBUG    			printf("ERROR: encode_contact: Unable to parse Contact header\n");#endif                        			return -4;		}#ifdef DEBUG	fprintf (stdout,"---END--------ENCODE CONTACT-----------------\n");#endif	return 1;}intdecode_contact (struct sip_msg *msg,char *unused1,char *unused2){	str uri;	str newUri;	char separator;	int res;		uri.s=0; /* fixes gcc 4.0 warning */	uri.len=0;#ifdef DEBUG	fprintf (stdout,"---START--------DECODE CONTACT-----------------\n");        fprintf (stdout,"%.*s\n",50,msg->buf);	fprintf (stdout, "INITIAL.s=[%.*s]\n", uri.len, uri.s);#endif	separator = DEFAULT_SEPARATOR[0];	if (contact_flds_separator != NULL)		if (strlen(contact_flds_separator)>=1)			separator = contact_flds_separator[0];			if ((msg->new_uri.s == NULL) || (msg->new_uri.len == 0))		{		uri = msg->first_line.u.request.uri;		if (uri.s == NULL) return -1;		}			res = decode_uri (uri, separator, &newUri);	#ifdef DEBUG		if (res == 0) fprintf (stdout, "newuri.s=[%.*s]\n", newUri.len, newUri.s);#endif		if (res != 0)		{			LOG (L_ERR,"ERROR: decode_contact:Failed decoding contact.Code %d\n", res);#ifdef STRICT_CHECK				return res;#endif		}		else			/* we do not modify the original first line */			if ((msg->new_uri.s == NULL) || (msg->new_uri.len == 0)) msg->new_uri = newUri;				else					{						pkg_free(msg->new_uri.s);						msg->new_uri = newUri;					}								/*		if (patch (msg, uri.s, uri.len, newUri.s, newUri.len) < 0)		{			LOG (L_ERR,"ERROR: decode_contact:lumping failed in mangling port \n");			return -2;		}		*/	return 1;}intdecode_contact_header (struct sip_msg *msg,char *unused1,char *unused2){	contact_body_t *cb;	contact_t *c;	str uri;	str newUri;	char separator;	int res;		#ifdef DEBUG	fprintf (stdout,"---START--------DECODE CONTACT HEADER-----------------\n");#endif	if ((msg->contact == NULL)&&((parse_headers(msg,HDR_CONTACT,0) == -1) || 				(msg->contact== NULL) ))		{		LOG(L_ERR,"ERROR: decode_contact_header: no Contact header present\n");		return -1;		}	separator = DEFAULT_SEPARATOR[0];	if (contact_flds_separator != NULL)		if (strlen(contact_flds_separator)>=1)			separator = contact_flds_separator[0];#ifdef DEBUG	fprintf (stdout,"Using separator %c\n",separator);	str* ruri;	ruri = GET_RURI(msg);	fprintf (stdout,"[len = %d]New uri is->%*.s\n",ruri->len,ruri->len,ruri->s);	ruri = &msg->first_line.u.request.uri;	fprintf (stdout, "INITIAL.s=[%.*s]\n", ruri->len, ruri->s);#endif			if (msg->contact->parsed == NULL) parse_contact (msg->contact);	if (msg->contact->parsed != NULL)	{		cb = (contact_body_t *) msg->contact->parsed;		c = cb->contacts;		// we visit each contact 	 if (c != NULL)	  {		uri = c->uri;		res = decode_uri (uri, separator, &newUri);#ifdef DEBUG		fprintf (stdout, "newuri.s=[%.*s]\n", newUri.len, newUri.s);#endif		if (res != 0)		{			LOG (L_ERR,"ERROR: decode_contact_header:Failed decoding contact.Code %d\n", res);#ifdef STRICT_CHECK				return res;#endif		}		else		if (patch (msg, uri.s, uri.len, newUri.s, newUri.len) < 0)		{			LOG (L_ERR,"ERROR: decode_contact:lumping failed in mangling port \n");			return -2;		}#ifdef DECODE_ALL_CONTACTS		while (c->next != NULL)		{			c = c->next;			uri = c->uri;			res = decode_uri (uri, separator, &newUri);			if (res != 0)				{				LOG (L_ERR,"ERROR: decode_contact: Failed decoding contact.Code %d\n",res);#ifdef STRICT_CHECK				return res;#endif				}			else			if (patch (msg, uri.s, uri.len, newUri.s, newUri.len) < 0)			{				LOG (L_ERR,"ERROR: decode_contact:lumping failed in mangling port \n");				return -3;			}		} // end while #endif	   } // if c!= NULL 	} // end if 	else // after parsing still NULL 		{			LOG(L_ERR,"ERROR: decode_contact: Unable to parse Contact header\n");			return -4;		}#ifdef DEBUG	fprintf (stdout,"---END--------DECODE CONTACT HEADER-----------------\n");fflush(stdout);#endif	return 1;}intencode2format (str uri, struct uri_format *format){	int foo;	char *string, *pos, *start, *end;	struct sip_uri sipUri;	if (uri.s == NULL)		return -1;	string = uri.s;	pos = q_memchr (string, '<', uri.len);	if (pos != NULL)	/* we are only interested of chars inside <> */	{		start = q_memchr (string, ':', uri.len);		if (start == NULL)	return -2;		if (start - pos < 4) return -3;		start = start - 3;		end = strchr (start, '>');		if (end == NULL)			return -4;	/* must be a match to < */	}

⌨️ 快捷键说明

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