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

📄 driver.c

📁 使用TAP的蜂窝型GSM手机短消息服务中心
💻 C
字号:
/* -------------------------------------------------------------------- *//* SMS Client, send messages to mobile phones and pagers		*//*									*//* driver.c								*//*									*//*  Copyright (C) 1997,1998 Angelo Masci				*//*									*//*  This library is free software; you can redistribute it and/or	*//*  modify it under the terms of the GNU Library General Public		*//*  License as published by the Free Software Foundation; either	*//*  version 2 of the License, or (at your option) any later version.	*//*									*//*  This library 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	*//*  Library General Public License for more details.			*//*									*//*  You should have received a copy of the GNU Library General Public	*//*  License along with this library; if not, write to the Free		*//*  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.	*//*									*//*  You can contact the author at this e-mail address:			*//*									*//*  angelo@styx.demon.co.uk						*//*									*//* -------------------------------------------------------------------- *//* $Id: driver.c,v 5.1 1998/02/01 07:10:39 root Exp $   -------------------------------------------------------------------- */#include <stdio.h>#include <string.h>#if defined(MODEMLIB) && (MODEMLIB == LIBMODEM)#include <termios.h>#include <dial/modems.h>#else#include "sms_modem.h"#endif#include "common.h"#include "logfile.h"#include "driver.h"#include "parserc.h"#include "sms_error.h"/* -------------------------------------------------------------------- */#if !defined(MSERVICEDIR)#error "MSERVICEDIR undefined"#else#define SERVICEDIR        MSERVICEDIR#endif/* -------------------------------------------------------------------- */DEVICE_ENTRY *device_list[] = {#if defined(TAP)	&tap_device,#endif#if defined(VODAFONE)	&vodafone_device,#endif#if defined(ORANGE)	&orange_device,#endif#if defined(PAGEONE)	&pageone_device,#endif#if defined(VODACOM)	&vodacom_device,#endif#if defined(MTN)	&mtn_device,#endif#if defined(ONE2ONE)	&one2one_device,#endif#if defined(LIBERTEL)	&libertel_device,#endif#if defined(TIM)	&tim_device,#endif#if defined(SNPP)	&snpp_device,#endif#if defined(CIMD)	&cimd_device,#endif#if defined(VODAPAGE_BLOCK)	&vodapage_block_device,#endif#if defined(PROXIMUS)	&proximus_device,#endif#if defined(KPN)	&kpn_device,#endif#if defined(ANSWER)	&answer_device,#endif#if defined(GENERIC)	&generic_device,#endif	NULL};/* -------------------------------------------------------------------- */#if defined(MODEMLIB) && (MODEMLIB == LIBMODEM)static void LIBMODEM_setup_comm_params(int fd, char *params);static int LIBMODEM_dial(char *number, char *params, long baud);static int num2baud (long baud_num);static int SMS_dial(char *number, char *params, long baud);static void SMS_hangup(int fd);#endif/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */DEVICE_ENTRY *get_device(char *name){	DEVICE_ENTRY **device;	if (name == NULL)	{	return NULL;	}		device = device_list;	while (*device != NULL)	{		if ((*device)->name != NULL)		{	if (strcmp((*device)->name, name) == 0)			{				lprintf(LOG_VERBOSE, "Device Found: %s\n", name);				return *device;			}		}		device++;	}	lprintf(LOG_VERBOSE, "Device NOT Found: %s\n", name);	return NULL;}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */void display_drivers(void){	DEVICE_ENTRY **device;	device = device_list;	if (*device == NULL)	{	lprintf(LOG_WARNING, "No drivers have been included!\n");	}	while (*device != NULL)	{		if ((*device)->name != NULL)		{	lprintf(LOG_STANDARD, "%s\n", (*device)->name);		}		else		{	lprintf(LOG_STANDARD, "<NULL>\n");		}		device++;	}}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */#if defined(MODEMLIB) && (MODEMLIB == LIBMODEM)static void LIBMODEM_setup_comm_params(int fd, char *params){	struct 	termios 		trm;		if (params == NULL)	{	return;	}	lprintf(LOG_VERBOSE, "Setting communications parameters: %s\n", params);	if (strcmp(params, "8N1") == 0)	{		/* Default - No ACTION */	}	else if (strcmp(params, "7E1") == 0)	{		tcgetattr(fd, &trm);		trm.c_cflag &= ~(CSIZE|CSTOPB|PARODD);		trm.c_cflag |= CS7|PARENB;		tcsetattr(fd, TCSAFLUSH, &trm);	}}        static int num2baud(long baud) {	switch (baud)	{		case 0:			return B0;		case 50:			return B50;		case 75:			return B75;		case 110:			return B110;		case 134:			return B134;		case 150:			return B150;		case 200:			return B200;		case 300:			return B300;		case 600:			return B600;		case 1200:			return B1200;		case 1800:			return B1800;		case 2400:			return B2400;		case 4800:			return B4800;		case 7200:		case 9600:			return B9600;		case 12200:		case 14400:		case 16800:		case 19200:			return B19200;		case 21600:		case 24000:		case 26400:		case 28800:		case 31200:		case 33600:		case 38400:			return B38400;	}	return -1;}static int LIBMODEM_dial(char *number, char *params, long baud){	int 	fd, mbaud;	lprintf(LOG_VERBOSE, "Using Libmodem Package\n");		mbaud = num2baud(baud);	if (mbaud != -1)	{	fd = bdial(number, num2baud(baud));	}	else	{	lprintf(LOG_WARNING, "Unknown baud %ld\n", baud);		return -1;	}	/* Libmodem-1.0.0 does not supports 	*/	/* cofiguration of modem parameters.	*/	/* Use own function to change them.	*/	if (fd >= 0)	{	LIBMODEM_setup_comm_params(fd, params);	}	return fd;}static int SMS_dial(char *number, char *params, long baud){	return LIBMODEM_dial(number, params, baud);}static void SMS_hangup(int fd){	hangup(fd);}#endif/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */int default_dial(DRIVER_DEFAULT_ENV *env){	lprintf(LOG_STANDARD, "Dialing SMSC %s...\n", env->centre_number);		env->fd = SMS_dial(env->centre_number, env->comms_params, env->baud);	if (env->fd < 0)	{ 	lprintf(LOG_WARNING, "Failed to connect\n"); 		return EDIAL;	}	lprintf(LOG_STANDARD, "Connection Established.\n");	return 0;}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */void default_hangup(DRIVER_DEFAULT_ENV *env){	lprintf(LOG_STANDARD, "Hangup...\n");	SMS_hangup(env->fd);	env->connection_status = SERVICE_NOT_CONNECTED;}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */SMS_list *default_main(SMS_list *list, char *message, DRIVER_DEFAULT_ENV *env){	SMS_list 		*node;	int	result;	if (env->device->name != NULL)	{	lprintf(LOG_VERBOSE, "%s driver called\n", env->device->name);	}	else	{	lprintf(LOG_VERBOSE, "<NULL> driver called\n");	}	env->connection_status = SERVICE_NOT_CONNECTED;	result = 0;		node = get_first(list);	while (node != NULL)	{		result = (* env->device->deliver)(node, message, env);		set_delivery(node, result);		if (result)		{	(* env->device->hangup)(env);			env->connection_status = SERVICE_NOT_CONNECTED;		}		node = get_next(node);	}	if ((result == 0) && (env->connection_status == SERVICE_CONNECTED))	{		(* env->device->disconnect)();		(* env->device->hangup)(env);		env->connection_status = SERVICE_NOT_CONNECTED;	}	return NULL;}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */int default_multiple_deliver(SMS_list *node, char *message, DRIVER_DEFAULT_ENV *env){	char 	*msisdn, 		*name;	int 	error;	msisdn = get_number(node);	name   = get_name(node);	lprintf(LOG_VERBOSE, "Name     :%s\n", name);	lprintf(LOG_VERBOSE, "Number   :%s\n", msisdn);	if (env->connection_status == SERVICE_NOT_CONNECTED)	{		env->connection_status = SERVICE_CONNECTED;	 	error = (* env->device->dial)(env);		if (error)		{	return error;		}		error = (* env->device->login)();		if (error)		{	return error;		}	}	error = (* env->device->sendmessage)(msisdn, message);	if (error)	{	return error;	}	return 0;}/* -------------------------------------------------------------------- *//* Send as many messages as we are allowed.				*//* Keep track of number of messages sent and compare against		*//* Max allowed, disconnecting when number sent reaches			*//* the max allowed.							*//* -------------------------------------------------------------------- */int default_multiple_counted_deliver(SMS_list *node, char *message, DRIVER_DEFAULT_ENV *env){	char 	*msisdn, 		*name;	int 	error;	msisdn = get_number(node);	name   = get_name(node);	lprintf(LOG_VERBOSE, "Name     :%s\n", name);	lprintf(LOG_VERBOSE, "Number   :%s\n", msisdn);	if (env->connection_status == SERVICE_NOT_CONNECTED)	{		env->num_sent          = 0;		env->connection_status = SERVICE_CONNECTED;	 	error = (* env->device->dial)(env);		if (error)		{	return error;		}		error = (* env->device->login)();		if (error)		{	return error;		}	}	error = (* env->device->sendmessage)(msisdn, message);	if (error)	{	return error;	}	env->num_sent++;	lprintf(LOG_VERBOSE, "Num sent    = %ld\n", env->num_sent);	lprintf(LOG_VERBOSE, "Max deliver = %ld\n", env->max_deliver);	if ((env->max_deliver != 0) && 	    (env->num_sent >= env->max_deliver))	{		(* env->device->disconnect)();		(* env->device->hangup)(env);		env->connection_status = SERVICE_NOT_CONNECTED;	}	return 0;}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */int default_send_disconnect(void){	return 0;}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */int default_single_deliver(SMS_list *node, char *message, DRIVER_DEFAULT_ENV *env){	char 	*msisdn, 		*name;	int 	error;		msisdn = get_number(node);	name   = get_name(node);	lprintf(LOG_VERBOSE, "Name     :%s\n", name);	lprintf(LOG_VERBOSE, "Number   :%s\n", msisdn);	env->connection_status = SERVICE_CONNECTED;	error = (* env->device->dial)(env);	if (error)	{	return error;	}	error = (* env->device->login)();	if (error)	{	return error;	}	error = (* env->device->sendmessage)(msisdn, message);	if (error)	{	return error;	}	(* env->device->disconnect)();	(* env->device->hangup)(env);	env->connection_status = SERVICE_NOT_CONNECTED;	return 0;}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */int default_validate_numeric_id(char *id){	return is_numeric(id);}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */int default_validate_always_true(char *id){	return TRUE;}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */void default_init(char *mservice, DEVICE_ENTRY *device){	char fname[1024];	sms_strcpy(fname, SERVICEDIR);	sms_strcat(fname, "/services/");	sms_strcat(fname, mservice);	if (read_resource_file(fname, device->resource_list, TRUE) != RESOURCE_FILE_OK)	{	lprintf(LOG_ERROR, "Unrecoverable Failure Parsing file %s\n", fname); 		exit(1);	}	device->env->device = device;}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */int default_login(void){	return 0;}/* -------------------------------------------------------------------- *//* -------------------------------------------------------------------- */int default_sendmessage(char *msisdn, char *message){	return 0;}

⌨️ 快捷键说明

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