Wed Oct 28 13:31:30 2009

Asterisk developer's documentation


app_osplookup.c File Reference

Open Settlement Protocol (OSP) Applications. More...

#include "asterisk.h"
#include <osp/osp.h>
#include <osp/osputils.h>
#include <osp/ospb64.h>
#include "asterisk/paths.h"
#include "asterisk/lock.h"
#include "asterisk/config.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/channel.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/cli.h"
#include "asterisk/astosp.h"

Include dependency graph for app_osplookup.c:

Go to the source code of this file.

Data Structures

struct  osp_callid
struct  osp_provider
struct  osp_result

Defines

#define OSP_AUDIT_URL   ((const char*)"localhost")
#define OSP_CALLID_H323   ((unsigned int)(1 << 0))
#define OSP_CALLID_IAX   ((unsigned int)(1 << 2))
#define OSP_CALLID_MAXNUM   ((unsigned int)3)
#define OSP_CALLID_SIP   ((unsigned int)(1 << 1))
#define OSP_CALLID_UNDEFINED   ((unsigned int)0)
#define OSP_CONFIG_FILE   ((const char*)"osp.conf")
#define OSP_CUSTOMER_ID   ((const char*)"")
#define OSP_DEF_AUTHPOLICY   ((enum osp_authpolicy)OSP_AUTH_YES)
#define OSP_DEF_DESTINATIONS   ((unsigned int)5)
#define OSP_DEF_MAXCONNECTIONS   ((unsigned int)20)
#define OSP_DEF_PROTOCOL   OSP_PROT_SIP
#define OSP_DEF_PROVIDER   ((const char*)"default")
#define OSP_DEF_RETRYDELAY   ((unsigned int)0)
#define OSP_DEF_RETRYLIMIT   ((unsigned int)2)
#define OSP_DEF_TIMELIMIT   ((unsigned int)0)
#define OSP_DEF_TIMEOUT   ((unsigned int)500)
#define OSP_DEVICE_ID   ((const char*)"")
#define OSP_GENERAL_CAT   ((const char*)"general")
#define OSP_HTTP_PERSISTENCE   ((int)1)
#define OSP_INTSTR_SIZE   ((unsigned int)16)
#define OSP_INVALID_HANDLE   ((int)-1)
#define OSP_KEYSTR_SIZE   ((unsigned int)1024)
#define OSP_LOCAL_VALIDATION   ((int)1)
#define OSP_MAX_CERTS   ((unsigned int)10)
#define OSP_MAX_MAXCONNECTIONS   ((unsigned int)1000)
#define OSP_MAX_RETRYDELAY   ((unsigned int)10)
#define OSP_MAX_RETRYLIMIT   ((unsigned int)100)
#define OSP_MAX_SRVS   ((unsigned int)10)
#define OSP_MAX_TIMEOUT   ((unsigned int)10000)
#define OSP_MIN_MAXCONNECTIONS   ((unsigned int)1)
#define OSP_MIN_RETRYDELAY   ((unsigned int)0)
#define OSP_MIN_RETRYLIMIT   ((unsigned int)0)
#define OSP_MIN_TIMEOUT   ((unsigned int)200)
#define OSP_NORSTR_SIZE   ((unsigned int)256)
#define OSP_PROT_H323   ((char*)"H323")
#define OSP_PROT_IAX   ((char*)"IAX")
#define OSP_PROT_OTHER   ((char*)"OTHER")
#define OSP_PROT_SIP   ((char*)"SIP")
#define OSP_SIP_HEADER   ((char*)"P-OSP-Auth-Token: ")
#define OSP_SSL_LIFETIME   ((unsigned int)300)
#define OSP_TECH_H323   ((char*)"H323")
#define OSP_TECH_IAX   ((char*)"IAX2")
#define OSP_TECH_SIP   ((char*)"SIP")
#define OSP_TECHSTR_SIZE   ((unsigned int)32)
#define OSP_TOKSTR_SIZE   ((unsigned int)4096)
#define OSP_UUID_SIZE   ((unsigned int)16)
#define OSP_UUIDSTR_SIZE   ((unsigned int)36)

Enumerations

enum  osp_authpolicy { OSP_AUTH_NO, OSP_AUTH_YES, OSP_AUTH_EXCLUSIVE }

Functions

static void __reg_module (void)
static void __unreg_module (void)
static OSPEFAILREASON asterisk2osp (int cause)
 Convert Asterisk status to TC code.
static char * handle_cli_osp_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int load_module (void)
static int osp_auth (const char *provider, int *transaction, const char *source, const char *calling, const char *called, const char *token, unsigned int *timelimit)
 OSP Authentication function.
static int osp_check_destination (struct osp_provider *provider, const char *called, const char *calling, char *destination, unsigned int tokenlen, const char *token, OSPEFAILREASON *reason, struct osp_result *result)
 Choose min duration limit.
static unsigned int osp_choose_timelimit (unsigned int in, unsigned int out)
 Choose min duration limit.
static void osp_convert_address (const char *src, char *dst, int buffersize)
 Convert address to "[x.x.x.x]" or "host.domain" format.
static int osp_create_callid (unsigned int type, struct osp_callid *callid)
 Create a call ID according to the type.
static int osp_create_provider (struct ast_config *cfg, const char *provider)
 Create OSP provider handle according to configuration.
static int osp_create_transaction (const char *provider, int *transaction, unsigned int sourcesize, char *source)
 Create OSP transaction handle.
static int osp_create_uuid (unsigned char *uuid, unsigned int *buffersize)
 Create a UUID.
static int osp_finish (int handle, int recorded, int cause, time_t start, time_t connect, time_t end, unsigned int release)
 OSP Finish function.
static int osp_get_provider (const char *name, struct osp_provider **provider)
 Get OSP provider by name.
static int osp_load (int reload)
static int osp_lookup (const char *provider, const char *srcdev, const char *calling, const char *called, const char *snetid, const char *rnumber, unsigned int callidtypes, struct osp_result *result)
 OSP Lookup function.
static int osp_next (const char *provider, int cause, struct osp_result *result)
 OSP Lookup Next function.
static int osp_unload (void)
static int osp_uuid2str (unsigned char *uuid, char *buffer, unsigned int buffersize)
 UUID to string.
static int osp_validate_token (int transaction, const char *source, const char *destination, const char *calling, const char *called, const char *token, unsigned int *timelimit)
 Validate OSP token of inbound call.
static int ospauth_exec (struct ast_channel *chan, const char *data)
 OSP Application OSPAuth.
static int ospfinished_exec (struct ast_channel *chan, const char *data)
 OSP Application OSPFinish.
static int osplookup_exec (struct ast_channel *chan, const char *data)
 OSP Application OSPLookup.
static int ospnext_exec (struct ast_channel *chan, const char *data)
 OSP Application OSPNext.
static int reload (void)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Open Settlement Protocol Applications" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, }
static const char app1 [] = "OSPAuth"
static const char app2 [] = "OSPLookup"
static const char app3 [] = "OSPNext"
static const char app4 [] = "OSPFinish"
static struct ast_module_infoast_module_info = &__mod_info
const char * B64CACert = "MIIBYDCCAQoCAQEwDQYJKoZIhvcNAQEEBQAwOzElMCMGA1UEAxMcb3NwdGVzdHNlcnZlci50cmFuc25leHVzLmNvbTESMBAGA1UEChMJT1NQU2VydmVyMB4XDTAyMDIwNDE4MjU1MloXDTEyMDIwMzE4MjU1MlowOzElMCMGA1UEAxMcb3NwdGVzdHNlcnZlci50cmFuc25leHVzLmNvbTESMBAGA1UEChMJT1NQU2VydmVyMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAPGeGwV41EIhX0jEDFLRXQhDEr50OUQPq+f55VwQd0TQNts06BP29+UiNdRW3c3IRHdZcJdC1Cg68ME9cgeq0h8CAwEAATANBgkqhkiG9w0BAQQFAANBAGkzBSj1EnnmUxbaiG1N4xjIuLAWydun7o3bFk2tV8dBIhnuh445obYyk1EnQ27kI7eACCILBZqi2MHDOIMnoN0="
const char * B64LCert = "MIIBeTCCASMCEHqkOHVRRWr+1COq3CR/xsowDQYJKoZIhvcNAQEEBQAwOzElMCMGA1UEAxMcb3NwdGVzdHNlcnZlci50cmFuc25leHVzLmNvbTESMBAGA1UEChMJT1NQU2VydmVyMB4XDTA1MDYyMzAwMjkxOFoXDTA2MDYyNDAwMjkxOFowRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQCvLeZfj1G0wuJb8JTcVeZaZftncEmRluOnaME3ustd918lRMDYokZmtmDZN8SrP0yd1pfVqZ7NkmBACbBX0k7pAgMBAAEwDQYJKoZIhvcNAQEEBQADQQDnV8QNFVVJx/+7IselU0wsepqMurivXZzuxOmTEmTVDzCJx1xhA8jd3vGAj7XDIYiPub1PV23eY5a2ARJuw5w9"
const char * B64PKey = "MIIBOgIBAAJBAK8t5l+PUbTC4lvwlNxV5lpl+2dwSZGW46dowTe6y133XyVEwNiiRma2YNk3xKs/TJ3Wl9Wpns2SYEAJsFfSTukCAwEAAQJAPz13vCm2GmZ8Zyp74usTxLCqSJZNyMRLHQWBM0g44Iuy4wE3vpi7Wq+xYuSOH2mu4OddnxswCP4QhaXVQavTAQIhAOBVCKXtppEw9UaOBL4vW0Ed/6EA/1D8hDW6St0h7EXJAiEAx+iRmZKhJD6VT84dtX5ZYNVk3j3dAcIOovpzUj9a0CECIEduTCapmZQ5xqAEsLXuVlxRtQgLTUD4ZxDElPn8x0MhAiBE2HlcND0+qDbvtwJQQOUzDgqg5xk3w8capboVdzAlQQIhAMC+lDL7+gDYkNAft5Mu+NObJmQs4Cr+DkDFsKqoxqrm"
static struct ast_cli_entry cli_osp []
static int osp_hardware = 0
static int osp_initialized = 0
static int osp_security = 0
static unsigned int osp_tokenformat = TOKEN_ALGO_SIGNED
static ast_mutex_t osplock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER )
static struct osp_providerospproviders = NULL


Detailed Description

Open Settlement Protocol (OSP) Applications.

Author:
Mark Spencer <markster@digium.com>
ExtRef:
The OSP Toolkit: http://www.transnexus.com
ExtRef:
OpenSSL http://www.openssl.org

Definition in file app_osplookup.c.


Define Documentation

#define OSP_AUDIT_URL   ((const char*)"localhost")

Definition at line 268 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_CALLID_H323   ((unsigned int)(1 << 0))

Definition at line 226 of file app_osplookup.c.

Referenced by osp_create_callid(), osplookup_exec(), and ospnext_exec().

#define OSP_CALLID_IAX   ((unsigned int)(1 << 2))

Definition at line 228 of file app_osplookup.c.

Referenced by osp_create_callid(), and osplookup_exec().

#define OSP_CALLID_MAXNUM   ((unsigned int)3)

Definition at line 229 of file app_osplookup.c.

Referenced by osp_lookup().

#define OSP_CALLID_SIP   ((unsigned int)(1 << 1))

Definition at line 227 of file app_osplookup.c.

Referenced by osp_create_callid(), and osplookup_exec().

#define OSP_CALLID_UNDEFINED   ((unsigned int)0)

Definition at line 225 of file app_osplookup.c.

Referenced by osplookup_exec(), and ospnext_exec().

#define OSP_CONFIG_FILE   ((const char*)"osp.conf")

Definition at line 250 of file app_osplookup.c.

Referenced by osp_load().

#define OSP_CUSTOMER_ID   ((const char*)"")

Definition at line 272 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_AUTHPOLICY   ((enum osp_authpolicy)OSP_AUTH_YES)

Definition at line 267 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_DESTINATIONS   ((unsigned int)5)

Definition at line 274 of file app_osplookup.c.

Referenced by osp_lookup().

#define OSP_DEF_MAXCONNECTIONS   ((unsigned int)20)

Definition at line 255 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_PROTOCOL   OSP_PROT_SIP

Definition at line 276 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_PROVIDER   ((const char*)"default")

Definition at line 252 of file app_osplookup.c.

Referenced by ospauth_exec(), osplookup_exec(), and ospnext_exec().

#define OSP_DEF_RETRYDELAY   ((unsigned int)0)

Definition at line 258 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_RETRYLIMIT   ((unsigned int)2)

Definition at line 261 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_TIMELIMIT   ((unsigned int)0)

#define OSP_DEF_TIMEOUT   ((unsigned int)500)

Definition at line 264 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEVICE_ID   ((const char*)"")

Definition at line 273 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_GENERAL_CAT   ((const char*)"general")

Definition at line 251 of file app_osplookup.c.

Referenced by osp_load().

#define OSP_HTTP_PERSISTENCE   ((int)1)

Definition at line 271 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_INTSTR_SIZE   ((unsigned int)16)

Definition at line 209 of file app_osplookup.c.

Referenced by ospauth_exec(), and ospfinished_exec().

#define OSP_INVALID_HANDLE   ((int)-1)

#define OSP_KEYSTR_SIZE   ((unsigned int)1024)

Definition at line 211 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_LOCAL_VALIDATION   ((int)1)

Definition at line 269 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_CERTS   ((unsigned int)10)

Definition at line 253 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_MAXCONNECTIONS   ((unsigned int)1000)

Definition at line 257 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_RETRYDELAY   ((unsigned int)10)

Definition at line 260 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_RETRYLIMIT   ((unsigned int)100)

Definition at line 263 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_SRVS   ((unsigned int)10)

Definition at line 254 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_TIMEOUT   ((unsigned int)10000)

Definition at line 266 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MIN_MAXCONNECTIONS   ((unsigned int)1)

Definition at line 256 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MIN_RETRYDELAY   ((unsigned int)0)

Definition at line 259 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MIN_RETRYLIMIT   ((unsigned int)0)

Definition at line 262 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MIN_TIMEOUT   ((unsigned int)200)

Definition at line 265 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_NORSTR_SIZE   ((unsigned int)256)

Definition at line 210 of file app_osplookup.c.

Referenced by osp_auth(), osp_lookup(), osp_next(), and osp_validate_token().

#define OSP_PROT_H323   ((char*)"H323")

Definition at line 232 of file app_osplookup.c.

Referenced by osp_check_destination(), and osp_create_provider().

#define OSP_PROT_IAX   ((char*)"IAX")

Definition at line 234 of file app_osplookup.c.

Referenced by osp_check_destination(), and osp_create_provider().

#define OSP_PROT_OTHER   ((char*)"OTHER")

Definition at line 235 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_PROT_SIP   ((char*)"SIP")

Definition at line 233 of file app_osplookup.c.

Referenced by osp_check_destination(), and osp_create_provider().

#define OSP_SIP_HEADER   ((char*)"P-OSP-Auth-Token: ")

Definition at line 246 of file app_osplookup.c.

Referenced by osplookup_exec(), and ospnext_exec().

#define OSP_SSL_LIFETIME   ((unsigned int)300)

Definition at line 270 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_TECH_H323   ((char*)"H323")

Definition at line 241 of file app_osplookup.c.

Referenced by osp_check_destination(), osplookup_exec(), and ospnext_exec().

#define OSP_TECH_IAX   ((char*)"IAX2")

Definition at line 243 of file app_osplookup.c.

Referenced by osp_check_destination(), osplookup_exec(), and ospnext_exec().

#define OSP_TECH_SIP   ((char*)"SIP")

Definition at line 242 of file app_osplookup.c.

Referenced by osp_check_destination(), osplookup_exec(), and ospnext_exec().

#define OSP_TECHSTR_SIZE   ((unsigned int)32)

Definition at line 213 of file app_osplookup.c.

#define OSP_TOKSTR_SIZE   ((unsigned int)4096)

#define OSP_UUID_SIZE   ((unsigned int)16)

Definition at line 214 of file app_osplookup.c.

Referenced by osp_create_uuid().

#define OSP_UUIDSTR_SIZE   ((unsigned int)36)

Definition at line 215 of file app_osplookup.c.

Referenced by osp_uuid2str().


Enumeration Type Documentation

Enumerator:
OSP_AUTH_NO 
OSP_AUTH_YES 
OSP_AUTH_EXCLUSIVE 

Definition at line 218 of file app_osplookup.c.

00218                     {
00219    OSP_AUTH_NO,      /* Accept any call */
00220    OSP_AUTH_YES,     /* Accept call with valid OSP token or without OSP token */
00221    OSP_AUTH_EXCLUSIVE   /* Only accept call with valid OSP token */
00222 };


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 2215 of file app_osplookup.c.

static void __unreg_module ( void   )  [static]

Definition at line 2215 of file app_osplookup.c.

static OSPEFAILREASON asterisk2osp ( int  cause  )  [static]

Convert Asterisk status to TC code.

Parameters:
cause Asterisk hangup cause
Returns:
OSP TC code

Definition at line 873 of file app_osplookup.c.

Referenced by osp_finish(), and osp_next().

00875 {
00876    return (OSPEFAILREASON)cause;
00877 }

static char* handle_cli_osp_show ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 2073 of file app_osplookup.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), osp_provider::authpolicy, osp_provider::cacerts, osp_provider::cacount, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, osp_provider::defaultprotocol, ast_cli_args::fd, osp_provider::handle, osp_provider::localcert, osp_provider::maxconnections, osp_provider::name, osp_provider::next, osplock, osp_provider::privatekey, osp_provider::retrydelay, osp_provider::retrylimit, osp_provider::source, osp_provider::spcount, osp_provider::srvpoints, osp_provider::timeout, and ast_cli_entry::usage.

02074 {
02075    int i;
02076    int found = 0;
02077    struct osp_provider* p;
02078    const char* provider = NULL;
02079    const char* tokenalgo;
02080 
02081    switch (cmd) {
02082    case CLI_INIT:
02083       e->command = "osp show";
02084       e->usage =
02085          "Usage: osp show\n"
02086          "       Displays information on Open Settlement Protocol support\n";
02087       return NULL;
02088    case CLI_GENERATE:
02089       return NULL;
02090    }
02091 
02092    if ((a->argc < 2) || (a->argc > 3))
02093       return CLI_SHOWUSAGE;
02094    if (a->argc > 2) 
02095       provider = a->argv[2];
02096    if (!provider) {
02097       switch (osp_tokenformat) {
02098       case TOKEN_ALGO_BOTH:
02099          tokenalgo = "Both";
02100          break;
02101       case TOKEN_ALGO_UNSIGNED:
02102          tokenalgo = "Unsigned";
02103          break;
02104       case TOKEN_ALGO_SIGNED:
02105       default:
02106          tokenalgo = "Signed";
02107          break;
02108       }
02109       ast_cli(a->fd, "OSP: %s/%s/%s/%s\n",
02110          osp_initialized ? "Initialized" : "Uninitialized", 
02111          osp_hardware ? "Accelerated" : "Normal", 
02112          osp_security ? "Enabled" : "Disabled", 
02113          tokenalgo);
02114    }
02115 
02116    ast_mutex_lock(&osplock);
02117    p = ospproviders;
02118    while(p) {
02119       if (!provider || !strcasecmp(p->name, provider)) {
02120          if (found) {
02121             ast_cli(a->fd, "\n");
02122          }
02123          ast_cli(a->fd, " == OSP Provider '%s' == \n", p->name);
02124          if (osp_security) {
02125             ast_cli(a->fd, "Local Private Key: %s\n", p->privatekey);
02126             ast_cli(a->fd, "Local Certificate: %s\n", p->localcert);
02127             for (i = 0; i < p->cacount; i++) {
02128                ast_cli(a->fd, "CA Certificate %d:  %s\n", i + 1, p->cacerts[i]);
02129             }
02130          }
02131          for (i = 0; i < p->spcount; i++) {
02132             ast_cli(a->fd, "Service Point %d:   %s\n", i + 1, p->srvpoints[i]);
02133          }
02134          ast_cli(a->fd, "Max Connections:   %d\n", p->maxconnections);
02135          ast_cli(a->fd, "Retry Delay:       %d seconds\n", p->retrydelay);
02136          ast_cli(a->fd, "Retry Limit:       %d\n", p->retrylimit);
02137          ast_cli(a->fd, "Timeout:           %d milliseconds\n", p->timeout);
02138          ast_cli(a->fd, "Source:            %s\n", strlen(p->source) ? p->source : "<unspecified>");
02139          ast_cli(a->fd, "Auth Policy        %d\n", p->authpolicy);
02140          ast_cli(a->fd, "Default protocol   %s\n", p->defaultprotocol);
02141          ast_cli(a->fd, "OSP Handle:        %d\n", p->handle);
02142          found++;
02143       }
02144       p = p->next;
02145    }
02146    ast_mutex_unlock(&osplock);
02147 
02148    if (!found) {
02149       if (provider) {
02150          ast_cli(a->fd, "Unable to find OSP provider '%s'\n", provider);
02151       } else {
02152          ast_cli(a->fd, "No OSP providers configured\n");
02153       }
02154    }
02155    return CLI_SUCCESS;
02156 }

static int load_module ( void   )  [static]

static int osp_auth ( const char *  provider,
int *  transaction,
const char *  source,
const char *  calling,
const char *  called,
const char *  token,
unsigned int *  timelimit 
) [static]

OSP Authentication function.

Parameters:
provider OSP provider context name
transaction OSP transaction handle, output
source Source of inbound call
calling Calling number
called Called number
token OSP token, may be empty
timelimit Call duration limit, output
Returns:
1 Authenricated, 0 Unauthenticated, -1 Error

Definition at line 890 of file app_osplookup.c.

References ast_debug, ast_strlen_zero(), osp_provider::authpolicy, OSP_AUTH_EXCLUSIVE, OSP_AUTH_NO, OSP_AUTH_YES, osp_create_transaction(), OSP_DEF_TIMELIMIT, osp_get_provider(), OSP_INVALID_HANDLE, OSP_NORSTR_SIZE, and osp_validate_token().

Referenced by ospauth_exec().

00898 {
00899    int res;
00900    struct osp_provider* p = NULL;
00901    char dest[OSP_NORSTR_SIZE];
00902 
00903    *transaction = OSP_INVALID_HANDLE;
00904    *timelimit = OSP_DEF_TIMELIMIT;
00905 
00906    if ((res = osp_get_provider(provider, &p)) <= 0) {
00907       ast_debug(1, "OSP: Unabe to find OSP provider '%s'\n", provider);
00908       return res;
00909    }
00910 
00911    switch (p->authpolicy) {
00912    case OSP_AUTH_NO:
00913       res = 1;
00914       break;
00915    case OSP_AUTH_EXCLUSIVE:
00916       if (ast_strlen_zero(token)) {
00917          res = 0;
00918       } else if ((res = osp_create_transaction(provider, transaction, sizeof(dest), dest)) <= 0) {
00919          ast_debug(1, "OSP: Unable to generate transaction handle\n");
00920          *transaction = OSP_INVALID_HANDLE;
00921          res = 0;
00922       } else if((res = osp_validate_token(*transaction, source, dest, calling, called, token, timelimit)) <= 0) {
00923          OSPPTransactionRecordFailure(*transaction, OSPC_FAIL_CALL_REJECTED);
00924       }
00925       break;
00926    case OSP_AUTH_YES:
00927    default:
00928       if (ast_strlen_zero(token)) {
00929          res = 1;
00930       } else if ((res = osp_create_transaction(provider, transaction, sizeof(dest), dest)) <= 0) {
00931          ast_debug(1, "OSP: Unable to generate transaction handle\n");
00932          *transaction = OSP_INVALID_HANDLE;
00933          res = 0;
00934       } else if((res = osp_validate_token(*transaction, source, dest, calling, called, token, timelimit)) <= 0) {
00935          OSPPTransactionRecordFailure(*transaction, OSPC_FAIL_CALL_REJECTED);
00936       }
00937       break;
00938    }
00939 
00940    return res;
00941 }

static int osp_check_destination ( struct osp_provider provider,
const char *  called,
const char *  calling,
char *  destination,
unsigned int  tokenlen,
const char *  token,
OSPEFAILREASON *  reason,
struct osp_result result 
) [static]

Choose min duration limit.

Parameters:
provider OSP provider
called Called number
calling Calling number
destination Destination IP in '[x.x.x.x]' format
tokenlen OSP token length
token OSP token
reason Failure reason, output
result OSP lookup results, in/output
Returns:
1 Success, 0 Failed, -1 Error

Definition at line 774 of file app_osplookup.c.

References ast_base64encode(), ast_copy_string(), ast_debug, ast_log(), osp_result::called, osp_result::calling, osp_provider::defaultprotocol, osp_result::dest, enabled, LOG_WARNING, osp_result::networkid, OSP_PROT_H323, OSP_PROT_IAX, OSP_PROT_SIP, OSP_TECH_H323, OSP_TECH_IAX, OSP_TECH_SIP, osp_result::outhandle, osp_result::tech, and osp_result::token.

Referenced by osp_lookup(), and osp_next().

00783 {
00784    int res;
00785    OSPE_DEST_OSPENABLED enabled;
00786    OSPE_DEST_PROTOCOL protocol;
00787    int error;
00788 
00789    if (strlen(destination) <= 2) {
00790       ast_debug(1, "OSP: Wrong destination format '%s'\n", destination);
00791       *reason = OSPC_FAIL_NORMAL_UNSPECIFIED;
00792       return -1;
00793    }
00794 
00795    if ((error = OSPPTransactionIsDestOSPEnabled(result->outhandle, &enabled)) != OSPC_ERR_NO_ERROR) {
00796       ast_debug(1, "OSP: Unable to get destination OSP version, error '%d'\n", error);
00797       *reason = OSPC_FAIL_NORMAL_UNSPECIFIED;
00798       return -1;
00799    }
00800 
00801    if (enabled == OSPC_DOSP_FALSE) {
00802       result->token[0] = '\0';
00803    } else {
00804       ast_base64encode(result->token, (const unsigned char*)token, tokenlen, sizeof(result->token) - 1);
00805    }
00806 
00807    if ((error = OSPPTransactionGetDestNetworkId(result->outhandle, result->networkid)) != OSPC_ERR_NO_ERROR) {
00808       ast_debug(1, "OSP: Unable to get destination network ID, error '%d'\n", error);
00809       result->networkid[0] = '\0';
00810    }
00811 
00812    if ((error = OSPPTransactionGetDestProtocol(result->outhandle, &protocol)) != OSPC_ERR_NO_ERROR) {
00813       ast_debug(1, "OSP: Unable to get destination protocol, error '%d'\n", error);
00814       *reason = OSPC_FAIL_NORMAL_UNSPECIFIED;
00815       result->token[0] = '\0';
00816       result->networkid[0] = '\0';
00817       return -1;
00818    }
00819 
00820    res = 1;
00821    /* Strip leading and trailing brackets */
00822    destination[strlen(destination) - 1] = '\0';
00823    switch(protocol) {
00824    case OSPC_DPROT_Q931:
00825       ast_debug(1, "OSP: protocol '%s'\n", OSP_PROT_H323);
00826       ast_copy_string(result->tech, OSP_TECH_H323, sizeof(result->tech));
00827       ast_copy_string(result->dest, destination + 1, sizeof(result->dest));
00828       ast_copy_string(result->called, called, sizeof(result->called));
00829       ast_copy_string(result->calling, calling, sizeof(result->calling));
00830       break;
00831    case OSPC_DPROT_SIP:
00832       ast_debug(1, "OSP: protocol '%s'\n", OSP_PROT_SIP);
00833       ast_copy_string(result->tech, OSP_TECH_SIP, sizeof(result->tech));
00834       ast_copy_string(result->dest, destination + 1, sizeof(result->dest));
00835       ast_copy_string(result->called, called, sizeof(result->called));
00836       ast_copy_string(result->calling, calling, sizeof(result->calling));
00837       break;
00838    case OSPC_DPROT_IAX:
00839       ast_debug(1, "OSP: protocol '%s'\n", OSP_PROT_IAX);
00840       ast_copy_string(result->tech, OSP_TECH_IAX, sizeof(result->tech));
00841       ast_copy_string(result->dest, destination + 1, sizeof(result->dest));
00842       ast_copy_string(result->called, called, sizeof(result->called));
00843       ast_copy_string(result->calling, calling, sizeof(result->calling));
00844       break;
00845    case OSPC_DPROT_UNDEFINED:
00846    case OSPC_DPROT_UNKNOWN:
00847       ast_debug(1, "OSP: unknown/undefined protocol '%d'\n", protocol);
00848       ast_debug(1, "OSP: use default protocol '%s'\n", provider->defaultprotocol);
00849 
00850       ast_copy_string(result->tech, provider->defaultprotocol, sizeof(result->tech));
00851       ast_copy_string(result->dest, destination + 1, sizeof(result->dest));
00852       ast_copy_string(result->called, called, sizeof(result->called));
00853       ast_copy_string(result->calling, calling, sizeof(result->calling));
00854       break;
00855    case OSPC_DPROT_LRQ:
00856    default:
00857       ast_log(LOG_WARNING, "OSP: unsupported protocol '%d'\n", protocol);
00858       *reason = OSPC_FAIL_PROTOCOL_ERROR;
00859       result->token[0] = '\0';
00860       result->networkid[0] = '\0';
00861       res = 0;
00862       break;
00863    }
00864 
00865    return res;
00866 }

static unsigned int osp_choose_timelimit ( unsigned int  in,
unsigned int  out 
) [static]

Choose min duration limit.

Parameters:
in Inbound duration limit
out Outbound duration limit
Returns:
min duration limit

Definition at line 749 of file app_osplookup.c.

References OSP_DEF_TIMELIMIT.

Referenced by osp_lookup(), and osp_next().

00752 {
00753    if (in == OSP_DEF_TIMELIMIT) {
00754       return out;
00755    } else if (out == OSP_DEF_TIMELIMIT) {
00756       return in;
00757    } else {
00758       return in < out ? in : out;
00759    }
00760 }

static void osp_convert_address ( const char *  src,
char *  dst,
int  buffersize 
) [static]

Convert address to "[x.x.x.x]" or "host.domain" format.

Parameters:
src Source address string
dst Destination address string
buffersize Size of dst buffer

Definition at line 664 of file app_osplookup.c.

References inet_aton().

Referenced by osp_lookup(), and osp_validate_token().

00668 {
00669    struct in_addr inp;
00670 
00671    if (inet_aton(src, &inp) != 0) {
00672       snprintf(dst, buffersize, "[%s]", src);
00673    } else {
00674       snprintf(dst, buffersize, "%s", src);
00675    }
00676 }

static int osp_create_callid ( unsigned int  type,
struct osp_callid callid 
) [static]

Create a call ID according to the type.

Parameters:
type Call ID type
callid Call ID buffer
Returns:
1 Created, 0 Not create, -1 Error

Definition at line 1002 of file app_osplookup.c.

References osp_callid::buf, osp_callid::len, OSP_CALLID_H323, OSP_CALLID_IAX, OSP_CALLID_SIP, and osp_create_uuid().

Referenced by osp_lookup().

01005 {
01006    int res;
01007 
01008    callid->len = sizeof(callid->buf);
01009    switch (type) {
01010    case OSP_CALLID_H323:
01011       res = osp_create_uuid(callid->buf, &callid->len);
01012       break;
01013    case OSP_CALLID_SIP:
01014    case OSP_CALLID_IAX:
01015       res = 0;
01016    default:
01017       res = -1;
01018       break;
01019    }
01020 
01021    if ((res != 1) && (callid->len != 0)) {
01022       callid->buf[0] = '\0';
01023       callid->len = 0;
01024    }
01025 
01026    return res;
01027 }

static int osp_create_provider ( struct ast_config cfg,
const char *  provider 
) [static]

Create OSP provider handle according to configuration.

Parameters:
cfg OSP configuration
provider OSP provider context name
Returns:
1 Success, 0 Failed, -1 Error

Definition at line 341 of file app_osplookup.c.

References ast_calloc, ast_config_AST_KEY_DIR, ast_copy_string(), ast_debug, ast_free, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_variable_browse(), osp_provider::authpolicy, osp_provider::cacerts, osp_provider::cacount, osp_provider::defaultprotocol, osp_provider::handle, ast_variable::lineno, osp_provider::localcert, LOG_ERROR, LOG_WARNING, osp_provider::maxconnections, ast_variable::name, osp_provider::name, osp_provider::next, ast_variable::next, OSP_AUDIT_URL, OSP_AUTH_EXCLUSIVE, OSP_AUTH_NO, OSP_AUTH_YES, OSP_CUSTOMER_ID, OSP_DEF_AUTHPOLICY, OSP_DEF_MAXCONNECTIONS, OSP_DEF_PROTOCOL, OSP_DEF_RETRYDELAY, OSP_DEF_RETRYLIMIT, OSP_DEF_TIMEOUT, OSP_DEVICE_ID, OSP_HTTP_PERSISTENCE, OSP_INVALID_HANDLE, OSP_KEYSTR_SIZE, OSP_LOCAL_VALIDATION, OSP_MAX_CERTS, OSP_MAX_MAXCONNECTIONS, OSP_MAX_RETRYDELAY, OSP_MAX_RETRYLIMIT, OSP_MAX_SRVS, OSP_MAX_TIMEOUT, OSP_MIN_MAXCONNECTIONS, OSP_MIN_RETRYDELAY, OSP_MIN_RETRYLIMIT, OSP_MIN_TIMEOUT, OSP_PROT_H323, OSP_PROT_IAX, OSP_PROT_OTHER, OSP_PROT_SIP, OSP_SSL_LIFETIME, osplock, osp_provider::privatekey, osp_provider::retrydelay, osp_provider::retrylimit, osp_provider::source, osp_provider::spcount, osp_provider::srvpoints, osp_provider::timeout, and ast_variable::value.

Referenced by osp_load().

00344 {
00345    int res = 0;
00346    struct ast_variable* v;
00347    struct osp_provider* p;
00348    OSPTPRIVATEKEY privatekey;
00349    OSPT_CERT localcert;
00350    OSPT_CERT cacerts[OSP_MAX_CERTS];
00351    const OSPT_CERT* pcacerts[OSP_MAX_CERTS];
00352    const char* psrvpoints[OSP_MAX_SRVS];
00353    unsigned char privatekeydata[OSP_KEYSTR_SIZE];
00354    unsigned char localcertdata[OSP_KEYSTR_SIZE];
00355    unsigned char cacertdata[OSP_KEYSTR_SIZE];
00356    int i, t, error = OSPC_ERR_NO_ERROR;
00357 
00358    if (!(p = ast_calloc(1, sizeof(*p)))) {
00359       ast_log(LOG_ERROR, "Out of memory\n");
00360       return -1;
00361    }
00362 
00363    /* ast_calloc has set 0 in p */
00364    ast_copy_string(p->name, provider, sizeof(p->name));
00365    snprintf(p->privatekey, sizeof(p->privatekey), "%s/%s-privatekey.pem", ast_config_AST_KEY_DIR, provider);
00366    snprintf(p->localcert, sizeof(p->localcert), "%s/%s-localcert.pem", ast_config_AST_KEY_DIR, provider);
00367    snprintf(p->cacerts[0], sizeof(p->cacerts[0]), "%s/%s-cacert_0.pem", ast_config_AST_KEY_DIR, provider);
00368    p->maxconnections = OSP_DEF_MAXCONNECTIONS;
00369    p->retrydelay = OSP_DEF_RETRYDELAY;
00370    p->retrylimit = OSP_DEF_RETRYLIMIT;
00371    p->timeout = OSP_DEF_TIMEOUT;
00372    p->authpolicy = OSP_DEF_AUTHPOLICY;
00373    p->defaultprotocol = OSP_DEF_PROTOCOL;
00374    p->handle = OSP_INVALID_HANDLE;
00375 
00376    v = ast_variable_browse(cfg, provider);
00377    while(v) {
00378       if (!strcasecmp(v->name, "privatekey")) {
00379          if (osp_security) {
00380             if (v->value[0] == '/') {
00381                ast_copy_string(p->privatekey, v->value, sizeof(p->privatekey));
00382             } else {
00383                snprintf(p->privatekey, sizeof(p->privatekey), "%s/%s", ast_config_AST_KEY_DIR, v->value);
00384             }
00385             ast_debug(1, "OSP: privatekey '%s'\n", p->privatekey);
00386          }
00387       } else if (!strcasecmp(v->name, "localcert")) {
00388          if (osp_security) {
00389             if (v->value[0] == '/') {
00390                ast_copy_string(p->localcert, v->value, sizeof(p->localcert));
00391             } else {
00392                snprintf(p->localcert, sizeof(p->localcert), "%s/%s", ast_config_AST_KEY_DIR, v->value);
00393             }
00394             ast_debug(1, "OSP: localcert '%s'\n", p->localcert);
00395          }
00396       } else if (!strcasecmp(v->name, "cacert")) {
00397          if (osp_security) {
00398             if (p->cacount < OSP_MAX_CERTS) {
00399                if (v->value[0] == '/') {
00400                   ast_copy_string(p->cacerts[p->cacount], v->value, sizeof(p->cacerts[0]));
00401                } else {
00402                   snprintf(p->cacerts[p->cacount], sizeof(p->cacerts[0]), "%s/%s", ast_config_AST_KEY_DIR, v->value);
00403                }
00404                ast_debug(1, "OSP: cacerts[%d]: '%s'\n", p->cacount, p->cacerts[p->cacount]);
00405                p->cacount++;
00406             } else {
00407                ast_log(LOG_WARNING, "OSP: Too many CA Certificates at line %d\n", v->lineno);
00408             }
00409          }
00410       } else if (!strcasecmp(v->name, "servicepoint")) {
00411          if (p->spcount < OSP_MAX_SRVS) {
00412             ast_copy_string(p->srvpoints[p->spcount], v->value, sizeof(p->srvpoints[0]));
00413             ast_debug(1, "OSP: servicepoint[%d]: '%s'\n", p->spcount, p->srvpoints[p->spcount]);
00414             p->spcount++;
00415          } else {
00416             ast_log(LOG_WARNING, "OSP: Too many Service Points at line %d\n", v->lineno);
00417          }
00418       } else if (!strcasecmp(v->name, "maxconnections")) {
00419          if ((sscanf(v->value, "%30d", &t) == 1) && (t >= OSP_MIN_MAXCONNECTIONS) && (t <= OSP_MAX_MAXCONNECTIONS)) {
00420             p->maxconnections = t;
00421             ast_debug(1, "OSP: maxconnections '%d'\n", t);
00422          } else {
00423             ast_log(LOG_WARNING, "OSP: maxconnections should be an integer from %d to %d, not '%s' at line %d\n",
00424                OSP_MIN_MAXCONNECTIONS, OSP_MAX_MAXCONNECTIONS, v->value, v->lineno);
00425          }
00426       } else if (!strcasecmp(v->name, "retrydelay")) {
00427          if ((sscanf(v->value, "%30d", &t) == 1) && (t >= OSP_MIN_RETRYDELAY) && (t <= OSP_MAX_RETRYDELAY)) {
00428             p->retrydelay = t;
00429             ast_debug(1, "OSP: retrydelay '%d'\n", t);
00430          } else {
00431             ast_log(LOG_WARNING, "OSP: retrydelay should be an integer from %d to %d, not '%s' at line %d\n",
00432                OSP_MIN_RETRYDELAY, OSP_MAX_RETRYDELAY, v->value, v->lineno);
00433          }
00434       } else if (!strcasecmp(v->name, "retrylimit")) {
00435          if ((sscanf(v->value, "%30d", &t) == 1) && (t >= OSP_MIN_RETRYLIMIT) && (t <= OSP_MAX_RETRYLIMIT)) {
00436             p->retrylimit = t;
00437             ast_debug(1, "OSP: retrylimit '%d'\n", t);
00438          } else {
00439             ast_log(LOG_WARNING, "OSP: retrylimit should be an integer from %d to %d, not '%s' at line %d\n",
00440                OSP_MIN_RETRYLIMIT, OSP_MAX_RETRYLIMIT, v->value, v->lineno);
00441          }
00442       } else if (!strcasecmp(v->name, "timeout")) {
00443          if ((sscanf(v->value, "%30d", &t) == 1) && (t >= OSP_MIN_TIMEOUT) && (t <= OSP_MAX_TIMEOUT)) {
00444             p->timeout = t;
00445             ast_debug(1, "OSP: timeout '%d'\n", t);
00446          } else {
00447             ast_log(LOG_WARNING, "OSP: timeout should be an integer from %d to %d, not '%s' at line %d\n",
00448                OSP_MIN_TIMEOUT, OSP_MAX_TIMEOUT, v->value, v->lineno);
00449          }
00450       } else if (!strcasecmp(v->name, "source")) {
00451          ast_copy_string(p->source, v->value, sizeof(p->source));
00452          ast_debug(1, "OSP: source '%s'\n", p->source);
00453       } else if (!strcasecmp(v->name, "authpolicy")) {
00454          if ((sscanf(v->value, "%30d", &t) == 1) && ((t == OSP_AUTH_NO) || (t == OSP_AUTH_YES) || (t == OSP_AUTH_EXCLUSIVE))) {
00455             p->authpolicy = t;
00456             ast_debug(1, "OSP: authpolicy '%d'\n", t);
00457          } else {
00458             ast_log(LOG_WARNING, "OSP: authpolicy should be %d, %d or %d, not '%s' at line %d\n",
00459                OSP_AUTH_NO, OSP_AUTH_YES, OSP_AUTH_EXCLUSIVE, v->value, v->lineno);
00460          }
00461       } else if (!strcasecmp(v->name, "defaultprotocol")) {
00462          if (!strcasecmp(v->value, OSP_PROT_SIP)) {
00463             p->defaultprotocol = OSP_PROT_SIP;
00464             ast_debug(1, "OSP: default protocol '%s'\n", p->defaultprotocol);
00465          } else if (!strcasecmp(v->value, OSP_PROT_H323)) {
00466             p->defaultprotocol = OSP_PROT_H323;
00467             ast_debug(1, "OSP: default protocol '%s'\n", p->defaultprotocol);
00468          } else if (!strcasecmp(v->value, OSP_PROT_IAX)) {
00469             p->defaultprotocol = OSP_PROT_IAX;
00470             ast_debug(1, "OSP: default protocol '%s'\n", p->defaultprotocol);
00471          } else {
00472             ast_log(LOG_WARNING, "OSP: default protocol should be %s, %s, %s, or %s not '%s' at line %d\n",
00473                OSP_PROT_SIP, OSP_PROT_H323, OSP_PROT_IAX, OSP_PROT_OTHER, v->value, v->lineno);
00474          }
00475       }
00476       v = v->next;
00477    }
00478 
00479    if (p->cacount == 0) {
00480       p->cacount = 1;
00481    }
00482 
00483    for (i = 0; i < p->spcount; i++) {
00484       psrvpoints[i] = p->srvpoints[i];
00485    }
00486 
00487    if (osp_security) {
00488       privatekey.PrivateKeyData = NULL;
00489       privatekey.PrivateKeyLength = 0;
00490 
00491       localcert.CertData = NULL;
00492       localcert.CertDataLength = 0;
00493 
00494       for (i = 0; i < p->cacount; i++) {
00495          cacerts[i].CertData = NULL;
00496          cacerts[i].CertDataLength = 0;
00497       }
00498 
00499       if ((error = OSPPUtilLoadPEMPrivateKey((unsigned char*)p->privatekey, &privatekey)) != OSPC_ERR_NO_ERROR) {
00500          ast_log(LOG_WARNING, "OSP: Unable to load privatekey '%s', error '%d'\n", p->privatekey, error);
00501       } else if ((error = OSPPUtilLoadPEMCert((unsigned char*)p->localcert, &localcert)) != OSPC_ERR_NO_ERROR) {
00502          ast_log(LOG_WARNING, "OSP: Unable to load localcert '%s', error '%d'\n", p->localcert, error);
00503       } else {
00504          for (i = 0; i < p->cacount; i++) {
00505             if ((error = OSPPUtilLoadPEMCert((unsigned char*)p->cacerts[i], &cacerts[i])) != OSPC_ERR_NO_ERROR) {
00506                ast_log(LOG_WARNING, "OSP: Unable to load cacert '%s', error '%d'\n", p->cacerts[i], error);
00507                break;
00508             } else {
00509                pcacerts[i] = &cacerts[i];
00510             }
00511          }
00512       }
00513    } else {
00514       privatekey.PrivateKeyData = privatekeydata;
00515       privatekey.PrivateKeyLength = sizeof(privatekeydata);
00516 
00517       localcert.CertData = localcertdata;
00518       localcert.CertDataLength = sizeof(localcertdata);
00519 
00520       cacerts[0].CertData = cacertdata;
00521       cacerts[0].CertDataLength = sizeof(cacertdata);
00522       pcacerts[0] = &cacerts[0];
00523 
00524       if ((error = OSPPBase64Decode(B64PKey, strlen(B64PKey), privatekey.PrivateKeyData, &privatekey.PrivateKeyLength)) != OSPC_ERR_NO_ERROR) {
00525          ast_log(LOG_WARNING, "OSP: Unable to decode private key, error '%d'\n", error);
00526       } else if ((error = OSPPBase64Decode(B64LCert, strlen(B64LCert), localcert.CertData, &localcert.CertDataLength)) != OSPC_ERR_NO_ERROR) {
00527          ast_log(LOG_WARNING, "OSP: Unable to decode local cert, error '%d'\n", error);
00528       } else if ((error = OSPPBase64Decode(B64CACert, strlen(B64CACert), cacerts[0].CertData, &cacerts[0].CertDataLength)) != OSPC_ERR_NO_ERROR) {
00529          ast_log(LOG_WARNING, "OSP: Unable to decode cacert, error '%d'\n", error);
00530       }
00531    }
00532 
00533    if (error == OSPC_ERR_NO_ERROR) {
00534       error = OSPPProviderNew(
00535          p->spcount,
00536          psrvpoints,
00537          NULL,
00538          OSP_AUDIT_URL,
00539          &privatekey,
00540          &localcert,
00541          p->cacount,
00542          pcacerts,
00543          OSP_LOCAL_VALIDATION,
00544          OSP_SSL_LIFETIME,
00545          p->maxconnections,
00546          OSP_HTTP_PERSISTENCE,
00547          p->retrydelay,
00548          p->retrylimit,
00549          p->timeout,
00550          OSP_CUSTOMER_ID,
00551          OSP_DEVICE_ID,
00552          &p->handle);
00553       if (error != OSPC_ERR_NO_ERROR) {
00554          ast_log(LOG_WARNING, "OSP: Unable to create provider '%s', error '%d'\n", provider, error);
00555          res = -1;
00556       } else {
00557          ast_debug(1, "OSP: provider '%s'\n", provider);
00558          ast_mutex_lock(&osplock);
00559          p->next = ospproviders;
00560          ospproviders = p;
00561          ast_mutex_unlock(&osplock);
00562          res = 1;
00563       }
00564    }
00565 
00566    if (osp_security) {
00567       for (i = 0; i < p->cacount; i++) {
00568          if (cacerts[i].CertData) {
00569             ast_free(cacerts[i].CertData);
00570          }
00571       }
00572       if (localcert.CertData) {
00573          ast_free(localcert.CertData);
00574       }
00575       if (privatekey.PrivateKeyData) {
00576          ast_free(privatekey.PrivateKeyData);
00577       }
00578    }
00579 
00580    if (res != 1) {
00581       ast_free(p);
00582    }
00583 
00584    return res;
00585 }

static int osp_create_transaction ( const char *  provider,
int *  transaction,
unsigned int  sourcesize,
char *  source 
) [static]

Create OSP transaction handle.

Parameters:
provider OSP provider context name
transaction OSP transaction handle, output
sourcesize Size of source buffer, in/output
source Source of provider, output
Returns:
1 Success, 0 Failed, -1 Error

Definition at line 624 of file app_osplookup.c.

References ast_copy_string(), ast_debug, ast_mutex_lock(), ast_mutex_unlock(), osp_provider::handle, osp_provider::name, osp_provider::next, OSP_INVALID_HANDLE, osplock, and osp_provider::source.

Referenced by osp_auth(), and osp_lookup().

00629 {
00630    int res = 0;
00631    struct osp_provider* p;
00632    int error;
00633 
00634    ast_mutex_lock(&osplock);
00635    p = ospproviders;
00636    while(p) {
00637       if (!strcasecmp(p->name, provider)) {
00638          error = OSPPTransactionNew(p->handle, transaction);
00639          if (error == OSPC_ERR_NO_ERROR) {
00640             ast_debug(1, "OSP: transaction '%d'\n", *transaction);
00641             ast_copy_string(source, p->source, sourcesize);
00642             ast_debug(1, "OSP: source '%s'\n", source);
00643             res = 1;
00644          } else {
00645             *transaction = OSP_INVALID_HANDLE;
00646             ast_debug(1, "OSP: Unable to create transaction handle, error '%d'\n", error);
00647             res = -1;
00648          }
00649          break;
00650       }
00651       p = p->next;
00652    }
00653    ast_mutex_unlock(&osplock);
00654 
00655    return res;
00656 }

static int osp_create_uuid ( unsigned char *  uuid,
unsigned int *  buffersize 
) [static]

Create a UUID.

Parameters:
uuid UUID buffer
buffersize UUID buffer size
Returns:
1 Created, -1 Error

Definition at line 949 of file app_osplookup.c.

References ast_random(), and OSP_UUID_SIZE.

Referenced by osp_create_callid().

00952 {
00953    int i, res;
00954    long int* tmp;
00955 
00956    if (*buffersize >= OSP_UUID_SIZE) {
00957       tmp = (long int*)uuid;
00958       for (i = 0; i < OSP_UUID_SIZE / sizeof(long int); i++) {
00959          tmp[i] = ast_random();
00960       }
00961       *buffersize = OSP_UUID_SIZE;
00962       res = 1;
00963    } else {
00964       res = -1;
00965    }
00966 
00967    return res;
00968 }

static int osp_finish ( int  handle,
int  recorded,
int  cause,
time_t  start,
time_t  connect,
time_t  end,
unsigned int  release 
) [static]

OSP Finish function.

Parameters:
handle OSP in/outbound transaction handle
recorded If failure reason has been recorded
cause Asterisk hangup cause
start Call start time
connect Call connect time
end Call end time
release Who release first, 0 source, 1 destination
Returns:
1 Success, 0 Failed, -1 Error

Definition at line 1387 of file app_osplookup.c.

References ast_debug, asterisk2osp(), dummy(), and OSP_INVALID_HANDLE.

Referenced by ospfinished_exec().

01395 {
01396    int res;
01397    OSPEFAILREASON reason;
01398    time_t alert = 0;
01399    unsigned isPddInfoPresent = 0;
01400    unsigned pdd = 0;
01401    unsigned int dummy = 0;
01402    int error;
01403 
01404    if (handle == OSP_INVALID_HANDLE) {
01405       return 0;
01406    }
01407 
01408    if (!recorded) {
01409       reason = asterisk2osp(cause);
01410       OSPPTransactionRecordFailure(handle, reason);
01411    }
01412 
01413    error = OSPPTransactionReportUsage(
01414       handle,
01415       difftime(end, connect),
01416       start,
01417       end,
01418       alert,
01419       connect,
01420       isPddInfoPresent,
01421       pdd,
01422       release,
01423       NULL,
01424       -1,
01425       -1,
01426       -1,
01427       -1,
01428       &dummy,
01429       NULL);
01430    if (error == OSPC_ERR_NO_ERROR) {
01431       ast_debug(1, "OSP: Usage reported\n");
01432       res = 1;
01433    } else {
01434       ast_debug(1, "OSP: Unable to report usage, error '%d'\n", error);
01435       res = -1;
01436    }
01437    OSPPTransactionDelete(handle);
01438 
01439    return res;
01440 }

static int osp_get_provider ( const char *  name,
struct osp_provider **  provider 
) [static]

Get OSP provider by name.

Parameters:
name OSP provider context name
provider OSP provider structure
Returns:
1 Success, 0 Failed, -1 Error

Definition at line 593 of file app_osplookup.c.

References ast_debug, ast_mutex_lock(), ast_mutex_unlock(), osp_provider::name, osp_provider::next, and osplock.

Referenced by osp_auth(), osp_lookup(), and osp_next().

00596 {
00597    int res = 0;
00598    struct osp_provider* p;
00599 
00600    ast_mutex_lock(&osplock);
00601    p = ospproviders;
00602    while(p) {
00603       if (!strcasecmp(p->name, name)) {
00604          *provider = p;
00605          ast_debug(1, "OSP: find provider '%s'\n", name);
00606          res = 1;
00607          break;
00608       }
00609       p = p->next;
00610    }
00611    ast_mutex_unlock(&osplock);
00612 
00613    return res;
00614 }

static int osp_load ( int  reload  )  [static]

Definition at line 1975 of file app_osplookup.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load, ast_debug, ast_log(), ast_true(), ast_variable_retrieve(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, LOG_ERROR, LOG_WARNING, OSP_CONFIG_FILE, osp_create_provider(), OSP_GENERAL_CAT, and osp_unload().

Referenced by load_module(), and reload().

01976 {
01977    const char* t;
01978    unsigned int v;
01979    struct ast_config* cfg;
01980    struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
01981    int error = OSPC_ERR_NO_ERROR;
01982 
01983    if ((cfg = ast_config_load(OSP_CONFIG_FILE, config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
01984       return 0;
01985    } else if (cfg == CONFIG_STATUS_FILEINVALID) {
01986       ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", OSP_CONFIG_FILE);
01987       return 0;
01988    }
01989 
01990    if (cfg) {
01991       if (reload)
01992          osp_unload();
01993 
01994       t = ast_variable_retrieve(cfg, OSP_GENERAL_CAT, "accelerate");
01995       if (t && ast_true(t)) {
01996          if ((error = OSPPInit(1)) != OSPC_ERR_NO_ERROR) {
01997             ast_log(LOG_WARNING, "OSP: Unable to enable hardware accelleration\n");
01998             OSPPInit(0);
01999          } else {
02000             osp_hardware = 1;
02001          }
02002       } else {
02003          OSPPInit(0);
02004       }
02005       ast_debug(1, "OSP: osp_hardware '%d'\n", osp_hardware);
02006 
02007       t = ast_variable_retrieve(cfg, OSP_GENERAL_CAT, "securityfeatures");
02008       if (t && ast_true(t)) {
02009          osp_security = 1;
02010       }
02011       ast_debug(1, "OSP: osp_security '%d'\n", osp_security);
02012 
02013       t = ast_variable_retrieve(cfg, OSP_GENERAL_CAT, "tokenformat");
02014       if (t) {
02015          if ((sscanf(t, "%30d", &v) == 1) &&
02016             ((v == TOKEN_ALGO_SIGNED) || (v == TOKEN_ALGO_UNSIGNED) || (v == TOKEN_ALGO_BOTH)))
02017          {
02018             osp_tokenformat = v;
02019          } else {
02020             ast_log(LOG_WARNING, "tokenformat should be an integer from %d, %d or %d, not '%s'\n",
02021                TOKEN_ALGO_SIGNED, TOKEN_ALGO_UNSIGNED, TOKEN_ALGO_BOTH, t);
02022          }
02023       }
02024       ast_debug(1, "OSP: osp_tokenformat '%d'\n", osp_tokenformat);
02025 
02026       t = ast_category_browse(cfg, NULL);
02027       while(t) {
02028          if (strcasecmp(t, OSP_GENERAL_CAT)) {
02029             osp_create_provider(cfg, t);
02030          }
02031          t = ast_category_browse(cfg, t);
02032       }
02033 
02034       osp_initialized = 1;
02035 
02036       ast_config_destroy(cfg);
02037    } else {
02038       ast_log(LOG_WARNING, "OSP: Unable to find configuration. OSP support disabled\n");
02039       return 0;
02040    }
02041    ast_debug(1, "OSP: osp_initialized '%d'\n", osp_initialized);
02042 
02043    return 1;
02044 }

static int osp_lookup ( const char *  provider,
const char *  srcdev,
const char *  calling,
const char *  called,
const char *  snetid,
const char *  rnumber,
unsigned int  callidtypes,
struct osp_result result 
) [static]

OSP Lookup function.

Parameters:
provider OSP provider context name
srcdev Source device of outbound call
calling Calling number
called Called number
snetid Source network ID
rnumber Routing number
callidtypes Call ID types
result Lookup results
Returns:
1 Found , 0 No route, -1 Error

Definition at line 1041 of file app_osplookup.c.

References ast_debug, ast_strlen_zero(), osp_callid::buf, osp_result::called, osp_result::calling, osp_result::dest, dummy(), osp_result::inhandle, osp_result::intimelimit, osp_callid::len, osp_result::networkid, osp_result::numresults, OSP_CALLID_MAXNUM, osp_check_destination(), osp_choose_timelimit(), osp_convert_address(), osp_create_callid(), osp_create_transaction(), OSP_DEF_DESTINATIONS, OSP_DEF_TIMELIMIT, osp_get_provider(), OSP_INVALID_HANDLE, OSP_NORSTR_SIZE, OSP_TOKSTR_SIZE, osp_result::outcallid, osp_result::outhandle, osp_result::outtimelimit, osp_provider::source, osp_result::tech, osp_result::token, and type.

Referenced by osplookup_exec().

01050 {
01051    int res;
01052    struct osp_provider* p = NULL;
01053    char source[OSP_NORSTR_SIZE];
01054    char callingnum[OSP_NORSTR_SIZE];
01055    char callednum[OSP_NORSTR_SIZE];
01056    char destination[OSP_NORSTR_SIZE];
01057    unsigned int tokenlen;
01058    char token[OSP_TOKSTR_SIZE];
01059    char src[OSP_NORSTR_SIZE];
01060    char dev[OSP_NORSTR_SIZE];
01061    unsigned int i, type;
01062    struct osp_callid callid;
01063    unsigned int callidnum;
01064    OSPT_CALL_ID* callids[OSP_CALLID_MAXNUM];
01065    unsigned int dummy = 0;
01066    OSPEFAILREASON reason;
01067    int error;
01068 
01069    result->outhandle = OSP_INVALID_HANDLE;
01070    result->tech[0] = '\0';
01071    result->dest[0] = '\0';
01072    result->called[0] = '\0';
01073    result->calling[0] = '\0';
01074    result->token[0] = '\0';
01075    result->networkid[0] = '\0';
01076    result->numresults = 0;
01077    result->outtimelimit = OSP_DEF_TIMELIMIT;
01078 
01079    if ((res = osp_get_provider(provider, &p)) <= 0) {
01080       ast_debug(1, "OSP: Unabe to find OSP provider '%s'\n", provider);
01081       return res;
01082    }
01083 
01084    if ((res = osp_create_transaction(provider, &result->outhandle, sizeof(source), source)) <= 0) {
01085       ast_debug(1, "OSP: Unable to generate transaction handle\n");
01086       result->outhandle = OSP_INVALID_HANDLE;
01087       if (result->inhandle != OSP_INVALID_HANDLE) {
01088          OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NORMAL_UNSPECIFIED);
01089       }
01090       return -1;
01091    }
01092 
01093    if (!ast_strlen_zero(snetid)) {
01094       OSPPTransactionSetNetworkIds(result->outhandle, snetid, "");
01095    }
01096 
01097    if (!ast_strlen_zero(rnumber)) {
01098       OSPPTransactionSetRoutingNumber(result->outhandle, rnumber);
01099    }
01100 
01101    callidnum = 0;
01102    callids[0] = NULL;
01103    for (i = 0; i < OSP_CALLID_MAXNUM; i++) {
01104       type = 1 << i;
01105       if (callidtypes & type) {
01106          error = osp_create_callid(type, &callid);
01107          if (error == 1) {
01108             callids[callidnum] = OSPPCallIdNew(callid.len, callid.buf);
01109             callidnum++;
01110          }
01111       }
01112    }
01113 
01114    osp_convert_address(source, src, sizeof(src));
01115    osp_convert_address(srcdev, dev, sizeof(dev));
01116    result->numresults = OSP_DEF_DESTINATIONS;
01117    error = OSPPTransactionRequestAuthorisation(
01118       result->outhandle,
01119       src,
01120       dev,
01121       calling ? calling : "",
01122       OSPC_NFORMAT_E164,
01123       called,
01124       OSPC_NFORMAT_E164,
01125       NULL,
01126       callidnum,
01127       callids,
01128       NULL,
01129       &result->numresults,
01130       &dummy,
01131       NULL);
01132 
01133    for (i = 0; i < callidnum; i++) {
01134       OSPPCallIdDelete(&callids[i]);
01135    }
01136 
01137    if (error != OSPC_ERR_NO_ERROR) {
01138       ast_debug(1, "OSP: Unable to request authorization, error '%d'\n", error);
01139       result->numresults = 0;
01140       if (result->inhandle != OSP_INVALID_HANDLE) {
01141          OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NORMAL_UNSPECIFIED);
01142       }
01143       return -1;
01144    }
01145 
01146    if (!result->numresults) {
01147       ast_debug(1, "OSP: No more destination\n");
01148       if (result->inhandle != OSP_INVALID_HANDLE) {
01149          OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01150       }
01151       return 0;
01152    }
01153 
01154    result->outcallid.len = sizeof(result->outcallid.buf);
01155    tokenlen = sizeof(token);
01156    error = OSPPTransactionGetFirstDestination(
01157       result->outhandle,
01158       0,
01159       NULL,
01160       NULL,
01161       &result->outtimelimit,
01162       &result->outcallid.len,
01163       result->outcallid.buf,
01164       sizeof(callednum),
01165       callednum,
01166       sizeof(callingnum),
01167       callingnum,
01168       sizeof(destination),
01169       destination,
01170       0,
01171       NULL,
01172       &tokenlen,
01173       token);
01174    if (error != OSPC_ERR_NO_ERROR) {
01175       ast_debug(1, "OSP: Unable to get first route, error '%d'\n", error);
01176       result->numresults = 0;
01177       result->outtimelimit = OSP_DEF_TIMELIMIT;
01178       if (result->inhandle != OSP_INVALID_HANDLE) {
01179          OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01180       }
01181       return -1;
01182    }
01183 
01184    result->numresults--;
01185    result->outtimelimit = osp_choose_timelimit(result->intimelimit, result->outtimelimit);
01186    ast_debug(1, "OSP: outtimelimit '%d'\n", result->outtimelimit);
01187    ast_debug(1, "OSP: called '%s'\n", callednum);
01188    ast_debug(1, "OSP: calling '%s'\n", callingnum);
01189    ast_debug(1, "OSP: destination '%s'\n", destination);
01190    ast_debug(1, "OSP: token size '%d'\n", tokenlen);
01191 
01192    if ((res = osp_check_destination(p, callednum, callingnum, destination, tokenlen, token, &reason, result)) > 0) {
01193       return 1;
01194    }
01195 
01196    if (!result->numresults) {
01197       ast_debug(1, "OSP: No more destination\n");
01198       result->outtimelimit = OSP_DEF_TIMELIMIT;
01199       OSPPTransactionRecordFailure(result->outhandle, reason);
01200       if (result->inhandle != OSP_INVALID_HANDLE) {
01201          OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01202       }
01203       return 0;
01204    }
01205 
01206    while(result->numresults) {
01207       result->outcallid.len = sizeof(result->outcallid.buf);
01208       tokenlen = sizeof(token);
01209       error = OSPPTransactionGetNextDestination(
01210          result->outhandle,
01211          reason,
01212          0,
01213          NULL,
01214          NULL,
01215          &result->outtimelimit,
01216          &result->outcallid.len,
01217          result->outcallid.buf,
01218          sizeof(callednum),
01219          callednum,
01220          sizeof(callingnum),
01221          callingnum,
01222          sizeof(destination),
01223          destination,
01224          0,
01225          NULL,
01226          &tokenlen,
01227          token);
01228       if (error == OSPC_ERR_NO_ERROR) {
01229          result->numresults--;
01230          result->outtimelimit = osp_choose_timelimit(result->intimelimit, result->outtimelimit);
01231          ast_debug(1, "OSP: outtimelimit '%d'\n", result->outtimelimit);
01232          ast_debug(1, "OSP: called '%s'\n", callednum);
01233          ast_debug(1, "OSP: calling '%s'\n", callingnum);
01234          ast_debug(1, "OSP: destination '%s'\n", destination);
01235          ast_debug(1, "OSP: token size '%d'\n", tokenlen);
01236 
01237          if ((res = osp_check_destination(p, callednum, callingnum, destination, tokenlen, token, &reason, result)) > 0) {
01238             break;
01239          } else if (!result->numresults) {
01240             ast_debug(1, "OSP: No more destination\n");
01241             OSPPTransactionRecordFailure(result->outhandle, reason);
01242             if (result->inhandle != OSP_INVALID_HANDLE) {
01243                OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01244             }
01245             res = 0;
01246             break;
01247          }
01248       } else {
01249          ast_debug(1, "OSP: Unable to get route, error '%d'\n", error);
01250          result->numresults = 0;
01251          result->outtimelimit = OSP_DEF_TIMELIMIT;
01252          if (result->inhandle != OSP_INVALID_HANDLE) {
01253             OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NORMAL_UNSPECIFIED);
01254          }
01255          res = -1;
01256          break;
01257       }
01258    }
01259    return res;
01260 }

static int osp_next ( const char *  provider,
int  cause,
struct osp_result result 
) [static]

OSP Lookup Next function.

Parameters:
provider OSP provider name
cause Asterisk hangup cuase
result Lookup results, in/output
Returns:
1 Found , 0 No route, -1 Error

Definition at line 1269 of file app_osplookup.c.

References ast_debug, asterisk2osp(), osp_callid::buf, osp_result::called, osp_result::calling, osp_result::dest, osp_result::inhandle, osp_result::intimelimit, osp_callid::len, osp_result::networkid, osp_result::numresults, osp_check_destination(), osp_choose_timelimit(), OSP_DEF_TIMELIMIT, osp_get_provider(), OSP_INVALID_HANDLE, OSP_NORSTR_SIZE, OSP_TOKSTR_SIZE, osp_result::outcallid, osp_result::outhandle, osp_result::outtimelimit, osp_result::tech, and osp_result::token.

Referenced by ospnext_exec().

01273 {
01274    int res;
01275    struct osp_provider* p = NULL;
01276    char callingnum[OSP_NORSTR_SIZE];
01277    char callednum[OSP_NORSTR_SIZE];
01278    char destination[OSP_NORSTR_SIZE];
01279    unsigned int tokenlen;
01280    char token[OSP_TOKSTR_SIZE];
01281    OSPEFAILREASON reason;
01282    int error;
01283 
01284    result->tech[0] = '\0';
01285    result->dest[0] = '\0';
01286    result->called[0] = '\0';
01287    result->calling[0] = '\0';
01288    result->token[0] = '\0';
01289    result->networkid[0] = '\0';
01290    result->outtimelimit = OSP_DEF_TIMELIMIT;
01291 
01292    if ((res = osp_get_provider(provider, &p)) <= 0) {
01293       ast_debug(1, "OSP: Unabe to find OSP provider '%s'\n", provider);
01294       return res;
01295    }
01296 
01297    if (result->outhandle == OSP_INVALID_HANDLE) {
01298       ast_debug(1, "OSP: Transaction handle undefined\n");
01299       result->numresults = 0;
01300       if (result->inhandle != OSP_INVALID_HANDLE) {
01301          OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NORMAL_UNSPECIFIED);
01302       }
01303       return -1;
01304    }
01305 
01306    reason = asterisk2osp(cause);
01307 
01308    if (!result->numresults) {
01309       ast_debug(1, "OSP: No more destination\n");
01310       OSPPTransactionRecordFailure(result->outhandle, reason);
01311       if (result->inhandle != OSP_INVALID_HANDLE) {
01312          OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01313       }
01314       return 0;
01315    }
01316 
01317    while(result->numresults) {
01318       result->outcallid.len = sizeof(result->outcallid.buf);
01319       tokenlen = sizeof(token);
01320       error = OSPPTransactionGetNextDestination(
01321          result->outhandle,
01322          reason,
01323          0,
01324          NULL,
01325          NULL,
01326          &result->outtimelimit,
01327          &result->outcallid.len,
01328          result->outcallid.buf,
01329          sizeof(callednum),
01330          callednum,
01331          sizeof(callingnum),
01332          callingnum,
01333          sizeof(destination),
01334          destination,
01335          0,
01336          NULL,
01337          &tokenlen,
01338          token);
01339       if (error == OSPC_ERR_NO_ERROR) {
01340          result->numresults--;
01341          result->outtimelimit = osp_choose_timelimit(result->intimelimit, result->outtimelimit);
01342          ast_debug(1, "OSP: outtimelimit '%d'\n", result->outtimelimit);
01343          ast_debug(1, "OSP: called '%s'\n", callednum);
01344          ast_debug(1, "OSP: calling '%s'\n", callingnum);
01345          ast_debug(1, "OSP: destination '%s'\n", destination);
01346          ast_debug(1, "OSP: token size '%d'\n", tokenlen);
01347 
01348          if ((res = osp_check_destination(p, callednum, callingnum, destination, tokenlen, token, &reason, result)) > 0) {
01349             res = 1;
01350             break;
01351          } else if (!result->numresults) {
01352             ast_debug(1, "OSP: No more destination\n");
01353             OSPPTransactionRecordFailure(result->outhandle, reason);
01354             if (result->inhandle != OSP_INVALID_HANDLE) {
01355                OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01356             }
01357             res = 0;
01358             break;
01359          }
01360       } else {
01361          ast_debug(1, "OSP: Unable to get route, error '%d'\n", error);
01362          result->token[0] = '\0';
01363          result->numresults = 0;
01364          result->outtimelimit = OSP_DEF_TIMELIMIT;
01365          if (result->inhandle != OSP_INVALID_HANDLE) {
01366             OSPPTransactionRecordFailure(result->inhandle, OSPC_FAIL_NORMAL_UNSPECIFIED);
01367          }
01368          res = -1;
01369          break;
01370       }
01371    }
01372 
01373    return res;
01374 }

static int osp_unload ( void   )  [static]

Definition at line 2046 of file app_osplookup.c.

References ast_free, ast_mutex_lock(), ast_mutex_unlock(), osp_provider::handle, osp_provider::next, and osplock.

Referenced by osp_load(), and unload_module().

02047 {
02048    struct osp_provider* p;
02049    struct osp_provider* next;
02050 
02051    if (osp_initialized) {
02052       ast_mutex_lock(&osplock);
02053       p = ospproviders;
02054       while(p) {
02055          next = p->next;
02056          OSPPProviderDelete(p->handle, 0);
02057          ast_free(p);
02058          p = next;
02059       }
02060       ospproviders = NULL;
02061       ast_mutex_unlock(&osplock);
02062 
02063       OSPPCleanup();
02064 
02065       osp_tokenformat = TOKEN_ALGO_SIGNED;
02066       osp_security = 0;
02067       osp_hardware = 0;
02068       osp_initialized = 0;
02069    }
02070    return 0;
02071 }

static int osp_uuid2str ( unsigned char *  uuid,
char *  buffer,
unsigned int  buffersize 
) [static]

UUID to string.

Parameters:
uuid UUID
buffer String buffer
buffersize String buffer size
Returns:
1 Successed, -1 Error

Definition at line 977 of file app_osplookup.c.

References OSP_UUIDSTR_SIZE.

Referenced by osplookup_exec(), and ospnext_exec().

00981 {
00982    int res;
00983 
00984    if (buffersize > OSP_UUIDSTR_SIZE) {
00985       snprintf(buffer, buffersize, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
00986          uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
00987          uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
00988       res = 1;
00989    } else {
00990       res = -1;
00991    }
00992 
00993    return res;
00994 }

static int osp_validate_token ( int  transaction,
const char *  source,
const char *  destination,
const char *  calling,
const char *  called,
const char *  token,
unsigned int *  timelimit 
) [static]

Validate OSP token of inbound call.

Parameters:
transaction OSP transaction handle
source Source of inbound call
destination Destination of inbound call
calling Calling number
called Called number
token OSP token, may be empty
timelimit Call duration limit, output
Returns:
1 Success, 0 Failed, -1 Error

Definition at line 689 of file app_osplookup.c.

References ast_base64decode(), ast_debug, dummy(), osp_convert_address(), OSP_NORSTR_SIZE, and OSP_TOKSTR_SIZE.

Referenced by osp_auth().

00697 {
00698    int res;
00699    int tokenlen;
00700    unsigned char tokenstr[OSP_TOKSTR_SIZE];
00701    char src[OSP_NORSTR_SIZE];
00702    char dst[OSP_NORSTR_SIZE];
00703    unsigned int authorised;
00704    unsigned int dummy = 0;
00705    int error;
00706 
00707    tokenlen = ast_base64decode(tokenstr, token, strlen(token));
00708    osp_convert_address(source, src, sizeof(src));
00709    osp_convert_address(destination, dst, sizeof(dst));
00710    error = OSPPTransactionValidateAuthorisation(
00711       transaction,
00712       src,
00713       dst,
00714       NULL,
00715       NULL,
00716       calling ? calling : "",
00717       OSPC_NFORMAT_E164,
00718       called,
00719       OSPC_NFORMAT_E164,
00720       0,
00721       NULL,
00722       tokenlen,
00723       (char*)tokenstr,
00724       &authorised,
00725       timelimit,
00726       &dummy,
00727       NULL,
00728       osp_tokenformat);
00729    if (error != OSPC_ERR_NO_ERROR) {
00730       ast_debug(1, "OSP: Unable to validate inbound token, error '%d'\n", error);
00731       res = -1;
00732    } else if (authorised) {
00733       ast_debug(1, "OSP: Authorised\n");
00734       res = 1;
00735    } else {
00736       ast_debug(1, "OSP: Unauthorised\n");
00737       res = 0;
00738    }
00739 
00740    return res;
00741 }

static int ospauth_exec ( struct ast_channel chan,
const char *  data 
) [static]

OSP Application OSPAuth.

Parameters:
chan Channel
data Parameter
Returns:
0 Success, -1 Failed

Definition at line 1450 of file app_osplookup.c.

References AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, AST_LIST_TRAVERSE, ast_log(), AST_OSP_ERROR, AST_OSP_FAILED, AST_OSP_SUCCESS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_var_name(), ast_var_value(), ast_channel::cid, ast_callerid::cid_num, ast_var_t::entries, ast_channel::exten, LOG_ERROR, osp_auth(), OSP_DEF_PROVIDER, OSP_DEF_TIMELIMIT, OSP_INTSTR_SIZE, pbx_builtin_setvar_helper(), status, and ast_channel::varshead.

Referenced by load_module().

01453 {
01454    int res;
01455    const char* provider = OSP_DEF_PROVIDER;
01456    struct varshead* headp;
01457    struct ast_var_t* current;
01458    const char* source = "";
01459    const char* token = "";
01460    int handle;
01461    unsigned int timelimit;
01462    char buffer[OSP_INTSTR_SIZE];
01463    const char* status;
01464    char* tmp;
01465 
01466    AST_DECLARE_APP_ARGS(args,
01467       AST_APP_ARG(provider);
01468       AST_APP_ARG(options);
01469    );
01470 
01471    if (!(tmp = ast_strdupa(data))) {
01472       ast_log(LOG_ERROR, "Out of memory\n");
01473       return -1;
01474    }
01475 
01476    AST_STANDARD_APP_ARGS(args, tmp);
01477 
01478    if (!ast_strlen_zero(args.provider)) {
01479       provider = args.provider;
01480    }
01481    ast_debug(1, "OSPAuth: provider '%s'\n", provider);
01482 
01483    headp = &chan->varshead;
01484    AST_LIST_TRAVERSE(headp, current, entries) {
01485       if (!strcasecmp(ast_var_name(current), "OSPPEERIP")) {
01486          source = ast_var_value(current);
01487       } else if (!strcasecmp(ast_var_name(current), "OSPINTOKEN")) {
01488          token = ast_var_value(current);
01489       }
01490    }
01491 
01492    ast_debug(1, "OSPAuth: source '%s'\n", source);
01493    ast_debug(1, "OSPAuth: token size '%zd'\n", strlen(token));
01494 
01495    if ((res = osp_auth(provider, &handle, source, chan->cid.cid_num, chan->exten, token, &timelimit)) > 0) {
01496       status = AST_OSP_SUCCESS;
01497    } else {
01498       timelimit = OSP_DEF_TIMELIMIT;
01499       if (!res) {
01500          status = AST_OSP_FAILED;
01501       } else {
01502          status = AST_OSP_ERROR;
01503       }
01504    }
01505 
01506    snprintf(buffer, sizeof(buffer), "%d", handle);
01507    pbx_builtin_setvar_helper(chan, "OSPINHANDLE", buffer);
01508    ast_debug(1, "OSPAuth: OSPINHANDLE '%s'\n", buffer);
01509    snprintf(buffer, sizeof(buffer), "%d", timelimit);
01510    pbx_builtin_setvar_helper(chan, "OSPINTIMELIMIT", buffer);
01511    ast_debug(1, "OSPAuth: OSPINTIMELIMIT '%s'\n", buffer);
01512    pbx_builtin_setvar_helper(chan, "OSPAUTHSTATUS", status);
01513    ast_debug(1, "OSPAuth: %s\n", status);
01514 
01515    if(res <= 0) {
01516       res = -1;
01517    } else {
01518       res = 0;
01519    }
01520 
01521    return res;
01522 }

static int ospfinished_exec ( struct ast_channel chan,
const char *  data 
) [static]

OSP Application OSPFinish.

Parameters:
chan Channel
data Parameter
Returns:
0 Success, -1 Failed

Definition at line 1860 of file app_osplookup.c.

References ast_cdr::answer, AST_APP_ARG, AST_CAUSE_NO_ROUTE_DESTINATION, AST_CAUSE_NORMAL_CLEARING, ast_check_hangup(), ast_debug, AST_DECLARE_APP_ARGS, AST_LIST_TRAVERSE, ast_log(), AST_OSP_ERROR, AST_OSP_FAILED, AST_OSP_SUCCESS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_var_name(), ast_var_value(), cause, ast_channel::cdr, ast_var_t::entries, LOG_ERROR, osp_finish(), OSP_INTSTR_SIZE, OSP_INVALID_HANDLE, pbx_builtin_setvar_helper(), ast_cdr::start, status, and ast_channel::varshead.

Referenced by load_module().

01863 {
01864    int res = 1;
01865    int cause = 0;
01866    struct varshead* headp;
01867    struct ast_var_t* current;
01868    int inhandle = OSP_INVALID_HANDLE;
01869    int outhandle = OSP_INVALID_HANDLE;
01870    int recorded = 0;
01871    time_t start, connect, end;
01872    unsigned int release;
01873    char buffer[OSP_INTSTR_SIZE];
01874    const char* status;
01875    char* tmp;
01876 
01877    AST_DECLARE_APP_ARGS(args,
01878       AST_APP_ARG(cause);
01879       AST_APP_ARG(options);
01880    );
01881 
01882    if (!(tmp = ast_strdupa(data))) {
01883       ast_log(LOG_ERROR, "Out of memory\n");
01884       return -1;
01885    }
01886 
01887    AST_STANDARD_APP_ARGS(args, tmp);
01888 
01889    headp = &chan->varshead;
01890    AST_LIST_TRAVERSE(headp, current, entries) {
01891       if (!strcasecmp(ast_var_name(current), "OSPINHANDLE")) {
01892          if (sscanf(ast_var_value(current), "%30d", &inhandle) != 1) {
01893             inhandle = OSP_INVALID_HANDLE;
01894          }
01895       } else if (!strcasecmp(ast_var_name(current), "OSPOUTHANDLE")) {
01896          if (sscanf(ast_var_value(current), "%30d", &outhandle) != 1) {
01897             outhandle = OSP_INVALID_HANDLE;
01898          }
01899       } else if (!recorded &&
01900          (!strcasecmp(ast_var_name(current), "OSPAUTHSTATUS") ||
01901          !strcasecmp(ast_var_name(current), "OSPLOOKUPSTATUS") ||
01902          !strcasecmp(ast_var_name(current), "OSPNEXTSTATUS")))
01903       {
01904          if (strcasecmp(ast_var_value(current), AST_OSP_SUCCESS)) {
01905             recorded = 1;
01906          }
01907       }
01908    }
01909    ast_debug(1, "OSPFinish: OSPINHANDLE '%d'\n", inhandle);
01910    ast_debug(1, "OSPFinish: OSPOUTHANDLE '%d'\n", outhandle);
01911    ast_debug(1, "OSPFinish: recorded '%d'\n", recorded);
01912 
01913    if (!ast_strlen_zero(args.cause) && sscanf(args.cause, "%30d", &cause) != 1) {
01914       cause = 0;
01915    }
01916    ast_debug(1, "OSPFinish: cause '%d'\n", cause);
01917 
01918    if (chan->cdr) {
01919       start = chan->cdr->start.tv_sec;
01920       connect = chan->cdr->answer.tv_sec;
01921       if (connect) {
01922          end = time(NULL);
01923       } else {
01924          end = connect;
01925       }
01926    } else {
01927       start = 0;
01928       connect = 0;
01929       end = 0;
01930    }
01931    ast_debug(1, "OSPFinish: start '%ld'\n", start);
01932    ast_debug(1, "OSPFinish: connect '%ld'\n", connect);
01933    ast_debug(1, "OSPFinish: end '%ld'\n", end);
01934 
01935    release = ast_check_hangup(chan) ? 0 : 1;
01936 
01937    if (osp_finish(outhandle, recorded, cause, start, connect, end, release) <= 0) {
01938       ast_debug(1, "OSPFinish: Unable to report usage for outbound call\n");
01939    }
01940    switch (cause) {
01941    case AST_CAUSE_NORMAL_CLEARING:
01942       break;
01943    default:
01944       cause = AST_CAUSE_NO_ROUTE_DESTINATION;
01945       break;
01946    }
01947    if (osp_finish(inhandle, recorded, cause, start, connect, end, release) <= 0) {
01948       ast_debug(1, "OSPFinish: Unable to report usage for inbound call\n");
01949    }
01950    snprintf(buffer, sizeof(buffer), "%d", OSP_INVALID_HANDLE);
01951    pbx_builtin_setvar_helper(chan, "OSPOUTHANDLE", buffer);
01952    pbx_builtin_setvar_helper(chan, "OSPINHANDLE", buffer);
01953 
01954    if (res > 0) {
01955       status = AST_OSP_SUCCESS;
01956    } else if (!res) {
01957       status = AST_OSP_FAILED;
01958    } else {
01959       status = AST_OSP_ERROR;
01960    }
01961    pbx_builtin_setvar_helper(chan, "OSPFINISHSTATUS", status);
01962 
01963    if(!res) {
01964       res = -1;
01965    } else {
01966       res = 0;
01967    }
01968 
01969    return res;
01970 }

static int osplookup_exec ( struct ast_channel chan,
const char *  data 
) [static]

OSP Application OSPLookup.

Parameters:
chan Channel
data Parameter
Returns:
0 Success, -1 Failed

Definition at line 1530 of file app_osplookup.c.

References AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), ast_debug, AST_DECLARE_APP_ARGS, AST_LIST_TRAVERSE, ast_log(), AST_OSP_ERROR, AST_OSP_FAILED, AST_OSP_SUCCESS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_var_name(), ast_var_value(), osp_callid::buf, osp_result::called, osp_result::calling, ast_channel::cid, ast_callerid::cid_num, osp_result::dest, exten, osp_result::inhandle, osp_result::intimelimit, osp_callid::len, LOG_ERROR, LOG_WARNING, osp_result::networkid, osp_result::numresults, OSP_CALLID_H323, OSP_CALLID_IAX, OSP_CALLID_SIP, OSP_CALLID_UNDEFINED, OSP_DEF_PROVIDER, OSP_DEF_TIMELIMIT, OSP_INVALID_HANDLE, osp_lookup(), OSP_SIP_HEADER, OSP_TECH_H323, OSP_TECH_IAX, OSP_TECH_SIP, OSP_TOKSTR_SIZE, osp_uuid2str(), osp_result::outcallid, osp_result::outhandle, osp_result::outtimelimit, pbx_builtin_setvar_helper(), status, osp_result::tech, osp_result::token, and ast_channel::varshead.

Referenced by load_module().

01533 {
01534    int res, cres;
01535    const char* provider = OSP_DEF_PROVIDER;
01536    struct varshead* headp;
01537    struct ast_var_t* current;
01538    const char* srcdev = "";
01539    const char* snetid = "";
01540    const char* rnumber = "";
01541    char buffer[OSP_TOKSTR_SIZE];
01542    unsigned int callidtypes = OSP_CALLID_UNDEFINED;
01543    struct osp_result result;
01544    const char* status;
01545    char* tmp;
01546 
01547    AST_DECLARE_APP_ARGS(args,
01548       AST_APP_ARG(exten);
01549       AST_APP_ARG(provider);
01550       AST_APP_ARG(options);
01551    );
01552 
01553    if (ast_strlen_zero(data)) {
01554       ast_log(LOG_WARNING, "OSPLookup: Arg required, OSPLookup(exten[|provider[|options]])\n");
01555       return -1;
01556    }
01557 
01558    if (!(tmp = ast_strdupa(data))) {
01559       ast_log(LOG_ERROR, "Out of memory\n");
01560       return -1;
01561    }
01562 
01563    AST_STANDARD_APP_ARGS(args, tmp);
01564 
01565    ast_debug(1, "OSPLookup: exten '%s'\n", args.exten);
01566 
01567    if (!ast_strlen_zero(args.provider)) {
01568       provider = args.provider;
01569    }
01570    ast_debug(1, "OSPlookup: provider '%s'\n", provider);
01571 
01572    if (args.options) {
01573       if (strchr(args.options, 'h')) {
01574          callidtypes |= OSP_CALLID_H323;
01575       }
01576       if (strchr(args.options, 's')) {
01577          callidtypes |= OSP_CALLID_SIP;
01578       }
01579       if (strchr(args.options, 'i')) {
01580          callidtypes |= OSP_CALLID_IAX;
01581       }
01582    }
01583    ast_debug(1, "OSPLookup: call id types '%d'\n", callidtypes);
01584 
01585    result.inhandle = OSP_INVALID_HANDLE;
01586    result.intimelimit = OSP_DEF_TIMELIMIT;
01587 
01588    headp = &chan->varshead;
01589    AST_LIST_TRAVERSE(headp, current, entries) {
01590       if (!strcasecmp(ast_var_name(current), "OSPINHANDLE")) {
01591          if (sscanf(ast_var_value(current), "%30d", &result.inhandle) != 1) {
01592             result.inhandle = OSP_INVALID_HANDLE;
01593          }
01594       } else if (!strcasecmp(ast_var_name(current), "OSPINTIMELIMIT")) {
01595          if (sscanf(ast_var_value(current), "%30d", &result.intimelimit) != 1) {
01596             result.intimelimit = OSP_DEF_TIMELIMIT;
01597          }
01598       } else if (!strcasecmp(ast_var_name(current), "OSPINNETWORKID")) {
01599          snetid = ast_var_value(current);
01600       } else if (!strcasecmp(ast_var_name(current), "OSPROUTINGNUMBER")) {
01601          rnumber = ast_var_value(current);
01602       } else if (!strcasecmp(ast_var_name(current), "OSPPEERIP")) {
01603          srcdev = ast_var_value(current);
01604       }
01605    }
01606    ast_debug(1, "OSPLookup: OSPINHANDLE '%d'\n", result.inhandle);
01607    ast_debug(1, "OSPLookup: OSPINTIMELIMIT '%d'\n", result.intimelimit);
01608    ast_debug(1, "OSPLookup: OSPINNETWORKID '%s'\n", snetid);
01609    ast_debug(1, "OSPLookup: OSPROUTINGNUMBER '%s'\n", rnumber);
01610    ast_debug(1, "OSPLookup: source device '%s'\n", srcdev);
01611 
01612    if ((cres = ast_autoservice_start(chan)) < 0) {
01613       return -1;
01614    }
01615 
01616    if ((res = osp_lookup(provider, srcdev, chan->cid.cid_num, args.exten, snetid, rnumber, callidtypes, &result)) > 0) {
01617       status = AST_OSP_SUCCESS;
01618    } else {
01619       result.tech[0] = '\0';
01620       result.dest[0] = '\0';
01621       result.called[0] = '\0';
01622       result.calling[0] = '\0';
01623       result.token[0] = '\0';
01624       result.networkid[0] = '\0';
01625       result.numresults = 0;
01626       result.outtimelimit = OSP_DEF_TIMELIMIT;
01627       result.outcallid.buf[0] = '\0';
01628       result.outcallid.len = 0;
01629       if (!res) {
01630          status = AST_OSP_FAILED;
01631       } else {
01632          status = AST_OSP_ERROR;
01633       }
01634    }
01635 
01636    snprintf(buffer, sizeof(buffer), "%d", result.outhandle);
01637    pbx_builtin_setvar_helper(chan, "OSPOUTHANDLE", buffer);
01638    ast_debug(1, "OSPLookup: OSPOUTHANDLE '%s'\n", buffer);
01639    pbx_builtin_setvar_helper(chan, "OSPTECH", result.tech);
01640    ast_debug(1, "OSPLookup: OSPTECH '%s'\n", result.tech);
01641    pbx_builtin_setvar_helper(chan, "OSPDEST", result.dest);
01642    ast_debug(1, "OSPLookup: OSPDEST '%s'\n", result.dest);
01643    pbx_builtin_setvar_helper(chan, "OSPCALLED", result.called);
01644    ast_debug(1, "OSPLookup: OSPCALLED '%s'\n", result.called);
01645    pbx_builtin_setvar_helper(chan, "OSPCALLING", result.calling);
01646    ast_debug(1, "OSPLookup: OSPCALLING '%s'\n", result.calling);
01647    pbx_builtin_setvar_helper(chan, "OSPOUTNETWORKID", result.networkid);
01648    ast_debug(1, "OSPLookup: OSPOUTNETWORKID '%s'\n", result.networkid);
01649    pbx_builtin_setvar_helper(chan, "OSPOUTTOKEN", result.token);
01650    ast_debug(1, "OSPLookup: OSPOUTTOKEN size '%zd'\n", strlen(result.token));
01651    snprintf(buffer, sizeof(buffer), "%d", result.numresults);
01652    pbx_builtin_setvar_helper(chan, "OSPRESULTS", buffer);
01653    ast_debug(1, "OSPLookup: OSPRESULTS '%s'\n", buffer);
01654    snprintf(buffer, sizeof(buffer), "%d", result.outtimelimit);
01655    pbx_builtin_setvar_helper(chan, "OSPOUTTIMELIMIT", buffer);
01656    ast_debug(1, "OSPLookup: OSPOUTTIMELIMIT '%s'\n", buffer);
01657    snprintf(buffer, sizeof(buffer), "%d", callidtypes);
01658    pbx_builtin_setvar_helper(chan, "OSPOUTCALLIDTYPES", buffer);
01659    ast_debug(1, "OSPLookup: OSPOUTCALLIDTYPES '%s'\n", buffer);
01660    pbx_builtin_setvar_helper(chan, "OSPLOOKUPSTATUS", status);
01661    ast_debug(1, "OSPLookup: %s\n", status);
01662 
01663    if (!strcasecmp(result.tech, OSP_TECH_H323)) {
01664       if ((callidtypes & OSP_CALLID_H323) && (result.outcallid.len != 0)) {
01665          osp_uuid2str(result.outcallid.buf, buffer, sizeof(buffer));
01666       } else {
01667          buffer[0] = '\0';
01668       }
01669       pbx_builtin_setvar_helper(chan, "OSPOUTCALLID", buffer);
01670       snprintf(buffer, sizeof(buffer), "%s/%s@%s", result.tech, result.called, result.dest);
01671       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
01672    } else if (!strcasecmp(result.tech, OSP_TECH_SIP)) {
01673       snprintf(buffer, sizeof(buffer), "%s/%s@%s", result.tech, result.called, result.dest);
01674       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
01675       if (!ast_strlen_zero(result.token)) {
01676          snprintf(buffer, sizeof(buffer), "%s%s", OSP_SIP_HEADER, result.token);
01677          pbx_builtin_setvar_helper(chan, "_SIPADDHEADER", buffer);
01678          ast_debug(1, "OSPLookup: SIPADDHEADER size '%zd'\n", strlen(buffer));
01679       }
01680    } else if (!strcasecmp(result.tech, OSP_TECH_IAX)) {
01681       snprintf(buffer, sizeof(buffer), "%s/%s/%s", result.tech, result.dest, result.called);
01682       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
01683    }
01684 
01685    if ((cres = ast_autoservice_stop(chan)) < 0) {
01686       return -1;
01687    }
01688 
01689    if(res <= 0) {
01690       res = -1;
01691    } else {
01692       res = 0;
01693    }
01694 
01695    return res;
01696 }

static int ospnext_exec ( struct ast_channel chan,
const char *  data 
) [static]

OSP Application OSPNext.

Parameters:
chan Channel
data Parameter
Returns:
0 Success, -1 Failed

Definition at line 1704 of file app_osplookup.c.

References AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, AST_LIST_TRAVERSE, ast_log(), AST_OSP_ERROR, AST_OSP_FAILED, AST_OSP_SUCCESS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_var_name(), ast_var_value(), osp_callid::buf, osp_result::called, osp_result::calling, cause, osp_result::dest, osp_result::inhandle, osp_result::intimelimit, osp_callid::len, LOG_ERROR, LOG_WARNING, osp_result::networkid, osp_result::numresults, OSP_CALLID_H323, OSP_CALLID_UNDEFINED, OSP_DEF_PROVIDER, OSP_DEF_TIMELIMIT, OSP_INVALID_HANDLE, osp_next(), OSP_SIP_HEADER, OSP_TECH_H323, OSP_TECH_IAX, OSP_TECH_SIP, OSP_TOKSTR_SIZE, osp_uuid2str(), osp_result::outcallid, osp_result::outhandle, osp_result::outtimelimit, pbx_builtin_setvar_helper(), status, osp_result::tech, osp_result::token, and ast_channel::varshead.

Referenced by load_module().

01707 {
01708    int res;
01709    const char* provider = OSP_DEF_PROVIDER;
01710    int cause = 0;
01711    struct varshead* headp;
01712    struct ast_var_t* current;
01713    struct osp_result result;
01714    char buffer[OSP_TOKSTR_SIZE];
01715    unsigned int callidtypes = OSP_CALLID_UNDEFINED;
01716    const char* status;
01717    char* tmp;
01718 
01719    AST_DECLARE_APP_ARGS(args,
01720       AST_APP_ARG(cause);
01721       AST_APP_ARG(provider);
01722       AST_APP_ARG(options);
01723    );
01724 
01725    if (ast_strlen_zero(data)) {
01726       ast_log(LOG_WARNING, "OSPNext: Arg required, OSPNext(cause[|provider[|options]])\n");
01727       return -1;
01728    }
01729 
01730    if (!(tmp = ast_strdupa(data))) {
01731       ast_log(LOG_ERROR, "Out of memory\n");
01732       return -1;
01733    }
01734 
01735    AST_STANDARD_APP_ARGS(args, tmp);
01736 
01737    if (!ast_strlen_zero(args.cause) && sscanf(args.cause, "%30d", &cause) != 1) {
01738       cause = 0;
01739    }
01740    ast_debug(1, "OSPNext: cause '%d'\n", cause);
01741 
01742    if (!ast_strlen_zero(args.provider)) {
01743       provider = args.provider;
01744    }
01745    ast_debug(1, "OSPlookup: provider '%s'\n", provider);
01746 
01747    result.inhandle = OSP_INVALID_HANDLE;
01748    result.outhandle = OSP_INVALID_HANDLE;
01749    result.intimelimit = OSP_DEF_TIMELIMIT;
01750    result.numresults = 0;
01751 
01752    headp = &chan->varshead;
01753    AST_LIST_TRAVERSE(headp, current, entries) {
01754       if (!strcasecmp(ast_var_name(current), "OSPINHANDLE")) {
01755          if (sscanf(ast_var_value(current), "%30d", &result.inhandle) != 1) {
01756             result.inhandle = OSP_INVALID_HANDLE;
01757          }
01758       } else if (!strcasecmp(ast_var_name(current), "OSPOUTHANDLE")) {
01759          if (sscanf(ast_var_value(current), "%30d", &result.outhandle) != 1) {
01760             result.outhandle = OSP_INVALID_HANDLE;
01761          }
01762       } else if (!strcasecmp(ast_var_name(current), "OSPINTIMELIMIT")) {
01763          if (sscanf(ast_var_value(current), "%30d", &result.intimelimit) != 1) {
01764             result.intimelimit = OSP_DEF_TIMELIMIT;
01765          }
01766       } else if (!strcasecmp(ast_var_name(current), "OSPOUTCALLIDTYPES")) {
01767          if (sscanf(ast_var_value(current), "%30d", &callidtypes) != 1) {
01768             callidtypes = OSP_CALLID_UNDEFINED;
01769          }
01770       } else if (!strcasecmp(ast_var_name(current), "OSPRESULTS")) {
01771          if (sscanf(ast_var_value(current), "%30d", &result.numresults) != 1) {
01772             result.numresults = 0;
01773          }
01774       }
01775    }
01776    ast_debug(1, "OSPNext: OSPINHANDLE '%d'\n", result.inhandle);
01777    ast_debug(1, "OSPNext: OSPOUTHANDLE '%d'\n", result.outhandle);
01778    ast_debug(1, "OSPNext: OSPINTIMELIMIT '%d'\n", result.intimelimit);
01779    ast_debug(1, "OSPNext: OSPOUTCALLIDTYPES '%d'\n", callidtypes);
01780    ast_debug(1, "OSPNext: OSPRESULTS '%d'\n", result.numresults);
01781 
01782    if ((res = osp_next(provider, cause, &result)) > 0) {
01783       status = AST_OSP_SUCCESS;
01784    } else {
01785       result.tech[0] = '\0';
01786       result.dest[0] = '\0';
01787       result.called[0] = '\0';
01788       result.calling[0] = '\0';
01789       result.token[0] = '\0';
01790       result.networkid[0] = '\0';
01791       result.numresults = 0;
01792       result.outtimelimit = OSP_DEF_TIMELIMIT;
01793       result.outcallid.buf[0] = '\0';
01794       result.outcallid.len = 0;
01795       if (!res) {
01796          status = AST_OSP_FAILED;
01797       } else {
01798          status = AST_OSP_ERROR;
01799       }
01800    }
01801 
01802    pbx_builtin_setvar_helper(chan, "OSPTECH", result.tech);
01803    ast_debug(1, "OSPNext: OSPTECH '%s'\n", result.tech);
01804    pbx_builtin_setvar_helper(chan, "OSPDEST", result.dest);
01805    ast_debug(1, "OSPNext: OSPDEST '%s'\n", result.dest);
01806    pbx_builtin_setvar_helper(chan, "OSPCALLED", result.called);
01807    ast_debug(1, "OSPNext: OSPCALLED'%s'\n", result.called);
01808    pbx_builtin_setvar_helper(chan, "OSPCALLING", result.calling);
01809    ast_debug(1, "OSPNext: OSPCALLING '%s'\n", result.calling);
01810    pbx_builtin_setvar_helper(chan, "OSPOUTNETWORKID", result.networkid);
01811    ast_debug(1, "OSPLookup: OSPOUTNETWORKID '%s'\n", result.networkid);
01812    pbx_builtin_setvar_helper(chan, "OSPOUTTOKEN", result.token);
01813    ast_debug(1, "OSPNext: OSPOUTTOKEN size '%zd'\n", strlen(result.token));
01814    snprintf(buffer, sizeof(buffer), "%d", result.numresults);
01815    pbx_builtin_setvar_helper(chan, "OSPRESULTS", buffer);
01816    ast_debug(1, "OSPNext: OSPRESULTS '%s'\n", buffer);
01817    snprintf(buffer, sizeof(buffer), "%d", result.outtimelimit);
01818    pbx_builtin_setvar_helper(chan, "OSPOUTTIMELIMIT", buffer);
01819    ast_debug(1, "OSPNext: OSPOUTTIMELIMIT '%s'\n", buffer);
01820    pbx_builtin_setvar_helper(chan, "OSPNEXTSTATUS", status);
01821    ast_debug(1, "OSPNext: %s\n", status);
01822 
01823    if (!strcasecmp(result.tech, OSP_TECH_H323)) {
01824       if ((callidtypes & OSP_CALLID_H323) && (result.outcallid.len != 0)) {
01825          osp_uuid2str(result.outcallid.buf, buffer, sizeof(buffer));
01826       } else {
01827          buffer[0] = '\0';
01828       }
01829       pbx_builtin_setvar_helper(chan, "OSPOUTCALLID", buffer);
01830       snprintf(buffer, sizeof(buffer), "%s/%s@%s", result.tech, result.called, result.dest);
01831       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
01832    } else if (!strcasecmp(result.tech, OSP_TECH_SIP)) {
01833       snprintf(buffer, sizeof(buffer), "%s/%s@%s", result.tech, result.called, result.dest);
01834       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
01835       if (!ast_strlen_zero(result.token)) {
01836          snprintf(buffer, sizeof(buffer), "%s%s", OSP_SIP_HEADER, result.token);
01837          pbx_builtin_setvar_helper(chan, "_SIPADDHEADER", buffer);
01838          ast_debug(1, "OSPLookup: SIPADDHEADER size '%zd'\n", strlen(buffer));
01839       }
01840    } else if (!strcasecmp(result.tech, OSP_TECH_IAX)) {
01841       snprintf(buffer, sizeof(buffer), "%s/%s/%s", result.tech, result.dest, result.called);
01842       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
01843    }
01844 
01845    if(res <= 0) {
01846       res = -1;
01847    } else {
01848       res = 0;
01849    }
01850 
01851    return res;
01852 }

static int reload ( void   )  [static]

Definition at line 2204 of file app_osplookup.c.

References osp_load().

02205 {
02206    osp_load(1);
02207 
02208    return 0;
02209 }

static int unload_module ( void   )  [static]

Definition at line 2190 of file app_osplookup.c.

References ast_cli_unregister_multiple(), ast_unregister_application(), and osp_unload().

02191 {
02192    int res;
02193 
02194    res = ast_unregister_application(app4);
02195    res |= ast_unregister_application(app3);
02196    res |= ast_unregister_application(app2);
02197    res |= ast_unregister_application(app1);
02198    ast_cli_unregister_multiple(cli_osp, sizeof(cli_osp) / sizeof(struct ast_cli_entry));
02199    osp_unload();
02200 
02201    return res;
02202 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Open Settlement Protocol Applications" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } [static]

Definition at line 2215 of file app_osplookup.c.

const char app1[] = "OSPAuth" [static]

Definition at line 2159 of file app_osplookup.c.

Referenced by app_cmp().

const char app2[] = "OSPLookup" [static]

Definition at line 2162 of file app_osplookup.c.

const char app3[] = "OSPNext" [static]

Definition at line 2165 of file app_osplookup.c.

const char app4[] = "OSPFinish" [static]

Definition at line 2168 of file app_osplookup.c.

Definition at line 2215 of file app_osplookup.c.

const char* B64CACert = "MIIBYDCCAQoCAQEwDQYJKoZIhvcNAQEEBQAwOzElMCMGA1UEAxMcb3NwdGVzdHNlcnZlci50cmFuc25leHVzLmNvbTESMBAGA1UEChMJT1NQU2VydmVyMB4XDTAyMDIwNDE4MjU1MloXDTEyMDIwMzE4MjU1MlowOzElMCMGA1UEAxMcb3NwdGVzdHNlcnZlci50cmFuc25leHVzLmNvbTESMBAGA1UEChMJT1NQU2VydmVyMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAPGeGwV41EIhX0jEDFLRXQhDEr50OUQPq+f55VwQd0TQNts06BP29+UiNdRW3c3IRHdZcJdC1Cg68ME9cgeq0h8CAwEAATANBgkqhkiG9w0BAQQFAANBAGkzBSj1EnnmUxbaiG1N4xjIuLAWydun7o3bFk2tV8dBIhnuh445obYyk1EnQ27kI7eACCILBZqi2MHDOIMnoN0="

Definition at line 331 of file app_osplookup.c.

const char* B64LCert = "MIIBeTCCASMCEHqkOHVRRWr+1COq3CR/xsowDQYJKoZIhvcNAQEEBQAwOzElMCMGA1UEAxMcb3NwdGVzdHNlcnZlci50cmFuc25leHVzLmNvbTESMBAGA1UEChMJT1NQU2VydmVyMB4XDTA1MDYyMzAwMjkxOFoXDTA2MDYyNDAwMjkxOFowRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQCvLeZfj1G0wuJb8JTcVeZaZftncEmRluOnaME3ustd918lRMDYokZmtmDZN8SrP0yd1pfVqZ7NkmBACbBX0k7pAgMBAAEwDQYJKoZIhvcNAQEEBQADQQDnV8QNFVVJx/+7IselU0wsepqMurivXZzuxOmTEmTVDzCJx1xhA8jd3vGAj7XDIYiPub1PV23eY5a2ARJuw5w9"

Definition at line 330 of file app_osplookup.c.

const char* B64PKey = "MIIBOgIBAAJBAK8t5l+PUbTC4lvwlNxV5lpl+2dwSZGW46dowTe6y133XyVEwNiiRma2YNk3xKs/TJ3Wl9Wpns2SYEAJsFfSTukCAwEAAQJAPz13vCm2GmZ8Zyp74usTxLCqSJZNyMRLHQWBM0g44Iuy4wE3vpi7Wq+xYuSOH2mu4OddnxswCP4QhaXVQavTAQIhAOBVCKXtppEw9UaOBL4vW0Ed/6EA/1D8hDW6St0h7EXJAiEAx+iRmZKhJD6VT84dtX5ZYNVk3j3dAcIOovpzUj9a0CECIEduTCapmZQ5xqAEsLXuVlxRtQgLTUD4ZxDElPn8x0MhAiBE2HlcND0+qDbvtwJQQOUzDgqg5xk3w8capboVdzAlQQIhAMC+lDL7+gDYkNAft5Mu+NObJmQs4Cr+DkDFsKqoxqrm"

Definition at line 329 of file app_osplookup.c.

struct ast_cli_entry cli_osp[] [static]

Initial value:

 {
   AST_CLI_DEFINE(handle_cli_osp_show, "Displays OSF information")
}

Definition at line 2170 of file app_osplookup.c.

int osp_hardware = 0 [static]

Definition at line 323 of file app_osplookup.c.

int osp_initialized = 0 [static]

Definition at line 322 of file app_osplookup.c.

int osp_security = 0 [static]

Definition at line 324 of file app_osplookup.c.

unsigned int osp_tokenformat = TOKEN_ALGO_SIGNED [static]

Definition at line 326 of file app_osplookup.c.

ast_mutex_t osplock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) [static]

struct osp_provider* ospproviders = NULL [static]

Definition at line 325 of file app_osplookup.c.


Generated on Wed Oct 28 13:31:31 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6