Sat Feb 11 06:33:51 2012

Asterisk developer's documentation


app_osplookup.c File Reference

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

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

Include dependency graph for app_osplookup.c:

Go to the source code of this file.

Data Structures

struct  osp_callid
struct  osp_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, .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 3177 of file app_osplookup.c.

static void __unreg_module ( void   )  [static]

Definition at line 3177 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 3030 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, 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.

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

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, 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, LOG_ERROR, LOG_WARNING, osp_results::networkid, osp_results::npcic, osp_results::npdi, osp_results::nprn, 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(), 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(), 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 1446 of file app_osplookup.c.

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

Referenced by osp_lookup().

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

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, 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, 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, osp_provider::handle, LOG_ERROR, osp_provider::name, osp_provider::next, 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, OSP_ERROR, OSP_OK, and OSP_SIZE_UUID.

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

References ast_debug, asterisk2osp(), dummy(), 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().

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

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

References ast_strlen_zero(), OSP_DEF_FLOATSTATS, and value.

Referenced by osp_report_qos().

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

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

References ast_strlen_zero(), OSP_DEF_INTSTATS, and value.

Referenced by osp_report_qos().

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

static int osp_load ( int  reload  )  [static]

Definition at line 2963 of file app_osplookup.c.

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

Referenced by load_module(), and reload().

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

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 1494 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(), 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, 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, osp_results::token, type, and osp_provider::workmode.

Referenced by osplookup_exec().

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

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

References ast_debug, ast_log(), asterisk2osp(), osp_callid::buf, osp_results::called, osp_results::calling, osp_results::dest, osp_results::inhandle, osp_results::intimelimit, osp_callid::len, LOG_ERROR, osp_results::networkid, osp_results::npcic, osp_results::npdi, osp_results::nprn, 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().

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

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

References ast_copy_string(), ast_debug, ast_strlen_zero(), osp_metrics::avg, osp_metrics::max, osp_metrics::min, 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, osp_metrics::value, and value.

Referenced by osp_finish().

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

static int osp_unload ( void   )  [static]

Definition at line 2937 of file app_osplookup.c.

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

Referenced by osp_load(), and unload_module().

02938 {
02939    struct osp_provider* provider;
02940    struct osp_provider* next;
02941 
02942    if (osp_initialized) {
02943       ast_mutex_lock(&osp_lock);
02944       for (provider = osp_providers; provider; provider = next) {
02945          next = provider->next;
02946          OSPPProviderDelete(provider->handle, 0);
02947          ast_free(provider);
02948       }
02949       osp_providers = NULL;
02950       ast_mutex_unlock(&osp_lock);
02951 
02952       OSPPCleanup();
02953 
02954       osp_tokenformat = TOKEN_ALGO_SIGNED;
02955       osp_security = 0;
02956       osp_hardware = 0;
02957       osp_initialized = 0;
02958    }
02959 
02960    return 0;
02961 }

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, 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, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
01429          uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
01430          uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
01431       res = OSP_OK;
01432    } else {
01433       ast_log(LOG_ERROR, "Invalid parameters\n");
01434       res = OSP_ERROR;
01435    }
01436 
01437    return res;
01438 }

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(), LOG_ERROR, LOG_WARNING, 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 2252 of file app_osplookup.c.

References args, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, AST_LIST_TRAVERSE, ast_log(), AST_OSP_ERROR, AST_OSP_FAILED, AST_OSP_SUCCESS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_var_name(), ast_var_value(), ast_channel::caller, ast_var_t::entries, ast_channel::exten, ast_party_caller::id, LOG_ERROR, ast_party_id::number, 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, ast_party_number::str, ast_party_number::valid, and ast_channel::varshead.

Referenced by load_module().

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

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

References ast_cdr::answer, args, AST_APP_ARG, AST_CAUSE_NO_ROUTE_DESTINATION, AST_CAUSE_NORMAL_CLEARING, ast_check_hangup(), 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_var_name(), ast_var_value(), cause, ast_channel::cdr, ast_var_t::entries, LOG_ERROR, OSP_AST_ERROR, OSP_AST_OK, osp_finish(), OSP_INVALID_HANDLE, OSP_OK, OSP_SIZE_INTSTR, OSP_SIZE_QOSSTR, pbx_builtin_setvar_helper(), ast_cdr::start, status, and ast_channel::varshead.

Referenced by load_module().

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

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

References args, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), 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, ast_channel::caller, osp_results::calling, osp_npdata::cic, osp_results::dest, osp_headers::divhost, osp_headers::divuser, exten, ast_party_caller::id, osp_results::inhandle, osp_results::intech, osp_results::intimelimit, osp_callid::len, LOG_ERROR, LOG_WARNING, osp_results::networkid, osp_results::npcic, osp_results::npdi, osp_npdata::npdi, osp_results::nprn, ast_party_id::number, 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, ast_party_number::str, osp_results::token, type, ast_party_number::valid, and ast_channel::varshead.

Referenced by load_module().

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

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

References args, AST_APP_ARG, ast_debug, AST_DECLARE_APP_ARGS, AST_LIST_TRAVERSE, ast_log(), AST_OSP_ERROR, AST_OSP_FAILED, AST_OSP_SUCCESS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_var_name(), ast_var_value(), osp_callid::buf, osp_results::called, osp_results::calling, cause, osp_results::dest, osp_results::inhandle, osp_results::intimelimit, osp_callid::len, LOG_ERROR, 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, osp_results::token, type, and ast_channel::varshead.

Referenced by load_module().

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

static int reload ( void   )  [static]

Definition at line 3166 of file app_osplookup.c.

References osp_load().

03167 {
03168    osp_load(1);
03169 
03170    return 0;
03171 }

static int unload_module ( void   )  [static]

Definition at line 3152 of file app_osplookup.c.

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

03153 {
03154    int res;
03155 
03156    res = ast_unregister_application(app4);
03157    res |= ast_unregister_application(app3);
03158    res |= ast_unregister_application(app2);
03159    res |= ast_unregister_application(app1);
03160    ast_cli_unregister_multiple(cli_osp, sizeof(cli_osp) / sizeof(struct ast_cli_entry));
03161    osp_unload();
03162 
03163    return res;
03164 }


Variable Documentation

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

Definition at line 3177 of file app_osplookup.c.

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

Definition at line 3121 of file app_osplookup.c.

Referenced by app_cmp().

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

Definition at line 3124 of file app_osplookup.c.

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

Definition at line 3127 of file app_osplookup.c.

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

Definition at line 3130 of file app_osplookup.c.

Definition at line 3177 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 3132 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 Sat Feb 11 06:33:51 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6