- Added Quick Dial feature

This commit is contained in:
Thomas Ries
2005-12-26 16:39:12 +00:00
parent 6c6535ccd6
commit 9ac6fd6f0a
9 changed files with 193 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
0.5.12
======
26-Dec-2005: - Added a short-dial feature ("pi_shortdial_*" config options)
18-Dec-2005: - Grandstream "unregister at startup" works now
9-Oct-2005: - Expiration timeout is now taken from the REGISTER response
- fix: no audio with some UAs that do not include a

View File

@@ -238,3 +238,21 @@ debug_port = 0
#outbound_domain_name = freenet.de
#outbound_domain_host = proxy.for.domain.freende.de
#outbound_domain_port = 5060
######################################################################
# Plugins
#
# Quick Dial (Short Dial)
# ability to define quick dial numbers that can be accessed by
# dialing "*nn" from a local phone. 'nn' corresponse to the entry number
# (pi_shortdial_entry) below. The '*' character can be chosen freely
# (pi_shortdial_akey).
# Note: To call a real number like "*1234" you would have to dial "**1234"
#
pi_shortdial_enable = 1
pi_shortdial_akey = *
#
# *01 sipphone echo test
pi_shortdial_entry = 17474743246
# *02 sipcall welcome message
pi_shortdial_entry = 17474745000

View File

@@ -28,8 +28,9 @@ AM_CFLAGS = -Wall -D_GNU_SOURCE \
sbin_PROGRAMS = siproxd
siproxd_SOURCES = siproxd.c proxy.c register.c sock.c utils.c \
sip_utils.c sip_layer.c log.c readconf.c rtpproxy.c \
rtpproxy_relay.c accessctl.c route_processing.c \
security.c auth.c fwapi.c resolve.c
rtpproxy_relay.c accessctl.c route_processing.c \
security.c auth.c fwapi.c resolve.c \
plugin_shortdial.c
#
# an example for a custom firewall control module
@@ -40,7 +41,7 @@ libcustom_fw_module_a_SOURCES = custom_fw_module.c
noinst_HEADERS = log.h rewrite_rules.h siproxd.h digcalc.h rtpproxy.h \
fwapi.h
fwapi.h plugins.h
EXTRA_DIST = .buildno

View File

@@ -34,6 +34,7 @@
#define DBCLASS_RTP 0x00000200 /* RTP proxy */
#define DBCLASS_ACCESS 0x00000400 /* Access list evaluation */
#define DBCLASS_AUTH 0x00000800 /* Authentication */
#define DBCLASS_PLUGIN 0x00001000 /* Plugins */
#define DBCLASS_ALL 0xffffffff /* All classes */

134
src/plugin_shortdial.c Normal file
View File

@@ -0,0 +1,134 @@
/* -*- Mode: C; c-basic-offset: 3 -*-
Copyright (C) 2002-2005 Thomas Ries <tries@gmx.net>
This file is part of Siproxd.
Siproxd 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.
Siproxd 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 Siproxd; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <stdio.h>
//#include <errno.h>
#include <string.h>
//#include <stdlib.h>
//#include <unistd.h>
//#include <signal.h>
#include <netinet/in.h>
//#include <arpa/inet.h>
#include <osipparser2/osip_parser.h>
#include "siproxd.h"
//#include "plugins.h"
#include "log.h"
static char const ident[]="$Id$";
/* configuration storage */
extern struct siproxd_config configuration;
/* local prototypes */
static int plugin_shortdial_process(sip_ticket_t *ticket);
/* code (entry point) */
int plugin_shortdial(sip_ticket_t *ticket) {
DEBUGC(DBCLASS_PLUGIN,"plugin entered");
/* only deal with outoing calls (outgoing INVITE requests) */
sip_find_direction(ticket, NULL);
if ((ticket->direction == DIR_OUTGOING) ||
(MSG_IS_INVITE(ticket->sipmsg))) {
/* To header with username must exist, max of 2 characters */
if (ticket && ticket->sipmsg && ticket->sipmsg &&
ticket->sipmsg->to && ticket->sipmsg->to->url &&
ticket->sipmsg->to->url->username &&
(strlen(ticket->sipmsg->to->url->username) >= 2) &&
configuration.pi_shortdial_akey) {
char digit1=ticket->sipmsg->to->url->username[0];
/* check for "activation key" - 1st character in number dialled */
if (digit1 == configuration.pi_shortdial_akey[0]) {
DEBUGC(DBCLASS_PLUGIN,"processing");
plugin_shortdial_process(ticket);
}
}
}
DEBUGC(DBCLASS_PLUGIN,"plugin left");
return STS_SUCCESS;
}
/* private code */
static int plugin_shortdial_process(sip_ticket_t *ticket) {
osip_uri_t *to_url=ticket->sipmsg->to->url;
osip_uri_t *req_url;
char *to_user=to_url->username;
char *new_to_user=NULL;
int shortcut_no=0;
int i, len;
DEBUGC(DBCLASS_PLUGIN,"process: username=[%s]", to_user);
req_url=osip_message_get_uri(ticket->sipmsg);
/* escaped akey? (if it appears twice: e.g. "**1234" -> "*1234") */
if (to_user[1] == configuration.pi_shortdial_akey[0]) {
/* shift left the whole string for 1 position (incl \0 termination)*/
for (i=0; i<strlen(to_user); i++) {
to_user[i]=to_user[i+1];
}
return STS_SUCCESS;
}
/* extract number */
shortcut_no = atoi(&(to_user[1]));
if (shortcut_no <= 0) return STS_SUCCESS; /* not a number */
/* requested number is not defined */
if (shortcut_no > configuration.pi_shortdial_entry.used) {
INFO ("shortdial: requested shortcut %i > available shortcuts",
shortcut_no, configuration.pi_shortdial_entry.used);
return STS_SUCCESS;
}
/* actual replacement INVITE and To header */
new_to_user=configuration.pi_shortdial_entry.string[shortcut_no-1];
if (new_to_user) {
DEBUGC(DBCLASS_PLUGIN,"process: rewriting [%s]->[%s]",
to_user, new_to_user);
len=strlen(new_to_user)+1; /* include trailing "\0" */
/* Request URI */
if (req_url && req_url->username) {
osip_free(req_url->username);
req_url->username=osip_malloc(len);
strncpy(req_url->username, new_to_user, len);
}
/* To header */
to_user=NULL;
osip_free(to_url->username);
to_url->username=osip_malloc(len);
strncpy(to_url->username, new_to_user, len);
}
/* done */
return STS_SUCCESS;
}

26
src/plugins.h Normal file
View File

@@ -0,0 +1,26 @@
/*
Copyright (C) 2002-2005 Thomas Ries <tries@gmx.net>
This file is part of Siproxd.
Siproxd 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.
Siproxd 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 Siproxd; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Id$ */
/* Plugins must return STS_SUCCESS / SUCCESS_FAILURE */
/* short Dial plugin */
int plugin_shortdial(sip_ticket_t *ticket);

View File

@@ -177,6 +177,9 @@ static int parse_config (FILE *configfile) {
{ "pid_file", TYP_STRING, &configuration.pid_file },
{ "default_expires", TYP_INT4, &configuration.default_expires },
{ "autosave_registrations",TYP_INT4, &configuration.autosave_registrations },
{ "pi_shortdial_enable", TYP_INT4, &configuration.pi_shortdial },
{ "pi_shortdial_akey", TYP_STRING, &configuration.pi_shortdial_akey },
{ "pi_shortdial_entry", TYP_STRINGA,&configuration.pi_shortdial_entry },
{0, 0, 0}
};

View File

@@ -36,6 +36,7 @@
#include <osipparser2/osip_parser.h>
#include "siproxd.h"
#include "plugins.h"
#include "log.h"
static char const ident[]="$Id$";
@@ -424,8 +425,8 @@ int main (int argc, char *argv[])
* Before we do so, we apply some
* additional preprocessing
*********************************/
/*&&& coming soon: short dial strings*/
/* Dial shortcuts */
if (configuration.pi_shortdial) plugin_shortdial(&ticket);
/*********************************

View File

@@ -89,6 +89,9 @@ struct siproxd_config {
char *pid_file;
int default_expires;
int autosave_registrations;
int pi_shortdial;
char *pi_shortdial_akey;
stringa_t pi_shortdial_entry;
};
/*