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_headers
struct  osp_metrics
struct  osp_npdata
struct  osp_provider
struct  osp_results

Defines

#define OSP_AST_ERROR   ((int)-1)
#define OSP_AST_OK   ((int)0)
#define OSP_AUDIT_URL   ((const char*)"localhost")
#define OSP_CALLID_H323   ((unsigned int)(1 << 1))
#define OSP_CALLID_IAX   ((unsigned int)(1 << 2))
#define OSP_CALLID_MAXNUM   ((unsigned int)3)
#define OSP_CALLID_SIP   ((unsigned int)(1 << 0))
#define OSP_CALLID_UNDEF   ((unsigned int)0)
#define OSP_CONFIG_FILE   ((const char*)"osp.conf")
#define OSP_CUSTOMER_ID   ((const char*)"")
#define OSP_DEF_AUTHPOLICY   OSP_AUTH_YES
#define OSP_DEF_FLOATSTATS   ((float)-1)
#define OSP_DEF_INTSTATS   ((int)-1)
#define OSP_DEF_MAXCONNECT   ((unsigned int)20)
#define OSP_DEF_MAXDESTS   ((unsigned int)12)
#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_SRVTYPE   OSP_SRV_VOICE
#define OSP_DEF_TIMELIMIT   ((unsigned int)0)
#define OSP_DEF_TIMEOUT   ((unsigned int)500)
#define OSP_DEF_WORKMODE   OSP_MODE_DIRECT
#define OSP_DEVICE_ID   ((const char*)"")
#define OSP_ERROR   ((int)-1)
#define OSP_FAILED   ((int)0)
#define OSP_GENERAL_CAT   ((const char*)"general")
#define OSP_HTTP_PERSISTENCE   ((int)1)
#define OSP_INVALID_HANDLE   ((int)-1)
#define OSP_LOCAL_VALIDATION   ((int)1)
#define OSP_MAX_CERTS   ((unsigned int)10)
#define OSP_MAX_CUSTOMINFO   ((unsigned int)8)
#define OSP_MAX_MAXCONNECT   ((unsigned int)1000)
#define OSP_MAX_RETRYDELAY   ((unsigned int)10)
#define OSP_MAX_RETRYLIMIT   ((unsigned int)100)
#define OSP_MAX_SPOINTS   ((unsigned int)10)
#define OSP_MAX_TIMEOUT   ((unsigned int)10000)
#define OSP_MIN_MAXCONNECT   ((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_OK   ((int)1)
#define OSP_PROT_H323   ((const char*)"H323")
#define OSP_PROT_IAX   ((const char*)"IAX")
#define OSP_PROT_SIP   ((const char*)"SIP")
#define OSP_PROT_SKYPE   ((const char*)"SKYPE")
#define OSP_SIP_HEADER   ((const char*)"P-OSP-Auth-Token")
#define OSP_SIZE_INTSTR   ((unsigned int)16)
#define OSP_SIZE_KEYSTR   ((unsigned int)1024)
#define OSP_SIZE_NORSTR   ((unsigned int)256)
#define OSP_SIZE_QOSSTR   ((unsigned int)1024)
#define OSP_SIZE_TECHSTR   ((unsigned int)32)
#define OSP_SIZE_TOKSTR   ((unsigned int)4096)
#define OSP_SIZE_UUID   ((unsigned int)16)
#define OSP_SIZE_UUIDSTR   ((unsigned int)36)
#define OSP_SSL_LIFETIME   ((unsigned int)300)
#define OSP_TECH_H323   ((const char*)"H323")
#define OSP_TECH_IAX   ((const char*)"IAX2")
#define OSP_TECH_SIP   ((const char*)"SIP")
#define OSP_TECH_SKYPE   ((const char*)"SKYPE")

Enumerations

enum  osp_authpolicy { OSP_AUTH_NO = 0, OSP_AUTH_YES, OSP_AUTH_EXC }
enum  osp_callleg { OSP_CALL_INBOUND, OSP_CALL_OUTBOUND }
enum  osp_direction { OSP_DIR_RX = 0, OSP_DIR_TX, OSP_DIR_NUMBER }
enum  osp_srvtype { OSP_SRV_VOICE = 0, OSP_SRV_NPQUERY }
enum  osp_workmode { OSP_MODE_DIRECT = 0, OSP_MODE_INDIRECT }

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 *name, int *trans, 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 *calling, const char *called, const char *destination, unsigned int tokenlen, const char *token, OSPEFAILREASON *reason, struct osp_results *results)
 Choose min duration limit.
static unsigned int osp_choose_timelimit (unsigned int in, unsigned int out)
 Choose min duration limit.
static void osp_convert_inout (const char *src, char *dest, unsigned int destsize)
 Convert "address:port" to "[x.x.x.x]:port" or "hostname:port" format.
static void osp_convert_outin (const char *src, char *dest, unsigned int destsize)
 Convert "[x.x.x.x]:port" or "hostname:prot" to "address:port" 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 *name)
 Create OSP provider handle according to configuration.
static int osp_create_transaction (const char *name, int *trans, char *source, unsigned int srcsize)
 Create OSP transaction handle.
static int osp_create_uuid (unsigned char *uuid, unsigned int *bufsize)
 Create a UUID.
static int osp_finish (int trans, int recorded, int cause, time_t start, time_t connect, time_t end, unsigned int release, const char *inqos, const char *outqos)
 OSP Finish function.
static int osp_get_provider (const char *name, struct osp_provider **provider)
 Get OSP provider by name.
static float osp_get_varfloat (const char *vstr)
 Get float from variable string.
static int osp_get_varint (const char *vstr)
 Get integer from variable string.
static int osp_load (int reload)
static int osp_lookup (const char *name, unsigned int callidtypes, const char *actualsrc, const char *srcdev, const char *calling, const char *called, const char *snetid, struct osp_npdata *np, struct osp_headers *headers, const char *cinfo[], struct osp_results *results)
 OSP Lookup function.
static int osp_next (const char *name, int cause, struct osp_results *results)
 OSP Lookup Next function.
static int osp_report_qos (int trans, enum osp_callleg leg, const char *qos)
 Report QoS.
static int osp_unload (void)
static int osp_uuid2str (unsigned char *uuid, char *buffer, unsigned int bufsize)
 UUID to string.
static int osp_validate_token (int trans, 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, .support_level = AST_MODULE_SUPPORT_EXTENDED, .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 ast_mutex_t osp_lock = { PTHREAD_MUTEX_INITIALIZER , NULL, 1 }
static struct osp_providerosp_providers = NULL
static int osp_security = 0
static unsigned int osp_tokenformat = TOKEN_ALGO_SIGNED


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_AST_ERROR   ((int)-1)

Definition at line 497 of file app_osplookup.c.

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

#define OSP_AST_OK   ((int)0)

Definition at line 496 of file app_osplookup.c.

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

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

Definition at line 517 of file app_osplookup.c.

Referenced by osp_create_provider().

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

Definition at line 454 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 455 of file app_osplookup.c.

Referenced by osp_create_callid(), and osplookup_exec().

#define OSP_CALLID_MAXNUM   ((unsigned int)3)

Definition at line 456 of file app_osplookup.c.

Referenced by osp_lookup().

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

Definition at line 453 of file app_osplookup.c.

Referenced by osp_create_callid(), and osplookup_exec().

#define OSP_CALLID_UNDEF   ((unsigned int)0)

Definition at line 452 of file app_osplookup.c.

Referenced by osplookup_exec(), and ospnext_exec().

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

Definition at line 499 of file app_osplookup.c.

Referenced by osp_load().

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

Definition at line 521 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_AUTHPOLICY   OSP_AUTH_YES

Definition at line 516 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_FLOATSTATS   ((float)-1)

Definition at line 530 of file app_osplookup.c.

Referenced by osp_get_varfloat(), and osp_report_qos().

#define OSP_DEF_INTSTATS   ((int)-1)

Definition at line 529 of file app_osplookup.c.

Referenced by osp_finish(), osp_get_varint(), and osp_report_qos().

#define OSP_DEF_MAXCONNECT   ((unsigned int)20)

Definition at line 504 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_MAXDESTS   ((unsigned int)12)

Definition at line 523 of file app_osplookup.c.

Referenced by osp_lookup().

#define OSP_DEF_PROTOCOL   OSP_PROT_SIP

Definition at line 525 of file app_osplookup.c.

Referenced by osp_create_provider().

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

Definition at line 501 of file app_osplookup.c.

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

#define OSP_DEF_RETRYDELAY   ((unsigned int)0)

Definition at line 507 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_RETRYLIMIT   ((unsigned int)2)

Definition at line 510 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_SRVTYPE   OSP_SRV_VOICE

Definition at line 527 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 513 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_DEF_WORKMODE   OSP_MODE_DIRECT

Definition at line 526 of file app_osplookup.c.

Referenced by osp_create_provider().

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

Definition at line 522 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_ERROR   ((int)-1)

#define OSP_FAILED   ((int)0)

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

Definition at line 500 of file app_osplookup.c.

Referenced by osp_load().

#define OSP_HTTP_PERSISTENCE   ((int)1)

Definition at line 520 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_INVALID_HANDLE   ((int)-1)

#define OSP_LOCAL_VALIDATION   ((int)1)

Definition at line 518 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_CERTS   ((unsigned int)10)

Definition at line 502 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_CUSTOMINFO   ((unsigned int)8)

Definition at line 528 of file app_osplookup.c.

Referenced by osp_lookup(), and osplookup_exec().

#define OSP_MAX_MAXCONNECT   ((unsigned int)1000)

Definition at line 506 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_RETRYDELAY   ((unsigned int)10)

Definition at line 509 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_RETRYLIMIT   ((unsigned int)100)

Definition at line 512 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_SPOINTS   ((unsigned int)10)

Definition at line 503 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MAX_TIMEOUT   ((unsigned int)10000)

Definition at line 515 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MIN_MAXCONNECT   ((unsigned int)1)

Definition at line 505 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MIN_RETRYDELAY   ((unsigned int)0)

Definition at line 508 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MIN_RETRYLIMIT   ((unsigned int)0)

Definition at line 511 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_MIN_TIMEOUT   ((unsigned int)200)

Definition at line 514 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_OK   ((int)1)

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

Definition at line 460 of file app_osplookup.c.

Referenced by osp_create_provider().

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

Definition at line 461 of file app_osplookup.c.

Referenced by osp_create_provider().

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

Definition at line 459 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_PROT_SKYPE   ((const char*)"SKYPE")

Definition at line 462 of file app_osplookup.c.

Referenced by osp_create_provider().

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

Definition at line 471 of file app_osplookup.c.

Referenced by osplookup_exec(), and ospnext_exec().

#define OSP_SIZE_INTSTR   ((unsigned int)16)

Definition at line 442 of file app_osplookup.c.

Referenced by ospauth_exec(), and ospfinished_exec().

#define OSP_SIZE_KEYSTR   ((unsigned int)1024)

Definition at line 444 of file app_osplookup.c.

Referenced by osp_create_provider().

#define OSP_SIZE_NORSTR   ((unsigned int)256)

#define OSP_SIZE_QOSSTR   ((unsigned int)1024)

Definition at line 449 of file app_osplookup.c.

Referenced by ospfinished_exec().

#define OSP_SIZE_TECHSTR   ((unsigned int)32)

Definition at line 446 of file app_osplookup.c.

#define OSP_SIZE_TOKSTR   ((unsigned int)4096)

#define OSP_SIZE_UUID   ((unsigned int)16)

Definition at line 447 of file app_osplookup.c.

Referenced by osp_create_uuid().

#define OSP_SIZE_UUIDSTR   ((unsigned int)36)

Definition at line 448 of file app_osplookup.c.

Referenced by osp_uuid2str().

#define OSP_SSL_LIFETIME   ((unsigned int)300)

Definition at line 519 of file app_osplookup.c.

Referenced by osp_create_provider().

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

Definition at line 466 of file app_osplookup.c.

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

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

Definition at line 467 of file app_osplookup.c.

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

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

Definition at line 465 of file app_osplookup.c.

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

#define OSP_TECH_SKYPE   ((const char*)"SKYPE")

Definition at line 468 of file app_osplookup.c.

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


Enumeration Type Documentation

Enumerator:
OSP_AUTH_NO 
OSP_AUTH_YES 
OSP_AUTH_EXC 

Definition at line 474 of file app_osplookup.c.

00474                     {
00475    OSP_AUTH_NO = 0,  /* Accept any call */
00476    OSP_AUTH_YES,     /* Accept call with valid OSP token or without OSP token */
00477    OSP_AUTH_EXC      /* Only accept call with valid OSP token */
00478 };

Enumerator:
OSP_CALL_INBOUND 
OSP_CALL_OUTBOUND 

Definition at line 599 of file app_osplookup.c.

00599                  {
00600    OSP_CALL_INBOUND, /* Inbound call leg */
00601    OSP_CALL_OUTBOUND /* Outbound call leg */
00602 };

Enumerator:
OSP_DIR_RX 
OSP_DIR_TX 
OSP_DIR_NUMBER 

Definition at line 605 of file app_osplookup.c.

00605                    {
00606    OSP_DIR_RX = 0,      /* Receive */
00607    OSP_DIR_TX,       /* Send */
00608    OSP_DIR_NUMBER    /* Number of directions */
00609 };

Enumerator:
OSP_SRV_VOICE 
OSP_SRV_NPQUERY 

Definition at line 487 of file app_osplookup.c.

00487                  {
00488    OSP_SRV_VOICE = 0,   /* Normal voice service */
00489    OSP_SRV_NPQUERY      /* Ported number query service */
00490 };

Enumerator:
OSP_MODE_DIRECT 
OSP_MODE_INDIRECT 

Definition at line 481 of file app_osplookup.c.

00481                   {
00482    OSP_MODE_DIRECT= 0,  /* Direct */
00483    OSP_MODE_INDIRECT /* Indirect */
00484 };


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 3167 of file app_osplookup.c.

static void __unreg_module ( void   )  [static]

Definition at line 3167 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 1310 of file app_osplookup.c.

Referenced by osp_finish(), and osp_next().

01312 {
01313    return (OSPEFAILREASON)cause;
01314 }

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

Definition at line 3019 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::canum, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, osp_provider::defprotocol, ast_cli_args::fd, osp_provider::handle, osp_provider::localcert, osp_provider::maxconnect, osp_provider::name, name, osp_provider::next, NULL, osp_lock, osp_provider::privatekey, osp_provider::retrydelay, osp_provider::retrylimit, osp_provider::source, osp_provider::spnum, osp_provider::spoints, osp_provider::srvtype, osp_provider::timeout, ast_cli_entry::usage, and osp_provider::workmode.

03020 {
03021    int i;
03022    int found = 0;
03023    struct osp_provider* provider;
03024    const char* name = NULL;
03025    const char* tokenalgo;
03026 
03027    switch (cmd) {
03028    case CLI_INIT:
03029       e->command = "osp show";
03030       e->usage =
03031          "Usage: osp show\n"
03032          "       Displays information on Open Settlement Protocol support\n";
03033       return NULL;
03034    case CLI_GENERATE:
03035       return NULL;
03036    }
03037 
03038    if ((a->argc < 2) || (a->argc > 3)) {
03039       return CLI_SHOWUSAGE;
03040    }
03041 
03042    if (a->argc > 2) {
03043       name = a->argv[2];
03044    }
03045 
03046    if (!name) {
03047       switch (osp_tokenformat) {
03048       case TOKEN_ALGO_BOTH:
03049          tokenalgo = "Both";
03050          break;
03051       case TOKEN_ALGO_UNSIGNED:
03052          tokenalgo = "Unsigned";
03053          break;
03054       case TOKEN_ALGO_SIGNED:
03055       default:
03056          tokenalgo = "Signed";
03057          break;
03058       }
03059       ast_cli(a->fd, "OSP: %s/%s/%s/%s\n",
03060          osp_initialized ? "Initialized" : "Uninitialized",
03061          osp_hardware ? "Accelerated" : "Normal",
03062          osp_security ? "Enabled" : "Disabled",
03063          tokenalgo);
03064    }
03065 
03066    ast_mutex_lock(&osp_lock);
03067    for (provider = osp_providers; provider; provider = provider->next) {
03068       if (!name || !strcasecmp(provider->name, name)) {
03069          if (found) {
03070             ast_cli(a->fd, "\n");
03071          }
03072          ast_cli(a->fd, " == OSP Provider '%s' == \n", provider->name);
03073          if (osp_security) {
03074             ast_cli(a->fd, "Local Private Key: %s\n", provider->privatekey);
03075             ast_cli(a->fd, "Local Certificate: %s\n", provider->localcert);
03076             for (i = 0; i < provider->canum; i++) {
03077                ast_cli(a->fd, "CA Certificate %d:  %s\n", i + 1, provider->cacerts[i]);
03078             }
03079          }
03080          for (i = 0; i < provider->spnum; i++) {
03081             ast_cli(a->fd, "Service Point %d:   %s\n", i + 1, provider->spoints[i]);
03082          }
03083          ast_cli(a->fd, "Max Connections:   %d\n", provider->maxconnect);
03084          ast_cli(a->fd, "Retry Delay:       %d seconds\n", provider->retrydelay);
03085          ast_cli(a->fd, "Retry Limit:       %d\n", provider->retrylimit);
03086          ast_cli(a->fd, "Timeout:           %d milliseconds\n", provider->timeout);
03087          ast_cli(a->fd, "Source:            %s\n", strlen(provider->source) ? provider->source : "<unspecified>");
03088          ast_cli(a->fd, "Auth Policy        %d\n", provider->authpolicy);
03089          ast_cli(a->fd, "Default protocol   %s\n", provider->defprotocol);
03090          ast_cli(a->fd, "Work mode          %d\n", provider->workmode);
03091          ast_cli(a->fd, "Service type       %d\n", provider->srvtype);
03092          ast_cli(a->fd, "OSP Handle:        %d\n", provider->handle);
03093          found++;
03094       }
03095    }
03096    ast_mutex_unlock(&osp_lock);
03097 
03098    if (!found) {
03099       if (name) {
03100          ast_cli(a->fd, "Unable to find OSP provider '%s'\n", name);
03101       } else {
03102          ast_cli(a->fd, "No OSP providers configured\n");
03103       }
03104    }
03105 
03106    return CLI_SUCCESS;
03107 }

static int load_module ( void   )  [static]

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

OSP Authentication function.

Parameters:
name OSP provider context name
trans 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:
OSP_OK Authenricated, OSP_FAILED Unauthenticated, OSP_ERROR Error

Definition at line 1327 of file app_osplookup.c.

References ast_debug, ast_log, ast_strlen_zero, osp_provider::authpolicy, LOG_ERROR, NULL, OSP_AUTH_EXC, OSP_AUTH_NO, OSP_AUTH_YES, osp_create_transaction(), OSP_DEF_TIMELIMIT, OSP_ERROR, OSP_FAILED, osp_get_provider(), OSP_INVALID_HANDLE, OSP_OK, OSP_SIZE_NORSTR, and osp_validate_token().

Referenced by ospauth_exec().

01335 {
01336    int res;
01337    struct osp_provider* provider = NULL;
01338    char dest[OSP_SIZE_NORSTR];
01339 
01340    if ((trans == NULL) || (timelimit == NULL)) {
01341       ast_log(LOG_ERROR, "Invalid parameters\n");
01342       return OSP_ERROR;
01343    }
01344 
01345    *trans = OSP_INVALID_HANDLE;
01346    *timelimit = OSP_DEF_TIMELIMIT;
01347 
01348    if ((res = osp_get_provider(name, &provider)) <= 0) {
01349       ast_debug(1, "OSP: Unabe to find OSP provider '%s'\n", name);
01350       return res;
01351    }
01352 
01353    switch (provider->authpolicy) {
01354    case OSP_AUTH_NO:
01355       res = OSP_OK;
01356       break;
01357    case OSP_AUTH_EXC:
01358       if (ast_strlen_zero(token)) {
01359          res = OSP_FAILED;
01360       } else if ((res = osp_create_transaction(name, trans, dest, sizeof(dest))) <= 0) {
01361          ast_debug(1, "OSP: Unable to generate transaction handle\n");
01362          *trans = OSP_INVALID_HANDLE;
01363          res = OSP_FAILED;
01364       } else if((res = osp_validate_token(*trans, source, dest, calling, called, token, timelimit)) <= 0) {
01365          OSPPTransactionRecordFailure(*trans, OSPC_FAIL_CALL_REJECTED);
01366       }
01367       break;
01368    case OSP_AUTH_YES:
01369    default:
01370       if (ast_strlen_zero(token)) {
01371          res = OSP_OK;
01372       } else if ((res = osp_create_transaction(name, trans, dest, sizeof(dest))) <= 0) {
01373          ast_debug(1, "OSP: Unable to generate transaction handle\n");
01374          *trans = OSP_INVALID_HANDLE;
01375          res = OSP_FAILED;
01376       } else if((res = osp_validate_token(*trans, source, dest, calling, called, token, timelimit)) <= 0) {
01377          OSPPTransactionRecordFailure(*trans, OSPC_FAIL_CALL_REJECTED);
01378       }
01379       break;
01380    }
01381 
01382    return res;
01383 }

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

Choose min duration limit.

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

Definition at line 1168 of file app_osplookup.c.

References ast_base64encode(), ast_copy_string(), ast_debug, ast_log, osp_results::called, osp_results::calling, osp_provider::defprotocol, osp_results::dest, enabled, error(), LOG_ERROR, LOG_WARNING, osp_results::networkid, osp_results::npcic, osp_results::npdi, osp_results::nprn, NULL, osp_results::opname, osp_convert_outin(), OSP_ERROR, OSP_FAILED, OSP_OK, OSP_SIZE_NORSTR, OSP_TECH_H323, OSP_TECH_IAX, OSP_TECH_SIP, OSP_TECH_SKYPE, osp_results::outhandle, osp_results::outtech, osp_results::token, and type.

Referenced by osp_lookup(), and osp_next().

01177 {
01178    int res;
01179    OSPE_DEST_OSPENABLED enabled;
01180    OSPE_PROTOCOL_NAME protocol;
01181    char dest[OSP_SIZE_NORSTR];
01182    OSPE_OPERATOR_NAME type;
01183    int error;
01184 
01185    if ((provider == NULL) || (reason == NULL) || (results == NULL)) {
01186       ast_log(LOG_ERROR, "Invalid parameters\n");
01187       return OSP_ERROR;
01188    }
01189 
01190    if ((error = OSPPTransactionIsDestOSPEnabled(results->outhandle, &enabled)) != OSPC_ERR_NO_ERROR) {
01191       ast_debug(1, "OSP: Unable to get destination OSP version, error '%d'\n", error);
01192       *reason = OSPC_FAIL_NORMAL_UNSPECIFIED;
01193       return OSP_ERROR;
01194    }
01195 
01196    if (enabled == OSPC_DOSP_FALSE) {
01197       results->token[0] = '\0';
01198    } else {
01199       ast_base64encode(results->token, (const unsigned char*)token, tokenlen, sizeof(results->token) - 1);
01200    }
01201 
01202    if ((error = OSPPTransactionGetDestinationNetworkId(results->outhandle, sizeof(results->networkid), results->networkid)) != OSPC_ERR_NO_ERROR) {
01203       ast_debug(1, "OSP: Unable to get destination network ID, error '%d'\n", error);
01204       results->networkid[0] = '\0';
01205    }
01206 
01207    error = OSPPTransactionGetNumberPortabilityParameters(results->outhandle,
01208       sizeof(results->nprn),
01209       results->nprn,
01210       sizeof(results->npcic),
01211       results->npcic,
01212       &results->npdi);
01213    if (error != OSPC_ERR_NO_ERROR) {
01214       ast_debug(1, "OSP: Unable to get number portability parameters, error '%d'\n", error);
01215       results->nprn[0] = '\0';
01216       results->npcic[0] = '\0';
01217       results->npdi = 0;
01218    }
01219 
01220    for (type = OSPC_OPNAME_START; type < OSPC_OPNAME_NUMBER; type++) {
01221       error = OSPPTransactionGetOperatorName(results->outhandle, type, sizeof(results->opname[type]), results->opname[type]);
01222       if (error != OSPC_ERR_NO_ERROR) {
01223          ast_debug(1, "OSP: Unable to get operator name of type '%d', error '%d'\n", type, error);
01224          results->opname[type][0] = '\0';
01225       }
01226    }
01227 
01228    if ((error = OSPPTransactionGetDestProtocol(results->outhandle, &protocol)) != OSPC_ERR_NO_ERROR) {
01229       ast_debug(1, "OSP: Unable to get destination protocol, error '%d'\n", error);
01230       *reason = OSPC_FAIL_NORMAL_UNSPECIFIED;
01231       results->token[0] = '\0';
01232       results->networkid[0] = '\0';
01233       results->nprn[0] = '\0';
01234       results->npcic[0] = '\0';
01235       results->npdi = 0;
01236       for (type = OSPC_OPNAME_START; type < OSPC_OPNAME_NUMBER; type++) {
01237          results->opname[type][0] = '\0';
01238       }
01239       return OSP_ERROR;
01240    }
01241 
01242    res = OSP_OK;
01243    osp_convert_outin(destination, dest, sizeof(dest));
01244    switch(protocol) {
01245    case OSPC_PROTNAME_SIP:
01246       ast_debug(1, "OSP: protocol SIP\n");
01247       ast_copy_string(results->outtech, OSP_TECH_SIP, sizeof(results->outtech));
01248       ast_copy_string(results->dest, dest, sizeof(results->dest));
01249       ast_copy_string(results->calling, calling, sizeof(results->calling));
01250       ast_copy_string(results->called, called, sizeof(results->called));
01251       break;
01252    case OSPC_PROTNAME_Q931:
01253       ast_debug(1, "OSP: protocol Q.931\n");
01254       ast_copy_string(results->outtech, OSP_TECH_H323, sizeof(results->outtech));
01255       ast_copy_string(results->dest, dest, sizeof(results->dest));
01256       ast_copy_string(results->calling, calling, sizeof(results->calling));
01257       ast_copy_string(results->called, called, sizeof(results->called));
01258       break;
01259    case OSPC_PROTNAME_IAX:
01260       ast_debug(1, "OSP: protocol IAX\n");
01261       ast_copy_string(results->outtech, OSP_TECH_IAX, sizeof(results->outtech));
01262       ast_copy_string(results->dest, dest, sizeof(results->dest));
01263       ast_copy_string(results->calling, calling, sizeof(results->calling));
01264       ast_copy_string(results->called, called, sizeof(results->called));
01265       break;
01266    case OSPC_PROTNAME_SKYPE:
01267       ast_debug(1, "OSP: protocol Skype\n");
01268       ast_copy_string(results->outtech, OSP_TECH_SKYPE, sizeof(results->outtech));
01269       ast_copy_string(results->dest, dest, sizeof(results->dest));
01270       ast_copy_string(results->calling, calling, sizeof(results->calling));
01271       ast_copy_string(results->called, called, sizeof(results->called));
01272       break;
01273    case OSPC_PROTNAME_UNDEFINED:
01274    case OSPC_PROTNAME_UNKNOWN:
01275       ast_debug(1, "OSP: unknown/undefined protocol '%d'\n", protocol);
01276       ast_debug(1, "OSP: use default protocol '%s'\n", provider->defprotocol);
01277       ast_copy_string(results->outtech, provider->defprotocol, sizeof(results->outtech));
01278       ast_copy_string(results->dest, dest, sizeof(results->dest));
01279       ast_copy_string(results->calling, calling, sizeof(results->calling));
01280       ast_copy_string(results->called, called, sizeof(results->called));
01281       break;
01282    case OSPC_PROTNAME_LRQ:
01283    case OSPC_PROTNAME_T37:
01284    case OSPC_PROTNAME_T38:
01285    case OSPC_PROTNAME_SMPP:
01286    case OSPC_PROTNAME_XMPP:
01287    default:
01288       ast_log(LOG_WARNING, "OSP: unsupported protocol '%d'\n", protocol);
01289       *reason = OSPC_FAIL_PROTOCOL_ERROR;
01290       results->token[0] = '\0';
01291       results->networkid[0] = '\0';
01292       results->nprn[0] = '\0';
01293       results->npcic[0] = '\0';
01294       results->npdi = 0;
01295       for (type = OSPC_OPNAME_START; type < OSPC_OPNAME_NUMBER; type++) {
01296          results->opname[type][0] = '\0';
01297       }
01298       res = OSP_FAILED;
01299       break;
01300    }
01301 
01302    return res;
01303 }

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 1143 of file app_osplookup.c.

References OSP_DEF_TIMELIMIT.

Referenced by osp_lookup(), and osp_next().

01146 {
01147    if (in == OSP_DEF_TIMELIMIT) {
01148       return out;
01149    } else if (out == OSP_DEF_TIMELIMIT) {
01150       return in;
01151    } else {
01152       return in < out ? in : out;
01153    }
01154 }

static void osp_convert_inout ( const char *  src,
char *  dest,
unsigned int  destsize 
) [static]

Convert "address:port" to "[x.x.x.x]:port" or "hostname:port" format.

Parameters:
src Source address string
dest Destination address string
destsize Size of dest buffer

Definition at line 989 of file app_osplookup.c.

References ast_copy_string(), ast_strlen_zero, NULL, and OSP_SIZE_NORSTR.

Referenced by osp_lookup(), and osp_validate_token().

00993 {
00994    struct in_addr inp;
00995    char buffer[OSP_SIZE_NORSTR];
00996    char* port;
00997 
00998    if ((dest != NULL) && (destsize > 0)) {
00999       if (!ast_strlen_zero(src)) {
01000          ast_copy_string(buffer, src, sizeof(buffer));
01001 
01002          if((port = strchr(buffer, ':')) != NULL) {
01003             *port = '\0';
01004             port++;
01005          }
01006 
01007          if (inet_pton(AF_INET, buffer, &inp) == 1) {
01008             if (port != NULL) {
01009                snprintf(dest, destsize, "[%s]:%s", buffer, port);
01010             } else {
01011                snprintf(dest, destsize, "[%s]", buffer);
01012             }
01013             dest[destsize - 1] = '\0';
01014          } else {
01015             ast_copy_string(dest, src, destsize);
01016          }
01017       } else {
01018          *dest = '\0';
01019       }
01020    }
01021 }

static void osp_convert_outin ( const char *  src,
char *  dest,
unsigned int  destsize 
) [static]

Convert "[x.x.x.x]:port" or "hostname:prot" to "address:port" format.

Parameters:
src Source address string
dest Destination address string
destsize Size of dest buffer

Definition at line 1029 of file app_osplookup.c.

References ast_copy_string(), ast_strlen_zero, end, NULL, and OSP_SIZE_NORSTR.

Referenced by osp_check_destination().

01033 {
01034    char buffer[OSP_SIZE_NORSTR];
01035    char* end;
01036    char* port;
01037 
01038    if ((dest != NULL) && (destsize > 0)) {
01039       if (!ast_strlen_zero(src)) {
01040          ast_copy_string(buffer, src, sizeof(buffer));
01041 
01042          if (buffer[0] == '[') {
01043             if((port = strchr(buffer + 1, ':')) != NULL) {
01044                *port = '\0';
01045                port++;
01046             }
01047 
01048             if ((end = strchr(buffer + 1, ']')) != NULL) {
01049                *end = '\0';
01050             }
01051 
01052             if (port != NULL) {
01053                snprintf(dest, destsize, "%s:%s", buffer + 1, port);
01054                dest[destsize - 1] = '\0';
01055             } else {
01056                ast_copy_string(dest, buffer + 1, destsize);
01057             }
01058          } else {
01059             ast_copy_string(dest, src, destsize);
01060          }
01061       } else {
01062          *dest = '\0';
01063       }
01064    }
01065 }

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:
OSK_OK Created, OSP_FAILED Not create, OSP_ERROR Error

Definition at line 1448 of file app_osplookup.c.

References ast_log, osp_callid::buf, osp_callid::len, LOG_ERROR, NULL, OSP_CALLID_H323, OSP_CALLID_IAX, OSP_CALLID_SIP, osp_create_uuid(), OSP_ERROR, OSP_FAILED, and OSP_OK.

Referenced by osp_lookup().

01451 {
01452    int res;
01453 
01454    if (callid == NULL) {
01455       ast_log(LOG_ERROR, "Invalid parameters\n");
01456       return OSP_ERROR;
01457    }
01458 
01459    callid->len = sizeof(callid->buf);
01460    switch (type) {
01461    case OSP_CALLID_H323:
01462       res = osp_create_uuid(callid->buf, &callid->len);
01463       break;
01464    case OSP_CALLID_SIP:
01465    case OSP_CALLID_IAX:
01466       res = OSP_FAILED;
01467       break;
01468    default:
01469       res = OSP_ERROR;
01470       break;
01471    }
01472 
01473    if ((res != OSP_OK) && (callid->len != 0)) {
01474       callid->buf[0] = '\0';
01475       callid->len = 0;
01476    }
01477 
01478    return res;
01479 }

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

Create OSP provider handle according to configuration.

Parameters:
cfg OSP configuration
name OSP provider context name
Returns:
OSP_OK Success, OSP_FAILED Failed, OSP_ERROR Error

Definition at line 641 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::canum, osp_provider::defprotocol, error(), osp_provider::handle, ast_variable::lineno, osp_provider::localcert, LOG_ERROR, LOG_WARNING, osp_provider::maxconnect, ast_variable::name, osp_provider::name, osp_provider::next, ast_variable::next, NULL, OSP_AUDIT_URL, OSP_AUTH_EXC, OSP_AUTH_NO, OSP_AUTH_YES, OSP_CUSTOMER_ID, OSP_DEF_AUTHPOLICY, OSP_DEF_MAXCONNECT, OSP_DEF_PROTOCOL, OSP_DEF_RETRYDELAY, OSP_DEF_RETRYLIMIT, OSP_DEF_SRVTYPE, OSP_DEF_TIMEOUT, OSP_DEF_WORKMODE, OSP_DEVICE_ID, OSP_ERROR, OSP_FAILED, OSP_HTTP_PERSISTENCE, OSP_INVALID_HANDLE, OSP_LOCAL_VALIDATION, osp_lock, OSP_MAX_CERTS, OSP_MAX_MAXCONNECT, OSP_MAX_RETRYDELAY, OSP_MAX_RETRYLIMIT, OSP_MAX_SPOINTS, OSP_MAX_TIMEOUT, OSP_MIN_MAXCONNECT, OSP_MIN_RETRYDELAY, OSP_MIN_RETRYLIMIT, OSP_MIN_TIMEOUT, OSP_MODE_DIRECT, OSP_MODE_INDIRECT, OSP_OK, OSP_PROT_H323, OSP_PROT_IAX, OSP_PROT_SIP, OSP_PROT_SKYPE, OSP_SIZE_KEYSTR, OSP_SRV_NPQUERY, OSP_SRV_VOICE, OSP_SSL_LIFETIME, osp_provider::privatekey, osp_provider::retrydelay, osp_provider::retrylimit, osp_provider::source, osp_provider::spnum, osp_provider::spoints, osp_provider::srvtype, osp_provider::timeout, ast_variable::value, var, and osp_provider::workmode.

Referenced by osp_load().

00644 {
00645    int res = OSP_FAILED;
00646    struct ast_variable* var;
00647    struct osp_provider* provider;
00648    OSPTPRIVATEKEY privatekey;
00649    OSPT_CERT localcert;
00650    OSPT_CERT cacerts[OSP_MAX_CERTS];
00651    const OSPT_CERT* pcacerts[OSP_MAX_CERTS];
00652    const char* pspoints[OSP_MAX_SPOINTS];
00653    unsigned char privatekeydata[OSP_SIZE_KEYSTR];
00654    unsigned char localcertdata[OSP_SIZE_KEYSTR];
00655    unsigned char cacertdata[OSP_SIZE_KEYSTR];
00656    int i, num, error = OSPC_ERR_NO_ERROR;
00657 
00658    if (!(provider = ast_calloc(1, sizeof(*provider)))) {
00659       ast_log(LOG_ERROR, "Out of memory\n");
00660       return OSP_ERROR;
00661    }
00662 
00663    /* ast_calloc has set 0 in provider */
00664    provider->handle = OSP_INVALID_HANDLE;
00665    ast_copy_string(provider->name, name, sizeof(provider->name));
00666    snprintf(provider->privatekey, sizeof(provider->privatekey), "%s/%s-privatekey.pem", ast_config_AST_KEY_DIR, name);
00667    snprintf(provider->localcert, sizeof(provider->localcert), "%s/%s-localcert.pem", ast_config_AST_KEY_DIR, name);
00668    snprintf(provider->cacerts[0], sizeof(provider->cacerts[0]), "%s/%s-cacert_0.pem", ast_config_AST_KEY_DIR, name);
00669    provider->maxconnect = OSP_DEF_MAXCONNECT;
00670    provider->retrydelay = OSP_DEF_RETRYDELAY;
00671    provider->retrylimit = OSP_DEF_RETRYLIMIT;
00672    provider->timeout = OSP_DEF_TIMEOUT;
00673    provider->authpolicy = OSP_DEF_AUTHPOLICY;
00674    provider->defprotocol = OSP_DEF_PROTOCOL;
00675    provider->workmode = OSP_DEF_WORKMODE;
00676    provider->srvtype = OSP_DEF_SRVTYPE;
00677 
00678    for (var = ast_variable_browse(cfg, name); var != NULL; var = var->next) {
00679       if (!strcasecmp(var->name, "privatekey")) {
00680          if (osp_security) {
00681             if (var->value[0] == '/') {
00682                ast_copy_string(provider->privatekey, var->value, sizeof(provider->privatekey));
00683             } else {
00684                snprintf(provider->privatekey, sizeof(provider->privatekey), "%s/%s", ast_config_AST_KEY_DIR, var->value);
00685             }
00686             ast_debug(1, "OSP: privatekey '%s'\n", provider->privatekey);
00687          }
00688       } else if (!strcasecmp(var->name, "localcert")) {
00689          if (osp_security) {
00690             if (var->value[0] == '/') {
00691                ast_copy_string(provider->localcert, var->value, sizeof(provider->localcert));
00692             } else {
00693                snprintf(provider->localcert, sizeof(provider->localcert), "%s/%s", ast_config_AST_KEY_DIR, var->value);
00694             }
00695             ast_debug(1, "OSP: localcert '%s'\n", provider->localcert);
00696          }
00697       } else if (!strcasecmp(var->name, "cacert")) {
00698          if (osp_security) {
00699             if (provider->canum < OSP_MAX_CERTS) {
00700                if (var->value[0] == '/') {
00701                   ast_copy_string(provider->cacerts[provider->canum], var->value, sizeof(provider->cacerts[provider->canum]));
00702                } else {
00703                   snprintf(provider->cacerts[provider->canum], sizeof(provider->cacerts[provider->canum]), "%s/%s", ast_config_AST_KEY_DIR, var->value);
00704                }
00705                ast_debug(1, "OSP: cacerts[%d]: '%s'\n", provider->canum, provider->cacerts[provider->canum]);
00706                provider->canum++;
00707             } else {
00708                ast_log(LOG_WARNING, "OSP: Too many CA Certificates at line %d\n", var->lineno);
00709             }
00710          }
00711       } else if (!strcasecmp(var->name, "servicepoint")) {
00712          if (provider->spnum < OSP_MAX_SPOINTS) {
00713             ast_copy_string(provider->spoints[provider->spnum], var->value, sizeof(provider->spoints[provider->spnum]));
00714             ast_debug(1, "OSP: servicepoint[%d]: '%s'\n", provider->spnum, provider->spoints[provider->spnum]);
00715             provider->spnum++;
00716          } else {
00717             ast_log(LOG_WARNING, "OSP: Too many Service Points at line %d\n", var->lineno);
00718          }
00719       } else if (!strcasecmp(var->name, "maxconnect")) {
00720          if ((sscanf(var->value, "%30d", &num) == 1) && (num >= OSP_MIN_MAXCONNECT) && (num <= OSP_MAX_MAXCONNECT)) {
00721             provider->maxconnect = num;
00722             ast_debug(1, "OSP: maxconnect '%d'\n", num);
00723          } else {
00724             ast_log(LOG_WARNING, "OSP: maxconnect should be an integer from %d to %d, not '%s' at line %d\n",
00725                OSP_MIN_MAXCONNECT, OSP_MAX_MAXCONNECT, var->value, var->lineno);
00726          }
00727       } else if (!strcasecmp(var->name, "retrydelay")) {
00728          if ((sscanf(var->value, "%30d", &num) == 1) && (num >= OSP_MIN_RETRYDELAY) && (num <= OSP_MAX_RETRYDELAY)) {
00729             provider->retrydelay = num;
00730             ast_debug(1, "OSP: retrydelay '%d'\n", num);
00731          } else {
00732             ast_log(LOG_WARNING, "OSP: retrydelay should be an integer from %d to %d, not '%s' at line %d\n",
00733                OSP_MIN_RETRYDELAY, OSP_MAX_RETRYDELAY, var->value, var->lineno);
00734          }
00735       } else if (!strcasecmp(var->name, "retrylimit")) {
00736          if ((sscanf(var->value, "%30d", &num) == 1) && (num >= OSP_MIN_RETRYLIMIT) && (num <= OSP_MAX_RETRYLIMIT)) {
00737             provider->retrylimit = num;
00738             ast_debug(1, "OSP: retrylimit '%d'\n", num);
00739          } else {
00740             ast_log(LOG_WARNING, "OSP: retrylimit should be an integer from %d to %d, not '%s' at line %d\n",
00741                OSP_MIN_RETRYLIMIT, OSP_MAX_RETRYLIMIT, var->value, var->lineno);
00742          }
00743       } else if (!strcasecmp(var->name, "timeout")) {
00744          if ((sscanf(var->value, "%30d", &num) == 1) && (num >= OSP_MIN_TIMEOUT) && (num <= OSP_MAX_TIMEOUT)) {
00745             provider->timeout = num;
00746             ast_debug(1, "OSP: timeout '%d'\n", num);
00747          } else {
00748             ast_log(LOG_WARNING, "OSP: timeout should be an integer from %d to %d, not '%s' at line %d\n",
00749                OSP_MIN_TIMEOUT, OSP_MAX_TIMEOUT, var->value, var->lineno);
00750          }
00751       } else if (!strcasecmp(var->name, "source")) {
00752          ast_copy_string(provider->source, var->value, sizeof(provider->source));
00753          ast_debug(1, "OSP: source '%s'\n", provider->source);
00754       } else if (!strcasecmp(var->name, "authpolicy")) {
00755          if ((sscanf(var->value, "%30d", &num) == 1) && ((num == OSP_AUTH_NO) || (num == OSP_AUTH_YES) || (num == OSP_AUTH_EXC))) {
00756             provider->authpolicy = num;
00757             ast_debug(1, "OSP: authpolicy '%d'\n", num);
00758          } else {
00759             ast_log(LOG_WARNING, "OSP: authpolicy should be %d, %d or %d, not '%s' at line %d\n",
00760                OSP_AUTH_NO, OSP_AUTH_YES, OSP_AUTH_EXC, var->value, var->lineno);
00761          }
00762       } else if (!strcasecmp(var->name, "defprotocol")) {
00763          if (!strcasecmp(var->value, OSP_PROT_SIP)) {
00764             provider->defprotocol = OSP_PROT_SIP;
00765             ast_debug(1, "OSP: default protocol SIP\n");
00766          } else if (!strcasecmp(var->value, OSP_PROT_H323)) {
00767             provider->defprotocol = OSP_PROT_H323;
00768             ast_debug(1, "OSP: default protocol H.323\n");
00769          } else if (!strcasecmp(var->value, OSP_PROT_IAX)) {
00770             provider->defprotocol = OSP_PROT_IAX;
00771             ast_debug(1, "OSP: default protocol IAX\n");
00772          } else if (!strcasecmp(var->value, OSP_PROT_SKYPE)) {
00773             provider->defprotocol = OSP_PROT_SKYPE;
00774             ast_debug(1, "OSP: default protocol Skype\n");
00775          } else {
00776             ast_log(LOG_WARNING, "OSP: default protocol should be %s, %s, %s or %s not '%s' at line %d\n",
00777                OSP_PROT_SIP, OSP_PROT_H323, OSP_PROT_IAX, OSP_PROT_SKYPE, var->value, var->lineno);
00778          }
00779       } else if (!strcasecmp(var->name, "workmode")) {
00780          if ((sscanf(var->value, "%30d", &num) == 1) && ((num == OSP_MODE_DIRECT) || (num == OSP_MODE_INDIRECT))) {
00781             provider->workmode = num;
00782             ast_debug(1, "OSP: workmode '%d'\n", num);
00783          } else {
00784             ast_log(LOG_WARNING, "OSP: workmode should be %d or %d, not '%s' at line %d\n",
00785                OSP_MODE_DIRECT, OSP_MODE_INDIRECT, var->value, var->lineno);
00786          }
00787       } else if (!strcasecmp(var->name, "servicetype")) {
00788          if ((sscanf(var->value, "%30d", &num) == 1) && ((num == OSP_SRV_VOICE) || (num == OSP_SRV_NPQUERY))) {
00789             provider->srvtype = num;
00790             ast_debug(1, "OSP: servicetype '%d'\n", num);
00791          } else {
00792             ast_log(LOG_WARNING, "OSP: servicetype should be %d or %d, not '%s' at line %d\n",
00793                OSP_SRV_VOICE, OSP_SRV_NPQUERY, var->value, var->lineno);
00794          }
00795       }
00796    }
00797 
00798    if (provider->canum == 0) {
00799       provider->canum = 1;
00800    }
00801 
00802    for (i = 0; i < provider->spnum; i++) {
00803       pspoints[i] = provider->spoints[i];
00804    }
00805 
00806    if (osp_security) {
00807       privatekey.PrivateKeyData = NULL;
00808       privatekey.PrivateKeyLength = 0;
00809 
00810       localcert.CertData = NULL;
00811       localcert.CertDataLength = 0;
00812 
00813       for (i = 0; i < provider->canum; i++) {
00814          cacerts[i].CertData = NULL;
00815          cacerts[i].CertDataLength = 0;
00816       }
00817 
00818       if ((error = OSPPUtilLoadPEMPrivateKey((unsigned char*)provider->privatekey, &privatekey)) != OSPC_ERR_NO_ERROR) {
00819          ast_log(LOG_WARNING, "OSP: Unable to load privatekey '%s', error '%d'\n", provider->privatekey, error);
00820       } else if ((error = OSPPUtilLoadPEMCert((unsigned char*)provider->localcert, &localcert)) != OSPC_ERR_NO_ERROR) {
00821          ast_log(LOG_WARNING, "OSP: Unable to load localcert '%s', error '%d'\n", provider->localcert, error);
00822       } else {
00823          for (i = 0; i < provider->canum; i++) {
00824             if ((error = OSPPUtilLoadPEMCert((unsigned char*)provider->cacerts[i], &cacerts[i])) != OSPC_ERR_NO_ERROR) {
00825                ast_log(LOG_WARNING, "OSP: Unable to load cacert '%s', error '%d'\n", provider->cacerts[i], error);
00826                break;
00827             } else {
00828                pcacerts[i] = &cacerts[i];
00829             }
00830          }
00831       }
00832    } else {
00833       privatekey.PrivateKeyData = privatekeydata;
00834       privatekey.PrivateKeyLength = sizeof(privatekeydata);
00835 
00836       localcert.CertData = localcertdata;
00837       localcert.CertDataLength = sizeof(localcertdata);
00838 
00839       cacerts[0].CertData = cacertdata;
00840       cacerts[0].CertDataLength = sizeof(cacertdata);
00841       pcacerts[0] = &cacerts[0];
00842 
00843       if ((error = OSPPBase64Decode(B64PKey, strlen(B64PKey), privatekey.PrivateKeyData, &privatekey.PrivateKeyLength)) != OSPC_ERR_NO_ERROR) {
00844          ast_log(LOG_WARNING, "OSP: Unable to decode private key, error '%d'\n", error);
00845       } else if ((error = OSPPBase64Decode(B64LCert, strlen(B64LCert), localcert.CertData, &localcert.CertDataLength)) != OSPC_ERR_NO_ERROR) {
00846          ast_log(LOG_WARNING, "OSP: Unable to decode local cert, error '%d'\n", error);
00847       } else if ((error = OSPPBase64Decode(B64CACert, strlen(B64CACert), cacerts[0].CertData, &cacerts[0].CertDataLength)) != OSPC_ERR_NO_ERROR) {
00848          ast_log(LOG_WARNING, "OSP: Unable to decode cacert, error '%d'\n", error);
00849       }
00850    }
00851 
00852    if (error == OSPC_ERR_NO_ERROR) {
00853       error = OSPPProviderNew(provider->spnum,
00854          pspoints,
00855          NULL,
00856          OSP_AUDIT_URL,
00857          &privatekey,
00858          &localcert,
00859          provider->canum,
00860          pcacerts,
00861          OSP_LOCAL_VALIDATION,
00862          OSP_SSL_LIFETIME,
00863          provider->maxconnect,
00864          OSP_HTTP_PERSISTENCE,
00865          provider->retrydelay,
00866          provider->retrylimit,
00867          provider->timeout,
00868          OSP_CUSTOMER_ID,
00869          OSP_DEVICE_ID,
00870          &provider->handle);
00871       if (error != OSPC_ERR_NO_ERROR) {
00872          ast_log(LOG_WARNING, "OSP: Unable to create provider '%s', error '%d'\n", name, error);
00873          res = OSP_ERROR;
00874       } else {
00875          ast_debug(1, "OSP: provider '%s'\n", name);
00876          ast_mutex_lock(&osp_lock);
00877          provider->next = osp_providers;
00878          osp_providers = provider;
00879          ast_mutex_unlock(&osp_lock);
00880          res = OSP_OK;
00881       }
00882    }
00883 
00884    if (osp_security) {
00885       for (i = 0; i < provider->canum; i++) {
00886          if (cacerts[i].CertData) {
00887             ast_free(cacerts[i].CertData);
00888          }
00889       }
00890       if (localcert.CertData) {
00891          ast_free(localcert.CertData);
00892       }
00893       if (privatekey.PrivateKeyData) {
00894          ast_free(privatekey.PrivateKeyData);
00895       }
00896    }
00897 
00898    if (res != OSP_OK) {
00899       ast_free(provider);
00900    }
00901 
00902    return res;
00903 }

static int osp_create_transaction ( const char *  name,
int *  trans,
char *  source,
unsigned int  srcsize 
) [static]

Create OSP transaction handle.

Parameters:
name OSP provider context name
trans OSP transaction handle, output
source Source of provider, output
srcsize Size of source buffer, in
Returns:
OSK_OK Success, OSK_FAILED Failed, OSP_ERROR Error

Definition at line 942 of file app_osplookup.c.

References ast_copy_string(), ast_debug, ast_log, ast_mutex_lock, ast_mutex_unlock, error(), osp_provider::handle, LOG_ERROR, osp_provider::name, osp_provider::next, NULL, OSP_ERROR, OSP_FAILED, OSP_INVALID_HANDLE, osp_lock, OSP_OK, and osp_provider::source.

Referenced by osp_auth(), and osp_lookup().

00947 {
00948    int res = OSP_FAILED;
00949    struct osp_provider* provider;
00950    int error;
00951 
00952    if ((trans == NULL) || (source == NULL) || (srcsize <= 0)) {
00953       ast_log(LOG_ERROR, "Invalid parameters\n");
00954       return OSP_ERROR;
00955    }
00956 
00957    *trans = OSP_INVALID_HANDLE;
00958    *source = '\0';
00959 
00960    ast_mutex_lock(&osp_lock);
00961    for (provider = osp_providers; provider; provider = provider->next) {
00962       if (!strcasecmp(provider->name, name)) {
00963          error = OSPPTransactionNew(provider->handle, trans);
00964          if (error == OSPC_ERR_NO_ERROR) {
00965             ast_debug(1, "OSP: transaction '%d'\n", *trans);
00966             ast_copy_string(source, provider->source, srcsize);
00967             ast_debug(1, "OSP: source '%s'\n", source);
00968             res = OSP_OK;
00969          } else {
00970             *trans = OSP_INVALID_HANDLE;
00971             ast_debug(1, "OSP: Unable to create transaction handle, error '%d'\n", error);
00972             *source = '\0';
00973             res = OSP_ERROR;
00974          }
00975          break;
00976       }
00977    }
00978    ast_mutex_unlock(&osp_lock);
00979 
00980    return res;
00981 }

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

Create a UUID.

Parameters:
uuid UUID buffer
bufsize UUID buffer size
Returns:
OSK_OK Created, OSP_ERROR Error

Definition at line 1391 of file app_osplookup.c.

References ast_log, ast_random(), LOG_ERROR, NULL, OSP_ERROR, OSP_OK, OSP_SIZE_UUID, and tmp().

Referenced by osp_create_callid().

01394 {
01395    int i, res;
01396    long int tmp[OSP_SIZE_UUID / sizeof(long int)];
01397 
01398    if ((uuid != NULL) && (*bufsize >= OSP_SIZE_UUID)) {
01399       for (i = 0; i < OSP_SIZE_UUID / sizeof(long int); i++) {
01400          tmp[i] = ast_random();
01401       }
01402       memcpy(uuid, tmp, OSP_SIZE_UUID);
01403       *bufsize = OSP_SIZE_UUID;
01404       res = OSP_OK;
01405    } else {
01406       ast_log(LOG_ERROR, "Invalid parameters\n");
01407       res = OSP_ERROR;
01408    }
01409 
01410    return res;
01411 }

static int osp_finish ( int  trans,
int  recorded,
int  cause,
time_t  start,
time_t  connect,
time_t  end,
unsigned int  release,
const char *  inqos,
const char *  outqos 
) [static]

OSP Finish function.

Parameters:
trans 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
inqos Inbound QoS string
outqos Outbound QoS string
Returns:
OSP_OK Success, OSP_FAILED Failed, OSP_ERROR Error

Definition at line 2185 of file app_osplookup.c.

References ast_debug, asterisk2osp(), dummy(), error(), NULL, OSP_CALL_INBOUND, OSP_CALL_OUTBOUND, OSP_DEF_INTSTATS, OSP_ERROR, OSP_FAILED, OSP_INVALID_HANDLE, OSP_OK, and osp_report_qos().

Referenced by ospfinished_exec().

02195 {
02196    int res;
02197    OSPEFAILREASON reason;
02198    time_t alert = 0;
02199    unsigned isPddInfoPresent = 0;
02200    unsigned pdd = 0;
02201    unsigned int dummy = 0;
02202    int error;
02203 
02204    if (trans == OSP_INVALID_HANDLE) {
02205       return OSP_FAILED;
02206    }
02207 
02208    OSPPTransactionSetRoleInfo(trans, OSPC_RSTATE_STOP, OSPC_RFORMAT_OSP, OSPC_RVENDOR_ASTERISK);
02209 
02210    if (!recorded) {
02211       reason = asterisk2osp(cause);
02212       OSPPTransactionRecordFailure(trans, reason);
02213    }
02214 
02215    osp_report_qos(trans, OSP_CALL_INBOUND, inqos);
02216    osp_report_qos(trans, OSP_CALL_OUTBOUND, outqos);
02217 
02218    error = OSPPTransactionReportUsage(trans,
02219       difftime(end, connect),
02220       start,
02221       end,
02222       alert,
02223       connect,
02224       isPddInfoPresent,
02225       pdd,
02226       release,
02227       NULL,
02228       OSP_DEF_INTSTATS,
02229       OSP_DEF_INTSTATS,
02230       OSP_DEF_INTSTATS,
02231       OSP_DEF_INTSTATS,
02232       &dummy,
02233       NULL);
02234    if (error == OSPC_ERR_NO_ERROR) {
02235       ast_debug(1, "OSP: Usage reported\n");
02236       res = OSP_OK;
02237    } else {
02238       ast_debug(1, "OSP: Unable to report usage, error '%d'\n", error);
02239       res = OSP_ERROR;
02240    }
02241    OSPPTransactionDelete(trans);
02242 
02243    return res;
02244 }

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:
OSP_OK Success, OSP_FAILED Failed, OSP_ERROR Error

Definition at line 911 of file app_osplookup.c.

References ast_debug, ast_mutex_lock, ast_mutex_unlock, osp_provider::name, osp_provider::next, NULL, OSP_FAILED, osp_lock, and OSP_OK.

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

00914 {
00915    int res = OSP_FAILED;
00916    struct osp_provider* p;
00917 
00918    *provider = NULL;
00919 
00920    ast_mutex_lock(&osp_lock);
00921    for (p = osp_providers; p != NULL; p = p->next) {
00922       if (!strcasecmp(p->name, name)) {
00923          *provider = p;
00924          ast_debug(1, "OSP: find provider '%s'\n", name);
00925          res = OSP_OK;
00926          break;
00927       }
00928    }
00929    ast_mutex_unlock(&osp_lock);
00930 
00931    return res;
00932 }

static float osp_get_varfloat ( const char *  vstr  )  [static]

Get float from variable string.

Parameters:
vstr Variable string
Returns:
OSP_DEF_FLOATSTATS Error

Definition at line 1943 of file app_osplookup.c.

References ast_strlen_zero, NULL, OSP_DEF_FLOATSTATS, tmp(), and value.

Referenced by osp_report_qos().

01945 {
01946    char* tmp;
01947    float value = OSP_DEF_FLOATSTATS;
01948 
01949    if (!ast_strlen_zero(vstr)) {
01950       if ((tmp = strchr(vstr, '=')) != NULL) {
01951          tmp++;
01952          if (sscanf(tmp, "%30f", &value) != 1) {
01953             value = OSP_DEF_FLOATSTATS;
01954          }
01955       }
01956    }
01957 
01958    return value;
01959 }

static int osp_get_varint ( const char *  vstr  )  [static]

Get integer from variable string.

Parameters:
vstr Variable string
Returns:
OSP_DEF_INTSTATS Error

Definition at line 1920 of file app_osplookup.c.

References ast_strlen_zero, NULL, OSP_DEF_INTSTATS, tmp(), and value.

Referenced by osp_report_qos().

01922 {
01923    char* tmp;
01924    int value = OSP_DEF_INTSTATS;
01925 
01926    if (!ast_strlen_zero(vstr)) {
01927       if ((tmp = strchr(vstr, '=')) != NULL) {
01928          tmp++;
01929          if (sscanf(tmp, "%30d", &value) != 1) {
01930             value = OSP_DEF_INTSTATS;
01931          }
01932       }
01933    }
01934 
01935    return value;
01936 }

static int osp_load ( int  reload  )  [static]

Definition at line 2952 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, error(), LOG_ERROR, LOG_WARNING, NULL, OSP_CONFIG_FILE, osp_create_provider(), OSP_GENERAL_CAT, and osp_unload().

Referenced by load_module(), and reload().

02953 {
02954    const char* cvar;
02955    unsigned int ivar;
02956    struct ast_config* cfg;
02957    struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
02958    int error = OSPC_ERR_NO_ERROR;
02959 
02960    if ((cfg = ast_config_load(OSP_CONFIG_FILE, config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
02961       return 0;
02962    } else if (cfg == CONFIG_STATUS_FILEINVALID) {
02963       ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", OSP_CONFIG_FILE);
02964       return 0;
02965    }
02966 
02967    if (cfg) {
02968       if (reload) {
02969          osp_unload();
02970       }
02971 
02972       if ((cvar = ast_variable_retrieve(cfg, OSP_GENERAL_CAT, "accelerate")) && ast_true(cvar)) {
02973          if ((error = OSPPInit(1)) != OSPC_ERR_NO_ERROR) {
02974             ast_log(LOG_WARNING, "OSP: Unable to enable hardware acceleration, error='%d'\n", error);
02975             OSPPInit(0);
02976          } else {
02977             osp_hardware = 1;
02978          }
02979       } else {
02980          OSPPInit(0);
02981       }
02982       ast_debug(1, "OSP: osp_hardware '%d'\n", osp_hardware);
02983 
02984       if ((cvar = ast_variable_retrieve(cfg, OSP_GENERAL_CAT, "securityfeatures")) && ast_true(cvar)) {
02985          osp_security = 1;
02986       }
02987       ast_debug(1, "OSP: osp_security '%d'\n", osp_security);
02988 
02989       if ((cvar = ast_variable_retrieve(cfg, OSP_GENERAL_CAT, "tokenformat"))) {
02990          if ((sscanf(cvar, "%30d", &ivar) == 1) &&
02991             ((ivar == TOKEN_ALGO_SIGNED) || (ivar == TOKEN_ALGO_UNSIGNED) || (ivar == TOKEN_ALGO_BOTH)))
02992          {
02993             osp_tokenformat = ivar;
02994          } else {
02995             ast_log(LOG_WARNING, "tokenformat should be an integer from %d, %d or %d, not '%s'\n",
02996                TOKEN_ALGO_SIGNED, TOKEN_ALGO_UNSIGNED, TOKEN_ALGO_BOTH, cvar);
02997          }
02998       }
02999       ast_debug(1, "OSP: osp_tokenformat '%d'\n", osp_tokenformat);
03000 
03001       for (cvar = ast_category_browse(cfg, NULL); cvar != NULL; cvar = ast_category_browse(cfg, cvar)) {
03002          if (strcasecmp(cvar, OSP_GENERAL_CAT)) {
03003             osp_create_provider(cfg, cvar);
03004          }
03005       }
03006 
03007       osp_initialized = 1;
03008 
03009       ast_config_destroy(cfg);
03010    } else {
03011       ast_log(LOG_WARNING, "OSP: Unable to find configuration. OSP support disabled\n");
03012       return 0;
03013    }
03014    ast_debug(1, "OSP: osp_initialized '%d'\n", osp_initialized);
03015 
03016    return 1;
03017 }

static int osp_lookup ( const char *  name,
unsigned int  callidtypes,
const char *  actualsrc,
const char *  srcdev,
const char *  calling,
const char *  called,
const char *  snetid,
struct osp_npdata np,
struct osp_headers headers,
const char *  cinfo[],
struct osp_results results 
) [static]

OSP Lookup function.

Parameters:
name OSP provider context name
callidtypes Call ID types
actualsrc Actual source device in indirect mode
srcdev Source device of outbound call
calling Calling number
called Called number
snetid Source network ID
np NP parameters
headers SIP header parameters
cinfo Custom info
results Lookup results
Returns:
OSP_OK Found , OSP_FAILED No route, OSP_ERROR Error

Definition at line 1496 of file app_osplookup.c.

References ast_copy_string(), ast_debug, ast_log, ast_strlen_zero, osp_callid::buf, osp_results::called, osp_results::calling, osp_npdata::cic, osp_results::dest, osp_headers::divhost, osp_headers::divuser, dummy(), error(), host, osp_results::inhandle, osp_results::intech, osp_results::intimelimit, osp_callid::len, LOG_ERROR, LOG_WARNING, osp_results::networkid, osp_results::npcic, osp_npdata::npdi, osp_results::npdi, osp_results::nprn, NULL, osp_results::numdests, osp_npdata::opname, osp_results::opname, OSP_CALLID_MAXNUM, osp_check_destination(), osp_choose_timelimit(), osp_convert_inout(), osp_create_callid(), osp_create_transaction(), OSP_DEF_MAXDESTS, OSP_DEF_TIMELIMIT, OSP_ERROR, OSP_FAILED, osp_get_provider(), OSP_INVALID_HANDLE, OSP_MAX_CUSTOMINFO, OSP_MODE_INDIRECT, OSP_OK, OSP_SIZE_NORSTR, OSP_SIZE_TOKSTR, OSP_SRV_NPQUERY, OSP_TECH_H323, OSP_TECH_IAX, OSP_TECH_SIP, OSP_TECH_SKYPE, osp_results::outcallid, osp_results::outhandle, osp_results::outtech, osp_results::outtimelimit, osp_headers::paiuser, osp_headers::pciuser, osp_npdata::rn, osp_headers::rpiduser, osp_provider::source, osp_provider::srvtype, tmp(), osp_results::token, type, and osp_provider::workmode.

Referenced by osplookup_exec().

01508 {
01509    int res;
01510    struct osp_provider* provider = NULL;
01511    OSPE_PROTOCOL_NAME protocol;
01512    char source[OSP_SIZE_NORSTR];
01513    char callingnum[OSP_SIZE_NORSTR];
01514    char callednum[OSP_SIZE_NORSTR];
01515    char destination[OSP_SIZE_NORSTR];
01516    char* tmp;
01517    unsigned int tokenlen;
01518    char token[OSP_SIZE_TOKSTR];
01519    char src[OSP_SIZE_NORSTR];
01520    char dev[OSP_SIZE_NORSTR];
01521    char host[OSP_SIZE_NORSTR];
01522    unsigned int i, type;
01523    struct osp_callid callid;
01524    unsigned int callidnum;
01525    OSPT_CALL_ID* callids[OSP_CALLID_MAXNUM];
01526    char dest[OSP_SIZE_NORSTR];
01527    const char* preferred[2] = { NULL };
01528    unsigned int dummy = 0;
01529    OSPEFAILREASON reason;
01530    int error;
01531 
01532    if (results == NULL) {
01533       ast_log(LOG_ERROR, "Invalid parameters\n");
01534       return OSP_ERROR;
01535    }
01536 
01537    osp_convert_inout(results->dest, dest, sizeof(dest));
01538 
01539    results->outhandle = OSP_INVALID_HANDLE;
01540    results->outtech[0] = '\0';
01541    results->calling[0] = '\0';
01542    results->called[0] = '\0';
01543    results->token[0] = '\0';
01544    results->networkid[0] = '\0';
01545    results->nprn[0] = '\0';
01546    results->npcic[0] = '\0';
01547    results->npdi = 0;
01548    for (type = OSPC_OPNAME_START; type < OSPC_OPNAME_NUMBER; type++) {
01549       results->opname[type][0] = '\0';
01550    }
01551    results->numdests = 0;
01552    results->outtimelimit = OSP_DEF_TIMELIMIT;
01553 
01554    if ((res = osp_get_provider(name, &provider)) <= 0) {
01555       ast_debug(1, "OSP: Unabe to find OSP provider '%s'\n", name);
01556       return res;
01557    }
01558 
01559    if ((res = osp_create_transaction(name, &results->outhandle, source, sizeof(source))) <= 0) {
01560       ast_debug(1, "OSP: Unable to generate transaction handle\n");
01561       results->outhandle = OSP_INVALID_HANDLE;
01562       if (results->inhandle != OSP_INVALID_HANDLE) {
01563          OSPPTransactionRecordFailure(results->inhandle, OSPC_FAIL_NORMAL_UNSPECIFIED);
01564       }
01565       return OSP_ERROR;
01566    }
01567 
01568    if (!strcasecmp(results->intech, OSP_TECH_SIP)) {
01569       protocol = OSPC_PROTNAME_SIP;
01570    } else if (!strcasecmp(results->intech, OSP_TECH_H323)) {
01571       protocol = OSPC_PROTNAME_Q931;
01572    } else if (!strcasecmp(results->intech, OSP_TECH_IAX)) {
01573       protocol = OSPC_PROTNAME_IAX;
01574    } else if (!strcasecmp(results->intech, OSP_TECH_SKYPE)) {
01575       protocol = OSPC_PROTNAME_SKYPE;
01576    } else {
01577       protocol = OSPC_PROTNAME_SIP;
01578    }
01579    OSPPTransactionSetProtocol(results->outhandle, OSPC_PROTTYPE_SOURCE, protocol);
01580 
01581    if (!ast_strlen_zero(snetid)) {
01582       OSPPTransactionSetNetworkIds(results->outhandle, snetid, "");
01583    }
01584 
01585    OSPPTransactionSetNumberPortability(results->outhandle, np->rn, np->cic, np->npdi);
01586 
01587    for (type = OSPC_OPNAME_START; type < OSPC_OPNAME_NUMBER; type++) {
01588       OSPPTransactionSetOperatorName(results->outhandle, type, np->opname[type]);
01589    }
01590 
01591     OSPPTransactionSetRemotePartyId(results->outhandle, OSPC_NFORMAT_E164, headers->rpiduser);
01592     OSPPTransactionSetAssertedId(results->outhandle, OSPC_NFORMAT_E164, headers->paiuser);
01593    osp_convert_inout(headers->divhost, host, sizeof(host));
01594    OSPPTransactionSetDiversion(results->outhandle, headers->divuser, host);
01595     OSPPTransactionSetChargeInfo(results->outhandle, OSPC_NFORMAT_E164, headers->pciuser);
01596 
01597    if (cinfo != NULL) {
01598       for (i = 0; i < OSP_MAX_CUSTOMINFO; i++) {
01599          if (!ast_strlen_zero(cinfo[i])) {
01600             OSPPTransactionSetCustomInfo(results->outhandle, i, cinfo[i]);
01601          }
01602       }
01603    }
01604 
01605    ast_copy_string(callednum, called, sizeof(callednum));
01606    if((tmp = strchr(callednum, ';')) != NULL) {
01607       *tmp = '\0';
01608    }
01609 
01610    callidnum = 0;
01611    callids[0] = NULL;
01612    for (i = 0; i < OSP_CALLID_MAXNUM; i++) {
01613       type = 1 << i;
01614       if (callidtypes & type) {
01615          error = osp_create_callid(type, &callid);
01616          if (error == 1) {
01617             callids[callidnum] = OSPPCallIdNew(callid.len, callid.buf);
01618             callidnum++;
01619          }
01620       }
01621    }
01622 
01623    if (provider->workmode == OSP_MODE_INDIRECT) {
01624       osp_convert_inout(srcdev, src, sizeof(src));
01625       if (ast_strlen_zero(actualsrc)) {
01626          osp_convert_inout(srcdev, dev, sizeof(dev));
01627       } else {
01628          osp_convert_inout(actualsrc, dev, sizeof(dev));
01629       }
01630    } else {
01631       osp_convert_inout(source, src, sizeof(src));
01632       osp_convert_inout(srcdev, dev, sizeof(dev));
01633    }
01634 
01635    if (provider->srvtype == OSP_SRV_NPQUERY) {
01636       OSPPTransactionSetServiceType(results->outhandle, OSPC_SERVICE_NPQUERY);
01637       if (!ast_strlen_zero(dest)) {
01638          preferred[0] = dest;
01639       }
01640       results->numdests = 1;
01641    } else {
01642       OSPPTransactionSetServiceType(results->outhandle, OSPC_SERVICE_VOICE);
01643       results->numdests = OSP_DEF_MAXDESTS;
01644    }
01645 
01646    error = OSPPTransactionRequestAuthorisation(results->outhandle,
01647       src,
01648       dev,
01649       calling ? calling : "",
01650       OSPC_NFORMAT_E164,
01651       callednum,
01652       OSPC_NFORMAT_E164,
01653       NULL,
01654       callidnum,
01655       callids,
01656       preferred,
01657       &results->numdests,
01658       &dummy,
01659       NULL);
01660 
01661    for (i = 0; i < callidnum; i++) {
01662       OSPPCallIdDelete(&callids[i]);
01663    }
01664 
01665    if (error != OSPC_ERR_NO_ERROR) {
01666       ast_log(LOG_WARNING, "OSP: Unable to request authorization, error '%d'\n", error);
01667       results->numdests = 0;
01668       if (results->inhandle != OSP_INVALID_HANDLE) {
01669          OSPPTransactionRecordFailure(results->inhandle, OSPC_FAIL_NORMAL_UNSPECIFIED);
01670       }
01671       return OSP_ERROR;
01672    }
01673 
01674    if (!results->numdests) {
01675       ast_debug(1, "OSP: No more destination\n");
01676       if (results->inhandle != OSP_INVALID_HANDLE) {
01677          OSPPTransactionRecordFailure(results->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01678       }
01679       return OSP_FAILED;
01680    }
01681 
01682    results->outcallid.len = sizeof(results->outcallid.buf);
01683    tokenlen = sizeof(token);
01684    error = OSPPTransactionGetFirstDestination(results->outhandle,
01685       0,
01686       NULL,
01687       NULL,
01688       &results->outtimelimit,
01689       &results->outcallid.len,
01690       results->outcallid.buf,
01691       sizeof(callednum),
01692       callednum,
01693       sizeof(callingnum),
01694       callingnum,
01695       sizeof(destination),
01696       destination,
01697       0,
01698       NULL,
01699       &tokenlen,
01700       token);
01701    if (error != OSPC_ERR_NO_ERROR) {
01702       ast_debug(1, "OSP: Unable to get first route, error '%d'\n", error);
01703       results->numdests = 0;
01704       results->outtimelimit = OSP_DEF_TIMELIMIT;
01705       if (results->inhandle != OSP_INVALID_HANDLE) {
01706          OSPPTransactionRecordFailure(results->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01707       }
01708       return OSP_ERROR;
01709    }
01710 
01711    results->numdests--;
01712    results->outtimelimit = osp_choose_timelimit(results->intimelimit, results->outtimelimit);
01713    ast_debug(1, "OSP: outtimelimit '%d'\n", results->outtimelimit);
01714    ast_debug(1, "OSP: calling '%s'\n", callingnum);
01715    ast_debug(1, "OSP: called '%s'\n", callednum);
01716    ast_debug(1, "OSP: destination '%s'\n", destination);
01717    ast_debug(1, "OSP: token size '%d'\n", tokenlen);
01718 
01719    if ((res = osp_check_destination(provider, callingnum, callednum, destination, tokenlen, token, &reason, results)) > 0) {
01720       return OSP_OK;
01721    }
01722 
01723    if (!results->numdests) {
01724       ast_debug(1, "OSP: No more destination\n");
01725       results->outtimelimit = OSP_DEF_TIMELIMIT;
01726       OSPPTransactionRecordFailure(results->outhandle, reason);
01727       if (results->inhandle != OSP_INVALID_HANDLE) {
01728          OSPPTransactionRecordFailure(results->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01729       }
01730       return OSP_FAILED;
01731    }
01732 
01733    while(results->numdests) {
01734       results->outcallid.len = sizeof(results->outcallid.buf);
01735       tokenlen = sizeof(token);
01736       error = OSPPTransactionGetNextDestination(results->outhandle,
01737          reason,
01738          0,
01739          NULL,
01740          NULL,
01741          &results->outtimelimit,
01742          &results->outcallid.len,
01743          results->outcallid.buf,
01744          sizeof(callednum),
01745          callednum,
01746          sizeof(callingnum),
01747          callingnum,
01748          sizeof(destination),
01749          destination,
01750          0,
01751          NULL,
01752          &tokenlen,
01753          token);
01754       if (error == OSPC_ERR_NO_ERROR) {
01755          results->numdests--;
01756          results->outtimelimit = osp_choose_timelimit(results->intimelimit, results->outtimelimit);
01757          ast_debug(1, "OSP: outtimelimit '%d'\n", results->outtimelimit);
01758          ast_debug(1, "OSP: calling '%s'\n", callingnum);
01759          ast_debug(1, "OSP: called '%s'\n", callednum);
01760          ast_debug(1, "OSP: destination '%s'\n", destination);
01761          ast_debug(1, "OSP: token size '%d'\n", tokenlen);
01762 
01763          if ((res = osp_check_destination(provider, callingnum, callednum, destination, tokenlen, token, &reason, results)) > 0) {
01764             break;
01765          } else if (!results->numdests) {
01766             ast_debug(1, "OSP: No more destination\n");
01767             OSPPTransactionRecordFailure(results->outhandle, reason);
01768             if (results->inhandle != OSP_INVALID_HANDLE) {
01769                OSPPTransactionRecordFailure(results->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01770             }
01771             res = OSP_FAILED;
01772             break;
01773          }
01774       } else {
01775          ast_debug(1, "OSP: Unable to get route, error '%d'\n", error);
01776          results->numdests = 0;
01777          results->outtimelimit = OSP_DEF_TIMELIMIT;
01778          if (results->inhandle != OSP_INVALID_HANDLE) {
01779             OSPPTransactionRecordFailure(results->inhandle, OSPC_FAIL_NORMAL_UNSPECIFIED);
01780          }
01781          res = OSP_ERROR;
01782          break;
01783       }
01784    }
01785 
01786    return res;
01787 }

static int osp_next ( const char *  name,
int  cause,
struct osp_results results 
) [static]

OSP Lookup Next function.

Parameters:
name OSP provider name
cause Asterisk hangup cause
results Lookup results, in/output
Returns:
OSP_OK Found , OSP_FAILED No route, OSP_ERROR Error

Definition at line 1796 of file app_osplookup.c.

References ast_debug, ast_log, asterisk2osp(), osp_callid::buf, osp_results::called, osp_results::calling, osp_results::dest, error(), osp_results::inhandle, osp_results::intimelimit, osp_callid::len, LOG_ERROR, osp_results::networkid, osp_results::npcic, osp_results::npdi, osp_results::nprn, NULL, osp_results::numdests, osp_results::opname, osp_check_destination(), osp_choose_timelimit(), OSP_DEF_TIMELIMIT, OSP_ERROR, OSP_FAILED, osp_get_provider(), OSP_INVALID_HANDLE, OSP_OK, OSP_SIZE_NORSTR, OSP_SIZE_TOKSTR, osp_results::outcallid, osp_results::outhandle, osp_results::outtech, osp_results::outtimelimit, osp_results::token, and type.

Referenced by ospnext_exec().

01800 {
01801    int res;
01802    struct osp_provider* provider = NULL;
01803    char calling[OSP_SIZE_NORSTR];
01804    char called[OSP_SIZE_NORSTR];
01805    char dest[OSP_SIZE_NORSTR];
01806    unsigned int tokenlen;
01807    char token[OSP_SIZE_TOKSTR];
01808    OSPEFAILREASON reason;
01809    OSPE_OPERATOR_NAME type;
01810    int error;
01811 
01812    if (results == NULL) {
01813       ast_log(LOG_ERROR, "Invalid parameters\n");
01814       return OSP_ERROR;
01815    }
01816 
01817    results->outtech[0] = '\0';
01818    results->dest[0] = '\0';
01819    results->calling[0] = '\0';
01820    results->called[0] = '\0';
01821    results->token[0] = '\0';
01822    results->networkid[0] = '\0';
01823    results->nprn[0] = '\0';
01824    results->npcic[0] = '\0';
01825    results->npdi = 0;
01826    for (type = OSPC_OPNAME_START; type < OSPC_OPNAME_NUMBER; type++) {
01827       results->opname[type][0] = '\0';
01828    }
01829    results->outtimelimit = OSP_DEF_TIMELIMIT;
01830 
01831    if ((res = osp_get_provider(name, &provider)) <= 0) {
01832       ast_debug(1, "OSP: Unabe to find OSP provider '%s'\n", name);
01833       return res;
01834    }
01835 
01836    if (results->outhandle == OSP_INVALID_HANDLE) {
01837       ast_debug(1, "OSP: Transaction handle undefined\n");
01838       results->numdests = 0;
01839       if (results->inhandle != OSP_INVALID_HANDLE) {
01840          OSPPTransactionRecordFailure(results->inhandle, OSPC_FAIL_NORMAL_UNSPECIFIED);
01841       }
01842       return OSP_ERROR;
01843    }
01844 
01845    reason = asterisk2osp(cause);
01846 
01847    if (!results->numdests) {
01848       ast_debug(1, "OSP: No more destination\n");
01849       OSPPTransactionRecordFailure(results->outhandle, reason);
01850       if (results->inhandle != OSP_INVALID_HANDLE) {
01851          OSPPTransactionRecordFailure(results->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01852       }
01853       return OSP_FAILED;
01854    }
01855 
01856    while(results->numdests) {
01857       results->outcallid.len = sizeof(results->outcallid.buf);
01858       tokenlen = sizeof(token);
01859       error = OSPPTransactionGetNextDestination(
01860          results->outhandle,
01861          reason,
01862          0,
01863          NULL,
01864          NULL,
01865          &results->outtimelimit,
01866          &results->outcallid.len,
01867          results->outcallid.buf,
01868          sizeof(called),
01869          called,
01870          sizeof(calling),
01871          calling,
01872          sizeof(dest),
01873          dest,
01874          0,
01875          NULL,
01876          &tokenlen,
01877          token);
01878       if (error == OSPC_ERR_NO_ERROR) {
01879          results->numdests--;
01880          results->outtimelimit = osp_choose_timelimit(results->intimelimit, results->outtimelimit);
01881          ast_debug(1, "OSP: outtimelimit '%d'\n", results->outtimelimit);
01882          ast_debug(1, "OSP: calling '%s'\n", calling);
01883          ast_debug(1, "OSP: called '%s'\n", called);
01884          ast_debug(1, "OSP: destination '%s'\n", dest);
01885          ast_debug(1, "OSP: token size '%d'\n", tokenlen);
01886 
01887          if ((res = osp_check_destination(provider, calling, called, dest, tokenlen, token, &reason, results)) > 0) {
01888             res = OSP_OK;
01889             break;
01890          } else if (!results->numdests) {
01891             ast_debug(1, "OSP: No more destination\n");
01892             OSPPTransactionRecordFailure(results->outhandle, reason);
01893             if (results->inhandle != OSP_INVALID_HANDLE) {
01894                OSPPTransactionRecordFailure(results->inhandle, OSPC_FAIL_NO_ROUTE_TO_DEST);
01895             }
01896             res = OSP_FAILED;
01897             break;
01898          }
01899       } else {
01900          ast_debug(1, "OSP: Unable to get route, error '%d'\n", error);
01901          results->token[0] = '\0';
01902          results->numdests = 0;
01903          results->outtimelimit = OSP_DEF_TIMELIMIT;
01904          if (results->inhandle != OSP_INVALID_HANDLE) {
01905             OSPPTransactionRecordFailure(results->inhandle, OSPC_FAIL_NORMAL_UNSPECIFIED);
01906          }
01907          res = OSP_ERROR;
01908          break;
01909       }
01910    }
01911 
01912    return res;
01913 }

static int osp_report_qos ( int  trans,
enum osp_callleg  leg,
const char *  qos 
) [static]

Report QoS.

Parameters:
trans OSP in/outbound transaction handle
leg Inbound/outbound
qos QoS string
Returns:
OSP_OK Success, OSP_FAILED Failed, OSP_ERROR Error

Definition at line 1968 of file app_osplookup.c.

References ast_copy_string(), ast_debug, ast_strlen_zero, osp_metrics::avg, item, max, osp_metrics::max, min, osp_metrics::min, NULL, OSP_CALL_INBOUND, OSP_DEF_FLOATSTATS, OSP_DEF_INTSTATS, OSP_DIR_NUMBER, OSP_DIR_RX, OSP_DIR_TX, OSP_FAILED, osp_get_varfloat(), osp_get_varint(), OSP_OK, OSP_SIZE_NORSTR, osp_metrics::sdev, tmp(), osp_metrics::value, and value.

Referenced by osp_finish().

01972 {
01973    int res = OSP_FAILED;
01974    enum osp_direction dir;
01975    char buffer[OSP_SIZE_NORSTR];
01976    char* tmp;
01977    char* item;
01978    int totalpackets[OSP_DIR_NUMBER];
01979    struct osp_metrics lost[OSP_DIR_NUMBER];
01980    struct osp_metrics jitter[OSP_DIR_NUMBER];
01981    struct osp_metrics rtt;
01982    int value;
01983 
01984    if (!ast_strlen_zero(qos)) {
01985       for (dir = OSP_DIR_RX; dir < OSP_DIR_NUMBER; dir++) {
01986          totalpackets[dir] = OSP_DEF_INTSTATS;
01987       }
01988 
01989       for (dir = OSP_DIR_RX; dir < OSP_DIR_NUMBER; dir++) {
01990          lost[dir].value = OSP_DEF_INTSTATS;
01991          lost[dir].min = OSP_DEF_FLOATSTATS;
01992          lost[dir].max = OSP_DEF_FLOATSTATS;
01993          lost[dir].avg = OSP_DEF_FLOATSTATS;
01994          lost[dir].sdev = OSP_DEF_FLOATSTATS;
01995       }
01996 
01997       for (dir = OSP_DIR_RX; dir < OSP_DIR_NUMBER; dir++) {
01998          jitter[dir].value = OSP_DEF_INTSTATS;
01999          jitter[dir].min = OSP_DEF_FLOATSTATS;
02000          jitter[dir].max = OSP_DEF_FLOATSTATS;
02001          jitter[dir].avg = OSP_DEF_FLOATSTATS;
02002          jitter[dir].sdev = OSP_DEF_FLOATSTATS;
02003       }
02004 
02005       rtt.value = OSP_DEF_INTSTATS;
02006       rtt.min = OSP_DEF_FLOATSTATS;
02007       rtt.max = OSP_DEF_FLOATSTATS;
02008       rtt.avg = OSP_DEF_FLOATSTATS;
02009       rtt.sdev = OSP_DEF_FLOATSTATS;
02010 
02011       ast_copy_string(buffer, qos, sizeof(buffer));
02012       for (item = strtok_r(buffer, ";", &tmp); item; item = strtok_r(NULL, ";", &tmp)) {
02013          if (!strncasecmp(item, "rxcount", strlen("rxcount"))) {
02014             totalpackets[OSP_DIR_RX] = osp_get_varint(item);
02015          } else if (!strncasecmp(item, "txcount", strlen("txcount"))) {
02016             totalpackets[OSP_DIR_TX] = osp_get_varint(item);
02017          } else if (!strncasecmp(item, "lp", strlen("lp"))) {
02018             lost[OSP_DIR_RX].value = osp_get_varint(item);
02019          } else if (!strncasecmp(item, "minrxlost", strlen("minrxlost"))) {
02020             lost[OSP_DIR_RX].min = osp_get_varfloat(item);
02021          } else if (!strncasecmp(item, "maxrxlost", strlen("maxrxlost"))) {
02022             lost[OSP_DIR_RX].max = osp_get_varfloat(item);
02023          } else if (!strncasecmp(item, "avgrxlost", strlen("avgrxlost"))) {
02024             lost[OSP_DIR_RX].avg = osp_get_varfloat(item);
02025          } else if (!strncasecmp(item, "stdevrxlost", strlen("stdevrxlost"))) {
02026             lost[OSP_DIR_RX].sdev = osp_get_varfloat(item);
02027          } else if (!strncasecmp(item, "rlp", strlen("rlp"))) {
02028             lost[OSP_DIR_TX].value = osp_get_varint(item);
02029          } else if (!strncasecmp(item, "reported_minlost", strlen("reported_minlost"))) {
02030             lost[OSP_DIR_TX].min = osp_get_varfloat(item);
02031          } else if (!strncasecmp(item, "reported_maxlost", strlen("reported_maxlost"))) {
02032             lost[OSP_DIR_TX].max = osp_get_varfloat(item);
02033          } else if (!strncasecmp(item, "reported_avglost", strlen("reported_avglost"))) {
02034             lost[OSP_DIR_TX].avg = osp_get_varfloat(item);
02035          } else if (!strncasecmp(item, "reported_stdevlost", strlen("reported_stdevlost"))) {
02036             lost[OSP_DIR_TX].sdev = osp_get_varfloat(item);
02037          } else if (!strncasecmp(item, "rxjitter", strlen("rxjitter"))) {
02038             jitter[OSP_DIR_RX].value = osp_get_varint(item);
02039          } else if (!strncasecmp(item, "minrxjitter", strlen("minrxjitter"))) {
02040             jitter[OSP_DIR_RX].min = osp_get_varfloat(item);
02041          } else if (!strncasecmp(item, "maxrxjitter", strlen("maxrxjitter"))) {
02042             jitter[OSP_DIR_RX].max = osp_get_varfloat(item);
02043          } else if (!strncasecmp(item, "avgrxjitter", strlen("avgjitter"))) {
02044             jitter[OSP_DIR_RX].avg = osp_get_varfloat(item);
02045          } else if (!strncasecmp(item, "stdevrxjitter", strlen("stdevjitter"))) {
02046             jitter[OSP_DIR_RX].sdev = osp_get_varfloat(item);
02047          } else if (!strncasecmp(item, "txjitter", strlen("txjitter"))) {
02048             jitter[OSP_DIR_TX].value = osp_get_varint(item);
02049          } else if (!strncasecmp(item, "reported_minjitter", strlen("reported_minjitter"))) {
02050             jitter[OSP_DIR_TX].min = osp_get_varfloat(item);
02051          } else if (!strncasecmp(item, "reported_maxjitter", strlen("reported_maxjitter"))) {
02052             jitter[OSP_DIR_TX].max = osp_get_varfloat(item);
02053          } else if (!strncasecmp(item, "reported_avgjitter", strlen("reported_avgjitter"))) {
02054             jitter[OSP_DIR_TX].avg = osp_get_varfloat(item);
02055          } else if (!strncasecmp(item, "reported_stdevjitter", strlen("reported_stdevjitter"))) {
02056             jitter[OSP_DIR_TX].sdev = osp_get_varfloat(item);
02057          } else if (!strncasecmp(item, "rtt", strlen("rtt"))) {
02058             rtt.value = osp_get_varint(item);
02059          } else if (!strncasecmp(item, "minrtt", strlen("minrtt"))) {
02060             rtt.min = osp_get_varfloat(item);
02061          } else if (!strncasecmp(item, "maxrtt", strlen("maxrtt"))) {
02062             rtt.max = osp_get_varfloat(item);
02063          } else if (!strncasecmp(item, "avgrtt", strlen("avgrtt"))) {
02064             rtt.avg = osp_get_varfloat(item);
02065          } else if (!strncasecmp(item, "stdevrtt", strlen("stdevrtt"))) {
02066             rtt.sdev = osp_get_varfloat(item);
02067          }
02068       }
02069 
02070       ast_debug(1, "OSP: call leg '%d'\n", leg);
02071       ast_debug(1, "OSP: rxcount '%d'\n", totalpackets[OSP_DIR_RX]);
02072       ast_debug(1, "OSP: txcount '%d'\n", totalpackets[OSP_DIR_TX]);
02073       ast_debug(1, "OSP: lp '%d'\n",lost[OSP_DIR_RX].value);
02074       ast_debug(1, "OSP: minrxlost '%f'\n", lost[OSP_DIR_RX].min);
02075       ast_debug(1, "OSP: maxrxlost '%f'\n", lost[OSP_DIR_RX].max);
02076       ast_debug(1, "OSP: avgrxlost '%f'\n", lost[OSP_DIR_RX].avg);
02077       ast_debug(1, "OSP: stdevrxlost '%f'\n", lost[OSP_DIR_RX].sdev);
02078       ast_debug(1, "OSP: rlp '%d'\n", lost[OSP_DIR_TX].value);
02079       ast_debug(1, "OSP: reported_minlost '%f'\n", lost[OSP_DIR_TX].min);
02080       ast_debug(1, "OSP: reported_maxlost '%f'\n", lost[OSP_DIR_TX].max);
02081       ast_debug(1, "OSP: reported_avglost '%f'\n", lost[OSP_DIR_TX].avg);
02082       ast_debug(1, "OSP: reported_stdevlost '%f'\n", lost[OSP_DIR_TX].sdev);
02083       ast_debug(1, "OSP: rxjitter '%d'\n", jitter[OSP_DIR_RX].value);
02084       ast_debug(1, "OSP: minrxjitter '%f'\n", jitter[OSP_DIR_RX].min);
02085       ast_debug(1, "OSP: maxrxjitter '%f'\n", jitter[OSP_DIR_RX].max);
02086       ast_debug(1, "OSP: avgrxjitter '%f'\n", jitter[OSP_DIR_RX].avg);
02087       ast_debug(1, "OSP: stdevrxjitter '%f'\n", jitter[OSP_DIR_RX].sdev);
02088       ast_debug(1, "OSP: txjitter '%d'\n", jitter[OSP_DIR_TX].value);
02089       ast_debug(1, "OSP: reported_minjitter '%f'\n", jitter[OSP_DIR_TX].min);
02090       ast_debug(1, "OSP: reported_maxjitter '%f'\n", jitter[OSP_DIR_TX].max);
02091       ast_debug(1, "OSP: reported_avgjitter '%f'\n", jitter[OSP_DIR_TX].avg);
02092       ast_debug(1, "OSP: reported_stdevjitter '%f'\n", jitter[OSP_DIR_TX].sdev);
02093       ast_debug(1, "OSP: rtt '%d'\n", rtt.value);
02094       ast_debug(1, "OSP: minrtt '%f'\n", rtt.min);
02095       ast_debug(1, "OSP: maxrtt '%f'\n", rtt.max);
02096       ast_debug(1, "OSP: avgrtt '%f'\n", rtt.avg);
02097       ast_debug(1, "OSP: stdevrtt '%f'\n", rtt.sdev);
02098 
02099       if (leg == OSP_CALL_INBOUND) {
02100          OSPPTransactionSetPackets(trans, OSPC_SMETRIC_RTP, OSPC_SDIR_SRCREP, totalpackets[OSP_DIR_RX]);
02101          OSPPTransactionSetPackets(trans, OSPC_SMETRIC_RTCP, OSPC_SDIR_DESTREP, totalpackets[OSP_DIR_TX]);
02102          if (lost[OSP_DIR_RX].value >= 0) {
02103             value = lost[OSP_DIR_RX].value;
02104          } else {
02105             value = (int)lost[OSP_DIR_RX].avg;
02106          }
02107          OSPPTransactionSetLost(trans, OSPC_SMETRIC_RTP, OSPC_SDIR_SRCREP, value, OSP_DEF_INTSTATS);
02108          if (lost[OSP_DIR_TX].value >= 0) {
02109             value = lost[OSP_DIR_TX].value;
02110          } else {
02111             value = (int)lost[OSP_DIR_TX].avg;
02112          }
02113          OSPPTransactionSetLost(trans, OSPC_SMETRIC_RTCP, OSPC_SDIR_DESTREP, value, OSP_DEF_INTSTATS);
02114          if (jitter[OSP_DIR_RX].value >= 0) {
02115             value = jitter[OSP_DIR_RX].value;
02116          } else {
02117             value = (int)jitter[OSP_DIR_RX].avg;
02118          }
02119          OSPPTransactionSetJitter(trans,
02120             OSPC_SMETRIC_RTP,
02121             OSPC_SDIR_SRCREP,
02122             OSP_DEF_INTSTATS,
02123             (int)jitter[OSP_DIR_RX].min,
02124             (int)jitter[OSP_DIR_RX].max,
02125             value, jitter[OSP_DIR_RX].sdev);
02126          if (jitter[OSP_DIR_TX].value >= 0) {
02127             value = jitter[OSP_DIR_TX].value;
02128          } else {
02129             value = (int)jitter[OSP_DIR_TX].avg;
02130          }
02131          OSPPTransactionSetJitter(trans, OSPC_SMETRIC_RTCP, OSPC_SDIR_DESTREP,
02132             OSP_DEF_INTSTATS, (int)jitter[OSP_DIR_TX].min, (int)jitter[OSP_DIR_TX].max, value, jitter[OSP_DIR_TX].sdev);
02133       } else {
02134          OSPPTransactionSetPackets(trans, OSPC_SMETRIC_RTP, OSPC_SDIR_DESTREP, totalpackets[OSP_DIR_RX]);
02135          OSPPTransactionSetPackets(trans, OSPC_SMETRIC_RTCP, OSPC_SDIR_SRCREP, totalpackets[OSP_DIR_TX]);
02136          OSPPTransactionSetLost(trans, OSPC_SMETRIC_RTP, OSPC_SDIR_DESTREP, lost[OSP_DIR_RX].value, OSP_DEF_INTSTATS);
02137          OSPPTransactionSetLost(trans, OSPC_SMETRIC_RTCP, OSPC_SDIR_SRCREP, lost[OSP_DIR_TX].value, OSP_DEF_INTSTATS);
02138          if (jitter[OSP_DIR_RX].value >= 0) {
02139             value = jitter[OSP_DIR_RX].value;
02140          } else {
02141             value = (int)jitter[OSP_DIR_RX].avg;
02142          }
02143          OSPPTransactionSetJitter(trans,
02144             OSPC_SMETRIC_RTP,
02145             OSPC_SDIR_DESTREP,
02146             OSP_DEF_INTSTATS,
02147             (int)jitter[OSP_DIR_RX].min,
02148             (int)jitter[OSP_DIR_RX].max,
02149             value,
02150             jitter[OSP_DIR_RX].sdev);
02151          if (jitter[OSP_DIR_TX].value >= 0) {
02152             value = jitter[OSP_DIR_TX].value;
02153          } else {
02154             value = (int)jitter[OSP_DIR_TX].avg;
02155          }
02156          OSPPTransactionSetJitter(trans,
02157             OSPC_SMETRIC_RTCP,
02158             OSPC_SDIR_SRCREP,
02159             OSP_DEF_INTSTATS,
02160             (int)jitter[OSP_DIR_TX].min,
02161             (int)jitter[OSP_DIR_TX].max,
02162             value,
02163             jitter[OSP_DIR_TX].sdev);
02164       }
02165 
02166       res = OSP_OK;
02167    }
02168 
02169    return res;
02170 }

static int osp_unload ( void   )  [static]

Definition at line 2926 of file app_osplookup.c.

References ast_free, ast_mutex_lock, ast_mutex_unlock, osp_provider::handle, osp_provider::next, NULL, and osp_lock.

Referenced by osp_load(), and unload_module().

02927 {
02928    struct osp_provider* provider;
02929    struct osp_provider* next;
02930 
02931    if (osp_initialized) {
02932       ast_mutex_lock(&osp_lock);
02933       for (provider = osp_providers; provider; provider = next) {
02934          next = provider->next;
02935          OSPPProviderDelete(provider->handle, 0);
02936          ast_free(provider);
02937       }
02938       osp_providers = NULL;
02939       ast_mutex_unlock(&osp_lock);
02940 
02941       OSPPCleanup();
02942 
02943       osp_tokenformat = TOKEN_ALGO_SIGNED;
02944       osp_security = 0;
02945       osp_hardware = 0;
02946       osp_initialized = 0;
02947    }
02948 
02949    return 0;
02950 }

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

UUID to string.

Parameters:
uuid UUID
buffer String buffer
bufsize String buffer size
Returns:
OSP_OK Successed, OSP_ERROR Error

Definition at line 1420 of file app_osplookup.c.

References ast_log, LOG_ERROR, NULL, OSP_ERROR, OSP_OK, and OSP_SIZE_UUIDSTR.

Referenced by osplookup_exec(), and ospnext_exec().

01424 {
01425    int res;
01426 
01427    if ((uuid != NULL) && (bufsize > OSP_SIZE_UUIDSTR)) {
01428       snprintf(buffer, bufsize, "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-"
01429                  "%02hhx%02hhx-%02hhx%02hhx-"
01430                  "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
01431          uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
01432          uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
01433       res = OSP_OK;
01434    } else {
01435       ast_log(LOG_ERROR, "Invalid parameters\n");
01436       res = OSP_ERROR;
01437    }
01438 
01439    return res;
01440 }

static int osp_validate_token ( int  trans,
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:
trans 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:
OSP_OK Success, OSP_FAILED Failed, OSP_ERROR Error

Definition at line 1078 of file app_osplookup.c.

References ast_base64decode(), ast_debug, ast_log, dummy(), error(), LOG_ERROR, LOG_WARNING, NULL, osp_convert_inout(), OSP_ERROR, OSP_FAILED, OSP_OK, OSP_SIZE_NORSTR, and OSP_SIZE_TOKSTR.

Referenced by osp_auth().

01086 {
01087    int res;
01088    int tokenlen;
01089    unsigned char tokenstr[OSP_SIZE_TOKSTR];
01090    char src[OSP_SIZE_NORSTR];
01091    char dest[OSP_SIZE_NORSTR];
01092    unsigned int authorised;
01093    unsigned int dummy = 0;
01094    int error;
01095 
01096    if (timelimit == NULL) {
01097       ast_log(LOG_ERROR, "Invalid parameters\n");
01098       return OSP_ERROR;
01099    }
01100 
01101    tokenlen = ast_base64decode(tokenstr, token, strlen(token));
01102    osp_convert_inout(source, src, sizeof(src));
01103    osp_convert_inout(destination, dest, sizeof(dest));
01104    error = OSPPTransactionValidateAuthorisation(trans,
01105       src,
01106       dest,
01107       NULL,
01108       NULL,
01109       calling ? calling : "",
01110       OSPC_NFORMAT_E164,
01111       called,
01112       OSPC_NFORMAT_E164,
01113       0,
01114       NULL,
01115       tokenlen,
01116       (char*)tokenstr,
01117       &authorised,
01118       timelimit,
01119       &dummy,
01120       NULL,
01121       osp_tokenformat);
01122    if (error != OSPC_ERR_NO_ERROR) {
01123       ast_log(LOG_WARNING, "OSP: Unable to validate inbound token, error '%d'\n", error);
01124       *timelimit = 0;
01125       res = OSP_ERROR;
01126    } else if (authorised) {
01127       ast_debug(1, "OSP: Authorised\n");
01128       res = OSP_OK;
01129    } else {
01130       ast_debug(1, "OSP: Unauthorised\n");
01131       res = OSP_FAILED;
01132    }
01133 
01134    return res;
01135 }

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

OSP Application OSPAuth.

Parameters:
chan Channel
data Parameter
Returns:
OSP_AST_OK Success, OSP_AST_ERROR Error

Definition at line 2254 of file app_osplookup.c.

References args, AST_APP_ARG, ast_channel_caller(), ast_channel_exten(), ast_channel_varshead(), ast_debug, AST_DECLARE_APP_ARGS, AST_LIST_TRAVERSE, 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_var_t::entries, NULL, OSP_AST_ERROR, OSP_AST_OK, osp_auth(), OSP_DEF_PROVIDER, OSP_DEF_TIMELIMIT, OSP_OK, OSP_SIZE_INTSTR, pbx_builtin_setvar_helper(), S_COR, status, and tmp().

Referenced by load_module().

02257 {
02258    int res;
02259    const char* provider = OSP_DEF_PROVIDER;
02260    struct varshead* headp;
02261    struct ast_var_t* current;
02262    const char* source = "";
02263    const char* token = "";
02264    int handle;
02265    unsigned int timelimit;
02266    char buffer[OSP_SIZE_INTSTR];
02267    const char* status;
02268    char* tmp;
02269 
02270    AST_DECLARE_APP_ARGS(args,
02271       AST_APP_ARG(provider);
02272       AST_APP_ARG(options);
02273    );
02274 
02275    tmp = ast_strdupa(data);
02276 
02277    AST_STANDARD_APP_ARGS(args, tmp);
02278 
02279    if (!ast_strlen_zero(args.provider)) {
02280       provider = args.provider;
02281    }
02282    ast_debug(1, "OSPAuth: provider '%s'\n", provider);
02283 
02284    headp = ast_channel_varshead(chan);
02285    AST_LIST_TRAVERSE(headp, current, entries) {
02286       if (!strcmp(ast_var_name(current), "OSPINPEERIP")) {
02287          source = ast_var_value(current);
02288       } else if (!strcmp(ast_var_name(current), "OSPINTOKEN")) {
02289          token = ast_var_value(current);
02290       }
02291    }
02292 
02293    ast_debug(1, "OSPAuth: source '%s'\n", source);
02294    ast_debug(1, "OSPAuth: token size '%zd'\n", strlen(token));
02295 
02296    res = osp_auth(provider, &handle, source,
02297       S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL),
02298       ast_channel_exten(chan), token, &timelimit);
02299    if (res > 0) {
02300       status = AST_OSP_SUCCESS;
02301    } else {
02302       timelimit = OSP_DEF_TIMELIMIT;
02303       if (!res) {
02304          status = AST_OSP_FAILED;
02305       } else {
02306          status = AST_OSP_ERROR;
02307       }
02308    }
02309 
02310    snprintf(buffer, sizeof(buffer), "%d", handle);
02311    pbx_builtin_setvar_helper(chan, "OSPINHANDLE", buffer);
02312    ast_debug(1, "OSPAuth: OSPINHANDLE '%s'\n", buffer);
02313    snprintf(buffer, sizeof(buffer), "%d", timelimit);
02314    pbx_builtin_setvar_helper(chan, "OSPINTIMELIMIT", buffer);
02315    ast_debug(1, "OSPAuth: OSPINTIMELIMIT '%s'\n", buffer);
02316    pbx_builtin_setvar_helper(chan, "OSPAUTHSTATUS", status);
02317    ast_debug(1, "OSPAuth: %s\n", status);
02318 
02319    if(res != OSP_OK) {
02320       res = OSP_AST_ERROR;
02321    } else {
02322       res = OSP_AST_OK;
02323    }
02324 
02325    return res;
02326 }

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

OSP Application OSPFinish.

Parameters:
chan Channel
data Parameter
Returns:
OSP_AST_OK Success, OSP_AST_ERROR Error

Definition at line 2808 of file app_osplookup.c.

References args, AST_APP_ARG, AST_CAUSE_NO_ROUTE_DESTINATION, AST_CAUSE_NORMAL_CLEARING, ast_channel_answertime(), ast_channel_creationtime(), ast_channel_varshead(), ast_check_hangup(), ast_copy_string(), ast_debug, AST_DECLARE_APP_ARGS, AST_LIST_TRAVERSE, AST_OSP_ERROR, AST_OSP_FAILED, AST_OSP_SUCCESS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, ast_tvzero(), ast_var_name(), ast_var_value(), end, ast_var_t::entries, NULL, OSP_AST_ERROR, OSP_AST_OK, osp_finish(), OSP_INVALID_HANDLE, OSP_OK, OSP_SIZE_INTSTR, OSP_SIZE_QOSSTR, pbx_builtin_setvar_helper(), status, and tmp().

Referenced by load_module().

02811 {
02812    int res = OSP_OK;
02813    int cause = 0;
02814    struct varshead* headp;
02815    struct ast_var_t* current;
02816    int inhandle = OSP_INVALID_HANDLE;
02817    int outhandle = OSP_INVALID_HANDLE;
02818    int recorded = 0;
02819    time_t start = 0, connect = 0, end = 0;
02820    unsigned int release;
02821    char buffer[OSP_SIZE_INTSTR];
02822    char inqos[OSP_SIZE_QOSSTR] = { 0 };
02823    char outqos[OSP_SIZE_QOSSTR] = { 0 };
02824    const char* status;
02825    char* tmp;
02826 
02827    AST_DECLARE_APP_ARGS(args,
02828       AST_APP_ARG(cause);
02829       AST_APP_ARG(options);
02830    );
02831 
02832    tmp = ast_strdupa(data);
02833 
02834    AST_STANDARD_APP_ARGS(args, tmp);
02835 
02836    headp = ast_channel_varshead(chan);
02837    AST_LIST_TRAVERSE(headp, current, entries) {
02838       if (!strcmp(ast_var_name(current), "OSPINHANDLE")) {
02839          if (sscanf(ast_var_value(current), "%30d", &inhandle) != 1) {
02840             inhandle = OSP_INVALID_HANDLE;
02841          }
02842       } else if (!strcmp(ast_var_name(current), "OSPOUTHANDLE")) {
02843          if (sscanf(ast_var_value(current), "%30d", &outhandle) != 1) {
02844             outhandle = OSP_INVALID_HANDLE;
02845          }
02846       } else if (!recorded &&
02847          (!strcmp(ast_var_name(current), "OSPAUTHSTATUS") ||
02848          !strcmp(ast_var_name(current), "OSPLOOKUPSTATUS") ||
02849          !strcmp(ast_var_name(current), "OSPNEXTSTATUS")))
02850       {
02851          if (strcmp(ast_var_value(current), AST_OSP_SUCCESS)) {
02852             recorded = 1;
02853          }
02854       } else if (!strcmp(ast_var_name(current), "OSPINAUDIOQOS")) {
02855          ast_copy_string(inqos, ast_var_value(current), sizeof(inqos));
02856       } else if (!strcmp(ast_var_name(current), "OSPOUTAUDIOQOS")) {
02857          ast_copy_string(outqos, ast_var_value(current), sizeof(outqos));
02858       }
02859    }
02860    ast_debug(1, "OSPFinish: OSPINHANDLE '%d'\n", inhandle);
02861    ast_debug(1, "OSPFinish: OSPOUTHANDLE '%d'\n", outhandle);
02862    ast_debug(1, "OSPFinish: recorded '%d'\n", recorded);
02863    ast_debug(1, "OSPFinish: OSPINAUDIOQOS '%s'\n", inqos);
02864    ast_debug(1, "OSPFinish: OSPOUTAUDIOQOS '%s'\n", outqos);
02865 
02866    if (!ast_strlen_zero(args.cause) && sscanf(args.cause, "%30d", &cause) != 1) {
02867       cause = 0;
02868    }
02869    ast_debug(1, "OSPFinish: cause '%d'\n", cause);
02870 
02871    if (!ast_tvzero(ast_channel_creationtime(chan))) {
02872       start = ast_channel_creationtime(chan).tv_sec;
02873    }
02874    if (!ast_tvzero(ast_channel_answertime(chan))) {
02875       connect = ast_channel_answertime(chan).tv_sec;
02876    }
02877    if (connect) {
02878       end = time(NULL);
02879    } else {
02880       end = connect;
02881    }
02882 
02883    ast_debug(1, "OSPFinish: start '%ld'\n", start);
02884    ast_debug(1, "OSPFinish: connect '%ld'\n", connect);
02885    ast_debug(1, "OSPFinish: end '%ld'\n", end);
02886 
02887    release = ast_check_hangup(chan) ? 0 : 1;
02888 
02889    if (osp_finish(outhandle, recorded, cause, start, connect, end, release, inqos, outqos) <= 0) {
02890       ast_debug(1, "OSPFinish: Unable to report usage for outbound call\n");
02891    }
02892    switch (cause) {
02893    case AST_CAUSE_NORMAL_CLEARING:
02894       break;
02895    default:
02896       cause = AST_CAUSE_NO_ROUTE_DESTINATION;
02897       break;
02898    }
02899    if (osp_finish(inhandle, recorded, cause, start, connect, end, release, inqos, outqos) <= 0) {
02900       ast_debug(1, "OSPFinish: Unable to report usage for inbound call\n");
02901    }
02902    snprintf(buffer, sizeof(buffer), "%d", OSP_INVALID_HANDLE);
02903    pbx_builtin_setvar_helper(chan, "OSPOUTHANDLE", buffer);
02904    pbx_builtin_setvar_helper(chan, "OSPINHANDLE", buffer);
02905 
02906    if (res > 0) {
02907       status = AST_OSP_SUCCESS;
02908    } else if (!res) {
02909       status = AST_OSP_FAILED;
02910    } else {
02911       status = AST_OSP_ERROR;
02912    }
02913    pbx_builtin_setvar_helper(chan, "OSPFINISHSTATUS", status);
02914 
02915    if(res != OSP_OK) {
02916       res = OSP_AST_ERROR;
02917    } else {
02918       res = OSP_AST_OK;
02919    }
02920 
02921    return res;
02922 }

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

OSP Application OSPLookup.

Parameters:
chan Channel
data Parameter
Returns:
OSP_AST_OK Success, OSP_AST_ERROR Error

Definition at line 2334 of file app_osplookup.c.

References args, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), ast_channel_caller(), ast_channel_varshead(), ast_copy_string(), 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_true(), ast_var_name(), ast_var_value(), osp_callid::buf, osp_results::called, osp_results::calling, osp_npdata::cic, osp_results::dest, osp_headers::divhost, osp_headers::divuser, exten, osp_results::inhandle, osp_results::intech, osp_results::intimelimit, osp_callid::len, LOG_WARNING, osp_results::networkid, osp_results::npcic, osp_results::npdi, osp_npdata::npdi, osp_results::nprn, NULL, osp_results::numdests, osp_results::opname, osp_npdata::opname, OSP_AST_ERROR, OSP_AST_OK, OSP_CALLID_H323, OSP_CALLID_IAX, OSP_CALLID_SIP, OSP_CALLID_UNDEF, OSP_DEF_PROVIDER, OSP_DEF_TIMELIMIT, OSP_INVALID_HANDLE, osp_lookup(), OSP_MAX_CUSTOMINFO, OSP_OK, OSP_SIP_HEADER, OSP_SIZE_TOKSTR, OSP_TECH_H323, OSP_TECH_IAX, OSP_TECH_SIP, OSP_TECH_SKYPE, osp_uuid2str(), osp_results::outcallid, osp_results::outhandle, osp_results::outtech, osp_results::outtimelimit, osp_headers::paiuser, pbx_builtin_setvar_helper(), osp_headers::pciuser, osp_npdata::rn, osp_headers::rpiduser, S_COR, status, tmp(), osp_results::token, and type.

Referenced by load_module().

02337 {
02338    int res;
02339    const char* provider = OSP_DEF_PROVIDER;
02340    unsigned int callidtypes = OSP_CALLID_UNDEF;
02341    struct varshead* headp;
02342    struct ast_var_t* current;
02343    const char* actualsrc = "";
02344    const char* srcdev = "";
02345    const char* snetid = "";
02346    struct osp_npdata np;
02347    OSPE_OPERATOR_NAME type;
02348    struct osp_headers headers;
02349    unsigned int i;
02350    const char* cinfo[OSP_MAX_CUSTOMINFO] = { NULL };
02351    char buffer[OSP_SIZE_TOKSTR];
02352    struct osp_results results;
02353    const char* status;
02354    char* tmp;
02355 
02356    AST_DECLARE_APP_ARGS(args,
02357       AST_APP_ARG(exten);
02358       AST_APP_ARG(provider);
02359       AST_APP_ARG(options);
02360    );
02361 
02362    if (ast_strlen_zero(data)) {
02363       ast_log(LOG_WARNING, "OSPLookup: Arg required, OSPLookup(exten[,provider[,options]])\n");
02364       return OSP_AST_ERROR;
02365    }
02366 
02367    tmp = ast_strdupa(data);
02368 
02369    AST_STANDARD_APP_ARGS(args, tmp);
02370 
02371    ast_debug(1, "OSPLookup: exten '%s'\n", args.exten);
02372 
02373    if (!ast_strlen_zero(args.provider)) {
02374       provider = args.provider;
02375    }
02376    ast_debug(1, "OSPlookup: provider '%s'\n", provider);
02377 
02378    if (args.options) {
02379       if (strchr(args.options, 'h')) {
02380          callidtypes |= OSP_CALLID_H323;
02381       }
02382       if (strchr(args.options, 's')) {
02383          callidtypes |= OSP_CALLID_SIP;
02384       }
02385       if (strchr(args.options, 'i')) {
02386          callidtypes |= OSP_CALLID_IAX;
02387       }
02388    }
02389    ast_debug(1, "OSPLookup: call id types '%d'\n", callidtypes);
02390 
02391    results.inhandle = OSP_INVALID_HANDLE;
02392    results.intimelimit = OSP_DEF_TIMELIMIT;
02393    results.dest[0] = '\0';
02394 
02395    np.rn = "";
02396    np.cic = "";
02397    np.npdi = 0;
02398    for (type = OSPC_OPNAME_START; type < OSPC_OPNAME_NUMBER; type++) {
02399       np.opname[type] = "";
02400    }
02401 
02402    headers.rpiduser = "";
02403    headers.paiuser = "";
02404    headers.divuser = "";
02405    headers.divhost = "";
02406    headers.pciuser = "";
02407 
02408    headp = ast_channel_varshead(chan);
02409    AST_LIST_TRAVERSE(headp, current, entries) {
02410       if (!strcmp(ast_var_name(current), "OSPINACTUALSRC")) {
02411          actualsrc = ast_var_value(current);
02412       } else if (!strcmp(ast_var_name(current), "OSPINPEERIP")) {
02413          srcdev = ast_var_value(current);
02414       } else if (!strcmp(ast_var_name(current), "OSPINTECH")) {
02415          ast_copy_string(results.intech, ast_var_value(current), sizeof(results.intech));
02416       } else if (!strcmp(ast_var_name(current), "OSPINHANDLE")) {
02417          if (sscanf(ast_var_value(current), "%30d", &results.inhandle) != 1) {
02418             results.inhandle = OSP_INVALID_HANDLE;
02419          }
02420       } else if (!strcmp(ast_var_name(current), "OSPINTIMELIMIT")) {
02421          if (sscanf(ast_var_value(current), "%30d", &results.intimelimit) != 1) {
02422             results.intimelimit = OSP_DEF_TIMELIMIT;
02423          }
02424       } else if (!strcmp(ast_var_name(current), "OSPINNETWORKID")) {
02425          snetid = ast_var_value(current);
02426       } else if (!strcmp(ast_var_name(current), "OSPINNPRN")) {
02427          np.rn = ast_var_value(current);
02428       } else if (!strcmp(ast_var_name(current), "OSPINNPCIC")) {
02429          np.cic = ast_var_value(current);
02430       } else if (!strcmp(ast_var_name(current), "OSPINNPDI")) {
02431          if (ast_true(ast_var_value(current))) {
02432             np.npdi = 1;
02433          }
02434       } else if (!strcmp(ast_var_name(current), "OSPINSPID")) {
02435          np.opname[OSPC_OPNAME_SPID] = ast_var_value(current);
02436       } else if (!strcmp(ast_var_name(current), "OSPINOCN")) {
02437          np.opname[OSPC_OPNAME_OCN] = ast_var_value(current);
02438       } else if (!strcmp(ast_var_name(current), "OSPINSPN")) {
02439          np.opname[OSPC_OPNAME_SPN] = ast_var_value(current);
02440       } else if (!strcmp(ast_var_name(current), "OSPINALTSPN")) {
02441          np.opname[OSPC_OPNAME_ALTSPN] = ast_var_value(current);
02442       } else if (!strcmp(ast_var_name(current), "OSPINMCC")) {
02443          np.opname[OSPC_OPNAME_MCC] = ast_var_value(current);
02444       } else if (!strcmp(ast_var_name(current), "OSPINMNC")) {
02445          np.opname[OSPC_OPNAME_MNC] = ast_var_value(current);
02446       } else if (!strcmp(ast_var_name(current), "OSPINTOHOST")) {
02447          ast_copy_string(results.dest, ast_var_value(current), sizeof(results.dest));
02448       } else if (!strcmp(ast_var_name(current), "OSPINRPIDUSER")) {
02449          headers.rpiduser = ast_var_value(current);
02450       } else if (!strcmp(ast_var_name(current), "OSPINPAIUSER")) {
02451          headers.paiuser = ast_var_value(current);
02452       } else if (!strcmp(ast_var_name(current), "OSPINDIVUSER")) {
02453          headers.divuser = ast_var_value(current);
02454       } else if (!strcmp(ast_var_name(current), "OSPINDIVHOST")) {
02455          headers.divhost = ast_var_value(current);
02456       } else if (!strcmp(ast_var_name(current), "OSPINPCIUSER")) {
02457          headers.pciuser = ast_var_value(current);
02458       } else if (!strcmp(ast_var_name(current), "OSPINCUSTOMINFO1")) {
02459          cinfo[0] = ast_var_value(current);
02460       } else if (!strcmp(ast_var_name(current), "OSPINCUSTOMINFO2")) {
02461          cinfo[1] = ast_var_value(current);
02462       } else if (!strcmp(ast_var_name(current), "OSPINCUSTOMINFO3")) {
02463          cinfo[2] = ast_var_value(current);
02464       } else if (!strcmp(ast_var_name(current), "OSPINCUSTOMINFO4")) {
02465          cinfo[3] = ast_var_value(current);
02466       } else if (!strcmp(ast_var_name(current), "OSPINCUSTOMINFO5")) {
02467          cinfo[4] = ast_var_value(current);
02468       } else if (!strcmp(ast_var_name(current), "OSPINCUSTOMINFO6")) {
02469          cinfo[5] = ast_var_value(current);
02470       } else if (!strcmp(ast_var_name(current), "OSPINCUSTOMINFO7")) {
02471          cinfo[6] = ast_var_value(current);
02472       } else if (!strcmp(ast_var_name(current), "OSPINCUSTOMINFO8")) {
02473          cinfo[7] = ast_var_value(current);
02474       }
02475    }
02476    ast_debug(1, "OSPLookup: actual source device '%s'\n", actualsrc);
02477    ast_debug(1, "OSPLookup: source device '%s'\n", srcdev);
02478    ast_debug(1, "OSPLookup: OSPINTECH '%s'\n", results.intech);
02479    ast_debug(1, "OSPLookup: OSPINHANDLE '%d'\n", results.inhandle);
02480    ast_debug(1, "OSPLookup: OSPINTIMELIMIT '%d'\n", results.intimelimit);
02481    ast_debug(1, "OSPLookup: OSPINNETWORKID '%s'\n", snetid);
02482    ast_debug(1, "OSPLookup: OSPINNPRN '%s'\n", np.rn);
02483    ast_debug(1, "OSPLookup: OSPINNPCIC '%s'\n", np.cic);
02484    ast_debug(1, "OSPLookup: OSPINNPDI '%d'\n", np.npdi);
02485    ast_debug(1, "OSPLookup: OSPINSPID '%s'\n", np.opname[OSPC_OPNAME_SPID]);
02486    ast_debug(1, "OSPLookup: OSPINOCN '%s'\n", np.opname[OSPC_OPNAME_OCN]);
02487    ast_debug(1, "OSPLookup: OSPINSPN '%s'\n", np.opname[OSPC_OPNAME_SPN]);
02488    ast_debug(1, "OSPLookup: OSPINALTSPN '%s'\n", np.opname[OSPC_OPNAME_ALTSPN]);
02489    ast_debug(1, "OSPLookup: OSPINMCC '%s'\n", np.opname[OSPC_OPNAME_MCC]);
02490    ast_debug(1, "OSPLookup: OSPINMNC '%s'\n", np.opname[OSPC_OPNAME_MNC]);
02491    ast_debug(1, "OSPLookup: OSPINTOHOST '%s'\n", results.dest);
02492    ast_debug(1, "OSPLookup: OSPINRPIDUSER '%s'\n", headers.rpiduser);
02493    ast_debug(1, "OSPLookup: OSPINPAIUSER '%s'\n", headers.paiuser);
02494    ast_debug(1, "OSPLookup: OSPINDIVUSER '%s'\n", headers.divuser);
02495    ast_debug(1, "OSPLookup: OSPINDIVHOST'%s'\n", headers.divhost);
02496    ast_debug(1, "OSPLookup: OSPINPCIUSER '%s'\n", headers.pciuser);
02497    for (i = 0; i < OSP_MAX_CUSTOMINFO; i++) {
02498       if (!ast_strlen_zero(cinfo[i])) {
02499          ast_debug(1, "OSPLookup: OSPINCUSTOMINFO%d '%s'\n", i, cinfo[i]);
02500       }
02501    }
02502 
02503    if (ast_autoservice_start(chan) < 0) {
02504       return OSP_AST_ERROR;
02505    }
02506 
02507    res = osp_lookup(provider, callidtypes, actualsrc, srcdev,
02508       S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL),
02509       args.exten, snetid, &np, &headers, cinfo, &results);
02510    if (res > 0) {
02511       status = AST_OSP_SUCCESS;
02512    } else {
02513       results.outtech[0] = '\0';
02514       results.dest[0] = '\0';
02515       results.calling[0] = '\0';
02516       results.called[0] = '\0';
02517       results.token[0] = '\0';
02518       results.networkid[0] = '\0';
02519       results.nprn[0] = '\0';
02520       results.npcic[0] = '\0';
02521       results.npdi = 0;
02522       for (type = OSPC_OPNAME_START; type < OSPC_OPNAME_NUMBER; type++) {
02523          results.opname[type][0] = '\0';
02524       }
02525       results.numdests = 0;
02526       results.outtimelimit = OSP_DEF_TIMELIMIT;
02527       results.outcallid.buf[0] = '\0';
02528       results.outcallid.len = 0;
02529       if (!res) {
02530          status = AST_OSP_FAILED;
02531       } else {
02532          status = AST_OSP_ERROR;
02533       }
02534    }
02535 
02536    snprintf(buffer, sizeof(buffer), "%d", results.outhandle);
02537    pbx_builtin_setvar_helper(chan, "OSPOUTHANDLE", buffer);
02538    ast_debug(1, "OSPLookup: OSPOUTHANDLE '%s'\n", buffer);
02539    pbx_builtin_setvar_helper(chan, "OSPOUTTECH", results.outtech);
02540    ast_debug(1, "OSPLookup: OSPOUTTECH '%s'\n", results.outtech);
02541    pbx_builtin_setvar_helper(chan, "OSPDESTINATION", results.dest);
02542    ast_debug(1, "OSPLookup: OSPDESTINATION '%s'\n", results.dest);
02543    pbx_builtin_setvar_helper(chan, "OSPOUTCALLING", results.calling);
02544    ast_debug(1, "OSPLookup: OSPOUTCALLING '%s'\n", results.calling);
02545    pbx_builtin_setvar_helper(chan, "OSPOUTCALLED", results.called);
02546    ast_debug(1, "OSPLookup: OSPOUTCALLED '%s'\n", results.called);
02547    pbx_builtin_setvar_helper(chan, "OSPOUTNETWORKID", results.networkid);
02548    ast_debug(1, "OSPLookup: OSPOUTNETWORKID '%s'\n", results.networkid);
02549    pbx_builtin_setvar_helper(chan, "OSPOUTNPRN", results.nprn);
02550    ast_debug(1, "OSPLookup: OSPOUTNPRN '%s'\n", results.nprn);
02551    pbx_builtin_setvar_helper(chan, "OSPOUTNPCIC", results.npcic);
02552    ast_debug(1, "OSPLookup: OSPOUTNPCIC '%s'\n", results.npcic);
02553    snprintf(buffer, sizeof(buffer), "%d", results.npdi);
02554    pbx_builtin_setvar_helper(chan, "OSPOUTNPDI", buffer);
02555    ast_debug(1, "OSPLookup: OSPOUTNPDI'%s'\n", buffer);
02556    pbx_builtin_setvar_helper(chan, "OSPOUTSPID", results.opname[OSPC_OPNAME_SPID]);
02557    ast_debug(1, "OSPLookup: OSPOUTSPID '%s'\n", results.opname[OSPC_OPNAME_SPID]);
02558    pbx_builtin_setvar_helper(chan, "OSPOUTOCN", results.opname[OSPC_OPNAME_OCN]);
02559    ast_debug(1, "OSPLookup: OSPOUTOCN '%s'\n", results.opname[OSPC_OPNAME_OCN]);
02560    pbx_builtin_setvar_helper(chan, "OSPOUTSPN", results.opname[OSPC_OPNAME_SPN]);
02561    ast_debug(1, "OSPLookup: OSPOUTSPN '%s'\n", results.opname[OSPC_OPNAME_SPN]);
02562    pbx_builtin_setvar_helper(chan, "OSPOUTALTSPN", results.opname[OSPC_OPNAME_ALTSPN]);
02563    ast_debug(1, "OSPLookup: OSPOUTALTSPN '%s'\n", results.opname[OSPC_OPNAME_ALTSPN]);
02564    pbx_builtin_setvar_helper(chan, "OSPOUTMCC", results.opname[OSPC_OPNAME_MCC]);
02565    ast_debug(1, "OSPLookup: OSPOUTMCC '%s'\n", results.opname[OSPC_OPNAME_MCC]);
02566    pbx_builtin_setvar_helper(chan, "OSPOUTMNC", results.opname[OSPC_OPNAME_MNC]);
02567    ast_debug(1, "OSPLookup: OSPOUTMNC '%s'\n", results.opname[OSPC_OPNAME_MNC]);
02568    pbx_builtin_setvar_helper(chan, "OSPOUTTOKEN", results.token);
02569    ast_debug(1, "OSPLookup: OSPOUTTOKEN size '%zd'\n", strlen(results.token));
02570    snprintf(buffer, sizeof(buffer), "%d", results.numdests);
02571    pbx_builtin_setvar_helper(chan, "OSPDESTREMAILS", buffer);
02572    ast_debug(1, "OSPLookup: OSPDESTREMAILS '%s'\n", buffer);
02573    snprintf(buffer, sizeof(buffer), "%d", results.outtimelimit);
02574    pbx_builtin_setvar_helper(chan, "OSPOUTTIMELIMIT", buffer);
02575    ast_debug(1, "OSPLookup: OSPOUTTIMELIMIT '%s'\n", buffer);
02576    snprintf(buffer, sizeof(buffer), "%d", callidtypes);
02577    pbx_builtin_setvar_helper(chan, "OSPOUTCALLIDTYPES", buffer);
02578    ast_debug(1, "OSPLookup: OSPOUTCALLIDTYPES '%s'\n", buffer);
02579    pbx_builtin_setvar_helper(chan, "OSPLOOKUPSTATUS", status);
02580    ast_debug(1, "OSPLookup: %s\n", status);
02581 
02582    if (!strcasecmp(results.outtech, OSP_TECH_SIP)) {
02583       snprintf(buffer, sizeof(buffer), "%s/%s@%s", results.outtech, results.called, results.dest);
02584       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
02585       if (!ast_strlen_zero(results.token)) {
02586          snprintf(buffer, sizeof(buffer), "%s: %s", OSP_SIP_HEADER, results.token);
02587          pbx_builtin_setvar_helper(chan, "_SIPADDHEADER", buffer);
02588          ast_debug(1, "OSPLookup: SIPADDHEADER size '%zd'\n", strlen(buffer));
02589       }
02590    } else if (!strcasecmp(results.outtech, OSP_TECH_H323)) {
02591       if ((callidtypes & OSP_CALLID_H323) && (results.outcallid.len != 0)) {
02592          osp_uuid2str(results.outcallid.buf, buffer, sizeof(buffer));
02593       } else {
02594          buffer[0] = '\0';
02595       }
02596       pbx_builtin_setvar_helper(chan, "OSPOUTCALLID", buffer);
02597       snprintf(buffer, sizeof(buffer), "%s/%s@%s", results.outtech, results.called, results.dest);
02598       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
02599    } else if (!strcasecmp(results.outtech, OSP_TECH_IAX)) {
02600       snprintf(buffer, sizeof(buffer), "%s/%s/%s", results.outtech, results.dest, results.called);
02601       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
02602    } else if (!strcasecmp(results.outtech, OSP_TECH_SKYPE)) {
02603       snprintf(buffer, sizeof(buffer), "%s/%s", results.outtech, results.called);
02604       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
02605    }
02606 
02607    if (ast_autoservice_stop(chan) < 0) {
02608       return OSP_AST_ERROR;
02609    }
02610 
02611    if(res != OSP_OK) {
02612       res = OSP_AST_ERROR;
02613    } else {
02614       res = OSP_AST_OK;
02615    }
02616 
02617    return res;
02618 }

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

OSP Application OSPNext.

Parameters:
chan Channel
data Parameter
Returns:
OSP_AST_OK Success, OSP_AST_ERROR Error

Definition at line 2626 of file app_osplookup.c.

References args, AST_APP_ARG, ast_channel_varshead(), 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_results::called, osp_results::calling, osp_results::dest, osp_results::inhandle, osp_results::intimelimit, osp_callid::len, LOG_WARNING, osp_results::networkid, osp_results::npcic, osp_results::npdi, osp_results::nprn, osp_results::numdests, osp_results::opname, OSP_AST_ERROR, OSP_AST_OK, OSP_CALLID_H323, OSP_CALLID_UNDEF, OSP_DEF_PROVIDER, OSP_DEF_TIMELIMIT, OSP_INVALID_HANDLE, osp_next(), OSP_OK, OSP_SIP_HEADER, OSP_SIZE_TOKSTR, OSP_TECH_H323, OSP_TECH_IAX, OSP_TECH_SIP, OSP_TECH_SKYPE, osp_uuid2str(), osp_results::outcallid, osp_results::outhandle, osp_results::outtech, osp_results::outtimelimit, pbx_builtin_setvar_helper(), status, tmp(), osp_results::token, and type.

Referenced by load_module().

02629 {
02630    int res;
02631    const char* provider = OSP_DEF_PROVIDER;
02632    int cause = 0;
02633    struct varshead* headp;
02634    struct ast_var_t* current;
02635    struct osp_results results;
02636    OSPE_OPERATOR_NAME type;
02637    char buffer[OSP_SIZE_TOKSTR];
02638    unsigned int callidtypes = OSP_CALLID_UNDEF;
02639    const char* status;
02640    char* tmp;
02641 
02642    AST_DECLARE_APP_ARGS(args,
02643       AST_APP_ARG(cause);
02644       AST_APP_ARG(provider);
02645       AST_APP_ARG(options);
02646    );
02647 
02648    if (ast_strlen_zero(data)) {
02649       ast_log(LOG_WARNING, "OSPNext: Arg required, OSPNext(cause[,provider[,options]])\n");
02650       return OSP_AST_ERROR;
02651    }
02652 
02653    tmp = ast_strdupa(data);
02654 
02655    AST_STANDARD_APP_ARGS(args, tmp);
02656 
02657    if (!ast_strlen_zero(args.cause) && sscanf(args.cause, "%30d", &cause) != 1) {
02658       cause = 0;
02659    }
02660    ast_debug(1, "OSPNext: cause '%d'\n", cause);
02661 
02662    if (!ast_strlen_zero(args.provider)) {
02663       provider = args.provider;
02664    }
02665    ast_debug(1, "OSPlookup: provider '%s'\n", provider);
02666 
02667    results.inhandle = OSP_INVALID_HANDLE;
02668    results.outhandle = OSP_INVALID_HANDLE;
02669    results.intimelimit = OSP_DEF_TIMELIMIT;
02670    results.numdests = 0;
02671 
02672    headp = ast_channel_varshead(chan);
02673    AST_LIST_TRAVERSE(headp, current, entries) {
02674       if (!strcmp(ast_var_name(current), "OSPINHANDLE")) {
02675          if (sscanf(ast_var_value(current), "%30d", &results.inhandle) != 1) {
02676             results.inhandle = OSP_INVALID_HANDLE;
02677          }
02678       } else if (!strcmp(ast_var_name(current), "OSPOUTHANDLE")) {
02679          if (sscanf(ast_var_value(current), "%30d", &results.outhandle) != 1) {
02680             results.outhandle = OSP_INVALID_HANDLE;
02681          }
02682       } else if (!strcmp(ast_var_name(current), "OSPINTIMELIMIT")) {
02683          if (sscanf(ast_var_value(current), "%30d", &results.intimelimit) != 1) {
02684             results.intimelimit = OSP_DEF_TIMELIMIT;
02685          }
02686       } else if (!strcmp(ast_var_name(current), "OSPOUTCALLIDTYPES")) {
02687          if (sscanf(ast_var_value(current), "%30d", &callidtypes) != 1) {
02688             callidtypes = OSP_CALLID_UNDEF;
02689          }
02690       } else if (!strcmp(ast_var_name(current), "OSPDESTREMAILS")) {
02691          if (sscanf(ast_var_value(current), "%30d", &results.numdests) != 1) {
02692             results.numdests = 0;
02693          }
02694       }
02695    }
02696    ast_debug(1, "OSPNext: OSPINHANDLE '%d'\n", results.inhandle);
02697    ast_debug(1, "OSPNext: OSPOUTHANDLE '%d'\n", results.outhandle);
02698    ast_debug(1, "OSPNext: OSPINTIMELIMIT '%d'\n", results.intimelimit);
02699    ast_debug(1, "OSPNext: OSPOUTCALLIDTYPES '%d'\n", callidtypes);
02700    ast_debug(1, "OSPNext: OSPDESTREMAILS '%d'\n", results.numdests);
02701 
02702    if ((res = osp_next(provider, cause, &results)) > 0) {
02703       status = AST_OSP_SUCCESS;
02704    } else {
02705       results.outtech[0] = '\0';
02706       results.dest[0] = '\0';
02707       results.calling[0] = '\0';
02708       results.called[0] = '\0';
02709       results.token[0] = '\0';
02710       results.networkid[0] = '\0';
02711       results.nprn[0] = '\0';
02712       results.npcic[0] = '\0';
02713       results.npdi = 0;
02714       for (type = OSPC_OPNAME_START; type < OSPC_OPNAME_NUMBER; type++) {
02715          results.opname[type][0] = '\0';
02716       }
02717       results.numdests = 0;
02718       results.outtimelimit = OSP_DEF_TIMELIMIT;
02719       results.outcallid.buf[0] = '\0';
02720       results.outcallid.len = 0;
02721       if (!res) {
02722          status = AST_OSP_FAILED;
02723       } else {
02724          status = AST_OSP_ERROR;
02725       }
02726    }
02727 
02728    pbx_builtin_setvar_helper(chan, "OSPOUTTECH", results.outtech);
02729    ast_debug(1, "OSPNext: OSPOUTTECH '%s'\n", results.outtech);
02730    pbx_builtin_setvar_helper(chan, "OSPDESTINATION", results.dest);
02731    ast_debug(1, "OSPNext: OSPDESTINATION '%s'\n", results.dest);
02732    pbx_builtin_setvar_helper(chan, "OSPOUTCALLING", results.calling);
02733    ast_debug(1, "OSPNext: OSPOUTCALLING '%s'\n", results.calling);
02734    pbx_builtin_setvar_helper(chan, "OSPOUTCALLED", results.called);
02735    ast_debug(1, "OSPNext: OSPOUTCALLED'%s'\n", results.called);
02736    pbx_builtin_setvar_helper(chan, "OSPOUTNETWORKID", results.networkid);
02737    ast_debug(1, "OSPLookup: OSPOUTNETWORKID '%s'\n", results.networkid);
02738    pbx_builtin_setvar_helper(chan, "OSPOUTNPRN", results.nprn);
02739    ast_debug(1, "OSPLookup: OSPOUTNPRN '%s'\n", results.nprn);
02740    pbx_builtin_setvar_helper(chan, "OSPOUTNPCIC", results.npcic);
02741    ast_debug(1, "OSPLookup: OSPOUTNPCIC '%s'\n", results.npcic);
02742    snprintf(buffer, sizeof(buffer), "%d", results.npdi);
02743    pbx_builtin_setvar_helper(chan, "OSPOUTNPDI", buffer);
02744    ast_debug(1, "OSPLookup: OSPOUTNPDI'%s'\n", buffer);
02745    pbx_builtin_setvar_helper(chan, "OSPOUTSPID", results.opname[OSPC_OPNAME_SPID]);
02746    ast_debug(1, "OSPLookup: OSPOUTSPID '%s'\n", results.opname[OSPC_OPNAME_SPID]);
02747    pbx_builtin_setvar_helper(chan, "OSPOUTOCN", results.opname[OSPC_OPNAME_OCN]);
02748    ast_debug(1, "OSPLookup: OSPOUTOCN '%s'\n", results.opname[OSPC_OPNAME_OCN]);
02749    pbx_builtin_setvar_helper(chan, "OSPOUTSPN", results.opname[OSPC_OPNAME_SPN]);
02750    ast_debug(1, "OSPLookup: OSPOUTSPN '%s'\n", results.opname[OSPC_OPNAME_SPN]);
02751    pbx_builtin_setvar_helper(chan, "OSPOUTALTSPN", results.opname[OSPC_OPNAME_ALTSPN]);
02752    ast_debug(1, "OSPLookup: OSPOUTALTSPN '%s'\n", results.opname[OSPC_OPNAME_ALTSPN]);
02753    pbx_builtin_setvar_helper(chan, "OSPOUTMCC", results.opname[OSPC_OPNAME_MCC]);
02754    ast_debug(1, "OSPLookup: OSPOUTMCC '%s'\n", results.opname[OSPC_OPNAME_MCC]);
02755    pbx_builtin_setvar_helper(chan, "OSPOUTMNC", results.opname[OSPC_OPNAME_MNC]);
02756    ast_debug(1, "OSPLookup: OSPOUTMNC '%s'\n", results.opname[OSPC_OPNAME_MNC]);
02757    pbx_builtin_setvar_helper(chan, "OSPOUTTOKEN", results.token);
02758    ast_debug(1, "OSPNext: OSPOUTTOKEN size '%zd'\n", strlen(results.token));
02759    snprintf(buffer, sizeof(buffer), "%d", results.numdests);
02760    pbx_builtin_setvar_helper(chan, "OSPDESTREMAILS", buffer);
02761    ast_debug(1, "OSPNext: OSPDESTREMAILS '%s'\n", buffer);
02762    snprintf(buffer, sizeof(buffer), "%d", results.outtimelimit);
02763    pbx_builtin_setvar_helper(chan, "OSPOUTTIMELIMIT", buffer);
02764    ast_debug(1, "OSPNext: OSPOUTTIMELIMIT '%s'\n", buffer);
02765    pbx_builtin_setvar_helper(chan, "OSPNEXTSTATUS", status);
02766    ast_debug(1, "OSPNext: %s\n", status);
02767 
02768    if (!strcasecmp(results.outtech, OSP_TECH_SIP)) {
02769       snprintf(buffer, sizeof(buffer), "%s/%s@%s", results.outtech, results.called, results.dest);
02770       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
02771       if (!ast_strlen_zero(results.token)) {
02772          snprintf(buffer, sizeof(buffer), "%s: %s", OSP_SIP_HEADER, results.token);
02773          pbx_builtin_setvar_helper(chan, "_SIPADDHEADER", buffer);
02774          ast_debug(1, "OSPLookup: SIPADDHEADER size '%zd'\n", strlen(buffer));
02775       }
02776    } else if (!strcasecmp(results.outtech, OSP_TECH_H323)) {
02777       if ((callidtypes & OSP_CALLID_H323) && (results.outcallid.len != 0)) {
02778          osp_uuid2str(results.outcallid.buf, buffer, sizeof(buffer));
02779       } else {
02780          buffer[0] = '\0';
02781       }
02782       pbx_builtin_setvar_helper(chan, "OSPOUTCALLID", buffer);
02783       snprintf(buffer, sizeof(buffer), "%s/%s@%s", results.outtech, results.called, results.dest);
02784       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
02785    } else if (!strcasecmp(results.outtech, OSP_TECH_IAX)) {
02786       snprintf(buffer, sizeof(buffer), "%s/%s/%s", results.outtech, results.dest, results.called);
02787       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
02788    } else if (!strcasecmp(results.outtech, OSP_TECH_SKYPE)) {
02789       snprintf(buffer, sizeof(buffer), "%s/%s", results.outtech, results.called);
02790       pbx_builtin_setvar_helper(chan, "OSPDIALSTR", buffer);
02791    }
02792 
02793    if(res != OSP_OK) {
02794       res = OSP_AST_ERROR;
02795    } else {
02796       res = OSP_AST_OK;
02797    }
02798 
02799    return res;
02800 }

static int reload ( void   )  [static]

Definition at line 3155 of file app_osplookup.c.

References osp_load().

03156 {
03157    osp_load(1);
03158 
03159    return 0;
03160 }

static int unload_module ( void   )  [static]

Definition at line 3141 of file app_osplookup.c.

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

03142 {
03143    int res;
03144 
03145    res = ast_unregister_application(app4);
03146    res |= ast_unregister_application(app3);
03147    res |= ast_unregister_application(app2);
03148    res |= ast_unregister_application(app1);
03149    ast_cli_unregister_multiple(cli_osp, sizeof(cli_osp) / sizeof(struct ast_cli_entry));
03150    osp_unload();
03151 
03152    return res;
03153 }


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, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload, } [static]

Definition at line 3167 of file app_osplookup.c.

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

Definition at line 3110 of file app_osplookup.c.

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

Definition at line 3113 of file app_osplookup.c.

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

Definition at line 3116 of file app_osplookup.c.

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

Definition at line 3119 of file app_osplookup.c.

Definition at line 3167 of file app_osplookup.c.

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

Definition at line 631 of file app_osplookup.c.

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

Definition at line 630 of file app_osplookup.c.

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

Definition at line 629 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 3121 of file app_osplookup.c.

int osp_hardware = 0 [static]

Definition at line 623 of file app_osplookup.c.

int osp_initialized = 0 [static]

Definition at line 622 of file app_osplookup.c.

ast_mutex_t osp_lock = { PTHREAD_MUTEX_INITIALIZER , NULL, 1 } [static]

struct osp_provider* osp_providers = NULL [static]

Definition at line 625 of file app_osplookup.c.

int osp_security = 0 [static]

Definition at line 624 of file app_osplookup.c.

unsigned int osp_tokenformat = TOKEN_ALGO_SIGNED [static]

Definition at line 626 of file app_osplookup.c.


Generated on Thu Apr 16 06:28:37 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6