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

📄 sms.c

📁 用来作为linux中SIP SERVER,完成VOIP网络电话中服务器的功能
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * $Id: sms.c,v 1.37 2004/08/24 09:00:39 janakj 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-03-11  updated to the new module exports interface (andrei) *  2003-03-16  flags export parameter added (janakj) *  2003-03-19  all mallocs/frees replaced w/ pkg_malloc/pkg_free (andrei) *  2003-04-02  port_no_str does not contain a leading ':' anymore (andrei) *  2003-04-06  Only child 1 will execute child init (janakj) *  2003-10-24  updated to the new socket_info lists (andrei) */#include <stdio.h>#include <string.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include "../../sr_module.h"#include "../../error.h"#include "../../dprint.h"#include "../../ut.h"#include "../../globals.h"#include "../../mem/mem.h"#include "../../mem/shm_mem.h"#include "../../socket_info.h"#include "../tm/tm_load.h"#include "sms_funcs.h"#include "sms_report.h"#include "libsms_modem.h"MODULE_VERSIONstatic int sms_init(void);static int sms_exit(void);static int sms_child_init(int);static int w_sms_send_msg(struct sip_msg*, char*, char* );static int w_sms_send_msg_to_net(struct sip_msg*, char*, char*);static int fixup_sms_send_msg_to_net(void** param, int param_no);/* parameters */char *networks_config = 0;char *modems_config   = 0;char *links_config    = 0;char *default_net_str = 0;char *domain_str      = 0;/*global variables*/int    default_net    = 0;int    max_sms_parts  = MAX_SMS_PARTS;str    domain;int    *queued_msgs    = 0;int    use_contact     = 0;int    sms_report_type = NO_REPORT;struct tm_binds tmb;static cmd_export_t cmds[]={	{"sms_send_msg_to_net", w_sms_send_msg_to_net, 1, 	     fixup_sms_send_msg_to_net, REQUEST_ROUTE},	{"sms_send_msg",        w_sms_send_msg,        0,  	     0,                         REQUEST_ROUTE},	{0,0,0,0,0}};static param_export_t params[]={	{"networks",        STR_PARAM, &networks_config },	{"modems",          STR_PARAM, &modems_config   },	{"links",           STR_PARAM, &links_config    },	{"default_net",     STR_PARAM, &default_net_str },	{"max_sms_parts",   INT_PARAM, &max_sms_parts   },	{"domain",          STR_PARAM, &domain_str      },	{"use_contact",     INT_PARAM, &use_contact     },	{"sms_report_type", INT_PARAM, &sms_report_type },	{0,0,0}};struct module_exports exports= {	"sms",	cmds,	params,		sms_init,   /* module initialization function */	(response_function) 0,	(destroy_function) sms_exit,   /* module exit function */	0,	(child_init_function) sms_child_init  /* per-child init function */};static int fixup_sms_send_msg_to_net(void** param, int param_no){	long net_nr,i;	if (param_no==1) {		for(net_nr=-1,i=0;i<nr_of_networks&&net_nr==-1;i++)			if (!strcasecmp(networks[i].name,*param))				net_nr = i;		if (net_nr==-1) {			LOG(L_ERR,"ERROR:fixup_sms_send_msg_to_net: network \"%s\""				" not found in net list!\n",(char*)*param);			return E_UNSPEC;		} else {			pkg_free(*param);			*param=(void*)net_nr;			return 0;		}	}	return 0;}#define eat_spaces(_p) \	while( *(_p)==' ' || *(_p)=='\t' ){\	(_p)++;}int set_modem_arg(struct modem *mdm, char *arg, char *arg_end){	int err, foo;	if (*(arg+1)!='=') {		LOG(L_ERR,"ERROR: invalid parameter syntax near [=]\n");		goto error;	}	switch (*arg)	{		case 'd':  /* device */			memcpy(mdm->device,arg+2,arg_end-arg-2);			mdm->device[arg_end-arg-2] = 0;			break;		case 'p':  /* pin */			memcpy(mdm->pin,arg+2,arg_end-arg-2);			mdm->pin[arg_end-arg-2] = 0;			break;		case 'm':  /* mode */			if (!strncasecmp(arg+2,"OLD",3)			&& arg_end-arg-2==3) {				mdm->mode = MODE_OLD;			} else if (!strncasecmp(arg+2,"DIGICOM",7)			&& arg_end-arg-2==7) {				mdm->mode = MODE_DIGICOM;			} else if (!strncasecmp(arg+2,"ASCII",5)			&& arg_end-arg-2==5) {				mdm->mode = MODE_ASCII;			} else if (!strncasecmp(arg+2,"NEW",3)			&& arg_end-arg-2==3) {				mdm->mode = MODE_NEW;			} else {				LOG(L_ERR,"ERROR: invalid value \"%.*s\" for param [m]\n",					(int)(arg_end-arg-2),arg+2);				goto error;			}			break;		case 'c':  /* sms center number */			memcpy(mdm->smsc,arg+2,arg_end-arg-2);			mdm->smsc[arg_end-arg-2] = 0;			break;		case 'r':  /* retry time */			foo=str2s(arg+2,arg_end-arg-2,&err);			if (err) {				LOG(L_ERR,"ERROR:set_modem_arg: cannot convert [r] arg to"					" integer!\n");				goto error;			}			mdm->retry = foo;			break;		case 'l':  /* looping interval */			foo=str2s(arg+2,arg_end-arg-2,&err);			if (err) {				LOG(L_ERR,"ERROR:set_modem_arg: cannot convert [l] arg to"					" integer!\n");				goto error;			}			mdm->looping_interval = foo;			break;		case 'b':  /* baudrate */			foo=str2s(arg+2,arg_end-arg-2,&err);			if (err) {				LOG(L_ERR,"ERROR:set_modem_arg: cannot convert [b] arg to"					" integer!\n");				goto error;			}			switch (foo) {				case   300: foo=B300; break;				case  1200: foo=B1200; break;				case  2400: foo=B2400; break;				case  9600: foo=B9600; break;				case 19200: foo=B19200; break;				case 38400: foo=B38400; break;				case 57600: foo=B57600; break;				default:					LOG(L_ERR,"ERROR:set_modem_arg: unsupported value %d "						"for [b] arg!\n",foo);					goto error;			}			mdm->baudrate = foo;			break;		default:			LOG(L_ERR,"ERROR:set_modem_arg: unknown param name [%c]\n",*arg);			goto error;	}	return 1;error:	return -1;}int set_network_arg(struct network *net, char *arg, char *arg_end){	int err,foo;	if (*(arg+1)!='=') {		LOG(L_ERR,"ERROR:set_network_arg:invalid parameter syntax near [=]\n");		goto error;	}	switch (*arg)	{		case 'm':  /* maximum sms per one call */			foo=str2s(arg+2,arg_end-arg-2,&err);			if (err) {				LOG(L_ERR,"ERROR:set_network_arg: cannot convert [m] arg to"					" integer!\n");				goto error;			}			net->max_sms_per_call = foo;			break;		default:			LOG(L_ERR,"ERROR:set_network_arg: unknown param name [%c]\n",*arg);			goto error;	}	return 1;error:	return -1;}int parse_config_lines(){	char *p,*start;	int  i, k, step;	int  mdm_nr, net_nr;	nr_of_networks = 0;	nr_of_modems = 0;	step = 1;	/* parsing modems configuration string */	if ( (p = modems_config)==0) {		LOG(L_ERR,"ERROR:SMS parse_config_lines: param \"modems\" not"			" found\n");		goto error;	}	while (*p)	{		eat_spaces(p);		/*get modem's name*/		start = p;		while (*p!=' ' && *p!='\t' && *p!='[' && *p!=0)			p++;		if ( p==start || *p==0 )			goto parse_error;		memcpy(modems[nr_of_modems].name, start, p-start);		modems[nr_of_modems].name[p-start] = 0;		modems[nr_of_modems].smsc[0] = 0;		modems[nr_of_modems].device[0] = 0;		modems[nr_of_modems].pin[0] = 0;		modems[nr_of_modems].mode = MODE_NEW;		modems[nr_of_modems].retry = 4;		modems[nr_of_modems].looping_interval = 20;		modems[nr_of_modems].baudrate = B9600;		memset(modems[nr_of_modems].net_list,0XFF,			sizeof(modems[nr_of_modems].net_list) );		/*get modem parameters*/		eat_spaces(p);		if (*p!='[')			goto parse_error;		p++;		while (*p!=']')		{			eat_spaces(p);			start = p;			while(*p!=' ' && *p!='\t' && *p!=']' && *p!=';' && *p!=0)				p++;			if ( p==start || *p==0 )				goto parse_error;			if (set_modem_arg( &(modems[nr_of_modems]), start, p)==-1)				goto error;			eat_spaces(p);			if (*p==';') {				p++;				eat_spaces(p);			}		}		if (*p!=']')			goto parse_error;		p++;

⌨️ 快捷键说明

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